1 /* $NetBSD: asm.h,v 1.18 1999/02/24 18:36:32 drochner 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 /* 62 * Symbolic register names 63 */ 64 #define zero $0 /* always zero */ 65 #define AT $at /* assembler temporary */ 66 #define v0 $2 /* return value */ 67 #define v1 $3 68 #define a0 $4 /* argument registers */ 69 #define a1 $5 70 #define a2 $6 71 #define a3 $7 72 #define t0 $8 /* temp registers (not saved across subroutine calls) */ 73 #define t1 $9 74 #define t2 $10 75 #define t3 $11 76 #define t4 $12 77 #define t5 $13 78 #define t6 $14 79 #define t7 $15 80 #define s0 $16 /* saved across subroutine calls (callee saved) */ 81 #define s1 $17 82 #define s2 $18 83 #define s3 $19 84 #define s4 $20 85 #define s5 $21 86 #define s6 $22 87 #define s7 $23 88 #define t8 $24 /* two more temporary registers */ 89 #define t9 $25 90 #define k0 $26 /* kernel temporary */ 91 #define k1 $27 92 #define gp $28 /* global pointer */ 93 #define sp $29 /* stack pointer */ 94 #define s8 $30 /* one more callee saved */ 95 #define ra $31 /* return address */ 96 97 /* 98 * Define -pg profile entry code. 99 * XXX assume .set noreorder for kernel, .set reorder for user code. 100 */ 101 #define _KERN_MCOUNT \ 102 .set noat; \ 103 move $1,$31; \ 104 jal _mcount; \ 105 subu sp,sp,8; \ 106 .set at 107 108 #ifdef GPROF 109 # if defined(_KERNEL) || defined(_LOCORE) 110 # define MCOUNT _KERN_MCOUNT 111 # else 112 # define MCOUNT .set noreorder; _KERN_MCOUNT ; .set reorder; 113 # endif 114 #else 115 #define MCOUNT 116 #endif 117 118 #ifdef __NO_LEADING_UNDERSCORES__ 119 # define _C_LABEL(x) x 120 #else 121 # ifdef __STDC__ 122 # define _C_LABEL(x) _ ## x 123 # else 124 # define _C_LABEL(x) _/**/x 125 # define _END_LABEL(x) x/**/End 126 # endif 127 #endif 128 129 #ifdef __STDC__ 130 # define _END_LABEL(x) x ## End 131 #else 132 # define _END_LABEL(x) x/**/End 133 #endif 134 135 #ifdef USE_AENT 136 #define AENT(x) \ 137 .aent x, 0 138 #else 139 #define AENT(x) 140 #endif 141 142 /* 143 * WARN_REFERENCES: create a warning if the specified symbol is referenced 144 * (ELF only, and thus, no leading underscores). 145 */ 146 #ifdef __ELF__ 147 #ifdef __STDC__ 148 #define WARN_REFERENCES(_sym,_msg) \ 149 .section .gnu.warning. ## _sym ; .ascii _msg ; .text 150 #else 151 #define WARN_REFERENCES(_sym,_msg) \ 152 .section .gnu.warning./**/_sym ; .ascii _msg ; .text 153 #endif /* __STDC__ */ 154 #endif /* __ELF__ */ 155 156 /* 157 * LEAF 158 * A leaf routine does 159 * - call no other function, 160 * - never use any register that callee-saved (S0-S8), and 161 * - not use any local stack storage. 162 */ 163 #define LEAF(x) \ 164 .globl _C_LABEL(x); \ 165 .ent _C_LABEL(x), 0; \ 166 _C_LABEL(x): ; \ 167 .frame sp, 0, ra; \ 168 MCOUNT 169 170 /* 171 * LEAF_NOPROFILE 172 * No profilable leaf routine. 173 */ 174 #define LEAF_NOPROFILE(x) \ 175 .globl _C_LABEL(x); \ 176 .ent _C_LABEL(x), 0; \ 177 _C_LABEL(x): ; \ 178 .frame sp, 0, ra 179 180 /* 181 * XLEAF 182 * declare alternate entry to leaf routine 183 */ 184 #define XLEAF(x) \ 185 .globl _C_LABEL(x); \ 186 .aent _C_LABEL(x),0; \ 187 _C_LABEL(x): 188 189 /* 190 * NESTED 191 * A function calls other functions and needs 192 * therefore stack space to save/restore registers. 193 */ 194 #define NESTED(x, fsize, retpc) \ 195 .globl _C_LABEL(x); \ 196 .ent _C_LABEL(x), 0; \ 197 _C_LABEL(x): ; \ 198 .frame sp, fsize, retpc; \ 199 MCOUNT 200 201 /* 202 * NESTED_NOPROFILE(x) 203 * No profilable nested routine. 204 */ 205 #define NESTED_NOPROFILE(x, fsize, retpc) \ 206 .globl _C_LABEL(x); \ 207 .ent _C_LABEL(x), 0; \ 208 _C_LABEL(x): ; \ 209 .frame sp, fsize, retpc 210 211 /* 212 * XNESTED 213 * declare alternate entry point to nested routine. 214 */ 215 #define XNESTED(x) \ 216 .globl _C_LABEL(x); \ 217 .aent _C_LABEL(x),0; \ 218 _C_LABEL(x): 219 220 /* 221 * END 222 * Mark end of a procedure. 223 */ 224 #define END(x) \ 225 .end _C_LABEL(x) 226 227 /* 228 * IMPORT -- import external symbol 229 */ 230 #define IMPORT(sym, size) \ 231 .extern sym,size 232 233 /* 234 * EXPORT -- export definition of symbol 235 */ 236 #define EXPORT(x) \ 237 .globl _C_LABEL(x); \ 238 _C_LABEL(x): 239 240 /* 241 * ALIAS 242 * Global alias for a function, or alternate entry point 243 */ 244 #define ALIAS(x) \ 245 .globl _C_LABEL(x); \ 246 _C_LABEL(x): 247 248 /* 249 * VECTOR 250 * exception vector entrypoint 251 */ 252 #define VECTOR(x, regmask) \ 253 .ent _C_LABEL(x),0; \ 254 EXPORT(x); \ 255 256 #define VECTOR_END(x) \ 257 .end _C_LABEL(x); \ 258 EXPORT(_END_LABEL(x)) 259 260 /* 261 * Macros to panic and printf from assembly language. 262 */ 263 #define PANIC(msg) \ 264 la a0, 9f; \ 265 jal _C_LABEL(panic); \ 266 MSG(msg) 267 268 #define PRINTF(msg) \ 269 la a0, 9f; \ 270 jal _C_LABEL(printf); \ 271 MSG(msg) 272 273 #define MSG(msg) \ 274 .rdata; \ 275 9: .asciiz msg; \ 276 .text 277 278 #define ASMSTR(str) \ 279 .asciiz str; \ 280 .align 3 281 282 /* 283 * XXX retain dialects XXX 284 */ 285 #define ALEAF(x) \ 286 .globl _C_LABEL(x); \ 287 AENT (_C_LABEL(x)) \ 288 _C_LABEL(x): 289 290 #define NLEAF(x) \ 291 .globl _C_LABEL(x); \ 292 .ent _C_LABEL(x), 0; \ 293 _C_LABEL(x): ; \ 294 .frame sp, 0, ra 295 296 #define NON_LEAF(x, fsize, retpc) \ 297 .globl _C_LABEL(x); \ 298 .ent _C_LABEL(x), 0; \ 299 _C_LABEL(x): ; \ 300 .frame sp, fsize, retpc; \ 301 MCOUNT 302 303 #define NNON_LEAF(x, fsize, retpc) \ 304 .globl _C_LABEL(x); \ 305 .ent _C_LABEL(x), 0; \ 306 _C_LABEL(x): ; \ 307 .frame sp, fsize, retpc 308 309 /* 310 * standard callframe { 311 * register_t cf_args[4]; arg0 - arg3 312 * register_t cf_sp; frame pointer 313 * register_t cf_ra; return address 314 * }; 315 */ 316 #define CALLFRAME_SIZ (4 * (4 + 2)) 317 #define CALLFRAME_SP (4 * 4) 318 #define CALLFRAME_RA (4 * 5) 319 320 /* 321 * While it would be nice to be compatible with the SGI 322 * REG_L and REG_S macros, because they do not take parameters, it 323 * is impossible to use them with the _MIPS_SIM_ABIX32 model. 324 * 325 * These macros hide the use of mips3 instructions from the 326 * assembler to prevent the assembler from generating 64-bit style 327 * ABI calls. 328 */ 329 330 #if !defined(_MIPS_BSD_API) || _MIPS_BSD_API == _MIPS_BSD_API_LP32 331 #define REG_L lw 332 #define REG_S sw 333 #define REG_LI li 334 #define REG_PROLOGUE .set push 335 #define REG_EPILOGUE .set pop 336 #define SZREG 4 337 #else 338 #define REG_L ld 339 #define REG_S sd 340 #define REG_LI dli 341 #define REG_PROLOGUE .set push ; .set mips3 342 #define REG_EPILOGUE .set pop 343 #define SZREG 8 344 #endif /* _MIPS_BSD_API */ 345 346 #endif /* _MIPS_ASM_H */ 347