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