asm.h revision 1.18 1 1.18 drochner /* $NetBSD: asm.h,v 1.18 1999/02/24 18:36:32 drochner 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.18 drochner /*
62 1.18 drochner * Symbolic register names
63 1.18 drochner */
64 1.18 drochner #define zero $0 /* always zero */
65 1.18 drochner #define AT $at /* assembler temporary */
66 1.18 drochner #define v0 $2 /* return value */
67 1.18 drochner #define v1 $3
68 1.18 drochner #define a0 $4 /* argument registers */
69 1.18 drochner #define a1 $5
70 1.18 drochner #define a2 $6
71 1.18 drochner #define a3 $7
72 1.18 drochner #define t0 $8 /* temp registers (not saved across subroutine calls) */
73 1.18 drochner #define t1 $9
74 1.18 drochner #define t2 $10
75 1.18 drochner #define t3 $11
76 1.18 drochner #define t4 $12
77 1.18 drochner #define t5 $13
78 1.18 drochner #define t6 $14
79 1.18 drochner #define t7 $15
80 1.18 drochner #define s0 $16 /* saved across subroutine calls (callee saved) */
81 1.18 drochner #define s1 $17
82 1.18 drochner #define s2 $18
83 1.18 drochner #define s3 $19
84 1.18 drochner #define s4 $20
85 1.18 drochner #define s5 $21
86 1.18 drochner #define s6 $22
87 1.18 drochner #define s7 $23
88 1.18 drochner #define t8 $24 /* two more temporary registers */
89 1.18 drochner #define t9 $25
90 1.18 drochner #define k0 $26 /* kernel temporary */
91 1.18 drochner #define k1 $27
92 1.18 drochner #define gp $28 /* global pointer */
93 1.18 drochner #define sp $29 /* stack pointer */
94 1.18 drochner #define s8 $30 /* one more callee saved */
95 1.18 drochner #define ra $31 /* return address */
96 1.1 deraadt
97 1.1 deraadt /*
98 1.1 deraadt * Define -pg profile entry code.
99 1.13 jonathan * XXX assume .set noreorder for kernel, .set reorder for user code.
100 1.1 deraadt */
101 1.15 castor #define _KERN_MCOUNT \
102 1.15 castor .set noat; \
103 1.15 castor move $1,$31; \
104 1.15 castor jal _mcount; \
105 1.15 castor subu sp,sp,8; \
106 1.15 castor .set at
107 1.13 jonathan
108 1.11 jtc #ifdef GPROF
109 1.13 jonathan # if defined(_KERNEL) || defined(_LOCORE)
110 1.13 jonathan # define MCOUNT _KERN_MCOUNT
111 1.13 jonathan # else
112 1.13 jonathan # define MCOUNT .set noreorder; _KERN_MCOUNT ; .set reorder;
113 1.13 jonathan # endif
114 1.1 deraadt #else
115 1.1 deraadt #define MCOUNT
116 1.2 glass #endif
117 1.1 deraadt
118 1.7 mellon #ifdef __NO_LEADING_UNDERSCORES__
119 1.6 mycroft # define _C_LABEL(x) x
120 1.6 mycroft #else
121 1.6 mycroft # ifdef __STDC__
122 1.6 mycroft # define _C_LABEL(x) _ ## x
123 1.6 mycroft # else
124 1.6 mycroft # define _C_LABEL(x) _/**/x
125 1.17 jonathan # define _END_LABEL(x) x/**/End
126 1.6 mycroft # endif
127 1.6 mycroft #endif
128 1.14 thorpej
129 1.17 jonathan #ifdef __STDC__
130 1.17 jonathan # define _END_LABEL(x) x ## End
131 1.17 jonathan #else
132 1.17 jonathan # define _END_LABEL(x) x/**/End
133 1.17 jonathan #endif
134 1.17 jonathan
135 1.15 castor #ifdef USE_AENT
136 1.15 castor #define AENT(x) \
137 1.15 castor .aent x, 0
138 1.15 castor #else
139 1.15 castor #define AENT(x)
140 1.15 castor #endif
141 1.15 castor
142 1.14 thorpej /*
143 1.14 thorpej * WARN_REFERENCES: create a warning if the specified symbol is referenced
144 1.14 thorpej * (ELF only, and thus, no leading underscores).
145 1.14 thorpej */
146 1.14 thorpej #ifdef __ELF__
147 1.14 thorpej #ifdef __STDC__
148 1.14 thorpej #define WARN_REFERENCES(_sym,_msg) \
149 1.14 thorpej .section .gnu.warning. ## _sym ; .ascii _msg ; .text
150 1.14 thorpej #else
151 1.14 thorpej #define WARN_REFERENCES(_sym,_msg) \
152 1.14 thorpej .section .gnu.warning./**/_sym ; .ascii _msg ; .text
153 1.14 thorpej #endif /* __STDC__ */
154 1.14 thorpej #endif /* __ELF__ */
155 1.6 mycroft
156 1.1 deraadt /*
157 1.15 castor * LEAF
158 1.15 castor * A leaf routine does
159 1.15 castor * - call no other function,
160 1.15 castor * - never use any register that callee-saved (S0-S8), and
161 1.15 castor * - not use any local stack storage.
162 1.15 castor */
163 1.15 castor #define LEAF(x) \
164 1.15 castor .globl _C_LABEL(x); \
165 1.15 castor .ent _C_LABEL(x), 0; \
166 1.15 castor _C_LABEL(x): ; \
167 1.15 castor .frame sp, 0, ra; \
168 1.1 deraadt MCOUNT
169 1.1 deraadt
170 1.1 deraadt /*
171 1.15 castor * LEAF_NOPROFILE
172 1.15 castor * No profilable leaf routine.
173 1.1 deraadt */
174 1.15 castor #define LEAF_NOPROFILE(x) \
175 1.15 castor .globl _C_LABEL(x); \
176 1.15 castor .ent _C_LABEL(x), 0; \
177 1.15 castor _C_LABEL(x): ; \
178 1.15 castor .frame sp, 0, ra
179 1.15 castor
180 1.15 castor /*
181 1.15 castor * XLEAF
182 1.15 castor * declare alternate entry to leaf routine
183 1.15 castor */
184 1.15 castor #define XLEAF(x) \
185 1.15 castor .globl _C_LABEL(x); \
186 1.15 castor .aent _C_LABEL(x),0; \
187 1.15 castor _C_LABEL(x):
188 1.15 castor
189 1.15 castor /*
190 1.15 castor * NESTED
191 1.15 castor * A function calls other functions and needs
192 1.15 castor * therefore stack space to save/restore registers.
193 1.15 castor */
194 1.15 castor #define NESTED(x, fsize, retpc) \
195 1.15 castor .globl _C_LABEL(x); \
196 1.15 castor .ent _C_LABEL(x), 0; \
197 1.15 castor _C_LABEL(x): ; \
198 1.15 castor .frame sp, fsize, retpc; \
199 1.15 castor MCOUNT
200 1.1 deraadt
201 1.1 deraadt /*
202 1.15 castor * NESTED_NOPROFILE(x)
203 1.15 castor * No profilable nested routine.
204 1.1 deraadt */
205 1.15 castor #define NESTED_NOPROFILE(x, fsize, retpc) \
206 1.15 castor .globl _C_LABEL(x); \
207 1.15 castor .ent _C_LABEL(x), 0; \
208 1.15 castor _C_LABEL(x): ; \
209 1.15 castor .frame sp, fsize, retpc
210 1.15 castor
211 1.15 castor /*
212 1.15 castor * XNESTED
213 1.15 castor * declare alternate entry point to nested routine.
214 1.15 castor */
215 1.15 castor #define XNESTED(x) \
216 1.15 castor .globl _C_LABEL(x); \
217 1.15 castor .aent _C_LABEL(x),0; \
218 1.6 mycroft _C_LABEL(x):
219 1.1 deraadt
220 1.1 deraadt /*
221 1.15 castor * END
222 1.15 castor * Mark end of a procedure.
223 1.1 deraadt */
224 1.15 castor #define END(x) \
225 1.15 castor .end _C_LABEL(x)
226 1.2 glass
227 1.2 glass /*
228 1.15 castor * IMPORT -- import external symbol
229 1.2 glass */
230 1.15 castor #define IMPORT(sym, size) \
231 1.15 castor .extern sym,size
232 1.1 deraadt
233 1.1 deraadt /*
234 1.15 castor * EXPORT -- export definition of symbol
235 1.1 deraadt */
236 1.15 castor #define EXPORT(x) \
237 1.15 castor .globl _C_LABEL(x); \
238 1.15 castor _C_LABEL(x):
239 1.1 deraadt
240 1.15 castor /*
241 1.15 castor * ALIAS
242 1.15 castor * Global alias for a function, or alternate entry point
243 1.15 castor */
244 1.15 castor #define ALIAS(x) \
245 1.15 castor .globl _C_LABEL(x); \
246 1.15 castor _C_LABEL(x):
247 1.17 jonathan
248 1.17 jonathan /*
249 1.17 jonathan * VECTOR
250 1.17 jonathan * exception vector entrypoint
251 1.17 jonathan */
252 1.17 jonathan #define VECTOR(x, regmask) \
253 1.17 jonathan .ent _C_LABEL(x),0; \
254 1.17 jonathan EXPORT(x); \
255 1.17 jonathan
256 1.17 jonathan #define VECTOR_END(x) \
257 1.17 jonathan .end _C_LABEL(x); \
258 1.17 jonathan EXPORT(_END_LABEL(x))
259 1.1 deraadt
260 1.1 deraadt /*
261 1.10 christos * Macros to panic and printf from assembly language.
262 1.1 deraadt */
263 1.15 castor #define PANIC(msg) \
264 1.15 castor la a0, 9f; \
265 1.15 castor jal _C_LABEL(panic); \
266 1.1 deraadt MSG(msg)
267 1.1 deraadt
268 1.15 castor #define PRINTF(msg) \
269 1.15 castor la a0, 9f; \
270 1.15 castor jal _C_LABEL(printf); \
271 1.1 deraadt MSG(msg)
272 1.1 deraadt
273 1.15 castor #define MSG(msg) \
274 1.15 castor .rdata; \
275 1.15 castor 9: .asciiz msg; \
276 1.1 deraadt .text
277 1.1 deraadt
278 1.15 castor #define ASMSTR(str) \
279 1.15 castor .asciiz str; \
280 1.12 jonathan .align 3
281 1.15 castor
282 1.15 castor /*
283 1.15 castor * XXX retain dialects XXX
284 1.15 castor */
285 1.15 castor #define ALEAF(x) \
286 1.15 castor .globl _C_LABEL(x); \
287 1.15 castor AENT (_C_LABEL(x)) \
288 1.15 castor _C_LABEL(x):
289 1.15 castor
290 1.15 castor #define NLEAF(x) \
291 1.15 castor .globl _C_LABEL(x); \
292 1.15 castor .ent _C_LABEL(x), 0; \
293 1.15 castor _C_LABEL(x): ; \
294 1.15 castor .frame sp, 0, ra
295 1.15 castor
296 1.15 castor #define NON_LEAF(x, fsize, retpc) \
297 1.15 castor .globl _C_LABEL(x); \
298 1.15 castor .ent _C_LABEL(x), 0; \
299 1.15 castor _C_LABEL(x): ; \
300 1.15 castor .frame sp, fsize, retpc; \
301 1.15 castor MCOUNT
302 1.15 castor
303 1.15 castor #define NNON_LEAF(x, fsize, retpc) \
304 1.15 castor .globl _C_LABEL(x); \
305 1.15 castor .ent _C_LABEL(x), 0; \
306 1.15 castor _C_LABEL(x): ; \
307 1.15 castor .frame sp, fsize, retpc
308 1.15 castor
309 1.16 castor /*
310 1.16 castor * standard callframe {
311 1.16 castor * register_t cf_args[4]; arg0 - arg3
312 1.16 castor * register_t cf_sp; frame pointer
313 1.16 castor * register_t cf_ra; return address
314 1.16 castor * };
315 1.16 castor */
316 1.16 castor #define CALLFRAME_SIZ (4 * (4 + 2))
317 1.16 castor #define CALLFRAME_SP (4 * 4)
318 1.16 castor #define CALLFRAME_RA (4 * 5)
319 1.16 castor
320 1.15 castor /*
321 1.15 castor * While it would be nice to be compatible with the SGI
322 1.15 castor * REG_L and REG_S macros, because they do not take parameters, it
323 1.15 castor * is impossible to use them with the _MIPS_SIM_ABIX32 model.
324 1.15 castor *
325 1.15 castor * These macros hide the use of mips3 instructions from the
326 1.15 castor * assembler to prevent the assembler from generating 64-bit style
327 1.15 castor * ABI calls.
328 1.15 castor */
329 1.15 castor
330 1.16 castor #if !defined(_MIPS_BSD_API) || _MIPS_BSD_API == _MIPS_BSD_API_LP32
331 1.16 castor #define REG_L lw
332 1.16 castor #define REG_S sw
333 1.16 castor #define REG_LI li
334 1.16 castor #define REG_PROLOGUE .set push
335 1.16 castor #define REG_EPILOGUE .set pop
336 1.16 castor #define SZREG 4
337 1.16 castor #else
338 1.15 castor #define REG_L ld
339 1.15 castor #define REG_S sd
340 1.15 castor #define REG_LI dli
341 1.15 castor #define REG_PROLOGUE .set push ; .set mips3
342 1.15 castor #define REG_EPILOGUE .set pop
343 1.15 castor #define SZREG 8
344 1.16 castor #endif /* _MIPS_BSD_API */
345 1.1 deraadt
346 1.8 jonathan #endif /* _MIPS_ASM_H */
347