fault.c revision 1.34 1 /* $NetBSD: fault.c,v 1.34 2003/10/05 19:44:58 matt 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.34 2003/10/05 19:44:58 matt Exp $");
86
87 #include <sys/param.h>
88 #include <sys/systm.h>
89 #include <sys/proc.h>
90 #include <sys/savar.h>
91 #include <sys/user.h>
92 #include <sys/kernel.h>
93
94 #include <uvm/uvm_extern.h>
95
96 #include <arm/cpuconf.h>
97
98 #include <machine/frame.h>
99 #include <arm/arm32/katelib.h>
100 #include <machine/cpu.h>
101 #include <machine/intr.h>
102 #if defined(DDB) || defined(KGDB)
103 #include <machine/db_machdep.h>
104 #ifdef KGDB
105 #include <sys/kgdb.h>
106 #endif
107 #if !defined(DDB)
108 #define kdb_trap kgdb_trap
109 #endif
110 #endif
111
112 #include <arch/arm/arm/disassem.h>
113 #include <arm/arm32/machdep.h>
114
115 extern char fusubailout[];
116
117 #ifdef DEBUG
118 int last_fault_code; /* For the benefit of pmap_fault_fixup() */
119 #endif
120
121 static void report_abort __P((const char *, u_int, u_int, u_int));
122
123 /* Abort code */
124
125 /* Define text descriptions of the different aborts */
126
127 static const char *aborts[16] = {
128 "Write buffer fault",
129 "Alignment fault",
130 "Write buffer fault",
131 "Alignment fault",
132 "Bus error (LF section)",
133 "Translation fault (section)",
134 "Bus error (page)",
135 "Translation fault (page)",
136 "Bus error (section)",
137 "Domain error (section)",
138 "Bus error (page)",
139 "Domain error (page)",
140 "Bus error trans (L1)",
141 "Permission error (section)",
142 "Bus error trans (L2)",
143 "Permission error (page)"
144 };
145
146 static void
147 report_abort(prefix, fault_status, fault_address, fault_pc)
148 const char *prefix;
149 u_int fault_status;
150 u_int fault_address;
151 u_int fault_pc;
152 {
153 #ifndef DEBUG
154 if (prefix == NULL) {
155 #endif
156 if (prefix)
157 printf("%s ", prefix);
158 printf("Data abort: '%s' status=%03x address=%08x PC=%08x\n",
159 aborts[fault_status & FAULT_TYPE_MASK],
160 fault_status & 0xfff, fault_address, fault_pc);
161 #ifndef DEBUG
162 }
163 #endif
164 }
165
166 static __volatile int data_abort_expected;
167 static __volatile int data_abort_received;
168
169 int
170 badaddr_read(void *addr, size_t size, void *rptr)
171 {
172 u_long rcpt;
173 int rv;
174
175 /* Tell the Data Abort handler that we're expecting one. */
176 data_abort_received = 0;
177 data_abort_expected = 1;
178
179 cpu_drain_writebuf();
180
181 /* Read from the test address. */
182 switch (size) {
183 case sizeof(uint8_t):
184 __asm __volatile("ldrb %0, [%1]"
185 : "=r" (rcpt)
186 : "r" (addr));
187 break;
188
189 case sizeof(uint16_t):
190 __asm __volatile("ldrh %0, [%1]"
191 : "=r" (rcpt)
192 : "r" (addr));
193 break;
194
195 case sizeof(uint32_t):
196 __asm __volatile("ldr %0, [%1]"
197 : "=r" (rcpt)
198 : "r" (addr));
199 break;
200
201 default:
202 data_abort_expected = 0;
203 panic("badaddr: invalid size (%lu)", (u_long) size);
204 }
205
206 /* Disallow further Data Aborts. */
207 data_abort_expected = 0;
208
209 rv = data_abort_received;
210 data_abort_received = 0;
211
212 /* Copy the data back if no fault occurred. */
213 if (rptr != NULL && rv == 0) {
214 switch (size) {
215 case sizeof(uint8_t):
216 *(uint8_t *) rptr = rcpt;
217 break;
218
219 case sizeof(uint16_t):
220 *(uint16_t *) rptr = rcpt;
221 break;
222
223 case sizeof(uint32_t):
224 *(uint32_t *) rptr = rcpt;
225 break;
226 }
227 }
228
229 /* Return true if the address was invalid. */
230 return (rv);
231 }
232
233 /*
234 * void data_abort_handler(trapframe_t *frame)
235 *
236 * Abort handler called when read/write occurs at an address of
237 * a non existent or restricted (access permissions) memory page.
238 * We first need to identify the type of page fault.
239 */
240
241 #define TRAP_CODE ((fault_status & 0x0f) | (fault_address & 0xfffffff0))
242
243 /* Determine if we can recover from a fault */
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
252 void
253 data_abort_handler(frame)
254 trapframe_t *frame;
255 {
256 struct lwp *l;
257 struct proc *p;
258 struct pcb *pcb;
259 u_int fault_address;
260 u_int fault_status;
261 u_int fault_pc;
262 u_int fault_instruction;
263 int fault_code, fatal_fault;
264 int user;
265 int error;
266 int rv;
267 void *onfault;
268 vaddr_t va;
269 struct vmspace *vm;
270 struct vm_map *map;
271 vm_prot_t ftype;
272 extern struct vm_map *kernel_map;
273 ksiginfo_t ksi;
274
275 /*
276 * If we were expecting a Data Abort, signal that we got
277 * one, adjust the PC to skip the faulting insn, and
278 * return.
279 */
280 if (data_abort_expected) {
281 data_abort_received = 1;
282 frame->tf_pc += INSN_SIZE;
283 return;
284 }
285
286 /*
287 * Must get fault address and status from the CPU before
288 * re-enabling interrupts. (Interrupt handlers may take
289 * R/M emulation faults.)
290 */
291 fault_address = cpu_faultaddress();
292 fault_status = cpu_faultstatus();
293 fault_pc = frame->tf_pc;
294
295 /*
296 * Enable IRQ's (disabled by CPU on abort) if trapframe
297 * shows they were enabled.
298 */
299 if (!(frame->tf_spsr & I32_bit))
300 enable_interrupts(I32_bit);
301
302 #ifdef DEBUG
303 if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE)
304 panic("data_abort_handler: not in SVC32 mode");
305 #endif
306
307 /* Update vmmeter statistics */
308 uvmexp.traps++;
309
310 /* Extract the fault code from the fault status */
311 fault_code = fault_status & FAULT_TYPE_MASK;
312 fatal_fault = IS_FATAL_FAULT(fault_code);
313
314 /* Get the current lwp structure or lwp0 if there is none */
315 l = curlwp == NULL ? &lwp0 : curlwp;
316 p = l->l_proc;
317
318 /*
319 * can't use curpcb, as it might be NULL; and we have p in
320 * a register anyway
321 */
322 pcb = &l->l_addr->u_pcb;
323
324 /* fusubailout is used by [fs]uswintr to avoid page faulting */
325 if (pcb->pcb_onfault &&
326 (fatal_fault || pcb->pcb_onfault == fusubailout)) {
327
328 frame->tf_r0 = EFAULT;
329 copyfault:
330 #ifdef DEBUG
331 printf("Using pcb_onfault=%p addr=%08x st=%08x l=%p\n",
332 pcb->pcb_onfault, fault_address, fault_status, l);
333 #endif
334 frame->tf_pc = (u_int)pcb->pcb_onfault;
335 if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE)
336 panic("Yikes pcb_onfault=%p during USR mode fault",
337 pcb->pcb_onfault);
338 return;
339 }
340
341 /* More debug stuff */
342
343 fault_instruction = ReadWord(fault_pc);
344
345 #ifdef PMAP_DEBUG
346 if (pmap_debug_level >= 0) {
347 report_abort(NULL, fault_status, fault_address, fault_pc);
348 printf("Instruction @V%08x = %08x\n",
349 fault_pc, fault_instruction);
350 }
351 #endif
352
353 /* Call the cpu specific abort fixup routine */
354 error = cpu_dataabt_fixup(frame);
355 if (error == ABORT_FIXUP_RETURN)
356 return;
357 if (error == ABORT_FIXUP_FAILED) {
358 printf("pc = 0x%08x, opcode 0x%08x, insn = ", fault_pc, *((u_int *)fault_pc));
359 disassemble(fault_pc);
360 printf("data abort handler: fixup failed for this instruction\n");
361 }
362
363 #ifdef PMAP_DEBUG
364 if (pmap_debug_level >= 0)
365 printf("fault in process %p\n", p);
366 #endif
367
368 #ifdef DEBUG
369 /* Is this needed ? (XXXSCW: yes. can happen during boot ...) */
370 if (!cold && pcb != curpcb) {
371 printf("data_abort: Alert ! pcb(%p) != curpcb(%p)\n",
372 pcb, curpcb);
373 printf("data_abort: Alert ! proc(%p), curlwp(%p)\n",
374 p, curlwp);
375 }
376 #endif /* DEBUG */
377
378 /* Were we in user mode when the abort occurred ? */
379 if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) {
380 /*
381 * Note that the fault was from USR mode.
382 */
383 user = 1;
384 l->l_addr->u_pcb.pcb_tf = frame;
385 } else
386 user = 0;
387
388 /* check if this was a failed fixup */
389 if (error == ABORT_FIXUP_FAILED) {
390 if (user) {
391 (void)memset(&ksi, 0, sizeof(ksi));
392 ksi.ksi_signo = SIGSEGV;
393 ksi.ksi_code = 0;
394 ksi.ksi_addr = (u_int32_t *)fault_address;
395 ksi.ksi_trap = TRAP_CODE;
396 ksi.ksi_errno = error;
397 goto trapsignal;
398 };
399 panic("Data abort fixup failed in kernel - we're dead");
400 };
401
402 /* Now act on the fault type */
403 if (fatal_fault) {
404 /*
405 * None of these faults should happen on a perfectly
406 * functioning system. They indicate either some gross
407 * problem with the kernel, or a hardware problem.
408 * In either case, stop.
409 */
410 report_abort(NULL, fault_status, fault_address, fault_pc);
411
412 we_re_toast:
413 /*
414 * We're are dead, try and provide some debug
415 * information before dying.
416 */
417 #if defined(DDB) || defined(KGDB)
418 printf("Unhandled trap (frame = %p)\n", frame);
419 report_abort(NULL, fault_status, fault_address, fault_pc);
420 kdb_trap(T_FAULT, frame);
421 return;
422 #else
423 panic("Unhandled trap (frame = %p)", frame);
424 #endif /* DDB || KGDB */
425 }
426
427 /*
428 * At this point, we're dealing with one of the following faults:
429 *
430 * FAULT_TRANS_P Page Translation Fault
431 * FAULT_PERM_P Page Permission Fault
432 * FAULT_TRANS_S Section Translation Fault
433 * FAULT_PERM_S Section Permission Fault
434 * FAULT_DOMAIN_P Page Domain Error Fault
435 * FAULT_DOMAIN_S Section Domain Error Fault
436 *
437 * Page/section translation/permission fault -- need to fault in
438 * the page.
439 *
440 * Page/section domain fault -- need to see if the L1 entry can
441 * be fixed up.
442 */
443 vm = p->p_vmspace;
444 va = trunc_page((vaddr_t)fault_address);
445
446 #ifdef PMAP_DEBUG
447 if (pmap_debug_level >= 0)
448 printf("page fault: addr=V%08lx ", va);
449 #endif
450
451 /*
452 * It is only a kernel address space fault iff:
453 * 1. user == 0 and
454 * 2. pcb_onfault not set or
455 * 3. pcb_onfault set but supervisor space fault
456 * The last can occur during an exec() copyin where the
457 * argument space is lazy-allocated.
458 */
459 if (!user &&
460 (va >= VM_MIN_KERNEL_ADDRESS || va < VM_MIN_ADDRESS)) {
461 /* Was the fault due to the FPE/IPKDB ? */
462 if ((frame->tf_spsr & PSR_MODE) == PSR_UND32_MODE) {
463 report_abort("UND32", fault_status,
464 fault_address, fault_pc);
465 (void)memset(&ksi, 0, sizeof(ksi));
466 ksi.ksi_signo = SIGSEGV;
467 ksi.ksi_code = fault_status;
468 ksi.ksi_addr = (u_int32_t *)fault_address;
469 ksi.ksi_trap = TRAP_CODE;
470 KERNEL_PROC_LOCK(p);
471 trapsignal(l, &ksi);
472 KERNEL_PROC_UNLOCK(p);
473
474 /*
475 * Force exit via userret()
476 * This is necessary as the FPE is an extension
477 * to userland that actually runs in a
478 * priveledged mode but uses USR mode
479 * permissions for its accesses.
480 */
481 userret(l);
482 return;
483 }
484 map = kernel_map;
485 } else {
486 map = &vm->vm_map;
487 if (l->l_flag & L_SA) {
488 KDASSERT(p != NULL && p->p_sa != NULL);
489 p->p_sa->sa_vp_faultaddr = (vaddr_t)fault_address;
490 l->l_flag |= L_SA_PAGEFAULT;
491 }
492 }
493
494 #ifdef PMAP_DEBUG
495 if (pmap_debug_level >= 0)
496 printf("vmmap=%p ", map);
497 #endif
498
499 if (map == NULL)
500 printf("No map for fault address va = 0x%08lx", va);
501
502 /*
503 * We need to know whether the page should be mapped
504 * as R or R/W. The MMU does not give us the info as
505 * to whether the fault was caused by a read or a write.
506 * This means we need to disassemble the instruction
507 * responsible and determine if it was a read or write
508 * instruction.
509 */
510 /* STR instruction ? */
511 if ((fault_instruction & 0x0c100000) == 0x04000000)
512 ftype = VM_PROT_WRITE;
513 /* STM or CDT instruction ? */
514 else if ((fault_instruction & 0x0a100000) == 0x08000000)
515 ftype = VM_PROT_WRITE;
516 /* STRH, STRSH or STRSB instruction ? */
517 else if ((fault_instruction & 0x0e100090) == 0x00000090)
518 ftype = VM_PROT_WRITE;
519 /* SWP instruction ? */
520 else if ((fault_instruction & 0x0fb00ff0) == 0x01000090)
521 ftype = VM_PROT_READ | VM_PROT_WRITE;
522 else
523 ftype = VM_PROT_READ;
524
525 #ifdef PMAP_DEBUG
526 if (pmap_debug_level >= 0)
527 printf("fault protection = %d\n", ftype);
528 #endif
529
530 if (pmap_fault_fixup(map->pmap, va, ftype, user))
531 goto out;
532
533 if (current_intr_depth > 0) {
534 #if defined(DDB) || defined(KGDB)
535 printf("Non-emulated page fault with intr_depth > 0\n");
536 report_abort(NULL, fault_status, fault_address, fault_pc);
537 kdb_trap(T_FAULT, frame);
538 return;
539 #else
540 panic("Fault with intr_depth > 0");
541 #endif /* DDB */
542 }
543
544 onfault = pcb->pcb_onfault;
545 pcb->pcb_onfault = NULL;
546 rv = uvm_fault(map, va, 0, ftype);
547 pcb->pcb_onfault = onfault;
548 if (map != kernel_map)
549 l->l_flag &= ~L_SA_PAGEFAULT;
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
567 (void)memset(&ksi, 0, sizeof(ksi));
568 ksi.ksi_signo = SIGSEGV;
569 ksi.ksi_code = 0;
570 ksi.ksi_addr = (u_int32_t *)fault_address;
571 ksi.ksi_trap = TRAP_CODE;
572 ksi.ksi_errno = rv;
573
574 if (rv == ENOMEM) {
575 printf("UVM: pid %d (%s), uid %d killed: "
576 "out of swap\n", p->p_pid, p->p_comm,
577 (p->p_cred && p->p_ucred) ? p->p_ucred->cr_uid : -1);
578 }
579
580 trapsignal:
581 KERNEL_PROC_LOCK(p);
582 #if 0
583 /* maybe one day we'll do emulations */
584 (*p->p_emul->e_trapsignal)(l, &ksi);
585 #else
586 trapsignal(l, &ksi);
587 #endif
588 KERNEL_PROC_UNLOCK(p);
589
590 out:
591 /* Call userret() if it was a USR mode fault */
592 if (user)
593 userret(l);
594 }
595
596
597 /*
598 * void prefetch_abort_handler(trapframe_t *frame)
599 *
600 * Abort handler called when instruction execution occurs at
601 * a non existent or restricted (access permissions) memory page.
602 * If the address is invalid and we were in SVC mode then panic as
603 * the kernel should never prefetch abort.
604 * If the address is invalid and the page is mapped then the user process
605 * does no have read permission so send it a signal.
606 * Otherwise fault the page in and try again.
607 */
608
609 void
610 prefetch_abort_handler(frame)
611 trapframe_t *frame;
612 {
613 struct lwp *l;
614 struct proc *p;
615 struct vm_map *map;
616 vaddr_t fault_pc, va;
617 int error;
618 ksiginfo_t ksi;
619
620 /*
621 * Enable IRQ's (disabled by the abort) This always comes
622 * from user mode so we know interrupts were not disabled.
623 * But we check anyway.
624 */
625 if (!(frame->tf_spsr & I32_bit))
626 enable_interrupts(I32_bit);
627
628 #ifdef DEBUG
629 if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE)
630 panic("prefetch_abort_handler: not in SVC32 mode");
631 #endif
632
633 /* Update vmmeter statistics */
634 uvmexp.traps++;
635
636 /* Call the cpu specific abort fixup routine */
637 error = cpu_prefetchabt_fixup(frame);
638 if (error == ABORT_FIXUP_RETURN)
639 return;
640 if (error == ABORT_FIXUP_FAILED)
641 panic("prefetch abort fixup failed");
642
643 /* Get the current proc structure or proc0 if there is none */
644 if ((l = curlwp) == NULL) {
645 l = &lwp0;
646 #ifdef DEBUG
647 printf("Prefetch abort with curlwp == 0\n");
648 #endif
649 }
650 p = l->l_proc;
651
652 #ifdef PMAP_DEBUG
653 if (pmap_debug_level >= 0)
654 printf("prefetch fault in process %p %s\n", p, p->p_comm);
655 #endif
656
657 /* Get fault address */
658 fault_pc = frame->tf_pc;
659 va = trunc_page(fault_pc);
660
661 /* Was the prefectch abort from USR32 mode ? */
662 if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) {
663 l->l_addr->u_pcb.pcb_tf = frame;
664 } else {
665 /*
666 * All the kernel code pages are loaded at boot time
667 * and do not get paged
668 */
669 panic("Prefetch abort in non-USR mode (frame=%p PC=0x%08lx)",
670 frame, fault_pc);
671 }
672
673 map = &p->p_vmspace->vm_map;
674
675 #ifdef PMAP_DEBUG
676 if (pmap_debug_level >= 0)
677 printf("prefetch_abort: PC = %08lx\n", fault_pc);
678 #endif
679 /* Ok validate the address, can only execute in USER space */
680 if (fault_pc < VM_MIN_ADDRESS || fault_pc >= VM_MAXUSER_ADDRESS) {
681 #ifdef DEBUG
682 printf("prefetch: pc (%08lx) not in user process space\n",
683 fault_pc);
684 #endif
685 (void)memset(&ksi, 0, sizeof(ksi));
686 ksi.ksi_signo = SIGSEGV;
687 ksi.ksi_code = SEGV_ACCERR;
688 ksi.ksi_addr = (u_int32_t *)fault_pc;
689 ksi.ksi_trap = fault_pc;
690
691 goto prefetch_trapsignal;
692 }
693
694 /*
695 * See if the pmap can handle this fault on its own...
696 */
697 if (pmap_fault_fixup(map->pmap, va, VM_PROT_READ, 1))
698 goto prefetch_out;
699
700 if (current_intr_depth > 0) {
701 #ifdef DDB
702 printf("Non-emulated prefetch abort with intr_depth > 0\n");
703 kdb_trap(T_FAULT, frame);
704 return;
705 #else
706 panic("Prefetch Abort with intr_depth > 0");
707 #endif
708 }
709
710 error = uvm_fault(map, va, 0, VM_PROT_READ);
711 if (error == 0)
712 goto prefetch_out;
713
714 (void)memset(&ksi, 0, sizeof(ksi));
715 ksi.ksi_signo = SIGSEGV;
716 ksi.ksi_code = 0;
717 ksi.ksi_errno = error;
718 ksi.ksi_addr = (u_int32_t *)fault_pc;
719 ksi.ksi_trap = fault_pc;
720
721 if (error == ENOMEM) {
722 printf("UVM: pid %d (%s), uid %d killed: "
723 "out of swap\n", p->p_pid, p->p_comm,
724 (p->p_cred && p->p_ucred) ? p->p_ucred->cr_uid : -1);
725 }
726 prefetch_trapsignal:
727 KERNEL_PROC_LOCK(p);
728 #if 0
729 /* maybe one day we'll do emulations */
730 (*p->p_emul->e_trapsignal)(l, &ksi);
731 #else
732 trapsignal(l, &ksi);
733 #endif
734 KERNEL_PROC_UNLOCK(p);
735 prefetch_out:
736 userret(l);
737 }
738