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