1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1990-2001 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _SYS_TRAPTRACE_H 28*0Sstevel@tonic-gate #define _SYS_TRAPTRACE_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #ifdef __cplusplus 33*0Sstevel@tonic-gate extern "C" { 34*0Sstevel@tonic-gate #endif 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate /* 37*0Sstevel@tonic-gate * Trap tracing. If TRAPTRACE is defined, every trap records info 38*0Sstevel@tonic-gate * in a circular buffer. Define TRAPTRACE in Makefile.sun4m. 39*0Sstevel@tonic-gate * 40*0Sstevel@tonic-gate * Trap trace records are 8 words, consisting of the %tbr, %psr, %pc, %sp, 41*0Sstevel@tonic-gate * %g7 (THREAD_REG), and up to three other words. 42*0Sstevel@tonic-gate * 43*0Sstevel@tonic-gate * Auxilliary entries (not of just a trap), have obvious non-%tbr values in 44*0Sstevel@tonic-gate * the first word. 45*0Sstevel@tonic-gate */ 46*0Sstevel@tonic-gate #define TRAP_ENT_TBR 0x00 47*0Sstevel@tonic-gate #define TRAP_ENT_PSR 0x04 48*0Sstevel@tonic-gate #define TRAP_ENT_PC 0x08 49*0Sstevel@tonic-gate #define TRAP_ENT_SP 0x0c 50*0Sstevel@tonic-gate #define TRAP_ENT_G7 0x10 51*0Sstevel@tonic-gate #define TRAP_ENT_TR 0x14 52*0Sstevel@tonic-gate #define TRAP_ENT_F1 0x18 53*0Sstevel@tonic-gate #define TRAP_ENT_F2 0x1c 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate #define TRAP_ENT_SIZE 32 56*0Sstevel@tonic-gate #define TRAP_TSIZE (TRAP_ENT_SIZE*256) 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate /* 59*0Sstevel@tonic-gate * Trap tracing buffer header. 60*0Sstevel@tonic-gate */ 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate /* 63*0Sstevel@tonic-gate * Example buffer header in locore.s: 64*0Sstevel@tonic-gate * 65*0Sstevel@tonic-gate * trap_trace_ctl: 66*0Sstevel@tonic-gate * .word trap_tr0 ! next CPU 0 67*0Sstevel@tonic-gate * .word trap_tr0 ! first 68*0Sstevel@tonic-gate * .word trap_tr0 + TRAP_TSIZE ! limit 69*0Sstevel@tonic-gate * .word 0 ! junk for alignment of prom dump 70*0Sstevel@tonic-gate * 71*0Sstevel@tonic-gate * .word trap_tr1 ! next CPU 1 72*0Sstevel@tonic-gate * .word trap_tr1 ! first 73*0Sstevel@tonic-gate * .word trap_tr1 + TRAP_TSIZE ! limit 74*0Sstevel@tonic-gate * .word 0 ! junk for alignment of prom dump 75*0Sstevel@tonic-gate * 76*0Sstevel@tonic-gate * .word trap_tr2 ! next CPU 2 77*0Sstevel@tonic-gate * .word trap_tr2 ! first 78*0Sstevel@tonic-gate * .word trap_tr2 + TRAP_TSIZE ! limit 79*0Sstevel@tonic-gate * .word 0 ! junk for alignment of prom dump 80*0Sstevel@tonic-gate * 81*0Sstevel@tonic-gate * .word trap_tr3 ! next CPU 3 82*0Sstevel@tonic-gate * .word trap_tr3 ! first 83*0Sstevel@tonic-gate * .word trap_tr3 + TRAP_TSIZE ! limit 84*0Sstevel@tonic-gate * .word 0 ! junk for alignment of prom dump 85*0Sstevel@tonic-gate * .align 16 86*0Sstevel@tonic-gate * 87*0Sstevel@tonic-gate * Offsets of words in trap_trace_ctl: 88*0Sstevel@tonic-gate */ 89*0Sstevel@tonic-gate #define TRAPTR_NEXT 0 /* next trace entry pointer */ 90*0Sstevel@tonic-gate #define TRAPTR_FIRST 4 /* start of buffer */ 91*0Sstevel@tonic-gate #define TRAPTR_LIMIT 8 /* pointer past end of buffer */ 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate #define TRAPTR_SIZE_SHIFT 4 /* shift count for CPU indexing */ 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate #ifdef _ASM 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate /* 98*0Sstevel@tonic-gate * TRACE_PTR(ptr, scr1) - get trap trace entry pointer. 99*0Sstevel@tonic-gate * ptr is the register to receive the trace pointer. 100*0Sstevel@tonic-gate * reg is a different register to be used as scratch. 101*0Sstevel@tonic-gate */ 102*0Sstevel@tonic-gate #define TRACE_PTR(ptr, scr1) \ 103*0Sstevel@tonic-gate CPU_INDEX(scr1); \ 104*0Sstevel@tonic-gate sll scr1, TRAPTR_SIZE_SHIFT, scr1; \ 105*0Sstevel@tonic-gate set trap_trace_ctl, ptr; \ 106*0Sstevel@tonic-gate ld [ptr + scr1], ptr; \ 107*0Sstevel@tonic-gate set panicstr, scr1; \ 108*0Sstevel@tonic-gate ld [scr1], scr1; \ 109*0Sstevel@tonic-gate tst scr1; \ 110*0Sstevel@tonic-gate bz .+0xc; \ 111*0Sstevel@tonic-gate sethi %hi(trap_tr_panic), scr1; \ 112*0Sstevel@tonic-gate or scr1, %lo(trap_tr_panic), ptr 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate /* 115*0Sstevel@tonic-gate * TRACE_NEXT(ptr, scr1, scr2) - advance the trap trace pointer. 116*0Sstevel@tonic-gate * ptr is the register holding the current trace pointer (from TRACE_PTR). 117*0Sstevel@tonic-gate * scr1, and scr2 are scratch registers (different from ptr). 118*0Sstevel@tonic-gate */ 119*0Sstevel@tonic-gate #define TRACE_NEXT(ptr, scr1, scr2) \ 120*0Sstevel@tonic-gate CPU_INDEX(scr2); \ 121*0Sstevel@tonic-gate sll scr2, TRAPTR_SIZE_SHIFT, scr2; \ 122*0Sstevel@tonic-gate set trap_trace_ctl, scr1; \ 123*0Sstevel@tonic-gate add scr2, scr1, scr1; \ 124*0Sstevel@tonic-gate add ptr, TRAP_ENT_SIZE, ptr; \ 125*0Sstevel@tonic-gate ld [scr1 + TRAPTR_LIMIT], scr2; \ 126*0Sstevel@tonic-gate cmp ptr, scr2; \ 127*0Sstevel@tonic-gate /* CSTYLED */ \ 128*0Sstevel@tonic-gate bgeu,a .+8; \ 129*0Sstevel@tonic-gate ld [scr1 + TRAPTR_FIRST], ptr; \ 130*0Sstevel@tonic-gate set panicstr, scr2; \ 131*0Sstevel@tonic-gate ld [scr2], scr2; \ 132*0Sstevel@tonic-gate tst scr2; \ 133*0Sstevel@tonic-gate /* CSTYLED */ \ 134*0Sstevel@tonic-gate bz,a .+8; \ 135*0Sstevel@tonic-gate st ptr, [scr1] 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate /* 138*0Sstevel@tonic-gate * Macro to restore the %psr (thus enabling traps) while preserving 139*0Sstevel@tonic-gate * cpu_base_spl. Note that the actual write to the %psr is broken into 140*0Sstevel@tonic-gate * two writes to avoid the IU bug (one cannot raise PIL and enable traps 141*0Sstevel@tonic-gate * in a single write to the %psr). 142*0Sstevel@tonic-gate */ 143*0Sstevel@tonic-gate #define TRACE_RESTORE_PSR(old, scr1, scr2) \ 144*0Sstevel@tonic-gate andn old, PSR_ET, old; \ 145*0Sstevel@tonic-gate ld [THREAD_REG + T_CPU], scr1; \ 146*0Sstevel@tonic-gate ld [scr1 + CPU_BASE_SPL], scr1; \ 147*0Sstevel@tonic-gate and old, PSR_PIL, scr2; \ 148*0Sstevel@tonic-gate subcc scr1, scr2, scr1; \ 149*0Sstevel@tonic-gate /* CSTYLED */ \ 150*0Sstevel@tonic-gate bg,a 9f; \ 151*0Sstevel@tonic-gate add old, scr1, old; \ 152*0Sstevel@tonic-gate 9: mov old, %psr; \ 153*0Sstevel@tonic-gate wr old, PSR_ET, %psr; \ 154*0Sstevel@tonic-gate nop; \ 155*0Sstevel@tonic-gate nop; \ 156*0Sstevel@tonic-gate nop 157*0Sstevel@tonic-gate 158*0Sstevel@tonic-gate /* 159*0Sstevel@tonic-gate * Trace macro for underflow or overflow trap handler 160*0Sstevel@tonic-gate */ 161*0Sstevel@tonic-gate #ifdef TRAPTRACE 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate #define TRACE_UNFL(code, addr, scr1, scr2, scr3) \ 164*0Sstevel@tonic-gate TRACE_PTR(scr1, scr2); \ 165*0Sstevel@tonic-gate set code, scr2; \ 166*0Sstevel@tonic-gate st scr2, [scr1 + TRAP_ENT_TBR]; \ 167*0Sstevel@tonic-gate mov %psr, scr2; \ 168*0Sstevel@tonic-gate st scr2, [scr1 + TRAP_ENT_PSR]; \ 169*0Sstevel@tonic-gate st %g0, [scr1 + TRAP_ENT_PC]; \ 170*0Sstevel@tonic-gate st addr, [scr1 + TRAP_ENT_SP]; \ 171*0Sstevel@tonic-gate st %g0, [scr1 + TRAP_ENT_G7]; \ 172*0Sstevel@tonic-gate TRACE_NEXT(scr1, scr2, scr3) 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate #else /* TRAPTRACE */ 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate #define TRACE_UNFL(code, addr, scr1, scr2, scr3) 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate #endif /* TRAPTRACE */ 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate #define TRACE_OVFL TRACE_UNFL /* overflow trace is the same */ 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate #endif /* _ASM */ 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate /* 185*0Sstevel@tonic-gate * Trap trace codes used in place of a %tbr value when more than one 186*0Sstevel@tonic-gate * entry is made by a trap. The general scheme is that the trap-type is 187*0Sstevel@tonic-gate * in the same position as in the TBR, and the low-order bits indicate 188*0Sstevel@tonic-gate * which precise entry is being made. 189*0Sstevel@tonic-gate */ 190*0Sstevel@tonic-gate #define TT_OV_USR 0x051 /* overflow to user address in %sp */ 191*0Sstevel@tonic-gate #define TT_OV_SYS 0x052 /* overflow to system address in %sp */ 192*0Sstevel@tonic-gate #define TT_OV_SHR 0x053 /* overflow of shared window to user */ 193*0Sstevel@tonic-gate #define TT_OV_SHRK 0x054 /* overflow of shared window to system */ 194*0Sstevel@tonic-gate #define TT_OV_BUF 0x055 /* overflow from user of user window to PCB */ 195*0Sstevel@tonic-gate #define TT_OV_BUFK 0x056 /* overflow from kernel of user window to PCB */ 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate #define TT_UF_USR 0x061 /* underflow of user window */ 198*0Sstevel@tonic-gate #define TT_UF_SYS 0x062 /* underflow of kernel window */ 199*0Sstevel@tonic-gate #define TT_UF_FAULT 0x063 /* underflow of user window had fault */ 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate #define TT_SC_RET 0x881 /* system call normal return */ 202*0Sstevel@tonic-gate #define TT_SC_POST 0x882 /* system call return after post_syscall */ 203*0Sstevel@tonic-gate #define TT_SC_TRAP 0x883 /* system call return calling trap */ 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate #define TT_SYS_RTT 0x6666 /* return from trap */ 206*0Sstevel@tonic-gate #define TT_SYS_RTTU 0x7777 /* return from trap to user */ 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate #define TT_INTR_ENT -1 /* interrupt entry */ 209*0Sstevel@tonic-gate #define TT_INTR_RET -2 /* interrupt return */ 210*0Sstevel@tonic-gate #define TT_INTR_RET2 -3 /* interrupt return */ 211*0Sstevel@tonic-gate #define TT_INTR_EXIT 0x8888 /* interrupt thread exit (no pinned thread) */ 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate #ifdef __cplusplus 214*0Sstevel@tonic-gate } 215*0Sstevel@tonic-gate #endif 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gate #endif /* _SYS_TRAPTRACE_H */ 218