Make the emulations, exec formats, coredump, NFS, and the NFS server trunk
authorad <ad@NetBSD.org>
Wed, 19 Nov 2008 18:35:57 +0000
branchtrunk
changeset 175252 1e3f5990b380
parent 175251 8a18703d598c
child 175253 8615d10891cd
Make the emulations, exec formats, coredump, NFS, and the NFS server into modules. By and large this commit: - shuffles header files and ifdefs - splits code out where necessary to be modular - adds module glue for each of the components - adds/replaces hooks for things that can be installed at runtime
distrib/sets/lists/base/lkm.mi
distrib/sets/lists/base/md.amd64
distrib/sets/lists/base/md.i386
sys/arch/alpha/alpha/core_machdep.c
sys/arch/alpha/alpha/machdep.c
sys/arch/alpha/alpha/vm_machdep.c
sys/arch/alpha/conf/files.alpha
sys/arch/alpha/include/signal.h
sys/arch/amd64/amd64/core_machdep.c
sys/arch/amd64/amd64/machdep.c
sys/arch/amd64/amd64/netbsd32_machdep.c
sys/arch/amd64/amd64/vm_machdep.c
sys/arch/amd64/conf/files.amd64
sys/arch/amd64/include/signal.h
sys/arch/arm/arm/core_machdep.c
sys/arch/arm/arm/sig_machdep.c
sys/arch/arm/arm/vm_machdep_arm.c
sys/arch/arm/conf/files.arm
sys/arch/arm/include/signal.h
sys/arch/hppa/conf/files.hppa
sys/arch/hppa/hppa/core_machdep.c
sys/arch/hppa/hppa/vm_machdep.c
sys/arch/i386/conf/files.i386
sys/arch/i386/i386/compat_16_machdep.c
sys/arch/i386/i386/core_machdep.c
sys/arch/i386/i386/locore.S
sys/arch/i386/i386/machdep.c
sys/arch/i386/i386/process_machdep.c
sys/arch/i386/i386/svr4_machdep.c
sys/arch/i386/i386/svr4_sigcode.S
sys/arch/i386/i386/vm86.c
sys/arch/i386/i386/vm_machdep.c
sys/arch/i386/include/signal.h
sys/arch/m68k/conf/files.m68k
sys/arch/m68k/include/signal.h
sys/arch/m68k/m68k/core_machdep.c
sys/arch/m68k/m68k/sig_machdep.c
sys/arch/m68k/m68k/svr4_machdep.c
sys/arch/m68k/m68k/vm_machdep.c
sys/arch/mips/conf/files.mips
sys/arch/mips/include/signal.h
sys/arch/mips/mips/core_machdep.c
sys/arch/mips/mips/sig_machdep.c
sys/arch/mips/mips/svr4_machdep.c
sys/arch/mips/mips/vm_machdep.c
sys/arch/powerpc/conf/files.powerpc
sys/arch/powerpc/include/signal.h
sys/arch/powerpc/powerpc/core_machdep.c
sys/arch/powerpc/powerpc/sig_machdep.c
sys/arch/powerpc/powerpc/vm_machdep.c
sys/arch/sh3/conf/files.sh3
sys/arch/sh3/include/signal.h
sys/arch/sh3/sh3/coff_exec.c
sys/arch/sh3/sh3/core_machdep.c
sys/arch/sh3/sh3/sh3_machdep.c
sys/arch/sh3/sh3/vm_machdep.c
sys/arch/sparc/conf/files.sparc
sys/arch/sparc/include/signal.h
sys/arch/sparc/sparc/compat_16_machdep.c
sys/arch/sparc/sparc/core_machdep.c
sys/arch/sparc/sparc/machdep.c
sys/arch/sparc/sparc/svr4_machdep.c
sys/arch/sparc/sparc/vm_machdep.c
sys/arch/sparc64/conf/files.sparc64
sys/arch/sparc64/sparc64/core_machdep.c
sys/arch/sparc64/sparc64/machdep.c
sys/arch/sparc64/sparc64/svr4_machdep.c
sys/arch/sparc64/sparc64/vm_machdep.c
sys/arch/vax/conf/files.vax
sys/arch/vax/include/signal.h
sys/arch/vax/vax/core_machdep.c
sys/arch/vax/vax/vm_machdep.c
sys/arch/x86/x86/sys_machdep.c
sys/arch/xen/conf/files.xen
sys/compat/aoutm68k/aoutm68k_exec.c
sys/compat/aoutm68k/aoutm68k_mod.c
sys/compat/aoutm68k/files.aoutm68k
sys/compat/common/compat_mod.c
sys/compat/common/compat_util.h
sys/compat/common/tty_43.c
sys/compat/common/vfs_syscalls_43.c
sys/compat/darwin/darwin_exec.c
sys/compat/darwin/darwin_exec.h
sys/compat/freebsd/files.freebsd
sys/compat/freebsd/freebsd_exec.c
sys/compat/freebsd/freebsd_exec.h
sys/compat/freebsd/freebsd_mod.c
sys/compat/freebsd/freebsd_sysctl.c
sys/compat/freebsd/freebsd_sysctl.h
sys/compat/freebsd/syscalls.master
sys/compat/ibcs2/files.ibcs2
sys/compat/ibcs2/ibcs2_exec.c
sys/compat/ibcs2/ibcs2_exec.h
sys/compat/ibcs2/ibcs2_mod.c
sys/compat/irix/files.irix
sys/compat/irix/irix_exec.c
sys/compat/irix/irix_exec.h
sys/compat/irix/irix_mod.c
sys/compat/irix/irix_sysctl.c
sys/compat/irix/irix_sysctl.h
sys/compat/linux/arch/alpha/syscalls.master
sys/compat/linux/arch/amd64/linux_commons.c
sys/compat/linux/arch/arm/linux_commons.c
sys/compat/linux/arch/arm/syscalls.master
sys/compat/linux/arch/i386/linux_commons.c
sys/compat/linux/arch/i386/syscalls.master
sys/compat/linux/arch/mips/syscalls.master
sys/compat/linux/arch/powerpc/syscalls.master
sys/compat/linux/common/linux_exec.c
sys/compat/linux/common/linux_exec.h
sys/compat/linux/common/linux_mod.c
sys/compat/linux/common/linux_socket.c
sys/compat/linux/common/linux_sysctl.c
sys/compat/linux/common/linux_sysctl.h
sys/compat/linux/files.linux
sys/compat/linux32/arch/amd64/linux32_missing.c
sys/compat/linux32/arch/amd64/syscalls.master
sys/compat/linux32/common/linux32_dirent.c
sys/compat/linux32/common/linux32_exec.c
sys/compat/linux32/common/linux32_exec.h
sys/compat/linux32/common/linux32_fcntl.c
sys/compat/linux32/common/linux32_ioctl.c
sys/compat/linux32/common/linux32_misc.c
sys/compat/linux32/common/linux32_mman.c
sys/compat/linux32/common/linux32_mod.c
sys/compat/linux32/common/linux32_resource.c
sys/compat/linux32/common/linux32_sched.c
sys/compat/linux32/common/linux32_socket.c
sys/compat/linux32/common/linux32_socketcall.c
sys/compat/linux32/common/linux32_stat.c
sys/compat/linux32/common/linux32_sysctl.c
sys/compat/linux32/common/linux32_sysctl.h
sys/compat/linux32/common/linux32_sysinfo.c
sys/compat/linux32/common/linux32_termios.c
sys/compat/linux32/common/linux32_time.c
sys/compat/linux32/common/linux32_uid16.c
sys/compat/linux32/common/linux32_unistd.c
sys/compat/linux32/common/linux32_utsname.c
sys/compat/linux32/common/linux32_wait.c
sys/compat/linux32/files.linux32
sys/compat/m68k4k/m68k4k_exec.c
sys/compat/mach/mach_exec.c
sys/compat/mach/mach_exec.h
sys/compat/netbsd32/files.netbsd32
sys/compat/netbsd32/netbsd32_compat_30.c
sys/compat/netbsd32/netbsd32_exec.h
sys/compat/netbsd32/netbsd32_mod.c
sys/compat/netbsd32/netbsd32_netbsd.c
sys/compat/netbsd32/netbsd32_sysctl.c
sys/compat/netbsd32/netbsd32_sysctl.h
sys/compat/netbsd32/syscalls.master
sys/compat/osf1/files.osf1
sys/compat/osf1/osf1_exec.c
sys/compat/osf1/osf1_exec.h
sys/compat/osf1/osf1_mod.c
sys/compat/pecoff/files.pecoff
sys/compat/pecoff/pecoff_emul.c
sys/compat/pecoff/pecoff_exec.h
sys/compat/pecoff/pecoff_mod.c
sys/compat/sunos/files.sunos
sys/compat/sunos/sunos_exec.c
sys/compat/sunos/sunos_exec.h
sys/compat/sunos/sunos_ioctl.c
sys/compat/sunos/sunos_misc.c
sys/compat/sunos/sunos_mod.c
sys/compat/sunos/syscalls.master
sys/compat/sunos32/files.sunos32
sys/compat/sunos32/sunos32_exec.c
sys/compat/sunos32/sunos32_exec.h
sys/compat/sunos32/sunos32_misc.c
sys/compat/sunos32/sunos32_mod.c
sys/compat/sunos32/syscalls.master
sys/compat/svr4/svr4_exec.c
sys/compat/svr4/svr4_exec.h
sys/compat/svr4/svr4_mod.c
sys/compat/svr4/svr4_util.h
sys/compat/svr4_32/files.svr4_32
sys/compat/svr4_32/svr4_32_exec.c
sys/compat/svr4_32/svr4_32_exec.h
sys/compat/svr4_32/svr4_32_mod.c
sys/compat/sys/sockio.h
sys/compat/ultrix/files.ultrix
sys/compat/ultrix/syscalls.master
sys/compat/ultrix/ultrix_exec.h
sys/compat/ultrix/ultrix_misc.c
sys/compat/ultrix/ultrix_mod.c
sys/compat/vax1k/vax1k_exec.c
sys/conf/files
sys/kern/core_elf32.c
sys/kern/core_netbsd.c
sys/kern/exec_aout.c
sys/kern/exec_conf.c
sys/kern/exec_ecoff.c
sys/kern/exec_elf.c
sys/kern/exec_elf32.c
sys/kern/exec_elf64.c
sys/kern/exec_script.c
sys/kern/kern_core.c
sys/kern/kern_exec.c
sys/kern/kern_ntptime.c
sys/kern/kern_proc.c
sys/kern/kern_sig.c
sys/kern/kern_stub.c
sys/kern/sys_process.c
sys/kern/sys_sig.c
sys/kern/syscalls.master
sys/kern/tty.c
sys/kern/vfs_hooks.c
sys/kern/vfs_syscalls.c
sys/modules/Makefile
sys/modules/compat/Makefile
sys/modules/compat_freebsd/Makefile
sys/modules/compat_ibcs2/Makefile
sys/modules/compat_irix/Makefile
sys/modules/compat_linux/Makefile
sys/modules/compat_linux32/Makefile
sys/modules/compat_netbsd32/Makefile
sys/modules/compat_sunos/Makefile
sys/modules/compat_sunos32/Makefile
sys/modules/compat_svr4/Makefile
sys/modules/coredump/Makefile
sys/modules/exec_aout/Makefile
sys/modules/exec_ecoff/Makefile
sys/modules/exec_elf32/Makefile
sys/modules/exec_elf64/Makefile
sys/modules/exec_script/Makefile
sys/modules/nfs/Makefile
sys/modules/nfsserver/Makefile
sys/nfs/files.nfs
sys/nfs/nfs_bio.c
sys/nfs/nfs_boot.c
sys/nfs/nfs_bootdhcp.c
sys/nfs/nfs_bootparam.c
sys/nfs/nfs_bootstatic.c
sys/nfs/nfs_export.c
sys/nfs/nfs_iod.c
sys/nfs/nfs_kq.c
sys/nfs/nfs_node.c
sys/nfs/nfs_serv.c
sys/nfs/nfs_socket.c
sys/nfs/nfs_srvcache.c
sys/nfs/nfs_srvsocket.c
sys/nfs/nfs_srvsubs.c
sys/nfs/nfs_subs.c
sys/nfs/nfs_syscalls.c
sys/nfs/nfs_var.h
sys/nfs/nfs_vfsops.c
sys/nfs/nfs_vnops.c
sys/rump/fs/lib/libnfs/Makefile
sys/sys/exec.h
sys/sys/mount.h
sys/sys/proc.h
sys/sys/signalvar.h
sys/sys/syscallvar.h
sys/sys/tty.h
sys/uvm/files.uvm
sys/uvm/uvm_coredump.c
sys/uvm/uvm_glue.c
--- a/distrib/sets/lists/base/lkm.mi	Wed Nov 19 18:07:19 2008 +0000
+++ b/distrib/sets/lists/base/lkm.mi	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: lkm.mi,v 1.33 2008/11/14 23:33:45 ad Exp $
+# $NetBSD: lkm.mi,v 1.34 2008/11/19 18:35:57 ad Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -19,12 +19,20 @@
 ./@MODULEDIR@/coda/coda.kmod			base-kernel-modules
 ./@MODULEDIR@/coda5				base-kernel-modules
 ./@MODULEDIR@/coda5/coda5.kmod			base-kernel-modules
+./@MODULEDIR@/compat				base-kernel-modules
+./@MODULEDIR@/compat/compat.kmod		base-kernel-modules
 ./@MODULEDIR@/compat_ossaudio			base-kernel-modules
 ./@MODULEDIR@/compat_ossaudio/compat_ossaudio.kmod	base-kernel-modules
+./@MODULEDIR@/coredump				base-kernel-modules
+./@MODULEDIR@/coredump/coredump.kmod		base-kernel-modules
 ./@MODULEDIR@/dirhash				base-obsolete	obsolete
 ./@MODULEDIR@/dirhash/dirhash.kmod		base-obsolete	obsolete
 ./@MODULEDIR@/efs				base-kernel-modules
 ./@MODULEDIR@/efs/efs.kmod			base-kernel-modules
+./@MODULEDIR@/exec_elf32			base-kernel-modules
+./@MODULEDIR@/exec_elf32/exec_elf32.kmod	base-kernel-modules
+./@MODULEDIR@/exec_script			base-kernel-modules
+./@MODULEDIR@/exec_script/exec_script.kmod	base-kernel-modules
 ./@MODULEDIR@/ext2fs				base-kernel-modules
 ./@MODULEDIR@/ext2fs/ext2fs.kmod		base-kernel-modules
 ./@MODULEDIR@/fdesc				base-kernel-modules
@@ -49,6 +57,10 @@
 ./@MODULEDIR@/miniroot/miniroot.kmod		base-kernel-modules
 ./@MODULEDIR@/msdosfs				base-kernel-modules
 ./@MODULEDIR@/msdosfs/msdosfs.kmod		base-kernel-modules
+./@MODULEDIR@/nfs				base-kernel-modules
+./@MODULEDIR@/nfs/nfs.kmod			base-kernel-modules
+./@MODULEDIR@/nfsserver				base-kernel-modules
+./@MODULEDIR@/nfsserver/nfsserver.kmod		base-kernel-modules
 ./@MODULEDIR@/ntfs				base-kernel-modules
 ./@MODULEDIR@/ntfs/ntfs.kmod			base-kernel-modules
 ./@MODULEDIR@/nullfs				base-kernel-modules
--- a/distrib/sets/lists/base/md.amd64	Wed Nov 19 18:07:19 2008 +0000
+++ b/distrib/sets/lists/base/md.amd64	Wed Nov 19 18:35:57 2008 +0000
@@ -1,66 +1,18 @@
-# $NetBSD: md.amd64,v 1.30 2008/11/19 14:10:48 pooka Exp $
-./@MODULEDIR@/adosfs				base-kernel-modules
-./@MODULEDIR@/adosfs/adosfs.kmod		base-kernel-modules
+# $NetBSD: md.amd64,v 1.31 2008/11/19 18:35:57 ad Exp $
 ./@MODULEDIR@/azalia				base-kernel-modules
 ./@MODULEDIR@/azalia/azalia.kmod		base-kernel-modules
-./@MODULEDIR@/cd9660				base-kernel-modules
-./@MODULEDIR@/cd9660/cd9660.kmod		base-kernel-modules
-./@MODULEDIR@/coda				base-kernel-modules
-./@MODULEDIR@/coda/coda.kmod			base-kernel-modules
-./@MODULEDIR@/coda5				base-kernel-modules
-./@MODULEDIR@/coda5/coda5.kmod			base-kernel-modules
+./@MODULEDIR@/compat_linux			base-kernel-modules
+./@MODULEDIR@/compat_linux/compat_linux.kmod	base-kernel-modules
+./@MODULEDIR@/compat_linux32			base-kernel-modules
+./@MODULEDIR@/compat_linux32/compat_linux32.kmod	base-kernel-modules
+./@MODULEDIR@/compat_netbsd32			base-kernel-modules
+./@MODULEDIR@/compat_netbsd32/compat_netbsd32.kmod	base-kernel-modules
 ./@MODULEDIR@/drm				base-kernel-modules
 ./@MODULEDIR@/drm/drm.kmod			base-kernel-modules
-./@MODULEDIR@/efs				base-kernel-modules
-./@MODULEDIR@/efs/efs.kmod			base-kernel-modules
-./@MODULEDIR@/ext2fs				base-kernel-modules
-./@MODULEDIR@/ext2fs/ext2fs.kmod		base-kernel-modules
-./@MODULEDIR@/fdesc				base-kernel-modules
-./@MODULEDIR@/fdesc/fdesc.kmod			base-kernel-modules
-./@MODULEDIR@/ffs				base-kernel-modules
-./@MODULEDIR@/ffs/ffs.kmod			base-kernel-modules
-./@MODULEDIR@/filecorefs			base-kernel-modules
-./@MODULEDIR@/filecorefs/filecorefs.kmod	base-kernel-modules
-./@MODULEDIR@/hfs				base-kernel-modules
-./@MODULEDIR@/hfs/hfs.kmod			base-kernel-modules
+./@MODULEDIR@/exec_elf64			base-kernel-modules
+./@MODULEDIR@/exec_elf64/exec_elf64.kmod	base-kernel-modules
 ./@MODULEDIR@/i915drm				base-kernel-modules
 ./@MODULEDIR@/i915drm/i915drm.kmod		base-kernel-modules
-./@MODULEDIR@/kernfs				base-kernel-modules
-./@MODULEDIR@/kernfs/kernfs.kmod		base-kernel-modules
-./@MODULEDIR@/lfs				base-kernel-modules
-./@MODULEDIR@/lfs/lfs.kmod			base-kernel-modules
-./@MODULEDIR@/mfs				base-kernel-modules
-./@MODULEDIR@/mfs/mfs.kmod			base-kernel-modules
-./@MODULEDIR@/miniroot				base-kernel-modules
-./@MODULEDIR@/miniroot/miniroot.kmod		base-kernel-modules
-./@MODULEDIR@/msdosfs				base-kernel-modules
-./@MODULEDIR@/msdosfs/msdosfs.kmod		base-kernel-modules
-./@MODULEDIR@/ntfs				base-kernel-modules
-./@MODULEDIR@/ntfs/ntfs.kmod			base-kernel-modules
-./@MODULEDIR@/nullfs				base-kernel-modules
-./@MODULEDIR@/nullfs/nullfs.kmod		base-kernel-modules
-./@MODULEDIR@/overlay				base-kernel-modules
-./@MODULEDIR@/overlay/overlay.kmod		base-kernel-modules
-./@MODULEDIR@/portal				base-kernel-modules
-./@MODULEDIR@/portal/portal.kmod		base-kernel-modules
-./@MODULEDIR@/procfs				base-kernel-modules
-./@MODULEDIR@/procfs/procfs.kmod		base-kernel-modules
-./@MODULEDIR@/ptyfs				base-kernel-modules
-./@MODULEDIR@/ptyfs/ptyfs.kmod			base-kernel-modules
-./@MODULEDIR@/puffs				base-kernel-modules
-./@MODULEDIR@/puffs/puffs.kmod			base-kernel-modules
-./@MODULEDIR@/putter				base-kernel-modules
-./@MODULEDIR@/putter/putter.kmod		base-kernel-modules
-./@MODULEDIR@/smbfs				base-kernel-modules
-./@MODULEDIR@/smbfs/smbfs.kmod			base-kernel-modules
-./@MODULEDIR@/tmpfs				base-kernel-modules
-./@MODULEDIR@/tmpfs/tmpfs.kmod			base-kernel-modules
-./@MODULEDIR@/udf				base-kernel-modules
-./@MODULEDIR@/udf/udf.kmod			base-kernel-modules
-./@MODULEDIR@/umapfs				base-kernel-modules
-./@MODULEDIR@/umapfs/umapfs.kmod		base-kernel-modules
-./@MODULEDIR@/union				base-kernel-modules
-./@MODULEDIR@/union/union.kmod			base-kernel-modules
 ./dev/lms0					base-obsolete		obsolete
 ./dev/mms0					base-obsolete		obsolete
 ./usr/bin/fdformat				base-util-bin
--- a/distrib/sets/lists/base/md.i386	Wed Nov 19 18:07:19 2008 +0000
+++ b/distrib/sets/lists/base/md.i386	Wed Nov 19 18:35:57 2008 +0000
@@ -1,68 +1,22 @@
-# $NetBSD: md.i386,v 1.131 2008/11/12 12:35:50 ad Exp $
-./@MODULEDIR@/adosfs				base-kernel-modules
-./@MODULEDIR@/adosfs/adosfs.kmod		base-kernel-modules
+# $NetBSD: md.i386,v 1.132 2008/11/19 18:35:57 ad Exp $
 ./@MODULEDIR@/azalia				base-kernel-modules
 ./@MODULEDIR@/azalia/azalia.kmod		base-kernel-modules
-./@MODULEDIR@/cd9660				base-kernel-modules
-./@MODULEDIR@/cd9660/cd9660.kmod		base-kernel-modules
-./@MODULEDIR@/coda				base-kernel-modules
-./@MODULEDIR@/coda/coda.kmod			base-kernel-modules
-./@MODULEDIR@/coda5				base-kernel-modules
-./@MODULEDIR@/coda5/coda5.kmod			base-kernel-modules
+./@MODULEDIR@/compat_freebsd			base-kernel-modules
+./@MODULEDIR@/compat_freebsd/compat_freebsd.kmod	base-kernel-modules
+./@MODULEDIR@/compat_ibcs2			base-kernel-modules
+./@MODULEDIR@/compat_ibcs2/compat_ibcs2.kmod	base-kernel-modules
+./@MODULEDIR@/compat_linux			base-kernel-modules
+./@MODULEDIR@/compat_linux/compat_linux.kmod	base-kernel-modules
+./@MODULEDIR@/compat_svr4			base-kernel-modules
+./@MODULEDIR@/compat_svr4/compat_svr4.kmod	base-kernel-modules
 ./@MODULEDIR@/drm				base-kernel-modules
 ./@MODULEDIR@/drm/drm.kmod			base-kernel-modules
-./@MODULEDIR@/efs				base-kernel-modules
-./@MODULEDIR@/efs/efs.kmod			base-kernel-modules
-./@MODULEDIR@/ext2fs				base-kernel-modules
-./@MODULEDIR@/ext2fs/ext2fs.kmod		base-kernel-modules
-./@MODULEDIR@/fdesc				base-kernel-modules
-./@MODULEDIR@/fdesc/fdesc.kmod			base-kernel-modules
-./@MODULEDIR@/ffs				base-kernel-modules
-./@MODULEDIR@/ffs/ffs.kmod			base-kernel-modules
-./@MODULEDIR@/filecorefs			base-kernel-modules
-./@MODULEDIR@/filecorefs/filecorefs.kmod	base-kernel-modules
-./@MODULEDIR@/hfs				base-kernel-modules
-./@MODULEDIR@/hfs/hfs.kmod			base-kernel-modules
+./@MODULEDIR@/exec_aout				base-kernel-modules
+./@MODULEDIR@/exec_aout/exec_aout.kmod		base-kernel-modules
 ./@MODULEDIR@/i915drm				base-kernel-modules
 ./@MODULEDIR@/i915drm/i915drm.kmod		base-kernel-modules
-./@MODULEDIR@/kernfs				base-kernel-modules
-./@MODULEDIR@/kernfs/kernfs.kmod		base-kernel-modules
-./@MODULEDIR@/lfs				base-kernel-modules
-./@MODULEDIR@/lfs/lfs.kmod			base-kernel-modules
-./@MODULEDIR@/mfs				base-kernel-modules
-./@MODULEDIR@/mfs/mfs.kmod			base-kernel-modules
-./@MODULEDIR@/miniroot				base-kernel-modules
-./@MODULEDIR@/miniroot/miniroot.kmod		base-kernel-modules
-./@MODULEDIR@/msdosfs				base-kernel-modules
-./@MODULEDIR@/msdosfs/msdosfs.kmod		base-kernel-modules
-./@MODULEDIR@/ntfs				base-kernel-modules
-./@MODULEDIR@/ntfs/ntfs.kmod			base-kernel-modules
-./@MODULEDIR@/nullfs				base-kernel-modules
-./@MODULEDIR@/nullfs/nullfs.kmod		base-kernel-modules
-./@MODULEDIR@/overlay				base-kernel-modules
-./@MODULEDIR@/overlay/overlay.kmod		base-kernel-modules
-./@MODULEDIR@/portal				base-kernel-modules
-./@MODULEDIR@/portal/portal.kmod		base-kernel-modules
-./@MODULEDIR@/procfs				base-kernel-modules
-./@MODULEDIR@/procfs/procfs.kmod		base-kernel-modules
-./@MODULEDIR@/ptyfs				base-kernel-modules
-./@MODULEDIR@/ptyfs/ptyfs.kmod			base-kernel-modules
-./@MODULEDIR@/puffs				base-kernel-modules
-./@MODULEDIR@/puffs/puffs.kmod			base-kernel-modules
-./@MODULEDIR@/putter				base-kernel-modules
-./@MODULEDIR@/putter/putter.kmod		base-kernel-modules
 ./@MODULEDIR@/radeondrm				base-kernel-modules
 ./@MODULEDIR@/radeondrm/radeondrm.kmod		base-kernel-modules
-./@MODULEDIR@/smbfs				base-kernel-modules
-./@MODULEDIR@/smbfs/smbfs.kmod			base-kernel-modules
-./@MODULEDIR@/tmpfs				base-kernel-modules
-./@MODULEDIR@/tmpfs/tmpfs.kmod			base-kernel-modules
-./@MODULEDIR@/udf				base-kernel-modules
-./@MODULEDIR@/udf/udf.kmod			base-kernel-modules
-./@MODULEDIR@/umapfs				base-kernel-modules
-./@MODULEDIR@/umapfs/umapfs.kmod		base-kernel-modules
-./@MODULEDIR@/union				base-kernel-modules
-./@MODULEDIR@/union/union.kmod			base-kernel-modules
 ./dev/lms0					base-obsolete		obsolete
 ./dev/mms0					base-obsolete		obsolete
 ./dev/pms0					base-obsolete		obsolete
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/alpha/alpha/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,90 @@
+/* $NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:57 ad Exp $ */
+
+/*
+ * 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 <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
+
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:57 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+#include <sys/buf.h>
+#include <sys/vnode.h>
+#include <sys/user.h>
+#include <sys/core.h>
+#include <sys/exec.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/cpu.h>
+#include <machine/alpha.h>
+#include <machine/pmap.h>
+#include <machine/reg.h>
+
+/*
+ * Dump the machine specific header information at the start of a core dump.
+ */
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	int error;
+	struct md_coredump cpustate;
+	struct coreseg cseg;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+		chdr->c_cpusize = sizeof(cpustate);
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	cpustate.md_tf = *l->l_md.md_tf;
+	cpustate.md_tf.tf_regs[FRAME_SP] = alpha_pal_rdusp();	/* XXX */
+	if (l->l_md.md_flags & MDP_FPUSED) {
+		if (l->l_addr->u_pcb.pcb_fpcpu != NULL)
+			fpusave_proc(l, 1);
+		cpustate.md_fpstate = l->l_addr->u_pcb.pcb_fp;
+	} else
+		memset(&cpustate.md_fpstate, 0, sizeof(cpustate.md_fpstate));
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+	    chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE, &cpustate,
+	    sizeof(cpustate));
+}
--- a/sys/arch/alpha/alpha/machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/alpha/alpha/machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.309 2008/11/12 12:35:55 ad Exp $ */
+/* $NetBSD: machdep.c,v 1.310 2008/11/19 18:35:57 ad Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -63,12 +63,11 @@
 #include "opt_dec_3000_300.h"
 #include "opt_dec_3000_500.h"
 #include "opt_compat_osf1.h"
-#include "opt_compat_netbsd.h"
 #include "opt_execfmt.h"
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.309 2008/11/12 12:35:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.310 2008/11/19 18:35:57 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1462,18 +1461,6 @@
 	/* Allocate space for the signal handler context. */
 	fp--;
 
-	/* Build stack frame for signal trampoline. */
-	switch (ps->sa_sigdesc[sig].sd_vers) {
-	case 0:		/* handled by sendsig_sigcontext */
-	case 1:		/* handled by sendsig_sigcontext */
-	default:	/* unknown version */
-		printf("nsendsig: bad version %d\n",
-		    ps->sa_sigdesc[sig].sd_vers);
-		sigexit(l, SIGILL);
-	case 2:
-		break;
-	}
-
 #ifdef DEBUG
 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
 		printf("sendsig_siginfo(%d): sig %d ssp %p usp %p\n", p->p_pid,
@@ -1541,26 +1528,6 @@
 }
 
 
-void
-sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
-{
-#ifdef COMPAT_16
-	if (curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers < 2) {
-		sendsig_sigcontext(ksi, mask);
-	} else {
-#endif
-#ifdef DEBUG
-	if (sigdebug & SDB_FOLLOW)
-		printf("sendsig: sendsig called: sig %d vers %d\n",
-		       ksi->ksi_signo,
-		       curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers);
-#endif
-		sendsig_siginfo(ksi, mask);
-#ifdef COMPAT_16
-	}
-#endif
-}
-
 void 
 cpu_upcall(struct lwp *l, int type, int nevents, int ninterrupted, void *sas, void *ap, void *sp, sa_upcall_t upcall)
 {
--- a/sys/arch/alpha/alpha/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/alpha/alpha/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.96 2007/10/17 19:52:56 garbled Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.97 2008/11/19 18:35:57 ad Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,8 +29,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.96 2007/10/17 19:52:56 garbled Exp $");
-#include "opt_coredump.h"
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.97 2008/11/19 18:35:57 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -49,49 +48,6 @@
 #include <machine/pmap.h>
 #include <machine/reg.h>
 
-#ifdef COREDUMP
-/*
- * Dump the machine specific header information at the start of a core dump.
- */
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	int error;
-	struct md_coredump cpustate;
-	struct coreseg cseg;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-		chdr->c_cpusize = sizeof(cpustate);
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	cpustate.md_tf = *l->l_md.md_tf;
-	cpustate.md_tf.tf_regs[FRAME_SP] = alpha_pal_rdusp();	/* XXX */
-	if (l->l_md.md_flags & MDP_FPUSED) {
-		if (l->l_addr->u_pcb.pcb_fpcpu != NULL)
-			fpusave_proc(l, 1);
-		cpustate.md_fpstate = l->l_addr->u_pcb.pcb_fp;
-	} else
-		memset(&cpustate.md_fpstate, 0, sizeof(cpustate.md_fpstate));
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-	    chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE, &cpustate,
-	    sizeof(cpustate));
-}
-#endif
-
 void
 cpu_lwp_free(struct lwp *l, int proc)
 {
--- a/sys/arch/alpha/conf/files.alpha	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/alpha/conf/files.alpha	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.alpha,v 1.179 2008/02/20 21:43:33 drochner Exp $
+# $NetBSD: files.alpha,v 1.180 2008/11/19 18:35:57 ad Exp $
 #
 # alpha-specific configuration info
 
@@ -398,6 +398,7 @@
 #
 file	arch/alpha/alpha/autoconf.c
 file	arch/alpha/alpha/clock.c
+file	arch/alpha/alpha/core_machdep.c		coredump
 file	arch/alpha/alpha/cpuconf.c
 file	arch/alpha/alpha/interrupt.c
 file	arch/alpha/alpha/ipifuncs.c		multiprocessor
--- a/sys/arch/alpha/include/signal.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/alpha/include/signal.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: signal.h,v 1.14 2005/12/11 12:16:16 christos Exp $ */
+/* $NetBSD: signal.h,v 1.15 2008/11/19 18:35:57 ad Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
@@ -34,17 +34,10 @@
 
 typedef long	sig_atomic_t;
 
-#ifdef _KERNEL
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
 #include "opt_compat_osf1.h"
 #endif
-#ifdef COMPAT_16
-#define SIGTRAMP_VALID(vers)	((unsigned)(vers) <= 2)
-#else
-#define SIGTRAMP_VALID(vers)	((vers) == 2)
-#endif
-#endif
 
 /*
  * Information pushed on stack when a signal is delivered.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amd64/amd64/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,149 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:58 ad Exp $	*/
+
+/*-
+ * Copyright (c) 1982, 1986 The Regents of the University of California.
+ * 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. 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.
+ *
+ *	@(#)vm_machdep.c	7.3 (Berkeley) 5/13/91
+ */
+
+/*-
+ * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
+ * Copyright (c) 1989, 1990 William Jolitz
+ * 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.
+ *
+ *	@(#)vm_machdep.c	7.3 (Berkeley) 5/13/91
+ */
+
+/*
+ *	Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:58 ad 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>
+#include <sys/core.h>
+#include <sys/exec.h>
+#include <sys/ptrace.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/cpu.h>
+#include <machine/gdt.h>
+#include <machine/reg.h>
+#include <machine/specialreg.h>
+#include <machine/fpu.h>
+
+/*
+ * Dump the machine specific segment at the start of a core dump.
+ */     
+struct md_core {
+	struct reg intreg;
+	struct fpreg freg;
+};
+
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	struct md_core md_core;
+	struct coreseg cseg;
+	int error;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+		chdr->c_cpusize = sizeof(md_core);
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	/* Save integer registers. */
+	error = process_read_regs(l, &md_core.intreg);
+	if (error)
+		return error;
+
+	/* Save floating point registers. */
+	error = process_read_fpregs(l, &md_core.freg);
+	if (error)
+		return error;
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+	    chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_USERSPACE, &md_core,
+	    sizeof(md_core));
+}
--- a/sys/arch/amd64/amd64/machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/amd64/amd64/machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.111 2008/11/16 20:13:50 bouyer Exp $	*/
+/*	$NetBSD: machdep.c,v 1.112 2008/11/19 18:35:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -112,7 +112,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.111 2008/11/16 20:13:50 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.112 2008/11/19 18:35:58 ad Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -538,7 +538,15 @@
 }
 
 void
-sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
+sendsig_sigcontext(const ksiginfo_t *ksi, const sigset_t *mask)
+{
+
+	printf("sendsig_sigcontext: illegal\n");
+	sigexit(curlwp, SIGILL);
+}
+
+void
+sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
 {
 	struct lwp *l = curlwp;
 	struct proc *p = l->l_proc;
@@ -570,16 +578,6 @@
 	 */
 	fp = (struct sigframe_siginfo *)(((unsigned long)sp & ~15) - 8);
 
