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