4 #include <geekos/ktypes.h>
5 #include <geekos/vmcs.h>
7 #define IA32_FEATURE_CONTROL_MSR ((unsigned int)0x3a)
8 #define IA32_VMX_BASIC_MSR ((unsigned int)0x480)
9 #define IA32_VMX_PINBASED_CTLS_MSR ((unsigned int)0x481)
10 #define IA32_VMX_PROCBASED_CTLS_MSR ((unsigned int)0x482)
11 #define IA32_VMX_EXIT_CTLS_MSR ((unsigned int)0x483)
12 #define IA32_VMX_ENTRY_CTLS_MSR ((unsigned int)0x484)
13 #define IA32_VMX_MISC_MSR ((unsigned int)0x485)
14 #define IA32_VMX_CR0_FIXED0_MSR ((unsigned int)0x486)
15 #define IA32_VMX_CR0_FIXED1_MSR ((unsigned int)0x487)
16 #define IA32_VMX_CR4_FIXED0_MSR ((unsigned int)0x488)
17 #define IA32_VMX_CR4_FIXED1_MSR ((unsigned int)0x489)
18 #define IA32_VMX_VMCS_ENUM_MSR ((unsigned ing)0x48A)
21 #define VMX_FAIL_INVALID 1
22 #define VMX_FAIL_VALID 2
25 #define FEATURE_CONTROL_LOCK (1)
26 #define FEATURE_CONTROL_VMXON (1<<2)
27 #define FEATURE_CONTROL_VALID ( FEATURE_CONTROL_LOCK | FEATURE_CONTROL_VMXON)
30 #define CPUID_1_ECX_VTXFLAG (1<<5)
36 typedef void VmxOnRegion;
41 #define PACKED __attribute__((packed))
51 uint_t revision PACKED ;
52 uint_t regionSize : 13 PACKED ;
53 uint_t rsvd1 : 4 PACKED ; // Always 0
54 uint_t physWidth : 1 PACKED ;
55 uint_t smm : 1 PACKED ; // Always 1
56 uint_t memType : 4 PACKED ;
57 uint_t rsvd2 : 10 PACKED ; // Always 0
61 struct MSR_REGS regs PACKED;
62 struct VMX_BASIC vmxBasic PACKED;
73 enum VMState { VM_VMXASSIST_STARTUP, VM_VMXASSIST_V8086_BIOS, VM_VMXASSIST_V8086, VM_NORMAL };
77 struct VMXRegs registers;
78 struct VMDescriptor descriptor;
80 struct VMCS *vmcsregion;
81 struct VmxOnRegion *vmxonregion;
85 enum InstructionType { VM_UNKNOWN_INST, VM_MOV_TO_CR0 } ;
88 enum InstructionType type;
97 void DecodeCurrentInstruction(struct VM *vm, struct Instruction *out);
100 int is_vmx_capable();
102 VmxOnRegion * Init_VMX();
103 VmxOnRegion * CreateVmxOnRegion();
105 int VMLaunch(struct VMDescriptor *vm);
108 int Do_VMM(struct VMXRegs regs);