vm_machdep.c revision 118893
136865Sdfr/*- 236865Sdfr * Copyright (c) 1982, 1986 The Regents of the University of California. 336865Sdfr * Copyright (c) 1989, 1990 William Jolitz 436865Sdfr * Copyright (c) 1994 John Dyson 536865Sdfr * All rights reserved. 636865Sdfr * 736865Sdfr * This code is derived from software contributed to Berkeley by 836865Sdfr * the Systems Programming Group of the University of Utah Computer 936865Sdfr * Science Department, and William Jolitz. 1036865Sdfr * 1136865Sdfr * Redistribution and use in source and binary forms, with or without 1236865Sdfr * modification, are permitted provided that the following conditions 1336865Sdfr * are met: 1436865Sdfr * 1. Redistributions of source code must retain the above copyright 1536865Sdfr * notice, this list of conditions and the following disclaimer. 1636865Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1736865Sdfr * notice, this list of conditions and the following disclaimer in the 1836865Sdfr * documentation and/or other materials provided with the distribution. 1936865Sdfr * 3. All advertising materials mentioning features or use of this software 2036865Sdfr * must display the following acknowledgement: 2136865Sdfr * This product includes software developed by the University of 2236865Sdfr * California, Berkeley and its contributors. 2336865Sdfr * 4. Neither the name of the University nor the names of its contributors 2436865Sdfr * may be used to endorse or promote products derived from this software 2536865Sdfr * without specific prior written permission. 2636865Sdfr * 2736865Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2836865Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2936865Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3036865Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3136865Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3236865Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3336865Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3436865Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3536865Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3636865Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3736865Sdfr * SUCH DAMAGE. 3836865Sdfr * 3936865Sdfr * from: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 4036865Sdfr * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ 4150477Speter * $FreeBSD: head/sys/powerpc/aim/vm_machdep.c 118893 2003-08-14 03:56:24Z grehan $ 4236865Sdfr */ 4336865Sdfr/* 4436865Sdfr * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. 4536865Sdfr * All rights reserved. 4636865Sdfr * 4736865Sdfr * Author: Chris G. Demetriou 4836865Sdfr * 4936865Sdfr * Permission to use, copy, modify and distribute this software and 5036865Sdfr * its documentation is hereby granted, provided that both the copyright 5136865Sdfr * notice and this permission notice appear in all copies of the 5236865Sdfr * software, derivative works or modified versions, and any portions 5336865Sdfr * thereof, and that both notices appear in supporting documentation. 5436865Sdfr * 5536865Sdfr * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 5636865Sdfr * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 5736865Sdfr * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 5836865Sdfr * 5936865Sdfr * Carnegie Mellon requests users of this software to return to 6036865Sdfr * 6136865Sdfr * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 6236865Sdfr * School of Computer Science 6336865Sdfr * Carnegie Mellon University 6436865Sdfr * Pittsburgh PA 15213-3890 6536865Sdfr * 6636865Sdfr * any improvements or extensions that they make and grant Carnegie the 6736865Sdfr * rights to redistribute these changes. 6836865Sdfr */ 6936865Sdfr 70118239Speter#include "opt_kstack_pages.h" 71118239Speter 7236865Sdfr#include <sys/param.h> 7336865Sdfr#include <sys/systm.h> 7436865Sdfr#include <sys/proc.h> 7536865Sdfr#include <sys/malloc.h> 7660041Sphk#include <sys/bio.h> 7736865Sdfr#include <sys/buf.h> 7885201Smp#include <sys/ktr.h> 7985201Smp#include <sys/lock.h> 8067365Sjhb#include <sys/mutex.h> 8136865Sdfr#include <sys/vnode.h> 8236865Sdfr#include <sys/vmmeter.h> 8336865Sdfr#include <sys/kernel.h> 8436865Sdfr#include <sys/sysctl.h> 8554207Speter#include <sys/unistd.h> 8636865Sdfr 8736865Sdfr#include <machine/clock.h> 8836865Sdfr#include <machine/cpu.h> 8941499Sdfr#include <machine/fpu.h> 9097397Sbenno#include <machine/frame.h> 9136865Sdfr#include <machine/md_var.h> 9236865Sdfr 9378342Sbenno#include <dev/ofw/openfirm.h> 9478342Sbenno 9536865Sdfr#include <vm/vm.h> 9636865Sdfr#include <vm/vm_param.h> 9736865Sdfr#include <vm/vm_kern.h> 9836865Sdfr#include <vm/vm_page.h> 9936865Sdfr#include <vm/vm_map.h> 10036865Sdfr#include <vm/vm_extern.h> 10136865Sdfr 10236865Sdfr#include <sys/user.h> 10336865Sdfr 10436865Sdfr/* 10536865Sdfr * Finish a fork operation, with process p2 nearly set up. 10636865Sdfr * Copy and update the pcb, set up the stack so that the child 10736865Sdfr * ready to run and return to user mode. 10836865Sdfr */ 10936865Sdfrvoid 11090361Sjuliancpu_fork(struct thread *td1, struct proc *p2, struct thread *td2, int flags) 11136865Sdfr{ 11284977Sbenno struct proc *p1; 11384977Sbenno struct trapframe *tf; 11484977Sbenno struct callframe *cf; 11590643Sbenno struct pcb *pcb; 11684977Sbenno 11791467Sbenno KASSERT(td1 == curthread || td1 == &thread0, 11890643Sbenno ("cpu_fork: p1 not curproc and not proc0")); 11984977Sbenno CTR3(KTR_PROC, "cpu_fork: called td1=%08x p2=%08x flags=%x", (u_int)td1, (u_int)p2, flags); 12084977Sbenno 12184977Sbenno if ((flags & RFPROC) == 0) 12284977Sbenno return; 12384977Sbenno 12484977Sbenno p1 = td1->td_proc; 12584977Sbenno 12691467Sbenno pcb = (struct pcb *)((td2->td_kstack + KSTACK_PAGES * PAGE_SIZE - 12791467Sbenno sizeof(struct pcb)) & ~0x2fU); 12890643Sbenno td2->td_pcb = pcb; 12984977Sbenno 13090643Sbenno /* Copy the pcb */ 13190643Sbenno bcopy(td1->td_pcb, pcb, sizeof(struct pcb)); 13284977Sbenno 13384977Sbenno /* 13490643Sbenno * Create a fresh stack for the new process. 13584977Sbenno * Copy the trap frame for the return to user mode as if from a 13684977Sbenno * syscall. This copies most of the user mode register values. 13784977Sbenno */ 13890643Sbenno tf = (struct trapframe *)pcb - 1; 13990643Sbenno bcopy(td1->td_frame, tf, sizeof(*tf)); 14084977Sbenno 14197397Sbenno /* Set up trap frame. */ 14297397Sbenno tf->fixreg[FIRSTARG] = 0; 14397397Sbenno tf->fixreg[FIRSTARG + 1] = 0; 14497397Sbenno tf->cr &= ~0x10000000; 14590643Sbenno 14690643Sbenno td2->td_frame = tf; 14790643Sbenno 14890643Sbenno cf = (struct callframe *)tf - 1; 14991467Sbenno cf->cf_func = (register_t)fork_return; 15091467Sbenno cf->cf_arg0 = (register_t)td2; 15191467Sbenno cf->cf_arg1 = (register_t)tf; 15284977Sbenno 15391467Sbenno pcb->pcb_sp = (register_t)cf; 15491467Sbenno pcb->pcb_lr = (register_t)fork_trampoline; 155105611Sgrehan pcb->pcb_usr = kernel_pmap->pm_sr[USER_SR]; 15684977Sbenno 15790643Sbenno /* 15890643Sbenno * Now cpu_switch() can schedule the new process. 15990643Sbenno */ 16036865Sdfr} 16136865Sdfr 16236865Sdfr/* 16336865Sdfr * Intercept the return address from a freshly forked process that has NOT 16436865Sdfr * been scheduled yet. 16536865Sdfr * 16636865Sdfr * This is needed to make kernel threads stay in kernel mode. 16736865Sdfr */ 16836865Sdfrvoid 16983682Smpcpu_set_fork_handler(td, func, arg) 17083682Smp struct thread *td; 17192842Salfred void (*func)(void *); 17248391Speter void *arg; 17336865Sdfr{ 17484977Sbenno struct callframe *cf; 17584977Sbenno 17684977Sbenno CTR3(KTR_PROC, "cpu_set_fork_handler: called with td=%08x func=%08x arg=%08x", 17784977Sbenno (u_int)td, (u_int)func, (u_int)arg); 17884977Sbenno 17991467Sbenno cf = (struct callframe *)td->td_pcb->pcb_sp; 18084977Sbenno 18191467Sbenno cf->cf_func = (register_t)func; 18291467Sbenno cf->cf_arg0 = (register_t)arg; 18336865Sdfr} 18436865Sdfr 18536865Sdfr/* 18636865Sdfr * cpu_exit is called as the last action during exit. 18736865Sdfr * We release the address space of the process, block interrupts, 18836865Sdfr * and call switch_exit. switch_exit switches to proc0's PCB and stack, 18936865Sdfr * then jumps into the middle of cpu_switch, as if it were switching 19036865Sdfr * from proc0. 19136865Sdfr */ 19236865Sdfrvoid 19383682Smpcpu_exit(td) 19483682Smp register struct thread *td; 19536865Sdfr{ 19636865Sdfr} 19736865Sdfr 19836865Sdfrvoid 19998765Sjakecpu_sched_exit(td) 20098765Sjake register struct thread *td; 20198765Sjake{ 20298765Sjake} 20398765Sjake 20483276Speter/* Temporary helper */ 20583276Spetervoid 206118893Sgrehancpu_throw(struct thread *old, struct thread *new) 20783276Speter{ 20883276Speter 209118893Sgrehan cpu_switch(old, new); 21083276Speter panic("cpu_throw() didn't"); 21136865Sdfr} 21236865Sdfr 21336865Sdfr/* 21465557Sjasone * Reset back to firmware. 21536865Sdfr */ 21636865Sdfrvoid 21736865Sdfrcpu_reset() 21836865Sdfr{ 21978342Sbenno OF_exit(); 22036865Sdfr} 22136865Sdfr 22236865Sdfr/* 22336865Sdfr * Software interrupt handler for queued VM system processing. 22436865Sdfr */ 22536865Sdfrvoid 22667551Sjhbswi_vm(void *dummy) 22736865Sdfr{ 22878342Sbenno#if 0 /* XXX: Don't have busdma stuff yet */ 22936865Sdfr if (busdma_swi_pending != 0) 23036865Sdfr busdma_swi(); 23178342Sbenno#endif 23236865Sdfr} 23336865Sdfr 23436865Sdfr/* 23536865Sdfr * Tell whether this address is in some physical memory region. 23636865Sdfr * Currently used by the kernel coredump code in order to avoid 23736865Sdfr * dumping the ``ISA memory hole'' which could cause indefinite hangs, 23836865Sdfr * or other unpredictable behaviour. 23936865Sdfr */ 24036865Sdfr 24136865Sdfr 24236865Sdfrint 24336865Sdfris_physical_memory(addr) 24436865Sdfr vm_offset_t addr; 24536865Sdfr{ 24636865Sdfr /* 24736865Sdfr * stuff other tests for known memory-mapped devices (PCI?) 24836865Sdfr * here 24936865Sdfr */ 25036865Sdfr 25136865Sdfr return 1; 25236865Sdfr} 25399659Sbenno 25499659Sbenno/* 25599659Sbenno * KSE functions 25699659Sbenno */ 25799659Sbennovoid 25899659Sbennocpu_thread_exit(struct thread *td) 25999659Sbenno{ 26099659Sbenno 26199659Sbenno return; 26299659Sbenno} 26399659Sbenno 26499659Sbennovoid 265107719Sjuliancpu_thread_clean(struct thread *td) 266107180Smux{ 267107180Smux} 268107180Smux 269107180Smuxvoid 27099659Sbennocpu_thread_setup(struct thread *td) 27199659Sbenno{ 27299659Sbenno 27399659Sbenno return; 27499659Sbenno} 27599659Sbenno 27699659Sbennovoid 277115858Smarcelcpu_set_upcall(struct thread *td, struct thread *td0) 27899659Sbenno{ 27999659Sbenno 28099659Sbenno return; 28199659Sbenno} 28299659Sbenno 28399659Sbennovoid 284111028Sjeffcpu_set_upcall_kse(struct thread *td, struct kse_upcall *ku) 28599659Sbenno{ 28699659Sbenno 28799659Sbenno return; 28899659Sbenno} 289