vm_machdep.c revision 83276
1/*- 2 * Copyright (c) 1982, 1986 The Regents of the University of California. 3 * Copyright (c) 1989, 1990 William Jolitz 4 * Copyright (c) 1994 John Dyson 5 * Copyright (c) 2001 Jake Burkholder. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * the Systems Programming Group of the University of Utah Computer 10 * Science Department, and William Jolitz. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * from: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 41 * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ 42 * from: FreeBSD: src/sys/i386/i386/vm_machdep.c,v 1.167 2001/07/12 43 * $FreeBSD: head/sys/sparc64/sparc64/vm_machdep.c 83276 2001-09-10 04:28:58Z peter $ 44 */ 45 46#include <sys/param.h> 47#include <sys/systm.h> 48#include <sys/proc.h> 49#include <sys/bio.h> 50#include <sys/buf.h> 51#include <sys/unistd.h> 52#include <sys/user.h> 53#include <sys/vmmeter.h> 54 55#include <dev/ofw/openfirm.h> 56 57#include <vm/vm.h> 58#include <vm/vm_extern.h> 59#include <vm/pmap.h> 60 61#include <machine/cpu.h> 62#include <machine/frame.h> 63#include <machine/md_var.h> 64#include <machine/tstate.h> 65 66void 67cpu_exit(struct proc *p) 68{ 69} 70 71/* 72 * Finish a fork operation, with process p2 nearly set up. 73 * Copy and update the pcb, set up the stack so that the child 74 * ready to run and return to user mode. 75 */ 76void 77cpu_fork(struct proc *p1, struct proc *p2, int flags) 78{ 79 struct trapframe *tf; 80 struct frame *fp; 81 struct pcb *pcb; 82 83 KASSERT(p1 == curproc || p1 == &proc0, 84 ("cpu_fork: p1 not curproc and not proc0")); 85 86 if ((flags & RFPROC) == 0) 87 return; 88 89 /* 90 * Ensure that p1's pcb is up to date. 91 */ 92 pcb = &p2->p_addr->u_pcb; 93 p1->p_addr->u_pcb.pcb_y = rd(y); 94 p1->p_addr->u_pcb.pcb_fpstate.fp_fprs = rd(fprs); 95 if ((p1->p_frame->tf_tstate & TSTATE_PEF) != 0) { 96 mtx_lock_spin(&sched_lock); 97 savefpctx(&pcb->pcb_fpstate); 98 mtx_unlock_spin(&sched_lock); 99 } 100 /* Make sure the copied windows are spilled. */ 101 __asm __volatile("flushw"); 102 /* Copy the pcb (this will copy the windows saved in the pcb, too). */ 103 pcb = &p2->p_addr->u_pcb; 104 bcopy(&p1->p_addr->u_pcb, pcb, sizeof(*pcb)); 105 pcb->pcb_cwp = 2; 106 107 /* 108 * Create a new fresh stack for the new process. 109 * Copy the trap frame for the return to user mode as if from a 110 * syscall. This copies most of the user mode register values. 111 */ 112 tf = (struct trapframe *)((caddr_t)p2->p_addr + UPAGES * PAGE_SIZE) - 1; 113 bcopy(p1->p_frame, tf, sizeof(*tf)); 114 115 tf->tf_out[0] = 0; /* Child returns zero */ 116 tf->tf_out[1] = 1; /* XXX i386 returns 1 in %edx */ 117 tf->tf_tstate &= ~(TSTATE_XCC_C | TSTATE_CWP_MASK); /* success */ 118 119 p2->p_frame = tf; 120 fp = (struct frame *)tf - 1; 121 fp->f_local[0] = (u_long)fork_return; 122 fp->f_local[1] = (u_long)p2; 123 fp->f_local[2] = (u_long)tf; 124 pcb->pcb_cwp = 2; 125 pcb->pcb_fp = (u_long)fp - SPOFF; 126 pcb->pcb_pc = (u_long)fork_trampoline - 8; 127 128 /* 129 * Now, cpu_switch() can schedule the new process. 130 */ 131} 132 133void 134cpu_reset(void) 135{ 136 OF_exit(); 137} 138 139/* 140 * Intercept the return address from a freshly forked process that has NOT 141 * been scheduled yet. 142 * 143 * This is needed to make kernel threads stay in kernel mode. 144 */ 145void 146cpu_set_fork_handler(struct proc *p, void (*func)(void *), void *arg) 147{ 148 struct frame *fp; 149 struct pcb *pcb; 150 151 pcb = &p->p_addr->u_pcb; 152 fp = (struct frame *)(pcb->pcb_fp + SPOFF); 153 fp->f_local[0] = (u_long)func; 154 fp->f_local[1] = (u_long)arg; 155} 156 157void 158cpu_wait(struct proc *p) 159{ 160} 161 162void 163swi_vm(void *v) 164{ 165 TODO; 166} 167 168int 169vm_fault_quick(caddr_t v, int prot) 170{ 171 TODO; 172 return (0); 173} 174 175void 176vmapbuf(struct buf *bp) 177{ 178 TODO; 179} 180 181void 182vunmapbuf(struct buf *bp) 183{ 184 TODO; 185} 186