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