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.


79efe4e6e081e078452329cf5c168ae0126b2130
[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 #include <palacios/vm_guest.h>
31
32 /* VM-Exit Controls */
33 /* INTEL MANUAL: 20-16 vol. 3B */
34 #define   HOST_ADDR_SPACE_SIZE          0x00000200
35 #define   ACK_IRQ_ON_EXIT               0x00008000
36
37 /* Control register exit masks */
38 #define   CR4_VMXE      0x00002000
39
40 int v3_load_vmcs_guest_state(struct guest_info * info);
41 int v3_update_vmcs_guest_state(struct guest_info * info);
42 int v3_update_vmcs_host_state(struct guest_info * info);
43 int v3_update_vmcs_ctrl_fields(struct guest_info * info);
44
45
46 typedef enum {
47     VMCS_GUEST_ES_SELECTOR       = 0x00000800,
48     VMCS_GUEST_CS_SELECTOR       = 0x00000802,
49     VMCS_GUEST_SS_SELECTOR       = 0x00000804,
50     VMCS_GUEST_DS_SELECTOR       = 0x00000806,
51     VMCS_GUEST_FS_SELECTOR       = 0x00000808,
52     VMCS_GUEST_GS_SELECTOR       = 0x0000080A,
53     VMCS_GUEST_LDTR_SELECTOR     = 0x0000080C,
54     VMCS_GUEST_TR_SELECTOR       = 0x0000080E,
55     /* 16 bit host state */
56     VMCS_HOST_ES_SELECTOR        = 0x00000C00,
57     VMCS_HOST_CS_SELECTOR        = 0x00000C02,
58     VMCS_HOST_SS_SELECTOR        = 0x00000C04,
59     VMCS_HOST_DS_SELECTOR        = 0x00000C06,
60     VMCS_HOST_FS_SELECTOR        = 0x00000C08,
61     VMCS_HOST_GS_SELECTOR        = 0x00000C0A,
62     VMCS_HOST_TR_SELECTOR        = 0x00000C0C,
63     /* 64 bit control fields */
64     VMCS_IO_BITMAP_A_ADDR             = 0x00002000,
65     VMCS_IO_BITMAP_A_ADDR_HIGH        = 0x00002001,
66     VMCS_IO_BITMAP_B_ADDR             = 0x00002002,
67     VMCS_IO_BITMAP_B_ADDR_HIGH        = 0x00002003,
68     VMCS_MSR_BITMAP                   = 0x00002004,
69     VMCS_MSR_BITMAP_HIGH              = 0x00002005,
70     VMCS_EXIT_MSR_STORE_ADDR          = 0x00002006,
71     VMCS_EXIT_MSR_STORE_ADDR_HIGH     = 0x00002007,
72     VMCS_EXIT_MSR_LOAD_ADDR           = 0x00002008,
73     VMCS_EXIT_MSR_LOAD_ADDR_HIGH      = 0x00002009,
74     VMCS_ENTRY_MSR_LOAD_ADDR          = 0x0000200A,
75     VMCS_ENTRY_MSR_LOAD_ADDR_HIGH     = 0x0000200B,
76     VMCS_EXEC_PTR                     = 0x0000200C,
77     VMCS_EXEC_PTR_HIGH                = 0x0000200D,
78     VMCS_TSC_OFFSET                   = 0x00002010,
79     VMCS_TSC_OFFSET_HIGH              = 0x00002011,
80     VMCS_VAPIC_ADDR                   = 0x00002012,
81     VMCS_VAPIC_ADDR_HIGH              = 0x00002013,
82     VMCS_APIC_ACCESS_ADDR             = 0x00002014,
83     VMCS_APIC_ACCESS_ADDR_HIGH        = 0x00002015,
84     /* 64 bit guest state fields */
85     VMCS_LINK_PTR                     = 0x00002800,
86     VMCS_LINK_PTR_HIGH                = 0x00002801,
87     VMCS_GUEST_DBG_CTL               = 0x00002802,
88     VMCS_GUEST_DBG_CTL_HIGH          = 0x00002803,
89     VMCS_GUEST_EFER                   = 0x00002805,
90     VMCS_GUEST_EFER_HIGH              = 0x00002807,
91     VMCS_GUEST_PERF_GLOBAL_CTRL       = 0x00002808,
92     VMCS_GUEST_PERF_GLOBAL_CTRL_HIGH  = 0x00002809,
93
94     VMCS_HOST_PERF_GLOBAL_CTRL        = 0x00002c04,
95     VMCS_HOST_PERF_GLOBAL_CTRL_HIGH   = 0x00002c05,
96     /* 32 bit control fields */
97     VMCS_PIN_CTRLS                    = 0x00004000,
98     VMCS_PROC_CTRLS                   = 0x00004002,
99     VMCS_EXCP_BITMAP                  = 0x00004004,
100     VMCS_PG_FAULT_ERR_MASK            = 0x00004006,
101     VMCS_PG_FAULT_ERR_MATCH           = 0x00004008,
102     VMCS_CR3_TGT_CNT                  = 0x0000400A,
103     VMCS_EXIT_CTRLS                   = 0x0000400C,
104     VMCS_EXIT_MSR_STORE_CNT           = 0x0000400E,
105     VMCS_EXIT_MSR_LOAD_CNT            = 0x00004010,
106     VMCS_ENTRY_CTRLS                  = 0x00004012,
107     VMCS_ENTRY_MSR_LOAD_CNT           = 0x00004014,
108     VMCS_ENTRY_INT_INFO               = 0x00004016,
109     VMCS_ENTRY_EXCP_ERR               = 0x00004018,
110     VMCS_ENTRY_INSTR_LEN              = 0x0000401A,
111     VMCS_TPR_THRESHOLD                = 0x0000401C,
112     VMCS_SEC_PROC_CTRLS               = 0x0000401e,
113     /* 32 bit Read Only data fields */
114     VMCS_INSTR_ERR                    = 0x00004400,
115     VMCS_EXIT_REASON                  = 0x00004402,
116     VMCS_EXIT_INT_INFO                = 0x00004404,
117     VMCS_EXIT_INT_ERR                 = 0x00004406,
118     VMCS_IDT_VECTOR_INFO              = 0x00004408,
119     VMCS_IDT_VECTOR_ERR               = 0x0000440A,
120     VMCS_EXIT_INSTR_LEN               = 0x0000440C,
121     VMCS_EXIT_INSTR_INFO               = 0x0000440E,
122     /* 32 bit Guest state fields */
123     VMCS_GUEST_ES_LIMIT               = 0x00004800,
124     VMCS_GUEST_CS_LIMIT               = 0x00004802,
125     VMCS_GUEST_SS_LIMIT               = 0x00004804,
126     VMCS_GUEST_DS_LIMIT               = 0x00004806,
127     VMCS_GUEST_FS_LIMIT               = 0x00004808,
128     VMCS_GUEST_GS_LIMIT               = 0x0000480A,
129     VMCS_GUEST_LDTR_LIMIT             = 0x0000480C,
130     VMCS_GUEST_TR_LIMIT               = 0x0000480E,
131     VMCS_GUEST_GDTR_LIMIT             = 0x00004810,
132     VMCS_GUEST_IDTR_LIMIT             = 0x00004812,
133     VMCS_GUEST_ES_ACCESS              = 0x00004814,
134     VMCS_GUEST_CS_ACCESS              = 0x00004816,
135     VMCS_GUEST_SS_ACCESS              = 0x00004818,
136     VMCS_GUEST_DS_ACCESS              = 0x0000481A,
137     VMCS_GUEST_FS_ACCESS              = 0x0000481C,
138     VMCS_GUEST_GS_ACCESS              = 0x0000481E,
139     VMCS_GUEST_LDTR_ACCESS            = 0x00004820,
140     VMCS_GUEST_TR_ACCESS              = 0x00004822,
141     VMCS_GUEST_INT_STATE              = 0x00004824,
142     VMCS_GUEST_ACTIVITY_STATE         = 0x00004826,
143     VMCS_GUEST_SMBASE                 = 0x00004828,
144     VMCS_GUEST_SYSENTER_CS            = 0x0000482A,
145     /* 32 bit host state field */
146     VMCS_HOST_SYSENTER_CS             = 0x00004C00,
147     /* Natural Width Control Fields */
148     VMCS_CR0_MASK                     = 0x00006000,
149     VMCS_CR4_MASK                     = 0x00006002,
150     VMCS_CR0_READ_SHDW                = 0x00006004,
151     VMCS_CR4_READ_SHDW                = 0x00006006,
152     VMCS_CR3_TGT_VAL_0                = 0x00006008,
153     VMCS_CR3_TGT_VAL_1                = 0x0000600A,
154     VMCS_CR3_TGT_VAL_2                = 0x0000600C,
155     VMCS_CR3_TGT_VAL_3                = 0x0000600E,
156     /* Natural Width Read Only Fields */
157     VMCS_EXIT_QUAL                    = 0x00006400,
158     VMCS_IO_RCX                       = 0x00006402,
159     VMCS_IO_RSI                       = 0x00006404,
160     VMCS_IO_RDI                       = 0x00006406,
161     VMCS_IO_RIP                       = 0x00006408,
162     VMCS_GUEST_LINEAR_ADDR            = 0x0000640A,
163     /* Natural Width Guest State Fields */
164     VMCS_GUEST_CR0                    = 0x00006800,
165     VMCS_GUEST_CR3                    = 0x00006802,
166     VMCS_GUEST_CR4                    = 0x00006804,
167     VMCS_GUEST_ES_BASE                = 0x00006806,
168     VMCS_GUEST_CS_BASE                = 0x00006808,
169     VMCS_GUEST_SS_BASE                = 0x0000680A,
170     VMCS_GUEST_DS_BASE                = 0x0000680C,
171     VMCS_GUEST_FS_BASE                = 0x0000680E,
172     VMCS_GUEST_GS_BASE                = 0x00006810,
173     VMCS_GUEST_LDTR_BASE              = 0x00006812,
174     VMCS_GUEST_TR_BASE                = 0x00006814,
175     VMCS_GUEST_GDTR_BASE              = 0x00006816,
176     VMCS_GUEST_IDTR_BASE              = 0x00006818,
177     VMCS_GUEST_DR7                    = 0x0000681A,
178     VMCS_GUEST_RSP                    = 0x0000681C,
179     VMCS_GUEST_RIP                    = 0x0000681E,
180     VMCS_GUEST_RFLAGS                 = 0x00006820,
181     VMCS_GUEST_PENDING_DBG_EXCP       = 0x00006822,
182     VMCS_GUEST_SYSENTER_ESP           = 0x00006824,
183     VMCS_GUEST_SYSENTER_EIP           = 0x00006826,
184     /* Natural Width Host State Fields */
185     VMCS_HOST_CR0                     = 0x00006C00,
186     VMCS_HOST_CR3                     = 0x00006C02,
187     VMCS_HOST_CR4                     = 0x00006C04,
188     VMCS_HOST_FS_BASE                 = 0x00006C06,
189     VMCS_HOST_GS_BASE                 = 0x00006C08,
190     VMCS_HOST_TR_BASE                 = 0x00006C0A,
191     VMCS_HOST_GDTR_BASE               = 0x00006C0C,
192     VMCS_HOST_IDTR_BASE               = 0x00006C0E,
193     VMCS_HOST_SYSENTER_ESP            = 0x00006C10,
194     VMCS_HOST_SYSENTER_EIP            = 0x00006C12,
195     VMCS_HOST_RSP                     = 0x00006C14,
196     VMCS_HOST_RIP                     = 0x00006C16,
197 } vmcs_field_t;
198
199
200
201 struct vmx_exception_bitmap {
202     union {
203         uint32_t value;
204         struct {
205             uint_t de          : 1; // (0) divide by zero
206             uint_t db          : 1; // (1) Debug
207             uint_t nmi         : 1; // (2) Non-maskable interrupt
208             uint_t bp          : 1; // (3) Breakpoint
209             uint_t of          : 1; // (4) Overflow
210             uint_t br          : 1; // (5) Bound-Range
211             uint_t ud          : 1; // (6) Invalid-Opcode
212             uint_t nm          : 1; // (7) Device-not-available
213             uint_t df          : 1; // (8) Double Fault
214             uint_t ex9         : 1; 
215             uint_t ts          : 1; // (10) Invalid TSS
216             uint_t np          : 1; // (11) Segment-not-present
217             uint_t ss          : 1; // (12) Stack
218             uint_t gp          : 1; // (13) General Protection Fault
219             uint_t pf          : 1; // (14) Page fault
220             uint_t ex15        : 1;
221             uint_t mf          : 1; // (15) Floating point exception
222             uint_t ac          : 1; // (16) Alignment-check
223             uint_t mc          : 1; // (17) Machine Check
224             uint_t xf          : 1; // (18) SIMD floating-point
225             uint_t ex20        : 1;
226             uint_t ex21        : 1;
227             uint_t ex22        : 1;
228             uint_t ex23        : 1;
229             uint_t ex24        : 1;
230             uint_t ex25        : 1;
231             uint_t ex26        : 1;
232             uint_t ex27        : 1;
233             uint_t ex28        : 1;
234             uint_t ex29        : 1;
235             uint_t sx          : 1; // (30) Security Exception
236             uint_t ex31        : 1;
237         } __attribute__ ((packed));
238     } __attribute__ ((packed));
239 } __attribute__((packed));
240
241
242
243
244 /* Segment Selector Access Rights (32 bits) */
245 /* INTEL Manual: 20-4 vol 3B */
246 struct vmcs_segment_access {
247     union {
248         uint32_t value;
249         struct {
250             uint32_t    type        : 4;
251             uint32_t    desc_type   : 1; 
252             uint32_t    dpl         : 2;
253             uint32_t    present     : 1;
254             uint32_t    rsvd1       : 4;
255             uint32_t    avail       : 1;
256             uint32_t    long_mode   : 1; // CS only (64 bit active), reserved otherwise
257             uint32_t    db          : 1; 
258             uint32_t    granularity : 1;
259             uint32_t    unusable    : 1; 
260             uint32_t    rsvd2       : 15;
261         } __attribute__((packed));
262     } __attribute__((packed));
263 }__attribute__((packed));
264
265
266 struct vmcs_interrupt_state {
267     uint32_t    sti_blocking    : 1;
268     uint32_t    mov_ss_blocking : 1;
269     uint32_t    smi_blocking    : 1;
270     uint32_t    nmi_blocking    : 1;
271     uint32_t    rsvd1           : 28;
272 } __attribute__((packed));
273
274
275
276 struct vmcs_data {
277     uint32_t revision ;
278     uint32_t abort    ;
279 } __attribute__((packed));
280
281
282
283 int v3_vmcs_get_field_len(vmcs_field_t field);
284
285 const char * v3_vmcs_field_to_str(vmcs_field_t field);
286
287 void v3_print_vmcs();
288
289
290 #endif // ! __V3VEE__
291
292
293 #endif