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