Home | History | Annotate | Line # | Download | only in arm32
fault.c revision 1.37
      1 /*	$NetBSD: fault.c,v 1.37 2003/10/15 14:07:03 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.37 2003/10/15 14:07:03 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 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 			KSI_INIT_TRAP(&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 			KSI_INIT_TRAP(&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, STRD instruction ? */
    517 	else if ((fault_instruction & 0x0e1000b0) == 0x000000b0)
    518 		ftype = VM_PROT_WRITE;
    519 	/* STRSH or STRSB instruction ? */
    520 	else if ((fault_instruction & 0x0e100090) == 0x00000090)
    521 		ftype = VM_PROT_WRITE;
    522 	/* SWP instruction ? */
    523 	else if ((fault_instruction & 0x0fb00ff0) == 0x01000090)
    524 		ftype = VM_PROT_READ | VM_PROT_WRITE;
    525 	else
    526 		ftype = VM_PROT_READ;
    527 
    528 #ifdef PMAP_DEBUG
    529 	if (pmap_debug_level >= 0)
    530 		printf("fault protection = %d\n", ftype);
    531 #endif
    532 
    533 	if (pmap_fault_fixup(map->pmap, va, ftype, user))
    534 		goto out;
    535 
    536 	if (current_intr_depth > 0) {
    537 #if defined(DDB) || defined(KGDB)
    538 		printf("Non-emulated page fault with intr_depth > 0\n");
    539 		report_abort(NULL, fault_status, fault_address, fault_pc);
    540 		kdb_trap(T_FAULT, frame);
    541 		return;
    542 #else
    543 		panic("Fault with intr_depth > 0");
    544 #endif	/* DDB */
    545 	}
    546 
    547 	onfault = pcb->pcb_onfault;
    548 	pcb->pcb_onfault = NULL;
    549 	rv = uvm_fault(map, va, 0, ftype);
    550 	pcb->pcb_onfault = onfault;
    551 	if (map != kernel_map)
    552 		l->l_flag &= ~L_SA_PAGEFAULT;
    553 	if (rv == 0) {
    554 		if (user != 0) /* Record any stack growth... */
    555 			uvm_grow(p, trunc_page(va));
    556 		goto out;
    557 	}
    558 	if (user == 0) {
    559 		if (pcb->pcb_onfault) {
    560 			frame->tf_r0 = rv;
    561 			goto copyfault;
    562 		}
    563 		printf("[u]vm_fault(%p, %lx, %x, 0) -> %x\n", map, va, ftype,
    564 		    rv);
    565 		goto we_re_toast;
    566 	}
    567 
    568 	report_abort("", fault_status, fault_address, fault_pc);
    569 
    570 	KSI_INIT_TRAP(&ksi);
    571 	ksi.ksi_signo = SIGSEGV;
    572 	ksi.ksi_code = 0;
    573 	ksi.ksi_addr = (u_int32_t *)fault_address;
    574 	ksi.ksi_trap = TRAP_CODE;
    575 	ksi.ksi_errno = rv;
    576 
    577 	if (rv == ENOMEM) {
    578 		printf("UVM: pid %d (%s), uid %d killed: "
    579 		    "out of swap\n", p->p_pid, p->p_comm,
    580 		    (p->p_cred && p->p_ucred) ?  p->p_ucred->cr_uid : -1);
    581 	}
    582 
    583 trapsignal:
    584 	KERNEL_PROC_LOCK(p);
    585 #if 0
    586 	/* maybe one day we'll do emulations */
    587 	(*p->p_emul->e_trapsignal)(l, &ksi);
    588 #else
    589 	trapsignal(l, &ksi);
    590 #endif
    591 	KERNEL_PROC_UNLOCK(p);
    592 
    593 out:
    594 	/* Call userret() if it was a USR mode fault */
    595 	if (user)
    596 		userret(l);
    597 }
    598 
    599 
    600 /*
    601  * void prefetch_abort_handler(trapframe_t *frame)
    602  *
    603  * Abort handler called when instruction execution occurs at
    604  * a non existent or restricted (access permissions) memory page.
    605  * If the address is invalid and we were in SVC mode then panic as
    606  * the kernel should never prefetch abort.
    607  * If the address is invalid and the page is mapped then the user process
    608  * does no have read permission so send it a signal.
    609  * Otherwise fault the page in and try again.
    610  */
    611 
    612 void
    613 prefetch_abort_handler(frame)
    614 	trapframe_t *frame;
    615 {
    616 	struct lwp *l;
    617 	struct proc *p;
    618 	struct vm_map *map;
    619 	vaddr_t fault_pc, va;
    620 	int error;
    621 	ksiginfo_t ksi;
    622 
    623 	/*
    624 	 * Enable IRQ's (disabled by the abort) This always comes
    625 	 * from user mode so we know interrupts were not disabled.
    626 	 * But we check anyway.
    627 	 */
    628 	if (!(frame->tf_spsr & I32_bit))
    629 		enable_interrupts(I32_bit);
    630 
    631 #ifdef DEBUG
    632 	if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE)
    633 		panic("prefetch_abort_handler: not in SVC32 mode");
    634 #endif
    635 
    636 	/* Update vmmeter statistics */
    637 	uvmexp.traps++;
    638 
    639 	/* Call the cpu specific abort fixup routine */
    640 	error = cpu_prefetchabt_fixup(frame);
    641 	if (error == ABORT_FIXUP_RETURN)
    642 		return;
    643 	if (error == ABORT_FIXUP_FAILED)
    644 		panic("prefetch abort fixup failed");
    645 
    646 	/* Get the current proc structure or proc0 if there is none */
    647 	if ((l = curlwp) == NULL) {
    648 		l = &lwp0;
    649 #ifdef DEBUG
    650 		printf("Prefetch abort with curlwp == 0\n");
    651 #endif
    652 	}
    653 	p = l->l_proc;
    654 
    655 #ifdef PMAP_DEBUG
    656 	if (pmap_debug_level >= 0)
    657 		printf("prefetch fault in process %p %s\n", p, p->p_comm);
    658 #endif
    659 
    660 	/* Get fault address */
    661 	fault_pc = frame->tf_pc;
    662 	va = trunc_page(fault_pc);
    663 
    664 	/* Was the prefectch abort from USR32 mode ? */
    665 	if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) {
    666 		l->l_addr->u_pcb.pcb_tf = frame;
    667 	} else {
    668 		/*
    669 		 * All the kernel code pages are loaded at boot time
    670 		 * and do not get paged
    671 		 */
    672 	        panic("Prefetch abort in non-USR mode (frame=%p PC=0x%08lx)",
    673 	            frame, fault_pc);
    674 	}
    675 
    676 	map = &p->p_vmspace->vm_map;
    677 
    678 #ifdef PMAP_DEBUG
    679 	if (pmap_debug_level >= 0)
    680 		printf("prefetch_abort: PC = %08lx\n", fault_pc);
    681 #endif
    682 	/* Ok validate the address, can only execute in USER space */
    683 	if (fault_pc < VM_MIN_ADDRESS || fault_pc >= VM_MAXUSER_ADDRESS) {
    684 #ifdef DEBUG
    685 		printf("prefetch: pc (%08lx) not in user process space\n",
    686 		    fault_pc);
    687 #endif
    688 		KSI_INIT_TRAP(&ksi);
    689 		ksi.ksi_signo = SIGSEGV;
    690 		ksi.ksi_code = SEGV_ACCERR;
    691 		ksi.ksi_addr = (u_int32_t *)fault_pc;
    692 		ksi.ksi_trap = fault_pc;
    693 
    694 		goto prefetch_trapsignal;
    695 	}
    696 
    697 	/*
    698 	 * See if the pmap can handle this fault on its own...
    699 	 */
    700 	if (pmap_fault_fixup(map->pmap, va, VM_PROT_READ, 1))
    701 		goto prefetch_out;
    702 
    703 	if (current_intr_depth > 0) {
    704 #ifdef DDB
    705 		printf("Non-emulated prefetch abort with intr_depth > 0\n");
    706 		kdb_trap(T_FAULT, frame);
    707 		return;
    708 #else
    709 		panic("Prefetch Abort with intr_depth > 0");
    710 #endif
    711 	}
    712 
    713 	error = uvm_fault(map, va, 0, VM_PROT_READ);
    714 	if (error == 0)
    715 		goto prefetch_out;
    716 
    717 	KSI_INIT_TRAP(&ksi);
    718 	ksi.ksi_signo = SIGSEGV;
    719 	ksi.ksi_code = 0;
    720 	ksi.ksi_errno = error;
    721 	ksi.ksi_addr = (u_int32_t *)fault_pc;
    722 	ksi.ksi_trap = fault_pc;
    723 
    724 	if (error == ENOMEM) {
    725 		printf("UVM: pid %d (%s), uid %d killed: "
    726 		    "out of swap\n", p->p_pid, p->p_comm,
    727 		    (p->p_cred && p->p_ucred) ?  p->p_ucred->cr_uid : -1);
    728 	}
    729 prefetch_trapsignal:
    730 	KERNEL_PROC_LOCK(p);
    731 #if 0
    732 	/* maybe one day we'll do emulations */
    733 	(*p->p_emul->e_trapsignal)(l, &ksi);
    734 #else
    735 	trapsignal(l, &ksi);
    736 #endif
    737 	KERNEL_PROC_UNLOCK(p);
    738 prefetch_out:
    739 	userret(l);
    740 }
    741