Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.39
      1 /*	$NetBSD: asm.h,v 1.39 2007/05/17 14:51:22 yamt 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  * STRONG_ALIAS: create a strong alias.
    112  */
    113 #define STRONG_ALIAS(alias,sym)						\
    114 	.globl alias;							\
    115 	alias = sym
    116 
    117 /*
    118  * WARN_REFERENCES: create a warning if the specified symbol is referenced.
    119  */
    120 #ifdef __STDC__
    121 #define	WARN_REFERENCES(_sym,_msg)				\
    122 	.section .gnu.warning. ## _sym ; .ascii _msg ; .text
    123 #else
    124 #define	WARN_REFERENCES(_sym,_msg)				\
    125 	.section .gnu.warning./**/_sym ; .ascii _msg ; .text
    126 #endif /* __STDC__ */
    127 
    128 /*
    129  * LEAF
    130  *	A leaf routine does
    131  *	- call no other function,
    132  *	- never use any register that callee-saved (S0-S8), and
    133  *	- not use any local stack storage.
    134  */
    135 #define LEAF(x)				\
    136 	.globl	_C_LABEL(x);		\
    137 	.ent	_C_LABEL(x), 0;		\
    138 _C_LABEL(x): ;				\
    139 	.frame sp, 0, ra;		\
    140 	MCOUNT
    141 
    142 /*
    143  * LEAF_NOPROFILE
    144  *	No profilable leaf routine.
    145  */
    146 #define LEAF_NOPROFILE(x)		\
    147 	.globl	_C_LABEL(x);		\
    148 	.ent	_C_LABEL(x), 0;		\
    149 _C_LABEL(x): ;				\
    150 	.frame	sp, 0, ra
    151 
    152 /*
    153  * STATIC_LEAF
    154  *	Declare a local leaf function.
    155  */
    156 #define STATIC_LEAF(x)			\
    157 	.ent	_C_LABEL(x), 0;		\
    158 _C_LABEL(x): ;				\
    159 	.frame sp, 0, ra;		\
    160 	MCOUNT
    161 
    162 /*
    163  * XLEAF
    164  *	declare alternate entry to leaf routine
    165  */
    166 #define XLEAF(x)			\
    167 	.globl	_C_LABEL(x);		\
    168 	AENT (_C_LABEL(x));		\
    169 _C_LABEL(x):
    170 
    171 /*
    172  * STATIC_XLEAF
    173  *	declare alternate entry to a static leaf routine
    174  */
    175 #define STATIC_XLEAF(x)			\
    176 	AENT (_C_LABEL(x));		\
    177 _C_LABEL(x):
    178 
    179 /*
    180  * NESTED
    181  *	A function calls other functions and needs
    182  *	therefore stack space to save/restore registers.
    183  */
    184 #define NESTED(x, fsize, retpc)		\
    185 	.globl	_C_LABEL(x);		\
    186 	.ent	_C_LABEL(x), 0; 	\
    187 _C_LABEL(x): ;				\
    188 	.frame	sp, fsize, retpc;	\
    189 	MCOUNT
    190 
    191 /*
    192  * NESTED_NOPROFILE(x)
    193  *	No profilable nested routine.
    194  */
    195 #define NESTED_NOPROFILE(x, fsize, retpc)	\
    196 	.globl	_C_LABEL(x);		\
    197 	.ent	_C_LABEL(x), 0;		\
    198 _C_LABEL(x): ;				\
    199 	.frame	sp, fsize, retpc
    200 
    201 /*
    202  * XNESTED
    203  *	declare alternate entry point to nested routine.
    204  */
    205 #define XNESTED(x)			\
    206 	.globl	_C_LABEL(x);		\
    207 	AENT (_C_LABEL(x));		\
    208 _C_LABEL(x):
    209 
    210 /*
    211  * END
    212  *	Mark end of a procedure.
    213  */
    214 #define END(x) \
    215 	.end _C_LABEL(x)
    216 
    217 /*
    218  * IMPORT -- import external symbol
    219  */
    220 #define IMPORT(sym, size)		\
    221 	.extern _C_LABEL(sym),size
    222 
    223 /*
    224  * EXPORT -- export definition of symbol
    225  */
    226 #define EXPORT(x)			\
    227 	.globl	_C_LABEL(x);		\
    228 _C_LABEL(x):
    229 
    230 /*
    231  * VECTOR
    232  *	exception vector entrypoint
    233  *	XXX: regmask should be used to generate .mask
    234  */
    235 #define VECTOR(x, regmask)		\
    236 	.ent	_C_LABEL(x),0;		\
    237 	EXPORT(x);			\
    238 
    239 #ifdef __STDC__
    240 #define VECTOR_END(x)			\
    241 	EXPORT(x ## End);		\
    242 	END(x)
    243 #else
    244 #define VECTOR_END(x)			\
    245 	EXPORT(x/**/End);		\
    246 	END(x)
    247 #endif
    248 
    249 /*
    250  * Macros to panic and printf from assembly language.
    251  */
    252 #define PANIC(msg)			\
    253 	la	a0, 9f;			\
    254 	jal	_C_LABEL(panic);	\
    255 	nop;				\
    256 	MSG(msg)
    257 
    258 #define	PRINTF(msg)			\
    259 	la	a0, 9f;			\
    260 	jal	_C_LABEL(printf);	\
    261 	nop;				\
    262 	MSG(msg)
    263 
    264 #define	MSG(msg)			\
    265 	.rdata;				\
    266 9:	.asciiz	msg;			\
    267 	.text
    268 
    269 #define ASMSTR(str)			\
    270 	.asciiz str;			\
    271 	.align	3
    272 
    273 /*
    274  * XXX retain dialects XXX
    275  */
    276 #define ALEAF(x)			XLEAF(x)
    277 #define NLEAF(x)			LEAF_NOPROFILE(x)
    278 #define NON_LEAF(x, fsize, retpc)	NESTED(x, fsize, retpc)
    279 #define NNON_LEAF(x, fsize, retpc)	NESTED_NOPROFILE(x, fsize, retpc)
    280 
    281 /*
    282  *  standard callframe {
    283  *  	register_t cf_args[4];		arg0 - arg3
    284  *  	register_t cf_sp;		frame pointer
    285  *  	register_t cf_ra;		return address
    286  *  };
    287  */
    288 #define	CALLFRAME_SIZ	(4 * (4 + 2))
    289 #define	CALLFRAME_SP	(4 * 4)
    290 #define	CALLFRAME_RA	(4 * 5)
    291 
    292 /*
    293  * While it would be nice to be compatible with the SGI
    294  * REG_L and REG_S macros, because they do not take parameters, it
    295  * is impossible to use them with the _MIPS_SIM_ABIX32 model.
    296  *
    297  * These macros hide the use of mips3 instructions from the
    298  * assembler to prevent the assembler from generating 64-bit style
    299  * ABI calls.
    300  */
    301 
    302 #if !defined(_MIPS_BSD_API) || _MIPS_BSD_API == _MIPS_BSD_API_LP32
    303 #define	REG_L	lw
    304 #define REG_S	sw
    305 #define	REG_LI	li
    306 #define	REG_PROLOGUE	.set push
    307 #define	REG_EPILOGUE	.set pop
    308 #define SZREG	4
    309 #else
    310 #define	REG_L	ld
    311 #define REG_S	sd
    312 #define	REG_LI	dli
    313 #define	REG_PROLOGUE	.set push ; .set mips3
    314 #define	REG_EPILOGUE	.set pop
    315 #define SZREG	8
    316 #endif	/* _MIPS_BSD_API */
    317 
    318 /*
    319  * The DYNAMIC_STATUS_MASK option adds an additional masking operation
    320  * when updating the hardware interrupt mask in the status register.
    321  *
    322  * This is useful for platforms that need to at run-time mask
    323  * interrupts based on motherboard configuration or to handle
    324  * slowly clearing interrupts.
    325  *
    326  * XXX this is only currently implemented for mips3.
    327  */
    328 #ifdef MIPS_DYNAMIC_STATUS_MASK
    329 #define DYNAMIC_STATUS_MASK(sr,scratch)	\
    330 	lw	scratch, mips_dynamic_status_mask; \
    331 	and	sr, sr, scratch
    332 
    333 #define DYNAMIC_STATUS_MASK_TOUSER(sr,scratch1)		\
    334 	ori	sr, (MIPS_INT_MASK | MIPS_SR_INT_IE);	\
    335 	DYNAMIC_STATUS_MASK(sr,scratch1)
    336 #else
    337 #define DYNAMIC_STATUS_MASK(sr,scratch)
    338 #define DYNAMIC_STATUS_MASK_TOUSER(sr,scratch1)
    339 #endif
    340 
    341 /* See lock_stubs.S. */
    342 #define	MIPS_LOCK_RAS_SIZE	128
    343 
    344 #define CPUVAR(off) _C_LABEL(cpu_info_store)+__CONCAT(CPU_INFO_,off)
    345 
    346 #endif /* _MIPS_ASM_H */
    347