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