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