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