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 segmentation helper
Jack Lange [Fri, 4 Apr 2008 19:30:27 +0000 (19:30 +0000)]
palacios/include/geekos/vmm_emulate.h
palacios/src/geekos/svm_ctrl_regs.c
palacios/src/geekos/svm_io.c

index 4b843cc..dcead40 100644 (file)
@@ -150,14 +150,14 @@ static inline int is_prefix_byte(char byte) {
 
 
 
-static inline addr_t get_rip_linear(struct guest_info * info, addr_t rip, addr_t cs_base) {
+static inline addr_t get_addr_linear(struct guest_info * info, addr_t addr, addr_t seg_base) {
   switch (info->cpu_mode) {
   case REAL:
-    return rip + (cs_base << 4);
+    return addr + (seg_base << 4);
     break;
   case PROTECTED:
   case PROTECTED_PG:
-    return rip + cs_base;
+    return addr + seg_base;
     break;
   default:
     return 0;
index ffdd3de..75e133f 100644 (file)
@@ -25,7 +25,7 @@ int handle_cr0_write(struct guest_info * info) {
     int ret;
 
     // The real rip address is actually a combination of the rip + CS base 
-    ret = read_guest_pa_memory(info, get_rip_linear(info, guest_state->rip, guest_state->cs.base), 15, instr);
+    ret = read_guest_pa_memory(info, get_addr_linear(info, guest_state->rip, guest_state->cs.base), 15, instr);
     if (ret != 15) {
       // I think we should inject a GPF into the guest
       PrintDebug("Could not read instruction (ret=%d)\n", ret);
@@ -117,7 +117,7 @@ int handle_cr0_write(struct guest_info * info) {
     PrintDebug("Protected Mode write to CR0\n");
 
     // The real rip address is actually a combination of the rip + CS base 
-    ret = read_guest_pa_memory(info, get_rip_linear(info, guest_state->rip, guest_state->cs.base), 15, instr);
+    ret = read_guest_pa_memory(info, get_addr_linear(info, guest_state->rip, guest_state->cs.base), 15, instr);
     if (ret != 0) {
       // I think we should inject a GPF into the guest
       PrintDebug("Could not read instruction (ret=%d)\n", ret);
@@ -200,7 +200,7 @@ int handle_cr0_read(struct guest_info * info) {
     int ret;
 
     // The real rip address is actually a combination of the rip + CS base 
-    ret = read_guest_pa_memory(info, get_rip_linear(info, guest_state->rip, guest_state->cs.base), 15, instr);
+    ret = read_guest_pa_memory(info, get_addr_linear(info, guest_state->rip, guest_state->cs.base), 15, instr);
     if (ret != 15) {
       // I think we should inject a GPF into the guest
       PrintDebug("Could not read instruction (ret=%d)\n", ret);
@@ -257,7 +257,7 @@ int handle_cr0_read(struct guest_info * info) {
     int ret;
 
     // The real rip address is actually a combination of the rip + CS base 
-    ret = read_guest_pa_memory(info, get_rip_linear(info, guest_state->rip, guest_state->cs.base), 15, instr);
+    ret = read_guest_pa_memory(info, get_addr_linear(info, guest_state->rip, guest_state->cs.base), 15, instr);
     if (ret != 15) {
       // I think we should inject a GPF into the guest
       PrintDebug("Could not read instruction (ret=%d)\n", ret);
index e573549..9582893 100644 (file)
@@ -55,18 +55,12 @@ int handle_svm_io_ins(struct guest_info * info) {
   
   vmm_io_hook_t * hook = get_io_hook(&(info->io_map), io_info->port);
   uint_t read_size = 0;
-  addr_t base_addr = 0;
+  addr_t base_addr = guest_state->es.base ;
   addr_t dst_addr = 0;
   uint_t rep_num = 1;
   ullong_t mask = 0;
 
 
-  if (info->cpu_mode == REAL) {
-    base_addr = (guest_state->es.base << 4);
-  } else if (info->cpu_mode == PROTECTED) {
-    base_addr = guest_state->es.base;
-  }
-
 
   // This is kind of hacky...
   // direction can equal either 1 or -1
@@ -113,7 +107,7 @@ int handle_svm_io_ins(struct guest_info * info) {
 
   while (rep_num > 0) {
     addr_t host_addr;
-    dst_addr = base_addr + (info->vm_regs.rdi & mask);
+    dst_addr = get_addr_linear(info, info->vm_regs.rdi & mask, base_addr);
     
     if (guest_va_to_host_va(info, dst_addr, &host_addr) == -1) {
       // either page fault or gpf...
@@ -185,19 +179,13 @@ int handle_svm_io_outs(struct guest_info * info) {
   
   vmm_io_hook_t * hook = get_io_hook(&(info->io_map), io_info->port);
   uint_t write_size = 0;
-  addr_t base_addr = 0;
+  addr_t base_addr = guest_state->ds.base;
   addr_t dst_addr = 0;
   uint_t rep_num = 1;
   ullong_t mask = 0;
 
 
 
-  if (info->cpu_mode == REAL) {
-    base_addr = (guest_state->ds.base << 4);
-  } else if (info->cpu_mode == PROTECTED) {
-    base_addr = guest_state->ds.base;
-  }
-
   // This is kind of hacky...
   // direction can equal either 1 or -1
   // We will multiply the final added offset by this value to go the correct direction
@@ -242,7 +230,7 @@ int handle_svm_io_outs(struct guest_info * info) {
 
   while (rep_num > 0) {
     addr_t host_addr;
-    dst_addr = base_addr + (info->vm_regs.rsi & mask);
+    dst_addr = get_addr_linear(info, (info->vm_regs.rsi & mask), base_addr);
     
     if (guest_va_to_host_va(info, dst_addr, &host_addr) == -1) {
       // either page fault or gpf...