Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Sep 2009 08:17:57 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r197383 - in head/sys: conf contrib/x86emu dev/dpms dev/fb dev/x86bios modules modules/x86bios modules/x86emu
Message-ID:  <200909210817.n8L8HvP3080703@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Mon Sep 21 08:17:57 2009
New Revision: 197383
URL: http://svn.freebsd.org/changeset/base/197383

Log:
  Collapase interrupt supporting functions to a new module, and switch from
  x86emu to this new module.
  
  This changeset also brings a fix for bugs introduced with the initial
  x86emu commit, which prevents the user from using some display mode or
  cause instant reboots during mode switch.
  
  Submitted by:	paradox <ddkprog yahoo com>

Added:
  head/sys/dev/x86bios/
  head/sys/dev/x86bios/x86bios.c   (contents, props changed)
  head/sys/dev/x86bios/x86bios.h   (contents, props changed)
  head/sys/dev/x86bios/x86bios_alloc.c   (contents, props changed)
  head/sys/modules/x86bios/
  head/sys/modules/x86bios/Makefile   (contents, props changed)
Deleted:
  head/sys/modules/x86emu/Makefile
Modified:
  head/sys/conf/NOTES
  head/sys/conf/files
  head/sys/conf/options
  head/sys/contrib/x86emu/x86emu.c
  head/sys/dev/dpms/dpms.c
  head/sys/dev/fb/vesa.c
  head/sys/modules/Makefile

Modified: head/sys/conf/NOTES
==============================================================================
--- head/sys/conf/NOTES	Mon Sep 21 07:50:57 2009	(r197382)
+++ head/sys/conf/NOTES	Mon Sep 21 08:17:57 2009	(r197383)
@@ -2758,4 +2758,4 @@ options 	BROOKTREE_ALLOC_PAGES=(217*4+1)
 options 	MAXFILES=999
 
 # x86 real mode emulator
-options		X86EMU
+options		X86BIOS

Modified: head/sys/conf/files
==============================================================================
--- head/sys/conf/files	Mon Sep 21 07:50:57 2009	(r197382)
+++ head/sys/conf/files	Mon Sep 21 08:17:57 2009	(r197383)
@@ -2828,6 +2828,8 @@ dev/xen/netfront/netfront.c	optional xen
 dev/xen/xenpci/xenpci.c		optional xenpci
 dev/xen/xenpci/evtchn.c         optional xenpci
 dev/xen/xenpci/machine_reboot.c optional xenpci
-contrib/x86emu/x86emu.c		optional x86emu | dpms | vesa
-contrib/x86emu/x86emu_util.c	optional x86emu | dpms | vesa
+dev/x86bios/x86bios.c		optional x86bios | dpms | vesa
+dev/x86bios/x86bios_alloc.c	optional x86bios | dpms | vesa
+contrib/x86emu/x86emu.c		optional x86bios | dpms | vesa
+contrib/x86emu/x86emu_util.c	optional x86bios | dpms | vesa
 

Modified: head/sys/conf/options
==============================================================================
--- head/sys/conf/options	Mon Sep 21 07:50:57 2009	(r197382)
+++ head/sys/conf/options	Mon Sep 21 08:17:57 2009	(r197383)
@@ -838,4 +838,4 @@ SND_FEEDER_RATE_HP	opt_snd.h
 SND_PCM_64		opt_snd.h
 SND_OLDSTEREO		opt_snd.h
 
-X86EMU
+X86BIOS

Modified: head/sys/contrib/x86emu/x86emu.c
==============================================================================
--- head/sys/contrib/x86emu/x86emu.c	Mon Sep 21 07:50:57 2009	(r197382)
+++ head/sys/contrib/x86emu/x86emu.c	Mon Sep 21 08:17:57 2009	(r197383)
@@ -33,10 +33,6 @@
  *
  */
 
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-
 #include <contrib/x86emu/x86emu.h>
 #include <contrib/x86emu/x86emu_regs.h>
 
@@ -8335,32 +8331,3 @@ pop_long(struct x86emu *emu)
 	emu->x86.R_SP += 4;
 	return res;
 }
