trap.c revision 1.8 1 1.8 dsl /* $NetBSD: trap.c,v 1.8 2009/03/14 15:36:08 dsl Exp $ */
2 1.2 cherry
3 1.2 cherry /*-
4 1.2 cherry * Copyright (c) 2005 Marcel Moolenaar
5 1.2 cherry * All rights reserved.
6 1.2 cherry *
7 1.2 cherry * Redistribution and use in source and binary forms, with or without
8 1.2 cherry * modification, are permitted provided that the following conditions
9 1.2 cherry * are met:
10 1.2 cherry *
11 1.2 cherry * 1. Redistributions of source code must retain the above copyright
12 1.2 cherry * notice, this list of conditions and the following disclaimer.
13 1.2 cherry * 2. Redistributions in binary form must reproduce the above copyright
14 1.2 cherry * notice, this list of conditions and the following disclaimer in the
15 1.2 cherry * documentation and/or other materials provided with the distribution.
16 1.2 cherry *
17 1.2 cherry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.2 cherry * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.2 cherry * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.2 cherry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.2 cherry * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.2 cherry * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.2 cherry * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.2 cherry * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.2 cherry * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 1.2 cherry * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.2 cherry */
28 1.1 cherry
29 1.1 cherry /*-
30 1.1 cherry * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
31 1.1 cherry * All rights reserved.
32 1.1 cherry *
33 1.1 cherry * This code is derived from software contributed to The NetBSD Foundation
34 1.1 cherry * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
35 1.1 cherry * NASA Ames Research Center, by Charles M. Hannum, and by Ross Harvey.
36 1.1 cherry *
37 1.1 cherry * Redistribution and use in source and binary forms, with or without
38 1.1 cherry * modification, are permitted provided that the following conditions
39 1.1 cherry * are met:
40 1.1 cherry * 1. Redistributions of source code must retain the above copyright
41 1.1 cherry * notice, this list of conditions and the following disclaimer.
42 1.1 cherry * 2. Redistributions in binary form must reproduce the above copyright
43 1.1 cherry * notice, this list of conditions and the following disclaimer in the
44 1.1 cherry * documentation and/or other materials provided with the distribution.
45 1.1 cherry *
46 1.1 cherry * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
47 1.1 cherry * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
48 1.1 cherry * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49 1.1 cherry * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
50 1.1 cherry * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51 1.1 cherry * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52 1.1 cherry * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 1.1 cherry * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 1.1 cherry * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 1.1 cherry * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
56 1.1 cherry * POSSIBILITY OF SUCH DAMAGE.
57 1.1 cherry */
58 1.1 cherry
59 1.1 cherry
60 1.1 cherry #include "opt_ddb.h"
61 1.1 cherry
62 1.1 cherry #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
63 1.1 cherry
64 1.8 dsl __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.8 2009/03/14 15:36:08 dsl Exp $");
65 1.1 cherry
66 1.1 cherry #include <sys/param.h>
67 1.1 cherry #include <sys/systm.h>
68 1.1 cherry #include <sys/proc.h>
69 1.7 wrstuden #include <sys/sa.h>
70 1.7 wrstuden #include <sys/savar.h>
71 1.1 cherry
72 1.1 cherry #include <sys/userret.h>
73 1.1 cherry
74 1.1 cherry #include <uvm/uvm_extern.h>
75 1.1 cherry
76 1.1 cherry #include <machine/frame.h>
77 1.1 cherry #include <machine/md_var.h>
78 1.1 cherry #include <machine/cpu.h>
79 1.1 cherry #include <machine/ia64_cpu.h>
80 1.1 cherry #include <machine/fpu.h>
81 1.1 cherry #ifdef DDB
82 1.1 cherry #include <machine/db_machdep.h>
83 1.1 cherry #include <ddb/db_extern.h>
84 1.1 cherry #endif
85 1.1 cherry
86 1.1 cherry #include <ia64/disasm/disasm.h>
87 1.1 cherry
88 1.1 cherry
89 1.1 cherry static const char *ia64_vector_names[] = {
90 1.1 cherry "VHPT Translation", /* 0 */
91 1.1 cherry "Instruction TLB", /* 1 */
92 1.1 cherry "Data TLB", /* 2 */
93 1.1 cherry "Alternate Instruction TLB", /* 3 */
94 1.1 cherry "Alternate Data TLB", /* 4 */
95 1.1 cherry "Data Nested TLB", /* 5 */
96 1.1 cherry "Instruction Key Miss", /* 6 */
97 1.1 cherry "Data Key Miss", /* 7 */
98 1.1 cherry "Dirty-Bit", /* 8 */
99 1.1 cherry "Instruction Access-Bit", /* 9 */
100 1.1 cherry "Data Access-Bit", /* 10 */
101 1.1 cherry "Break Instruction", /* 11 */
102 1.1 cherry "External Interrupt", /* 12 */
103 1.1 cherry "Reserved 13", /* 13 */
104 1.1 cherry "Reserved 14", /* 14 */
105 1.1 cherry "Reserved 15", /* 15 */
106 1.1 cherry "Reserved 16", /* 16 */
107 1.1 cherry "Reserved 17", /* 17 */
108 1.1 cherry "Reserved 18", /* 18 */
109 1.1 cherry "Reserved 19", /* 19 */
110 1.1 cherry "Page Not Present", /* 20 */
111 1.1 cherry "Key Permission", /* 21 */
112 1.1 cherry "Instruction Access Rights", /* 22 */
113 1.1 cherry "Data Access Rights", /* 23 */
114 1.1 cherry "General Exception", /* 24 */
115 1.1 cherry "Disabled FP-Register", /* 25 */
116 1.1 cherry "NaT Consumption", /* 26 */
117 1.1 cherry "Speculation", /* 27 */
118 1.1 cherry "Reserved 28", /* 28 */
119 1.1 cherry "Debug", /* 29 */
120 1.1 cherry "Unaligned Reference", /* 30 */
121 1.1 cherry "Unsupported Data Reference", /* 31 */
122 1.1 cherry "Floating-point Fault", /* 32 */
123 1.1 cherry "Floating-point Trap", /* 33 */
124 1.1 cherry "Lower-Privilege Transfer Trap", /* 34 */
125 1.1 cherry "Taken Branch Trap", /* 35 */
126 1.1 cherry "Single Step Trap", /* 36 */
127 1.1 cherry "Reserved 37", /* 37 */
128 1.1 cherry "Reserved 38", /* 38 */
129 1.1 cherry "Reserved 39", /* 39 */
130 1.1 cherry "Reserved 40", /* 40 */
131 1.1 cherry "Reserved 41", /* 41 */
132 1.1 cherry "Reserved 42", /* 42 */
133 1.1 cherry "Reserved 43", /* 43 */
134 1.1 cherry "Reserved 44", /* 44 */
135 1.1 cherry "IA-32 Exception", /* 45 */
136 1.1 cherry "IA-32 Intercept", /* 46 */
137 1.1 cherry "IA-32 Interrupt", /* 47 */
138 1.1 cherry "Reserved 48", /* 48 */
139 1.1 cherry "Reserved 49", /* 49 */
140 1.1 cherry "Reserved 50", /* 50 */
141 1.1 cherry "Reserved 51", /* 51 */
142 1.1 cherry "Reserved 52", /* 52 */
143 1.1 cherry "Reserved 53", /* 53 */
144 1.1 cherry "Reserved 54", /* 54 */
145 1.1 cherry "Reserved 55", /* 55 */
146 1.1 cherry "Reserved 56", /* 56 */
147 1.1 cherry "Reserved 57", /* 57 */
148 1.1 cherry "Reserved 58", /* 58 */
149 1.1 cherry "Reserved 59", /* 59 */
150 1.1 cherry "Reserved 60", /* 60 */
151 1.1 cherry "Reserved 61", /* 61 */
152 1.1 cherry "Reserved 62", /* 62 */
153 1.1 cherry "Reserved 63", /* 63 */
154 1.1 cherry "Reserved 64", /* 64 */
155 1.1 cherry "Reserved 65", /* 65 */
156 1.1 cherry "Reserved 66", /* 66 */
157 1.1 cherry "Reserved 67", /* 67 */
158 1.1 cherry };
159 1.1 cherry
160 1.1 cherry struct bitname {
161 1.1 cherry uint64_t mask;
162 1.1 cherry const char* name;
163 1.1 cherry };
164 1.1 cherry
165 1.1 cherry static void
166 1.1 cherry printbits(uint64_t mask, struct bitname *bn, int count)
167 1.1 cherry {
168 1.1 cherry int i, first = 1;
169 1.1 cherry uint64_t bit;
170 1.1 cherry
171 1.1 cherry for (i = 0; i < count; i++) {
172 1.1 cherry /*
173 1.1 cherry * Handle fields wider than one bit.
174 1.1 cherry */
175 1.1 cherry bit = bn[i].mask & ~(bn[i].mask - 1);
176 1.1 cherry if (bn[i].mask > bit) {
177 1.1 cherry if (first)
178 1.1 cherry first = 0;
179 1.1 cherry else
180 1.1 cherry printf(",");
181 1.1 cherry printf("%s=%ld", bn[i].name,
182 1.1 cherry (mask & bn[i].mask) / bit);
183 1.1 cherry } else if (mask & bit) {
184 1.1 cherry if (first)
185 1.1 cherry first = 0;
186 1.1 cherry else
187 1.1 cherry printf(",");
188 1.1 cherry printf("%s", bn[i].name);
189 1.1 cherry }
190 1.1 cherry }
191 1.1 cherry }
192 1.1 cherry
193 1.1 cherry struct bitname psr_bits[] = {
194 1.1 cherry {IA64_PSR_BE, "be"},
195 1.1 cherry {IA64_PSR_UP, "up"},
196 1.1 cherry {IA64_PSR_AC, "ac"},
197 1.1 cherry {IA64_PSR_MFL, "mfl"},
198 1.1 cherry {IA64_PSR_MFH, "mfh"},
199 1.1 cherry {IA64_PSR_IC, "ic"},
200 1.1 cherry {IA64_PSR_I, "i"},
201 1.1 cherry {IA64_PSR_PK, "pk"},
202 1.1 cherry {IA64_PSR_DT, "dt"},
203 1.1 cherry {IA64_PSR_DFL, "dfl"},
204 1.1 cherry {IA64_PSR_DFH, "dfh"},
205 1.1 cherry {IA64_PSR_SP, "sp"},
206 1.1 cherry {IA64_PSR_PP, "pp"},
207 1.1 cherry {IA64_PSR_DI, "di"},
208 1.1 cherry {IA64_PSR_SI, "si"},
209 1.1 cherry {IA64_PSR_DB, "db"},
210 1.1 cherry {IA64_PSR_LP, "lp"},
211 1.1 cherry {IA64_PSR_TB, "tb"},
212 1.1 cherry {IA64_PSR_RT, "rt"},
213 1.1 cherry {IA64_PSR_CPL, "cpl"},
214 1.1 cherry {IA64_PSR_IS, "is"},
215 1.1 cherry {IA64_PSR_MC, "mc"},
216 1.1 cherry {IA64_PSR_IT, "it"},
217 1.1 cherry {IA64_PSR_ID, "id"},
218 1.1 cherry {IA64_PSR_DA, "da"},
219 1.1 cherry {IA64_PSR_DD, "dd"},
220 1.1 cherry {IA64_PSR_SS, "ss"},
221 1.1 cherry {IA64_PSR_RI, "ri"},
222 1.1 cherry {IA64_PSR_ED, "ed"},
223 1.1 cherry {IA64_PSR_BN, "bn"},
224 1.1 cherry {IA64_PSR_IA, "ia"},
225 1.1 cherry };
226 1.1 cherry
227 1.1 cherry static void
228 1.1 cherry printpsr(uint64_t psr)
229 1.1 cherry {
230 1.1 cherry printbits(psr, psr_bits, sizeof(psr_bits)/sizeof(psr_bits[0]));
231 1.1 cherry }
232 1.1 cherry
233 1.1 cherry struct bitname isr_bits[] = {
234 1.1 cherry {IA64_ISR_CODE, "code"},
235 1.1 cherry {IA64_ISR_VECTOR, "vector"},
236 1.1 cherry {IA64_ISR_X, "x"},
237 1.1 cherry {IA64_ISR_W, "w"},
238 1.1 cherry {IA64_ISR_R, "r"},
239 1.1 cherry {IA64_ISR_NA, "na"},
240 1.1 cherry {IA64_ISR_SP, "sp"},
241 1.1 cherry {IA64_ISR_RS, "rs"},
242 1.1 cherry {IA64_ISR_IR, "ir"},
243 1.1 cherry {IA64_ISR_NI, "ni"},
244 1.1 cherry {IA64_ISR_SO, "so"},
245 1.1 cherry {IA64_ISR_EI, "ei"},
246 1.1 cherry {IA64_ISR_ED, "ed"},
247 1.1 cherry };
248 1.1 cherry
249 1.1 cherry static void printisr(uint64_t isr)
250 1.1 cherry {
251 1.1 cherry printbits(isr, isr_bits, sizeof(isr_bits)/sizeof(isr_bits[0]));
252 1.1 cherry }
253 1.1 cherry
254 1.1 cherry static void
255 1.1 cherry printtrap(int vector, struct trapframe *tf, int isfatal, int user)
256 1.1 cherry {
257 1.1 cherry
258 1.1 cherry printf("\n");
259 1.1 cherry printf("%s %s trap (cpu %lu):\n", isfatal? "fatal" : "handled",
260 1.1 cherry user ? "user" : "kernel", curcpu()->ci_cpuid);
261 1.1 cherry printf("\n");
262 1.1 cherry printf(" trap vector = 0x%x (%s)\n",
263 1.1 cherry vector, ia64_vector_names[vector]);
264 1.1 cherry printf(" cr.iip = 0x%lx\n", tf->tf_special.iip);
265 1.1 cherry printf(" cr.ipsr = 0x%lx (", tf->tf_special.psr);
266 1.1 cherry printpsr(tf->tf_special.psr);
267 1.1 cherry printf(")\n");
268 1.1 cherry printf(" cr.isr = 0x%lx (", tf->tf_special.isr);
269 1.1 cherry printisr(tf->tf_special.isr);
270 1.1 cherry printf(")\n");
271 1.1 cherry printf(" cr.ifa = 0x%lx\n", tf->tf_special.ifa);
272 1.1 cherry if (tf->tf_special.psr & IA64_PSR_IS) {
273 1.1 cherry printf(" ar.cflg = 0x%lx\n", ia64_get_cflg());
274 1.1 cherry printf(" ar.csd = 0x%lx\n", ia64_get_csd());
275 1.1 cherry printf(" ar.ssd = 0x%lx\n", ia64_get_ssd());
276 1.1 cherry }
277 1.1 cherry printf(" curlwp = %p\n", curlwp);
278 1.1 cherry if (curproc != NULL)
279 1.1 cherry printf(" pid = %d, comm = %s\n",
280 1.1 cherry curproc->p_pid, curproc->p_comm);
281 1.1 cherry printf("\n");
282 1.1 cherry }
283 1.1 cherry
284 1.1 cherry /*
285 1.1 cherry * We got a trap caused by a break instruction and the immediate was 0.
286 1.1 cherry * This indicates that we may have a break.b with some non-zero immediate.
287 1.1 cherry * The break.b doesn't cause the immediate to be put in cr.iim. Hence,
288 1.1 cherry * we need to disassemble the bundle and return the immediate found there.
289 1.1 cherry * This may be a 0 value anyway. Return 0 for any error condition. This
290 1.1 cherry * will result in a SIGILL, which is pretty much the best thing to do.
291 1.1 cherry */
292 1.1 cherry static uint64_t
293 1.1 cherry trap_decode_break(struct trapframe *tf)
294 1.1 cherry {
295 1.1 cherry struct asm_bundle bundle;
296 1.1 cherry struct asm_inst *inst;
297 1.1 cherry int slot;
298 1.1 cherry
299 1.1 cherry if (!asm_decode(tf->tf_special.iip, &bundle))
300 1.1 cherry return (0);
301 1.1 cherry
302 1.1 cherry slot = ((tf->tf_special.psr & IA64_PSR_RI) == IA64_PSR_RI_0) ? 0 :
303 1.1 cherry ((tf->tf_special.psr & IA64_PSR_RI) == IA64_PSR_RI_1) ? 1 : 2;
304 1.1 cherry inst = bundle.b_inst + slot;
305 1.1 cherry
306 1.1 cherry /*
307 1.1 cherry * Sanity checking: It must be a break instruction and the operand
308 1.1 cherry * that has the break value must be an immediate.
309 1.1 cherry */
310 1.1 cherry if (inst->i_op != ASM_OP_BREAK ||
311 1.1 cherry inst->i_oper[1].o_type != ASM_OPER_IMM)
312 1.1 cherry return (0);
313 1.1 cherry
314 1.1 cherry return (inst->i_oper[1].o_value);
315 1.1 cherry }
316 1.1 cherry
317 1.1 cherry
318 1.1 cherry /*
319 1.1 cherry * Start a new LWP
320 1.1 cherry */
321 1.1 cherry void
322 1.8 dsl startlwp(void *arg)
323 1.1 cherry {
324 1.1 cherry return;
325 1.1 cherry }
326 1.1 cherry
327 1.7 wrstuden void
328 1.7 wrstuden upcallret(struct lwp *l)
329 1.7 wrstuden {
330 1.7 wrstuden return;
331 1.7 wrstuden }
332 1.7 wrstuden
333 1.1 cherry #ifdef DDB
334 1.1 cherry int call_debugger = 1;
335 1.1 cherry
336 1.1 cherry /*
337 1.1 cherry * Enter the debugger due to a trap.
338 1.1 cherry */
339 1.1 cherry
340 1.1 cherry int
341 1.1 cherry ia64_trap(int type, int code, db_regs_t *regs)
342 1.1 cherry {
343 1.1 cherry
344 1.1 cherry /* XXX: Switch stacks ? */
345 1.1 cherry
346 1.1 cherry /* Debugger is not re-entrant. */
347 1.1 cherry
348 1.1 cherry ddb_regp = regs;
349 1.1 cherry db_trap(type, code);
350 1.1 cherry return 1; /* XXX: Always handled ??? */
351 1.1 cherry
352 1.1 cherry }
353 1.1 cherry
354 1.1 cherry #endif
355 1.1 cherry
356 1.1 cherry void
357 1.1 cherry trap_panic(int vector, struct trapframe *tf)
358 1.1 cherry {
359 1.1 cherry
360 1.1 cherry printtrap(vector, tf, 1, TRAPF_USERMODE(tf));
361 1.1 cherry
362 1.1 cherry #ifdef DDB
363 1.1 cherry if (ia64_trap(vector, 0, tf)) return;
364 1.1 cherry #endif
365 1.1 cherry panic("trap");
366 1.1 cherry
367 1.1 cherry return;
368 1.1 cherry }
369 1.1 cherry
370 1.1 cherry /*
371 1.1 cherry *
372 1.1 cherry */
373 1.1 cherry int
374 1.1 cherry do_ast(struct trapframe *tf)
375 1.1 cherry {
376 1.1 cherry return 0;
377 1.1 cherry }
378 1.1 cherry
379 1.1 cherry /*
380 1.1 cherry * Trap is called from exception.s to handle most types of processor traps.
381 1.1 cherry */
382 1.1 cherry /*ARGSUSED*/
383 1.1 cherry void
384 1.1 cherry trap(int vector, struct trapframe *tf)
385 1.1 cherry {
386 1.1 cherry
387 1.1 cherry struct proc *p;
388 1.1 cherry struct lwp *l;
389 1.1 cherry uint64_t ucode;
390 1.1 cherry int sig, user;
391 1.1 cherry u_int sticks;
392 1.1 cherry ksiginfo_t ksi;
393 1.1 cherry
394 1.1 cherry user = TRAPF_USERMODE(tf) ? 1 : 0;
395 1.1 cherry
396 1.1 cherry l = curlwp;
397 1.1 cherry
398 1.1 cherry ucode = 0;
399 1.1 cherry
400 1.1 cherry #if 0
401 1.1 cherry printtrap(vector, tf, 0, TRAPF_USERMODE(tf));
402 1.1 cherry #endif
403 1.1 cherry if (user) {
404 1.1 cherry ia64_set_fpsr(IA64_FPSR_DEFAULT);
405 1.4 mrg p = l->l_proc;
406 1.1 cherry sticks = p->p_sticks;
407 1.1 cherry l->l_md.md_tf = tf;
408 1.3 ad LWP_CACHE_CREDS(l, p);
409 1.1 cherry } else {
410 1.1 cherry sticks = 0; /* XXX bogus -Wuninitialized warning */
411 1.1 cherry p = NULL;
412 1.1 cherry }
413 1.1 cherry sig = 0;
414 1.1 cherry switch (vector) {
415 1.1 cherry case IA64_VEC_VHPT:
416 1.1 cherry /*
417 1.1 cherry * This one is tricky. We should hardwire the VHPT, but
418 1.1 cherry * don't at this time. I think we're mostly lucky that
419 1.1 cherry * the VHPT is mapped.
420 1.1 cherry */
421 1.1 cherry trap_panic(vector, tf);
422 1.1 cherry break;
423 1.1 cherry case IA64_VEC_ITLB:
424 1.1 cherry case IA64_VEC_DTLB:
425 1.1 cherry case IA64_VEC_EXT_INTR:
426 1.1 cherry /* We never call trap() with these vectors. */
427 1.1 cherry trap_panic(vector, tf);
428 1.1 cherry break;
429 1.1 cherry
430 1.1 cherry case IA64_VEC_ALT_ITLB:
431 1.1 cherry case IA64_VEC_ALT_DTLB:
432 1.1 cherry /*
433 1.1 cherry * These should never happen, because regions 0-4 use the
434 1.1 cherry * VHPT. If we get one of these it means we didn't program
435 1.1 cherry * the region registers correctly.
436 1.1 cherry */
437 1.1 cherry trap_panic(vector, tf);
438 1.1 cherry break;
439 1.1 cherry
440 1.1 cherry case IA64_VEC_NESTED_DTLB:
441 1.1 cherry /*
442 1.1 cherry * We never call trap() with this vector. We may want to
443 1.1 cherry * do that in the future in case the nested TLB handler
444 1.1 cherry * could not find the translation it needs. In that case
445 1.1 cherry * we could switch to a special (hardwired) stack and
446 1.1 cherry * come here to produce a nice panic().
447 1.1 cherry */
448 1.1 cherry trap_panic(vector, tf);
449 1.1 cherry break;
450 1.1 cherry
451 1.1 cherry case IA64_VEC_IKEY_MISS:
452 1.1 cherry case IA64_VEC_DKEY_MISS:
453 1.1 cherry case IA64_VEC_KEY_PERMISSION:
454 1.1 cherry /*
455 1.1 cherry * We don't use protection keys, so we should never get
456 1.1 cherry * these faults.
457 1.1 cherry */
458 1.1 cherry trap_panic(vector, tf);
459 1.1 cherry break;
460 1.1 cherry
461 1.1 cherry case IA64_VEC_DIRTY_BIT:
462 1.1 cherry case IA64_VEC_INST_ACCESS:
463 1.1 cherry case IA64_VEC_DATA_ACCESS:
464 1.1 cherry /*
465 1.1 cherry * We get here if we read or write to a page of which the
466 1.1 cherry * PTE does not have the access bit or dirty bit set and
467 1.1 cherry * we can not find the PTE in our datastructures. This
468 1.1 cherry * either means we have a stale PTE in the TLB, or we lost
469 1.1 cherry * the PTE in our datastructures.
470 1.1 cherry */
471 1.1 cherry trap_panic(vector, tf);
472 1.1 cherry break;
473 1.1 cherry
474 1.1 cherry case IA64_VEC_BREAK:
475 1.1 cherry if (user) {
476 1.1 cherry ucode = (int)tf->tf_special.ifa & 0x1FFFFF;
477 1.1 cherry if (ucode == 0) {
478 1.1 cherry /*
479 1.1 cherry * A break.b doesn't cause the immediate to be
480 1.1 cherry * stored in cr.iim (and saved in the TF in
481 1.1 cherry * tf_special.ifa). We need to decode the
482 1.1 cherry * instruction to find out what the immediate
483 1.1 cherry * was. Note that if the break instruction
484 1.1 cherry * didn't happen to be a break.b, but any
485 1.1 cherry * other break with an immediate of 0, we
486 1.1 cherry * will do unnecessary work to get the value
487 1.1 cherry * we already had. Not an issue, because a
488 1.1 cherry * break 0 is invalid.
489 1.1 cherry */
490 1.1 cherry ucode = trap_decode_break(tf);
491 1.1 cherry }
492 1.1 cherry if (ucode < 0x80000) {
493 1.1 cherry /* Software interrupts. */
494 1.1 cherry switch (ucode) {
495 1.1 cherry case 0: /* Unknown error. */
496 1.1 cherry sig = SIGILL;
497 1.1 cherry break;
498 1.1 cherry case 1: /* Integer divide by zero. */
499 1.1 cherry sig = SIGFPE;
500 1.1 cherry ucode = FPE_INTDIV;
501 1.1 cherry break;
502 1.1 cherry case 2: /* Integer overflow. */
503 1.1 cherry sig = SIGFPE;
504 1.1 cherry ucode = FPE_INTOVF;
505 1.1 cherry break;
506 1.1 cherry case 3: /* Range check/bounds check. */
507 1.1 cherry sig = SIGFPE;
508 1.1 cherry ucode = FPE_FLTSUB;
509 1.1 cherry break;
510 1.1 cherry case 6: /* Decimal overflow. */
511 1.1 cherry case 7: /* Decimal divide by zero. */
512 1.1 cherry case 8: /* Packed decimal error. */
513 1.1 cherry case 9: /* Invalid ASCII digit. */
514 1.1 cherry case 10: /* Invalid decimal digit. */
515 1.1 cherry sig = SIGFPE;
516 1.1 cherry ucode = FPE_FLTINV;
517 1.1 cherry break;
518 1.1 cherry case 4: /* Null pointer dereference. */
519 1.1 cherry case 5: /* Misaligned data. */
520 1.1 cherry case 11: /* Paragraph stack overflow. */
521 1.1 cherry sig = SIGSEGV;
522 1.1 cherry break;
523 1.1 cherry default:
524 1.1 cherry sig = SIGILL;
525 1.1 cherry break;
526 1.1 cherry }
527 1.1 cherry } else if (ucode < 0x100000) {
528 1.1 cherry /* Debugger breakpoint. */
529 1.1 cherry tf->tf_special.psr &= ~IA64_PSR_SS;
530 1.1 cherry sig = SIGTRAP;
531 1.1 cherry #if 0
532 1.1 cherry } else if (ucode == 0x100000) {
533 1.1 cherry break_syscall(tf);
534 1.1 cherry return; /* do_ast() already called. */
535 1.1 cherry
536 1.1 cherry } else if (ucode == 0x180000) {
537 1.1 cherry mcontext_t mc;
538 1.1 cherry
539 1.1 cherry error = copyin((void*)tf->tf_scratch.gr8,
540 1.1 cherry &mc, sizeof(mc));
541 1.1 cherry if (!error) {
542 1.1 cherry set_mcontext(td, &mc);
543 1.1 cherry return; /* Don't call do_ast()!!! */
544 1.1 cherry }
545 1.1 cherry sig = SIGSEGV;
546 1.1 cherry ucode = tf->tf_scratch.gr8;
547 1.1 cherry #endif
548 1.1 cherry } else
549 1.1 cherry sig = SIGILL;
550 1.1 cherry } else {
551 1.1 cherry trap_panic(vector, tf);
552 1.1 cherry goto out;
553 1.1 cherry }
554 1.1 cherry break;
555 1.1 cherry
556 1.1 cherry /* XXX: Fill in the rest */
557 1.1 cherry
558 1.1 cherry case IA64_VEC_DEBUG:
559 1.1 cherry case IA64_VEC_SINGLE_STEP_TRAP:
560 1.1 cherry tf->tf_special.psr &= ~IA64_PSR_SS;
561 1.1 cherry if (!user) {
562 1.1 cherry trap_panic(vector, tf);
563 1.1 cherry goto out;
564 1.1 cherry }
565 1.1 cherry sig = SIGTRAP;
566 1.1 cherry break;
567 1.1 cherry
568 1.1 cherry
569 1.1 cherry
570 1.1 cherry default:
571 1.1 cherry /* Reserved vectors get here. Should never happen of course. */
572 1.1 cherry trap_panic(vector, tf);
573 1.1 cherry break;
574 1.1 cherry }
575 1.1 cherry
576 1.1 cherry printf("sig = %d", sig);
577 1.1 cherry KASSERT(sig != 0);
578 1.1 cherry
579 1.1 cherry KSI_INIT(&ksi);
580 1.1 cherry ksi.ksi_signo = sig;
581 1.1 cherry ksi.ksi_code = ucode;
582 1.1 cherry trapsignal(l, &ksi);
583 1.1 cherry
584 1.1 cherry #if 1
585 1.1 cherry out:
586 1.1 cherry #endif
587 1.1 cherry
588 1.1 cherry if (user) {
589 1.1 cherry mi_userret(l);
590 1.1 cherry }
591 1.1 cherry
592 1.1 cherry
593 1.1 cherry return;
594 1.1 cherry }
595