asm.h revision 1.1 1 1.1 cherry /* $NetBSD: asm.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
2 1.1 cherry
3 1.1 cherry /* -
4 1.1 cherry * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University
5 1.1 cherry * All Rights Reserved.
6 1.1 cherry *
7 1.1 cherry * Permission to use, copy, modify and distribute this software and its
8 1.1 cherry * documentation is hereby granted, provided that both the copyright
9 1.1 cherry * notice and this permission notice appear in all copies of the
10 1.1 cherry * software, derivative works or modified versions, and any portions
11 1.1 cherry * thereof, and that both notices appear in supporting documentation.
12 1.1 cherry *
13 1.1 cherry * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 1.1 cherry * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 1.1 cherry * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 1.1 cherry *
17 1.1 cherry * Carnegie Mellon requests users of this software to return to
18 1.1 cherry *
19 1.1 cherry * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
20 1.1 cherry * School of Computer Science
21 1.1 cherry * Carnegie Mellon University
22 1.1 cherry * Pittsburgh PA 15213-3890
23 1.1 cherry *
24 1.1 cherry * any improvements or extensions that they make and grant Carnegie Mellon
25 1.1 cherry * the rights to redistribute these changes.
26 1.1 cherry */
27 1.1 cherry
28 1.1 cherry /*
29 1.1 cherry * Assembly coding style
30 1.1 cherry *
31 1.1 cherry * This file contains macros and register defines to
32 1.1 cherry * aid in writing more readable assembly code.
33 1.1 cherry * Some rules to make assembly code understandable by
34 1.1 cherry * a debugger are also noted.
35 1.1 cherry */
36 1.1 cherry
37 1.1 cherry /*
38 1.1 cherry * Macro to make a local label name.
39 1.1 cherry */
40 1.1 cherry #define LLABEL(name,num) L ## name ## num
41 1.1 cherry
42 1.1 cherry /*
43 1.1 cherry * MCOUNT
44 1.1 cherry */
45 1.1 cherry #if defined(GPROF)
46 1.1 cherry #define MCOUNT \
47 1.1 cherry alloc out0 = ar.pfs, 8, 0, 4, 0; \
48 1.1 cherry mov out1 = r1; \
49 1.1 cherry mov out2 = b0;; \
50 1.1 cherry mov out3 = r0; \
51 1.1 cherry br.call.sptk b0 = _mcount;;
52 1.1 cherry #else
53 1.1 cherry #define MCOUNT /* nothing */
54 1.1 cherry #endif
55 1.1 cherry
56 1.1 cherry /*
57 1.1 cherry * ENTRY
58 1.1 cherry * Declare a global leaf function.
59 1.1 cherry * A leaf function does not call other functions.
60 1.1 cherry */
61 1.1 cherry #define ENTRY(_name_, _n_args_) \
62 1.1 cherry .global _name_; \
63 1.1 cherry .align 16; \
64 1.1 cherry .proc _name_; \
65 1.1 cherry _name_:; \
66 1.1 cherry .regstk _n_args_, 0, 0, 0; \
67 1.1 cherry MCOUNT
68 1.1 cherry
69 1.1 cherry #define ENTRY_NOPROFILE(_name_, _n_args_) \
70 1.1 cherry .global _name_; \
71 1.1 cherry .align 16; \
72 1.1 cherry .proc _name_; \
73 1.1 cherry _name_:; \
74 1.1 cherry .regstk _n_args_, 0, 0, 0
75 1.1 cherry
76 1.1 cherry /*
77 1.1 cherry * STATIC_ENTRY
78 1.1 cherry * Declare a local leaf function.
79 1.1 cherry */
80 1.1 cherry #define STATIC_ENTRY(_name_, _n_args_) \
81 1.1 cherry .align 16; \
82 1.1 cherry .proc _name_; \
83 1.1 cherry _name_:; \
84 1.1 cherry .regstk _n_args_, 0, 0, 0 \
85 1.1 cherry MCOUNT
86 1.1 cherry /*
87 1.1 cherry * XENTRY
88 1.1 cherry * Global alias for a leaf function, or alternate entry point
89 1.1 cherry */
90 1.1 cherry #define XENTRY(_name_) \
91 1.1 cherry .globl _name_; \
92 1.1 cherry _name_:
93 1.1 cherry
94 1.1 cherry /*
95 1.1 cherry * STATIC_XENTRY
96 1.1 cherry * Local alias for a leaf function, or alternate entry point
97 1.1 cherry */
98 1.1 cherry #define STATIC_XENTRY(_name_) \
99 1.1 cherry _name_:
100 1.1 cherry
101 1.1 cherry
102 1.1 cherry /*
103 1.1 cherry * END
104 1.1 cherry * Function delimiter
105 1.1 cherry */
106 1.1 cherry #define END(_name_) \
107 1.1 cherry .endp _name_
108 1.1 cherry
109 1.1 cherry
110 1.1 cherry /*
111 1.1 cherry * EXPORT
112 1.1 cherry * Export a symbol
113 1.1 cherry */
114 1.1 cherry #define EXPORT(_name_) \
115 1.1 cherry .global _name_; \
116 1.1 cherry _name_:
117 1.1 cherry
118 1.1 cherry
119 1.1 cherry /*
120 1.1 cherry * IMPORT
121 1.1 cherry * Make an external name visible, typecheck the size
122 1.1 cherry */
123 1.1 cherry #define IMPORT(_name_, _size_) \
124 1.1 cherry /* .extern _name_,_size_ */
125 1.1 cherry
126 1.1 cherry
127 1.1 cherry /*
128 1.1 cherry * ABS
129 1.1 cherry * Define an absolute symbol
130 1.1 cherry */
131 1.1 cherry #define ABS(_name_, _value_) \
132 1.1 cherry .globl _name_; \
133 1.1 cherry _name_ = _value_
134 1.1 cherry
135 1.1 cherry
136 1.1 cherry /*
137 1.1 cherry * BSS
138 1.1 cherry * Allocate un-initialized space for a global symbol
139 1.1 cherry */
140 1.1 cherry #define BSS(_name_,_numbytes_) \
141 1.1 cherry .comm _name_,_numbytes_
142 1.1 cherry
143 1.1 cherry
144 1.1 cherry /*
145 1.1 cherry * MSG
146 1.1 cherry * Allocate space for a message (a read-only ascii string)
147 1.1 cherry */
148 1.1 cherry #define ASCIZ .asciz
149 1.1 cherry #define MSG(msg,reg,label) \
150 1.1 cherry addl reg,@ltoff(label),gp;; \
151 1.1 cherry ld8 reg=[reg];; \
152 1.1 cherry .data; \
153 1.1 cherry label: ASCIZ msg; \
154 1.1 cherry .text;
155 1.1 cherry
156 1.1 cherry
157 1.1 cherry /*
158 1.1 cherry * System call glue.
159 1.1 cherry */
160 1.1 cherry #define SYSCALLNUM(name) SYS_ ## name
161 1.1 cherry
162 1.1 cherry #define CALLSYS_NOERROR(name) \
163 1.1 cherry { .mmi ; \
164 1.1 cherry alloc r9 = ar.pfs, 0, 0, 8, 0 ; \
165 1.1 cherry mov r31 = ar.k5 ; \
166 1.1 cherry mov r10 = b0 ;; } \
167 1.1 cherry { .mib ; \
168 1.1 cherry mov r8 = SYSCALLNUM(name) ; \
169 1.1 cherry mov b7 = r31 ; \
170 1.1 cherry br.call.sptk b0 = b7 ;; }
171 1.1 cherry
172 1.1 cherry
173 1.1 cherry /*
174 1.1 cherry * WEAK_ALIAS: create a weak alias (ELF only).
175 1.1 cherry */
176 1.1 cherry #define WEAK_ALIAS(alias,sym) \
177 1.1 cherry .weak alias; \
178 1.1 cherry alias = sym
179 1.1 cherry
180