asm.h revision 1.17 1 /* $NetBSD: asm.h,v 1.17 1999/02/16 05:06:26 jonathan Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Ralph Campbell.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)machAsmDefs.h 8.1 (Berkeley) 6/10/93
39 */
40
41 /*
42 * machAsmDefs.h --
43 *
44 * Macros used when writing assembler programs.
45 *
46 * Copyright (C) 1989 Digital Equipment Corporation.
47 * Permission to use, copy, modify, and distribute this software and
48 * its documentation for any purpose and without fee is hereby granted,
49 * provided that the above copyright notice appears in all copies.
50 * Digital Equipment Corporation makes no representations about the
51 * suitability of this software for any purpose. It is provided "as is"
52 * without express or implied warranty.
53 *
54 * from: Header: /sprite/src/kernel/mach/ds3100.md/RCS/machAsmDefs.h,
55 * v 1.2 89/08/15 18:28:24 rab Exp SPRITE (DECWRL)
56 */
57
58 #ifndef _MIPS_ASM_H
59 #define _MIPS_ASM_H
60
61 #include <machine/regdef.h>
62
63 /*
64 * Define -pg profile entry code.
65 * XXX assume .set noreorder for kernel, .set reorder for user code.
66 */
67 #define _KERN_MCOUNT \
68 .set noat; \
69 move $1,$31; \
70 jal _mcount; \
71 subu sp,sp,8; \
72 .set at
73
74 #ifdef GPROF
75 # if defined(_KERNEL) || defined(_LOCORE)
76 # define MCOUNT _KERN_MCOUNT
77 # else
78 # define MCOUNT .set noreorder; _KERN_MCOUNT ; .set reorder;
79 # endif
80 #else
81 #define MCOUNT
82 #endif
83
84 #ifdef __NO_LEADING_UNDERSCORES__
85 # define _C_LABEL(x) x
86 #else
87 # ifdef __STDC__
88 # define _C_LABEL(x) _ ## x
89 # else
90 # define _C_LABEL(x) _/**/x
91 # define _END_LABEL(x) x/**/End
92 # endif
93 #endif
94
95 #ifdef __STDC__
96 # define _END_LABEL(x) x ## End
97 #else
98 # define _END_LABEL(x) x/**/End
99 #endif
100
101 #ifdef USE_AENT
102 #define AENT(x) \
103 .aent x, 0
104 #else
105 #define AENT(x)
106 #endif
107
108 /*
109 * WARN_REFERENCES: create a warning if the specified symbol is referenced
110 * (ELF only, and thus, no leading underscores).
111 */
112 #ifdef __ELF__
113 #ifdef __STDC__
114 #define WARN_REFERENCES(_sym,_msg) \
115 .section .gnu.warning. ## _sym ; .ascii _msg ; .text
116 #else
117 #define WARN_REFERENCES(_sym,_msg) \
118 .section .gnu.warning./**/_sym ; .ascii _msg ; .text
119 #endif /* __STDC__ */
120 #endif /* __ELF__ */
121
122 /*
123 * LEAF
124 * A leaf routine does
125 * - call no other function,
126 * - never use any register that callee-saved (S0-S8), and
127 * - not use any local stack storage.
128 */
129 #define LEAF(x) \
130 .globl _C_LABEL(x); \
131 .ent _C_LABEL(x), 0; \
132 _C_LABEL(x): ; \
133 .frame sp, 0, ra; \
134 MCOUNT
135
136 /*
137 * LEAF_NOPROFILE
138 * No profilable leaf routine.
139 */
140 #define LEAF_NOPROFILE(x) \
141 .globl _C_LABEL(x); \
142 .ent _C_LABEL(x), 0; \
143 _C_LABEL(x): ; \
144 .frame sp, 0, ra
145
146 /*
147 * XLEAF
148 * declare alternate entry to leaf routine
149 */
150 #define XLEAF(x) \
151 .globl _C_LABEL(x); \
152 .aent _C_LABEL(x),0; \
153 _C_LABEL(x):
154
155 /*
156 * NESTED
157 * A function calls other functions and needs
158 * therefore stack space to save/restore registers.
159 */
160 #define NESTED(x, fsize, retpc) \
161 .globl _C_LABEL(x); \
162 .ent _C_LABEL(x), 0; \
163 _C_LABEL(x): ; \
164 .frame sp, fsize, retpc; \
165 MCOUNT
166
167 /*
168 * NESTED_NOPROFILE(x)
169 * No profilable nested routine.
170 */
171 #define NESTED_NOPROFILE(x, fsize, retpc) \
172 .globl _C_LABEL(x); \
173 .ent _C_LABEL(x), 0; \
174 _C_LABEL(x): ; \
175 .frame sp, fsize, retpc
176
177 /*
178 * XNESTED
179 * declare alternate entry point to nested routine.
180 */
181 #define XNESTED(x) \
182 .globl _C_LABEL(x); \
183 .aent _C_LABEL(x),0; \
184 _C_LABEL(x):
185
186 /*
187 * END
188 * Mark end of a procedure.
189 */
190 #define END(x) \
191 .end _C_LABEL(x)
192
193 /*
194 * IMPORT -- import external symbol
195 */
196 #define IMPORT(sym, size) \
197 .extern sym,size
198
199 /*
200 * EXPORT -- export definition of symbol
201 */
202 #define EXPORT(x) \
203 .globl _C_LABEL(x); \
204 _C_LABEL(x):
205
206 /*
207 * ALIAS
208 * Global alias for a function, or alternate entry point
209 */
210 #define ALIAS(x) \
211 .globl _C_LABEL(x); \
212 _C_LABEL(x):
213
214 /*
215 * VECTOR
216 * exception vector entrypoint
217 */
218 #define VECTOR(x, regmask) \
219 .ent _C_LABEL(x),0; \
220 EXPORT(x); \
221
222 #define VECTOR_END(x) \
223 .end _C_LABEL(x); \
224 EXPORT(_END_LABEL(x))
225
226 /*
227 * Macros to panic and printf from assembly language.
228 */
229 #define PANIC(msg) \
230 la a0, 9f; \
231 jal _C_LABEL(panic); \
232 MSG(msg)
233
234 #define PRINTF(msg) \
235 la a0, 9f; \
236 jal _C_LABEL(printf); \
237 MSG(msg)
238
239 #define MSG(msg) \
240 .rdata; \
241 9: .asciiz msg; \
242 .text
243
244 #define ASMSTR(str) \
245 .asciiz str; \
246 .align 3
247
248 /*
249 * XXX retain dialects XXX
250 */
251 #define ALEAF(x) \
252 .globl _C_LABEL(x); \
253 AENT (_C_LABEL(x)) \
254 _C_LABEL(x):
255
256 #define NLEAF(x) \
257 .globl _C_LABEL(x); \
258 .ent _C_LABEL(x), 0; \
259 _C_LABEL(x): ; \
260 .frame sp, 0, ra
261
262 #define NON_LEAF(x, fsize, retpc) \
263 .globl _C_LABEL(x); \
264 .ent _C_LABEL(x), 0; \
265 _C_LABEL(x): ; \
266 .frame sp, fsize, retpc; \
267 MCOUNT
268
269 #define NNON_LEAF(x, fsize, retpc) \
270 .globl _C_LABEL(x); \
271 .ent _C_LABEL(x), 0; \
272 _C_LABEL(x): ; \
273 .frame sp, fsize, retpc
274
275 /*
276 * standard callframe {
277 * register_t cf_args[4]; arg0 - arg3
278 * register_t cf_sp; frame pointer
279 * register_t cf_ra; return address
280 * };
281 */
282 #define CALLFRAME_SIZ (4 * (4 + 2))
283 #define CALLFRAME_SP (4 * 4)
284 #define CALLFRAME_RA (4 * 5)
285
286 /*
287 * While it would be nice to be compatible with the SGI
288 * REG_L and REG_S macros, because they do not take parameters, it
289 * is impossible to use them with the _MIPS_SIM_ABIX32 model.
290 *
291 * These macros hide the use of mips3 instructions from the
292 * assembler to prevent the assembler from generating 64-bit style
293 * ABI calls.
294 */
295
296 #if !defined(_MIPS_BSD_API) || _MIPS_BSD_API == _MIPS_BSD_API_LP32
297 #define REG_L lw
298 #define REG_S sw
299 #define REG_LI li
300 #define REG_PROLOGUE .set push
301 #define REG_EPILOGUE .set pop
302 #define SZREG 4
303 #else
304 #define REG_L ld
305 #define REG_S sd
306 #define REG_LI dli
307 #define REG_PROLOGUE .set push ; .set mips3
308 #define REG_EPILOGUE .set pop
309 #define SZREG 8
310 #endif /* _MIPS_BSD_API */
311
312 #endif /* _MIPS_ASM_H */
313