-	/* Build stack frame for signal trampoline. */
-	switch (ps->sa_sigdesc[sig].sd_vers) {
-	default:	/* unknown version */
-		printf("nsendsig: bad version %d\n",
-		    ps->sa_sigdesc[sig].sd_vers);
-		sigexit(l, SIGILL);
-	case 2:
-		break;
-	}
-
 	/*
 	 * Don't bother copying out FP state if there is none.
 	 */
--- a/sys/arch/amd64/amd64/netbsd32_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/amd64/amd64/netbsd32_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.55 2008/10/15 06:51:17 wrstuden Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.56 2008/11/19 18:35:58 ad Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,13 +36,15 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.55 2008/10/15 06:51:17 wrstuden Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.56 2008/11/19 18:35:58 ad Exp $");
 
+#ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
 #include "opt_coredump.h"
 #include "opt_execfmt.h"
 #include "opt_user_ldt.h"
 #include "opt_mtrr.h"
+#endif
 
 #include <sys/param.h>
 #include <sys/exec.h>
--- a/sys/arch/amd64/amd64/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/amd64/amd64/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.34 2008/10/19 03:39:26 christos Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.35 2008/11/19 18:35:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,9 +80,8 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.34 2008/10/19 03:39:26 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.35 2008/11/19 18:35:58 ad Exp $");
 
-#include "opt_coredump.h"
 #include "opt_user_ldt.h"
 
 #include <sys/param.h>
@@ -253,55 +252,6 @@
 	/* nothing */
 }
 
-#ifdef COREDUMP
-/*
- * Dump the machine specific segment at the start of a core dump.
- */     
-struct md_core {
-	struct reg intreg;
-	struct fpreg freg;
-};
-
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	struct md_core md_core;
-	struct coreseg cseg;
-	int error;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-		chdr->c_cpusize = sizeof(md_core);
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	/* Save integer registers. */
-	error = process_read_regs(l, &md_core.intreg);
-	if (error)
-		return error;
-
-	/* Save floating point registers. */
-	error = process_read_fpregs(l, &md_core.freg);
-	if (error)
-		return error;
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-	    chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_USERSPACE, &md_core,
-	    sizeof(md_core));
-}
-#endif
-
 /*
  * Set a red zone in the kernel stack after the u. area.
  */
--- a/sys/arch/amd64/conf/files.amd64	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/amd64/conf/files.amd64	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.amd64,v 1.60 2008/05/11 14:44:53 ad Exp $
+#	$NetBSD: files.amd64,v 1.61 2008/11/19 18:35:58 ad Exp $
 #
 # new style config file for amd64 architecture
 #
@@ -33,6 +33,7 @@
 file	arch/amd64/amd64/amd64func.S
 file	arch/amd64/amd64/autoconf.c
 file	arch/amd64/amd64/busfunc.S
+file	arch/amd64/amd64/core_machdep.c		coredump
 file	arch/amd64/amd64/cpu_in_cksum.S		(inet | inet6) & cpu_in_cksum
 file	arch/amd64/amd64/cpufunc.S
 file	arch/amd64/amd64/db_disasm.c		ddb
--- a/sys/arch/amd64/include/signal.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/amd64/include/signal.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: signal.h,v 1.10 2008/10/26 00:08:15 mrg Exp $	*/
+/*	$NetBSD: signal.h,v 1.11 2008/11/19 18:35:58 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
@@ -48,17 +48,10 @@
 #include <machine/fpu.h>
 #include <machine/mcontext.h>
 
-#ifdef _KERNEL
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
 #include "opt_compat_netbsd32.h"
 #endif
-#if defined(COMPAT_16) && defined(COMPAT_NETBSD32)
-#define SIGTRAMP_VALID(vers)	((unsigned)(vers) <= 2)
-#else
-#define SIGTRAMP_VALID(vers)	((vers) == 2)
-#endif
-#endif
 
 #endif	/* _NETBSD_SOURCE */
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/arm/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,95 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:58 ad Exp $	*/
+
+/*
+ * Copyright (c) 1994-1998 Mark Brinicombe.
+ * Copyright (c) 1994 Brini.
+ * All rights reserved.
+ *
+ * This code is derived from software written for Brini by Mark Brinicombe
+ *
+ * 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 Brini.
+ * 4. The name of the company nor the name of the author may be used to
+ *    endorse or promote products derived from this software without specific
+ *    prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI 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.
+ */
+
+#include <sys/param.h>
+
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:58 ad Exp $");
+
+#include <sys/core.h>
+#include <sys/exec.h>
+#include <sys/ptrace.h>
+#include <sys/signalvar.h>
+#include <sys/systm.h>
+#include <sys/uio.h>
+#include <sys/vnode.h>
+
+#include <machine/reg.h>
+
+
+/*
+ * Dump the machine specific segment at the start of a core dump.
+ */
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	int error;
+	struct {
+		struct reg regs;
+		struct fpreg fpregs;
+	} cpustate;
+	struct coreseg cseg;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+		chdr->c_cpusize = sizeof(cpustate);
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	/* Save integer registers. */
+	error = process_read_regs(l, &cpustate.regs);
+	if (error)
+		return error;
+	/* Save floating point registers. */
+	error = process_read_fpregs(l, &cpustate.fpregs);
+	if (error)
+		return error;
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE,
+	    &cseg, chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE,
+	    &cpustate, sizeof(cpustate));
+}
--- a/sys/arch/arm/arm/sig_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/arm/arm/sig_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sig_machdep.c,v 1.35 2008/04/24 18:39:20 ad Exp $	*/
+/*	$NetBSD: sig_machdep.c,v 1.36 2008/11/19 18:35:58 ad Exp $	*/
 
 /*
  * Copyright (c) 1994-1998 Mark Brinicombe.
@@ -40,12 +40,11 @@
  * Created      : 17/09/94
  */
 
-#include "opt_compat_netbsd.h"
 #include "opt_armfpe.h"
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.35 2008/04/24 18:39:20 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.36 2008/11/19 18:35:58 ad Exp $");
 
 #include <sys/mount.h>		/* XXX only needed by syscallargs.h */
 #include <sys/proc.h>
@@ -89,7 +88,7 @@
  * resets the signal mask, the stack, and the
  * frame pointer, it returns to the user specified pc.
  */
-static void
+void
 sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
 {
 	struct lwp *l = curlwp;
@@ -112,18 +111,6 @@
 	/* make the stack aligned */
 	fp = (struct sigframe_siginfo *)STACKALIGN(fp);
 
-	/* Build stack frame for signal trampoline. */
-	switch (ps->sa_sigdesc[sig].sd_vers) {
-	case 0:		/* handled by sendsig_sigcontext */
-	case 1:		/* handled by sendsig_sigcontext */
-	default:	/* unknown version */
-		printf("nsendsig: bad version %d\n",
-		    ps->sa_sigdesc[sig].sd_vers);
-		sigexit(l, SIGILL);
-	case 2:
-		break;
-	}
-
 	/* populate the siginfo frame */
 	frame.sf_si._info = ksi->ksi_info;
 	frame.sf_uc.uc_flags = _UC_SIGMASK;
@@ -177,17 +164,6 @@
 }
 
 void
-sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
-{
-#ifdef COMPAT_16
-	if (curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers < 2)
-		sendsig_sigcontext(ksi, mask);
-	else
-#endif
-		sendsig_siginfo(ksi, mask);
-}
-
-void
 cpu_getmcontext(l, mcp, flags)
 	struct lwp *l;
 	mcontext_t *mcp;
--- a/sys/arch/arm/arm/vm_machdep_arm.c	Wed Nov 19 18:07:19 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-/*	$NetBSD: vm_machdep_arm.c,v 1.11 2006/08/30 22:24:55 matt Exp $	*/
-
-/*
- * Copyright (c) 1994-1998 Mark Brinicombe.
- * Copyright (c) 1994 Brini.
- * All rights reserved.
- *
- * This code is derived from software written for Brini by Mark Brinicombe
- *
- * 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 Brini.
- * 4. The name of the company nor the name of the author may be used to
- *    endorse or promote products derived from this software without specific
- *    prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI 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.
- */
-
-#include <sys/param.h>
-
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep_arm.c,v 1.11 2006/08/30 22:24:55 matt Exp $");
-#include "opt_coredump.h"
-
-#include <sys/core.h>
-#include <sys/exec.h>
-#include <sys/ptrace.h>
-#include <sys/signalvar.h>
-#include <sys/systm.h>
-#include <sys/uio.h>
-#include <sys/vnode.h>
-
-#include <machine/reg.h>
-
-
-/*
- * Dump the machine specific segment at the start of a core dump.
- */
-
-#ifdef COREDUMP
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	int error;
-	struct {
-		struct reg regs;
-		struct fpreg fpregs;
-	} cpustate;
-	struct coreseg cseg;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-		chdr->c_cpusize = sizeof(cpustate);
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	/* Save integer registers. */
-	error = process_read_regs(l, &cpustate.regs);
-	if (error)
-		return error;
-	/* Save floating point registers. */
-	error = process_read_fpregs(l, &cpustate.fpregs);
-	if (error)
-		return error;
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE,
-	    &cseg, chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE,
-	    &cpustate, sizeof(cpustate));
-}
-#endif
--- a/sys/arch/arm/conf/files.arm	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/arm/conf/files.arm	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.arm,v 1.93 2008/10/14 16:01:22 matt Exp $
+#	$NetBSD: files.arm,v 1.94 2008/11/19 18:35:58 ad Exp $
 
 # temporary define to allow easy moving to ../arch/arm/arm32
 defflag				ARM32
@@ -94,6 +94,7 @@
 file	arch/arm/arm/compat_13_machdep.c	compat_13
 file	arch/arm/arm/compat_16_machdep.c	compat_16
 file	arch/arm/arm/copystr.S
+file	arch/arm/arm/core_machdep.c
 file	arch/arm/arm/cpu_in_cksum.S		(inet | inet6) & cpu_in_cksum
 file	arch/arm/arm/cpufunc.c
 file	arch/arm/arm/cpufunc_asm.S
@@ -143,7 +144,6 @@
 # vectors.S gets included manually by Makefile.acorn26, since it needs
 # to be at the start of the text segment on those machines.
 file	arch/arm/arm/vectors.S			arm32
-file	arch/arm/arm/vm_machdep_arm.c
 
 # files common to arm32 implementations
 file	arch/arm/arm32/arm32_machdep.c		arm32
--- a/sys/arch/arm/include/signal.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/arm/include/signal.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: signal.h,v 1.10 2005/12/11 12:16:47 christos Exp $	*/
+/*	$NetBSD: signal.h,v 1.11 2008/11/19 18:35:58 ad Exp $	*/
 
 /*
  * Copyright (c) 1994-1996 Mark Brinicombe.
@@ -54,14 +54,6 @@
 
 #if defined(_NETBSD_SOURCE)
 
-#ifdef _KERNEL
-#ifdef COMPAT_16
-#define SIGTRAMP_VALID(vers)	((unsigned)(vers) <= 2)
-#else
-#define SIGTRAMP_VALID(vers)	((vers) == 2)
-#endif
-#endif
-
 #ifndef _LOCORE
 /*
  * Information pushed on stack when a signal is delivered.
--- a/sys/arch/hppa/conf/files.hppa	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/hppa/conf/files.hppa	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.hppa,v 1.14 2008/04/25 12:41:50 skrll Exp $
+#	$NetBSD: files.hppa,v 1.15 2008/11/19 18:35:58 ad Exp $
 #
 #	$OpenBSD: files.hppa,v 1.31 2001/06/26 02:41:25 mickey Exp $
 #
@@ -9,6 +9,7 @@
 			HP7200_CPU HP7250_CPU HP7300LC_CPU
 			HP8000_CPU HP8200_CPU HP8500_CPU HP8600_CPU
 
+file	arch/hppa/hppa/core_machdep.c		coredump
 file	arch/hppa/hppa/db_interface.c		ddb
 file	arch/hppa/hppa/db_disasm.c		ddb
 file	arch/hppa/hppa/db_memrw.c		ddb | kgdb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hppa/hppa/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,98 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:58 ad Exp $	*/
+
+/*	$OpenBSD: vm_machdep.c,v 1.25 2001/09/19 20:50:56 mickey Exp $	*/
+
+/*
+ * Copyright (c) 1999-2000 Michael Shalayeff
+ * All rights reserved.
+ *
+ * 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 Michael Shalayeff.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR OR HIS RELATIVES 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 MIND, 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:58 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/signalvar.h>
+#include <sys/malloc.h>
+#include <sys/buf.h>
+#include <sys/vnode.h>
+#include <sys/user.h>
+#include <sys/ptrace.h>
+#include <sys/exec.h>
+#include <sys/core.h>
+
+#include <machine/cpufunc.h>
+#include <machine/pmap.h>
+#include <machine/pcb.h>
+
+#include <uvm/uvm.h>
+
+#include <hppa/hppa/machdep.h>
+
+/*
+ * Dump the machine specific header information at the start of a core dump.
+ */
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *core)
+{
+	struct md_coredump md_core;
+	struct coreseg cseg;
+	int error;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*core, COREMAGIC, MID_MACHINE, 0);
+		core->c_hdrsize = ALIGN(sizeof(*core));
+		core->c_seghdrsize = ALIGN(sizeof(cseg));
+		core->c_cpusize = sizeof(md_core);
+		core->c_nseg++;
+		return 0;
+	}
+
+	error = process_read_regs(l, &md_core.md_reg);
+	if (error)
+		return error;
+
+	/* Save floating point registers. */
+	error = process_read_fpregs(l, &md_core.md_fpreg);
+	if (error)
+		return error;
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = core->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+	    core->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
+	    sizeof(md_core));
+}
--- a/sys/arch/hppa/hppa/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/hppa/hppa/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.33 2008/10/17 12:35:12 skrll Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.34 2008/11/19 18:35:58 ad Exp $	*/
 
 /*	$OpenBSD: vm_machdep.c,v 1.25 2001/09/19 20:50:56 mickey Exp $	*/
 
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.33 2008/10/17 12:35:12 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.34 2008/11/19 18:35:58 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -56,47 +56,6 @@
 
 #include <hppa/hppa/machdep.h>
 
-/*
- * Dump the machine specific header information at the start of a core dump.
- */
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *core)
-{
-	struct md_coredump md_core;
-	struct coreseg cseg;
-	int error;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*core, COREMAGIC, MID_MACHINE, 0);
-		core->c_hdrsize = ALIGN(sizeof(*core));
-		core->c_seghdrsize = ALIGN(sizeof(cseg));
-		core->c_cpusize = sizeof(md_core);
-		core->c_nseg++;
-		return 0;
-	}
-
-	error = process_read_regs(l, &md_core.md_reg);
-	if (error)
-		return error;
-
-	/* Save floating point registers. */
-	error = process_read_fpregs(l, &md_core.md_fpreg);
-	if (error)
-		return error;
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = core->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-	    core->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
-	    sizeof(md_core));
-}
-
 void
 cpu_swapin(struct lwp *l)
 {
--- a/sys/arch/i386/conf/files.i386	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/i386/conf/files.i386	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.i386,v 1.338 2008/06/13 17:26:33 christos Exp $
+#	$NetBSD: files.i386,v 1.339 2008/11/19 18:35:58 ad Exp $
 #
 # new style config file for i386 architecture
 #
@@ -66,6 +66,7 @@
 
 file	arch/i386/i386/autoconf.c
 file	arch/i386/i386/busfunc.S
+file	arch/i386/i386/core_machdep.c	coredump
 file	arch/i386/i386/cpufunc.S
 file	arch/i386/i386/cpu_in_cksum.S	(inet | inet6) & cpu_in_cksum
 file	arch/i386/i386/db_dbgreg.S	ddb | kstack_check_dr0
--- a/sys/arch/i386/i386/compat_16_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/i386/i386/compat_16_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_16_machdep.c,v 1.18 2008/11/14 13:11:53 ad Exp $	*/
+/*	$NetBSD: compat_16_machdep.c,v 1.19 2008/11/19 18:35:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.18 2008/11/14 13:11:53 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.19 2008/11/19 18:35:58 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_vm86.h"
@@ -269,97 +269,3 @@
 		l->l_sigstk.ss_flags |= SS_ONSTACK;
 }
 #endif
-
-#if defined(COMPAT_16) && defined(VM86)
-struct compat_16_vm86_kern {
-	struct sigcontext regs;
-	unsigned long ss_cpu_type;
-};
-
-struct compat_16_vm86_struct {
-	struct compat_16_vm86_kern substr;
-	unsigned long screen_bitmap;	/* not used/supported (yet) */
-	unsigned long flags;		/* not used/supported (yet) */
-	unsigned char int_byuser[32];	/* 256 bits each: pass control to user */
-	unsigned char int21_byuser[32];	/* otherwise, handle directly */
-};
-
-int
-compat_16_x86_vm86(struct lwp *l, char *args, register_t *retval)
-{
-	struct trapframe *tf = l->l_md.md_regs;
-	struct pcb *pcb = &l->l_addr->u_pcb;
-	struct compat_16_vm86_kern vm86s;
-	struct proc *p = l->l_proc;
-	int error;
-
-	error = copyin(args, &vm86s, sizeof(vm86s));
-	if (error)
-		return (error);
-
-	pcb->vm86_userp = (void *)(args +
-	    (offsetof(struct compat_16_vm86_struct, screen_bitmap)
-	    - offsetof(struct vm86_struct, screen_bitmap)));
-	printf("offsetting by %lu\n", (unsigned long)
-	    (offsetof(struct compat_16_vm86_struct, screen_bitmap)
-	    - offsetof(struct vm86_struct, screen_bitmap)));
-
-	/*
-	 * Keep mask of flags we simulate to simulate a particular type of
-	 * processor.
-	 */
-	switch (vm86s.ss_cpu_type) {
-	case VCPU_086:
-	case VCPU_186:
-	case VCPU_286:
-		pcb->vm86_flagmask = PSL_ID|PSL_AC|PSL_NT|PSL_IOPL;
-		break;
-	case VCPU_386:
-		pcb->vm86_flagmask = PSL_ID|PSL_AC;
-		break;
-	case VCPU_486:
-		pcb->vm86_flagmask = PSL_ID;
-		break;
-	case VCPU_586:
-		pcb->vm86_flagmask = 0;
-		break;
-	default:
-		return (EINVAL);
-	}
-
-#define DOVREG(reg) tf->tf_vm86_##reg = (u_short) vm86s.regs.sc_##reg
-#define DOREG(reg) tf->tf_##reg = (u_short) vm86s.regs.sc_##reg
-
-	DOVREG(ds);
-	DOVREG(es);
-	DOVREG(fs);
-	DOVREG(gs);
-	DOREG(edi);
-	DOREG(esi);
-	DOREG(ebp);
-	DOREG(eax);
-	DOREG(ebx);
-	DOREG(ecx);
-	DOREG(edx);
-	DOREG(eip);
-	DOREG(cs);
-	DOREG(esp);
-	DOREG(ss);
-
-#undef	DOVREG
-#undef	DOREG
-
-	mutex_enter(p->p_lock);
-
-	/* Going into vm86 mode jumps off the signal stack. */
-	l->l_sigstk.ss_flags &= ~SS_ONSTACK;
-
-	mutex_exit(p->p_lock);
-
-	set_vflags(l, vm86s.regs.sc_eflags | PSL_VM);
-
-	return (EJUSTRETURN);
-}
-
-#endif
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/i386/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,149 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:58 ad Exp $	*/
+
+/*-
+ * Copyright (c) 1982, 1986 The Regents of the University of California.
+ * 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. 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.
+ *
+ *	@(#)vm_machdep.c	7.3 (Berkeley) 5/13/91
+ */
+
+/*-
+ * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
+ * Copyright (c) 1989, 1990 William Jolitz
+ * 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.
+ *
+ *	@(#)vm_machdep.c	7.3 (Berkeley) 5/13/91
+ */
+
+/*
+ *	Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:58 ad 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>
+#include <sys/core.h>
+#include <sys/exec.h>
+#include <sys/ptrace.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/cpu.h>
+#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;
+};
+
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	struct md_core md_core;
+	struct coreseg cseg;
+	int error;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+		chdr->c_cpusize = sizeof(md_core);
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	/* Save integer registers. */
+	error = process_read_regs(l, &md_core.intreg);
+	if (error)
+		return error;
+
+	/* Save floating point registers. */
+	error = process_read_fpregs(l, &md_core.freg);
+	if (error)
+		return error;
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+	    chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE,
+	    &md_core, sizeof(md_core));
+}
--- a/sys/arch/i386/i386/locore.S	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/i386/i386/locore.S	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.80 2008/11/13 10:53:30 ad Exp $	*/
+/*	$NetBSD: locore.S,v 1.81 2008/11/19 18:35:58 ad Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -134,7 +134,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.80 2008/11/13 10:53:30 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.81 2008/11/19 18:35:58 ad Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_ddb.h"
@@ -1176,6 +1176,38 @@
 	jmp	.Lsyscall_checkast	/* re-check ASTs */
 IDTVEC_END(syscall)
 
+IDTVEC(svr4_fasttrap)
+	pushl	$2		# size of instruction for restart
+	pushl	$T_ASTFLT	# trap # for doing ASTs
+	INTRENTRY
+	pushl	$RW_READER
+	pushl	$_C_LABEL(svr4_fasttrap_lock)
+	call	_C_LABEL(rw_enter)
+	addl	$8,%esp
+	call	*_C_LABEL(svr4_fasttrap_vec)
+	pushl	$_C_LABEL(svr4_fasttrap_lock)
+	call	_C_LABEL(rw_exit)
+	addl	$4,%esp
+2:	/* Check for ASTs on exit to user mode. */
+	cli
+	CHECK_ASTPENDING(%eax)		
+	je	1f
+	/* Always returning to user mode here. */
+	CLEAR_ASTPENDING(%eax)
+	sti
+	/* Pushed T_ASTFLT into tf_trapno on entry. */
+	pushl	%esp
+	call	_C_LABEL(trap)
+	addl	$4,%esp
+	jmp	2b
+1:	CHECK_DEFERRED_SWITCH
+	jnz	9f
+	INTRFASTEXIT
+9:	sti
+	call	_C_LABEL(pmap_load)
+	cli
+	jmp	2b
+
 #if NNPX > 0
 /*
  * Special interrupt handlers.  Someday intr0-intr15 will be used to count
--- a/sys/arch/i386/i386/machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/i386/i386/machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.650 2008/11/14 00:41:36 cegger Exp $	*/
+/*	$NetBSD: machdep.c,v 1.651 2008/11/19 18:35:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.650 2008/11/14 00:41:36 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.651 2008/11/19 18:35:59 ad Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -774,7 +774,7 @@
 	l->l_md.md_flags &= ~MDL_USEDFPU;
 }
 
-static void
+void
 sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
 {
 	struct lwp *l = curlwp;
@@ -793,18 +793,6 @@
 
 	fp--;
 
-	/* Build stack frame for signal trampoline. */
-	switch (ps->sa_sigdesc[sig].sd_vers) {
-	case 0:		/* handled by sendsig_sigcontext */
-	case 1:		/* handled by sendsig_sigcontext */
-	default:	/* unknown version */
-		printf("nsendsig: bad version %d\n",
-		    ps->sa_sigdesc[sig].sd_vers);
-		sigexit(l, SIGILL);
-	case 2:
-		break;
-	}
-
 	frame.sf_ra = (int)ps->sa_sigdesc[sig].sd_tramp;
 	frame.sf_signum = sig;
 	frame.sf_sip = &fp->sf_si;
@@ -843,22 +831,8 @@
 }
 
 void
-sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
-{
-
-	KASSERT(mutex_owned(curproc->p_lock));
-
-#ifdef COMPAT_16
-	if (curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers < 2)
-		sendsig_sigcontext(ksi, mask);
-	else
-#endif
-		sendsig_siginfo(ksi, mask);
-}
-
-void
 cpu_upcall(struct lwp *l, int type, int nevents, int ninterrupted, void *sas,
-    void *ap, void *sp, sa_upcall_t upcall)
+	   void *ap, void *sp, sa_upcall_t upcall)
 {
 	struct pmap *pmap = vm_map_pmap(&l->l_proc->p_vmspace->vm_map);
 	struct saframe *sf, frame;
@@ -1132,9 +1106,9 @@
 extern vector IDTVEC(syscall);
 extern vector IDTVEC(osyscall);
 extern vector *IDTVEC(exceptions)[];
-#ifdef COMPAT_SVR4
 extern vector IDTVEC(svr4_fasttrap);
-#endif /* COMPAT_SVR4 */
+void (*svr4_fasttrap_vec)(void) = (void (*)(void))nullop;
+krwlock_t svr4_fasttrap_lock;
 #ifdef COMPAT_MACH
 extern vector IDTVEC(mach_trap);
 #endif
@@ -1551,11 +1525,9 @@
 	idt_vec_reserve(128);
 	setgate(&idt[128], &IDTVEC(syscall), 0, SDT_SYS386TGT, SEL_UPL,
 	    GSEL(GCODE_SEL, SEL_KPL));
-#ifdef COMPAT_SVR4
 	idt_vec_reserve(0xd2);
 	setgate(&idt[0xd2], &IDTVEC(svr4_fasttrap), 0, SDT_SYS386TGT,
 	    SEL_UPL, GSEL(GCODE_SEL, SEL_KPL));
-#endif /* COMPAT_SVR4 */
 
 	setregion(&region, gdt, NGDT * sizeof(gdt[0]) - 1);
 	lgdt(&region);
@@ -1593,14 +1565,12 @@
 	xen_idt[xen_idt_idx].cs = GSEL(GCODE_SEL, SEL_KPL);
 	xen_idt[xen_idt_idx].address = (uint32_t)&IDTVEC(syscall);
 	xen_idt_idx++;
-#ifdef COMPAT_SVR4
 	KASSERT(xen_idt_idx < MAX_XEN_IDT);
 	xen_idt[xen_idt_idx].vector = 0xd2;
 	xen_idt[xen_idt_idx].flags = SEL_UPL;
 	xen_idt[xen_idt_idx].cs = GSEL(GCODE_SEL, SEL_KPL);
 	xen_idt[xen_idt_idx].address = (uint32_t)&IDTVEC(svr4_fasttrap);
 	xen_idt_idx++;
-#endif /* COMPAT_SVR4 */
 	lldt(GSEL(GLDT_SEL, SEL_KPL));
 
 	XENPRINTF(("HYPERVISOR_set_trap_table %p\n", xen_idt));
@@ -1652,6 +1622,8 @@
 		       ptoa(physmem), 2*1024*1024UL);
 		cngetc();
 	}
+
+	rw_init(&svr4_fasttrap_lock);
 }
 
 #ifdef COMPAT_NOMID
--- a/sys/arch/i386/i386/process_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/i386/i386/process_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,7 +1,7 @@
-/*	$NetBSD: process_machdep.c,v 1.67 2008/04/28 20:23:24 martin Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.68 2008/11/19 18:35:59 ad Exp $	*/
 
 /*-
- * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2000, 2001, 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -52,11 +52,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.67 2008/04/28 20:23:24 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.68 2008/11/19 18:35:59 ad Exp $");
 
 #include "opt_vm86.h"
 #include "opt_ptrace.h"
-#include "opt_coredump.h"
 #include "npx.h"
 
 #include <sys/param.h>
@@ -78,7 +77,6 @@
 #include <machine/vm86.h>
 #endif
 
-#if defined(PTRACE) || defined(COREDUMP)
 static inline struct trapframe *
 process_frame(struct lwp *l)
 {
@@ -92,7 +90,6 @@
 
 	return (&l->l_addr->u_pcb.pcb_savefpu);
 }
-#endif /* defined(PTRACE) || defined(COREDUMP) */
 
 static int
 xmm_to_s87_tag(const uint8_t *fpac, int regno, uint8_t tw)
@@ -208,7 +205,6 @@
 #endif
 }
 
-#if defined(PTRACE) || defined(COREDUMP)
 int
 process_read_regs(struct lwp *l, struct reg *regs)
 {
@@ -291,7 +287,6 @@
 		memcpy(regs, &frame->sv_87, sizeof(*regs));
 	return (0);
 }
-#endif /* defined(PTRACE) || defined(COREDUMP) */
 
 #ifdef PTRACE
 int
--- a/sys/arch/i386/i386/svr4_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/i386/i386/svr4_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: svr4_machdep.c,v 1.92 2008/09/19 19:15:58 christos Exp $	 */
+/*	$NetBSD: svr4_machdep.c,v 1.93 2008/11/19 18:35:59 ad Exp $	 */
 
 /*-
  * Copyright (c) 1994, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.92 2008/09/19 19:15:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.93 2008/11/19 18:35:59 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vm86.h"
@@ -71,6 +71,7 @@
 #include <machine/svr4_machdep.h>
 
 static void svr4_getsiginfo(union svr4_siginfo *, int, u_long, void *);
+extern void (*svr4_fasttrap_vec)(void);
 void svr4_fasttrap(struct trapframe);
 
 #ifdef DEBUG_SVR4
@@ -485,6 +486,8 @@
 
 /*
  * Fast syscall gate trap...
+ *
+ * NOTE: svr4_fasttrap_lock is held.
  */
 void
 svr4_fasttrap(struct trapframe frame)
@@ -499,11 +502,7 @@
 	l->l_md.md_regs = &frame;
 
 	if (p->p_emul != &emul_svr4) {
-		ksiginfo_t ksi;
-		memset(&ksi, 0, sizeof(ksi));
-		ksi.ksi_signo = SIGILL;
-		ksi.ksi_code = ILL_ILLTRP;
-		trapsignal(l, &ksi);
+		/* can't exit, because we need svr4_fasttrap_lock held. */
 		return;
 	}
 
@@ -562,3 +561,20 @@
 		break;
 	}
 }
