From owner-svn-src-head@FreeBSD.ORG Wed Sep 23 20:13:37 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 096F7106566C; Wed, 23 Sep 2009 20:13:37 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EBCDE8FC1E; Wed, 23 Sep 2009 20:13:36 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n8NKDain073118; Wed, 23 Sep 2009 20:13:36 GMT (envelope-from jkim@svn.freebsd.org) Received: (from jkim@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n8NKDa7c073117; Wed, 23 Sep 2009 20:13:36 GMT (envelope-from jkim@svn.freebsd.org) Message-Id: <200909232013.n8NKDa7c073117@svn.freebsd.org> From: Jung-uk Kim Date: Wed, 23 Sep 2009 20:13:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r197442 - head/sys/dev/x86bios X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Sep 2009 20:13:37 -0000 Author: jkim Date: Wed Sep 23 20:13:36 2009 New Revision: 197442 URL: http://svn.freebsd.org/changeset/base/197442 Log: - Use spin lock instead of default mutex for safety. INT/IRET instructions save/clear/restore flags but emulated flags have no effect on the host. I believe BIOS writers never meant to run their code in emulated environment with interrupt enabled. :-) - Use memcpy(3) instead of copying individual members. I believe struct x86regs was intentionally copied from the first half of struct x86emu_regs for this very purpose. - Fix some style nits and consistencies. Reviewed by: delphij, paradox (ddkprog yahoo com) Modified: head/sys/dev/x86bios/x86bios.c Modified: head/sys/dev/x86bios/x86bios.c ============================================================================== --- head/sys/dev/x86bios/x86bios.c Wed Sep 23 17:48:16 2009 (r197441) +++ head/sys/dev/x86bios/x86bios.c Wed Sep 23 20:13:36 2009 (r197442) @@ -9,16 +9,12 @@ __FBSDID("$FreeBSD$"); #include "opt_x86bios.h" #include -#include #include -#include #include +#include #include #include -#include -#include -#include #include #include @@ -32,39 +28,43 @@ static u_char *pbiosStack = NULL; int busySegMap[5]; -static struct x86emu xbios86emu; +static struct x86emu x86bios_emu; static struct mtx x86bios_lock; static uint8_t -vm86_emu_inb(struct x86emu *emu, uint16_t port) +x86bios_emu_inb(struct x86emu *emu, uint16_t port) { + if (port == 0xb2) /* APM scratch register */ - return 0; + return (0); if (port >= 0x80 && port < 0x88) /* POST status register */ - return 0; - return inb(port); + return (0); + return (inb(port)); } static uint16_t -vm86_emu_inw(struct x86emu *emu, uint16_t port) +x86bios_emu_inw(struct x86emu *emu, uint16_t port) { + if (port >= 0x80 && port < 0x88) /* POST status register */ - return 0; - return inw(port); + return (0); + return (inw(port)); } static uint32_t -vm86_emu_inl(struct x86emu *emu, uint16_t port) +x86bios_emu_inl(struct x86emu *emu, uint16_t port) { + if (port >= 0x80 && port < 0x88) /* POST status register */ - return 0; - return inl(port); + return (0); + return (inl(port)); } static void -vm86_emu_outb(struct x86emu *emu, uint16_t port, uint8_t val) +x86bios_emu_outb(struct x86emu *emu, uint16_t port, uint8_t val) { + if (port == 0xb2) /* APM scratch register */ return; if (port >= 0x80 && port < 0x88) /* POST status register */ @@ -73,16 +73,18 @@ vm86_emu_outb(struct x86emu *emu, uint16 } static void -vm86_emu_outw(struct x86emu *emu, uint16_t port, uint16_t val) +x86bios_emu_outw(struct x86emu *emu, uint16_t port, uint16_t val) { + if (port >= 0x80 && port < 0x88) /* POST status register */ return; outw(port, val); } static void -vm86_emu_outl(struct x86emu *emu, uint16_t port, uint32_t val) +x86bios_emu_outl(struct x86emu *emu, uint16_t port, uint32_t val) { + if (port >= 0x80 && port < 0x88) /* POST status register */ return; outl(port, val); @@ -91,59 +93,23 @@ vm86_emu_outl(struct x86emu *emu, uint16 void x86biosCall(struct x86regs *regs, int intno) { + if (intno < 0 || intno > 255) return; - mtx_lock(&x86bios_lock); - critical_enter(); + mtx_lock_spin(&x86bios_lock); - xbios86emu.x86.R_EAX = regs->R_EAX; - xbios86emu.x86.R_EBX = regs->R_EBX; - xbios86emu.x86.R_ECX = regs->R_ECX; - xbios86emu.x86.R_EDX = regs->R_EDX; - - xbios86emu.x86.R_ESP = regs->R_ESP; - xbios86emu.x86.R_EBP = regs->R_EBP; - xbios86emu.x86.R_ESI = regs->R_ESI; - xbios86emu.x86.R_EDI = regs->R_EDI; - xbios86emu.x86.R_EIP = regs->R_EIP; - xbios86emu.x86.R_EFLG = regs->R_EFLG; - - xbios86emu.x86.R_CS = regs->R_CS; - xbios86emu.x86.R_DS = regs->R_DS; - xbios86emu.x86.R_SS = regs->R_SS; - xbios86emu.x86.R_ES = regs->R_ES; - xbios86emu.x86.R_FS = regs->R_FS; - xbios86emu.x86.R_GS = regs->R_GS; - - x86emu_exec_intr(&xbios86emu, intno); - - regs->R_EAX = xbios86emu.x86.R_EAX; - regs->R_EBX = xbios86emu.x86.R_EBX; - regs->R_ECX = xbios86emu.x86.R_ECX; - regs->R_EDX = xbios86emu.x86.R_EDX; - - regs->R_ESP = xbios86emu.x86.R_ESP; - regs->R_EBP = xbios86emu.x86.R_EBP; - regs->R_ESI = xbios86emu.x86.R_ESI; - regs->R_EDI = xbios86emu.x86.R_EDI; - regs->R_EIP = xbios86emu.x86.R_EIP; - regs->R_EFLG = xbios86emu.x86.R_EFLG; - - regs->R_CS = xbios86emu.x86.R_CS; - regs->R_DS = xbios86emu.x86.R_DS; - regs->R_SS = xbios86emu.x86.R_SS; - regs->R_ES = xbios86emu.x86.R_ES; - regs->R_FS = xbios86emu.x86.R_FS; - regs->R_GS = xbios86emu.x86.R_GS; + memcpy(&x86bios_emu.x86, regs, sizeof(*regs)); + x86emu_exec_intr(&x86bios_emu, intno); + memcpy(regs, &x86bios_emu.x86, sizeof(*regs)); - critical_exit(); - mtx_unlock(&x86bios_lock); + mtx_unlock_spin(&x86bios_lock); } void * x86biosOffs(uint32_t offs) { + return (pbiosMem + offs); } @@ -152,23 +118,23 @@ x86bios_init(void *arg __unused) { int offs; - mtx_init(&x86bios_lock, "x86bios lock", NULL, MTX_DEF); + mtx_init(&x86bios_lock, "x86bios lock", NULL, MTX_SPIN); /* Can pbiosMem be NULL here? */ pbiosMem = pmap_mapbios(0x0, MAPPED_MEMORY_SIZE); - memset(&xbios86emu, 0, sizeof(xbios86emu)); - x86emu_init_default(&xbios86emu); + memset(&x86bios_emu, 0, sizeof(x86bios_emu)); + x86emu_init_default(&x86bios_emu); - xbios86emu.emu_inb = vm86_emu_inb; - xbios86emu.emu_inw = vm86_emu_inw; - xbios86emu.emu_inl = vm86_emu_inl; - xbios86emu.emu_outb = vm86_emu_outb; - xbios86emu.emu_outw = vm86_emu_outw; - xbios86emu.emu_outl = vm86_emu_outl; + x86bios_emu.emu_inb = x86bios_emu_inb; + x86bios_emu.emu_inw = x86bios_emu_inw; + x86bios_emu.emu_inl = x86bios_emu_inl; + x86bios_emu.emu_outb = x86bios_emu_outb; + x86bios_emu.emu_outw = x86bios_emu_outw; + x86bios_emu.emu_outl = x86bios_emu_outl; - xbios86emu.mem_base = (char *)pbiosMem; - xbios86emu.mem_size = 1024 * 1024; + x86bios_emu.mem_base = (char *)pbiosMem; + x86bios_emu.mem_size = 1024 * 1024; memset(busySegMap, 0, sizeof(busySegMap)); @@ -178,6 +144,7 @@ x86bios_init(void *arg __unused) static void x86bios_uninit(void *arg __unused) { + x86biosFree(pbiosStack, 1); if (pbiosMem) @@ -215,4 +182,3 @@ static moduledata_t x86bios_mod = { DECLARE_MODULE(x86bios, x86bios_mod, SI_SUB_CPU, SI_ORDER_ANY); MODULE_VERSION(x86bios, 1); -