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