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