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.


Latest VMX work that still has bug in guest state causing #GP after launch.
[palacios.git] / palacios / include / palacios / vmcs.h
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Peter Dinda <pdinda@northwestern.edu> 
11  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
12  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
13  * All rights reserved.
14  *
15  * Author: Peter Dinda <pdinda@northwestern.edu>
16  *         Jack Lange <jarusl@cs.northwestern.edu>
17  *
18  * This is free software.  You are permitted to use,
19  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20  */
21
22
23 #ifndef __VMCS_H__
24 #define __VMCS_H__
25
26 #ifdef __V3VEE__
27
28
29 #include <palacios/vmm_types.h>
30     /* Pin Based VM Execution Controls */
31     /* INTEL MANUAL: 20-10 vol 3B */
32 #define   EXT_INTR_EXIT                 0x00000001
33 #define   NMI_EXIT                      0x00000008
34 #define   VIRTUAL_NMIS                  0x00000020
35 /* Processor Based VM Execution Controls */
36 /* INTEL MANUAL: 20-11 vol. 3B */
37 #define   INTR_WIN_EXIT                 0x00000004
38 #define   USE_TSC_OFFSET                0x00000008
39 #define   HLT_EXIT                      0x00000080
40 #define   INVLPG_EXIT                   0x00000200
41 #define   MWAIT_EXIT                    0x00000400
42 #define   RDPMC_EXIT                    0x00000800
43 #define   RDTSC_EXIT                    0x00001000
44 #define   CR8_LOAD_EXIT                 0x00080000
45 #define   CR8_STORE_EXIT                0x00100000
46 #define   USE_TPR_SHADOW                0x00200000
47 #define   NMI_WINDOW_EXIT               0x00400000
48 #define   MOVDR_EXIT                    0x00800000
49 #define   UNCOND_IO_EXIT                0x01000000
50 #define   USE_IO_BITMAPS                0x02000000
51 #define   USE_MSR_BITMAPS               0x10000000
52 #define   MONITOR_EXIT                  0x20000000
53 #define   PAUSE_EXIT                    0x40000000
54 /* VM-Exit Controls */
55 /* INTEL MANUAL: 20-16 vol. 3B */
56 #define   HOST_ADDR_SPACE_SIZE          0x00000200
57 #define   ACK_IRQ_ON_EXIT               0x00008000
58
59 typedef enum {
60     VMCS_GUEST_ES_SELECTOR       = 0x00000800,
61     VMCS_GUEST_CS_SELECTOR       = 0x00000802,
62     VMCS_GUEST_SS_SELECTOR       = 0x00000804,
63     VMCS_GUEST_DS_SELECTOR       = 0x00000806,
64     VMCS_GUEST_FS_SELECTOR       = 0x00000808,
65     VMCS_GUEST_GS_SELECTOR       = 0x0000080A,
66     VMCS_GUEST_LDTR_SELECTOR     = 0x0000080C,
67     VMCS_GUEST_TR_SELECTOR       = 0x0000080E,
68     /* 16 bit host state */
69     VMCS_HOST_ES_SELECTOR        = 0x00000C00,
70     VMCS_HOST_CS_SELECTOR        = 0x00000C02,
71     VMCS_HOST_SS_SELECTOR        = 0x00000C04,
72     VMCS_HOST_DS_SELECTOR        = 0x00000C06,
73     VMCS_HOST_FS_SELECTOR        = 0x00000C08,
74     VMCS_HOST_GS_SELECTOR        = 0x00000C0A,
75     VMCS_HOST_TR_SELECTOR        = 0x00000C0C,
76     /* 64 bit control fields */
77     VMCS_IO_BITMAP_A_ADDR             = 0x00002000,
78     VMCS_IO_BITMAP_A_ADDR_HIGH        = 0x00002001,
79     VMCS_IO_BITMAP_B_ADDR             = 0x00002002,
80     VMCS_IO_BITMAP_B_ADDR_HIGH        = 0x00002003,
81     VMCS_MSR_BITMAP                   = 0x00002004,
82     VMCS_MSR_BITMAP_HIGH              = 0x00002005,
83     VMCS_EXIT_MSR_STORE_ADDR          = 0x00002006,
84     VMCS_EXIT_MSR_STORE_ADDR_HIGH     = 0x00002007,
85     VMCS_EXIT_MSR_LOAD_ADDR           = 0x00002008,
86     VMCS_EXIT_MSR_LOAD_ADDR_HIGH      = 0x00002009,
87     VMCS_ENTRY_MSR_LOAD_ADDR          = 0x0000200A,
88     VMCS_ENTRY_MSR_LOAD_ADDR_HIGH     = 0x0000200B,
89     VMCS_EXEC_PTR                     = 0x0000200C,
90     VMCS_EXEC_PTR_HIGH                = 0x0000200D,
91     VMCS_TSC_OFFSET                   = 0x00002010,
92     VMCS_TSC_OFFSET_HIGH              = 0x00002011,
93     VMCS_VAPIC_ADDR                   = 0x00002012,
94     VMCS_VAPIC_ADDR_HIGH              = 0x00002013,
95     VMCS_APIC_ACCESS_ADDR             = 0x00002014,
96     VMCS_APIC_ACCESS_ADDR_HIGH        = 0x00002015,
97     /* 64 bit guest state fields */
98     VMCS_LINK_PTR                     = 0x00002800,
99     VMCS_LINK_PTR_HIGH                = 0x00002801,
100     VMCS_GUEST_DBG_CTL               = 0x00002802,
101     VMCS_GUEST_DBG_CTL_HIGH          = 0x00002803,
102     VMCS_GUEST_PERF_GLOBAL_CTRL       = 0x00002808,
103     VMCS_GUEST_PERF_GLOBAL_CTRL_HIGH  = 0x00002809,
104
105     VMCS_HOST_PERF_GLOBAL_CTRL        = 0x00002c04,
106     VMCS_HOST_PERF_GLOBAL_CTRL_HIGH   = 0x00002c05,
107     /* 32 bit control fields */
108     VMCS_PIN_CTRLS                    = 0x00004000,
109     VMCS_PROC_CTRLS                   = 0x00004002,
110     VMCS_EXCP_BITMAP                  = 0x00004004,
111     VMCS_PG_FAULT_ERR_MASK            = 0x00004006,
112     VMCS_PG_FAULT_ERR_MATCH           = 0x00004008,
113     VMCS_CR3_TGT_CNT                  = 0x0000400A,
114     VMCS_EXIT_CTRLS                   = 0x0000400C,
115     VMCS_EXIT_MSR_STORE_CNT           = 0x0000400E,
116     VMCS_EXIT_MSR_LOAD_CNT            = 0x00004010,
117     VMCS_ENTRY_CTRLS                  = 0x00004012,
118     VMCS_ENTRY_MSR_LOAD_CNT           = 0x00004014,
119     VMCS_ENTRY_INT_INFO               = 0x00004016,
120     VMCS_ENTRY_EXCP_ERR               = 0x00004018,
121     VMCS_ENTRY_INSTR_LEN              = 0x0000401A,
122     VMCS_TPR_THRESHOLD                = 0x0000401C,
123     VMCS_SEC_PROC_CTRLS               = 0x0000401e,
124     /* 32 bit Read Only data fields */
125     VMCS_INSTR_ERR                    = 0x00004400,
126     VMCS_EXIT_REASON                  = 0x00004402,
127     VMCS_EXIT_INT_INFO                = 0x00004404,
128     VMCS_EXIT_INT_ERR                 = 0x00004406,
129     VMCS_IDT_VECTOR_INFO              = 0x00004408,
130     VMCS_IDT_VECTOR_ERR               = 0x0000440A,
131     VMCS_EXIT_INSTR_LEN               = 0x0000440C,
132     VMCS_VMX_INSTR_INFO               = 0x0000440E,
133     /* 32 bit Guest state fields */
134     VMCS_GUEST_ES_LIMIT               = 0x00004800,
135     VMCS_GUEST_CS_LIMIT               = 0x00004802,
136     VMCS_GUEST_SS_LIMIT               = 0x00004804,
137     VMCS_GUEST_DS_LIMIT               = 0x00004806,
138     VMCS_GUEST_FS_LIMIT               = 0x00004808,
139     VMCS_GUEST_GS_LIMIT               = 0x0000480A,
140     VMCS_GUEST_LDTR_LIMIT             = 0x0000480C,
141     VMCS_GUEST_TR_LIMIT               = 0x0000480E,
142     VMCS_GUEST_GDTR_LIMIT             = 0x00004810,
143     VMCS_GUEST_IDTR_LIMIT             = 0x00004812,
144     VMCS_GUEST_ES_ACCESS              = 0x00004814,
145     VMCS_GUEST_CS_ACCESS              = 0x00004816,
146     VMCS_GUEST_SS_ACCESS              = 0x00004818,
147     VMCS_GUEST_DS_ACCESS              = 0x0000481A,
148     VMCS_GUEST_FS_ACCESS              = 0x0000481C,
149     VMCS_GUEST_GS_ACCESS              = 0x0000481E,
150     VMCS_GUEST_LDTR_ACCESS            = 0x00004820,
151     VMCS_GUEST_TR_ACCESS              = 0x00004822,
152     VMCS_GUEST_INT_STATE              = 0x00004824,
153     VMCS_GUEST_ACTIVITY_STATE         = 0x00004826,
154     VMCS_GUEST_SMBASE                 = 0x00004828,
155     VMCS_GUEST_SYSENTER_CS            = 0x0000482A,
156     /* 32 bit host state field */
157     VMCS_HOST_SYSENTER_CS             = 0x00004C00,
158     /* Natural Width Control Fields */
159     VMCS_CR0_MASK                     = 0x00006000,
160     VMCS_CR4_MASK                     = 0x00006002,
161     VMCS_CR0_READ_SHDW                = 0x00006004,
162     VMCS_CR4_READ_SHDW                = 0x00006006,
163     VMCS_CR3_TGT_VAL_0                = 0x00006008,
164     VMCS_CR3_TGT_VAL_1                = 0x0000600A,
165     VMCS_CR3_TGT_VAL_2                = 0x0000600C,
166     VMCS_CR3_TGT_VAL_3                = 0x0000600E,
167     /* Natural Width Read Only Fields */
168     VMCS_EXIT_QUAL                    = 0x00006400,
169     VMCS_IO_RCX                       = 0x00006402,
170     VMCS_IO_RSI                       = 0x00006404,
171     VMCS_IO_RDI                       = 0x00006406,
172     VMCS_IO_RIP                       = 0x00006408,
173     VMCS_GUEST_LINEAR_ADDR            = 0x0000640A,
174     /* Natural Width Guest State Fields */
175     VMCS_GUEST_CR0                    = 0x00006800,
176     VMCS_GUEST_CR3                    = 0x00006802,
177     VMCS_GUEST_CR4                    = 0x00006804,
178     VMCS_GUEST_ES_BASE                = 0x00006806,
179     VMCS_GUEST_CS_BASE                = 0x00006808,
180     VMCS_GUEST_SS_BASE                = 0x0000680A,
181     VMCS_GUEST_DS_BASE                = 0x0000680C,
182     VMCS_GUEST_FS_BASE                = 0x0000680E,
183     VMCS_GUEST_GS_BASE                = 0x00006810,
184     VMCS_GUEST_LDTR_BASE              = 0x00006812,
185     VMCS_GUEST_TR_BASE                = 0x00006814,
186     VMCS_GUEST_GDTR_BASE              = 0x00006816,
187     VMCS_GUEST_IDTR_BASE              = 0x00006818,
188     VMCS_GUEST_DR7                    = 0x0000681A,
189     VMCS_GUEST_RSP                    = 0x0000681C,
190     VMCS_GUEST_RIP                    = 0x0000681E,
191     VMCS_GUEST_RFLAGS                 = 0x00006820,
192     VMCS_GUEST_PENDING_DBG_EXCP       = 0x00006822,
193     VMCS_GUEST_SYSENTER_ESP           = 0x00006824,
194     VMCS_GUEST_SYSENTER_EIP           = 0x00006826,
195     /* Natural Width Host State Fields */
196     VMCS_HOST_CR0                     = 0x00006C00,
197     VMCS_HOST_CR3                     = 0x00006C02,
198     VMCS_HOST_CR4                     = 0x00006C04,
199     VMCS_HOST_FS_BASE                 = 0x00006C06,
200     VMCS_HOST_GS_BASE                 = 0x00006C08,
201     VMCS_HOST_TR_BASE                 = 0x00006C0A,
202     VMCS_HOST_GDTR_BASE               = 0x00006C0C,
203     VMCS_HOST_IDTR_BASE               = 0x00006C0E,
204     VMCS_HOST_SYSENTER_ESP            = 0x00006C10,
205     VMCS_HOST_SYSENTER_EIP            = 0x00006C12,
206     VMCS_HOST_RSP                     = 0x00006C14,
207     VMCS_HOST_RIP                     = 0x00006C16,
208 } vmcs_field_t;
209
210 int v3_vmcs_get_field_len(vmcs_field_t field);
211 const char* v3_vmcs_field_to_str(vmcs_field_t field);
212 void v3_print_vmcs();
213
214
215
216 /* VMCS Exit QUALIFICATIONs */
217 struct VMExitIOQual {
218     uint32_t accessSize : 3; // (0: 1 Byte ;; 1: 2 Bytes ;; 3: 4 Bytes)
219     uint32_t dir        : 1; // (0: Out ;; 1: In)
220     uint32_t string     : 1; // (0: not string ;; 1: string)
221     uint32_t REP        : 1; // (0: not REP ;; 1: REP)
222     uint32_t opEnc      : 1; // (0: DX ;; 1: immediate)
223     uint32_t rsvd       : 9; // Set to 0
224     uint32_t port       : 16; // IO Port Number
225 } __attribute__((packed));
226
227
228
229 struct VMExitDBGQual {
230     uint32_t B0         : 1; // Breakpoint 0 condition met
231     uint32_t B1         : 1; // Breakpoint 1 condition met
232     uint32_t B2         : 1; // Breakpoint 2 condition met
233     uint32_t B3         : 1; // Breakpoint 3 condition met
234     uint32_t rsvd       : 9; // reserved to 0
235     uint32_t BD         : 1; // detected DBG reg access
236     uint32_t BS         : 1; // cause either single instr or taken branch
237 } __attribute__((packed));
238
239
240 struct VMExitTSQual {
241     uint32_t selector   : 16; // selector of destination TSS 
242     uint32_t rsvd       : 14; // reserved to 0
243     uint32_t src        : 2; // (0: CALL ; 1: IRET ; 2: JMP ; 3: Task gate in IDT)
244 } __attribute__((packed));
245
246 struct VMExitCRQual {
247     uint32_t crID       : 4; // cr number (0 for CLTS and LMSW) (bit 3 always 0, on 32bit)
248     uint32_t accessType : 2; // (0: MOV to CR ; 1: MOV from CR ; 2: CLTS ; 3: LMSW)
249     uint32_t lmswOpType : 1; // (0: register ; 1: memory)
250     uint32_t rsvd1      : 1; // reserved to 0
251     uint32_t gpr        : 4; // (0:RAX+[CLTS/LMSW], 1:RCX, 2:RDX, 3:RBX, 4:RSP, 5:RBP, 6:RSI, 6:RDI, 8-15:64bit regs)
252     uint32_t rsvd2      : 4; // reserved to 0
253     uint32_t lmswSrc    : 16; // src data for lmsw
254 } __attribute__((packed));
255
256 struct VMExitMovDRQual {
257     uint32_t regID      : 3; // debug register number
258     uint32_t rsvd1      : 1; // reserved to 0
259     uint32_t dir        : 1; // (0: MOV to DR , 1: MOV from DR)
260     uint32_t rsvd2      : 3; // reserved to 0
261     uint32_t gpr        : 4; // (0:RAX, 1:RCX, 2:RDX, 3:RBX, 4:RSP, 5:RBP, 6:RSI, 6:RDI, 8-15:64bit regs)
262 } __attribute__((packed));
263
264 /* End Exit Qualifications */
265
266 /* Exit Vector Info */
267 struct VMExitIntInfo {
268     uint32_t nr         : 8; // IRQ number, exception vector, NMI = 2 
269     uint32_t type       : 3; // (0: ext. IRQ , 2: NMI , 3: hw exception , 6: sw exception
270     uint32_t errorCode  : 1; // 1: error Code present
271     uint32_t iret       : 1; // something to do with NMIs and IRETs (Intel 3B, sec. 23.2.2) 
272     uint32_t rsvd       : 18; // always 0
273     uint32_t valid      : 1; // always 1 if valid
274 } __attribute__((packed));
275
276
277
278
279 /*  End Exit Vector Info */
280
281
282
283
284 /* Segment Selector Access Rights (32 bits) */
285 /* INTEL Manual: 20-4 vol 3B */
286
287
288 struct vmcs_segment_access {
289     union {
290         uint32_t value;
291         struct {
292             uint32_t    type        : 4;
293             uint32_t    desc_type   : 1; 
294             uint32_t    dpl         : 2;
295             uint32_t    present     : 1;
296             uint32_t    rsvd1       : 4;
297             uint32_t    avail       : 1;
298             uint32_t    long_mode   : 1; // CS only (64 bit active), reserved otherwise
299             uint32_t    db          : 1; 
300             uint32_t    granularity : 1;
301             uint32_t    unusable    : 1; 
302             uint32_t    rsvd2       : 15;
303         } __attribute__((packed));
304     } __attribute__((packed));
305 }__attribute__((packed));
306
307
308 struct vmcs_interrupt_state {
309     uint32_t    sti_blocking    : 1;
310     uint32_t    mov_ss_blocking : 1;
311     uint32_t    smi_blocking    : 1;
312     uint32_t    nmi_blocking    : 1;
313     uint32_t    rsvd1           : 28;
314 } __attribute__((packed));
315
316
317
318 struct vmcs_data {
319     uint32_t revision ;
320     uint32_t abort    ;
321 } __attribute__((packed));
322
323
324 //uint_t VMCSRead(uint_t tag, void * val);
325
326
327 #endif // ! __V3VEE__
328
329
330 #endif