10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
53446Smrj * Common Development and Distribution License (the "License").
63446Smrj * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*9613SAbhinandan.Ekande@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/trap.h>
270Sstevel@tonic-gate #include <sys/machtrap.h>
280Sstevel@tonic-gate #include <sys/machsystm.h>
290Sstevel@tonic-gate #include <sys/cpu_module.h>
300Sstevel@tonic-gate #include <sys/panic.h>
310Sstevel@tonic-gate #include <sys/uadmin.h>
320Sstevel@tonic-gate #include <sys/kobj.h>
330Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
340Sstevel@tonic-gate #include <sys/reboot.h>
350Sstevel@tonic-gate
360Sstevel@tonic-gate #ifdef TRAPTRACE
370Sstevel@tonic-gate #include <sys/traptrace.h>
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate
400Sstevel@tonic-gate void showregs(unsigned, struct regs *, caddr_t, uint_t);
410Sstevel@tonic-gate
420Sstevel@tonic-gate extern int tudebug;
430Sstevel@tonic-gate
440Sstevel@tonic-gate void
mmu_print_sfsr(uint_t sfsr)450Sstevel@tonic-gate mmu_print_sfsr(uint_t sfsr)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate printf("MMU sfsr=%x:", sfsr);
480Sstevel@tonic-gate switch (X_FAULT_TYPE(sfsr)) {
490Sstevel@tonic-gate case FT_NONE:
500Sstevel@tonic-gate printf(" No error");
510Sstevel@tonic-gate break;
520Sstevel@tonic-gate case FT_PRIV:
530Sstevel@tonic-gate printf(" Privilege violation");
540Sstevel@tonic-gate break;
550Sstevel@tonic-gate case FT_SPEC_LD:
560Sstevel@tonic-gate printf(" Speculative load on E-bit page");
570Sstevel@tonic-gate break;
580Sstevel@tonic-gate case FT_ATOMIC_NC:
590Sstevel@tonic-gate printf(" Atomic to uncacheable page");
600Sstevel@tonic-gate break;
610Sstevel@tonic-gate case FT_ILL_ALT:
620Sstevel@tonic-gate printf(" Illegal lda or sta");
630Sstevel@tonic-gate break;
640Sstevel@tonic-gate case FT_NFO:
650Sstevel@tonic-gate printf(" Normal access to NFO page");
660Sstevel@tonic-gate break;
670Sstevel@tonic-gate case FT_RANGE:
680Sstevel@tonic-gate printf(" Data or instruction address out of range");
690Sstevel@tonic-gate break;
700Sstevel@tonic-gate case FT_RANGE_REG:
710Sstevel@tonic-gate printf(" Jump to register out of range");
720Sstevel@tonic-gate break;
730Sstevel@tonic-gate default:
740Sstevel@tonic-gate printf(" Unknown error");
750Sstevel@tonic-gate break;
760Sstevel@tonic-gate }
770Sstevel@tonic-gate if (sfsr) {
780Sstevel@tonic-gate printf(" on ASI 0x%x E %d CID %d PRIV %d W %d OW %d FV %d",
795084Sjohnlev (sfsr & SFSR_ASI) >> SFSR_ASI_SHIFT,
805084Sjohnlev (sfsr & SFSR_E) != 0,
815084Sjohnlev (sfsr & SFSR_CTX) >> SFSR_CT_SHIFT,
825084Sjohnlev (sfsr & SFSR_PR) != 0,
835084Sjohnlev (sfsr & SFSR_W) != 0,
845084Sjohnlev (sfsr & SFSR_OW) != 0,
855084Sjohnlev (sfsr & SFSR_FV) != 0);
860Sstevel@tonic-gate }
870Sstevel@tonic-gate printf("\n");
880Sstevel@tonic-gate }
890Sstevel@tonic-gate
900Sstevel@tonic-gate #ifdef TRAPWINDOW
910Sstevel@tonic-gate long trap_window[25];
920Sstevel@tonic-gate #endif /* TRAPWINDOW */
930Sstevel@tonic-gate
940Sstevel@tonic-gate /*
950Sstevel@tonic-gate * Print out debugging info.
960Sstevel@tonic-gate */
970Sstevel@tonic-gate /*ARGSUSED*/
980Sstevel@tonic-gate void
showregs(uint_t type,struct regs * rp,caddr_t addr,uint_t mmu_fsr)990Sstevel@tonic-gate showregs(uint_t type, struct regs *rp, caddr_t addr, uint_t mmu_fsr)
1000Sstevel@tonic-gate {
1010Sstevel@tonic-gate int s;
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate s = spl7();
1040Sstevel@tonic-gate type &= ~T_USER;
1053446Smrj printf("%s: ", PTOU(curproc)->u_comm);
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate switch (type) {
1080Sstevel@tonic-gate case T_SYS_RTT_ALIGN:
1090Sstevel@tonic-gate case T_ALIGNMENT:
1100Sstevel@tonic-gate printf("alignment error:\n");
1110Sstevel@tonic-gate break;
1120Sstevel@tonic-gate case T_INSTR_EXCEPTION:
1130Sstevel@tonic-gate printf("text access exception:\n");
1140Sstevel@tonic-gate break;
1150Sstevel@tonic-gate case T_DATA_EXCEPTION:
1160Sstevel@tonic-gate printf("data access exception:\n");
1170Sstevel@tonic-gate break;
1180Sstevel@tonic-gate case T_PRIV_INSTR:
1190Sstevel@tonic-gate printf("privileged instruction fault:\n");
1200Sstevel@tonic-gate break;
1210Sstevel@tonic-gate case T_UNIMP_INSTR:
1220Sstevel@tonic-gate printf("illegal instruction fault:\n");
1230Sstevel@tonic-gate break;
1240Sstevel@tonic-gate case T_IDIV0:
1250Sstevel@tonic-gate printf("integer divide zero trap:\n");
1260Sstevel@tonic-gate break;
1270Sstevel@tonic-gate case T_DIV0:
1280Sstevel@tonic-gate printf("zero divide trap:\n");
1290Sstevel@tonic-gate break;
1300Sstevel@tonic-gate case T_INT_OVERFLOW:
1310Sstevel@tonic-gate printf("integer overflow:\n");
1320Sstevel@tonic-gate break;
1330Sstevel@tonic-gate case T_BREAKPOINT:
1340Sstevel@tonic-gate printf("breakpoint trap:\n");
1350Sstevel@tonic-gate break;
1360Sstevel@tonic-gate case T_TAG_OVERFLOW:
1370Sstevel@tonic-gate printf("tag overflow:\n");
1380Sstevel@tonic-gate break;
1390Sstevel@tonic-gate default:
1400Sstevel@tonic-gate if (type >= T_SOFTWARE_TRAP && type <= T_ESOFTWARE_TRAP)
1410Sstevel@tonic-gate printf("software trap 0x%x\n", type - T_SOFTWARE_TRAP);
1420Sstevel@tonic-gate else
1430Sstevel@tonic-gate printf("trap type = 0x%x\n", type);
1440Sstevel@tonic-gate break;
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate if (type == T_DATA_EXCEPTION || type == T_INSTR_EXCEPTION) {
1470Sstevel@tonic-gate mmu_print_sfsr(mmu_fsr);
1480Sstevel@tonic-gate } else if (addr) {
1490Sstevel@tonic-gate printf("addr=0x%p\n", (void *)addr);
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate printf("pid=%d, pc=0x%lx, sp=0x%llx, tstate=0x%llx, context=0x%x\n",
1530Sstevel@tonic-gate (ttoproc(curthread) && ttoproc(curthread)->p_pidp) ?
1540Sstevel@tonic-gate (ttoproc(curthread)->p_pid) : 0, rp->r_pc, rp->r_sp,
1550Sstevel@tonic-gate rp->r_tstate, sfmmu_getctx_sec());
1560Sstevel@tonic-gate if (USERMODE(rp->r_tstate)) {
1570Sstevel@tonic-gate printf("o0-o7: %llx, %llx, %llx, %llx, %llx, %llx, "
1580Sstevel@tonic-gate "%llx, %llx\n", rp->r_o0, rp->r_o1, rp->r_o2, rp->r_o3,
1590Sstevel@tonic-gate rp->r_o4, rp->r_o5, rp->r_o6, rp->r_o7);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate printf("g1-g7: %llx, %llx, %llx, %llx, %llx, %llx, %llx\n",
1620Sstevel@tonic-gate rp->r_g1, rp->r_g2, rp->r_g3,
1630Sstevel@tonic-gate rp->r_g4, rp->r_g5, rp->r_g6, rp->r_g7);
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate #ifdef TRAPWINDOW
1660Sstevel@tonic-gate printf("trap_window: wim=%x\n", trap_window[24]);
1670Sstevel@tonic-gate printf("o0-o7: %x, %x, %x, %x, %x, %x, %x, %x\n",
1680Sstevel@tonic-gate trap_window[0], trap_window[1], trap_window[2], trap_window[3],
1690Sstevel@tonic-gate trap_window[4], trap_window[5], trap_window[6], trap_window[7]);
1700Sstevel@tonic-gate printf("l0-l7: %x, %x, %x, %x, %x, %x, %x, %x\n",
1710Sstevel@tonic-gate trap_window[8], trap_window[9], trap_window[10], trap_window[11],
1720Sstevel@tonic-gate trap_window[12], trap_window[13], trap_window[14], trap_window[15]);
1730Sstevel@tonic-gate printf("i0-i7: %x, %x, %x, %x, %x, %x, %x, %x\n",
1740Sstevel@tonic-gate trap_window[16], trap_window[17], trap_window[18], trap_window[19],
1750Sstevel@tonic-gate trap_window[20], trap_window[21], trap_window[22], trap_window[23]);
1760Sstevel@tonic-gate #endif /* TRAPWINDOW */
1770Sstevel@tonic-gate if (tudebug > 1 && (boothowto & RB_DEBUG)) {
1780Sstevel@tonic-gate debug_enter((char *)NULL);
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate splx(s);
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate static void
ptl1_showtrap(ptl1_state_t * pstate)1840Sstevel@tonic-gate ptl1_showtrap(ptl1_state_t *pstate)
1850Sstevel@tonic-gate {
1860Sstevel@tonic-gate ptl1_regs_t *rp = &pstate->ptl1_regs;
1870Sstevel@tonic-gate short i, j, maxtl = rp->ptl1_trap_regs[0].ptl1_tl;
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate printf("%%tl %%tpc %%tnpc %%tstate"
1900Sstevel@tonic-gate " %%tt\n");
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate for (i = maxtl - 1; i >= 0; i--) {
1930Sstevel@tonic-gate ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i];
1940Sstevel@tonic-gate uint64_t tstate = ptp->ptl1_tstate;
1950Sstevel@tonic-gate uint32_t ccr, asi, cwp, pstate;
1960Sstevel@tonic-gate
1970Sstevel@tonic-gate cwp = (tstate >> TSTATE_CWP_SHIFT) & TSTATE_CWP_MASK;
1980Sstevel@tonic-gate pstate = (tstate >> TSTATE_PSTATE_SHIFT) & TSTATE_PSTATE_MASK;
1990Sstevel@tonic-gate asi = (tstate >> TSTATE_ASI_SHIFT) & TSTATE_ASI_MASK;
2000Sstevel@tonic-gate ccr = (tstate >> TSTATE_CCR_SHIFT) & TSTATE_CCR_MASK;
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate printf(" %d %016" PRIx64 " %016" PRIx64 " %010" PRIx64
2030Sstevel@tonic-gate " %03x\n", ptp->ptl1_tl, ptp->ptl1_tpc,
2040Sstevel@tonic-gate ptp->ptl1_tnpc, tstate, ptp->ptl1_tt);
2050Sstevel@tonic-gate printf(" %%ccr: %02x %%asi: %02x %%cwp: %x "
2060Sstevel@tonic-gate "%%pstate: %b\n", ccr, asi, cwp, pstate, PSTATE_BITS);
2070Sstevel@tonic-gate }
2080Sstevel@tonic-gate
2090Sstevel@tonic-gate printf("%%g0-3: %016x %016" PRIx64 " %016" PRIx64 " %016"
2100Sstevel@tonic-gate PRIx64 "\n", 0, rp->ptl1_g1, rp->ptl1_g2, rp->ptl1_g3);
2110Sstevel@tonic-gate printf("%%g4-7: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016"
2120Sstevel@tonic-gate PRIx64 "\n", rp->ptl1_g4, rp->ptl1_g5, rp->ptl1_g6, rp->ptl1_g7);
2130Sstevel@tonic-gate
2140Sstevel@tonic-gate i = rp->ptl1_cwp;
2150Sstevel@tonic-gate j = rp->ptl1_canrestore;
2160Sstevel@tonic-gate for (; j >= 0; i--, j--) {
2170Sstevel@tonic-gate struct rwindow *wp;
2180Sstevel@tonic-gate ulong_t off;
2190Sstevel@tonic-gate char *sym;
2200Sstevel@tonic-gate
2210Sstevel@tonic-gate if (i < 0)
2220Sstevel@tonic-gate i += MAXWIN;
2230Sstevel@tonic-gate
2240Sstevel@tonic-gate wp = &rp->ptl1_rwindow[i];
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate if ((sym = kobj_getsymname(wp->rw_in[7], &off)) != NULL) {
2270Sstevel@tonic-gate printf("Register window %d, caller %s+%lx\n",
2280Sstevel@tonic-gate i, sym, off);
2290Sstevel@tonic-gate } else {
2300Sstevel@tonic-gate printf("Register window %d, caller %lx\n",
2310Sstevel@tonic-gate i, wp->rw_in[7]);
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate if (i == rp->ptl1_cwp) {
2350Sstevel@tonic-gate struct rwindow *nwp;
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate if (i == MAXWIN - 1)
2380Sstevel@tonic-gate nwp = &rp->ptl1_rwindow[0];
2390Sstevel@tonic-gate else
2400Sstevel@tonic-gate nwp = &rp->ptl1_rwindow[i+1];
2410Sstevel@tonic-gate printf("%%o0-3: %016lx %016lx %016lx %016lx\n"
2420Sstevel@tonic-gate "%%o4-7: %016lx %016lx %016lx %016lx\n",
2430Sstevel@tonic-gate nwp->rw_in[0], nwp->rw_in[1], nwp->rw_in[2],
2440Sstevel@tonic-gate nwp->rw_in[3], nwp->rw_in[4], nwp->rw_in[5],
2450Sstevel@tonic-gate nwp->rw_in[6], nwp->rw_in[7]);
2460Sstevel@tonic-gate }
2470Sstevel@tonic-gate printf("%%l0-3: %016lx %016lx %016lx %016lx\n"
2480Sstevel@tonic-gate "%%l4-7: %016lx %016lx %016lx %016lx\n",
2490Sstevel@tonic-gate wp->rw_local[0], wp->rw_local[1], wp->rw_local[2],
2500Sstevel@tonic-gate wp->rw_local[3], wp->rw_local[4], wp->rw_local[5],
2510Sstevel@tonic-gate wp->rw_local[6], wp->rw_local[7]);
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate printf("%%i0-3: %016lx %016lx %016lx %016lx\n"
2540Sstevel@tonic-gate "%%i4-7: %016lx %016lx %016lx %016lx\n",
2550Sstevel@tonic-gate wp->rw_in[0], wp->rw_in[1], wp->rw_in[2], wp->rw_in[3],
2560Sstevel@tonic-gate wp->rw_in[4], wp->rw_in[5], wp->rw_in[6], wp->rw_in[7]);
2570Sstevel@tonic-gate }
2580Sstevel@tonic-gate }
2590Sstevel@tonic-gate
2600Sstevel@tonic-gate void
panic_showtrap(struct panic_trap_info * tip)2615084Sjohnlev panic_showtrap(struct panic_trap_info *tip)
2620Sstevel@tonic-gate {
2630Sstevel@tonic-gate ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state;
2640Sstevel@tonic-gate /*
2650Sstevel@tonic-gate * If ptl1_panic() was called, print out the information
2660Sstevel@tonic-gate * saved in the ptl1_state struture.
2670Sstevel@tonic-gate */
2680Sstevel@tonic-gate if (pstate->ptl1_entry_count) {
2690Sstevel@tonic-gate ptl1_showtrap(pstate);
2700Sstevel@tonic-gate return;
2710Sstevel@tonic-gate }
2720Sstevel@tonic-gate
2730Sstevel@tonic-gate showregs(tip->trap_type, tip->trap_regs, tip->trap_addr,
2740Sstevel@tonic-gate tip->trap_mmu_fsr);
2750Sstevel@tonic-gate }
2760Sstevel@tonic-gate
2770Sstevel@tonic-gate static void
ptl1_savetrap(panic_data_t * pdp,ptl1_state_t * pstate)2780Sstevel@tonic-gate ptl1_savetrap(panic_data_t *pdp, ptl1_state_t *pstate)
2790Sstevel@tonic-gate {
2800Sstevel@tonic-gate ptl1_regs_t *rp = &pstate->ptl1_regs;
2810Sstevel@tonic-gate short i, maxtl = rp->ptl1_trap_regs[0].ptl1_tl;
2820Sstevel@tonic-gate panic_nv_t *pnv = PANICNVGET(pdp);
2830Sstevel@tonic-gate char name[PANICNVNAMELEN];
2840Sstevel@tonic-gate
2850Sstevel@tonic-gate for (i = maxtl - 1; i >= 0; i--) {
2860Sstevel@tonic-gate ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i];
2870Sstevel@tonic-gate
2880Sstevel@tonic-gate (void) snprintf(name, sizeof (name), "tl[%d]", i);
2890Sstevel@tonic-gate PANICNVADD(pnv, name, ptp->ptl1_tl);
2900Sstevel@tonic-gate (void) snprintf(name, sizeof (name), "tt[%d]", i);
2910Sstevel@tonic-gate PANICNVADD(pnv, name, ptp->ptl1_tt);
2920Sstevel@tonic-gate (void) snprintf(name, sizeof (name), "tpc[%d]", i);
2930Sstevel@tonic-gate PANICNVADD(pnv, name, ptp->ptl1_tpc);
2940Sstevel@tonic-gate (void) snprintf(name, sizeof (name), "tnpc[%d]", i);
2950Sstevel@tonic-gate PANICNVADD(pnv, name, ptp->ptl1_tnpc);
2960Sstevel@tonic-gate (void) snprintf(name, sizeof (name), "tstate[%d]", i);
2970Sstevel@tonic-gate PANICNVADD(pnv, name, ptp->ptl1_tstate);
2980Sstevel@tonic-gate }
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate PANICNVSET(pdp, pnv);
3010Sstevel@tonic-gate }
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate void
panic_savetrap(panic_data_t * pdp,struct panic_trap_info * tip)3045084Sjohnlev panic_savetrap(panic_data_t *pdp, struct panic_trap_info *tip)
3050Sstevel@tonic-gate {
3060Sstevel@tonic-gate panic_nv_t *pnv;
3070Sstevel@tonic-gate ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state;
3080Sstevel@tonic-gate /*
3090Sstevel@tonic-gate * If ptl1_panic() was called, save the trap registers
3100Sstevel@tonic-gate * stored in the ptl1_state struture.
3110Sstevel@tonic-gate */
3120Sstevel@tonic-gate if (pstate->ptl1_entry_count) {
3130Sstevel@tonic-gate ptl1_savetrap(pdp, pstate);
3140Sstevel@tonic-gate return;
3150Sstevel@tonic-gate }
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate panic_saveregs(pdp, tip->trap_regs);
3180Sstevel@tonic-gate pnv = PANICNVGET(pdp);
3190Sstevel@tonic-gate
3200Sstevel@tonic-gate PANICNVADD(pnv, "sfsr", tip->trap_mmu_fsr);
3210Sstevel@tonic-gate PANICNVADD(pnv, "sfar", tip->trap_addr);
3220Sstevel@tonic-gate PANICNVADD(pnv, "tt", tip->trap_type);
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate PANICNVSET(pdp, pnv);
3250Sstevel@tonic-gate }
326