xref: /netbsd-src/common/lib/libc/arch/sparc64/string/strmacros.h (revision ca8f29b6bf953eda3addd5415ebb64e0dcfcd44d)
1*ca8f29b6Schristos /*	$NetBSD: strmacros.h,v 1.1 2013/03/17 00:42:32 christos Exp $	*/
2*ca8f29b6Schristos 
3*ca8f29b6Schristos /*
4*ca8f29b6Schristos  * Copyright (c) 1996-2002 Eduardo Horvath
5*ca8f29b6Schristos  * All rights reserved.
6*ca8f29b6Schristos  *
7*ca8f29b6Schristos  * Redistribution and use in source and binary forms, with or without
8*ca8f29b6Schristos  * modification, are permitted provided that the following conditions
9*ca8f29b6Schristos  * are met:
10*ca8f29b6Schristos  * 1. Redistributions of source code must retain the above copyright
11*ca8f29b6Schristos  *notice, this list of conditions and the following disclaimer.
12*ca8f29b6Schristos  *
13*ca8f29b6Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR  ``AS IS'' AND
14*ca8f29b6Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15*ca8f29b6Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*ca8f29b6Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR  BE LIABLE
17*ca8f29b6Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18*ca8f29b6Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19*ca8f29b6Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20*ca8f29b6Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21*ca8f29b6Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*ca8f29b6Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*ca8f29b6Schristos  * SUCH DAMAGE.
24*ca8f29b6Schristos  *
25*ca8f29b6Schristos  */
26*ca8f29b6Schristos 
27*ca8f29b6Schristos #include <machine/asm.h>
28*ca8f29b6Schristos #if defined(_KERNEL) && !defined(_RUMPKERNEL)
29*ca8f29b6Schristos #define USE_BLOCK_STORE_LOAD	/* enable block load/store ops */
30*ca8f29b6Schristos #include "assym.h"
31*ca8f29b6Schristos #include <machine/param.h>
32*ca8f29b6Schristos #include <machine/ctlreg.h>
33*ca8f29b6Schristos #include <machine/psl.h>
34*ca8f29b6Schristos #include <machine/frame.h>
35*ca8f29b6Schristos #include <machine/intr.h>
36*ca8f29b6Schristos #include <machine/locore.h>
37*ca8f29b6Schristos 
38*ca8f29b6Schristos #ifdef USE_BLOCK_STORE_LOAD
39*ca8f29b6Schristos 
40*ca8f29b6Schristos #define BLOCK_SIZE SPARC64_BLOCK_SIZE
41*ca8f29b6Schristos #define BLOCK_ALIGN SPARC64_BLOCK_ALIGN
42*ca8f29b6Schristos 
43*ca8f29b6Schristos /*
44*ca8f29b6Schristos  * The following routines allow fpu use in the kernel.
45*ca8f29b6Schristos  *
46*ca8f29b6Schristos  * They allocate a stack frame and use all local regs.	Extra
47*ca8f29b6Schristos  * local storage can be requested by setting the siz parameter,
48*ca8f29b6Schristos  * and can be accessed at %sp+CC64FSZ.
49*ca8f29b6Schristos  */
50*ca8f29b6Schristos 
51*ca8f29b6Schristos #define ENABLE_FPU(siz)							\
52*ca8f29b6Schristos 	save	%sp, -(CC64FSZ), %sp;	/* Allocate a stack frame */	\
53*ca8f29b6Schristos 	sethi	%hi(FPLWP), %l1;					\
54*ca8f29b6Schristos 	add	%fp, STKB-FS_SIZE, %l0;		/* Allocate a fpstate */\
55*ca8f29b6Schristos 	LDPTR	[%l1 + %lo(FPLWP)], %l2;	/* Load fplwp */	\
56*ca8f29b6Schristos 	andn	%l0, BLOCK_ALIGN, %l0;		/* Align it */		\
57*ca8f29b6Schristos 	clr	%l3;				/* NULL fpstate */	\
58*ca8f29b6Schristos 	brz,pt	%l2, 1f;			/* fplwp == NULL? */	\
59*ca8f29b6Schristos 	 add	%l0, -STKB-CC64FSZ-(siz), %sp;	/* Set proper %sp */	\
60*ca8f29b6Schristos 	LDPTR	[%l2 + L_FPSTATE], %l3;					\
61*ca8f29b6Schristos 	brz,pn	%l3, 1f;	/* Make sure we have an fpstate */	\
62*ca8f29b6Schristos 	 mov	%l3, %o0;						\
63*ca8f29b6Schristos 	call	_C_LABEL(savefpstate);	/* Save the old fpstate */	\
64*ca8f29b6Schristos 1:									\
65*ca8f29b6Schristos 	 set	EINTSTACK-STKB, %l4;	/* Are we on intr stack? */	\
66*ca8f29b6Schristos 	cmp	%sp, %l4;						\
67*ca8f29b6Schristos 	bgu,pt	%xcc, 1f;						\
68*ca8f29b6Schristos 	 set	INTSTACK-STKB, %l4;					\
69*ca8f29b6Schristos 	cmp	%sp, %l4;						\
70*ca8f29b6Schristos 	blu	%xcc, 1f;						\
71*ca8f29b6Schristos 0:									\
72*ca8f29b6Schristos 	 sethi	%hi(_C_LABEL(lwp0)), %l4;	/* Yes, use lpw0 */	\
73*ca8f29b6Schristos 	ba,pt	%xcc, 2f; /* XXXX needs to change to CPUs idle proc */	\
74*ca8f29b6Schristos 	 or	%l4, %lo(_C_LABEL(lwp0)), %l5;				\
75*ca8f29b6Schristos 1:									\
76*ca8f29b6Schristos 	sethi	%hi(CURLWP), %l4;		/* Use curlwp */	\
77*ca8f29b6Schristos 	LDPTR	[%l4 + %lo(CURLWP)], %l5;				\
78*ca8f29b6Schristos 	brz,pn	%l5, 0b; nop;	/* If curlwp is NULL need to use lwp0 */\
79*ca8f29b6Schristos 2:									\
80*ca8f29b6Schristos 	LDPTR	[%l5 + L_FPSTATE], %l6;		/* Save old fpstate */	\
81*ca8f29b6Schristos 	STPTR	%l0, [%l5 + L_FPSTATE];		/* Insert new fpstate */\
82*ca8f29b6Schristos 	STPTR	%l5, [%l1 + %lo(FPLWP)];	/* Set new fplwp */	\
83*ca8f29b6Schristos 	wr	%g0, FPRS_FEF, %fprs		/* Enable FPU */
84*ca8f29b6Schristos 
85*ca8f29b6Schristos /*
86*ca8f29b6Schristos  * Weve saved our possible fpstate, now disable the fpu
87*ca8f29b6Schristos  * and continue with life.
88*ca8f29b6Schristos  */
89*ca8f29b6Schristos #ifdef DEBUG
90*ca8f29b6Schristos #define __CHECK_FPU				\
91*ca8f29b6Schristos 	LDPTR	[%l5 + L_FPSTATE], %l7;		\
92*ca8f29b6Schristos 	cmp	%l7, %l0;			\
93*ca8f29b6Schristos 	tnz	1;
94*ca8f29b6Schristos #else
95*ca8f29b6Schristos #define __CHECK_FPU
96*ca8f29b6Schristos #endif
97*ca8f29b6Schristos 
98*ca8f29b6Schristos #define RESTORE_FPU							 \
99*ca8f29b6Schristos 	__CHECK_FPU							 \
100*ca8f29b6Schristos 	STPTR	%l2, [%l1 + %lo(FPLWP)];	/* Restore old fproc */	 \
101*ca8f29b6Schristos 	wr	%g0, 0, %fprs;			/* Disable fpu */	 \
102*ca8f29b6Schristos 	brz,pt	%l3, 1f;			/* Skip if no fpstate */ \
103*ca8f29b6Schristos 	 STPTR	%l6, [%l5 + L_FPSTATE];		/* Restore old fpstate */\
104*ca8f29b6Schristos 									 \
105*ca8f29b6Schristos 	mov	%l3, %o0;						 \
106*ca8f29b6Schristos 	call	_C_LABEL(loadfpstate);		/* Reload orig fpstate */\
107*ca8f29b6Schristos 1: 									 \
108*ca8f29b6Schristos 	 membar #Sync;				/* Finish all FP ops */
109*ca8f29b6Schristos 
110*ca8f29b6Schristos #endif	/* USE_BLOCK_STORE_LOAD */
111*ca8f29b6Schristos 
112*ca8f29b6Schristos #ifdef USE_BLOCK_STORE_LOAD
113*ca8f29b6Schristos #if 0
114*ca8f29b6Schristos #define ASI_STORE	ASI_BLK_COMMIT_P
115*ca8f29b6Schristos #else
116*ca8f29b6Schristos #define ASI_STORE	ASI_BLK_P
117*ca8f29b6Schristos #endif
118*ca8f29b6Schristos #endif	/* USE_BLOCK_STORE_LOAD */
119*ca8f29b6Schristos #endif /* _KERNEL && !_RUMPKERNEL */
120