Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added emulator
[palacios.git] / palacios / src / devices / generic.c
index 8d329f5..13d9b9c 100644 (file)
@@ -4,12 +4,10 @@
 #include <geekos/io.h>
 
 
-#define GENERIC_DEBUG 1
 
-#if GENERIC_DEBUG
-#define GENERIC_DEBUG_PRINT(first, rest...) PrintDebug(first, ##rest) 
-#else
-#define GENERIC_DEBUG_PRINT(first, rest...)
+#ifndef DEBUG_GENERIC
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
 #endif
 
 
@@ -35,7 +33,7 @@ struct generic_internal {
 
 int generic_reset_device(struct vm_device * dev)
 {
-  GENERIC_DEBUG_PRINT("generic: reset device\n");
+  PrintDebug("generic: reset device\n");
  
   return 0;
 
@@ -47,14 +45,14 @@ int generic_reset_device(struct vm_device * dev)
 
 int generic_start_device(struct vm_device *dev)
 {
-  GENERIC_DEBUG_PRINT("generic: start device\n");
+  PrintDebug("generic: start device\n");
   return 0;
 }
 
 
 int generic_stop_device(struct vm_device *dev)
 {
-  GENERIC_DEBUG_PRINT("generic: stop device\n");
+  PrintDebug("generic: stop device\n");
   return 0;
 }
 
@@ -68,13 +66,13 @@ int generic_write_port_passthrough(ushort_t port,
 {
   uint_t i;
 
-  GENERIC_DEBUG_PRINT("generic: writing 0x");
+  PrintDebug("generic: writing 0x");
 
   for (i = 0; i < length; i++) { 
-    GENERIC_DEBUG_PRINT("%x", ((uchar_t*)src)[i]);
+    PrintDebug("%x", ((uchar_t*)src)[i]);
   }
   
-  GENERIC_DEBUG_PRINT(" to port 0x%x ... ", port);
+  PrintDebug(" to port 0x%x ... ", port);
 
   switch (length) {
   case 1:
@@ -92,7 +90,7 @@ int generic_write_port_passthrough(ushort_t port,
     }
   }
 
-  GENERIC_DEBUG_PRINT(" done\n");
+  PrintDebug(" done\n");
   
   return length;
 }
@@ -104,7 +102,7 @@ int generic_read_port_passthrough(ushort_t port,
 {
   uint_t i;
 
-  GENERIC_DEBUG_PRINT("generic: reading 0x%x bytes from port 0x%x ...", length, port);
+  PrintDebug("generic: reading 0x%x bytes from port 0x%x ...", length, port);
 
   switch (length) {
   case 1:
@@ -122,13 +120,13 @@ int generic_read_port_passthrough(ushort_t port,
     }
   }
 
-  GENERIC_DEBUG_PRINT(" done ... read 0x");
+  PrintDebug(" done ... read 0x");
 
   for (i = 0; i < length; i++) { 
-    GENERIC_DEBUG_PRINT("%x", ((uchar_t*)src)[i]);
+    PrintDebug("%x", ((uchar_t*)src)[i]);
   }
 
-  GENERIC_DEBUG_PRINT("\n");
+  PrintDebug("\n");
 
   return length;
 }
@@ -140,15 +138,15 @@ int generic_write_port_ignore(ushort_t port,
 {
   uint_t i;
 
-  GENERIC_DEBUG_PRINT("generic: writing 0x");
+  PrintDebug("generic: writing 0x");
 
   for (i = 0; i < length; i++) { 
-    GENERIC_DEBUG_PRINT("%x", ((uchar_t*)src)[i]);
+    PrintDebug("%x", ((uchar_t*)src)[i]);
   }
   
-  GENERIC_DEBUG_PRINT(" to port 0x%x ... ", port);
+  PrintDebug(" to port 0x%x ... ", port);
 
-  GENERIC_DEBUG_PRINT(" ignored\n");
+  PrintDebug(" ignored\n");
   
   return length;
 }
@@ -159,10 +157,10 @@ int generic_read_port_ignore(ushort_t port,
                             struct vm_device * dev)
 {
 
-  GENERIC_DEBUG_PRINT("generic: reading 0x%x bytes from port 0x%x ...", length, port);
+  PrintDebug("generic: reading 0x%x bytes from port 0x%x ...", length, port);
 
   memset((char*)src,0,length);
-  GENERIC_DEBUG_PRINT(" ignored (return zeroed buffer)\n");
+  PrintDebug(" ignored (return zeroed buffer)\n");
 
   return length;
 }
@@ -186,58 +184,58 @@ int generic_init_device(struct vm_device * dev)
   struct generic_internal *state = (struct generic_internal *)(dev->private_data);
   uint_t i, j;
 
-  GENERIC_DEBUG_PRINT("generic: init_device\n");
+  PrintDebug("generic: init_device\n");
 
   // Would read state here
 
   generic_reset_device(dev);
 
   for (i = 0; i < state->num_port_ranges; i++) { 
-    GENERIC_DEBUG_PRINT("generic: hooking ports 0x%x to 0x%x as %x\n", state->port_ranges[i][0], state->port_ranges[i][1], state->port_ranges[i][2]==GENERIC_PRINT_AND_PASSTHROUGH ? "print-and-passthrough" : "print-and-ignore");
+    PrintDebug("generic: hooking ports 0x%x to 0x%x as %x\n", state->port_ranges[i][0], state->port_ranges[i][1], state->port_ranges[i][2]==GENERIC_PRINT_AND_PASSTHROUGH ? "print-and-passthrough" : "print-and-ignore");
 
 #if PORT_HOOKS
     for (j = state->port_ranges[i][0]; j <= state->port_ranges[i][1]; j++) { 
       if (state->port_ranges[i][2]==GENERIC_PRINT_AND_PASSTHROUGH) { 
        if (dev_hook_io(dev, j, &generic_read_port_passthrough, &generic_write_port_passthrough)) { 
-         GENERIC_DEBUG_PRINT("generic: can't hook port 0x%x (already hooked?)\n", j);
+         PrintDebug("generic: can't hook port 0x%x (already hooked?)\n", j);
        }
       } else if (state->port_ranges[i][2]==GENERIC_PRINT_AND_IGNORE) { 
        if (dev_hook_io(dev, j, &generic_read_port_ignore, &generic_write_port_ignore)) { 
-         GENERIC_DEBUG_PRINT("generic: can't hook port 0x%x (already hooked?)\n", j);
+         PrintDebug("generic: can't hook port 0x%x (already hooked?)\n", j);
        }
       } 
     }
 #else
-    GENERIC_DEBUG_PRINT("generic: hooking ports not supported\n");
+    PrintDebug("generic: hooking ports not supported\n");
 #endif
 
   }
 
   for (i = 0; i < state->num_address_ranges; i++) { 
-    GENERIC_DEBUG_PRINT("generic: hooking addresses 0x%x to 0x%x\n",state->address_ranges[i][0],state->address_ranges[i][1]); 
+    PrintDebug("generic: hooking addresses 0x%x to 0x%x\n",state->address_ranges[i][0],state->address_ranges[i][1]); 
 
 #if MEM_HOOKS
     if (dev_hook_mem(dev, state->address_ranges[i][0], state->address_ranges[i][1])) {
-      GENERIC_DEBUG_PRINT("generic: Can't hook addresses 0x%x to 0x%x (already hooked?)\n",
+      PrintDebug("generic: Can't hook addresses 0x%x to 0x%x (already hooked?)\n",
                  state->address_ranges[i][0], state->address_ranges[i][1]); 
     }
 #else
-    GENERIC_DEBUG_PRINT("generic: hooking addresses not supported\n");
+    PrintDebug("generic: hooking addresses not supported\n");
 #endif
 
   }
 
   for (i = 0; i < state->num_irq_ranges; i++) { 
-    GENERIC_DEBUG_PRINT("generic: hooking irqs 0x%x to 0x%x\n",state->irq_ranges[i][0],state->irq_ranges[i][1]);
+    PrintDebug("generic: hooking irqs 0x%x to 0x%x\n",state->irq_ranges[i][0],state->irq_ranges[i][1]);
 
 #if IRQ_HOOKS
     for (j = state->irq_ranges[i][0]; j <= state->irq_ranges[i][1]; j++) { 
       if (dev_hook_irq(dev, j, &generic_interrupt)) { 
-       GENERIC_DEBUG_PRINT("generic: can't hook irq  0x%x (already hooked?)\n", j);
+       PrintDebug("generic: can't hook irq  0x%x (already hooked?)\n", j);
       }
     }
 #else
-    GENERIC_DEBUG_PRINT("generic: hooking irqs not supported\n");
+    PrintDebug("generic: hooking irqs not supported\n");
 #endif
 
   }
@@ -250,48 +248,48 @@ int generic_deinit_device(struct vm_device *dev)
   struct generic_internal *state = (struct generic_internal *)(dev->private_data);
   uint_t i, j;
 
-  GENERIC_DEBUG_PRINT("generic: deinit_device\n");
+  PrintDebug("generic: deinit_device\n");
 
   for (i = 0; i < state->num_irq_ranges; i++) { 
-    GENERIC_DEBUG_PRINT("generic: unhooking irqs 0x%x to 0x%x\n", state->irq_ranges[i][0], state->irq_ranges[i][1]);
+    PrintDebug("generic: unhooking irqs 0x%x to 0x%x\n", state->irq_ranges[i][0], state->irq_ranges[i][1]);
 
 #if IRQ_HOOKS
     for (j = state->irq_ranges[i][0]; j <= state->irq_ranges[i][1]; j++) { 
       if (dev_unhook_irq(dev, j)) {
-       GENERIC_DEBUG_PRINT("generic: can't unhook irq 0x%x (already unhooked?)\n",j);
+       PrintDebug("generic: can't unhook irq 0x%x (already unhooked?)\n",j);
       }
     }
 #else
-    GENERIC_DEBUG_PRINT("generic: unhooking irqs not supported\n");
+    PrintDebug("generic: unhooking irqs not supported\n");
 #endif
 
   }
 
   for (i = 0; i < state->num_address_ranges; i++) { 
-    GENERIC_DEBUG_PRINT("generic: unhooking addresses 0x%x to 0x%x\n",state->address_ranges[i][0],state->address_ranges[i][1]); 
+    PrintDebug("generic: unhooking addresses 0x%x to 0x%x\n",state->address_ranges[i][0],state->address_ranges[i][1]); 
 
 #if MEM_HOOKS
     if (dev_unhook_mem(dev, state->address_ranges[i][0], state->address_ranges[i][1])) {
-      GENERIC_DEBUG_PRINT("generic: Can't unhook addresses 0x%x to 0x%x (already unhooked?)\n",
+      PrintDebug("generic: Can't unhook addresses 0x%x to 0x%x (already unhooked?)\n",
                  state->address_ranges[i][0], state->address_ranges[i][1]); 
     }
 #else
-    GENERIC_DEBUG_PRINT("generic: unhooking addresses not supported\n");
+    PrintDebug("generic: unhooking addresses not supported\n");
 #endif
 
   }
 
   for (i = 0; i < state->num_port_ranges; i++) { 
-    GENERIC_DEBUG_PRINT("generic: unhooking ports 0x%x to 0x%x\n",state->port_ranges[i][0],state->port_ranges[i][1]);
+    PrintDebug("generic: unhooking ports 0x%x to 0x%x\n",state->port_ranges[i][0],state->port_ranges[i][1]);
 
 #if PORT_HOOKS
     for (j = state->port_ranges[i][0]; j <= state->port_ranges[i][1]; j++) { 
       if (dev_unhook_io(dev, j)) {
-       GENERIC_DEBUG_PRINT("generic: can't unhook port 0x%x (already unhooked?)\n", j);
+       PrintDebug("generic: can't unhook port 0x%x (already unhooked?)\n", j);
       }
     }
 #else
-    GENERIC_DEBUG_PRINT("generic: unhooking ports not supported\n");
+    PrintDebug("generic: unhooking ports not supported\n");
 #endif
 
   }