Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.13.10.3
      1 /*	$NetBSD: asm.h,v 1.13.10.3 1998/12/06 21:02:49 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 # endif
    126 #endif
    127 
    128 #ifdef USE_AENT
    129 #define AENT(x)				\
    130 	.aent	x, 0
    131 #else
    132 #define AENT(x)
    133 #endif
    134 
    135 /*
    136  * WARN_REFERENCES: create a warning if the specified symbol is referenced
    137  * (ELF only, and thus, no leading underscores).
    138  */
    139 #ifdef __ELF__
    140 #ifdef __STDC__
    141 #define	WARN_REFERENCES(_sym,_msg)				\
    142 	.section .gnu.warning. ## _sym ; .ascii _msg ; .text
    143 #else
    144 #define	WARN_REFERENCES(_sym,_msg)				\
    145 	.section .gnu.warning./**/_sym ; .ascii _msg ; .text
    146 #endif /* __STDC__ */
    147 #endif /* __ELF__ */
    148 
    149 /*
    150  * LEAF
    151  *	A leaf routine does
    152  *	- call no other function,
    153  *	- never use any register that callee-saved (S0-S8), and
    154  *	- not use any local stack storage.
    155  */
    156 #define LEAF(x)				\
    157 	.globl	_C_LABEL(x);		\
    158 	.ent	_C_LABEL(x), 0;		\
    159 _C_LABEL(x): ;				\
    160 	.frame sp, 0, ra;		\
    161 	MCOUNT
    162 
    163 /*
    164  * LEAF_NOPROFILE
    165  *	No profilable leaf routine.
    166  */
    167 #define LEAF_NOPROFILE(x)		\
    168 	.globl	_C_LABEL(x);		\
    169 	.ent	_C_LABEL(x), 0;		\
    170 _C_LABEL(x): ;				\
    171 	.frame	sp, 0, ra
    172 
    173 /*
    174  * XLEAF
    175  *	declare alternate entry to leaf routine
    176  */
    177 #define XLEAF(x)			\
    178 	.globl	_C_LABEL(x);		\
    179 	.aent	_C_LABEL(x),0;		\
    180 _C_LABEL(x):
    181 
    182 /*
    183  * NESTED
    184  *	A function calls other functions and needs
    185  *	therefore stack space to save/restore registers.
    186  */
    187 #define NESTED(x, fsize, retpc)		\
    188 	.globl	_C_LABEL(x);		\
    189 	.ent	_C_LABEL(x), 0; 	\
    190 _C_LABEL(x): ;				\
    191 	.frame	sp, fsize, retpc;	\
    192 	MCOUNT
    193 
    194 /*
    195  * NESTED_NOPROFILE(x)
    196  *	No profilable nested routine.
    197  */
    198 #define NESTED_NOPROFILE(x, fsize, retpc)	\
    199 	.globl	_C_LABEL(x);		\
    200 	.ent	_C_LABEL(x), 0;		\
    201 _C_LABEL(x): ;				\
    202 	.frame	sp, fsize, retpc
    203 
    204 /*
    205  * XNESTED
    206  *	declare alternate entry point to nested routine.
    207  */
    208 #define XNESTED(x)			\
    209 	.globl	_C_LABEL(x);		\
    210 	.aent	_C_LABEL(x),0;		\
    211 _C_LABEL(x):
    212 
    213 /*
    214  * END
    215  *	Mark end of a procedure.
    216  */
    217 #define END(x) \
    218 	.end _C_LABEL(x)
    219 
    220 /*
    221  * IMPORT -- import external symbol
    222  */
    223 #define IMPORT(sym, size)		\
    224 	.extern sym,size
    225 
    226 /*
    227  * EXPORT -- export definition of symbol
    228  */
    229 #define EXPORT(x)			\
    230 	.globl	_C_LABEL(x);		\
    231 _C_LABEL(x):
    232 
    233 /*
    234  * ALIAS
    235  *	Global alias for a function, or alternate entry point
    236  */
    237 #define	ALIAS(x)			\
    238 	.globl	_C_LABEL(x);		\
    239 _C_LABEL(x):
    240 
    241 /*
    242  * Macros to panic and printf from assembly language.
    243  */
    244 #define PANIC(msg)			\
    245 	la	a0, 9f;			\
    246 	jal	_C_LABEL(panic);	\
    247 	MSG(msg)
    248 
    249 #define	PRINTF(msg)			\
    250 	la	a0, 9f;			\
    251 	jal	_C_LABEL(printf);	\
    252 	MSG(msg)
    253 
    254 #define	MSG(msg)			\
    255 	.rdata;				\
    256 9:	.asciiz	msg;			\
    257 	.text
    258 
    259 #define ASMSTR(str)			\
    260 	.asciiz str;			\
    261 	.align	3
    262 
    263 /*
    264  * XXX retain dialects XXX
    265  */
    266 #define ALEAF(x)			\
    267 	.globl _C_LABEL(x);		\
    268 	AENT (_C_LABEL(x))		\
    269 _C_LABEL(x):
    270 
    271 #define NLEAF(x)			\
    272 	.globl _C_LABEL(x); 		\
    273 	.ent _C_LABEL(x), 0;		\
    274 _C_LABEL(x): ; \
    275 	.frame sp, 0, ra
    276 
    277 #define NON_LEAF(x, fsize, retpc)	\
    278 	.globl _C_LABEL(x);		\
    279 	.ent _C_LABEL(x), 0;		\
    280 _C_LABEL(x): ;				\
    281 	.frame sp, fsize, retpc;	\
    282 	MCOUNT
    283 
    284 #define NNON_LEAF(x, fsize, retpc)	\
    285 	.globl _C_LABEL(x);		\
    286 	.ent _C_LABEL(x), 0;		\
    287 _C_LABEL(x): ;				\
    288 	.frame sp, fsize, retpc
    289 
    290 #endif /* _MIPS_ASM_H */
    291