summaryrefslogtreecommitdiff
path: root/usr/src/uts/sun4u/os/mach_trap.c
blob: f6ab0b999eb0c103f6080343a0fbc70ffc263fb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/trap.h>
#include <sys/machtrap.h>
#include <sys/machsystm.h>
#include <sys/cpu_module.h>
#include <sys/panic.h>
#include <sys/uadmin.h>
#include <sys/kobj.h>
#include <sys/contract/process_impl.h>
#include <vm/hat_sfmmu.h>
#include <sys/reboot.h>

#ifdef  TRAPTRACE
#include <sys/traptrace.h>
#endif

void showregs(unsigned, struct regs *, caddr_t, uint_t);

extern int tudebug;

void
mmu_print_sfsr(uint_t sfsr)
{
	printf("MMU sfsr=%x:", sfsr);
	switch (X_FAULT_TYPE(sfsr)) {
	case FT_NONE:
		printf(" No error");
		break;
	case FT_PRIV:
		printf(" Privilege violation");
		break;
	case FT_SPEC_LD:
		printf(" Speculative load on E-bit page");
		break;
	case FT_ATOMIC_NC:
		printf(" Atomic to uncacheable page");
		break;
	case FT_ILL_ALT:
		printf(" Illegal lda or sta");
		break;
	case FT_NFO:
		printf(" Normal access to NFO page");
		break;
	case FT_RANGE:
		printf(" Data or instruction address out of range");
		break;
	case FT_RANGE_REG:
		printf(" Jump to register out of range");
		break;
	default:
		printf(" Unknown error");
		break;
	}
	if (sfsr) {
		printf(" on ASI 0x%x E %d CID %d PRIV %d W %d OW %d FV %d",
			(sfsr & SFSR_ASI) >> SFSR_ASI_SHIFT,
			(sfsr & SFSR_E) != 0,
			(sfsr & SFSR_CTX) >> SFSR_CT_SHIFT,
			(sfsr & SFSR_PR) != 0,
			(sfsr & SFSR_W) != 0,
			(sfsr & SFSR_OW) != 0,
			(sfsr & SFSR_FV) != 0);
	}
	printf("\n");
}


/*
 * Handle an asynchronous hardware error, i.e. an E-$ parity error.
 * The policy is currently to send a hardware error contract event to
 * the process's process contract and to kill the process.  Eventually
 * we may want to instead send a special signal whose default
 * disposition is to generate the contract event.
 */
void
trap_async_hwerr(void)
{
	k_siginfo_t si;
	proc_t *p = ttoproc(curthread);

	errorq_drain(ue_queue); /* flush pending async error messages */

	contract_process_hwerr(p->p_ct_process, p);

	bzero(&si, sizeof (k_siginfo_t));
	si.si_signo = SIGKILL;
	si.si_code = SI_NOINFO;
	trapsig(&si, 1);
}

/*
 * Handle bus error and bus timeout for a user process by sending SIGBUS
 * The type is either ASYNC_BERR or ASYNC_BTO.
 */
void
trap_async_berr_bto(int type, struct regs *rp)
{
	k_siginfo_t si;

	errorq_drain(ue_queue); /* flush pending async error messages */
	bzero(&si, sizeof (k_siginfo_t));

	si.si_signo = SIGBUS;
	si.si_code = (type == ASYNC_BERR ? BUS_OBJERR : BUS_ADRERR);
	si.si_addr = (caddr_t)rp->r_pc; /* AFAR unavailable - future RFE */
	si.si_errno = ENXIO;

	trapsig(&si, 1);
}

#ifdef TRAPWINDOW
long trap_window[25];
#endif /* TRAPWINDOW */

/*
 * Print out debugging info.
 */
