Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.15
      1 /*	$NetBSD: asm.h,v 1.15 1999/01/14 18:45:46 castor 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/regdef.h>
     62 
     63 /*
     64  * Define -pg profile entry code.
     65  * XXX assume .set noreorder for kernel, .set reorder for user code.
     66  */
     67 #define _KERN_MCOUNT		\
     68 	.set	noat;		\
     69 	move	$1,$31;		\
     70 	jal	_mcount;	\
     71 	subu	sp,sp,8;	\
     72 	.set at
     73 
     74 #ifdef GPROF
     75 # if defined(_KERNEL) || defined(_LOCORE)
     76 #  define MCOUNT _KERN_MCOUNT
     77 # else
     78 #  define MCOUNT .set noreorder; _KERN_MCOUNT ;  .set reorder;
     79 # endif
     80 #else
     81 #define	MCOUNT
     82 #endif
     83 
     84 #ifdef __NO_LEADING_UNDERSCORES__
     85 # define _C_LABEL(x)	x
     86 #else
     87 # ifdef __STDC__
     88 #  define _C_LABEL(x)	_ ## x
     89 # else
     90 #  define _C_LABEL(x)	_/**/x
     91 # endif
     92 #endif
     93 
     94 #ifdef USE_AENT
     95 #define AENT(x)				\
     96 	.aent	x, 0
     97 #else
     98 #define AENT(x)
     99 #endif
    100 
    101 /*
    102  * WARN_REFERENCES: create a warning if the specified symbol is referenced
    103  * (ELF only, and thus, no leading underscores).
    104  */
    105 #ifdef __ELF__
    106 #ifdef __STDC__
    107 #define	WARN_REFERENCES(_sym,_msg)				\
    108 	.section .gnu.warning. ## _sym ; .ascii _msg ; .text
    109 #else
    110 #define	WARN_REFERENCES(_sym,_msg)				\
    111 	.section .gnu.warning./**/_sym ; .ascii _msg ; .text
    112 #endif /* __STDC__ */
    113 #endif /* __ELF__ */
    114 
    115 /*
    116  * LEAF
    117  *	A leaf routine does
    118  *	- call no other function,
    119  *	- never use any register that callee-saved (S0-S8), and
    120  *	- not use any local stack storage.
    121  */
    122 #define LEAF(x)				\
    123 	.globl	_C_LABEL(x);		\
    124 	.ent	_C_LABEL(x), 0;		\
    125 _C_LABEL(x): ;				\
    126 	.frame sp, 0, ra;		\
    127 	MCOUNT
    128 
    129 /*
    130  * LEAF_NOPROFILE
    131  *	No profilable leaf routine.
    132  */
    133 #define LEAF_NOPROFILE(x)		\
    134 	.globl	_C_LABEL(x);		\
    135 	.ent	_C_LABEL(x), 0;		\
    136 _C_LABEL(x): ;				\
    137 	.frame	sp, 0, ra
    138 
    139 /*
    140  * XLEAF
    141  *	declare alternate entry to leaf routine
    142  */
    143 #define XLEAF(x)			\
    144 	.globl	_C_LABEL(x);		\
    145 	.aent	_C_LABEL(x),0;		\
    146 _C_LABEL(x):
    147 
    148 /*
    149  * NESTED
    150  *	A function calls other functions and needs
    151  *	therefore stack space to save/restore registers.
    152  */
    153 #define NESTED(x, fsize, retpc)		\
    154 	.globl	_C_LABEL(x);		\
    155 	.ent	_C_LABEL(x), 0; 	\
    156 _C_LABEL(x): ;				\
    157 	.frame	sp, fsize, retpc;	\
    158 	MCOUNT
    159 
    160 /*
    161  * NESTED_NOPROFILE(x)
    162  *	No profilable nested routine.
    163  */
    164 #define NESTED_NOPROFILE(x, fsize, retpc)	\
    165 	.globl	_C_LABEL(x);		\
    166 	.ent	_C_LABEL(x), 0;		\
    167 _C_LABEL(x): ;				\
    168 	.frame	sp, fsize, retpc
    169 
    170 /*
    171  * XNESTED
    172  *	declare alternate entry point to nested routine.
    173  */
    174 #define XNESTED(x)			\
    175 	.globl	_C_LABEL(x);		\
    176 	.aent	_C_LABEL(x),0;		\
    177 _C_LABEL(x):
    178 
    179 /*
    180  * END
    181  *	Mark end of a procedure.
    182  */
    183 #define END(x) \
    184 	.end _C_LABEL(x)
    185 
    186 /*
    187  * IMPORT -- import external symbol
    188  */
    189 #define IMPORT(sym, size)		\
    190 	.extern sym,size
    191 
    192 /*
    193  * EXPORT -- export definition of symbol
    194  */
    195 #define EXPORT(x)			\
    196 	.globl	_C_LABEL(x);		\
    197 _C_LABEL(x):
    198 
    199 /*
    200  * ALIAS
    201  *	Global alias for a function, or alternate entry point
    202  */
    203 #define	ALIAS(x)			\
    204 	.globl	_C_LABEL(x);		\
    205 _C_LABEL(x):
    206 
    207 /*
    208  * Macros to panic and printf from assembly language.
    209  */
    210 #define PANIC(msg)			\
    211 	la	a0, 9f;			\
    212 	jal	_C_LABEL(panic);	\
    213 	MSG(msg)
    214 
    215 #define	PRINTF(msg)			\
    216 	la	a0, 9f;			\
    217 	jal	_C_LABEL(printf);	\
    218 	MSG(msg)
    219 
    220 #define	MSG(msg)			\
    221 	.rdata;				\
    222 9:	.asciiz	msg;			\
    223 	.text
    224 
    225 #define ASMSTR(str)			\
    226 	.asciiz str;			\
    227 	.align	3
    228 
    229 /*
    230  * XXX retain dialects XXX
    231  */
    232 #define ALEAF(x)			\
    233 	.globl _C_LABEL(x);		\
    234 	AENT (_C_LABEL(x))		\
    235 _C_LABEL(x):
    236 
    237 #define NLEAF(x)			\
    238 	.globl _C_LABEL(x); 		\
    239 	.ent _C_LABEL(x), 0;		\
    240 _C_LABEL(x): ; \
    241 	.frame sp, 0, ra
    242 
    243 #define NON_LEAF(x, fsize, retpc)	\
    244 	.globl _C_LABEL(x);		\
    245 	.ent _C_LABEL(x), 0;		\
    246 _C_LABEL(x): ;				\
    247 	.frame sp, fsize, retpc;	\
    248 	MCOUNT
    249 
    250 #define NNON_LEAF(x, fsize, retpc)	\
    251 	.globl _C_LABEL(x);		\
    252 	.ent _C_LABEL(x), 0;		\
    253 _C_LABEL(x): ;				\
    254 	.frame sp, fsize, retpc
    255 
    256 /*
    257  * While it would be nice to be compatible with the SGI
    258  * REG_L and REG_S macros, because they do not take parameters, it
    259  * is impossible to use them with the _MIPS_SIM_ABIX32 model.
    260  *
    261  * These macros hide the use of mips3 instructions from the
    262  * assembler to prevent the assembler from generating 64-bit style
    263  * ABI calls.
    264  */
    265 
    266 #if	defined(_MIPS_BSD_SIM) && _MIPS_BSD_SIM_ != _MIPS_SIM_ABI32
    267 #define	REG_L	ld
    268 #define REG_S	sd
    269 #define	REG_LI	dli
    270 #define	REG_PROLOGUE	.set push ; .set mips3
    271 #define	REG_EPILOGUE	.set pop
    272 #define SZREG	8
    273 #else
    274 #define	REG_L	lw
    275 #define REG_S	sw
    276 #define	REG_LI	li
    277 #define	REG_PROLOGUE	.set push
    278 #define	REG_EPILOGUE	.set pop
    279 #define SZREG	4
    280 #endif	/* _MIPS_BSD_SIM */
    281 
    282 #ifndef _KERNEL
    283 #include <machine/pubassym.h>
    284 #endif
    285 
    286 #endif /* _MIPS_ASM_H */
    287