Home | History | Annotate | Line # | Download | only in include
locore.h revision 1.4
      1  1.4  martin /*	$NetBSD: locore.h,v 1.4 2010/05/23 18:49:14 martin Exp $	*/
      2  1.1     mrg 
      3  1.1     mrg /*
      4  1.1     mrg  * Copyright (c) 1996-2002 Eduardo Horvath
      5  1.1     mrg  * All rights reserved.
      6  1.1     mrg  *
      7  1.1     mrg  * Redistribution and use in source and binary forms, with or without
      8  1.1     mrg  * modification, are permitted provided that the following conditions
      9  1.1     mrg  * are met:
     10  1.1     mrg  * 1. Redistributions of source code must retain the above copyright
     11  1.1     mrg  *    notice, this list of conditions and the following disclaimer.
     12  1.1     mrg  *
     13  1.1     mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR  ``AS IS'' AND
     14  1.1     mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  1.1     mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     16  1.1     mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR  BE LIABLE
     17  1.1     mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     18  1.1     mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     19  1.1     mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     20  1.1     mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     21  1.1     mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     22  1.1     mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     23  1.1     mrg  * SUCH DAMAGE.
     24  1.1     mrg  *
     25  1.1     mrg  */
     26  1.1     mrg 
     27  1.1     mrg #undef	CURLWP
     28  1.1     mrg #undef	CPCB
     29  1.1     mrg #undef	FPLWP
     30  1.1     mrg 
     31  1.1     mrg #define	CURLWP	(CPUINFO_VA + CI_CURLWP)
     32  1.1     mrg #define	CPCB	(CPUINFO_VA + CI_CPCB)
     33  1.1     mrg #define	FPLWP	(CPUINFO_VA + CI_FPLWP)
     34  1.1     mrg 
     35  1.1     mrg /*
     36  1.1     mrg  * Here are some defines to try to maintain consistency but still
     37  1.1     mrg  * support 32-and 64-bit compilers.
     38  1.1     mrg  */
     39  1.1     mrg #ifdef _LP64
     40  1.1     mrg /* reg that points to base of data/text segment */
     41  1.1     mrg #define	BASEREG	%g4
     42  1.1     mrg /* first constants for storage allocation */
     43  1.1     mrg #define LNGSZ		8
     44  1.1     mrg #define LNGSHFT		3
     45  1.1     mrg #define PTRSZ		8
     46  1.1     mrg #define PTRSHFT		3
     47  1.1     mrg #define POINTER		.xword
     48  1.1     mrg #define ULONG		.xword
     49  1.1     mrg /* Now instructions to load/store pointers & long ints */
     50  1.1     mrg #define LDLNG		ldx
     51  1.1     mrg #define LDULNG		ldx
     52  1.1     mrg #define STLNG		stx
     53  1.1     mrg #define STULNG		stx
     54  1.1     mrg #define LDPTR		ldx
     55  1.1     mrg #define LDPTRA		ldxa
     56  1.1     mrg #define STPTR		stx
     57  1.1     mrg #define STPTRA		stxa
     58  1.1     mrg #define	CASPTR		casxa
     59  1.1     mrg /* Now something to calculate the stack bias */
     60  1.1     mrg #define STKB		BIAS
     61  1.1     mrg #define	CCCR		%xcc
     62  1.1     mrg #else
     63  1.1     mrg #define	BASEREG		%g0
     64  1.1     mrg #define LNGSZ		4
     65  1.1     mrg #define LNGSHFT		2
     66  1.1     mrg #define PTRSZ		4
     67  1.1     mrg #define PTRSHFT		2
     68  1.1     mrg #define POINTER		.word
     69  1.1     mrg #define ULONG		.word
     70  1.1     mrg /* Instructions to load/store pointers & long ints */
     71  1.1     mrg #define LDLNG		ldsw
     72  1.1     mrg #define LDULNG		lduw
     73  1.1     mrg #define STLNG		stw
     74  1.1     mrg #define STULNG		stw
     75  1.1     mrg #define LDPTR		lduw
     76  1.1     mrg #define LDPTRA		lduwa
     77  1.1     mrg #define STPTR		stw
     78  1.1     mrg #define STPTRA		stwa
     79  1.1     mrg #define	CASPTR		casa
     80  1.1     mrg #define STKB		0
     81  1.1     mrg #define	CCCR		%icc
     82  1.1     mrg #endif
     83  1.1     mrg 
     84  1.1     mrg /* Give this real authority: reset the machine */
     85  1.1     mrg #define NOTREACHED	sir
     86  1.1     mrg 
     87  1.1     mrg /* if < 32, copy by bytes, memcpy, kcopy, ... */
     88  1.1     mrg #define	BCOPY_SMALL	32
     89  1.3     mrg 
     90  1.3     mrg /* use as needed to align things on longword boundaries */
     91  1.3     mrg #define	_ALIGN	.align 8
     92  1.3     mrg #define ICACHE_ALIGN	.align	32
     93  1.4  martin 
     94  1.4  martin /* A few convenient abbreviations for trapframe fields. */
     95  1.4  martin #define	TF_G	TF_GLOBAL
     96  1.4  martin #define	TF_O	TF_OUT
     97  1.4  martin #define	TF_L	TF_LOCAL
     98  1.4  martin #define	TF_I	TF_IN
     99  1.4  martin 
    100  1.4  martin /* Let us use same syntax as C code */
    101  1.4  martin #define Debugger()	ta	1; nop
    102  1.4  martin 
    103  1.4  martin 
    104  1.4  martin /*
    105  1.4  martin  * This macro will clear out a cache line before an explicit
    106  1.4  martin  * access to that location.  It's mostly used to make certain
    107  1.4  martin  * loads bypassing the D$ do not get stale D$ data.
    108  1.4  martin  *
    109  1.4  martin  * It uses a register with the address to clear and a temporary
    110  1.4  martin  * which is destroyed.
    111  1.4  martin  */
    112  1.4  martin #ifdef DCACHE_BUG
    113  1.4  martin #define DLFLUSH(a,t) \
    114  1.4  martin 	andn	a, 0x3f, t; \
    115  1.4  martin 	stxa	%g0, [ t ] ASI_DCACHE_TAG; \
    116  1.4  martin 	membar	#Sync
    117  1.4  martin /* The following can be used if the pointer is 32-byte aligned */
    118  1.4  martin #define DLFLUSH2(t) \
    119  1.4  martin 	stxa	%g0, [ t ] ASI_DCACHE_TAG; \
    120  1.4  martin 	membar	#Sync
    121  1.4  martin #else
    122  1.4  martin #define DLFLUSH(a,t)
    123  1.4  martin #define DLFLUSH2(t)
    124  1.4  martin #endif
    125  1.4  martin 
    126  1.4  martin 
    127  1.4  martin /*
    128  1.4  martin  * Combine 2 regs -- used to convert 64-bit ILP32
    129  1.4  martin  * values to LP64.
    130  1.4  martin  */
    131  1.4  martin #define	COMBINE(r1, r2, d)	\
    132  1.4  martin 	sllx	r1, 32, d;	\
    133  1.4  martin 	or	d, r2, d
    134  1.4  martin 
    135  1.4  martin /*
    136  1.4  martin  * Split 64-bit value in 1 reg into high and low halves.
    137  1.4  martin  * Used for ILP32 return values.
    138  1.4  martin  */
    139  1.4  martin #define	SPLIT(r0, r1)		\
    140  1.4  martin 	srl	r0, 0, r1;	\
    141  1.4  martin 	srlx	r0, 32, r0
    142  1.4  martin 
    143  1.4  martin 
    144  1.4  martin /*
    145  1.4  martin  * A handy macro for maintaining instrumentation counters.
    146  1.4  martin  * Note that this clobbers %o0, %o1 and %o2.  Normal usage is
    147  1.4  martin  * something like:
    148  1.4  martin  *	foointr:
    149  1.4  martin  *		TRAP_SETUP(...)		! makes %o registers safe
    150  1.4  martin  *		INCR(_C_LABEL(cnt)+V_FOO)	! count a foo
    151  1.4  martin  */
    152  1.4  martin #define INCR(what) \
    153  1.4  martin 	sethi	%hi(what), %o0; \
    154  1.4  martin 	or	%o0, %lo(what), %o0; \
    155  1.4  martin 99:	\
    156  1.4  martin 	lduw	[%o0], %o1; \
    157  1.4  martin 	add	%o1, 1, %o2; \
    158  1.4  martin 	casa	[%o0] ASI_P, %o1, %o2; \
    159  1.4  martin 	cmp	%o1, %o2; \
    160  1.4  martin 	bne,pn	%icc, 99b; \
    161  1.4  martin 	 nop
    162  1.4  martin 
    163  1.4  martin /*
    164  1.4  martin  * A couple of handy macros to save and restore globals to/from
    165  1.4  martin  * locals.  Since udivrem uses several globals, and it's called
    166  1.4  martin  * from vsprintf, we need to do this before and after doing a printf.
    167  1.4  martin  */
    168  1.4  martin #define GLOBTOLOC \
    169  1.4  martin 	mov	%g1, %l1; \
    170  1.4  martin 	mov	%g2, %l2; \
    171  1.4  martin 	mov	%g3, %l3; \
    172  1.4  martin 	mov	%g4, %l4; \
    173  1.4  martin 	mov	%g5, %l5; \
    174  1.4  martin 	mov	%g6, %l6; \
    175  1.4  martin 	mov	%g7, %l7
    176  1.4  martin 
    177  1.4  martin #define LOCTOGLOB \
    178  1.4  martin 	mov	%l1, %g1; \
    179  1.4  martin 	mov	%l2, %g2; \
    180  1.4  martin 	mov	%l3, %g3; \
    181  1.4  martin 	mov	%l4, %g4; \
    182  1.4  martin 	mov	%l5, %g5; \
    183  1.4  martin 	mov	%l6, %g6; \
    184  1.4  martin 	mov	%l7, %g7
    185  1.4  martin 
    186  1.4  martin /* Load strings address into register; NOTE: hidden local label 99 */
    187  1.4  martin #define LOAD_ASCIZ(reg, s)	\
    188  1.4  martin 	set	99f, reg ;	\
    189  1.4  martin 	.data ;			\
    190  1.4  martin 99:	.asciz	s ;		\
    191  1.4  martin 	_ALIGN ;		\
    192  1.4  martin 	.text
    193  1.4  martin 
    194  1.4  martin /*
    195  1.4  martin  * Handy stack conversion macros.
    196  1.4  martin  * They correctly switch to requested stack type
    197  1.4  martin  * regardless of the current stack.
    198  1.4  martin  */
    199  1.4  martin 
    200  1.4  martin #define TO_STACK64(size)					\
    201  1.4  martin 	save	%sp, size, %sp;					\
    202  1.4  martin 	add	%sp, -BIAS, %o0; /* Convert to 64-bits */	\
    203  1.4  martin 	andcc	%sp, 1, %g0; /* 64-bit stack? */		\
    204  1.4  martin 	movz	%icc, %o0, %sp
    205  1.4  martin 
    206  1.4  martin #define TO_STACK32(size)					\
    207  1.4  martin 	save	%sp, size, %sp;					\
    208  1.4  martin 	add	%sp, +BIAS, %o0; /* Convert to 32-bits */	\
    209  1.4  martin 	andcc	%sp, 1, %g0; /* 64-bit stack? */		\
    210  1.4  martin 	movnz	%icc, %o0, %sp
    211  1.4  martin 
    212  1.4  martin #ifdef _LP64
    213  1.4  martin #define	STACKFRAME(size)	TO_STACK64(size)
    214  1.4  martin #else
    215  1.4  martin #define	STACKFRAME(size)	TO_STACK32(size)
    216  1.4  martin #endif
    217  1.4  martin 
    218  1.4  martin /*
    219  1.4  martin  * Primitives
    220  1.4  martin  */
    221  1.4  martin #ifdef ENTRY
    222  1.4  martin #undef ENTRY
    223  1.4  martin #endif
    224  1.4  martin 
    225  1.4  martin #ifdef GPROF
    226  1.4  martin 	.globl	_mcount
    227  1.4  martin #define	ENTRY(x) \
    228  1.4  martin 	.globl _C_LABEL(x); .proc 1; .type _C_LABEL(x),@function; \
    229  1.4  martin _C_LABEL(x): ; \
    230  1.4  martin 	.data; \
    231  1.4  martin 	.align 8; \
    232  1.4  martin 0:	.uaword 0; .uaword 0; \
    233  1.4  martin 	.text;	\
    234  1.4  martin 	save	%sp, -CC64FSZ, %sp; \
    235  1.4  martin 	sethi	%hi(0b), %o0; \
    236  1.4  martin 	call	_mcount; \
    237  1.4  martin 	or	%o0, %lo(0b), %o0; \
    238  1.4  martin 	restore
    239  1.4  martin #else
    240  1.4  martin #define	ENTRY(x)	.globl _C_LABEL(x); .proc 1; \
    241  1.4  martin 	.type _C_LABEL(x),@function; _C_LABEL(x):
    242  1.4  martin #endif
    243  1.4  martin #define	ALTENTRY(x)	.globl _C_LABEL(x); _C_LABEL(x):
    244  1.4  martin 
    245  1.4  martin 
    246