Index: head/sys/alpha/alpha/vm_machdep.c =================================================================== --- head/sys/alpha/alpha/vm_machdep.c (revision 84380) +++ head/sys/alpha/alpha/vm_machdep.c (revision 84381) @@ -1,399 +1,399 @@ /*- * Copyright (c) 1982, 1986 The Regents of the University of California. * Copyright (c) 1989, 1990 William Jolitz * Copyright (c) 1994 John Dyson * All rights reserved. * * This code is derived from software contributed to Berkeley by * the Systems Programming Group of the University of Utah Computer * Science Department, 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: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ * $FreeBSD$ */ /* * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. * All rights reserved. * * Author: Chris G. Demetriou * * Permission to use, copy, modify and distribute this software and * its documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * quick version of vm_fault */ int vm_fault_quick(v, prot) caddr_t v; int prot; { int r; if (prot & VM_PROT_WRITE) r = subyte(v, fubyte(v)); else r = fubyte(v); return(r); } /* * Finish a fork operation, with process p2 nearly set up. * Copy and update the pcb, set up the stack so that the child * ready to run and return to user mode. */ void cpu_fork(td1, p2, flags) register struct thread *td1; register struct proc *p2; int flags; { struct proc *p1; struct thread *td2; struct trapframe *p2tf; if ((flags & RFPROC) == 0) return; p1 = td1->td_proc; td2 = &p2->p_thread; td2->td_pcb = (struct pcb *) (td2->td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1; td2->td_md.md_flags = td1->td_md.md_flags & (MDP_FPUSED | MDP_UAC_MASK); /* * Cache the physical address of the pcb, so we can * swap to it easily. */ td2->td_md.md_pcbpaddr = (void*)vtophys((vm_offset_t)td2->td_pcb); /* * Copy floating point state from the FP chip to the PCB * if this process has state stored there. */ alpha_fpstate_save(td1, 0); /* * Copy pcb and stack from proc p1 to p2. We do this as * cheaply as possible, copying only the active part of the * stack. The stack and pcb need to agree. Make sure that the * new process has FEN disabled. */ bcopy(td1->td_pcb, td2->td_pcb, sizeof(struct pcb)); td2->td_pcb->pcb_hw.apcb_usp = alpha_pal_rdusp(); td2->td_pcb->pcb_hw.apcb_flags &= ~ALPHA_PCB_FLAGS_FEN; /* * Set the floating point state. */ if ((td2->td_pcb->pcb_fp_control & IEEE_INHERIT) == 0) { td2->td_pcb->pcb_fp_control = 0; td2->td_pcb->pcb_fp.fpr_cr = (FPCR_DYN_NORMAL | FPCR_INVD | FPCR_DZED | FPCR_OVFD | FPCR_INED | FPCR_UNFD); } /* * Arrange for a non-local goto when the new process * is started, to resume here, returning nonzero from setjmp. */ #ifdef DIAGNOSTIC alpha_fpstate_check(td1); #endif /* * Create the child's kernel stack, from scratch. * * Pick a stack pointer, leaving room for a trapframe; * copy trapframe from parent so return to user mode * will be to right address, with correct registers. */ td2->td_frame = (struct trapframe *)td2->td_pcb - 1; bcopy(td1->td_frame, td2->td_frame, sizeof(struct trapframe)); /* * Set up return-value registers as fork() libc stub expects. */ p2tf = td2->td_frame; p2tf->tf_regs[FRAME_V0] = 0; /* child's pid (linux) */ p2tf->tf_regs[FRAME_A3] = 0; /* no error */ p2tf->tf_regs[FRAME_A4] = 1; /* is child (FreeBSD) */ /* * Arrange for continuation at fork_return(), which * will return to exception_return(). Note that the child * process doesn't stay in the kernel for long! */ td2->td_pcb->pcb_hw.apcb_ksp = (u_int64_t)p2tf; td2->td_pcb->pcb_context[0] = (u_int64_t)fork_return; /* s0: a0 */ td2->td_pcb->pcb_context[1] = (u_int64_t)exception_return;/* s1: ra */ td2->td_pcb->pcb_context[2] = (u_long)td2; /* s2: a1 */ td2->td_pcb->pcb_context[7] = (u_int64_t)fork_trampoline; /* ra: magic*/ #ifdef SMP /* * We start off at a nesting level of 1 within the kernel. */ td2->td_md.md_kernnest = 1; #endif } /* * Intercept the return address from a freshly forked process that has NOT * been scheduled yet. * * This is needed to make kernel threads stay in kernel mode. */ void cpu_set_fork_handler(td, func, arg) struct thread *td; void (*func) __P((void *)); void *arg; { /* * Note that the trap frame follows the args, so the function * is really called like this: func(arg, frame); */ td->td_pcb->pcb_context[0] = (u_long) func; td->td_pcb->pcb_context[2] = (u_long) arg; } /* * cpu_exit is called as the last action during exit. * We release the address space of the process, block interrupts, * and call switch_exit. switch_exit switches to proc0's PCB and stack, * then jumps into the middle of cpu_switch, as if it were switching * from proc0. */ void cpu_exit(td) register struct thread *td; { alpha_fpstate_drop(td); } void cpu_wait(p) struct proc *p; { } /* * Dump the machine specific header information at the start of a core dump. */ int cpu_coredump(td, vp, cred) struct thread *td; struct vnode *vp; struct ucred *cred; { int error; /* XXXKSE this is totally bogus! (and insecure) */ error = vn_rdwr(UIO_WRITE, vp, (caddr_t) td->td_proc->p_uarea, ctob(UAREA_PAGES), (off_t)0, UIO_SYSSPACE, IO_UNIT, cred, (int *)NULL, td); if (error) return error; error = vn_rdwr(UIO_WRITE, vp, (caddr_t) td->td_kstack, ctob(KSTACK_PAGES), (off_t)ctob(UAREA_PAGES), UIO_SYSSPACE, IO_UNIT, cred, (int *)NULL, td); return error; } /* * Map an IO request into kernel virtual address space. * * All requests are (re)mapped into kernel VA space. * Notice that we use b_bufsize for the size of the buffer * to be mapped. b_bcount might be modified by the driver. */ void vmapbuf(bp) register struct buf *bp; { register caddr_t addr, v, kva; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vmapbuf"); for (v = bp->b_saveaddr, addr = (caddr_t)trunc_page(bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE, v += PAGE_SIZE) { /* * Do the vm_fault if needed; do the copy-on-write thing * when reading stuff off device into memory. */ - vm_fault_quick(addr, + vm_fault_quick((addr >= bp->b_data) ? addr : bp->b_data, (bp->b_iocmd == BIO_READ)?(VM_PROT_READ|VM_PROT_WRITE):VM_PROT_READ); pa = trunc_page(pmap_kextract((vm_offset_t) addr)); if (pa == 0) panic("vmapbuf: page not present"); vm_page_hold(PHYS_TO_VM_PAGE(pa)); pmap_kenter((vm_offset_t) v, pa); } kva = bp->b_saveaddr; bp->b_saveaddr = bp->b_data; bp->b_data = kva + (((vm_offset_t) bp->b_data) & PAGE_MASK); } /* * Free the io map PTEs associated with this IO operation. * We also invalidate the TLB entries and restore the original b_addr. */ void vunmapbuf(bp) register struct buf *bp; { register caddr_t addr; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vunmapbuf"); for (addr = (caddr_t)trunc_page(bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE) { pa = trunc_page(pmap_kextract((vm_offset_t) addr)); pmap_kremove((vm_offset_t) addr); vm_page_unhold(PHYS_TO_VM_PAGE(pa)); } bp->b_data = bp->b_saveaddr; } /* * Reset back to firmware. */ void cpu_reset() { prom_halt(0); } int grow_stack(p, sp) struct proc *p; size_t sp; { int rv; rv = vm_map_growstack (p, sp); if (rv != KERN_SUCCESS) return (0); return (1); } /* * Software interrupt handler for queued VM system processing. */ void swi_vm(void *dummy) { if (busdma_swi_pending != 0) busdma_swi(); } /* * Tell whether this address is in some physical memory region. * Currently used by the kernel coredump code in order to avoid * dumping the ``ISA memory hole'' which could cause indefinite hangs, * or other unpredictable behaviour. */ int is_physical_memory(addr) vm_offset_t addr; { /* * stuff other tests for known memory-mapped devices (PCI?) * here */ return 1; } Index: head/sys/amd64/amd64/vm_machdep.c =================================================================== --- head/sys/amd64/amd64/vm_machdep.c (revision 84380) +++ head/sys/amd64/amd64/vm_machdep.c (revision 84381) @@ -1,555 +1,555 @@ /*- * Copyright (c) 1982, 1986 The Regents of the University of California. * Copyright (c) 1989, 1990 William Jolitz * Copyright (c) 1994 John Dyson * All rights reserved. * * This code is derived from software contributed to Berkeley by * the Systems Programming Group of the University of Utah Computer * Science Department, 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: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ * $FreeBSD$ */ #include "opt_npx.h" #ifdef PC98 #include "opt_pc98.h" #endif #include "opt_reset.h" #include "opt_isa.h" #include "opt_kstack_pages.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef PC98 #include #else #include #endif static void cpu_reset_real __P((void)); #ifdef SMP static void cpu_reset_proxy __P((void)); static u_int cpu_reset_proxyid; static volatile u_int cpu_reset_proxy_active; #endif extern int _ucodesel, _udatasel; /* * quick version of vm_fault */ int vm_fault_quick(v, prot) caddr_t v; int prot; { int r; if (prot & VM_PROT_WRITE) r = subyte(v, fubyte(v)); else r = fubyte(v); return(r); } /* * Finish a fork operation, with process p2 nearly set up. * Copy and update the pcb, set up the stack so that the child * ready to run and return to user mode. */ void cpu_fork(td1, p2, flags) register struct thread *td1; register struct proc *p2; int flags; { register struct proc *p1; struct thread *td2; struct pcb *pcb2; #ifdef DEV_NPX int savecrit; #endif p1 = td1->td_proc; td2 = &p2->p_thread; if ((flags & RFPROC) == 0) { if ((flags & RFMEM) == 0) { /* unshare user LDT */ struct pcb *pcb1 = td1->td_pcb; struct pcb_ldt *pcb_ldt = pcb1->pcb_ldt; if (pcb_ldt && pcb_ldt->ldt_refcnt > 1) { pcb_ldt = user_ldt_alloc(pcb1,pcb_ldt->ldt_len); if (pcb_ldt == NULL) panic("could not copy LDT"); pcb1->pcb_ldt = pcb_ldt; set_user_ldt(pcb1); user_ldt_free(pcb1); } } return; } /* Ensure that p1's pcb is up to date. */ #ifdef DEV_NPX if (td1 == curthread) td1->td_pcb->pcb_gs = rgs(); savecrit = critical_enter(); if (PCPU_GET(npxthread) == td1) npxsave(&td1->td_pcb->pcb_save); critical_exit(savecrit); #endif /* Point the pcb to the top of the stack */ pcb2 = (struct pcb *)(td2->td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1; td2->td_pcb = pcb2; /* Copy p1's pcb. */ bcopy(td1->td_pcb, pcb2, sizeof(*pcb2)); /* * Create a new fresh stack for the new process. * Copy the trap frame for the return to user mode as if from a * syscall. This copies most of the user mode register values. * The -16 is so we can expand the trapframe if we go to vm86. */ td2->td_frame = (struct trapframe *)((caddr_t)td2->td_pcb - 16) - 1; bcopy(td1->td_frame, td2->td_frame, sizeof(struct trapframe)); td2->td_frame->tf_eax = 0; /* Child returns zero */ td2->td_frame->tf_eflags &= ~PSL_C; /* success */ td2->td_frame->tf_edx = 1; /* * Set registers for trampoline to user mode. Leave space for the * return address on stack. These are the kernel mode register values. */ pcb2->pcb_cr3 = vtophys(vmspace_pmap(p2->p_vmspace)->pm_pdir); pcb2->pcb_edi = 0; pcb2->pcb_esi = (int)fork_return; /* fork_trampoline argument */ pcb2->pcb_ebp = 0; pcb2->pcb_esp = (int)td2->td_frame - sizeof(void *); pcb2->pcb_ebx = (int)td2; /* fork_trampoline argument */ pcb2->pcb_eip = (int)fork_trampoline; /*- * pcb2->pcb_dr*: cloned above. * pcb2->pcb_ldt: duplicated below, if necessary. * pcb2->pcb_savefpu: cloned above. * pcb2->pcb_flags: cloned above. * pcb2->pcb_onfault: cloned above (always NULL here?). * pcb2->pcb_gs: cloned above. * pcb2->pcb_ext: cleared below. */ /* * XXX don't copy the i/o pages. this should probably be fixed. */ pcb2->pcb_ext = 0; /* Copy the LDT, if necessary. */ mtx_lock_spin(&sched_lock); if (pcb2->pcb_ldt != 0) { if (flags & RFMEM) { pcb2->pcb_ldt->ldt_refcnt++; } else { pcb2->pcb_ldt = user_ldt_alloc(pcb2, pcb2->pcb_ldt->ldt_len); if (pcb2->pcb_ldt == NULL) panic("could not copy LDT"); } } mtx_unlock_spin(&sched_lock); /* * Now, cpu_switch() can schedule the new process. * pcb_esp is loaded pointing to the cpu_switch() stack frame * containing the return address when exiting cpu_switch. * This will normally be to fork_trampoline(), which will have * %ebx loaded with the new proc's pointer. fork_trampoline() * will set up a stack to call fork_return(p, frame); to complete * the return to user-mode. */ } /* * Intercept the return address from a freshly forked process that has NOT * been scheduled yet. * * This is needed to make kernel threads stay in kernel mode. */ void cpu_set_fork_handler(td, func, arg) struct thread *td; void (*func) __P((void *)); void *arg; { /* * Note that the trap frame follows the args, so the function * is really called like this: func(arg, frame); */ td->td_pcb->pcb_esi = (int) func; /* function */ td->td_pcb->pcb_ebx = (int) arg; /* first arg */ } void cpu_exit(td) register struct thread *td; { struct pcb *pcb = td->td_pcb; #ifdef DEV_NPX npxexit(td); #endif if (pcb->pcb_ext != 0) { /* * XXX do we need to move the TSS off the allocated pages * before freeing them? (not done here) */ kmem_free(kernel_map, (vm_offset_t)pcb->pcb_ext, ctob(IOPAGES + 1)); pcb->pcb_ext = 0; } if (pcb->pcb_ldt) user_ldt_free(pcb); if (pcb->pcb_flags & PCB_DBREGS) { /* * disable all hardware breakpoints */ reset_dbregs(); pcb->pcb_flags &= ~PCB_DBREGS; } } void cpu_wait(p) struct proc *p; { } /* * Dump the machine specific header information at the start of a core dump. */ int cpu_coredump(td, vp, cred) struct thread *td; struct vnode *vp; struct ucred *cred; { struct proc *p = td->td_proc; int error; caddr_t tempuser; tempuser = malloc(ctob(UAREA_PAGES + KSTACK_PAGES), M_TEMP, M_WAITOK | M_ZERO); if (!tempuser) return EINVAL; bcopy(p->p_uarea, tempuser, sizeof(struct user)); #if 0 /* XXXKSE - broken, fixme!!!!! td_frame is in kstack! */ bcopy(td->td_frame, tempuser + ((caddr_t) td->td_frame - (caddr_t) p->p_uarea), sizeof(struct trapframe)); #endif error = vn_rdwr(UIO_WRITE, vp, (caddr_t) tempuser, ctob(UAREA_PAGES + KSTACK_PAGES), (off_t)0, UIO_SYSSPACE, IO_UNIT, cred, (int *)NULL, td); free(tempuser, M_TEMP); return error; } /* * Convert kernel VA to physical address */ u_long kvtop(void *addr) { vm_offset_t va; va = pmap_kextract((vm_offset_t)addr); if (va == 0) panic("kvtop: zero page frame"); return((int)va); } /* * Map an IO request into kernel virtual address space. * * All requests are (re)mapped into kernel VA space. * Notice that we use b_bufsize for the size of the buffer * to be mapped. b_bcount might be modified by the driver. */ void vmapbuf(bp) register struct buf *bp; { register caddr_t addr, v, kva; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vmapbuf"); for (v = bp->b_saveaddr, addr = (caddr_t)trunc_page((vm_offset_t)bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE, v += PAGE_SIZE) { /* * Do the vm_fault if needed; do the copy-on-write thing * when reading stuff off device into memory. */ - vm_fault_quick(addr, + vm_fault_quick((addr >= bp->b_data) ? addr : bp->b_data, (bp->b_iocmd == BIO_READ)?(VM_PROT_READ|VM_PROT_WRITE):VM_PROT_READ); pa = trunc_page(pmap_kextract((vm_offset_t) addr)); if (pa == 0) panic("vmapbuf: page not present"); vm_page_hold(PHYS_TO_VM_PAGE(pa)); pmap_kenter((vm_offset_t) v, pa); } kva = bp->b_saveaddr; bp->b_saveaddr = bp->b_data; bp->b_data = kva + (((vm_offset_t) bp->b_data) & PAGE_MASK); } /* * Free the io map PTEs associated with this IO operation. * We also invalidate the TLB entries and restore the original b_addr. */ void vunmapbuf(bp) register struct buf *bp; { register caddr_t addr; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vunmapbuf"); for (addr = (caddr_t)trunc_page((vm_offset_t)bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE) { pa = trunc_page(pmap_kextract((vm_offset_t) addr)); pmap_kremove((vm_offset_t) addr); vm_page_unhold(PHYS_TO_VM_PAGE(pa)); } bp->b_data = bp->b_saveaddr; } /* * Force reset the processor by invalidating the entire address space! */ #ifdef SMP static void cpu_reset_proxy() { cpu_reset_proxy_active = 1; while (cpu_reset_proxy_active == 1) ; /* Wait for other cpu to see that we've started */ stop_cpus((1<" */ invltlb(); /* NOTREACHED */ while(1); } int grow_stack(p, sp) struct proc *p; u_int sp; { int rv; rv = vm_map_growstack (p, sp); if (rv != KERN_SUCCESS) return (0); return (1); } /* * Software interrupt handler for queued VM system processing. */ void swi_vm(void *dummy) { if (busdma_swi_pending != 0) busdma_swi(); } /* * Tell whether this address is in some physical memory region. * Currently used by the kernel coredump code in order to avoid * dumping the ``ISA memory hole'' which could cause indefinite hangs, * or other unpredictable behaviour. */ int is_physical_memory(addr) vm_offset_t addr; { #ifdef DEV_ISA /* The ISA ``memory hole''. */ if (addr >= 0xa0000 && addr < 0x100000) return 0; #endif /* * stuff other tests for known memory-mapped devices (PCI?) * here */ return 1; } Index: head/sys/i386/i386/vm_machdep.c =================================================================== --- head/sys/i386/i386/vm_machdep.c (revision 84380) +++ head/sys/i386/i386/vm_machdep.c (revision 84381) @@ -1,555 +1,555 @@ /*- * Copyright (c) 1982, 1986 The Regents of the University of California. * Copyright (c) 1989, 1990 William Jolitz * Copyright (c) 1994 John Dyson * All rights reserved. * * This code is derived from software contributed to Berkeley by * the Systems Programming Group of the University of Utah Computer * Science Department, 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: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ * $FreeBSD$ */ #include "opt_npx.h" #ifdef PC98 #include "opt_pc98.h" #endif #include "opt_reset.h" #include "opt_isa.h" #include "opt_kstack_pages.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef PC98 #include #else #include #endif static void cpu_reset_real __P((void)); #ifdef SMP static void cpu_reset_proxy __P((void)); static u_int cpu_reset_proxyid; static volatile u_int cpu_reset_proxy_active; #endif extern int _ucodesel, _udatasel; /* * quick version of vm_fault */ int vm_fault_quick(v, prot) caddr_t v; int prot; { int r; if (prot & VM_PROT_WRITE) r = subyte(v, fubyte(v)); else r = fubyte(v); return(r); } /* * Finish a fork operation, with process p2 nearly set up. * Copy and update the pcb, set up the stack so that the child * ready to run and return to user mode. */ void cpu_fork(td1, p2, flags) register struct thread *td1; register struct proc *p2; int flags; { register struct proc *p1; struct thread *td2; struct pcb *pcb2; #ifdef DEV_NPX int savecrit; #endif p1 = td1->td_proc; td2 = &p2->p_thread; if ((flags & RFPROC) == 0) { if ((flags & RFMEM) == 0) { /* unshare user LDT */ struct pcb *pcb1 = td1->td_pcb; struct pcb_ldt *pcb_ldt = pcb1->pcb_ldt; if (pcb_ldt && pcb_ldt->ldt_refcnt > 1) { pcb_ldt = user_ldt_alloc(pcb1,pcb_ldt->ldt_len); if (pcb_ldt == NULL) panic("could not copy LDT"); pcb1->pcb_ldt = pcb_ldt; set_user_ldt(pcb1); user_ldt_free(pcb1); } } return; } /* Ensure that p1's pcb is up to date. */ #ifdef DEV_NPX if (td1 == curthread) td1->td_pcb->pcb_gs = rgs(); savecrit = critical_enter(); if (PCPU_GET(npxthread) == td1) npxsave(&td1->td_pcb->pcb_save); critical_exit(savecrit); #endif /* Point the pcb to the top of the stack */ pcb2 = (struct pcb *)(td2->td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1; td2->td_pcb = pcb2; /* Copy p1's pcb. */ bcopy(td1->td_pcb, pcb2, sizeof(*pcb2)); /* * Create a new fresh stack for the new process. * Copy the trap frame for the return to user mode as if from a * syscall. This copies most of the user mode register values. * The -16 is so we can expand the trapframe if we go to vm86. */ td2->td_frame = (struct trapframe *)((caddr_t)td2->td_pcb - 16) - 1; bcopy(td1->td_frame, td2->td_frame, sizeof(struct trapframe)); td2->td_frame->tf_eax = 0; /* Child returns zero */ td2->td_frame->tf_eflags &= ~PSL_C; /* success */ td2->td_frame->tf_edx = 1; /* * Set registers for trampoline to user mode. Leave space for the * return address on stack. These are the kernel mode register values. */ pcb2->pcb_cr3 = vtophys(vmspace_pmap(p2->p_vmspace)->pm_pdir); pcb2->pcb_edi = 0; pcb2->pcb_esi = (int)fork_return; /* fork_trampoline argument */ pcb2->pcb_ebp = 0; pcb2->pcb_esp = (int)td2->td_frame - sizeof(void *); pcb2->pcb_ebx = (int)td2; /* fork_trampoline argument */ pcb2->pcb_eip = (int)fork_trampoline; /*- * pcb2->pcb_dr*: cloned above. * pcb2->pcb_ldt: duplicated below, if necessary. * pcb2->pcb_savefpu: cloned above. * pcb2->pcb_flags: cloned above. * pcb2->pcb_onfault: cloned above (always NULL here?). * pcb2->pcb_gs: cloned above. * pcb2->pcb_ext: cleared below. */ /* * XXX don't copy the i/o pages. this should probably be fixed. */ pcb2->pcb_ext = 0; /* Copy the LDT, if necessary. */ mtx_lock_spin(&sched_lock); if (pcb2->pcb_ldt != 0) { if (flags & RFMEM) { pcb2->pcb_ldt->ldt_refcnt++; } else { pcb2->pcb_ldt = user_ldt_alloc(pcb2, pcb2->pcb_ldt->ldt_len); if (pcb2->pcb_ldt == NULL) panic("could not copy LDT"); } } mtx_unlock_spin(&sched_lock); /* * Now, cpu_switch() can schedule the new process. * pcb_esp is loaded pointing to the cpu_switch() stack frame * containing the return address when exiting cpu_switch. * This will normally be to fork_trampoline(), which will have * %ebx loaded with the new proc's pointer. fork_trampoline() * will set up a stack to call fork_return(p, frame); to complete * the return to user-mode. */ } /* * Intercept the return address from a freshly forked process that has NOT * been scheduled yet. * * This is needed to make kernel threads stay in kernel mode. */ void cpu_set_fork_handler(td, func, arg) struct thread *td; void (*func) __P((void *)); void *arg; { /* * Note that the trap frame follows the args, so the function * is really called like this: func(arg, frame); */ td->td_pcb->pcb_esi = (int) func; /* function */ td->td_pcb->pcb_ebx = (int) arg; /* first arg */ } void cpu_exit(td) register struct thread *td; { struct pcb *pcb = td->td_pcb; #ifdef DEV_NPX npxexit(td); #endif if (pcb->pcb_ext != 0) { /* * XXX do we need to move the TSS off the allocated pages * before freeing them? (not done here) */ kmem_free(kernel_map, (vm_offset_t)pcb->pcb_ext, ctob(IOPAGES + 1)); pcb->pcb_ext = 0; } if (pcb->pcb_ldt) user_ldt_free(pcb); if (pcb->pcb_flags & PCB_DBREGS) { /* * disable all hardware breakpoints */ reset_dbregs(); pcb->pcb_flags &= ~PCB_DBREGS; } } void cpu_wait(p) struct proc *p; { } /* * Dump the machine specific header information at the start of a core dump. */ int cpu_coredump(td, vp, cred) struct thread *td; struct vnode *vp; struct ucred *cred; { struct proc *p = td->td_proc; int error; caddr_t tempuser; tempuser = malloc(ctob(UAREA_PAGES + KSTACK_PAGES), M_TEMP, M_WAITOK | M_ZERO); if (!tempuser) return EINVAL; bcopy(p->p_uarea, tempuser, sizeof(struct user)); #if 0 /* XXXKSE - broken, fixme!!!!! td_frame is in kstack! */ bcopy(td->td_frame, tempuser + ((caddr_t) td->td_frame - (caddr_t) p->p_uarea), sizeof(struct trapframe)); #endif error = vn_rdwr(UIO_WRITE, vp, (caddr_t) tempuser, ctob(UAREA_PAGES + KSTACK_PAGES), (off_t)0, UIO_SYSSPACE, IO_UNIT, cred, (int *)NULL, td); free(tempuser, M_TEMP); return error; } /* * Convert kernel VA to physical address */ u_long kvtop(void *addr) { vm_offset_t va; va = pmap_kextract((vm_offset_t)addr); if (va == 0) panic("kvtop: zero page frame"); return((int)va); } /* * Map an IO request into kernel virtual address space. * * All requests are (re)mapped into kernel VA space. * Notice that we use b_bufsize for the size of the buffer * to be mapped. b_bcount might be modified by the driver. */ void vmapbuf(bp) register struct buf *bp; { register caddr_t addr, v, kva; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vmapbuf"); for (v = bp->b_saveaddr, addr = (caddr_t)trunc_page((vm_offset_t)bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE, v += PAGE_SIZE) { /* * Do the vm_fault if needed; do the copy-on-write thing * when reading stuff off device into memory. */ - vm_fault_quick(addr, + vm_fault_quick((addr >= bp->b_data) ? addr : bp->b_data, (bp->b_iocmd == BIO_READ)?(VM_PROT_READ|VM_PROT_WRITE):VM_PROT_READ); pa = trunc_page(pmap_kextract((vm_offset_t) addr)); if (pa == 0) panic("vmapbuf: page not present"); vm_page_hold(PHYS_TO_VM_PAGE(pa)); pmap_kenter((vm_offset_t) v, pa); } kva = bp->b_saveaddr; bp->b_saveaddr = bp->b_data; bp->b_data = kva + (((vm_offset_t) bp->b_data) & PAGE_MASK); } /* * Free the io map PTEs associated with this IO operation. * We also invalidate the TLB entries and restore the original b_addr. */ void vunmapbuf(bp) register struct buf *bp; { register caddr_t addr; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vunmapbuf"); for (addr = (caddr_t)trunc_page((vm_offset_t)bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE) { pa = trunc_page(pmap_kextract((vm_offset_t) addr)); pmap_kremove((vm_offset_t) addr); vm_page_unhold(PHYS_TO_VM_PAGE(pa)); } bp->b_data = bp->b_saveaddr; } /* * Force reset the processor by invalidating the entire address space! */ #ifdef SMP static void cpu_reset_proxy() { cpu_reset_proxy_active = 1; while (cpu_reset_proxy_active == 1) ; /* Wait for other cpu to see that we've started */ stop_cpus((1<" */ invltlb(); /* NOTREACHED */ while(1); } int grow_stack(p, sp) struct proc *p; u_int sp; { int rv; rv = vm_map_growstack (p, sp); if (rv != KERN_SUCCESS) return (0); return (1); } /* * Software interrupt handler for queued VM system processing. */ void swi_vm(void *dummy) { if (busdma_swi_pending != 0) busdma_swi(); } /* * Tell whether this address is in some physical memory region. * Currently used by the kernel coredump code in order to avoid * dumping the ``ISA memory hole'' which could cause indefinite hangs, * or other unpredictable behaviour. */ int is_physical_memory(addr) vm_offset_t addr; { #ifdef DEV_ISA /* The ISA ``memory hole''. */ if (addr >= 0xa0000 && addr < 0x100000) return 0; #endif /* * stuff other tests for known memory-mapped devices (PCI?) * here */ return 1; } Index: head/sys/ia64/ia64/vm_machdep.c =================================================================== --- head/sys/ia64/ia64/vm_machdep.c (revision 84380) +++ head/sys/ia64/ia64/vm_machdep.c (revision 84381) @@ -1,454 +1,454 @@ /*- * Copyright (c) 1982, 1986 The Regents of the University of California. * Copyright (c) 1989, 1990 William Jolitz * Copyright (c) 1994 John Dyson * All rights reserved. * * This code is derived from software contributed to Berkeley by * the Systems Programming Group of the University of Utah Computer * Science Department, 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: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ * $FreeBSD$ */ /* * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. * All rights reserved. * * Author: Chris G. Demetriou * * Permission to use, copy, modify and distribute this software and * its documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * quick version of vm_fault */ int vm_fault_quick(v, prot) caddr_t v; int prot; { int r; if (prot & VM_PROT_WRITE) r = subyte(v, fubyte(v)); else r = fubyte(v); return(r); } struct ia64_fdesc { u_int64_t func; u_int64_t gp; }; #define FDESC_FUNC(fn) (((struct ia64_fdesc *) fn)->func) #define FDESC_GP(fn) (((struct ia64_fdesc *) fn)->gp) /* * Finish a fork operation, with process p2 nearly set up. * Copy and update the pcb, set up the stack so that the child * ready to run and return to user mode. */ void cpu_fork(td1, p2, flags) register struct thread *td1; register struct proc *p2; int flags; { struct proc *p1; struct thread *td2; struct trapframe *p2tf; u_int64_t bspstore, *p1bs, *p2bs, rnatloc, rnat; if ((flags & RFPROC) == 0) return; p1 = td1->td_proc; td2 = &p2->p_thread; td2->td_pcb = (struct pcb *) (td2->td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1; td2->td_md.md_flags = td1->td_md.md_flags & (MDP_FPUSED | MDP_UAC_MASK); /* * Copy floating point state from the FP chip to the PCB * if this process has state stored there. */ ia64_fpstate_save(td1, 0); /* * Copy pcb and stack from proc p1 to p2. We do this as * cheaply as possible, copying only the active part of the * stack. The stack and pcb need to agree. Make sure that the * new process has FEN disabled. */ bcopy(td1->td_pcb, td2->td_pcb, sizeof(struct pcb)); /* * Set the floating point state. */ #if 0 if ((td2->td_pcb->pcb_fp_control & IEEE_INHERIT) == 0) { td2->td_pcb->pcb_fp_control = 0; td2->td_pcb->pcb_fp.fpr_cr = (FPCR_DYN_NORMAL | FPCR_INVD | FPCR_DZED | FPCR_OVFD | FPCR_INED | FPCR_UNFD); } #endif /* * Arrange for a non-local goto when the new process * is started, to resume here, returning nonzero from setjmp. */ #ifdef DIAGNOSTIC if (td1 != curthread) panic("cpu_fork: curproc"); ia64_fpstate_check(td1); #endif /* * create the child's kernel stack, from scratch. * * Pick a stack pointer, leaving room for a trapframe; * copy trapframe from parent so return to user mode * will be to right address, with correct registers. */ td2->td_frame = (struct trapframe *)td2->td_pcb - 1; bcopy(td1->td_frame, td2->td_frame, sizeof(struct trapframe)); /* * Set up return-value registers as fork() libc stub expects. */ p2tf = td2->td_frame; p2tf->tf_r[FRAME_R8] = 0; /* child's pid (linux) */ p2tf->tf_r[FRAME_R9] = 1; /* is child (FreeBSD) */ p2tf->tf_r[FRAME_R10] = 0; /* no error */ /* * Turn off RSE for a moment and work out our current * ar.bspstore. This assumes that td1==curthread. Also * flush dirty regs to ensure that the user's stacked * regs are written out to backing store. * * We could cope with td1!=curthread by digging values * out of its PCB but I don't see the point since * current usage never allows it. */ __asm __volatile("mov ar.rsc=0;;"); __asm __volatile("flushrs;;" ::: "memory"); __asm __volatile("mov %0=ar.bspstore" : "=r"(bspstore)); p1bs = (u_int64_t *)td1->td_kstack; p2bs = (u_int64_t *)td2->td_kstack; /* * Copy enough of td1's backing store to include all * the user's stacked regs. */ bcopy(p1bs, p2bs, td1->td_frame->tf_ndirty); /* * To calculate the ar.rnat for td2, we need to decide * if td1's ar.bspstore has advanced past the place * where the last ar.rnat which covers the user's * saved registers would be placed. If so, we read * that one from memory, otherwise we take td1's * current ar.rnat. */ rnatloc = (u_int64_t)p1bs + td1->td_frame->tf_ndirty; rnatloc |= 0x1f8; if (bspstore > rnatloc) rnat = *(u_int64_t *) rnatloc; else __asm __volatile("mov %0=ar.rnat;;" : "=r"(rnat)); /* * Switch the RSE back on. */ __asm __volatile("mov ar.rsc=3;;"); /* * Setup the child's pcb so that its ar.bspstore * starts just above the region which we copied. This * should work since the child will normally return * straight into exception_restore. */ td2->td_pcb->pcb_bspstore = (u_int64_t)p2bs + td1->td_frame->tf_ndirty; td2->td_pcb->pcb_rnat = rnat; td2->td_pcb->pcb_pfs = 0; /* * Arrange for continuation at fork_return(), which * will return to exception_restore(). Note that the * child process doesn't stay in the kernel for long! * * XXX what is this +/- 16 stuff here? */ td2->td_pcb->pcb_sp = (u_int64_t)p2tf - 16; td2->td_pcb->pcb_r4 = (u_int64_t)fork_return; td2->td_pcb->pcb_r5 = FDESC_FUNC(exception_restore); td2->td_pcb->pcb_r6 = (u_int64_t)td2; td2->td_pcb->pcb_b0 = FDESC_FUNC(fork_trampoline); } /* * Intercept the return address from a freshly forked process that has NOT * been scheduled yet. * * This is needed to make kernel threads stay in kernel mode. */ void cpu_set_fork_handler(td, func, arg) struct thread *td; void (*func) __P((void *)); void *arg; { td->td_pcb->pcb_r4 = (u_int64_t) func; td->td_pcb->pcb_r6 = (u_int64_t) arg; } /* * cpu_exit is called as the last action during exit. * We drop the fp state (if we have it) and switch to a live one. * When the proc is reaped, cpu_wait() will gc the VM state. */ void cpu_exit(td) register struct thread *td; { ia64_fpstate_drop(td); } void cpu_wait(p) struct proc *p; { } /* Temporary helper */ void cpu_throw(void) { cpu_switch(); panic("cpu_throw() didn't"); } /* * Dump the machine specific header information at the start of a core dump. */ int cpu_coredump(td, vp, cred) struct thread *td; struct vnode *vp; struct ucred *cred; { int error; error = vn_rdwr(UIO_WRITE, vp, (caddr_t) td->td_proc->p_uarea, ctob(UAREA_PAGES), (off_t)0, UIO_SYSSPACE, IO_UNIT, cred, (int *)NULL, td); if (error) return error; error = vn_rdwr(UIO_WRITE, vp, (caddr_t) td->td_kstack, ctob(KSTACK_PAGES), (off_t)0, UIO_SYSSPACE, IO_UNIT, cred, (int *)NULL, td); return error; } /* * Map an IO request into kernel virtual address space. * * All requests are (re)mapped into kernel VA space. * Notice that we use b_bufsize for the size of the buffer * to be mapped. b_bcount might be modified by the driver. */ void vmapbuf(bp) register struct buf *bp; { register caddr_t addr, v, kva; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vmapbuf"); for (v = bp->b_saveaddr, addr = (caddr_t)trunc_page(bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE, v += PAGE_SIZE) { /* * Do the vm_fault if needed; do the copy-on-write thing * when reading stuff off device into memory. */ - vm_fault_quick(addr, + vm_fault_quick((addr >= bp->b_data) ? addr : bp->b_data, (bp->b_iocmd == BIO_READ)?(VM_PROT_READ|VM_PROT_WRITE):VM_PROT_READ); pa = trunc_page(pmap_kextract((vm_offset_t) addr)); if (pa == 0) panic("vmapbuf: page not present"); vm_page_hold(PHYS_TO_VM_PAGE(pa)); pmap_kenter((vm_offset_t) v, pa); } kva = bp->b_saveaddr; bp->b_saveaddr = bp->b_data; bp->b_data = kva + (((vm_offset_t) bp->b_data) & PAGE_MASK); } /* * Free the io map PTEs associated with this IO operation. * We also invalidate the TLB entries and restore the original b_addr. */ void vunmapbuf(bp) register struct buf *bp; { register caddr_t addr; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vunmapbuf"); for (addr = (caddr_t)trunc_page(bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE) { pa = trunc_page(pmap_kextract((vm_offset_t) addr)); pmap_kremove((vm_offset_t) addr); vm_page_unhold(PHYS_TO_VM_PAGE(pa)); } bp->b_data = bp->b_saveaddr; } /* * Force reset the processor by invalidating the entire address space! */ void cpu_reset() { cpu_boot(0); } int grow_stack(p, sp) struct proc *p; size_t sp; { int rv; rv = vm_map_growstack (p, sp); if (rv != KERN_SUCCESS) return (0); return (1); } /* * Software interrupt handler for queued VM system processing. */ void swi_vm(void *dummy) { #if 0 if (busdma_swi_pending != 0) busdma_swi(); #endif } /* * Tell whether this address is in some physical memory region. * Currently used by the kernel coredump code in order to avoid * dumping the ``ISA memory hole'' which could cause indefinite hangs, * or other unpredictable behaviour. */ int is_physical_memory(addr) vm_offset_t addr; { /* * stuff other tests for known memory-mapped devices (PCI?) * here */ return 1; } Index: head/sys/powerpc/aim/vm_machdep.c =================================================================== --- head/sys/powerpc/aim/vm_machdep.c (revision 84380) +++ head/sys/powerpc/aim/vm_machdep.c (revision 84381) @@ -1,315 +1,315 @@ /*- * Copyright (c) 1982, 1986 The Regents of the University of California. * Copyright (c) 1989, 1990 William Jolitz * Copyright (c) 1994 John Dyson * All rights reserved. * * This code is derived from software contributed to Berkeley by * the Systems Programming Group of the University of Utah Computer * Science Department, 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: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ * $FreeBSD$ */ /* * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. * All rights reserved. * * Author: Chris G. Demetriou * * Permission to use, copy, modify and distribute this software and * its documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * quick version of vm_fault */ int vm_fault_quick(v, prot) caddr_t v; int prot; { int r; if (prot & VM_PROT_WRITE) r = subyte(v, fubyte(v)); else r = fubyte(v); return(r); } /* * Finish a fork operation, with process p2 nearly set up. * Copy and update the pcb, set up the stack so that the child * ready to run and return to user mode. */ void cpu_fork(td1, p2, flags) register struct thread *td1; register struct proc *p2; int flags; { /* XXX: coming soon... */ } /* * Intercept the return address from a freshly forked process that has NOT * been scheduled yet. * * This is needed to make kernel threads stay in kernel mode. */ void cpu_set_fork_handler(td, func, arg) struct thread *td; void (*func) __P((void *)); void *arg; { /* * Note that the trap frame follows the args, so the function * is really called like this: func(arg, frame); */ #if 0 /* XXX */ td->p_addr->u_pcb.pcb_context[0] = (u_long) func; td->p_addr->u_pcb.pcb_context[2] = (u_long) arg; #endif } /* * cpu_exit is called as the last action during exit. * We release the address space of the process, block interrupts, * and call switch_exit. switch_exit switches to proc0's PCB and stack, * then jumps into the middle of cpu_switch, as if it were switching * from proc0. */ void cpu_exit(td) register struct thread *td; { } void cpu_wait(td) struct proc *td; { } /* Temporary helper */ void cpu_throw(void) { cpu_switch(); panic("cpu_throw() didn't"); } /* * Dump the machine specific header information at the start of a core dump. */ int cpu_coredump(td, vp, cred) struct thread *td; struct vnode *vp; struct ucred *cred; { struct proc *p = td->td_proc; return (vn_rdwr(UIO_WRITE, vp, (caddr_t)p->p_uarea, ctob(UAREA_PAGES), (off_t)0, UIO_SYSSPACE, IO_UNIT, cred, (int *)NULL, p)); } /* * Map an IO request into kernel virtual address space. * * All requests are (re)mapped into kernel VA space. * Notice that we use b_bufsize for the size of the buffer * to be mapped. b_bcount might be modified by the driver. */ void vmapbuf(bp) register struct buf *bp; { register caddr_t addr, v, kva; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vmapbuf"); for (v = bp->b_saveaddr, addr = (caddr_t)trunc_page(bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE, v += PAGE_SIZE) { /* * Do the vm_fault if needed; do the copy-on-write thing * when reading stuff off device into memory. */ - vm_fault_quick(addr, + vm_fault_quick((addr >= bp->b_data) ? addr : bp->b_data, (bp->b_iocmd == BIO_READ)?(VM_PROT_READ|VM_PROT_WRITE):VM_PROT_READ); pa = trunc_page(pmap_kextract((vm_offset_t) addr)); if (pa == 0) panic("vmapbuf: page not present"); vm_page_hold(PHYS_TO_VM_PAGE(pa)); pmap_kenter((vm_offset_t) v, pa); } kva = bp->b_saveaddr; bp->b_saveaddr = bp->b_data; bp->b_data = kva + (((vm_offset_t) bp->b_data) & PAGE_MASK); } /* * Free the io map PTEs associated with this IO operation. * We also invalidate the TLB entries and restore the original b_addr. */ void vunmapbuf(bp) register struct buf *bp; { register caddr_t addr; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vunmapbuf"); for (addr = (caddr_t)trunc_page(bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE) { pa = trunc_page(pmap_kextract((vm_offset_t) addr)); pmap_kremove((vm_offset_t) addr); vm_page_unhold(PHYS_TO_VM_PAGE(pa)); } bp->b_data = bp->b_saveaddr; } /* * Reset back to firmware. */ void cpu_reset() { OF_exit(); } int grow_stack(p, sp) struct proc *p; size_t sp; { int rv; rv = vm_map_growstack (p, sp); if (rv != KERN_SUCCESS) return (0); return (1); } /* * Software interrupt handler for queued VM system processing. */ void swi_vm(void *dummy) { #if 0 /* XXX: Don't have busdma stuff yet */ if (busdma_swi_pending != 0) busdma_swi(); #endif } /* * Tell whether this address is in some physical memory region. * Currently used by the kernel coredump code in order to avoid * dumping the ``ISA memory hole'' which could cause indefinite hangs, * or other unpredictable behaviour. */ int is_physical_memory(addr) vm_offset_t addr; { /* * stuff other tests for known memory-mapped devices (PCI?) * here */ return 1; } Index: head/sys/powerpc/powerpc/vm_machdep.c =================================================================== --- head/sys/powerpc/powerpc/vm_machdep.c (revision 84380) +++ head/sys/powerpc/powerpc/vm_machdep.c (revision 84381) @@ -1,315 +1,315 @@ /*- * Copyright (c) 1982, 1986 The Regents of the University of California. * Copyright (c) 1989, 1990 William Jolitz * Copyright (c) 1994 John Dyson * All rights reserved. * * This code is derived from software contributed to Berkeley by * the Systems Programming Group of the University of Utah Computer * Science Department, 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: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ * $FreeBSD$ */ /* * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. * All rights reserved. * * Author: Chris G. Demetriou * * Permission to use, copy, modify and distribute this software and * its documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * quick version of vm_fault */ int vm_fault_quick(v, prot) caddr_t v; int prot; { int r; if (prot & VM_PROT_WRITE) r = subyte(v, fubyte(v)); else r = fubyte(v); return(r); } /* * Finish a fork operation, with process p2 nearly set up. * Copy and update the pcb, set up the stack so that the child * ready to run and return to user mode. */ void cpu_fork(td1, p2, flags) register struct thread *td1; register struct proc *p2; int flags; { /* XXX: coming soon... */ } /* * Intercept the return address from a freshly forked process that has NOT * been scheduled yet. * * This is needed to make kernel threads stay in kernel mode. */ void cpu_set_fork_handler(td, func, arg) struct thread *td; void (*func) __P((void *)); void *arg; { /* * Note that the trap frame follows the args, so the function * is really called like this: func(arg, frame); */ #if 0 /* XXX */ td->p_addr->u_pcb.pcb_context[0] = (u_long) func; td->p_addr->u_pcb.pcb_context[2] = (u_long) arg; #endif } /* * cpu_exit is called as the last action during exit. * We release the address space of the process, block interrupts, * and call switch_exit. switch_exit switches to proc0's PCB and stack, * then jumps into the middle of cpu_switch, as if it were switching * from proc0. */ void cpu_exit(td) register struct thread *td; { } void cpu_wait(td) struct proc *td; { } /* Temporary helper */ void cpu_throw(void) { cpu_switch(); panic("cpu_throw() didn't"); } /* * Dump the machine specific header information at the start of a core dump. */ int cpu_coredump(td, vp, cred) struct thread *td; struct vnode *vp; struct ucred *cred; { struct proc *p = td->td_proc; return (vn_rdwr(UIO_WRITE, vp, (caddr_t)p->p_uarea, ctob(UAREA_PAGES), (off_t)0, UIO_SYSSPACE, IO_UNIT, cred, (int *)NULL, p)); } /* * Map an IO request into kernel virtual address space. * * All requests are (re)mapped into kernel VA space. * Notice that we use b_bufsize for the size of the buffer * to be mapped. b_bcount might be modified by the driver. */ void vmapbuf(bp) register struct buf *bp; { register caddr_t addr, v, kva; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vmapbuf"); for (v = bp->b_saveaddr, addr = (caddr_t)trunc_page(bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE, v += PAGE_SIZE) { /* * Do the vm_fault if needed; do the copy-on-write thing * when reading stuff off device into memory. */ - vm_fault_quick(addr, + vm_fault_quick((addr >= bp->b_data) ? addr : bp->b_data, (bp->b_iocmd == BIO_READ)?(VM_PROT_READ|VM_PROT_WRITE):VM_PROT_READ); pa = trunc_page(pmap_kextract((vm_offset_t) addr)); if (pa == 0) panic("vmapbuf: page not present"); vm_page_hold(PHYS_TO_VM_PAGE(pa)); pmap_kenter((vm_offset_t) v, pa); } kva = bp->b_saveaddr; bp->b_saveaddr = bp->b_data; bp->b_data = kva + (((vm_offset_t) bp->b_data) & PAGE_MASK); } /* * Free the io map PTEs associated with this IO operation. * We also invalidate the TLB entries and restore the original b_addr. */ void vunmapbuf(bp) register struct buf *bp; { register caddr_t addr; vm_offset_t pa; GIANT_REQUIRED; if ((bp->b_flags & B_PHYS) == 0) panic("vunmapbuf"); for (addr = (caddr_t)trunc_page(bp->b_data); addr < bp->b_data + bp->b_bufsize; addr += PAGE_SIZE) { pa = trunc_page(pmap_kextract((vm_offset_t) addr)); pmap_kremove((vm_offset_t) addr); vm_page_unhold(PHYS_TO_VM_PAGE(pa)); } bp->b_data = bp->b_saveaddr; } /* * Reset back to firmware. */ void cpu_reset() { OF_exit(); } int grow_stack(p, sp) struct proc *p; size_t sp; { int rv; rv = vm_map_growstack (p, sp); if (rv != KERN_SUCCESS) return (0); return (1); } /* * Software interrupt handler for queued VM system processing. */ void swi_vm(void *dummy) { #if 0 /* XXX: Don't have busdma stuff yet */ if (busdma_swi_pending != 0) busdma_swi(); #endif } /* * Tell whether this address is in some physical memory region. * Currently used by the kernel coredump code in order to avoid * dumping the ``ISA memory hole'' which could cause indefinite hangs, * or other unpredictable behaviour. */ int is_physical_memory(addr) vm_offset_t addr; { /* * stuff other tests for known memory-mapped devices (PCI?) * here */ return 1; }