1 /* $NetBSD: fault.c,v 1.29 2003/04/28 15:57:23 scw Exp $ */ 2 3 /* 4 * Copyright 2003 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Steve C. Woodford for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 /* 38 * Copyright (c) 1994-1997 Mark Brinicombe. 39 * Copyright (c) 1994 Brini. 40 * All rights reserved. 41 * 42 * This code is derived from software written for Brini by Mark Brinicombe 43 * 44 * Redistribution and use in source and binary forms, with or without 45 * modification, are permitted provided that the following conditions 46 * are met: 47 * 1. Redistributions of source code must retain the above copyright 48 * notice, this list of conditions and the following disclaimer. 49 * 2. Redistributions in binary form must reproduce the above copyright 50 * notice, this list of conditions and the following disclaimer in the 51 * documentation and/or other materials provided with the distribution. 52 * 3. All advertising materials mentioning features or use of this software 53 * must display the following acknowledgement: 54 * This product includes software developed by Brini. 55 * 4. The name of the company nor the name of the author may be used to 56 * endorse or promote products derived from this software without specific 57 * prior written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED 60 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 61 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 62 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 63 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 64 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 65 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 * SUCH DAMAGE. 70 * 71 * RiscBSD kernel project 72 * 73 * fault.c 74 * 75 * Fault handlers 76 * 77 * Created : 28/11/94 78 */ 79 80 #include "opt_ddb.h" 81 #include "opt_kgdb.h" 82 #include "opt_pmap_debug.h" 83 84 #include <sys/types.h> 85 __KERNEL_RCSID(0, "$NetBSD: fault.c,v 1.29 2003/04/28 15:57:23 scw Exp $"); 86 87 #include <sys/param.h> 88 #include <sys/systm.h> 89 #include <sys/proc.h> 90 #include <sys/user.h> 91 #include <sys/kernel.h> 92 93 #include <uvm/uvm_extern.h> 94 95 #include <arm/cpuconf.h> 96 97 #include <machine/frame.h> 98 #include <arm/arm32/katelib.h> 99 #include <machine/cpu.h> 100 #include <machine/intr.h> 101 #if defined(DDB) || defined(KGDB) 102 #include <machine/db_machdep.h> 103 #ifdef KGDB 104 #include <sys/kgdb.h> 105 #endif 106 #if !defined(DDB) 107 #define kdb_trap kgdb_trap 108 #endif 109 #endif 110 111 #include <arch/arm/arm/disassem.h> 112 #include <arm/arm32/machdep.h> 113 114 extern char fusubailout[]; 115 116 #ifdef DEBUG 117 int last_fault_code; /* For the benefit of pmap_fault_fixup() */ 118 #endif 119 120 static void report_abort __P((const char *, u_int, u_int, u_int)); 121 122 /* Abort code */ 123 124 /* Define text descriptions of the different aborts */ 125 126 static const char *aborts[16] = { 127 "Write buffer fault", 128 "Alignment fault", 129 "Write buffer fault", 130 "Alignment fault", 131 "Bus error (LF section)", 132 "Translation fault (section)", 133 "Bus error (page)", 134 "Translation fault (page)", 135 "Bus error (section)", 136 "Domain error (section)", 137 "Bus error (page)", 138 "Domain error (page)", 139 "Bus error trans (L1)", 140 "Permission error (section)", 141 "Bus error trans (L2)", 142 "Permission error (page)" 143 }; 144 145 static void 146 report_abort(prefix, fault_status, fault_address, fault_pc) 147 const char *prefix; 148 u_int fault_status; 149 u_int fault_address; 150 u_int fault_pc; 151 { 152 #ifndef DEBUG 153 if (prefix == NULL) { 154 #endif 155 if (prefix) 156 printf("%s ", prefix); 157 printf("Data abort: '%s' status=%03x address=%08x PC=%08x\n", 158 aborts[fault_status & FAULT_TYPE_MASK], 159 fault_status & 0xfff, fault_address, fault_pc); 160 #ifndef DEBUG 161 } 162 #endif 163 } 164 165 static __volatile int data_abort_expected; 166 static __volatile int data_abort_received; 167 168 int 169 badaddr_read(void *addr, size_t size, void *rptr) 170 { 171 u_long rcpt; 172 int rv; 173 174 /* Tell the Data Abort handler that we're expecting one. */ 175 data_abort_received = 0; 176 data_abort_expected = 1; 177 178 cpu_drain_writebuf(); 179 180 /* Read from the test address. */ 181 switch (size) { 182 case sizeof(uint8_t): 183 __asm __volatile("ldrb %0, [%1]" 184 : "=r" (rcpt) 185 : "r" (addr)); 186 break; 187 188 case sizeof(uint16_t): 189 __asm __volatile("ldrh %0, [%1]" 190 : "=r" (rcpt) 191 : "r" (addr)); 192 break; 193 194 case sizeof(uint32_t): 195 __asm __volatile("ldr %0, [%1]" 196 : "=r" (rcpt) 197 : "r" (addr)); 198 break; 199 200 default: 201 data_abort_expected = 0; 202 panic("badaddr: invalid size (%lu)", (u_long) size); 203 } 204 205 /* Disallow further Data Aborts. */ 206 data_abort_expected = 0; 207 208 rv = data_abort_received; 209 data_abort_received = 0; 210 211 /* Copy the data back if no fault occurred. */ 212 if (rptr != NULL && rv == 0) { 213 switch (size) { 214 case sizeof(uint8_t): 215 *(uint8_t *) rptr = rcpt; 216 break; 217 218 case sizeof(uint16_t): 219 *(uint16_t *) rptr = rcpt; 220 break; 221 222 case sizeof(uint32_t): 223 *(uint32_t *) rptr = rcpt; 224 break; 225 } 226 } 227 228 /* Return true if the address was invalid. */ 229 return (rv); 230 } 231 232 /* 233 * void data_abort_handler(trapframe_t *frame) 234 * 235 * Abort handler called when read/write occurs at an address of 236 * a non existent or restricted (access permissions) memory page. 237 * We first need to identify the type of page fault. 238 */ 239 240 #define TRAP_CODE ((fault_status & 0x0f) | (fault_address & 0xfffffff0)) 241 242 /* Determine if we can recover from a fault */ 243 #ifdef ARM32_PMAP_NEW 244 #define IS_FATAL_FAULT(x) \ 245 (((1 << (x)) & \ 246 ((1 << FAULT_WRTBUF_0) | (1 << FAULT_WRTBUF_1) | \ 247 (1 << FAULT_BUSERR_0) | (1 << FAULT_BUSERR_1) | \ 248 (1 << FAULT_BUSERR_2) | (1 << FAULT_BUSERR_3) | \ 249 (1 << FAULT_BUSTRNL1) | (1 << FAULT_BUSTRNL2) | \ 250 (1 << FAULT_ALIGN_0) | (1 << FAULT_ALIGN_1))) != 0) 251 #else 252 #define IS_FATAL_FAULT(x) \ 253 (((1 << (x)) & \ 254 ((1 << FAULT_WRTBUF_0) | (1 << FAULT_WRTBUF_1) | \ 255 (1 << FAULT_BUSERR_0) | (1 << FAULT_BUSERR_1) | \ 256 (1 << FAULT_BUSERR_2) | (1 << FAULT_BUSERR_3) | \ 257 (1 << FAULT_BUSTRNL1) | (1 << FAULT_BUSTRNL2) | \ 258 (1 << FAULT_DOMAIN_S) | (1 << FAULT_DOMAIN_P) | \ 259 (1 << FAULT_ALIGN_0) | (1 << FAULT_ALIGN_1))) != 0) 260 #endif 261 262 void 263 data_abort_handler(frame) 264 trapframe_t *frame; 265 { 266 struct lwp *l; 267 struct proc *p; 268 struct pcb *pcb; 269 u_int fault_address; 270 u_int fault_status; 271 u_int fault_pc; 272 u_int fault_instruction; 273 int fault_code, fatal_fault; 274 int user; 275 int error; 276 int rv; 277 void *onfault; 278 vaddr_t va; 279 struct vmspace *vm; 280 struct vm_map *map; 281 vm_prot_t ftype; 282 extern struct vm_map *kernel_map; 283 284 /* 285 * If we were expecting a Data Abort, signal that we got 286 * one, adjust the PC to skip the faulting insn, and 287 * return. 288 */ 289 if (data_abort_expected) { 290 data_abort_received = 1; 291 frame->tf_pc += INSN_SIZE; 292 return; 293 } 294 295 /* 296 * Must get fault address and status from the CPU before 297 * re-enabling interrupts. (Interrupt handlers may take 298 * R/M emulation faults.) 299 */ 300 fault_address = cpu_faultaddress(); 301 fault_status = cpu_faultstatus(); 302 fault_pc = frame->tf_pc; 303 304 /* 305 * Enable IRQ's (disabled by CPU on abort) if trapframe 306 * shows they were enabled. 307 */ 308 if (!(frame->tf_spsr & I32_bit)) 309 enable_interrupts(I32_bit); 310 311 #ifdef DEBUG 312 if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE) 313 panic("data_abort_handler: not in SVC32 mode"); 314 #endif 315 316 /* Update vmmeter statistics */ 317 uvmexp.traps++; 318 319 /* Extract the fault code from the fault status */ 320 fault_code = fault_status & FAULT_TYPE_MASK; 321 fatal_fault = IS_FATAL_FAULT(fault_code); 322 323 /* Get the current lwp structure or lwp0 if there is none */ 324 l = curlwp == NULL ? &lwp0 : curlwp; 325 p = l->l_proc; 326 327 /* 328 * can't use curpcb, as it might be NULL; and we have p in 329 * a register anyway 330 */ 331 pcb = &l->l_addr->u_pcb; 332 333 /* fusubailout is used by [fs]uswintr to avoid page faulting */ 334 if (pcb->pcb_onfault && 335 (fatal_fault || pcb->pcb_onfault == fusubailout)) { 336 337 frame->tf_r0 = EFAULT; 338 copyfault: 339 #ifdef DEBUG 340 printf("Using pcb_onfault=%p addr=%08x st=%08x l=%p\n", 341 pcb->pcb_onfault, fault_address, fault_status, l); 342 #endif 343 frame->tf_pc = (u_int)pcb->pcb_onfault; 344 if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) 345 panic("Yikes pcb_onfault=%p during USR mode fault", 346 pcb->pcb_onfault); 347 return; 348 } 349 350 /* More debug stuff */ 351 352 fault_instruction = ReadWord(fault_pc); 353 354 #ifdef PMAP_DEBUG 355 if (pmap_debug_level >= 0) { 356 report_abort(NULL, fault_status, fault_address, fault_pc); 357 printf("Instruction @V%08x = %08x\n", 358 fault_pc, fault_instruction); 359 } 360 #endif 361 362 /* Call the cpu specific abort fixup routine */ 363 error = cpu_dataabt_fixup(frame); 364 if (error == ABORT_FIXUP_RETURN) 365 return; 366 if (error == ABORT_FIXUP_FAILED) { 367 printf("pc = 0x%08x, opcode 0x%08x, insn = ", fault_pc, *((u_int *)fault_pc)); 368 disassemble(fault_pc); 369 printf("data abort handler: fixup failed for this instruction\n"); 370 } 371 372 #ifdef PMAP_DEBUG 373 if (pmap_debug_level >= 0) 374 printf("fault in process %p\n", p); 375 #endif 376 377 #ifdef DEBUG 378 /* Is this needed ? (XXXSCW: yes. can happen during boot ...) */ 379 if (!cold && pcb != curpcb) { 380 printf("data_abort: Alert ! pcb(%p) != curpcb(%p)\n", 381 pcb, curpcb); 382 printf("data_abort: Alert ! proc(%p), curlwp(%p)\n", 383 p, curlwp); 384 } 385 #endif /* DEBUG */ 386 387 /* Were we in user mode when the abort occurred ? */ 388 if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) { 389 /* 390 * Note that the fault was from USR mode. 391 */ 392 user = 1; 393 l->l_addr->u_pcb.pcb_tf = frame; 394 } else 395 user = 0; 396 397 /* check if this was a failed fixup */ 398 if (error == ABORT_FIXUP_FAILED) { 399 if (user) { 400 trapsignal(l, SIGSEGV, TRAP_CODE); 401 userret(l); 402 return; 403 }; 404 panic("Data abort fixup failed in kernel - we're dead"); 405 }; 406 407 /* Now act on the fault type */ 408 if (fatal_fault) { 409 /* 410 * None of these faults should happen on a perfectly 411 * functioning system. They indicate either some gross 412 * problem with the kernel, or a hardware problem. 413 * In either case, stop. 414 */ 415 report_abort(NULL, fault_status, fault_address, fault_pc); 416 417 we_re_toast: 418 /* 419 * Were are dead, try and provide some debug 420 * information before dying. 421 */ 422 #if defined(DDB) || defined(KGDB) 423 printf("Unhandled trap (frame = %p)\n", frame); 424 report_abort(NULL, fault_status, fault_address, fault_pc); 425 kdb_trap(-1, frame); 426 return; 427 #else 428 panic("Unhandled trap (frame = %p)", frame); 429 #endif /* DDB || KGDB */ 430 } 431 432 /* 433 * At this point, we're dealing with one of the following faults: 434 * 435 * FAULT_TRANS_P Page Translation Fault 436 * FAULT_PERM_P Page Permission Fault 437 * FAULT_TRANS_S Section Translation Fault 438 * FAULT_PERM_S Section Permission Fault 439 * 440 * And if ARM32_PMAP_NEW is in effect: 441 * 442 * FAULT_DOMAIN_P Page Domain Error Fault 443 * FAULT_DOMAIN_S Section Domain Error Fault 444 * 445 * Page/section translation/permission fault -- need to fault in 446 * the page. 447 * 448 * Page/section domain fault -- need to see if the L1 entry can 449 * be fixed up. 450 */ 451 vm = p->p_vmspace; 452 va = trunc_page((vaddr_t)fault_address); 453 454 #ifdef PMAP_DEBUG 455 if (pmap_debug_level >= 0) 456 printf("page fault: addr=V%08lx ", va); 457 #endif 458 459 /* 460 * It is only a kernel address space fault iff: 461 * 1. user == 0 and 462 * 2. pcb_onfault not set or 463 * 3. pcb_onfault set but supervisor space fault 464 * The last can occur during an exec() copyin where the 465 * argument space is lazy-allocated. 466 */ 467 if (!user && 468 (va >= VM_MIN_KERNEL_ADDRESS || va < VM_MIN_ADDRESS)) { 469 /* Was the fault due to the FPE/IPKDB ? */ 470 if ((frame->tf_spsr & PSR_MODE) == PSR_UND32_MODE) { 471 report_abort("UND32", fault_status, 472 fault_address, fault_pc); 473 trapsignal(l, SIGSEGV, TRAP_CODE); 474 475 /* 476 * Force exit via userret() 477 * This is necessary as the FPE is an extension 478 * to userland that actually runs in a 479 * priveledged mode but uses USR mode 480 * permissions for its accesses. 481 */ 482 userret(l); 483 return; 484 } 485 map = kernel_map; 486 } else 487 map = &vm->vm_map; 488 489 #ifdef PMAP_DEBUG 490 if (pmap_debug_level >= 0) 491 printf("vmmap=%p ", map); 492 #endif 493 494 if (map == NULL) 495 printf("No map for fault address va = 0x%08lx", va); 496 497 /* 498 * We need to know whether the page should be mapped 499 * as R or R/W. The MMU does not give us the info as 500 * to whether the fault was caused by a read or a write. 501 * This means we need to disassemble the instruction 502 * responsible and determine if it was a read or write 503 * instruction. 504 */ 505 /* STR instruction ? */ 506 if ((fault_instruction & 0x0c100000) == 0x04000000) 507 ftype = VM_PROT_WRITE; 508 /* STM or CDT instruction ? */ 509 else if ((fault_instruction & 0x0a100000) == 0x08000000) 510 ftype = VM_PROT_WRITE; 511 /* STRH, STRSH or STRSB instruction ? */ 512 else if ((fault_instruction & 0x0e100090) == 0x00000090) 513 ftype = VM_PROT_WRITE; 514 /* SWP instruction ? */ 515 else if ((fault_instruction & 0x0fb00ff0) == 0x01000090) 516 ftype = VM_PROT_READ | VM_PROT_WRITE; 517 else 518 ftype = VM_PROT_READ; 519 520 #ifdef PMAP_DEBUG 521 if (pmap_debug_level >= 0) 522 printf("fault protection = %d\n", ftype); 523 #endif 524 525 #ifndef ARM32_PMAP_NEW 526 if ((ftype & VM_PROT_WRITE) ? 527 pmap_modified_emulation(map->pmap, va) : 528 pmap_handled_emulation(map->pmap, va)) 529 goto out; 530 #else 531 if (pmap_fault_fixup(map->pmap, va, ftype, user)) 532 goto out; 533 #endif 534 535 if (current_intr_depth > 0) { 536 #if defined(DDB) || defined(KGDB) 537 printf("Non-emulated page fault with intr_depth > 0\n"); 538 report_abort(NULL, fault_status, fault_address, fault_pc); 539 kdb_trap(-1, frame); 540 return; 541 #else 542 panic("Fault with intr_depth > 0"); 543 #endif /* DDB */ 544 } 545 546 onfault = pcb->pcb_onfault; 547 pcb->pcb_onfault = NULL; 548 rv = uvm_fault(map, va, 0, ftype); 549 pcb->pcb_onfault = onfault; 550 if (rv == 0) { 551 if (user != 0) /* Record any stack growth... */ 552 uvm_grow(p, trunc_page(va)); 553 goto out; 554 } 555 if (user == 0) { 556 if (pcb->pcb_onfault) { 557 frame->tf_r0 = rv; 558 goto copyfault; 559 } 560 printf("[u]vm_fault(%p, %lx, %x, 0) -> %x\n", map, va, ftype, 561 rv); 562 goto we_re_toast; 563 } 564 565 report_abort("", fault_status, fault_address, fault_pc); 566 if (rv == ENOMEM) { 567 printf("UVM: pid %d (%s), uid %d killed: " 568 "out of swap\n", p->p_pid, p->p_comm, 569 (p->p_cred && p->p_ucred) ? p->p_ucred->cr_uid : -1); 570 trapsignal(l, SIGKILL, TRAP_CODE); 571 } else 572 trapsignal(l, SIGSEGV, TRAP_CODE); 573 574 out: 575 /* Call userret() if it was a USR mode fault */ 576 if (user) 577 userret(l); 578 } 579 580 581 /* 582 * void prefetch_abort_handler(trapframe_t *frame) 583 * 584 * Abort handler called when instruction execution occurs at 585 * a non existent or restricted (access permissions) memory page. 586 * If the address is invalid and we were in SVC mode then panic as 587 * the kernel should never prefetch abort. 588 * If the address is invalid and the page is mapped then the user process 589 * does no have read permission so send it a signal. 590 * Otherwise fault the page in and try again. 591 */ 592 593 void 594 prefetch_abort_handler(frame) 595 trapframe_t *frame; 596 { 597 struct lwp *l; 598 struct proc *p; 599 struct vm_map *map; 600 vaddr_t fault_pc, va; 601 int error; 602 603 /* 604 * Enable IRQ's (disabled by the abort) This always comes 605 * from user mode so we know interrupts were not disabled. 606 * But we check anyway. 607 */ 608 if (!(frame->tf_spsr & I32_bit)) 609 enable_interrupts(I32_bit); 610 611 #ifdef DEBUG 612 if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE) 613 panic("prefetch_abort_handler: not in SVC32 mode"); 614 #endif 615 616 /* Update vmmeter statistics */ 617 uvmexp.traps++; 618 619 /* Call the cpu specific abort fixup routine */ 620 error = cpu_prefetchabt_fixup(frame); 621 if (error == ABORT_FIXUP_RETURN) 622 return; 623 if (error == ABORT_FIXUP_FAILED) 624 panic("prefetch abort fixup failed"); 625 626 /* Get the current proc structure or proc0 if there is none */ 627 if ((l = curlwp) == NULL) { 628 l = &lwp0; 629 #ifdef DEBUG 630 printf("Prefetch abort with curlwp == 0\n"); 631 #endif 632 } 633 p = l->l_proc; 634 635 #ifdef PMAP_DEBUG 636 if (pmap_debug_level >= 0) 637 printf("prefetch fault in process %p %s\n", p, p->p_comm); 638 #endif 639 640 /* Get fault address */ 641 fault_pc = frame->tf_pc; 642 va = trunc_page(fault_pc); 643 644 /* Was the prefectch abort from USR32 mode ? */ 645 if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) { 646 l->l_addr->u_pcb.pcb_tf = frame; 647 } else { 648 /* 649 * All the kernel code pages are loaded at boot time 650 * and do not get paged 651 */ 652 panic("Prefetch abort in non-USR mode (frame=%p PC=0x%08lx)", 653 frame, fault_pc); 654 } 655 656 map = &p->p_vmspace->vm_map; 657 658 #ifdef PMAP_DEBUG 659 if (pmap_debug_level >= 0) 660 printf("prefetch_abort: PC = %08lx\n", fault_pc); 661 #endif 662 /* Ok validate the address, can only execute in USER space */ 663 if (fault_pc < VM_MIN_ADDRESS || fault_pc >= VM_MAXUSER_ADDRESS) { 664 #ifdef DEBUG 665 printf("prefetch: pc (%08lx) not in user process space\n", 666 fault_pc); 667 #endif 668 trapsignal(l, SIGSEGV, fault_pc); 669 userret(l); 670 return; 671 } 672 673 #ifndef ARM32_PMAP_NEW 674 #ifdef CPU_SA110 675 /* 676 * There are bugs in the rev K SA110. This is a check for one 677 * of them. 678 */ 679 if (curcpu()->ci_arm_cputype == CPU_ID_SA110 && 680 curcpu()->ci_arm_cpurev < 3) { 681 /* Always current pmap */ 682 pt_entry_t *pte = vtopte((vaddr_t) fault_pc); 683 struct pmap *pmap = p->p_vmspace->vm_map.pmap; 684 685 if (pmap_pde_v(pmap_pde(pmap, (vaddr_t) fault_pc)) && 686 pmap_pte_v(pte)) { 687 extern int kernel_debug; 688 if (kernel_debug & 1) { 689 printf("prefetch_abort: page is already " 690 "mapped - pte=%p *pte=%08x\n", pte, *pte); 691 printf("prefetch_abort: pc=%08lx proc=%p " 692 "process=%s\n", fault_pc, p, p->p_comm); 693 printf("prefetch_abort: far=%08x fs=%x\n", 694 cpu_faultaddress(), cpu_faultstatus()); 695 printf("prefetch_abort: trapframe=%08x\n", 696 (u_int)frame); 697 } 698 #ifdef DDB 699 if (kernel_debug & 2) 700 Debugger(); 701 #endif 702 } 703 } 704 #endif /* CPU_SA110 */ 705 706 if (pmap_handled_emulation(map->pmap, va)) 707 goto out; 708 709 #else /* ARM32_PMAP_NEW */ 710 711 /* 712 * See if the pmap can handle this fault on its own... 713 */ 714 if (pmap_fault_fixup(map->pmap, va, VM_PROT_READ, 1)) 715 goto out; 716 #endif 717 718 if (current_intr_depth > 0) { 719 #ifdef DDB 720 printf("Non-emulated prefetch abort with intr_depth > 0\n"); 721 kdb_trap(-1, frame); 722 return; 723 #else 724 panic("Prefetch Abort with intr_depth > 0"); 725 #endif 726 } 727 728 error = uvm_fault(map, va, 0, VM_PROT_READ); 729 if (error == 0) 730 goto out; 731 732 if (error == ENOMEM) { 733 printf("UVM: pid %d (%s), uid %d killed: " 734 "out of swap\n", p->p_pid, p->p_comm, 735 (p->p_cred && p->p_ucred) ? p->p_ucred->cr_uid : -1); 736 trapsignal(l, SIGKILL, fault_pc); 737 } else 738 trapsignal(l, SIGSEGV, fault_pc); 739 out: 740 userret(l); 741 } 742