1 /* $NetBSD: asm.h,v 1.40 2007/10/17 19:55:36 garbled Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)machAsmDefs.h 8.1 (Berkeley) 6/10/93
40 * Macros used when writing assembler programs.
42 * Copyright (C) 1989 Digital Equipment Corporation.
43 * Permission to use, copy, modify, and distribute this software and
44 * its documentation for any purpose and without fee is hereby granted,
45 * provided that the above copyright notice appears in all copies.
46 * Digital Equipment Corporation makes no representations about the
47 * suitability of this software for any purpose. It is provided "as is"
48 * without express or implied warranty.
50 * from: Header: /sprite/src/kernel/mach/ds3100.md/RCS/machAsmDefs.h,
51 * v 1.2 89/08/15 18:28:24 rab Exp SPRITE (DECWRL)
57 #include <machine/cdefs.h> /* for API selection */
58 #include <mips/regdef.h>
61 * Define -pg profile entry code.
62 * Must always be noreorder, must never use a macro instruction
63 * Final addiu to t9 must always equal the size of this _KERN_MCOUNT
65 #define _KERN_MCOUNT \
72 lui t9,%hi(_mcount); \
73 addiu t9,t9,%lo(_mcount); \
82 #define MCOUNT _KERN_MCOUNT
87 #ifdef __NO_LEADING_UNDERSCORES__
88 # define _C_LABEL(x) x
91 # define _C_LABEL(x) _ ## x
93 # define _C_LABEL(x) _/**/x
105 * WEAK_ALIAS: create a weak alias.
107 #define WEAK_ALIAS(alias,sym) \
111 * STRONG_ALIAS: create a strong alias.
113 #define STRONG_ALIAS(alias,sym) \
118 * WARN_REFERENCES: create a warning if the specified symbol is referenced.
121 #define WARN_REFERENCES(_sym,_msg) \
122 .section .gnu.warning. ## _sym ; .ascii _msg ; .text
124 #define WARN_REFERENCES(_sym,_msg) \
125 .section .gnu.warning./**/_sym ; .ascii _msg ; .text
126 #endif /* __STDC__ */
130 * A leaf routine does
131 * - call no other function,
132 * - never use any register that callee-saved (S0-S8), and
133 * - not use any local stack storage.
136 .globl _C_LABEL(x); \
137 .ent _C_LABEL(x), 0; \
144 * No profilable leaf routine.
146 #define LEAF_NOPROFILE(x) \
147 .globl _C_LABEL(x); \
148 .ent _C_LABEL(x), 0; \
154 * Declare a local leaf function.
156 #define STATIC_LEAF(x) \
157 .ent _C_LABEL(x), 0; \
164 * declare alternate entry to leaf routine
167 .globl _C_LABEL(x); \
168 AENT (_C_LABEL(x)); \
173 * declare alternate entry to a static leaf routine
175 #define STATIC_XLEAF(x) \
176 AENT (_C_LABEL(x)); \
181 * A function calls other functions and needs
182 * therefore stack space to save/restore registers.
184 #define NESTED(x, fsize, retpc) \
185 .globl _C_LABEL(x); \
186 .ent _C_LABEL(x), 0; \
188 .frame sp, fsize, retpc; \
192 * NESTED_NOPROFILE(x)
193 * No profilable nested routine.
195 #define NESTED_NOPROFILE(x, fsize, retpc) \
196 .globl _C_LABEL(x); \
197 .ent _C_LABEL(x), 0; \
199 .frame sp, fsize, retpc
203 * declare alternate entry point to nested routine.
206 .globl _C_LABEL(x); \
207 AENT (_C_LABEL(x)); \
212 * Mark end of a procedure.
216 .size _C_LABEL(x), . - _C_LABEL(x)
219 * IMPORT -- import external symbol
221 #define IMPORT(sym, size) \
222 .extern _C_LABEL(sym),size
225 * EXPORT -- export definition of symbol
228 .globl _C_LABEL(x); \
233 * exception vector entrypoint
234 * XXX: regmask should be used to generate .mask
236 #define VECTOR(x, regmask) \
237 .ent _C_LABEL(x),0; \
241 #define VECTOR_END(x) \
245 #define VECTOR_END(x) \
251 * Macros to panic and printf from assembly language.
255 jal _C_LABEL(panic); \
259 #define PRINTF(msg) \
261 jal _C_LABEL(printf); \
270 #define ASMSTR(str) \
274 #define RCSID(name) .pushsection ".ident"; .asciz name; .popsection
277 * XXX retain dialects XXX
279 #define ALEAF(x) XLEAF(x)
280 #define NLEAF(x) LEAF_NOPROFILE(x)
281 #define NON_LEAF(x, fsize, retpc) NESTED(x, fsize, retpc)
282 #define NNON_LEAF(x, fsize, retpc) NESTED_NOPROFILE(x, fsize, retpc)
284 #if defined(__mips_o32)
290 #if defined(__mips_o32) || defined(__mips_o64)
291 #define ALSK 7 /* stack alignment */
292 #define ALMASK -7 /* stack alignment */
297 #define ALSK 15 /* stack alignment */
298 #define ALMASK -15 /* stack alignment */
305 * standard callframe {
306 * register_t cf_pad[N]; o32/64 (N=0), n32 (N=1) n64 (N=1)
307 * register_t cf_args[4]; arg0 - arg3 (only on o32 and o64)
308 * register_t cf_gp; global pointer (only on n32 and n64)
309 * register_t cf_sp; frame pointer
310 * register_t cf_ra; return address
313 #if defined(__mips_o32) || defined(__mips_o64)
314 #define CALLFRAME_SIZ (SZREG * (4 + 2))
315 #define CALLFRAME_S0 0
316 #elif defined(__mips_n32) || defined(__mips_n64)
317 #define CALLFRAME_SIZ (SZREG * 4)
318 #define CALLFRAME_S0 (CALLFRAME_SIZ - 4 * SZREG)
321 #define CALLFRAME_GP (CALLFRAME_SIZ - 3 * SZREG)
323 #define CALLFRAME_SP (CALLFRAME_SIZ - 2 * SZREG)
324 #define CALLFRAME_RA (CALLFRAME_SIZ - 1 * SZREG)
327 * While it would be nice to be compatible with the SGI
328 * REG_L and REG_S macros, because they do not take parameters, it
329 * is impossible to use them with the _MIPS_SIM_ABIX32 model.
331 * These macros hide the use of mips3 instructions from the
332 * assembler to prevent the assembler from generating 64-bit style
335 #if _MIPS_SZPTR == 32
337 #define PTR_ADDI addi
338 #define PTR_ADDU addu
339 #define PTR_ADDIU addiu
341 #define PTR_SUBI subi
342 #define PTR_SUBU subu
343 #define PTR_SUBIU subu
348 #define PTR_SLLV sllv
350 #define PTR_SRLV srlv
352 #define PTR_SRAV srav
355 #define PTR_WORD .word
356 #define PTR_SCALESHIFT 2
357 #else /* _MIPS_SZPTR == 64 */
359 #define PTR_ADDI daddi
360 #define PTR_ADDU daddu
361 #define PTR_ADDIU daddiu
363 #define PTR_SUBI dsubi
364 #define PTR_SUBU dsubu
365 #define PTR_SUBIU dsubu
370 #define PTR_SLLV dsllv
372 #define PTR_SRLV dsrlv
374 #define PTR_SRAV dsrav
377 #define PTR_WORD .dword
378 #define PTR_SCALESHIFT 3
379 #endif /* _MIPS_SZPTR == 64 */
381 #if _MIPS_SZINT == 32
383 #define INT_ADDI addi
384 #define INT_ADDU addu
385 #define INT_ADDIU addiu
387 #define INT_SUBI subi
388 #define INT_SUBU subu
389 #define INT_SUBIU subu
394 #define INT_SLLV sllv
396 #define INT_SRLV srlv
398 #define INT_SRAV srav
401 #define INT_WORD .word
402 #define INT_SCALESHIFT 2
405 #define INT_ADDI daddi
406 #define INT_ADDU daddu
407 #define INT_ADDIU daddiu
409 #define INT_SUBI dsubi
410 #define INT_SUBU dsubu
411 #define INT_SUBIU dsubu
416 #define INT_SLLV dsllv
418 #define INT_SRLV dsrlv
420 #define INT_SRAV dsrav
423 #define INT_WORD .dword
424 #define INT_SCALESHIFT 3
427 #if _MIPS_SZLONG == 32
429 #define LONG_ADDI addi
430 #define LONG_ADDU addu
431 #define LONG_ADDIU addiu
433 #define LONG_SUBI subi
434 #define LONG_SUBU subu
435 #define LONG_SUBIU subu
440 #define LONG_SLLV sllv
442 #define LONG_SRLV srlv
444 #define LONG_SRAV srav
447 #define LONG_WORD .word
448 #define LONG_SCALESHIFT 2
450 #define LONG_ADD dadd
451 #define LONG_ADDI daddi
452 #define LONG_ADDU daddu
453 #define LONG_ADDIU daddiu
454 #define LONG_SUB dadd
455 #define LONG_SUBI dsubi
456 #define LONG_SUBU dsubu
457 #define LONG_SUBIU dsubu
461 #define LONG_SLL dsll
462 #define LONG_SLLV dsllv
463 #define LONG_SRL dsrl
464 #define LONG_SRLV dsrlv
465 #define LONG_SRA dsra
466 #define LONG_SRAV dsrav
469 #define LONG_WORD .dword
470 #define LONG_SCALESHIFT 3
477 #define REG_ADDU addu
479 #define REG_SLLV sllv
481 #define REG_SRLV srlv
483 #define REG_SRAV srav
486 #define REG_SCALESHIFT 2
491 #define REG_ADDU daddu
493 #define REG_SLLV dsllv
495 #define REG_SRLV dsrlv
497 #define REG_SRAV dsrav
500 #define REG_SCALESHIFT 3
503 #if _MIPS_ISA == _MIPS_ISA_MIPS1 || _MIPS_ISA == _MIPS_ISA_MIPS2 || \
504 _MIPS_ISA == _MIPS_ISA_MIPS32
508 #if _MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4 || \
509 _MIPS_ISA == _MIPS_ISA_MIPS64
514 #if defined(__mips_o32) || defined(__mips_o64)
517 #define CPRESTORE(r) .cprestore r
518 #define CPLOAD(r) .cpload r
520 #define CPRESTORE(r) /* not needed */
521 #define CPLOAD(r) /* not needed */
529 #define SETUP_GPX(r) \
532 move r,ra; /* save old ra */ \
538 #define SETUP_GPX_L(r,lbl) \
541 move r,ra; /* save old ra */ \
547 #define SAVE_GP(x) .cprestore x
549 #define SETUP_GP64(a,b) /* n32/n64 specific */
550 #define SETUP_GP64_R(a,b) /* n32/n64 specific */
551 #define SETUP_GPX64(a,b) /* n32/n64 specific */
552 #define SETUP_GPX64_L(a,b,c) /* n32/n64 specific */
553 #define RESTORE_GP64 /* n32/n64 specific */
554 #define USE_ALT_CP(a) /* n32/n64 specific */
555 #endif /* __mips_o32 || __mips_o64 */
557 #if defined(__mips_o32) || defined(__mips_o64)
558 #define REG_PROLOGUE .set push
559 #define REG_EPILOGUE .set pop
561 #if defined(__mips_n32) || defined(__mips_n64)
562 #define REG_PROLOGUE .set push ; .set mips3
563 #define REG_EPILOGUE .set pop
566 #if defined(__mips_n32) || defined(__mips_n64)
567 #define SETUP_GP /* o32 specific */
568 #define SETUP_GPX(r) /* o32 specific */
569 #define SETUP_GPX_L(r,lbl) /* o32 specific */
570 #define SAVE_GP(x) /* o32 specific */
571 #define SETUP_GP64(a,b) .cpsetup $25, a, b
572 #define SETUP_GPX64(a,b) \
579 .cpsetup ra, a, 7b; \
581 #define SETUP_GPX64_L(a,b,c) \
590 #define RESTORE_GP64 .cpreturn
591 #define USE_ALT_CP(a) .cplocal a
592 #endif /* __mips_n32 || __mips_n64 */
595 * The DYNAMIC_STATUS_MASK option adds an additional masking operation
596 * when updating the hardware interrupt mask in the status register.
598 * This is useful for platforms that need to at run-time mask
599 * interrupts based on motherboard configuration or to handle
600 * slowly clearing interrupts.
602 * XXX this is only currently implemented for mips3.
604 #ifdef MIPS_DYNAMIC_STATUS_MASK
605 #define DYNAMIC_STATUS_MASK(sr,scratch) \
606 lw scratch, mips_dynamic_status_mask; \
609 #define DYNAMIC_STATUS_MASK_TOUSER(sr,scratch1) \
610 ori sr, (MIPS_INT_MASK | MIPS_SR_INT_IE); \
611 DYNAMIC_STATUS_MASK(sr,scratch1)
613 #define DYNAMIC_STATUS_MASK(sr,scratch)
614 #define DYNAMIC_STATUS_MASK_TOUSER(sr,scratch1)
617 /* See lock_stubs.S. */
618 #define MIPS_LOCK_RAS_SIZE 128
620 #define CPUVAR(off) _C_LABEL(cpu_info_store)+__CONCAT(CPU_INFO_,off)
622 #endif /* _MIPS_ASM_H */