Home | History | Annotate | Line # | Download | only in arm32
fault.c revision 1.4.2.11
      1 /*	$NetBSD: fault.c,v 1.4.2.11 2002/08/13 02:17:50 nathanw 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.4.2.11 2002/08/13 02:17:50 nathanw 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 lwp *l;
    203 	struct proc *p;
    204 	struct pcb *pcb;
    205 	u_int fault_address;
    206 	u_int fault_status;
    207 	u_int fault_pc;
    208 	u_int fault_instruction;
    209 	int fault_code;
    210 	int user;
    211 	int error;
    212 	void *onfault;
    213 
    214 	/*
    215 	 * If we were expecting a Data Abort, signal that we got
    216 	 * one, adjust the PC to skip the faulting insn, and
    217 	 * return.
    218 	 */
    219 	if (data_abort_expected) {
    220 		data_abort_received = 1;
    221 		frame->tf_pc += INSN_SIZE;
    222 		return;
    223 	}
    224 
    225 	/*
    226 	 * Must get fault address and status from the CPU before
    227 	 * re-enabling interrupts.  (Interrupt handlers may take
    228 	 * R/M emulation faults.)
    229 	 */
    230 	fault_address = cpu_faultaddress();
    231 	fault_status = cpu_faultstatus();
    232 	fault_pc = frame->tf_pc;
    233 
    234 	/*
    235 	 * Enable IRQ's (disabled by CPU on abort) if trapframe
    236 	 * shows they were enabled.
    237 	 */
    238 	if (!(frame->tf_spsr & I32_bit))
    239 		enable_interrupts(I32_bit);
    240 
    241 #ifdef DEBUG
    242 	if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE)
    243 		panic("data_abort_handler: not in SVC32 mode");
    244 #endif
    245 
    246 	/* Update vmmeter statistics */
    247 	uvmexp.traps++;
    248 
    249 	/* Extract the fault code from the fault status */
    250 	fault_code = fault_status & FAULT_TYPE_MASK;
    251 
    252 	/* Get the current lwp structure or lwp0 if there is none */
    253 	l = curlwp == NULL ? &lwp0 : curlwp;
    254 	p = l->l_proc;
    255 
    256 	/*
    257 	 * can't use curpcb, as it might be NULL; and we have p in
    258 	 * a register anyway
    259 	 */
    260 	pcb = &l->l_addr->u_pcb;
    261 
    262 	/* fusubailout is used by [fs]uswintr to avoid page faulting */
    263 	if (pcb->pcb_onfault
    264 	    && ((fault_code != FAULT_TRANS_S && fault_code != FAULT_TRANS_P &&
    265 		 fault_code != FAULT_PERM_S && fault_code != FAULT_PERM_P)
    266 	        || pcb->pcb_onfault == fusubailout)) {
    267 
    268 		frame->tf_r0 = EFAULT;
    269 copyfault:
    270 #ifdef DEBUG
    271 		printf("Using pcb_onfault=%p addr=%08x st=%08x l=%p\n",
    272 		    pcb->pcb_onfault, fault_address, fault_status, l);
    273 #endif
    274 		frame->tf_pc = (u_int)pcb->pcb_onfault;
    275 		if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE)
    276 			panic("Yikes pcb_onfault=%p during USR mode fault\n",
    277 			    pcb->pcb_onfault);
    278 		return;
    279 	}
    280 
    281 	/* More debug stuff */
    282 
    283 	fault_instruction = ReadWord(fault_pc);
    284 
    285 #ifdef PMAP_DEBUG
    286 	if (pmap_debug_level >= 0) {
    287 		report_abort(NULL, fault_status, fault_address, fault_pc);
    288 		printf("Instruction @V%08x = %08x\n",
    289 		    fault_pc, fault_instruction);
    290 	}
    291 #endif
    292 
    293 	/* Call the cpu specific abort fixup routine */
    294 	error = cpu_dataabt_fixup(frame);
    295 	if (error == ABORT_FIXUP_RETURN)
    296 		return;
    297 	if (error == ABORT_FIXUP_FAILED) {
    298 		printf("pc = 0x%08x, opcode 0x%08x, insn = ", fault_pc, *((u_int *)fault_pc));
    299 		disassemble(fault_pc);
    300 		printf("data abort handler: fixup failed for this instruction\n");
    301 	}
    302 
    303 #ifdef PMAP_DEBUG
    304 	if (pmap_debug_level >= 0)
    305 		printf("fault in process %p\n", p);
    306 #endif
    307 
    308 #ifdef DEBUG
    309 	/* Is this needed ? */
    310 	if (pcb != curpcb) {
    311 		printf("data_abort: Alert ! pcb(%p) != curpcb(%p)\n",
    312 		    pcb, curpcb);
    313 		printf("data_abort: Alert ! proc(%p), curlwp(%p)\n",
    314 		    p, curlwp);
    315 	}
    316 #endif	/* DEBUG */
    317 
    318 	/* Were we in user mode when the abort occurred ? */
    319 	if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) {
    320 		/*
    321 		 * Note that the fault was from USR mode.
    322 		 */
    323 		user = 1;
    324 		l->l_addr->u_pcb.pcb_tf = frame;
    325 	} else
    326 		user = 0;
    327 
    328 	/* check if this was a failed fixup */
    329 	if (error == ABORT_FIXUP_FAILED) {
    330 		if (user) {
    331 			trapsignal(l, SIGSEGV, TRAP_CODE);
    332 			userret(l);
    333 			return;
    334 		};
    335 		panic("Data abort fixup failed in kernel - we're dead\n");
    336 	};
    337 
    338 	/* Now act on the fault type */
    339 	switch (fault_code) {
    340 	case FAULT_WRTBUF_0:              /* Write Buffer Fault */
    341 	case FAULT_WRTBUF_1:              /* Write Buffer Fault */
    342 		/* If this happens forget it no point in continuing */
    343 
    344 		/* FALLTHROUGH */
    345 
    346 	case FAULT_ALIGN_0:              /* Alignment Fault */
    347 	case FAULT_ALIGN_1:              /* Alignment Fault */
    348 		/*
    349 		 * Really this should just kill the process.
    350 		 * Alignment faults are turned off in the kernel
    351 		 * in order to get better performance from shorts with
    352 		 * GCC so an alignment fault means somebody has played
    353 		 * with the control register in the CPU. Might as well
    354 		 * panic as the kernel was not compiled for aligned accesses.
    355 		 */
    356 
    357 		/* FALLTHROUGH */
    358 
    359 	case FAULT_BUSERR_0:              /* Bus Error LF Section */
    360 	case FAULT_BUSERR_1:              /* Bus Error Page */
    361 	case FAULT_BUSERR_2:              /* Bus Error Section */
    362 	case FAULT_BUSERR_3:              /* Bus Error Page */
    363 		/* What will accutally cause a bus error ? */
    364 		/* Real bus errors are not a process problem but hardware */
    365 
    366 		/* FALLTHROUGH */
    367 
    368 	case FAULT_DOMAIN_S:              /* Section Domain Error Fault */
    369 	case FAULT_DOMAIN_P:              /* Page Domain Error Fault*/
    370 		/*
    371 		 * Right well we dont use domains, everything is
    372 		 * always a client and thus subject to access permissions.
    373 		 * If we get a domain error then we have corrupts PTE's
    374 		 * so we might as well die !
    375 		 * I suppose eventually this should just kill the process
    376 		 * who owns the PTE's but if this happens it implies a
    377 		 * kernel problem.
    378 		 */
    379 
    380 		/* FALLTHROUGH */
    381 
    382 	case FAULT_BUSTRNL1:              /* Bus Error Trans L1 Fault */
    383 	case FAULT_BUSTRNL2:              /* Bus Error Trans L2 Fault */
    384 		/*
    385 		 * These faults imply that the PTE is corrupt.
    386 		 * Likely to be a kernel fault so we had better stop.
    387 		 */
    388 
    389 		/* FALLTHROUGH */
    390 
    391 	default :
    392 		/* Are there any combinations I have missed ? */
    393 		report_abort(NULL, fault_status, fault_address, fault_pc);
    394 
    395 	we_re_toast:
    396 		/*
    397 		 * Were are dead, try and provide some debug
    398 		 * information before dying.
    399 		 */
    400 #ifdef DDB
    401 		printf("Unhandled trap (frame = %p)\n", frame);
    402 		report_abort(NULL, fault_status, fault_address, fault_pc);
    403 		kdb_trap(-1, frame);
    404 		return;
    405 #else
    406 		panic("Unhandled trap (frame = %p)", frame);
    407 #endif	/* DDB */
    408 
    409 	case FAULT_TRANS_P:              /* Page Translation Fault */
    410 	case FAULT_PERM_P:		 /* Page Permission Fault */
    411 	case FAULT_TRANS_S:              /* Section Translation Fault */
    412 	case FAULT_PERM_S:		 /* Section Permission Fault */
    413 	/*
    414 	 * Page/section translation/permission fault -- need to fault in
    415 	 * the page and possibly the page table page.
    416 	 */
    417 	    {
    418 		register vaddr_t va;
    419 		register struct vmspace *vm = p->p_vmspace;
    420 		register struct vm_map *map;
    421 		int rv;
    422 		vm_prot_t ftype;
    423 		extern struct vm_map *kernel_map;
    424 
    425 		va = trunc_page((vaddr_t)fault_address);
    426 
    427 #ifdef PMAP_DEBUG
    428 		if (pmap_debug_level >= 0)
    429 			printf("page fault: addr=V%08lx ", va);
    430 #endif
    431 
    432 		/*
    433 		 * It is only a kernel address space fault iff:
    434 		 *	1. user == 0  and
    435 		 *	2. pcb_onfault not set or
    436 		 *	3. pcb_onfault set but supervisor space fault
    437 		 * The last can occur during an exec() copyin where the
    438 		 * argument space is lazy-allocated.
    439 		 */
    440 		if (!user &&
    441 		    (va >= VM_MIN_KERNEL_ADDRESS || va < VM_MIN_ADDRESS)) {
    442 			/* Was the fault due to the FPE/IPKDB ? */
    443 			if ((frame->tf_spsr & PSR_MODE) == PSR_UND32_MODE) {
    444 				report_abort("UND32", fault_status,
    445 				    fault_address, fault_pc);
    446 				trapsignal(l, SIGSEGV, TRAP_CODE);
    447 
    448 				/*
    449 				 * Force exit via userret()
    450 				 * This is necessary as the FPE is an extension
    451 				 * to userland that actually runs in a
    452 				 * priveledged mode but uses USR mode
    453 				 * permissions for its accesses.
    454 				 */
    455 				userret(l);
    456 				return;
    457 			}
    458 			map = kernel_map;
    459 		} else
    460 			map = &vm->vm_map;
    461 
    462 #ifdef PMAP_DEBUG
    463 		if (pmap_debug_level >= 0)
    464 			printf("vmmap=%p ", map);
    465 #endif
    466 
    467 		if (map == NULL)
    468 			panic("No map for fault address va = 0x%08lx", va);
    469 
    470 		/*
    471 		 * We need to know whether the page should be mapped
    472 		 * as R or R/W. The MMU does not give us the info as
    473 		 * to whether the fault was caused by a read or a write.
    474 		 * This means we need to disassemble the instruction
    475 		 * responsible and determine if it was a read or write
    476 		 * instruction.
    477 		 */
    478 		/* STR instruction ? */
    479 		if ((fault_instruction & 0x0c100000) == 0x04000000)
    480 			ftype = VM_PROT_WRITE;
    481 		/* STM or CDT instruction ? */
    482 		else if ((fault_instruction & 0x0a100000) == 0x08000000)
    483 			ftype = VM_PROT_WRITE;
    484 		/* STRH, STRSH or STRSB instruction ? */
    485 		else if ((fault_instruction & 0x0e100090) == 0x00000090)
    486 			ftype = VM_PROT_WRITE;
    487 		/* SWP instruction ? */
    488 		else if ((fault_instruction & 0x0fb00ff0) == 0x01000090)
    489 			ftype = VM_PROT_READ | VM_PROT_WRITE;
    490 		else
    491 			ftype = VM_PROT_READ;
    492 
    493 #ifdef PMAP_DEBUG
    494 		if (pmap_debug_level >= 0)
    495 			printf("fault protection = %d\n", ftype);
    496 #endif
    497 
    498 		if ((ftype & VM_PROT_WRITE) ?
    499 		    pmap_modified_emulation(map->pmap, va) :
    500 		    pmap_handled_emulation(map->pmap, va))
    501 			goto out;
    502 
    503 		if (current_intr_depth > 0) {
    504 #ifdef DDB
    505 			printf("Non-emulated page fault with intr_depth > 0\n");
    506 			report_abort(NULL, fault_status, fault_address, fault_pc);
    507 			kdb_trap(-1, frame);
    508 			return;
    509 #else
    510 			panic("Fault with intr_depth > 0");
    511 #endif	/* DDB */
    512 		}
    513 
    514 		onfault = pcb->pcb_onfault;
    515 		pcb->pcb_onfault = NULL;
    516 		rv = uvm_fault(map, va, 0, ftype);
    517 		pcb->pcb_onfault = onfault;
    518 		if (rv == 0)
    519 			goto out;
    520 
    521 		if (user == 0) {
    522 			if (pcb->pcb_onfault) {
    523 				frame->tf_r0 = rv;
    524 				goto copyfault;
    525 			}
    526 			printf("[u]vm_fault(%p, %lx, %x, 0) -> %x\n",
    527 			    map, va, ftype, rv);
    528 			goto we_re_toast;
    529 		}
    530 
    531 		report_abort("", fault_status, fault_address, fault_pc);
    532 		if (rv == ENOMEM) {
    533 			printf("UVM: pid %d (%s), uid %d killed: "
    534 			       "out of swap\n", p->p_pid, p->p_comm,
    535 			       p->p_cred && p->p_ucred ?
    536 			       p->p_ucred->cr_uid : -1);
    537 			trapsignal(l, SIGKILL, TRAP_CODE);
    538 		} else
    539 			trapsignal(l, SIGSEGV, TRAP_CODE);
    540 		break;
    541 	    }
    542 	}
    543 
    544  out:
    545 	/* Call userret() if it was a USR mode fault */
    546 	if (user)
    547 		userret(l);
    548 }
    549 
    550 
    551 /*
    552  * void prefetch_abort_handler(trapframe_t *frame)
    553  *
    554  * Abort handler called when instruction execution occurs at
    555  * a non existent or restricted (access permissions) memory page.
    556  * If the address is invalid and we were in SVC mode then panic as
    557  * the kernel should never prefetch abort.
    558  * If the address is invalid and the page is mapped then the user process
    559  * does no have read permission so send it a signal.
    560  * Otherwise fault the page in and try again.
    561  */
    562 
    563 extern int kernel_debug;
    564 
    565 void
    566 prefetch_abort_handler(frame)
    567 	trapframe_t *frame;
    568 {
    569 	struct lwp *l;
    570 	struct proc *p;
    571 	struct vm_map *map;
    572 	vaddr_t fault_pc, va;
    573 	int error;
    574 
    575 	/*
    576 	 * Enable IRQ's (disabled by the abort) This always comes
    577 	 * from user mode so we know interrupts were not disabled.
    578 	 * But we check anyway.
    579 	 */
    580 	if (!(frame->tf_spsr & I32_bit))
    581 		enable_interrupts(I32_bit);
    582 
    583 #ifdef DEBUG
    584 	if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE)
    585 		panic("prefetch_abort_handler: not in SVC32 mode");
    586 #endif
    587 
    588 	/* Update vmmeter statistics */
    589 	uvmexp.traps++;
    590 
    591 	/* Call the cpu specific abort fixup routine */
    592 	error = cpu_prefetchabt_fixup(frame);
    593 	if (error == ABORT_FIXUP_RETURN)
    594 		return;
    595 	if (error == ABORT_FIXUP_FAILED)
    596 		panic("prefetch abort fixup failed\n");
    597 
    598 	/* Get the current proc structure or proc0 if there is none */
    599 	if ((l = curlwp) == NULL) {
    600 		l = &lwp0;
    601 #ifdef DEBUG
    602 		printf("Prefetch abort with curlwp == 0\n");
    603 #endif
    604 	}
    605 	p = l->l_proc;
    606 
    607 #ifdef PMAP_DEBUG
    608 	if (pmap_debug_level >= 0)
    609 		printf("prefetch fault in process %p %s\n", p, p->p_comm);
    610 #endif
    611 
    612 	/* Get fault address */
    613 	fault_pc = frame->tf_pc;
    614 	va = trunc_page(fault_pc);
    615 
    616 	/* Was the prefectch abort from USR32 mode ? */
    617 	if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) {
    618 		l->l_addr->u_pcb.pcb_tf = frame;
    619 	} else {
    620 		/*
    621 		 * All the kernel code pages are loaded at boot time
    622 		 * and do not get paged
    623 		 */
    624 	        panic("Prefetch abort in non-USR mode (frame=%p PC=0x%08lx)\n",
    625 	            frame, fault_pc);
    626 	}
    627 
    628 	map = &p->p_vmspace->vm_map;
    629 
    630 #ifdef PMAP_DEBUG
    631 	if (pmap_debug_level >= 0)
    632 		printf("prefetch_abort: PC = %08lx\n", fault_pc);
    633 #endif
    634 	/* Ok validate the address, can only execute in USER space */
    635 	if (fault_pc < VM_MIN_ADDRESS || fault_pc >= VM_MAXUSER_ADDRESS) {
    636 #ifdef DEBUG
    637 		printf("prefetch: pc (%08lx) not in user process space\n",
    638 		    fault_pc);
    639 #endif
    640 		trapsignal(l, SIGSEGV, fault_pc);
    641 		userret(l);
    642 		return;
    643 	}
    644 
    645 #ifdef CPU_SA110
    646 	/*
    647 	 * There are bugs in the rev K SA110.  This is a check for one
    648 	 * of them.
    649 	 */
    650 	if (curcpu()->ci_cputype == CPU_ID_SA110 && curcpu()->ci_cpurev < 3) {
    651 		/* Always current pmap */
    652 		pt_entry_t *pte = vtopte((vaddr_t) fault_pc);
    653 		struct pmap *pmap = p->p_vmspace->vm_map.pmap;
    654 
    655 		if (pmap_pde_v(pmap_pde(pmap, (vaddr_t) fault_pc)) &&
    656 		    pmap_pte_v(pte)) {
    657 			if (kernel_debug & 1) {
    658 				printf("prefetch_abort: page is already "
    659 				    "mapped - pte=%p *pte=%08x\n", pte, *pte);
    660 				printf("prefetch_abort: pc=%08lx proc=%p "
    661 				    "process=%s\n", fault_pc, p, p->p_comm);
    662 				printf("prefetch_abort: far=%08x fs=%x\n",
    663 				    cpu_faultaddress(), cpu_faultstatus());
    664 				printf("prefetch_abort: trapframe=%08x\n",
    665 				    (u_int)frame);
    666 			}
    667 #ifdef DDB
    668 			if (kernel_debug & 2)
    669 				Debugger();
    670 #endif
    671 		}
    672 	}
    673 #endif /* CPU_SA110 */
    674 
    675 	if (pmap_handled_emulation(map->pmap, va))
    676 		goto out;
    677 
    678 	if (current_intr_depth > 0) {
    679 #ifdef DDB
    680 		printf("Non-emulated prefetch abort with intr_depth > 0\n");
    681 		kdb_trap(-1, frame);
    682 		return;
    683 #else
    684 		panic("Prefetch Abort with intr_depth > 0");
    685 #endif
    686 	}
    687 
    688 	error = uvm_fault(map, va, 0, VM_PROT_READ);
    689 	if (error == 0)
    690 		goto out;
    691 
    692 	if (error == ENOMEM) {
    693 		printf("UVM: pid %d (%s), uid %d killed: "
    694 		    "out of swap\n", p->p_pid, p->p_comm,
    695 		    p->p_cred && p->p_ucred ?
    696 		    p->p_ucred->cr_uid : -1);
    697 		trapsignal(l, SIGKILL, fault_pc);
    698 	} else
    699 		trapsignal(l, SIGSEGV, fault_pc);
    700  out:
    701 	userret(l);
    702 }
    703 
    704 int
    705 cowfault(va)
    706 	vaddr_t va;
    707 {
    708 	struct vmspace *vm;
    709 	int error;
    710 
    711 	if (va >= VM_MAXUSER_ADDRESS)
    712 		return (EFAULT);
    713 
    714 	/* uvm_fault can't be called from within an interrupt */
    715 	KASSERT(current_intr_depth == 0);
    716 
    717 	vm = curproc->p_vmspace;
    718 	error = uvm_fault(&vm->vm_map, va, 0, VM_PROT_WRITE);
    719 	return error;
    720 }
    721