/*ARGSUSED*/
void
showregs(uint_t type, struct regs *rp, caddr_t addr, uint_t mmu_fsr)
{
	int s;

	s = spl7();
	type &= ~T_USER;
	printf("%s: ", PTOU(curproc)->u_comm);

	switch (type) {
	case T_SYS_RTT_ALIGN:
	case T_ALIGNMENT:
		printf("alignment error:\n");
		break;
	case T_INSTR_EXCEPTION:
		printf("text access exception:\n");
		break;
	case T_DATA_EXCEPTION:
		printf("data access exception:\n");
		break;
	case T_PRIV_INSTR:
		printf("privileged instruction fault:\n");
		break;
	case T_UNIMP_INSTR:
		printf("illegal instruction fault:\n");
		break;
	case T_IDIV0:
		printf("integer divide zero trap:\n");
		break;
	case T_DIV0:
		printf("zero divide trap:\n");
		break;
	case T_INT_OVERFLOW:
		printf("integer overflow:\n");
		break;
	case T_BREAKPOINT:
		printf("breakpoint trap:\n");
		break;
	case T_TAG_OVERFLOW:
		printf("tag overflow:\n");
		break;
	default:
		if (type >= T_SOFTWARE_TRAP && type <= T_ESOFTWARE_TRAP)
			printf("software trap 0x%x\n", type - T_SOFTWARE_TRAP);
		else
			printf("trap type = 0x%x\n", type);
		break;
	}
	if (type == T_DATA_EXCEPTION || type == T_INSTR_EXCEPTION) {
		mmu_print_sfsr(mmu_fsr);
	} else if (addr) {
		printf("addr=0x%p\n", (void *)addr);
	}

	printf("pid=%d, pc=0x%lx, sp=0x%llx, tstate=0x%llx, context=0x%x\n",
	    (ttoproc(curthread) && ttoproc(curthread)->p_pidp) ?
	    (ttoproc(curthread)->p_pid) : 0, rp->r_pc, rp->r_sp,
	    rp->r_tstate, sfmmu_getctx_sec());
	if (USERMODE(rp->r_tstate)) {
		printf("o0-o7: %llx, %llx, %llx, %llx, %llx, %llx, "
		    "%llx, %llx\n", rp->r_o0, rp->r_o1, rp->r_o2, rp->r_o3,
		    rp->r_o4, rp->r_o5, rp->r_o6, rp->r_o7);
	}
	printf("g1-g7: %llx, %llx, %llx, %llx, %llx, %llx, %llx\n",
	    rp->r_g1, rp->r_g2, rp->r_g3,
	    rp->r_g4, rp->r_g5, rp->r_g6, rp->r_g7);

#ifdef TRAPWINDOW
	printf("trap_window: wim=%x\n", trap_window[24]);
	printf("o0-o7: %x, %x, %x, %x, %x, %x, %x, %x\n",
	    trap_window[0], trap_window[1], trap_window[2], trap_window[3],
	    trap_window[4], trap_window[5], trap_window[6], trap_window[7]);
	printf("l0-l7: %x, %x, %x, %x, %x, %x, %x, %x\n",
	    trap_window[8], trap_window[9], trap_window[10], trap_window[11],
	    trap_window[12], trap_window[13], trap_window[14], trap_window[15]);
	printf("i0-i7: %x, %x, %x, %x, %x, %x, %x, %x\n",
	    trap_window[16], trap_window[17], trap_window[18], trap_window[19],
	    trap_window[20], trap_window[21], trap_window[22], trap_window[23]);
#endif /* TRAPWINDOW */
	if (tudebug > 1 && (boothowto & RB_DEBUG)) {
		debug_enter((char *)NULL);
	}
	splx(s);
}

