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.


formatting change
Jack Lange [Tue, 30 Sep 2008 21:43:07 +0000 (16:43 -0500)]
palacios/src/devices/generic.c

index b16dd07..d9bf3ea 100644 (file)
 #define IRQ_HOOKS  0   // not yet implemented in device model
 
 struct generic_internal {
-  generic_port_range_type    *port_ranges;
+  generic_port_range_type    * port_ranges;
   uint_t                     num_port_ranges;
-  generic_address_range_type *address_ranges;
+  generic_address_range_type * address_ranges;
   uint_t                     num_address_ranges;
-  generic_irq_range_type     *irq_ranges;
+  generic_irq_range_type     * irq_ranges;
   uint_t                     num_irq_ranges;
 };
 
@@ -42,14 +42,14 @@ int generic_reset_device(struct vm_device * dev)
 
 
 
-int generic_start_device(struct vm_device *dev)
+int generic_start_device(struct vm_device * dev)
 {
   PrintDebug("generic: start device\n");
   return 0;
 }
 
 
-int generic_stop_device(struct vm_device *dev)
+int generic_stop_device(struct vm_device * dev)
 {
   PrintDebug("generic: stop device\n");
   return 0;
@@ -76,13 +76,13 @@ int generic_write_port_passthrough(ushort_t port,
 
   switch (length) {
   case 1:
-    Out_Byte(port,((uchar_t*)src)[0]);
+    Out_Byte(port, ((uchar_t*)src)[0]);
     break;
   case 2:
-    Out_Word(port,((ushort_t*)src)[0]);
+    Out_Word(port, ((ushort_t*)src)[0]);
     break;
   case 4:
-    Out_DWord(port,((uint_t*)src)[0]);
+    Out_DWord(port, ((uint_t*)src)[0]);
     break;
   default:
     for (i = 0; i < length; i++) { 
@@ -161,7 +161,7 @@ int generic_read_port_ignore(ushort_t port,
 
   PrintDebug("generic: reading 0x%x bytes from port 0x%x ...", length, port);
 
-  memset((char*)src,0,length);
+  memset((char*)src, 0, length);
   PrintDebug(" ignored (return zeroed buffer)\n");
 
   return length;
@@ -169,21 +169,17 @@ int generic_read_port_ignore(ushort_t port,
 
 
 
-int generic_interrupt(uint_t irq,
-                     struct vm_device * dev) 
-{
+int generic_interrupt(uint_t irq, struct vm_device * dev) {
   PrintDebug("generic: interrupt 0x%x - injecting into VM\n", irq);
 
   dev->vm->vm_ops.raise_irq(dev->vm, irq);
 
   return 0;
-
 }
 
 
-int generic_init_device(struct vm_device * dev) 
-{
-  struct generic_internal *state = (struct generic_internal *)(dev->private_data);
+int generic_init_device(struct vm_device * dev) {
+  struct generic_internal * state = (struct generic_internal *)(dev->private_data);
   uint_t i, j;
 
   PrintDebug("generic: init_device\n");
@@ -193,60 +189,69 @@ int generic_init_device(struct vm_device * dev)
   generic_reset_device(dev);
 
   for (i = 0; i < state->num_port_ranges; i++) { 
-    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)) { 
-         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)) { 
-         PrintDebug("generic: can't hook port 0x%x (already hooked?)\n", j);
-       }
-      } 
+    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) { // This is a runtime conditional on a #define
+      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)) { 
+           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)) { 
+           PrintDebug("generic: can't hook port 0x%x (already hooked?)\n", j);
+         }
+
+       } 
+      }
+    } else {
+      PrintDebug("generic: hooking ports not supported\n");
     }
