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 default:
710Sstevel@tonic-gate printf(" Unknown error");
720Sstevel@tonic-gate break;
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate printf(" context 0x%x", X_FAULT_CTX(sfsr));
760Sstevel@tonic-gate printf("\n");
770Sstevel@tonic-gate }
780Sstevel@tonic-gate
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate * Print out debugging info.
810Sstevel@tonic-gate */
820Sstevel@tonic-gate /*ARGSUSED*/
830Sstevel@tonic-gate void
showregs(uint_t type,struct regs * rp,caddr_t addr,uint_t mmu_fsr)840Sstevel@tonic-gate showregs(uint_t type, struct regs *rp, caddr_t addr, uint_t mmu_fsr)
850Sstevel@tonic-gate {
860Sstevel@tonic-gate int s;
870Sstevel@tonic-gate
880Sstevel@tonic-gate s = spl7();
890Sstevel@tonic-gate type &= ~T_USER;
903446Smrj printf("%s: ", PTOU(curproc)->u_comm);
910Sstevel@tonic-gate
920Sstevel@tonic-gate switch (type) {
930Sstevel@tonic-gate case T_SYS_RTT_ALIGN:
940Sstevel@tonic-gate case T_ALIGNMENT:
950Sstevel@tonic-gate printf("alignment error:\n");
960Sstevel@tonic-gate break;
970Sstevel@tonic-gate case T_INSTR_EXCEPTION:
980Sstevel@tonic-gate printf("text access exception:\n");
990Sstevel@tonic-gate break;
1000Sstevel@tonic-gate case T_DATA_EXCEPTION:
1010Sstevel@tonic-gate printf("data access exception:\n");
1020Sstevel@tonic-gate break;
1030Sstevel@tonic-gate case T_PRIV_INSTR:
1040Sstevel@tonic-gate printf("privileged instruction fault:\n");
1050Sstevel@tonic-gate break;
1060Sstevel@tonic-gate case T_UNIMP_INSTR:
1070Sstevel@tonic-gate printf("illegal instruction fault:\n");
1080Sstevel@tonic-gate break;
1090Sstevel@tonic-gate case T_IDIV0:
1100Sstevel@tonic-gate printf("integer divide zero trap:\n");
1110Sstevel@tonic-gate break;
1120Sstevel@tonic-gate case T_DIV0:
1130Sstevel@tonic-gate printf("zero divide trap:\n");
1140Sstevel@tonic-gate break;
1150Sstevel@tonic-gate case T_INT_OVERFLOW:
1160Sstevel@tonic-gate printf("integer overflow:\n");
1170Sstevel@tonic-gate break;
1180Sstevel@tonic-gate case T_BREAKPOINT:
1190Sstevel@tonic-gate printf("breakpoint trap:\n");
1200Sstevel@tonic-gate break;
1210Sstevel@tonic-gate case T_TAG_OVERFLOW:
1220Sstevel@tonic-gate printf("tag overflow:\n");
1230Sstevel@tonic-gate break;
1240Sstevel@tonic-gate default:
1250Sstevel@tonic-gate if (type >= T_SOFTWARE_TRAP && type <= T_ESOFTWARE_TRAP)
1260Sstevel@tonic-gate printf("software trap 0x%x\n", type - T_SOFTWARE_TRAP);
1270Sstevel@tonic-gate else
1280Sstevel@tonic-gate printf("trap type = 0x%x\n", type);
1290Sstevel@tonic-gate break;
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate if (type == T_DATA_EXCEPTION || type == T_INSTR_EXCEPTION) {
1320Sstevel@tonic-gate mmu_print_sfsr(mmu_fsr);
1330Sstevel@tonic-gate } else if (addr) {
1340Sstevel@tonic-gate printf("addr=0x%p\n", (void *)addr);
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate printf("pid=%d, pc=0x%lx, sp=0x%llx, tstate=0x%llx, context=0x%x\n",
1380Sstevel@tonic-gate (ttoproc(curthread) && ttoproc(curthread)->p_pidp) ?
1390Sstevel@tonic-gate (ttoproc(curthread)->p_pid) : 0, rp->r_pc, rp->r_sp,
1400Sstevel@tonic-gate rp->r_tstate, sfmmu_getctx_sec());
1410Sstevel@tonic-gate if (USERMODE(rp->r_tstate)) {
1420Sstevel@tonic-gate printf("o0-o7: %llx, %llx, %llx, %llx, %llx, %llx, "
1430Sstevel@tonic-gate "%llx, %llx\n", rp->r_o0, rp->r_o1, rp->r_o2, rp->r_o3,
1440Sstevel@tonic-gate rp->r_o4, rp->r_o5, rp->r_o6, rp->r_o7);
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate printf("g1-g7: %llx, %llx, %llx, %llx, %llx, %llx, %llx\n",
1470Sstevel@tonic-gate rp->r_g1, rp->r_g2, rp->r_g3,
1480Sstevel@tonic-gate rp->r_g4, rp->r_g5, rp->r_g6, rp->r_g7);
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate if (tudebug > 1 && (boothowto & RB_DEBUG)) {
1510Sstevel@tonic-gate debug_enter((char *)NULL);
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate splx(s);
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate static void
ptl1_showtrap(ptl1_state_t * pstate)1570Sstevel@tonic-gate ptl1_showtrap(ptl1_state_t *pstate)
1580Sstevel@tonic-gate {
1590Sstevel@tonic-gate ptl1_regs_t *rp = &pstate->ptl1_regs;
1600Sstevel@tonic-gate short i, j, maxtl = rp->ptl1_trap_regs[0].ptl1_tl;
161357Ssvemuri short curgl = rp->ptl1_gregs[0].ptl1_gl;
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate printf("%%tl %%tpc %%tnpc %%tstate"
1640Sstevel@tonic-gate " %%tt\n");
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate for (i = maxtl - 1; i >= 0; i--) {
1670Sstevel@tonic-gate ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i];
1680Sstevel@tonic-gate uint64_t tstate = ptp->ptl1_tstate;
169357Ssvemuri uint32_t gl, ccr, asi, cwp, pstate;
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate cwp = (tstate >> TSTATE_CWP_SHIFT) & TSTATE_CWP_MASK;
1720Sstevel@tonic-gate pstate = (tstate >> TSTATE_PSTATE_SHIFT) & TSTATE_PSTATE_MASK;
1730Sstevel@tonic-gate asi = (tstate >> TSTATE_ASI_SHIFT) & TSTATE_ASI_MASK;
1740Sstevel@tonic-gate ccr = (tstate >> TSTATE_CCR_SHIFT) & TSTATE_CCR_MASK;
175357Ssvemuri gl = (tstate >> TSTATE_GL_SHIFT) & TSTATE_GL_MASK;
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate printf(" %d %016" PRIx64 " %016" PRIx64 " %010" PRIx64
1780Sstevel@tonic-gate " %03x\n", ptp->ptl1_tl, ptp->ptl1_tpc,
1790Sstevel@tonic-gate ptp->ptl1_tnpc, tstate, ptp->ptl1_tt);
180357Ssvemuri printf(" %%gl: %02x %%ccr: %02x %%asi: %02x %%cwp: %x "
181357Ssvemuri "%%pstate: %b\n", gl, ccr, asi, cwp, pstate, PSTATE_BITS);
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate
184357Ssvemuri /*
185357Ssvemuri * ptl1_gregs[] array holds global registers for GL 0 through
186357Ssvemuri * current GL. Note that the current GL global registers are
187357Ssvemuri * always stored at index 0 in the ptl1_gregs[] array.
188357Ssvemuri */
189357Ssvemuri for (i = 0; i <= curgl; i++) {
190357Ssvemuri ptl1_gregs_t *pgp = &rp->ptl1_gregs[i];
191357Ssvemuri
192357Ssvemuri printf(" %%gl: %02" PRIx64 "\n", pgp->ptl1_gl);
193357Ssvemuri printf("%%g0-3: %016x %016" PRIx64 " %016" PRIx64 " %016"
194357Ssvemuri PRIx64 "\n", 0, pgp->ptl1_g1, pgp->ptl1_g2, pgp->ptl1_g3);
195357Ssvemuri printf("%%g4-7: %016" PRIx64 " %016" PRIx64 " %016"
196357Ssvemuri PRIx64 " %016" PRIx64 "\n", pgp->ptl1_g4, pgp->ptl1_g5,
197357Ssvemuri pgp->ptl1_g6, pgp->ptl1_g7);
198357Ssvemuri }
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate i = rp->ptl1_cwp;
2010Sstevel@tonic-gate j = rp->ptl1_canrestore;
2020Sstevel@tonic-gate for (; j >= 0; i--, j--) {
2030Sstevel@tonic-gate struct rwindow *wp;
2040Sstevel@tonic-gate ulong_t off;
2050Sstevel@tonic-gate char *sym;
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate if (i < 0)
2080Sstevel@tonic-gate i += MAXWIN;
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate wp = &rp->ptl1_rwindow[i];
2110Sstevel@tonic-gate
2120Sstevel@tonic-gate if ((sym = kobj_getsymname(wp->rw_in[7], &off)) != NULL) {
2130Sstevel@tonic-gate printf("Register window %d, caller %s+%lx\n",
2140Sstevel@tonic-gate i, sym, off);
2150Sstevel@tonic-gate } else {
2160Sstevel@tonic-gate printf("Register window %d, caller %lx\n",
2170Sstevel@tonic-gate i, wp->rw_in[7]);
2180Sstevel@tonic-gate }
2190Sstevel@tonic-gate
2200Sstevel@tonic-gate if (i == rp->ptl1_cwp) {
2210Sstevel@tonic-gate struct rwindow *nwp;
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate if (i == MAXWIN - 1)
2240Sstevel@tonic-gate nwp = &rp->ptl1_rwindow[0];
2250Sstevel@tonic-gate else
2260Sstevel@tonic-gate nwp = &rp->ptl1_rwindow[i+1];
2270Sstevel@tonic-gate printf("%%o0-3: %016lx %016lx %016lx %016lx\n"
2280Sstevel@tonic-gate "%%o4-7: %016lx %016lx %016lx %016lx\n",
2290Sstevel@tonic-gate nwp->rw_in[0], nwp->rw_in[1], nwp->rw_in[2],
2300Sstevel@tonic-gate nwp->rw_in[3], nwp->rw_in[4], nwp->rw_in[5],
2310Sstevel@tonic-gate nwp->rw_in[6], nwp->rw_in[7]);
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate printf("%%l0-3: %016lx %016lx %016lx %016lx\n"
2340Sstevel@tonic-gate "%%l4-7: %016lx %016lx %016lx %016lx\n",
2350Sstevel@tonic-gate wp->rw_local[0], wp->rw_local[1], wp->rw_local[2],
2360Sstevel@tonic-gate wp->rw_local[3], wp->rw_local[4], wp->rw_local[5],
2370Sstevel@tonic-gate wp->rw_local[6], wp->rw_local[7]);
2380Sstevel@tonic-gate
2390Sstevel@tonic-gate printf("%%i0-3: %016lx %016lx %016lx %016lx\n"
2400Sstevel@tonic-gate "%%i4-7: %016lx %016lx %016lx %016lx\n",
2410Sstevel@tonic-gate wp->rw_in[0], wp->rw_in[1], wp->rw_in[2], wp->rw_in[3],
2420Sstevel@tonic-gate wp->rw_in[4], wp->rw_in[5], wp->rw_in[6], wp->rw_in[7]);
2430Sstevel@tonic-gate }
2440Sstevel@tonic-gate }
2450Sstevel@tonic-gate
2460Sstevel@tonic-gate void
panic_showtrap(struct panic_trap_info * tip)2475084Sjohnlev panic_showtrap(struct panic_trap_info *tip)
2480Sstevel@tonic-gate {
2490Sstevel@tonic-gate ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state;
2500Sstevel@tonic-gate /*
2510Sstevel@tonic-gate * If ptl1_panic() was called, print out the information
2520Sstevel@tonic-gate * saved in the ptl1_state struture.
2530Sstevel@tonic-gate */
2540Sstevel@tonic-gate if (pstate->ptl1_entry_count) {
2550Sstevel@tonic-gate ptl1_showtrap(pstate);
2560Sstevel@tonic-gate return;
2570Sstevel@tonic-gate }
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate showregs(tip->trap_type, tip->trap_regs, tip->trap_addr,
2600Sstevel@tonic-gate tip->trap_mmu_fsr);
2610Sstevel@tonic-gate }
2620Sstevel@tonic-gate
2630Sstevel@tonic-gate static void
ptl1_savetrap(panic_data_t * pdp,ptl1_state_t * pstate)2640Sstevel@tonic-gate ptl1_savetrap(panic_data_t *pdp, ptl1_state_t *pstate)
2650Sstevel@tonic-gate {
2660Sstevel@tonic-gate ptl1_regs_t *rp = &pstate->ptl1_regs;
2670Sstevel@tonic-gate short i, maxtl = rp->ptl1_trap_regs[0].ptl1_tl;
2680Sstevel@tonic-gate panic_nv_t *pnv = PANICNVGET(pdp);
2690Sstevel@tonic-gate char name[PANICNVNAMELEN];
2700Sstevel@tonic-gate
2710Sstevel@tonic-gate for (i = maxtl - 1; i >= 0; i--) {
2720Sstevel@tonic-gate ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i];
2730Sstevel@tonic-gate
2740Sstevel@tonic-gate (void) snprintf(name, sizeof (name), "tl[%d]", i);
2750Sstevel@tonic-gate PANICNVADD(pnv, name, ptp->ptl1_tl);
2760Sstevel@tonic-gate (void) snprintf(name, sizeof (name), "tt[%d]", i);
2770Sstevel@tonic-gate PANICNVADD(pnv, name, ptp->ptl1_tt);
2780Sstevel@tonic-gate (void) snprintf(name, sizeof (name), "tpc[%d]", i);
2790Sstevel@tonic-gate PANICNVADD(pnv, name, ptp->ptl1_tpc);
2800Sstevel@tonic-gate (void) snprintf(name, sizeof (name), "tnpc[%d]", i);
2810Sstevel@tonic-gate PANICNVADD(pnv, name, ptp->ptl1_tnpc);
2820Sstevel@tonic-gate (void) snprintf(name, sizeof (name), "tstate[%d]", i);
2830Sstevel@tonic-gate PANICNVADD(pnv, name, ptp->ptl1_tstate);
2840Sstevel@tonic-gate }
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate PANICNVSET(pdp, pnv);
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate
2890Sstevel@tonic-gate void
panic_savetrap(panic_data_t * pdp,struct panic_trap_info * tip)2905084Sjohnlev panic_savetrap(panic_data_t *pdp, struct panic_trap_info *tip)
2910Sstevel@tonic-gate {
2920Sstevel@tonic-gate panic_nv_t *pnv;
2930Sstevel@tonic-gate ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state;
2940Sstevel@tonic-gate /*
2950Sstevel@tonic-gate * If ptl1_panic() was called, save the trap registers
2960Sstevel@tonic-gate * stored in the ptl1_state struture.
2970Sstevel@tonic-gate */
2980Sstevel@tonic-gate if (pstate->ptl1_entry_count) {
2990Sstevel@tonic-gate ptl1_savetrap(pdp, pstate);
3000Sstevel@tonic-gate return;
3010Sstevel@tonic-gate }
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate panic_saveregs(pdp, tip->trap_regs);
3040Sstevel@tonic-gate pnv = PANICNVGET(pdp);
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate PANICNVADD(pnv, "sfsr", tip->trap_mmu_fsr);
3070Sstevel@tonic-gate PANICNVADD(pnv, "sfar", tip->trap_addr);
3080Sstevel@tonic-gate PANICNVADD(pnv, "tt", tip->trap_type);
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate PANICNVSET(pdp, pnv);
3110Sstevel@tonic-gate }
312