#define __VMM_IO_H
 
 
+#ifdef __V3VEE__
 
 #include <palacios/vmm_types.h>
 #include <palacios/vmm_util.h>
 
 
 
-#ifdef __V3VEE__
 
 
 struct vmm_io_hook;
 void PrintDebugIOMap(struct vmm_io_map * io_map);
 
 
+
+
+void v3_outb(ushort_t port, uchar_t value);
+uchar_t v3_inb(ushort_t port);
+
+void v3_outw(ushort_t port, ushort_t value);
+ushort_t v3_inw(ushort_t port);
+
+void v3_outdw(ushort_t port, uint_t value);
+uint_t v3_indw(ushort_t port);
+
+
+
 #endif // !__V3VEE__
 
 
 
 #ifndef __VMM_TYPES_H
 #define __VMM_TYPES_H
 
-#include <geekos/ktypes.h>
+#ifdef __V3VEE__
+//#include <geekos/ktypes.h>
+
 
-/*
 typedef signed char schar_t;
 typedef unsigned char uchar_t;
 
 
 typedef unsigned long size_t;
 
-*/
+
 
 
 
 typedef ulong_t addr_t;
 
 #endif
+
+#endif
 
 #include <devices/generic.h>
 #include <palacios/vmm.h>
 #include <palacios/vmm_types.h>
-#include <geekos/io.h>
+
 
 
 
 
   switch (length) {
   case 1:
-    Out_Byte(port,((uchar_t*)src)[0]);
+    v3_outb(port,((uchar_t*)src)[0]);
     break;
   case 2:
-    Out_Word(port,((ushort_t*)src)[0]);
+    v3_outw(port,((ushort_t*)src)[0]);
     break;
   case 4:
-    Out_DWord(port,((uint_t*)src)[0]);
+    v3_outdw(port,((uint_t*)src)[0]);
     break;
   default:
     for (i = 0; i < length; i++) { 
-      Out_Byte(port, ((uchar_t*)src)[i]);
+      v3_outb(port, ((uchar_t*)src)[i]);
     }
   } //switch length
 #ifdef RAMDISK_BOOT
 
     switch (length) {
     case 1:
-      ((uchar_t*)src)[0] = In_Byte(port);
+      ((uchar_t*)src)[0] = v3_inb(port);
       break;
     case 2:
-      ((ushort_t*)src)[0] = In_Word(port);
+      ((ushort_t*)src)[0] = v3_inw(port);
       break;
     case 4:
-      ((uint_t*)src)[0] = In_DWord(port);
+      ((uint_t*)src)[0] = v3_indw(port);
       break;
     default:
       for (i = 0; i < length; i++) { 
-       ((uchar_t*)src)[i] = In_Byte(port);
+       ((uchar_t*)src)[i] = v3_inb(port);
       }
     }//switch length
 #ifdef RAMDISK_BOOT
 
 /* (c) 2008, The V3VEE Project <http://www.v3vee.org> */
 
 #include <devices/keyboard.h>
