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