+
+void
+svr4_md_init(void)
+{
+
+	svr4_fasttrap_vec = (void (*)(void))svr4_fasttrap;
+}
+
+void
+svr4_md_fini(void)
+{
+	extern krwlock_t svr4_fasttrap_lock;
+
+	rw_enter(&svr4_fasttrap_lock, RW_WRITER);
+	svr4_fasttrap_vec = (void (*)(void))nullop;
+	rw_exit(&svr4_fasttrap_lock);
+}
--- a/sys/arch/i386/i386/svr4_sigcode.S	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/i386/i386/svr4_sigcode.S	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: svr4_sigcode.S,v 1.12 2008/04/28 20:23:24 martin Exp $	*/
+/*	$NetBSD: svr4_sigcode.S,v 1.13 2008/11/19 18:35:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -64,12 +64,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_sigcode.S,v 1.12 2008/04/28 20:23:24 martin Exp $");
-
-#if defined(_KERNEL_OPT)
-#include "opt_vm86.h"
-#include "opt_multiprocessor.h"
-#endif
+__KERNEL_RCSID(0, "$NetBSD: svr4_sigcode.S,v 1.13 2008/11/19 18:35:59 ad Exp $");
 
 #include "assym.h"
 
@@ -95,28 +90,3 @@
 	int	$0x80			# exit if sigreturn fails
 	.globl	_C_LABEL(svr4_esigcode)
 _C_LABEL(svr4_esigcode):
-
-IDTVEC(svr4_fasttrap)
-	pushl	$2		# size of instruction for restart
-	pushl	$T_ASTFLT	# trap # for doing ASTs
-	INTRENTRY
-	call	_C_LABEL(svr4_fasttrap)
-2:	/* Check for ASTs on exit to user mode. */
-	cli
-	CHECK_ASTPENDING(%eax)		
-	je	1f
-	/* Always returning to user mode here. */
-	CLEAR_ASTPENDING(%eax)
-	sti
-	/* Pushed T_ASTFLT into tf_trapno on entry. */
-	pushl	%esp
-	call	_C_LABEL(trap)
-	addl	$4,%esp
-	jmp	2b
-1:	CHECK_DEFERRED_SWITCH
-	jnz	9f
-	INTRFASTEXIT
-9:	sti
-	call	_C_LABEL(pmap_load)
-	cli
-	jmp	2b
--- a/sys/arch/i386/i386/vm86.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/i386/i386/vm86.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm86.c,v 1.48 2008/04/28 20:23:24 martin Exp $	*/
+/*	$NetBSD: vm86.c,v 1.49 2008/11/19 18:35:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm86.c,v 1.48 2008/04/28 20:23:24 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm86.c,v 1.49 2008/11/19 18:35:59 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -441,3 +441,93 @@
 
 	return (EJUSTRETURN);
 }
+
+struct compat_16_vm86_kern {
+	struct sigcontext regs;
+	unsigned long ss_cpu_type;
+};
+
+struct compat_16_vm86_struct {
+	struct compat_16_vm86_kern substr;
+	unsigned long screen_bitmap;	/* not used/supported (yet) */
+	unsigned long flags;		/* not used/supported (yet) */
+	unsigned char int_byuser[32];	/* 256 bits each: pass control to user */
+	unsigned char int21_byuser[32];	/* otherwise, handle directly */
+};
+
+int
+compat_16_x86_vm86(struct lwp *l, char *args, register_t *retval)
+{
+	struct trapframe *tf = l->l_md.md_regs;
+	struct pcb *pcb = &l->l_addr->u_pcb;
+	struct compat_16_vm86_kern vm86s;
+	struct proc *p = l->l_proc;
+	int error;
+
+	error = copyin(args, &vm86s, sizeof(vm86s));
+	if (error)
+		return (error);
+
+	pcb->vm86_userp = (void *)(args +
+	    (offsetof(struct compat_16_vm86_struct, screen_bitmap)
+	    - offsetof(struct vm86_struct, screen_bitmap)));
+	printf("offsetting by %lu\n", (unsigned long)
+	    (offsetof(struct compat_16_vm86_struct, screen_bitmap)
+	    - offsetof(struct vm86_struct, screen_bitmap)));
+
+	/*
+	 * Keep mask of flags we simulate to simulate a particular type of
+	 * processor.
+	 */
+	switch (vm86s.ss_cpu_type) {
+	case VCPU_086:
+	case VCPU_186:
+	case VCPU_286:
+		pcb->vm86_flagmask = PSL_ID|PSL_AC|PSL_NT|PSL_IOPL;
+		break;
+	case VCPU_386:
+		pcb->vm86_flagmask = PSL_ID|PSL_AC;
+		break;
+	case VCPU_486:
+		pcb->vm86_flagmask = PSL_ID;
+		break;
+	case VCPU_586:
+		pcb->vm86_flagmask = 0;
+		break;
+	default:
+		return (EINVAL);
+	}
+
+#define DOVREG(reg) tf->tf_vm86_##reg = (u_short) vm86s.regs.sc_##reg
+#define DOREG(reg) tf->tf_##reg = (u_short) vm86s.regs.sc_##reg
+
+	DOVREG(ds);
+	DOVREG(es);
+	DOVREG(fs);
+	DOVREG(gs);
+	DOREG(edi);
+	DOREG(esi);
+	DOREG(ebp);
+	DOREG(eax);
+	DOREG(ebx);
+	DOREG(ecx);
+	DOREG(edx);
+	DOREG(eip);
+	DOREG(cs);
+	DOREG(esp);
+	DOREG(ss);
+
+#undef	DOVREG
+#undef	DOREG
+
+	mutex_enter(p->p_lock);
+
+	/* Going into vm86 mode jumps off the signal stack. */
+	l->l_sigstk.ss_flags &= ~SS_ONSTACK;
+
+	mutex_exit(p->p_lock);
+
+	set_vflags(l, vm86s.regs.sc_eflags | PSL_VM);
+
+	return (EJUSTRETURN);
+}
--- a/sys/arch/i386/i386/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/i386/i386/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.140 2008/11/12 12:36:02 ad Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.141 2008/11/19 18:35:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,13 +80,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.140 2008/11/12 12:36:02 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.141 2008/11/19 18:35:59 ad Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_mtrr.h"
 #include "opt_noredzone.h"
 #include "opt_execfmt.h"
-#include "opt_coredump.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -265,56 +264,6 @@
 	/* nothing */
 }
 
-#if (defined(EXEC_AOUT) || defined(EXEC_COFF) || defined(EXEC_ECOFF) || \
-    defined(EXEC_MACHO) || defined(MODULAR)) && defined(COREDUMP)
-/*
- * Dump the machine specific segment at the start of a core dump.
- */
-struct md_core {
-	struct reg intreg;
-	struct fpreg freg;
-};
-
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	struct md_core md_core;
-	struct coreseg cseg;
-	int error;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-		chdr->c_cpusize = sizeof(md_core);
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	/* Save integer registers. */
-	error = process_read_regs(l, &md_core.intreg);
-	if (error)
-		return error;
-
-	/* Save floating point registers. */
-	error = process_read_fpregs(l, &md_core.freg);
-	if (error)
-		return error;
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-	    chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE,
-	    &md_core, sizeof(md_core));
-}
-#endif
-
 #ifndef NOREDZONE
 /*
  * Set a red zone in the kernel stack after the u. area.
--- a/sys/arch/i386/include/signal.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/i386/include/signal.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: signal.h,v 1.28 2008/11/14 12:53:18 ad Exp $	*/
+/*	$NetBSD: signal.h,v 1.29 2008/11/19 18:35:59 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
@@ -38,10 +38,6 @@
 
 typedef int sig_atomic_t;
 
-#ifdef _KERNEL
-#define SIGTRAMP_VALID(vers)	((unsigned)(vers) <= 2)
-#endif
-
 #if defined(_NETBSD_SOURCE)
 /*
  * Get the "code" values
--- a/sys/arch/m68k/conf/files.m68k	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/m68k/conf/files.m68k	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.m68k,v 1.44 2008/01/25 21:12:12 joerg Exp $
+#	$NetBSD: files.m68k,v 1.45 2008/11/19 18:35:59 ad Exp $
 #
 
 defflag	opt_fpsp.h		FPSP
@@ -7,6 +7,7 @@
 
 file	arch/m68k/m68k/copy.s
 file	arch/m68k/m68k/copypage.s
+file	arch/m68k/m68k/core_machdep.c		coredump
 file	arch/m68k/m68k/db_disasm.c		ddb
 file	arch/m68k/m68k/db_interface.c		ddb
 file	arch/m68k/m68k/db_trace.c		ddb
--- a/sys/arch/m68k/include/signal.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/m68k/include/signal.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: signal.h,v 1.23 2006/04/01 18:03:55 oster Exp $	*/
+/*	$NetBSD: signal.h,v 1.24 2008/11/19 18:35:59 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
@@ -40,14 +40,6 @@
 
 #if defined(_NETBSD_SOURCE)
 
-#ifdef _KERNEL
-#ifdef COMPAT_16
-#define SIGTRAMP_VALID(vers)	((unsigned)(vers) <= 2)
-#else
-#define SIGTRAMP_VALID(vers)	((vers) == 2)
-#endif
-#endif
-
 /*
  * Get the "code" values
  */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/m68k/m68k/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,149 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:59 ad Exp $	*/
+
+/*
+ * Copyright (c) 1982, 1986, 1990, 1993
+ *	The Regents of the University of California.  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.
+ *
+ * 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. 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: Utah $Hdr: vm_machdep.c 1.21 91/04/06$
+ *
+ *	@(#)vm_machdep.c	8.6 (Berkeley) 1/12/94
+ */
+/*
+ * Copyright (c) 1988 University of Utah.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * 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: Utah $Hdr: vm_machdep.c 1.21 91/04/06$
+ *
+ *	@(#)vm_machdep.c	8.6 (Berkeley) 1/12/94
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:59 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+#include <sys/buf.h>
+#include <sys/vnode.h>
+#include <sys/user.h>
+#include <sys/core.h>
+#include <sys/exec.h>
+
+#include <machine/frame.h>
+#include <machine/cpu.h>
+#include <machine/pte.h>
+#include <machine/reg.h>
+
+#include <uvm/uvm_extern.h>
+
+/*
+ * Dump the machine specific header information at the start of a core dump.
+ */
+struct md_core {
+	struct reg intreg;
+	struct fpreg freg;
+};
+
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	struct md_core md_core;
+	struct coreseg cseg;
+	int error;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+		chdr->c_cpusize = sizeof(md_core);
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	/* Save integer registers. */
+	error = process_read_regs(l, &md_core.intreg);
+	if (error)
+		return error;
+
+	if (fputype) {
+		/* Save floating point registers. */
+		error = process_read_fpregs(l, &md_core.freg);
+		if (error)
+			return error;
+	} else {
+		/* Make sure these are clear. */
+		memset((void *)&md_core.freg, 0, sizeof(md_core.freg));
+	}
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+	    chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
+	    sizeof(md_core));
+}
--- a/sys/arch/m68k/m68k/sig_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/m68k/m68k/sig_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sig_machdep.c,v 1.39 2008/10/18 13:38:42 martin Exp $	*/
+/*	$NetBSD: sig_machdep.c,v 1.40 2008/11/19 18:35:59 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -75,9 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.39 2008/10/18 13:38:42 martin Exp $");
-
-#include "opt_compat_netbsd.h"
+__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.40 2008/11/19 18:35:59 ad Exp $");
 
 #define __M68K_SIGNAL_PRIVATE
 
@@ -171,7 +169,7 @@
 	frame->f_pc = (int)catcher;
 }
 
-static void
+void
 sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
 {
 	struct lwp *l = curlwp;
@@ -184,18 +182,6 @@
 
 	fp--;
 
-	/* Build stack frame for signal trampoline. */
-	switch (ps->sa_sigdesc[sig].sd_vers) {
-	case 0:		/* handled by sendsig_sigcontext */
-	case 1:		/* handled by sendsig_sigcontext */
-	default:	/* unknown version */
-		printf("nsendsig: bad version %d\n",
-		    ps->sa_sigdesc[sig].sd_vers);
-		sigexit(l, SIGILL);
-	case 2:
-		break;
-	}
-
 	kf.sf_ra = (int)ps->sa_sigdesc[sig].sd_tramp;
 	kf.sf_signum = sig;
 	kf.sf_sip = &fp->sf_si;
@@ -230,18 +216,6 @@
 }
 
 void
-sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
-{
-
-#ifdef COMPAT_16
-	if (curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers < 2)
-		sendsig_sigcontext(ksi, mask);
-	else
-#endif
-		sendsig_siginfo(ksi, mask);
-}
-
-void
 cpu_upcall(struct lwp *l, int type, int nevents, int ninterrupted, void *sas,
     void *ap, void *sp, sa_upcall_t upcall)
 {
--- a/sys/arch/m68k/m68k/svr4_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/m68k/m68k/svr4_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: svr4_machdep.c,v 1.29 2008/04/28 20:23:27 martin Exp $	*/
+/*	$NetBSD: svr4_machdep.c,v 1.30 2008/11/19 18:35:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.29 2008/04/28 20:23:27 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.30 2008/11/19 18:35:59 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -306,3 +306,15 @@
 
 	return error;
 }
+
+void
+svr4_md_init(void)
+{
+
+}
+
+void
+svr4_md_fini(void)
+{
+
+}
--- a/sys/arch/m68k/m68k/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/m68k/m68k/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.26 2007/10/17 19:55:12 garbled Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.27 2008/11/19 18:35:59 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -77,9 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.26 2007/10/17 19:55:12 garbled Exp $");
-
-#include "opt_coredump.h"
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.27 2008/11/19 18:35:59 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -194,60 +192,6 @@
 	/* Nothing to do */
 }
 
-#ifdef COREDUMP
-/*
- * Dump the machine specific header information at the start of a core dump.
- */
-struct md_core {
-	struct reg intreg;
-	struct fpreg freg;
-};
-
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	struct md_core md_core;
-	struct coreseg cseg;
-	int error;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-		chdr->c_cpusize = sizeof(md_core);
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	/* Save integer registers. */
-	error = process_read_regs(l, &md_core.intreg);
-	if (error)
-		return error;
-
-	if (fputype) {
-		/* Save floating point registers. */
-		error = process_read_fpregs(l, &md_core.freg);
-		if (error)
-			return error;
-	} else {
-		/* Make sure these are clear. */
-		memset((void *)&md_core.freg, 0, sizeof(md_core.freg));
-	}
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-	    chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
-	    sizeof(md_core));
-}
-#endif
-
 /*
  * Map a user I/O request into kernel virtual address space.
  * Note: the pages are already locked by uvm_vslock(), so we
--- a/sys/arch/mips/conf/files.mips	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/mips/conf/files.mips	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.mips,v 1.58 2008/01/25 21:12:12 joerg Exp $
+#	$NetBSD: files.mips,v 1.59 2008/11/19 18:35:59 ad Exp $
 #
 
 defflag	opt_cputype.h		NOFPU
@@ -25,6 +25,7 @@
 file	arch/mips/mips/copy.S
 file	arch/mips/mips/lock_stubs.S
 
+file	arch/mips/mips/core_machdep.c		coredump
 file	arch/mips/mips/db_disasm.c		ddb
 file	arch/mips/mips/db_interface.c		ddb | kgdb
 file	arch/mips/mips/db_trace.c		ddb
--- a/sys/arch/mips/include/signal.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/mips/include/signal.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: signal.h,v 1.27 2005/12/11 12:18:09 christos Exp $	*/
+/*	$NetBSD: signal.h,v 1.28 2008/11/19 18:35:59 ad Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,17 +41,10 @@
 
 #include <machine/cdefs.h>	/* for API selection */
 
-#ifdef _KERNEL
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
 #include "opt_compat_ultrix.h"
 #endif
-#ifdef COMPAT_16 
-#define SIGTRAMP_VALID(vers) ((unsigned)(vers) <= 2)
-#else
-#define SIGTRAMP_VALID(vers) ((vers) == 2)
-#endif 
-#endif
 
 #if !defined(__ASSEMBLER__)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/mips/mips/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,139 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:59 ad Exp $	*/
+
+/*
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  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 Ralph Campbell.
+ *
+ * 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. 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: Utah Hdr: vm_machdep.c 1.21 91/04/06
+ *
+ *	@(#)vm_machdep.c	8.3 (Berkeley) 1/4/94
+ */
+/*
+ * Copyright (c) 1988 University of Utah.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department and Ralph Campbell.
+ *
+ * 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: Utah Hdr: vm_machdep.c 1.21 91/04/06
+ *
+ *	@(#)vm_machdep.c	8.3 (Berkeley) 1/4/94
+ */
+
+#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:35:59 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+#include <sys/buf.h>
+#include <sys/vnode.h>
+#include <sys/user.h>
+#include <sys/core.h>
+#include <sys/exec.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <mips/cache.h>
+#include <mips/regnum.h>
+#include <mips/locore.h>
+#include <mips/pte.h>
+#include <mips/psl.h>
+#include <machine/cpu.h>
+
+/*
+ * Dump the machine specific segment at the start of a core dump.
+ */
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	int error;
+	struct coreseg cseg;
+	struct cpustate {
+		struct frame frame;
+		struct fpreg fpregs;
+	} cpustate;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+		chdr->c_hdrsize = ALIGN(sizeof(struct core));
+		chdr->c_seghdrsize = ALIGN(sizeof(struct coreseg));
+		chdr->c_cpusize = sizeof(struct cpustate);
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	if ((l->l_md.md_flags & MDP_FPUSED) && l == fpcurlwp)
+		savefpregs(l);
+	cpustate.frame = *(struct frame *)l->l_md.md_regs;
+	cpustate.fpregs = l->l_addr->u_pcb.pcb_fpregs;
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+	    chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE, &cpustate,
+	    chdr->c_cpusize);
+}
--- a/sys/arch/mips/mips/sig_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/mips/mips/sig_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sig_machdep.c,v 1.16 2008/04/28 20:23:28 martin Exp $	*/
+/*	$NetBSD: sig_machdep.c,v 1.17 2008/11/19 18:35:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,10 +31,9 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 	
-__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.16 2008/04/28 20:23:28 martin Exp $"); 
+__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.17 2008/11/19 18:35:59 ad Exp $"); 
 
 #include "opt_cputype.h"
-#include "opt_compat_netbsd.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -74,7 +73,7 @@
 /*
  * Send a signal to process.
  */
-static void
+void
 sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
 {
 	struct lwp *l = curlwp;
@@ -91,18 +90,6 @@
 	tf = (struct frame *)l->l_md.md_regs;
 	fp--;
 
-        /* Build stack frame for signal trampoline. */
-        switch (ps->sa_sigdesc[sig].sd_vers) {
-        case 0:         /* handled by sendsig_sigcontext */
-        case 1:         /* handled by sendsig_sigcontext */
-        default:        /* unknown version */
-                printf("sendsig_siginfo: bad version %d\n",
-                    ps->sa_sigdesc[sig].sd_vers);
-                sigexit(l, SIGILL);
-        case 2:
-                break;
-        }
-
         uc.uc_flags = _UC_SIGMASK
             | ((l->l_sigstk.ss_flags & SS_ONSTACK)
             ? _UC_SETSTACK : _UC_CLRSTACK);
@@ -145,14 +132,3 @@
 	if (onstack)
 		l->l_sigstk.ss_flags |= SS_ONSTACK;
 }
-
-void    
-sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
-{               
-#ifdef COMPAT_16    
-	if (curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers < 2)
-		sendsig_sigcontext(ksi, mask);
-	else    
-#endif  
-		sendsig_siginfo(ksi, mask);
-}       
--- a/sys/arch/mips/mips/svr4_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/mips/mips/svr4_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: svr4_machdep.c,v 1.11 2008/04/28 20:23:28 martin Exp $ */
+/*	$NetBSD: svr4_machdep.c,v 1.12 2008/11/19 18:36:00 ad Exp $ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.11 2008/04/28 20:23:28 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.12 2008/11/19 18:36:00 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -88,3 +88,15 @@
 	printf("Warning: svr4_getmcontext() called\n");
 	return NULL;
 }
+
+void
+svr4_md_init(void)
+{
+
+}
+
+void
+svr4_md_fini(void)
+{
+
+}
--- a/sys/arch/mips/mips/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/mips/mips/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.121 2008/10/15 06:51:18 wrstuden Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.122 2008/11/19 18:36:00 ad Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -76,11 +76,10 @@
  *	@(#)vm_machdep.c	8.3 (Berkeley) 1/4/94
  */
 
-#include "opt_ddb.h"
-#include "opt_coredump.h"
+#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.122 2008/11/19 18:36:00 ad Exp $");
 
-#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.121 2008/10/15 06:51:18 wrstuden Exp $");
+#include "opt_ddb.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -244,48 +243,6 @@
 	(void)l;
 }
 
-#ifdef COREDUMP
-/*
- * Dump the machine specific segment at the start of a core dump.
- */
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	int error;
-	struct coreseg cseg;
-	struct cpustate {
-		struct frame frame;
-		struct fpreg fpregs;
-	} cpustate;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-		chdr->c_hdrsize = ALIGN(sizeof(struct core));
-		chdr->c_seghdrsize = ALIGN(sizeof(struct coreseg));
-		chdr->c_cpusize = sizeof(struct cpustate);
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	if ((l->l_md.md_flags & MDP_FPUSED) && l == fpcurlwp)
-		savefpregs(l);
-	cpustate.frame = *(struct frame *)l->l_md.md_regs;
-	cpustate.fpregs = l->l_addr->u_pcb.pcb_fpregs;
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-	    chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE, &cpustate,
-	    chdr->c_cpusize);
-}
-#endif
-
 /*
  * Map a user I/O request into kernel virtual address space.
  */
--- a/sys/arch/powerpc/conf/files.powerpc	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/powerpc/conf/files.powerpc	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.powerpc,v 1.69 2008/02/05 22:31:49 garbled Exp $
+#	$NetBSD: files.powerpc,v 1.70 2008/11/19 18:36:00 ad Exp $
 
 defflag	opt_altivec.h	ALTIVEC K_ALTIVEC
 defflag	opt_openpic.h	OPENPIC OPENPIC_SERIAL_MODE
@@ -8,6 +8,7 @@
 defparam opt_pmap.h	PTEGCOUNT PMAP_MEMLIMIT
 
 file	arch/powerpc/powerpc/copystr.c
+file	arch/powerpc/powerpc/core_machdep.c		coredump
 file	arch/powerpc/powerpc/fubyte.c
 file	arch/powerpc/powerpc/fuswintr.c
 file	arch/powerpc/powerpc/ipkdb_glue.c		ipkdb
--- a/sys/arch/powerpc/include/signal.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/powerpc/include/signal.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: signal.h,v 1.18 2005/12/11 12:18:43 christos Exp $	*/
+/*	$NetBSD: signal.h,v 1.19 2008/11/19 18:36:00 ad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -61,13 +61,6 @@
 
 #ifdef _KERNEL
 void	sendsig_sigcontext(int, const sigset_t *, u_long);
-
-#ifdef COMPAT_16
-#define	SIGTRAMP_VALID(vers)	((unsigned)(vers) <= 2)
-#else
-#define	SIGTRAMP_VALID(vers)	((vers) == 2)
-#endif
-
 #endif	/* _KERNEL */
 
 #endif	/* _NETBSD_SOURCE */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/powerpc/powerpc/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,106 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:36:00 ad Exp $	*/
+
+/*
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * All rights reserved.
+ *
+ * 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 TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:36:00 ad Exp $");
+
+#include "opt_altivec.h"
+#include "opt_ppcarch.h"
+
+#include <sys/param.h>
+#include <sys/core.h>
+#include <sys/exec.h>
+#include <sys/proc.h>
+#include <sys/systm.h>
+#include <sys/user.h>
+#include <sys/vnode.h>
+
+#include <uvm/uvm_extern.h>
+
+#ifdef ALTIVEC
+#include <powerpc/altivec.h>
+#endif
+#include <machine/fpu.h>
+#include <machine/pcb.h>
+
+/*
+ * Write the machine-dependent part of a core dump.
+ */
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	struct coreseg cseg;
+	struct md_coredump md_core;
+	struct pcb *pcb = &l->l_addr->u_pcb;
+	int error;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_POWERPC, 0);
+		chdr->c_hdrsize = ALIGN(sizeof *chdr);
+		chdr->c_seghdrsize = ALIGN(sizeof cseg);
+		chdr->c_cpusize = sizeof md_core;
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	md_core.frame = *trapframe(l);
+	if (pcb->pcb_flags & PCB_FPU) {
+#ifdef PPC_HAVE_FPU
+		if (pcb->pcb_fpcpu)
+			save_fpu_lwp(l, FPU_SAVE);
+#endif
+		md_core.fpstate = pcb->pcb_fpu;
+	} else
+		memset(&md_core.fpstate, 0, sizeof(md_core.fpstate));
+
+#ifdef ALTIVEC
+	if (pcb->pcb_flags & PCB_ALTIVEC) {
+		if (pcb->pcb_veccpu)
+			save_vec_lwp(l, ALTIVEC_SAVE);
+		md_core.vstate = pcb->pcb_vr;
+	} else
+#endif
+		memset(&md_core.vstate, 0, sizeof(md_core.vstate));
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+		    chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
+	    sizeof(md_core));
+}
--- a/sys/arch/powerpc/powerpc/sig_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/powerpc/powerpc/sig_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sig_machdep.c,v 1.32 2008/04/24 18:39:21 ad Exp $	*/
+/*	$NetBSD: sig_machdep.c,v 1.33 2008/11/19 18:36:00 ad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,9 +32,8 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.32 2008/04/24 18:39:21 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.33 2008/11/19 18:36:00 ad Exp $");
 
-#include "opt_compat_netbsd.h"
 #include "opt_ppcarch.h"
 #include "opt_altivec.h"
 
@@ -53,7 +52,7 @@
  * Send a signal to process.
  */
 void
-sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
+sendsig_sigcontext(const ksiginfo_t *ksi, const sigset_t *mask)
 {
 	struct lwp * const l = curlwp;
 	struct proc * const p = l->l_proc;
@@ -65,15 +64,6 @@
 	vaddr_t sp, sip, ucp;
 	int onstack, error;
 
-	if (sd->sd_vers < 2) {
-#ifdef COMPAT_16
-		sendsig_sigcontext(ksi->ksi_signo, mask, KSI_TRAPCODE(ksi));
-		return;
-#else
-		goto nosupport;
-#endif
-	}
-
 	/* Do we need to jump onto the signal stack? */
 	onstack = (ss->ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
 	    (sd->sd_sigact.sa_flags & SA_ONSTACK) != 0;
--- a/sys/arch/powerpc/powerpc/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/powerpc/powerpc/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.74 2008/10/25 09:10:07 mrg Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.75 2008/11/19 18:36:00 ad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,12 +32,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.74 2008/10/25 09:10:07 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.75 2008/11/19 18:36:00 ad Exp $");
 
 #include "opt_altivec.h"
 #include "opt_multiprocessor.h"
 #include "opt_ppcarch.h"
-#include "opt_coredump.h"
 
 #include <sys/param.h>
 #include <sys/core.h>
@@ -185,60 +184,6 @@
 
 }
 
-#ifdef COREDUMP
-/*
- * Write the machine-dependent part of a core dump.
- */
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	struct coreseg cseg;
-	struct md_coredump md_core;
-	struct pcb *pcb = &l->l_addr->u_pcb;
-	int error;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_POWERPC, 0);
-		chdr->c_hdrsize = ALIGN(sizeof *chdr);
-		chdr->c_seghdrsize = ALIGN(sizeof cseg);
-		chdr->c_cpusize = sizeof md_core;
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	md_core.frame = *trapframe(l);
-	if (pcb->pcb_flags & PCB_FPU) {
-#ifdef PPC_HAVE_FPU
-		if (pcb->pcb_fpcpu)
-			save_fpu_lwp(l, FPU_SAVE);
-#endif
-		md_core.fpstate = pcb->pcb_fpu;
-	} else
-		memset(&md_core.fpstate, 0, sizeof(md_core.fpstate));
-
-#ifdef ALTIVEC
-	if (pcb->pcb_flags & PCB_ALTIVEC) {
-		if (pcb->pcb_veccpu)
-			save_vec_lwp(l, ALTIVEC_SAVE);
-		md_core.vstate = pcb->pcb_vr;
-	} else
-#endif
-		memset(&md_core.vstate, 0, sizeof(md_core.vstate));
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-		    chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
-	    sizeof(md_core));
-}
-#endif
-
 #ifdef PPC_IBM4XX
 /*
  * Map a range of user addresses into the kernel.
--- a/sys/arch/sh3/conf/files.sh3	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sh3/conf/files.sh3	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sh3,v 1.40 2008/03/15 22:48:58 uwe Exp $
+#	$NetBSD: files.sh3,v 1.41 2008/11/19 18:36:00 ad Exp $
 #
 
 defflag	opt_cputype.h		SH3 SH4
@@ -13,6 +13,7 @@
 defflag opt_cache.h		SH4_CACHE_WB_U0_P0_P3
 defflag opt_cache.h		SH4_CACHE_WB_P1
 
+file	arch/sh3/sh3/core_machdep.c	coredump
 file	arch/sh3/sh3/db_disasm.c	ddb
 file	arch/sh3/sh3/db_interface.c	ddb | kgdb
 file	arch/sh3/sh3/db_memrw.c		ddb | kgdb
--- a/sys/arch/sh3/include/signal.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sh3/include/signal.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: signal.h,v 1.12 2005/12/11 12:18:58 christos Exp $	*/
+/*	$NetBSD: signal.h,v 1.13 2008/11/19 18:36:00 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
@@ -38,14 +38,6 @@
 
 typedef int sig_atomic_t;
 
-#ifdef _KERNEL
-#ifdef COMPAT_16
-#define SIGTRAMP_VALID(vers)	((unsigned)(vers) <= 2)
-#else
-#define SIGTRAMP_VALID(vers)	((vers) == 2)
-#endif
-#endif
-
 #if defined(_NETBSD_SOURCE)
 
 /*
--- a/sys/arch/sh3/sh3/coff_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sh3/sh3/coff_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: coff_exec.c,v 1.30 2008/02/25 08:31:00 dholland Exp $	*/
+/*	$NetBSD: coff_exec.c,v 1.31 2008/11/19 18:36:00 ad Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Scott Bartram
@@ -35,7 +35,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: coff_exec.c,v 1.30 2008/02/25 08:31:00 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: coff_exec.c,v 1.31 2008/11/19 18:36:00 ad Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_coredump.h"
+#endif
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -45,13 +49,53 @@
 #include <sys/vnode.h>
 #include <sys/resourcevar.h>
 #include <sys/namei.h>
+#include <sys/exec_coff.h>
+#include <sys/module.h>
+
 #include <uvm/uvm_extern.h>
 
-#include <sys/exec_coff.h>
+#ifdef COREDUMP
+#define	DEP	"coredump"
+#else
+#define	DEP	NULL
+#endif
+
+MODULE(MODULE_CLASS_MISC, exec_coff, DEP);
 
 static int coff_find_section(struct lwp *, struct vnode *,
     struct coff_filehdr *, struct coff_scnhdr *, int);
 
+static struct execsw exec_coff_execsw[] = {
+	{ COFF_HDR_SIZE,
+	  exec_coff_makecmds,
+	  { NULL },
+	  &emul_netbsd,
+	  EXECSW_PRIO_ANY,
+	  0,
+	  copyargs,
+	  NULL,
+	  coredump_netbsd,
+	  exec_setup_stack },
+};
+
+static int
+exec_coff_modcmd(modcmd_t cmd, void *arg)
+{
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		return exec_add(exec_coff_execsw,
+		    __arraycount(exec_coff_execsw));
+
+	case MODULE_CMD_FINI:
+		return exec_remove(exec_coff_execsw,
+		    __arraycount(exec_coff_execsw));
+
+	default:
+		return ENOTTY;
+        }
+}
+
 /*
  * exec_coff_makecmds(): Check if it's an coff-format executable.
  *
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sh3/sh3/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,147 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:36:00 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
+ * Copyright (c) 1982, 1986 The Regents of the University of California.
+ * 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. 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.
+ *
+ *	@(#)vm_machdep.c	7.3 (Berkeley) 5/13/91
+ */
+
+/*-
+ * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
+ * Copyright (c) 1989, 1990 William Jolitz
+ * 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.
+ *
+ *	@(#)vm_machdep.c	7.3 (Berkeley) 5/13/91
+ */
+
+/*
+ *	Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:36:00 ad 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>
+#include <sys/core.h>
+#include <sys/exec.h>
+#include <sys/ptrace.h>
+#include <sys/syscall.h>
+#include <sys/ktrace.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <sh3/locore.h>
+#include <sh3/cpu.h>
+#include <sh3/reg.h>
+#include <sh3/mmu.h>
+#include <sh3/cache.h>
+#include <sh3/userret.h>
+
+/*
+ * Dump the machine specific segment at the start of a core dump.
+ */
+struct md_core {
+	struct reg intreg;
+};
+
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	struct md_core md_core;
+	struct coreseg cseg;
+	int error;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+		chdr->c_cpusize = sizeof(md_core);
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	/* Save integer registers. */
+	error = process_read_regs(l, &md_core.intreg);
+	if (error)
+		return error;
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+	    chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
+	    sizeof(md_core));
+}
--- a/sys/arch/sh3/sh3/sh3_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sh3/sh3/sh3_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sh3_machdep.c,v 1.76 2008/10/15 06:51:18 wrstuden Exp $	*/
+/*	$NetBSD: sh3_machdep.c,v 1.77 2008/11/19 18:36:00 ad Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2002 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sh3_machdep.c,v 1.76 2008/10/15 06:51:18 wrstuden Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sh3_machdep.c,v 1.77 2008/11/19 18:36:00 ad Exp $");
 
 #include "opt_kgdb.h"
 #include "opt_memsize.h"
@@ -371,7 +371,7 @@
  * frame pointer, it returns to the user
  * specified pc, psl.
  */
