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