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