1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <sys/trap.h> 30 #include <sys/machtrap.h> 31 #include <sys/machsystm.h> 32 #include <sys/cpu_module.h> 33 #include <sys/panic.h> 34 #include <sys/uadmin.h> 35 #include <sys/kobj.h> 36 #include <sys/contract/process_impl.h> 37 #include <vm/hat_sfmmu.h> 38 #include <sys/reboot.h> 39 40 #ifdef TRAPTRACE 41 #include <sys/traptrace.h> 42 #endif 43 44 void showregs(unsigned, struct regs *, caddr_t, uint_t); 45 46 extern int tudebug; 47 48 void 49 mmu_print_sfsr(uint_t sfsr) 50 { 51 printf("MMU sfsr=%x:", sfsr); 52 switch (X_FAULT_TYPE(sfsr)) { 53 case FT_NONE: 54 printf(" No error"); 55 break; 56 case FT_PRIV: 57 printf(" Privilege violation"); 58 break; 59 case FT_SPEC_LD: 60 printf(" Speculative load on E-bit page"); 61 break; 62 case FT_ATOMIC_NC: 63 printf(" Atomic to uncacheable page"); 64 break; 65 case FT_ILL_ALT: 66 printf(" Illegal lda or sta"); 67 break; 68 case FT_NFO: 69 printf(" Normal access to NFO page"); 70 break; 71 case FT_RANGE: 72 printf(" Data or instruction address out of range"); 73 break; 74 default: 75 printf(" Unknown error"); 76 break; 77 } 78 79 printf(" context 0x%x", X_FAULT_CTX(sfsr)); 80 printf("\n"); 81 } 82 83 84 /* 85 * Handle an asynchronous hardware error, i.e. an E-$ parity error. 86 * The policy is currently to send a hardware error contract event to 87 * the process's process contract and to kill the process. Eventually 88 * we may want to instead send a special signal whose default 89 * disposition is to generate the contract event. 90 */ 91 void 92 trap_async_hwerr(void) 93 { 94 k_siginfo_t si; 95 proc_t *p = ttoproc(curthread); 96 97 errorq_drain(ue_queue); /* flush pending async error messages */ 98 99 contract_process_hwerr(p->p_ct_process, p); 100 101 bzero(&si, sizeof (k_siginfo_t)); 102 si.si_signo = SIGKILL; 103 si.si_code = SI_NOINFO; 104 trapsig(&si, 1); 105 } 106 107 /* 108 * Handle bus error and bus timeout for a user process by sending SIGBUS 109 * The type is either ASYNC_BERR or ASYNC_BTO. 110 */ 111 void 112 trap_async_berr_bto(int type, struct regs *rp) 113 { 114 k_siginfo_t si; 115 116 errorq_drain(ue_queue); /* flush pending async error messages */ 117 bzero(&si, sizeof (k_siginfo_t)); 118 119 si.si_signo = SIGBUS; 120 si.si_code = (type == ASYNC_BERR ? BUS_OBJERR : BUS_ADRERR); 121 si.si_addr = (caddr_t)rp->r_pc; /* AFAR unavailable - future RFE */ 122 si.si_errno = ENXIO; 123 124 trapsig(&si, 1); 125 } 126 127 /* 128 * Print out debugging info. 129 */ 130 /*ARGSUSED*/ 131 void 132 showregs(uint_t type, struct regs *rp, caddr_t addr, uint_t mmu_fsr) 133 { 134 int s; 135 136 s = spl7(); 137 type &= ~T_USER; 138 printf("%s: ", u.u_comm); 139 140 switch (type) { 141 case T_SYS_RTT_ALIGN: 142 case T_ALIGNMENT: 143 printf("alignment error:\n"); 144 break; 145 case T_INSTR_EXCEPTION: 146 printf("text access exception:\n"); 147 break; 148 case T_DATA_EXCEPTION: 149 printf("data access exception:\n"); 150 break; 151 case T_PRIV_INSTR: 152 printf("privileged instruction fault:\n"); 153 break; 154 case T_UNIMP_INSTR: 155 printf("illegal instruction fault:\n"); 156 break; 157 case T_IDIV0: 158 printf("integer divide zero trap:\n"); 159 break; 160 case T_DIV0: 161 printf("zero divide trap:\n"); 162 break; 163 case T_INT_OVERFLOW: 164 printf("integer overflow:\n"); 165 break; 166 case T_BREAKPOINT: 167 printf("breakpoint trap:\n"); 168 break; 169 case T_TAG_OVERFLOW: 170 printf("tag overflow:\n"); 171 break; 172 default: 173 if (type >= T_SOFTWARE_TRAP && type <= T_ESOFTWARE_TRAP) 174 printf("software trap 0x%x\n", type - T_SOFTWARE_TRAP); 175 else 176 printf("trap type = 0x%x\n", type); 177 break; 178 } 179 if (type == T_DATA_EXCEPTION || type == T_INSTR_EXCEPTION) { 180 mmu_print_sfsr(mmu_fsr); 181 } else if (addr) { 182 printf("addr=0x%p\n", (void *)addr); 183 } 184 185 printf("pid=%d, pc=0x%lx, sp=0x%llx, tstate=0x%llx, context=0x%x\n", 186 (ttoproc(curthread) && ttoproc(curthread)->p_pidp) ? 187 (ttoproc(curthread)->p_pid) : 0, rp->r_pc, rp->r_sp, 188 rp->r_tstate, sfmmu_getctx_sec()); 189 if (USERMODE(rp->r_tstate)) { 190 printf("o0-o7: %llx, %llx, %llx, %llx, %llx, %llx, " 191 "%llx, %llx\n", rp->r_o0, rp->r_o1, rp->r_o2, rp->r_o3, 192 rp->r_o4, rp->r_o5, rp->r_o6, rp->r_o7); 193 } 194 printf("g1-g7: %llx, %llx, %llx, %llx, %llx, %llx, %llx\n", 195 rp->r_g1, rp->r_g2, rp->r_g3, 196 rp->r_g4, rp->r_g5, rp->r_g6, rp->r_g7); 197 198 if (tudebug > 1 && (boothowto & RB_DEBUG)) { 199 debug_enter((char *)NULL); 200 } 201 splx(s); 202 } 203 204 static void 205 ptl1_showtrap(ptl1_state_t *pstate) 206 { 207 ptl1_regs_t *rp = &pstate->ptl1_regs; 208 short i, j, maxtl = rp->ptl1_trap_regs[0].ptl1_tl; 209 210 printf("%%tl %%tpc %%tnpc %%tstate" 211 " %%tt\n"); 212 213 for (i = maxtl - 1; i >= 0; i--) { 214 ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i]; 215 uint64_t tstate = ptp->ptl1_tstate; 216 uint32_t ccr, asi, cwp, pstate; 217 218 cwp = (tstate >> TSTATE_CWP_SHIFT) & TSTATE_CWP_MASK; 219 pstate = (tstate >> TSTATE_PSTATE_SHIFT) & TSTATE_PSTATE_MASK; 220 asi = (tstate >> TSTATE_ASI_SHIFT) & TSTATE_ASI_MASK; 221 ccr = (tstate >> TSTATE_CCR_SHIFT) & TSTATE_CCR_MASK; 222 223 printf(" %d %016" PRIx64 " %016" PRIx64 " %010" PRIx64 224 " %03x\n", ptp->ptl1_tl, ptp->ptl1_tpc, 225 ptp->ptl1_tnpc, tstate, ptp->ptl1_tt); 226 printf(" %%ccr: %02x %%asi: %02x %%cwp: %x " 227 "%%pstate: %b\n", ccr, asi, cwp, pstate, PSTATE_BITS); 228 } 229 230 printf("%%g0-3: %016x %016" PRIx64 " %016" PRIx64 " %016" 231 PRIx64 "\n", 0, rp->ptl1_g1, rp->ptl1_g2, rp->ptl1_g3); 232 printf("%%g4-7: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" 233 PRIx64 "\n", rp->ptl1_g4, rp->ptl1_g5, rp->ptl1_g6, rp->ptl1_g7); 234 235 i = rp->ptl1_cwp; 236 j = rp->ptl1_canrestore; 237 for (; j >= 0; i--, j--) { 238 struct rwindow *wp; 239 ulong_t off; 240 char *sym; 241 242 if (i < 0) 243 i += MAXWIN; 244 245 wp = &rp->ptl1_rwindow[i]; 246 247 if ((sym = kobj_getsymname(wp->rw_in[7], &off)) != NULL) { 248 printf("Register window %d, caller %s+%lx\n", 249 i, sym, off); 250 } else { 251 printf("Register window %d, caller %lx\n", 252 i, wp->rw_in[7]); 253 } 254 255 if (i == rp->ptl1_cwp) { 256 struct rwindow *nwp; 257 258 if (i == MAXWIN - 1) 259 nwp = &rp->ptl1_rwindow[0]; 260 else 261 nwp = &rp->ptl1_rwindow[i+1]; 262 printf("%%o0-3: %016lx %016lx %016lx %016lx\n" 263 "%%o4-7: %016lx %016lx %016lx %016lx\n", 264 nwp->rw_in[0], nwp->rw_in[1], nwp->rw_in[2], 265 nwp->rw_in[3], nwp->rw_in[4], nwp->rw_in[5], 266 nwp->rw_in[6], nwp->rw_in[7]); 267 } 268 printf("%%l0-3: %016lx %016lx %016lx %016lx\n" 269 "%%l4-7: %016lx %016lx %016lx %016lx\n", 270 wp->rw_local[0], wp->rw_local[1], wp->rw_local[2], 271 wp->rw_local[3], wp->rw_local[4], wp->rw_local[5], 272 wp->rw_local[6], wp->rw_local[7]); 273 274 printf("%%i0-3: %016lx %016lx %016lx %016lx\n" 275 "%%i4-7: %016lx %016lx %016lx %016lx\n", 276 wp->rw_in[0], wp->rw_in[1], wp->rw_in[2], wp->rw_in[3], 277 wp->rw_in[4], wp->rw_in[5], wp->rw_in[6], wp->rw_in[7]); 278 } 279 } 280 281 void 282 panic_showtrap(struct trap_info *tip) 283 { 284 ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state; 285 /* 286 * If ptl1_panic() was called, print out the information 287 * saved in the ptl1_state struture. 288 */ 289 if (pstate->ptl1_entry_count) { 290 ptl1_showtrap(pstate); 291 return; 292 } 293 294 showregs(tip->trap_type, tip->trap_regs, tip->trap_addr, 295 tip->trap_mmu_fsr); 296 } 297 298 static void 299 ptl1_savetrap(panic_data_t *pdp, ptl1_state_t *pstate) 300 { 301 ptl1_regs_t *rp = &pstate->ptl1_regs; 302 short i, maxtl = rp->ptl1_trap_regs[0].ptl1_tl; 303 panic_nv_t *pnv = PANICNVGET(pdp); 304 char name[PANICNVNAMELEN]; 305 306 for (i = maxtl - 1; i >= 0; i--) { 307 ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i]; 308 309 (void) snprintf(name, sizeof (name), "tl[%d]", i); 310 PANICNVADD(pnv, name, ptp->ptl1_tl); 311 (void) snprintf(name, sizeof (name), "tt[%d]", i); 312 PANICNVADD(pnv, name, ptp->ptl1_tt); 313 (void) snprintf(name, sizeof (name), "tpc[%d]", i); 314 PANICNVADD(pnv, name, ptp->ptl1_tpc); 315 (void) snprintf(name, sizeof (name), "tnpc[%d]", i); 316 PANICNVADD(pnv, name, ptp->ptl1_tnpc); 317 (void) snprintf(name, sizeof (name), "tstate[%d]", i); 318 PANICNVADD(pnv, name, ptp->ptl1_tstate); 319 } 320 321 PANICNVSET(pdp, pnv); 322 } 323 324 void 325 panic_savetrap(panic_data_t *pdp, struct trap_info *tip) 326 { 327 panic_nv_t *pnv; 328 ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state; 329 /* 330 * If ptl1_panic() was called, save the trap registers 331 * stored in the ptl1_state struture. 332 */ 333 if (pstate->ptl1_entry_count) { 334 ptl1_savetrap(pdp, pstate); 335 return; 336 } 337 338 panic_saveregs(pdp, tip->trap_regs); 339 pnv = PANICNVGET(pdp); 340 341 PANICNVADD(pnv, "sfsr", tip->trap_mmu_fsr); 342 PANICNVADD(pnv, "sfar", tip->trap_addr); 343 PANICNVADD(pnv, "tt", tip->trap_type); 344 345 PANICNVSET(pdp, pnv); 346 } 347