/*
  * GeekOS interrupt handling data structures and functions
  * Copyright (c) 2001,2003 David H. Hovemeyer <daveho@cs.umd.edu>
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
  * 
  * This is free software.  You are permitted to use,
  * redistribute, and modify it as specified in the file "COPYING".
 {
     uint_t errorCode = state->errorCode;
 
-   PrintBoth("eax=%08x ebx=%08x ecx=%08x edx=%08x\n"
+   SerialPrint("eax=%08x ebx=%08x ecx=%08x edx=%08x\n"
           "esi=%08x edi=%08x ebp=%08x\n"
           "eip=%08x cs=%08x eflags=%08x\n"
           "Interrupt number=%d (%s), error code=%d\n"
 
 /*
  * x86 port IO routines
  * Copyright (c) 2001, David H. Hovemeyer <daveho@cs.umd.edu>
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
  * 
  * This is free software.  You are permitted to use,
  * redistribute, and modify it as specified in the file "COPYING".
 }
 
 /*
- * Read a byte from an I/O port.
+ * Read a word from an I/O port.
  */
 ushort_t In_Word(ushort_t port)
 {
 }
 
 /*
+ * Write a double word to an I/O port.
+ */
+void Out_DWord(ushort_t port, uint_t value)
+{
+    __asm__ __volatile__ (
+       "outl %0, %1"
+       :
+       : "a" (value), "Nd" (port)
+    );
+}
+
+/*
+ * Read a double word from an I/O port.
+ */
+uint_t In_DWord(ushort_t port)
+{
+    uint_t value;
+
+    __asm__ __volatile__ (
+       "inl %1, %0"
+       : "=a" (value)
+       : "Nd" (port)
+    );
+
+    return value;
+}
+
+/*
  * Short delay.  May be needed when talking to some
  * (slow) I/O devices.
  */
 
 /*
  * Kernel threads
  * Copyright (c) 2001,2003 David H. Hovemeyer <daveho@cs.umd.edu>
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
  * 
  * This is free software.  You are permitted to use,
  * redistribute, and modify it as specified in the file "COPYING".
      * will "return", and then Schedule() will return to wherever
      * it was called from.
      */
+
+    SerialPrint("Switch_To_Thread() in Schedule()\n");
     Switch_To_Thread(runnable);
 }
 
 
  * Copyright (c) 2001,2003,2004 David H. Hovemeyer <daveho@cs.umd.edu>
  * Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu>
  * Copyright (c) 2004, Iulian Neamtiu <neamtiu@cs.umd.edu>
- * $Revision: 1.36 $
+ * $Revision: 1.37 $
  * 
  * This is free software.  You are permitted to use,
  * redistribute, and modify it as specified in the file "COPYING".
 
 #include <geekos/vmm_stubs.h>
 
+#include <geekos/pci.h>
 
 
 
   Init_Keyboard();
   Init_VM(bootInfo);
   Init_Paging();
+  
+  Init_PCI();
+
   Init_Stubs();
 
   //  Init_IDE();
 
  * GeekOS timer interrupt support
  * Copyright (c) 2001,2003 David H. Hovemeyer <daveho@cs.umd.edu>
  * Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu>
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
  * 
  * This is free software.  You are permitted to use,
  * redistribute, and modify it as specified in the file "COPYING".
 
     SerialPrint("Host Timer Interrupt Handler running\n");
 
+
+#if 0
+#define STACK_LEN 256
+
+    SerialPrint("Timer====\n");
+    Dump_Interrupt_State(state);
+    //    SerialMemDump((unsigned char*)(¤t),STACK_LEN);
+    SerialPrint("Timer done===\n");
+
+#endif
     /* Update global and per-thread number of ticks */
     ++g_numTicks;
     ++current->numTicks;
 
-
     /*
      * If thread has been running for an entire quantum,
      * inform the interrupt return code that we want
 
        struct vm_device * keyboard = create_keyboard();
        struct vm_device * pit = create_pit();
 
-       //generic_port_range_type range = {0,1024} ; // hook first 1024 ports if not already hooked
 
-       //struct vm_device * generic = create_generic(&range, 1, NULL, 0, NULL, 0);
+
+#if GENERIC
+       generic_port_range_type range[] = {
+          {0x00, 0x07},   // DMA 1 channels 0,1,2,3 (address, counter)
+          {0xc0, 0xc7},   // DMA 2 channels 4,5,6,7 (address, counter)
+          {0x87, 0x87},   // DMA 1 channel 0 page register
+          {0x83, 0x83},   // DMA 1 channel 1 page register
+          {0x81, 0x81},   // DMA 1 channel 2 page register
+          {0x82, 0x82},   // DMA 1 channel 3 page register
+          {0x8f, 0x8f},   // DMA 2 channel 4 page register
+          {0x8b, 0x8b},   // DMA 2 channel 5 page register
+          {0x89, 0x89},   // DMA 2 channel 6 page register
+          {0x8a, 0x8a},   // DMA 2 channel 7 page register
+         {0x08, 0x0f},   // DMA 1 misc registers (csr, req, smask,mode,clearff,reset,enable,mmask)
+          {0xd0, 0xde},   // DMA 2 misc registers
+          {0x3f0, 0x3f2}, // Primary floppy controller (base,statusa/statusb,DOR)
+          {0x3f4, 0x3f5}, // Primary floppy controller (mainstat/datarate,data)
+          {0x3f7, 0x3f7}, // Primary floppy controller (DIR)
+          {0x370, 0x372}, // Secondary floppy controller (base,statusa/statusb,DOR)
+          {0x374, 0x375}, // Secondary floppy controller (mainstat/datarate,data)
+          {0x377, 0x377}, // Secondary floppy controller (DIR)
+          {0x378, 0x400}
+        };
+
+       struct vm_device * generic = create_generic(range,19,NULL,0,NULL,0);
        
+#endif
 
        attach_device(&(vm_info), nvram);
        //attach_device(&(vm_info), timer);
        attach_device(&(vm_info), pit);
        attach_device(&(vm_info), keyboard);
 
+
+#if GENERIC
        // Important that this be attached last!
-       //attach_device(&(vm_info), generic);
+       attach_device(&(vm_info), generic);
+
+#endif
 
        PrintDebugDevMgr(&(vm_info.dev_mgr));
       }
 
        push    ebp
        mov     ebp, esp
        pushf
+       push    fs
+       push    gs
        pusha                                   ;; Save Host state
 
 
        add     esp, 4                          ;; skip past the gpr ptr
        
        popa                                    ;; Restore Host state
+       pop     gs
+       pop     fs
        popf
        pop     ebp
        ret
 
                   struct x86_operand * dst_operand,
                   struct x86_operand * extra_operand) {
 
-  V3_Assert(src_operand != NULL);
-  V3_Assert(dst_operand != NULL);
-  V3_Assert(extra_operand != NULL);
-  V3_Assert(instr_length != NULL);
-  V3_Assert(info != NULL);
+  V3_ASSERT(src_operand != NULL);
+  V3_ASSERT(dst_operand != NULL);
+  V3_ASSERT(extra_operand != NULL);
+  V3_ASSERT(instr_length != NULL);
+  V3_ASSERT(info != NULL);
 
   
   // Ignore prefixes for now
-  while (is_prefix_byte(*instr)) {
-    instr++;
+  while (is_prefix_byte(*instr_ptr)) {
+    instr_ptr++;
     *instr_length++;
   }