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.


212daaf3b6a7ea4d2cdc67a7f23133b83429fe43
[palacios.git] / palacios / include / geekos / vmcb.h
1 #ifndef __VMCB_H
2 #define __VMCB_H
3
4
5
6
7 #if __TINYC__
8 #define PACKED
9 #else
10 #define PACKED __attribute__((packed))
11 #endif
12
13 union Ctrl_Registers {
14   ushort_t bitmap                PACKED;
15   struct {
16     uint_t cr0        : 1        PACKED;
17     uint_t cr1        : 1        PACKED;
18     uint_t cr2        : 1        PACKED;
19     uint_t cr3        : 1        PACKED;
20     uint_t cr4        : 1        PACKED;
21     uint_t cr5        : 1        PACKED;
22     uint_t cr6        : 1        PACKED;
23     uint_t cr7        : 1        PACKED;
24     uint_t cr8        : 1        PACKED;
25     uint_t cr9        : 1        PACKED;
26     uint_t cr10       : 1        PACKED;
27     uint_t cr11       : 1        PACKED;
28     uint_t cr12       : 1        PACKED;
29     uint_t cr13       : 1        PACKED;
30     uint_t cr14       : 1        PACKED;
31     uint_t cr15       : 1        PACKED;
32   } crs;
33 };
34
35
36 union Debug_Registers {
37   ushort_t bitmap                PACKED;
38   struct {
39     uint_t dr0        : 1        PACKED;
40     uint_t dr1        : 1        PACKED;
41     uint_t dr2        : 1        PACKED;
42     uint_t dr3        : 1        PACKED;
43     uint_t dr4        : 1        PACKED;
44     uint_t dr5        : 1        PACKED;
45     uint_t dr6        : 1        PACKED;
46     uint_t dr7        : 1        PACKED;
47     uint_t dr8        : 1        PACKED;
48     uint_t dr9        : 1        PACKED;
49     uint_t dr10       : 1        PACKED;
50     uint_t dr11       : 1        PACKED;
51     uint_t dr12       : 1        PACKED;
52     uint_t dr13       : 1        PACKED;
53     uint_t dr14       : 1        PACKED;
54     uint_t dr15       : 1        PACKED;
55   } drs;
56 };
57
58
59 union Exception_Vectors {
60   ulong_t bitmap                  PACKED;
61   struct {
62     uint_t ex0         : 1        PACKED;
63     uint_t ex1         : 1        PACKED;
64     uint_t ex2         : 1        PACKED;
65     uint_t ex3         : 1        PACKED;
66     uint_t ex4         : 1        PACKED;
67     uint_t ex5         : 1        PACKED;
68     uint_t ex6         : 1        PACKED;
69     uint_t ex7         : 1        PACKED;
70     uint_t ex8         : 1        PACKED;
71     uint_t ex9         : 1        PACKED;
72     uint_t ex10        : 1        PACKED;
73     uint_t ex11        : 1        PACKED;
74     uint_t ex12        : 1        PACKED;
75     uint_t ex13        : 1        PACKED;
76     uint_t ex14        : 1        PACKED;
77     uint_t ex15        : 1        PACKED;
78     uint_t ex16        : 1        PACKED;
79     uint_t ex17        : 1        PACKED;
80     uint_t ex18        : 1        PACKED;
81     uint_t ex19        : 1        PACKED;
82     uint_t ex20        : 1        PACKED;
83     uint_t ex21        : 1        PACKED;
84     uint_t ex22        : 1        PACKED;
85     uint_t ex23        : 1        PACKED;
86     uint_t ex24        : 1        PACKED;
87     uint_t ex25        : 1        PACKED;
88     uint_t ex26        : 1        PACKED;
89     uint_t ex27        : 1        PACKED;
90     uint_t ex28        : 1        PACKED;
91     uint_t ex29        : 1        PACKED;
92     uint_t ex30        : 1        PACKED;
93     uint_t ex31        : 1        PACKED;
94   } exceptions;
95 };
96
97
98 union Instr_Intercepts {
99   ulong_t bitmap                  PACKED;
100   struct {
101     uint_t INTR        : 1        PACKED;
102     uint_t NMI         : 1        PACKED;
103     uint_t SMI         : 1        PACKED;
104     uint_t INIT        : 1        PACKED;
105     uint_t VINTR       : 1        PACKED;
106     uint_t CR0         : 1        PACKED;
107     uint_t RD_IDTR     : 1        PACKED;
108     uint_t RD_GDTR     : 1        PACKED;
109     uint_t RD_LDTR     : 1        PACKED;
110     uint_t RD_TR       : 1        PACKED;
111     uint_t WR_IDTR     : 1        PACKED;
112     uint_t WR_GDTR     : 1        PACKED;
113     uint_t WR_LDTR     : 1        PACKED;
114     uint_t WR_TR       : 1        PACKED;
115     uint_t RDTSC       : 1        PACKED;
116     uint_t RDPMC       : 1        PACKED;
117     uint_t PUSHF       : 1        PACKED;
118     uint_t POPF        : 1        PACKED;
119     uint_t CPUID       : 1        PACKED;
120     uint_t RSM         : 1        PACKED;
121     uint_t IRET        : 1        PACKED;
122     uint_t INTn        : 1        PACKED;
123     uint_t INVD        : 1        PACKED;
124     uint_t PAUSE       : 1        PACKED;
125     uint_t HLT         : 1        PACKED;
126     uint_t INVPLG      : 1        PACKED;
127     uint_t INVPLGA     : 1        PACKED;
128     uint_t IOIO_PROT   : 1        PACKED;
129     uint_t MSR_PROT    : 1        PACKED;
130     uint_t task_switch : 1        PACKED;
131     uint_t FERR_FREEZE : 1        PACKED;
132     uint_t shutdown_evts: 1       PACKED;
133   } instrs;
134 };
135
136 union SVM_Instr_Intercepts { 
137   ulong_t bitmap                  PACKED;
138   struct {
139     uint_t VMRUN      : 1         PACKED;
140     uint_t VMMCALL    : 1         PACKED;
141     uint_t VMLOAD     : 1         PACKED;
142     uint_t VMSAVE     : 1         PACKED;
143     uint_t STGI       : 1         PACKED;
144     uint_t CLGI       : 1         PACKED;
145     uint_t SKINIT     : 1         PACKED;
146     uint_t RDTSCP     : 1         PACKED;
147     uint_t ICEBP      : 1         PACKED;
148     uint_t WBINVD     : 1         PACKED;
149     uint_t MONITOR    : 1         PACKED;
150     uint_t MWAIT_always : 1       PACKED;
151     uint_t MWAIT_if_armed : 1     PACKED;
152     ulong_t reserved  : 19        PACKED;
153   } instrs;
154 };
155
156
157 union Guest_Control {
158   ulong_t bitmap                  PACKED;
159   struct {
160     uchar_t V_TPR                 PACKED;
161     uint_t V_IRQ      : 1         PACKED;
162     uint_t rsvd1      : 7         PACKED;
163     uint_t V_INTR_PRIO : 4        PACKED;
164     uint_t V_IGN_TPR  : 1         PACKED;
165     uint_t rsvd2      : 3         PACKED;
166     uint_t V_INTR_MASKING : 1     PACKED;
167     uint_t rsvd3      : 7         PACKED;
168     uchar_t V_INTR_VECTOR         PACKED;
169     uint_t rsvd4      : 24        PACKED;
170   } ctrls;
171 };
172
173
174
175 typedef struct VMCB_Control_Area {
176   // offset 0x0
177   union Ctrl_Registers cr_reads        PACKED;
178   union Ctrl_Registers cr_writes       PACKED;
179   union Debug_Registers dr_reads       PACKED;
180   union Debug_Registers dr_writes      PACKED;
181   union Exception_Vectors exceptions   PACKED;
182   union Instr_Intercepts instrs        PACKED;
183   union SVM_Instr_Intercepts svm_instrs PACKED;
184
185   uchar_t rsvd1[43]                    PACKED;
186
187   // offset 0x040
188   ullong_t IOPM_BASE_PA                PACKED;
189   ullong_t MSRPM_BASE_PA               PACKED;
190   ullong_t TSC_OFFSET                  PACKED;
191
192   ulong_t guest_ASID                   PACKED;
193   uchar_t TLB_CONTROL                  PACKED;
194
195   uchar_t rsvd2[3]                     PACKED;
196
197   union Guest_Control guest_ctrl       PACKED;
198   
199   ulong_t interrupt_shadow  : 1        PACKED;
200   ulong_t rsvd3             : 31       PACKED;
201   ulong_t rsvd4                        PACKED;
202
203   ullong_t exit_code                   PACKED;
204   ullong_t exit_info1                  PACKED;
205   ullong_t exit_info2                  PACKED;
206
207   /* This could be a typo in the manual....
208    * It doesn't actually say that there is a reserved bit
209    * But it does say that the EXITINTINFO field is in bits 63-1
210    * ALL other occurances mention a 1 bit reserved field
211    */
212   ulong_t rsvd5             : 1        PACKED;
213   ullong_t exit_int_info    : 63       PACKED;
214   /* ** */
215
216   ulong_t NP_ENABLE         : 1        PACKED;
217   ullong_t rsvd6            : 63       PACKED;
218
219   uchar_t rsvd7[15]                    PACKED;
220
221   // Offset 0xA8
222   ullong_t EVENTINJ                    PACKED;
223
224
225   /* This could be a typo in the manual....
226    * It doesn't actually say that there is a reserved bit
227    * But it does say that the EXITINTINFO field is in bits 63-1
228    * ALL other occurances mention a 1 bit reserved field
229    */
230   ulong_t rsvd8             : 1        PACKED;
231   ullong_t N_CR3            : 63       PACKED;
232   /* ** */
233
234   ulong_t LBR_VIRTUALIZATION_ENABLE  : 1  PACKED;
235   ullong_t rsvd9            : 63       PACKED;
236
237 } vmcb_ctrl_t;
238
239
240
241
242
243
244 struct vmcb_selector {
245   ushort_t selector                   PACKED;
246   ushort_t attrib                     PACKED;
247   ulong_t  limit                      PACKED;
248   ullong_t base                       PACKED;
249 }
250
251
252
253
254
255
256
257 typedef struct VMCB_State_Save_Area {
258   struct vmcb_selector es            PACKED; // only lower 32 bits of base are implemented
259   struct vmcb_selector cs            PACKED; // only lower 32 bits of base are implemented
260   struct vmcb_selector ss            PACKED; // only lower 32 bits of base are implemented
261   struct vmcb_selector ds            PACKED; // only lower 32 bits of base are implemented
262   struct vmcb_selector fs            PACKED; 
263   struct vmcb_selector gs            PACKED; 
264
265   struct vmcb_selector gdtr          PACKED; // selector+attrib are reserved, only lower 16 bits of limit are implemented
266   struct vmcb_selector ldtr          PACKED; 
267   struct vmcb_selector idtr          PACKED; // selector+attrib are reserved, only lower 16 bits of limit are implemented
268   struct vmcb_selector tr            PACKED; 
269
270   uchar_t rsvd1[42]                  PACKED;
271
272   //offset 0x0cb
273   uchar_t cpl                        PACKED; // if the guest is real-mode then the CPL is forced to 0
274                                              // if the guest is virtual-mode then the CPL is forced to 3
275
276   ulong_t rsvd2                      PACKED;
277
278   // offset 0x0d0
279   ullong_t efer                      PACKED;
280
281   uchar_t rsvd3[111]                 PACKED;
282   
283   //offset 0x148
284   ullong_t cr4                       PACKED;
285   ullong_t cr3                       PACKED;
286   ullong_t cr0                       PACKED;
287   ullong_t dr7                       PACKED;
288   ullong_t dr6                       PACKED;
289   ullong_t rflags                    PACKED;
290   ullong_t rip                       PACKED;
291
292   uchar_t rsvd4[87]                  PACKED;
293   
294   //offset 0x1d8
295   ullong_t rsp                       PACKED;
296
297   uchar_t rsvd5[23]                  PACKED;
298
299   //offset 0x1f8
300   ullong_t rax                       PACKED;
301   ullong_t star                      PACKED;
302   ullong_t lstar                     PACKED;
303   ullong_t cstar                     PACKED;
304   ullong_t sfmask                    PACKED;
305   ullong_t KernelGsBase              PACKED;
306   ullong_t sysenter_cs               PACKED;
307   ullong_t sysenter_esp              PACKED;
308   ullong_t sysenter_eip              PACKED;
309   ullong_t cr2                       PACKED;
310
311
312   uchar_t rsvd6[31]                  PACKED;
313
314   //offset 0x268
315   ullong_t g_pat                     PACKED; // Guest PAT                          -- only used if nested paging is enabled
316   ullong_t dbgctl                    PACKED; // Guest DBGCTL MSR                   -- only used if the LBR registers are virtualized
317   ullong_t br_from                   PACKED; // Guest LastBranchFromIP MSR         -- only used if the LBR registers are virtualized
318   ullong_t br_to                     PACKED; // Guest LastBranchToIP MSR           -- only used if the LBR registers are virtualized
319   ullong_t lastexcpfrom              PACKED; // Guest LastExceptionFromIP MSR      -- only used if the LBR registers are virtualized
320   ullong_t lastexcpto                PACKED; // Guest LastExceptionToIP MSR        -- only used if the LBR registers are virtualized
321
322 } vmcb_saved_state_t;
323
324
325 #endif