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