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