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.


Cleanup of linkage issues for non-Linux hosts
[palacios.git] / palacios / include / palacios / vmx_lowlevel.h
index 9ea6ffb..713875f 100644 (file)
 
 
 
-static inline int v3_enable_vmx(addr_t vmxon_ptr) {
-    uint64_t vmxon_ptr_64 __attribute__((aligned(8))) = (uint64_t)vmxon_ptr;
-    uint8_t ret_invalid = 0;
-
-    __asm__ __volatile__ (
-                VMXON_OPCODE
-                EAX_06_MODRM
-                "setnaeb %0;" // fail invalid (CF=1)
-                : "=q"(ret_invalid)
-                : "a"(&vmxon_ptr_64),"0"(ret_invalid)
-                : "memory");
 
-    if (ret_invalid) {
-        return VMX_FAIL_INVALID;
-    } else {
-        return VMX_SUCCESS;
-    }
-}
 
 static inline int vmcs_clear(addr_t vmcs_ptr) {
     uint64_t vmcs_ptr_64 __attribute__ ((aligned(8))) = (uint64_t)vmcs_ptr;
@@ -114,21 +97,21 @@ static inline int vmcs_load(addr_t vmcs_ptr) {
     return VMX_SUCCESS;
 }
 
-static inline int vmcs_store(addr_t vmcs_ptr) {
-    uint64_t vmcs_ptr_64 = (uint64_t)vmcs_ptr;
+static inline uint64_t vmcs_store() {
+    uint64_t vmcs_ptr = 0;
 
     __asm__ __volatile__ (
                VMPTRST_OPCODE
                EAX_07_MODRM
                :
-               : "a"(&vmcs_ptr_64)
+               : "a"(&vmcs_ptr)
                : "memory");
 
-    return VMX_SUCCESS;
+    return vmcs_ptr;
 }
 
 static inline int vmcs_read(vmcs_field_t vmcs_field, void * dst) {
-    uint64_t val = 0;
+    addr_t val = 0;
     uint8_t ret_valid = 0;
     uint8_t ret_invalid = 0;
 
@@ -155,6 +138,8 @@ static inline int vmcs_read(vmcs_field_t vmcs_field, void * dst) {
         case 8:
             *((uint64_t*)dst) = (uint64_t)val;
             break;
+       default:
+            return -1;
     }
 
 
@@ -170,7 +155,7 @@ static inline int vmcs_write(vmcs_field_t vmcs_field, addr_t value) {
                 EAX_ECX_MODRM
                 "seteb %0;" // fail valid (ZF=1)
                 "setnaeb %1;" // fail invalid (CF=1)
-                : "=r" (ret_valid), "=r" (ret_invalid)
+                : "=q" (ret_valid), "=q" (ret_invalid)
                 : "a" (vmcs_field), "c"(value)
                 : "memory");
 
@@ -179,6 +164,26 @@ static inline int vmcs_write(vmcs_field_t vmcs_field, addr_t value) {
     return VMX_SUCCESS;
 }
 
+
+static inline int vmx_on(addr_t vmxon_ptr) {
+    uint64_t vmxon_ptr_64 __attribute__((aligned(8))) = (uint64_t)vmxon_ptr;
+    uint8_t ret_invalid = 0;
+
+    __asm__ __volatile__ (
+                VMXON_OPCODE
+                EAX_06_MODRM
+                "setnaeb %0;" // fail invalid (CF=1)
+                : "=q"(ret_invalid)
+                : "a"(&vmxon_ptr_64),"0"(ret_invalid)
+                : "memory");
+
+    if (ret_invalid) {
+        return VMX_FAIL_INVALID;
+    } else {
+        return VMX_SUCCESS;
+    }
+}
+
 static inline int vmx_off() {
     uint8_t ret_valid = 0;
     uint8_t ret_invalid = 0;
@@ -196,6 +201,57 @@ static inline int vmx_off() {
     return VMX_SUCCESS;
 }
 
+
+static inline int enable_vmx() {
+#ifdef __V3_64BIT__
+    __asm__ __volatile__ (
+                         "movq %%cr4, %%rcx;"
+                         "orq  $0x00002000, %%rcx;"
+                         "movq %%rcx, %%cr4;"
+                         : 
+                         :
+                         : "%rcx"
+                         );
+
+
+    __asm__ __volatile__ (
+                         "movq %%cr0, %%rcx; "
+                         "orq  $0x00000020,%%rcx; "
+                         "movq %%rcx, %%cr0;"
+                         :
+                         :
+                         : "%rcx"
+                         );
+#elif __V3_32BIT__
+    __asm__ __volatile__ (
+                         "movl %%cr4, %%ecx;"
+                         "orl  $0x00002000, %%ecx;"
+                         "movl %%ecx, %%cr4;"
+                         : 
+                         :
+                         : "%ecx"
+                         );
+
+
+
+    __asm__ __volatile__ (
+                         "movl %%cr0, %%ecx; "
+                         "orl  $0x00000020,%%ecx; "
+                         "movl %%ecx, %%cr0;"
+                         :
+                         :
+                         : "%ecx"
+                         );
+    
+#endif
+
+    return 0;
+}
+
+
+
+
+
 #endif
 
 #endif