-#else
-    PrintDebug("generic: hooking ports not supported\n");
-#endif
 
   }
 
   for (i = 0; i < state->num_address_ranges; i++) { 
-    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])) {
-      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
-    PrintDebug("generic: hooking addresses not supported\n");
-#endif
+    PrintDebug("generic: hooking addresses 0x%x to 0x%x\n", 
+              state->address_ranges[i][0], state->address_ranges[i][1]); 
 
+    if (MEM_HOOKS) { // This is a runtime conditional on a #define
+      if (dev_hook_mem(dev, state->address_ranges[i][0], state->address_ranges[i][1])) {
+       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 {
+      PrintDebug("generic: hooking addresses not supported\n");
+    }
   }
 
   for (i = 0; i < state->num_irq_ranges; i++) { 
-    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)) { 
-       PrintDebug("generic: can't hook irq  0x%x (already hooked?)\n", j);
+    PrintDebug("generic: hooking irqs 0x%x to 0x%x\n",
+              state->irq_ranges[i][0], state->irq_ranges[i][1]);
+
+    if (IRQ_HOOKS) { // This is a runtime conditional on a #define
+      for (j = state->irq_ranges[i][0]; j <= state->irq_ranges[i][1]; j++) { 
+       if (dev_hook_irq(dev, j, &generic_interrupt)) { 
+         PrintDebug("generic: can't hook irq  0x%x (already hooked?)\n", j);
+       }
       }
+    } else {
+      PrintDebug("generic: hooking irqs not supported\n");
     }
-#else
-    PrintDebug("generic: hooking irqs not supported\n");
-#endif
 
   }
 
   return 0;
 }
 