-
-static int
-x86emu_modevent(module_t mod __unused, int type, void *data __unused)
-{
-	int err = 0;
-
-	switch (type) {
-	case MOD_LOAD:
-		break;
-
-	case MOD_UNLOAD:
-		break;
-
-	default:
-		err = ENOTSUP;
-		break;
-
-	}
-	return (err);
-}
-
-static moduledata_t x86emu_mod = {
-	"x86emu",
-	x86emu_modevent,
-	NULL,
-};
-
-DECLARE_MODULE(x86emu, x86emu_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
-MODULE_VERSION(x86emu, 1);

Modified: head/sys/dev/dpms/dpms.c
==============================================================================
--- head/sys/dev/dpms/dpms.c	Mon Sep 21 07:50:57 2009	(r197382)
+++ head/sys/dev/dpms/dpms.c	Mon Sep 21 08:17:57 2009	(r197383)
@@ -67,11 +67,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/libkern.h>
 #include <sys/module.h>
 
-#include <vm/vm.h>
-#include <vm/pmap.h>
-
-#include <contrib/x86emu/x86emu.h>
-#include <contrib/x86emu/x86emu_regs.h>
+#include <dev/x86bios/x86bios.h>
 
 /*
  * VESA DPMS States 
@@ -94,9 +90,6 @@ struct dpms_softc {
 	int	dpms_initial_state;
 };
 
-static struct x86emu vesa_emu;
-static unsigned char *emumem = NULL;
-
 static int	dpms_attach(device_t);
 static int	dpms_detach(device_t);
 static int	dpms_get_supported_states(int *);
@@ -126,59 +119,7 @@ static driver_t dpms_driver = {
 static devclass_t dpms_devclass;
 
 DRIVER_MODULE(dpms, vgapci, dpms_driver, dpms_devclass, NULL, NULL);
-MODULE_DEPEND(dpms, x86emu, 1, 1, 1);
-
-static uint8_t
-vm86_emu_inb(struct x86emu *emu, uint16_t port)
-{
-	if (port == 0xb2) /* APM scratch register */
-		return 0;
-	if (port >= 0x80 && port < 0x88) /* POST status register */
-		return 0;
-	return inb(port);
-}
-
-static uint16_t
-vm86_emu_inw(struct x86emu *emu, uint16_t port)
-{
-	if (port >= 0x80 && port < 0x88) /* POST status register */
-		return 0;
-	return inw(port);
-}
-
-static uint32_t
-vm86_emu_inl(struct x86emu *emu, uint16_t port)
-{
-	if (port >= 0x80 && port < 0x88) /* POST status register */
-		return 0;
-	return inl(port);
-}
-
-static void
-vm86_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 */
-		return;
-	outb(port, val);
-}
-
-static void
-vm86_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)
-{
-	if (port >= 0x80 && port < 0x88) /* POST status register */
-		return;
-	outl(port, val);
-}
+MODULE_DEPEND(dpms, x86bios, 1, 1, 1);
 
 static void
 dpms_identify(driver_t *driver, device_t parent)
@@ -192,7 +133,6 @@ dpms_identify(driver_t *driver, device_t
 	 */
 	if (devclass_get_device(dpms_devclass, 0) == NULL)
 		device_add_child(parent, "dpms", 0);
-
 }
 
 static int
