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