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