xref: /onnv-gate/usr/src/uts/sun4v/sys/traptrace.h (revision 11172:a792f425ae2e)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51859Sha137994  * Common Development and Distribution License (the "License").
61859Sha137994  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11172SHaik.Aftandilian@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _SYS_TRAPTRACE_H
270Sstevel@tonic-gate #define	_SYS_TRAPTRACE_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifdef	__cplusplus
300Sstevel@tonic-gate extern "C" {
310Sstevel@tonic-gate #endif
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #define	TRAP_TENABLE_ALL	-1	/* enable all hv traptracing */
340Sstevel@tonic-gate #define	TRAP_TDISABLE_ALL	0	/* disable all hv traptracing */
350Sstevel@tonic-gate #define	TRAP_TFREEZE_ALL	-1	/* freeze all hv traptracing */
360Sstevel@tonic-gate #define	TRAP_TUNFREEZE_ALL	0	/* unfreeze all hv traptracing */
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate  * Trap tracing. If TRAPTRACE is defined, every trap records info
400Sstevel@tonic-gate  * in a circular buffer.  Define TRAPTRACE in Makefile.$ARCH.
410Sstevel@tonic-gate  *
420Sstevel@tonic-gate  * Trap trace records are TRAP_ENT_SIZE bytes, consisting of the
430Sstevel@tonic-gate  * %tick, %tl, %tt, %tpc, %tstate, %sp, and a few other words:
440Sstevel@tonic-gate  *
450Sstevel@tonic-gate  * struct trap_trace_record {
460Sstevel@tonic-gate  *	ushort_t tl, tt;
470Sstevel@tonic-gate  *	long	pc;
480Sstevel@tonic-gate  *	int64_t	tstate, tick;
490Sstevel@tonic-gate  *	long	sp, tr, f1, f2, f3, f4;
500Sstevel@tonic-gate  * };
510Sstevel@tonic-gate  *
520Sstevel@tonic-gate  * Note that for UltraSparc III and beyond %stick is used in place of %tick
530Sstevel@tonic-gate  * unless compiled with TRAPTRACE_FORCE_TICK.
540Sstevel@tonic-gate  *
550Sstevel@tonic-gate  * Auxilliary entries (not of just a trap), have obvious non-%tt values in
560Sstevel@tonic-gate  * the TRAP_ENT_TT field
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate 
595939Ssetje #define	TRAP_TBUF	(2 * PAGESIZE)	/* default size is two pages */
600Sstevel@tonic-gate 
610Sstevel@tonic-gate #ifndef	_ASM
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate  * HV Trap trace header
650Sstevel@tonic-gate  */
660Sstevel@tonic-gate typedef struct htrap_trace_hdr {
670Sstevel@tonic-gate 	uint64_t	last_offset;	/* most recently completed entry */
680Sstevel@tonic-gate 	uint64_t	offset;		/* next entry to be written */
690Sstevel@tonic-gate 	uint64_t	dummy1;
700Sstevel@tonic-gate 	uint64_t	dummy2;
710Sstevel@tonic-gate 	uint64_t	dummy3;
720Sstevel@tonic-gate 	uint64_t	dummy4;
730Sstevel@tonic-gate 	uint64_t	dummy5;
740Sstevel@tonic-gate 	uint64_t	dummy6;
750Sstevel@tonic-gate } htrap_trace_hdr_t;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * HV Trap trace record
790Sstevel@tonic-gate  */
800Sstevel@tonic-gate struct htrap_trace_record {
810Sstevel@tonic-gate 	uint8_t		tt_ty;		/* Indicates HV or Guest entry */
820Sstevel@tonic-gate 	uint8_t		tt_hpstate;	/* Hyper-privilege State */
830Sstevel@tonic-gate 	uint8_t		tt_tl;		/* Trap level */
840Sstevel@tonic-gate 	uint8_t		tt_gl;		/* Global register level */
850Sstevel@tonic-gate 	uint16_t	tt_tt;		/* Trap type */
860Sstevel@tonic-gate 	uint16_t	tt_tag;		/* Extended Trap Indentifier */
870Sstevel@tonic-gate 	uint64_t	tt_tstate;	/* Trap state */
880Sstevel@tonic-gate 	uint64_t	tt_tick;	/* Tick */
890Sstevel@tonic-gate 	uint64_t	tt_tpc;		/* Trap PC */
900Sstevel@tonic-gate 	uint64_t	tt_f1;		/* Entry specific */
910Sstevel@tonic-gate 	uint64_t	tt_f2;		/* Entry specific */
920Sstevel@tonic-gate 	uint64_t	tt_f3;		/* Entry specific */
930Sstevel@tonic-gate 	uint64_t	tt_f4;		/* Entry specific */
940Sstevel@tonic-gate };
950Sstevel@tonic-gate 
960Sstevel@tonic-gate /*
970Sstevel@tonic-gate  * Kernel Trap trace record
980Sstevel@tonic-gate  */
990Sstevel@tonic-gate struct trap_trace_record {
1000Sstevel@tonic-gate 	uint8_t		tt_tl;
1010Sstevel@tonic-gate 	uint8_t		tt_gl;
1020Sstevel@tonic-gate 	uint16_t	tt_tt;
1030Sstevel@tonic-gate 	uintptr_t	tt_tpc;
1040Sstevel@tonic-gate 	uint64_t	tt_tstate;
1050Sstevel@tonic-gate 	uint64_t	tt_tick;
1060Sstevel@tonic-gate 	uintptr_t	tt_sp;
1070Sstevel@tonic-gate 	uintptr_t	tt_tr;
1080Sstevel@tonic-gate 	uintptr_t	tt_f1;
1090Sstevel@tonic-gate 	uintptr_t	tt_f2;
1100Sstevel@tonic-gate 	uintptr_t	tt_f3;
1110Sstevel@tonic-gate 	uintptr_t	tt_f4;
1120Sstevel@tonic-gate };
1130Sstevel@tonic-gate 
1145939Ssetje #define	TRAP_TSIZE	((TRAP_TBUF / sizeof (struct trap_trace_record)) * \
1155939Ssetje 			sizeof (struct trap_trace_record))
1165939Ssetje 
1175939Ssetje /* Rounding not needed, done for consistency */
1185939Ssetje #define	HTRAP_TSIZE	((TRAP_TBUF / sizeof (struct htrap_trace_record)) * \
1195939Ssetje 			sizeof (struct htrap_trace_record))
1200Sstevel@tonic-gate 
1215939Ssetje #else
1220Sstevel@tonic-gate 
1235939Ssetje #define	TRAP_TSIZE	((TRAP_TBUF / TRAP_ENT_SIZE) * TRAP_ENT_SIZE)
1245939Ssetje #define	HTRAP_TSIZE	((TRAP_TBUF / HTRAP_ENT_SIZE) * HTRAP_ENT_SIZE)
1255939Ssetje 
1265939Ssetje #endif
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate /*
1290Sstevel@tonic-gate  * Trap tracing buffer header.
1300Sstevel@tonic-gate  */
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate #ifndef	_ASM
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate /*
1350Sstevel@tonic-gate  * Example buffer header stored in locore.s:
1360Sstevel@tonic-gate  *
1370Sstevel@tonic-gate  * (the actual implementation could be .skip TRAPTR_SIZE*NCPU)
1380Sstevel@tonic-gate  */
1390Sstevel@tonic-gate typedef union {
1400Sstevel@tonic-gate     struct {
1410Sstevel@tonic-gate 	caddr_t		vaddr_base;	/* virtual address of top of buffer */
1420Sstevel@tonic-gate 	uint64_t	paddr_base;	/* physical address of buffer */
1430Sstevel@tonic-gate 	uint_t		last_offset;	/* to "know" what trace completed */
1440Sstevel@tonic-gate 	uint_t		offset;		/* current index into buffer (bytes) */
1450Sstevel@tonic-gate 	uint_t		limit;		/* upper limit on index */
1460Sstevel@tonic-gate 	uchar_t		asi;		/* cache for real asi */
1470Sstevel@tonic-gate 	caddr_t		hvaddr_base;	/* HV virtual addr of top of buffer */
1480Sstevel@tonic-gate 	uint64_t	hpaddr_base;	/* HV physical addr of buffer */
1490Sstevel@tonic-gate 	uint_t		hlimit;		/* HV upper limit on index */
1500Sstevel@tonic-gate 	} d;
1510Sstevel@tonic-gate     char		cache_linesize[64];
1520Sstevel@tonic-gate } TRAP_TRACE_CTL;
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate #ifdef _KERNEL
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate extern TRAP_TRACE_CTL	trap_trace_ctl[];	/* allocated in locore.s */
1570Sstevel@tonic-gate extern int		trap_trace_bufsize;	/* default buffer size */
1580Sstevel@tonic-gate extern char		trap_tr0[];		/* prealloc buf for boot cpu */
1590Sstevel@tonic-gate extern int		trap_freeze;		/* freeze the trap trace */
1605648Ssetje extern caddr_t		ttrace_buf;		/* kmem64 buffer */
1610Sstevel@tonic-gate extern int		ttrace_index;		/* index used */
1625648Ssetje extern size_t		calc_traptrace_sz(void);
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate extern int		htrap_trace_bufsize;	/* default hv buffer size */
1651077Ssvemuri extern int		mach_htraptrace_enable;
1661077Ssvemuri extern void mach_htraptrace_setup(int);
1671077Ssvemuri extern void mach_htraptrace_configure(int);
1681077Ssvemuri extern void mach_htraptrace_cleanup(int);
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate #endif
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate /*
1730Sstevel@tonic-gate  * freeze the trap trace
1740Sstevel@tonic-gate  */
1750Sstevel@tonic-gate #define	TRAPTRACE_FREEZE	trap_freeze = 1;
1760Sstevel@tonic-gate #define	TRAPTRACE_UNFREEZE	trap_freeze = 0;
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate #else /* _ASM */
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate #include <sys/machthread.h>
181*11172SHaik.Aftandilian@Sun.COM #include <sys/machclock.h>
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate /*
1840Sstevel@tonic-gate  * Offsets of words in trap_trace_ctl:
1850Sstevel@tonic-gate  */
1860Sstevel@tonic-gate /*
1870Sstevel@tonic-gate  * XXX This should be done with genassym
1880Sstevel@tonic-gate  */
1890Sstevel@tonic-gate #define	TRAPTR_VBASE	0		/* virtual address of buffer */
1900Sstevel@tonic-gate #define	TRAPTR_LAST_OFFSET 16		/* last completed trace entry */
1910Sstevel@tonic-gate #define	TRAPTR_OFFSET	20		/* next trace entry pointer */
1920Sstevel@tonic-gate #define	TRAPTR_LIMIT	24		/* pointer past end of buffer */
1930Sstevel@tonic-gate #define	TRAPTR_PBASE	8		/* start of buffer */
1940Sstevel@tonic-gate #define	TRAPTR_ASIBUF	28		/* cache of current asi */
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate #define	TRAPTR_HVBASE	32		/* HV virtual address of buffer */
1970Sstevel@tonic-gate #define	TRAPTR_HPBASE	40		/* HV start of buffer */
1980Sstevel@tonic-gate #define	TRAPTR_HLIMIT	48		/* HV pointer past end of buffer */
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate #define	TRAPTR_SIZE_SHIFT	6	/* shift count -- per CPU indexing */
2010Sstevel@tonic-gate #define	TRAPTR_SIZE		(1<<TRAPTR_SIZE_SHIFT)
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate #define	TRAPTR_ASI	ASI_MEM		/* ASI to use for TRAPTR access */
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate /*
2060Sstevel@tonic-gate  * Use new %stick register for UltraSparc III and beyond for
2070Sstevel@tonic-gate  * sane debugging of mixed speed CPU systems. Use TRAPTRACE_FORCE_TICK
208*11172SHaik.Aftandilian@Sun.COM  * for finer granularity on same speed systems. Note that traptrace
209*11172SHaik.Aftandilian@Sun.COM  * %tick or %stick reads use the NO_SUSPEND_CHECK version of the
210*11172SHaik.Aftandilian@Sun.COM  * register read macros. This requires fewer registers and a few less
211*11172SHaik.Aftandilian@Sun.COM  * instructions to execute. As a result, if a suspend operation occurs
212*11172SHaik.Aftandilian@Sun.COM  * while traptrace is executing GET_TRACE_TICK between the time that
213*11172SHaik.Aftandilian@Sun.COM  * the counter offset variable is read and the hardware register is read,
214*11172SHaik.Aftandilian@Sun.COM  * this traptrace entry in the log will have an incorrect %tick value
215*11172SHaik.Aftandilian@Sun.COM  * since it is derived from a pre-suspend offset variable and a post-
216*11172SHaik.Aftandilian@Sun.COM  * suspend hardware counter.
2170Sstevel@tonic-gate  */
2180Sstevel@tonic-gate #ifdef	TRAPTRACE_FORCE_TICK
219*11172SHaik.Aftandilian@Sun.COM #define	GET_TRACE_TICK(reg, scr)				\
220*11172SHaik.Aftandilian@Sun.COM 	RD_TICK_NO_SUSPEND_CHECK(reg, scr);
2210Sstevel@tonic-gate #else
222*11172SHaik.Aftandilian@Sun.COM #define	GET_TRACE_TICK(reg, scr)				\
223*11172SHaik.Aftandilian@Sun.COM 	RD_TICKSTICK_FLAG(reg, scr, traptrace_use_stick);
2240Sstevel@tonic-gate #endif
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate /*
2270Sstevel@tonic-gate  * TRACE_PTR(ptr, scr1) - get trap trace entry physical pointer.
2280Sstevel@tonic-gate  *	ptr is the register to receive the trace pointer.
2290Sstevel@tonic-gate  *	scr1 is a different register to be used as scratch.
2300Sstevel@tonic-gate  * TRACING now needs a known processor state.  Hence the assertion.
2310Sstevel@tonic-gate  *	NOTE: this caches and resets %asi
2320Sstevel@tonic-gate  */
2330Sstevel@tonic-gate #define	TRACE_PTR(ptr, scr1)				\
2340Sstevel@tonic-gate 	sethi	%hi(trap_freeze), ptr;			\
2350Sstevel@tonic-gate 	ld	[ptr + %lo(trap_freeze)], ptr;		\
2360Sstevel@tonic-gate 	/* CSTYLED */					\
2370Sstevel@tonic-gate 	brnz,pn	ptr, .+20; /* skip assertion */		\
2380Sstevel@tonic-gate 	rdpr	%pstate, scr1;				\
2390Sstevel@tonic-gate 	andcc	scr1, PSTATE_IE | PSTATE_AM, scr1;	\
2400Sstevel@tonic-gate 	/* CSTYLED */					\
2410Sstevel@tonic-gate 	bne,a,pn %icc, trace_ptr_panic;			\
2420Sstevel@tonic-gate 	rd	%pc, %g1;				\
2430Sstevel@tonic-gate 	CPU_INDEX(scr1, ptr);				\
2440Sstevel@tonic-gate 	sll	scr1, TRAPTR_SIZE_SHIFT, scr1;		\
2450Sstevel@tonic-gate 	set	trap_trace_ctl, ptr; 			\
2460Sstevel@tonic-gate 	add	ptr, scr1, scr1;			\
2470Sstevel@tonic-gate 	rd	%asi, ptr;				\
2480Sstevel@tonic-gate 	stb	ptr, [scr1 + TRAPTR_ASIBUF];		\
2490Sstevel@tonic-gate 	sethi	%hi(trap_freeze), ptr;			\
2500Sstevel@tonic-gate 	ld	[ptr + %lo(trap_freeze)], ptr;		\
2510Sstevel@tonic-gate 	/* CSTYLED */					\
2520Sstevel@tonic-gate 	brnz,pn	ptr, .+20; /* skip assertion */		\
2530Sstevel@tonic-gate 	ld	[scr1 + TRAPTR_LIMIT], ptr;		\
2540Sstevel@tonic-gate 	tst	ptr;					\
2550Sstevel@tonic-gate 	/* CSTYLED */					\
2560Sstevel@tonic-gate 	be,a,pn	%icc, trace_ptr_panic;			\
2570Sstevel@tonic-gate 	rd	%pc, %g1;				\
2580Sstevel@tonic-gate 	ldx	[scr1 + TRAPTR_PBASE], ptr;		\
2590Sstevel@tonic-gate 	ld	[scr1 + TRAPTR_OFFSET], scr1;		\
2600Sstevel@tonic-gate 	wr	%g0, TRAPTR_ASI, %asi;			\
2610Sstevel@tonic-gate 	add	ptr, scr1, ptr;
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate /*
2640Sstevel@tonic-gate  * TRACE_NEXT(scr1, scr2, scr3) - advance the trap trace pointer.
2650Sstevel@tonic-gate  *	scr1, scr2, scr3 are scratch registers.
2660Sstevel@tonic-gate  *	This routine will skip updating the trap pointers if the
2670Sstevel@tonic-gate  *	global freeze register is set (e.g. in panic).
2680Sstevel@tonic-gate  *	(we also restore the asi register)
2690Sstevel@tonic-gate  */
2700Sstevel@tonic-gate #define	TRACE_NEXT(scr1, scr2, scr3)			\
2710Sstevel@tonic-gate 	CPU_INDEX(scr2, scr1);				\
2720Sstevel@tonic-gate 	sll	scr2, TRAPTR_SIZE_SHIFT, scr2;		\
2730Sstevel@tonic-gate 	set	trap_trace_ctl, scr1; 			\
2740Sstevel@tonic-gate 	add	scr1, scr2, scr2;			\
2750Sstevel@tonic-gate 	ldub	[scr2 + TRAPTR_ASIBUF], scr1;		\
2760Sstevel@tonic-gate 	wr	%g0, scr1, %asi;			\
2770Sstevel@tonic-gate 	sethi	%hi(trap_freeze), scr1;			\
2780Sstevel@tonic-gate 	ld	[scr1 + %lo(trap_freeze)], scr1;	\
2790Sstevel@tonic-gate 	/* CSTYLED */					\
2800Sstevel@tonic-gate 	brnz	scr1, .+36; /* skip update on freeze */	\
2810Sstevel@tonic-gate 	ld	[scr2 + TRAPTR_OFFSET], scr1;		\
2820Sstevel@tonic-gate 	ld	[scr2 + TRAPTR_LIMIT], scr3;		\
2830Sstevel@tonic-gate 	st	scr1, [scr2 + TRAPTR_LAST_OFFSET];	\
2840Sstevel@tonic-gate 	add	scr1, TRAP_ENT_SIZE, scr1;		\
2850Sstevel@tonic-gate 	sub	scr3, TRAP_ENT_SIZE, scr3;		\
2860Sstevel@tonic-gate 	cmp	scr1, scr3;				\
2870Sstevel@tonic-gate 	movge	%icc, 0, scr1;				\
2880Sstevel@tonic-gate 	st	scr1, [scr2 + TRAPTR_OFFSET];
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate /*
2910Sstevel@tonic-gate  * macro to save %tl, %gl to trap trace record at addr
2920Sstevel@tonic-gate  */
2930Sstevel@tonic-gate #define	TRACE_SAVE_TL_GL_REGS(addr, scr1)		\
2940Sstevel@tonic-gate 	rdpr	%tl, scr1;				\
2950Sstevel@tonic-gate 	stba	scr1, [addr + TRAP_ENT_TL]%asi;		\
2960Sstevel@tonic-gate 	rdpr	%gl, scr1;				\
2970Sstevel@tonic-gate 	stba	scr1, [addr + TRAP_ENT_GL]%asi
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate /*
3000Sstevel@tonic-gate  * macro to save tl to trap trace record at addr
3010Sstevel@tonic-gate  */
3020Sstevel@tonic-gate #define	TRACE_SAVE_TL_VAL(addr, tl)			\
3030Sstevel@tonic-gate 	stba	tl, [addr + TRAP_ENT_TL]%asi
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate /*
3060Sstevel@tonic-gate  * macro to save gl to trap trace record at addr
3070Sstevel@tonic-gate  */
3080Sstevel@tonic-gate #define	TRACE_SAVE_GL_VAL(addr, gl)			\
3090Sstevel@tonic-gate 	stba	gl, [addr + TRAP_ENT_GL]%asi
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate /*
3130Sstevel@tonic-gate  * Trace macro for sys_trap return entries:
3140Sstevel@tonic-gate  *	prom_rtt, priv_rtt, and user_rtt
3150Sstevel@tonic-gate  *	%l7 - regs
3160Sstevel@tonic-gate  *	%l6 - trap %pil for prom_rtt and priv_rtt; THREAD_REG for user_rtt
3170Sstevel@tonic-gate  */
3180Sstevel@tonic-gate #define	TRACE_RTT(code, scr1, scr2, scr3, scr4)		\
3190Sstevel@tonic-gate 	rdpr	%pstate, scr4;				\
3200Sstevel@tonic-gate 	andn	scr4, PSTATE_IE | PSTATE_AM, scr3;	\
3210Sstevel@tonic-gate 	wrpr	%g0, scr3, %pstate;			\
3220Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
323*11172SHaik.Aftandilian@Sun.COM 	GET_TRACE_TICK(scr2, scr3);			\
3240Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
3250Sstevel@tonic-gate 	TRACE_SAVE_TL_GL_REGS(scr1, scr2);		\
3260Sstevel@tonic-gate 	set	code, scr2;				\
3270Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
3280Sstevel@tonic-gate 	ldn	[%l7 + PC_OFF], scr2;			\
3290Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
3300Sstevel@tonic-gate 	ldx	[%l7 + TSTATE_OFF], scr2;		\
3310Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
3320Sstevel@tonic-gate 	stna	%sp, [scr1 + TRAP_ENT_SP]%asi;		\
3330Sstevel@tonic-gate 	stna	%l6, [scr1 + TRAP_ENT_TR]%asi;		\
3340Sstevel@tonic-gate 	stna	%l7, [scr1 + TRAP_ENT_F1]%asi;		\
3350Sstevel@tonic-gate 	ldn	[THREAD_REG + T_CPU], scr2;		\
3360Sstevel@tonic-gate 	ld	[scr2 + CPU_BASE_SPL], scr2;		\
3370Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F2]%asi;		\
3380Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_F3]%asi;		\
3390Sstevel@tonic-gate 	rdpr	%cwp, scr2;				\
3400Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F4]%asi;		\
3410Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3);			\
3420Sstevel@tonic-gate 	wrpr	%g0, scr4, %pstate
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate /*
3450Sstevel@tonic-gate  * Trace macro for spill and fill trap handlers
3460Sstevel@tonic-gate  *	tl and tt fields indicate which spill handler is entered
3470Sstevel@tonic-gate  */
3480Sstevel@tonic-gate #define	TRACE_WIN_INFO(code, scr1, scr2, scr3)		\
3490Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
350*11172SHaik.Aftandilian@Sun.COM 	GET_TRACE_TICK(scr2, scr3);			\
3510Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
3520Sstevel@tonic-gate 	TRACE_SAVE_TL_GL_REGS(scr1, scr2);		\
3530Sstevel@tonic-gate 	rdpr	%tt, scr2;				\
3540Sstevel@tonic-gate 	set	code, scr3;				\
3550Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3560Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
3570Sstevel@tonic-gate 	rdpr	%tstate, scr2;				\
3580Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
3590Sstevel@tonic-gate 	stna	%sp, [scr1 + TRAP_ENT_SP]%asi;		\
3600Sstevel@tonic-gate 	rdpr	%tpc, scr2;				\
3610Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
3620Sstevel@tonic-gate 	set	TT_FSPILL_DEBUG, scr2;			\
3630Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TR]%asi;		\
3640Sstevel@tonic-gate 	rdpr	%pstate, scr2;				\
3650Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F1]%asi;		\
3660Sstevel@tonic-gate 	rdpr	%cwp, scr2;				\
3670Sstevel@tonic-gate 	sll	scr2, 24, scr2;				\
3680Sstevel@tonic-gate 	rdpr	%cansave, scr3;				\
3690Sstevel@tonic-gate 	sll	scr3, 16, scr3;				\
3700Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3710Sstevel@tonic-gate 	rdpr	%canrestore, scr3;			\
3720Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3730Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F2]%asi;		\
3740Sstevel@tonic-gate 	rdpr	%otherwin, scr2;			\
3750Sstevel@tonic-gate 	sll	scr2, 24, scr2;				\
3760Sstevel@tonic-gate 	rdpr	%cleanwin, scr3;			\
3770Sstevel@tonic-gate 	sll	scr3, 16, scr3;				\
3780Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3790Sstevel@tonic-gate 	rdpr	%wstate, scr3;				\
3800Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3810Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F3]%asi;		\
3820Sstevel@tonic-gate 	stna	%o7, [scr1 + TRAP_ENT_F4]%asi;		\
3830Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3)
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate #ifdef TRAPTRACE
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate #define	FAULT_WINTRACE(scr1, scr2, scr3, type)		\
3880Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
389*11172SHaik.Aftandilian@Sun.COM 	GET_TRACE_TICK(scr2, scr3);			\
3900Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
3910Sstevel@tonic-gate 	TRACE_SAVE_TL_GL_REGS(scr1, scr2);		\
3920Sstevel@tonic-gate 	set	type, scr2;				\
3930Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
3940Sstevel@tonic-gate 	rdpr	%tpc, scr2;				\
3950Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
3960Sstevel@tonic-gate 	rdpr	%tstate, scr2;				\
3970Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
3980Sstevel@tonic-gate 	stna	%sp, [scr1 + TRAP_ENT_SP]%asi;		\
3990Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_TR]%asi;		\
4000Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_F1]%asi;		\
4010Sstevel@tonic-gate 	stna	%g4, [scr1 + TRAP_ENT_F2]%asi;		\
4020Sstevel@tonic-gate 	rdpr	%pil, scr2;				\
4030Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F3]%asi;		\
4040Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_F4]%asi;		\
4050Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3)
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate #define	SYSTRAP_TT	0x1300
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate #define	SYSTRAP_TRACE(scr1, scr2, scr3)			\
4100Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
411*11172SHaik.Aftandilian@Sun.COM 	GET_TRACE_TICK(scr2, scr3);			\
4120Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
4130Sstevel@tonic-gate 	TRACE_SAVE_TL_GL_REGS(scr1, scr2);		\
4140Sstevel@tonic-gate 	set	SYSTRAP_TT, scr3;			\
4150Sstevel@tonic-gate 	rdpr	%tt, scr2;				\
4160Sstevel@tonic-gate 	or	scr3, scr2, scr2;			\
4170Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
4180Sstevel@tonic-gate 	rdpr	%tpc, scr2;				\
4190Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
4200Sstevel@tonic-gate 	rdpr	%tstate, scr2;				\
4210Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
4220Sstevel@tonic-gate 	stna	%g1, [scr1 + TRAP_ENT_SP]%asi;		\
4230Sstevel@tonic-gate 	stna	%g2, [scr1 + TRAP_ENT_TR]%asi;		\
4240Sstevel@tonic-gate 	stna	%g3, [scr1 + TRAP_ENT_F1]%asi;		\
4250Sstevel@tonic-gate 	stna	%g4, [scr1 + TRAP_ENT_F2]%asi;		\
4260Sstevel@tonic-gate 	rdpr	%pil, scr2;				\
4270Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F3]%asi;		\
4280Sstevel@tonic-gate 	rdpr	%cwp, scr2;				\
4290Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F4]%asi;		\
4300Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3)
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate #else /* TRAPTRACE */
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate #define	FAULT_WINTRACE(scr1, scr2, scr3, type)
4350Sstevel@tonic-gate #define	SYSTRAP_TRACE(scr1, scr2, scr3)
4360Sstevel@tonic-gate 
4370Sstevel@tonic-gate #endif /* TRAPTRACE */
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate #endif	/* _ASM */
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate /*
4420Sstevel@tonic-gate  * Trap trace codes used in place of a %tbr value when more than one
4430Sstevel@tonic-gate  * entry is made by a trap.  The general scheme is that the trap-type is
4440Sstevel@tonic-gate  * in the same position as in the TT, and the low-order bits indicate
4450Sstevel@tonic-gate  * which precise entry is being made.
4460Sstevel@tonic-gate  */
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate #define	TT_F32_SN0	0x1084
4490Sstevel@tonic-gate #define	TT_F64_SN0	0x1088
4500Sstevel@tonic-gate #define	TT_F32_NT0	0x1094
4510Sstevel@tonic-gate #define	TT_F64_NT0	0x1098
4520Sstevel@tonic-gate #define	TT_F32_SO0	0x10A4
4530Sstevel@tonic-gate #define	TT_F64_SO0	0x10A8
4540Sstevel@tonic-gate #define	TT_F32_FN0	0x10C4
4550Sstevel@tonic-gate #define	TT_F64_FN0	0x10C8
4560Sstevel@tonic-gate #define	TT_F32_SN1	0x1284
4570Sstevel@tonic-gate #define	TT_F64_SN1	0x1288
4580Sstevel@tonic-gate #define	TT_F32_NT1	0x1294
4590Sstevel@tonic-gate #define	TT_F64_NT1	0x1298
4600Sstevel@tonic-gate #define	TT_F32_SO1	0x12A4
4610Sstevel@tonic-gate #define	TT_F64_SO1	0x12A8
4620Sstevel@tonic-gate #define	TT_F32_FN1	0x12C4
4630Sstevel@tonic-gate #define	TT_F64_FN1	0x12C8
4640Sstevel@tonic-gate #define	TT_RTT_FN1	0x12DD
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate #define	TT_SC_ENTR	0x880	/* enter system call */
4670Sstevel@tonic-gate #define	TT_SC_RET	0x881	/* system call normal return */
4680Sstevel@tonic-gate 
4690Sstevel@tonic-gate #define	TT_SYS_RTT_PROM	0x5555	/* return from trap to prom */
4700Sstevel@tonic-gate #define	TT_SYS_RTT_PRIV	0x6666	/* return from trap to privilege */
4710Sstevel@tonic-gate #define	TT_SYS_RTT_USER	0x7777	/* return from trap to user */
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate #define	TT_INTR_EXIT	0x8888	/* interrupt thread exit (no pinned thread) */
4740Sstevel@tonic-gate #define	TT_FSPILL_DEBUG	0x9999	/* fill/spill debugging */
4750Sstevel@tonic-gate 
4760Sstevel@tonic-gate #define	TT_SERVE_INTR	0x6000	/* SERVE_INTR */
4770Sstevel@tonic-gate #define	TT_XCALL	0xd000	/* xcall/xtrap */
4780Sstevel@tonic-gate #define	TT_XCALL_CONT	0xdc00	/* continuation of an xcall/xtrap record */
4790Sstevel@tonic-gate 
4800Sstevel@tonic-gate #define	TT_MMU_MISS	0x200	/* or'd into %tt to indicate a miss */
4810Sstevel@tonic-gate #define	TT_MMU_EXEC	0x400	/* or'd into %tt to indicate exec_fault */
4820Sstevel@tonic-gate 
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate #ifdef	__cplusplus
4850Sstevel@tonic-gate }
4860Sstevel@tonic-gate #endif
4870Sstevel@tonic-gate 
4880Sstevel@tonic-gate #endif	/* _SYS_TRAPTRACE_H */
489