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