asm.h revision 1.34 1 /* $NetBSD: asm.h,v 1.34 2003/06/27 08:22:05 simonb 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/cdefs.h> /* for API selection */
62 #include <mips/regdef.h>
63
64 /*
65 * Define -pg profile entry code.
66 * Must always be noreorder, must never use a macro instruction
67 * Final addiu to t9 must always equal the size of this _KERN_MCOUNT
68 */
69 #define _KERN_MCOUNT \
70 .set push; \
71 .set noreorder; \
72 .set noat; \
73 subu sp,sp,16; \
74 sw t9,12(sp); \
75 move AT,ra; \
76 lui t9,%hi(_mcount); \
77 addiu t9,t9,%lo(_mcount); \
78 jalr t9; \
79 nop; \
80 lw t9,4(sp); \
81 addiu sp,sp,8; \
82 addiu t9,t9,40; \
83 .set pop;
84
85 #ifdef GPROF
86 #define MCOUNT _KERN_MCOUNT
87 #else
88 #define MCOUNT
89 #endif
90
91 #ifdef __NO_LEADING_UNDERSCORES__
92 # define _C_LABEL(x) x
93 #else
94 # ifdef __STDC__
95 # define _C_LABEL(x) _ ## x
96 # else
97 # define _C_LABEL(x) _/**/x
98 # endif
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 * WEAK_ALIAS: create a weak alias.
110 */
111 #define WEAK_ALIAS(alias,sym) \
112 .weak alias; \
113 alias = sym
114
115 /*
116 * WARN_REFERENCES: create a warning if the specified symbol is referenced.
117 */
118 #ifdef __STDC__
119 #define WARN_REFERENCES(_sym,_msg) \
120 .section .gnu.warning. ## _sym ; .ascii _msg ; .text
121 #else
122 #define WARN_REFERENCES(_sym,_msg) \
123 .section .gnu.warning./**/_sym ; .ascii _msg ; .text
124 #endif /* __STDC__ */
125
126 /*
127 * LEAF
128 * A leaf routine does
129 * - call no other function,
130 * - never use any register that callee-saved (S0-S8), and
131 * - not use any local stack storage.
132 */
133 #define LEAF(x) \
134 .globl _C_LABEL(x); \
135 .ent _C_LABEL(x), 0; \
136 _C_LABEL(x): ; \
137 .frame sp, 0, ra; \
138 MCOUNT
139
140 /*
141 * LEAF_NOPROFILE
142 * No profilable leaf routine.
143 */
144 #define LEAF_NOPROFILE(x) \
145 .globl _C_LABEL(x); \
146 .ent _C_LABEL(x), 0; \
147 _C_LABEL(x): ; \
148 .frame sp, 0, ra
149
150 /*
151 * STATIC_LEAF
152 * Declare a local leaf function.
153 */
154 #define STATIC_LEAF(x) \
155 .ent _C_LABEL(x), 0; \
156 _C_LABEL(x): ; \
157 .frame sp, 0, ra; \
158 MCOUNT
159
160 /*
161 * XLEAF
162 * declare alternate entry to leaf routine
163 */
164 #define XLEAF(x) \
165 .globl _C_LABEL(x); \
166 AENT (_C_LABEL(x)); \
167 _C_LABEL(x):
168
169 /*
170 * STATIC_XLEAF
171 * declare alternate entry to a static leaf routine
172 */
173 #define STATIC_XLEAF(x) \
174 AENT (_C_LABEL(x)); \
175 _C_LABEL(x):
176
177 /*
178 * NESTED
179 * A function calls other functions and needs
180 * therefore stack space to save/restore registers.
181 */
182 #define NESTED(x, fsize, retpc) \
183 .globl _C_LABEL(x); \
184 .ent _C_LABEL(x), 0; \
185 _C_LABEL(x): ; \
186 .frame sp, fsize, retpc; \
187 MCOUNT
188
189 /*
190 * NESTED_NOPROFILE(x)
191 * No profilable nested routine.
192 */
193 #define NESTED_NOPROFILE(x, fsize, retpc) \
194 .globl _C_LABEL(x); \
195 .ent _C_LABEL(x), 0; \
196 _C_LABEL(x): ; \
197 .frame sp, fsize, retpc
198
199 /*
200 * XNESTED
201 * declare alternate entry point to nested routine.
202 */
203 #define XNESTED(x) \
204 .globl _C_LABEL(x); \
205 AENT (_C_LABEL(x)); \
206 _C_LABEL(x):
207
208 /*
209 * END
210 * Mark end of a procedure.
211 */
212 #define END(x) \
213 .end _C_LABEL(x)
214
215 /*
216 * IMPORT -- import external symbol
217 */
218 #define IMPORT(sym, size) \
219 .extern _C_LABEL(sym),size
220
221 /*
222 * EXPORT -- export definition of symbol
223 */
224 #define EXPORT(x) \
225 .globl _C_LABEL(x); \
226 _C_LABEL(x):
227
228 /*
229 * VECTOR
230 * exception vector entrypoint
231 * XXX: regmask should be used to generate .mask
232 */
233 #define VECTOR(x, regmask) \
234 .ent _C_LABEL(x),0; \
235 EXPORT(x); \
236
237 #ifdef __STDC__
238 #define VECTOR_END(x) \
239 EXPORT(x ## End); \
240 END(x)
241 #else
242 #define VECTOR_END(x) \
243 EXPORT(x/**/End); \
244 END(x)
245 #endif
246
247 /*
248 * Macros to panic and printf from assembly language.
249 */
250 #define PANIC(msg) \
251 la a0, 9f; \
252 jal _C_LABEL(panic); \
253 nop; \
254 MSG(msg)
255
256 #define PRINTF(msg) \
257 la a0, 9f; \
258 jal _C_LABEL(printf); \
259 nop; \
260 MSG(msg)
261
262 #define MSG(msg) \
263 .rdata; \
264 9: .asciiz msg; \
265 .text
266
267 #define ASMSTR(str) \
268 .asciiz str; \
269 .align 3
270
271 /*
272 * XXX retain dialects XXX
273 */
274 #define ALEAF(x) XLEAF(x)
275 #define NLEAF(x) LEAF_NOPROFILE(x)
276 #define NON_LEAF(x, fsize, retpc) NESTED(x, fsize, retpc)
277 #define NNON_LEAF(x, fsize, retpc) NESTED_NOPROFILE(x, fsize, retpc)
278
279 /*
280 * standard callframe {
281 * register_t cf_args[4]; arg0 - arg3
282 * register_t cf_sp; frame pointer
283 * register_t cf_ra; return address
284 * };
285 */
286 #define CALLFRAME_SIZ (4 * (4 + 2))
287 #define CALLFRAME_SP (4 * 4)
288 #define CALLFRAME_RA (4 * 5)
289
290 /*
291 * While it would be nice to be compatible with the SGI
292 * REG_L and REG_S macros, because they do not take parameters, it
293 * is impossible to use them with the _MIPS_SIM_ABIX32 model.
294 *
295 * These macros hide the use of mips3 instructions from the
296 * assembler to prevent the assembler from generating 64-bit style
297 * ABI calls.
298 */
299
300 #if !defined(_MIPS_BSD_API) || _MIPS_BSD_API == _MIPS_BSD_API_LP32
301 #define REG_L lw
302 #define REG_S sw
303 #define REG_LI li
304 #define REG_PROLOGUE .set push
305 #define REG_EPILOGUE .set pop
306 #define SZREG 4
307 #else
308 #define REG_L ld
309 #define REG_S sd
310 #define REG_LI dli
311 #define REG_PROLOGUE .set push ; .set mips3
312 #define REG_EPILOGUE .set pop
313 #define SZREG 8
314 #endif /* _MIPS_BSD_API */
315
316 /*
317 * The DYNAMIC_STATUS_MASK option adds an additional masking operation
318 * when updating the hardware interrupt mask in the status register.
319 *
320 * This is useful for platforms that need to at run-time mask
321 * interrupts based on motherboard configuration or to handle
322 * slowly clearing interrupts.
323 *
324 * XXX this is only currently implemented for mips3.
325 */
326 #ifdef MIPS_DYNAMIC_STATUS_MASK
327 #define DYNAMIC_STATUS_MASK(sr,scratch) \
328 lw scratch, mips_dynamic_status_mask; \
329 and sr, sr, scratch
330
331 #define DYNAMIC_STATUS_MASK_TOUSER(sr,scratch1) \
332 ori sr, (MIPS_INT_MASK | MIPS_SR_INT_IE); \
333 DYNAMIC_STATUS_MASK(sr,scratch1)
334 #else
335 #define DYNAMIC_STATUS_MASK(sr,scratch)
336 #define DYNAMIC_STATUS_MASK_TOUSER(sr,scratch1)
337 #endif
338
339 #endif /* _MIPS_ASM_H */
340