xref: /titanic_44/usr/src/uts/sun4v/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 #define	TRAP_TENABLE_ALL	-1	/* enable all hv traptracing */
347c478bd9Sstevel@tonic-gate #define	TRAP_TDISABLE_ALL	0	/* disable all hv traptracing */
357c478bd9Sstevel@tonic-gate #define	TRAP_TFREEZE_ALL	-1	/* freeze all hv traptracing */
367c478bd9Sstevel@tonic-gate #define	TRAP_TUNFREEZE_ALL	0	/* unfreeze all hv traptracing */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * Trap tracing. If TRAPTRACE is defined, every trap records info
407c478bd9Sstevel@tonic-gate  * in a circular buffer.  Define TRAPTRACE in Makefile.$ARCH.
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  * Trap trace records are TRAP_ENT_SIZE bytes, consisting of the
437c478bd9Sstevel@tonic-gate  * %tick, %tl, %tt, %tpc, %tstate, %sp, and a few other words:
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * struct trap_trace_record {
467c478bd9Sstevel@tonic-gate  *	ushort_t tl, tt;
477c478bd9Sstevel@tonic-gate  *	long	pc;
487c478bd9Sstevel@tonic-gate  *	int64_t	tstate, tick;
497c478bd9Sstevel@tonic-gate  *	long	sp, tr, f1, f2, f3, f4;
507c478bd9Sstevel@tonic-gate  * };
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * Note that for UltraSparc III and beyond %stick is used in place of %tick
537c478bd9Sstevel@tonic-gate  * unless compiled with TRAPTRACE_FORCE_TICK.
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  * Auxilliary entries (not of just a trap), have obvious non-%tt values in
567c478bd9Sstevel@tonic-gate  * the TRAP_ENT_TT field
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate 
5994119526Ssetje #define	TRAP_TBUF	(2 * PAGESIZE)	/* default size is two pages */
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #ifndef	_ASM
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * HV Trap trace header
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate typedef struct htrap_trace_hdr {
677c478bd9Sstevel@tonic-gate 	uint64_t	last_offset;	/* most recently completed entry */
687c478bd9Sstevel@tonic-gate 	uint64_t	offset;		/* next entry to be written */
697c478bd9Sstevel@tonic-gate 	uint64_t	dummy1;
707c478bd9Sstevel@tonic-gate 	uint64_t	dummy2;
717c478bd9Sstevel@tonic-gate 	uint64_t	dummy3;
727c478bd9Sstevel@tonic-gate 	uint64_t	dummy4;
737c478bd9Sstevel@tonic-gate 	uint64_t	dummy5;
747c478bd9Sstevel@tonic-gate 	uint64_t	dummy6;
757c478bd9Sstevel@tonic-gate } htrap_trace_hdr_t;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * HV Trap trace record
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate struct htrap_trace_record {
817c478bd9Sstevel@tonic-gate 	uint8_t		tt_ty;		/* Indicates HV or Guest entry */
827c478bd9Sstevel@tonic-gate 	uint8_t		tt_hpstate;	/* Hyper-privilege State */
837c478bd9Sstevel@tonic-gate 	uint8_t		tt_tl;		/* Trap level */
847c478bd9Sstevel@tonic-gate 	uint8_t		tt_gl;		/* Global register level */
857c478bd9Sstevel@tonic-gate 	uint16_t	tt_tt;		/* Trap type */
867c478bd9Sstevel@tonic-gate 	uint16_t	tt_tag;		/* Extended Trap Indentifier */
877c478bd9Sstevel@tonic-gate 	uint64_t	tt_tstate;	/* Trap state */
887c478bd9Sstevel@tonic-gate 	uint64_t	tt_tick;	/* Tick */
897c478bd9Sstevel@tonic-gate 	uint64_t	tt_tpc;		/* Trap PC */
907c478bd9Sstevel@tonic-gate 	uint64_t	tt_f1;		/* Entry specific */
917c478bd9Sstevel@tonic-gate 	uint64_t	tt_f2;		/* Entry specific */
927c478bd9Sstevel@tonic-gate 	uint64_t	tt_f3;		/* Entry specific */
937c478bd9Sstevel@tonic-gate 	uint64_t	tt_f4;		/* Entry specific */
947c478bd9Sstevel@tonic-gate };
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Kernel Trap trace record
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate struct trap_trace_record {
1007c478bd9Sstevel@tonic-gate 	uint8_t		tt_tl;
1017c478bd9Sstevel@tonic-gate 	uint8_t		tt_gl;
1027c478bd9Sstevel@tonic-gate 	uint16_t	tt_tt;
1037c478bd9Sstevel@tonic-gate 	uintptr_t	tt_tpc;
1047c478bd9Sstevel@tonic-gate 	uint64_t	tt_tstate;
1057c478bd9Sstevel@tonic-gate 	uint64_t	tt_tick;
1067c478bd9Sstevel@tonic-gate 	uintptr_t	tt_sp;
1077c478bd9Sstevel@tonic-gate 	uintptr_t	tt_tr;
1087c478bd9Sstevel@tonic-gate 	uintptr_t	tt_f1;
1097c478bd9Sstevel@tonic-gate 	uintptr_t	tt_f2;
1107c478bd9Sstevel@tonic-gate 	uintptr_t	tt_f3;
1117c478bd9Sstevel@tonic-gate 	uintptr_t	tt_f4;
1127c478bd9Sstevel@tonic-gate };
1137c478bd9Sstevel@tonic-gate 
11494119526Ssetje #define	TRAP_TSIZE	((TRAP_TBUF / sizeof (struct trap_trace_record)) * \
11594119526Ssetje 			sizeof (struct trap_trace_record))
11694119526Ssetje 
11794119526Ssetje /* Rounding not needed, done for consistency */
11894119526Ssetje #define	HTRAP_TSIZE	((TRAP_TBUF / sizeof (struct htrap_trace_record)) * \
11994119526Ssetje 			sizeof (struct htrap_trace_record))
12094119526Ssetje 
12194119526Ssetje #else
12294119526Ssetje 
12394119526Ssetje #define	TRAP_TSIZE	((TRAP_TBUF / TRAP_ENT_SIZE) * TRAP_ENT_SIZE)
12494119526Ssetje #define	HTRAP_TSIZE	((TRAP_TBUF / HTRAP_ENT_SIZE) * HTRAP_ENT_SIZE)
12594119526Ssetje 
1267c478bd9Sstevel@tonic-gate #endif
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * Trap tracing buffer header.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #ifndef	_ASM
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * Example buffer header stored in locore.s:
1367c478bd9Sstevel@tonic-gate  *
1377c478bd9Sstevel@tonic-gate  * (the actual implementation could be .skip TRAPTR_SIZE*NCPU)
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate typedef union {
1407c478bd9Sstevel@tonic-gate     struct {
1417c478bd9Sstevel@tonic-gate 	caddr_t		vaddr_base;	/* virtual address of top of buffer */
1427c478bd9Sstevel@tonic-gate 	uint64_t	paddr_base;	/* physical address of buffer */
1437c478bd9Sstevel@tonic-gate 	uint_t		last_offset;	/* to "know" what trace completed */
1447c478bd9Sstevel@tonic-gate 	uint_t		offset;		/* current index into buffer (bytes) */
1457c478bd9Sstevel@tonic-gate 	uint_t		limit;		/* upper limit on index */
1467c478bd9Sstevel@tonic-gate 	uchar_t		asi;		/* cache for real asi */
1477c478bd9Sstevel@tonic-gate 	caddr_t		hvaddr_base;	/* HV virtual addr of top of buffer */
1487c478bd9Sstevel@tonic-gate 	uint64_t	hpaddr_base;	/* HV physical addr of buffer */
1497c478bd9Sstevel@tonic-gate 	uint_t		hlimit;		/* HV upper limit on index */
1507c478bd9Sstevel@tonic-gate 	} d;
1517c478bd9Sstevel@tonic-gate     char		cache_linesize[64];
1527c478bd9Sstevel@tonic-gate } TRAP_TRACE_CTL;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate extern TRAP_TRACE_CTL	trap_trace_ctl[];	/* allocated in locore.s */
1577c478bd9Sstevel@tonic-gate extern int		trap_trace_bufsize;	/* default buffer size */
1587c478bd9Sstevel@tonic-gate extern char		trap_tr0[];		/* prealloc buf for boot cpu */
1597c478bd9Sstevel@tonic-gate extern int		trap_freeze;		/* freeze the trap trace */
160986fd29aSsetje extern caddr_t		ttrace_buf;		/* kmem64 buffer */
1617c478bd9Sstevel@tonic-gate extern int		ttrace_index;		/* index used */
162986fd29aSsetje extern size_t		calc_traptrace_sz(void);
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate extern int		htrap_trace_bufsize;	/* default hv buffer size */
165db6d2ee3Ssvemuri extern int		mach_htraptrace_enable;
166db6d2ee3Ssvemuri extern void mach_htraptrace_setup(int);
167db6d2ee3Ssvemuri extern void mach_htraptrace_configure(int);
168db6d2ee3Ssvemuri extern void mach_htraptrace_cleanup(int);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate #endif
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate  * freeze the trap trace
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate #define	TRAPTRACE_FREEZE	trap_freeze = 1;
1767c478bd9Sstevel@tonic-gate #define	TRAPTRACE_UNFREEZE	trap_freeze = 0;
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate #else /* _ASM */
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate #include <sys/machthread.h>
181*023e71deSHaik Aftandilian #include <sys/machclock.h>
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate  * Offsets of words in trap_trace_ctl:
1857c478bd9Sstevel@tonic-gate  */
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate  * XXX This should be done with genassym
1887c478bd9Sstevel@tonic-gate  */
1897c478bd9Sstevel@tonic-gate #define	TRAPTR_VBASE	0		/* virtual address of buffer */
1907c478bd9Sstevel@tonic-gate #define	TRAPTR_LAST_OFFSET 16		/* last completed trace entry */
1917c478bd9Sstevel@tonic-gate #define	TRAPTR_OFFSET	20		/* next trace entry pointer */
1927c478bd9Sstevel@tonic-gate #define	TRAPTR_LIMIT	24		/* pointer past end of buffer */
1937c478bd9Sstevel@tonic-gate #define	TRAPTR_PBASE	8		/* start of buffer */
1947c478bd9Sstevel@tonic-gate #define	TRAPTR_ASIBUF	28		/* cache of current asi */
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate #define	TRAPTR_HVBASE	32		/* HV virtual address of buffer */
1977c478bd9Sstevel@tonic-gate #define	TRAPTR_HPBASE	40		/* HV start of buffer */
1987c478bd9Sstevel@tonic-gate #define	TRAPTR_HLIMIT	48		/* HV pointer past end of buffer */
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate #define	TRAPTR_SIZE_SHIFT	6	/* shift count -- per CPU indexing */
2017c478bd9Sstevel@tonic-gate #define	TRAPTR_SIZE		(1<<TRAPTR_SIZE_SHIFT)
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate #define	TRAPTR_ASI	ASI_MEM		/* ASI to use for TRAPTR access */
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate /*
2067c478bd9Sstevel@tonic-gate  * Use new %stick register for UltraSparc III and beyond for
2077c478bd9Sstevel@tonic-gate  * sane debugging of mixed speed CPU systems. Use TRAPTRACE_FORCE_TICK
208*023e71deSHaik Aftandilian  * for finer granularity on same speed systems. Note that traptrace
209*023e71deSHaik Aftandilian  * %tick or %stick reads use the NO_SUSPEND_CHECK version of the
210*023e71deSHaik Aftandilian  * register read macros. This requires fewer registers and a few less
211*023e71deSHaik Aftandilian  * instructions to execute. As a result, if a suspend operation occurs
212*023e71deSHaik Aftandilian  * while traptrace is executing GET_TRACE_TICK between the time that
213*023e71deSHaik Aftandilian  * the counter offset variable is read and the hardware register is read,
214*023e71deSHaik Aftandilian  * this traptrace entry in the log will have an incorrect %tick value
215*023e71deSHaik Aftandilian  * since it is derived from a pre-suspend offset variable and a post-
216*023e71deSHaik Aftandilian  * suspend hardware counter.
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate #ifdef	TRAPTRACE_FORCE_TICK
219*023e71deSHaik Aftandilian #define	GET_TRACE_TICK(reg, scr)				\
220*023e71deSHaik Aftandilian 	RD_TICK_NO_SUSPEND_CHECK(reg, scr);
2217c478bd9Sstevel@tonic-gate #else
222*023e71deSHaik Aftandilian #define	GET_TRACE_TICK(reg, scr)				\
223*023e71deSHaik Aftandilian 	RD_TICKSTICK_FLAG(reg, scr, traptrace_use_stick);
2247c478bd9Sstevel@tonic-gate #endif
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate /*
2277c478bd9Sstevel@tonic-gate  * TRACE_PTR(ptr, scr1) - get trap trace entry physical pointer.
2287c478bd9Sstevel@tonic-gate  *	ptr is the register to receive the trace pointer.
2297c478bd9Sstevel@tonic-gate  *	scr1 is a different register to be used as scratch.
2307c478bd9Sstevel@tonic-gate  * TRACING now needs a known processor state.  Hence the assertion.
2317c478bd9Sstevel@tonic-gate  *	NOTE: this caches and resets %asi
2327c478bd9Sstevel@tonic-gate  */
2337c478bd9Sstevel@tonic-gate #define	TRACE_PTR(ptr, scr1)				\
2347c478bd9Sstevel@tonic-gate 	sethi	%hi(trap_freeze), ptr;			\
2357c478bd9Sstevel@tonic-gate 	ld	[ptr + %lo(trap_freeze)], ptr;		\
2367c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
2377c478bd9Sstevel@tonic-gate 	brnz,pn	ptr, .+20; /* skip assertion */		\
2387c478bd9Sstevel@tonic-gate 	rdpr	%pstate, scr1;				\
2397c478bd9Sstevel@tonic-gate 	andcc	scr1, PSTATE_IE | PSTATE_AM, scr1;	\
2407c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
2417c478bd9Sstevel@tonic-gate 	bne,a,pn %icc, trace_ptr_panic;			\
2427c478bd9Sstevel@tonic-gate 	rd	%pc, %g1;				\
2437c478bd9Sstevel@tonic-gate 	CPU_INDEX(scr1, ptr);				\
2447c478bd9Sstevel@tonic-gate 	sll	scr1, TRAPTR_SIZE_SHIFT, scr1;		\
2457c478bd9Sstevel@tonic-gate 	set	trap_trace_ctl, ptr; 			\
2467c478bd9Sstevel@tonic-gate 	add	ptr, scr1, scr1;			\
2477c478bd9Sstevel@tonic-gate 	rd	%asi, ptr;				\
2487c478bd9Sstevel@tonic-gate 	stb	ptr, [scr1 + TRAPTR_ASIBUF];		\
2497c478bd9Sstevel@tonic-gate 	sethi	%hi(trap_freeze), ptr;			\
2507c478bd9Sstevel@tonic-gate 	ld	[ptr + %lo(trap_freeze)], ptr;		\
2517c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
2527c478bd9Sstevel@tonic-gate 	brnz,pn	ptr, .+20; /* skip assertion */		\
2537c478bd9Sstevel@tonic-gate 	ld	[scr1 + TRAPTR_LIMIT], ptr;		\
2547c478bd9Sstevel@tonic-gate 	tst	ptr;					\
2557c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
2567c478bd9Sstevel@tonic-gate 	be,a,pn	%icc, trace_ptr_panic;			\
2577c478bd9Sstevel@tonic-gate 	rd	%pc, %g1;				\
2587c478bd9Sstevel@tonic-gate 	ldx	[scr1 + TRAPTR_PBASE], ptr;		\
2597c478bd9Sstevel@tonic-gate 	ld	[scr1 + TRAPTR_OFFSET], scr1;		\
2607c478bd9Sstevel@tonic-gate 	wr	%g0, TRAPTR_ASI, %asi;			\
2617c478bd9Sstevel@tonic-gate 	add	ptr, scr1, ptr;
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate  * TRACE_NEXT(scr1, scr2, scr3) - advance the trap trace pointer.
2657c478bd9Sstevel@tonic-gate  *	scr1, scr2, scr3 are scratch registers.
2667c478bd9Sstevel@tonic-gate  *	This routine will skip updating the trap pointers if the
2677c478bd9Sstevel@tonic-gate  *	global freeze register is set (e.g. in panic).
2687c478bd9Sstevel@tonic-gate  *	(we also restore the asi register)
2697c478bd9Sstevel@tonic-gate  */
2707c478bd9Sstevel@tonic-gate #define	TRACE_NEXT(scr1, scr2, scr3)			\
2717c478bd9Sstevel@tonic-gate 	CPU_INDEX(scr2, scr1);				\
2727c478bd9Sstevel@tonic-gate 	sll	scr2, TRAPTR_SIZE_SHIFT, scr2;		\
2737c478bd9Sstevel@tonic-gate 	set	trap_trace_ctl, scr1; 			\
2747c478bd9Sstevel@tonic-gate 	add	scr1, scr2, scr2;			\
2757c478bd9Sstevel@tonic-gate 	ldub	[scr2 + TRAPTR_ASIBUF], scr1;		\
2767c478bd9Sstevel@tonic-gate 	wr	%g0, scr1, %asi;			\
2777c478bd9Sstevel@tonic-gate 	sethi	%hi(trap_freeze), scr1;			\
2787c478bd9Sstevel@tonic-gate 	ld	[scr1 + %lo(trap_freeze)], scr1;	\
2797c478bd9Sstevel@tonic-gate 	/* CSTYLED */					\
2807c478bd9Sstevel@tonic-gate 	brnz	scr1, .+36; /* skip update on freeze */	\
2817c478bd9Sstevel@tonic-gate 	ld	[scr2 + TRAPTR_OFFSET], scr1;		\
2827c478bd9Sstevel@tonic-gate 	ld	[scr2 + TRAPTR_LIMIT], scr3;		\
2837c478bd9Sstevel@tonic-gate 	st	scr1, [scr2 + TRAPTR_LAST_OFFSET];	\
2847c478bd9Sstevel@tonic-gate 	add	scr1, TRAP_ENT_SIZE, scr1;		\
2857c478bd9Sstevel@tonic-gate 	sub	scr3, TRAP_ENT_SIZE, scr3;		\
2867c478bd9Sstevel@tonic-gate 	cmp	scr1, scr3;				\
2877c478bd9Sstevel@tonic-gate 	movge	%icc, 0, scr1;				\
2887c478bd9Sstevel@tonic-gate 	st	scr1, [scr2 + TRAPTR_OFFSET];
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate /*
2917c478bd9Sstevel@tonic-gate  * macro to save %tl, %gl to trap trace record at addr
2927c478bd9Sstevel@tonic-gate  */
2937c478bd9Sstevel@tonic-gate #define	TRACE_SAVE_TL_GL_REGS(addr, scr1)		\
2947c478bd9Sstevel@tonic-gate 	rdpr	%tl, scr1;				\
2957c478bd9Sstevel@tonic-gate 	stba	scr1, [addr + TRAP_ENT_TL]%asi;		\
2967c478bd9Sstevel@tonic-gate 	rdpr	%gl, scr1;				\
2977c478bd9Sstevel@tonic-gate 	stba	scr1, [addr + TRAP_ENT_GL]%asi
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate /*
3007c478bd9Sstevel@tonic-gate  * macro to save tl to trap trace record at addr
3017c478bd9Sstevel@tonic-gate  */
3027c478bd9Sstevel@tonic-gate #define	TRACE_SAVE_TL_VAL(addr, tl)			\
3037c478bd9Sstevel@tonic-gate 	stba	tl, [addr + TRAP_ENT_TL]%asi
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate /*
3067c478bd9Sstevel@tonic-gate  * macro to save gl to trap trace record at addr
3077c478bd9Sstevel@tonic-gate  */
3087c478bd9Sstevel@tonic-gate #define	TRACE_SAVE_GL_VAL(addr, gl)			\
3097c478bd9Sstevel@tonic-gate 	stba	gl, [addr + TRAP_ENT_GL]%asi
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate /*
3137c478bd9Sstevel@tonic-gate  * Trace macro for sys_trap return entries:
3147c478bd9Sstevel@tonic-gate  *	prom_rtt, priv_rtt, and user_rtt
3157c478bd9Sstevel@tonic-gate  *	%l7 - regs
3167c478bd9Sstevel@tonic-gate  *	%l6 - trap %pil for prom_rtt and priv_rtt; THREAD_REG for user_rtt
3177c478bd9Sstevel@tonic-gate  */
3187c478bd9Sstevel@tonic-gate #define	TRACE_RTT(code, scr1, scr2, scr3, scr4)		\
3197c478bd9Sstevel@tonic-gate 	rdpr	%pstate, scr4;				\
3207c478bd9Sstevel@tonic-gate 	andn	scr4, PSTATE_IE | PSTATE_AM, scr3;	\
3217c478bd9Sstevel@tonic-gate 	wrpr	%g0, scr3, %pstate;			\
3227c478bd9Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
323*023e71deSHaik Aftandilian 	GET_TRACE_TICK(scr2, scr3);			\
3247c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
3257c478bd9Sstevel@tonic-gate 	TRACE_SAVE_TL_GL_REGS(scr1, scr2);		\
3267c478bd9Sstevel@tonic-gate 	set	code, scr2;				\
3277c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
3287c478bd9Sstevel@tonic-gate 	ldn	[%l7 + PC_OFF], scr2;			\
3297c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
3307c478bd9Sstevel@tonic-gate 	ldx	[%l7 + TSTATE_OFF], scr2;		\
3317c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
3327c478bd9Sstevel@tonic-gate 	stna	%sp, [scr1 + TRAP_ENT_SP]%asi;		\
3337c478bd9Sstevel@tonic-gate 	stna	%l6, [scr1 + TRAP_ENT_TR]%asi;		\
3347c478bd9Sstevel@tonic-gate 	stna	%l7, [scr1 + TRAP_ENT_F1]%asi;		\
3357c478bd9Sstevel@tonic-gate 	ldn	[THREAD_REG + T_CPU], scr2;		\
3367c478bd9Sstevel@tonic-gate 	ld	[scr2 + CPU_BASE_SPL], scr2;		\
3377c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F2]%asi;		\
3387c478bd9Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_F3]%asi;		\
3397c478bd9Sstevel@tonic-gate 	rdpr	%cwp, scr2;				\
3407c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F4]%asi;		\
3417c478bd9Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3);			\
3427c478bd9Sstevel@tonic-gate 	wrpr	%g0, scr4, %pstate
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate /*
3457c478bd9Sstevel@tonic-gate  * Trace macro for spill and fill trap handlers
3467c478bd9Sstevel@tonic-gate  *	tl and tt fields indicate which spill handler is entered
3477c478bd9Sstevel@tonic-gate  */
3487c478bd9Sstevel@tonic-gate #define	TRACE_WIN_INFO(code, scr1, scr2, scr3)		\
3497c478bd9Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
350*023e71deSHaik Aftandilian 	GET_TRACE_TICK(scr2, scr3);			\
3517c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
3527c478bd9Sstevel@tonic-gate 	TRACE_SAVE_TL_GL_REGS(scr1, scr2);		\
3537c478bd9Sstevel@tonic-gate 	rdpr	%tt, scr2;				\
3547c478bd9Sstevel@tonic-gate 	set	code, scr3;				\
3557c478bd9Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3567c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
3577c478bd9Sstevel@tonic-gate 	rdpr	%tstate, scr2;				\
3587c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
3597c478bd9Sstevel@tonic-gate 	stna	%sp, [scr1 + TRAP_ENT_SP]%asi;		\
3607c478bd9Sstevel@tonic-gate 	rdpr	%tpc, scr2;				\
3617c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
3627c478bd9Sstevel@tonic-gate 	set	TT_FSPILL_DEBUG, scr2;			\
3637c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TR]%asi;		\
3647c478bd9Sstevel@tonic-gate 	rdpr	%pstate, scr2;				\
3657c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F1]%asi;		\
3667c478bd9Sstevel@tonic-gate 	rdpr	%cwp, scr2;				\
3677c478bd9Sstevel@tonic-gate 	sll	scr2, 24, scr2;				\
3687c478bd9Sstevel@tonic-gate 	rdpr	%cansave, scr3;				\
3697c478bd9Sstevel@tonic-gate 	sll	scr3, 16, scr3;				\
3707c478bd9Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3717c478bd9Sstevel@tonic-gate 	rdpr	%canrestore, scr3;			\
3727c478bd9Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3737c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F2]%asi;		\
3747c478bd9Sstevel@tonic-gate 	rdpr	%otherwin, scr2;			\
3757c478bd9Sstevel@tonic-gate 	sll	scr2, 24, scr2;				\
3767c478bd9Sstevel@tonic-gate 	rdpr	%cleanwin, scr3;			\
3777c478bd9Sstevel@tonic-gate 	sll	scr3, 16, scr3;				\
3787c478bd9Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3797c478bd9Sstevel@tonic-gate 	rdpr	%wstate, scr3;				\
3807c478bd9Sstevel@tonic-gate 	or	scr2, scr3, scr2;			\
3817c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F3]%asi;		\
3827c478bd9Sstevel@tonic-gate 	stna	%o7, [scr1 + TRAP_ENT_F4]%asi;		\
3837c478bd9Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3)
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate #define	FAULT_WINTRACE(scr1, scr2, scr3, type)		\
3887c478bd9Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
389*023e71deSHaik Aftandilian 	GET_TRACE_TICK(scr2, scr3);			\
3907c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
3917c478bd9Sstevel@tonic-gate 	TRACE_SAVE_TL_GL_REGS(scr1, scr2);		\
3927c478bd9Sstevel@tonic-gate 	set	type, scr2;				\
3937c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
3947c478bd9Sstevel@tonic-gate 	rdpr	%tpc, scr2;				\
3957c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
3967c478bd9Sstevel@tonic-gate 	rdpr	%tstate, scr2;				\
3977c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
3987c478bd9Sstevel@tonic-gate 	stna	%sp, [scr1 + TRAP_ENT_SP]%asi;		\
3997c478bd9Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_TR]%asi;		\
4007c478bd9Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_F1]%asi;		\
4017c478bd9Sstevel@tonic-gate 	stna	%g4, [scr1 + TRAP_ENT_F2]%asi;		\
4027c478bd9Sstevel@tonic-gate 	rdpr	%pil, scr2;				\
4037c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F3]%asi;		\
4047c478bd9Sstevel@tonic-gate 	stna	%g0, [scr1 + TRAP_ENT_F4]%asi;		\
4057c478bd9Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3)
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate #define	SYSTRAP_TT	0x1300
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate #define	SYSTRAP_TRACE(scr1, scr2, scr3)			\
4107c478bd9Sstevel@tonic-gate 	TRACE_PTR(scr1, scr2);				\
411*023e71deSHaik Aftandilian 	GET_TRACE_TICK(scr2, scr3);			\
4127c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TICK]%asi;	\
4137c478bd9Sstevel@tonic-gate 	TRACE_SAVE_TL_GL_REGS(scr1, scr2);		\
4147c478bd9Sstevel@tonic-gate 	set	SYSTRAP_TT, scr3;			\
4157c478bd9Sstevel@tonic-gate 	rdpr	%tt, scr2;				\
4167c478bd9Sstevel@tonic-gate 	or	scr3, scr2, scr2;			\
4177c478bd9Sstevel@tonic-gate 	stha	scr2, [scr1 + TRAP_ENT_TT]%asi;		\
4187c478bd9Sstevel@tonic-gate 	rdpr	%tpc, scr2;				\
4197c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_TPC]%asi;	\
4207c478bd9Sstevel@tonic-gate 	rdpr	%tstate, scr2;				\
4217c478bd9Sstevel@tonic-gate 	stxa	scr2, [scr1 + TRAP_ENT_TSTATE]%asi;	\
4227c478bd9Sstevel@tonic-gate 	stna	%g1, [scr1 + TRAP_ENT_SP]%asi;		\
4237c478bd9Sstevel@tonic-gate 	stna	%g2, [scr1 + TRAP_ENT_TR]%asi;		\
4247c478bd9Sstevel@tonic-gate 	stna	%g3, [scr1 + TRAP_ENT_F1]%asi;		\
4257c478bd9Sstevel@tonic-gate 	stna	%g4, [scr1 + TRAP_ENT_F2]%asi;		\
4267c478bd9Sstevel@tonic-gate 	rdpr	%pil, scr2;				\
4277c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F3]%asi;		\
4287c478bd9Sstevel@tonic-gate 	rdpr	%cwp, scr2;				\
4297c478bd9Sstevel@tonic-gate 	stna	scr2, [scr1 + TRAP_ENT_F4]%asi;		\
4307c478bd9Sstevel@tonic-gate 	TRACE_NEXT(scr1, scr2, scr3)
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate #else /* TRAPTRACE */
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate #define	FAULT_WINTRACE(scr1, scr2, scr3, type)
4357c478bd9Sstevel@tonic-gate #define	SYSTRAP_TRACE(scr1, scr2, scr3)
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate #endif	/* _ASM */
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate /*
4427c478bd9Sstevel@tonic-gate  * Trap trace codes used in place of a %tbr value when more than one
4437c478bd9Sstevel@tonic-gate  * entry is made by a trap.  The general scheme is that the trap-type is
4447c478bd9Sstevel@tonic-gate  * in the same position as in the TT, and the low-order bits indicate
4457c478bd9Sstevel@tonic-gate  * which precise entry is being made.
4467c478bd9Sstevel@tonic-gate  */
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate #define	TT_F32_SN0	0x1084
4497c478bd9Sstevel@tonic-gate #define	TT_F64_SN0	0x1088
4507c478bd9Sstevel@tonic-gate #define	TT_F32_NT0	0x1094
4517c478bd9Sstevel@tonic-gate #define	TT_F64_NT0	0x1098
4527c478bd9Sstevel@tonic-gate #define	TT_F32_SO0	0x10A4
4537c478bd9Sstevel@tonic-gate #define	TT_F64_SO0	0x10A8
4547c478bd9Sstevel@tonic-gate #define	TT_F32_FN0	0x10C4
4557c478bd9Sstevel@tonic-gate #define	TT_F64_FN0	0x10C8
4567c478bd9Sstevel@tonic-gate #define	TT_F32_SN1	0x1284
4577c478bd9Sstevel@tonic-gate #define	TT_F64_SN1	0x1288
4587c478bd9Sstevel@tonic-gate #define	TT_F32_NT1	0x1294
4597c478bd9Sstevel@tonic-gate #define	TT_F64_NT1	0x1298
4607c478bd9Sstevel@tonic-gate #define	TT_F32_SO1	0x12A4
4617c478bd9Sstevel@tonic-gate #define	TT_F64_SO1	0x12A8
4627c478bd9Sstevel@tonic-gate #define	TT_F32_FN1	0x12C4
4637c478bd9Sstevel@tonic-gate #define	TT_F64_FN1	0x12C8
4647c478bd9Sstevel@tonic-gate #define	TT_RTT_FN1	0x12DD
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate #define	TT_SC_ENTR	0x880	/* enter system call */
4677c478bd9Sstevel@tonic-gate #define	TT_SC_RET	0x881	/* system call normal return */
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate #define	TT_SYS_RTT_PROM	0x5555	/* return from trap to prom */
4707c478bd9Sstevel@tonic-gate #define	TT_SYS_RTT_PRIV	0x6666	/* return from trap to privilege */
4717c478bd9Sstevel@tonic-gate #define	TT_SYS_RTT_USER	0x7777	/* return from trap to user */
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate #define	TT_INTR_EXIT	0x8888	/* interrupt thread exit (no pinned thread) */
4747c478bd9Sstevel@tonic-gate #define	TT_FSPILL_DEBUG	0x9999	/* fill/spill debugging */
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate #define	TT_SERVE_INTR	0x6000	/* SERVE_INTR */
4777c478bd9Sstevel@tonic-gate #define	TT_XCALL	0xd000	/* xcall/xtrap */
4787c478bd9Sstevel@tonic-gate #define	TT_XCALL_CONT	0xdc00	/* continuation of an xcall/xtrap record */
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate #define	TT_MMU_MISS	0x200	/* or'd into %tt to indicate a miss */
4817c478bd9Sstevel@tonic-gate #define	TT_MMU_EXEC	0x400	/* or'd into %tt to indicate exec_fault */
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate #endif
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate #endif	/* _SYS_TRAPTRACE_H */
489