Module Name: src
Committed By: rmind
Date: Sun Mar 29 01:10:28 UTC 2009
Modified Files:
src/sys/arch/amd64/amd64: mem.c syscall.c vm_machdep.c
src/sys/arch/i386/i386: core_machdep.c mem.c syscall.c vm_machdep.c
Log Message:
Reduce some differences between i386 and amd64.
Mainly cosmetical changes - no functional changes intended.
To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/amd64/amd64/mem.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/amd64/amd64/syscall.c
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/amd64/amd64/vm_machdep.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/i386/i386/core_machdep.c
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/i386/i386/mem.c
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/i386/i386/syscall.c
cvs rdiff -u -r1.144 -r1.145 src/sys/arch/i386/i386/vm_machdep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/amd64/amd64/mem.c
diff -u src/sys/arch/amd64/amd64/mem.c:1.18 src/sys/arch/amd64/amd64/mem.c:1.19
--- src/sys/arch/amd64/amd64/mem.c:1.18 Sat Mar 28 21:23:44 2009
+++ src/sys/arch/amd64/amd64/mem.c Sun Mar 29 01:10:28 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: mem.c,v 1.18 2009/03/28 21:23:44 rmind Exp $ */
+/* $NetBSD: mem.c,v 1.19 2009/03/29 01:10:28 rmind Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -101,15 +101,13 @@
* @(#)mem.c 8.3 (Berkeley) 1/12/94
*/
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.18 2009/03/28 21:23:44 rmind Exp $");
-
-#include "opt_compat_netbsd.h"
-
/*
* Memory special file
*/
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.19 2009/03/29 01:10:28 rmind Exp $");
+
#include <sys/param.h>
#include <sys/buf.h>
#include <sys/systm.h>
@@ -144,7 +142,6 @@
int check_pa_acc(paddr_t, vm_prot_t);
-/* ARGSUSED */
int
mmopen(dev_t dev, int flag, int mode, struct lwp *l)
{
@@ -158,9 +155,8 @@
}
return (0);
-}
+}
-/*ARGSUSED*/
int
mmrw(dev_t dev, struct uio *uio, int flags)
{
@@ -180,8 +176,8 @@
continue;
}
switch (minor(dev)) {
-
case DEV_MEM:
+ /* lock against other uses of shared vmmap */
mutex_enter(&mm_lock);
v = uio->uio_offset;
prot = uio->uio_rw == UIO_READ ? VM_PROT_READ :
@@ -242,12 +238,14 @@
return (ENXIO);
}
}
+
return (error);
}
paddr_t
mmmmap(dev_t dev, off_t off, int prot)
{
+
/*
* /dev/mem is the only one that makes sense through this
* interface. For /dev/kmem any physaddr we return here
@@ -257,10 +255,10 @@
* pager in mmap().
*/
if (minor(dev) != DEV_MEM)
- return (-1);
+ return -1;
if (check_pa_acc(off, prot) != 0)
- return (-1);
+ return -1;
- return (x86_btop(off));
+ return x86_btop(off);
}
Index: src/sys/arch/amd64/amd64/syscall.c
diff -u src/sys/arch/amd64/amd64/syscall.c:1.44 src/sys/arch/amd64/amd64/syscall.c:1.45
--- src/sys/arch/amd64/amd64/syscall.c:1.44 Tue Oct 21 12:16:59 2008
+++ src/sys/arch/amd64/amd64/syscall.c Sun Mar 29 01:10:28 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: syscall.c,v 1.44 2008/10/21 12:16:59 ad Exp $ */
+/* $NetBSD: syscall.c,v 1.45 2009/03/29 01:10:28 rmind Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.44 2008/10/21 12:16:59 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.45 2009/03/29 01:10:28 rmind Exp $");
#include "opt_sa.h"
@@ -95,11 +95,9 @@
l = curlwp;
p = l->l_proc;
-
- code = frame->tf_rax & (SYS_NSYSENT - 1);
-
LWP_CACHE_CREDS(l, p);
+ code = frame->tf_rax & (SYS_NSYSENT - 1);
callp = p->p_emul->e_sysent + code;
SYSCALL_COUNT(syscall_counts, code);
@@ -130,6 +128,7 @@
|| (error = trace_enter(code, args, callp->sy_narg)) == 0) {
rval[0] = 0;
rval[1] = 0;
+ KASSERT(l->l_holdcnt == 0);
error = sy_call(callp, l, args, rval);
}
Index: src/sys/arch/amd64/amd64/vm_machdep.c
diff -u src/sys/arch/amd64/amd64/vm_machdep.c:1.38 src/sys/arch/amd64/amd64/vm_machdep.c:1.39
--- src/sys/arch/amd64/amd64/vm_machdep.c:1.38 Sat Mar 28 21:34:17 2009
+++ src/sys/arch/amd64/amd64/vm_machdep.c Sun Mar 29 01:10:28 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.38 2009/03/28 21:34:17 rmind Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.39 2009/03/29 01:10:28 rmind Exp $ */
/*-
* Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,9 +80,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.38 2009/03/28 21:34:17 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.39 2009/03/29 01:10:28 rmind Exp $");
-#include "opt_user_ldt.h"
+#include "opt_mtrr.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -105,22 +105,21 @@
#include <machine/mtrr.h>
#endif
-extern char x86_64_doubleflt_stack[];
-
static void setredzone(struct lwp *);
void
cpu_proc_fork(struct proc *p1, struct proc *p2)
{
+
p2->p_md.md_flags = p1->p_md.md_flags;
if (p1->p_flag & PK_32)
p2->p_flag |= PK_32;
}
/*
- * Finish a new thread operation, with lwp l2 nearly set up.
+ * Finish a new thread operation, with LWP l2 nearly set up.
* Copy and update the pcb and trap frame, making the child ready to run.
- *
+ *
* Rig the child's kernel stack so that it will start out in
* lwp_trampoline() and call child_return() with l2 as an
* argument. This causes the newly-created child process to go
@@ -137,7 +136,7 @@
*/
void
cpu_lwp_fork(struct lwp *l1, struct lwp *l2, void *stack, size_t stacksize,
- void (*func)(void *), void *arg)
+ void (*func)(void *), void *arg)
{
struct pcb *pcb = &l2->l_addr->u_pcb;
struct trapframe *tf;
@@ -159,11 +158,9 @@
if (l1 == curlwp) {
/* Sync the PCB before we copy it. */
savectx(curpcb);
+ } else {
+ KASSERT(l1 == &lwp0);
}
-#ifdef DIAGNOSTIC
- else if (l1 != &lwp0)
- panic("cpu_fork: curproc");
-#endif
*pcb = l1->l_addr->u_pcb;
#if defined(XEN)
pcb->pcb_iopl = SEL_KPL;
@@ -177,6 +174,9 @@
pcb->pcb_rsp0 = (USER_TO_UAREA(l2->l_addr) + KSTACK_SIZE - 16) & ~0xf;
+ pcb->pcb_fs = l1->l_addr->u_pcb.pcb_fs;
+ pcb->pcb_gs = l1->l_addr->u_pcb.pcb_gs;
+
/*
* Copy the trapframe.
*/
@@ -192,9 +192,6 @@
if (stack != NULL)
tf->tf_rsp = (uint64_t)stack + stacksize;
- pcb->pcb_fs = l1->l_addr->u_pcb.pcb_fs;
- pcb->pcb_gs = l1->l_addr->u_pcb.pcb_gs;
-
cpu_setfunc(l2, func, arg);
}
@@ -218,6 +215,7 @@
void
cpu_swapin(struct lwp *l)
{
+
setredzone(l);
}
@@ -244,6 +242,10 @@
#endif
}
+/*
+ * cpu_lwp_free2 is called when an LWP is being reaped. This routine
+ * may block.
+ */
void
cpu_lwp_free2(struct lwp *l)
{
@@ -283,7 +285,7 @@
/*
* Map a user I/O request into kernel virtual address space.
* Note: the pages are already locked by uvm_vslock(), so we
- * do not need to pass an access_type to pmap_enter().
+ * do not need to pass an access_type to pmap_enter().
*/
void
vmapbuf(struct buf *bp, vsize_t len)
@@ -291,8 +293,8 @@
vaddr_t faddr, taddr, off;
paddr_t fpa;
- if ((bp->b_flags & B_PHYS) == 0)
- panic("vmapbuf");
+ KASSERT((bp->b_flags & B_PHYS) != 0);
+
bp->b_saveaddr = bp->b_data;
faddr = trunc_page((vaddr_t)bp->b_data);
off = (vaddr_t)bp->b_data - faddr;
@@ -303,7 +305,7 @@
* The region is locked, so we expect that pmap_pte() will return
* non-NULL.
* XXX: unwise to expect this in a multithreaded environment.
- * anything can happen to a pmap between the time we lock a
+ * anything can happen to a pmap between the time we lock a
* region, release the pmap lock, and then relock it for
* the pmap_extract().
*
@@ -319,6 +321,7 @@
taddr += PAGE_SIZE;
len -= PAGE_SIZE;
}
+ pmap_update(pmap_kernel());
}
/*
@@ -329,8 +332,8 @@
{
vaddr_t addr, off;
- if ((bp->b_flags & B_PHYS) == 0)
- panic("vunmapbuf");
+ KASSERT((bp->b_flags & B_PHYS) != 0);
+
addr = trunc_page((vaddr_t)bp->b_data);
off = (vaddr_t)bp->b_data - addr;
len = round_page(off + len);
Index: src/sys/arch/i386/i386/core_machdep.c
diff -u src/sys/arch/i386/i386/core_machdep.c:1.1 src/sys/arch/i386/i386/core_machdep.c:1.2
--- src/sys/arch/i386/i386/core_machdep.c:1.1 Wed Nov 19 18:35:58 2008
+++ src/sys/arch/i386/i386/core_machdep.c Sun Mar 29 01:10:28 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:58 ad Exp $ */
+/* $NetBSD: core_machdep.c,v 1.2 2009/03/29 01:10:28 rmind Exp $ */
/*-
* Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,12 +80,11 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:58 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.2 2009/03/29 01:10:28 rmind Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
-#include <sys/malloc.h>
#include <sys/vnode.h>
#include <sys/buf.h>
#include <sys/user.h>
@@ -99,11 +98,11 @@
#include <machine/gdt.h>
#include <machine/reg.h>
#include <machine/specialreg.h>
-#include <machine/mtrr.h>
/*
* Dump the machine specific segment at the start of a core dump.
*/
+
struct md_core {
struct reg intreg;
struct fpreg freg;
Index: src/sys/arch/i386/i386/mem.c
diff -u src/sys/arch/i386/i386/mem.c:1.71 src/sys/arch/i386/i386/mem.c:1.72
--- src/sys/arch/i386/i386/mem.c:1.71 Fri Nov 14 13:59:10 2008
+++ src/sys/arch/i386/i386/mem.c Sun Mar 29 01:10:28 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: mem.c,v 1.71 2008/11/14 13:59:10 ad Exp $ */
+/* $NetBSD: mem.c,v 1.72 2009/03/29 01:10:28 rmind Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -106,9 +106,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.71 2008/11/14 13:59:10 ad Exp $");
-
-#include "opt_compat_freebsd.h"
+__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.72 2009/03/29 01:10:28 rmind Exp $");
#include <sys/param.h>
#include <sys/buf.h>
@@ -126,7 +124,7 @@
#define DEV_IO 14 /* iopl for compat_10 */
-extern char *vmmap; /* poor name! */
+extern void *vmmap; /* poor name! */
void *zeropage;
static kmutex_t mm_lock;
@@ -137,12 +135,11 @@
const struct cdevsw mem_cdevsw = {
mmopen, nullclose, mmrw, mmrw, mmioctl,
- nostop, notty, nopoll, mmmmap, nokqfilter, D_OTHER | D_MPSAFE,
+ nostop, notty, nopoll, mmmmap, nokqfilter, D_OTHER | D_MPSAFE
};
int check_pa_acc(paddr_t, vm_prot_t);
-/*ARGSUSED*/
int
mmopen(dev_t dev, int flag, int mode, struct lwp *l)
{
@@ -153,7 +150,7 @@
again = true;
mutex_init(&mm_lock, MUTEX_DEFAULT, IPL_NONE);
zeropage = kmem_zalloc(PAGE_SIZE, KM_SLEEP);
- }
+ }
switch (minor(dev)) {
/* This is done by i386_iopl(3) now. */
@@ -178,7 +175,6 @@
return (0);
}
-/*ARGSUSED*/
int
mmrw(dev_t dev, struct uio *uio, int flags)
{
@@ -267,9 +263,8 @@
if (minor(dev) != DEV_MEM)
return -1;
- if (check_pa_acc(off, prot) != 0) {
+ if (check_pa_acc(off, prot) != 0)
return -1;
- }
return x86_btop(off);
}
Index: src/sys/arch/i386/i386/syscall.c
diff -u src/sys/arch/i386/i386/syscall.c:1.58 src/sys/arch/i386/i386/syscall.c:1.59
--- src/sys/arch/i386/i386/syscall.c:1.58 Sat Mar 14 15:36:07 2009
+++ src/sys/arch/i386/i386/syscall.c Sun Mar 29 01:10:28 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: syscall.c,v 1.58 2009/03/14 15:36:07 dsl Exp $ */
+/* $NetBSD: syscall.c,v 1.59 2009/03/29 01:10:28 rmind Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.58 2009/03/14 15:36:07 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.59 2009/03/29 01:10:28 rmind Exp $");
#include "opt_vm86.h"
#include "opt_sa.h"
@@ -40,9 +40,9 @@
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/signal.h>
-#include <sys/ktrace.h>
#include <sys/sa.h>
#include <sys/savar.h>
+#include <sys/ktrace.h>
#include <sys/syscall.h>
#include <sys/syscallvar.h>
#include <sys/syscall_stats.h>
@@ -53,13 +53,26 @@
#include <machine/psl.h>
#include <machine/userret.h>
-void syscall(struct trapframe *);
+static void syscall(struct trapframe *);
int x86_copyargs(void *, void *, size_t);
#ifdef VM86
void syscall_vm86(struct trapframe *);
#endif
void
+child_return(void *arg)
+{
+ struct lwp *l = arg;
+ struct trapframe *tf = l->l_md.md_regs;
+
+ tf->tf_eax = 0;
+ tf->tf_eflags &= ~PSL_C;
+
+ userret(l);
+ ktrsysret(SYS_fork, 0, 0);
+}
+
+void
syscall_intern(struct proc *p)
{
@@ -71,19 +84,21 @@
* System call request from POSIX system call gate interface to kernel.
* Like trap(), argument is call by reference.
*/
-void
+static void
syscall(struct trapframe *frame)
{
const struct sysent *callp;
+ struct proc *p;
struct lwp *l;
int error;
register_t code, args[2 + SYS_MAXSYSARGS], rval[2];
l = curlwp;
- LWP_CACHE_CREDS(l, l->l_proc);
+ p = l->l_proc;
+ LWP_CACHE_CREDS(l, p);
code = frame->tf_eax & (SYS_NSYSENT - 1);
- callp = l->l_proc->p_emul->e_sysent + code;
+ callp = p->p_emul->e_sysent + code;
SYSCALL_COUNT(syscall_counts, code);
SYSCALL_TIME_SYS_ENTRY(l, syscall_times, code);
@@ -101,7 +116,7 @@
goto bad;
}
- if (!__predict_false(l->l_proc->p_trace_enabled)
+ if (!__predict_false(p->p_trace_enabled)
|| __predict_false(callp->sy_flags & SYCALL_INDIRECT)
|| (error = trace_enter(frame->tf_eax & (SYS_NSYSENT - 1),
args, callp->sy_narg)) == 0) {
@@ -111,7 +126,7 @@
error = sy_call(callp, l, args, rval);
}
- if (__predict_false(l->l_proc->p_trace_enabled)
+ if (__predict_false(p->p_trace_enabled)
&& !__predict_false(callp->sy_flags & SYCALL_INDIRECT)) {
code = frame->tf_eax & (SYS_NSYSENT - 1);
trace_exit(code, rval, error);
@@ -174,16 +189,3 @@
userret(l);
}
#endif
-
-void
-child_return(void *arg)
-{
- struct lwp *l = arg;
- struct trapframe *tf = l->l_md.md_regs;
-
- tf->tf_eax = 0;
- tf->tf_eflags &= ~PSL_C;
-
- userret(l);
- ktrsysret(SYS_fork, 0, 0);
-}
Index: src/sys/arch/i386/i386/vm_machdep.c
diff -u src/sys/arch/i386/i386/vm_machdep.c:1.144 src/sys/arch/i386/i386/vm_machdep.c:1.145
--- src/sys/arch/i386/i386/vm_machdep.c:1.144 Sat Mar 28 21:34:17 2009
+++ src/sys/arch/i386/i386/vm_machdep.c Sun Mar 29 01:10:28 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.144 2009/03/28 21:34:17 rmind Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.145 2009/03/29 01:10:28 rmind Exp $ */
/*-
* Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,16 +80,13 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.144 2009/03/28 21:34:17 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.145 2009/03/29 01:10:28 rmind Exp $");
-#include "opt_user_ldt.h"
#include "opt_mtrr.h"
-#include "opt_execfmt.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
-#include <sys/malloc.h>
#include <sys/vnode.h>
#include <sys/buf.h>
#include <sys/user.h>
@@ -103,11 +100,13 @@
#include <machine/gdt.h>
#include <machine/reg.h>
#include <machine/specialreg.h>
+#ifdef MTRR
#include <machine/mtrr.h>
+#endif
#include "npx.h"
-static void setredzone(struct lwp *l);
+static void setredzone(struct lwp *);
void
cpu_proc_fork(struct proc *p1, struct proc *p2)
@@ -155,24 +154,19 @@
if (l1 == curlwp) {
/* Sync the PCB before we copy it. */
savectx(curpcb);
+ } else {
+ KASSERT(l1 == &lwp0);
}
-#ifdef DIAGNOSTIC
- else if (l1 != &lwp0)
- panic("cpu_lwp_fork: curlwp");
-#endif
*pcb = l1->l_addr->u_pcb;
#if defined(XEN)
pcb->pcb_iopl = SEL_KPL;
#endif /* defined(XEN) */
- /*
- * Fix up the ring0 esp.
- */
+ l2->l_md.md_astpending = 0;
+
pcb->pcb_esp0 = USER_TO_UAREA(l2->l_addr) + KSTACK_SIZE - 16;
pcb->pcb_iomap = NULL;
-
- l2->l_md.md_astpending = 0;
memcpy(&pcb->pcb_fsd, curpcb->pcb_fsd, sizeof(pcb->pcb_fsd));
memcpy(&pcb->pcb_gsd, curpcb->pcb_gsd, sizeof(pcb->pcb_gsd));
@@ -206,7 +200,7 @@
sf->sf_eip = (int)lwp_trampoline;
pcb->pcb_esp = (int)sf;
pcb->pcb_ebp = (int)l;
-}
+}
void
cpu_swapin(struct lwp *l)
@@ -271,7 +265,7 @@
addr = USER_TO_UAREA(l->l_addr);
pmap_remove(pmap_kernel(), addr, addr + PAGE_SIZE);
pmap_update(pmap_kernel());
-#endif /* DIAGNOSTIC */
+#endif
}
/*
@@ -299,12 +293,13 @@
vaddr_t faddr, taddr, off;
paddr_t fpa;
- if ((bp->b_flags & B_PHYS) == 0)
- panic("vmapbuf");
- faddr = trunc_page((vaddr_t)(bp->b_saveaddr = bp->b_data));
+ KASSERT((bp->b_flags & B_PHYS) != 0);
+
+ bp->b_saveaddr = bp->b_data;
+ faddr = trunc_page((vaddr_t)bp->b_data);
off = (vaddr_t)bp->b_data - faddr;
len = round_page(off + len);
- taddr = uvm_km_alloc(phys_map, len, 0, UVM_KMF_VAONLY|UVM_KMF_WAITVA);
+ taddr = uvm_km_alloc(phys_map, len, 0, UVM_KMF_VAONLY | UVM_KMF_WAITVA);
bp->b_data = (void *)(taddr + off);
/*
* The region is locked, so we expect that pmap_pte() will return
@@ -337,8 +332,8 @@
{
vaddr_t addr, off;
- if ((bp->b_flags & B_PHYS) == 0)
- panic("vunmapbuf");
+ KASSERT((bp->b_flags & B_PHYS) != 0);
+
addr = trunc_page((vaddr_t)bp->b_data);
off = (vaddr_t)bp->b_data - addr;
len = round_page(off + len);