1 #include <geekos/svm.h>
4 extern struct vmm_os_hooks * os_hooks;
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);
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;
18 if ((ret & CPUID_FEATURE_IDS_ecx_svm_avail) == 0) {
19 PrintDebug("SVM Not Available\n");
23 Get_MSR(SVM_VM_CR_MSR, &vm_cr_high, &vm_cr_low);
25 if ((vm_cr_low & SVM_VM_CR_MSR_svmdis) == 0) {
29 ret = cpuid_edx(CPUID_SVM_REV_AND_FEATURE_IDS);
31 if ((ret & CPUID_SVM_REV_AND_FEATURE_IDS_edx_svml) == 0) {
32 PrintDebug("SVM BIOS Disabled, not unlockable\n");
34 PrintDebug("SVM is locked with a key\n");
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);
52 PrintDebug("SVM Enabled\n");
55 // Setup the host state save area
56 host_state = os_hooks->Allocate_Pages(1);
59 msr.e_reg.low = (uint_t)host_state;
61 Set_MSR(SVM_VM_HSAVE_PA_MSR, msr.e_reg.high, msr.e_reg.low);
70 void Allocate_VMCB() {
71 void * vmcb_page = os_hooks->Allocate_Pages(1);
74 memset(vmcb_page, 0, 4096);