1 /* $NetBSD: locore.h,v 1.5 2010/07/10 10:10:36 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 /* 36 * Here are some defines to try to maintain consistency but still 37 * support 32-and 64-bit compilers. 38 */ 39 #ifdef _LP64 40 /* reg that points to base of data/text segment */ 41 #define BASEREG %g4 42 /* first constants for storage allocation */ 43 #define LNGSZ 8 44 #define LNGSHFT 3 45 #define PTRSZ 8 46 #define PTRSHFT 3 47 #define POINTER .xword 48 #define ULONG .xword 49 /* Now instructions to load/store pointers & long ints */ 50 #define LDLNG ldx 51 #define LDULNG ldx 52 #define STLNG stx 53 #define STULNG stx 54 #define LDPTR ldx 55 #define LDPTRA ldxa 56 #define STPTR stx 57 #define STPTRA stxa 58 #define CASPTR casxa 59 /* Now something to calculate the stack bias */ 60 #define STKB BIAS 61 #define CCCR %xcc 62 #else 63 #define BASEREG %g0 64 #define LNGSZ 4 65 #define LNGSHFT 2 66 #define PTRSZ 4 67 #define PTRSHFT 2 68 #define POINTER .word 69 #define ULONG .word 70 /* Instructions to load/store pointers & long ints */ 71 #define LDLNG ldsw 72 #define LDULNG lduw 73 #define STLNG stw 74 #define STULNG stw 75 #define LDPTR lduw 76 #define LDPTRA lduwa 77 #define STPTR stw 78 #define STPTRA stwa 79 #define CASPTR casa 80 #define STKB 0 81 #define CCCR %icc 82 #endif 83 84 /* Give this real authority: reset the machine */ 85 #define NOTREACHED sir 86 87 /* if < 32, copy by bytes, memcpy, kcopy, ... */ 88 #define BCOPY_SMALL 32 89 90 /* use as needed to align things on longword boundaries */ 91 #define _ALIGN .align 8 92 #define ICACHE_ALIGN .align 32 93 94 /* A few convenient abbreviations for trapframe fields. */ 95 #define TF_G TF_GLOBAL 96 #define TF_O TF_OUT 97 #define TF_L TF_LOCAL 98 #define TF_I TF_IN 99 100 /* Let us use same syntax as C code */ 101 #define Debugger() ta 1; nop 102 103 104 /* 105 * This macro will clear out a cache line before an explicit 106 * access to that location. It's mostly used to make certain 107 * loads bypassing the D$ do not get stale D$ data. 108 * 109 * It uses a register with the address to clear and a temporary 110 * which is destroyed. 111 */ 112 #ifdef DCACHE_BUG 113 #define DLFLUSH(a,t) \ 114 andn a, 0x3f, t; \ 115 stxa %g0, [ t ] ASI_DCACHE_TAG; \ 116 membar #Sync 117 /* The following can be used if the pointer is 32-byte aligned */ 118 #define DLFLUSH2(t) \ 119 stxa %g0, [ t ] ASI_DCACHE_TAG; \ 120 membar #Sync 121 #else 122 #define DLFLUSH(a,t) 123 #define DLFLUSH2(t) 124 #endif 125 126 127 /* 128 * Combine 2 regs -- used to convert 64-bit ILP32 129 * values to LP64. 130 */ 131 #define COMBINE(r1, r2, d) \ 132 clruw r2; \ 133 sllx r1, 32, d; \ 134 or d, r2, d 135 136 /* 137 * Split 64-bit value in 1 reg into high and low halves. 138 * Used for ILP32 return values. 139 */ 140 #define SPLIT(r0, r1) \ 141 srl r0, 0, r1; \ 142 srlx r0, 32, r0 143 144 145 /* 146 * A handy macro for maintaining instrumentation counters. 147 * Note that this clobbers %o0, %o1 and %o2. Normal usage is 148 * something like: 149 * foointr: 150 * TRAP_SETUP(...) ! makes %o registers safe 151 * INCR(_C_LABEL(cnt)+V_FOO) ! count a foo 152 */ 153 #define INCR(what) \ 154 sethi %hi(what), %o0; \ 155 or %o0, %lo(what), %o0; \ 156 99: \ 157 lduw [%o0], %o1; \ 158 add %o1, 1, %o2; \ 159 casa [%o0] ASI_P, %o1, %o2; \ 160 cmp %o1, %o2; \ 161 bne,pn %icc, 99b; \ 162 nop 163 164 /* 165 * A couple of handy macros to save and restore globals to/from 166 * locals. Since udivrem uses several globals, and it's called 167 * from vsprintf, we need to do this before and after doing a printf. 168 */ 169 #define GLOBTOLOC \ 170 mov %g1, %l1; \ 171 mov %g2, %l2; \ 172 mov %g3, %l3; \ 173 mov %g4, %l4; \ 174 mov %g5, %l5; \ 175 mov %g6, %l6; \ 176 mov %g7, %l7 177 178 #define LOCTOGLOB \ 179 mov %l1, %g1; \ 180 mov %l2, %g2; \ 181 mov %l3, %g3; \ 182 mov %l4, %g4; \ 183 mov %l5, %g5; \ 184 mov %l6, %g6; \ 185 mov %l7, %g7 186 187 /* Load strings address into register; NOTE: hidden local label 99 */ 188 #define LOAD_ASCIZ(reg, s) \ 189 set 99f, reg ; \ 190 .data ; \ 191 99: .asciz s ; \ 192 _ALIGN ; \ 193 .text 194 195 /* 196 * Handy stack conversion macros. 197 * They correctly switch to requested stack type 198 * regardless of the current stack. 199 */ 200 201 #define TO_STACK64(size) \ 202 save %sp, size, %sp; \ 203 add %sp, -BIAS, %o0; /* Convert to 64-bits */ \ 204 andcc %sp, 1, %g0; /* 64-bit stack? */ \ 205 movz %icc, %o0, %sp 206 207 #define TO_STACK32(size) \ 208 save %sp, size, %sp; \ 209 add %sp, +BIAS, %o0; /* Convert to 32-bits */ \ 210 andcc %sp, 1, %g0; /* 64-bit stack? */ \ 211 movnz %icc, %o0, %sp 212 213 #ifdef _LP64 214 #define STACKFRAME(size) TO_STACK64(size) 215 #else 216 #define STACKFRAME(size) TO_STACK32(size) 217 #endif 218 219 /* 220 * Primitives 221 */ 222 #ifdef ENTRY 223 #undef ENTRY 224 #endif 225 226 #ifdef GPROF 227 .globl _mcount 228 #define ENTRY(x) \ 229 .globl _C_LABEL(x); .proc 1; .type _C_LABEL(x),@function; \ 230 _C_LABEL(x): ; \ 231 .data; \ 232 .align 8; \ 233 0: .uaword 0; .uaword 0; \ 234 .text; \ 235 save %sp, -CC64FSZ, %sp; \ 236 sethi %hi(0b), %o0; \ 237 call _mcount; \ 238 or %o0, %lo(0b), %o0; \ 239 restore 240 #else 241 #define ENTRY(x) .globl _C_LABEL(x); .proc 1; \ 242 .type _C_LABEL(x),@function; _C_LABEL(x): 243 #endif 244 #define ALTENTRY(x) .globl _C_LABEL(x); _C_LABEL(x): 245 246 247