-static void
+void
 sendsig_sigcontext(const ksiginfo_t *ksi, const sigset_t *mask)
 {
 	struct lwp *l = curlwp;
@@ -461,7 +461,7 @@
 }
 #endif /* COMPAT_16 */
 
-static void
+void
 sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
 {
 	struct lwp *l = curlwp;
@@ -473,18 +473,6 @@
 	struct sigframe_siginfo *fp, frame;
 	int onstack;
 
-	switch (ps->sa_sigdesc[sig].sd_vers) {
-	case 0:		/* FALLTHROUGH */ /* handled by sendsig_sigcontext */
-	case 1:		/* FALLTHROUGH */ /* handled by sendsig_sigcontext */
-	default:	/* unknown version */
-		printf("sendsig_siginfo: bad version %d\n",
-		       ps->sa_sigdesc[sig].sd_vers);
-		sigexit(l, SIGILL);
-		/* NOTREACHED */
-	case 2:
-		break;
-	}
-
 	fp = getframe(l, sig, &onstack);
 	--fp;
 
@@ -522,20 +510,6 @@
 		l->l_sigstk.ss_flags |= SS_ONSTACK;
 }
 
-/*
- * Send an interrupt to process.
- */
-void
-sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
-{
-#ifdef COMPAT_16
-	if (curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers < 2)
-		sendsig_sigcontext(ksi, mask);
-	else
-#endif
-		sendsig_siginfo(ksi, mask);
-}
-
 #ifdef COMPAT_16
 /*
  * System call to cleanup state after a signal
--- a/sys/arch/sh3/sh3/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sh3/sh3/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.62 2008/02/15 03:02:43 uwe Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.63 2008/11/19 18:36:00 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
@@ -81,10 +81,9 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.62 2008/02/15 03:02:43 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.63 2008/11/19 18:36:00 ad Exp $");
 
 #include "opt_kstack_debug.h"
-#include "opt_coredump.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -314,50 +313,6 @@
 	/* Nothing to do */
 }
 
-
-#ifdef COREDUMP
-/*
- * Dump the machine specific segment at the start of a core dump.
- */
-struct md_core {
-	struct reg intreg;
-};
-
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	struct md_core md_core;
-	struct coreseg cseg;
-	int error;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-		chdr->c_cpusize = sizeof(md_core);
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	/* Save integer registers. */
-	error = process_read_regs(l, &md_core.intreg);
-	if (error)
-		return error;
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-	    chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
-	    sizeof(md_core));
-}
-#endif /* COREDUMP */
-
 /*
  * Map an IO request into kernel virtual address space.  Requests fall into
  * one of five catagories:
--- a/sys/arch/sparc/conf/files.sparc	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sparc/conf/files.sparc	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sparc,v 1.146 2008/02/20 21:43:35 drochner Exp $
+#	$NetBSD: files.sparc,v 1.147 2008/11/19 18:36:00 ad Exp $
 
 # @(#)files.sparc	8.1 (Berkeley) 7/19/93
 # sparc-specific configuration info
@@ -285,6 +285,7 @@
 
 file	arch/sparc/sparc/autoconf.c
 file	arch/sparc/sparc/cache.c
+file	arch/sparc/sparc/core_machdep.c		coredump
 file	arch/sparc/sparc/emul.c
 file	arch/sparc/sparc/intr.c
 file	arch/sparc/sparc/kgdb_machdep.c	kgdb
@@ -329,6 +330,7 @@
 
 # Binary compatibility with previous NetBSD releases (COMPAT_XX)
 # Note: SunOS compatibility also uses some of `compat_13_machdep.c'
+file	arch/sparc/sparc/compat_16_machdep.c	compat_16
 file	arch/sparc/sparc/compat_13_machdep.c	compat_13 | compat_sunos
 
 # Miscellaneous
--- a/sys/arch/sparc/include/signal.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sparc/include/signal.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: signal.h,v 1.21 2005/12/11 12:19:06 christos Exp $ */
+/*	$NetBSD: signal.h,v 1.22 2008/11/19 18:36:00 ad Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -95,14 +95,6 @@
 	sigset_t	sc_mask;	/* signal mask to restore (new style) */
 };
 
-#ifdef _KERNEL
-#ifdef COMPAT_16
-#define	SIGTRAMP_VALID(vers)	((unsigned)(vers) <= 2)
-#else
-#define	SIGTRAMP_VALID(vers)	((vers) == 2)
-#endif
-#endif
-
 #else /* _LOCORE */
 /* XXXXX These values don't work for _LP64 */
 #define	SC_SP_OFFSET	8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sparc/sparc/compat_16_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,298 @@
+/*	$NetBSD: compat_16_machdep.c,v 1.1 2008/11/19 18:36:01 ad Exp $ */
+
+/*-
+ * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * 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, Lawrence Berkeley Laboratory.
+ *
+ * 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. 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.
+ *
+ *	@(#)machdep.c	8.6 (Berkeley) 1/14/94
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.1 2008/11/19 18:36:01 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/signal.h>
+#include <sys/signalvar.h>
+#include <sys/proc.h>
+#include <sys/user.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/syscallargs.h>
+
+#include <machine/frame.h>
+
+struct sigframe_sigcontext {
+	int	sf_signo;		/* signal number */
+	int	sf_code;		/* code */
+	struct	sigcontext *sf_scp;	/* SunOS user addr of sigcontext */
+	int	sf_addr;		/* SunOS compat, always 0 for now */
+	struct	sigcontext sf_sc;	/* actual sigcontext */
+};
+
+void
+sendsig_sigcontext(const ksiginfo_t *ksi, const sigset_t *mask)
+{
+	struct lwp *l = curlwp;
+	struct proc *p = l->l_proc;
+	struct sigacts *ps = p->p_sigacts;
+	struct sigframe_sigcontext *fp;
+	struct trapframe *tf;
+	int addr, onstack, oldsp, newsp, error;
+	struct sigframe_sigcontext sf;
+	int sig = ksi->ksi_signo;
+	u_long code = KSI_TRAPCODE(ksi);
+	sig_t catcher = SIGACTION(p, sig).sa_handler;
+
+	tf = l->l_md.md_tf;
+	oldsp = tf->tf_out[6];
+
+	/*
+	 * Compute new user stack addresses, subtract off
+	 * one signal frame, and align.
+	 */
+	onstack =
+	    (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
+	    (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
+
+	if (onstack)
+		fp = (struct sigframe_sigcontext *)
+			((char *)l->l_sigstk.ss_sp +
+			 l->l_sigstk.ss_size);
+	else
+		fp = (struct sigframe_sigcontext *)oldsp;
+
+	fp = (struct sigframe_sigcontext *)((int)(fp - 1) & ~7);
+
+#ifdef DEBUG
+	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
+		printf("sendsig_sigcontext: %s[%d] sig %d newusp %p scp %p\n",
+		    p->p_comm, p->p_pid, sig, fp, &fp->sf_sc);
+#endif
+	/*
+	 * Now set up the signal frame.  We build it in kernel space
+	 * and then copy it out.  We probably ought to just build it
+	 * directly in user space....
+	 */
+	sf.sf_signo = sig;
+	sf.sf_code = code;
+	sf.sf_scp = 0;
+	sf.sf_addr = 0;			/* XXX */
+
+	/*
+	 * Build the signal context to be used by sigreturn.
+	 */
+	sf.sf_sc.sc_onstack = l->l_sigstk.ss_flags & SS_ONSTACK;
+	sf.sf_sc.sc_mask = *mask;
+#ifdef COMPAT_13
+	/*
+	 * XXX We always have to save an old style signal mask because
+	 * XXX we might be delivering a signal to a process which will
+	 * XXX escape from the signal in a non-standard way and invoke
+	 * XXX sigreturn() directly.
+	 */
+	native_sigset_to_sigset13(mask, &sf.sf_sc.__sc_mask13);
+#endif
+	sf.sf_sc.sc_sp = oldsp;
+	sf.sf_sc.sc_pc = tf->tf_pc;
+	sf.sf_sc.sc_npc = tf->tf_npc;
+	sf.sf_sc.sc_psr = tf->tf_psr;
+	sf.sf_sc.sc_g1 = tf->tf_global[1];
+	sf.sf_sc.sc_o0 = tf->tf_out[0];
+
+	/*
+	 * Put the stack in a consistent state before we whack away
+	 * at it.  Note that write_user_windows may just dump the
+	 * registers into the pcb; we need them in the process's memory.
+	 * We also need to make sure that when we start the signal handler,
+	 * its %i6 (%fp), which is loaded from the newly allocated stack area,
+	 * joins seamlessly with the frame it was in when the signal occurred,
+	 * so that the debugger and _longjmp code can back up through it.
+	 */
+	sendsig_reset(l, sig);
+	mutex_exit(p->p_lock);
+	newsp = (int)fp - sizeof(struct rwindow);
+	write_user_windows();
+	error = (rwindow_save(l) || copyout((void *)&sf, (void *)fp, sizeof sf) ||
+	    suword(&((struct rwindow *)newsp)->rw_in[6], oldsp));
+	mutex_enter(p->p_lock);
+
+	if (error) {
+		/*
+		 * Process has trashed its stack; give it an illegal
+		 * instruction to halt it in its tracks.
+		 */
+#ifdef DEBUG
+		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
+			printf("sendsig_sigcontext: window save or copyout error\n");
+#endif
+		sigexit(l, SIGILL);
+		/* NOTREACHED */
+	}
+#ifdef DEBUG
+	if (sigdebug & SDB_FOLLOW)
+		printf("sendsig_siginfo: %s[%d] sig %d scp %p\n",
+		       p->p_comm, p->p_pid, sig, &fp->sf_sc);
+#endif
+	/*
+	 * Arrange to continue execution at the code copied out in exec().
+	 * It needs the function to call in %g1, and a new stack pointer.
+	 */
+	switch (ps->sa_sigdesc[sig].sd_vers) {
+	case 0:		/* legacy on-stack sigtramp */
+		addr = (int)p->p_sigctx.ps_sigcode;
+		break;
+
+	case 1:
+		addr = (int)ps->sa_sigdesc[sig].sd_tramp;
+		break;
+
+	default:
+		/* Don't know what trampoline version; kill it. */
+		addr = 0;
+		sigexit(l, SIGILL);
+	}
+
+	tf->tf_global[1] = (int)catcher;
+	tf->tf_pc = addr;
+	tf->tf_npc = addr + 4;
+	tf->tf_out[6] = newsp;
+
+	/* Remember that we're now on the signal stack. */
+	if (onstack)
+		l->l_sigstk.ss_flags |= SS_ONSTACK;
+
+#ifdef DEBUG
+	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
+		printf("sendsig: about to return to catcher\n");
+#endif
+}
+
+/*
+ * System call to cleanup state after a signal
+ * has been taken.  Reset signal mask and
+ * stack state from context left by sendsig (above),
+ * and return to the given trap frame (if there is one).
+ * Check carefully to make sure that the user has not
+ * modified the state to gain improper privileges or to cause
+ * a machine fault.
+ */
+/* ARGSUSED */
+int
+compat_16_sys___sigreturn14(struct lwp *l, const struct compat_16_sys___sigreturn14_args *uap, register_t *retval)
+{
+	/* {
+		syscallarg(struct sigcontext *) sigcntxp;
+	} */
+	struct sigcontext sc, *scp;
+	struct trapframe *tf;
+	struct proc *p;
+	int error;
+
+	p = l->l_proc;
+
+	/* First ensure consistent stack state (see sendsig). */
+	write_user_windows();
+	if (rwindow_save(l)) {
+		mutex_enter(p->p_lock);
+		sigexit(l, SIGILL);
+	}
+#ifdef DEBUG
+	if (sigdebug & SDB_FOLLOW)
+		printf("sigreturn: %s[%d], sigcntxp %p\n",
+		    p->p_comm, p->p_pid, SCARG(uap, sigcntxp));
+#endif
+	if ((error = copyin(SCARG(uap, sigcntxp), &sc, sizeof sc)) != 0)
+		return (error);
+	scp = &sc;
+
+	tf = l->l_md.md_tf;
+	/*
+	 * Only the icc bits in the psr are used, so it need not be
+	 * verified.  pc and npc must be multiples of 4.  This is all
+	 * that is required; if it holds, just do it.
+	 */
+	if (((scp->sc_pc | scp->sc_npc) & 3) != 0)
+		return (EINVAL);
+
+	/* take only psr ICC field */
+	tf->tf_psr = (tf->tf_psr & ~PSR_ICC) | (scp->sc_psr & PSR_ICC);
+	tf->tf_pc = scp->sc_pc;
+	tf->tf_npc = scp->sc_npc;
+	tf->tf_global[1] = scp->sc_g1;
+	tf->tf_out[0] = scp->sc_o0;
+	tf->tf_out[6] = scp->sc_sp;
+
+	mutex_enter(p->p_lock);
+	if (scp->sc_onstack & SS_ONSTACK)
+		l->l_sigstk.ss_flags |= SS_ONSTACK;
+	else
+		l->l_sigstk.ss_flags &= ~SS_ONSTACK;
+	/* Restore signal mask */
+	(void) sigprocmask1(l, SIG_SETMASK, &scp->sc_mask, 0);
+	mutex_exit(p->p_lock);
+
+	return (EJUSTRETURN);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sparc/sparc/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,111 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:36:01 ad Exp $ */
+
+/*
+ * Copyright (c) 1996
+ *	The President and Fellows of Harvard College. All rights reserved.
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * 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, Lawrence Berkeley Laboratory.
+ *	This product includes software developed by Harvard University.
+ *
+ * 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 Harvard University.
+ *	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.
+ *
+ *	@(#)vm_machdep.c	8.2 (Berkeley) 9/23/93
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:36:01 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/user.h>
+#include <sys/core.h>
+#include <sys/malloc.h>
+#include <sys/buf.h>
+#include <sys/exec.h>
+#include <sys/vnode.h>
+#include <sys/simplelock.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/cpu.h>
+#include <machine/frame.h>
+#include <machine/trap.h>
+
+#include <sparc/sparc/cpuvar.h>
+
+/*
+ * cpu_coredump is called to write a core dump header.
+ */
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	int error;
+	struct md_coredump md_core;
+	struct coreseg cseg;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+		chdr->c_cpusize = sizeof(md_core);
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	md_core.md_tf = *l->l_md.md_tf;
+	if (l->l_md.md_fpstate) {
+		if (l == cpuinfo.fplwp)
+			savefpstate(l->l_md.md_fpstate);
+		md_core.md_fpstate = *l->l_md.md_fpstate;
+	} else
+		bzero((void *)&md_core.md_fpstate, sizeof(struct fpstate));
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+	    chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
+	    sizeof(md_core));
+}
--- a/sys/arch/sparc/sparc/machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sparc/sparc/machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.283 2008/11/11 06:46:44 dyoung Exp $ */
+/*	$NetBSD: machdep.c,v 1.284 2008/11/19 18:36:01 ad Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.283 2008/11/11 06:46:44 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.284 2008/11/19 18:36:01 ad Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_compat_sunos.h"
@@ -475,160 +475,13 @@
 /*
  * Send an interrupt to process.
  */
-#ifdef COMPAT_16
-struct sigframe_sigcontext {
-	int	sf_signo;		/* signal number */
-	int	sf_code;		/* code */
-	struct	sigcontext *sf_scp;	/* SunOS user addr of sigcontext */
-	int	sf_addr;		/* SunOS compat, always 0 for now */
-	struct	sigcontext sf_sc;	/* actual sigcontext */
-};
-
-static void
-sendsig_sigcontext(const ksiginfo_t *ksi, const sigset_t *mask)
-{
-	struct lwp *l = curlwp;
-	struct proc *p = l->l_proc;
-	struct sigacts *ps = p->p_sigacts;
-	struct sigframe_sigcontext *fp;
-	struct trapframe *tf;
-	int addr, onstack, oldsp, newsp, error;
-	struct sigframe_sigcontext sf;
-	int sig = ksi->ksi_signo;
-	u_long code = KSI_TRAPCODE(ksi);
-	sig_t catcher = SIGACTION(p, sig).sa_handler;
-
-	tf = l->l_md.md_tf;
-	oldsp = tf->tf_out[6];
-
-	/*
-	 * Compute new user stack addresses, subtract off
-	 * one signal frame, and align.
-	 */
-	onstack =
-	    (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
-	    (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
-
-	if (onstack)
-		fp = (struct sigframe_sigcontext *)
-			((char *)l->l_sigstk.ss_sp +
-			 l->l_sigstk.ss_size);
-	else
-		fp = (struct sigframe_sigcontext *)oldsp;
-
-	fp = (struct sigframe_sigcontext *)((int)(fp - 1) & ~7);
-
-#ifdef DEBUG
-	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
-		printf("sendsig: %s[%d] sig %d newusp %p scp %p\n",
-		    p->p_comm, p->p_pid, sig, fp, &fp->sf_sc);
-#endif
-	/*
-	 * Now set up the signal frame.  We build it in kernel space
-	 * and then copy it out.  We probably ought to just build it
-	 * directly in user space....
-	 */
-	sf.sf_signo = sig;
-	sf.sf_code = code;
-	sf.sf_scp = 0;
-	sf.sf_addr = 0;			/* XXX */
-
-	/*
-	 * Build the signal context to be used by sigreturn.
-	 */
-	sf.sf_sc.sc_onstack = l->l_sigstk.ss_flags & SS_ONSTACK;
-	sf.sf_sc.sc_mask = *mask;
-#ifdef COMPAT_13
-	/*
-	 * XXX We always have to save an old style signal mask because
-	 * XXX we might be delivering a signal to a process which will
-	 * XXX escape from the signal in a non-standard way and invoke
-	 * XXX sigreturn() directly.
-	 */
-	native_sigset_to_sigset13(mask, &sf.sf_sc.__sc_mask13);
-#endif
-	sf.sf_sc.sc_sp = oldsp;
-	sf.sf_sc.sc_pc = tf->tf_pc;
-	sf.sf_sc.sc_npc = tf->tf_npc;
-	sf.sf_sc.sc_psr = tf->tf_psr;
-	sf.sf_sc.sc_g1 = tf->tf_global[1];
-	sf.sf_sc.sc_o0 = tf->tf_out[0];
-
-	/*
-	 * Put the stack in a consistent state before we whack away
-	 * at it.  Note that write_user_windows may just dump the
-	 * registers into the pcb; we need them in the process's memory.
-	 * We also need to make sure that when we start the signal handler,
-	 * its %i6 (%fp), which is loaded from the newly allocated stack area,
-	 * joins seamlessly with the frame it was in when the signal occurred,
-	 * so that the debugger and _longjmp code can back up through it.
-	 */
-	sendsig_reset(l, sig);
-	mutex_exit(p->p_lock);
-	newsp = (int)fp - sizeof(struct rwindow);
-	write_user_windows();
-	error = (rwindow_save(l) || copyout((void *)&sf, (void *)fp, sizeof sf) ||
-	    suword(&((struct rwindow *)newsp)->rw_in[6], oldsp));
-	mutex_enter(p->p_lock);
-
-	if (error) {
-		/*
-		 * Process has trashed its stack; give it an illegal
-		 * instruction to halt it in its tracks.
-		 */
-#ifdef DEBUG
-		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
-			printf("sendsig: window save or copyout error\n");
-#endif
-		sigexit(l, SIGILL);
-		/* NOTREACHED */
-	}
-#ifdef DEBUG
-	if (sigdebug & SDB_FOLLOW)
-		printf("sendsig: %s[%d] sig %d scp %p\n",
-		       p->p_comm, p->p_pid, sig, &fp->sf_sc);
-#endif
-	/*
-	 * Arrange to continue execution at the code copied out in exec().
-	 * It needs the function to call in %g1, and a new stack pointer.
-	 */
-	switch (ps->sa_sigdesc[sig].sd_vers) {
-	case 0:		/* legacy on-stack sigtramp */
-		addr = (int)p->p_sigctx.ps_sigcode;
-		break;
-
-	case 1:
-		addr = (int)ps->sa_sigdesc[sig].sd_tramp;
-		break;
-
-	default:
-		/* Don't know what trampoline version; kill it. */
-		addr = 0;
-		sigexit(l, SIGILL);
-	}
-
-	tf->tf_global[1] = (int)catcher;
-	tf->tf_pc = addr;
-	tf->tf_npc = addr + 4;
-	tf->tf_out[6] = newsp;
-
-	/* Remember that we're now on the signal stack. */
-	if (onstack)
-		l->l_sigstk.ss_flags |= SS_ONSTACK;
-
-#ifdef DEBUG
-	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
-		printf("sendsig: about to return to catcher\n");
-#endif
-}
-#endif /* COMPAT_16 */
-
 struct sigframe {
 	siginfo_t sf_si;
 	ucontext_t sf_uc;
 };
 
-void sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
+void
+sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
 {
 	struct lwp *l = curlwp;
 	struct proc *p = l->l_proc;
@@ -643,13 +496,6 @@
 
 	sig = ksi->ksi_signo;
 
-#ifdef COMPAT_16
-	if (ps->sa_sigdesc[sig].sd_vers < 2) {
-		sendsig_sigcontext(ksi, mask);
-		return;
-	}
-#endif /* COMPAT_16 */
-
 	tf = l->l_md.md_tf;
 	oldsp = tf->tf_out[6];
 
@@ -749,75 +595,6 @@
 #endif
 }
 
-#ifdef COMPAT_16
-/*
- * System call to cleanup state after a signal
- * has been taken.  Reset signal mask and
- * stack state from context left by sendsig (above),
- * and return to the given trap frame (if there is one).
- * Check carefully to make sure that the user has not
- * modified the state to gain improper privileges or to cause
- * a machine fault.
- */
-/* ARGSUSED */
-int
-compat_16_sys___sigreturn14(struct lwp *l, const struct compat_16_sys___sigreturn14_args *uap, register_t *retval)
-{
-	/* {
-		syscallarg(struct sigcontext *) sigcntxp;
-	} */
-	struct sigcontext sc, *scp;
-	struct trapframe *tf;
-	struct proc *p;
-	int error;
-
-	p = l->l_proc;
-
-	/* First ensure consistent stack state (see sendsig). */
-	write_user_windows();
-	if (rwindow_save(l)) {
-		mutex_enter(p->p_lock);
-		sigexit(l, SIGILL);
-	}
-#ifdef DEBUG
-	if (sigdebug & SDB_FOLLOW)
-		printf("sigreturn: %s[%d], sigcntxp %p\n",
-		    p->p_comm, p->p_pid, SCARG(uap, sigcntxp));
-#endif
-	if ((error = copyin(SCARG(uap, sigcntxp), &sc, sizeof sc)) != 0)
-		return (error);
-	scp = &sc;
-
-	tf = l->l_md.md_tf;
-	/*
-	 * Only the icc bits in the psr are used, so it need not be
-	 * verified.  pc and npc must be multiples of 4.  This is all
-	 * that is required; if it holds, just do it.
-	 */
-	if (((scp->sc_pc | scp->sc_npc) & 3) != 0)
-		return (EINVAL);
-
-	/* take only psr ICC field */
-	tf->tf_psr = (tf->tf_psr & ~PSR_ICC) | (scp->sc_psr & PSR_ICC);
-	tf->tf_pc = scp->sc_pc;
-	tf->tf_npc = scp->sc_npc;
-	tf->tf_global[1] = scp->sc_g1;
-	tf->tf_out[0] = scp->sc_o0;
-	tf->tf_out[6] = scp->sc_sp;
-
-	mutex_enter(p->p_lock);
-	if (scp->sc_onstack & SS_ONSTACK)
-		l->l_sigstk.ss_flags |= SS_ONSTACK;
-	else
-		l->l_sigstk.ss_flags &= ~SS_ONSTACK;
-	/* Restore signal mask */
-	(void) sigprocmask1(l, SIG_SETMASK, &scp->sc_mask, 0);
-	mutex_exit(p->p_lock);
-
-	return (EJUSTRETURN);
-}
-#endif /* COMPAT_16 */
-
 /*
  * cpu_upcall:
  *
--- a/sys/arch/sparc/sparc/svr4_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sparc/sparc/svr4_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: svr4_machdep.c,v 1.66 2008/04/28 20:23:36 martin Exp $	 */
+/*	$NetBSD: svr4_machdep.c,v 1.67 2008/11/19 18:36:01 ad Exp $	 */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.66 2008/04/28 20:23:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.67 2008/11/19 18:36:01 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_kgdb.h"
@@ -622,3 +622,15 @@
 		return EINVAL;
 	}
 }
+
+void
+svr4_md_init(void)
+{
+
+}
+
+void
+svr4_md_fini(void)
+{
+
+}
--- a/sys/arch/sparc/sparc/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sparc/sparc/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.95 2008/10/16 19:28:52 martin Exp $ */
+/*	$NetBSD: vm_machdep.c,v 1.96 2008/11/19 18:36:01 ad Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -49,10 +49,9 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.95 2008/10/16 19:28:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.96 2008/11/19 18:36:01 ad Exp $");
 
 #include "opt_multiprocessor.h"
-#include "opt_coredump.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -339,46 +338,3 @@
 	pcb->pcb_psr &= ~PSR_CWP;	/* Run in window #0 */
 	pcb->pcb_wim = 1;		/* Fence at window #1 */
 }
-
-#ifdef COREDUMP
-/*
- * cpu_coredump is called to write a core dump header.
- * (should this be defined elsewhere?  machdep.c?)
- */
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	int error;
-	struct md_coredump md_core;
-	struct coreseg cseg;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-		chdr->c_cpusize = sizeof(md_core);
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	md_core.md_tf = *l->l_md.md_tf;
-	if (l->l_md.md_fpstate) {
-		if (l == cpuinfo.fplwp)
-			savefpstate(l->l_md.md_fpstate);
-		md_core.md_fpstate = *l->l_md.md_fpstate;
-	} else
-		bzero((void *)&md_core.md_fpstate, sizeof(struct fpstate));
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-	    chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
-	    sizeof(md_core));
-}
-#endif
--- a/sys/arch/sparc64/conf/files.sparc64	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sparc64/conf/files.sparc64	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sparc64,v 1.118 2008/02/20 21:43:35 drochner Exp $
+#	$NetBSD: files.sparc64,v 1.119 2008/11/19 18:36:01 ad Exp $
 
 # @(#)files.sparc64	8.1 (Berkeley) 7/19/93
 # sparc64-specific configuration info
@@ -177,6 +177,7 @@
 file	arch/sparc/sparc/promlib.c
 file	arch/sparc64/sparc64/autoconf.c
 file	arch/sparc64/sparc64/clock.c
+file	arch/sparc64/sparc64/core_machdep.c	coredump
 file	arch/sparc64/sparc64/emul.c
 file	arch/sparc64/sparc64/intr.c
 file	arch/sparc64/sparc64/kgdb_machdep.c	kgdb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sparc64/sparc64/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,154 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:36:01 ad Exp $ */
+
+/*
+ * Copyright (c) 1996-2002 Eduardo Horvath.  All rights reserved.
+ * Copyright (c) 1996
+ *	The President and Fellows of Harvard College. All rights reserved.
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * 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, Lawrence Berkeley Laboratory.
+ *	This product includes software developed by Harvard University.
+ *
+ * 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 Harvard University.
+ *	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.
+ *
+ *	@(#)vm_machdep.c	8.2 (Berkeley) 9/23/93
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:36:01 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/user.h>
+#include <sys/core.h>
+#include <sys/buf.h>
+#include <sys/exec.h>
+#include <sys/vnode.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/cpu.h>
+#include <machine/frame.h>
+#include <machine/trap.h>
+#include <machine/bus.h>
+
+/*
+ * cpu_coredump is called to write a core dump header.
+ */
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	int error;
+	struct md_coredump md_core;
+	struct coreseg cseg;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+		chdr->c_cpusize = sizeof(md_core);
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	/* Copy important fields over. */
+	md_core.md_tf.tf_tstate = l->l_md.md_tf->tf_tstate;
+	md_core.md_tf.tf_pc = l->l_md.md_tf->tf_pc;
+	md_core.md_tf.tf_npc = l->l_md.md_tf->tf_npc;
+	md_core.md_tf.tf_y = l->l_md.md_tf->tf_y;
+	md_core.md_tf.tf_tt = l->l_md.md_tf->tf_tt;
+	md_core.md_tf.tf_pil = l->l_md.md_tf->tf_pil;
+	md_core.md_tf.tf_oldpil = l->l_md.md_tf->tf_oldpil;
+
+	md_core.md_tf.tf_global[0] = l->l_md.md_tf->tf_global[0];
+	md_core.md_tf.tf_global[1] = l->l_md.md_tf->tf_global[1];
+	md_core.md_tf.tf_global[2] = l->l_md.md_tf->tf_global[2];
+	md_core.md_tf.tf_global[3] = l->l_md.md_tf->tf_global[3];
+	md_core.md_tf.tf_global[4] = l->l_md.md_tf->tf_global[4];
+	md_core.md_tf.tf_global[5] = l->l_md.md_tf->tf_global[5];
+	md_core.md_tf.tf_global[6] = l->l_md.md_tf->tf_global[6];
+	md_core.md_tf.tf_global[7] = l->l_md.md_tf->tf_global[7];
+
+	md_core.md_tf.tf_out[0] = l->l_md.md_tf->tf_out[0];
+	md_core.md_tf.tf_out[1] = l->l_md.md_tf->tf_out[1];
+	md_core.md_tf.tf_out[2] = l->l_md.md_tf->tf_out[2];
+	md_core.md_tf.tf_out[3] = l->l_md.md_tf->tf_out[3];
+	md_core.md_tf.tf_out[4] = l->l_md.md_tf->tf_out[4];
+	md_core.md_tf.tf_out[5] = l->l_md.md_tf->tf_out[5];
+	md_core.md_tf.tf_out[6] = l->l_md.md_tf->tf_out[6];
+	md_core.md_tf.tf_out[7] = l->l_md.md_tf->tf_out[7];
+
+#ifdef DEBUG
+	md_core.md_tf.tf_local[0] = l->l_md.md_tf->tf_local[0];
+	md_core.md_tf.tf_local[1] = l->l_md.md_tf->tf_local[1];
+	md_core.md_tf.tf_local[2] = l->l_md.md_tf->tf_local[2];
+	md_core.md_tf.tf_local[3] = l->l_md.md_tf->tf_local[3];
+	md_core.md_tf.tf_local[4] = l->l_md.md_tf->tf_local[4];
+	md_core.md_tf.tf_local[5] = l->l_md.md_tf->tf_local[5];
+	md_core.md_tf.tf_local[6] = l->l_md.md_tf->tf_local[6];
+	md_core.md_tf.tf_local[7] = l->l_md.md_tf->tf_local[7];
+
+	md_core.md_tf.tf_in[0] = l->l_md.md_tf->tf_in[0];
+	md_core.md_tf.tf_in[1] = l->l_md.md_tf->tf_in[1];
+	md_core.md_tf.tf_in[2] = l->l_md.md_tf->tf_in[2];
+	md_core.md_tf.tf_in[3] = l->l_md.md_tf->tf_in[3];
+	md_core.md_tf.tf_in[4] = l->l_md.md_tf->tf_in[4];
+	md_core.md_tf.tf_in[5] = l->l_md.md_tf->tf_in[5];
+	md_core.md_tf.tf_in[6] = l->l_md.md_tf->tf_in[6];
+	md_core.md_tf.tf_in[7] = l->l_md.md_tf->tf_in[7];
+#endif
+	if (l->l_md.md_fpstate) {
+		fpusave_lwp(l, true);
+		md_core.md_fpstate = *l->l_md.md_fpstate;
+	} else
+		memset(&md_core.md_fpstate, 0,
+		      sizeof(md_core.md_fpstate));
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+	    chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
+	    sizeof(md_core));
+}
--- a/sys/arch/sparc64/sparc64/machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sparc64/sparc64/machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.228 2008/11/11 06:46:44 dyoung Exp $ */
+/*	$NetBSD: machdep.c,v 1.229 2008/11/19 18:36:01 ad Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.228 2008/11/11 06:46:44 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.229 2008/11/19 18:36:01 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -452,7 +452,7 @@
 	ucontext_t	sf_uc;		/* saved ucontext */
 };
 
