xref: /titanic_52/usr/src/uts/sun4u/sys/traptrace.h (revision 0400e0b7b3d7439bda29b4d73e29bff158199bc4)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0400e0b7Sha137994  * Common Development and Distribution License (the "License").
6*0400e0b7Sha137994  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*0400e0b7Sha137994  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_TRAPTRACE_H
277c478bd9Sstevel@tonic-gate #define	_SYS_TRAPTRACE_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Trap tracing. If TRAPTRACE is defined, every trap records info
377c478bd9Sstevel@tonic-gate  * in a circular buffer.  Define TRAPTRACE in Makefile.$ARCH.
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  * Trap trace records are TRAP_ENT_SIZE bytes, consisting of the
407c478bd9Sstevel@tonic-gate  * %tick, %tl, %tt, %tpc, %tstate, %sp, and a few other words:
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  * struct trap_trace_record {
437c478bd9Sstevel@tonic-gate  *	ushort_t tl, tt;
447c478bd9Sstevel@tonic-gate  *	long	pc;
457c478bd9Sstevel@tonic-gate  *	int64_t	tstate, tick;
467c478bd9Sstevel@tonic-gate  *	long	sp, tr, f1, f2, f3, f4;
477c478bd9Sstevel@tonic-gate  * };
487c478bd9Sstevel@tonic-gate  *
497c478bd9Sstevel@tonic-gate  * Note that for UltraSparc III and beyond %stick is used in place of %tick
507c478bd9Sstevel@tonic-gate  * unless compiled with TRAPTRACE_FORCE_TICK.
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * Auxilliary entries (not of just a trap), have obvious non-%tt values in
537c478bd9Sstevel@tonic-gate  * the TRAP_ENT_TT field
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	TRAP_TPGS	(2 * PAGESIZE)	/* default size is two pages */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #ifndef	_ASM
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate struct trap_trace_record {
617c478bd9Sstevel@tonic-gate 	uint16_t	tt_tl;
627c478bd9Sstevel@tonic-gate 	uint16_t	tt_tt;
637c478bd9Sstevel@tonic-gate 	uintptr_t	tt_tpc;
647c478bd9Sstevel@tonic-gate 	uint64_t	tt_tstate;
657c478bd9Sstevel@tonic-gate 	uint64_t	tt_tick;
667c478bd9Sstevel@tonic-gate 	uintptr_t	tt_sp;
677c478bd9Sstevel@tonic-gate 	uintptr_t	tt_tr;
687c478bd9Sstevel@tonic-gate 	uintptr_t	tt_f1;
697c478bd9Sstevel@tonic-gate 	uintptr_t	tt_f2;
707c478bd9Sstevel@tonic-gate 	uintptr_t	tt_f3;
717c478bd9Sstevel@tonic-gate 	uintptr_t	tt_f4;
727c478bd9Sstevel@tonic-gate };
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define	TRAP_TSIZE	((TRAP_TPGS / sizeof (struct trap_trace_record)) * \
757c478bd9Sstevel@tonic-gate 			sizeof (struct trap_trace_record))
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #else
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	TRAP_TSIZE	((TRAP_TPGS / TRAP_ENT_SIZE) * TRAP_ENT_SIZE)
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #endif
827c478bd9Sstevel@tonic-gate 
83db6d2ee3Ssvemuri #define	HTRAP_TSIZE	0
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * Trap tracing buffer header.
877c478bd9Sstevel@tonic-gate  */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #ifndef	_ASM
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * Example buffer header stored in locore.s:
937c478bd9Sstevel@tonic-gate  *
947c478bd9Sstevel@tonic-gate  * (the actual implementation could be .skip TRAPTR_SIZE*NCPU)
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate typedef union {
977c478bd9Sstevel@tonic-gate     struct {
987c478bd9Sstevel@tonic-gate 	caddr_t		vaddr_base;	/* virtual address of top of buffer */
997c478bd9Sstevel@tonic-gate 	uint64_t	paddr_base;	/* physical address of buffer */
1007c478bd9Sstevel@tonic-gate 	uint_t		last_offset;	/* to "know" what trace completed */
1017c478bd9Sstevel@tonic-gate 	uint_t		offset;		/* current index into buffer (bytes) */
1027c478bd9Sstevel@tonic-gate 	uint_t		limit;		/* upper limit on index */
1037c478bd9Sstevel@tonic-gate 	uchar_t		asi;		/* cache for real asi */
1047c478bd9Sstevel@tonic-gate 	} d;
1057c478bd9Sstevel@tonic-gate     char		cache_linesize[64];
1067c478bd9Sstevel@tonic-gate } TRAP_TRACE_CTL;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate extern TRAP_TRACE_CTL	trap_trace_ctl[];	/* allocated in locore.s */
1117c478bd9Sstevel@tonic-gate extern int		trap_trace_bufsize;	/* default buffer size */
1127c478bd9Sstevel@tonic-gate extern char		trap_tr0[];		/* prealloc buf for boot cpu */
1137c478bd9Sstevel@tonic-gate extern int		trap_freeze;		/* freeze the trap trace */
1147c478bd9Sstevel@tonic-gate extern caddr_t		ttrace_buf;		/* buffer bop alloced */
1157c478bd9Sstevel@tonic-gate extern int		ttrace_index;		/* index used */
1167c478bd9Sstevel@tonic-gate extern caddr_t		trap_trace_alloc(caddr_t);
117db6d2ee3Ssvemuri extern void mach_htraptrace_setup(int);
118db6d2ee3Ssvemuri extern void mach_htraptrace_configure(int);
119db6d2ee3Ssvemuri extern void mach_htraptrace_cleanup(int);
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #endif
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * freeze the trap trace
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate #define	TRAPTRACE_FREEZE	trap_freeze = 1;
1277c478bd9Sstevel@tonic-gate #define	TRAPTRACE_UNFREEZE	trap_freeze = 0;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate #else /* _ASM */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate #include <sys/machthread.h>
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Offsets of words in trap_trace_ctl:
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * XXX This should be done with genassym
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate #define	TRAPTR_VBASE	0		/* virtual address of buffer */
1407c478bd9Sstevel@tonic-gate #define	TRAPTR_LAST_OFFSET 16		/* last completed trace entry */
1417c478bd9Sstevel@tonic-gate #define	TRAPTR_OFFSET	20		/* next trace entry pointer */
1427c478bd9Sstevel@tonic-gate #define	TRAPTR_LIMIT	24		/* pointer past end of buffer */
1437c478bd9Sstevel@tonic-gate #define	TRAPTR_PBASE	8		/* start of buffer */
1447c478bd9Sstevel@tonic-gate #define	TRAPTR_ASIBUF	28		/* cache of current asi */
1457c478bd9Sstevel@tonic-gate #define	TRAPTR_SIZE_SHIFT	6	/* shift count -- per CPU indexing */
1467c478bd9Sstevel@tonic-gate #define	TRAPTR_SIZE		(1<<TRAPTR_SIZE_SHIFT)
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #define	TRAPTR_ASI	ASI_MEM		/* ASI to use for TRAPTR access */
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * Use new %stick register for UltraSparc III and beyond for
1527c478bd9Sstevel@tonic-gate  * sane debugging of mixed speed CPU systems. Use TRAPTRACE_FORCE_TICK
1537c478bd9Sstevel@tonic-gate  * for finer granularity on same speed systems.
1547c478bd9Sstevel@tonic-gate  *
1557c478bd9Sstevel@tonic-gate  * Note the label-less branches used due to contraints of where
1567c478bd9Sstevel@tonic-gate  * and when trap trace macros are used.
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate #ifdef	TRAPTRACE_FORCE_TICK
1597c478bd9Sstevel@tonic-gate #define	GET_TRACE_TICK(reg)				\
1607c478bd9Sstevel@tonic-gate 	rdpr	%tick, reg;
1617c478bd9Sstevel@tonic-gate #else
1627c478bd9Sstevel@tonic-gate #define	GET_TRACE_TICK(reg)				\
1637c478bd9Sstevel@tonic-gate 	sethi	%hi(traptrace_use_stick), reg;		\
1647c478bd9Sstevel@tonic-gate 	lduw	[reg + %lo(traptrace_use_stick)], reg;	\
1657c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
1667c478bd9Sstevel@tonic-gate         brz,a	reg, .+12;				\
1677c478bd9Sstevel@tonic-gate 	rdpr	%tick, reg;				\
1687c478bd9Sstevel@tonic-gate 	rd	%asr24, reg;
1697c478bd9Sstevel@tonic-gate #endif
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate /*
1727c478bd9Sstevel@tonic-gate  * TRACE_PTR(ptr, scr1) - get trap trace entry physical pointer.
1737c478bd9Sstevel@tonic-gate  *	ptr is the register to receive the trace pointer.
1747c478bd9Sstevel@tonic-gate  *	scr1 is a different register to be used as scratch.
1757c478bd9Sstevel@tonic-gate  * TRACING now needs a known processor state.  Hence the assertion.
1767c478bd9Sstevel@tonic-gate  *	NOTE: this caches and resets %asi
1777c478bd9Sstevel@tonic-gate  */
1787c478bd9Sstevel@tonic-gate #define	TRACE_PTR(ptr, scr1)				\
1797c478bd9Sstevel@tonic-gate 	sethi	%hi(trap_freeze), ptr;			\
1807c478bd9Sstevel@tonic-gate 	ld	[ptr + %lo(trap_freeze)], ptr;		\
1817c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
1827c478bd9Sstevel@tonic-gate 	brnz,pn	ptr, .+20; /* skip assertion */		\
1837c478bd9Sstevel@tonic-gate 	rdpr	%pstate, scr1;				\
1847c478bd9Sstevel@tonic-gate 	andcc	scr1, PSTATE_IE | PSTATE_AM, scr1;	\
1857c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
1867c478bd9Sstevel@tonic-gate 	bne,a,pn %icc, trace_ptr_panic;			\
1877c478bd9Sstevel@tonic-gate 	rd	%pc, %g1;				\
1887c478bd9Sstevel@tonic-gate 	CPU_INDEX(scr1, ptr);				\
1897c478bd9Sstevel@tonic-gate 	sll	scr1, TRAPTR_SIZE_SHIFT, scr1;		\
1907c478bd9Sstevel@tonic-gate 	set	trap_trace_ctl, ptr; 			\
1917c478bd9Sstevel@tonic-gate 	add	ptr, scr1, scr1;			\
1927c478bd9Sstevel@tonic-gate 	rd	%asi, ptr;				\
1937c478bd9Sstevel@tonic-gate 	stb	ptr, [scr1 + TRAPTR_ASIBUF];		\
1947c478bd9Sstevel@tonic-gate 	sethi	%hi(trap_freeze), ptr;			\
1957c478bd9Sstevel@tonic-gate 	ld	[ptr + %lo(trap_freeze)], ptr;		\
1967c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
1977c478bd9Sstevel@tonic-gate 	brnz,pn	ptr, .+20; /* skip assertion */		\
1987c478bd9Sstevel@tonic-gate 	ld	[scr1 + TRAPTR_LIMIT], ptr;		\
1997c478bd9Sstevel@tonic-gate 	tst	ptr;					\
2007c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
2017c478bd9Sstevel@tonic-gate 	be,a,pn	%icc, trace_ptr_panic;			\
2027c478bd9Sstevel@tonic-gate 	rd	%pc, %g1;				\
2037c478bd9Sstevel@tonic-gate 	ldx	[scr1 + TRAPTR_PBASE], ptr;		\
2047c478bd9Sstevel@tonic-gate 	ld	[scr1 + TRAPTR_OFFSET], scr1;		\
2057c478bd9Sstevel@tonic-gate 	wr	%g0, TRAPTR_ASI, %asi;			\
2067c478bd9Sstevel@tonic-gate 	add	ptr, scr1, ptr;
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * TRACE_NEXT(scr1, scr2, scr3) - advance the trap trace pointer.
2107c478bd9Sstevel@tonic-gate  *	scr1, scr2, scr3 are scratch registers.
2117c478bd9Sstevel@tonic-gate  *	This routine will skip updating the trap pointers if the
2127c478bd9Sstevel@tonic-gate  *	global freeze register is set (e.g. in panic).
2137c478bd9Sstevel@tonic-gate  *	(we also restore the asi register)
2147c478bd9Sstevel@tonic-gate  */
2157c478bd9Sstevel@tonic-gate #define	TRACE_NEXT(scr1, scr2, scr3)			\
2167c478bd9Sstevel@tonic-gate 	CPU_INDEX(scr2, scr1);				\
2177c478bd9Sstevel@tonic-gate 	sll	scr2, TRAPTR_SIZE_SHIFT, scr2;		\
2187c478bd9Sstevel@tonic-gate 	set	trap_trace_ctl, scr1; 			\
2197c478bd9Sstevel@tonic-gate 	add	scr1, scr2, scr2;			\
2207c478bd9Sstevel@tonic-gate 	ldub	[scr2 + TRAPTR_ASIBUF], scr1;		\
2217c478bd9Sstevel@tonic-gate 	wr	%g0, scr1, %asi;			\
2227c478bd9Sstevel@tonic-gate 	sethi	%hi(trap_freeze), scr1;			\
2237c478bd9Sstevel@tonic-gate 	ld	[scr1 + %lo(trap_freeze)], scr1;	\
2247c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
2257c478bd9Sstevel@tonic-gate 	brnz	scr1, .+36; /* skip update on freeze */	\
2267c478bd9Sstevel@tonic-gate 	ld	[scr2 + TRAPTR_OFFSET], scr1;		\
2277c478bd9Sstevel@tonic-gate 	ld	[scr2 + TRAPTR_LIMIT], scr3;		\
2287c478bd9Sstevel@tonic-gate 	st	scr1, [scr2 + TRAPTR_LAST_OFFSET];	\
2297c478bd9Sstevel@tonic-gate 	add	scr1, TRAP_ENT_SIZE, scr1;		\
2307c478bd9Sstevel@tonic-gate 	sub	scr3, TRAP_ENT_SIZE, scr3;		\
2317c478bd9Sstevel@tonic-gate 	cmp	scr1, scr3;				\
2327c478bd9Sstevel@tonic-gate 	movge	%icc, 0, scr1;				\
2337c478bd9Sstevel@tonic-gate 	st	scr1, [scr2 + TRAPTR_OFFSET];
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  * macro to save %tl to trap trace record at addr
2377c478bd9Sstevel@tonic-gate  */
2387c478bd9Sstevel@tonic-gate #define	TRACE_SAVE_TL_GL_REGS(addr, scr1)		\
2397c478bd9Sstevel@tonic-gate 	rdpr	%tl, scr1;				\
2407c478bd9Sstevel@tonic-gate 	stha	scr1, [addr + TRAP_ENT_TL]%asi
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate /*
2437c478bd9Sstevel@tonic-gate  * macro to save tl to trap trace record at addr
2447c478bd9Sstevel@tonic-gate  */
2457c478bd9Sstevel@tonic-gate #define	TRACE_SAVE_TL_VAL(addr, tl)			\
2467c478bd9Sstevel@tonic-gate 	stha	tl, [addr + TRAP_ENT_TL]%asi
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate /*
2497c478bd9Sstevel@tonic-gate  * dummy macro
2507c478bd9Sstevel@tonic-gate  */
2517c478bd9Sstevel@tonic-gate #define	TRACE_SAVE_GL_VAL(addr, gl)
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate /*
2557c478bd9Sstevel@tonic-gate  * Trace macro for sys_trap return entries:
2567c478bd9Sstevel@tonic-gate  *	prom_rtt, priv_rtt, and user_rtt
2577c478bd9Sstevel@tonic-gate  *	%l7 - regs
2587c478bd9Sstevel@tonic-gate  *	%l6 - trap %pil for prom_rtt and priv_rtt; THREAD_REG for user_rtt
2597c478bd9Sstevel@tonic-gate  */
2607c478bd9Sstevel@tonic-gate #define	TRACE_RTT(code, scr1, scr2, scr3, scr4)		\
2617c478bd9Sstevel@tonic-gate 	rdpr	%pstate, scr4;				\
2627c478bd9Sstevel@tonic-gate 	andn	scr4, PSTATE_IE | PSTATE_AM, scr3;	\
2637c478bd9Sstevel@tonic-gate 	wrpr	%g0, scr3, %pstate;			\
2647c478bd9Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
2657c478bd9Sstevel@tonic-gate 	GET_TRACE_TICK(scr2);				\
2667c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
2677c478bd9Sstevel@tonic-gate 	rdpr	%tl, scr2;				\
2687c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TL]%asi;		\
2697c478bd9Sstevel@tonic-gate 	set	code, scr2;				\
2707c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
2717c478bd9Sstevel@tonic-gate 	ldn	[%l7 + PC_OFF], scr2;			\
2727c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
2737c478bd9Sstevel@tonic-gate 	ldx	[%l7 + TSTATE_OFF], scr2;		\
2747c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
2757c478bd9Sstevel@tonic-gate 	stna	%sp, [scr1 + TRAP_ENT_SP]%asi;		\
2767c478bd9Sstevel@tonic-gate 	stna	%l6, [scr1 + TRAP_ENT_TR]%asi;		\
2777c478bd9Sstevel@tonic-gate 	stna	%l7, [scr1 + TRAP_ENT_F1]%asi;		\
2787c478bd9Sstevel@tonic-gate 	ldn	[THREAD_REG + T_CPU], scr2;		\
2797c478bd9Sstevel@tonic-gate 	ld	[scr2 + CPU_BASE_SPL], scr2;		\
2807c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F2]%asi;		\
2817c478bd9Sstevel@tonic-gate 	mov	MMU_SCONTEXT, scr2;			\
2827c478bd9Sstevel@tonic-gate 	ldxa	[scr2]ASI_DMMU, scr2;			\
2837c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F3]%asi;		\
2847c478bd9Sstevel@tonic-gate 	rdpr	%cwp, scr2;				\
2857c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F4]%asi;		\
2867c478bd9Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3);			\
2877c478bd9Sstevel@tonic-gate 	wrpr	%g0, scr4, %pstate
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate /*
2907c478bd9Sstevel@tonic-gate  * Trace macro for spill and fill trap handlers
2917c478bd9Sstevel@tonic-gate  *	tl and tt fields indicate which spill handler is entered
2927c478bd9Sstevel@tonic-gate  */
2937c478bd9Sstevel@tonic-gate #define	TRACE_WIN_INFO(code, scr1, scr2, scr3)		\
2947c478bd9Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
2957c478bd9Sstevel@tonic-gate 	GET_TRACE_TICK(scr2);				\
2967c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
2977c478bd9Sstevel@tonic-gate 	rdpr	%tl, scr2;				\
2987c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TL]%asi;		\
2997c478bd9Sstevel@tonic-gate 	rdpr	%tt, scr2;				\
3007c478bd9Sstevel@tonic-gate 	set	code, scr3;				\
3017c478bd9Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3027c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
3037c478bd9Sstevel@tonic-gate 	rdpr	%tstate, scr2;				\
3047c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
3057c478bd9Sstevel@tonic-gate 	stna	%sp, [scr1 + TRAP_ENT_SP]%asi;		\
3067c478bd9Sstevel@tonic-gate 	rdpr	%tpc, scr2;				\
3077c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
3087c478bd9Sstevel@tonic-gate 	set	TT_FSPILL_DEBUG, scr2;			\
3097c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TR]%asi;		\
3107c478bd9Sstevel@tonic-gate 	rdpr	%pstate, scr2;				\
3117c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F1]%asi;		\
3127c478bd9Sstevel@tonic-gate 	rdpr	%cwp, scr2;				\
3137c478bd9Sstevel@tonic-gate 	sll	scr2, 24, scr2;				\
3147c478bd9Sstevel@tonic-gate 	rdpr	%cansave, scr3;				\
3157c478bd9Sstevel@tonic-gate 	sll	scr3, 16, scr3;				\
3167c478bd9Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3177c478bd9Sstevel@tonic-gate 	rdpr	%canrestore, scr3;			\
3187c478bd9Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3197c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F2]%asi;		\
3207c478bd9Sstevel@tonic-gate 	rdpr	%otherwin, scr2;			\
3217c478bd9Sstevel@tonic-gate 	sll	scr2, 24, scr2;				\
3227c478bd9Sstevel@tonic-gate 	rdpr	%cleanwin, scr3;			\
3237c478bd9Sstevel@tonic-gate 	sll	scr3, 16, scr3;				\
3247c478bd9Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3257c478bd9Sstevel@tonic-gate 	rdpr	%wstate, scr3;				\
3267c478bd9Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3277c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F3]%asi;		\
3287c478bd9Sstevel@tonic-gate 	stna	%o7, [scr1 + TRAP_ENT_F4]%asi;		\
3297c478bd9Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3)
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate #define	FAULT_WINTRACE(scr1, scr2, scr3, type)		\
3347c478bd9Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
3357c478bd9Sstevel@tonic-gate 	GET_TRACE_TICK(scr2);				\
3367c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
3377c478bd9Sstevel@tonic-gate 	rdpr	%tl, scr2;				\
3387c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TL]%asi;		\
3397c478bd9Sstevel@tonic-gate 	set	type, scr2;				\
3407c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
3417c478bd9Sstevel@tonic-gate 	rdpr	%tpc, scr2;				\
3427c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
3437c478bd9Sstevel@tonic-gate 	rdpr	%tstate, scr2;				\
3447c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
3457c478bd9Sstevel@tonic-gate 	stna	%sp, [scr1 + TRAP_ENT_SP]%asi;		\
3467c478bd9Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_TR]%asi;		\
3477c478bd9Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_F1]%asi;		\
3487c478bd9Sstevel@tonic-gate 	stna	%g4, [scr1 + TRAP_ENT_F2]%asi;		\
3497c478bd9Sstevel@tonic-gate 	rdpr	%pil, scr2;				\
3507c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F3]%asi;		\
3517c478bd9Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_F4]%asi;		\
3527c478bd9Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3)
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate #define	SYSTRAP_TT	0x1300
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate #define	SYSTRAP_TRACE(scr1, scr2, scr3)			\
3577c478bd9Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
3587c478bd9Sstevel@tonic-gate 	GET_TRACE_TICK(scr2);				\
3597c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
3607c478bd9Sstevel@tonic-gate 	rdpr	%tl, scr2;				\
3617c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TL]%asi;		\
3627c478bd9Sstevel@tonic-gate 	set	SYSTRAP_TT, scr3;			\
3637c478bd9Sstevel@tonic-gate 	rdpr	%tt, scr2;				\
3647c478bd9Sstevel@tonic-gate 	or	scr3, scr2, scr2;			\
3657c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
3667c478bd9Sstevel@tonic-gate 	rdpr	%tpc, scr2;				\
3677c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
3687c478bd9Sstevel@tonic-gate 	rdpr	%tstate, scr2;				\
3697c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
3707c478bd9Sstevel@tonic-gate 	stna	%g1, [scr1 + TRAP_ENT_SP]%asi;		\
3717c478bd9Sstevel@tonic-gate 	stna	%g2, [scr1 + TRAP_ENT_TR]%asi;		\
3727c478bd9Sstevel@tonic-gate 	stna	%g3, [scr1 + TRAP_ENT_F1]%asi;		\
3737c478bd9Sstevel@tonic-gate 	stna	%g4, [scr1 + TRAP_ENT_F2]%asi;		\
3747c478bd9Sstevel@tonic-gate 	rdpr	%pil, scr2;				\
3757c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F3]%asi;		\
3767c478bd9Sstevel@tonic-gate 	rdpr	%cwp, scr2;				\
3777c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F4]%asi;		\
3787c478bd9Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3)
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate #else /* TRAPTRACE */
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate #define	FAULT_WINTRACE(scr1, scr2, scr3, type)
3837c478bd9Sstevel@tonic-gate #define	SYSTRAP_TRACE(scr1, scr2, scr3)
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate #endif	/* _ASM */
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate /*
3907c478bd9Sstevel@tonic-gate  * Trap trace codes used in place of a %tbr value when more than one
3917c478bd9Sstevel@tonic-gate  * entry is made by a trap.  The general scheme is that the trap-type is
3927c478bd9Sstevel@tonic-gate  * in the same position as in the TT, and the low-order bits indicate
3937c478bd9Sstevel@tonic-gate  * which precise entry is being made.
3947c478bd9Sstevel@tonic-gate  */
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate #define	TT_F32_SN0	0x1084
3977c478bd9Sstevel@tonic-gate #define	TT_F64_SN0	0x1088
3987c478bd9Sstevel@tonic-gate #define	TT_F32_NT0	0x1094
3997c478bd9Sstevel@tonic-gate #define	TT_F64_NT0	0x1098
4007c478bd9Sstevel@tonic-gate #define	TT_F32_SO0	0x10A4
4017c478bd9Sstevel@tonic-gate #define	TT_F64_SO0	0x10A8
4027c478bd9Sstevel@tonic-gate #define	TT_F32_FN0	0x10C4
4037c478bd9Sstevel@tonic-gate #define	TT_F64_FN0	0x10C8
4047c478bd9Sstevel@tonic-gate #define	TT_F32_SN1	0x1284
4057c478bd9Sstevel@tonic-gate #define	TT_F64_SN1	0x1288
4067c478bd9Sstevel@tonic-gate #define	TT_F32_NT1	0x1294
4077c478bd9Sstevel@tonic-gate #define	TT_F64_NT1	0x1298
4087c478bd9Sstevel@tonic-gate #define	TT_F32_SO1	0x12A4
4097c478bd9Sstevel@tonic-gate #define	TT_F64_SO1	0x12A8
4107c478bd9Sstevel@tonic-gate #define	TT_F32_FN1	0x12C4
4117c478bd9Sstevel@tonic-gate #define	TT_F64_FN1	0x12C8
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate #define	TT_SC_ENTR	0x880	/* enter system call */
4147c478bd9Sstevel@tonic-gate #define	TT_SC_RET	0x881	/* system call normal return */
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate #define	TT_SYS_RTT_PROM	0x5555	/* return from trap to prom */
4177c478bd9Sstevel@tonic-gate #define	TT_SYS_RTT_PRIV	0x6666	/* return from trap to privilege */
4187c478bd9Sstevel@tonic-gate #define	TT_SYS_RTT_USER	0x7777	/* return from trap to user */
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate #define	TT_INTR_EXIT	0x8888	/* interrupt thread exit (no pinned thread) */
4217c478bd9Sstevel@tonic-gate #define	TT_FSPILL_DEBUG	0x9999	/* fill/spill debugging */
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate #define	TT_SERVE_INTR	0x6000	/* SERVE_INTR */
4247c478bd9Sstevel@tonic-gate #define	TT_XCALL	0xd000	/* xcall/xtrap */
4257c478bd9Sstevel@tonic-gate #define	TT_XCALL_CONT	0xdc00	/* continuation of an xcall/xtrap record */
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate #define	TT_MMU_MISS	0x200	/* or'd into %tt to indicate a miss */
4287c478bd9Sstevel@tonic-gate #define	TT_SPURIOUS_INT	0x400	/* or'd into %tt for spurious intr. */
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4327c478bd9Sstevel@tonic-gate }
4337c478bd9Sstevel@tonic-gate #endif
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate #endif	/* _SYS_TRAPTRACE_H */
436