@@ -200,21 +140,6 @@ dpms_probe(device_t dev)
 {
 	int error, states;
 
-	emumem = pmap_mapbios(0x0, 0xc00000);
-
-	memset(&vesa_emu, 0, sizeof(vesa_emu));
-	x86emu_init_default(&vesa_emu);
-
-	vesa_emu.emu_inb = vm86_emu_inb;
-	vesa_emu.emu_inw = vm86_emu_inw;
-	vesa_emu.emu_inl = vm86_emu_inl;
-	vesa_emu.emu_outb = vm86_emu_outb;
-	vesa_emu.emu_outw = vm86_emu_outw;
-	vesa_emu.emu_outl = vm86_emu_outl;
-
-	vesa_emu.mem_base = (char *)emumem;
-	vesa_emu.mem_size = 1024 * 1024;
-
 	error = dpms_get_supported_states(&states);
 	if (error)
 		return (error);
@@ -240,8 +165,6 @@ dpms_attach(device_t dev)
 static int
 dpms_detach(device_t dev)
 {
-	if (emumem)
-		pmap_unmapdev((vm_offset_t)emumem, 0xc00000);
 
 	return (0);
 }
@@ -267,17 +190,19 @@ dpms_resume(device_t dev)
 static int
 dpms_call_bios(int subfunction, int *bh)
 {
-	vesa_emu.x86.R_AX = VBE_DPMS_FUNCTION;
-	vesa_emu.x86.R_BL = subfunction;
-	vesa_emu.x86.R_BH = *bh;
-	vesa_emu.x86.R_ES = 0;
-	vesa_emu.x86.R_DI = 0;
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86regs_t regs;
+
+	regs.R_AX = VBE_DPMS_FUNCTION;
+	regs.R_BL = subfunction;
+	regs.R_BH = *bh;
+	regs.R_ES = 0;
+	regs.R_DI = 0;
+	x86biosCall(&regs, 0x10);
 
-	if ((vesa_emu.x86.R_EAX & 0xffff) != 0x004f)
+	if ((regs.R_EAX & 0xffff) != 0x004f)
 		return (ENXIO);
 
-	*bh = vesa_emu.x86.R_BH;
+	*bh = regs.R_BH;
 
 	return (0);
 }

Modified: head/sys/dev/fb/vesa.c
==============================================================================
--- head/sys/dev/fb/vesa.c	Mon Sep 21 07:50:57 2009	(r197382)
+++ head/sys/dev/fb/vesa.c	Mon Sep 21 08:17:57 2009	(r197383)
@@ -45,16 +45,15 @@ __FBSDID("$FreeBSD$");
 #include <vm/vm_param.h>
 #include <vm/pmap.h>
 
+#include <machine/pc/bios.h>
 #include <dev/fb/vesa.h>
 
 #include <dev/fb/fbreg.h>
 #include <dev/fb/vgareg.h>
 
 #include <isa/isareg.h>
-#include <machine/cpufunc.h>
 
-#include <contrib/x86emu/x86emu.h>
-#include <contrib/x86emu/x86emu_regs.h>
+#include <dev/x86bios/x86bios.h>
 
 #define	VESA_VIA_CLE266		"VIA CLE266\r\n"
 
@@ -73,7 +72,7 @@ typedef struct adp_state adp_state_t;
 /* VESA video adapter */
 static video_adapter_t *vesa_adp = NULL;
 static int vesa_state_buf_size = 0;
-#define VESA_X86EMU_BUFSIZE	(3 * PAGE_SIZE)
+#define VESA_BIOS_BUFSIZE	(3 * PAGE_SIZE)
 
 /* VESA functions */
 #if 0
@@ -106,8 +105,6 @@ static vi_bitblt_t		vesa_bitblt;
 static vi_diag_t		vesa_diag;
 static int			vesa_bios_info(int level);
 
-static struct x86emu		vesa_emu;
-
 static video_switch_t vesavidsw = {
 	vesa_probe,
 	vesa_init,
@@ -206,77 +203,6 @@ static void vesa_unmap_buffer(vm_offset_
 static int vesa_get_origin(video_adapter_t *adp, off_t *offset);
 #endif
 
-#define SEG_ADDR(x)	(((x) >> 4) & 0x00F000)
-#define SEG_OFF(x)	((x) & 0x0FFFF)
-
-#if _BYTE_ORDER == _LITTLE_ENDIAN
-#define B_O16(x)	(x)
-#define B_O32(x)	(x)
-#else
-#define B_O16(x)	((((x) & 0xff) << 8) | (((x) & 0xff) >> 8))
-#define B_O32(x)	((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) \
-		| (((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24))
-#endif
-
-#define L_ADD(x)	(B_O32(x) & 0xffff) + ((B_O32(x) >> 12) & 0xffff00)
-#define FARP(p)		(((unsigned)(p & 0xffff0000) >> 12) | (p & 0xffff))
-
-#define REALOFF(x)	(x*4096)
-
-static unsigned char *emumem = NULL;
-
-static uint8_t
-vm86_emu_inb(struct x86emu *emu, uint16_t port)
-{
-	if (port == 0xb2) /* APM scratch register */
-		return 0;
-	if (port >= 0x80 && port < 0x88) /* POST status register */
-		return 0;
-	return inb(port);
-}
-
-static uint16_t
-vm86_emu_inw(struct x86emu *emu, uint16_t port)
-{
-	if (port >= 0x80 && port < 0x88) /* POST status register */
-		return 0;
-	return inw(port);
-}
-
-static uint32_t
-vm86_emu_inl(struct x86emu *emu, uint16_t port)
-{
-	if (port >= 0x80 && port < 0x88) /* POST status register */
-		return 0;
-	return inl(port);
-}
-
-static void
-vm86_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 */
-		return;
-	outb(port, val);
-}
-
-static void
-vm86_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)
-{
-	if (port >= 0x80 && port < 0x88) /* POST status register */
-		return;
-	outl(port, val);
-}
-
 static void
 dump_buffer(u_char *buf, size_t len)
 {
@@ -293,8 +219,11 @@ dump_buffer(u_char *buf, size_t len)
 static int
 int10_set_mode(int mode)
 {
-	vesa_emu.x86.R_EAX = 0x0000 | mode;
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86regs_t regs;
+
+	regs.R_EAX = 0x0000 | mode;
+
+	x86biosCall(&regs, 0x10);
 
 	return 0;
 }
@@ -303,21 +232,28 @@ int10_set_mode(int mode)
 static int
 vesa_bios_get_mode(int mode, struct vesa_mode *vmode)
 {
+	x86regs_t regs;
+	int offs;
 	u_char *buf;
 
-	vesa_emu.x86.R_EAX = 0x4f01;
-	vesa_emu.x86.R_ECX = mode;
+	regs.R_EAX = 0x4f01;
+	regs.R_ECX = mode;
+
+	buf = (u_char *)x86biosAlloc(1, &offs);
 
-	buf = (emumem + REALOFF(3));
-	vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(3));
-	vesa_emu.x86.R_DI = SEG_OFF(REALOFF(3));
+	regs.R_ES = SEG_ADDR(offs);
+	regs.R_DI = SEG_OFF(offs);
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86biosCall(&regs, 0x10);
 
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	if ((regs.R_AX & 0xff) != 0x4f)
+	{
+		x86biosFree(buf, 1);
 		return 1;
+	}
 
 	bcopy(buf, vmode, sizeof(*vmode));
+	x86biosFree(buf, 1);
 
 	return 0;
 }
@@ -325,62 +261,73 @@ vesa_bios_get_mode(int mode, struct vesa
 static int
 vesa_bios_set_mode(int mode)
 {
-	vesa_emu.x86.R_EAX = 0x4f02;
-	vesa_emu.x86.R_EBX = mode;
+	x86regs_t regs;
+
+	regs.R_EAX = 0x4f02;
+	regs.R_EBX = mode;
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86biosCall(&regs, 0x10);
 
-	return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
+	return ((regs.R_AX & 0xff) != 0x4f);
 }
 
 static int
 vesa_bios_get_dac(void)
 {
-	vesa_emu.x86.R_EAX = 0x4f08;
-	vesa_emu.x86.R_EBX = 1;
+	x86regs_t regs;
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	regs.R_EAX = 0x4f08;
+	regs.R_EBX = 1;
 
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	x86biosCall(&regs, 0x10);
+
+	if ((regs.R_AX & 0xff) != 0x4f)
 		return 6;
 
-	return ((vesa_emu.x86.R_EBX >> 8) & 0x00ff);
+	return ((regs.R_EBX >> 8) & 0x00ff);
 }
 
 static int
 vesa_bios_set_dac(int bits)
 {
-	vesa_emu.x86.R_EAX = 0x4f08;
-	vesa_emu.x86.R_EBX = (bits << 8);
+	x86regs_t regs;
+
+	regs.R_EAX = 0x4f08;
+	regs.R_EBX = (bits << 8);
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86biosCall(&regs, 0x10);
 
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	if ((regs.R_AX & 0xff) != 0x4f)
 		return 6;
 
-	return ((vesa_emu.x86.R_EBX >> 8) & 0x00ff);
+	return ((regs.R_EBX >> 8) & 0x00ff);
 }
 
 static int
 vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
 {
+	x86regs_t regs;
+	int offs;
 	u_char *p;
 	int i;
 
-	vesa_emu.x86.R_EAX = 0x4f09;
-	vesa_emu.x86.R_EBX = 1;
-	vesa_emu.x86.R_ECX = colors;
-	vesa_emu.x86.R_EDX = start;
+	regs.R_EAX = 0x4f09;
+	regs.R_EBX = 1;
+	regs.R_ECX = colors;
+	regs.R_EDX = start;
 
-	vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
-	vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
+	p = (u_char *)x86biosAlloc(1, &offs);
 
-	p = emumem + REALOFF(2);
+	regs.R_ES = SEG_ADDR(offs);
+	regs.R_DI = SEG_OFF(offs);
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86biosCall(&regs, 0x10);
 
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	if ((regs.R_AX & 0xff) != 0x4f)
+	{
+		x86biosFree(p, 1);
 		return 1;
+	}
 
 	bits = 8 - bits;
 	for (i = 0; i < colors; ++i) {
@@ -388,6 +335,8 @@ vesa_bios_save_palette(int start, int co
 		palette[i*3 + 1] = p[i*4 + 1] << bits;
 		palette[i*3 + 2] = p[i*4] << bits;
 	}
+
+	x86biosFree(p, 1);
 	return 0;
 }
 
@@ -395,23 +344,28 @@ static int
 vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
 			int bits)
 {
+	x86regs_t regs;
+	int offs;
 	u_char *p;
 	int i;
 
-	vesa_emu.x86.R_EAX = 0x4f09;
-	vesa_emu.x86.R_EBX = 1;
-	vesa_emu.x86.R_ECX = colors;
-	vesa_emu.x86.R_EDX = start;
+	regs.R_EAX = 0x4f09;
+	regs.R_EBX = 1;
+	regs.R_ECX = colors;
+	regs.R_EDX = start;
 
-	vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
-	vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
+	p = (u_char *)x86biosAlloc(1, &offs);
 
-	p = emumem + REALOFF(2);
+	regs.R_ES = SEG_ADDR(offs);
+	regs.R_DI = SEG_OFF(offs);
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86biosCall(&regs, 0x10);
 
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	if ((regs.R_AX & 0xff) != 0x4f)
+	{
+		x86biosFree(p, 1);
 		return 1;
+	}
 
 	bits = 8 - bits;
 	for (i = 0; i < colors; ++i) {
@@ -419,16 +373,20 @@ vesa_bios_save_palette2(int start, int c
 		g[i] = p[i*4 + 1] << bits;
 		b[i] = p[i*4] << bits;
 	}
+
+	x86biosFree(p, 1);
 	return 0;
 }
 
 static int
 vesa_bios_load_palette(int start, int colors, u_char *palette, int bits)
 {
+	x86regs_t regs;
+	int offs;
 	u_char *p;
 	int i;
 
-	p = (emumem + REALOFF(2));
+	p = (u_char *)x86biosAlloc(1, &offs);
 
 	bits = 8 - bits;
 	for (i = 0; i < colors; ++i) {
@@ -438,17 +396,19 @@ vesa_bios_load_palette(int start, int co
 		p[i*4 + 3] = 0;
 	}
 
-	vesa_emu.x86.R_EAX = 0x4f09;
-	vesa_emu.x86.R_EBX = 0;
-	vesa_emu.x86.R_ECX = colors;
-	vesa_emu.x86.R_EDX = start;
+	regs.R_EAX = 0x4f09;
+	regs.R_EBX = 0;
+	regs.R_ECX = colors;
+	regs.R_EDX = start;
 
-	vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
-	vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
+	regs.R_ES = SEG_ADDR(offs);
+	regs.R_DI = SEG_OFF(offs);
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86biosCall(&regs, 0x10);
 
-	return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
+	x86biosFree(p, 1);
+
+	return ((regs.R_AX & 0xff) != 0x4f);
 }
 
 #ifdef notyet
@@ -456,10 +416,12 @@ static int
 vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
 			int bits)
 {
+	x86regs_t regs;
+	int offs;
 	u_char *p;
 	int i;
 
-	p = (emumem + REALOFF(2));
+	p = (u_char *)x86biosAlloc(1, &offs);
 
 	bits = 8 - bits;
 	for (i = 0; i < colors; ++i) {
@@ -469,93 +431,106 @@ vesa_bios_load_palette2(int start, int c
 		p[i*4 + 3] = 0;
 	}
 
-	vesa_emu.x86.R_EAX = 0x4f09;
-	vesa_emu.x86.R_EBX = 0;
-	vesa_emu.x86.R_ECX = colors;
-	vesa_emu.x86.R_EDX = start;
+	regs.R_EAX = 0x4f09;
+	regs.R_EBX = 0;
+	regs.R_ECX = colors;
+	regs.R_EDX = start;
+
+	regs.R_ES = SEG_ADDR(offs);
+	regs.R_DI = SEG_OFF(offs);
 
-	vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
-	vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
+	x86biosCall(&regs, 0x10);
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86biosFree(p, 1);
 
-	return ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	return ((regs.R_AX & 0xff) != 0x4f);
 }
 #endif
 
 static int
 vesa_bios_state_buf_size(void)
 {
-	vesa_emu.x86.R_EAX = 0x4f04;
-	vesa_emu.x86.R_ECX = STATE_ALL;
-	vesa_emu.x86.R_EDX = STATE_SIZE;
+	x86regs_t regs;
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	regs.R_EAX = 0x4f04;
+	regs.R_ECX = STATE_ALL;
+	regs.R_EDX = STATE_SIZE;
 
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	x86biosCall(&regs, 0x10);
+
+	if ((regs.R_AX & 0xff) != 0x4f)
 		return 0;
 
-	return vesa_emu.x86.R_BX*64;
+	return regs.R_BX*64;
 }
 
 static int
 vesa_bios_save_restore(int code, void *p, size_t size)
 {
+	x86regs_t regs;
+	int offs;
 	u_char *buf;
 
-	if (size > VESA_X86EMU_BUFSIZE)
+	if (size > VESA_BIOS_BUFSIZE)
 		return (1);
 
-	vesa_emu.x86.R_EAX = 0x4f04;
-	vesa_emu.x86.R_ECX = STATE_ALL;
-	vesa_emu.x86.R_EDX = code;
+	regs.R_EAX = 0x4f04;
+	regs.R_ECX = STATE_ALL;
+	regs.R_EDX = code;
 
-	buf = emumem + REALOFF(2);
+	buf = (u_char *)x86biosAlloc(1, &offs);
 
-	vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
-	vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
+	regs.R_ES = SEG_ADDR(offs);
+	regs.R_DI = SEG_OFF(offs);
 
 	bcopy(p, buf, size);
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86biosCall(&regs, 0x10);
 
 	bcopy(buf, p, size);
 
-	return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
+	x86biosFree(p, 1);
+
+	return ((regs.R_AX & 0xff) != 0x4f);
 }
 
 static int
 vesa_bios_get_line_length(void)
 {
-	vesa_emu.x86.R_EAX = 0x4f06;
-	vesa_emu.x86.R_EBX = 1;
+	x86regs_t regs;
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	regs.R_EAX = 0x4f06;
+	regs.R_EBX = 1;
 
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	x86biosCall(&regs, 0x10);
+
+	if ((regs.R_AX & 0xff) != 0x4f)
 		return -1;
-	return vesa_emu.x86.R_BX;
+
+	return regs.R_BX;
 }
 
 static int
 vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
 {
-	vesa_emu.x86.R_EAX = 0x4f06;
-	vesa_emu.x86.R_EBX = 0;
-	vesa_emu.x86.R_ECX = pixel;
+	x86regs_t regs;
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	regs.R_EAX = 0x4f06;
+	regs.R_EBX = 0;
+	regs.R_ECX = pixel;
+
+	x86biosCall(&regs, 0x10);
 
 #if VESA_DEBUG > 1
-	printf("bx:%d, cx:%d, dx:%d\n", vesa_emu.x86.R_BX, vesa_emu.x86.R_CX, vesa_emu.x86.R_DX);
+	printf("bx:%d, cx:%d, dx:%d\n", regs.R_BX, regs.R_CX, regs.R_DX);
 #endif
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	if ((regs.R_AX & 0xff) != 0x4f)
 		return -1;
 
 	if (bytes)
-		*bytes = vesa_emu.x86.R_BX;
+		*bytes = regs.R_BX;
 	if (lines)
-		*lines = vesa_emu.x86.R_DX;
+		*lines = regs.R_DX;
 
 	return 0;
 }
@@ -564,16 +539,18 @@ vesa_bios_set_line_length(int pixel, int
 static int
 vesa_bios_get_start(int *x, int *y)
 {
-	vesa_emu.x86.R_EAX = 0x4f07;
-	vesa_emu.x86.R_EBX = 1;
+	x86regs_t regs;
+
+	regs.R_EAX = 0x4f07;
+	regs.R_EBX = 1;
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86biosCall(&regs, 0x10);
 
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	if ((regs.R_AX & 0xff) != 0x4f)
 		return -1;
 
-	*x = vesa_emu.x86.R_CX;
-	*y = vesa_emu.x86.R_DX;
+	*x = regs.R_CX;
+	*y = regs.R_DX;
 
 	return 0;
 }
@@ -582,14 +559,16 @@ vesa_bios_get_start(int *x, int *y)
 static int
 vesa_bios_set_start(int x, int y)
 {
-	vesa_emu.x86.R_EAX = 0x4f07;
-	vesa_emu.x86.R_EBX = 0x80;
-	vesa_emu.x86.R_EDX = y;
-	vesa_emu.x86.R_ECX = x;
+	x86regs_t regs;
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	regs.R_EAX = 0x4f07;
+	regs.R_EBX = 0x80;
+	regs.R_EDX = y;
+	regs.R_ECX = x;
 
-	return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
+	x86biosCall(&regs, 0x10);
+
+	return ((regs.R_AX & 0xff) != 0x4f);
 }
 
 /* map a generic video mode to a known mode */
@@ -665,6 +644,8 @@ vesa_bios_init(void)
 	static struct vesa_info buf;
 	struct vesa_mode vmode;
 	video_info_t *p;
+	x86regs_t regs;
+	int offs;
 	u_char *vmbuf;
 	int is_via_cle266;
 	int modes;
@@ -678,16 +659,16 @@ vesa_bios_init(void)
 	vesa_vmode_max = 0;
 	vesa_vmode[0].vi_mode = EOT;
 
-	vmbuf = (emumem + REALOFF(2));
+	vmbuf = (u_char *)x86biosAlloc(1, &offs);
 	bcopy("VBE2", vmbuf, 4);	/* try for VBE2 data */
 
-	vesa_emu.x86.R_EAX = 0x4f00;
-	vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
-	vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
+	regs.R_EAX = 0x4f00;
+	regs.R_ES = SEG_ADDR(offs);
+	regs.R_DI = SEG_OFF(offs);
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	x86biosCall(&regs, 0x10);
 
-	if (((vesa_emu.x86.R_AX & 0xff) != 0x4f) || bcmp("VESA", vmbuf, 4))
+	if (((regs.R_AX & 0xff) != 0x4f) || bcmp("VESA", vmbuf, 4))
 		return 1;
 
 	bcopy(vmbuf, &buf, sizeof(buf));
@@ -707,17 +688,17 @@ vesa_bios_init(void)
 		return 1;
 	}
 
-	vesa_oemstr = (char *)(emumem + L_ADD(vesa_adp_info->v_oemstr));
+	vesa_oemstr = (char *)x86biosOffs(FARP(vesa_adp_info->v_oemstr));
 
 	is_via_cle266 = strcmp(vesa_oemstr, VESA_VIA_CLE266) == 0;
 
 	if (vesa_adp_info->v_version >= 0x0200) {
-		vesa_venderstr = (char *)(emumem+L_ADD(vesa_adp_info->v_venderstr));
-		vesa_prodstr = (char *)(emumem+L_ADD(vesa_adp_info->v_prodstr));
-		vesa_revstr = (char *)(emumem+L_ADD(vesa_adp_info->v_revstr));
+		vesa_venderstr = (char *)x86biosOffs(FARP(vesa_adp_info->v_venderstr));
+		vesa_prodstr = (char *)x86biosOffs(FARP(vesa_adp_info->v_prodstr));
+		vesa_revstr = (char *)x86biosOffs(FARP(vesa_adp_info->v_revstr));
 	}
 
-	vesa_vmodetab = (u_int16_t *)(emumem+L_ADD(vesa_adp_info->v_modetable));
+	vesa_vmodetab = (u_int16_t *)x86biosOffs(FARP(vesa_adp_info->v_modetable));
 
 	if (vesa_vmodetab == NULL)
 		return 1;
@@ -802,7 +783,7 @@ vesa_bios_init(void)
 				      - vmode.v_lfb;
 		else
 			vesa_vmode[modes].vi_buffer_size
-				= vmode.v_offscreen + vmode.v_offscreensize*1024
+				= vmode.v_offscreen + vmode.v_offscreensize*1024;
 #endif
 		vesa_vmode[modes].vi_mem_model 
 			= vesa_translate_mmodel(vmode.v_memmodel);
@@ -843,6 +824,9 @@ vesa_bios_init(void)
 		++modes;
 	}
 	vesa_vmode[modes].vi_mode = EOT;
+
+	x86biosFree(vmbuf, 1);
+
 	if (bootverbose)
 		printf("VESA: %d mode(s) found\n", modes);
 
@@ -1127,7 +1111,7 @@ vesa_set_mode(video_adapter_t *adp, int 
 	} else {
 		vesa_adp->va_buffer = 0;
 		vesa_adp->va_buffer_size = info.vi_buffer_size;
-		vesa_adp->va_window = (vm_offset_t)(emumem+L_ADD(info.vi_window));
+		vesa_adp->va_window = BIOS_PADDRTOVADDR(info.vi_window);
 		vesa_adp->va_window_size = info.vi_window_size;
 		vesa_adp->va_window_gran = info.vi_window_gran;
 	}
@@ -1276,14 +1260,16 @@ vesa_load_state(video_adapter_t *adp, vo
 static int
 vesa_get_origin(video_adapter_t *adp, off_t *offset)
 {
-	vesa_emu.x86.R_EAX = 0x4f05;
-	vesa_emu.x86.R_EBX = 0x10;
+	x86regs_t regs;
 
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	regs.R_EAX = 0x4f05;
+	regs.R_EBX = 0x10;
 
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	x86biosCall(&regs, 0x10);
+
+	if ((regs.R_AX & 0xff) != 0x4f)
 		return 1;
-	*offset = vesa_emu.x86.DX*adp->va_window_gran;
+	*offset = regs.DX*adp->va_window_gran;
 
 	return 0;
 }
@@ -1292,6 +1278,8 @@ vesa_get_origin(video_adapter_t *adp, of
 static int
 vesa_set_origin(video_adapter_t *adp, off_t offset)
 {
+	x86regs_t regs;
+
 	/*
 	 * This function should return as quickly as possible to 
 	 * maintain good performance of the system. For this reason,
@@ -1308,18 +1296,18 @@ vesa_set_origin(video_adapter_t *adp, of
 	if (adp->va_window_gran == 0)
 		return 1;
 
-	vesa_emu.x86.R_EAX = 0x4f05;
-	vesa_emu.x86.R_EBX = 0;
-	vesa_emu.x86.R_EDX = offset/adp->va_window_gran;
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	regs.R_EAX = 0x4f05;
+	regs.R_EBX = 0;
+	regs.R_EDX = offset/adp->va_window_gran;
+	x86biosCall(&regs, 0x10);
 
-	if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
+	if ((regs.R_AX & 0xff) != 0x4f)
 		return 1;
 
-	vesa_emu.x86.R_EAX = 0x4f05;
-	vesa_emu.x86.R_EBX = 1;
-	vesa_emu.x86.R_EDX = offset/adp->va_window_gran;
-	x86emu_exec_intr(&vesa_emu, 0x10);
+	regs.R_EAX = 0x4f05;
+	regs.R_EBX = 1;
+	regs.R_EDX = offset/adp->va_window_gran;
+	x86biosCall(&regs, 0x10);
 
 	adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran;
 	return 0;			/* XXX */
@@ -1654,22 +1642,6 @@ vesa_load(void)
 	if (vesa_init_done)
 		return 0;
 
-	/* Can `emumem' be NULL here? */
-	emumem = pmap_mapbios(0x0, 0xc00000);
-
-	memset(&vesa_emu, 0, sizeof(vesa_emu));
-	x86emu_init_default(&vesa_emu);
-
-	vesa_emu.emu_inb = vm86_emu_inb;
-	vesa_emu.emu_inw = vm86_emu_inw;
-	vesa_emu.emu_inl = vm86_emu_inl;
-	vesa_emu.emu_outb = vm86_emu_outb;
-	vesa_emu.emu_outw = vm86_emu_outw;
-	vesa_emu.emu_outl = vm86_emu_outl;
-
-	vesa_emu.mem_base = (char *)emumem;
-	vesa_emu.mem_size = 1024 * 1024;
-
 	/* locate a VGA adapter */
 	s = spltty();
 	vesa_adp = NULL;
@@ -1717,9 +1689,6 @@ vesa_unload(void)
 	}
 	splx(s);
 
-	if (emumem)
-		pmap_unmapdev((vm_offset_t)emumem, 0xc00000);
-
 	return error;
 }
 
@@ -1744,6 +1713,6 @@ static moduledata_t vesa_mod = {
 };
 
 DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
-MODULE_DEPEND(vesa, x86emu, 1, 1, 1);
+MODULE_DEPEND(vesa, x86bios, 1, 1, 1);
 
 #endif	/* VGA_NO_MODE_CHANGE */

Added: head/sys/dev/x86bios/x86bios.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/x86bios/x86bios.c	Mon Sep 21 08:17:57 2009	(r197383)
@@ -0,0 +1,218 @@
+/*-
+ * Written by paradox <ddkprog@yahoo.com>
+ * Public domain.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_x86bios.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+
+#include <vm/vm.h>
+#include <vm/vm_extern.h>
+#include <vm/vm_kern.h>

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200909210817.n8L8HvP3080703>