xref: /titanic_51/usr/src/uts/sun4v/os/mach_trap.c (revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c)
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 	short curgl = rp->ptl1_gregs[0].ptl1_gl;
210 
211 	printf("%%tl %%tpc              %%tnpc             %%tstate"
212 	    "           %%tt\n");
213 
214 	for (i = maxtl - 1; i >= 0; i--) {
215 		ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i];
216 		uint64_t tstate = ptp->ptl1_tstate;
217 		uint32_t gl, ccr, asi, cwp, pstate;
218 
219 		cwp = (tstate >> TSTATE_CWP_SHIFT) & TSTATE_CWP_MASK;
220 		pstate = (tstate >> TSTATE_PSTATE_SHIFT) & TSTATE_PSTATE_MASK;
221 		asi = (tstate >> TSTATE_ASI_SHIFT) & TSTATE_ASI_MASK;
222 		ccr = (tstate >> TSTATE_CCR_SHIFT) & TSTATE_CCR_MASK;
223 		gl = (tstate >> TSTATE_GL_SHIFT) & TSTATE_GL_MASK;
224 
225 		printf(" %d  %016" PRIx64 "  %016" PRIx64 "  %010" PRIx64
226 		    "        %03x\n", ptp->ptl1_tl, ptp->ptl1_tpc,
227 		    ptp->ptl1_tnpc, tstate, ptp->ptl1_tt);
228 		printf("    %%gl: %02x  %%ccr: %02x  %%asi: %02x  %%cwp: %x  "
229 		    "%%pstate: %b\n", gl, ccr, asi, cwp, pstate, PSTATE_BITS);
230 	}
231 
232 	/*
233 	 * ptl1_gregs[] array holds global registers for GL 0 through
234 	 * current GL. Note that the current GL global registers are
235 	 * always stored at index 0 in the ptl1_gregs[] array.
236 	 */
237 	for (i = 0; i <= curgl; i++) {
238 		ptl1_gregs_t *pgp = &rp->ptl1_gregs[i];
239 
240 		printf("    %%gl: %02" PRIx64 "\n", pgp->ptl1_gl);
241 		printf("%%g0-3: %016x %016" PRIx64 " %016" PRIx64 " %016"
242 		    PRIx64 "\n", 0, pgp->ptl1_g1, pgp->ptl1_g2, pgp->ptl1_g3);
243 		printf("%%g4-7: %016" PRIx64 " %016" PRIx64 " %016"
244 		    PRIx64 " %016" PRIx64 "\n", pgp->ptl1_g4, pgp->ptl1_g5,
245 		    pgp->ptl1_g6, pgp->ptl1_g7);
246 	}
247 
248 	i = rp->ptl1_cwp;
249 	j = rp->ptl1_canrestore;
250 	for (; j >= 0; i--, j--) {
251 		struct rwindow *wp;
252 		ulong_t off;
253 		char *sym;
254 
255 		if (i < 0)
256 			i += MAXWIN;
257 
258 		wp = &rp->ptl1_rwindow[i];
259 
260 		if ((sym = kobj_getsymname(wp->rw_in[7], &off)) != NULL) {
261 			printf("Register window %d, caller %s+%lx\n",
262 			    i, sym, off);
263 		} else {
264 			printf("Register window %d, caller %lx\n",
265 			    i, wp->rw_in[7]);
266 		}
267 
268 		if (i == rp->ptl1_cwp) {
269 			struct rwindow *nwp;
270 
271 			if (i == MAXWIN - 1)
272 				nwp = &rp->ptl1_rwindow[0];
273 			else
274 				nwp = &rp->ptl1_rwindow[i+1];
275 			printf("%%o0-3: %016lx %016lx %016lx %016lx\n"
276 			    "%%o4-7: %016lx %016lx %016lx %016lx\n",
277 			    nwp->rw_in[0], nwp->rw_in[1], nwp->rw_in[2],
278 			    nwp->rw_in[3], nwp->rw_in[4], nwp->rw_in[5],
279 			    nwp->rw_in[6], nwp->rw_in[7]);
280 		}
281 		printf("%%l0-3: %016lx %016lx %016lx %016lx\n"
282 		    "%%l4-7: %016lx %016lx %016lx %016lx\n",
283 		    wp->rw_local[0], wp->rw_local[1], wp->rw_local[2],
284 		    wp->rw_local[3], wp->rw_local[4], wp->rw_local[5],
285 		    wp->rw_local[6], wp->rw_local[7]);
286 
287 		printf("%%i0-3: %016lx %016lx %016lx %016lx\n"
288 		    "%%i4-7: %016lx %016lx %016lx %016lx\n",
289 		    wp->rw_in[0], wp->rw_in[1], wp->rw_in[2], wp->rw_in[3],
290 		    wp->rw_in[4], wp->rw_in[5], wp->rw_in[6], wp->rw_in[7]);
291 	}
292 }
293 
294 void
295 panic_showtrap(struct trap_info *tip)
296 {
297 	ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state;
298 	/*
299 	 * If ptl1_panic() was called, print out the information
300 	 * saved in the ptl1_state struture.
301 	 */
302 	if (pstate->ptl1_entry_count) {
303 		ptl1_showtrap(pstate);
304 		return;
305 	}
306 
307 	showregs(tip->trap_type, tip->trap_regs, tip->trap_addr,
308 	    tip->trap_mmu_fsr);
309 }
310 
311 static void
312 ptl1_savetrap(panic_data_t *pdp, ptl1_state_t *pstate)
313 {
314 	ptl1_regs_t *rp = &pstate->ptl1_regs;
315 	short i, maxtl = rp->ptl1_trap_regs[0].ptl1_tl;
316 	panic_nv_t *pnv = PANICNVGET(pdp);
317 	char name[PANICNVNAMELEN];
318 
319 	for (i = maxtl - 1; i >= 0; i--) {
320 		ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i];
321 
322 		(void) snprintf(name, sizeof (name), "tl[%d]", i);
323 		PANICNVADD(pnv, name, ptp->ptl1_tl);
324 		(void) snprintf(name, sizeof (name), "tt[%d]", i);
325 		PANICNVADD(pnv, name, ptp->ptl1_tt);
326 		(void) snprintf(name, sizeof (name), "tpc[%d]", i);
327 		PANICNVADD(pnv, name, ptp->ptl1_tpc);
328 		(void) snprintf(name, sizeof (name), "tnpc[%d]", i);
329 		PANICNVADD(pnv, name, ptp->ptl1_tnpc);
330 		(void) snprintf(name, sizeof (name), "tstate[%d]", i);
331 		PANICNVADD(pnv, name, ptp->ptl1_tstate);
332 	}
333 
334 	PANICNVSET(pdp, pnv);
335 }
336 
337 void
338 panic_savetrap(panic_data_t *pdp, struct trap_info *tip)
339 {
340 	panic_nv_t *pnv;
341 	ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state;
342 	/*
343 	 * If ptl1_panic() was called, save the trap registers
344 	 * stored in the ptl1_state struture.
345 	 */
346 	if (pstate->ptl1_entry_count) {
347 		ptl1_savetrap(pdp, pstate);
348 		return;
349 	}
350 
351 	panic_saveregs(pdp, tip->trap_regs);
352 	pnv = PANICNVGET(pdp);
353 
354 	PANICNVADD(pnv, "sfsr", tip->trap_mmu_fsr);
355 	PANICNVADD(pnv, "sfar", tip->trap_addr);
356 	PANICNVADD(pnv, "tt", tip->trap_type);
357 
358 	PANICNVSET(pdp, pnv);
359 }
360