Home | History | Annotate | Line # | Download | only in arm32
fault.c revision 1.32
      1 /*	$NetBSD: fault.c,v 1.32 2003/09/18 22:37:38 cl 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.32 2003/09/18 22:37:38 cl 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 #define	IS_FATAL_FAULT(x)					\
    244 	(((1 << (x)) &						\
    245 	  ((1 << FAULT_WRTBUF_0) | (1 << FAULT_WRTBUF_1) |	\
    246 	   (1 << FAULT_BUSERR_0) | (1 << FAULT_BUSERR_1) |	\
    247 	   (1 << FAULT_BUSERR_2) | (1 << FAULT_BUSERR_3) |	\
    248 	   (1 << FAULT_BUSTRNL1) | (1 << FAULT_BUSTRNL2) |	\
    249 	   (1 << FAULT_ALIGN_0)  | (1 << FAULT_ALIGN_1))) != 0)
    250 
    251 void
    252 data_abort_handler(frame)
    253 	trapframe_t *frame;
    254 {
    255 	struct lwp *l;
    256 	struct proc *p;
    257 	struct pcb *pcb;
    258 	u_int fault_address;
    259 	u_int fault_status;
    260 	u_int fault_pc;
    261 	u_int fault_instruction;
    262 	int fault_code, fatal_fault;
    263 	int user;
    264 	int error;
    265 	int rv;
    266 	void *onfault;
    267 	vaddr_t va;
    268 	struct vmspace *vm;
    269 	struct vm_map *map;
    270 	vm_prot_t ftype;
    271 	extern struct vm_map *kernel_map;
    272 
    273 	/*
    274 	 * If we were expecting a Data Abort, signal that we got
    275 	 * one, adjust the PC to skip the faulting insn, and
    276 	 * return.
    277 	 */
    278 	if (data_abort_expected) {
    279 		data_abort_received = 1;
    280 		frame->tf_pc += INSN_SIZE;
    281 		return;
    282 	}
    283 
    284 	/*
    285 	 * Must get fault address and status from the CPU before
    286 	 * re-enabling interrupts.  (Interrupt handlers may take
    287 	 * R/M emulation faults.)
    288 	 */
    289 	fault_address = cpu_faultaddress();
    290 	fault_status = cpu_faultstatus();
    291 	fault_pc = frame->tf_pc;
    292 
    293 	/*
    294 	 * Enable IRQ's (disabled by CPU on abort) if trapframe
    295 	 * shows they were enabled.
    296 	 */
    297 	if (!(frame->tf_spsr & I32_bit))
    298 		enable_interrupts(I32_bit);
    299 
    300 #ifdef DEBUG
    301 	if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE)
    302 		panic("data_abort_handler: not in SVC32 mode");
    303 #endif
    304 
    305 	/* Update vmmeter statistics */
    306 	uvmexp.traps++;
    307 
    308 	/* Extract the fault code from the fault status */
    309 	fault_code = fault_status & FAULT_TYPE_MASK;
    310 	fatal_fault = IS_FATAL_FAULT(fault_code);
    311 
    312 	/* Get the current lwp structure or lwp0 if there is none */
    313 	l = curlwp == NULL ? &lwp0 : curlwp;
    314 	p = l->l_proc;
    315 
    316 	/*
    317 	 * can't use curpcb, as it might be NULL; and we have p in
    318 	 * a register anyway
    319 	 */
    320 	pcb = &l->l_addr->u_pcb;
    321 
    322 	/* fusubailout is used by [fs]uswintr to avoid page faulting */
    323 	if (pcb->pcb_onfault &&
    324 	    (fatal_fault || pcb->pcb_onfault == fusubailout)) {
    325 
    326 		frame->tf_r0 = EFAULT;
    327 copyfault:
    328 #ifdef DEBUG
    329 		printf("Using pcb_onfault=%p addr=%08x st=%08x l=%p\n",
    330 		    pcb->pcb_onfault, fault_address, fault_status, l);
    331 #endif
    332 		frame->tf_pc = (u_int)pcb->pcb_onfault;
    333 		if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE)
    334 			panic("Yikes pcb_onfault=%p during USR mode fault",
    335 			    pcb->pcb_onfault);
    336 		return;
    337 	}
    338 
    339 	/* More debug stuff */
    340 
    341 	fault_instruction = ReadWord(fault_pc);
    342 
    343 #ifdef PMAP_DEBUG
    344 	if (pmap_debug_level >= 0) {
    345 		report_abort(NULL, fault_status, fault_address, fault_pc);
    346 		printf("Instruction @V%08x = %08x\n",
    347 		    fault_pc, fault_instruction);
    348 	}
    349 #endif
    350 
    351 	/* Call the cpu specific abort fixup routine */
    352 	error = cpu_dataabt_fixup(frame);
    353 	if (error == ABORT_FIXUP_RETURN)
    354 		return;
    355 	if (error == ABORT_FIXUP_FAILED) {
    356 		printf("pc = 0x%08x, opcode 0x%08x, insn = ", fault_pc, *((u_int *)fault_pc));
    357 		disassemble(fault_pc);
    358 		printf("data abort handler: fixup failed for this instruction\n");
    359 	}
    360 
    361 #ifdef PMAP_DEBUG
    362 	if (pmap_debug_level >= 0)
    363 		printf("fault in process %p\n", p);
    364 #endif
    365 
    366 #ifdef DEBUG
    367 	/* Is this needed ? (XXXSCW: yes. can happen during boot ...) */
    368 	if (!cold && pcb != curpcb) {
    369 		printf("data_abort: Alert ! pcb(%p) != curpcb(%p)\n",
    370 		    pcb, curpcb);
    371 		printf("data_abort: Alert ! proc(%p), curlwp(%p)\n",
    372 		    p, curlwp);
    373 	}
    374 #endif	/* DEBUG */
    375 
    376 	/* Were we in user mode when the abort occurred ? */
    377 	if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) {
    378 		/*
    379 		 * Note that the fault was from USR mode.
    380 		 */
    381 		user = 1;
    382 		l->l_addr->u_pcb.pcb_tf = frame;
    383 	} else
    384 		user = 0;
    385 
    386 	/* check if this was a failed fixup */
    387 	if (error == ABORT_FIXUP_FAILED) {
    388 		if (user) {
    389 			trapsignal(l, SIGSEGV, TRAP_CODE);
    390 			userret(l);
    391 			return;
    392 		};
    393 		panic("Data abort fixup failed in kernel - we're dead");
    394 	};
    395 
    396 	/* Now act on the fault type */
    397 	if (fatal_fault) {
    398 		/*
    399 		 * None of these faults should happen on a perfectly
    400 		 * functioning system. They indicate either some gross
    401 		 * problem with the kernel, or a hardware problem.
    402 		 * In either case, stop.
    403 		 */
    404 		report_abort(NULL, fault_status, fault_address, fault_pc);
    405 
    406 we_re_toast:
    407 		/*
    408 		 * Were are dead, try and provide some debug
    409 		 * information before dying.
    410 		 */
    411 #if defined(DDB) || defined(KGDB)
    412 		printf("Unhandled trap (frame = %p)\n", frame);
    413 		report_abort(NULL, fault_status, fault_address, fault_pc);
    414 		kdb_trap(T_FAULT, frame);
    415 		return;
    416 #else
    417 		panic("Unhandled trap (frame = %p)", frame);
    418 #endif	/* DDB || KGDB */
    419 	}
    420 
    421 	/*
    422 	 * At this point, we're dealing with one of the following faults:
    423 	 *
    424 	 *  FAULT_TRANS_P	Page Translation Fault
    425 	 *  FAULT_PERM_P	Page Permission Fault
    426 	 *  FAULT_TRANS_S	Section Translation Fault
    427 	 *  FAULT_PERM_S	Section Permission Fault
    428 	 *  FAULT_DOMAIN_P	Page Domain Error Fault
    429 	 *  FAULT_DOMAIN_S	Section Domain Error Fault
    430 	 *
    431 	 * Page/section translation/permission fault -- need to fault in
    432 	 * the page.
    433 	 *
    434 	 * Page/section domain fault -- need to see if the L1 entry can
    435 	 * be fixed up.
    436 	 */
    437 	vm = p->p_vmspace;
    438 	va = trunc_page((vaddr_t)fault_address);
    439 
    440 #ifdef PMAP_DEBUG
    441 	if (pmap_debug_level >= 0)
    442 		printf("page fault: addr=V%08lx ", va);
    443 #endif
    444 
    445 	/*
    446 	 * It is only a kernel address space fault iff:
    447 	 *	1. user == 0  and
    448 	 *	2. pcb_onfault not set or
    449 	 *	3. pcb_onfault set but supervisor space fault
    450 	 * The last can occur during an exec() copyin where the
    451 	 * argument space is lazy-allocated.
    452 	 */
    453 	if (!user &&
    454 	    (va >= VM_MIN_KERNEL_ADDRESS || va < VM_MIN_ADDRESS)) {
    455 		/* Was the fault due to the FPE/IPKDB ? */
    456 		if ((frame->tf_spsr & PSR_MODE) == PSR_UND32_MODE) {
    457 			report_abort("UND32", fault_status,
    458 			    fault_address, fault_pc);
    459 			trapsignal(l, SIGSEGV, TRAP_CODE);
    460 
    461 			/*
    462 			 * Force exit via userret()
    463 			 * This is necessary as the FPE is an extension
    464 			 * to userland that actually runs in a
    465 			 * priveledged mode but uses USR mode
    466 			 * permissions for its accesses.
    467 			 */
    468 			userret(l);
    469 			return;
    470 		}
    471 		map = kernel_map;
    472 	} else {
    473 		map = &vm->vm_map;
    474 		if (l->l_flag & L_SA) {
    475 			KDASSERT(p != NULL && p->p_sa != NULL);
    476 			p->p_sa->sa_vp_faultaddr = (vaddr_t)fault_address;
    477 			l->l_flag |= L_SA_PAGEFAULT;
    478 		}
    479 	}
    480 
    481 #ifdef PMAP_DEBUG
    482 	if (pmap_debug_level >= 0)
    483 		printf("vmmap=%p ", map);
    484 #endif
    485 
    486 	if (map == NULL)
    487 		printf("No map for fault address va = 0x%08lx", va);
    488 
    489 	/*
    490 	 * We need to know whether the page should be mapped
    491 	 * as R or R/W. The MMU does not give us the info as
    492 	 * to whether the fault was caused by a read or a write.
    493 	 * This means we need to disassemble the instruction
    494 	 * responsible and determine if it was a read or write
    495 	 * instruction.
    496 	 */
    497 	/* STR instruction ? */
    498 	if ((fault_instruction & 0x0c100000) == 0x04000000)
    499 		ftype = VM_PROT_WRITE;
    500 	/* STM or CDT instruction ? */
    501 	else if ((fault_instruction & 0x0a100000) == 0x08000000)
    502 		ftype = VM_PROT_WRITE;
    503 	/* STRH, STRSH or STRSB instruction ? */
    504 	else if ((fault_instruction & 0x0e100090) == 0x00000090)
    505 		ftype = VM_PROT_WRITE;
    506 	/* SWP instruction ? */
    507 	else if ((fault_instruction & 0x0fb00ff0) == 0x01000090)
    508 		ftype = VM_PROT_READ | VM_PROT_WRITE;
    509 	else
    510 		ftype = VM_PROT_READ;
    511 
    512 #ifdef PMAP_DEBUG
    513 	if (pmap_debug_level >= 0)
    514 		printf("fault protection = %d\n", ftype);
    515 #endif
    516 
    517 	if (pmap_fault_fixup(map->pmap, va, ftype, user))
    518 		goto out;
    519 
    520 	if (current_intr_depth > 0) {
    521 #if defined(DDB) || defined(KGDB)
    522 		printf("Non-emulated page fault with intr_depth > 0\n");
    523 		report_abort(NULL, fault_status, fault_address, fault_pc);
    524 		kdb_trap(T_FAULT, frame);
    525 		return;
    526 #else
    527 		panic("Fault with intr_depth > 0");
    528 #endif	/* DDB */
    529 	}
    530 
    531 	onfault = pcb->pcb_onfault;
    532 	pcb->pcb_onfault = NULL;
    533 	rv = uvm_fault(map, va, 0, ftype);
    534 	pcb->pcb_onfault = onfault;
    535 	if (map != kernel_map)
    536 		l->l_flag &= ~L_SA_PAGEFAULT;
    537 	if (rv == 0) {
    538 		if (user != 0) /* Record any stack growth... */
    539 			uvm_grow(p, trunc_page(va));
    540 		goto out;
    541 	}
    542 	if (user == 0) {
    543 		if (pcb->pcb_onfault) {
    544 			frame->tf_r0 = rv;
    545 			goto copyfault;
    546 		}
    547 		printf("[u]vm_fault(%p, %lx, %x, 0) -> %x\n", map, va, ftype,
    548 		    rv);
    549 		goto we_re_toast;
    550 	}
    551 
    552 	report_abort("", fault_status, fault_address, fault_pc);
    553 	if (rv == ENOMEM) {
    554 		printf("UVM: pid %d (%s), uid %d killed: "
    555 		    "out of swap\n", p->p_pid, p->p_comm,
    556 		    (p->p_cred && p->p_ucred) ?  p->p_ucred->cr_uid : -1);
    557 			trapsignal(l, SIGKILL, TRAP_CODE);
    558 	} else
    559 		trapsignal(l, SIGSEGV, TRAP_CODE);
    560 
    561 out:
    562 	/* Call userret() if it was a USR mode fault */
    563 	if (user)
    564 		userret(l);
    565 }
    566 
    567 
    568 /*
    569  * void prefetch_abort_handler(trapframe_t *frame)
    570  *
    571  * Abort handler called when instruction execution occurs at
    572  * a non existent or restricted (access permissions) memory page.
    573  * If the address is invalid and we were in SVC mode then panic as
    574  * the kernel should never prefetch abort.
    575  * If the address is invalid and the page is mapped then the user process
    576  * does no have read permission so send it a signal.
    577  * Otherwise fault the page in and try again.
    578  */
    579 
    580 void
    581 prefetch_abort_handler(frame)
    582 	trapframe_t *frame;
    583 {
    584 	struct lwp *l;
    585 	struct proc *p;
    586 	struct vm_map *map;
    587 	vaddr_t fault_pc, va;
    588 	int error;
    589 
    590 	/*
    591 	 * Enable IRQ's (disabled by the abort) This always comes
    592 	 * from user mode so we know interrupts were not disabled.
    593 	 * But we check anyway.
    594 	 */
    595 	if (!(frame->tf_spsr & I32_bit))
    596 		enable_interrupts(I32_bit);
    597 
    598 #ifdef DEBUG
    599 	if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE)
    600 		panic("prefetch_abort_handler: not in SVC32 mode");
    601 #endif
    602 
    603 	/* Update vmmeter statistics */
    604 	uvmexp.traps++;
    605 
    606 	/* Call the cpu specific abort fixup routine */
    607 	error = cpu_prefetchabt_fixup(frame);
    608 	if (error == ABORT_FIXUP_RETURN)
    609 		return;
    610 	if (error == ABORT_FIXUP_FAILED)
    611 		panic("prefetch abort fixup failed");
    612 
    613 	/* Get the current proc structure or proc0 if there is none */
    614 	if ((l = curlwp) == NULL) {
    615 		l = &lwp0;
    616 #ifdef DEBUG
    617 		printf("Prefetch abort with curlwp == 0\n");
    618 #endif
    619 	}
    620 	p = l->l_proc;
    621 
    622 #ifdef PMAP_DEBUG
    623 	if (pmap_debug_level >= 0)
    624 		printf("prefetch fault in process %p %s\n", p, p->p_comm);
    625 #endif
    626 
    627 	/* Get fault address */
    628 	fault_pc = frame->tf_pc;
    629 	va = trunc_page(fault_pc);
    630 
    631 	/* Was the prefectch abort from USR32 mode ? */
    632 	if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) {
    633 		l->l_addr->u_pcb.pcb_tf = frame;
    634 	} else {
    635 		/*
    636 		 * All the kernel code pages are loaded at boot time
    637 		 * and do not get paged
    638 		 */
    639 	        panic("Prefetch abort in non-USR mode (frame=%p PC=0x%08lx)",
    640 	            frame, fault_pc);
    641 	}
    642 
    643 	map = &p->p_vmspace->vm_map;
    644 
    645 #ifdef PMAP_DEBUG
    646 	if (pmap_debug_level >= 0)
    647 		printf("prefetch_abort: PC = %08lx\n", fault_pc);
    648 #endif
    649 	/* Ok validate the address, can only execute in USER space */
    650 	if (fault_pc < VM_MIN_ADDRESS || fault_pc >= VM_MAXUSER_ADDRESS) {
    651 #ifdef DEBUG
    652 		printf("prefetch: pc (%08lx) not in user process space\n",
    653 		    fault_pc);
    654 #endif
    655 		trapsignal(l, SIGSEGV, fault_pc);
    656 		userret(l);
    657 		return;
    658 	}
    659 
    660 	/*
    661 	 * See if the pmap can handle this fault on its own...
    662 	 */
    663 	if (pmap_fault_fixup(map->pmap, va, VM_PROT_READ, 1))
    664 		goto out;
    665 
    666 	if (current_intr_depth > 0) {
    667 #ifdef DDB
    668 		printf("Non-emulated prefetch abort with intr_depth > 0\n");
    669 		kdb_trap(T_FAULT, frame);
    670 		return;
    671 #else
    672 		panic("Prefetch Abort with intr_depth > 0");
    673 #endif
    674 	}
    675 
    676 	error = uvm_fault(map, va, 0, VM_PROT_READ);
    677 	if (error == 0)
    678 		goto out;
    679 
    680 	if (error == ENOMEM) {
    681 		printf("UVM: pid %d (%s), uid %d killed: "
    682 		    "out of swap\n", p->p_pid, p->p_comm,
    683 		    (p->p_cred && p->p_ucred) ?  p->p_ucred->cr_uid : -1);
    684 		trapsignal(l, SIGKILL, fault_pc);
    685 	} else
    686 		trapsignal(l, SIGSEGV, fault_pc);
    687 out:
    688 	userret(l);
    689 }
    690