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