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.


added copyright tags
[palacios.git] / palacios / include / palacios / vmx.h
1 /* Northwestern University */
2 /* (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> */
3
4 #ifndef __VMX_H
5 #define __VMX_H
6
7 #include <palacios/vmm_types.h>
8 #include <palacios/vmcs.h>
9
10 #define IA32_FEATURE_CONTROL_MSR ((unsigned int)0x3a)
11 #define IA32_VMX_BASIC_MSR ((unsigned int)0x480)
12 #define IA32_VMX_PINBASED_CTLS_MSR ((unsigned int)0x481)
13 #define IA32_VMX_PROCBASED_CTLS_MSR ((unsigned int)0x482)
14 #define IA32_VMX_EXIT_CTLS_MSR ((unsigned int)0x483)
15 #define IA32_VMX_ENTRY_CTLS_MSR ((unsigned int)0x484)
16 #define IA32_VMX_MISC_MSR ((unsigned int)0x485)
17 #define IA32_VMX_CR0_FIXED0_MSR ((unsigned int)0x486)
18 #define IA32_VMX_CR0_FIXED1_MSR ((unsigned int)0x487)
19 #define IA32_VMX_CR4_FIXED0_MSR ((unsigned int)0x488)
20 #define IA32_VMX_CR4_FIXED1_MSR ((unsigned int)0x489)
21 #define IA32_VMX_VMCS_ENUM_MSR ((unsigned ing)0x48A)
22
23 #define VMX_SUCCESS         0
24 #define VMX_FAIL_INVALID   1
25 #define VMX_FAIL_VALID     2
26 #define VMM_ERROR          3
27
28 #define FEATURE_CONTROL_LOCK (1)
29 #define FEATURE_CONTROL_VMXON (1<<2)
30 #define FEATURE_CONTROL_VALID ( FEATURE_CONTROL_LOCK | FEATURE_CONTROL_VMXON)
31
32
33 #define CPUID_1_ECX_VTXFLAG (1<<5)
34
35
36
37
38
39 typedef void VmxOnRegion;
40
41 #if __TINYC__
42 #define PACKED
43 #else
44 #define PACKED __attribute__((packed))
45 #endif
46
47
48 struct MSR_REGS {
49   uint_t low PACKED;
50   uint_t high  PACKED;
51 };
52
53 struct VMX_BASIC {
54   uint_t revision          PACKED ;
55   uint_t regionSize   : 13 PACKED ;
56   uint_t rsvd1        : 4  PACKED ; // Always 0
57   uint_t physWidth    : 1  PACKED ;
58   uint_t smm          : 1  PACKED ; // Always 1
59   uint_t memType      : 4  PACKED ;
60   uint_t rsvd2        : 10 PACKED ; // Always 0
61 };
62
63 union VMX_MSR {
64   struct MSR_REGS regs PACKED;
65   struct VMX_BASIC vmxBasic PACKED;
66 };
67
68
69 struct VMDescriptor {
70   uint_t   entry_ip;
71   uint_t   exit_eip;
72   uint_t   guest_esp;
73 } ;
74
75
76 enum VMState { VM_VMXASSIST_STARTUP, VM_VMXASSIST_V8086_BIOS, VM_VMXASSIST_V8086, VM_NORMAL };
77
78 struct VM {
79   enum VMState        state;
80   struct VMXRegs      registers;
81   struct VMDescriptor descriptor;
82   struct VMCSData     vmcs;
83   struct VMCS         *vmcsregion;
84   struct VmxOnRegion  *vmxonregion;
85 };
86
87
88 enum InstructionType { VM_UNKNOWN_INST, VM_MOV_TO_CR0 } ;
89
90 struct Instruction {
91   enum InstructionType type;
92   uint_t          address;
93   uint_t          size;
94   uint_t          input1;
95   uint_t          input2;
96   uint_t          output;
97 };
98
99
100 void DecodeCurrentInstruction(struct VM *vm, struct Instruction *out);
101
102
103 int is_vmx_capable();
104
105 VmxOnRegion * Init_VMX();
106 VmxOnRegion * CreateVmxOnRegion();
107
108 int VMLaunch(struct VMDescriptor *vm);
109
110
111 int Do_VMM(struct VMXRegs regs);
112
113
114
115
116 #endif