asm.h revision 1.64 1 1.64 simonb /* $NetBSD: asm.h,v 1.64 2021/02/16 06:06:58 simonb 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.35 agc * 3. Neither the name of the University nor the names of its contributors
19 1.1 deraadt * may be used to endorse or promote products derived from this software
20 1.1 deraadt * without specific prior written permission.
21 1.1 deraadt *
22 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 deraadt * SUCH DAMAGE.
33 1.1 deraadt *
34 1.4 cgd * @(#)machAsmDefs.h 8.1 (Berkeley) 6/10/93
35 1.1 deraadt */
36 1.1 deraadt
37 1.1 deraadt /*
38 1.1 deraadt * machAsmDefs.h --
39 1.1 deraadt *
40 1.1 deraadt * Macros used when writing assembler programs.
41 1.1 deraadt *
42 1.1 deraadt * Copyright (C) 1989 Digital Equipment Corporation.
43 1.1 deraadt * Permission to use, copy, modify, and distribute this software and
44 1.1 deraadt * its documentation for any purpose and without fee is hereby granted,
45 1.1 deraadt * provided that the above copyright notice appears in all copies.
46 1.1 deraadt * Digital Equipment Corporation makes no representations about the
47 1.1 deraadt * suitability of this software for any purpose. It is provided "as is"
48 1.1 deraadt * without express or implied warranty.
49 1.1 deraadt *
50 1.1 deraadt * from: Header: /sprite/src/kernel/mach/ds3100.md/RCS/machAsmDefs.h,
51 1.2 glass * v 1.2 89/08/15 18:28:24 rab Exp SPRITE (DECWRL)
52 1.1 deraadt */
53 1.1 deraadt
54 1.8 jonathan #ifndef _MIPS_ASM_H
55 1.41 matt #define _MIPS_ASM_H
56 1.1 deraadt
57 1.44 matt #include <sys/cdefs.h> /* for API selection */
58 1.21 soda #include <mips/regdef.h>
59 1.1 deraadt
60 1.64 simonb #if defined(_KERNEL_OPT)
61 1.64 simonb #include "opt_gprof.h"
62 1.64 simonb #endif
63 1.64 simonb
64 1.61 skrll #define __BIT(n) (1 << (n))
65 1.61 skrll #define __BITS(hi,lo) ((~((~0)<<((hi)+1)))&((~0)<<(lo)))
66 1.61 skrll
67 1.61 skrll #define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask))
68 1.61 skrll #define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask))
69 1.61 skrll #define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask))
70 1.61 skrll
71 1.1 deraadt /*
72 1.1 deraadt * Define -pg profile entry code.
73 1.64 simonb * Must always be noreorder, must never use a macro instruction.
74 1.64 simonb */
75 1.64 simonb #if defined(__mips_o32) /* Old 32-bit ABI */
76 1.64 simonb /*
77 1.64 simonb * The old ABI version must also decrement two less words off the
78 1.64 simonb * stack and the final addiu to t9 must always equal the size of this
79 1.64 simonb * _KERN_MCOUNT.
80 1.1 deraadt */
81 1.41 matt #define _KERN_MCOUNT \
82 1.23 castor .set push; \
83 1.23 castor .set noreorder; \
84 1.23 castor .set noat; \
85 1.64 simonb subu sp,16; \
86 1.27 jeffs sw t9,12(sp); \
87 1.23 castor move AT,ra; \
88 1.23 castor lui t9,%hi(_mcount); \
89 1.23 castor addiu t9,t9,%lo(_mcount); \
90 1.23 castor jalr t9; \
91 1.64 simonb nop; \
92 1.23 castor lw t9,4(sp); \
93 1.64 simonb addiu sp,8; \
94 1.64 simonb addiu t9,40; \
95 1.64 simonb .set pop;
96 1.64 simonb #elif defined(__mips_o64) /* Old 64-bit ABI */
97 1.64 simonb # error yeahnah
98 1.64 simonb #else /* New (n32/n64) ABI */
99 1.64 simonb /*
100 1.64 simonb * The new ABI version just needs to put the return address in AT and
101 1.64 simonb * call _mcount().
102 1.64 simonb */
103 1.64 simonb #define _KERN_MCOUNT \
104 1.64 simonb .set push; \
105 1.64 simonb .set noreorder; \
106 1.64 simonb .set noat; \
107 1.64 simonb move AT,ra; \
108 1.64 simonb jal _mcount; \
109 1.64 simonb nop; \
110 1.50 skrll .set pop;
111 1.64 simonb #endif /* n32/n64 */
112 1.13 jonathan
113 1.11 jtc #ifdef GPROF
114 1.41 matt #define MCOUNT _KERN_MCOUNT
115 1.1 deraadt #else
116 1.1 deraadt #define MCOUNT
117 1.2 glass #endif
118 1.1 deraadt
119 1.15 castor #ifdef USE_AENT
120 1.41 matt #define AENT(x) \
121 1.15 castor .aent x, 0
122 1.15 castor #else
123 1.41 matt #define AENT(x)
124 1.24 kleink #endif
125 1.24 kleink
126 1.31 simonb /*
127 1.31 simonb * WEAK_ALIAS: create a weak alias.
128 1.31 simonb */
129 1.24 kleink #define WEAK_ALIAS(alias,sym) \
130 1.24 kleink .weak alias; \
131 1.24 kleink alias = sym
132 1.37 christos /*
133 1.37 christos * STRONG_ALIAS: create a strong alias.
134 1.37 christos */
135 1.41 matt #define STRONG_ALIAS(alias,sym) \
136 1.37 christos .globl alias; \
137 1.37 christos alias = sym
138 1.15 castor
139 1.14 thorpej /*
140 1.33 simonb * WARN_REFERENCES: create a warning if the specified symbol is referenced.
141 1.14 thorpej */
142 1.43 joerg #define WARN_REFERENCES(sym,msg) \
143 1.44 matt .pushsection __CONCAT(.gnu.warning.,sym); \
144 1.43 joerg .ascii msg; \
145 1.43 joerg .popsection
146 1.6 mycroft
147 1.1 deraadt /*
148 1.44 matt * STATIC_LEAF_NOPROFILE
149 1.44 matt * No profilable local leaf routine.
150 1.15 castor */
151 1.44 matt #define STATIC_LEAF_NOPROFILE(x) \
152 1.47 joerg .ent _C_LABEL(x); \
153 1.15 castor _C_LABEL(x): ; \
154 1.44 matt .frame sp, 0, ra
155 1.1 deraadt
156 1.1 deraadt /*
157 1.15 castor * LEAF_NOPROFILE
158 1.15 castor * No profilable leaf routine.
159 1.1 deraadt */
160 1.41 matt #define LEAF_NOPROFILE(x) \
161 1.15 castor .globl _C_LABEL(x); \
162 1.44 matt STATIC_LEAF_NOPROFILE(x)
163 1.15 castor
164 1.15 castor /*
165 1.34 simonb * STATIC_LEAF
166 1.34 simonb * Declare a local leaf function.
167 1.34 simonb */
168 1.41 matt #define STATIC_LEAF(x) \
169 1.44 matt STATIC_LEAF_NOPROFILE(x); \
170 1.34 simonb MCOUNT
171 1.34 simonb
172 1.34 simonb /*
173 1.44 matt * LEAF
174 1.44 matt * A leaf routine does
175 1.44 matt * - call no other function,
176 1.44 matt * - never use any register that callee-saved (S0-S8), and
177 1.44 matt * - not use any local stack storage.
178 1.15 castor */
179 1.44 matt #define LEAF(x) \
180 1.44 matt LEAF_NOPROFILE(x); \
181 1.44 matt MCOUNT
182 1.34 simonb
183 1.34 simonb /*
184 1.34 simonb * STATIC_XLEAF
185 1.34 simonb * declare alternate entry to a static leaf routine
186 1.34 simonb */
187 1.41 matt #define STATIC_XLEAF(x) \
188 1.20 soda AENT (_C_LABEL(x)); \
189 1.15 castor _C_LABEL(x):
190 1.15 castor
191 1.15 castor /*
192 1.44 matt * XLEAF
193 1.44 matt * declare alternate entry to leaf routine
194 1.44 matt */
195 1.44 matt #define XLEAF(x) \
196 1.44 matt .globl _C_LABEL(x); \
197 1.44 matt STATIC_XLEAF(x)
198 1.44 matt
199 1.44 matt /*
200 1.44 matt * STATIC_NESTED_NOPROFILE
201 1.44 matt * No profilable local nested routine.
202 1.44 matt */
203 1.44 matt #define STATIC_NESTED_NOPROFILE(x, fsize, retpc) \
204 1.55 mrg .ent _C_LABEL(x); \
205 1.55 mrg .type _C_LABEL(x), @function; \
206 1.55 mrg _C_LABEL(x): ; \
207 1.44 matt .frame sp, fsize, retpc
208 1.44 matt
209 1.44 matt /*
210 1.44 matt * NESTED_NOPROFILE
211 1.44 matt * No profilable nested routine.
212 1.44 matt */
213 1.44 matt #define NESTED_NOPROFILE(x, fsize, retpc) \
214 1.44 matt .globl _C_LABEL(x); \
215 1.44 matt STATIC_NESTED_NOPROFILE(x, fsize, retpc)
216 1.44 matt
217 1.44 matt /*
218 1.15 castor * NESTED
219 1.15 castor * A function calls other functions and needs
220 1.15 castor * therefore stack space to save/restore registers.
221 1.15 castor */
222 1.44 matt #define NESTED(x, fsize, retpc) \
223 1.44 matt NESTED_NOPROFILE(x, fsize, retpc); \
224 1.15 castor MCOUNT
225 1.1 deraadt
226 1.1 deraadt /*
227 1.44 matt * STATIC_NESTED
228 1.44 matt * No profilable local nested routine.
229 1.1 deraadt */
230 1.44 matt #define STATIC_NESTED(x, fsize, retpc) \
231 1.44 matt STATIC_NESTED_NOPROFILE(x, fsize, retpc); \
232 1.44 matt MCOUNT
233 1.15 castor
234 1.15 castor /*
235 1.15 castor * XNESTED
236 1.15 castor * declare alternate entry point to nested routine.
237 1.15 castor */
238 1.41 matt #define XNESTED(x) \
239 1.15 castor .globl _C_LABEL(x); \
240 1.20 soda AENT (_C_LABEL(x)); \
241 1.6 mycroft _C_LABEL(x):
242 1.1 deraadt
243 1.1 deraadt /*
244 1.15 castor * END
245 1.15 castor * Mark end of a procedure.
246 1.1 deraadt */
247 1.44 matt #define END(x) \
248 1.41 matt .end _C_LABEL(x); \
249 1.41 matt .size _C_LABEL(x), . - _C_LABEL(x)
250 1.2 glass
251 1.2 glass /*
252 1.15 castor * IMPORT -- import external symbol
253 1.2 glass */
254 1.41 matt #define IMPORT(sym, size) \
255 1.20 soda .extern _C_LABEL(sym),size
256 1.1 deraadt
257 1.1 deraadt /*
258 1.15 castor * EXPORT -- export definition of symbol
259 1.1 deraadt */
260 1.41 matt #define EXPORT(x) \
261 1.15 castor .globl _C_LABEL(x); \
262 1.15 castor _C_LABEL(x):
263 1.1 deraadt
264 1.15 castor /*
265 1.62 simonb * EXPORT_OBJECT -- export definition of symbol of symbol
266 1.62 simonb * type Object, visible to ksyms(4) address search.
267 1.62 simonb */
268 1.62 simonb #define EXPORT_OBJECT(x) \
269 1.62 simonb EXPORT(x); \
270 1.62 simonb .type _C_LABEL(x), @object;
271 1.62 simonb
272 1.62 simonb /*
273 1.17 jonathan * VECTOR
274 1.17 jonathan * exception vector entrypoint
275 1.20 soda * XXX: regmask should be used to generate .mask
276 1.17 jonathan */
277 1.41 matt #define VECTOR(x, regmask) \
278 1.47 joerg .ent _C_LABEL(x); \
279 1.17 jonathan EXPORT(x); \
280 1.17 jonathan
281 1.41 matt #define VECTOR_END(x) \
282 1.44 matt EXPORT(__CONCAT(x,_end)); \
283 1.44 matt END(x); \
284 1.44 matt .org _C_LABEL(x) + 0x80
285 1.1 deraadt
286 1.1 deraadt /*
287 1.10 christos * Macros to panic and printf from assembly language.
288 1.1 deraadt */
289 1.41 matt #define PANIC(msg) \
290 1.41 matt PTR_LA a0, 9f; \
291 1.15 castor jal _C_LABEL(panic); \
292 1.26 cgd nop; \
293 1.1 deraadt MSG(msg)
294 1.1 deraadt
295 1.15 castor #define PRINTF(msg) \
296 1.41 matt PTR_LA a0, 9f; \
297 1.15 castor jal _C_LABEL(printf); \
298 1.26 cgd nop; \
299 1.1 deraadt MSG(msg)
300 1.1 deraadt
301 1.15 castor #define MSG(msg) \
302 1.15 castor .rdata; \
303 1.48 joerg 9: .asciz msg; \
304 1.1 deraadt .text
305 1.1 deraadt
306 1.41 matt #define ASMSTR(str) \
307 1.48 joerg .asciz str; \
308 1.12 jonathan .align 3
309 1.15 castor
310 1.57 simonb #define RCSID(x) .pushsection ".ident","MS",@progbits,1; \
311 1.56 joerg .asciz x; \
312 1.56 joerg .popsection
313 1.41 matt
314 1.15 castor /*
315 1.15 castor * XXX retain dialects XXX
316 1.15 castor */
317 1.41 matt #define ALEAF(x) XLEAF(x)
318 1.41 matt #define NLEAF(x) LEAF_NOPROFILE(x)
319 1.41 matt #define NON_LEAF(x, fsize, retpc) NESTED(x, fsize, retpc)
320 1.41 matt #define NNON_LEAF(x, fsize, retpc) NESTED_NOPROFILE(x, fsize, retpc)
321 1.41 matt
322 1.41 matt #if defined(__mips_o32)
323 1.41 matt #define SZREG 4
324 1.41 matt #else
325 1.41 matt #define SZREG 8
326 1.41 matt #endif
327 1.41 matt
328 1.41 matt #if defined(__mips_o32) || defined(__mips_o64)
329 1.41 matt #define ALSK 7 /* stack alignment */
330 1.41 matt #define ALMASK -7 /* stack alignment */
331 1.41 matt #define SZFPREG 4
332 1.41 matt #define FP_L lwc1
333 1.41 matt #define FP_S swc1
334 1.41 matt #else
335 1.41 matt #define ALSK 15 /* stack alignment */
336 1.41 matt #define ALMASK -15 /* stack alignment */
337 1.41 matt #define SZFPREG 8
338 1.41 matt #define FP_L ldc1
339 1.41 matt #define FP_S sdc1
340 1.41 matt #endif
341 1.15 castor
342 1.22 simonb /*
343 1.16 castor * standard callframe {
344 1.44 matt * register_t cf_args[4]; arg0 - arg3 (only on o32 and o64)
345 1.41 matt * register_t cf_pad[N]; o32/64 (N=0), n32 (N=1) n64 (N=1)
346 1.41 matt * register_t cf_gp; global pointer (only on n32 and n64)
347 1.16 castor * register_t cf_sp; frame pointer
348 1.16 castor * register_t cf_ra; return address
349 1.16 castor * };
350 1.16 castor */
351 1.41 matt #if defined(__mips_o32) || defined(__mips_o64)
352 1.41 matt #define CALLFRAME_SIZ (SZREG * (4 + 2))
353 1.41 matt #define CALLFRAME_S0 0
354 1.41 matt #elif defined(__mips_n32) || defined(__mips_n64)
355 1.41 matt #define CALLFRAME_SIZ (SZREG * 4)
356 1.41 matt #define CALLFRAME_S0 (CALLFRAME_SIZ - 4 * SZREG)
357 1.41 matt #endif
358 1.41 matt #ifndef _KERNEL
359 1.41 matt #define CALLFRAME_GP (CALLFRAME_SIZ - 3 * SZREG)
360 1.41 matt #endif
361 1.41 matt #define CALLFRAME_SP (CALLFRAME_SIZ - 2 * SZREG)
362 1.41 matt #define CALLFRAME_RA (CALLFRAME_SIZ - 1 * SZREG)
363 1.16 castor
364 1.15 castor /*
365 1.22 simonb * While it would be nice to be compatible with the SGI
366 1.15 castor * REG_L and REG_S macros, because they do not take parameters, it
367 1.15 castor * is impossible to use them with the _MIPS_SIM_ABIX32 model.
368 1.15 castor *
369 1.22 simonb * These macros hide the use of mips3 instructions from the
370 1.15 castor * assembler to prevent the assembler from generating 64-bit style
371 1.15 castor * ABI calls.
372 1.15 castor */
373 1.49 matt #ifdef __mips_o32
374 1.41 matt #define PTR_ADD add
375 1.41 matt #define PTR_ADDI addi
376 1.41 matt #define PTR_ADDU addu
377 1.41 matt #define PTR_ADDIU addiu
378 1.45 matt #define PTR_SUB subu
379 1.41 matt #define PTR_SUBI subi
380 1.41 matt #define PTR_SUBU subu
381 1.41 matt #define PTR_SUBIU subu
382 1.41 matt #define PTR_L lw
383 1.41 matt #define PTR_LA la
384 1.41 matt #define PTR_S sw
385 1.41 matt #define PTR_SLL sll
386 1.41 matt #define PTR_SLLV sllv
387 1.41 matt #define PTR_SRL srl
388 1.41 matt #define PTR_SRLV srlv
389 1.41 matt #define PTR_SRA sra
390 1.41 matt #define PTR_SRAV srav
391 1.41 matt #define PTR_LL ll
392 1.41 matt #define PTR_SC sc
393 1.41 matt #define PTR_WORD .word
394 1.41 matt #define PTR_SCALESHIFT 2
395 1.41 matt #else /* _MIPS_SZPTR == 64 */
396 1.41 matt #define PTR_ADD dadd
397 1.41 matt #define PTR_ADDI daddi
398 1.41 matt #define PTR_ADDU daddu
399 1.41 matt #define PTR_ADDIU daddiu
400 1.45 matt #define PTR_SUB dsubu
401 1.41 matt #define PTR_SUBI dsubi
402 1.41 matt #define PTR_SUBU dsubu
403 1.41 matt #define PTR_SUBIU dsubu
404 1.49 matt #ifdef __mips_n32
405 1.49 matt #define PTR_L lw
406 1.49 matt #define PTR_LL ll
407 1.49 matt #define PTR_SC sc
408 1.49 matt #define PTR_S sw
409 1.49 matt #define PTR_SCALESHIFT 2
410 1.49 matt #define PTR_WORD .word
411 1.49 matt #else
412 1.41 matt #define PTR_L ld
413 1.49 matt #define PTR_LL lld
414 1.49 matt #define PTR_SC scd
415 1.49 matt #define PTR_S sd
416 1.49 matt #define PTR_SCALESHIFT 3
417 1.49 matt #define PTR_WORD .dword
418 1.49 matt #endif
419 1.41 matt #define PTR_LA dla
420 1.41 matt #define PTR_SLL dsll
421 1.41 matt #define PTR_SLLV dsllv
422 1.41 matt #define PTR_SRL dsrl
423 1.41 matt #define PTR_SRLV dsrlv
424 1.41 matt #define PTR_SRA dsra
425 1.41 matt #define PTR_SRAV dsrav
426 1.41 matt #endif /* _MIPS_SZPTR == 64 */
427 1.41 matt
428 1.41 matt #if _MIPS_SZINT == 32
429 1.41 matt #define INT_ADD add
430 1.41 matt #define INT_ADDI addi
431 1.41 matt #define INT_ADDU addu
432 1.41 matt #define INT_ADDIU addiu
433 1.45 matt #define INT_SUB subu
434 1.41 matt #define INT_SUBI subi
435 1.41 matt #define INT_SUBU subu
436 1.41 matt #define INT_SUBIU subu
437 1.41 matt #define INT_L lw
438 1.41 matt #define INT_LA la
439 1.41 matt #define INT_S sw
440 1.41 matt #define INT_SLL sll
441 1.41 matt #define INT_SLLV sllv
442 1.41 matt #define INT_SRL srl
443 1.41 matt #define INT_SRLV srlv
444 1.41 matt #define INT_SRA sra
445 1.41 matt #define INT_SRAV srav
446 1.41 matt #define INT_LL ll
447 1.41 matt #define INT_SC sc
448 1.41 matt #define INT_WORD .word
449 1.41 matt #define INT_SCALESHIFT 2
450 1.41 matt #else
451 1.41 matt #define INT_ADD dadd
452 1.41 matt #define INT_ADDI daddi
453 1.41 matt #define INT_ADDU daddu
454 1.41 matt #define INT_ADDIU daddiu
455 1.45 matt #define INT_SUB dsubu
456 1.41 matt #define INT_SUBI dsubi
457 1.41 matt #define INT_SUBU dsubu
458 1.41 matt #define INT_SUBIU dsubu
459 1.41 matt #define INT_L ld
460 1.41 matt #define INT_LA dla
461 1.41 matt #define INT_S sd
462 1.41 matt #define INT_SLL dsll
463 1.41 matt #define INT_SLLV dsllv
464 1.41 matt #define INT_SRL dsrl
465 1.41 matt #define INT_SRLV dsrlv
466 1.41 matt #define INT_SRA dsra
467 1.41 matt #define INT_SRAV dsrav
468 1.41 matt #define INT_LL lld
469 1.41 matt #define INT_SC scd
470 1.41 matt #define INT_WORD .dword
471 1.41 matt #define INT_SCALESHIFT 3
472 1.41 matt #endif
473 1.15 castor
474 1.41 matt #if _MIPS_SZLONG == 32
475 1.41 matt #define LONG_ADD add
476 1.41 matt #define LONG_ADDI addi
477 1.41 matt #define LONG_ADDU addu
478 1.41 matt #define LONG_ADDIU addiu
479 1.45 matt #define LONG_SUB subu
480 1.41 matt #define LONG_SUBI subi
481 1.41 matt #define LONG_SUBU subu
482 1.41 matt #define LONG_SUBIU subu
483 1.41 matt #define LONG_L lw
484 1.41 matt #define LONG_LA la
485 1.41 matt #define LONG_S sw
486 1.41 matt #define LONG_SLL sll
487 1.41 matt #define LONG_SLLV sllv
488 1.41 matt #define LONG_SRL srl
489 1.41 matt #define LONG_SRLV srlv
490 1.41 matt #define LONG_SRA sra
491 1.41 matt #define LONG_SRAV srav
492 1.41 matt #define LONG_LL ll
493 1.41 matt #define LONG_SC sc
494 1.41 matt #define LONG_WORD .word
495 1.41 matt #define LONG_SCALESHIFT 2
496 1.41 matt #else
497 1.41 matt #define LONG_ADD dadd
498 1.41 matt #define LONG_ADDI daddi
499 1.41 matt #define LONG_ADDU daddu
500 1.41 matt #define LONG_ADDIU daddiu
501 1.45 matt #define LONG_SUB dsubu
502 1.41 matt #define LONG_SUBI dsubi
503 1.41 matt #define LONG_SUBU dsubu
504 1.41 matt #define LONG_SUBIU dsubu
505 1.41 matt #define LONG_L ld
506 1.41 matt #define LONG_LA dla
507 1.41 matt #define LONG_S sd
508 1.41 matt #define LONG_SLL dsll
509 1.41 matt #define LONG_SLLV dsllv
510 1.41 matt #define LONG_SRL dsrl
511 1.41 matt #define LONG_SRLV dsrlv
512 1.41 matt #define LONG_SRA dsra
513 1.41 matt #define LONG_SRAV dsrav
514 1.41 matt #define LONG_LL lld
515 1.41 matt #define LONG_SC scd
516 1.41 matt #define LONG_WORD .dword
517 1.41 matt #define LONG_SCALESHIFT 3
518 1.41 matt #endif
519 1.41 matt
520 1.41 matt #if SZREG == 4
521 1.41 matt #define REG_L lw
522 1.41 matt #define REG_S sw
523 1.41 matt #define REG_LI li
524 1.41 matt #define REG_ADDU addu
525 1.41 matt #define REG_SLL sll
526 1.41 matt #define REG_SLLV sllv
527 1.41 matt #define REG_SRL srl
528 1.41 matt #define REG_SRLV srlv
529 1.41 matt #define REG_SRA sra
530 1.41 matt #define REG_SRAV srav
531 1.41 matt #define REG_LL ll
532 1.41 matt #define REG_SC sc
533 1.41 matt #define REG_SCALESHIFT 2
534 1.41 matt #else
535 1.41 matt #define REG_L ld
536 1.41 matt #define REG_S sd
537 1.41 matt #define REG_LI dli
538 1.41 matt #define REG_ADDU daddu
539 1.41 matt #define REG_SLL dsll
540 1.41 matt #define REG_SLLV dsllv
541 1.41 matt #define REG_SRL dsrl
542 1.41 matt #define REG_SRLV dsrlv
543 1.41 matt #define REG_SRA dsra
544 1.41 matt #define REG_SRAV dsrav
545 1.41 matt #define REG_LL lld
546 1.41 matt #define REG_SC scd
547 1.41 matt #define REG_SCALESHIFT 3
548 1.41 matt #endif
549 1.41 matt
550 1.51 skrll #if (MIPS1 + MIPS2) > 0
551 1.51 skrll #define NOP_L nop
552 1.51 skrll #else
553 1.51 skrll #define NOP_L /* nothing */
554 1.51 skrll #endif
555 1.51 skrll
556 1.59 skrll /* compiler define */
557 1.59 skrll #if defined(__OCTEON__)
558 1.58 skrll /* early cnMIPS have erratum which means 2 */
559 1.58 skrll #define LLSCSYNC sync 4; sync 4
560 1.58 skrll #define SYNC sync 4 /* sync 4 == syncw - sync all writes */
561 1.58 skrll #define BDSYNC sync 4 /* sync 4 == syncw - sync all writes */
562 1.60 skrll #elif __mips >= 3 || !defined(__mips_o32)
563 1.59 skrll #define LLSCSYNC sync
564 1.58 skrll #define SYNC sync
565 1.58 skrll #define BDSYNC sync
566 1.60 skrll #else
567 1.60 skrll #define LLSCSYNC /* nothing */
568 1.60 skrll #define SYNC /* nothing */
569 1.60 skrll #define BDSYNC nop
570 1.58 skrll #endif
571 1.58 skrll
572 1.52 maya /* CPU dependent hook for cp0 load delays */
573 1.52 maya #if defined(MIPS1) || defined(MIPS2) || defined(MIPS3)
574 1.57 simonb #define MFC0_HAZARD sll $0,$0,1 /* super scalar nop */
575 1.52 maya #else
576 1.57 simonb #define MFC0_HAZARD /* nothing */
577 1.52 maya #endif
578 1.52 maya
579 1.41 matt #if _MIPS_ISA == _MIPS_ISA_MIPS1 || _MIPS_ISA == _MIPS_ISA_MIPS2 || \
580 1.41 matt _MIPS_ISA == _MIPS_ISA_MIPS32
581 1.41 matt #define MFC0 mfc0
582 1.41 matt #define MTC0 mtc0
583 1.41 matt #endif
584 1.41 matt #if _MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4 || \
585 1.41 matt _MIPS_ISA == _MIPS_ISA_MIPS64
586 1.41 matt #define MFC0 dmfc0
587 1.41 matt #define MTC0 dmtc0
588 1.41 matt #endif
589 1.41 matt
590 1.41 matt #if defined(__mips_o32) || defined(__mips_o64)
591 1.41 matt
592 1.54 joerg #ifdef __mips_abicalls
593 1.41 matt #define CPRESTORE(r) .cprestore r
594 1.41 matt #define CPLOAD(r) .cpload r
595 1.41 matt #else
596 1.41 matt #define CPRESTORE(r) /* not needed */
597 1.41 matt #define CPLOAD(r) /* not needed */
598 1.41 matt #endif
599 1.41 matt
600 1.41 matt #define SETUP_GP \
601 1.41 matt .set push; \
602 1.41 matt .set noreorder; \
603 1.41 matt .cpload t9; \
604 1.41 matt .set pop
605 1.41 matt #define SETUP_GPX(r) \
606 1.41 matt .set push; \
607 1.41 matt .set noreorder; \
608 1.41 matt move r,ra; /* save old ra */ \
609 1.41 matt bal 7f; \
610 1.41 matt nop; \
611 1.41 matt 7: .cpload ra; \
612 1.41 matt move ra,r; \
613 1.41 matt .set pop
614 1.41 matt #define SETUP_GPX_L(r,lbl) \
615 1.41 matt .set push; \
616 1.41 matt .set noreorder; \
617 1.41 matt move r,ra; /* save old ra */ \
618 1.41 matt bal lbl; \
619 1.41 matt nop; \
620 1.41 matt lbl: .cpload ra; \
621 1.41 matt move ra,r; \
622 1.41 matt .set pop
623 1.41 matt #define SAVE_GP(x) .cprestore x
624 1.41 matt
625 1.41 matt #define SETUP_GP64(a,b) /* n32/n64 specific */
626 1.41 matt #define SETUP_GP64_R(a,b) /* n32/n64 specific */
627 1.41 matt #define SETUP_GPX64(a,b) /* n32/n64 specific */
628 1.41 matt #define SETUP_GPX64_L(a,b,c) /* n32/n64 specific */
629 1.41 matt #define RESTORE_GP64 /* n32/n64 specific */
630 1.41 matt #define USE_ALT_CP(a) /* n32/n64 specific */
631 1.41 matt #endif /* __mips_o32 || __mips_o64 */
632 1.41 matt
633 1.41 matt #if defined(__mips_o32) || defined(__mips_o64)
634 1.22 simonb #define REG_PROLOGUE .set push
635 1.16 castor #define REG_EPILOGUE .set pop
636 1.41 matt #endif
637 1.41 matt #if defined(__mips_n32) || defined(__mips_n64)
638 1.15 castor #define REG_PROLOGUE .set push ; .set mips3
639 1.15 castor #define REG_EPILOGUE .set pop
640 1.41 matt #endif
641 1.41 matt
642 1.41 matt #if defined(__mips_n32) || defined(__mips_n64)
643 1.41 matt #define SETUP_GP /* o32 specific */
644 1.41 matt #define SETUP_GPX(r) /* o32 specific */
645 1.41 matt #define SETUP_GPX_L(r,lbl) /* o32 specific */
646 1.41 matt #define SAVE_GP(x) /* o32 specific */
647 1.63 skrll #define SETUP_GP64(a,b) .cpsetup t9, a, b
648 1.41 matt #define SETUP_GPX64(a,b) \
649 1.41 matt .set push; \
650 1.41 matt move b,ra; \
651 1.41 matt .set noreorder; \
652 1.41 matt bal 7f; \
653 1.41 matt nop; \
654 1.41 matt 7: .set pop; \
655 1.41 matt .cpsetup ra, a, 7b; \
656 1.41 matt move ra,b
657 1.41 matt #define SETUP_GPX64_L(a,b,c) \
658 1.41 matt .set push; \
659 1.41 matt move b,ra; \
660 1.41 matt .set noreorder; \
661 1.41 matt bal c; \
662 1.41 matt nop; \
663 1.41 matt c: .set pop; \
664 1.41 matt .cpsetup ra, a, c; \
665 1.41 matt move ra,b
666 1.41 matt #define RESTORE_GP64 .cpreturn
667 1.41 matt #define USE_ALT_CP(a) .cplocal a
668 1.41 matt #endif /* __mips_n32 || __mips_n64 */
669 1.25 jeffs
670 1.25 jeffs /*
671 1.25 jeffs * The DYNAMIC_STATUS_MASK option adds an additional masking operation
672 1.25 jeffs * when updating the hardware interrupt mask in the status register.
673 1.25 jeffs *
674 1.25 jeffs * This is useful for platforms that need to at run-time mask
675 1.25 jeffs * interrupts based on motherboard configuration or to handle
676 1.25 jeffs * slowly clearing interrupts.
677 1.25 jeffs *
678 1.25 jeffs * XXX this is only currently implemented for mips3.
679 1.25 jeffs */
680 1.25 jeffs #ifdef MIPS_DYNAMIC_STATUS_MASK
681 1.41 matt #define DYNAMIC_STATUS_MASK(sr,scratch) \
682 1.25 jeffs lw scratch, mips_dynamic_status_mask; \
683 1.25 jeffs and sr, sr, scratch
684 1.29 jeffs
685 1.41 matt #define DYNAMIC_STATUS_MASK_TOUSER(sr,scratch1) \
686 1.29 jeffs ori sr, (MIPS_INT_MASK | MIPS_SR_INT_IE); \
687 1.29 jeffs DYNAMIC_STATUS_MASK(sr,scratch1)
688 1.25 jeffs #else
689 1.41 matt #define DYNAMIC_STATUS_MASK(sr,scratch)
690 1.41 matt #define DYNAMIC_STATUS_MASK_TOUSER(sr,scratch1)
691 1.25 jeffs #endif
692 1.1 deraadt
693 1.38 ad /* See lock_stubs.S. */
694 1.44 matt #define LOG2_MIPS_LOCK_RAS_SIZE 8
695 1.44 matt #define MIPS_LOCK_RAS_SIZE 256 /* 16 bytes left over */
696 1.38 ad
697 1.41 matt #define CPUVAR(off) _C_LABEL(cpu_info_store)+__CONCAT(CPU_INFO_,off)
698 1.39 yamt
699 1.8 jonathan #endif /* _MIPS_ASM_H */
700