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.


*** empty log message ***
[palacios.git] / palacios / src / geekos / svm.c
1 #include <geekos/svm.h>
2
3
4 extern struct vmm_os_hooks * os_hooks;
5
6 extern uint_t cpuid_ecx(uint_t op);
7 extern uint_t cpuid_edx(uint_t op);
8 extern void Get_MSR(uint_t MSR, uint_t * high_byte, uint_t * low_byte); 
9 extern void Set_MSR(uint_t MSR, uint_t high_byte, uint_t low_byte);
10
11 /* Checks machine SVM capability */
12 /* Implemented from: AMD Arch Manual 3, sect 15.4 */ 
13 int is_svm_capable() {
14   uint_t ret =  cpuid_ecx(CPUID_FEATURE_IDS);
15   uint_t vm_cr_low = 0, vm_cr_high = 0;
16
17
18   if ((ret & CPUID_FEATURE_IDS_ecx_svm_avail) == 0) {
19     PrintDebug("SVM Not Available\n");
20     return 0;
21   } 
22
23   Get_MSR(SVM_VM_CR_MSR, &vm_cr_high, &vm_cr_low);
24
25   if ((vm_cr_low & SVM_VM_CR_MSR_svmdis) == 0) {
26     return 1;
27   }
28
29   ret = cpuid_edx(CPUID_SVM_REV_AND_FEATURE_IDS);
30   
31   if ((ret & CPUID_SVM_REV_AND_FEATURE_IDS_edx_svml) == 0) {
32     PrintDebug("SVM BIOS Disabled, not unlockable\n");
33   } else {
34     PrintDebug("SVM is locked with a key\n");
35   }
36
37   return 0;
38 }
39
40
41
42 void Init_SVM() {
43   reg_ex_t msr;
44   void * host_state;
45
46
47   // setup 
48   Get_MSR(EFER_MSR, &(msr.e_reg.high), &(msr.e_reg.low));
49   msr.e_reg.low |= EFER_MSR_svm_enable;
50   Set_MSR(EFER_MSR, 0, msr.e_reg.low);
51   
52   PrintDebug("SVM Enabled\n");
53
54
55   // Setup the host state save area
56   host_state = os_hooks->Allocate_Pages(1);
57   
58   msr.e_reg.high = 0;
59   msr.e_reg.low = (uint_t)host_state;
60
61   Set_MSR(SVM_VM_HSAVE_PA_MSR, msr.e_reg.high, msr.e_reg.low);
62
63
64   return;
65 }
66
67
68
69
70 void Allocate_VMCB() {
71   void * vmcb_page = os_hooks->Allocate_Pages(1);
72
73
74   memset(vmcb_page, 0, 4096);
75 }