asm.h revision 1.16 1 1.16 castor /* $NetBSD: asm.h,v 1.16 1999/01/31 00:55:41 castor 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.1 deraadt #include <machine/regdef.h>
62 1.1 deraadt
63 1.1 deraadt /*
64 1.1 deraadt * Define -pg profile entry code.
65 1.13 jonathan * XXX assume .set noreorder for kernel, .set reorder for user code.
66 1.1 deraadt */
67 1.15 castor #define _KERN_MCOUNT \
68 1.15 castor .set noat; \
69 1.15 castor move $1,$31; \
70 1.15 castor jal _mcount; \
71 1.15 castor subu sp,sp,8; \
72 1.15 castor .set at
73 1.13 jonathan
74 1.11 jtc #ifdef GPROF
75 1.13 jonathan # if defined(_KERNEL) || defined(_LOCORE)
76 1.13 jonathan # define MCOUNT _KERN_MCOUNT
77 1.13 jonathan # else
78 1.13 jonathan # define MCOUNT .set noreorder; _KERN_MCOUNT ; .set reorder;
79 1.13 jonathan # endif
80 1.1 deraadt #else
81 1.1 deraadt #define MCOUNT
82 1.2 glass #endif
83 1.1 deraadt
84 1.7 mellon #ifdef __NO_LEADING_UNDERSCORES__
85 1.6 mycroft # define _C_LABEL(x) x
86 1.6 mycroft #else
87 1.6 mycroft # ifdef __STDC__
88 1.6 mycroft # define _C_LABEL(x) _ ## x
89 1.6 mycroft # else
90 1.6 mycroft # define _C_LABEL(x) _/**/x
91 1.6 mycroft # endif
92 1.6 mycroft #endif
93 1.14 thorpej
94 1.15 castor #ifdef USE_AENT
95 1.15 castor #define AENT(x) \
96 1.15 castor .aent x, 0
97 1.15 castor #else
98 1.15 castor #define AENT(x)
99 1.15 castor #endif
100 1.15 castor
101 1.14 thorpej /*
102 1.14 thorpej * WARN_REFERENCES: create a warning if the specified symbol is referenced
103 1.14 thorpej * (ELF only, and thus, no leading underscores).
104 1.14 thorpej */
105 1.14 thorpej #ifdef __ELF__
106 1.14 thorpej #ifdef __STDC__
107 1.14 thorpej #define WARN_REFERENCES(_sym,_msg) \
108 1.14 thorpej .section .gnu.warning. ## _sym ; .ascii _msg ; .text
109 1.14 thorpej #else
110 1.14 thorpej #define WARN_REFERENCES(_sym,_msg) \
111 1.14 thorpej .section .gnu.warning./**/_sym ; .ascii _msg ; .text
112 1.14 thorpej #endif /* __STDC__ */
113 1.14 thorpej #endif /* __ELF__ */
114 1.6 mycroft
115 1.1 deraadt /*
116 1.15 castor * LEAF
117 1.15 castor * A leaf routine does
118 1.15 castor * - call no other function,
119 1.15 castor * - never use any register that callee-saved (S0-S8), and
120 1.15 castor * - not use any local stack storage.
121 1.15 castor */
122 1.15 castor #define LEAF(x) \
123 1.15 castor .globl _C_LABEL(x); \
124 1.15 castor .ent _C_LABEL(x), 0; \
125 1.15 castor _C_LABEL(x): ; \
126 1.15 castor .frame sp, 0, ra; \
127 1.1 deraadt MCOUNT
128 1.1 deraadt
129 1.1 deraadt /*
130 1.15 castor * LEAF_NOPROFILE
131 1.15 castor * No profilable leaf routine.
132 1.1 deraadt */
133 1.15 castor #define LEAF_NOPROFILE(x) \
134 1.15 castor .globl _C_LABEL(x); \
135 1.15 castor .ent _C_LABEL(x), 0; \
136 1.15 castor _C_LABEL(x): ; \
137 1.15 castor .frame sp, 0, ra
138 1.15 castor
139 1.15 castor /*
140 1.15 castor * XLEAF
141 1.15 castor * declare alternate entry to leaf routine
142 1.15 castor */
143 1.15 castor #define XLEAF(x) \
144 1.15 castor .globl _C_LABEL(x); \
145 1.15 castor .aent _C_LABEL(x),0; \
146 1.15 castor _C_LABEL(x):
147 1.15 castor
148 1.15 castor /*
149 1.15 castor * NESTED
150 1.15 castor * A function calls other functions and needs
151 1.15 castor * therefore stack space to save/restore registers.
152 1.15 castor */
153 1.15 castor #define NESTED(x, fsize, retpc) \
154 1.15 castor .globl _C_LABEL(x); \
155 1.15 castor .ent _C_LABEL(x), 0; \
156 1.15 castor _C_LABEL(x): ; \
157 1.15 castor .frame sp, fsize, retpc; \
158 1.15 castor MCOUNT
159 1.1 deraadt
160 1.1 deraadt /*
161 1.15 castor * NESTED_NOPROFILE(x)
162 1.15 castor * No profilable nested routine.
163 1.1 deraadt */
164 1.15 castor #define NESTED_NOPROFILE(x, fsize, retpc) \
165 1.15 castor .globl _C_LABEL(x); \
166 1.15 castor .ent _C_LABEL(x), 0; \
167 1.15 castor _C_LABEL(x): ; \
168 1.15 castor .frame sp, fsize, retpc
169 1.15 castor
170 1.15 castor /*
171 1.15 castor * XNESTED
172 1.15 castor * declare alternate entry point to nested routine.
173 1.15 castor */
174 1.15 castor #define XNESTED(x) \
175 1.15 castor .globl _C_LABEL(x); \
176 1.15 castor .aent _C_LABEL(x),0; \
177 1.6 mycroft _C_LABEL(x):
178 1.1 deraadt
179 1.1 deraadt /*
180 1.15 castor * END
181 1.15 castor * Mark end of a procedure.
182 1.1 deraadt */
183 1.15 castor #define END(x) \
184 1.15 castor .end _C_LABEL(x)
185 1.2 glass
186 1.2 glass /*
187 1.15 castor * IMPORT -- import external symbol
188 1.2 glass */
189 1.15 castor #define IMPORT(sym, size) \
190 1.15 castor .extern sym,size
191 1.1 deraadt
192 1.1 deraadt /*
193 1.15 castor * EXPORT -- export definition of symbol
194 1.1 deraadt */
195 1.15 castor #define EXPORT(x) \
196 1.15 castor .globl _C_LABEL(x); \
197 1.15 castor _C_LABEL(x):
198 1.1 deraadt
199 1.15 castor /*
200 1.15 castor * ALIAS
201 1.15 castor * Global alias for a function, or alternate entry point
202 1.15 castor */
203 1.15 castor #define ALIAS(x) \
204 1.15 castor .globl _C_LABEL(x); \
205 1.15 castor _C_LABEL(x):
206 1.1 deraadt
207 1.1 deraadt /*
208 1.10 christos * Macros to panic and printf from assembly language.
209 1.1 deraadt */
210 1.15 castor #define PANIC(msg) \
211 1.15 castor la a0, 9f; \
212 1.15 castor jal _C_LABEL(panic); \
213 1.1 deraadt MSG(msg)
214 1.1 deraadt
215 1.15 castor #define PRINTF(msg) \
216 1.15 castor la a0, 9f; \
217 1.15 castor jal _C_LABEL(printf); \
218 1.1 deraadt MSG(msg)
219 1.1 deraadt
220 1.15 castor #define MSG(msg) \
221 1.15 castor .rdata; \
222 1.15 castor 9: .asciiz msg; \
223 1.1 deraadt .text
224 1.1 deraadt
225 1.15 castor #define ASMSTR(str) \
226 1.15 castor .asciiz str; \
227 1.12 jonathan .align 3
228 1.15 castor
229 1.15 castor /*
230 1.15 castor * XXX retain dialects XXX
231 1.15 castor */
232 1.15 castor #define ALEAF(x) \
233 1.15 castor .globl _C_LABEL(x); \
234 1.15 castor AENT (_C_LABEL(x)) \
235 1.15 castor _C_LABEL(x):
236 1.15 castor
237 1.15 castor #define NLEAF(x) \
238 1.15 castor .globl _C_LABEL(x); \
239 1.15 castor .ent _C_LABEL(x), 0; \
240 1.15 castor _C_LABEL(x): ; \
241 1.15 castor .frame sp, 0, ra
242 1.15 castor
243 1.15 castor #define NON_LEAF(x, fsize, retpc) \
244 1.15 castor .globl _C_LABEL(x); \
245 1.15 castor .ent _C_LABEL(x), 0; \
246 1.15 castor _C_LABEL(x): ; \
247 1.15 castor .frame sp, fsize, retpc; \
248 1.15 castor MCOUNT
249 1.15 castor
250 1.15 castor #define NNON_LEAF(x, fsize, retpc) \
251 1.15 castor .globl _C_LABEL(x); \
252 1.15 castor .ent _C_LABEL(x), 0; \
253 1.15 castor _C_LABEL(x): ; \
254 1.15 castor .frame sp, fsize, retpc
255 1.15 castor
256 1.16 castor /*
257 1.16 castor * standard callframe {
258 1.16 castor * register_t cf_args[4]; arg0 - arg3
259 1.16 castor * register_t cf_sp; frame pointer
260 1.16 castor * register_t cf_ra; return address
261 1.16 castor * };
262 1.16 castor */
263 1.16 castor #define CALLFRAME_SIZ (4 * (4 + 2))
264 1.16 castor #define CALLFRAME_SP (4 * 4)
265 1.16 castor #define CALLFRAME_RA (4 * 5)
266 1.16 castor
267 1.15 castor /*
268 1.15 castor * While it would be nice to be compatible with the SGI
269 1.15 castor * REG_L and REG_S macros, because they do not take parameters, it
270 1.15 castor * is impossible to use them with the _MIPS_SIM_ABIX32 model.
271 1.15 castor *
272 1.15 castor * These macros hide the use of mips3 instructions from the
273 1.15 castor * assembler to prevent the assembler from generating 64-bit style
274 1.15 castor * ABI calls.
275 1.15 castor */
276 1.15 castor
277 1.16 castor #if !defined(_MIPS_BSD_API) || _MIPS_BSD_API == _MIPS_BSD_API_LP32
278 1.16 castor #define REG_L lw
279 1.16 castor #define REG_S sw
280 1.16 castor #define REG_LI li
281 1.16 castor #define REG_PROLOGUE .set push
282 1.16 castor #define REG_EPILOGUE .set pop
283 1.16 castor #define SZREG 4
284 1.16 castor #else
285 1.15 castor #define REG_L ld
286 1.15 castor #define REG_S sd
287 1.15 castor #define REG_LI dli
288 1.15 castor #define REG_PROLOGUE .set push ; .set mips3
289 1.15 castor #define REG_EPILOGUE .set pop
290 1.15 castor #define SZREG 8
291 1.16 castor #endif /* _MIPS_BSD_API */
292 1.1 deraadt
293 1.8 jonathan #endif /* _MIPS_ASM_H */
294