-#include <geekos/io.h>
 #include <palacios/vmm.h>
 #include <palacios/vmm_types.h>
 
 {
 
   if (length == 1) { 
-    *((uchar_t*)dest) = In_Byte(port);
+    *((uchar_t*)dest) = v3_inb(port);
 
     PrintDebug("keyboard: read of 0x%x from 80h\n", *((uchar_t*)dest));
 
 
 
   PrintBoth("Configured guest\n");
   
-  v3_hook_io_port(vm_info, 0x61, &IO_Read, &IO_Write, NULL);
+
   //v3_hook_io_port(&vm_info, 0x05, &IO_Read, &IO_Write_to_Serial, NULL);
   
-  
-  v3_hook_io_port(vm_info, 0x400, &IO_Read, &IO_Write_to_Serial, NULL);
-  v3_hook_io_port(vm_info, 0x401, &IO_Read, &IO_Write_to_Serial, NULL);
-  v3_hook_io_port(vm_info, 0x402, &IO_Read, &IO_BOCHS_info, NULL);
-  v3_hook_io_port(vm_info, 0x403, &IO_Read, &IO_BOCHS_debug, NULL);
+  //v3_hook_io_port(vm_info, 0x61, &IO_Read, &IO_Write, NULL);
+  //v3_hook_io_port(vm_info, 0x400, &IO_Read, &IO_Write_to_Serial, NULL);
+  //v3_hook_io_port(vm_info, 0x401, &IO_Read, &IO_Write_to_Serial, NULL);
+  //v3_hook_io_port(vm_info, 0x402, &IO_Read, &IO_BOCHS_info, NULL);
+  //v3_hook_io_port(vm_info, 0x403, &IO_Read, &IO_BOCHS_debug, NULL);
   
 
   (vmm_ops).init_guest(vm_info);
 
 
   return 0;
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#if 0
-
-    
-    if (0) {
-      
-      //    add_shared_mem_range(&(vm_info.mem_layout), 0, 0x800000, 0x10000);    
-      //    add_shared_mem_range(&(vm_info.mem_layout), 0, 0x1000000, 0);
-      
-      rip = (ulong_t)(void*)&BuzzVM;
-      //  rip -= 0x10000;
-      //    rip = (addr_t)(void*)&exit_test;
-      //  rip -= 0x2000;
-      vm_info.rip = rip;
-      rsp = (addr_t)Alloc_Page();
-      
-      vm_info.vm_regs.rsp = (rsp +4092 );// - 0x2000;
-      
-            
-    } else if (0) {
-      //add_shared_mem_range(&(vm_info.mem_layout), 0x0, 0x1000, 0x100000);
-      //      add_shared_mem_range(&(vm_info.mem_layout), 0x0, 0x100000, 0x0);
-      
-      /*
-       shadow_region_t *ent = Malloc(sizeof(shadow_region_t));;
-       init_shadow_region_physical(ent,0,0x100000,GUEST_REGION_PHYSICAL_MEMORY,
-       0x100000, HOST_REGION_PHYSICAL_MEMORY);
-       add_shadow_region(&(vm_info.mem_map),ent);
-      */
-
-      add_shadow_region_passthrough(&vm_info, 0x0, 0x100000, 0x100000);
-
-      v3_hook_io_port(&vm_info, 0x61, &IO_Read, &IO_Write, NULL);
-      v3_hook_io_port(&vm_info, 0x05, &IO_Read, &IO_Write_to_Serial, NULL);
-      
-
-
-      /*
-       vm_info.cr0 = 0;
-       vm_info.cs.base=0xf000;
-       vm_info.cs.limit=0xffff;
-      */
-      //vm_info.rip = 0xfff0;
-
-      vm_info.rip = 0;
-      vm_info.vm_regs.rsp = 0x0;
-    } else {
-   
-    }
-
-#endif
 
 #endif
 
 
+static int default_write(ushort_t port, void *src, uint_t length, void * priv_data);
+static int default_read(ushort_t port, void * dst, uint_t length, void * priv_data);
+
+
 void init_vmm_io_map(struct guest_info * info) {
   struct vmm_io_map * io_map = &(info->io_map);
   io_map->num_ports = 0;
 
 
 
-/* FIX ME */
-static int default_write(ushort_t port, void *src, uint_t length, void * priv_data) {
-  /*
-    
-  if (length == 1) {
-  __asm__ __volatile__ (
-  "outb %b0, %w1"
-  :
-  : "a" (*dst), "Nd" (port)
-  );
-  } else if (length == 2) {
-  __asm__ __volatile__ (
-  "outw %b0, %w1"
-  :
-  : "a" (*dst), "Nd" (port)
-  );
-  } else if (length == 4) {
-  __asm__ __volatile__ (
-  "outw %b0, %w1"
-  :
-  : "a" (*dst), "Nd" (port)
-  );
-  }
-  */
-  return 0;
-}
-
-static int default_read(ushort_t port, void * dst, uint_t length, void * priv_data)
-{
-
-  /*    
-       uchar_t value;
-
-    __asm__ __volatile__ (
-       "inb %w1, %b0"
-       : "=a" (value)
-       : "Nd" (port)
-    );
-
-    return value;
-  */
 
-  return 0;
-}
 
 int v3_hook_io_port(struct guest_info * info, uint_t port, 
                    int (*read)(ushort_t port, void * dst, uint_t length, void * priv_data),
     PrintDebug("IO Port: %hu (Read=%x) (Write=%x)\n", iter->port, iter->read, iter->write);
   }
 }
+
+
+
+/*
+ * Write a byte to an I/O port.
+ */
+void v3_outb(ushort_t port, uchar_t value) {
+    __asm__ __volatile__ (
+       "outb %b0, %w1"
+       :
+       : "a" (value), "Nd" (port)
+    );
+}
+
+/*
+ * Read a byte from an I/O port.
+ */
+uchar_t v3_inb(ushort_t port) {
+    uchar_t value;
+
+    __asm__ __volatile__ (
+       "inb %w1, %b0"
+       : "=a" (value)
+       : "Nd" (port)
+    );
+
+    return value;
+}
+
+/*
+ * Write a word to an I/O port.
+ */
+void v3_outw(ushort_t port, ushort_t value) {
+    __asm__ __volatile__ (
+       "outw %w0, %w1"
+       :
+       : "a" (value), "Nd" (port)
+    );
+}
+
+/*
+ * Read a word from an I/O port.
+ */
+ushort_t v3_inw(ushort_t port) {
+    ushort_t value;
+
+    __asm__ __volatile__ (
+       "inw %w1, %w0"
+       : "=a" (value)
+       : "Nd" (port)
+    );
+
+    return value;
+}
+
+/*
+ * Write a double word to an I/O port.
+ */
+void v3_outdw(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 v3_indw(ushort_t port) {
+    uint_t value;
+
+    __asm__ __volatile__ (
+       "inl %1, %0"
+       : "=a" (value)
+       : "Nd" (port)
+    );
+
+    return value;
+}
+
+
+
+
+/* FIX ME */
+static int default_write(ushort_t port, void *src, uint_t length, void * priv_data) {
+  /*
+    
+  if (length == 1) {
+  __asm__ __volatile__ (
+  "outb %b0, %w1"
+  :
+  : "a" (*dst), "Nd" (port)
+  );
+  } else if (length == 2) {
+  __asm__ __volatile__ (
+  "outw %b0, %w1"
+  :
+  : "a" (*dst), "Nd" (port)
+  );
+  } else if (length == 4) {
+  __asm__ __volatile__ (
+  "outw %b0, %w1"
+  :
+  : "a" (*dst), "Nd" (port)
+  );
+  }
+  */
+  return 0;
+}
+
+static int default_read(ushort_t port, void * dst, uint_t length, void * priv_data) {
+
+  /*    
+       uchar_t value;
+
+    __asm__ __volatile__ (
+       "inb %w1, %b0"
+       : "=a" (value)
+       : "Nd" (port)
+    );
+
+    return value;
+  */
+
+  return 0;
+}