From ac83371d41c147ee182b9bc7101dcb353285a3be Mon Sep 17 00:00:00 2001 From: mickey Date: Wed, 17 Apr 1996 05:18:48 +0000 Subject: [PATCH] Cleanups & fixes from latest NetBSD primarily to run doscmd, etc. GENERIC added to the compile/.cvsignore (it is used for 'make links' for example), thus conf/GENERIC should appear magically ... --- sys/arch/i386/compile/.cvsignore | 2 + sys/arch/i386/i386/autoconf.c | 4 + sys/arch/i386/i386/db_interface.c | 4 +- sys/arch/i386/i386/freebsd_machdep.c | 102 +++++++------ sys/arch/i386/i386/gdt.c | 64 ++++---- sys/arch/i386/i386/linux_machdep.c | 90 +++++------ sys/arch/i386/i386/machdep.c | 50 +++--- sys/arch/i386/i386/pmap.c | 3 +- sys/arch/i386/i386/pmap.old.c | 3 +- sys/arch/i386/i386/process_machdep.c | 27 ++-- sys/arch/i386/i386/svr4_machdep.c | 50 +++--- sys/arch/i386/i386/swapgeneric.c | 3 + sys/arch/i386/i386/vm86.c | 221 +++++++++++---------------- sys/arch/i386/i386/vm_machdep.c | 4 +- sys/arch/i386/include/ansi.h | 4 +- sys/arch/i386/include/cpu.h | 1 + sys/arch/i386/include/pio.h | 8 +- sys/arch/i386/include/vm86.h | 159 +++++++++++++++---- 18 files changed, 444 insertions(+), 355 deletions(-) diff --git a/sys/arch/i386/compile/.cvsignore b/sys/arch/i386/compile/.cvsignore index 47065047104..9a245da2a93 100644 --- a/sys/arch/i386/compile/.cvsignore +++ b/sys/arch/i386/compile/.cvsignore @@ -1,6 +1,8 @@ DISKLESS +GENERIC GENERICADP GENERICOTHER INSTADP INSTOTHER +LOCAL TDR diff --git a/sys/arch/i386/i386/autoconf.c b/sys/arch/i386/i386/autoconf.c index a1ab9c17e31..3f94ac6d434 100644 --- a/sys/arch/i386/i386/autoconf.c +++ b/sys/arch/i386/i386/autoconf.c @@ -1,3 +1,4 @@ +/* $OpenBSD: autoconf.c,v 1.5 1996/04/17 05:18:49 mickey Exp $ */ /* $NetBSD: autoconf.c,v 1.14 1995/12/28 19:16:48 thorpej Exp $ */ /*- @@ -68,6 +69,7 @@ extern int cold; /* cold start flag initialized in locore.s */ /* * Determine i/o configuration for a machine. */ +void configure() { @@ -102,6 +104,7 @@ configure() /* * Configure swap space and related parameters. */ +void swapconf() { register struct swdevt *swp; @@ -138,6 +141,7 @@ static char devname[][2] = { * If we can do so, and not instructed not to do so, * change rootdev to correspond to the load device. */ +void setroot() { int majdev, mindev, unit, part, adaptor; diff --git a/sys/arch/i386/i386/db_interface.c b/sys/arch/i386/i386/db_interface.c index 9c632b7a239..60e3e293f3a 100644 --- a/sys/arch/i386/i386/db_interface.c +++ b/sys/arch/i386/i386/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.2 1996/03/11 11:16:42 mickey Exp $ */ +/* $OpenBSD: db_interface.c,v 1.3 1996/04/17 05:18:50 mickey Exp $ */ /* $NetBSD: db_interface.c,v 1.18 1995/10/10 04:45:03 mycroft Exp $ */ /* @@ -194,7 +194,7 @@ db_write_bytes(addr, size, data) } } -int +void Debugger() { asm("int $3"); diff --git a/sys/arch/i386/i386/freebsd_machdep.c b/sys/arch/i386/i386/freebsd_machdep.c index 48632236899..e70fa8e94eb 100644 --- a/sys/arch/i386/i386/freebsd_machdep.c +++ b/sys/arch/i386/i386/freebsd_machdep.c @@ -1,7 +1,8 @@ -/* $NetBSD: freebsd_machdep.c,v 1.5 1996/01/04 22:21:55 jtc Exp $ */ +/* $OpenBSD: freebsd_machdep.c,v 1.3 1996/04/17 05:18:51 mickey Exp $ */ +/* $NetBSD: freebsd_machdep.c,v 1.7 1996/04/11 07:47:44 mycroft Exp $ */ /*- - * Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved. + * Copyright (c) 1993, 1994, 1995, 1996 Charles M. Hannum. All rights reserved. * Copyright (c) 1992 Terrence R. Lambert. * Copyright (c) 1982, 1987, 1990 The Regents of the University of California. * All rights reserved. @@ -44,6 +45,7 @@ #include #include #include +#include #include #include @@ -52,6 +54,7 @@ #include #include #include +#include #include #include @@ -119,25 +122,27 @@ freebsd_sendsig(catcher, sig, mask, code) if (tf->tf_eflags & PSL_VM) { frame.sf_sc.sc_es = tf->tf_vm86_es; frame.sf_sc.sc_ds = tf->tf_vm86_ds; + frame.sf_sc.sc_eflags = get_vflags(p); + tf->tf_eflags &= ~PSL_VM; } else #endif { frame.sf_sc.sc_es = tf->tf_es; frame.sf_sc.sc_ds = tf->tf_ds; + frame.sf_sc.sc_eflags = tf->tf_eflags; } - frame.sf_sc.sc_edi = tf->tf_edi; - frame.sf_sc.sc_esi = tf->tf_esi; - frame.sf_sc.sc_ebp = tf->tf_ebp; - frame.sf_sc.sc_isp = 0; /* don't have to pass kernel sp to user. */ - frame.sf_sc.sc_ebx = tf->tf_ebx; - frame.sf_sc.sc_edx = tf->tf_edx; - frame.sf_sc.sc_ecx = tf->tf_ecx; - frame.sf_sc.sc_eax = tf->tf_eax; - frame.sf_sc.sc_eip = tf->tf_eip; - frame.sf_sc.sc_cs = tf->tf_cs; - frame.sf_sc.sc_eflags = tf->tf_eflags; - frame.sf_sc.sc_esp = tf->tf_esp; - frame.sf_sc.sc_ss = tf->tf_ss; + frame.sf_sc.sc_edi = tf->tf_edi; + frame.sf_sc.sc_esi = tf->tf_esi; + frame.sf_sc.sc_ebp = tf->tf_ebp; + frame.sf_sc.sc_isp = 0; /* don't have to pass kernel sp to user. */ + frame.sf_sc.sc_ebx = tf->tf_ebx; + frame.sf_sc.sc_edx = tf->tf_edx; + frame.sf_sc.sc_ecx = tf->tf_ecx; + frame.sf_sc.sc_eax = tf->tf_eax; + frame.sf_sc.sc_eip = tf->tf_eip; + frame.sf_sc.sc_cs = tf->tf_cs; + frame.sf_sc.sc_esp = tf->tf_esp; + frame.sf_sc.sc_ss = tf->tf_ss; if (copyout(&frame, fp, sizeof(frame)) != 0) { /* @@ -151,15 +156,12 @@ freebsd_sendsig(catcher, sig, mask, code) /* * Build context to run handler in. */ - tf->tf_esp = (int)fp; + tf->tf_es = GSEL(GUDATA_SEL, SEL_UPL); + tf->tf_ds = GSEL(GUDATA_SEL, SEL_UPL); tf->tf_eip = (int)(((char *)PS_STRINGS) - (freebsd_esigcode - freebsd_sigcode)); -#ifdef VM86 - tf->tf_eflags &= ~PSL_VM; -#endif tf->tf_cs = GSEL(GUCODE_SEL, SEL_UPL); - tf->tf_ds = GSEL(GUDATA_SEL, SEL_UPL); - tf->tf_es = GSEL(GUDATA_SEL, SEL_UPL); + tf->tf_esp = (int)fp; tf->tf_ss = GSEL(GUDATA_SEL, SEL_UPL); } @@ -173,6 +175,7 @@ freebsd_sendsig(catcher, sig, mask, code) * psl to gain improper privileges or to cause * a machine fault. */ +int freebsd_sys_sigreturn(p, v, retval) struct proc *p; void *v; @@ -195,22 +198,6 @@ freebsd_sys_sigreturn(p, v, retval) if (copyin((caddr_t)scp, &context, sizeof(*scp)) != 0) return (EFAULT); - /* - * Check for security violations. If we're returning to protected - * mode, the CPU will validate the segment registers automatically - * and generate a trap on violations. We handle the trap, rather - * than doing all of the checking here. - */ - if (((context.sc_eflags ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 || - !USERMODE(context.sc_cs, context.sc_eflags)) - return (EINVAL); - - if (context.sc_onstack & 01) - p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK; - else - p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK; - p->p_sigmask = context.sc_mask & ~sigcantmask; - /* * Restore signal context. */ @@ -218,25 +205,42 @@ freebsd_sys_sigreturn(p, v, retval) if (context.sc_eflags & PSL_VM) { tf->tf_vm86_es = context.sc_es; tf->tf_vm86_ds = context.sc_ds; + set_vflags(p, context.sc_eflags); } else #endif { + /* + * Check for security violations. If we're returning to + * protected mode, the CPU will validate the segment registers + * automatically and generate a trap on violations. We handle + * the trap, rather than doing all of the checking here. + */ + if (((context.sc_eflags ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 || + !USERMODE(context.sc_cs, context.sc_eflags)) + return (EINVAL); + tf->tf_es = context.sc_es; tf->tf_ds = context.sc_ds; + tf->tf_eflags = context.sc_eflags; } - tf->tf_edi = context.sc_edi; - tf->tf_esi = context.sc_esi; - tf->tf_ebp = context.sc_ebp; + tf->tf_edi = context.sc_edi; + tf->tf_esi = context.sc_esi; + tf->tf_ebp = context.sc_ebp; /* FreeBSD's context.sc_isp is useless. (`popal' ignores it.) */ - tf->tf_ebx = context.sc_ebx; - tf->tf_edx = context.sc_edx; - tf->tf_ecx = context.sc_ecx; - tf->tf_eax = context.sc_eax; - tf->tf_eip = context.sc_eip; - tf->tf_cs = context.sc_cs; - tf->tf_eflags = context.sc_eflags; - tf->tf_esp = context.sc_esp; - tf->tf_ss = context.sc_ss; + tf->tf_ebx = context.sc_ebx; + tf->tf_edx = context.sc_edx; + tf->tf_ecx = context.sc_ecx; + tf->tf_eax = context.sc_eax; + tf->tf_eip = context.sc_eip; + tf->tf_cs = context.sc_cs; + tf->tf_esp = context.sc_esp; + tf->tf_ss = context.sc_ss; + + if (context.sc_onstack & 01) + p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK; + else + p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK; + p->p_sigmask = context.sc_mask & ~sigcantmask; return (EJUSTRETURN); } diff --git a/sys/arch/i386/i386/gdt.c b/sys/arch/i386/i386/gdt.c index e827c337d54..f856603c5f5 100644 --- a/sys/arch/i386/i386/gdt.c +++ b/sys/arch/i386/i386/gdt.c @@ -1,32 +1,40 @@ -/* $NetBSD: gdt.c,v 1.6 1996/01/30 12:18:26 mycroft Exp $ */ +/* $OpenBSD: gdt.c,v 1.6 1996/04/17 05:18:52 mickey Exp $ */ +/* $NetBSD: gdt.c,v 1.7 1996/02/27 22:45:01 jtc Exp $ */ -/* - * Copyright (c) 1995 Charles M. Hannum. All rights reserved. - * Copyright (c) 1995 John T. Kohl. 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. 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 +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John T. Kohl and Charles M. Hannum. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 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 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. - * */ #include @@ -103,7 +111,6 @@ gdt_compact() int slot = NGDT, oslot; for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) { - PHOLD(p); pcb = &p->p_addr->u_pcb; oslot = IDXSEL(pcb->pcb_tss_sel); if (oslot >= gdt_count) { @@ -125,7 +132,6 @@ gdt_compact() dynamic_gdt[oslot].gd.gd_type = SDT_SYSNULL; pcb->pcb_ldt_sel = GSEL(slot, SEL_KPL); } - PRELE(p); } for (; slot < gdt_count; slot++) if (dynamic_gdt[slot].gd.gd_type == SDT_SYSNULL) diff --git a/sys/arch/i386/i386/linux_machdep.c b/sys/arch/i386/i386/linux_machdep.c index b38e48cf9ed..b01926463ab 100644 --- a/sys/arch/i386/i386/linux_machdep.c +++ b/sys/arch/i386/i386/linux_machdep.c @@ -1,5 +1,5 @@ -/* $OpenBSD: linux_machdep.c,v 1.3 1996/03/11 11:16:48 mickey Exp $ */ -/* $NetBSD: linux_machdep.c,v 1.24 1996/01/04 22:21:57 jtc Exp $ */ +/* $OpenBSD: linux_machdep.c,v 1.4 1996/04/17 05:18:53 mickey Exp $ */ +/* $NetBSD: linux_machdep.c,v 1.26 1996/04/11 07:47:45 mycroft Exp $ */ /* * Copyright (c) 1995 Frank van der Linden @@ -66,6 +66,7 @@ #include #include #include +#include #include /* @@ -134,6 +135,8 @@ linux_sendsig(catcher, sig, mask, code) frame.sf_sc.sc_fs = tf->tf_vm86_fs; frame.sf_sc.sc_es = tf->tf_vm86_es; frame.sf_sc.sc_ds = tf->tf_vm86_ds; + frame.sf_sc.sc_eflags = get_vflags(p); + tf->tf_eflags &= ~PSL_VM; } else #endif { @@ -141,20 +144,20 @@ linux_sendsig(catcher, sig, mask, code) __asm("movl %%fs,%w0" : "=r" (frame.sf_sc.sc_fs)); frame.sf_sc.sc_es = tf->tf_es; frame.sf_sc.sc_ds = tf->tf_ds; + frame.sf_sc.sc_eflags = tf->tf_eflags; } - frame.sf_sc.sc_edi = tf->tf_edi; - frame.sf_sc.sc_esi = tf->tf_esi; - frame.sf_sc.sc_ebp = tf->tf_ebp; - frame.sf_sc.sc_ebx = tf->tf_ebx; - frame.sf_sc.sc_edx = tf->tf_edx; - frame.sf_sc.sc_ecx = tf->tf_ecx; - frame.sf_sc.sc_eax = tf->tf_eax; - frame.sf_sc.sc_eip = tf->tf_eip; - frame.sf_sc.sc_cs = tf->tf_cs; - frame.sf_sc.sc_eflags = tf->tf_eflags; + frame.sf_sc.sc_edi = tf->tf_edi; + frame.sf_sc.sc_esi = tf->tf_esi; + frame.sf_sc.sc_ebp = tf->tf_ebp; + frame.sf_sc.sc_ebx = tf->tf_ebx; + frame.sf_sc.sc_edx = tf->tf_edx; + frame.sf_sc.sc_ecx = tf->tf_ecx; + frame.sf_sc.sc_eax = tf->tf_eax; + frame.sf_sc.sc_eip = tf->tf_eip; + frame.sf_sc.sc_cs = tf->tf_cs; frame.sf_sc.sc_esp_at_signal = tf->tf_esp; - frame.sf_sc.sc_ss = tf->tf_ss; - frame.sf_sc.sc_err = tf->tf_err; + frame.sf_sc.sc_ss = tf->tf_ss; + frame.sf_sc.sc_err = tf->tf_err; frame.sf_sc.sc_trapno = tf->tf_trapno; if (copyout(&frame, fp, sizeof(frame)) != 0) { @@ -169,15 +172,12 @@ linux_sendsig(catcher, sig, mask, code) /* * Build context to run handler in. */ - tf->tf_esp = (int)fp; + tf->tf_es = GSEL(GUDATA_SEL, SEL_UPL); + tf->tf_ds = GSEL(GUDATA_SEL, SEL_UPL); tf->tf_eip = (int)(((char *)PS_STRINGS) - (linux_esigcode - linux_sigcode)); -#ifdef VM86 - tf->tf_eflags &= ~PSL_VM; -#endif tf->tf_cs = GSEL(GUCODE_SEL, SEL_UPL); - tf->tf_ds = GSEL(GUDATA_SEL, SEL_UPL); - tf->tf_es = GSEL(GUDATA_SEL, SEL_UPL); + tf->tf_esp = (int)fp; tf->tf_ss = GSEL(GUDATA_SEL, SEL_UPL); } @@ -214,16 +214,6 @@ linux_sys_sigreturn(p, v, retval) if (copyin((caddr_t)scp, &context, sizeof(*scp)) != 0) return (EFAULT); - /* - * Check for security violations. - */ - if (((context.sc_eflags ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 || - !USERMODE(context.sc_cs, context.sc_eflags)) - return (EINVAL); - - p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK; - p->p_sigmask = context.sc_mask & ~sigcantmask; - /* * Restore signal context. */ @@ -233,25 +223,39 @@ linux_sys_sigreturn(p, v, retval) tf->tf_vm86_fs = context.sc_fs; tf->tf_vm86_es = context.sc_es; tf->tf_vm86_ds = context.sc_ds; + set_vflags(p, context.sc_eflags); } else #endif { + /* + * Check for security violations. If we're returning to + * protected mode, the CPU will validate the segment registers + * automatically and generate a trap on violations. We handle + * the trap, rather than doing all of the checking here. + */ + if (((context.sc_eflags ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 || + !USERMODE(context.sc_cs, context.sc_eflags)) + return (EINVAL); + /* %fs and %gs were restored by the trampoline. */ tf->tf_es = context.sc_es; tf->tf_ds = context.sc_ds; + tf->tf_eflags = context.sc_eflags; } - tf->tf_edi = context.sc_edi; - tf->tf_esi = context.sc_esi; - tf->tf_ebp = context.sc_ebp; - tf->tf_ebx = context.sc_ebx; - tf->tf_edx = context.sc_edx; - tf->tf_ecx = context.sc_ecx; - tf->tf_eax = context.sc_eax; - tf->tf_eip = context.sc_eip; - tf->tf_cs = context.sc_cs; - tf->tf_eflags = context.sc_eflags; - tf->tf_esp = context.sc_esp_at_signal; - tf->tf_ss = context.sc_ss; + tf->tf_edi = context.sc_edi; + tf->tf_esi = context.sc_esi; + tf->tf_ebp = context.sc_ebp; + tf->tf_ebx = context.sc_ebx; + tf->tf_edx = context.sc_edx; + tf->tf_ecx = context.sc_ecx; + tf->tf_eax = context.sc_eax; + tf->tf_eip = context.sc_eip; + tf->tf_cs = context.sc_cs; + tf->tf_esp = context.sc_esp_at_signal; + tf->tf_ss = context.sc_ss; + + p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK; + p->p_sigmask = context.sc_mask & ~sigcantmask; return (EJUSTRETURN); } @@ -503,9 +507,7 @@ linux_machdepioctl(p, v, retval) break; #endif default: -#ifdef DIAGNOSTIC printf("linux_machdepioctl: invalid ioctl %08x\n", com); -#endif return EINVAL; } SCARG(&bia, com) = com; diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index b20bc98824d..50ac68f6dae 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.8 1996/03/11 11:16:50 mickey Exp $ */ +/* $OpenBSD: machdep.c,v 1.9 1996/04/17 05:18:54 mickey Exp $ */ /* $NetBSD: machdep.c,v 1.191 1996/03/01 21:49:49 scottr Exp $ */ /*- @@ -360,6 +360,7 @@ struct cpu_nameclass i386_cpus[] = { { "Cx486DLC", CPUCLASS_486 }, /* CPU_486DLC (Cyrix) */ }; +void identifycpu() { int len; @@ -561,9 +562,8 @@ sendsig(catcher, sig, mask, code) frame.sf_sc.sc_fs = tf->tf_vm86_fs; frame.sf_sc.sc_es = tf->tf_vm86_es; frame.sf_sc.sc_ds = tf->tf_vm86_ds; - frame.sf_sc.sc_eflags = tf->tf_eflags; - SETFLAGS(frame.sf_sc.sc_eflags, VM86_EFLAGS(p), - VM86_FLAGMASK(p)|PSL_VIF); + frame.sf_sc.sc_eflags = get_vflag(p); + tf->tf_eflags &= ~PSL_VM; } else #endif { @@ -603,9 +603,6 @@ sendsig(catcher, sig, mask, code) tf->tf_ds = GSEL(GUDATA_SEL, SEL_UPL); tf->tf_eip = (int)(((char *)PS_STRINGS) - (esigcode - sigcode)); tf->tf_cs = GSEL(GUCODE_SEL, SEL_UPL); -#ifdef VM86 - tf->tf_eflags &= ~PSL_VM; -#endif tf->tf_esp = (int)fp; tf->tf_ss = GSEL(GUDATA_SEL, SEL_UPL); } @@ -620,6 +617,7 @@ sendsig(catcher, sig, mask, code) * psl to gain improper privileges or to cause * a machine fault. */ +int sys_sigreturn(p, v, retval) struct proc *p; void *v; @@ -642,22 +640,6 @@ sys_sigreturn(p, v, retval) if (copyin((caddr_t)scp, &context, sizeof(*scp)) != 0) return (EFAULT); - /* - * Check for security violations. If we're returning to protected - * mode, the CPU will validate the segment registers automatically - * and generate a trap on violations. We handle the trap, rather - * than doing all of the checking here. - */ - if (((context.sc_eflags ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 || - !USERMODE(context.sc_cs, context.sc_eflags)) - return (EINVAL); - - if (context.sc_onstack & 01) - p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK; - else - p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK; - p->p_sigmask = context.sc_mask & ~sigcantmask; - /* * Restore signal context. */ @@ -667,12 +649,20 @@ sys_sigreturn(p, v, retval) tf->tf_vm86_fs = context.sc_fs; tf->tf_vm86_es = context.sc_es; tf->tf_vm86_ds = context.sc_ds; - tf->tf_eflags = context.sc_eflags; - SETFLAGS(VM86_EFLAGS(p), context.sc_eflags, - VM86_FLAGMASK(p)|PSL_VIF); + set_vflags(p, context.sc_eflags); } else #endif { + /* + * Check for security violations. If we're returning to + * protected mode, the CPU will validate the segment registers + * automatically and generate a trap on violations. We handle + * the trap, rather than doing all of the checking here. + */ + if (((context.sc_eflags ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 || + !USERMODE(context.sc_cs, context.sc_eflags)) + return (EINVAL); + /* %fs and %gs were restored by the trampoline. */ tf->tf_es = context.sc_es; tf->tf_ds = context.sc_ds; @@ -690,6 +680,12 @@ sys_sigreturn(p, v, retval) tf->tf_esp = context.sc_esp; tf->tf_ss = context.sc_ss; + if (context.sc_onstack & 01) + p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK; + else + p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK; + p->p_sigmask = context.sc_mask & ~sigcantmask; + return (EJUSTRETURN); } @@ -698,7 +694,7 @@ struct pcb dumppcb; void boot(howto) - register int howto; + int howto; { extern int cold; diff --git a/sys/arch/i386/i386/pmap.c b/sys/arch/i386/i386/pmap.c index 9adae198c11..434a5a48f59 100644 --- a/sys/arch/i386/i386/pmap.c +++ b/sys/arch/i386/i386/pmap.c @@ -1,3 +1,4 @@ +/* $OpenBSD: pmap.c,v 1.6 1996/04/17 05:18:55 mickey Exp $ */ /* $NetBSD: pmap.c,v 1.34 1995/12/09 07:39:02 mycroft Exp $ */ /* @@ -1537,7 +1538,7 @@ pmap_pageable(pmap, sva, eva, pageable) /* * Miscellaneous support routines follow */ - +void i386_protection_init() { diff --git a/sys/arch/i386/i386/pmap.old.c b/sys/arch/i386/i386/pmap.old.c index 9adae198c11..9d661d0b2f5 100644 --- a/sys/arch/i386/i386/pmap.old.c +++ b/sys/arch/i386/i386/pmap.old.c @@ -1,3 +1,4 @@ +/* $OpenBSD: pmap.old.c,v 1.6 1996/04/17 05:18:55 mickey Exp $ */ /* $NetBSD: pmap.c,v 1.34 1995/12/09 07:39:02 mycroft Exp $ */ /* @@ -1537,7 +1538,7 @@ pmap_pageable(pmap, sva, eva, pageable) /* * Miscellaneous support routines follow */ - +void i386_protection_init() { diff --git a/sys/arch/i386/i386/process_machdep.c b/sys/arch/i386/i386/process_machdep.c index 56eda5950ac..fa5859c60e0 100644 --- a/sys/arch/i386/i386/process_machdep.c +++ b/sys/arch/i386/i386/process_machdep.c @@ -1,7 +1,8 @@ -/* $NetBSD: process_machdep.c,v 1.20 1996/01/13 06:14:44 mycroft Exp $ */ +/* $OpenBSD: process_machdep.c,v 1.3 1996/04/17 05:18:56 mickey Exp $ */ +/* $NetBSD: process_machdep.c,v 1.21 1996/04/11 07:47:48 mycroft Exp $ */ /* - * Copyright (c) 1995 Charles M. Hannum. All rights reserved. + * Copyright (c) 1995, 1996 Charles M. Hannum. All rights reserved. * Copyright (c) 1993 The Regents of the University of California. * Copyright (c) 1993 Jan-Simon Pendry * All rights reserved. @@ -110,9 +111,7 @@ process_read_regs(p, regs) regs->r_fs = tf->tf_vm86_fs; regs->r_es = tf->tf_vm86_es; regs->r_ds = tf->tf_vm86_ds; - regs->r_eflags = tf->tf_eflags; - SETFLAGS(regs->r_eflags, VM86_EFLAGS(p), - VM86_FLAGMASK(p)|PSL_VIF); + regs->r_eflags = get_vflags(p); } else #endif { @@ -166,22 +165,13 @@ process_write_regs(p, regs) struct trapframe *tf = process_frame(p); struct pcb *pcb = &p->p_addr->u_pcb; - /* - * Check for security violations. - */ - if (((regs->r_eflags ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 || - !USERMODE(regs->r_cs, regs->r_eflags)) - return (EINVAL); - #ifdef VM86 if (tf->tf_eflags & PSL_VM) { tf->tf_vm86_gs = regs->r_gs; tf->tf_vm86_fs = regs->r_fs; tf->tf_vm86_es = regs->r_es; tf->tf_vm86_ds = regs->r_ds; - tf->tf_eflags = regs->r_eflags; - SETFLAGS(VM86_EFLAGS(p), regs->r_eflags, - VM86_FLAGMASK(p)|PSL_VIF); + set_vflags(p, regs->r_eflags); } else #endif { @@ -201,6 +191,13 @@ process_write_regs(p, regs) #define valid_sel(sel) (ISPL(sel) == SEL_UPL && verr(sel)) #define null_sel(sel) (!ISLDT(sel) && IDXSEL(sel) == 0) + /* + * Check for security violations. + */ + if (((regs->r_eflags ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 || + !USERMODE(regs->r_cs, regs->r_eflags)) + return (EINVAL); + if ((regs->r_gs != pcb->pcb_gs && \ !valid_sel(regs->r_gs) && !null_sel(regs->r_gs)) || (regs->r_fs != pcb->pcb_fs && \ diff --git a/sys/arch/i386/i386/svr4_machdep.c b/sys/arch/i386/i386/svr4_machdep.c index 2f747f736dd..6d5851c4e34 100644 --- a/sys/arch/i386/i386/svr4_machdep.c +++ b/sys/arch/i386/i386/svr4_machdep.c @@ -1,4 +1,5 @@ -/* $NetBSD: svr4_machdep.c,v 1.20 1996/01/04 22:22:04 jtc Exp $ */ +/* $OpenBSD: svr4_machdep.c,v 1.3 1996/04/17 05:18:57 mickey Exp $ */ +/* $NetBSD: svr4_machdep.c,v 1.21 1996/04/11 07:47:50 mycroft Exp $ */ /* * Copyright (c) 1994 Christos Zoulas @@ -52,6 +53,7 @@ #include #include #include +#include #include static void svr4_getsiginfo __P((union svr4_siginfo *, int, u_long, caddr_t)); @@ -79,6 +81,8 @@ svr4_getcontext(p, uc, mask, oonstack) r[SVR4_X86_FS] = tf->tf_vm86_fs; r[SVR4_X86_ES] = tf->tf_vm86_es; r[SVR4_X86_DS] = tf->tf_vm86_ds; + r[SVR4_X86_EFL] = get_vflags(p); + tf->tf_eflags &= ~PSL_VM; } else #endif { @@ -86,6 +90,7 @@ svr4_getcontext(p, uc, mask, oonstack) __asm("movl %%fs,%w0" : "=r" (r[SVR4_X86_FS])); r[SVR4_X86_ES] = tf->tf_es; r[SVR4_X86_DS] = tf->tf_ds; + r[SVR4_X86_EFL] = tf->tf_eflags; } r[SVR4_X86_EDI] = tf->tf_edi; r[SVR4_X86_ESI] = tf->tf_esi; @@ -99,7 +104,6 @@ svr4_getcontext(p, uc, mask, oonstack) r[SVR4_X86_ERR] = 0; r[SVR4_X86_EIP] = tf->tf_eip; r[SVR4_X86_CS] = tf->tf_cs; - r[SVR4_X86_EFL] = tf->tf_eflags; r[SVR4_X86_UESP] = 0; r[SVR4_X86_SS] = tf->tf_ss; @@ -154,24 +158,6 @@ svr4_setcontext(p, uc) tf = p->p_md.md_regs; - /* - * Check for security violations. - */ - if (((r[SVR4_X86_EFL] ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 || - !USERMODE(r[SVR4_X86_CS], r[SVR4_X86_EFL])) - return (EINVAL); - - /* - * restore signal stack - */ - svr4_to_bsd_sigaltstack(s, sf); - - /* - * restore signal mask - */ - svr4_to_bsd_sigset(&uc->uc_sigmask, &mask); - p->p_sigmask = mask & ~sigcantmask; - /* * Restore register context. */ @@ -181,12 +167,24 @@ svr4_setcontext(p, uc) tf->tf_vm86_fs = r[SVR4_X86_FS]; tf->tf_vm86_es = r[SVR4_X86_ES]; tf->tf_vm86_ds = r[SVR4_X86_DS]; + set_vflags(p, r[SVR4_X86_EFL]); } else #endif { + /* + * Check for security violations. If we're returning to + * protected mode, the CPU will validate the segment registers + * automatically and generate a trap on violations. We handle + * the trap, rather than doing all of the checking here. + */ + if (((r[SVR4_X86_EFL] ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 || + !USERMODE(r[SVR4_X86_CS], r[SVR4_X86_EFL])) + return (EINVAL); + /* %fs and %gs were restored by the trampoline. */ tf->tf_es = r[SVR4_X86_ES]; tf->tf_ds = r[SVR4_X86_DS]; + tf->tf_eflags = r[SVR4_X86_EFL]; } tf->tf_edi = r[SVR4_X86_EDI]; tf->tf_esi = r[SVR4_X86_ESI]; @@ -197,10 +195,20 @@ svr4_setcontext(p, uc) tf->tf_eax = r[SVR4_X86_EAX]; tf->tf_eip = r[SVR4_X86_EIP]; tf->tf_cs = r[SVR4_X86_CS]; - tf->tf_eflags = r[SVR4_X86_EFL]; tf->tf_ss = r[SVR4_X86_SS]; tf->tf_esp = r[SVR4_X86_ESP]; + /* + * restore signal stack + */ + svr4_to_bsd_sigaltstack(s, sf); + + /* + * restore signal mask + */ + svr4_to_bsd_sigset(&uc->uc_sigmask, &mask); + p->p_sigmask = mask & ~sigcantmask; + return EJUSTRETURN; } diff --git a/sys/arch/i386/i386/swapgeneric.c b/sys/arch/i386/i386/swapgeneric.c index 7acbc0ee3b8..67bd58e2c2a 100644 --- a/sys/arch/i386/i386/swapgeneric.c +++ b/sys/arch/i386/i386/swapgeneric.c @@ -1,3 +1,4 @@ +/* $OpenBSD: swapgeneric.c,v 1.2 1996/04/17 05:18:58 mickey Exp $ */ /* $NetBSD: swapgeneric.c,v 1.9 1994/11/04 09:57:52 mycroft Exp $ */ /*- @@ -110,6 +111,7 @@ struct genericconf { extern int ffs_mountroot(); int (*mountroot)() = ffs_mountroot; +void setconf() { register struct genericconf *gc; @@ -172,6 +174,7 @@ doswap: rootdev = dumpdev; } +void gets(cp) char *cp; { diff --git a/sys/arch/i386/i386/vm86.c b/sys/arch/i386/i386/vm86.c index 5797db43e50..a6c558ceff0 100644 --- a/sys/arch/i386/i386/vm86.c +++ b/sys/arch/i386/i386/vm86.c @@ -1,32 +1,40 @@ -/* $NetBSD: vm86.c,v 1.3 1996/01/08 22:23:35 mycroft Exp $ */ - -/* - * Copyright (c) 1995 John T. Kohl - * 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. 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 +/* $OpenBSD: vm86.c,v 1.2 1996/04/17 05:18:59 mickey Exp $ */ +/* $NetBSD: vm86.c,v 1.8 1996/04/11 10:07:17 mycroft Exp $ */ + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John T. Kohl and Charles M. Hannum. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 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 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. - * */ #include @@ -64,13 +72,11 @@ #include #include -static void return_to_32bit __P((struct proc *, int)); static void fast_intxx __P((struct proc *, int)); -#define SETDIRECT ((~(PSL_USERSTATIC|PSL_NT)) & 0xffff) -#define GETDIRECT (SETDIRECT|0x02a) /* add in two MBZ bits */ - +#define CS(tf) (*(u_short *)&tf->tf_cs) #define IP(tf) (*(u_short *)&tf->tf_eip) +#define SS(tf) (*(u_short *)&tf->tf_ss) #define SP(tf) (*(u_short *)&tf->tf_esp) @@ -154,57 +160,6 @@ is_bitset(nr, bitmap) } -static __inline__ void -set_vif(p) - struct proc *p; -{ - - VM86_EFLAGS(p) |= PSL_VIF; - if (VM86_EFLAGS(p) & PSL_VIP) - return_to_32bit(p, VM86_STI); -} - -static __inline__ void -set_vflags(p, flags) - struct proc *p; - int flags; -{ - struct trapframe *tf = p->p_md.md_regs; - - SETFLAGS(VM86_EFLAGS(p), flags, VM86_FLAGMASK(p)); - SETFLAGS(tf->tf_eflags, flags, SETDIRECT); - if (flags & PSL_I) - set_vif(p); -} - -static __inline__ void -set_vflags_short(p, flags) - struct proc *p; - int flags; -{ - struct trapframe *tf = p->p_md.md_regs; - - SETFLAGS(VM86_EFLAGS(p), flags, VM86_FLAGMASK(p) & 0xffff); - SETFLAGS(tf->tf_eflags, flags, SETDIRECT); - if (flags & PSL_I) - set_vif(p); -} - -static __inline__ int -get_vflags(p) - struct proc *p; -{ - struct trapframe *tf = p->p_md.md_regs; - int flags = 0; - - SETFLAGS(flags, VM86_EFLAGS(p), VM86_FLAGMASK(p)); - SETFLAGS(flags, tf->tf_eflags, GETDIRECT); - if (VM86_EFLAGS(p) & PSL_VIF) - flags |= PSL_I; - return (flags); -} - - #define V86_AH(regs) (((u_char *)&((regs)->tf_eax))[1]) #define V86_AL(regs) (((u_char *)&((regs)->tf_eax))[0]) @@ -237,7 +192,7 @@ fast_intxx(p, intrno) * requested special handling, return to user space with indication * of which INT was requested. */ - cs = tf->tf_cs; + cs = CS(tf); if (cs == BIOSSEG || is_bitset(intrno, &u_vm86p->int_byuser[0])) goto vector; @@ -263,33 +218,33 @@ fast_intxx(p, intrno) * Otherwise, push flags, cs, eip, and jump to handler to * simulate direct INT call. */ - ss = tf->tf_ss << 4; + ss = SS(tf) << 4; sp = SP(tf); - putword(ss, sp, get_vflags(p)); - putword(ss, sp, tf->tf_cs); + putword(ss, sp, get_vflags_short(p)); + putword(ss, sp, CS(tf)); putword(ss, sp, IP(tf)); SP(tf) = sp; IP(tf) = ihand.ip; - tf->tf_cs = ihand.cs; + CS(tf) = ihand.cs; /* disable further "hardware" interrupts, turn off any tracing. */ - VM86_EFLAGS(p) &= ~PSL_VIF; - tf->tf_eflags &= ~PSL_VIF|PSL_T; + tf->tf_eflags &= ~PSL_T; + clr_vif(p); return; vector: - return_to_32bit(p, VM86_MAKEVAL(VM86_INTx, intrno)); + vm86_return(p, VM86_MAKEVAL(VM86_INTx, intrno)); return; bad: - return_to_32bit(p, VM86_UNKNOWN); + vm86_return(p, VM86_UNKNOWN); return; } -static void -return_to_32bit(p, retval) +void +vm86_return(p, retval) struct proc *p; int retval; { @@ -297,7 +252,7 @@ return_to_32bit(p, retval) /* * We can't set the virtual flags in our real trap frame, * since it's used to jump to the signal handler. Instead we - * let sendsig() pull in the VM86_EFLAGS bits. + * let sendsig() pull in the vm86_eflags bits. */ if (p->p_sigmask & sigmask(SIGURG)) { #ifdef DIAGNOSTIC @@ -339,22 +294,21 @@ vm86_gpfault(p, type) u_char tmpbyte; u_long cs, ip, ss, sp; - cs = tf->tf_cs << 4; + cs = CS(tf) << 4; ip = IP(tf); - ss = tf->tf_ss << 4; + ss = SS(tf) << 4; sp = SP(tf); /* * For most of these, we must set all the registers before calling - * macros/functions which might do a return_to_32bit. + * macros/functions which might do a vm86_return. */ tmpbyte = getbyte(cs, ip); IP(tf) = ip; switch (tmpbyte) { case CLI: /* simulate handling of IF */ - VM86_EFLAGS(p) &= ~PSL_VIF; - tf->tf_eflags &= ~PSL_VIF; + clr_vif(p); break; case STI: @@ -373,13 +327,13 @@ vm86_gpfault(p, type) break; case PUSHF: - putword(ss, sp, get_vflags(p)); + putword(ss, sp, get_vflags_short(p)); SP(tf) = sp; break; case IRET: IP(tf) = getword(ss, sp); - tf->tf_cs = getword(ss, sp); + CS(tf) = getword(ss, sp); case POPF: set_vflags_short(p, getword(ss, sp)); SP(tf) = sp; @@ -390,15 +344,15 @@ vm86_gpfault(p, type) IP(tf) = ip; switch (tmpbyte) { case PUSHF: - putdword(ss, sp, get_vflags(p)); + putdword(ss, sp, get_vflags(p) & ~PSL_VM); SP(tf) = sp; break; case IRET: IP(tf) = getdword(ss, sp); - tf->tf_cs = getdword(ss, sp); + CS(tf) = getdword(ss, sp); case POPF: - set_vflags(p, getdword(ss, sp)); + set_vflags(p, getdword(ss, sp) | PSL_VM); SP(tf) = sp; break; @@ -416,7 +370,7 @@ vm86_gpfault(p, type) return; bad: - return_to_32bit(p, VM86_UNKNOWN); + vm86_return(p, VM86_UNKNOWN); return; } @@ -427,13 +381,36 @@ i386_vm86(p, args, retval) register_t *retval; { struct trapframe *tf = p->p_md.md_regs; + struct pcb *pcb = &p->p_addr->u_pcb; struct vm86_kern vm86s; int err; if (err = copyin(args, &vm86s, sizeof(vm86s))) return err; - p->p_addr->u_pcb.vm86_userp = (void *)args; + pcb->vm86_userp = (void *)args; + + /* + * 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 = 0; + break; + case VCPU_386: + pcb->vm86_flagmask = PSL_NT|PSL_IOPL; + break; + case VCPU_486: + pcb->vm86_flagmask = PSL_AC|PSL_NT|PSL_IOPL; + break; + case VCPU_586: + default: + pcb->vm86_flagmask = PSL_ID|PSL_AC|PSL_NT|PSL_IOPL; + break; + } #define DOVREG(reg) tf->tf_vm86_##reg = (u_short) vm86s.regs.vmsc.sc_##reg #define DOREG(reg) tf->tf_##reg = (u_short) vm86s.regs.vmsc.sc_##reg @@ -457,34 +434,10 @@ i386_vm86(p, args, retval) #undef DOVREG #undef DOREG - SETFLAGS(VM86_EFLAGS(p), vm86s.regs.vmsc.sc_eflags, VM86_FLAGMASK(p)|PSL_VIF); - SETFLAGS(tf->tf_eflags, vm86s.regs.vmsc.sc_eflags, SETDIRECT); - tf->tf_eflags |= PSL_VM; - - /* - * 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: - VM86_FLAGMASK(p) = 0; - break; - case VCPU_386: - VM86_FLAGMASK(p) = PSL_NT|PSL_IOPL; - break; - case VCPU_486: - VM86_FLAGMASK(p) = PSL_AC|PSL_NT|PSL_IOPL; - break; - case VCPU_586: - default: - VM86_FLAGMASK(p) = PSL_ID|PSL_AC|PSL_NT|PSL_IOPL; - break; - } - /* Going into vm86 mode jumps off the signal stack. */ - p->p_sigacts->ps_sigstk.ss_flags &= ~SA_ONSTACK; + p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK; + + set_vflags(p, vm86s.regs.vmsc.sc_eflags | PSL_VM); return (EJUSTRETURN); } diff --git a/sys/arch/i386/i386/vm_machdep.c b/sys/arch/i386/i386/vm_machdep.c index b4aafa74ec1..f333c02f46c 100644 --- a/sys/arch/i386/i386/vm_machdep.c +++ b/sys/arch/i386/i386/vm_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vm_machdep.c,v 1.7 1996/03/19 21:09:24 mickey Exp $ */ +/* $OpenBSD: vm_machdep.c,v 1.8 1996/04/17 05:19:00 mickey Exp $ */ /* $NetBSD: vm_machdep.c,v 1.58 1996/02/05 02:00:35 christos Exp $ */ /*- @@ -262,6 +262,7 @@ cpu_coredump(p, vp, cred, chdr) /* * Set a red zone in the kernel stack after the u. area. */ +void setredzone(pte, vaddr) u_short *pte; caddr_t vaddr; @@ -281,6 +282,7 @@ setredzone(pte, vaddr) * Both addresses are assumed to reside in the Sysmap, * and size must be a multiple of CLSIZE. */ +void pagemove(from, to, size) register caddr_t from, to; int size; diff --git a/sys/arch/i386/include/ansi.h b/sys/arch/i386/include/ansi.h index 67a7752a0cb..40efacc18e9 100644 --- a/sys/arch/i386/include/ansi.h +++ b/sys/arch/i386/include/ansi.h @@ -1,4 +1,5 @@ -/* $NetBSD: ansi.h,v 1.5 1994/10/27 04:15:54 cgd Exp $ */ +/* $OpenBSD: ansi.h,v 1.2 1996/04/17 05:19:01 mickey Exp $ */ +/* $NetBSD: ansi.h,v 1.6 1996/03/16 01:31:50 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -69,6 +70,7 @@ * defined for ctype.h. */ #define _BSD_WCHAR_T_ int /* wchar_t */ +#define _BSD_WINT_T_ int /* wint_t */ #define _BSD_RUNE_T_ int /* rune_t */ #endif /* _ANSI_H_ */ diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h index 6d6c439e6ac..00e3ed0de3c 100644 --- a/sys/arch/i386/include/cpu.h +++ b/sys/arch/i386/include/cpu.h @@ -121,6 +121,7 @@ int want_resched; /* resched() was called */ } \ } while (0) #endif +void delay __P((int)); /* * pull in #defines for kinds of processors diff --git a/sys/arch/i386/include/pio.h b/sys/arch/i386/include/pio.h index 6771ff87829..d3614747cc9 100644 --- a/sys/arch/i386/include/pio.h +++ b/sys/arch/i386/include/pio.h @@ -1,4 +1,5 @@ -/* $NetBSD: pio.h,v 1.12 1995/12/20 07:53:09 mycroft Exp $ */ +/* $OpenBSD: pio.h,v 1.3 1996/04/17 05:19:03 mickey Exp $ */ +/* $NetBSD: pio.h,v 1.13 1996/03/08 20:15:23 cgd Exp $ */ /* * Copyright (c) 1993, 1995 Charles M. Hannum. All rights reserved. @@ -29,6 +30,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef _I386_PIO_H_ +#define _I386_PIO_H_ + /* * Functions to provide access to i386 programmed I/O instructions. * @@ -205,3 +209,5 @@ outsl(int port, void *addr, int cnt) "d" (port), "S" (addr), "c" (cnt) : "%esi", "%ecx"); } + +#endif /* _I386_PIO_H_ */ diff --git a/sys/arch/i386/include/vm86.h b/sys/arch/i386/include/vm86.h index 1f21db3dbdc..a996017ceba 100644 --- a/sys/arch/i386/include/vm86.h +++ b/sys/arch/i386/include/vm86.h @@ -1,37 +1,45 @@ -/* $NetBSD: vm86.h,v 1.1 1996/01/08 13:51:45 mycroft Exp $ */ +/* $OpenBSD: vm86.h,v 1.2 1996/04/17 05:19:04 mickey Exp $ */ +/* $NetBSD: vm86.h,v 1.4 1996/04/11 10:07:25 mycroft Exp $ */ -/* - * Copyright (c) 1995 John T. Kohl - * 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. 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 +#define VM86_USE_VIF + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John T. Kohl and Charles M. Hannum. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 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 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. - * */ #define SETFLAGS(targ, new, newmask) (targ) = ((targ) & ~(newmask)) | ((new) & (newmask)) -#define VM86_EFLAGS(p) ((p)->p_addr->u_pcb.vm86_eflags) -#define VM86_FLAGMASK(p) ((p)->p_addr->u_pcb.vm86_flagmask) #define VM86_TYPE(x) ((x) & 0xff) #define VM86_ARG(x) (((x) & 0xff00) >> 8) @@ -41,6 +49,9 @@ #define VM86_SIGNAL 2 #define VM86_UNKNOWN 3 +#define VM86_SETDIRECT (~PSL_USERSTATIC) +#define VM86_GETDIRECT (VM86_SETDIRECT|PSL_MBO|PSL_MBZ) + struct vm86_regs { struct sigcontext vmsc; }; @@ -74,6 +85,96 @@ struct vm86_struct { #ifdef _KERNEL int i386_vm86 __P((struct proc *, char *, register_t *)); void vm86_gpfault __P((struct proc *, int)); +void vm86_return __P((struct proc *, int)); + +static __inline__ void +clr_vif(p) + struct proc *p; +{ + struct pcb *pcb = &p->p_addr->u_pcb; + +#ifndef VM86_USE_VIF + pcb->vm86_eflags &= ~PSL_I; +#else + pcb->vm86_eflags &= ~PSL_VIF; +#endif +} + +static __inline__ void +set_vif(p) + struct proc *p; +{ + struct pcb *pcb = &p->p_addr->u_pcb; + +#ifndef VM86_USE_VIF + pcb->vm86_eflags |= PSL_I; + if ((pcb->vm86_eflags & (PSL_I|PSL_VIP)) == (PSL_I|PSL_VIP)) +#else + pcb->vm86_eflags |= PSL_VIF; + if ((pcb->vm86_eflags & (PSL_VIF|PSL_VIP)) == (PSL_VIF|PSL_VIP)) +#endif + vm86_return(p, VM86_STI); +} + +static __inline__ void +set_vflags(p, flags) + struct proc *p; + int flags; +{ + struct trapframe *tf = p->p_md.md_regs; + struct pcb *pcb = &p->p_addr->u_pcb; + + SETFLAGS(pcb->vm86_eflags, flags, pcb->vm86_flagmask | ~VM86_GETDIRECT); + SETFLAGS(tf->tf_eflags, flags, VM86_SETDIRECT); +#ifndef VM86_USE_VIF + if ((pcb->vm86_eflags & (PSL_I|PSL_VIP)) == (PSL_I|PSL_VIP)) +#else + if ((pcb->vm86_eflags & (PSL_VIF|PSL_VIP)) == (PSL_VIF|PSL_VIP)) +#endif + vm86_return(p, VM86_STI); +} + +static __inline__ int +get_vflags(p) + struct proc *p; +{ + struct trapframe *tf = p->p_md.md_regs; + struct pcb *pcb = &p->p_addr->u_pcb; + int flags = 0; + + SETFLAGS(flags, pcb->vm86_eflags, pcb->vm86_flagmask | ~VM86_GETDIRECT); + SETFLAGS(flags, tf->tf_eflags, VM86_GETDIRECT); + return (flags); +} + +static __inline__ void +set_vflags_short(p, flags) + struct proc *p; + int flags; +{ + struct trapframe *tf = p->p_md.md_regs; + struct pcb *pcb = &p->p_addr->u_pcb; + + SETFLAGS(pcb->vm86_eflags, flags, (pcb->vm86_flagmask | ~VM86_GETDIRECT) & 0xffff); + SETFLAGS(tf->tf_eflags, flags, VM86_SETDIRECT & 0xffff); +#ifndef VM86_USE_VIF + if ((pcb->vm86_eflags & (PSL_I|PSL_VIP)) == (PSL_I|PSL_VIP)) + vm86_return(p, VM86_STI); +#endif +} + +static __inline__ int +get_vflags_short(p) + struct proc *p; +{ + struct trapframe *tf = p->p_md.md_regs; + struct pcb *pcb = &p->p_addr->u_pcb; + int flags = 0; + + SETFLAGS(flags, pcb->vm86_eflags, (pcb->vm86_flagmask | ~VM86_GETDIRECT) & 0xffff); + SETFLAGS(flags, tf->tf_eflags, VM86_GETDIRECT & 0xffff); + return (flags); +} #else int i386_vm86 __P((struct vm86_struct *vmcp)); #endif -- 2.20.1