asm.h revision 1.13.10.2 1 /* $NetBSD: asm.h,v 1.13.10.2 1998/10/30 08:33:37 nisimura 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 /*
62 * Symbolic register names
63 */
64 #define zero $0 /* always zero */
65 #define AT $at /* assembler temporary */
66 #define v0 $2 /* return value */
67 #define v1 $3
68 #define a0 $4 /* argument registers */
69 #define a1 $5
70 #define a2 $6
71 #define a3 $7
72 #define t0 $8 /* temp registers (not saved across subroutine calls) */
73 #define t1 $9
74 #define t2 $10
75 #define t3 $11
76 #define t4 $12
77 #define t5 $13
78 #define t6 $14
79 #define t7 $15
80 #define s0 $16 /* saved across subroutine calls (callee saved) */
81 #define s1 $17
82 #define s2 $18
83 #define s3 $19
84 #define s4 $20
85 #define s5 $21
86 #define s6 $22
87 #define s7 $23
88 #define t8 $24 /* two more temporary registers */
89 #define t9 $25
90 #define k0 $26 /* kernel temporary */
91 #define k1 $27
92 #define gp $28 /* global pointer */
93 #define sp $29 /* stack pointer */
94 #define s8 $30 /* one more callee saved */
95 #define ra $31 /* return address */
96
97 /*
98 * Define -pg profile entry code.
99 * XXX assume .set noreorder for kernel, .set reorder for user code.
100 */
101 #define _KERN_MCOUNT \
102 .set noat; \
103 move $1,$31; \
104 jal _mcount; \
105 subu sp,sp,8; \
106 .set at
107
108 #ifdef GPROF
109 # if defined(_KERNEL) || defined(_LOCORE)
110 # define MCOUNT _KERN_MCOUNT
111 # else
112 # define MCOUNT .set noreorder; _KERN_MCOUNT ; .set reorder;
113 # endif
114 #else
115 #define MCOUNT
116 #endif
117
118 #ifdef __NO_LEADING_UNDERSCORES__
119 # define _C_LABEL(x) x
120 #else
121 # ifdef __STDC__
122 # define _C_LABEL(x) _ ## x
123 # else
124 # define _C_LABEL(x) _/**/x
125 # endif
126 #endif
127
128 #ifdef USE_AENT
129 #define AENT(x) \
130 .aent x, 0
131 #else
132 #define AENT(x)
133 #endif
134
135 /*
136 * LEAF
137 * A leaf routine does
138 * - call no other function,
139 * - never use any register that callee-saved (S0-S8), and
140 * - not use any local stack storage.
141 */
142 #define LEAF(x) \
143 .globl _C_LABEL(x); \
144 .ent _C_LABEL(x), 0; \
145 _C_LABEL(x): ; \
146 .frame sp, 0, ra; \
147 MCOUNT
148
149 /*
150 * LEAF_NOPROFILE
151 * No profilable leaf routine.
152 */
153 #define LEAF_NOPROFILE(x) \
154 .globl _C_LABEL(x); \
155 .ent _C_LABEL(x), 0; \
156 _C_LABEL(x): ; \
157 .frame sp, 0, ra
158
159 /*
160 * XLEAF
161 * declare alternate entry to leaf routine
162 */
163 #define XLEAF(x) \
164 .globl _C_LABEL(x); \
165 .aent _C_LABEL(x),0; \
166 _C_LABEL(x):
167
168 /*
169 * NESTED
170 * A function calls other functions and needs
171 * therefore stack space to save/restore registers.
172 */
173 #define NESTED(x, fsize, retpc) \
174 .globl _C_LABEL(x); \
175 .ent _C_LABEL(x), 0; \
176 _C_LABEL(x): ; \
177 .frame sp, fsize, retpc; \
178 MCOUNT
179
180 /*
181 * NESTED_NOPROFILE(x)
182 * No profilable nested routine.
183 */
184 #define NESTED_NOPROFILE(x, fsize, retpc) \
185 .globl _C_LABEL(x); \
186 .ent _C_LABEL(x), 0; \
187 _C_LABEL(x): ; \
188 .frame sp, fsize, retpc
189
190 /*
191 * XNESTED
192 * declare alternate entry point to nested routine.
193 */
194 #define XNESTED(x) \
195 .globl _C_LABEL(x); \
196 .aent _C_LABEL(x),0; \
197 _C_LABEL(x):
198
199 /*
200 * END
201 * Mark end of a procedure.
202 */
203 #define END(x) \
204 .end _C_LABEL(x)
205
206 /*
207 * IMPORT -- import external symbol
208 */
209 #define IMPORT(sym, size) \
210 .extern sym,size
211
212 /*
213 * EXPORT -- export definition of symbol
214 */
215 #define EXPORT(x) \
216 .globl _C_LABEL(x); \
217 _C_LABEL(x):
218
219 /*
220 * ALIAS
221 * Global alias for a function, or alternate entry point
222 */
223 #define ALIAS(x) \
224 .globl _C_LABEL(x); \
225 _C_LABEL(x):
226
227 /*
228 * Macros to panic and printf from assembly language.
229 */
230 #define PANIC(msg) \
231 la a0, 9f; \
232 jal _C_LABEL(panic); \
233 MSG(msg)
234
235 #define PRINTF(msg) \
236 la a0, 9f; \
237 jal _C_LABEL(printf); \
238 MSG(msg)
239
240 #define MSG(msg) \
241 .rdata; \
242 9: .asciiz msg; \
243 .text
244
245 #define ASMSTR(str) \
246 .asciiz str; \
247 .align 3
248
249 /*
250 * XXX retain dialects XXX
251 */
252 #define ALEAF(x) \
253 .globl _C_LABEL(x); \
254 AENT (_C_LABEL(x)) \
255 _C_LABEL(x):
256
257 #define NLEAF(x) \
258 .globl _C_LABEL(x); \
259 .ent _C_LABEL(x), 0; \
260 _C_LABEL(x): ; \
261 .frame sp, 0, ra
262
263 #define NON_LEAF(x, fsize, retpc) \
264 .globl _C_LABEL(x); \
265 .ent _C_LABEL(x), 0; \
266 _C_LABEL(x): ; \
267 .frame sp, fsize, retpc; \
268 MCOUNT
269
270 #define NNON_LEAF(x, fsize, retpc) \
271 .globl _C_LABEL(x); \
272 .ent _C_LABEL(x), 0; \
273 _C_LABEL(x): ; \
274 .frame sp, fsize, retpc
275
276 #endif /* _MIPS_ASM_H */
277