xref: /illumos-gate/usr/src/uts/sun4u/os/mach_trap.c (revision 3db86aab)
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 2004 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 	case FT_RANGE_REG:
75 		printf(" Jump to register out of range");
76 		break;
77 	default:
78 		printf(" Unknown error");
79 		break;
80 	}
81 	if (sfsr) {
82 		printf(" on ASI 0x%x E %d CID %d PRIV %d W %d OW %d FV %d",
83 			(sfsr & SFSR_ASI) >> SFSR_ASI_SHIFT,
84 			(sfsr & SFSR_E) != 0,
85 			(sfsr & SFSR_CTX) >> SFSR_CT_SHIFT,
86 			(sfsr & SFSR_PR) != 0,
87 			(sfsr & SFSR_W) != 0,
88 			(sfsr & SFSR_OW) != 0,
89 			(sfsr & SFSR_FV) != 0);
90 	}
91 	printf("\n");
92 }
93 
94 
95 /*
96  * Handle an asynchronous hardware error, i.e. an E-$ parity error.
97  * The policy is currently to send a hardware error contract event to
98  * the process's process contract and to kill the process.  Eventually
99  * we may want to instead send a special signal whose default
100  * disposition is to generate the contract event.
101  */
102 void
103 trap_async_hwerr(void)
104 {
105 	k_siginfo_t si;
106 	proc_t *p = ttoproc(curthread);
107 
108 	errorq_drain(ue_queue); /* flush pending async error messages */
109 
110 	contract_process_hwerr(p->p_ct_process, p);
111 
112 	bzero(&si, sizeof (k_siginfo_t));
113 	si.si_signo = SIGKILL;
114 	si.si_code = SI_NOINFO;
115 	trapsig(&si, 1);
116 }
117 
118 /*
119  * Handle bus error and bus timeout for a user process by sending SIGBUS
120  * The type is either ASYNC_BERR or ASYNC_BTO.
121  */
122 void
123 trap_async_berr_bto(int type, struct regs *rp)
124 {
125 	k_siginfo_t si;
126 
127 	errorq_drain(ue_queue); /* flush pending async error messages */
128 	bzero(&si, sizeof (k_siginfo_t));
129 
130 	si.si_signo = SIGBUS;
131 	si.si_code = (type == ASYNC_BERR ? BUS_OBJERR : BUS_ADRERR);
132 	si.si_addr = (caddr_t)rp->r_pc; /* AFAR unavailable - future RFE */
133 	si.si_errno = ENXIO;
134 
135 	trapsig(&si, 1);
136 }
137 
138 #ifdef TRAPWINDOW
139 long trap_window[25];
140 #endif /* TRAPWINDOW */
141 
142 /*
143  * Print out debugging info.
144  */
145 /*ARGSUSED*/
146 void
147 showregs(uint_t type, struct regs *rp, caddr_t addr, uint_t mmu_fsr)
148 {
149 	int s;
150 
151 	s = spl7();
152 	type &= ~T_USER;
153 	printf("%s: ", u.u_comm);
154 
155 	switch (type) {
156 	case T_SYS_RTT_ALIGN:
157 	case T_ALIGNMENT:
158 		printf("alignment error:\n");
159 		break;
160 	case T_INSTR_EXCEPTION:
161 		printf("text access exception:\n");
162 		break;
163 	case T_DATA_EXCEPTION:
164 		printf("data access exception:\n");
165 		break;
166 	case T_PRIV_INSTR:
167 		printf("privileged instruction fault:\n");
168 		break;
169 	case T_UNIMP_INSTR:
170 		printf("illegal instruction fault:\n");
171 		break;
172 	case T_IDIV0:
173 		printf("integer divide zero trap:\n");
174 		break;
175 	case T_DIV0:
176 		printf("zero divide trap:\n");
177 		break;
178 	case T_INT_OVERFLOW:
179 		printf("integer overflow:\n");
180 		break;
181 	case T_BREAKPOINT:
182 		printf("breakpoint trap:\n");
183 		break;
184 	case T_TAG_OVERFLOW:
185 		printf("tag overflow:\n");
186 		break;
187 	default:
188 		if (type >= T_SOFTWARE_TRAP && type <= T_ESOFTWARE_TRAP)
189 			printf("software trap 0x%x\n", type - T_SOFTWARE_TRAP);
190 		else
191 			printf("trap type = 0x%x\n", type);
192 		break;
193 	}
194 	if (type == T_DATA_EXCEPTION || type == T_INSTR_EXCEPTION) {
195 		mmu_print_sfsr(mmu_fsr);
196 	} else if (addr) {
197 		printf("addr=0x%p\n", (void *)addr);
198 	}
199 
200 	printf("pid=%d, pc=0x%lx, sp=0x%llx, tstate=0x%llx, context=0x%x\n",
201 	    (ttoproc(curthread) && ttoproc(curthread)->p_pidp) ?
202 	    (ttoproc(curthread)->p_pid) : 0, rp->r_pc, rp->r_sp,
203 	    rp->r_tstate, sfmmu_getctx_sec());
204 	if (USERMODE(rp->r_tstate)) {
205 		printf("o0-o7: %llx, %llx, %llx, %llx, %llx, %llx, "
206 		    "%llx, %llx\n", rp->r_o0, rp->r_o1, rp->r_o2, rp->r_o3,
207 		    rp->r_o4, rp->r_o5, rp->r_o6, rp->r_o7);
208 	}
209 	printf("g1-g7: %llx, %llx, %llx, %llx, %llx, %llx, %llx\n",
210 	    rp->r_g1, rp->r_g2, rp->r_g3,
211 	    rp->r_g4, rp->r_g5, rp->r_g6, rp->r_g7);
212 
213 #ifdef TRAPWINDOW
214 	printf("trap_window: wim=%x\n", trap_window[24]);
215 	printf("o0-o7: %x, %x, %x, %x, %x, %x, %x, %x\n",
216 	    trap_window[0], trap_window[1], trap_window[2], trap_window[3],
217 	    trap_window[4], trap_window[5], trap_window[6], trap_window[7]);
218 	printf("l0-l7: %x, %x, %x, %x, %x, %x, %x, %x\n",
219 	    trap_window[8], trap_window[9], trap_window[10], trap_window[11],
220 	    trap_window[12], trap_window[13], trap_window[14], trap_window[15]);
221 	printf("i0-i7: %x, %x, %x, %x, %x, %x, %x, %x\n",
222 	    trap_window[16], trap_window[17], trap_window[18], trap_window[19],
223 	    trap_window[20], trap_window[21], trap_window[22], trap_window[23]);
224 #endif /* TRAPWINDOW */
225 	if (tudebug > 1 && (boothowto & RB_DEBUG)) {
226 		debug_enter((char *)NULL);
227 	}
228 	splx(s);
229 }
230 
231 static void
232 ptl1_showtrap(ptl1_state_t *pstate)
233 {
234 	ptl1_regs_t *rp = &pstate->ptl1_regs;
235 	short i, j, maxtl = rp->ptl1_trap_regs[0].ptl1_tl;
236 
237 	printf("%%tl %%tpc              %%tnpc             %%tstate"
238 	    "           %%tt\n");
239 
240 	for (i = maxtl - 1; i >= 0; i--) {
241 		ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i];
242 		uint64_t tstate = ptp->ptl1_tstate;
243 		uint32_t ccr, asi, cwp, pstate;
244 
245 		cwp = (tstate >> TSTATE_CWP_SHIFT) & TSTATE_CWP_MASK;
246 		pstate = (tstate >> TSTATE_PSTATE_SHIFT) & TSTATE_PSTATE_MASK;
247 		asi = (tstate >> TSTATE_ASI_SHIFT) & TSTATE_ASI_MASK;
248 		ccr = (tstate >> TSTATE_CCR_SHIFT) & TSTATE_CCR_MASK;
249 
250 		printf(" %d  %016" PRIx64 "  %016" PRIx64 "  %010" PRIx64
251 		    "        %03x\n", ptp->ptl1_tl, ptp->ptl1_tpc,
252 		    ptp->ptl1_tnpc, tstate, ptp->ptl1_tt);
253 		printf("    %%ccr: %02x  %%asi: %02x  %%cwp: %x  "
254 		    "%%pstate: %b\n", ccr, asi, cwp, pstate, PSTATE_BITS);
255 	}
256 
257 	printf("%%g0-3: %016x %016" PRIx64 " %016" PRIx64 " %016"
258 	    PRIx64 "\n", 0, rp->ptl1_g1, rp->ptl1_g2, rp->ptl1_g3);
259 	printf("%%g4-7: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016"
260 	    PRIx64 "\n", rp->ptl1_g4, rp->ptl1_g5, rp->ptl1_g6, rp->ptl1_g7);
261 
262 	i = rp->ptl1_cwp;
263 	j = rp->ptl1_canrestore;
264 	for (; j >= 0; i--, j--) {
265 		struct rwindow *wp;
266 		ulong_t off;
267 		char *sym;
268 
269 		if (i < 0)
270 			i += MAXWIN;
271 
272 		wp = &rp->ptl1_rwindow[i];
273 
274 		if ((sym = kobj_getsymname(wp->rw_in[7], &off)) != NULL) {
275 			printf("Register window %d, caller %s+%lx\n",
276 			    i, sym, off);
277 		} else {
278 			printf("Register window %d, caller %lx\n",
279 			    i, wp->rw_in[7]);
280 		}
281 
282 		if (i == rp->ptl1_cwp) {
283 			struct rwindow *nwp;
284 
285 			if (i == MAXWIN - 1)
286 				nwp = &rp->ptl1_rwindow[0];
287 			else
288 				nwp = &rp->ptl1_rwindow[i+1];
289 			printf("%%o0-3: %016lx %016lx %016lx %016lx\n"
290 			    "%%o4-7: %016lx %016lx %016lx %016lx\n",
291 			    nwp->rw_in[0], nwp->rw_in[1], nwp->rw_in[2],
292 			    nwp->rw_in[3], nwp->rw_in[4], nwp->rw_in[5],
293 			    nwp->rw_in[6], nwp->rw_in[7]);
294 		}
295 		printf("%%l0-3: %016lx %016lx %016lx %016lx\n"
296 		    "%%l4-7: %016lx %016lx %016lx %016lx\n",
297 		    wp->rw_local[0], wp->rw_local[1], wp->rw_local[2],
298 		    wp->rw_local[3], wp->rw_local[4], wp->rw_local[5],
299 		    wp->rw_local[6], wp->rw_local[7]);
300 
301 		printf("%%i0-3: %016lx %016lx %016lx %016lx\n"
302 		    "%%i4-7: %016lx %016lx %016lx %016lx\n",
303 		    wp->rw_in[0], wp->rw_in[1], wp->rw_in[2], wp->rw_in[3],
304 		    wp->rw_in[4], wp->rw_in[5], wp->rw_in[6], wp->rw_in[7]);
305 	}
306 }
307 
308 void
309 panic_showtrap(struct trap_info *tip)
310 {
311 	ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state;
312 	/*
313 	 * If ptl1_panic() was called, print out the information
314 	 * saved in the ptl1_state struture.
315 	 */
316 	if (pstate->ptl1_entry_count) {
317 		ptl1_showtrap(pstate);
318 		return;
319 	}
320 
321 	showregs(tip->trap_type, tip->trap_regs, tip->trap_addr,
322 	    tip->trap_mmu_fsr);
323 }
324 
325 static void
326 ptl1_savetrap(panic_data_t *pdp, ptl1_state_t *pstate)
327 {
328 	ptl1_regs_t *rp = &pstate->ptl1_regs;
329 	short i, maxtl = rp->ptl1_trap_regs[0].ptl1_tl;
330 	panic_nv_t *pnv = PANICNVGET(pdp);
331 	char name[PANICNVNAMELEN];
332 
333 	for (i = maxtl - 1; i >= 0; i--) {
334 		ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i];
335 
336 		(void) snprintf(name, sizeof (name), "tl[%d]", i);
337 		PANICNVADD(pnv, name, ptp->ptl1_tl);
338 		(void) snprintf(name, sizeof (name), "tt[%d]", i);
339 		PANICNVADD(pnv, name, ptp->ptl1_tt);
340 		(void) snprintf(name, sizeof (name), "tpc[%d]", i);
341 		PANICNVADD(pnv, name, ptp->ptl1_tpc);
342 		(void) snprintf(name, sizeof (name), "tnpc[%d]", i);
343 		PANICNVADD(pnv, name, ptp->ptl1_tnpc);
344 		(void) snprintf(name, sizeof (name), "tstate[%d]", i);
345 		PANICNVADD(pnv, name, ptp->ptl1_tstate);
346 	}
347 
348 	PANICNVSET(pdp, pnv);
349 }
350 
351 void
352 panic_savetrap(panic_data_t *pdp, struct trap_info *tip)
353 {
354 	panic_nv_t *pnv;
355 	ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state;
356 	/*
357 	 * If ptl1_panic() was called, save the trap registers
358 	 * stored in the ptl1_state struture.
359 	 */
360 	if (pstate->ptl1_entry_count) {
361 		ptl1_savetrap(pdp, pstate);
362 		return;
363 	}
364 
365 	panic_saveregs(pdp, tip->trap_regs);
366 	pnv = PANICNVGET(pdp);
367 
368 	PANICNVADD(pnv, "sfsr", tip->trap_mmu_fsr);
369 	PANICNVADD(pnv, "sfar", tip->trap_addr);
370 	PANICNVADD(pnv, "tt", tip->trap_type);
371 
372 	PANICNVSET(pdp, pnv);
373 }
374