-static void
+void
 sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
 {
 	struct lwp *l = curlwp;
@@ -469,18 +469,6 @@
 	/* Allocate an aligned sigframe */
 	fp = (void *)((u_long)(fp - 1) & ~0x0f);
 
-	/* Build stack frame for signal trampoline. */
-	switch (ps->sa_sigdesc[sig].sd_vers) {
-	case 0:		/* handled by sendsig_sigcontext */
-	case 1:		/* handled by sendsig_sigcontext */
-	default:	/* unknown version */
-		printf("sendsig_siginfo: bad version %d\n",
-		    ps->sa_sigdesc[sig].sd_vers);
-		sigexit(l, SIGILL);
-	case 2:
-		break;
-	}
-
 	uc.uc_flags = _UC_SIGMASK |
 	    ((l->l_sigstk.ss_flags & SS_ONSTACK)
 		? _UC_SETSTACK : _UC_CLRSTACK);
@@ -530,17 +518,6 @@
 		l->l_sigstk.ss_flags |= SS_ONSTACK;
 }
 
-void
-sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
-{
-#ifdef COMPAT_16
-	if (curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers < 2)
-		sendsig_sigcontext(ksi, mask);
-	else
-#endif
-		sendsig_siginfo(ksi, mask);
-}
-
 /*
  * Set the lwp to begin execution in the upcall handler.  The upcall
  * handler will then simply call the upcall routine and then exit.
--- a/sys/arch/sparc64/sparc64/svr4_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sparc64/sparc64/svr4_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: svr4_machdep.c,v 1.51 2008/11/12 12:36:06 ad Exp $	 */
+/*	$NetBSD: svr4_machdep.c,v 1.52 2008/11/19 18:36:01 ad Exp $	 */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.51 2008/11/12 12:36:06 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.52 2008/11/19 18:36:01 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -700,3 +700,15 @@
 		return EINVAL;
 	}
 }
+
+void
+svr4_md_init(void)
+{
+
+}
+
+void
+svr4_md_fini(void)
+{
+
+}
--- a/sys/arch/sparc64/sparc64/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/sparc64/sparc64/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.84 2008/10/24 07:54:41 martin Exp $ */
+/*	$NetBSD: vm_machdep.c,v 1.85 2008/11/19 18:36:01 ad Exp $ */
 
 /*
  * Copyright (c) 1996-2002 Eduardo Horvath.  All rights reserved.
@@ -50,10 +50,9 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.84 2008/10/24 07:54:41 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.85 2008/11/19 18:36:01 ad Exp $");
 
 #include "opt_multiprocessor.h"
-#include "opt_coredump.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -354,91 +353,3 @@
 	if ((fs = l->l_md.md_fpstate) != NULL)
 		pool_cache_put(fpstate_cache, fs);
 }
-
-#ifdef COREDUMP
-/*
- * cpu_coredump is called to write a core dump header.
- * (should this be defined elsewhere?  machdep.c?)
- */
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	int error;
-	struct md_coredump md_core;
-	struct coreseg cseg;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-		chdr->c_cpusize = sizeof(md_core);
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	/* Copy important fields over. */
-	md_core.md_tf.tf_tstate = l->l_md.md_tf->tf_tstate;
-	md_core.md_tf.tf_pc = l->l_md.md_tf->tf_pc;
-	md_core.md_tf.tf_npc = l->l_md.md_tf->tf_npc;
-	md_core.md_tf.tf_y = l->l_md.md_tf->tf_y;
-	md_core.md_tf.tf_tt = l->l_md.md_tf->tf_tt;
-	md_core.md_tf.tf_pil = l->l_md.md_tf->tf_pil;
-	md_core.md_tf.tf_oldpil = l->l_md.md_tf->tf_oldpil;
-
-	md_core.md_tf.tf_global[0] = l->l_md.md_tf->tf_global[0];
-	md_core.md_tf.tf_global[1] = l->l_md.md_tf->tf_global[1];
-	md_core.md_tf.tf_global[2] = l->l_md.md_tf->tf_global[2];
-	md_core.md_tf.tf_global[3] = l->l_md.md_tf->tf_global[3];
-	md_core.md_tf.tf_global[4] = l->l_md.md_tf->tf_global[4];
-	md_core.md_tf.tf_global[5] = l->l_md.md_tf->tf_global[5];
-	md_core.md_tf.tf_global[6] = l->l_md.md_tf->tf_global[6];
-	md_core.md_tf.tf_global[7] = l->l_md.md_tf->tf_global[7];
-
-	md_core.md_tf.tf_out[0] = l->l_md.md_tf->tf_out[0];
-	md_core.md_tf.tf_out[1] = l->l_md.md_tf->tf_out[1];
-	md_core.md_tf.tf_out[2] = l->l_md.md_tf->tf_out[2];
-	md_core.md_tf.tf_out[3] = l->l_md.md_tf->tf_out[3];
-	md_core.md_tf.tf_out[4] = l->l_md.md_tf->tf_out[4];
-	md_core.md_tf.tf_out[5] = l->l_md.md_tf->tf_out[5];
-	md_core.md_tf.tf_out[6] = l->l_md.md_tf->tf_out[6];
-	md_core.md_tf.tf_out[7] = l->l_md.md_tf->tf_out[7];
-
-#ifdef DEBUG
-	md_core.md_tf.tf_local[0] = l->l_md.md_tf->tf_local[0];
-	md_core.md_tf.tf_local[1] = l->l_md.md_tf->tf_local[1];
-	md_core.md_tf.tf_local[2] = l->l_md.md_tf->tf_local[2];
-	md_core.md_tf.tf_local[3] = l->l_md.md_tf->tf_local[3];
-	md_core.md_tf.tf_local[4] = l->l_md.md_tf->tf_local[4];
-	md_core.md_tf.tf_local[5] = l->l_md.md_tf->tf_local[5];
-	md_core.md_tf.tf_local[6] = l->l_md.md_tf->tf_local[6];
-	md_core.md_tf.tf_local[7] = l->l_md.md_tf->tf_local[7];
-
-	md_core.md_tf.tf_in[0] = l->l_md.md_tf->tf_in[0];
-	md_core.md_tf.tf_in[1] = l->l_md.md_tf->tf_in[1];
-	md_core.md_tf.tf_in[2] = l->l_md.md_tf->tf_in[2];
-	md_core.md_tf.tf_in[3] = l->l_md.md_tf->tf_in[3];
-	md_core.md_tf.tf_in[4] = l->l_md.md_tf->tf_in[4];
-	md_core.md_tf.tf_in[5] = l->l_md.md_tf->tf_in[5];
-	md_core.md_tf.tf_in[6] = l->l_md.md_tf->tf_in[6];
-	md_core.md_tf.tf_in[7] = l->l_md.md_tf->tf_in[7];
-#endif
-	if (l->l_md.md_fpstate) {
-		fpusave_lwp(l, true);
-		md_core.md_fpstate = *l->l_md.md_fpstate;
-	} else
-		memset(&md_core.md_fpstate, 0,
-		      sizeof(md_core.md_fpstate));
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-	    chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
-	    sizeof(md_core));
-}
-#endif
--- a/sys/arch/vax/conf/files.vax	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/vax/conf/files.vax	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.vax,v 1.112 2008/08/12 17:54:47 hans Exp $
+#	$NetBSD: files.vax,v 1.113 2008/11/19 18:36:01 ad Exp $
 #
 # new style config file for vax architecture
 #
@@ -308,6 +308,7 @@
 file	arch/vax/vax/locore.c
 file	arch/vax/vax/mem.c
 file	arch/vax/vax/clock.c
+file	arch/vax/vax/core_machdep.c	coredump
 file	arch/vax/vax/gencons.c		vax8600 | vax780 | vax750 | vax630 |
 					vax8200 | vax680 | vax650 | vax660 |
 					vax670  | vaxany
--- a/sys/arch/vax/include/signal.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/vax/include/signal.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: signal.h,v 1.13 2005/12/11 12:19:34 christos Exp $   */
+/*      $NetBSD: signal.h,v 1.14 2008/11/19 18:36:01 ad Exp $   */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
@@ -73,13 +73,6 @@
 
 #ifdef _KERNEL
 void sendsig_context(int, const sigset_t *, u_long);
-
-#ifdef COMPAT_16
-#define	SIGTRAMP_VALID(vers)	((vers) <= 3 && (vers) != 1)
-#else
-#define	SIGTRAMP_VALID(vers)	((vers) == 3)
-#endif
-
 #endif	/* _KERNEL */
 
 #endif	/* _NETBSD_SOURCE */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/vax/vax/core_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,94 @@
+/*	$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:36:01 ad Exp $	     */
+
+/*
+ * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
+ * All rights reserved.
+ *
+ * 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 at Ludd, University of Lule}.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.1 2008/11/19 18:36:01 ad Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/user.h>
+#include <sys/exec.h>
+#include <sys/vnode.h>
+#include <sys/core.h>
+#include <sys/mount.h>
+#include <sys/device.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/vmparam.h>
+#include <machine/mtpr.h>
+#include <machine/pmap.h>
+#include <machine/pte.h>
+#include <machine/macros.h>
+#include <machine/trap.h>
+#include <machine/pcb.h>
+#include <machine/frame.h>
+#include <machine/cpu.h>
+#include <machine/sid.h>
+
+/*
+ * Dump the machine specific header information at the start of a core dump.
+ * First put all regs in PCB for debugging purposes. This is not an good
+ * way to do this, but good for my purposes so far.
+ */
+int
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
+{
+	struct md_coredump md_core;
+	struct coreseg cseg;
+	int error;
+
+	if (iocookie == NULL) {
+		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+		chdr->c_hdrsize = sizeof(struct core);
+		chdr->c_seghdrsize = sizeof(struct coreseg);
+		chdr->c_cpusize = sizeof(struct md_coredump);
+		chdr->c_nseg++;
+		return 0;
+	}
+
+	md_core.md_tf = *(struct trapframe *)l->l_addr->u_pcb.framep; /*XXX*/
+
+	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
+	cseg.c_addr = 0;
+	cseg.c_size = chdr->c_cpusize;
+
+	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+	    chdr->c_seghdrsize);
+	if (error)
+		return error;
+
+	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
+	    sizeof(md_core));
+}
--- a/sys/arch/vax/vax/vm_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/vax/vax/vm_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.103 2008/10/22 11:24:28 hans Exp $	     */
+/*	$NetBSD: vm_machdep.c,v 1.104 2008/11/19 18:36:01 ad Exp $	     */
 
 /*
  * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@@ -31,11 +31,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.103 2008/10/22 11:24:28 hans Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.104 2008/11/19 18:36:01 ad Exp $");
 
 #include "opt_compat_ultrix.h"
 #include "opt_multiprocessor.h"
-#include "opt_coredump.h"
 #include "opt_sa.h"
 
 #include <sys/types.h>
@@ -211,44 +210,6 @@
 	return (ENOSYS);
 }
 
-#ifdef COREDUMP
-/*
- * Dump the machine specific header information at the start of a core dump.
- * First put all regs in PCB for debugging purposes. This is not an good
- * way to do this, but good for my purposes so far.
- */
-int
-cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
-{
-	struct md_coredump md_core;
-	struct coreseg cseg;
-	int error;
-
-	if (iocookie == NULL) {
-		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-		chdr->c_hdrsize = sizeof(struct core);
-		chdr->c_seghdrsize = sizeof(struct coreseg);
-		chdr->c_cpusize = sizeof(struct md_coredump);
-		chdr->c_nseg++;
-		return 0;
-	}
-
-	md_core.md_tf = *(struct trapframe *)l->l_addr->u_pcb.framep; /*XXX*/
-
-	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
-	cseg.c_addr = 0;
-	cseg.c_size = chdr->c_cpusize;
-
-	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
-	    chdr->c_seghdrsize);
-	if (error)
-		return error;
-
-	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
-	    sizeof(md_core));
-}
-#endif
-
 /*
  * Map in a bunch of pages read/writable for the kernel.
  */
