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 address width calculations
[palacios.git] / palacios / src / palacios / vm_guest.c
index 614c6a5..5406e7a 100644 (file)
@@ -29,7 +29,7 @@
 v3_vm_cpu_mode_t v3_get_cpu_mode(struct guest_info * info) {
   struct cr0_32 * cr0;
   struct cr4_32 * cr4 = (struct cr4_32 *)&(info->ctrl_regs.cr4);
-  struct efer_64 * efer = (struct efer_64 *)&(info->ctrl_regs.efer);
+  struct efer_64 * efer = (struct efer_64 *)&(info->guest_efer);
   struct v3_segment * cs = &(info->segments.cs);
 
   if (info->shdw_pg_mode == SHADOW_PAGING) {
@@ -56,6 +56,37 @@ v3_vm_cpu_mode_t v3_get_cpu_mode(struct guest_info * info) {
   }
 }
 
+// Get address width in bytes
+uint_t v3_get_addr_width(struct guest_info * info) {
+  struct cr0_32 * cr0;
+  struct cr4_32 * cr4 = (struct cr4_32 *)&(info->ctrl_regs.cr4);
+  struct efer_64 * efer = (struct efer_64 *)&(info->guest_efer);
+  struct v3_segment * cs = &(info->segments.cs);
+
+  if (info->shdw_pg_mode == SHADOW_PAGING) {
+    cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
+  } else if (info->shdw_pg_mode == NESTED_PAGING) {
+    cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
+  } else {
+    PrintError("Invalid Paging Mode...\n");
+    V3_ASSERT(0);
+    return -1;
+  }
+
+  if (cr0->pe == 0) {
+    return 2;
+  } else if ((cr4->pae == 0) && (efer->lme == 0)) {
+    return 4;
+  } else if (efer->lme == 0) {
+    return 4;
+  } else if ((efer->lme == 1) && (cs->long_mode == 1)) {
+    return 8;
+  } else {
+    // What about LONG_16_COMPAT???
+    return 4;
+  }
+}
+
 
 static const uchar_t REAL_STR[] = "Real";
 static const uchar_t PROTECTED_STR[] = "Protected";
@@ -130,8 +161,9 @@ void v3_print_segments(struct guest_info * info) {
 
   for (i = 0; seg_names[i] != NULL; i++) {
 
-    PrintDebug("\t%s: Sel=%x, base=%p, limit=%x\n", seg_names[i], seg_ptr[i].selector, 
-              (void *)(addr_t)seg_ptr[i].base, seg_ptr[i].limit);
+    PrintDebug("\t%s: Sel=%x, base=%p, limit=%x (long_mode=%d, db=%d)\n", seg_names[i], seg_ptr[i].selector, 
+              (void *)(addr_t)seg_ptr[i].base, seg_ptr[i].limit,
+              seg_ptr[i].long_mode, seg_ptr[i].db);
 
   }
 
@@ -158,6 +190,7 @@ void v3_print_ctrl_regs(struct guest_info * info) {
 }
 
 
+#ifdef __V3_32BIT__
 void v3_print_GPRs(struct guest_info * info) {
   struct v3_gprs * regs = &(info->vm_regs);
   int i = 0;
@@ -172,3 +205,23 @@ void v3_print_GPRs(struct guest_info * info) {
     PrintDebug("\t%s=0x%p\n", reg_names[i], (void *)(addr_t)reg_ptr[i]);  
   }
 }
+#elif __V3_64BIT__
+void v3_print_GPRs(struct guest_info * info) {
+  struct v3_gprs * regs = &(info->vm_regs);
+  int i = 0;
+  v3_reg_t * reg_ptr;
+  char * reg_names[] = { "RDI", "RSI", "RBP", "RSP", "RBX", "RDX", "RCX", "RAX", \
+                        "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15", NULL};
+
+  reg_ptr= (v3_reg_t *)regs;
+
+  PrintDebug("64 bit GPRs:\n");
+
+  for (i = 0; reg_names[i] != NULL; i++) {
+    PrintDebug("\t%s=0x%p\n", reg_names[i], (void *)(addr_t)reg_ptr[i]);  
+  }
+}
+
+
+
+#endif