Home | History | Annotate | Line # | Download | only in include
      1 /*	$NetBSD: locore.h,v 1.9 2015/10/17 19:29:48 nakayama 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 /* A few convenient abbreviations for trapframe fields. */
     36 #define	TF_G	TF_GLOBAL
     37 #define	TF_O	TF_OUT
     38 #define	TF_L	TF_LOCAL
     39 #define	TF_I	TF_IN
     40 
     41 /* Let us use same syntax as C code */
     42 #define Debugger()	ta	1; nop
     43 
     44 
     45 /*
     46  * This macro will clear out a cache line before an explicit
     47  * access to that location.  It's mostly used to make certain
     48  * loads bypassing the D$ do not get stale D$ data.
     49  *
     50  * It uses a register with the address to clear and a temporary
     51  * which is destroyed.
     52  */
     53 #ifdef DCACHE_BUG
     54 #define DLFLUSH(a,t) \
     55 	andn	a, 0x3f, t; \
     56 	stxa	%g0, [ t ] ASI_DCACHE_TAG; \
     57 	membar	#Sync
     58 /* The following can be used if the pointer is 32-byte aligned */
     59 #define DLFLUSH2(t) \
     60 	stxa	%g0, [ t ] ASI_DCACHE_TAG; \
     61 	membar	#Sync
     62 #else
     63 #define DLFLUSH(a,t)
     64 #define DLFLUSH2(t)
     65 #endif
     66 
     67 
     68 /*
     69  * A handy macro for maintaining instrumentation counters.
     70  * Note that this clobbers %o0, %o1 and %o2.  Normal usage is
     71  * something like:
     72  *	foointr:
     73  *		TRAP_SETUP(...)		! makes %o registers safe
     74  *		INCR(_C_LABEL(cnt)+V_FOO)	! count a foo
     75  */
     76 #define INCR(what) \
     77 	sethi	%hi(what), %o0; \
     78 	or	%o0, %lo(what), %o0; \
     79 99:	\
     80 	lduw	[%o0], %o1; \
     81 	add	%o1, 1, %o2; \
     82 	casa	[%o0] ASI_P, %o1, %o2; \
     83 	cmp	%o1, %o2; \
     84 	bne,pn	%icc, 99b; \
     85 	 nop
     86 
     87 /*
     88  * A couple of handy macros to save and restore globals to/from
     89  * locals.  Since udivrem uses several globals, and it's called
     90  * from vsprintf, we need to do this before and after doing a printf.
     91  */
     92 #define GLOBTOLOC \
     93 	mov	%g1, %l1; \
     94 	mov	%g2, %l2; \
     95 	mov	%g3, %l3; \
     96 	mov	%g4, %l4; \
     97 	mov	%g5, %l5; \
     98 	mov	%g6, %l6; \
     99 	mov	%g7, %l7
    100 
    101 #define LOCTOGLOB \
    102 	mov	%l1, %g1; \
    103 	mov	%l2, %g2; \
    104 	mov	%l3, %g3; \
    105 	mov	%l4, %g4; \
    106 	mov	%l5, %g5; \
    107 	mov	%l6, %g6; \
    108 	mov	%l7, %g7
    109 
    110 /* Load strings address into register; NOTE: hidden local label 99 */
    111 #define LOAD_ASCIZ(reg, s)	\
    112 	set	99f, reg ;	\
    113 	.data ;			\
    114 99:	.asciz	s ;		\
    115 	_ALIGN ;		\
    116 	.text
    117 
    118 /*
    119  * Handy stack conversion macros.
    120  * They correctly switch to requested stack type
    121  * regardless of the current stack.
    122  */
    123 
    124 #define TO_STACK64(size)					\
    125 	save	%sp, size, %sp;					\
    126 	add	%sp, -BIAS, %o0; /* Convert to 64-bits */	\
    127 	andcc	%sp, 1, %g0; /* 64-bit stack? */		\
    128 	movz	%icc, %o0, %sp
    129 
    130 #define TO_STACK32(size)					\
    131 	save	%sp, size, %sp;					\
    132 	add	%sp, +BIAS, %o0; /* Convert to 32-bits */	\
    133 	andcc	%sp, 1, %g0; /* 64-bit stack? */		\
    134 	movnz	%icc, %o0, %sp
    135 
    136 #ifdef _LP64
    137 #define	STACKFRAME(size)	TO_STACK64(size)
    138 #else
    139 #define	STACKFRAME(size)	TO_STACK32(size)
    140 #endif
    141 
    142 /*
    143  * Primitives
    144  */
    145 #ifdef ENTRY
    146 #undef ENTRY
    147 #endif
    148 
    149 #ifdef GPROF
    150 	.globl	_mcount
    151 #define	ENTRY(x) \
    152 	.globl _C_LABEL(x); .type _C_LABEL(x),@function; \
    153 _C_LABEL(x): ; \
    154 	.data; \
    155 	.align 8; \
    156 0:	.word 0; .word 0; \
    157 	.text;	\
    158 	save	%sp, -CC64FSZ, %sp; \
    159 	sethi	%hi(0b), %o0; \
    160 	call	_mcount; \
    161 	or	%o0, %lo(0b), %o0; \
    162 	restore
    163 #else
    164 #define	ENTRY(x)	.globl _C_LABEL(x); .type _C_LABEL(x),@function; \
    165 	_C_LABEL(x):
    166 #endif
    167 #define	ALTENTRY(x)	.globl _C_LABEL(x); _C_LABEL(x):
    168 
    169 
    170