diff options
author | jake <jake@FreeBSD.org> | 2001-08-06 02:32:38 +0000 |
---|---|---|
committer | jake <jake@FreeBSD.org> | 2001-08-06 02:32:38 +0000 |
commit | da5146baa04a5623b0cf1ad7287f3c712da12011 (patch) | |
tree | 30e30cce8558e318630d1ad6f4c6527b96820884 /sys | |
parent | 9ce2e785400efba330d4d0593f5eb92310bc1eb3 (diff) | |
download | FreeBSD-src-da5146baa04a5623b0cf1ad7287f3c712da12011.zip FreeBSD-src-da5146baa04a5623b0cf1ad7287f3c712da12011.tar.gz |
Add page fault and high level tsb miss handlers.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/sparc64/sparc64/trap.c | 162 |
1 files changed, 159 insertions, 3 deletions
diff --git a/sys/sparc64/sparc64/trap.c b/sys/sparc64/sparc64/trap.c index 40548d9..6fa6f36 100644 --- a/sys/sparc64/sparc64/trap.c +++ b/sys/sparc64/sparc64/trap.c @@ -1,4 +1,43 @@ /*- + * Copyright (C) 1994, David Greenman + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the University of Utah, and William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 + * from: FreeBSD: src/sys/i386/i386/trap.c,v 1.197 2001/07/19 + */ +/*- * Copyright (c) 2001 Jake Burkholder. * All rights reserved. * @@ -37,8 +76,11 @@ #include <sys/user.h> #include <vm/vm.h> +#include <vm/pmap.h> +#include <vm/vm_extern.h> #include <vm/vm_param.h> #include <vm/vm_kern.h> +#include <vm/vm_map.h> #include <vm/vm_page.h> #include <machine/frame.h> @@ -50,6 +92,7 @@ #include <machine/tsb.h> void trap(struct trapframe *tf); +int trap_mmu_fault(struct proc *p, struct trapframe *tf); const char *trap_msg[] = { "reserved", @@ -93,7 +136,10 @@ trap(struct trapframe *tf) int ucode; int sig; - p = curproc; + KASSERT(PCPU_GET(curproc) != NULL, ("trap: curproc NULL")); + KASSERT(PCPU_GET(curpcb) != NULL, ("trap: curpcb NULL")); + + p = PCPU_GET(curproc); ucode = tf->tf_type; /* XXX */ mtx_lock_spin(&sched_lock); @@ -105,16 +151,21 @@ trap(struct trapframe *tf) if (fp_enable_proc(p)) goto user; else { - sig = SIGFPE; + sig = SIGFPE; goto trapsig; } break; #ifdef DDB case T_BREAKPOINT | T_KERNEL: if (kdb_trap(tf) != 0) - return; + goto out; break; #endif + case T_DMMU_MISS | T_KERNEL: + case T_DMMU_PROT | T_KERNEL: + if (trap_mmu_fault(p, tf) == 0) + goto out; + break; default: break; } @@ -135,3 +186,108 @@ user: out: return; } + +int +trap_mmu_fault(struct proc *p, struct trapframe *tf) +{ + struct mmuframe *mf; + struct vmspace *vm; + vm_offset_t va; + vm_prot_t type; + int flags; + int rv; + + KASSERT(p->p_vmspace != NULL, ("trap_dmmu_miss: vmspace NULL")); + + rv = KERN_FAILURE; + mf = tf->tf_arg; + va = TLB_TAR_VA(mf->mf_tar); + switch (tf->tf_type) { + case T_DMMU_MISS | T_KERNEL: + /* + * If the context is not nucleus, this is a fault on + * non-kernel virtual memory. + */ + if (TLB_TAR_CTX(mf->mf_tar) != TLB_CTX_KERNEL && + PCPU_GET(curpcb)->pcb_onfault == NULL) + break; + + /* + * First try the tsb. The primary tsb was already searched. + */ + vm = p->p_vmspace; + if (tsb_miss(&vm->vm_pmap, tf->tf_type, mf) == 0) { + rv = KERN_SUCCESS; + break; + } + + /* + * Not found, call the vm system. + */ + + /* + * XXX!!! + */ + type = VM_PROT_READ; + flags = VM_FAULT_NORMAL; + + /* + * Keep the process from being swapped out at this critical + * time. + */ + PROC_LOCK(p); + ++p->p_lock; + PROC_UNLOCK(p); + + /* + * Grow the stack if necessary. vm_map_growstack only fails + * if the va falls into a growable stack region and the stack + * growth fails. If it succeeds, or the va was not within a + * growable stack region, fault in the user page. + */ + if (vm_map_growstack(p, va) != KERN_SUCCESS) + rv = KERN_FAILURE; + else + rv = vm_fault(&vm->vm_map, va, type, flags); + + /* + * Now the process can be swapped again. + */ + PROC_LOCK(p); + --p->p_lock; + PROC_UNLOCK(p); + break; + case T_DMMU_PROT | T_KERNEL: + /* + * If the context is not nucleus, this is a fault on + * non-kernel virtual memory. + */ + if (TLB_TAR_CTX(mf->mf_tar) != TLB_CTX_KERNEL && + PCPU_GET(curpcb)->pcb_onfault == NULL) + break; + + /* + * Only look in the tsb. Write access to an unmapped page + * causes a miss first, so the page must have already been + * brought in by vm_fault, we just need to find the tte and + * update the write bit. XXX How do we tell them vm system + * that we are now writing? + */ + vm = p->p_vmspace; + if (tsb_miss(&vm->vm_pmap, tf->tf_type, mf) == 0) + rv = KERN_SUCCESS; + break; + default: + break; + } + if (rv == KERN_SUCCESS) + return (0); + if (tf->tf_type & T_KERNEL) { + if (PCPU_GET(curpcb)->pcb_onfault != NULL) { + tf->tf_tpc = PCPU_GET(curpcb)->pcb_onfault; + tf->tf_tnpc = tf->tf_tpc + 4; + return (0); + } + } + return (rv == KERN_PROTECTION_FAILURE ? SIGBUS : SIGSEGV); +} |