summaryrefslogtreecommitdiffstats
path: root/sys/compat/x86bios
diff options
context:
space:
mode:
authorjkim <jkim@FreeBSD.org>2009-10-19 20:58:10 +0000
committerjkim <jkim@FreeBSD.org>2009-10-19 20:58:10 +0000
commit99279734b833c18edb9cfc47db1c920327e97fde (patch)
treed4a62e4e5d88debc2e3a4761c8ceea077f9a2ac1 /sys/compat/x86bios
parent8f9031d9fe5f0fb11cd72dd010fbdac9560df819 (diff)
downloadFreeBSD-src-99279734b833c18edb9cfc47db1c920327e97fde.zip
FreeBSD-src-99279734b833c18edb9cfc47db1c920327e97fde.tar.gz
Rewrite x86bios and update its dependent drivers.
- Do not map entire real mode memory (1MB). Instead, we map IVT/BDA and ROM area separately. Most notably, ROM area is mapped as device memory (uncacheable) as it should be. User memory is dynamically allocated and free'ed with contigmalloc(9) and contigfree(9). Remove now redundant and potentially dangerous x86bios_alloc.c. If this emulator ever grows to support non-PC hardware, we may implement it with rman(9) later. - Move all host-specific initializations from x86emu_util.c to x86bios.c and remove now unnecessary x86emu_util.c. Currently, non-PC hardware is not supported. We may use bus_space(9) later when the KPI is fixed. - Replace all bzero() calls for emulated registers with more obviously named x86bios_init_regs(). This function also initializes DS and SS properly. - Add x86bios_get_intr(). This function checks if the interrupt vector is available for the platform. It is not necessary for PC-compatible hardware but it may be needed later. ;-) - Do not try turning off monitor if DPMS does not support the state. - Allocate stable memory for VESA OEM strings instead of just holding pointers to them. They may or may not be accessible always. Fix a memory leak of video mode table while I am here. - Add (experimental) BIOS POST call for vesa(4). This function calls VGA BIOS POST code from the current VGA option ROM. Some video controllers cannot save and restore the state properly even if it is claimed to be supported. Usually the symptom is blank display after resuming from suspend state. If the video mode does not match the previous mode after restoring, we try BIOS POST and force the known good initial state. Some magic was taken from NetBSD (and it was taken from vbetool, I believe.) - Add a loader tunable for vgapci(4) to give a hint to dpms(4) and vesa(4) to identify who owns the VESA BIOS. This is very useful for multi-display adapter setup. By default, the POST video controller is automatically probed and the tunable "hw.pci.default_vgapci_unit" is set to corresponding vgapci unit number. You may override it from loader but it is very unlikely to be necessary. Unfortunately only AGP/PCI/PCI-E controllers can be matched because ISA controller does not have necessary device IDs. - Fix a long standing bug in state save/restore function. The state buffer pointer should be ES:BX, not ES:DI according to VBE 3.0. If it ever worked, that's because BX was always zero. :-) - Clean up register initializations more clearer per VBE 3.0. - Fix a lot of style issues with vesa(4).
Diffstat (limited to 'sys/compat/x86bios')
-rw-r--r--sys/compat/x86bios/x86bios.c379
-rw-r--r--sys/compat/x86bios/x86bios.h113
-rw-r--r--sys/compat/x86bios/x86bios_alloc.c81
3 files changed, 404 insertions, 169 deletions
diff --git a/sys/compat/x86bios/x86bios.c b/sys/compat/x86bios/x86bios.c
index 1d1c48a..74c32a7 100644
--- a/sys/compat/x86bios/x86bios.c
+++ b/sys/compat/x86bios/x86bios.c
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2009 Alex Keda <admin@lissyara.su>
+ * Copyright (c) 2009 Jung-uk Kim <jkim@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -22,7 +23,6 @@
* 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>
@@ -31,29 +31,153 @@ __FBSDID("$FreeBSD$");
#include "opt_x86bios.h"
#include <sys/param.h>
+#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/lock.h>
+#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/mutex.h>
+#include <sys/proc.h>
+
+#include <contrib/x86emu/x86emu.h>
+#include <contrib/x86emu/x86emu_regs.h>
+#include <compat/x86bios/x86bios.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+#include <machine/cpufunc.h>
#include <vm/vm.h>
#include <vm/pmap.h>
-#include <machine/cpufunc.h>
+#define X86BIOS_PAGE_SIZE 0x00001000 /* 4K */
-#include <contrib/x86emu/x86emu.h>
-#include <contrib/x86emu/x86emu_regs.h>
-#include <compat/x86bios/x86bios.h>
+#define X86BIOS_IVT_SIZE 0x00000500 /* 1K + 256 (BDA) */
+#define X86BIOS_SEG_SIZE 0x00010000 /* 64K */
+#define X86BIOS_MEM_SIZE 0x00100000 /* 1M */
+
+#define X86BIOS_IVT_BASE 0x00000000
+#define X86BIOS_RAM_BASE 0x00001000
+#define X86BIOS_ROM_BASE 0x000a0000 /* XXX EBDA? */
+
+#define X86BIOS_ROM_SIZE (X86BIOS_MEM_SIZE - X86BIOS_ROM_BASE)
-u_char *pbiosMem = NULL;
-static u_char *pbiosStack = NULL;
+#define X86BIOS_PAGES (X86BIOS_MEM_SIZE / X86BIOS_PAGE_SIZE)
-int busySegMap[5];
+#define X86BIOS_R_DS _pad1
+#define X86BIOS_R_SS _pad2
static struct x86emu x86bios_emu;
static struct mtx x86bios_lock;
+static void *x86bios_ivt;
+static void *x86bios_rom;
+static void *x86bios_seg;
+
+static vm_offset_t *x86bios_map;
+
+static vm_paddr_t x86bios_seg_phys;
+
+static void *
+x86bios_get_pages(uint32_t offset, size_t size)
+{
+ int i;
+
+ if (offset + size > X86BIOS_MEM_SIZE)
+ return (NULL);
+
+ i = offset / X86BIOS_PAGE_SIZE;
+ if (x86bios_map[i] != 0)
+ return ((void *)(x86bios_map[i] + offset -
+ i * X86BIOS_PAGE_SIZE));
+
+ return (NULL);
+}
+
+static void
+x86bios_set_pages(vm_offset_t va, vm_paddr_t pa, size_t size)
+{
+ int i, j;
+
+ for (i = pa / X86BIOS_PAGE_SIZE, j = 0;
+ j < howmany(size, X86BIOS_PAGE_SIZE); i++, j++)
+ x86bios_map[i] = va + j * X86BIOS_PAGE_SIZE;
+}
+
+static uint8_t
+x86bios_emu_rdb(struct x86emu *emu, uint32_t addr)
+{
+ uint8_t *va;
+
+ va = x86bios_get_pages(addr, sizeof(*va));
+ if (va == NULL)
+ x86emu_halt_sys(emu);
+
+ return (*va);
+}
+
+static uint16_t
+x86bios_emu_rdw(struct x86emu *emu, uint32_t addr)
+{
+ uint16_t *va;
+
+ va = x86bios_get_pages(addr, sizeof(*va));
+ if (va == NULL)
+ x86emu_halt_sys(emu);
+
+ return (le16toh(*va));
+}
+
+static uint32_t
+x86bios_emu_rdl(struct x86emu *emu, uint32_t addr)
+{
+ uint32_t *va;
+
+ va = x86bios_get_pages(addr, sizeof(*va));
+ if (va == NULL)
+ x86emu_halt_sys(emu);
+
+ return (le32toh(*va));
+}
+
+static void
+x86bios_emu_wrb(struct x86emu *emu, uint32_t addr, uint8_t val)
+{
+ uint8_t *va;
+
+ va = x86bios_get_pages(addr, sizeof(*va));
+ if (va == NULL)
+ x86emu_halt_sys(emu);
+
+ *va = val;
+}
+
+static void
+x86bios_emu_wrw(struct x86emu *emu, uint32_t addr, uint16_t val)
+{
+ uint16_t *va;
+
+ va = x86bios_get_pages(addr, sizeof(*va));
+ if (va == NULL)
+ x86emu_halt_sys(emu);
+
+ *va = htole16(val);
+}
+
+static void
+x86bios_emu_wrl(struct x86emu *emu, uint32_t addr, uint32_t val)
+{
+ uint32_t *va;
+
+ va = x86bios_get_pages(addr, sizeof(*va));
+ if (va == NULL)
+ x86emu_halt_sys(emu);
+
+ *va = htole32(val);
+}
+
static uint8_t
x86bios_emu_inb(struct x86emu *emu, uint16_t port)
{
@@ -62,6 +186,7 @@ x86bios_emu_inb(struct x86emu *emu, uint16_t port)
return (0);
if (port >= 0x80 && port < 0x88) /* POST status register */
return (0);
+
return (inb(port));
}
@@ -71,6 +196,7 @@ x86bios_emu_inw(struct x86emu *emu, uint16_t port)
if (port >= 0x80 && port < 0x88) /* POST status register */
return (0);
+
return (inw(port));
}
@@ -80,6 +206,7 @@ x86bios_emu_inl(struct x86emu *emu, uint16_t port)
if (port >= 0x80 && port < 0x88) /* POST status register */
return (0);
+
return (inl(port));
}
@@ -91,6 +218,7 @@ x86bios_emu_outb(struct x86emu *emu, uint16_t port, uint8_t val)
return;
if (port >= 0x80 && port < 0x88) /* POST status register */
return;
+
outb(port, val);
}
@@ -100,6 +228,7 @@ x86bios_emu_outw(struct x86emu *emu, uint16_t port, uint16_t val)
if (port >= 0x80 && port < 0x88) /* POST status register */
return;
+
outw(port, val);
}
@@ -109,9 +238,109 @@ x86bios_emu_outl(struct x86emu *emu, uint16_t port, uint32_t val)
if (port >= 0x80 && port < 0x88) /* POST status register */
return;
+
outl(port, val);
}
+static void
+x86bios_emu_get_intr(struct x86emu *emu, int intno)
+{
+ uint16_t *sp;
+ uint32_t iv;
+
+ emu->x86.R_SP -= 6;
+
+ sp = (uint16_t *)((vm_offset_t)x86bios_seg + emu->x86.R_SP);
+ sp[0] = htole16(emu->x86.R_IP);
+ sp[1] = htole16(emu->x86.R_CS);
+ sp[2] = htole16(emu->x86.R_FLG);
+
+ iv = x86bios_get_intr(intno);
+ emu->x86.R_IP = iv & 0x000f;
+ emu->x86.R_CS = (iv >> 12) & 0xffff;
+ emu->x86.R_FLG &= ~(F_IF | F_TF);
+}
+
+void *
+x86bios_alloc(uint32_t *offset, size_t size)
+{
+ void *vaddr;
+
+ if (offset == NULL || size == 0)
+ return (NULL);
+
+ vaddr = contigmalloc(size, M_DEVBUF, M_NOWAIT, X86BIOS_RAM_BASE,
+ X86BIOS_ROM_BASE, X86BIOS_PAGE_SIZE, 0);
+ if (vaddr != NULL) {
+ *offset = vtophys(vaddr);
+ x86bios_set_pages((vm_offset_t)vaddr, *offset, size);
+ }
+
+ return (vaddr);
+}
+
+void
+x86bios_free(void *addr, size_t size)
+{
+ vm_paddr_t paddr;
+
+ if (addr == NULL || size == 0)
+ return;
+
+ paddr = vtophys(addr);
+ if (paddr < X86BIOS_RAM_BASE || paddr >= X86BIOS_ROM_BASE ||
+ paddr % X86BIOS_PAGE_SIZE != 0)
+ return;
+
+ bzero(x86bios_map + paddr / X86BIOS_PAGE_SIZE,
+ sizeof(*x86bios_map) * howmany(size, X86BIOS_PAGE_SIZE));
+ contigfree(addr, size, M_DEVBUF);
+}
+
+void
+x86bios_init_regs(struct x86regs *regs)
+{
+
+ bzero(regs, sizeof(*regs));
+ regs->X86BIOS_R_DS = regs->X86BIOS_R_SS = x86bios_seg_phys >> 4;
+}
+
+void
+x86bios_call(struct x86regs *regs, uint16_t seg, uint16_t off)
+{
+
+ if (x86bios_map == NULL)
+ return;
+
+ if (bootverbose)
+ printf("Calling 0x%05x (ax=0x%04x bx=0x%04x "
+ "cx=0x%04x dx=0x%04x es=0x%04x di=0x%04x)\n",
+ (seg << 4) + off, regs->R_AX, regs->R_BX, regs->R_CX,
+ regs->R_DX, regs->R_ES, regs->R_DI);
+
+ mtx_lock_spin(&x86bios_lock);
+ memcpy(&x86bios_emu.x86, regs, sizeof(*regs));
+ x86emu_exec_call(&x86bios_emu, seg, off);
+ memcpy(regs, &x86bios_emu.x86, sizeof(*regs));
+ mtx_unlock_spin(&x86bios_lock);
+
+ if (bootverbose)
+ printf("Exiting 0x%05x (ax=0x%04x bx=0x%04x "
+ "cx=0x%04x dx=0x%04x es=0x%04x di=0x%04x)\n",
+ (seg << 4) + off, regs->R_AX, regs->R_BX, regs->R_CX,
+ regs->R_DX, regs->R_ES, regs->R_DI);
+}
+
+uint32_t
+x86bios_get_intr(int intno)
+{
+ uint32_t *iv;
+
+ iv = (uint32_t *)((vm_offset_t)x86bios_ivt + intno * 4);
+
+ return (le32toh(*iv));
+}
+
void
x86bios_intr(struct x86regs *regs, int intno)
{
@@ -119,6 +348,9 @@ x86bios_intr(struct x86regs *regs, int intno)
if (intno < 0 || intno > 255)
return;
+ if (x86bios_map == NULL)
+ return;
+
if (bootverbose)
printf("Calling int 0x%x (ax=0x%04x bx=0x%04x "
"cx=0x%04x dx=0x%04x es=0x%04x di=0x%04x)\n",
@@ -126,11 +358,9 @@ x86bios_intr(struct x86regs *regs, int intno)
regs->R_DX, regs->R_ES, regs->R_DI);
mtx_lock_spin(&x86bios_lock);
-
memcpy(&x86bios_emu.x86, regs, sizeof(*regs));
x86emu_exec_intr(&x86bios_emu, intno);
memcpy(regs, &x86bios_emu.x86, sizeof(*regs));
-
mtx_unlock_spin(&x86bios_lock);
if (bootverbose)
@@ -141,24 +371,112 @@ x86bios_intr(struct x86regs *regs, int intno)
}
void *
-x86bios_offset(uint32_t offs)
+x86bios_offset(uint32_t offset)
+{
+
+ return (x86bios_get_pages(offset, 1));
+}
+
+void *
+x86bios_get_orm(uint32_t offset)
+{
+ uint8_t *p;
+
+ /* Does the shadow ROM contain BIOS POST code for x86? */
+ p = x86bios_offset(offset);
+ if (p == NULL || p[0] != 0x55 || p[1] != 0xaa || p[3] != 0xe9)
+ return (NULL);
+
+ return (p);
+}
+
+int
+x86bios_match_device(uint32_t offset, device_t dev)
+{
+ uint8_t *p;
+ uint16_t device, vendor;
+ uint8_t class, progif, subclass;
+
+ /* Does the shadow ROM contain BIOS POST code for x86? */
+ p = x86bios_get_orm(offset);
+ if (p == NULL)
+ return (0);
+
+ /* Does it contain PCI data structure? */
+ p += le16toh(*(uint16_t *)(p + 0x18));
+ if (bcmp(p, "PCIR", 4) != 0 ||
+ le16toh(*(uint16_t *)(p + 0x0a)) < 0x18 || *(p + 0x14) != 0)
+ return (0);
+
+ /* Does it match the vendor, device, and classcode? */
+ vendor = le16toh(*(uint16_t *)(p + 0x04));
+ device = le16toh(*(uint16_t *)(p + 0x06));
+ progif = *(p + 0x0d);
+ subclass = *(p + 0x0e);
+ class = *(p + 0x0f);
+ if (vendor != pci_get_vendor(dev) || device != pci_get_device(dev) ||
+ class != pci_get_class(dev) || subclass != pci_get_subclass(dev) ||
+ progif != pci_get_progif(dev))
+ return (0);
+
+ return (1);
+}
+
+static __inline int
+x86bios_map_mem(void)
+{
+
+ x86bios_ivt = pmap_mapdev(X86BIOS_IVT_BASE, X86BIOS_IVT_SIZE);
+ if (x86bios_ivt == NULL)
+ return (1);
+ x86bios_rom = pmap_mapdev(X86BIOS_ROM_BASE, X86BIOS_ROM_SIZE);
+ if (x86bios_rom == NULL) {
+ pmap_unmapdev((vm_offset_t)x86bios_ivt, X86BIOS_IVT_SIZE);
+ return (1);
+ }
+ x86bios_seg = contigmalloc(X86BIOS_SEG_SIZE, M_DEVBUF, M_WAITOK,
+ X86BIOS_RAM_BASE, X86BIOS_ROM_BASE, X86BIOS_PAGE_SIZE, 0);
+ x86bios_seg_phys = vtophys(x86bios_seg);
+
+ return (0);
+}
+
+static __inline void
+x86bios_unmap_mem(void)
{
- return (pbiosMem + offs);
+ pmap_unmapdev((vm_offset_t)x86bios_ivt, X86BIOS_IVT_SIZE);
+ pmap_unmapdev((vm_offset_t)x86bios_rom, X86BIOS_ROM_SIZE);
+ contigfree(x86bios_seg, X86BIOS_SEG_SIZE, M_DEVBUF);
}
static void
x86bios_init(void *arg __unused)
{
- int offs;
+ int i;
mtx_init(&x86bios_lock, "x86bios lock", NULL, MTX_SPIN);
- /* Can pbiosMem be NULL here? */
- pbiosMem = pmap_mapbios(0x0, MAPPED_MEMORY_SIZE);
+ if (x86bios_map_mem() != 0)
+ return;
+
+ x86bios_map = malloc(sizeof(*x86bios_map) * X86BIOS_PAGES, M_DEVBUF,
+ M_WAITOK | M_ZERO);
+ x86bios_set_pages((vm_offset_t)x86bios_ivt, X86BIOS_IVT_BASE,
+ X86BIOS_IVT_SIZE);
+ x86bios_set_pages((vm_offset_t)x86bios_rom, X86BIOS_ROM_BASE,
+ X86BIOS_ROM_SIZE);
+ x86bios_set_pages((vm_offset_t)x86bios_seg, x86bios_seg_phys,
+ X86BIOS_SEG_SIZE);
- memset(&x86bios_emu, 0, sizeof(x86bios_emu));
- x86emu_init_default(&x86bios_emu);
+ bzero(&x86bios_emu, sizeof(x86bios_emu));
+
+ x86bios_emu.emu_rdb = x86bios_emu_rdb;
+ x86bios_emu.emu_rdw = x86bios_emu_rdw;
+ x86bios_emu.emu_rdl = x86bios_emu_rdl;
+ x86bios_emu.emu_wrb = x86bios_emu_wrb;
+ x86bios_emu.emu_wrw = x86bios_emu_wrw;
+ x86bios_emu.emu_wrl = x86bios_emu_wrl;
x86bios_emu.emu_inb = x86bios_emu_inb;
x86bios_emu.emu_inw = x86bios_emu_inw;
@@ -167,23 +485,24 @@ x86bios_init(void *arg __unused)
x86bios_emu.emu_outw = x86bios_emu_outw;
x86bios_emu.emu_outl = x86bios_emu_outl;
- x86bios_emu.mem_base = (char *)pbiosMem;
- x86bios_emu.mem_size = MAPPED_MEMORY_SIZE;
-
- memset(busySegMap, 0, sizeof(busySegMap));
-
- pbiosStack = x86bios_alloc(1, &offs);
+ for (i = 0; i < 256; i++)
+ x86bios_emu._x86emu_intrTab[i] = x86bios_emu_get_intr;
}
static void
x86bios_uninit(void *arg __unused)
{
+ vm_offset_t *map = x86bios_map;
- x86bios_free(pbiosStack, 1);
+ mtx_lock_spin(&x86bios_lock);
+ if (x86bios_map != NULL) {
+ free(x86bios_map, M_DEVBUF);
+ x86bios_map = NULL;
+ }
+ mtx_unlock_spin(&x86bios_lock);
- if (pbiosMem)
- pmap_unmapdev((vm_offset_t)pbiosMem,
- MAPPED_MEMORY_SIZE);
+ if (map != NULL)
+ x86bios_unmap_mem();
mtx_destroy(&x86bios_lock);
}
@@ -191,7 +510,6 @@ x86bios_uninit(void *arg __unused)
static int
x86bios_modevent(module_t mod __unused, int type, void *data __unused)
{
- int err = 0;
switch (type) {
case MOD_LOAD:
@@ -201,11 +519,10 @@ x86bios_modevent(module_t mod __unused, int type, void *data __unused)
x86bios_uninit(NULL);
break;
default:
- err = ENOTSUP;
- break;
+ return (ENOTSUP);
}
- return (err);
+ return (0);
}
static moduledata_t x86bios_mod = {
diff --git a/sys/compat/x86bios/x86bios.h b/sys/compat/x86bios/x86bios.h
index 8d46d5b..4ed15e0 100644
--- a/sys/compat/x86bios/x86bios.h
+++ b/sys/compat/x86bios/x86bios.h
@@ -23,49 +23,51 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
+ * $FreeBSD$
*/
/*
* x86 registers were borrowed from x86emu.h x86emu_regs.h
* for compatability.
- *
- * $FreeBSD$
*/
#ifndef _X86BIOS_H_
-#define _X86BIOS_H_
+#define _X86BIOS_H_
-#include <sys/types.h>
#include <sys/endian.h>
#include <sys/systm.h>
+#include <sys/types.h>
#ifdef __BIG_ENDIAN__
struct x86_register32 {
- uint32_t e_reg;
+ uint32_t e_reg;
};
struct x86_register16 {
- uint16_t filler0;
- uint16_t x_reg;
+ uint16_t filler0;
+ uint16_t x_reg;
};
struct x86_register8 {
- uint8_t filler0, filler1;
- uint8_t h_reg, l_reg;
+ uint8_t filler0;
+ uint8_t filler1;
+ uint8_t h_reg;
+ uint8_t l_reg;
};
#else /* !__BIG_ENDIAN__ */
struct x86_register32 {
- uint32_t e_reg;
+ uint32_t e_reg;
};
struct x86_register16 {
- uint16_t x_reg;
+ uint16_t x_reg;
};
struct x86_register8 {
- uint8_t l_reg, h_reg;
+ uint8_t l_reg;
+ uint8_t h_reg;
};
#endif /* __BIG_ENDIAN__ */
@@ -77,19 +79,19 @@ union x86_register {
};
struct x86regs {
- uint16_t padding; /* CS is unused. */
- uint16_t register_ds;
+ uint16_t _pad0; /* CS */
+ uint16_t _pad1; /* DS */
uint16_t register_es;
uint16_t register_fs;
uint16_t register_gs;
- uint16_t register_ss;
+ uint16_t _pad2; /* SS */
uint32_t register_flags;
union x86_register register_a;
union x86_register register_b;
union x86_register register_c;
union x86_register register_d;
- union x86_register register_sp;
+ union x86_register _pad3; /* SP */
union x86_register register_bp;
union x86_register register_si;
union x86_register register_di;
@@ -98,60 +100,57 @@ struct x86regs {
typedef struct x86regs x86regs_t;
/* 8 bit registers */
-#define R_AH register_a.I8_reg.h_reg
-#define R_AL register_a.I8_reg.l_reg
-#define R_BH register_b.I8_reg.h_reg
-#define R_BL register_b.I8_reg.l_reg
-#define R_CH register_c.I8_reg.h_reg
-#define R_CL register_c.I8_reg.l_reg
-#define R_DH register_d.I8_reg.h_reg
-#define R_DL register_d.I8_reg.l_reg
+#define R_AH register_a.I8_reg.h_reg
+#define R_AL register_a.I8_reg.l_reg
+#define R_BH register_b.I8_reg.h_reg
+#define R_BL register_b.I8_reg.l_reg
+#define R_CH register_c.I8_reg.h_reg
+#define R_CL register_c.I8_reg.l_reg
+#define R_DH register_d.I8_reg.h_reg
+#define R_DL register_d.I8_reg.l_reg
/* 16 bit registers */
-#define R_AX register_a.I16_reg.x_reg
-#define R_BX register_b.I16_reg.x_reg
-#define R_CX register_c.I16_reg.x_reg
-#define R_DX register_d.I16_reg.x_reg
+#define R_AX register_a.I16_reg.x_reg
+#define R_BX register_b.I16_reg.x_reg
+#define R_CX register_c.I16_reg.x_reg
+#define R_DX register_d.I16_reg.x_reg
/* 32 bit extended registers */
-#define R_EAX register_a.I32_reg.e_reg
-#define R_EBX register_b.I32_reg.e_reg
-#define R_ECX register_c.I32_reg.e_reg
-#define R_EDX register_d.I32_reg.e_reg
+#define R_EAX register_a.I32_reg.e_reg
+#define R_EBX register_b.I32_reg.e_reg
+#define R_ECX register_c.I32_reg.e_reg
+#define R_EDX register_d.I32_reg.e_reg
/* special registers */
-#define R_SP register_sp.I16_reg.x_reg
-#define R_BP register_bp.I16_reg.x_reg
-#define R_SI register_si.I16_reg.x_reg
-#define R_DI register_di.I16_reg.x_reg
-#define R_FLG register_flags
+#define R_BP register_bp.I16_reg.x_reg
+#define R_SI register_si.I16_reg.x_reg
+#define R_DI register_di.I16_reg.x_reg
+#define R_FLG register_flags
/* special registers */
-#define R_ESP register_sp.I32_reg.e_reg
-#define R_EBP register_bp.I32_reg.e_reg
-#define R_ESI register_si.I32_reg.e_reg
-#define R_EDI register_di.I32_reg.e_reg
-#define R_EFLG register_flags
+#define R_EBP register_bp.I32_reg.e_reg
+#define R_ESI register_si.I32_reg.e_reg
+#define R_EDI register_di.I32_reg.e_reg
+#define R_EFLG register_flags
/* segment registers */
-#define R_DS register_ds
-#define R_SS register_ss
-#define R_ES register_es
-#define R_FS register_fs
-#define R_GS register_gs
-
-#define SEG_ADDR(x) (((x) >> 4) & 0x00F000)
-#define SEG_OFF(x) ((x) & 0x0FFFF)
-#define FARP(x) ((le32toh(x) & 0xffff) + ((le32toh(x) >> 12) & 0xffff00))
+#define R_ES register_es
+#define R_FS register_fs
+#define R_GS register_gs
-#define MAPPED_MEMORY_SIZE (1024 * 1024)
-#define PAGE_RESERV (4096 * 5)
+#define X86BIOS_PHYSTOSEG(x) (((x) >> 4) & 0xffff)
+#define X86BIOS_PHYSTOOFF(x) ((x) & 0x000f)
__BEGIN_DECLS
-void *x86bios_alloc(int count, int *segs);
-void x86bios_free(void *pbuf, int count);
-void x86bios_intr(struct x86regs *regs, int intno);
-void *x86bios_offset(uint32_t offs);
+void *x86bios_alloc(uint32_t *offset, size_t size);
+void x86bios_call(struct x86regs *regs, uint16_t seg, uint16_t off);
+void x86bios_free(void *addr, size_t size);
+uint32_t x86bios_get_intr(int intno);
+void *x86bios_get_orm(uint32_t offset);
+void x86bios_init_regs(struct x86regs *regs);
+void x86bios_intr(struct x86regs *regs, int intno);
+int x86bios_match_device(uint32_t offset, device_t dev);
+void *x86bios_offset(uint32_t offset);
__END_DECLS
#endif /* !_X86BIOS_H_ */
diff --git a/sys/compat/x86bios/x86bios_alloc.c b/sys/compat/x86bios/x86bios_alloc.c
deleted file mode 100644
index 0a364e7..0000000
--- a/sys/compat/x86bios/x86bios_alloc.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/*-
- * Copyright (C) 1999 Egbert Eich
- *
- * Permission to use, copy, modify, distribute, and sell this software and
- * its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and that
- * both that copyright notice and this permission notice appear in
- * supporting documentation, and that the name of the authors not be used
- * in advertising or publicity pertaining to distribution of the software
- * without specific, written prior permission. The authors makes no
- * representations about the suitability of this software for any purpose.
- * It is provided "as is" without express or implied warranty.
- *
- * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
- * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
- * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * xserver/hw/xfree86/int10/generic.c
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-
-#include <compat/x86bios/x86bios.h>
-
-extern u_char *pbiosMem;
-extern int busySegMap[5];
-
-void *
-x86bios_alloc(int count, int *segs)
-{
- int i;
- int j;
-
- /* find the free segblock of page */
- for (i = 0; i < (PAGE_RESERV - count); i++)
- {
- if (busySegMap[i] == 0)
- {
- /* find the capacity of segblock */
- for (j = i; j < (i + count); j++)
- {
- if (busySegMap[j] == 1)
- break;
- }
-
- if (j == (i + count))
- break;
- i += count;
- }
- }
-
- if (i == (PAGE_RESERV - count))
- return NULL;
-
- /* make the segblock is used */
- for (j = i; j < (i + count); j++)
- busySegMap[i] = 1;
-
- *segs = i * 4096;
-
- return (pbiosMem + *segs);
-}
-
-void
-x86bios_free(void *pbuf, int count)
-{
- int i;
- int busySeg;
-
- busySeg = ((u_char *)pbuf - pbiosMem) / 4096;
-
- for (i = busySeg; i < (busySeg + count); i++)
- busySegMap[i] = 0;
-}
OpenPOWER on IntegriCloud