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.


something that sort of works more than it did previously....
Jack Lange [Wed, 16 Apr 2008 06:07:07 +0000 (06:07 +0000)]
palacios/include/geekos/vmm_stubs.h
palacios/src/devices/nvram.c
palacios/src/geekos/vm.c
palacios/src/palacios/svm.c
palacios/src/palacios/svm_handler.c
palacios/src/palacios/svm_io.c
palacios/src/palacios/svm_lowlevel.asm

index 06e7189..d6a8441 100644 (file)
@@ -14,4 +14,6 @@ void VMM_Free(void * addr);
 
 void * Identity(void *addr);
 
+void Hook_IRQ(int irq, void (*handler)());
+
 #endif
index 52ae710..785cb45 100644 (file)
@@ -90,7 +90,7 @@ int nvram_write_reg_port(ushort_t port,
 
   memcpy(&(data->thereg), src, 1);
 
-  return 0;
+  return 1;
 }
 
 
@@ -103,7 +103,7 @@ int nvram_read_data_port(ushort_t port,
 
   memcpy(dst, &(data->mem_state[data->thereg]), 1);
 
-  return 0;
+  return 1;
 }
 
 int nvram_write_data_port(ushort_t port,
@@ -115,7 +115,7 @@ int nvram_write_data_port(ushort_t port,
 
   memcpy(&(data->mem_state[data->thereg]), src, 1);
 
-  return 0;
+  return 1;
 }
 
 
index b0e2b3f..1005507 100644 (file)
@@ -41,30 +41,26 @@ inline uchar_t VM_In_Byte(ushort_t port)
 
 
 int IO_Read(ushort_t port, void * dst, uint_t length, void * priv_data) {
-  uchar_t * iter = dst;
-  uint_t i;
 
-  for (i = 0; i < length; i++) {
-    *iter = VM_In_Byte(port);    
-    iter++;
+  if (length != 1) {
+    return 0;
   }
-  
-  return 0;
+
+  *(uchar_t*)dst = VM_In_Byte(port);    
+  return 1;
 }
 
 
 
 int IO_Write(ushort_t port, void * src, uint_t length, void * priv_data) {
-  uchar_t * iter = src;
-  uint_t i;
 
-
-  for (i = 0; i < length; i++) {
-    VM_Out_Byte(port, *iter);    
-    iter++;
+  if (length != 1) {
+    return 0;
   }
 
-  return 0;
+  VM_Out_Byte(port, *(uchar_t *)src);    
+
+  return 1;
 }
 
 
@@ -291,7 +287,7 @@ int RunVMM(struct Boot_Info * bootInfo) {
 
       {
        struct vm_device * nvram = create_nvram();
-       struct vm_device * timer = create_timer();
+       //struct vm_device * timer = create_timer();
 
        attach_device(&(vm_info), nvram);
        //attach_device(&(vm_info), timer);
@@ -301,7 +297,6 @@ int RunVMM(struct Boot_Info * bootInfo) {
 
 
       }
-      PrintDebug("foo\n");
 
 
       vm_info.rip = 0xfff0;
index 4a16070..077e95c 100644 (file)
@@ -20,10 +20,11 @@ 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 STGI();
+extern void CLGI();
+
 extern uint_t Get_CR3();
 
-extern void GetGDTR(void * gdt);
-extern void GetIDTR(void * idt);
 
 extern void DisableInts();
 
@@ -138,14 +139,18 @@ 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");
+    // PrintDebug("SVM Returned\n");
 
+    STGI();
+    
     if (handle_svm_exit(info) != 0) {
-      // handle exit code....
+      PrintDebug("SVM ERROR!!\n");
       break;
     }
   }
@@ -384,11 +389,10 @@ void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info vm_info) {
   }
 
 
-  if (vm_info.irq_map.num_hooks > 0) {
-    PrintDebug("Exiting on interrupts\n");
-    ctrl_area->guest_ctrl.V_INTR_MASKING = 1;
-    ctrl_area->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) {
@@ -434,6 +438,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 +602,7 @@ void Init_VMCB_pe(vmcb_t *vmcb, struct guest_info vm_info) {
 
 
 
-
+#endif
 
 
 
index c7ee14c..a2e7e14 100644 (file)
@@ -29,20 +29,35 @@ int handle_svm_exit(struct guest_info * info) {
  
   // PrintDebugVMCB((vmcb_t*)(info->vmm_data));
 
+
+  // PrintDebug("SVM Returned:(VMCB=%x)\n", info->vmm_data); 
+  //PrintDebug("RIP: %x\n", guest_state->rip);
+
+  
+  //PrintDebug("SVM Returned: Exit Code: %x\n",exit_code); 
+  
   if (exit_code == VMEXIT_IOIO) {
     struct svm_io_info * io_info = (struct svm_io_info *)&(guest_ctrl->exit_info1);
     
     if (io_info->type == 0) {
       if (io_info->str) {
-       handle_svm_io_outs(info);
+       if (handle_svm_io_outs(info) == -1 ) {
+         return -1;
+       }
       } else {
-       handle_svm_io_out(info);
+       if (handle_svm_io_out(info) == -1) {
+         return -1;
+       }
       }
     } else {
       if (io_info->str) {
-       handle_svm_io_ins(info);
+       if (handle_svm_io_ins(info) == -1) {
+         return -1;
+       }
       } else {
-       handle_svm_io_in(info);
+       if (handle_svm_io_in(info) == -1) {
+         return -1;
+       }
       }
     }
   } else if (exit_code == VMEXIT_CR0_WRITE) {
@@ -62,7 +77,8 @@ int handle_svm_exit(struct guest_info * info) {
     */
 
   } else if (exit_code == VMEXIT_INTR) {
-    handle_svm_intr(info);
+
+    //    handle_svm_intr(info);
   } else {
     addr_t rip_addr = get_addr_linear(info, guest_state->rip, guest_state->cs.selector);
     char buf[15];
index 3668897..4706817 100644 (file)
@@ -15,11 +15,12 @@ int handle_svm_io_in(struct guest_info * info) {
   uint_t read_size = 0;
 
   if (hook == NULL) {
+    PrintDebug("Hook Not present for in on port %x\n", io_info->port);
     // error, we should not have exited on this port
     return -1;
   }
 
-  //PrintDebug("IN on  port %d (0x%x)\n", io_info->port, io_info->port);
+  PrintDebug("IN on  port %d (0x%x)\n", io_info->port, io_info->port);
 
   if (io_info->sz8) { 
     read_size = 1;
@@ -32,6 +33,7 @@ int handle_svm_io_in(struct guest_info * info) {
 
   if (hook->read(io_info->port, &(info->vm_regs.rax), read_size, hook->priv_data) != read_size) {
     // not sure how we handle errors.....
+    PrintDebug("Read Failure for in on port %x\n", io_info->port);
     return -1;
   }
 
@@ -73,11 +75,12 @@ int handle_svm_io_ins(struct guest_info * info) {
 
 
   if (hook == NULL) {
+   PrintDebug("Hook Not present for ins on port %x\n", io_info->port);
     // error, we should not have exited on this port
     return -1;
   }
 
-  //PrintDebug("INS on  port %d (0x%x)\n", io_info->port, io_info->port);
+  PrintDebug("INS on  port %d (0x%x)\n", io_info->port, io_info->port);
 
   if (io_info->sz8) { 
     read_size = 1;
@@ -115,6 +118,7 @@ int handle_svm_io_ins(struct guest_info * info) {
 
     if (hook->read(io_info->port, (char*)host_addr, read_size, hook->priv_data) != read_size) {
       // not sure how we handle errors.....
+      PrintDebug("Read Failure for ins on port %x\n", io_info->port);
       return -1;
     }
 
@@ -141,11 +145,12 @@ int handle_svm_io_out(struct guest_info * info) {
   uint_t write_size = 0;
 
   if (hook == NULL) {
+    PrintDebug("Hook Not present for out on port %x\n", io_info->port);
     // error, we should not have exited on this port
     return -1;
   }
 
-  //PrintDebug("OUT on  port %d (0x%x)\n", io_info->port, io_info->port);
+  PrintDebug("OUT on  port %d (0x%x)\n", io_info->port, io_info->port);
 
   if (io_info->sz8) { 
     write_size = 1;
@@ -158,6 +163,7 @@ int handle_svm_io_out(struct guest_info * info) {
 
   if (hook->write(io_info->port, &(info->vm_regs.rax), write_size, hook->priv_data) != write_size) {
     // not sure how we handle errors.....
+    PrintDebug("Write Failure for out on port %x\n", io_info->port);
     return -1;
   }
 
@@ -197,11 +203,12 @@ int handle_svm_io_outs(struct guest_info * info) {
 
 
   if (hook == NULL) {
+    PrintDebug("Hook Not present for outs on port %x\n", io_info->port);
     // error, we should not have exited on this port
     return -1;
   }
 
-  //PrintDebug("OUTS on  port %d (0x%x)\n", io_info->port, io_info->port);
+  PrintDebug("OUTS on  port %d (0x%x)\n", io_info->port, io_info->port);
 
   if (io_info->sz8) { 
     write_size = 1;
@@ -238,6 +245,7 @@ int handle_svm_io_outs(struct guest_info * info) {
 
     if (hook->write(io_info->port, (char*)host_addr, write_size, hook->priv_data) != write_size) {
       // not sure how we handle errors.....
+      PrintDebug("Write Failure for outs on port %x\n", io_info->port);
       return -1;
     }
 
index 4731571..503776f 100644 (file)
@@ -12,9 +12,6 @@ SVM_SUCCESS equ 0x00000000
 
 EXPORT DisableInts
 
-EXPORT GetGDTR
-EXPORT GetIDTR
-EXPORT GetTR
 
 EXPORT exit_test
 
@@ -23,6 +20,8 @@ EXTERN handle_svm_exit
 EXPORT launch_svm
 EXPORT safe_svm_launch
 
+EXPORT STGI
+EXPORT CLGI
 
 
 
@@ -81,6 +80,14 @@ SVM_HANDLER_HALT equ 0x2
        db      00fh, 001h, 0dah
 %endmacro
 
+%macro stgi 0
+       db      00fh, 001h, 0dch
+%endmacro
+
+%macro clgi 0
+       db      00fh, 001h, 0ddh
+%endmacro
+
 ;VMRUN  equ db 0Fh, 01h, D8h
 ;VMLOAD equ db 0x0F,0x01,0xDA
 ;VMSAVE equ db 0x0F,0x01,0xDB
@@ -94,44 +101,15 @@ DisableInts:
        ret
 
 
-align 8
-GetGDTR:
-       push    ebp
-       mov     ebp, esp
-       pusha   
-       mov     ebx, [ebp + 8]
-       sgdt    [ebx]
-       
-       popa
-       pop     ebp
-       ret
-
 
 align 8
-GetIDTR:
-       push    ebp
-       mov     ebp, esp
-       pusha   
-
-       mov     ebx, [ebp + 8]
-       sidt    [ebx]
-       
-       popa
-       pop     ebp
+CLGI:
+       clgi
        ret
 
-
-
 align 8
-GetTR:
-       push    ebp
-       mov     ebp, esp
-       pusha   
-       mov     ebx, [ebp + 8]
-       str     [ebx]
-       
-       popa
-       pop     ebp
+STGI:
+       stgi
        ret