static void
ptl1_showtrap(ptl1_state_t *pstate)
{
	ptl1_regs_t *rp = &pstate->ptl1_regs;
	short i, j, maxtl = rp->ptl1_trap_regs[0].ptl1_tl;

	printf("%%tl %%tpc              %%tnpc             %%tstate"
	    "           %%tt\n");

	for (i = maxtl - 1; i >= 0; i--) {
		ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i];
		uint64_t tstate = ptp->ptl1_tstate;
		uint32_t ccr, asi, cwp, pstate;

		cwp = (tstate >> TSTATE_CWP_SHIFT) & TSTATE_CWP_MASK;
		pstate = (tstate >> TSTATE_PSTATE_SHIFT) & TSTATE_PSTATE_MASK;
		asi = (tstate >> TSTATE_ASI_SHIFT) & TSTATE_ASI_MASK;
		ccr = (tstate >> TSTATE_CCR_SHIFT) & TSTATE_CCR_MASK;

		printf(" %d  %016" PRIx64 "  %016" PRIx64 "  %010" PRIx64
		    "        %03x\n", ptp->ptl1_tl, ptp->ptl1_tpc,
		    ptp->ptl1_tnpc, tstate, ptp->ptl1_tt);
		printf("    %%ccr: %02x  %%asi: %02x  %%cwp: %x  "
		    "%%pstate: %b\n", ccr, asi, cwp, pstate, PSTATE_BITS);
	}

	printf("%%g0-3: %016x %016" PRIx64 " %016" PRIx64 " %016"
	    PRIx64 "\n", 0, rp->ptl1_g1, rp->ptl1_g2, rp->ptl1_g3);
	printf("%%g4-7: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016"
	    PRIx64 "\n", rp->ptl1_g4, rp->ptl1_g5, rp->ptl1_g6, rp->ptl1_g7);

	i = rp->ptl1_cwp;
	j = rp->ptl1_canrestore;
	for (; j >= 0; i--, j--) {
		struct rwindow *wp;
		ulong_t off;
		char *sym;

		if (i < 0)
			i += MAXWIN;

		wp = &rp->ptl1_rwindow[i];

		if ((sym = kobj_getsymname(wp->rw_in[7], &off)) != NULL) {
			printf("Register window %d, caller %s+%lx\n",
			    i, sym, off);
		} else {
			printf("Register window %d, caller %lx\n",
			    i, wp->rw_in[7]);
		}

		if (i == rp->ptl1_cwp) {
			struct rwindow *nwp;

			if (i == MAXWIN - 1)
				nwp = &rp->ptl1_rwindow[0];
			else
				nwp = &rp->ptl1_rwindow[i+1];
			printf("%%o0-3: %016lx %016lx %016lx %016lx\n"
			    "%%o4-7: %016lx %016lx %016lx %016lx\n",
			    nwp->rw_in[0], nwp->rw_in[1], nwp->rw_in[2],
			    nwp->rw_in[3], nwp->rw_in[4], nwp->rw_in[5],
			    nwp->rw_in[6], nwp->rw_in[7]);
		}
		printf("%%l0-3: %016lx %016lx %016lx %016lx\n"
		    "%%l4-7: %016lx %016lx %016lx %016lx\n",
		    wp->rw_local[0], wp->rw_local[1], wp->rw_local[2],
		    wp->rw_local[3], wp->rw_local[4], wp->rw_local[5],
		    wp->rw_local[6], wp->rw_local[7]);

		printf("%%i0-3: %016lx %016lx %016lx %016lx\n"
		    "%%i4-7: %016lx %016lx %016lx %016lx\n",
		    wp->rw_in[0], wp->rw_in[1], wp->rw_in[2], wp->rw_in[3],
		    wp->rw_in[4], wp->rw_in[5], wp->rw_in[6], wp->rw_in[7]);
	}
}

void
panic_showtrap(struct trap_info *tip)
{
	ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state;
	/*
	 * If ptl1_panic() was called, print out the information
	 * saved in the ptl1_state struture.
	 */
	if (pstate->ptl1_entry_count) {
		ptl1_showtrap(pstate);
		return;
	}

	showregs(tip->trap_type, tip->trap_regs, tip->trap_addr,
	    tip->trap_mmu_fsr);
}

static void
ptl1_savetrap(panic_data_t *pdp, ptl1_state_t *pstate)
{
	ptl1_regs_t *rp = &pstate->ptl1_regs;
	short i, maxtl = rp->ptl1_trap_regs[0].ptl1_tl;
	panic_nv_t *pnv = PANICNVGET(pdp);
	char name[PANICNVNAMELEN];

	for (i = maxtl - 1; i >= 0; i--) {
		ptl1_trapregs_t *ptp = &rp->ptl1_trap_regs[i];

		(void) snprintf(name, sizeof (name), "tl[%d]", i);
		PANICNVADD(pnv, name, ptp->ptl1_tl);
		(void) snprintf(name, sizeof (name), "tt[%d]", i);
		PANICNVADD(pnv, name, ptp->ptl1_tt);
		(void) snprintf(name, sizeof (name), "tpc[%d]", i);
		PANICNVADD(pnv, name, ptp->ptl1_tpc);
		(void) snprintf(name, sizeof (name), "tnpc[%d]", i);
		PANICNVADD(pnv, name, ptp->ptl1_tnpc);
		(void) snprintf(name, sizeof (name), "tstate[%d]", i);
		PANICNVADD(pnv, name, ptp->ptl1_tstate);
	}

	PANICNVSET(pdp, pnv);
}

void
panic_savetrap(panic_data_t *pdp, struct trap_info *tip)
{
	panic_nv_t *pnv;
	ptl1_state_t *pstate = &CPU->cpu_m.ptl1_state;
	/*
	 * If ptl1_panic() was called, save the trap registers
	 * stored in the ptl1_state struture.
	 */
	if (pstate->ptl1_entry_count) {
		ptl1_savetrap(pdp, pstate);
		return;
	}

	panic_saveregs(pdp, tip->trap_regs);
	pnv = PANICNVGET(pdp);

	PANICNVADD(pnv, "sfsr", tip->trap_mmu_fsr);
	PANICNVADD(pnv, "sfar", tip->trap_addr);
	PANICNVADD(pnv, "tt", tip->trap_type);

	PANICNVSET(pdp, pnv);
}