--- a/sys/arch/x86/x86/sys_machdep.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/x86/x86/sys_machdep.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_machdep.c,v 1.15 2008/05/11 16:13:34 ad Exp $	*/
+/*	$NetBSD: sys_machdep.c,v 1.16 2008/11/19 18:36:01 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
@@ -30,9 +30,8 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.15 2008/05/11 16:13:34 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.16 2008/11/19 18:36:01 ad Exp $");
 
-#include "opt_compat_netbsd.h"
 #include "opt_mtrr.h"
 #include "opt_perfctrs.h"
 #include "opt_user_ldt.h"
@@ -734,12 +733,10 @@
 	case X86_VM86:
 		error = x86_vm86(l, SCARG(uap, parms), retval);
 		break;
-#ifdef COMPAT_16
 	case X86_OLD_VM86:
 		error = compat_16_x86_vm86(l, SCARG(uap, parms), retval);
 		break;
 #endif
-#endif
 
 #ifdef PERFCTRS
 	case X86_PMC_INFO:
--- a/sys/arch/xen/conf/files.xen	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/arch/xen/conf/files.xen	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.88 2008/08/03 19:32:03 joerg Exp $
+#	$NetBSD: files.xen,v 1.89 2008/11/19 18:36:02 ad Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -34,6 +34,7 @@
 file	arch/xen/x86/autoconf.c
 ifdef i386
 file	arch/i386/i386/busfunc.S
+file	arch/i386/i386/core_machdep.c	coredump
 file	arch/i386/i386/cpufunc.S
 file	arch/i386/i386/cpu_in_cksum.S   (inet | inet6) & cpu_in_cksum
 file	arch/i386/i386/db_dbgreg.S	ddb | kstack_check_dr0
--- a/sys/compat/aoutm68k/aoutm68k_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/aoutm68k/aoutm68k_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: aoutm68k_exec.c,v 1.22 2008/04/28 20:23:41 martin Exp $	*/
+/*	$NetBSD: aoutm68k_exec.c,v 1.23 2008/11/19 18:36:02 ad Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: aoutm68k_exec.c,v 1.22 2008/04/28 20:23:41 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aoutm68k_exec.c,v 1.23 2008/11/19 18:36:02 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_syscall_debug.h"
@@ -56,7 +56,7 @@
 
 struct uvm_object *emul_netbsd_aoutm68k_object;
 
-const struct emul emul_netbsd_aoutm68k = {
+struct emul emul_netbsd_aoutm68k = {
 	"aoutm68k",
 	"/emul/aout",
 #ifndef __HAVE_MINIMAL_EMUL
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/aoutm68k/aoutm68k_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,74 @@
+/*	$NetBSD: aoutm68k_mod.c,v 1.1 2008/11/19 18:36:02 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: aoutm68k_mod.c,v 1.1 2008/11/19 18:36:02 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/exec_aout.h>
+#include <sys/signalvar.h>
+
+extern struct emul emul_netbsd_aoutm68k;
+
+MODULE(MODULE_CLASS_MISC, compat_aoutm68k, "exec_aout");
+
+static struct execsw aoutm68k_execsw[] = {
+	{ sizeof(struct exec),
+	  exec_aout_makecmds,
+	  { NULL },
+	  &emul_netbsd_aoutm68k,
+	  EXECSW_PRIO_FIRST,		/* before exec_aout */
+	  0,
+	  copyargs,
+	  NULL,
+	  coredump_netbsd,
+	  exec_setup_stack },
+};
+
+static int
+compat_aoutm68k_modcmd(modcmd_t cmd, void *arg)
+{
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		return exec_add(aoutm68k_execsw,
+		    __arraycount(aoutm68k_execsw));
+
+	case MODULE_CMD_FINI:
+		return exec_remove(aoutm68k_execsw,
+		    __arraycount(aoutm68k_execsw));
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/aoutm68k/files.aoutm68k	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/aoutm68k/files.aoutm68k	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.aoutm68k,v 1.5 2005/12/11 12:19:56 christos Exp $
+#	$NetBSD: files.aoutm68k,v 1.6 2008/11/19 18:36:02 ad Exp $
 #
 # Config file description for m68k a.out compat code.
 
@@ -8,3 +8,4 @@
 file	compat/aoutm68k/aoutm68k_exec.c		compat_aout_m68k
 file	compat/aoutm68k/aoutm68k_stat.c		compat_aout_m68k
 file	compat/aoutm68k/aoutm68k_sysent.c	compat_aout_m68k
+file	compat/aoutm68k/aoutm68k_mod.c		compat_aout_m68k
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/common/compat_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,275 @@
+/*	$NetBSD: compat_mod.c,v 1.1 2008/11/19 18:36:02 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * Linkage for the compat module: spaghetti.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: compat_mod.c,v 1.1 2008/11/19 18:36:02 ad Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_compat_netbsd.h"
+#include "opt_compat_43.h"
+#endif
+
+#include <sys/systm.h>
+#include <sys/module.h>
+#include <sys/rwlock.h>
+#include <sys/tty.h>
+#include <sys/signalvar.h>
+#include <sys/syscall.h>
+#include <sys/syscallargs.h>
+#include <sys/syscallvar.h>
+
+#include <uvm/uvm_extern.h>
+#include <uvm/uvm_object.h>
+
+#include <compat/common/compat_util.h>
+
+MODULE(MODULE_CLASS_MISC, compat, NULL);
+
+int	ttcompat(struct tty *, u_long, void *, int, struct lwp *);
+
+#ifdef COMPAT_16
+extern char sigcode[], esigcode[];
+struct uvm_object *emul_netbsd_object;
+#endif
+
+extern krwlock_t exec_lock;
+extern krwlock_t ttcompat_lock;
+
+static const struct syscall_package compat_syscalls[] = {
+#if defined(COMPAT_43)
+	{ SYS_compat_43_fstat43, 0, (sy_call_t *)compat_43_sys_fstat },
+	{ SYS_compat_43_lstat43, 0, (sy_call_t *)compat_43_sys_lstat },
+	{ SYS_compat_43_oaccept, 0, (sy_call_t *)compat_43_sys_accept },
+	{ SYS_compat_43_ocreat, 0, (sy_call_t *)compat_43_sys_creat },
+	{ SYS_compat_43_oftruncate, 0, (sy_call_t *)compat_43_sys_ftruncate },
+	{ SYS_compat_43_ogetdirentries, 0, (sy_call_t *)compat_43_sys_getdirentries },
+	{ SYS_compat_43_ogetdtablesize, 0, (sy_call_t *)compat_43_sys_getdtablesize },
+	{ SYS_compat_43_ogethostid, 0, (sy_call_t *)compat_43_sys_gethostid },
+	{ SYS_compat_43_ogethostname, 0, (sy_call_t *)compat_43_sys_gethostname },
+	{ SYS_compat_43_ogetkerninfo, 0, (sy_call_t *)compat_43_sys_getkerninfo },
+	{ SYS_compat_43_ogetpagesize, 0, (sy_call_t *)compat_43_sys_getpagesize },
+	{ SYS_compat_43_ogetpeername, 0, (sy_call_t *)compat_43_sys_getpeername },
+	{ SYS_compat_43_ogetrlimit, 0, (sy_call_t *)compat_43_sys_getrlimit },
+	{ SYS_compat_43_ogetsockname, 0, (sy_call_t *)compat_43_sys_getsockname },
+	{ SYS_compat_43_okillpg, 0, (sy_call_t *)compat_43_sys_killpg },
+	{ SYS_compat_43_olseek, 0, (sy_call_t *)compat_43_sys_lseek },
+	{ SYS_compat_43_ommap, 0, (sy_call_t *)compat_43_sys_mmap },
+	{ SYS_compat_43_oquota, 0, (sy_call_t *)compat_43_sys_quota },
+	{ SYS_compat_43_orecv, 0, (sy_call_t *)compat_43_sys_recv },
+	{ SYS_compat_43_orecvfrom, 0, (sy_call_t *)compat_43_sys_recvfrom },
+	{ SYS_compat_43_orecvmsg, 0, (sy_call_t *)compat_43_sys_recvmsg },
+	{ SYS_compat_43_osend, 0, (sy_call_t *)compat_43_sys_send },
+	{ SYS_compat_43_osendmsg, 0, (sy_call_t *)compat_43_sys_sendmsg },
+	{ SYS_compat_43_osethostid, 0, (sy_call_t *)compat_43_sys_sethostid },
+	{ SYS_compat_43_osethostname, 0, (sy_call_t *)compat_43_sys_sethostname },
+	{ SYS_compat_43_osetrlimit, 0, (sy_call_t *)compat_43_sys_setrlimit },
+	{ SYS_compat_43_osigblock, 0, (sy_call_t *)compat_43_sys_sigblock },
+	{ SYS_compat_43_osigsetmask, 0, (sy_call_t *)compat_43_sys_sigsetmask },
+	{ SYS_compat_43_osigstack, 0, (sy_call_t *)compat_43_sys_sigstack },
+	{ SYS_compat_43_osigvec, 0, (sy_call_t *)compat_43_sys_sigvec },
+	{ SYS_compat_43_otruncate, 0, (sy_call_t *)compat_43_sys_truncate },
+	{ SYS_compat_43_owait, 0, (sy_call_t *)compat_43_sys_wait },
+	{ SYS_compat_43_stat43, 0, (sy_call_t *)compat_43_sys_stat },
+#endif
+
+#if defined(COMPAT_09)
+	{ SYS_compat_09_ogetdomainname, 0, (sy_call_t *)compat_09_sys_getdomainname },
+	{ SYS_compat_09_osetdomainname, 0, (sy_call_t *)compat_09_sys_setdomainname },
+	{ SYS_compat_09_ouname, 0, (sy_call_t *)compat_09_sys_uname },
+#endif
+
+#if defined(COMPAT_10) && !defined(_LP64)
+# if defined(SYSVMSG)
+	{ SYS_compat_10_omsgsys, 0, (sy_call_t *)compat_10_sys_msgsys },
+# endif
+# if defined(SYSVSEM)
+	{ SYS_compat_10_osemsys, 0, (sy_call_t *)compat_10_sys_semsys },
+# endif
+# if defined(SYSVSHM)
+	{ SYS_compat_10_oshmsys, 0, (sy_call_t *)compat_10_sys_shmsys },
+# endif
+#endif	/* defined(COMPAT_10) && !defined(_LP64) */
+
+#if defined(COMPAT_12)
+	{ SYS_compat_12_fstat12, 0, (sy_call_t *)compat_12_sys_fstat },
+	{ SYS_compat_12_getdirentries, 0, (sy_call_t *)compat_12_sys_getdirentries },
+	{ SYS_compat_12_lstat12, 0, (sy_call_t *)compat_12_sys_lstat },
+	{ SYS_compat_12_msync, 0, (sy_call_t *)compat_12_sys_msync },
+	{ SYS_compat_12_oreboot, 0, (sy_call_t *)compat_12_sys_reboot },
+	{ SYS_compat_12_oswapon, 0, (sy_call_t *)compat_12_sys_swapon },
+	{ SYS_compat_12_stat12, 0, (sy_call_t *)compat_12_sys_stat },
+#endif
+
+#if defined(COMPAT_13)
+	{ SYS_compat_13_sigaction13, 0, (sy_call_t *)compat_13_sys_sigaction },
+	{ SYS_compat_13_sigaltstack13, 0, (sy_call_t *)compat_13_sys_sigaltstack },
+	{ SYS_compat_13_sigpending13, 0, (sy_call_t *)compat_13_sys_sigpending },
+	{ SYS_compat_13_sigprocmask13, 0, (sy_call_t *)compat_13_sys_sigprocmask },
+	{ SYS_compat_13_sigreturn13, 0, (sy_call_t *)compat_13_sys_sigreturn },
+	{ SYS_compat_13_sigsuspend13, 0, (sy_call_t *)compat_13_sys_sigsuspend },
+#endif
+
+#if defined(COMPAT_14)
+# if defined(SYSVSEM)
+	{ SYS_compat_14___semctl, 0, (sy_call_t *)compat_14_sys___semctl },
+# endif
+# if defined(SYSVMSG)
+	{ SYS_compat_14_msgctl, 0, (sy_call_t *)compat_14_sys_msgctl },
+# endif
+# if defined(SYSVSHM)
+	{ SYS_compat_14_shmctl, 0, (sy_call_t *)compat_14_sys_shmctl },
+# endif
+#endif
+
+#if defined(COMPAT_16)
+	{ SYS_compat_16___sigaction14, 0, (sy_call_t *)compat_16_sys___sigaction14 },
+	{ SYS_compat_16___sigreturn14, 0, (sy_call_t *)compat_16_sys___sigreturn14 },
+#endif
+
+#if defined(COMPAT_20)
+	{ SYS_compat_20_fhstatfs, 0, (sy_call_t *)compat_20_sys_fhstatfs },
+	{ SYS_compat_20_fstatfs, 0, (sy_call_t *)compat_20_sys_fstatfs },
+	{ SYS_compat_20_getfsstat, 0, (sy_call_t *)compat_20_sys_getfsstat },
+	{ SYS_compat_20_statfs, 0, (sy_call_t *)compat_20_sys_statfs },
+#endif
+
+#if defined(COMPAT_30)
+	{ SYS_compat_30___fhstat30, 0, (sy_call_t *)compat_30_sys___fhstat30 },
+	{ SYS_compat_30___fstat13, 0, (sy_call_t *)compat_30_sys___fstat13 },
+	{ SYS_compat_30___lstat13, 0, (sy_call_t *)compat_30_sys___lstat13 },
+	{ SYS_compat_30___stat13, 0, (sy_call_t *)compat_30_sys___stat13 },
+	{ SYS_compat_30_fhopen, 0, (sy_call_t *)compat_30_sys_fhopen },
+	{ SYS_compat_30_fhstat, 0, (sy_call_t *)compat_30_sys_fhstat },
+	{ SYS_compat_30_fhstatvfs1, 0, (sy_call_t *)compat_30_sys_fhstatvfs1 },
+	{ SYS_compat_30_getdents, 0, (sy_call_t *)compat_30_sys_getdents },
+	{ SYS_compat_30_getfh, 0, (sy_call_t *)compat_30_sys_getfh },
+	{ SYS_compat_30_socket, 0, (sy_call_t *)compat_30_sys_socket },
+#endif
+
+#if defined(COMPAT_40)
+	{ SYS_compat_40_mount, 0, (sy_call_t *)compat_40_sys_mount },
+#endif
+	{ 0, 0, NULL },
+};
+
+static int
+compat_modcmd(modcmd_t cmd, void *arg)
+{
+#ifdef COMPAT_16
+	proc_t *p;
+#endif
+	int error;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		error = syscall_establish(NULL, compat_syscalls);
+		if (error != 0) {
+			return error;
+		}
+#ifdef COMPAT_43
+		KASSERT(ttcompatvec == NULL);
+		ttcompatvec = ttcompat;
+#endif
+#ifdef COMPAT_16
+		KASSERT(emul_netbsd.e_sigobject == NULL);
+		rw_enter(&exec_lock, RW_WRITER);
+		emul_netbsd.e_sigcode = sigcode;
+		emul_netbsd.e_esigcode = esigcode;
+		emul_netbsd.e_sigobject = &emul_netbsd_object;
+		rw_exit(&exec_lock);
+		KASSERT(sendsig_sigcontext_vec == NULL);
+		sendsig_sigcontext_vec = sendsig_sigcontext;
+#endif
+#if defined(COMPAT_09) || defined(COMPAT_43)
+		compat_sysctl_init();
+#endif
+		return 0;
+
+	case MODULE_CMD_FINI:
+#ifdef COMPAT_16
+		/*
+		 * Ensure sendsig_sigcontext() is not being used.
+		 * module_lock prevents the flag being set on any
+		 * further processes while we are here.  See
+		 * sigaction1() for the opposing half.
+		 */
+		mutex_enter(proc_lock);
+		PROCLIST_FOREACH(p, &allproc) {
+			if ((p->p_lflag & PL_SIGCOMPAT) != 0) {
+				break;
+			}
+		}
+		mutex_exit(proc_lock);
+		if (p != NULL) {
+			return EBUSY;
+		}
+#endif
+		/* Unlink the the system calls. */
+		error = syscall_disestablish(NULL, compat_syscalls);
+		if (error != 0) {
+			return error;
+		}
+#ifdef COMPAT_43
+		/* Unlink ttcompatvec. */
+		if (rw_tryenter(&ttcompat_lock, RW_WRITER)) {
+			ttcompatvec = NULL;
+			rw_exit(&ttcompat_lock);
+		} else {
+			error = syscall_establish(NULL, compat_syscalls);
+			KASSERT(error == 0);
+			return EBUSY;
+		}
+#endif
+#ifdef COMPAT_16
+		/*
+		 * The sigobject may persist if still in use, but
+		 * is reference counted so will die eventually.
+		 */
+		rw_enter(&exec_lock, RW_WRITER);
+		(*emul_netbsd_object->pgops->pgo_detach)(emul_netbsd_object);
+		emul_netbsd.e_sigcode = NULL;
+		emul_netbsd.e_esigcode = NULL;
+		emul_netbsd.e_sigobject = NULL;
+		rw_exit(&exec_lock);
+#endif	/* COMPAT_16 */
+#if defined(COMPAT_09) || defined(COMPAT_43)
+		compat_sysctl_fini();
+#endif
+		return 0;
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/common/compat_util.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/common/compat_util.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_util.h,v 1.20 2008/04/28 20:23:41 martin Exp $	*/
+/*	$NetBSD: compat_util.h,v 1.21 2008/11/19 18:36:02 ad Exp $	*/
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -79,4 +79,7 @@
 
 void compat_offseterr(struct vnode *, const char *);
 
+void compat_sysctl_init(void);
+void compat_sysctl_fini(void);
+
 #endif /* !_COMPAT_UTIL_H_ */
--- a/sys/compat/common/tty_43.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/common/tty_43.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty_43.c,v 1.28 2008/11/14 23:10:57 ad Exp $	*/
+/*	$NetBSD: tty_43.c,v 1.29 2008/11/19 18:36:02 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_43.c,v 1.28 2008/11/14 23:10:57 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_43.c,v 1.29 2008/11/19 18:36:02 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -76,11 +76,6 @@
 #include <sys/syslog.h>
 #include <sys/ioctl_compat.h>
 
-/*
- * XXX libcompat files should be included with config attributes
- */
-#ifdef COMPAT_OLDTTY
-
 int ttydebug = 0;
 
 static const struct speedtab compatspeeds[] = {
@@ -516,5 +511,3 @@
 	t->c_lflag = lflag;
 	t->c_cflag = cflag;
 }
-
-#endif /* COMPAT_OLDTTY */
--- a/sys/compat/common/vfs_syscalls_43.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/common/vfs_syscalls_43.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_syscalls_43.c,v 1.47 2008/06/24 11:18:15 ad Exp $	*/
+/*	$NetBSD: vfs_syscalls_43.c,v 1.48 2008/11/19 18:36:02 ad Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.47 2008/06/24 11:18:15 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.48 2008/11/19 18:36:02 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "fs_union.h"
@@ -70,6 +70,8 @@
 #include <compat/sys/stat.h>
 #include <compat/sys/mount.h>
 
+#include <compat/common/compat_util.h>
+
 static void cvtstat(struct stat *, struct stat43 *);
 
 /*
@@ -454,6 +456,8 @@
  * sysctl helper routine for vfs.generic.conf lookups.
  */
 #if defined(COMPAT_09) || defined(COMPAT_43) || defined(COMPAT_44)
+static struct sysctllog *compat_clog;
+
 static int
 sysctl_vfs_generic_conf(SYSCTLFN_ARGS)
 {
@@ -491,17 +495,18 @@
 /*
  * Top level filesystem related information gathering.
  */
-SYSCTL_SETUP(compat_sysctl_vfs_setup, "compat sysctl vfs subtree setup")
+void
+compat_sysctl_init(void)
 {
 	extern int nmountcompatnames;
 
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&compat_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
 		       CTLTYPE_INT, "maxtypenum",
 		       SYSCTL_DESCR("Highest valid filesystem type number"),
 		       NULL, nmountcompatnames, NULL, 0,
 		       CTL_VFS, VFS_GENERIC, VFS_MAXTYPENUM, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&compat_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRUCT, "conf",
 		       SYSCTL_DESCR("Filesystem configuration information"),
@@ -509,4 +514,11 @@
 		       sizeof(struct vfsconf),
 		       CTL_VFS, VFS_GENERIC, VFS_CONF, CTL_EOL);
 }
+
+void
+compat_sysctl_fini(void)
+{
+
+	sysctl_teardown(&compat_clog);
+}
 #endif
--- a/sys/compat/darwin/darwin_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/darwin/darwin_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: darwin_exec.c,v 1.55 2008/10/15 06:51:19 wrstuden Exp $ */
+/*	$NetBSD: darwin_exec.c,v 1.56 2008/11/19 18:36:02 ad Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "opt_compat_darwin.h" /* For COMPAT_DARWIN in mach_port.h */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.55 2008/10/15 06:51:19 wrstuden Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.56 2008/11/19 18:36:02 ad Exp $");
 
 #include "opt_syscall_debug.h"
 
@@ -87,7 +87,7 @@
 void mach_syscall_intern(struct proc *);
 #endif
 
-const struct emul emul_darwin = {
+struct emul emul_darwin = {
 	"darwin",
 	"/emul/darwin",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/darwin/darwin_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/darwin/darwin_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: darwin_exec.h,v 1.15 2008/04/28 20:23:41 martin Exp $ */
+/*	$NetBSD: darwin_exec.h,v 1.16 2008/11/19 18:36:02 ad Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -54,6 +54,6 @@
 int exec_darwin_probe(const char **);
 int darwin_exec_setup_stack(struct lwp *, struct exec_package *);
 
-extern const struct emul emul_darwin;
+extern struct emul emul_darwin;
 
 #endif /* !_DARWIN_EXEC_H_ */
--- a/sys/compat/freebsd/files.freebsd	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/freebsd/files.freebsd	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.freebsd,v 1.11 2006/08/30 11:04:37 matt Exp $
+#	$NetBSD: files.freebsd,v 1.12 2008/11/19 18:36:02 ad Exp $
 #
 # Config file description for machine-independent FreeBSD compat code.
 # Included by ports that need it.
@@ -14,6 +14,7 @@
 file	compat/freebsd/freebsd_ioctl.c		compat_freebsd
 file	compat/freebsd/freebsd_ipc.c		compat_freebsd
 file	compat/freebsd/freebsd_misc.c		compat_freebsd
+file	compat/freebsd/freebsd_mod.c		compat_freebsd
 file	compat/freebsd/freebsd_ptrace.c		compat_freebsd & ptrace
 file	compat/freebsd/freebsd_sched.c		compat_freebsd
 file	compat/freebsd/freebsd_sysctl.c		compat_freebsd
--- a/sys/compat/freebsd/freebsd_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/freebsd/freebsd_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: freebsd_exec.c,v 1.35 2008/10/15 06:51:19 wrstuden Exp $	*/
+/*	$NetBSD: freebsd_exec.c,v 1.36 2008/11/19 18:36:02 ad Exp $	*/
 
 /*
  * Copyright (c) 1993, 1994 Christopher G. Demetriou
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: freebsd_exec.c,v 1.35 2008/10/15 06:51:19 wrstuden Exp $");
+__KERNEL_RCSID(0, "$NetBSD: freebsd_exec.c,v 1.36 2008/11/19 18:36:02 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_syscall_debug.h"
@@ -62,7 +62,7 @@
 void	syscall(void);
 #endif
 
-const struct emul emul_freebsd = {
+struct emul emul_freebsd = {
 	"freebsd",
 	"/emul/freebsd",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/freebsd/freebsd_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/freebsd/freebsd_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: freebsd_exec.h,v 1.15 2007/12/04 18:40:08 dsl Exp $	*/
+/*	$NetBSD: freebsd_exec.h,v 1.16 2008/11/19 18:36:02 ad Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -106,6 +106,6 @@
 void freebsd_setregs(struct lwp *, struct exec_package *, u_long);
 
 extern char freebsd_sigcode[], freebsd_esigcode[];
-extern const struct emul emul_freebsd;
+extern struct emul emul_freebsd;
 
 #endif /* !_FREEBSD_EXEC_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/freebsd/freebsd_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,117 @@
+/*	$NetBSD: freebsd_mod.c,v 1.1 2008/11/19 18:36:02 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: freebsd_mod.c,v 1.1 2008/11/19 18:36:02 ad Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_execfmt.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/exec_elf.h>
+#include <sys/signalvar.h>
+
+#include <compat/freebsd/freebsd_exec.h>
+#include <compat/freebsd/freebsd_sysctl.h>
+
+#if defined(EXEC_ELF32)
+# define	MD1	",exec_elf32"
+#else
+# define	MD1	""
+#endif
+#if defined(EXEC_AOUT)
+#  define	MD2	",exec_aout"
+#else
+# define	MD2	""
+#endif
+
+#define ELF32_AUXSIZE (howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), \
+    sizeof(Elf32_Addr)) + MAXPATHLEN + ALIGN(1))
+
+MODULE(MODULE_CLASS_MISC, compat_freebsd, "compat,compat_ossaudio" MD1 MD2);
+
+static struct execsw freebsd_execsw[] = {
+#ifdef EXEC_ELF32
+	/* FreeBSD Elf32 (probe not 64-bit safe) */
+	{ sizeof (Elf32_Ehdr),
+	  exec_elf32_makecmds,
+	  { freebsd_elf32_probe },
+	  &emul_freebsd,
+	  EXECSW_PRIO_ANY,
+	  ELF32_AUXSIZE,
+	  elf32_copyargs,
+	  NULL,
+	  coredump_elf32,
+	  exec_setup_stack },
+#endif
+#ifdef EXEC_AOUT
+	/* FreeBSD a.out (native word size) */
+	{ FREEBSD_AOUT_HDR_SIZE,
+	  exec_freebsd_aout_makecmds,
+	  { NULL },
+	  &emul_freebsd,
+	  EXECSW_PRIO_ANY,
+	  0,
+	  copyargs,
+	  NULL,
+	  coredump_netbsd,
+	  exec_setup_stack },
+#endif
+};
+
+static int
+compat_freebsd_modcmd(modcmd_t cmd, void *arg)
+{
+	int error;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		freebsd_sysctl_init();
+		error = exec_add(freebsd_execsw,
+		    __arraycount(freebsd_execsw));
+		if (error != 0)
+			freebsd_sysctl_fini();
+		return error;
+
+	case MODULE_CMD_FINI:
+		error = exec_remove(freebsd_execsw,
+		    __arraycount(freebsd_execsw));
+		if (error == 0)
+			freebsd_sysctl_fini();
+		return error;
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/freebsd/freebsd_sysctl.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/freebsd/freebsd_sysctl.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: freebsd_sysctl.c,v 1.14 2008/04/28 20:23:41 martin Exp $	*/
+/*	$NetBSD: freebsd_sysctl.c,v 1.15 2008/11/19 18:36:02 ad Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: freebsd_sysctl.c,v 1.14 2008/04/28 20:23:41 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: freebsd_sysctl.c,v 1.15 2008/11/19 18:36:02 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -52,18 +52,22 @@
 #include <compat/freebsd/freebsd_timex.h>
 #include <compat/freebsd/freebsd_signal.h>
 #include <compat/freebsd/freebsd_mman.h>
+#include <compat/freebsd/freebsd_sysctl.h>
 
 static int freebsd_sysctl_name2oid(char *, int *, int *);
 
-SYSCTL_SETUP_PROTO(freebsd_sysctl_setup);
-SYSCTL_SETUP(freebsd_sysctl_setup, "freebsd emulated sysctl setup")
+static struct sysctllog *freebsd_clog;
+
+void
+freebsd_sysctl_init(void)
 {
-	sysctl_createv(clog, 0, NULL, NULL,
+
+	sysctl_createv(&freebsd_clog, 0, NULL, NULL,
 			CTLFLAG_PERMANENT,
 			CTLTYPE_NODE, "kern", NULL,
 			NULL, 0, NULL, 0,
 			CTL_KERN, CTL_EOL);
-        sysctl_createv(clog, 0, NULL, NULL,
+        sysctl_createv(&freebsd_clog, 0, NULL, NULL,
 			CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
 			CTLTYPE_INT, "osreldate",
 			SYSCTL_DESCR("Operating system revision"),
@@ -71,6 +75,13 @@
 			CTL_KERN, CTL_CREATE, CTL_EOL);
 }
 
+void
+freebsd_sysctl_fini(void)
+{
+
+	sysctl_teardown(&freebsd_clog);
+}
+
 int
 freebsd_sys_sysctl(struct lwp *l, const struct freebsd_sys_sysctl_args *uap, register_t *retval)
 {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/freebsd/freebsd_sysctl.h	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,38 @@
+/*	$NetBSD: freebsd_sysctl.h,v 1.1 2008/11/19 18:36:02 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#ifndef _FREEBSD_SYSCTL_H
+#define _FREEBSD_SYSCTL_H
+
+void	freebsd_sysctl_init(void);
+void	freebsd_sysctl_fini(void);
+
+#endif /* !_FREEBSD_SYSCTL_H */
--- a/sys/compat/freebsd/syscalls.master	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/freebsd/syscalls.master	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.59 2008/11/14 15:49:20 ad Exp $
+	$NetBSD: syscalls.master,v 1.60 2008/11/19 18:36:02 ad Exp $
 
 ;	from: @(#)syscalls.master	8.2 (Berkeley) 1/13/94
 
@@ -33,14 +33,12 @@
 
 #if defined(_KERNEL_OPT)
 #include "opt_ktrace.h"
-#include "opt_nfsserver.h"
 #include "opt_ntp.h"
 #include "opt_sysv.h"
 #include "opt_compat_43.h"
 #include "opt_posix.h"
 
 #include "fs_lfs.h"
-#include "fs_nfs.h"
 #endif
 
 #include <sys/param.h>
@@ -293,11 +291,7 @@
 152	UNIMPL		sem_wakeup
 153	UNIMPL		asyncdaemon
 154	UNIMPL
-#if defined(NFS) || defined(NFSSERVER)
-155	NOARGS		{ int sys_nfssvc(int flag, void *argp); }
-#else
 155	UNIMPL		nfssvc
-#endif
 156	NOARGS		{ int compat_43_sys_getdirentries(int fd, char *buf, \
 			    u_int count, long *basep); } ogetdirentries
 157	NOARGS		{ int compat_20_sys_statfs(const char *path, \
--- a/sys/compat/ibcs2/files.ibcs2	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/ibcs2/files.ibcs2	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.ibcs2,v 1.8 2002/03/31 22:22:44 christos Exp $
+#	$NetBSD: files.ibcs2,v 1.9 2008/11/19 18:36:02 ad Exp $
 #
 # Config file description for machine-independent IBCS-2 compat code.
 # Included by ports that need it.
@@ -15,6 +15,7 @@
 file	compat/ibcs2/ibcs2_ioctl.c	compat_ibcs2
 file	compat/ibcs2/ibcs2_ipc.c	compat_ibcs2
 file	compat/ibcs2/ibcs2_misc.c	compat_ibcs2
+file	compat/ibcs2/ibcs2_mod.c	compat_ibcs2
 file	compat/ibcs2/ibcs2_signal.c	compat_ibcs2
 file	compat/ibcs2/ibcs2_signo.c	compat_ibcs2
 file	compat/ibcs2/ibcs2_socksys.c	compat_ibcs2
--- a/sys/compat/ibcs2/ibcs2_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/ibcs2/ibcs2_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ibcs2_exec.c,v 1.71 2008/10/15 06:51:19 wrstuden Exp $	*/
+/*	$NetBSD: ibcs2_exec.c,v 1.72 2008/11/19 18:36:03 ad Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995, 1998 Scott Bartram
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec.c,v 1.71 2008/10/15 06:51:19 wrstuden Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec.c,v 1.72 2008/11/19 18:36:03 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_syscall_debug.h"
@@ -76,7 +76,7 @@
 
 struct uvm_object *emul_ibcs2_object;
 
-const struct emul emul_ibcs2 = {
+struct emul emul_ibcs2 = {
 	"ibcs2",
 	"/emul/ibcs2",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/ibcs2/ibcs2_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/ibcs2/ibcs2_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ibcs2_exec.h,v 1.15 2007/12/04 18:40:10 dsl Exp $	*/
+/*	$NetBSD: ibcs2_exec.h,v 1.16 2008/11/19 18:36:03 ad Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995, 1998 Scott Bartram
@@ -176,7 +176,7 @@
 	long	xi_offset;	/* offset within segment to replicated data */
 };
 
-extern const struct emul emul_ibcs2;
+extern struct emul emul_ibcs2;
 
 #define XOUT_HDR_SIZE		(sizeof(struct xexec) + sizeof(struct xext))
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/ibcs2/ibcs2_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,115 @@
+/*	$NetBSD: ibcs2_mod.c,v 1.1 2008/11/19 18:36:03 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ibcs2_mod.c,v 1.1 2008/11/19 18:36:03 ad Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_execfmt.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/exec_elf.h>
+#include <sys/exec_coff.h>
+#include <sys/signalvar.h>
+
+#include <machine/ibcs2_machdep.h>
+
+#include <compat/ibcs2/ibcs2_exec.h>
+#include <compat/ibcs2/ibcs2_exec.h>
+
+#if defined(EXEC_ELF32)
+# define	MD1	",exec_elf32"
+#else
+# define	MD1	""
+#endif
+
+MODULE(MODULE_CLASS_MISC, compat_ibcs2, "compat" MD1);
+
+#define ELF32_AUXSIZE (howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), \
+    sizeof(Elf32_Addr)) + MAXPATHLEN + ALIGN(1))
+#define ELF64_AUXSIZE (howmany(ELF_AUX_ENTRIES * sizeof(Aux64Info), \
+    sizeof(Elf64_Addr)) + MAXPATHLEN + ALIGN(1))
+
+static struct execsw ibcs2_execsw[] = {
+#ifdef EXEC_ELF32
+	{ sizeof (Elf32_Ehdr),
+	  exec_elf32_makecmds,
+	  { ibcs2_elf32_probe },
+	  &emul_ibcs2,
+	  EXECSW_PRIO_ANY,
+	  ELF32_AUXSIZE,
+	  elf32_copyargs,
+	  NULL,
+	  coredump_elf32,
+	  exec_setup_stack },
+#endif
+	{ COFF_HDR_SIZE,
+	  exec_ibcs2_coff_makecmds,
+	  { NULL },
+	  &emul_ibcs2,
+	  EXECSW_PRIO_ANY,
+	  0,
+	  copyargs,
+	  NULL,
+	  coredump_netbsd,
+	  ibcs2_exec_setup_stack },
+
+	{ XOUT_HDR_SIZE,
+	  exec_ibcs2_xout_makecmds,
+	  { NULL },
+	  &emul_ibcs2,
+	  EXECSW_PRIO_ANY,
+	  0,
+	  copyargs,
+	  NULL,
+	  coredump_netbsd,
+	  ibcs2_exec_setup_stack },
+
+};
+
+static int
+compat_ibcs2_modcmd(modcmd_t cmd, void *arg)
+{
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		return exec_add(ibcs2_execsw, __arraycount(ibcs2_execsw));
+
+	case MODULE_CMD_FINI:
+		return exec_remove(ibcs2_execsw, __arraycount(ibcs2_execsw));
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/irix/files.irix	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/irix/files.irix	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.irix,v 1.25 2002/11/09 09:03:58 manu Exp $
+#	$NetBSD: files.irix,v 1.26 2008/11/19 18:36:03 ad Exp $
 #
 
 file	arch/mips/mips/irix_syscall.c		compat_irix
@@ -12,6 +12,7 @@
 file	compat/irix/irix_kmem.c			compat_irix
 file	compat/irix/irix_mman.c			compat_irix
 file	compat/irix/irix_misc.c			compat_irix
+file	compat/irix/irix_mod.c			compat_irix
 file	compat/irix/irix_mount.c		compat_irix
 file	compat/irix/irix_prctl.c		compat_irix
 file	compat/irix/irix_resource.c		compat_irix
--- a/sys/compat/irix/irix_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/irix/irix_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: irix_exec.c,v 1.52 2008/04/29 15:56:11 ad Exp $ */
+/*	$NetBSD: irix_exec.c,v 1.53 2008/11/19 18:36:03 ad Exp $ */
 
 /*-
  * Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: irix_exec.c,v 1.52 2008/04/29 15:56:11 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: irix_exec.c,v 1.53 2008/11/19 18:36:03 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_syscall_debug.h"
@@ -80,7 +80,7 @@
  */
 char irix_sigcode[] = { 0 };
 
-const struct emul emul_irix = {
+struct emul emul_irix = {
 	"irix",
 	"/emul/irix",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/irix/irix_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/irix/irix_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: irix_exec.h,v 1.25 2008/04/28 20:23:41 martin Exp $ */
+/*	$NetBSD: irix_exec.h,v 1.26 2008/11/19 18:36:03 ad Exp $ */
 
 /*-
  * Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
@@ -99,6 +99,6 @@
 
 void irix_n32_setregs(struct lwp *, struct exec_package *, u_long);
 
-extern const struct emul emul_irix;
+extern struct emul emul_irix;
 
 #endif /* !_IRIX_EXEC_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/irix/irix_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,104 @@
+/*	$NetBSD: irix_mod.c,v 1.1 2008/11/19 18:36:03 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: irix_mod.c,v 1.1 2008/11/19 18:36:03 ad Exp $");
+
+#ifndef ELFSIZE
+#define ELFSIZE ARCH_ELFSIZE
+#endif
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/exec_elf.h>
+
+#include <compat/irix/irix_util.h>
+#include <compat/irix/irix_exec.h>
+
+#if defined(EXEC_ELF32)
+# define	MD1	",exec_elf32"
+#else
+# define	MD1	""
+#endif
+
+MODULE(MODULE_CLASS_MISC, compat_irix, "compat,compat_svr4" MD1);
+
+static struct execsw irix_execsw[] = {
+#if defined(EXEC_ELF32)
+	/* IRIX Elf32 n32 ABI */
+	{ sizeof (Elf32_Ehdr),
+	  exec_elf32_makecmds,
+	  { irix_elf32_probe_n32 },
+	  &emul_irix,
+	  EXECSW_PRIO_ANY,
+	  IRIX_AUX_ARGSIZ,
+	  irix_elf32_copyargs,
+	  irix_n32_setregs,
+	  coredump_elf32,
+	  exec_setup_stack },
+	/* IRIX Elf32 o32 ABI */
+	{ sizeof (Elf32_Ehdr),
+	  exec_elf32_makecmds,
+	  { irix_elf32_probe_o32 },
+	  &emul_irix,
+	  EXECSW_PRIO_ANY,
+	  IRIX_AUX_ARGSIZ,
+	  irix_elf32_copyargs,
+	  NULL,
+	  coredump_elf32,
+	  exec_setup_stack },
+#endif
+};
+
+static int
+compat_irix_modcmd(modcmd_t cmd, void *arg)
+{
+	int error;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		irix_sysctl_init();
+		error = exec_add(irix_execsw, __arraycount(irix_execsw));
+		if (error != 0)
+			irix_sysctl_fini();
+		return error;
+
+	case MODULE_CMD_FINI:
+		error = exec_remove(irix_execsw, __arraycount(irix_execsw));
+		if (error == 0)
+			irix_sysctl_fini();
+		return error;
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/irix/irix_sysctl.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/irix/irix_sysctl.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,7 +1,7 @@
-/*	$NetBSD: irix_sysctl.c,v 1.6 2008/04/28 20:23:42 martin Exp $ */
+/*	$NetBSD: irix_sysctl.c,v 1.7 2008/11/19 18:36:03 ad Exp $ */
 
 /*-
- * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * Copyright (c) 2003, 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: irix_sysctl.c,v 1.6 2008/04/28 20:23:42 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: irix_sysctl.c,v 1.7 2008/11/19 18:36:03 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/signal.h>
@@ -38,84 +38,94 @@
 
 #include <compat/irix/irix_sysctl.h>
 
-SYSCTL_SETUP(sysctl_emul_irix_setup, "sysctl emul.irix subtree setup")
+static struct sysctllog *irix_clog;
+
+void
+irix_sysctl_fini(void)
 {
 
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_teardown(&irix_clog);
+}
+
+void
+irix_sysctl_init(void)
+{
+
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_NODE, "emul", NULL,
 		       NULL, 0, NULL, 0,
 		       CTL_EMUL, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_NODE, "irix",
 		       SYSCTL_DESCR("IRIX emulation settings"),
 		       NULL, 0, NULL, 0,
 		       CTL_EMUL, EMUL_IRIX, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_NODE, "kern",
 		       SYSCTL_DESCR("IRIX kernel emulation settings"),
 		       NULL, 0, NULL, 0,
 		       CTL_EMUL, EMUL_IRIX, EMUL_IRIX_KERN, CTL_EOL);
 
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		       CTLTYPE_STRING, "vendor",
 		       SYSCTL_DESCR("Emulated IRIX vendor name"),
 		       NULL, 0, irix_si_vendor, 128,
 		       CTL_EMUL, EMUL_IRIX, EMUL_IRIX_KERN,
 		       EMUL_IRIX_KERN_VENDOR, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		       CTLTYPE_STRING, "osprovider",
 		       SYSCTL_DESCR("Emulated IRIX system manufacturer"),
 		       NULL, 0, irix_si_os_provider, 128,
 		       CTL_EMUL, EMUL_IRIX, EMUL_IRIX_KERN,
 		       EMUL_IRIX_KERN_OSPROVIDER, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		       CTLTYPE_STRING, "osname",
 		       SYSCTL_DESCR("Emulated IRIX operating system name"),
 		       NULL, 0, irix_si_os_name, 128,
 		       CTL_EMUL, EMUL_IRIX, EMUL_IRIX_KERN,
 		       EMUL_IRIX_KERN_OSNAME, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		       CTLTYPE_STRING, "hwname",
 		       SYSCTL_DESCR("Emulated IRIX system type"),
 		       NULL, 0, irix_si_hw_name, 128,
 		       CTL_EMUL, EMUL_IRIX, EMUL_IRIX_KERN,
 		       EMUL_IRIX_KERN_HWNAME, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		       CTLTYPE_STRING, "osrelmaj",
 		       SYSCTL_DESCR("Emulated IRIX major release number"),
 		       NULL, 0, irix_si_osrel_maj, 128,
 		       CTL_EMUL, EMUL_IRIX, EMUL_IRIX_KERN,
 		       EMUL_IRIX_KERN_OSRELMAJ, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		       CTLTYPE_STRING, "osrelmin",
 		       SYSCTL_DESCR("Emulated IRIX minor release number"),
 		       NULL, 0, irix_si_osrel_min, 128,
 		       CTL_EMUL, EMUL_IRIX, EMUL_IRIX_KERN,
 		       EMUL_IRIX_KERN_OSRELMIN, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		       CTLTYPE_STRING, "osrelpatch",
 		       SYSCTL_DESCR("Emulated IRIX patch level"),
 		       NULL, 0, irix_si_osrel_patch, 128,
 		       CTL_EMUL, EMUL_IRIX, EMUL_IRIX_KERN,
 		       EMUL_IRIX_KERN_OSRELPATCH, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		       CTLTYPE_STRING, "processor",
 		       SYSCTL_DESCR("Emulated IRIX processor type"),
 		       NULL, 0, irix_si_processors, 128,
 		       CTL_EMUL, EMUL_IRIX, EMUL_IRIX_KERN,
 		       EMUL_IRIX_KERN_PROCESSOR, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
+	sysctl_createv(&irix_clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		       CTLTYPE_STRING, "version",
 		       SYSCTL_DESCR("Emulated IRIX version number"),
--- a/sys/compat/irix/irix_sysctl.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/irix/irix_sysctl.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: irix_sysctl.h,v 1.6 2008/04/28 20:23:42 martin Exp $ */
+/*	$NetBSD: irix_sysctl.h,v 1.7 2008/11/19 18:36:03 ad Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -77,8 +77,7 @@
 int irix_sysctl(int *, u_int, void *, size_t *,
     void *, size_t, struct proc *);
 
-#ifdef SYSCTL_SETUP_PROTO
-SYSCTL_SETUP_PROTO(sysctl_emul_irix_setup);
-#endif /* SYSCTL_SETUP_PROTO */
+void irix_sysctl_init(void);
+void irix_sysctl_fini(void);
 
 #endif /* _IRIX_SYSCTL_H_ */
--- a/sys/compat/linux/arch/alpha/syscalls.master	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/arch/alpha/syscalls.master	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.63 2008/11/12 18:07:40 njoly Exp $
+	$NetBSD: syscalls.master,v 1.64 2008/11/19 18:36:03 ad Exp $
 ;
 ;	@(#)syscalls.master	8.1 (Berkeley) 7/19/93
 
@@ -58,8 +58,6 @@
 
 #if defined(_KERNEL_OPT)
 #include "opt_sysv.h"
-#include "opt_compat_43.h"
-#include "opt_compat_osf1.h"
 #endif
 
 #include <sys/param.h>
--- a/sys/compat/linux/arch/amd64/linux_commons.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/arch/amd64/linux_commons.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_commons.c,v 1.8 2008/10/17 20:17:19 njoly Exp $ */
+/*	$NetBSD: linux_commons.c,v 1.9 2008/11/19 18:36:03 ad Exp $ */
 
 /*
  * This file includes C files from the common
@@ -13,12 +13,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.8 2008/10/17 20:17:19 njoly Exp $");
+__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.9 2008/11/19 18:36:03 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_sysv.h"
-#include "opt_nfsserver.h"
-#include "fs_nfs.h"
 #include "fs_lfs.h"
 #endif
 
--- a/sys/compat/linux/arch/arm/linux_commons.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/arch/arm/linux_commons.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_commons.c,v 1.7 2008/02/02 19:37:52 dsl Exp $	*/
+/*	$NetBSD: linux_commons.c,v 1.8 2008/11/19 18:36:03 ad Exp $	*/
 
 /*
  * This file includes C files from the common
@@ -13,12 +13,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.7 2008/02/02 19:37:52 dsl Exp $");
+__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.8 2008/11/19 18:36:03 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_sysv.h"
-#include "opt_nfsserver.h"
-#include "fs_nfs.h"
 #include "fs_lfs.h"
 #endif
 
--- a/sys/compat/linux/arch/arm/syscalls.master	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/arch/arm/syscalls.master	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.36 2008/11/12 18:07:40 njoly Exp $
+	$NetBSD: syscalls.master,v 1.37 2008/11/19 18:36:03 ad Exp $
 
 ; Derived from sys/compat/linux/arch/*/syscalls.master
 ; and from Linux 2.4.12 arch/arm/kernel/calls.S
@@ -34,10 +34,6 @@
 ; #ifdef's, etc. may be included, and are copied to the output files.
 ; #include's are copied to the syscall names and switch definition files only.
 
-#if defined(_KERNEL_OPT)
-#include "opt_compat_43.h"
-#endif
-
 #include <sys/param.h>
 #include <sys/poll.h>
 #include <sys/systm.h>
--- a/sys/compat/linux/arch/i386/linux_commons.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/arch/i386/linux_commons.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_commons.c,v 1.12 2008/02/02 19:37:52 dsl Exp $	*/
+/*	$NetBSD: linux_commons.c,v 1.13 2008/11/19 18:36:03 ad Exp $	*/
 
 /*
  * This file includes C files from the common
@@ -13,12 +13,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.12 2008/02/02 19:37:52 dsl Exp $");
+__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.13 2008/11/19 18:36:03 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_sysv.h"
-#include "opt_nfsserver.h"
-#include "fs_nfs.h"
 #include "fs_lfs.h"
 #endif
 
--- a/sys/compat/linux/arch/i386/syscalls.master	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/arch/i386/syscalls.master	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.95 2008/11/19 13:09:19 njoly Exp $
+	$NetBSD: syscalls.master,v 1.96 2008/11/19 18:36:03 ad Exp $
 
 ;	@(#)syscalls.master	8.1 (Berkeley) 7/19/93
 
@@ -33,10 +33,6 @@
 ; #ifdef's, etc. may be included, and are copied to the output files.
 ; #include's are copied to the syscall names and switch definition files only.
 
-#if defined(_KERNEL_OPT)
-#include "opt_compat_43.h"
-#endif
-
 #include <sys/param.h>
 #include <sys/poll.h>
 #include <sys/systm.h>
--- a/sys/compat/linux/arch/mips/syscalls.master	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/arch/mips/syscalls.master	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.30 2008/11/12 18:07:40 njoly Exp $  
+	$NetBSD: syscalls.master,v 1.31 2008/11/19 18:36:03 ad Exp $  
 
 ;	@(#)syscalls.master	8.1 (Berkeley) 7/19/93
 
@@ -40,11 +40,6 @@
 ; #ifdef's, etc. may be included, and are copied to the output files.
 ; #include's are copied to the syscall names and switch definition files only.
 
-#if defined(_KERNEL_OPT)
-#include "opt_compat_netbsd.h"
-#include "opt_compat_43.h"
-#endif
-
 #include <sys/param.h>
 #include <sys/poll.h>
 #include <sys/systm.h>
--- a/sys/compat/linux/arch/powerpc/syscalls.master	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/arch/powerpc/syscalls.master	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.38 2008/11/12 18:07:40 njoly Exp $  
+	$NetBSD: syscalls.master,v 1.39 2008/11/19 18:36:03 ad Exp $  
 
 ;	@(#)syscalls.master	8.1 (Berkeley) 7/19/93
 
@@ -62,11 +62,6 @@
 ; #ifdef's, etc. may be included, and are copied to the output files.
 ; #include's are copied to the syscall names and switch definition files only.
 
-#if defined(_KERNEL_OPT)
-#include "opt_compat_netbsd.h"
-#include "opt_compat_43.h"
-#endif
-
 #include <sys/param.h>
 #include <sys/poll.h>
 #include <sys/systm.h>
--- a/sys/compat/linux/common/linux_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/common/linux_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_exec.c,v 1.108 2008/10/28 11:42:30 jmcneill Exp $	*/
+/*	$NetBSD: linux_exec.c,v 1.109 2008/11/19 18:36:03 ad Exp $	*/
 
 /*-
  * Copyright (c) 1994, 1995, 1998, 2000, 2007, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_exec.c,v 1.108 2008/10/28 11:42:30 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_exec.c,v 1.109 2008/11/19 18:36:03 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -89,7 +89,7 @@
 
 struct uvm_object *emul_linux_object;
 
-const struct emul emul_linux = {
+struct emul emul_linux = {
 	"linux",
 	"/emul/linux",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/linux/common/linux_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/common/linux_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_exec.h,v 1.44 2008/10/25 23:38:28 christos Exp $	*/
+/*	$NetBSD: linux_exec.h,v 1.45 2008/11/19 18:36:03 ad Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
@@ -120,7 +120,7 @@
 
 #ifdef _KERNEL
 __BEGIN_DECLS
-extern const struct emul emul_linux;
+extern struct emul emul_linux;
 
 int linux_sysctl(int *, u_int, void *, size_t *, void *, size_t,
     struct lwp *);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/linux/common/linux_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,131 @@
+/*	$NetBSD: linux_mod.c,v 1.1 2008/11/19 18:36:03 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: linux_mod.c,v 1.1 2008/11/19 18:36:03 ad Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_execfmt.h"
+#endif
+
+#ifndef ELFSIZE
+#define ELFSIZE ARCH_ELFSIZE
+#endif
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/signalvar.h>
+
+#include <compat/linux/common/linux_sysctl.h>
+#include <compat/linux/common/linux_exec.h>
+
+#if defined(EXEC_ELF32) && ELFSIZE == 32
+# define	MD1	",exec_elf32"
+#else
+# define	MD1	""
+#endif
+#if defined(EXEC_ELF64)
+# define	MD2	",exec_elf64"
+#else
+# define	MD2	""
+#endif
+#if defined(EXEC_AOUT)
+#  define	MD3	",exec_aout"
+#else
+# define	MD3	""
+#endif
+
+MODULE(MODULE_CLASS_MISC, compat_linux, "compat,compat_ossaudio" MD1 MD2 MD3);
+
+static struct execsw linux_execsw[] = {
+#if defined(EXEC_ELF32) && ELFSIZE == 32
+	{ sizeof (Elf32_Ehdr),
+	  exec_elf32_makecmds,
+	  { linux_elf32_probe },
+	  &emul_linux,
+	  EXECSW_PRIO_ANY,
+	  LINUX_ELF_AUX_ARGSIZ,
+	  linux_elf32_copyargs,
+	  NULL,
+	  coredump_elf32,
+	  linux_exec_setup_stack },
+#elif defined(EXEC_ELF64)
+	{ sizeof (Elf64_Ehdr),
+	  exec_elf64_makecmds,
+	  { linux_elf64_probe },
+	  &emul_linux,
+	  EXECSW_PRIO_ANY,
+	  LINUX_ELF_AUX_ARGSIZ,
+	  linux_elf64_copyargs,
+	  NULL,
+ 	  coredump_elf64,
+	  linux_exec_setup_stack },
+#endif
+#ifdef EXEC_AOUT
+	{ LINUX_AOUT_HDR_SIZE,
+	  exec_linux_aout_makecmds,
+	  { NULL },
+	  &emul_linux,
+	  EXECSW_PRIO_LAST,
+	  LINUX_AOUT_AUX_ARGSIZ,
+	  linux_aout_copyargs,
+	  NULL,
+	  coredump_netbsd,
+	  linux_exec_setup_stack },
+#endif
+};
+
+static int
+compat_linux_modcmd(modcmd_t cmd, void *arg)
+{
+	int error;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		linux_sysctl_init();
+		error = exec_add(linux_execsw,
+		    __arraycount(linux_execsw));
+		if (error != 0)
+			linux_sysctl_fini();
+		return error;
+
+	case MODULE_CMD_FINI:
+		error = exec_remove(linux_execsw,
+		    __arraycount(linux_execsw));
+		if (error == 0)
+			linux_sysctl_fini();
+		return error;
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/linux/common/linux_socket.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/common/linux_socket.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_socket.c,v 1.98 2008/08/06 15:01:23 plunky Exp $	*/
+/*	$NetBSD: linux_socket.c,v 1.99 2008/11/19 18:36:03 ad Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.98 2008/08/06 15:01:23 plunky Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.99 2008/11/19 18:36:03 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -73,10 +73,8 @@
 
 #include <lib/libkern/libkern.h>
 
-#ifdef INET6
 #include <netinet/ip6.h>
 #include <netinet6/ip6_var.h>
-#endif
 
 #include <compat/sys/socket.h>
 #include <compat/sys/sockio.h>
@@ -1399,7 +1397,6 @@
 		DPRINTF(("AF_UNSPEC family adjusted to %d\n", bdom));
 	}
 
-#ifdef INET6
 	/*
 	 * Older Linux IPv6 code uses obsolete RFC2133 struct sockaddr_in6,
 	 * which lacks the scope id compared with RFC2553 one. If we detect
@@ -1428,7 +1425,6 @@
 		salen = sizeof (struct sockaddr_in6);
 		sin6->sin6_scope_id = 0;
 	}
-#endif
 
 	if (bdom == AF_INET)
 		salen = sizeof(struct sockaddr_in);
--- a/sys/compat/linux/common/linux_sysctl.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/common/linux_sysctl.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,7 +1,7 @@
-/*	$NetBSD: linux_sysctl.c,v 1.37 2008/11/12 12:36:10 ad Exp $	*/
+/*	$NetBSD: linux_sysctl.c,v 1.38 2008/11/19 18:36:03 ad Exp $	*/
 
 /*-
- * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * Copyright (c) 2003, 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_sysctl.c,v 1.37 2008/11/12 12:36:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_sysctl.c,v 1.38 2008/11/19 18:36:03 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -73,35 +73,83 @@
 	sysc_init_field(_sysctl_size, sizeof(struct sysctlnode)),
 };
 
-/*
- * setup for small sysctl tree used by emulation
- */
-SYSCTL_SETUP(linux_sysctl_setup, "linux emulated sysctl subtree setup")
+static struct sysctllog *linux_clog1;
+static struct sysctllog *linux_clog2;
+
+void
+linux_sysctl_fini(void)
+{
+
+	sysctl_teardown(&linux_clog2);
+	sysctl_teardown(&linux_clog1);
+	sysctl_free(&linux_sysctl_root);
+}
+
+void
+linux_sysctl_init(void)
 {
 	const struct sysctlnode *node = &linux_sysctl_root;
 
-	sysctl_createv(clog, 0, &node, &node,
+	sysctl_createv(&linux_clog1, 0, &node, &node,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_NODE, "kern", NULL,
 		       NULL, 0, NULL, 0,
 		       LINUX_CTL_KERN, CTL_EOL);
-
-	sysctl_createv(clog, 0, &node, NULL,
+	sysctl_createv(&linux_clog1, 0, &node, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRING, "ostype", NULL,
 		       NULL, 0, linux_sysname, sizeof(linux_sysname),
 		       LINUX_KERN_OSTYPE, CTL_EOL);
-	sysctl_createv(clog, 0, &node, NULL,
+	sysctl_createv(&linux_clog1, 0, &node, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRING, "osrelease", NULL,
 		       NULL, 0, linux_release, sizeof(linux_release),
 		       LINUX_KERN_OSRELEASE, CTL_EOL);
-	sysctl_createv(clog, 0, &node, NULL,
+	sysctl_createv(&linux_clog1, 0, &node, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRING, "version", NULL,
 		       NULL, 0, linux_version, sizeof(linux_version),
 		       LINUX_KERN_VERSION, CTL_EOL);
 
+	sysctl_createv(&linux_clog2, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT,
+		       CTLTYPE_NODE, "emul", NULL,
+		       NULL, 0, NULL, 0,
+		       CTL_EMUL, CTL_EOL);
+	sysctl_createv(&linux_clog2, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT,
+		       CTLTYPE_NODE, "linux",
+		       SYSCTL_DESCR("Linux emulation settings"),
+		       NULL, 0, NULL, 0,
+		       CTL_EMUL, EMUL_LINUX, CTL_EOL);
+	sysctl_createv(&linux_clog2, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT,
+		       CTLTYPE_NODE, "kern",
+		       SYSCTL_DESCR("Linux kernel emulation settings"),
+		       NULL, 0, NULL, 0,
+		       CTL_EMUL, EMUL_LINUX, EMUL_LINUX_KERN, CTL_EOL);
+	sysctl_createv(&linux_clog2, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		       CTLTYPE_STRING, "ostype",
+		       SYSCTL_DESCR("Linux operating system type"),
+		       NULL, 0, linux_sysname, sizeof(linux_sysname),
+		       CTL_EMUL, EMUL_LINUX, EMUL_LINUX_KERN,
+		       EMUL_LINUX_KERN_OSTYPE, CTL_EOL);
+	sysctl_createv(&linux_clog2, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		       CTLTYPE_STRING, "osrelease",
+		       SYSCTL_DESCR("Linux operating system release"),
+		       NULL, 0, linux_release, sizeof(linux_release),
+		       CTL_EMUL, EMUL_LINUX, EMUL_LINUX_KERN,
+		       EMUL_LINUX_KERN_OSRELEASE, CTL_EOL);
+	sysctl_createv(&linux_clog2, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		       CTLTYPE_STRING, "osversion",
+		       SYSCTL_DESCR("Linux operating system revision"),
+		       NULL, 0, linux_version, sizeof(linux_version),
+		       CTL_EMUL, EMUL_LINUX, EMUL_LINUX_KERN,
+		       EMUL_LINUX_KERN_VERSION, CTL_EOL);
+
 	linux_sysctl_root.sysctl_flags &= ~CTLFLAG_READWRITE;
 }
 
@@ -172,51 +220,3 @@
 
 	return (error);
 }
-
-/*
- * kernel related system variables under emul.linux in the main sysctl
- * tree
- */
-SYSCTL_SETUP(sysctl_emul_linux_setup, "sysctl emul.linux subtree setup")
-{
-
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT,
-		       CTLTYPE_NODE, "emul", NULL,
-		       NULL, 0, NULL, 0,
-		       CTL_EMUL, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT,
-		       CTLTYPE_NODE, "linux",
-		       SYSCTL_DESCR("Linux emulation settings"),
-		       NULL, 0, NULL, 0,
-		       CTL_EMUL, EMUL_LINUX, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT,
-		       CTLTYPE_NODE, "kern",
-		       SYSCTL_DESCR("Linux kernel emulation settings"),
-		       NULL, 0, NULL, 0,
-		       CTL_EMUL, EMUL_LINUX, EMUL_LINUX_KERN, CTL_EOL);
-
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-		       CTLTYPE_STRING, "ostype",
-		       SYSCTL_DESCR("Linux operating system type"),
-		       NULL, 0, linux_sysname, sizeof(linux_sysname),
-		       CTL_EMUL, EMUL_LINUX, EMUL_LINUX_KERN,
-		       EMUL_LINUX_KERN_OSTYPE, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-		       CTLTYPE_STRING, "osrelease",
-		       SYSCTL_DESCR("Linux operating system release"),
-		       NULL, 0, linux_release, sizeof(linux_release),
-		       CTL_EMUL, EMUL_LINUX, EMUL_LINUX_KERN,
-		       EMUL_LINUX_KERN_OSRELEASE, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-		       CTLTYPE_STRING, "osversion",
-		       SYSCTL_DESCR("Linux operating system revision"),
-		       NULL, 0, linux_version, sizeof(linux_version),
-		       CTL_EMUL, EMUL_LINUX, EMUL_LINUX_KERN,
-		       EMUL_LINUX_KERN_VERSION, CTL_EOL);
-}
--- a/sys/compat/linux/common/linux_sysctl.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/common/linux_sysctl.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_sysctl.h,v 1.4 2008/04/28 20:23:44 martin Exp $	*/
+/*	$NetBSD: linux_sysctl.h,v 1.5 2008/11/19 18:36:04 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -466,8 +466,7 @@
 #define	LINUX_BUS_ISA_PORT_BASE					2
 #define	LINUX_BUS_ISA_PORT_SHIFT				3
 
-#ifdef SYSCTL_SETUP_PROTO
-SYSCTL_SETUP_PROTO(linux_sysctl_setup);
-SYSCTL_SETUP_PROTO(sysctl_emul_linux_setup);
-#endif /* SYSCTL_SETUP_PROTO */
+void	linux_sysctl_init(void);
+void	linux_sysctl_fini(void);
+
 #endif /* !_LINUX_SYSCTL_H */
--- a/sys/compat/linux/files.linux	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux/files.linux	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.linux,v 1.19 2005/12/11 12:20:12 christos Exp $
+#	$NetBSD: files.linux,v 1.20 2008/11/19 18:36:03 ad Exp $
 #
 # Config file description for machine-independent Linux compat code.
 # Included by ports that need it.
@@ -19,6 +19,7 @@
 file	compat/linux/common/linux_ioctl.c	compat_linux
 file	compat/linux/common/linux_ipc.c		compat_linux
 file	compat/linux/common/linux_misc.c	compat_linux
+file	compat/linux/common/linux_mod.c		compat_linux
 file	compat/linux/common/linux_mtio.c	compat_linux
 file	compat/linux/common/linux_sched.c	compat_linux
 file	compat/linux/common/linux_sg.c		compat_linux
--- a/sys/compat/linux32/arch/amd64/linux32_missing.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/arch/amd64/linux32_missing.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,8 +1,10 @@
-/*	$NetBSD: linux32_missing.c,v 1.5 2008/02/02 19:37:53 dsl Exp $ */
+/*	$NetBSD: linux32_missing.c,v 1.6 2008/11/19 18:36:04 ad Exp $ */
 
 #include <sys/cdefs.h>
 
+#ifdef _KERNEL_OPT
 #include "opt_compat_linux32.h"
+#endif
 
 #include <sys/types.h>
 #include <sys/time.h>
@@ -21,6 +23,8 @@
 #include <compat/linux32/arch/amd64/linux32_missing.h>
 #include <compat/linux32/arch/amd64/linux32_syscallargs.h>
 
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/common/linux_fcntl64.c>
 #include <compat/linux/common/linux_llseek.c>
 #include <compat/linux/common/linux_misc_notalpha.c>
--- a/sys/compat/linux32/arch/amd64/syscalls.master	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/arch/amd64/syscalls.master	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.39 2008/11/12 18:07:41 njoly Exp $
+	$NetBSD: syscalls.master,v 1.40 2008/11/19 18:36:04 ad Exp $
 
 ; NetBSD i386 COMPAT_LINUX32 system call name/number "master" file.
 ; (See syscalls.conf to see what it is processed into.)
@@ -31,10 +31,6 @@
 ; #ifdef's, etc. may be included, and are copied to the output files.
 ; #include's are copied to the syscall names and switch definition files only.
 
-#if defined(_KERNEL_OPT)
-#include "opt_compat_43.h"
-#endif
-
 #include <sys/param.h>
 #include <sys/poll.h>
 #include <sys/systm.h>
@@ -57,7 +53,8 @@
 #include <compat/linux/common/linux_signal.h>
 #include <compat/linux/common/linux_siginfo.h>
 #include <compat/linux/common/linux_machdep.h>
-
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 %%
--- a/sys/compat/linux32/common/linux32_dirent.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_dirent.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_dirent.c,v 1.6 2008/09/04 17:45:00 njoly Exp $ */
+/*	$NetBSD: linux32_dirent.c,v 1.7 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_dirent.c,v 1.6 2008/09/04 17:45:00 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_dirent.c,v 1.7 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -65,6 +65,8 @@
 #include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_oldolduname.h>
 #include <compat/linux/common/linux_dirent.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_exec.c,v 1.15 2008/10/15 06:51:19 wrstuden Exp $ */
+/*	$NetBSD: linux32_exec.c,v 1.16 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 1994-2007 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_exec.c,v 1.15 2008/10/15 06:51:19 wrstuden Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_exec.c,v 1.16 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -89,7 +89,7 @@
 
 struct uvm_object *emul_linux32_object;
 
-const struct emul emul_linux32 = {
+struct emul emul_linux32 = {
 	"linux32",
 	"/emul/linux32",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/linux32/common/linux32_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_exec.h,v 1.4 2007/12/04 18:40:18 dsl Exp $ */
+/*	$NetBSD: linux32_exec.h,v 1.5 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -40,7 +40,7 @@
 #include <compat/linux32/arch/amd64/linux32_exec.h>
 #endif
 
-extern const struct emul emul_linux32;
+extern struct emul emul_linux32;
 
 /* XXXmanu Do a.out later... */
 
--- a/sys/compat/linux32/common/linux32_fcntl.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_fcntl.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_fcntl.c,v 1.6 2008/02/04 22:23:43 dsl Exp $ */
+/*	$NetBSD: linux32_fcntl.c,v 1.7 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_fcntl.c,v 1.6 2008/02/04 22:23:43 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_fcntl.c,v 1.7 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -52,6 +52,8 @@
 #include <compat/linux/common/linux_fcntl.h>
 #include <compat/linux/common/linux_machdep.h>
 #include <compat/linux/common/linux_misc.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_ioctl.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_ioctl.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_ioctl.c,v 1.11 2008/06/19 16:09:25 christos Exp $ */
+/*	$NetBSD: linux32_ioctl.c,v 1.12 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_ioctl.c,v 1.11 2008/06/19 16:09:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_ioctl.c,v 1.12 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -44,6 +44,8 @@
 
 #include <compat/linux/common/linux_types.h>
 #include <compat/linux/common/linux_signal.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_misc.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_misc.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_misc.c,v 1.14 2008/11/12 15:22:18 njoly Exp $	*/
+/*	$NetBSD: linux32_misc.c,v 1.15 2008/11/19 18:36:04 ad Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.14 2008/11/12 15:22:18 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.15 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -56,6 +56,8 @@
 #include <compat/linux/common/linux_signal.h>
 #include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_statfs.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 extern const struct linux_mnttypes linux_fstypes[];
--- a/sys/compat/linux32/common/linux32_mman.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_mman.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_mman.c,v 1.7 2008/03/27 14:14:06 njoly Exp $ */
+/*	$NetBSD: linux32_mman.c,v 1.8 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_mman.c,v 1.7 2008/03/27 14:14:06 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_mman.c,v 1.8 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -60,6 +60,8 @@
 #include <compat/linux/common/linux_machdep.h>
 #include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_oldolduname.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 #include <compat/linux/common/linux_mmap.h>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/linux32/common/linux32_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,98 @@
+/*	$NetBSD: linux32_mod.c,v 1.1 2008/11/19 18:36:04 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: linux32_mod.c,v 1.1 2008/11/19 18:36:04 ad Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_execfmt.h"
+#endif
+
+#ifndef ELFSIZE
+#define ELFSIZE ARCH_ELFSIZE
+#endif
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/signalvar.h>
+
+#include <compat/linux32/common/linux32_sysctl.h>
+#include <compat/linux32/common/linux32_exec.h>
+
+#if defined(EXEC_ELF32)
+# define	MD1	",exec_elf32"
+#else
+# define	MD1	""
+#endif
+
+MODULE(MODULE_CLASS_MISC, compat_linux32, "compat_linux" MD1);
+
+static struct execsw linux32_execsw[] = {
+#if defined(EXEC_ELF32)
+        { sizeof (Elf32_Ehdr),
+          exec_elf32_makecmds,
+          { linux32_elf32_probe },
+          &emul_linux32,
+          EXECSW_PRIO_FIRST, 
+	  LINUX32_ELF_AUX_ARGSIZ,
+          linux32_elf32_copyargs,
+          NULL,
+          coredump_elf32,
+          exec_setup_stack },
+#endif
+};
+
+static int
+compat_linux32_modcmd(modcmd_t cmd, void *arg)
+{
+	int error;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		linux32_sysctl_init();
+		error = exec_add(linux32_execsw,
+		    __arraycount(linux32_execsw));
+		if (error != 0)
+			linux32_sysctl_fini();
+		return error;
+
+	case MODULE_CMD_FINI:
+		error = exec_remove(linux32_execsw,
+		    __arraycount(linux32_execsw));
+		if (error == 0)
+			linux32_sysctl_fini();
+		return error;
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/linux32/common/linux32_resource.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_resource.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_resource.c,v 1.9 2008/09/22 13:07:46 njoly Exp $ */
+/*	$NetBSD: linux32_resource.c,v 1.10 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_resource.c,v 1.9 2008/09/22 13:07:46 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_resource.c,v 1.10 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -62,6 +62,8 @@
 #include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_limit.h>
 #include <compat/linux/common/linux_oldolduname.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_sched.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_sched.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_sched.c,v 1.6 2007/12/20 23:02:58 dsl Exp $ */
+/*	$NetBSD: linux32_sched.c,v 1.7 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_sched.c,v 1.6 2007/12/20 23:02:58 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_sched.c,v 1.7 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -60,6 +60,8 @@
 #include <compat/linux/common/linux_machdep.h>
 #include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_oldolduname.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_socket.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_socket.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_socket.c,v 1.9 2008/07/23 12:32:09 njoly Exp $ */
+/*	$NetBSD: linux32_socket.c,v 1.10 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.9 2008/07/23 12:32:09 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.10 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -78,6 +78,8 @@
 #include <compat/linux/common/linux_oldolduname.h>
 #include <compat/linux/common/linux_ioctl.h>
 #include <compat/linux/common/linux_sockio.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_socketcall.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_socketcall.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_socketcall.c,v 1.6 2007/12/20 23:02:58 dsl Exp $ */
+/*	$NetBSD: linux32_socketcall.c,v 1.7 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -31,9 +31,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_socketcall.c,v 1.6 2007/12/20 23:02:58 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_socketcall.c,v 1.7 2008/11/19 18:36:04 ad Exp $");
 
-#include "opt_ktrace.h"
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/time.h>
@@ -46,6 +45,8 @@
 
 #include <compat/linux/common/linux_types.h>
 #include <compat/linux/common/linux_signal.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_stat.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_stat.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_stat.c,v 1.11 2008/03/21 21:54:58 ad Exp $ */
+/*	$NetBSD: linux32_stat.c,v 1.12 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_stat.c,v 1.11 2008/03/21 21:54:58 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_stat.c,v 1.12 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -63,6 +63,8 @@
 #include <compat/linux/common/linux_machdep.h>
 #include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_oldolduname.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_sysctl.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_sysctl.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_sysctl.c,v 1.10 2008/11/12 12:36:10 ad Exp $ */
+/*	$NetBSD: linux32_sysctl.c,v 1.11 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -31,7 +31,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_sysctl.c,v 1.10 2008/11/12 12:36:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_sysctl.c,v 1.11 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -47,64 +47,19 @@
 #include <compat/linux/common/linux_types.h>
 #include <compat/linux/common/linux_signal.h>
 #include <compat/linux/common/linux_sysctl.h>
-
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
 #include <compat/linux32/common/linux32_signal.h>
 #include <compat/linux32/common/linux32_sysctl.h>
-
 #include <compat/linux32/linux32_syscallargs.h>
 
 char linux32_sysname[128] = "Linux";
 char linux32_release[128] = "2.4.18";
 char linux32_version[128] = "#0 Wed Feb 20 20:00:02 CET 2002";
 
-
-SYSCTL_SETUP(sysctl_emul_linux32_setup, "sysctl emul.linux32 subtree setup")
-{
-
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT,
-		       CTLTYPE_NODE, "emul", NULL,
-		       NULL, 0, NULL, 0,
-		       CTL_EMUL, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT,
-		       CTLTYPE_NODE, "linux32",
-		       SYSCTL_DESCR("Linux 32 bit emulation settings"),
-		       NULL, 0, NULL, 0,
-		       CTL_EMUL, EMUL_LINUX32, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT,
-		       CTLTYPE_NODE, "kern",
-		       SYSCTL_DESCR("Linux 32 bit kernel emulation settings"),
-		       NULL, 0, NULL, 0,
-		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN, CTL_EOL);
-
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-		       CTLTYPE_STRING, "ostype",
-		       SYSCTL_DESCR("Linux 32 bit operating system type"),
-		       NULL, 0, linux32_sysname, sizeof(linux32_sysname),
-		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
-		       EMUL_LINUX32_KERN_OSTYPE, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-		       CTLTYPE_STRING, "osrelease",
-		       SYSCTL_DESCR("Linux 32 bit operating system release"),
-		       NULL, 0, linux32_release, sizeof(linux32_release),
-		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
-		       EMUL_LINUX32_KERN_OSRELEASE, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-		       CTLTYPE_STRING, "osversion",
-		       SYSCTL_DESCR("Linux 32 bit operating system revision"),
-		       NULL, 0, linux32_version, sizeof(linux32_version),
-		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
-		       EMUL_LINUX32_KERN_VERSION, CTL_EOL);
-}
-
 struct sysctlnode linux32_sysctl_root = {
 	.sysctl_flags = SYSCTL_VERSION|
 	    CTLFLAG_ROOT|CTLTYPE_NODE|CTLFLAG_READWRITE,
@@ -113,27 +68,80 @@
 	sysc_init_field(_sysctl_size, sizeof(struct sysctlnode)),
 };
 
-SYSCTL_SETUP(linux32_sysctl_setup, "linux32 emulated sysctl subtree setup")
+static struct sysctllog *linux32_clog1;
+static struct sysctllog *linux32_clog2;
+
+void
+linux32_sysctl_fini(void)
+{
+
+	sysctl_teardown(&linux32_clog2);
+	sysctl_teardown(&linux32_clog1);
+	sysctl_free(&linux32_sysctl_root);
+}
+
+void
+linux32_sysctl_init(void)
 {
 	const struct sysctlnode *node = &linux32_sysctl_root;
 
-	sysctl_createv(clog, 0, &node, &node,
+	sysctl_createv(&linux32_clog1, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT,
+		       CTLTYPE_NODE, "emul", NULL,
+		       NULL, 0, NULL, 0,
+		       CTL_EMUL, CTL_EOL);
+	sysctl_createv(&linux32_clog1, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT,
+		       CTLTYPE_NODE, "linux32",
+		       SYSCTL_DESCR("Linux 32 bit emulation settings"),
+		       NULL, 0, NULL, 0,
+		       CTL_EMUL, EMUL_LINUX32, CTL_EOL);
+	sysctl_createv(&linux32_clog1, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT,
+		       CTLTYPE_NODE, "kern",
+		       SYSCTL_DESCR("Linux 32 bit kernel emulation settings"),
+		       NULL, 0, NULL, 0,
+		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN, CTL_EOL);
+
+	sysctl_createv(&linux32_clog1, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		       CTLTYPE_STRING, "ostype",
+		       SYSCTL_DESCR("Linux 32 bit operating system type"),
+		       NULL, 0, linux32_sysname, sizeof(linux32_sysname),
+		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
+		       EMUL_LINUX32_KERN_OSTYPE, CTL_EOL);
+	sysctl_createv(&linux32_clog1, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		       CTLTYPE_STRING, "osrelease",
+		       SYSCTL_DESCR("Linux 32 bit operating system release"),
+		       NULL, 0, linux32_release, sizeof(linux32_release),
+		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
+		       EMUL_LINUX32_KERN_OSRELEASE, CTL_EOL);
+	sysctl_createv(&linux32_clog1, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		       CTLTYPE_STRING, "osversion",
+		       SYSCTL_DESCR("Linux 32 bit operating system revision"),
+		       NULL, 0, linux32_version, sizeof(linux32_version),
+		       CTL_EMUL, EMUL_LINUX32, EMUL_LINUX32_KERN,
+		       EMUL_LINUX32_KERN_VERSION, CTL_EOL);
+
+	sysctl_createv(&linux32_clog2, 0, &node, &node,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_NODE, "kern", NULL,
 		       NULL, 0, NULL, 0,
 		       LINUX_CTL_KERN, CTL_EOL);
 
-	sysctl_createv(clog, 0, &node, NULL,
+	sysctl_createv(&linux32_clog2, 0, &node, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRING, "ostype", NULL,
 		       NULL, 0, linux32_sysname, sizeof(linux32_sysname),
 		       LINUX_KERN_OSTYPE, CTL_EOL);
-	sysctl_createv(clog, 0, &node, NULL,
+	sysctl_createv(&linux32_clog2, 0, &node, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRING, "osrelease", NULL,
 		       NULL, 0, linux32_release, sizeof(linux32_release),
 		       LINUX_KERN_OSRELEASE, CTL_EOL);
-	sysctl_createv(clog, 0, &node, NULL,
+	sysctl_createv(&linux32_clog2, 0, &node, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRING, "version", NULL,
 		       NULL, 0, linux32_version, sizeof(linux32_version),
--- a/sys/compat/linux32/common/linux32_sysctl.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_sysctl.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_sysctl.h,v 1.1 2006/02/09 19:18:57 manu Exp $ */
+/*	$NetBSD: linux32_sysctl.h,v 1.2 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -58,8 +58,7 @@
 	 { "osversion", CTLTYPE_STRING }, \
 }  
 
-#ifdef SYSCTL_SETUP_PROTO	                                
-SYSCTL_SETUP_PROTO(sysctl_emul_linux32_setup);	             
-#endif /* SYSCTL_SETUP_PROTO */	                          
+void	linux32_sysctl_init(void);
+void	linux32_sysctl_fini(void);
 
 #endif /* !_LINUX32_SYSCTL_H */
--- a/sys/compat/linux32/common/linux32_sysinfo.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_sysinfo.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_sysinfo.c,v 1.6 2007/12/20 23:02:58 dsl Exp $ */
+/*	$NetBSD: linux32_sysinfo.c,v 1.7 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_sysinfo.c,v 1.6 2007/12/20 23:02:58 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_sysinfo.c,v 1.7 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -52,6 +52,8 @@
 #include <compat/linux/common/linux_types.h>
 #include <compat/linux/common/linux_signal.h>
 #include <compat/linux/common/linux_misc.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_termios.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_termios.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_termios.c,v 1.13 2008/07/04 11:06:31 matthias Exp $ */
+/*	$NetBSD: linux32_termios.c,v 1.14 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 1995-2006, 2008  The NetBSD Foundation, Inc.
@@ -30,9 +30,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_termios.c,v 1.13 2008/07/04 11:06:31 matthias Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_termios.c,v 1.14 2008/11/19 18:36:04 ad Exp $");
 
+#ifdef _KERNEL_OPT
 #include "opt_compat_linux32.h"
+#endif
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -60,6 +62,8 @@
 #include <compat/linux/common/linux_signal.h>
 #include <compat/linux/common/linux_util.h>
 #include <compat/linux/common/linux_termios.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 int
--- a/sys/compat/linux32/common/linux32_time.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_time.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_time.c,v 1.22 2008/11/12 18:07:41 njoly Exp $ */
+/*	$NetBSD: linux32_time.c,v 1.23 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.22 2008/11/12 18:07:41 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.23 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -66,6 +66,8 @@
 #include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_oldolduname.h>
 #include <compat/linux/common/linux_sched.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_uid16.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_uid16.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux32_uid16.c,v 1.1 2008/01/15 22:38:35 njoly Exp $ */
+/* $NetBSD: linux32_uid16.c,v 1.2 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_uid16.c,v 1.1 2008/01/15 22:38:35 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_uid16.c,v 1.2 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -43,6 +43,8 @@
 
 #include <compat/linux/common/linux_types.h>
 #include <compat/linux/common/linux_signal.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_unistd.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_unistd.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_unistd.c,v 1.24 2008/10/03 22:39:36 njoly Exp $ */
+/*	$NetBSD: linux32_unistd.c,v 1.25 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.24 2008/10/03 22:39:36 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.25 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -59,6 +59,8 @@
 #include <compat/linux/common/linux_machdep.h>
 #include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_oldolduname.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_utsname.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_utsname.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_utsname.c,v 1.8 2007/12/24 15:56:21 njoly Exp $ */
+/*	$NetBSD: linux32_utsname.c,v 1.9 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_utsname.c,v 1.8 2007/12/24 15:56:21 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_utsname.c,v 1.9 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -61,6 +61,8 @@
 #include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_olduname.h>
 #include <compat/linux/common/linux_oldolduname.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/common/linux32_wait.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/common/linux32_wait.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_wait.c,v 1.8 2008/04/24 18:39:23 ad Exp $ */
+/*	$NetBSD: linux32_wait.c,v 1.9 2008/11/19 18:36:04 ad Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_wait.c,v 1.8 2008/04/24 18:39:23 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_wait.c,v 1.9 2008/11/19 18:36:04 ad Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -61,6 +61,8 @@
 #include <compat/linux/common/linux_machdep.h>
 #include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_oldolduname.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
 #include <compat/linux/linux_syscallargs.h>
 
 #include <compat/linux32/common/linux32_types.h>
--- a/sys/compat/linux32/files.linux32	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/linux32/files.linux32	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.linux32,v 1.4 2007/04/11 11:45:55 njoly Exp $
+#	$NetBSD: files.linux32,v 1.5 2008/11/19 18:36:04 ad Exp $
 #
 # Config file description for machine-independent Linux 32 bit compat code.
 # Included by ports that need it.
@@ -13,6 +13,7 @@
 file	compat/linux32/common/linux32_ioctl.c	compat_linux32
 file	compat/linux32/common/linux32_misc.c	compat_linux32
 file	compat/linux32/common/linux32_mman.c	compat_linux32
+file	compat/linux32/common/linux32_mod.c	compat_linux32
 file	compat/linux32/common/linux32_resource.c	compat_linux32
 file	compat/linux32/common/linux32_sched.c	compat_linux32
 file	compat/linux32/common/linux32_signal.c	compat_linux32
--- a/sys/compat/m68k4k/m68k4k_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/m68k4k/m68k4k_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: m68k4k_exec.c,v 1.19 2007/12/08 18:36:13 dsl Exp $	*/
+/*	$NetBSD: m68k4k_exec.c,v 1.20 2008/11/19 18:36:04 ad Exp $	*/
 
 /*
  * Copyright (c) 1993, 1994 Christopher G. Demetriou
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: m68k4k_exec.c,v 1.19 2007/12/08 18:36:13 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m68k4k_exec.c,v 1.20 2008/11/19 18:36:04 ad Exp $");
 
 #if !defined(__m68k__)
 #error YOU GOTTA BE KIDDING!
@@ -57,6 +57,45 @@
 
 #include <compat/m68k4k/m68k4k_exec.h>
 
+#ifdef COREDUMP
+#define	DEP	"coredump"
+#else
+#define	DEP	NULL
+#endif
+
+MODULE(MODULE_CLASS_MISC, exec_m68k4k, DEP);
+
+static struct execsw exec_m68k4k_execsw[] = {
+	{ sizeof(struct exec),
+	  exec_m68k4k_makecmds,
+	  { NULL },
+	  &emul_netbsd,
+	  EXECSW_PRIO_ANY,
+	  0,
+	  copyargs,
+	  NULL,
+	  coredump_netbsd,
+	  exec_setup_stack },
+};
+
+static int
+exec_m68k4k_modcmd(modcmd_t cmd, void *arg)
+{
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		return exec_add(exec_m68k4k_execsw,
+		    __arraycount(exec_m68k4k_execsw));
+
+	case MODULE_CMD_FINI:
+		return exec_remove(exec_m68k4k_execsw,
+		    __arraycount(exec_m68k4k_execsw));
+
+	default:
+		return ENOTTY;
+        }
+}
+
 int	exec_m68k4k_prep_zmagic(struct lwp *, struct exec_package *);
 int	exec_m68k4k_prep_nmagic(struct lwp *, struct exec_package *);
 int	exec_m68k4k_prep_omagic(struct lwp *, struct exec_package *);
--- a/sys/compat/mach/mach_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/mach/mach_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_exec.c,v 1.70 2008/10/15 06:51:19 wrstuden Exp $	 */
+/*	$NetBSD: mach_exec.c,v 1.71 2008/11/19 18:36:05 ad Exp $	 */
 
 /*-
  * Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.70 2008/10/15 06:51:19 wrstuden Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.71 2008/11/19 18:36:05 ad Exp $");
 
 #include "opt_syscall_debug.h"
 
@@ -72,7 +72,7 @@
 struct uvm_object *emul_mach_object;
 #endif
 
-const struct emul emul_mach = {
+struct emul emul_mach = {
 	"mach",
 	"/emul/mach",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/mach/mach_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/mach/mach_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_exec.h,v 1.32 2008/04/28 20:23:44 martin Exp $	 */
+/*	$NetBSD: mach_exec.h,v 1.33 2008/11/19 18:36:05 ad Exp $	 */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -72,6 +72,6 @@
 void mach_e_lwp_fork(struct lwp *, struct lwp *);
 void mach_e_lwp_exit(struct lwp *);
 
-extern const struct emul emul_mach;
+extern struct emul emul_mach;
 
 #endif /* !_MACH_EXEC_H_ */
--- a/sys/compat/netbsd32/files.netbsd32	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/netbsd32/files.netbsd32	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.netbsd32,v 1.26 2008/10/15 06:51:19 wrstuden Exp $
+#	$NetBSD: files.netbsd32,v 1.27 2008/11/19 18:36:05 ad Exp $
 #
 # config file description for machine-independent netbsd32 compat code.
 # included by ports that need it.
@@ -16,6 +16,7 @@
 file	compat/netbsd32/netbsd32_ioctl.c	compat_netbsd32
 file	compat/netbsd32/netbsd32_ipc.c		compat_netbsd32
 file	compat/netbsd32/netbsd32_lwp.c		compat_netbsd32
+file	compat/netbsd32/netbsd32_mod.c		compat_netbsd32
 file	compat/netbsd32/netbsd32_sa.c		compat_netbsd32
 file	compat/netbsd32/netbsd32_select.c	compat_netbsd32
 file	compat/netbsd32/netbsd32_sem.c		compat_netbsd32 & p1003_1b_semaphore
--- a/sys/compat/netbsd32/netbsd32_compat_30.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/netbsd32/netbsd32_compat_30.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_compat_30.c,v 1.26 2008/06/24 11:18:15 ad Exp $	*/
+/*	$NetBSD: netbsd32_compat_30.c,v 1.27 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,9 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.26 2008/06/24 11:18:15 ad Exp $");
-
-#include "opt_nfsserver.h"
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.27 2008/11/19 18:36:05 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
--- a/sys/compat/netbsd32/netbsd32_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/netbsd32/netbsd32_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_exec.h,v 1.27 2008/05/29 14:51:26 mrg Exp $	*/
+/*	$NetBSD: netbsd32_exec.h,v 1.28 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -48,7 +48,7 @@
 	netbsd32_u_long	a_drsize;	/* data relocation size */
 };
 
-extern const struct emul emul_netbsd32;
+extern struct emul emul_netbsd32;
 
 #ifdef EXEC_AOUT
 int netbsd32_exec_aout_prep_zmagic(struct lwp *, struct exec_package *);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/netbsd32/netbsd32_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,110 @@
+/*	$NetBSD: netbsd32_mod.c,v 1.1 2008/11/19 18:36:05 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_mod.c,v 1.1 2008/11/19 18:36:05 ad Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_execfmt.h"
+#define	MODDEPS	"compat"
+#else
+#define	MODDEPS	"compat,ksem"
+#endif
+
+#ifndef ELFSIZE
+#define ELFSIZE ARCH_ELFSIZE
+#endif
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/exec_elf.h>
+
+#include <compat/netbsd32/netbsd32_sysctl.h>
+#include <compat/netbsd32/netbsd32_exec.h>
+
+#define ELF32_AUXSIZE (howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), \
+    sizeof(Elf32_Addr)) + MAXPATHLEN + ALIGN(1))
+
+MODULE(MODULE_CLASS_MISC, compat_netbsd32, MODDEPS);
+
+static struct execsw netbsd32_execsw[] = {
+#ifdef EXEC_AOUT
+	{ sizeof(struct netbsd32_exec),
+	  exec_netbsd32_makecmds,
+	  { NULL },
+	  &emul_netbsd32,
+	  EXECSW_PRIO_FIRST,
+	  0,
+	  netbsd32_copyargs,
+	  NULL,
+	  coredump_netbsd32,
+	  exec_setup_stack },
+#endif
+#ifdef EXEC_ELF32
+	{ sizeof (Elf32_Ehdr),
+	  exec_elf32_makecmds,
+	  { netbsd32_elf32_probe },
+	  &emul_netbsd32,
+	  EXECSW_PRIO_FIRST,
+	  ELF32_AUXSIZE,
+	  netbsd32_elf32_copyargs,
+	  NULL,
+	  coredump_elf32,
+	  exec_setup_stack },		/* XXX XXX XXX */
+#endif
+};
+
+static int
+compat_netbsd32_modcmd(modcmd_t cmd, void *arg)
+{
+	int error;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		netbsd32_sysctl_init();
+		error = exec_add(netbsd32_execsw,
+		    __arraycount(netbsd32_execsw));
+		if (error != 0)
+			netbsd32_sysctl_fini();
+		return error;
+
+	case MODULE_CMD_FINI:
+		error = exec_remove(netbsd32_execsw,
+		    __arraycount(netbsd32_execsw));
+		if (error == 0)
+			netbsd32_sysctl_fini();
+		return error;
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/netbsd32/netbsd32_netbsd.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/netbsd32/netbsd32_netbsd.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_netbsd.c,v 1.146 2008/11/12 12:36:10 ad Exp $	*/
+/*	$NetBSD: netbsd32_netbsd.c,v 1.147 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.146 2008/11/12 12:36:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.147 2008/11/19 18:36:05 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ddb.h"
@@ -35,12 +35,10 @@
 #include "opt_compat_netbsd.h"
 #include "opt_compat_43.h"
 #include "opt_sysv.h"
-#include "opt_nfsserver.h"
 #include "opt_syscall_debug.h"
 #include "opt_sa.h"
 
 #include "fs_lfs.h"
-#include "fs_nfs.h"
 #endif
 
 /*
@@ -133,7 +131,7 @@
 #endif
 }; 
 
-const struct emul emul_netbsd32 = {
+struct emul emul_netbsd32 = {
 	"netbsd32",
 	"/emul/netbsd32",
 #ifndef __HAVE_MINIMAL_EMUL
@@ -1221,7 +1219,6 @@
 	return (sys_quotactl(l, &ua, retval));
 }
 
-#if defined(NFS) || defined(NFSSERVER)
 int
 netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap, register_t *retval)
 {
@@ -1240,7 +1237,6 @@
 	return (ENOSYS);
 #endif
 }
-#endif
 
 int
 netbsd32___getfh30(struct lwp *l, const struct netbsd32___getfh30_args *uap, register_t *retval)
--- a/sys/compat/netbsd32/netbsd32_sysctl.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/netbsd32/netbsd32_sysctl.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_sysctl.c,v 1.28 2008/01/07 16:12:53 ad Exp $	*/
+/*	$NetBSD: netbsd32_sysctl.c,v 1.29 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_sysctl.c,v 1.28 2008/01/07 16:12:53 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_sysctl.c,v 1.29 2008/11/19 18:36:05 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ddb.h"
@@ -58,6 +58,7 @@
 #include <compat/netbsd32/netbsd32_syscall.h>
 #include <compat/netbsd32/netbsd32_syscallargs.h>
 #include <compat/netbsd32/netbsd32_conv.h>
+#include <compat/netbsd32/netbsd32_sysctl.h>
 
 #if defined(DDB)
 #include <ddb/ddbvar.h>
@@ -70,6 +71,8 @@
 	sysc_init_field(_sysctl_size, sizeof(struct sysctlnode)),
 };
 
+static struct sysctllog *netbsd32_clog;
+
 /*
  * sysctl helper routine for netbsd32's kern.boottime node
  */
@@ -102,53 +105,62 @@
 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
 }
 
-SYSCTL_SETUP(netbsd32_sysctl_emul_setup, "sysctl netbsd32 shadow tree setup")
+void
+netbsd32_sysctl_init(void)
 {
 	const struct sysctlnode *_root = &netbsd32_sysctl_root;
 	extern const char machine_arch32[];
 	extern const char machine32[];
 
-	sysctl_createv(clog, 0, &_root, NULL,
+	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_NODE, "kern", NULL,
 		       NULL, 0, NULL, 0,
 		       CTL_KERN, CTL_EOL);
-	sysctl_createv(clog, 0, &_root, NULL,
+	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRUCT, "boottime", NULL,
 		       netbsd32_sysctl_kern_boottime, 0, NULL,
 		       sizeof(struct netbsd32_timeval),
 		       CTL_KERN, KERN_BOOTTIME, CTL_EOL);
 
-	sysctl_createv(clog, 0, &_root, NULL,
+	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_NODE, "vm", NULL,
 		       NULL, 0, NULL, 0,
 		       CTL_VM, CTL_EOL);
-	sysctl_createv(clog, 0, &_root, NULL,
+	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRUCT, "loadavg", NULL,
 		       netbsd32_sysctl_vm_loadavg, 0, NULL,
 		       sizeof(struct netbsd32_loadavg),
 		       CTL_VM, VM_LOADAVG, CTL_EOL);
 
-	sysctl_createv(clog, 0, &_root, NULL,
+	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_NODE, "hw", NULL,
 		       NULL, 0, NULL, 0,
 		       CTL_HW, CTL_EOL);
-	sysctl_createv(clog, 0, &_root, NULL,
+	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRING, "machine", NULL,
 		       NULL, 0, &machine32, 0,
 		       CTL_HW, HW_MACHINE, CTL_EOL);
-	sysctl_createv(clog, 0, &_root, NULL,
+	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
 		       CTLFLAG_PERMANENT,
 		       CTLTYPE_STRING, "machine_arch", NULL,
 		       NULL, 0, &machine_arch32, 0,
 		       CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
 }
 
+void
+netbsd32_sysctl_fini(void)
+{
+
+	sysctl_teardown(&netbsd32_clog);
+	sysctl_free(&netbsd32_sysctl_root);
+}
+
 int
 netbsd32___sysctl(struct lwp *l, const struct netbsd32___sysctl_args *uap, register_t *retval)
 {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/netbsd32/netbsd32_sysctl.h	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,38 @@
+/*	$NetBSD: netbsd32_sysctl.h,v 1.1 2008/11/19 18:36:05 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#ifndef _NETBSD32_SYSCTL_H
+#define _NETBSD32_SYSCTL_H
+
+void	netbsd32_sysctl_init(void);
+void	netbsd32_sysctl_fini(void);
+
+#endif /* !_NETBSD32_SYSCTL_H */
--- a/sys/compat/netbsd32/syscalls.master	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/netbsd32/syscalls.master	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.72 2008/11/14 15:49:20 ad Exp $
+	$NetBSD: syscalls.master,v 1.73 2008/11/19 18:36:05 ad Exp $
 
 ;	from: NetBSD: syscalls.master,v 1.81 1998/07/05 08:49:50 jonathan Exp
 ;	@(#)syscalls.master	8.2 (Berkeley) 1/13/94
@@ -37,7 +37,6 @@
 ; #include's are copied to the syscall names and switch definition files only.
 
 #if defined(_KERNEL_OPT)
-#include "opt_nfsserver.h"
 #include "opt_compat_netbsd.h"
 #include "opt_ntp.h"
 #include "opt_sysv.h"
@@ -228,11 +227,7 @@
 152	UNIMPL
 153	UNIMPL
 154	UNIMPL
-#if defined(NFS) || defined(NFSSERVER) || !defined(_KERNEL)
 155	STD		{ int netbsd32_nfssvc(int flag, netbsd32_voidp argp); }
-#else
-155	EXCL		netbsd32_nfssvc
-#endif
 156	COMPAT_43	{ int netbsd32_ogetdirentries(int fd, netbsd32_charp buf, u_int count, netbsd32_longp basep); }
 157	COMPAT_20	{ int netbsd32_statfs(netbsd32_charp path, netbsd32_statfsp_t buf); }
 158	COMPAT_20	{ int netbsd32_fstatfs(int fd, netbsd32_statfsp_t buf); }
--- a/sys/compat/osf1/files.osf1	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/osf1/files.osf1	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.osf1,v 1.18 2002/03/31 22:22:48 christos Exp $
+#	$NetBSD: files.osf1,v 1.19 2008/11/19 18:36:05 ad Exp $
 #
 # Config file description for machine-independent OSF/1 compat code.
 # Included by ports that need it.
@@ -26,6 +26,7 @@
 file	compat/osf1/osf1_ioctl.c	compat_osf1
 file	compat/osf1/osf1_misc.c		compat_osf1
 file	compat/osf1/osf1_mmap.c		compat_osf1
+file	compat/osf1/osf1_mod.c		compat_osf1
 file	compat/osf1/osf1_mount.c	compat_osf1
 file	compat/osf1/osf1_prot.c		compat_osf1
 file	compat/osf1/osf1_resource.c	compat_osf1
--- a/sys/compat/osf1/osf1_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/osf1/osf1_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: osf1_exec.c,v 1.41 2007/12/04 18:40:20 dsl Exp $ */
+/* $NetBSD: osf1_exec.c,v 1.42 2008/11/19 18:36:05 ad Exp $ */
 
 /*
  * Copyright (c) 1999 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: osf1_exec.c,v 1.41 2007/12/04 18:40:20 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: osf1_exec.c,v 1.42 2008/11/19 18:36:05 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_syscall_debug.h"
@@ -60,7 +60,7 @@
 
 struct uvm_object *emul_osf1_object;
 
-const struct emul emul_osf1 = {
+struct emul emul_osf1 = {
 	"osf1",
 	"/emul/osf1",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/osf1/osf1_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/osf1/osf1_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: osf1_exec.h,v 1.11 2007/12/04 18:40:20 dsl Exp $ */
+/* $NetBSD: osf1_exec.h,v 1.12 2008/11/19 18:36:05 ad Exp $ */
 
 /*
  * Copyright (c) 2000 The NetBSD foundation, Inc.
@@ -35,7 +35,7 @@
 #define _OSF1_EXEC_H
 #define	OSF1_MAX_AUX_ENTRIES	4	/* max we'll ever push (right now) */
 
-extern const struct emul emul_osf1;
+extern struct emul emul_osf1;
 
 int osf1_exec_ecoff_probe(struct lwp *, struct exec_package *);
 int osf1_copyargs(struct lwp *, struct exec_package *, struct ps_strings *, char **,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/osf1/osf1_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,80 @@
+/*	$NetBSD: osf1_mod.c,v 1.1 2008/11/19 18:36:05 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#ifdef _KERNEL_OPT
+#include "opt_execfmt.h"
+#endif
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: osf1_mod.c,v 1.1 2008/11/19 18:36:05 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/exec_elf.h>
+#include <sys/exec_coff.h>
+#include <sys/signalvar.h>
+
+#include <compat/osf1/osf1_exec.h>
+
+MODULE(MODULE_CLASS_MISC, compat_osf1, "compat,exec_ecoff");
+
+static struct execsw osf1_execsw[] = {
+	{ ECOFF_HDR_SIZE,
+	  exec_ecoff_makecmds,
+	  { .ecoff_probe_func = osf1_exec_ecoff_probe },
+	  &emul_osf1,
+	  EXECSW_PRIO_ANY,
+  	  howmany(OSF1_MAX_AUX_ENTRIES * sizeof (struct osf1_auxv) +
+	    2 * (MAXPATHLEN + 1), sizeof (char *)), /* exec & loader names */
+	  osf1_copyargs,
+	  cpu_exec_ecoff_setregs,
+	  coredump_netbsd,
+	  exec_setup_stack },
+};
+
+static int
+compat_osf1_modcmd(modcmd_t cmd, void *arg)
+{
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		return exec_add(osf1_execsw,
+		    __arraycount(osf1_execsw));
+
+	case MODULE_CMD_FINI:
+		return exec_remove(osf1_execsw,
+		    __arraycount(osf1_execsw));
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/pecoff/files.pecoff	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/pecoff/files.pecoff	Wed Nov 19 18:35:57 2008 +0000
@@ -1,5 +1,6 @@
-#	$NetBSD: files.pecoff,v 1.5 2007/11/10 09:41:02 dsl Exp $
+#	$NetBSD: files.pecoff,v 1.6 2008/11/19 18:36:05 ad Exp $
 #
 
 file	compat/pecoff/pecoff_exec.c	compat_pecoff
 file	compat/pecoff/pecoff_emul.c	compat_pecoff
+file	compat/pecoff/pecoff_mod.c	compat_pecoff
--- a/sys/compat/pecoff/pecoff_emul.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/pecoff/pecoff_emul.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pecoff_emul.c,v 1.21 2008/10/15 06:51:20 wrstuden Exp $	*/
+/*	$NetBSD: pecoff_emul.c,v 1.22 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 2000 Masaru OKI
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pecoff_emul.c,v 1.21 2008/10/15 06:51:20 wrstuden Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pecoff_emul.c,v 1.22 2008/11/19 18:36:05 ad Exp $");
 
 /*#define DEBUG_PECOFF*/
 
@@ -80,7 +80,7 @@
 extern const char * const syscallnames[];
 #endif
 
-const struct emul emul_pecoff = {
+struct emul emul_pecoff = {
 	"pecoff",
 	"/emul/pecoff",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/pecoff/pecoff_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/pecoff/pecoff_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pecoff_exec.h,v 1.9 2005/12/11 12:20:23 christos Exp $	*/
+/*	$NetBSD: pecoff_exec.h,v 1.10 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 2000 Masaru OKI
@@ -113,7 +113,7 @@
 	struct pecoff_opthdr a_opthdr;
 };
 
-extern const struct emul emul_pecoff;
+extern struct emul emul_pecoff;
 
 struct exec_package;
 int     exec_pecoff_makecmds (struct lwp *, struct exec_package *);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/pecoff/pecoff_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,78 @@
+/*	$NetBSD: pecoff_mod.c,v 1.1 2008/11/19 18:36:05 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#ifdef _KERNEL_OPT
+#include "opt_execfmt.h"
+#endif
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: pecoff_mod.c,v 1.1 2008/11/19 18:36:05 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/exec_elf.h>
+
+#include <compat/pecoff/pecoff_exec.h>
+
+MODULE(MODULE_CLASS_MISC, compat_pecoff, "compat");
+
+static struct execsw pecoff_execsw[] = {
+	{ PECOFF_HDR_SIZE,
+	  exec_pecoff_makecmds,
+	  { NULL },
+	  &emul_pecoff,
+	  EXECSW_PRIO_ANY,
+	  howmany(sizeof(struct pecoff_args), sizeof(char *)),
+	  pecoff_copyargs,
+	  NULL,
+	  coredump_netbsd,
+	  exec_setup_stack },
+};
+
+static int
+compat_pecoff_modcmd(modcmd_t cmd, void *arg)
+{
+	int error;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		return exec_add(pecoff_execsw,
+		    __arraycount(pecoff_execsw));
+
+	case MODULE_CMD_FINI:
+		return exec_remove(pecoff_execsw,
+		    __arraycount(pecoff_execsw));
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/sunos/files.sunos	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos/files.sunos	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sunos,v 1.7 2001/02/02 07:12:27 mrg Exp $
+#	$NetBSD: files.sunos,v 1.8 2008/11/19 18:36:05 ad Exp $
 #
 # Config file description for machine-independent SunOS compat code.
 # Included by ports that need it.
@@ -11,4 +11,5 @@
 file	compat/sunos/sunos_sysent.c	compat_sunos & !compat_netbsd32
 file	compat/sunos/sunos_ioctl.c	compat_sunos & !compat_netbsd32
 file	compat/sunos/sunos_misc.c	compat_sunos & !compat_netbsd32
+file	compat/sunos/sunos_mod.c	compat_sunos & !compat_netbsd32 
 file	compat/sunos/sunos_syscalls.c	syscall_debug & compat_sunos & !compat_netbsd32
--- a/sys/compat/sunos/sunos_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos/sunos_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sunos_exec.c,v 1.51 2007/12/04 18:40:21 dsl Exp $	*/
+/*	$NetBSD: sunos_exec.c,v 1.52 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 1993 Theo de Raadt
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunos_exec.c,v 1.51 2007/12/04 18:40:21 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunos_exec.c,v 1.52 2008/11/19 18:36:05 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_syscall_debug.h"
@@ -62,7 +62,7 @@
 
 struct uvm_object *emul_sunos_object;
 
-const struct emul emul_sunos = {
+struct emul emul_sunos = {
 	"sunos",
 	"/emul/sunos",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/sunos/sunos_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos/sunos_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sunos_exec.h,v 1.10 2007/12/04 18:40:21 dsl Exp $	*/
+/*	$NetBSD: sunos_exec.h,v 1.11 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 1993 Theo de Raadt
@@ -50,7 +50,7 @@
 
 #define SUNOS_AOUT_HDR_SIZE (sizeof(struct exec))
 
-extern const struct emul emul_sunos;
+extern struct emul emul_sunos;
 
 int exec_sunos_aout_makecmds(struct lwp *, struct exec_package *);
 
--- a/sys/compat/sunos/sunos_ioctl.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos/sunos_ioctl.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sunos_ioctl.c,v 1.60 2008/03/21 21:54:59 ad Exp $	*/
+/*	$NetBSD: sunos_ioctl.c,v 1.61 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 1993 Markus Wild.
@@ -27,11 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunos_ioctl.c,v 1.60 2008/03/21 21:54:59 ad Exp $");
-
-#if defined(_KERNEL_OPT)
-#include "opt_execfmt.h"
-#endif
+__KERNEL_RCSID(0, "$NetBSD: sunos_ioctl.c,v 1.61 2008/11/19 18:36:05 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
--- a/sys/compat/sunos/sunos_misc.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos/sunos_misc.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sunos_misc.c,v 1.162 2008/11/12 12:36:10 ad Exp $	*/
+/*	$NetBSD: sunos_misc.c,v 1.163 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -50,12 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunos_misc.c,v 1.162 2008/11/12 12:36:10 ad Exp $");
-
-#if defined(_KERNEL_OPT)
-#include "opt_nfsserver.h"
-#include "fs_nfs.h"
-#endif
+__KERNEL_RCSID(0, "$NetBSD: sunos_misc.c,v 1.163 2008/11/19 18:36:05 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -297,18 +292,12 @@
 	    UIO_USERSPACE, 0, &dummy);
 }
 
-#if defined(NFS)
 int
 async_daemon(struct lwp *l, const void *v, register_t *retval)
 {
-	struct sys_nfssvc_args ouap;
 
-	SCARG(&ouap, flag) = NFSSVC_BIOD;
-	SCARG(&ouap, argp) = NULL;
-
-	return (sys_nfssvc(l, &ouap, retval));
+	return kpause("fakeniod", false, 0, NULL);
 }
-#endif /* NFS */
 
 void	native_to_sunos_sigset(const sigset_t *, int *);
 void	sunos_to_native_sigset(const int, sigset_t *);
@@ -725,7 +714,6 @@
 	return ret;
 }
 
-#if defined (NFSSERVER)
 int
 sunos_sys_nfssvc(struct lwp *l, const struct sunos_sys_nfssvc_args *uap, register_t *retval)
 {
@@ -755,7 +743,6 @@
 	return (ENOSYS);
 #endif
 }
-#endif /* NFSSERVER */
 
 int
 sunos_sys_ustat(struct lwp *l, const struct sunos_sys_ustat_args *uap, register_t *retval)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/sunos/sunos_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,76 @@
+/*	$NetBSD: sunos_mod.c,v 1.1 2008/11/19 18:36:05 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: sunos_mod.c,v 1.1 2008/11/19 18:36:05 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/exec_aout.h>
+#include <sys/signalvar.h>
+
+#include <machine/sunos_machdep.h>
+
+#include <compat/sunos/sunos_exec.h>
+
+MODULE(MODULE_CLASS_MISC, compat_sunos, "compat,exec_aout");
+
+static struct execsw sunos_execsw[] = {
+	{ SUNOS_AOUT_HDR_SIZE,
+	  exec_sunos_aout_makecmds,
+	  { NULL },
+	  &emul_sunos,
+	  EXECSW_PRIO_ANY,
+	  0,
+	  copyargs,
+	  NULL,
+	  coredump_netbsd,
+	  exec_setup_stack },
+};
+
+static int
+compat_sunos_modcmd(modcmd_t cmd, void *arg)
+{
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		return exec_add(sunos_execsw,
+		    __arraycount(sunos_execsw));
+
+	case MODULE_CMD_FINI:
+		return exec_remove(sunos_execsw,
+		    __arraycount(sunos_execsw));
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/sunos/syscalls.master	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos/syscalls.master	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.69 2008/06/21 13:20:46 tsutsui Exp $
+	$NetBSD: syscalls.master,v 1.70 2008/11/19 18:36:05 ad Exp $
 
 ;	@(#)syscalls.master	8.1 (Berkeley) 7/19/93
 
@@ -32,10 +32,7 @@
 ; #include's are copied to the syscall names and switch definition files only.
 
 #if defined(_KERNEL_OPT)
-#include "opt_nfsserver.h"
 #include "opt_sysv.h"
-
-#include "fs_nfs.h"
 #endif
 
 #include <sys/param.h>
@@ -249,11 +246,7 @@
 153	NOARGS		{ int sys_poll(struct pollfd *fds, u_int nfds, \
 			    int timeout); }
 154	UNIMPL
-#ifdef NFSSERVER
 155	STD		{ int sunos_sys_nfssvc(int fd); }
-#else
-155	UNIMPL
-#endif
 156	NOARGS		{ int compat_12_sys_getdirentries(int fd, char *buf, \
 			    u_int count, long *basep); }
 157	STD		{ int sunos_sys_statfs(const char *path, \
@@ -261,13 +254,8 @@
 158	STD		{ int sunos_sys_fstatfs(int fd, \
 			    struct sunos_statfs *buf); }
 159	STD		{ int sunos_sys_unmount(char *path); }
-#ifdef NFS
 160	NOARGS		{ int async_daemon(void); }
 161	NOARGS		{ int compat_30_sys_getfh(char *fname, fhandle_t *fhp); }
-#else
-160	UNIMPL
-161	UNIMPL
-#endif
 162	NOARGS		{ int compat_09_sys_getdomainname(char *domainname, \
 			    int len); }
 163	NOARGS		{ int compat_09_sys_setdomainname(char *domainname, \
--- a/sys/compat/sunos32/files.sunos32	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos32/files.sunos32	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sunos32,v 1.1 2001/02/02 07:28:54 mrg Exp $
+#	$NetBSD: files.sunos32,v 1.2 2008/11/19 18:36:05 ad Exp $
 #
 # Config file description for machine-independent SunOS compat code for
 # 64-bit kernel.  Included by ports that need it.
@@ -11,4 +11,5 @@
 file	compat/sunos32/sunos32_misc.c		compat_sunos & compat_netbsd32
 file	compat/sunos32/sunos32_ioctl.c		compat_sunos & compat_netbsd32
 file	compat/sunos32/sunos32_sysent.c		compat_sunos & compat_netbsd32
+file	compat/sunos32/sunos32_mod.c		compat_sunos & compat_netbsd32
 file	compat/sunos32/sunos32_syscalls.c	syscall_debug & compat_sunos & compat_netbsd32
--- a/sys/compat/sunos32/sunos32_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos32/sunos32_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sunos32_exec.c,v 1.30 2008/10/15 06:51:20 wrstuden Exp $	 */
+/*	$NetBSD: sunos32_exec.c,v 1.31 2008/11/19 18:36:05 ad Exp $	 */
 
 /*
  * Copyright (c) 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunos32_exec.c,v 1.30 2008/10/15 06:51:20 wrstuden Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunos32_exec.c,v 1.31 2008/11/19 18:36:05 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_syscall_debug.h"
@@ -60,7 +60,7 @@
 
 struct uvm_object *emul_sunos32_object;
 
-const struct emul emul_sunos = {
+struct emul emul_sunos = {
 	"sunos32",
 	"/emul/sunos",
 #ifndef __HAVE_MINIMAL_EMUL
--- a/sys/compat/sunos32/sunos32_exec.h	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos32/sunos32_exec.h	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sunos32_exec.h,v 1.9 2008/05/29 14:51:26 mrg Exp $	*/
+/*	$NetBSD: sunos32_exec.h,v 1.10 2008/11/19 18:36:05 ad Exp $	*/
 
 /*
  * Copyright (c) 2001 Matthew R. Green
@@ -31,7 +31,7 @@
 
 #define SUNOS32_AOUT_HDR_SIZE (sizeof(struct netbsd32_exec))
 
-extern const struct emul emul_sunos;
+extern struct emul emul_sunos;
 
 int exec_sunos32_aout_makecmds(struct lwp *, struct exec_package *);
 void sunos32_setregs(struct lwp *l, struct exec_package *pack,
--- a/sys/compat/sunos32/sunos32_misc.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos32/sunos32_misc.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sunos32_misc.c,v 1.63 2008/11/12 12:36:11 ad Exp $	*/
+/*	$NetBSD: sunos32_misc.c,v 1.64 2008/11/19 18:36:05 ad Exp $	*/
 /* from :NetBSD: sunos_misc.c,v 1.107 2000/12/01 19:25:10 jdolecek Exp	*/
 
 /*
@@ -77,12 +77,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.63 2008/11/12 12:36:11 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.64 2008/11/19 18:36:05 ad Exp $");
 
 #define COMPAT_SUNOS 1
 
 #if defined(_KERNEL_OPT)
-#include "opt_nfsserver.h"
 #include "opt_compat_43.h"
 #include "opt_compat_netbsd.h"
 #include "fs_nfs.h"
@@ -1008,7 +1007,6 @@
 	return ret;
 }
 
-#if defined (NFSSERVER)
 int
 sunos32_sys_nfssvc(struct lwp *l, const struct sunos32_sys_nfssvc_args *uap, register_t *retval)
 {
@@ -1037,7 +1035,6 @@
 	return (ENOSYS);
 #endif
 }
-#endif /* NFSSERVER */
 
 int
 sunos32_sys_ustat(struct lwp *l, const struct sunos32_sys_ustat_args *uap, register_t *retval)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/sunos32/sunos32_mod.c	Wed Nov 19 18:35:57 2008 +0000
@@ -0,0 +1,78 @@
+/*	$NetBSD: sunos32_mod.c,v 1.1 2008/11/19 18:36:05 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software developed for The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: sunos32_mod.c,v 1.1 2008/11/19 18:36:05 ad Exp $");
+
+#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/exec.h>
+#include <sys/exec_aout.h>
+#include <sys/signalvar.h>
+
+#include <machine/sunos_machdep.h>
+
+#include <compat/sunos32/sunos32_exec.h>
+
+#include <compat/netbsd32/netbsd32_exec.h>
+
+MODULE(MODULE_CLASS_MISC, compat_sunos, "compat,compat_netbsd32,exec_aout");
+
+static struct execsw sunos_execsw[] = {
+	{ SUNOS32_AOUT_HDR_SIZE,
+	  exec_sunos32_aout_makecmds,
+	  { NULL },
+	  &emul_sunos,
+	  EXECSW_PRIO_ANY,
+	  0,
+	  netbsd32_copyargs,
+	  NULL,
+	  coredump_netbsd,
+	  exec_setup_stack },
+};
+
+static int
+compat_sunos_modcmd(modcmd_t cmd, void *arg)
+{
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		return exec_add(sunos_execsw,
+		    __arraycount(sunos_execsw));
+
+	case MODULE_CMD_FINI:
+		return exec_remove(sunos_execsw,
+		    __arraycount(sunos_execsw));
+
+	default:
+		return ENOTTY;
+	}
+}
--- a/sys/compat/sunos32/syscalls.master	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/sunos32/syscalls.master	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-;	$NetBSD: syscalls.master,v 1.16 2007/03/04 07:54:09 christos Exp $
+;	$NetBSD: syscalls.master,v 1.17 2008/11/19 18:36:05 ad Exp $
 
 ;	from :NetBSD: syscalls.master,v 1.57 2000/12/09 07:10:36 mycroft Exp
 
@@ -32,7 +32,6 @@
 ; #include's are copied to the syscall names and switch definition files only.
 
 #if defined(_KERNEL_OPT)
-#include "opt_nfsserver.h"
 #include "opt_sysv.h"
 #include "opt_compat_sunos.h"
 
@@ -249,11 +248,7 @@
 153	NOARGS		{ int netbsd32_poll(netbsd32_pollfdp_t fds, u_int nfds, \
 			    int timeout); }
 154	UNIMPL
-#ifdef NFSSERVER
 155	STD		{ int sunos32_sys_nfssvc(int fd); }
-#else
-155	UNIMPL
-#endif
 156	NOARGS		{ int compat_43_netbsd32_ogetdirentries(int fd, netbsd32_charp buf, \
 			    u_int count, netbsd32_longp basep); }
 157	STD		{ int sunos32_sys_statfs(const netbsd32_charp path, \
--- a/sys/compat/svr4/svr4_exec.c	Wed Nov 19 18:07:19 2008 +0000
+++ b/sys/compat/svr4/svr4_exec.c	Wed Nov 19 18:35:57 2008 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: svr4_exec.c,v 1.63 2008/10/15 06:51:20 wrstuden Exp $	 */
+/*	$NetBSD: svr4_exec.c,v 1.64 2008/11/19 18:36:05 ad Exp $	 */
 
 /*-
  * Copyright (c) 1994, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #