Hi,

i did some further work on the vgabios utility. Here's a quick try to
recatch the changes:

* drop more of the pInt dependencies
* drop some obsolete wrapping stuff
* split interrupt code into seperate files for each int.
  thus getting rid of inthandler.c
* cleaning up pci interface a bit
* implementing pci read/write functions for Linux userspace
* use getopt() for parameters and set up defaults for executing pci
  roms.
* make trace mode runtime chosable
* set up initial stack and registers

you can run a pci option firmware like this:
./testbios ~stepan/gxivideo.208

This will probably not work correctly, as the bus/device/function is
expected in AX before executing the option rom. Thus you might want to
use the -d option to specify it (this should be probed, somewhen)
so if your system says
00:12.4 VGA compatible controller: Cyrix Corporation 5530 Video [Kahlua]
your -d value is (0x12 << 3) | 0x04 => 0x94
So you might want to say "./testbios ~stepan/gxivideo.208 -d 0x94"

-t switches single step mode on, -d enables mode debugging.

Here's a little log from my network adaptor's pci rom
We're not 100% there, but getting a lot closer.

Any comments welcome!

   Stefan

-------------------------- 8< --------------------------------------
./testbios ~stepan/rtsrom_m.lom -d 0x78  -v             
running file /home/stepan/rtsrom_m.lom
No size specified. defaulting to 32k
No base specified. defaulting to 0xc0000
No initial code segment specified. defaulting to 0xc000
No initial instruction pointer specified. defaulting to 0x0003

int1a encountered.
        EAX=0000b109  EBX=00000078  ECX=00000000  EDX=00000080  
        ESP=0000ffe4  EBP=00000000  ESI=00000000  EDI=00000010
        DS=0040  ES=0000  SS=0030  CS=c000  EIP=00001aae
        NV UP DI NG NZ NA PO NC 
eax=0x9 ecx=0xe001 eflags=0x80

Realtek RTL8139(X) PXE/RPL BootROM

Press F10 key to change bootstrap selection.
Current Selection is �0�u�0f9F�s
                                �E�y.
int16: keyboard not supported right now.

int16: keyboard not supported right now.

int1a encountered.
        EAX=0000b101  EBX=00000000  ECX=00000000  EDX=00000080  
        ESP=0000ffd6  EBP=00000000  ESI=00000000  EDI=00000000
        DS=0040  ES=0000  SS=0030  CS=c000  EIP=00001975
        NV UP DI PL ZR NA PE NC 
PCI bios present.

int1a encountered.
        EAX=0000b109  EBX=00000078  ECX=00000000  EDX=20494350  
        ESP=0000ffd6  EBP=00000000  ESI=00000000  EDI=00000000
        DS=0040  ES=0000  SS=0030  CS=c000  EIP=000019c2
        NV UP DI PL ZR NA PE NC 
eax=0x9 ecx=0x10ec eflags=0x46

int1a encountered.
        EAX=0000b109  EBX=00000078  ECX=000010ec  EDX=20494350  
        ESP=0000ffd6  EBP=00000000  ESI=00000000  EDI=00000002
        DS=0040  ES=0000  SS=0030  CS=c000  EIP=000019db
        NV UP DI PL ZR NA PE NC 
eax=0x9 ecx=0x8139 eflags=0x46

int1a encountered.
        EAX=0000b10a  EBX=00000078  ECX=00008139  EDX=20494350  
        ESP=0000ffd6  EBP=00000000  ESI=00000000  EDI=00000030
        DS=0040  ES=0000  SS=0030  CS=c000  EIP=00001a74
        NV UP DI PL ZR NA PE NC 
eax=0xa ecx=0x0 eflags=0x46
-------------------------- 8< --------------------------------------
  
-- 
Ok hex 4666 dup negate do i 4000 dup 2* negate do " *" 0 dup 2dup 1e 0 do
 2swap * e >>a 2* 5 pick + -rot - j + dup dup * e >>a rot dup dup * e >>a 
  rot swap 2dup + 10000 > if 3drop 3drop "  " 0 dup 2dup leave then loop 
              2drop 2drop type 268 +loop cr drop 5de +loop
diff -urN new/freebios/util/vgabios/Makefile freebios/util/vgabios/Makefile
--- new/freebios/util/vgabios/Makefile  Thu Apr 18 02:34:04 2002
+++ freebios/util/vgabios/Makefile      Thu Apr 18 09:03:51 2002
@@ -1,13 +1,19 @@
-CFLAGS   =  -Ix86emu/include -O2 -g
+CC       =  gcc
+CFLAGS   =  -Wall -Ix86emu/include -O2 -g
+
+INTOBJS  =  int10.o int15.o int16.o int1a.o inte6.o
+OBJECTS  =  testbios.o helper_exec.o helper_mem.o $(INTOBJS)
 
-OBJECTS  =  testbios.o helper_exec.o inthandler.o pci-userspace.o
 LIBS     =  x86emu/src/x86emu/libx86emu.a
+
+# user space pci is the only option right now.
+OBJECTS += pci-userspace.o
 LIBS    +=  /usr/lib/libpci.a
 
 all: testbios
 
 testbios: $(OBJECTS) $(LIBS)
-       cc -o testbios $(OBJECTS) $(LIBS)
+       $(CC) -o testbios $(OBJECTS) $(LIBS)
  
 helper_exec.o: helper_exec.c test.h
 
diff -urN new/freebios/util/vgabios/helper_exec.c freebios/util/vgabios/helper_exec.c
--- new/freebios/util/vgabios/helper_exec.c     Thu Apr 18 02:34:04 2002
+++ freebios/util/vgabios/helper_exec.c Sat Apr 20 07:17:54 2002
@@ -19,9 +19,7 @@
 #include <asm/io.h>
 #include <sys/time.h>
 
-int
-port_rep_inb(ptr pInt,
-            u16 port, u32 base, int d_f, u32 count);
+int port_rep_inb(u16 port, u32 base, int d_f, u32 count);
 u8 x_inb(u16 port);
 u16 x_inw(u16 port);
 void x_outb(u16 port, u8 val);
@@ -30,113 +28,98 @@
 void x_outl(u16 port, u32 val);
 
 /* general software interrupt handler */
-u32
-getIntVect(ptr pInt,int num)
+u32 getIntVect(int num)
 {
-    return MEM_RW(pInt, num << 2) + (MEM_RW(pInt, (num << 2) + 2) << 4);
+    return MEM_RW(num << 2) + (MEM_RW((num << 2) + 2) << 4);
 }
 
 void
-pushw(ptr pInt, u16 val)
+pushw(u16 val)
 {
     X86_ESP -= 2;
-    MEM_WW(pInt, ((u32) X86_SS << 4) + X86_SP, val);
+    MEM_WW(((u32) X86_SS << 4) + X86_SP, val);
 }
 
-int
-run_bios_int(int num, ptr pInt)
+int run_bios_int(int num)
 {
     u32 eflags;
     eflags = X86_EFLAGS;
-    pushw(pInt, eflags);
-    pushw(pInt, X86_CS);
-    pushw(pInt, X86_IP);
-    X86_CS = MEM_RW(pInt, (num << 2) + 2);
-    X86_IP = MEM_RW(pInt,  num << 2);
+    pushw(eflags);
+    pushw(X86_CS);
+    pushw(X86_IP);
+    X86_CS = MEM_RW( (num << 2) + 2);
+    X86_IP = MEM_RW( num << 2);
 
     return 1;
 }
 
-int
-port_rep_inb(ptr pInt,
-            u16 port, u32 base, int d_f, u32 count)
+int port_rep_inb(u16 port, u32 base, int d_f, u32 count)
 {
     register int inc = d_f ? -1 : 1;
     u32 dst = base;
     while (count--) {
-       MEM_WB(pInt, dst, x_inb(port));
+       MEM_WB(dst, x_inb(port));
        dst += inc;
     }
     return dst - base;
 }
 
-int
-port_rep_inw(ptr pInt,
-            u16 port, u32 base, int d_f, u32 count)
+int port_rep_inw(u16 port, u32 base, int d_f, u32 count)
 {
     register int inc = d_f ? -2 : 2;
     u32 dst = base;
     while (count--) {
-       MEM_WW(pInt, dst, x_inw(port));
+       MEM_WW(dst, x_inw(port));
        dst += inc;
     }
     return dst - base;
 }
 
-int
-port_rep_inl(ptr pInt,
-            u16 port, u32 base, int d_f, u32 count)
+int port_rep_inl(u16 port, u32 base, int d_f, u32 count)
 {
     register int inc = d_f ? -4 : 4;
     u32 dst = base;
     while (count--) {
-       MEM_WL(pInt, dst, x_inl(port));
+       MEM_WL(dst, x_inl(port));
        dst += inc;
     }
     return dst - base;
 }
 
-int
-port_rep_outb(ptr pInt,
-             u16 port, u32 base, int d_f, u32 count)
+int port_rep_outb(u16 port, u32 base, int d_f, u32 count)
 {
     register int inc = d_f ? -1 : 1;
     u32 dst = base;
     while (count--) {
-       x_outb(port, MEM_RB(pInt, dst));
+       x_outb(port, MEM_RB(dst));
        dst += inc;
     }
     return dst - base;
 }
 
-int
-port_rep_outw(ptr pInt,
-             u16 port, u32 base, int d_f, u32 count)
+int port_rep_outw(u16 port, u32 base, int d_f, u32 count)
 {
     register int inc = d_f ? -2 : 2;
     u32 dst = base;
     while (count--) {
-       x_outw(port, MEM_RW(pInt, dst));
+       x_outw(port, MEM_RW(dst));
        dst += inc;
     }
     return dst - base;
 }
 
-int
-port_rep_outl(ptr pInt,
-             u16 port, u32 base, int d_f, u32 count)
+int port_rep_outl(u16 port, u32 base, int d_f, u32 count)
 {
     register int inc = d_f ? -4 : 4;
     u32 dst = base;
     while (count--) {
-       x_outl(port, MEM_RL(pInt, dst));
+       x_outl(port, MEM_RL(dst));
        dst += inc;
     }
     return dst - base;
 }
 
-u8
-x_inb(u16 port)
+u8 x_inb(u16 port)
 {
     u8 val;
 
@@ -152,16 +135,15 @@
     return val;
 }
 
-void
-getsecs(unsigned long *sec, unsigned long *usec)
+void getsecs(unsigned long *sec, unsigned long *usec)
 {
   struct timeval tv;
   gettimeofday(&tv, 0);
   *sec = tv.tv_sec;
   *usec = tv.tv_usec;
 }
-u16
-x_inw(u16 port)
+
+u16 x_inw(u16 port)
 {
     u16 val;
 
@@ -175,8 +157,7 @@
     return val;
 }
 
-void
-x_outb(u16 port, u8 val)
+void x_outb(u16 port, u8 val)
 {
     if ((port == 0x43) && (val == 0)) {
        /*
@@ -193,15 +174,13 @@
     }
 }
 
-void
-x_outw(u16 port, u16 val)
+void x_outw(u16 port, u16 val)
 {
 
     outw(port, val);
 }
 
-u32
-x_inl(u16 port)
+u32 x_inl(u16 port)
 {
     u32 val;
 
@@ -210,44 +189,37 @@
     return val;
 }
 
-void
-x_outl(u16 port, u32 val)
+void x_outl(u16 port, u32 val)
 {
     outl(port, val);
 }
 
-u8
-Mem_rb(int addr)
+u8 Mem_rb(int addr)
 {
     return (*current->mem->rb)(current, addr);
 }
 
-u16
-Mem_rw(int addr)
+u16 Mem_rw(int addr)
 {
     return (*current->mem->rw)(current, addr);
 }
 
-u32
-Mem_rl(int addr)
+u32 Mem_rl(int addr)
 {
     return (*current->mem->rl)(current, addr);
 }
 
-void
-Mem_wb(int addr, u8 val)
+void Mem_wb(int addr, u8 val)
 {
     (*current->mem->wb)(current, addr, val);
 }
 
-void
-Mem_ww(int addr, u16 val)
+void Mem_ww(int addr, u16 val)
 {
     (*current->mem->ww)(current, addr, val);
 }
 
-void
-Mem_wl(int addr, u32 val)
+void Mem_wl(int addr, u32 val)
 {
     (*current->mem->wl)(current, addr, val);
 }
@@ -256,8 +228,7 @@
 #define TAG(Cfg1Addr) (Cfg1Addr & 0xffff00)
 #define OFFSET(Cfg1Addr) (Cfg1Addr & 0xff)
 
-u8
-bios_checksum(u8 *start, int size)
+u8 bios_checksum(u8 *start, int size)
 {
     u8 sum = 0;
 
diff -urN new/freebios/util/vgabios/helper_mem.c freebios/util/vgabios/helper_mem.c
--- new/freebios/util/vgabios/helper_mem.c      Sun Apr 14 06:44:08 2002
+++ freebios/util/vgabios/helper_mem.c  Sat Apr 20 07:16:07 2002
@@ -4,11 +4,10 @@
  *   execute BIOS int 10h calls in x86 real mode environment
  *                 Copyright 1999 Egbert Eich
  */
-#if 0
 #define _INT10_PRIVATE
 
 #define REG pInt
-
+#if 0
 typedef enum {
     OPT_NOINT10,
     OPT_INIT_PRIMARY,
@@ -21,81 +20,79 @@
     {OPT_BIOS_LOCATION, "BiosLocation",        OPTV_STRING,    {0},    FALSE },
     { -1,              NULL,           OPTV_NONE,      {0},    FALSE },
 };
-
+#endif
 #ifdef DEBUG
-void
-dprint(unsigned long start, unsigned long size)
+void dprint(unsigned long start, unsigned long size)
 {
     int i,j;
     char *c = (char *)start;
 
     for (j = 0; j < (size >> 4); j++) {
        char *d = c;
-       ErrorF("\n0x%lx:  ",(unsigned long)c);
+       printf("\n0x%lx:  ",(unsigned long)c);
        for (i = 0; i<16; i++)
-           ErrorF("%2.2x ",(unsigned char) (*(c++)));
+           printf("%2.2x ",(unsigned char) (*(c++)));
        c = d;
        for (i = 0; i<16; i++) {
-           ErrorF("%c",((((CARD8)(*c)) > 32) && (((CARD8)(*c)) < 128)) ?
+           printf("%c",((((u8)(*c)) > 32) && (((u8)(*c)) < 128)) ?
                   (unsigned char) (*(c)): '.');
            c++;
        }
     }
-    ErrorF("\n");
+    printf("\n");
 }
 #endif
 
+#if 0
 #ifndef _PC
 /*
  * here we are really paranoid about faking a "real"
  * BIOS. Most of this information was pulled from
  * dosemu.
  */
-void
-setup_int_vect(xf86Int10InfoPtr pInt)
+void setup_int_vect(void)
 {
     int i;
 
     /* let the int vects point to the SYS_BIOS seg */
     for (i = 0; i < 0x80; i++) {
-       MEM_WW(pInt, i << 2, 0);
-       MEM_WW(pInt, (i << 2) + 2, SYS_BIOS >> 4);
+       MEM_WW( i << 2, 0);
+       MEM_WW( (i << 2) + 2, SYS_BIOS >> 4);
     }
 
-    reset_int_vect(pInt);
+    reset_int_vect(current);
     /* font tables default location (int 1F) */
-    MEM_WW(pInt,0x1f<<2,0xfa6e);
+    MEM_WW(0x1f<<2,0xfa6e);
 
     /* int 11 default location (Get Equipment Configuration) */
-    MEM_WW(pInt, 0x11 << 2, 0xf84d);
+    MEM_WW( 0x11 << 2, 0xf84d);
     /* int 12 default location (Get Conventional Memory Size) */
-    MEM_WW(pInt, 0x12 << 2, 0xf841);
+    MEM_WW( 0x12 << 2, 0xf841);
     /* int 15 default location (I/O System Extensions) */
-    MEM_WW(pInt, 0x15 << 2, 0xf859);
+    MEM_WW( 0x15 << 2, 0xf859);
     /* int 1A default location (RTC, PCI and others) */
-    MEM_WW(pInt, 0x1a << 2, 0xff6e);
+    MEM_WW( 0x1a << 2, 0xff6e);
     /* int 05 default location (Bound Exceeded) */
-    MEM_WW(pInt, 0x05 << 2, 0xff54);
+    MEM_WW( 0x05 << 2, 0xff54);
     /* int 08 default location (Double Fault) */
-    MEM_WW(pInt, 0x08 << 2, 0xfea5);
+    MEM_WW( 0x08 << 2, 0xfea5);
     /* int 13 default location (Disk) */
-    MEM_WW(pInt, 0x13 << 2, 0xec59);
+    MEM_WW( 0x13 << 2, 0xec59);
     /* int 0E default location (Page Fault) */
-    MEM_WW(pInt, 0x0e << 2, 0xef57);
+    MEM_WW( 0x0e << 2, 0xef57);
     /* int 17 default location (Parallel Port) */
-    MEM_WW(pInt, 0x17 << 2, 0xefd2);
+    MEM_WW( 0x17 << 2, 0xefd2);
     /* fdd table default location (int 1e) */
-    MEM_WW(pInt, 0x1e << 2, 0xefc7);
+    MEM_WW( 0x1e << 2, 0xefc7);
 
     /* Set Equipment flag to VGA */
-    i = MEM_RB(pInt, 0x0410) & 0xCF;
-    MEM_WB(pInt, 0x0410, i);
+    i = MEM_RB( 0x0410) & 0xCF;
+    MEM_WB( 0x0410, i);
     /* XXX Perhaps setup more of the BDA here.  See also int42(0x00). */
 }
 #endif
 
-int
-setup_system_bios(void *base_addr)
+int setup_system_bios(void *base_addr)
 {
     char *base = (char *) base_addr;
 
@@ -116,8 +113,7 @@
     return 1;
 }
 
-void
-reset_int_vect(xf86Int10InfoPtr pInt)
+void reset_int_vect(void)
 {
     /*
      * This table is normally located at 0xF000:0xF0A4.  However, int 0x42,
@@ -125,7 +121,7 @@
      * 64kB.  Note that because this data doesn't survive POST, int 0x42 should
      * only be used during EGA/VGA BIOS initialisation.
      */
-    static const CARD8 VideoParms[] = {
+    static const u8 VideoParms[] = {
        /* Timing for modes 0x00 & 0x01 */
        0x38, 0x28, 0x2d, 0x0a, 0x1f, 0x06, 0x19, 0x1c,
        0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
@@ -153,31 +149,30 @@
     int i;
 
     for (i = 0; i < sizeof(VideoParms); i++)
-       MEM_WB(pInt, i + (0x1000 - sizeof(VideoParms)), VideoParms[i]);
-    MEM_WW(pInt,  0x1d << 2, 0x1000 - sizeof(VideoParms));
-    MEM_WW(pInt, (0x1d << 2) + 2, 0);
-
-    MEM_WW(pInt,  0x10 << 2, 0xf065);
-    MEM_WW(pInt, (0x10 << 2) + 2, SYS_BIOS >> 4);
-    MEM_WW(pInt,  0x42 << 2, 0xf065);
-    MEM_WW(pInt, (0x42 << 2) + 2, SYS_BIOS >> 4);
-    MEM_WW(pInt,  0x6D << 2, 0xf065);
-    MEM_WW(pInt, (0x6D << 2) + 2, SYS_BIOS >> 4);
+       MEM_WB( i + (0x1000 - sizeof(VideoParms)), VideoParms[i]);
+    MEM_WW(  0x1d << 2, 0x1000 - sizeof(VideoParms));
+    MEM_WW( (0x1d << 2) + 2, 0);
+
+    MEM_WW(  0x10 << 2, 0xf065);
+    MEM_WW( (0x10 << 2) + 2, SYS_BIOS >> 4);
+    MEM_WW(  0x42 << 2, 0xf065);
+    MEM_WW( (0x42 << 2) + 2, SYS_BIOS >> 4);
+    MEM_WW(  0x6D << 2, 0xf065);
+    MEM_WW( (0x6D << 2) + 2, SYS_BIOS >> 4);
 }
 
-void
-set_return_trap(xf86Int10InfoPtr pInt)
+void set_return_trap(void)
 {
     /*
      * Here we set the exit condition:  We return when we encounter
      * 'hlt' (=0xf4), which we locate at address 0x600 in x86 memory.
      */
-    MEM_WB(pInt, 0x0600, 0xf4);
+    MEM_WB( 0x0600, 0xf4);
 
     /*
      * Allocate a segment for the stack
      */
-    xf86Int10AllocPages(pInt, 1, &pInt->stackseg);
+    xf86Int10AllocPages( 1, current->stackseg);
 }
 
 void *
@@ -312,7 +307,6 @@
     }
     xfree(s);
 }
-
 
 
 #endif
diff -urN new/freebios/util/vgabios/int10.c freebios/util/vgabios/int10.c
--- new/freebios/util/vgabios/int10.c   Thu Jan  1 01:00:00 1970
+++ freebios/util/vgabios/int10.c       Sat Apr 20 09:52:15 2002
@@ -0,0 +1,485 @@
+#include <stdio.h>
+#include "test.h"
+#include "pci.h"
+
+void x86emu_dump_xregs(void);
+extern ptr current;
+extern int verbose;
+
+
+#ifndef _PC
+/*
+ * This is derived from a number of PC system BIOS'es.  The intent here is to
+ * provide very primitive video support, before an EGA/VGA BIOS installs its
+ * own interrupt vector.  Here, "Ignored" calls should remain so.  "Not
+ * Implemented" denotes functionality that can be implemented should the need
+ * arise.  What are "Not Implemented" throughout are video memory accesses.
+ * Also, very little input validity checking is done here.
+ */
+int int42_handler()
+{
+
+       if (verbose && X86_AH != 0x0e) {
+               printf("int%x\n", current->num);
+               x86emu_dump_xregs();
+       }
+
+       switch (X86_AH) {
+       case 0x00:
+               /* Set Video Mode                                     */
+               /* Enter:  AL = video mode number                     */
+               /* Leave:  Nothing                                    */
+               /* Implemented (except for clearing the screen)       */
+               {               /* Localise */
+                       int i;
+                       u16 ioport, int1d, regvals, tmp;
+                       u8 mode, cgamode, cgacolour;
+
+                       /*
+                        * Ignore all mode numbers but 0x00-0x13.  Some systems also 
+ignore
+                        * 0x0B and 0x0C, but don't do that here.
+                        */
+                       if (X86_AL > 0x13)
+                               break;
+
+                       /*
+                        * You didn't think that was really the mode set, did you?  
+There
+                        * are only so many slots in the video parameter table...
+                        */
+                       mode = X86_AL;
+                       ioport = 0x03D4;
+                       switch (MEM_RB(0x0410) & 0x30) {
+                       case 0x30:      /* MDA */
+                               mode = 0x07;    /* Force mode to 0x07 */
+                               ioport = 0x03B4;
+                               break;
+                       case 0x10:      /* CGA 40x25 */
+                               if (mode >= 0x07)
+                                       mode = 0x01;
+                               break;
+                       case 0x20:      /* CGA 80x25 (MCGA?) */
+                               if (mode >= 0x07)
+                                       mode = 0x03;
+                               break;
+                       case 0x00:      /* EGA/VGA */
+                               if (mode >= 0x07)       /* Don't try MDA timings */
+                                       mode = 0x01;    /* !?!?! */
+                               break;
+                       }
+
+                       /* Locate data in video parameter table */
+                       int1d = MEM_RW(0x1d << 2);
+                       regvals = ((mode >> 1) << 4) + int1d;
+                       cgacolour = 0x30;
+                       if (mode == 0x06) {
+                               regvals -= 0x10;
+                               cgacolour = 0x3F;
+                       }
+
+           /** Update BIOS Data Area **/
+
+                       /* Video mode */
+                       MEM_WB(0x0449, mode);
+
+                       /* Columns */
+                       tmp = MEM_RB(mode + int1d + 0x48);
+                       MEM_WW(0x044A, tmp);
+
+                       /* Page length */
+                       tmp = MEM_RW((mode & 0x06) + int1d + 0x40);
+                       MEM_WW(0x044C, tmp);
+
+                       /* Start Address */
+                       MEM_WW(0x044E, 0);
+
+                       /* Cursor positions, one for each display page */
+                       for (i = 0x0450; i < 0x0460; i += 2)
+                               MEM_WW(i, 0);
+
+                       /* Cursor start & end scanlines */
+                       tmp = MEM_RB(regvals + 0x0B);
+                       MEM_WB(0x0460, tmp);
+                       tmp = MEM_RB(regvals + 0x0A);
+                       MEM_WB(0x0461, tmp);
+
+                       /* Current display page number */
+                       MEM_WB(0x0462, 0);
+
+                       /* CRTC I/O address */
+                       MEM_WW(0x0463, ioport);
+
+                       /* CGA Mode register value */
+                       cgamode = MEM_RB(mode + int1d + 0x50);
+                       MEM_WB(0x0465, cgamode);
+
+                       /* CGA Colour register value */
+                       MEM_WB(0x0466, cgacolour);
+
+                       /* Rows */
+                       MEM_WB(0x0484, (25 - 1));
+
+                       /* Programme the mode */
+                       outb(ioport + 4, cgamode & 0x37);       /* Turn off screen */
+                       for (i = 0; i < 0x10; i++) {
+                               tmp = MEM_RB(regvals + i);
+                               outb(ioport, i);
+                               outb(ioport + 1, tmp);
+                       }
+                       outb(ioport + 5, cgacolour);    /* Select colour mode */
+                       outb(ioport + 4, cgamode);      /* Turn on screen */
+               }
+               break;
+
+       case 0x01:
+               /* Set Cursor Type                                    */
+               /* Enter:  CH = starting line for cursor              */
+               /*         CL = ending line for cursor                */
+               /* Leave:  Nothing                                    */
+               /* Implemented                                        */
+               {               /* Localise */
+                       u16 ioport = MEM_RW(0x0463);
+
+                       MEM_WB(0x0460, X86_CL);
+                       MEM_WB(0x0461, X86_CH);
+
+                       outb(ioport, 0x0A);
+                       outb(ioport + 1, X86_CH);
+                       outb(ioport, 0x0B);
+                       outb(ioport + 1, X86_CL);
+               }
+               break;
+
+       case 0x02:
+               /* Set Cursor Position                                */
+               /* Enter:  BH = display page number                   */
+               /*         DH = row                                   */
+               /*         DL = column                                */
+               /* Leave:  Nothing                                    */
+               /* Implemented                                        */
+               {               /* Localise */
+                       u16 offset, ioport;
+
+                       MEM_WB((X86_BH << 1) + 0x0450, X86_DL);
+                       MEM_WB((X86_BH << 1) + 0x0451, X86_DH);
+
+                       if (X86_BH != MEM_RB(0x0462))
+                               break;
+
+                       offset = (X86_DH * MEM_RW(0x044A)) + X86_DL;
+                       offset += MEM_RW(0x044E) << 1;
+
+                       ioport = MEM_RW(0x0463);
+                       outb(ioport, 0x0E);
+                       outb(ioport + 1, offset >> 8);
+                       outb(ioport, 0x0F);
+                       outb(ioport + 1, offset & 0xFF);
+               }
+               break;
+
+       case 0x03:
+               /* Get Cursor Position                                */
+               /* Enter:  BH = display page number                   */
+               /* Leave:  CH = starting line for cursor              */
+               /*         CL = ending line for cursor                */
+               /*         DH = row                                   */
+               /*         DL = column                                */
+               /* Implemented                                        */
+               {               /* Localise */
+                       X86_CL = MEM_RB(0x0460);
+                       X86_CH = MEM_RB(0x0461);
+                       X86_DL = MEM_RB((X86_BH << 1) + 0x0450);
+                       X86_DH = MEM_RB((X86_BH << 1) + 0x0451);
+               }
+               break;
+
+       case 0x04:
+               /* Get Light Pen Position                             */
+               /* Enter:  Nothing                                    */
+               /* Leave:  AH = 0x01 (down/triggered) or 0x00 (not)   */
+               /*         BX = pixel column                          */
+               /*         CX = pixel row                             */
+               /*         DH = character row                         */
+               /*         DL = character column                      */
+               /* Not Implemented                                    */
+               {               /* Localise */
+                       printf("int%x - Get Light Pen Position. "
+                              "Function not implemented.\n",
+                              current->num);
+                       x86emu_dump_xregs();
+                       X86_AH = X86_BX = X86_CX = X86_DX = 0;
+               }
+               break;
+
+       case 0x05:
+               /* Set Display Page                                   */
+               /* Enter:  AL = display page number                   */
+               /* Leave:  Nothing                                    */
+               /* Implemented                                        */
+               {               /* Localise */
+                       u16 start, ioport = MEM_RW(0x0463);
+                       u8 x, y;
+
+                       /* Calculate new start address */
+                       MEM_WB(0x0462, X86_AL);
+                       start = X86_AL * MEM_RW(0x044C);
+                       MEM_WW(0x044E, start);
+                       start <<= 1;
+
+                       /* Update start address */
+                       outb(ioport, 0x0C);
+                       outb(ioport + 1, start >> 8);
+                       outb(ioport, 0x0D);
+                       outb(ioport + 1, start & 0xFF);
+
+                       /* Switch cursor position */
+                       y = MEM_RB((X86_AL << 1) + 0x0450);
+                       x = MEM_RB((X86_AL << 1) + 0x0451);
+                       start += (y * MEM_RW(0x044A)) + x;
+
+                       /* Update cursor position */
+                       outb(ioport, 0x0E);
+                       outb(ioport + 1, start >> 8);
+                       outb(ioport, 0x0F);
+                       outb(ioport + 1, start & 0xFF);
+               }
+               break;
+
+       case 0x06:
+               /* Initialise or Scroll Window Up                     */
+               /* Enter:  AL = lines to scroll up                    */
+               /*         BH = attribute for blank                   */
+               /*         CH = upper y of window                     */
+               /*         CL = left x of window                      */
+               /*         DH = lower y of window                     */
+               /*         DL = right x of window                     */
+               /* Leave:  Nothing                                    */
+               /* Not Implemented                                    */
+               {               /* Localise */
+                       printf("int%x: Initialise or Scroll Window Up - "
+                              "Function not implemented.\n",
+                              current->num);
+                       x86emu_dump_xregs();
+               }
+               break;
+
+       case 0x07:
+               /* Initialise or Scroll Window Down                   */
+               /* Enter:  AL = lines to scroll down                  */
+               /*         BH = attribute for blank                   */
+               /*         CH = upper y of window                     */
+               /*         CL = left x of window                      */
+               /*         DH = lower y of window                     */
+               /*         DL = right x of window                     */
+               /* Leave:  Nothing                                    */
+               /* Not Implemented                                    */
+               {               /* Localise */
+                       printf("int%x: Initialise or Scroll Window Down - "
+                              "Function not implemented.\n",
+                              current->num);
+                       x86emu_dump_xregs();
+
+               }
+               break;
+
+       case 0x08:
+               /* Read Character and Attribute at Cursor             */
+               /* Enter:  BH = display page number                   */
+               /* Leave:  AH = attribute                             */
+               /*         AL = character                             */
+               /* Not Implemented                                    */
+               {               /* Localise */
+                       printf
+                           ("int%x: Read Character and Attribute at Cursor - "
+                            "Function not implemented.\n", current->num);
+                       x86emu_dump_xregs();
+
+                       X86_AX = 0;
+               }
+               break;
+
+       case 0x09:
+               /* Write Character and Attribute at Cursor            */
+               /* Enter:  AL = character                             */
+               /*         BH = display page number                   */
+               /*         BL = attribute (text) or colour (graphics) */
+               /*         CX = replication count                     */
+               /* Leave:  Nothing                                    */
+               /* Not Implemented                                    */
+               {               /* Localise */
+                       printf
+                           ("int%x: Write Character and Attribute at Cursor - "
+                            "Function not implemented.\n", current->num);
+                       x86emu_dump_xregs();
+
+               }
+               break;
+
+       case 0x0a:
+               /* Write Character at Cursor                          */
+               /* Enter:  AL = character                             */
+               /*         BH = display page number                   */
+               /*         BL = colour                                */
+               /*         CX = replication count                     */
+               /* Leave:  Nothing                                    */
+               /* Not Implemented                                    */
+               {               /* Localise */
+                       printf("int%x: Write Character at Cursor - "
+                              "Function not implemented.\n",
+                              current->num);
+                       x86emu_dump_xregs();
+
+               }
+               break;
+
+       case 0x0b:
+               /* Set Palette, Background or Border                  */
+               /* Enter:  BH = 0x00 or 0x01                          */
+               /*         BL = colour or palette (respectively)      */
+               /* Leave:  Nothing                                    */
+               /* Implemented                                        */
+               {               /* Localise */
+                       u16 ioport = MEM_RW(0x0463) + 5;
+                       u8 cgacolour = MEM_RB(0x0466);
+
+                       if (X86_BH) {
+                               cgacolour &= 0xDF;
+                               cgacolour |= (X86_BL & 0x01) << 5;
+                       } else {
+                               cgacolour &= 0xE0;
+                               cgacolour |= X86_BL & 0x1F;
+                       }
+
+                       MEM_WB(0x0466, cgacolour);
+                       outb(ioport, cgacolour);
+               }
+               break;
+
+       case 0x0c:
+               /* Write Graphics Pixel                               */
+               /* Enter:  AL = pixel value                           */
+               /*         BH = display page number                   */
+               /*         CX = column                                */
+               /*         DX = row                                   */
+               /* Leave:  Nothing                                    */
+               /* Not Implemented                                    */
+               {               /* Localise */
+                       printf("int%x: Write Graphics Pixel - "
+                              "Function not implemented.\n",
+                              current->num);
+                       x86emu_dump_xregs();
+
+               }
+               break;
+
+       case 0x0d:
+               /* Read Graphics Pixel                                */
+               /* Enter:  BH = display page number                   */
+               /*         CX = column                                */
+               /*         DX = row                                   */
+               /* Leave:  AL = pixel value                           */
+               /* Not Implemented                                    */
+               {               /* Localise */
+                       printf("int%x: Write Graphics Pixel - "
+                              "Function not implemented.\n",
+                              current->num);
+                       x86emu_dump_xregs();
+
+                       X86_AL = 0;
+
+               }
+               break;
+
+       case 0x0e:
+               /* Write Character in Teletype Mode                   */
+               /* Enter:  AL = character                             */
+               /*         BH = display page number                   */
+               /*         BL = foreground colour                     */
+               /* Leave:  Nothing                                    */
+               /* Not Implemented                                    */
+               /* WARNING:  Emulation of BEL characters will require */
+               /*           emulation of RTC and PC speaker I/O.     */
+               /*           Also, this recurses through int 0x10     */
+               /*           which might or might not have been       */
+               /*           installed yet.                           */
+               {               /* Localise */
+#ifdef PARANOID
+                       printf("int%x: Write Character in Teletype Mode - "
+                              "Function not implemented.\n",
+                              current->num);
+                       x86emu_dump_xregs();
+#endif
+                       printf("%c", X86_AL);
+               }
+               break;
+
+       case 0x0f:
+               /* Get Video Mode                                     */
+               /* Enter:  Nothing                                    */
+               /* Leave:  AH = number of columns                     */
+               /*         AL = video mode number                     */
+               /*         BH = display page number                   */
+               /* Implemented                                        */
+               {               /* Localise */
+                       X86_AH = MEM_RW(0x044A);
+                       X86_AL = MEM_RB(0x0449);
+                       X86_BH = MEM_RB(0x0462);
+               }
+               break;
+
+       case 0x10:
+               /* Colour Control (subfunction in AL)                 */
+               /* Enter:  Various                                    */
+               /* Leave:  Various                                    */
+               /* Ignored                                            */
+               break;
+
+       case 0x11:
+               /* Font Control (subfunction in AL)                   */
+               /* Enter:  Various                                    */
+               /* Leave:  Various                                    */
+               /* Ignored                                            */
+               break;
+
+       case 0x12:
+               /* Miscellaneous (subfunction in BL)                  */
+               /* Enter:  Various                                    */
+               /* Leave:  Various                                    */
+               /* Ignored.  Previous code here optionally allowed    */
+               /* the enabling and disabling of VGA, but no system   */
+               /* BIOS I've come across actually implements it.      */
+               break;
+
+       case 0x13:
+               /* Write String in Teletype Mode                      */
+               /* Enter:  AL = write mode                            */
+               /*         BL = attribute (if (AL & 0x02) == 0)       */
+               /*         CX = string length                         */
+               /*         DH = row                                   */
+               /*         DL = column                                */
+               /*         ES:BP = string segment:offset              */
+               /* Leave:  Nothing                                    */
+               /* Not Implemented                                    */
+               /* WARNING:  Emulation of BEL characters will require */
+               /*           emulation of RTC and PC speaker I/O.     */
+               /*           Also, this recurses through int 0x10     */
+               /*           which might or might not have been       */
+               /*           installed yet.                           */
+               {               /* Localise */
+                       printf ("int%x: Write String in Teletype Mode - "
+                               "Function not implemented.\n", current->num);
+                       x86emu_dump_xregs();
+
+               }
+               break;
+
+       default:
+               /* Various extensions                                 */
+               /* Enter:  Various                                    */
+               /* Leave:  Various                                    */
+               /* Ignored                                            */
+               break;
+       }
+
+       return 1;
+}
+#endif
diff -urN new/freebios/util/vgabios/int15.c freebios/util/vgabios/int15.c
--- new/freebios/util/vgabios/int15.c   Thu Jan  1 01:00:00 1970
+++ freebios/util/vgabios/int15.c       Sat Apr 20 09:54:53 2002
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include "test.h"
+
+void x86emu_dump_xregs();
+
+int int15_handler(void)
+{
+       printf("\nint15 encountered.\n");
+       x86emu_dump_xregs();
+       X86_EAX = 0;
+       return 1;
+}
diff -urN new/freebios/util/vgabios/int16.c freebios/util/vgabios/int16.c
--- new/freebios/util/vgabios/int16.c   Thu Jan  1 01:00:00 1970
+++ freebios/util/vgabios/int16.c       Sat Apr 20 09:54:44 2002
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int int16_handler(void)
+{
+       printf("\nint16: keyboard not supported right now.\n");
+       return 1;
+}
diff -urN new/freebios/util/vgabios/int1a.c freebios/util/vgabios/int1a.c
--- new/freebios/util/vgabios/int1a.c   Thu Jan  1 01:00:00 1970
+++ freebios/util/vgabios/int1a.c       Sat Apr 20 10:11:30 2002
@@ -0,0 +1,178 @@
+#include <stdio.h>
+#include "test.h"
+#include "pci-userspace.h"
+
+#define DEBUG_INT1A
+
+#define SUCCESSFUL              0x00
+#define DEVICE_NOT_FOUND        0x86
+#define BAD_REGISTER_NUMBER     0x87
+
+void x86emu_dump_xregs(void);
+extern int verbose;
+
+
+int int1A_handler()
+{
+       PCITAG tag;
+       pciVideoPtr pvp=NULL;
+
+       if (verbose) {
+               printf("\nint1a encountered.\n");
+               x86emu_dump_xregs();
+       }
+
+       switch (X86_AX) {
+       case 0xb101:
+               X86_EAX = 0x00; /* no config space/special cycle support */
+               X86_AL  = 0x01; /* config mechanism 1 */
+               X86_EDX = 0x20494350;   /* " ICP" */
+               X86_EBX = 0x0210;       /* Version 2.10 */
+               X86_ECX &= 0xFF00;
+               X86_ECX |= (pciNumBuses & 0xFF);        /* Max bus number in system */
+               X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+#ifdef DEBUG_INT1A
+               if (verbose)
+                       printf("PCI bios present.\n");
+#endif
+               return 1;
+       case 0xb102:
+               if (X86_DX == pvp->vendor_id && X86_CX == pvp->device_id
+                   && X86_ESI == 0) {
+                       X86_EAX = X86_AL | (SUCCESSFUL << 8);
+                       X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+                       X86_EBX = pciSlotBX(pvp);
+               }
+#ifdef SHOW_ALL_DEVICES
+               else if ((pvp =
+                         xf86FindPciDeviceVendor(X86_EDX, X86_ECX, X86_ESI, pvp))) {
+                       X86_EAX = X86_AL | (SUCCESSFUL << 8);
+                       X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+                       X86_EBX = pciSlotBX(pvp);
+               }
+#endif
+               else {
+                       X86_EAX = X86_AL | (DEVICE_NOT_FOUND << 8);
+                       X86_EFLAGS |= ((unsigned long) 0x01);   /* set carry flag */
+               }
+#ifdef DEBUG_INT1A
+               printf("eax=0x%x ebx=0x%x eflags=0x%x\n", X86_EAX, X86_EBX,
+                      X86_EFLAGS);
+#endif
+               return 1;
+       case 0xb103:
+#if 0
+               if (X86_CL == pvp->interface &&
+                   X86_CH == pvp->subclass &&
+                   ((X86_ECX & 0xFFFF0000) >> 16) == pvp->class) {
+                       X86_EAX = X86_AL | (SUCCESSFUL << 8);
+                       X86_EBX = pciSlotBX(pvp);
+                       X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+               }
+#else
+               /* FIXME: dirty hack */
+               if (0) ;
+#endif
+#ifdef SHOW_ALL_DEVICES
+               else if ((pvp = FindPciClass(X86_CL, X86_CH,
+                                            (X86_ECX & 0xffff0000) >> 16,
+                                            X86_ESI, pvp))) {
+                       X86_EAX = X86_AL | (SUCCESSFUL << 8);
+                       X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+                       X86_EBX = pciSlotBX(pvp);
+               }
+#endif
+               else {
+                       X86_EAX = X86_AL | (DEVICE_NOT_FOUND << 8);
+                       X86_EFLAGS |= ((unsigned long) 0x01);   /* set carry flag */
+               }
+#ifdef DEBUG_INT1A
+               printf("eax=0x%x eflags=0x%x\n", X86_EAX, X86_EFLAGS);
+#endif
+               return 1;
+       case 0xb108:
+               if ((tag = findPci(X86_EBX))) {
+                       X86_CL = pciReadByte(tag, X86_EDI);
+                       X86_EAX = X86_AL | (SUCCESSFUL << 8);
+                       X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+               } else {
+                       X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
+                       X86_EFLAGS |= ((unsigned long) 0x01);   /* set carry flag */
+               }
+#ifdef DEBUG_INT1A
+               printf("eax=0x%x ecx=0x%x eflags=0x%x\n", X86_EAX, X86_ECX,
+                      X86_EFLAGS);
+#endif
+               return 1;
+       case 0xb109:
+               if ((tag = findPci(X86_EBX))) {
+                       X86_CX = pciReadWord(tag, X86_EDI);
+                       X86_EAX = X86_AL | (SUCCESSFUL << 8);
+                       X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+               } else {
+                       X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
+                       X86_EFLAGS |= ((unsigned long) 0x01);   /* set carry flag */
+               }
+#ifdef DEBUG_INT1A
+               printf("eax=0x%x ecx=0x%x eflags=0x%x\n", X86_EAX, X86_ECX,
+                               X86_EFLAGS);
+#endif
+               return 1;
+       case 0xb10a:
+               if ((tag = findPci(X86_EBX))) {
+                       X86_ECX = pciReadLong(tag, X86_EDI);
+                       X86_EAX = X86_AL | (SUCCESSFUL << 8);
+                       X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+               } else {
+                       X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
+                       X86_EFLAGS |= ((unsigned long) 0x01);   /* set carry flag */
+               }
+#ifdef DEBUG_INT1A
+               printf("eax=0x%x ecx=0x%x eflags=0x%x\n", X86_EAX, X86_ECX,
+                      X86_EFLAGS);
+#endif
+               return 1;
+       case 0xb10b:
+               if ((tag = findPci(X86_EBX))) {
+                       pciWriteByte(tag, X86_EDI, X86_CL);
+                       X86_EAX = X86_AL | (SUCCESSFUL << 8);
+                       X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+               } else {
+                       X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
+                       X86_EFLAGS |= ((unsigned long) 0x01);   /* set carry flag */
+               }
+#ifdef DEBUG_INT1A
+               printf("eax=0x%x eflags=0x%x\n", X86_EAX, X86_EFLAGS);
+#endif
+               return 1;
+       case 0xb10c:
+               if ((tag = findPci(X86_EBX))) {
+                       pciWriteWord(tag, X86_EDI, X86_CX);
+                       X86_EAX = X86_AL | (SUCCESSFUL << 8);
+                       X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+               } else {
+                       X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
+                       X86_EFLAGS |= ((unsigned long) 0x01);   /* set carry flag */
+               }
+#ifdef DEBUG_INT1A
+               printf("eax=0x%x eflags=0x%x\n", X86_EAX, X86_EFLAGS);
+#endif
+               return 1;
+       case 0xb10d:
+               if ((tag = findPci(X86_EBX))) {
+                       pciWriteLong(tag, X86_EDI, X86_ECX);
+                       X86_EAX = X86_AL | (SUCCESSFUL << 8);
+                       X86_EFLAGS &= ~((unsigned long) 0x01);  /* clear carry flag */
+               } else {
+                       X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
+                       X86_EFLAGS |= ((unsigned long) 0x01);   /* set carry flag */
+               }
+#ifdef DEBUG_INT1A
+               printf("eax=0x%x eflags=0x%x\n", X86_EAX, X86_EFLAGS);
+#endif
+               return 1;
+       default:
+               printf("int1a: subfunction not implemented.\n");
+               return 0;
+       }
+}
diff -urN new/freebios/util/vgabios/inte6.c freebios/util/vgabios/inte6.c
--- new/freebios/util/vgabios/inte6.c   Thu Jan  1 01:00:00 1970
+++ freebios/util/vgabios/inte6.c       Sat Apr 20 09:54:42 2002
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+int intE6_handler()
+{
+#if 0
+       pciVideoPtr pvp;
+
+       if ((pvp = xf86GetPciInfoForEntity(pInt->entityIndex)))
+               X86_AX =
+                   (pvp->bus << 8) | (pvp->device << 3) | (pvp->
+                                                           func & 0x7);
+       pushw(X86_CS);
+       pushw(X86_IP);
+       X86_CS = pInt->BIOSseg;
+       X86_EIP = 0x0003;
+       X86_ES = 0;             /* standard pc es */
+#endif
+       printf("intE6 not supported right now.\n");
+       return 1;
+}
diff -urN new/freebios/util/vgabios/inthandler.c freebios/util/vgabios/inthandler.c
--- new/freebios/util/vgabios/inthandler.c      Thu Apr 18 02:34:04 2002
+++ freebios/util/vgabios/inthandler.c  Thu Apr 18 08:48:06 2002
@@ -1,720 +0,0 @@
-#include "test.h"
-#define ErrorF(x...) printf(x);
-#define xf86Int10InfoPtr ptr
-#define REG pInt
-#define PRINT_INT
-#define outb x_outb
-#include "pci-userspace.h"
-
-void x86emu_dump_xregs (void);
-
-static int int1A_handler(ptr pInt);
-#ifndef _PC
-static int int42_handler(ptr pInt);
-#endif
-static int intE6_handler(ptr pInt);
-
-extern ptr current;
-
-void setup_int(void)
-{
-       pciInit();
-}
-
-void exit_int(void)
-{
-       pciExit();
-}
-
-void do_int(int num)
-{
-       int_handler(num);
-}
-
-int
-int_handler(int num)
-{
-
-    ptr pInt=current;
-    int ret = 0;
-
-    pInt->num=num;
-    switch (num) {
-#ifndef _PC
-    case 0x10:
-    case 0x42:
-    case 0x6D:
-#if 0
-       if (getIntVect(pInt, num) == I_S_DEFAULT_INT_VECT)
-#endif
-           ret = int42_handler(pInt);
-       break;
-#endif
-    case 0x1A:
-       ret = int1A_handler(pInt);
-       break;
-    case 0xe6:
-       ret = intE6_handler(pInt);
-       break;
-    default:
-       break;
-    }
-
-    //if (!ret)
-    // ret = run_bios_int(num, pInt);
-
-    if (!ret)
-        x86emu_dump_xregs();
-
-    return ret;
-}
-
-#ifndef _PC
-/*
- * This is derived from a number of PC system BIOS'es.  The intent here is to
- * provide very primitive video support, before an EGA/VGA BIOS installs its
- * own interrupt vector.  Here, "Ignored" calls should remain so.  "Not
- * Implemented" denotes functionality that can be implemented should the need
- * arise.  What are "Not Implemented" throughout are video memory accesses.
- * Also, very little input validity checking is done here.
- */
-static int
-int42_handler(xf86Int10InfoPtr pInt)
-{
-    switch (X86_AH) {
-    case 0x00:
-       /* Set Video Mode                                     */
-       /* Enter:  AL = video mode number                     */
-       /* Leave:  Nothing                                    */
-       /* Implemented (except for clearing the screen)       */
-       {                                         /* Localise */
-           int i;
-           CARD16 ioport, int1d, regvals, tmp;
-           CARD8 mode, cgamode, cgacolour;
-
-           /*
-            * Ignore all mode numbers but 0x00-0x13.  Some systems also ignore
-            * 0x0B and 0x0C, but don't do that here.
-            */
-           if (X86_AL > 0x13)
-               break;
-
-           /*
-            * You didn't think that was really the mode set, did you?  There
-            * are only so many slots in the video parameter table...
-            */
-           mode = X86_AL;
-           ioport = 0x03D4;
-           switch (MEM_RB(pInt, 0x0410) & 0x30) {
-           case 0x30:                  /* MDA */
-               mode = 0x07;            /* Force mode to 0x07 */
-               ioport = 0x03B4;
-               break;
-           case 0x10:                  /* CGA 40x25 */
-               if (mode >= 0x07)
-                   mode = 0x01;
-               break;
-           case 0x20:                  /* CGA 80x25 (MCGA?) */
-               if (mode >= 0x07)
-                   mode = 0x03;
-               break;
-           case 0x00:                  /* EGA/VGA */
-               if (mode >= 0x07)       /* Don't try MDA timings */
-                   mode = 0x01;        /* !?!?! */
-               break;
-           }
-
-           /* Locate data in video parameter table */
-           int1d = MEM_RW(pInt, 0x1d << 2);
-           regvals = ((mode >> 1) << 4) + int1d;
-           cgacolour = 0x30;
-           if (mode == 0x06) {
-               regvals -= 0x10;
-               cgacolour = 0x3F;
-           }
-
-           /** Update BIOS Data Area **/
-
-           /* Video mode */
-           MEM_WB(pInt, 0x0449, mode);
-
-           /* Columns */
-           tmp = MEM_RB(pInt, mode + int1d + 0x48);
-           MEM_WW(pInt, 0x044A, tmp);
-
-           /* Page length */
-           tmp = MEM_RW(pInt, (mode & 0x06) + int1d + 0x40);
-           MEM_WW(pInt, 0x044C, tmp);
-
-           /* Start Address */
-           MEM_WW(pInt, 0x044E, 0);
-
-           /* Cursor positions, one for each display page */
-           for (i = 0x0450; i < 0x0460; i += 2)
-               MEM_WW(pInt, i, 0);
-
-           /* Cursor start & end scanlines */
-           tmp = MEM_RB(pInt, regvals + 0x0B);
-           MEM_WB(pInt, 0x0460, tmp);
-           tmp = MEM_RB(pInt, regvals + 0x0A);
-           MEM_WB(pInt, 0x0461, tmp);
-
-           /* Current display page number */
-           MEM_WB(pInt, 0x0462, 0);
-
-           /* CRTC I/O address */
-           MEM_WW(pInt, 0x0463, ioport);
-
-           /* CGA Mode register value */
-           cgamode = MEM_RB(pInt, mode + int1d + 0x50);
-           MEM_WB(pInt, 0x0465, cgamode);
-
-           /* CGA Colour register value */
-           MEM_WB(pInt, 0x0466, cgacolour);
-
-           /* Rows */
-           MEM_WB(pInt, 0x0484, (25 - 1));
-
-           /* Programme the mode */
-           outb(ioport + 4, cgamode & 0x37);   /* Turn off screen */
-           for (i = 0; i < 0x10; i++) {
-               tmp = MEM_RB(pInt, regvals + i);
-               outb(ioport, i);
-               outb(ioport + 1, tmp);
-           }
-           outb(ioport + 5, cgacolour);        /* Select colour mode */
-           outb(ioport + 4, cgamode);          /* Turn on screen */
-       }
-       break;
-
-    case 0x01:
-       /* Set Cursor Type                                    */
-       /* Enter:  CH = starting line for cursor              */
-       /*         CL = ending line for cursor                */
-       /* Leave:  Nothing                                    */
-       /* Implemented                                        */
-       {                                         /* Localise */
-           CARD16 ioport = MEM_RW(pInt, 0x0463);
-
-           MEM_WB(pInt, 0x0460, X86_CL);
-           MEM_WB(pInt, 0x0461, X86_CH);
-
-           outb(ioport, 0x0A);
-           outb(ioport + 1, X86_CH);
-           outb(ioport, 0x0B);
-           outb(ioport + 1, X86_CL);
-       }
-       break;
-
-    case 0x02:
-       /* Set Cursor Position                                */
-       /* Enter:  BH = display page number                   */
-       /*         DH = row                                   */
-       /*         DL = column                                */
-       /* Leave:  Nothing                                    */
-       /* Implemented                                        */
-       {                                         /* Localise */
-           CARD16 offset, ioport;
-
-           MEM_WB(pInt, (X86_BH << 1) + 0x0450, X86_DL);
-           MEM_WB(pInt, (X86_BH << 1) + 0x0451, X86_DH);
-
-           if (X86_BH != MEM_RB(pInt, 0x0462))
-               break;
-
-           offset = (X86_DH * MEM_RW(pInt, 0x044A)) + X86_DL;
-           offset += MEM_RW(pInt, 0x044E) << 1;
-
-           ioport = MEM_RW(pInt, 0x0463);
-           outb(ioport, 0x0E);
-           outb(ioport + 1, offset >> 8);
-           outb(ioport, 0x0F);
-           outb(ioport + 1, offset & 0xFF);
-       }
-       break;
-
-    case 0x03:
-       /* Get Cursor Position                                */
-       /* Enter:  BH = display page number                   */
-       /* Leave:  CH = starting line for cursor              */
-       /*         CL = ending line for cursor                */
-       /*         DH = row                                   */
-       /*         DL = column                                */
-       /* Implemented                                        */
-       {                                         /* Localise */
-           X86_CL = MEM_RB(pInt, 0x0460);
-           X86_CH = MEM_RB(pInt, 0x0461);
-           X86_DL = MEM_RB(pInt, (X86_BH << 1) + 0x0450);
-           X86_DH = MEM_RB(pInt, (X86_BH << 1) + 0x0451);
-       }
-       break;
-
-    case 0x04:
-       /* Get Light Pen Position                             */
-       /* Enter:  Nothing                                    */
-       /* Leave:  AH = 0x01 (down/triggered) or 0x00 (not)   */
-       /*         BX = pixel column                          */
-       /*         CX = pixel row                             */
-       /*         DH = character row                         */
-       /*         DL = character column                      */
-       /* Not Implemented                                    */
-       {                                         /* Localise */
-           printf( "int%x - Get Light Pen Position. "
-               "Function not implemented.\n", pInt->num);
-           x86emu_dump_xregs();
-           X86_AH = X86_BX = X86_CX = X86_DX = 0;
-       }
-       break;
-
-    case 0x05:
-       /* Set Display Page                                   */
-       /* Enter:  AL = display page number                   */
-       /* Leave:  Nothing                                    */
-       /* Implemented                                        */
-       {                                         /* Localise */
-           CARD16 start, ioport = MEM_RW(pInt, 0x0463);
-           CARD8 x, y;
-
-           /* Calculate new start address */
-           MEM_WB(pInt, 0x0462, X86_AL);
-           start = X86_AL * MEM_RW(pInt, 0x044C);
-           MEM_WW(pInt, 0x044E, start);
-           start <<= 1;
-
-           /* Update start address */
-           outb(ioport, 0x0C);
-           outb(ioport + 1, start >> 8);
-           outb(ioport, 0x0D);
-           outb(ioport + 1, start & 0xFF);
-
-           /* Switch cursor position */
-           y = MEM_RB(pInt, (X86_AL << 1) + 0x0450);
-           x = MEM_RB(pInt, (X86_AL << 1) + 0x0451);
-           start += (y * MEM_RW(pInt, 0x044A)) + x;
-
-           /* Update cursor position */
-           outb(ioport, 0x0E);
-           outb(ioport + 1, start >> 8);
-           outb(ioport, 0x0F);
-           outb(ioport + 1, start & 0xFF);
-       }
-       break;
-
-    case 0x06:
-       /* Initialise or Scroll Window Up                     */
-       /* Enter:  AL = lines to scroll up                    */
-       /*         BH = attribute for blank                   */
-       /*         CH = upper y of window                     */
-       /*         CL = left x of window                      */
-       /*         DH = lower y of window                     */
-       /*         DL = right x of window                     */
-       /* Leave:  Nothing                                    */
-       /* Not Implemented                                    */
-       {                                         /* Localise */
-       printf( "int%x: Initialise or Scroll Window Up - "
-               "Function not implemented.\n", pInt->num);
-       x86emu_dump_xregs();
-       }
-       break;
-
-    case 0x07:
-       /* Initialise or Scroll Window Down                   */
-       /* Enter:  AL = lines to scroll down                  */
-       /*         BH = attribute for blank                   */
-       /*         CH = upper y of window                     */
-       /*         CL = left x of window                      */
-       /*         DH = lower y of window                     */
-       /*         DL = right x of window                     */
-       /* Leave:  Nothing                                    */
-       /* Not Implemented                                    */
-       {                                         /* Localise */
-        printf( "int%x: Initialise or Scroll Window Down - "
-               "Function not implemented.\n", pInt->num);
-        x86emu_dump_xregs();
-
-       }
-       break;
-
-    case 0x08:
-       /* Read Character and Attribute at Cursor             */
-       /* Enter:  BH = display page number                   */
-       /* Leave:  AH = attribute                             */
-       /*         AL = character                             */
-       /* Not Implemented                                    */
-       {                                         /* Localise */
-            printf( "int%x: Read Character and Attribute at Cursor - "
-               "Function not implemented.\n", pInt->num);
-            x86emu_dump_xregs();
-
-           X86_AX = 0;
-       }
-       break;
-
-    case 0x09:
-       /* Write Character and Attribute at Cursor            */
-       /* Enter:  AL = character                             */
-       /*         BH = display page number                   */
-       /*         BL = attribute (text) or colour (graphics) */
-       /*         CX = replication count                     */
-       /* Leave:  Nothing                                    */
-       /* Not Implemented                                    */
-       {                                         /* Localise */
-        printf( "int%x: Write Character and Attribute at Cursor - "
-               "Function not implemented.\n", pInt->num);
-        x86emu_dump_xregs();
-
-       }
-       break;
-
-    case 0x0a:
-       /* Write Character at Cursor                          */
-       /* Enter:  AL = character                             */
-       /*         BH = display page number                   */
-       /*         BL = colour                                */
-       /*         CX = replication count                     */
-       /* Leave:  Nothing                                    */
-       /* Not Implemented                                    */
-       {                                         /* Localise */
-        printf( "int%x: Write Character at Cursor - "
-               "Function not implemented.\n", pInt->num);
-        x86emu_dump_xregs();
-
-       }
-       break;
-
-    case 0x0b:
-       /* Set Palette, Background or Border                  */
-       /* Enter:  BH = 0x00 or 0x01                          */
-       /*         BL = colour or palette (respectively)      */
-       /* Leave:  Nothing                                    */
-       /* Implemented                                        */
-       {                                         /* Localise */
-           CARD16 ioport = MEM_RW(pInt, 0x0463) + 5;
-           CARD8 cgacolour = MEM_RB(pInt, 0x0466);
-
-           if (X86_BH) {
-               cgacolour &= 0xDF;
-               cgacolour |= (X86_BL & 0x01) << 5;
-           } else {
-               cgacolour &= 0xE0;
-               cgacolour |= X86_BL & 0x1F;
-           }
-
-           MEM_WB(pInt, 0x0466, cgacolour);
-           outb(ioport, cgacolour);
-       }
-       break;
-
-    case 0x0c:
-       /* Write Graphics Pixel                               */
-       /* Enter:  AL = pixel value                           */
-       /*         BH = display page number                   */
-       /*         CX = column                                */
-       /*         DX = row                                   */
-       /* Leave:  Nothing                                    */
-       /* Not Implemented                                    */
-       {                                         /* Localise */
-       printf( "int%x: Write Graphics Pixel - "
-               "Function not implemented.\n", pInt->num);
-        x86emu_dump_xregs();
-
-       }
-       break;
-
-    case 0x0d:
-       /* Read Graphics Pixel                                */
-       /* Enter:  BH = display page number                   */
-       /*         CX = column                                */
-       /*         DX = row                                   */
-       /* Leave:  AL = pixel value                           */
-       /* Not Implemented                                    */
-       {                                         /* Localise */
-       printf( "int%x: Write Graphics Pixel - "
-               "Function not implemented.\n", pInt->num);
-        x86emu_dump_xregs();
-
-       X86_AL = 0;
-
-       }
-       break;
-
-    case 0x0e:
-       /* Write Character in Teletype Mode                   */
-       /* Enter:  AL = character                             */
-       /*         BH = display page number                   */
-       /*         BL = foreground colour                     */
-       /* Leave:  Nothing                                    */
-       /* Not Implemented                                    */
-       /* WARNING:  Emulation of BEL characters will require */
-       /*           emulation of RTC and PC speaker I/O.     */
-       /*           Also, this recurses through int 0x10     */
-       /*           which might or might not have been       */
-       /*           installed yet.                           */
-       {                                         /* Localise */
-#ifdef PARANOID
-       printf( "int%x: Write Character in Teletype Mode - "
-               "Function not implemented.\n", pInt->num);
-        x86emu_dump_xregs();
-#endif
-       printf("%c",X86_AL);
-       }
-       break;
-
-    case 0x0f:
-       /* Get Video Mode                                     */
-       /* Enter:  Nothing                                    */
-       /* Leave:  AH = number of columns                     */
-       /*         AL = video mode number                     */
-       /*         BH = display page number                   */
-       /* Implemented                                        */
-       {                                         /* Localise */
-           X86_AH = MEM_RW(pInt, 0x044A);
-           X86_AL = MEM_RB(pInt, 0x0449);
-           X86_BH = MEM_RB(pInt, 0x0462);
-       }
-       break;
-
-    case 0x10:
-       /* Colour Control (subfunction in AL)                 */
-       /* Enter:  Various                                    */
-       /* Leave:  Various                                    */
-       /* Ignored                                            */
-       break;
-
-    case 0x11:
-       /* Font Control (subfunction in AL)                   */
-       /* Enter:  Various                                    */
-       /* Leave:  Various                                    */
-       /* Ignored                                            */
-       break;
-
-    case 0x12:
-       /* Miscellaneous (subfunction in BL)                  */
-       /* Enter:  Various                                    */
-       /* Leave:  Various                                    */
-       /* Ignored.  Previous code here optionally allowed    */
-       /* the enabling and disabling of VGA, but no system   */
-       /* BIOS I've come across actually implements it.      */
-       break;
-
-    case 0x13:
-       /* Write String in Teletype Mode                      */
-       /* Enter:  AL = write mode                            */
-       /*         BL = attribute (if (AL & 0x02) == 0)       */
-       /*         CX = string length                         */
-       /*         DH = row                                   */
-       /*         DL = column                                */
-       /*         ES:BP = string segment:offset              */
-       /* Leave:  Nothing                                    */
-       /* Not Implemented                                    */
-       /* WARNING:  Emulation of BEL characters will require */
-       /*           emulation of RTC and PC speaker I/O.     */
-       /*           Also, this recurses through int 0x10     */
-       /*           which might or might not have been       */
-       /*           installed yet.                           */
-       {                                         /* Localise */
-       printf("int%x: Write String in Teletype Mode - Function not implemented.\n", 
pInt->num);
-        x86emu_dump_xregs();
-
-       }
-       break;
-
-    default:
-       /* Various extensions                                 */
-       /* Enter:  Various                                    */
-       /* Leave:  Various                                    */
-       /* Ignored                                            */
-       break;
-    }
-
-    return 1;
-}
-#endif
-
-#define SUCCESSFUL              0x00
-#define DEVICE_NOT_FOUND        0x86
-#define BAD_REGISTER_NUMBER     0x87
-
-static int
-int1A_handler(xf86Int10InfoPtr pInt)
-{
-    PCITAG tag;
-    pciVideoPtr pvp;
-
-//    if (!(pvp = xf86GetPciInfoForEntity(pInt->entityIndex)))
-//     return 0; /* oops */
-
-#ifdef PRINT_INT
-    ErrorF("\nint 0x1a: ax=0x%x bx=0x%x cx=0x%x dx=0x%x di=0x%x es=0x%x\n",
-           X86_EAX, X86_EBX, X86_ECX, X86_EDX, X86_EDI, X86_ESI);
-#endif
-    switch (X86_AX) {
-    case 0xb101:
-       X86_EAX &= 0xFF00;   /* no config space/special cycle support */
-       X86_EDX = 0x20494350; /* " ICP" */
-       X86_EBX = 0x0210;    /* Version 2.10 */
-       X86_ECX &= 0xFF00;
-       X86_ECX |= (pciNumBuses & 0xFF);   /* Max bus number in system */
-       X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-#ifdef PRINT_INT
-       ErrorF("ax=0x%x dx=0x%x bx=0x%x cx=0x%x flags=0x%x\n",
-                X86_EAX, X86_EDX, X86_EBX, X86_ECX, X86_EFLAGS);
-#endif
-       return 1;
-    case 0xb102:
-       if (X86_DX == pvp->vendor_id && X86_CX == pvp->device_id && X86_ESI == 0) {
-           X86_EAX = X86_AL | (SUCCESSFUL << 8);
-           X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-           X86_EBX = pciSlotBX(pvp);
-       }
-#ifdef SHOW_ALL_DEVICES
-       else
-       if ((pvp = xf86FindPciDeviceVendor(X86_EDX, X86_ECX, X86_ESI, pvp))) {
-           X86_EAX = X86_AL | (SUCCESSFUL << 8);
-           X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-           X86_EBX = pciSlotBX(pvp);
-       }
-#endif
-       else {
-           X86_EAX = X86_AL | (DEVICE_NOT_FOUND << 8);
-           X86_EFLAGS |= ((unsigned long)0x01); /* set carry flag */
-       }
-#ifdef PRINT_INT
-       ErrorF("ax=0x%x bx=0x%x flags=0x%x\n", X86_EAX, X86_EBX, X86_EFLAGS);
-#endif
-       return 1;
-    case 0xb103:
-#if 0
-       if (X86_CL == pvp->interface &&
-           X86_CH == pvp->subclass &&
-           ((X86_ECX & 0xFFFF0000) >> 16) == pvp->class) {
-           X86_EAX = X86_AL | (SUCCESSFUL << 8);
-           X86_EBX = pciSlotBX(pvp);
-           X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-       }
-#ifdef SHOW_ALL_DEVICES
-       else if ((pvp = FindPciClass(X86_CL, X86_CH,
-                                        (X86_ECX & 0xffff0000) >> 16,
-                                        X86_ESI, pvp))) {
-           X86_EAX = X86_AL | (SUCCESSFUL << 8);
-           X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-           X86_EBX = pciSlotBX(pvp);
-       }
-#endif
-       else {
-#else
-       {
-            printf("int1a: pci_find_class not implemented.\n");
-#endif
-           X86_EAX = X86_AL | (DEVICE_NOT_FOUND << 8);
-           X86_EFLAGS |= ((unsigned long)0x01); /* set carry flag */
-       }
-#ifdef PRINT_INT
-       ErrorF("ax=0x%x flags=0x%x\n", X86_EAX, X86_EFLAGS);
-#endif
-       return 1;
-    case 0xb108:
-       if ((tag = findPci(X86_EBX))) {
-           X86_CL = pciReadByte(tag, X86_EDI);
-           X86_EAX = X86_AL | (SUCCESSFUL << 8);
-           X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-       } else {
-           X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
-           X86_EFLAGS |= ((unsigned long)0x01); /* set carry flag */
-       }
-#ifdef PRINT_INT
-       ErrorF("ax=0x%x cx=0x%x flags=0x%x\n", X86_EAX, X86_ECX, X86_EFLAGS);
-#endif
-       return 1;
-    case 0xb109:
-       if ((tag = findPci(X86_EBX))) {
-           X86_CX = pciReadWord(tag, X86_EDI);
-           X86_EAX = X86_AL | (SUCCESSFUL << 8);
-           X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-       } else {
-           X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
-           X86_EFLAGS |= ((unsigned long)0x01); /* set carry flag */
-       }
-#ifdef PRINT_INT
-       ErrorF("eax=0x%x ecx=0x%x eflags=0x%x\n", X86_EAX, X86_ECX, X86_EFLAGS);
-#endif
-       return 1;
-    case 0xb10a:
-       if ((tag = findPci(X86_EBX))) {
-           X86_ECX = pciReadLong(tag, X86_EDI);
-           X86_EAX = X86_AL | (SUCCESSFUL << 8);
-           X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-       } else {
-           X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
-           X86_EFLAGS |= ((unsigned long)0x01); /* set carry flag */
-       }
-#ifdef PRINT_INT
-       ErrorF("ax=0x%x cx=0x%x flags=0x%x\n", X86_EAX, X86_ECX, X86_EFLAGS);
-#endif
-       return 1;
-    case 0xb10b:
-       if ((tag = findPci(X86_EBX))) {
-           pciWriteByte(tag, X86_EDI, X86_CL);
-           X86_EAX = X86_AL | (SUCCESSFUL << 8);
-           X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-       } else {
-           X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
-           X86_EFLAGS |= ((unsigned long)0x01); /* set carry flag */
-       }
-#ifdef PRINT_INT
-       ErrorF("ax=0x%x flags=0x%x\n", X86_EAX, X86_EFLAGS);
-#endif
-       return 1;
-    case 0xb10c:
-       if ((tag = findPci(X86_EBX))) {
-           pciWriteWord(tag, X86_EDI, X86_CX);
-           X86_EAX = X86_AL | (SUCCESSFUL << 8);
-           X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-       } else { 
-           X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
-           X86_EFLAGS |= ((unsigned long)0x01); /* set carry flag */
-       }
-#ifdef PRINT_INT
-       ErrorF("ax=0x%x flags=0x%x\n", X86_EAX, X86_EFLAGS);
-#endif
-       return 1;
-    case 0xb10d:
-       if ((tag = findPci(X86_EBX))) {
-           pciWriteLong(tag, X86_EDI, X86_ECX);
-           X86_EAX = X86_AL | (SUCCESSFUL << 8);
-           X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */
-       } else {
-           X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
-           X86_EFLAGS |= ((unsigned long)0x01); /* set carry flag */
-       }
-#ifdef PRINT_INT
-       ErrorF("ax=0x%x flags=0x%x\n", X86_EAX, X86_EFLAGS);
-#endif
-       return 1;
-    default:
-       printf("int1a: subfunction not implemented.\n");
-       x86emu_dump_regs();
-       return 0;
-    }
-}
-
-/*
- * handle initialization
- */
-static int
-intE6_handler(xf86Int10InfoPtr pInt)
-{
-#if 0
-    pciVideoPtr pvp;
-
-    if ((pvp = xf86GetPciInfoForEntity(pInt->entityIndex)))
-       X86_AX = (pvp->bus << 8) | (pvp->device << 3) | (pvp->func & 0x7);
-    pushw(pInt, X86_CS);
-    pushw(pInt, X86_IP);
-    X86_CS = pInt->BIOSseg;
-    X86_EIP = 0x0003;
-    X86_ES = 0;                  /* standard pc es */
-#endif
-    printf ("intE6 not supported right now.\n");
-    return 1;
-}
diff -urN new/freebios/util/vgabios/pci-userspace.c 
freebios/util/vgabios/pci-userspace.c
--- new/freebios/util/vgabios/pci-userspace.c   Thu Apr 18 02:34:04 2002
+++ freebios/util/vgabios/pci-userspace.c       Sat Apr 20 09:56:00 2002
@@ -1,5 +1,10 @@
 #include <stdio.h>
-#include "pci-userspace.h"
+#include <pci/pci.h>
+#include "pci.h"
+
+#define PCITAG struct pci_filter *
+
+#define DEBUG_PCI 1
 
 struct pci_access *pacc;
 struct pci_dev *dev;
@@ -7,7 +12,7 @@
 struct pci_filter ltag;
 
 
-int pciNumBuses=0;
+int pciNumBuses = 0;
 
 int pciInit(void)
 {
@@ -15,7 +20,9 @@
 
        pci_init(pacc);
        pci_scan_bus(pacc);
-
+       for (dev = pacc->devices; dev; dev = dev->next) {
+               pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
+       }
        return 0;
 }
 
@@ -24,67 +31,103 @@
        pci_cleanup(pacc);
        return 0;
 }
-#if 0
-pciReadLong()
-{
-       int c;
-       pci_get_dev(struct pci_access *acc, int bus, int dev, int func);
-       pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
-       c=pci_read_dword(dev, regnum);
-}
-#endif
 
 PCITAG findPci(unsigned short bx)
 {
-    PCITAG tag=&ltag;
-    pciVideoPtr dev;
+       PCITAG tag = &ltag;
 
-    int bus  = (bx >> 8) & 0xFF;
-    int slot = (bx >> 3) & 0x1F;
-    int func = bx & 0x7;
+       int bus = (bx >> 8) & 0xFF;
+       int slot = (bx >> 3) & 0x1F;
+       int func = bx & 0x7;
 
-    tag->bus=bus; tag->slot=slot; tag->func=func;
+       tag->bus = bus;
+       tag->slot = slot;
+       tag->func = func;
 
-    if (pci_get_dev(pacc, bus, slot, func))
-        return tag;
+       if (pci_get_dev(pacc, bus, slot, func))
+               return tag;
 
-    return NULL;
+       return NULL;
 }
 
-CARD32 pciSlotBX(pciVideoPtr pvp)
+u32 pciSlotBX(PCITAG tag)
 {
-    return (pvp->bus << 8) | (pvp->dev << 3) | (pvp->func);
+       return (tag->bus << 8) | (tag->slot << 3) | (tag->func);
 }
 
-CARD8 pciReadByte(PCITAG tag, CARD32 idx)
+u8 pciReadByte(PCITAG tag, u32 idx)
 {
-       printf("pciReadByte: idx=%x\n",idx);
+       struct pci_dev *d;
+       if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
+               return pci_read_byte(d, idx);
+#ifdef DEBUG_PCI
+       printf("PCI: device not found while read byte (%x:%x.%x)\n",
+              tag->bus, tag->slot, tag->func);
+#endif
+       return 0;
 }
 
-CARD16 pciReadWord(PCITAG tag, CARD32 idx)
+u16 pciReadWord(PCITAG tag, u32 idx)
 {
-        printf("pciReadWord: idx=%x\n",idx);
+       struct pci_dev *d;
+       if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
+               return pci_read_word(d, idx);
+#ifdef DEBUG_PCI
+       printf("PCI: device not found while read word (%x:%x.%x)\n",
+              tag->bus, tag->slot, tag->func);
+#endif
+       return 0;
 }
 
-CARD32 pciReadLong(PCITAG tag, CARD32 idx)
+u32 pciReadLong(PCITAG tag, u32 idx)
 {
-        printf("pciReadWord: idx=%x\n",idx);
+       struct pci_dev *d;
+       if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
+               return pci_read_long(d, idx);
+#ifdef DEBUG_PCI
+       printf("PCI: device not found while read long (%x:%x.%x)\n",
+              tag->bus, tag->slot, tag->func);
+#endif
+       return 0;
 }
 
 
-void pciWriteLong(PCITAG tag, CARD32 idx, CARD32 data)
+void pciWriteLong(PCITAG tag, u32 idx, u32 data)
 {
-       printf("pciWriteLong: idx=%x, data=%x\n",idx,data);
+       struct pci_dev *d;
+       if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
+               pci_write_long(d, idx, data);
+#ifdef DEBUG_PCI
+       else
+               printf
+                   ("PCI: device not found while write long (%x:%x.%x)\n",
+                    tag->bus, tag->slot, tag->func);
+#endif
 }
 
-void pciWriteWord(PCITAG tag, CARD32 idx, CARD16 data)
+void pciWriteWord(PCITAG tag, u32 idx, u16 data)
 {
-       printf("pciWriteWord: idx=%x, data=%x\n",idx,data);
-}
+       struct pci_dev *d;
+       if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
+               pci_write_word(d, idx, data);
+#ifdef DEBUG_PCI
+       else
+               printf
+                   ("PCI: device not found while write word (%x:%x.%x)\n",
+                    tag->bus, tag->slot, tag->func);
+#endif
 
+}
 
-void pciWriteByte(PCITAG tag, CARD32 idx, CARD8 data)
+void pciWriteByte(PCITAG tag, u32 idx, u8 data)
 {
-       printf("pciWriteByte: idx=%x, data=%x\n",idx,data);
+       struct pci_dev *d;
+       if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
+               pci_write_long(d, idx, data);
+#ifdef DEBUG_PCI
+       else
+               printf
+                   ("PCI: device not found while write long (%x:%x.%x)\n",
+                    tag->bus, tag->slot, tag->func);
+#endif
 }
-
diff -urN new/freebios/util/vgabios/pci-userspace.h 
freebios/util/vgabios/pci-userspace.h
--- new/freebios/util/vgabios/pci-userspace.h   Thu Apr 18 02:34:04 2002
+++ freebios/util/vgabios/pci-userspace.h       Sat Apr 20 09:55:55 2002
@@ -1,8 +1,38 @@
-#include <pci/pci.h>
+#include "pci.h"
+
+typedef unsigned long pciaddr_t;
+typedef u8 byte;
+typedef u16 word;
+
+struct pci_dev {
+       struct pci_dev *next;   /* Next device in the chain */
+       word bus;               /* Higher byte can select host bridges */
+       byte dev, func;         /* Device and function */
+
+       /* These fields are set by pci_fill_info() */
+       int known_fields;       /* Set of info fields already known */
+       word vendor_id, device_id;      /* Identity of the device */
+       int irq;                /* IRQ number */
+       pciaddr_t base_addr[6]; /* Base addresses */
+       pciaddr_t size[6];      /* Region sizes */
+       pciaddr_t rom_base_addr;        /* Expansion ROM base address */
+       pciaddr_t rom_size;     /* Expansion ROM size */
+
+       /* Fields used internally: */
+       void *access;
+       void *methods;
+       byte *cache;            /* Cached information */
+       int cache_len;
+       int hdrtype;            /* Direct methods: header type */
+       void *aux;              /* Auxillary data */
+};
+
+
+struct pci_filter {
+       int bus, slot, func;    /* -1 = ANY */
+       int vendor, device;
+};
 
-#define CARD8 unsigned char
-#define CARD16 unsigned short
-#define CARD32 unsigned long
 
 #define PCITAG struct pci_filter *
 #define pciVideoPtr struct pci_dev *
@@ -14,14 +44,12 @@
 
 
 PCITAG findPci(unsigned short bx);
-CARD32 pciSlotBX(pciVideoPtr pvp);
-
-void pciWriteLong(PCITAG tag, CARD32 idx, CARD32 data);
-void pciWriteWord(PCITAG tag, CARD32 idx, CARD16 data);
-void pciWriteByte(PCITAG tag, CARD32 idx, CARD8 data);
-
-CARD32 pciReadLong(PCITAG tag, CARD32 idx);
-CARD16 pciReadWord(PCITAG tag, CARD32 idx);
-CARD8  pciReadByte(PCITAG tag, CARD32 idx);
-
+u32 pciSlotBX(pciVideoPtr pvp);
 
+void pciWriteLong(PCITAG tag, u32 idx, u32 data);
+void pciWriteWord(PCITAG tag, u32 idx, u16 data);
+void pciWriteByte(PCITAG tag, u32 idx, u8 data);
+
+u32 pciReadLong(PCITAG tag, u32 idx);
+u16 pciReadWord(PCITAG tag, u32 idx);
+u8 pciReadByte(PCITAG tag, u32 idx);
diff -urN new/freebios/util/vgabios/pci.h freebios/util/vgabios/pci.h
--- new/freebios/util/vgabios/pci.h     Thu Jan  1 01:00:00 1970
+++ freebios/util/vgabios/pci.h Sat Apr 20 07:16:53 2002
@@ -0,0 +1,4 @@
+void x_outb(u16 port, u8 val);
+#define outb x_outb
+
+
diff -urN new/freebios/util/vgabios/test.h freebios/util/vgabios/test.h
--- new/freebios/util/vgabios/test.h    Sun Apr 14 06:44:08 2002
+++ freebios/util/vgabios/test.h        Thu Apr 18 08:08:56 2002
@@ -76,25 +76,13 @@
     void(*wl)(ptr, int, u32);
 } mem;
 
-// I don't know why they did it this way. So I won't change it for now 
-// RGM
-#if 0
-#define MEM_WB(pint, where, what) (pint)->mem->wb(pint, where, what)
-#define MEM_WW(pint, where, what) (pint)->mem->ww(pint, where, what)
-#define MEM_WL(pint, where, what) (pint)->mem->wl(pint, where, what)
+#define MEM_WB(where, what) wrb(where,what)
+#define MEM_WW(where, what) wrw(where, what)
+#define MEM_WL(where, what) wrl(where, what)
 
-#define MEM_RB(pint, where) (pint)->mem->rb(pint, where)
-#define MEM_RW(pint, where) (pint)->mem->rw(pint, where)
-#define MEM_RL(pint, where) (pint)->mem->rl(pint, where)
-#endif
-
-#define MEM_WB(pint, where, what) wrb(where,what)
-#define MEM_WW(pint, where, what) wrw(where, what)
-#define MEM_WL(pint, where, what) wrl(where, what)
-
-#define MEM_RB(pint, where) rdb(where)
-#define MEM_RW(pint, where) rdw(where)
-#define MEM_RL(pint, where) rdl(where)
+#define MEM_RB(where) rdb(where)
+#define MEM_RW(where) rdw(where)
+#define MEM_RL(where) rdl(where)
 
 extern ptr current;
 
diff -urN new/freebios/util/vgabios/testbios.c freebios/util/vgabios/testbios.c
--- new/freebios/util/vgabios/testbios.c        Thu Apr 18 02:34:04 2002
+++ freebios/util/vgabios/testbios.c    Sat Apr 20 09:40:10 2002
@@ -1,29 +1,75 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <sys/io.h>
 #include <sys/mman.h>
 #include <fcntl.h>
+#include <getopt.h>
+
 #define die(x) { perror(x); exit(1); }
 
 #include <x86emu.h>
 #include "test.h"
+#include "pci-userspace.h"
+
+void x86emu_dump_xregs (void);
+int int15_handler(void);
+int int16_handler(void);
+int int1A_handler(void);
+#ifndef _PC
+int int42_handler(void);
+#endif
+int intE6_handler(void);
+
+void pushw(u16 val);
+
+extern int teststart, testend;
 
 _ptr p;
 ptr current = 0;
-extern int teststart, testend;
-#if 0
-void
-test()
+unsigned char biosmem[1024*1024];
+
+int verbose=0;
+
+
+/* Interrupt multiplexer */
+
+void do_int(int num)
 {
-  __asm__ __volatile__(".code16\nteststart:movb $4, %al\n outb %al, 
$0x80\n.code32\nhlt\ntestend:");
-}
-#endif
+    int ret = 0;
 
-void do_int(int num);
-void setup_int(void);
-void exit_int(void);
+    /* This is a pInt leftover */
+    current->num=num;
 
-unsigned char biosmem[1024*1024];
+    switch (num) {
+#ifndef _PC
+    case 0x10:
+    case 0x42:
+    case 0x6D:
+       ret = int42_handler();
+       break;
+#endif
+    case 0x15:
+       ret = int15_handler();
+       break;
+    case 0x16:
+       ret = int16_handler();
+       break;
+    case 0x1A:
+       ret = int1A_handler();
+       break;
+    case 0xe6:
+       ret = intE6_handler();
+       break;
+    default:
+       break;
+    }
+
+    if (!ret) {
+        printf("\nint%x: not implemented\n",num);
+        x86emu_dump_xregs();
+    }
+}
 
 unsigned char *mapitin(char *file, size_t size)
 {
@@ -58,27 +104,118 @@
 };
 
 
-int
-main(int argc, char **argv)
+void usage(char *name)
+{
+       printf("Usage: %s [-c codesegment] [-s size] [-b base] [-i ip] [-t] <filename> 
+... \n",name); 
+}
+
+int main(int argc, char **argv)
 {
-       int i;
+       int i,c,trace=0;
        unsigned char *cp;
        char *filename;
-       size_t size, howmuch;
-       int base;
-       unsigned short initialip, initialcs;
+       size_t size=0;
+       int base=0;
+       int have_size=0, have_base=0, have_ip=0, have_cs=0;
+       int parse_rom=0;
+       unsigned short initialip=0, initialcs=0, devfn=0;
        X86EMU_intrFuncs intFuncs[256];
        void X86EMU_setMemBase(void *base, size_t size);
        void x86emu_dump_xregs (void);
 
-       if (argc < 4) 
-               die("Usage: testbios <file> <size> <base> <initial IP> <initial CS>");
-
-       filename = argv[1];
-       size = strtol(argv[2], 0, 0);
-       base = strtol(argv[3], 0, 0);
-       initialip = strtol(argv[4], 0, 0);
-       initialcs = strtol(argv[5], 0, 0);
+       const char *optstring="vh?b:i:c:s:tpd:";
+       while (1) {
+               int option_index = 0;
+               static struct option long_options[] = {
+                       { "verbose", 0, 0, 'v' },
+                       { "help", 0, 0, 'h' },
+                       { "trace", 0, 0, 't' },
+                       { "base", 1, 0, 'b' },
+                       { "instructionpointer", 1, 0, 'i' },
+                       { "codesegment", 1, 0, 'c' },
+                       { "size", 1, 0, 's' },
+                       { "parserom", 0, 0, 'p' },
+                       { "device", 1, 0, 'd' },
+                       { 0, 0, 0, 0 }
+               };
+               c = getopt_long (argc, argv, optstring,
+                                       long_options, &option_index);
+               if (c == -1)
+                       break;
+               switch (c) {
+               case 'v':
+                       verbose=1;
+                       break;
+               case 'h':
+               case '?':
+                       usage(argv[0]);
+                       return 0;
+               case 't':
+                       trace=1;
+                       break;
+               case 'b':
+                       base = strtol(optarg, 0, 0);
+                       have_base=1;
+                       break;
+               case 'i':
+                       initialip=strtol(optarg, 0, 0);
+                       have_ip=1;
+                       break;
+               case 'c':
+                       initialcs=strtol(optarg, 0, 0);
+                       have_cs=1;
+                       break;
+               case 's':
+                       size=strtol(optarg, 0, 0);
+                       have_size=1;
+                       break;
+               case 'p':
+                       printf("Parsing rom images not implemented.\n");
+                       parse_rom=1;
+                       break;
+               case 'd':
+                       devfn=strtol(optarg, 0, 0);
+                       break;
+               default:
+                       printf("Unknown option \n");
+                       usage(argv[0]);
+                       return 1;
+               }
+       }
+
+       if (optind >= argc) {
+               printf("Filename missing.\n");
+               usage(argv[0]);
+               return 1;
+       }
+
+       while (optind < argc) {
+               printf("running file %s\n",argv[optind]);
+               filename=argv[optind];
+               optind++;
+               /* normally we would do continue, but for
+                * now only one filename is supported.
+                */
+               /* continue; */
+               break;
+       }
+
+       if (!have_size) {
+               printf("No size specified. defaulting to 32k\n");
+               size=32*1024;
+       }
+       if (!have_base) {
+               printf("No base specified. defaulting to 0xc0000\n");
+               base=0xc0000;
+       }
+       if (!have_cs) {
+               printf("No initial code segment specified. defaulting to 0xc000\n");
+               initialcs=0xc000;
+       }
+       if (!have_ip) {
+               printf("No initial instruction pointer specified. defaulting to 
+0x0003\n");
+               initialip=0x0003;
+       }
 
        current = &p;
        X86EMU_setMemBase(biosmem, sizeof(biosmem));
@@ -87,28 +224,58 @@
        if (iopl(3) < 0) 
                die("iopl");
 
-       setup_int();
+       /* Emergency sync ;-) */
        sync();
        sync();
+
+       /* Setting up interrupt environment.
+        * basically this means initializing PCI and
+        * intXX handlers.
+        */
+       
+       pciInit();
+
        for (i=0;i<256;i++)
                intFuncs[i] = do_int;
                X86EMU_setupIntrFuncs(intFuncs);
        cp = mapitin(filename, size);
 
-       current->ax = 0xff;
+       current->ax = devfn?devfn:0xff;
        current->dx = 0x80;
        //      current->ip = 0;
        for(i = 0; i < size; i++)
          wrb(base + i, cp[i]);
+
+       /* cpu setup */
+       X86_AX  = devfn?devfn:0xff;
+       X86_DX  = 0x80;
        X86_EIP = initialip;
-       X86_CS = initialcs;
-       //      M.x86.saved_cs = 0;
-       //      M.x86.saved_ip = 0;
-//     X86EMU_trace_on();
+       X86_CS  = initialcs;
+
+       /* Initialize stack and data segment */
+       X86_SS  = 0x0030;
+       X86_DS  = 0x0040;
+       X86_SP  = 0xfffe;
+
+       /* We need a sane way to return from bios
+        * execution. A hlt instruction and a pointer
+        * to it, both kept on the stack, will do.
+        */
+       pushw(0xf4f4);  /* hlt; hlt */
+       pushw(X86_SS);
+       pushw(X86_SP+2);
+
+       X86_ES  = 0x0000;
+
+       if (trace) {
+               printf("Switching to single step mode.\n");
+               X86EMU_trace_on();
+       }
 
        X86EMU_exec();
        
-       exit_int();
+       /* Cleaning up */
+       pciExit();
 
        return 0;
 }

Reply via email to