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 #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 617c478bd9Sstevel@tonic-gate #define TRAP_TBUF (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 #define TRAP_TSIZE ((TRAP_TBUF / sizeof (struct trap_trace_record)) * \ 1177c478bd9Sstevel@tonic-gate sizeof (struct trap_trace_record)) 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* Rounding not needed, done for consistency */ 1207c478bd9Sstevel@tonic-gate #define HTRAP_TSIZE ((TRAP_TBUF / sizeof (struct htrap_trace_record)) * \ 1217c478bd9Sstevel@tonic-gate sizeof (struct htrap_trace_record)) 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate #else 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate #define TRAP_TSIZE ((TRAP_TBUF / TRAP_ENT_SIZE) * TRAP_ENT_SIZE) 1267c478bd9Sstevel@tonic-gate #define HTRAP_TSIZE ((TRAP_TBUF / HTRAP_ENT_SIZE) * HTRAP_ENT_SIZE) 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate #endif 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* 1317c478bd9Sstevel@tonic-gate * Trap tracing buffer header. 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate #ifndef _ASM 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * Example buffer header stored in locore.s: 1387c478bd9Sstevel@tonic-gate * 1397c478bd9Sstevel@tonic-gate * (the actual implementation could be .skip TRAPTR_SIZE*NCPU) 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate typedef union { 1427c478bd9Sstevel@tonic-gate struct { 1437c478bd9Sstevel@tonic-gate caddr_t vaddr_base; /* virtual address of top of buffer */ 1447c478bd9Sstevel@tonic-gate uint64_t paddr_base; /* physical address of buffer */ 1457c478bd9Sstevel@tonic-gate uint_t last_offset; /* to "know" what trace completed */ 1467c478bd9Sstevel@tonic-gate uint_t offset; /* current index into buffer (bytes) */ 1477c478bd9Sstevel@tonic-gate uint_t limit; /* upper limit on index */ 1487c478bd9Sstevel@tonic-gate uchar_t asi; /* cache for real asi */ 1497c478bd9Sstevel@tonic-gate caddr_t hvaddr_base; /* HV virtual addr of top of buffer */ 1507c478bd9Sstevel@tonic-gate uint64_t hpaddr_base; /* HV physical addr of buffer */ 1517c478bd9Sstevel@tonic-gate uint_t hlimit; /* HV upper limit on index */ 1527c478bd9Sstevel@tonic-gate } d; 1537c478bd9Sstevel@tonic-gate char cache_linesize[64]; 1547c478bd9Sstevel@tonic-gate } TRAP_TRACE_CTL; 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate extern TRAP_TRACE_CTL trap_trace_ctl[]; /* allocated in locore.s */ 1597c478bd9Sstevel@tonic-gate extern int trap_trace_bufsize; /* default buffer size */ 1607c478bd9Sstevel@tonic-gate extern char trap_tr0[]; /* prealloc buf for boot cpu */ 1617c478bd9Sstevel@tonic-gate extern int trap_freeze; /* freeze the trap trace */ 1627c478bd9Sstevel@tonic-gate extern caddr_t ttrace_buf; /* buffer bop alloced */ 1637c478bd9Sstevel@tonic-gate extern int ttrace_index; /* index used */ 1647c478bd9Sstevel@tonic-gate extern caddr_t trap_trace_alloc(caddr_t); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate extern int htrap_trace_bufsize; /* default hv buffer size */ 167db6d2ee3Ssvemuri extern int mach_htraptrace_enable; 168db6d2ee3Ssvemuri extern void mach_htraptrace_setup(int); 169db6d2ee3Ssvemuri extern void mach_htraptrace_configure(int); 170db6d2ee3Ssvemuri extern void mach_htraptrace_cleanup(int); 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate #endif 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate /* 1757c478bd9Sstevel@tonic-gate * freeze the trap trace 1767c478bd9Sstevel@tonic-gate */ 1777c478bd9Sstevel@tonic-gate #define TRAPTRACE_FREEZE trap_freeze = 1; 1787c478bd9Sstevel@tonic-gate #define TRAPTRACE_UNFREEZE trap_freeze = 0; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate #else /* _ASM */ 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate #include <sys/machthread.h> 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate /* 1857c478bd9Sstevel@tonic-gate * Offsets of words in trap_trace_ctl: 1867c478bd9Sstevel@tonic-gate */ 1877c478bd9Sstevel@tonic-gate /* 1887c478bd9Sstevel@tonic-gate * XXX This should be done with genassym 1897c478bd9Sstevel@tonic-gate */ 1907c478bd9Sstevel@tonic-gate #define TRAPTR_VBASE 0 /* virtual address of buffer */ 1917c478bd9Sstevel@tonic-gate #define TRAPTR_LAST_OFFSET 16 /* last completed trace entry */ 1927c478bd9Sstevel@tonic-gate #define TRAPTR_OFFSET 20 /* next trace entry pointer */ 1937c478bd9Sstevel@tonic-gate #define TRAPTR_LIMIT 24 /* pointer past end of buffer */ 1947c478bd9Sstevel@tonic-gate #define TRAPTR_PBASE 8 /* start of buffer */ 1957c478bd9Sstevel@tonic-gate #define TRAPTR_ASIBUF 28 /* cache of current asi */ 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate #define TRAPTR_HVBASE 32 /* HV virtual address of buffer */ 1987c478bd9Sstevel@tonic-gate #define TRAPTR_HPBASE 40 /* HV start of buffer */ 1997c478bd9Sstevel@tonic-gate #define TRAPTR_HLIMIT 48 /* HV pointer past end of buffer */ 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate #define TRAPTR_SIZE_SHIFT 6 /* shift count -- per CPU indexing */ 2027c478bd9Sstevel@tonic-gate #define TRAPTR_SIZE (1<<TRAPTR_SIZE_SHIFT) 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate #define TRAPTR_ASI ASI_MEM /* ASI to use for TRAPTR access */ 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * Use new %stick register for UltraSparc III and beyond for 2087c478bd9Sstevel@tonic-gate * sane debugging of mixed speed CPU systems. Use TRAPTRACE_FORCE_TICK 2097c478bd9Sstevel@tonic-gate * for finer granularity on same speed systems. 2107c478bd9Sstevel@tonic-gate * 2117c478bd9Sstevel@tonic-gate * Note the label-less branches used due to contraints of where 2127c478bd9Sstevel@tonic-gate * and when trap trace macros are used. 2137c478bd9Sstevel@tonic-gate */ 2147c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE_FORCE_TICK 2157c478bd9Sstevel@tonic-gate #define GET_TRACE_TICK(reg) \ 2167c478bd9Sstevel@tonic-gate rdpr %tick, reg; 2177c478bd9Sstevel@tonic-gate #else 2187c478bd9Sstevel@tonic-gate #define GET_TRACE_TICK(reg) \ 2197c478bd9Sstevel@tonic-gate sethi %hi(traptrace_use_stick), reg; \ 2207c478bd9Sstevel@tonic-gate lduw [reg + %lo(traptrace_use_stick)], reg; \ 2217c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 2227c478bd9Sstevel@tonic-gate brz,a reg, .+12; \ 2237c478bd9Sstevel@tonic-gate rdpr %tick, reg; \ 2247c478bd9Sstevel@tonic-gate rd %asr24, reg; 2257c478bd9Sstevel@tonic-gate #endif 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate /* 2287c478bd9Sstevel@tonic-gate * TRACE_PTR(ptr, scr1) - get trap trace entry physical pointer. 2297c478bd9Sstevel@tonic-gate * ptr is the register to receive the trace pointer. 2307c478bd9Sstevel@tonic-gate * scr1 is a different register to be used as scratch. 2317c478bd9Sstevel@tonic-gate * TRACING now needs a known processor state. Hence the assertion. 2327c478bd9Sstevel@tonic-gate * NOTE: this caches and resets %asi 2337c478bd9Sstevel@tonic-gate */ 2347c478bd9Sstevel@tonic-gate #define TRACE_PTR(ptr, scr1) \ 2357c478bd9Sstevel@tonic-gate sethi %hi(trap_freeze), ptr; \ 2367c478bd9Sstevel@tonic-gate ld [ptr + %lo(trap_freeze)], ptr; \ 2377c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 2387c478bd9Sstevel@tonic-gate brnz,pn ptr, .+20; /* skip assertion */ \ 2397c478bd9Sstevel@tonic-gate rdpr %pstate, scr1; \ 2407c478bd9Sstevel@tonic-gate andcc scr1, PSTATE_IE | PSTATE_AM, scr1; \ 2417c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 2427c478bd9Sstevel@tonic-gate bne,a,pn %icc, trace_ptr_panic; \ 2437c478bd9Sstevel@tonic-gate rd %pc, %g1; \ 2447c478bd9Sstevel@tonic-gate CPU_INDEX(scr1, ptr); \ 2457c478bd9Sstevel@tonic-gate sll scr1, TRAPTR_SIZE_SHIFT, scr1; \ 2467c478bd9Sstevel@tonic-gate set trap_trace_ctl, ptr; \ 2477c478bd9Sstevel@tonic-gate add ptr, scr1, scr1; \ 2487c478bd9Sstevel@tonic-gate rd %asi, ptr; \ 2497c478bd9Sstevel@tonic-gate stb ptr, [scr1 + TRAPTR_ASIBUF]; \ 2507c478bd9Sstevel@tonic-gate sethi %hi(trap_freeze), ptr; \ 2517c478bd9Sstevel@tonic-gate ld [ptr + %lo(trap_freeze)], ptr; \ 2527c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 2537c478bd9Sstevel@tonic-gate brnz,pn ptr, .+20; /* skip assertion */ \ 2547c478bd9Sstevel@tonic-gate ld [scr1 + TRAPTR_LIMIT], ptr; \ 2557c478bd9Sstevel@tonic-gate tst ptr; \ 2567c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 2577c478bd9Sstevel@tonic-gate be,a,pn %icc, trace_ptr_panic; \ 2587c478bd9Sstevel@tonic-gate rd %pc, %g1; \ 2597c478bd9Sstevel@tonic-gate ldx [scr1 + TRAPTR_PBASE], ptr; \ 2607c478bd9Sstevel@tonic-gate ld [scr1 + TRAPTR_OFFSET], scr1; \ 2617c478bd9Sstevel@tonic-gate wr %g0, TRAPTR_ASI, %asi; \ 2627c478bd9Sstevel@tonic-gate add ptr, scr1, ptr; 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* 2657c478bd9Sstevel@tonic-gate * TRACE_NEXT(scr1, scr2, scr3) - advance the trap trace pointer. 2667c478bd9Sstevel@tonic-gate * scr1, scr2, scr3 are scratch registers. 2677c478bd9Sstevel@tonic-gate * This routine will skip updating the trap pointers if the 2687c478bd9Sstevel@tonic-gate * global freeze register is set (e.g. in panic). 2697c478bd9Sstevel@tonic-gate * (we also restore the asi register) 2707c478bd9Sstevel@tonic-gate */ 2717c478bd9Sstevel@tonic-gate #define TRACE_NEXT(scr1, scr2, scr3) \ 2727c478bd9Sstevel@tonic-gate CPU_INDEX(scr2, scr1); \ 2737c478bd9Sstevel@tonic-gate sll scr2, TRAPTR_SIZE_SHIFT, scr2; \ 2747c478bd9Sstevel@tonic-gate set trap_trace_ctl, scr1; \ 2757c478bd9Sstevel@tonic-gate add scr1, scr2, scr2; \ 2767c478bd9Sstevel@tonic-gate ldub [scr2 + TRAPTR_ASIBUF], scr1; \ 2777c478bd9Sstevel@tonic-gate wr %g0, scr1, %asi; \ 2787c478bd9Sstevel@tonic-gate sethi %hi(trap_freeze), scr1; \ 2797c478bd9Sstevel@tonic-gate ld [scr1 + %lo(trap_freeze)], scr1; \ 2807c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 2817c478bd9Sstevel@tonic-gate brnz scr1, .+36; /* skip update on freeze */ \ 2827c478bd9Sstevel@tonic-gate ld [scr2 + TRAPTR_OFFSET], scr1; \ 2837c478bd9Sstevel@tonic-gate ld [scr2 + TRAPTR_LIMIT], scr3; \ 2847c478bd9Sstevel@tonic-gate st scr1, [scr2 + TRAPTR_LAST_OFFSET]; \ 2857c478bd9Sstevel@tonic-gate add scr1, TRAP_ENT_SIZE, scr1; \ 2867c478bd9Sstevel@tonic-gate sub scr3, TRAP_ENT_SIZE, scr3; \ 2877c478bd9Sstevel@tonic-gate cmp scr1, scr3; \ 2887c478bd9Sstevel@tonic-gate movge %icc, 0, scr1; \ 2897c478bd9Sstevel@tonic-gate st scr1, [scr2 + TRAPTR_OFFSET]; 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate /* 2927c478bd9Sstevel@tonic-gate * macro to save %tl, %gl to trap trace record at addr 2937c478bd9Sstevel@tonic-gate */ 2947c478bd9Sstevel@tonic-gate #define TRACE_SAVE_TL_GL_REGS(addr, scr1) \ 2957c478bd9Sstevel@tonic-gate rdpr %tl, scr1; \ 2967c478bd9Sstevel@tonic-gate stba scr1, [addr + TRAP_ENT_TL]%asi; \ 2977c478bd9Sstevel@tonic-gate rdpr %gl, scr1; \ 2987c478bd9Sstevel@tonic-gate stba scr1, [addr + TRAP_ENT_GL]%asi 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate /* 3017c478bd9Sstevel@tonic-gate * macro to save tl to trap trace record at addr 3027c478bd9Sstevel@tonic-gate */ 3037c478bd9Sstevel@tonic-gate #define TRACE_SAVE_TL_VAL(addr, tl) \ 3047c478bd9Sstevel@tonic-gate stba tl, [addr + TRAP_ENT_TL]%asi 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate /* 3077c478bd9Sstevel@tonic-gate * macro to save gl to trap trace record at addr 3087c478bd9Sstevel@tonic-gate */ 3097c478bd9Sstevel@tonic-gate #define TRACE_SAVE_GL_VAL(addr, gl) \ 3107c478bd9Sstevel@tonic-gate stba gl, [addr + TRAP_ENT_GL]%asi 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate /* 3147c478bd9Sstevel@tonic-gate * Trace macro for sys_trap return entries: 3157c478bd9Sstevel@tonic-gate * prom_rtt, priv_rtt, and user_rtt 3167c478bd9Sstevel@tonic-gate * %l7 - regs 3177c478bd9Sstevel@tonic-gate * %l6 - trap %pil for prom_rtt and priv_rtt; THREAD_REG for user_rtt 3187c478bd9Sstevel@tonic-gate */ 3197c478bd9Sstevel@tonic-gate #define TRACE_RTT(code, scr1, scr2, scr3, scr4) \ 3207c478bd9Sstevel@tonic-gate rdpr %pstate, scr4; \ 3217c478bd9Sstevel@tonic-gate andn scr4, PSTATE_IE | PSTATE_AM, scr3; \ 3227c478bd9Sstevel@tonic-gate wrpr %g0, scr3, %pstate; \ 3237c478bd9Sstevel@tonic-gate TRACE_PTR(scr1, scr2); \ 3247c478bd9Sstevel@tonic-gate GET_TRACE_TICK(scr2); \ 3257c478bd9Sstevel@tonic-gate stxa scr2, [scr1 + TRAP_ENT_TICK]%asi; \ 3267c478bd9Sstevel@tonic-gate TRACE_SAVE_TL_GL_REGS(scr1, scr2); \ 3277c478bd9Sstevel@tonic-gate set code, scr2; \ 3287c478bd9Sstevel@tonic-gate stha scr2, [scr1 + TRAP_ENT_TT]%asi; \ 3297c478bd9Sstevel@tonic-gate ldn [%l7 + PC_OFF], scr2; \ 3307c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_TPC]%asi; \ 3317c478bd9Sstevel@tonic-gate ldx [%l7 + TSTATE_OFF], scr2; \ 3327c478bd9Sstevel@tonic-gate stxa scr2, [scr1 + TRAP_ENT_TSTATE]%asi; \ 3337c478bd9Sstevel@tonic-gate stna %sp, [scr1 + TRAP_ENT_SP]%asi; \ 3347c478bd9Sstevel@tonic-gate stna %l6, [scr1 + TRAP_ENT_TR]%asi; \ 3357c478bd9Sstevel@tonic-gate stna %l7, [scr1 + TRAP_ENT_F1]%asi; \ 3367c478bd9Sstevel@tonic-gate ldn [THREAD_REG + T_CPU], scr2; \ 3377c478bd9Sstevel@tonic-gate ld [scr2 + CPU_BASE_SPL], scr2; \ 3387c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_F2]%asi; \ 3397c478bd9Sstevel@tonic-gate stna %g0, [scr1 + TRAP_ENT_F3]%asi; \ 3407c478bd9Sstevel@tonic-gate rdpr %cwp, scr2; \ 3417c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_F4]%asi; \ 3427c478bd9Sstevel@tonic-gate TRACE_NEXT(scr1, scr2, scr3); \ 3437c478bd9Sstevel@tonic-gate wrpr %g0, scr4, %pstate 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate /* 3467c478bd9Sstevel@tonic-gate * Trace macro for spill and fill trap handlers 3477c478bd9Sstevel@tonic-gate * tl and tt fields indicate which spill handler is entered 3487c478bd9Sstevel@tonic-gate */ 3497c478bd9Sstevel@tonic-gate #define TRACE_WIN_INFO(code, scr1, scr2, scr3) \ 3507c478bd9Sstevel@tonic-gate TRACE_PTR(scr1, scr2); \ 3517c478bd9Sstevel@tonic-gate GET_TRACE_TICK(scr2); \ 3527c478bd9Sstevel@tonic-gate stxa scr2, [scr1 + TRAP_ENT_TICK]%asi; \ 3537c478bd9Sstevel@tonic-gate TRACE_SAVE_TL_GL_REGS(scr1, scr2); \ 3547c478bd9Sstevel@tonic-gate rdpr %tt, scr2; \ 3557c478bd9Sstevel@tonic-gate set code, scr3; \ 3567c478bd9Sstevel@tonic-gate or scr2, scr3, scr2; \ 3577c478bd9Sstevel@tonic-gate stha scr2, [scr1 + TRAP_ENT_TT]%asi; \ 3587c478bd9Sstevel@tonic-gate rdpr %tstate, scr2; \ 3597c478bd9Sstevel@tonic-gate stxa scr2, [scr1 + TRAP_ENT_TSTATE]%asi; \ 3607c478bd9Sstevel@tonic-gate stna %sp, [scr1 + TRAP_ENT_SP]%asi; \ 3617c478bd9Sstevel@tonic-gate rdpr %tpc, scr2; \ 3627c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_TPC]%asi; \ 3637c478bd9Sstevel@tonic-gate set TT_FSPILL_DEBUG, scr2; \ 3647c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_TR]%asi; \ 3657c478bd9Sstevel@tonic-gate rdpr %pstate, scr2; \ 3667c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_F1]%asi; \ 3677c478bd9Sstevel@tonic-gate rdpr %cwp, scr2; \ 3687c478bd9Sstevel@tonic-gate sll scr2, 24, scr2; \ 3697c478bd9Sstevel@tonic-gate rdpr %cansave, scr3; \ 3707c478bd9Sstevel@tonic-gate sll scr3, 16, scr3; \ 3717c478bd9Sstevel@tonic-gate or scr2, scr3, scr2; \ 3727c478bd9Sstevel@tonic-gate rdpr %canrestore, scr3; \ 3737c478bd9Sstevel@tonic-gate or scr2, scr3, scr2; \ 3747c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_F2]%asi; \ 3757c478bd9Sstevel@tonic-gate rdpr %otherwin, scr2; \ 3767c478bd9Sstevel@tonic-gate sll scr2, 24, scr2; \ 3777c478bd9Sstevel@tonic-gate rdpr %cleanwin, scr3; \ 3787c478bd9Sstevel@tonic-gate sll scr3, 16, scr3; \ 3797c478bd9Sstevel@tonic-gate or scr2, scr3, scr2; \ 3807c478bd9Sstevel@tonic-gate rdpr %wstate, scr3; \ 3817c478bd9Sstevel@tonic-gate or scr2, scr3, scr2; \ 3827c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_F3]%asi; \ 3837c478bd9Sstevel@tonic-gate stna %o7, [scr1 + TRAP_ENT_F4]%asi; \ 3847c478bd9Sstevel@tonic-gate TRACE_NEXT(scr1, scr2, scr3) 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate #define FAULT_WINTRACE(scr1, scr2, scr3, type) \ 3897c478bd9Sstevel@tonic-gate TRACE_PTR(scr1, scr2); \ 3907c478bd9Sstevel@tonic-gate GET_TRACE_TICK(scr2); \ 3917c478bd9Sstevel@tonic-gate stxa scr2, [scr1 + TRAP_ENT_TICK]%asi; \ 3927c478bd9Sstevel@tonic-gate TRACE_SAVE_TL_GL_REGS(scr1, scr2); \ 3937c478bd9Sstevel@tonic-gate set type, scr2; \ 3947c478bd9Sstevel@tonic-gate stha scr2, [scr1 + TRAP_ENT_TT]%asi; \ 3957c478bd9Sstevel@tonic-gate rdpr %tpc, scr2; \ 3967c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_TPC]%asi; \ 3977c478bd9Sstevel@tonic-gate rdpr %tstate, scr2; \ 3987c478bd9Sstevel@tonic-gate stxa scr2, [scr1 + TRAP_ENT_TSTATE]%asi; \ 3997c478bd9Sstevel@tonic-gate stna %sp, [scr1 + TRAP_ENT_SP]%asi; \ 4007c478bd9Sstevel@tonic-gate stna %g0, [scr1 + TRAP_ENT_TR]%asi; \ 4017c478bd9Sstevel@tonic-gate stna %g0, [scr1 + TRAP_ENT_F1]%asi; \ 4027c478bd9Sstevel@tonic-gate stna %g4, [scr1 + TRAP_ENT_F2]%asi; \ 4037c478bd9Sstevel@tonic-gate rdpr %pil, scr2; \ 4047c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_F3]%asi; \ 4057c478bd9Sstevel@tonic-gate stna %g0, [scr1 + TRAP_ENT_F4]%asi; \ 4067c478bd9Sstevel@tonic-gate TRACE_NEXT(scr1, scr2, scr3) 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate #define SYSTRAP_TT 0x1300 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate #define SYSTRAP_TRACE(scr1, scr2, scr3) \ 4117c478bd9Sstevel@tonic-gate TRACE_PTR(scr1, scr2); \ 4127c478bd9Sstevel@tonic-gate GET_TRACE_TICK(scr2); \ 4137c478bd9Sstevel@tonic-gate stxa scr2, [scr1 + TRAP_ENT_TICK]%asi; \ 4147c478bd9Sstevel@tonic-gate TRACE_SAVE_TL_GL_REGS(scr1, scr2); \ 4157c478bd9Sstevel@tonic-gate set SYSTRAP_TT, scr3; \ 4167c478bd9Sstevel@tonic-gate rdpr %tt, scr2; \ 4177c478bd9Sstevel@tonic-gate or scr3, scr2, scr2; \ 4187c478bd9Sstevel@tonic-gate stha scr2, [scr1 + TRAP_ENT_TT]%asi; \ 4197c478bd9Sstevel@tonic-gate rdpr %tpc, scr2; \ 4207c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_TPC]%asi; \ 4217c478bd9Sstevel@tonic-gate rdpr %tstate, scr2; \ 4227c478bd9Sstevel@tonic-gate stxa scr2, [scr1 + TRAP_ENT_TSTATE]%asi; \ 4237c478bd9Sstevel@tonic-gate stna %g1, [scr1 + TRAP_ENT_SP]%asi; \ 4247c478bd9Sstevel@tonic-gate stna %g2, [scr1 + TRAP_ENT_TR]%asi; \ 4257c478bd9Sstevel@tonic-gate stna %g3, [scr1 + TRAP_ENT_F1]%asi; \ 4267c478bd9Sstevel@tonic-gate stna %g4, [scr1 + TRAP_ENT_F2]%asi; \ 4277c478bd9Sstevel@tonic-gate rdpr %pil, scr2; \ 4287c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_F3]%asi; \ 4297c478bd9Sstevel@tonic-gate rdpr %cwp, scr2; \ 4307c478bd9Sstevel@tonic-gate stna scr2, [scr1 + TRAP_ENT_F4]%asi; \ 4317c478bd9Sstevel@tonic-gate TRACE_NEXT(scr1, scr2, scr3) 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate #else /* TRAPTRACE */ 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate #define FAULT_WINTRACE(scr1, scr2, scr3, type) 4367c478bd9Sstevel@tonic-gate #define SYSTRAP_TRACE(scr1, scr2, scr3) 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate #endif /* _ASM */ 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate /* 4437c478bd9Sstevel@tonic-gate * Trap trace codes used in place of a %tbr value when more than one 4447c478bd9Sstevel@tonic-gate * entry is made by a trap. The general scheme is that the trap-type is 4457c478bd9Sstevel@tonic-gate * in the same position as in the TT, and the low-order bits indicate 4467c478bd9Sstevel@tonic-gate * which precise entry is being made. 4477c478bd9Sstevel@tonic-gate */ 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate #define TT_F32_SN0 0x1084 4507c478bd9Sstevel@tonic-gate #define TT_F64_SN0 0x1088 4517c478bd9Sstevel@tonic-gate #define TT_F32_NT0 0x1094 4527c478bd9Sstevel@tonic-gate #define TT_F64_NT0 0x1098 4537c478bd9Sstevel@tonic-gate #define TT_F32_SO0 0x10A4 4547c478bd9Sstevel@tonic-gate #define TT_F64_SO0 0x10A8 4557c478bd9Sstevel@tonic-gate #define TT_F32_FN0 0x10C4 4567c478bd9Sstevel@tonic-gate #define TT_F64_FN0 0x10C8 4577c478bd9Sstevel@tonic-gate #define TT_F32_SN1 0x1284 4587c478bd9Sstevel@tonic-gate #define TT_F64_SN1 0x1288 4597c478bd9Sstevel@tonic-gate #define TT_F32_NT1 0x1294 4607c478bd9Sstevel@tonic-gate #define TT_F64_NT1 0x1298 4617c478bd9Sstevel@tonic-gate #define TT_F32_SO1 0x12A4 4627c478bd9Sstevel@tonic-gate #define TT_F64_SO1 0x12A8 4637c478bd9Sstevel@tonic-gate #define TT_F32_FN1 0x12C4 4647c478bd9Sstevel@tonic-gate #define TT_F64_FN1 0x12C8 4657c478bd9Sstevel@tonic-gate #define TT_RTT_FN1 0x12DD 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate #define TT_SC_ENTR 0x880 /* enter system call */ 4687c478bd9Sstevel@tonic-gate #define TT_SC_RET 0x881 /* system call normal return */ 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate #define TT_SYS_RTT_PROM 0x5555 /* return from trap to prom */ 4717c478bd9Sstevel@tonic-gate #define TT_SYS_RTT_PRIV 0x6666 /* return from trap to privilege */ 4727c478bd9Sstevel@tonic-gate #define TT_SYS_RTT_USER 0x7777 /* return from trap to user */ 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate #define TT_INTR_EXIT 0x8888 /* interrupt thread exit (no pinned thread) */ 4757c478bd9Sstevel@tonic-gate #define TT_FSPILL_DEBUG 0x9999 /* fill/spill debugging */ 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate #define TT_SERVE_INTR 0x6000 /* SERVE_INTR */ 4787c478bd9Sstevel@tonic-gate #define TT_XCALL 0xd000 /* xcall/xtrap */ 4797c478bd9Sstevel@tonic-gate #define TT_XCALL_CONT 0xdc00 /* continuation of an xcall/xtrap record */ 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate #define TT_MMU_MISS 0x200 /* or'd into %tt to indicate a miss */ 4827c478bd9Sstevel@tonic-gate #define TT_MMU_EXEC 0x400 /* or'd into %tt to indicate exec_fault */ 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate #ifdef __cplusplus 4867c478bd9Sstevel@tonic-gate } 4877c478bd9Sstevel@tonic-gate #endif 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate #endif /* _SYS_TRAPTRACE_H */ 490