-int generic_deinit_device(struct vm_device *dev)
-{
+int generic_deinit_device(struct vm_device * dev) {
   struct generic_internal *state = (struct generic_internal *)(dev->private_data);
   uint_t i, j;
 
@@ -254,46 +259,53 @@ int generic_deinit_device(struct vm_device *dev)
 
 
   for (i = 0; i < state->num_irq_ranges; i++) { 
-    PrintDebug("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) { // This is a runtime conditional on a #define
+      for (j = state->irq_ranges[i][0]; j <= state->irq_ranges[i][1]; j++) { 
+
+       if (dev_unhook_irq(dev, j)) {
+         PrintDebug("generic: can't unhook irq 0x%x (already unhooked?)\n",j);
+       }
 
-#if IRQ_HOOKS
-    for (j = state->irq_ranges[i][0]; j <= state->irq_ranges[i][1]; j++) { 
-      if (dev_unhook_irq(dev, j)) {
-       PrintDebug("generic: can't unhook irq 0x%x (already unhooked?)\n",j);
       }
+    } else {
+      PrintDebug("generic: unhooking irqs not supported\n");
     }
-#else
-    PrintDebug("generic: unhooking irqs not supported\n");
-#endif
-
   }
 
   for (i = 0; i < state->num_address_ranges; i++) { 
-    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])) {
-      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
-    PrintDebug("generic: unhooking addresses not supported\n");
-#endif
+    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])) {
+
+       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 {
+      PrintDebug("generic: unhooking addresses not supported\n");
+    }
   }
 
   for (i = 0; i < state->num_port_ranges; i++) { 
-    PrintDebug("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)) {
-       PrintDebug("generic: can't unhook port 0x%x (already unhooked?)\n", j);
+    if (PORT_HOOKS) {
+      for (j = state->port_ranges[i][0]; j <= state->port_ranges[i][1]; j++) { 
+       if (dev_unhook_io(dev, j)) {
+         PrintDebug("generic: can't unhook port 0x%x (already unhooked?)\n", j);
+       }
       }
+    } else {
+      PrintDebug("generic: unhooking ports not supported\n");
     }
-#else
-    PrintDebug("generic: unhooking ports not supported\n");
-#endif
 
   }
 
@@ -322,39 +334,66 @@ struct vm_device *create_generic(generic_port_range_type    port_ranges[],
 {
   struct generic_internal * generic_state = (struct generic_internal *)V3_Malloc(sizeof(struct generic_internal));
   int i;
-  uint_t num_port_ranges, num_address_ranges, num_irq_ranges;
-
-  num_port_ranges=0;
-  if (port_ranges!=NULL) { 
-    i=0;
-    while (port_ranges[i]!=NULL && 
-          !(port_ranges[i][0]==0 && port_ranges[i][1]==0 && port_ranges[i][2]==0)) 
-      { num_port_ranges++; i++; }
+  uint_t num_port_ranges;
+  uint_t num_address_ranges;
+  uint_t num_irq_ranges;
+
+
+  num_port_ranges = 0;
+
+  if (port_ranges != NULL) { 
+    i = 0;
+
+    while ((port_ranges[i] != NULL) && 
+          ( !( (port_ranges[i][0] == 0) && 
+               (port_ranges[i][1] == 0) && 
+               (port_ranges[i][2] == 0)) ) ) 
+      {
+       num_port_ranges++; 
+       i++; 
+      }
   }
 
   
-  num_address_ranges=0;
-  if (address_ranges!=NULL) { 
-    i=0;
-    while (address_ranges[i]!=NULL  && 
-          !(address_ranges[i][0]==0 && address_ranges[i][1]==0 && address_ranges[i][2]==0)) 
-      { num_address_ranges++; i++; }
+  num_address_ranges = 0;
+
+  if (address_ranges != NULL) { 
+    i = 0;
+
+    while ((address_ranges[i] != NULL)  && 
+          ( !( (address_ranges[i][0] == 0) && 
+               (address_ranges[i][1] == 0) && 
+               (address_ranges[i][2] == 0)) ) ) 
+      { 
+       num_address_ranges++; 
+       i++; 
+      }
   }
 
-  num_irq_ranges=0;
-  if (irq_ranges!=NULL) { 
-    i=0;
-    while (irq_ranges[i]!=NULL && 
-          !(irq_ranges[i][0]==0 && irq_ranges[i][1]==0 && irq_ranges[i][2]==0) ) 
-      { num_irq_ranges++; i++; }
+  num_irq_ranges = 0;
+
+  if (irq_ranges != NULL) { 
+    i = 0;
+
+    while ((irq_ranges[i] != NULL) && 
+          ( !( (irq_ranges[i][0] == 0) && 
+               (irq_ranges[i][1] == 0) && 
+               (irq_ranges[i][2] == 0)) ) ) 
+      { 
+       num_irq_ranges++; 
+       i++; 
+      }
   }
     
 
   generic_state->num_port_ranges = num_port_ranges;
 
   if (num_port_ranges > 0) { 
-    generic_state->port_ranges = V3_Malloc(sizeof(generic_address_range_type) * num_port_ranges);
-    memcpy(generic_state->port_ranges, port_ranges, sizeof(generic_port_range_type) * num_port_ranges);
+   generic_state->port_ranges = V3_Malloc(sizeof(generic_address_range_type) * num_port_ranges);
+   memcpy(generic_state->port_ranges, port_ranges, 
+         (sizeof(generic_port_range_type) * num_port_ranges));
+   
   } else {
     generic_state->port_ranges = NULL;
   }
@@ -363,8 +402,11 @@ struct vm_device *create_generic(generic_port_range_type    port_ranges[],
   generic_state->num_address_ranges = num_address_ranges;
 
   if (num_address_ranges > 0) { 
+
     generic_state->address_ranges = V3_Malloc(sizeof(generic_address_range_type) * num_address_ranges);
-    memcpy(generic_state->address_ranges, address_ranges, sizeof(generic_address_range_type) * num_address_ranges);
+    memcpy(generic_state->address_ranges, address_ranges, 
+          (sizeof(generic_address_range_type) * num_address_ranges));
+
   } else {
     generic_state->address_ranges = NULL;
   }
@@ -373,8 +415,11 @@ struct vm_device *create_generic(generic_port_range_type    port_ranges[],
   generic_state->num_irq_ranges = num_irq_ranges;
 
   if (num_irq_ranges > 0) { 
+
     generic_state->irq_ranges = V3_Malloc(sizeof(generic_address_range_type) * num_irq_ranges);
-    memcpy(generic_state->irq_ranges, irq_ranges, sizeof(generic_irq_range_type) * num_port_ranges);
+    memcpy(generic_state->irq_ranges, irq_ranges, 
+          (sizeof(generic_irq_range_type) * num_port_ranges));
+
   } else {
     generic_state->irq_ranges = NULL;
   }