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 invlpg support
[palacios.git] / palacios / src / palacios / svm.c
index 2003ba7..7889c11 100644 (file)
@@ -9,10 +9,7 @@
 #include <palacios/vmm_debug.h>
 #include <palacios/vm_guest_mem.h>
 
-
-/* TEMPORARY BECAUSE SVM IS WEIRD */
-//#include <palacios/tss.h>
-/* ** */
+#include <palacios/vmm_emulate.h>
 
 
 extern struct vmm_os_hooks * os_hooks;
@@ -22,12 +19,13 @@ extern uint_t cpuid_edx(uint_t op);
 extern void Get_MSR(uint_t MSR, uint_t * high_byte, uint_t * low_byte); 
 extern void Set_MSR(uint_t MSR, uint_t high_byte, uint_t low_byte);
 extern uint_t launch_svm(vmcb_t * vmcb_addr);
-extern void safe_svm_launch(vmcb_t * vmcb_addr, struct guest_gprs * gprs);
+extern void safe_svm_launch(vmcb_t * vmcb_addr, struct v3_gprs * gprs);
+
+extern void STGI();
+extern void CLGI();
 
 extern uint_t Get_CR3();
 
-extern void GetGDTR(void * gdt);
-extern void GetIDTR(void * idt);
 
 extern void DisableInts();
 
@@ -142,14 +140,42 @@ int start_svm_guest(struct guest_info *info) {
 
   while (1) {
 
+    CLGI();
+
     //PrintDebug("SVM Launch Args (vmcb=%x), (info=%x), (vm_regs=%x)\n", info->vmm_data,  &(info->vm_regs));
     //PrintDebug("Launching to RIP: %x\n", info->rip);
     safe_svm_launch((vmcb_t*)(info->vmm_data), &(info->vm_regs));
     //launch_svm((vmcb_t*)(info->vmm_data));
     //PrintDebug("SVM Returned\n");
 
+    
+
+    STGI();
+
+     
     if (handle_svm_exit(info) != 0) {
-      // handle exit code....
+      vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data));
+      addr_t host_addr;
+      addr_t linear_addr = 0;
+
+      PrintDebug("SVM ERROR!!\n"); 
+      
+
+      PrintDebug("RIP: %x\n", guest_state->rip);
+
+
+      linear_addr = get_addr_linear(info, guest_state->rip, &(info->segments.cs));
+
+
+      PrintDebug("RIP Linear: %x\n", linear_addr);
+
+      guest_pa_to_host_pa(info, linear_addr, &host_addr);
+
+      PrintDebug("Host Address of rip = 0x%x\n", host_addr);
+
+      PrintDebug("Instr (15 bytes) at %x:\n", host_addr);
+      PrintTraceMemDump((char*)host_addr, 15);
+
       break;
     }
   }
@@ -251,10 +277,10 @@ void Init_VMCB(vmcb_t * vmcb, struct guest_info vm_info) {
 
   if (vm_info.page_mode == SHADOW_PAGING) {
     PrintDebug("Creating initial shadow page table\n");
-    vm_info.shdw_pg_state.shadow_cr3.e_reg.low |= ((addr_t)create_passthrough_pde32_pts(&vm_info) & ~0xfff);
+    vm_info.shdw_pg_state.shadow_cr3 |= ((addr_t)create_passthrough_pde32_pts(&vm_info) & ~0xfff);
     PrintDebug("Created\n");
 
-    guest_state->cr3 = vm_info.shdw_pg_state.shadow_cr3.r_reg;
+    guest_state->cr3 = vm_info.shdw_pg_state.shadow_cr3;
 
     ctrl_area->cr_reads.cr3 = 1;
     ctrl_area->cr_writes.cr3 = 1;
@@ -301,6 +327,8 @@ void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info vm_info) {
   // guest_state->rip = vm_info.rip;
   guest_state->rip = 0xfff0;
 
+  guest_state->cpl = 0;
+
   //ctrl_area->instrs.instrs.CR0 = 1;
   ctrl_area->cr_reads.cr0 = 1;
   ctrl_area->cr_writes.cr0 = 1;
@@ -308,6 +336,7 @@ void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info vm_info) {
   guest_state->efer |= EFER_MSR_svm_enable;
   guest_state->rflags = 0x00000002; // The reserved bit is always 1
   ctrl_area->svm_instrs.VMRUN = 1;
+  ctrl_area->instrs.HLT = 1;
   // guest_state->cr0 = 0x00000001;    // PE 
   ctrl_area->guest_ASID = 1;
 
@@ -377,7 +406,7 @@ void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info vm_info) {
       uchar_t * bitmap = (uchar_t *)io_port_bitmap;
 
       bitmap += (port / 8);
-      PrintDebug("Setting Bit in block %x\n", bitmap);
+      PrintDebug("Setting Bit for port 0x%x\n", port);
       *bitmap |= 1 << (port % 8);
     }
 
@@ -387,16 +416,19 @@ void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info vm_info) {
     ctrl_area->instrs.IOIO_PROT = 1;
   }
 
-  //ctrl_area->instrs.instrs.INTR = 1;
 
 
+  PrintDebug("Exiting on interrupts\n");
+  ctrl_area->guest_ctrl.V_INTR_MASKING = 1;
+  ctrl_area->instrs.INTR = 1;
+
 
   if (vm_info.page_mode == SHADOW_PAGING) {
     PrintDebug("Creating initial shadow page table\n");
-    vm_info.shdw_pg_state.shadow_cr3.e_reg.low |= ((addr_t)create_passthrough_pde32_pts(&vm_info) & ~0xfff);
+    vm_info.shdw_pg_state.shadow_cr3 |= ((addr_t)create_passthrough_pde32_pts(&vm_info) & ~0xfff);
     PrintDebug("Created\n");
 
-    guest_state->cr3 = vm_info.shdw_pg_state.shadow_cr3.r_reg;
+    guest_state->cr3 = vm_info.shdw_pg_state.shadow_cr3;
 
     //PrintDebugPageTables((pde32_t*)(vm_info.shdw_pg_state.shadow_cr3.e_reg.low));
 
@@ -434,6 +466,7 @@ void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info vm_info) {
 }
 
 
+#if 0
 void Init_VMCB_pe(vmcb_t *vmcb, struct guest_info vm_info) {
   vmcb_ctrl_t * ctrl_area = GET_VMCB_CTRL_AREA(vmcb);
   vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA(vmcb);
@@ -597,7 +630,7 @@ void Init_VMCB_pe(vmcb_t *vmcb, struct guest_info vm_info) {
 
 
 
-
+#endif