-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine.h
327 lines (315 loc) · 11.8 KB
/
machine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
* machine.h
*
* This header-file is for inclusion in a Linux Kernel Module
* that will build a host Virtual Machine Manager and a guest
* Virtual Machine. See Intel 64 Software Developer's Manual
* (Volume 3B), Appendix H.
*
*/
typedef struct { int encoding; void *setting; } VMCS_DEF;
// Natural 32-bit Control fields
unsigned int control_VMX_pin_based;
unsigned int control_VMX_cpu_based;
unsigned int control_exception_bitmap;
unsigned int control_pagefault_errorcode_mask;
unsigned int control_pagefault_errorcode_match;
unsigned int control_CR3_target_count;
unsigned int control_VM_exit_controls;
unsigned int control_VM_exit_MSR_store_count;
unsigned int control_VM_exit_MSR_load_count;
unsigned int control_VM_entry_controls;
unsigned int control_VM_entry_MSR_load_count;
unsigned int control_VM_entry_interruption_information;
unsigned int control_VM_entry_exception_errorcode;
unsigned int control_VM_entry_instruction_length;
unsigned int control_Task_PRivilege_Threshold;
// Natural 64-bit Control fields
unsigned long long control_CR0_mask;
unsigned long long control_CR4_mask;
unsigned long long control_CR0_shadow;
unsigned long long control_CR4_shadow;
unsigned long long control_CR3_target0;
unsigned long long control_CR3_target1;
unsigned long long control_CR3_target2;
unsigned long long control_CR3_target3;
// Full 64-bit Control fields
unsigned int control_IO_BitmapA_address_full;
unsigned int control_IO_BitmapA_address_high;
unsigned int control_IO_BitmapB_address_full;
unsigned int control_IO_BitmapB_address_high;
unsigned int control_MSR_Bitmaps_address_full;
unsigned int control_MSR_Bitmaps_address_high;
unsigned int control_VM_exit_MSR_store_address_full;
unsigned int control_VM_exit_MSR_store_address_high;
unsigned int control_VM_exit_MSR_load_address_full;
unsigned int control_VM_exit_MSR_load_address_high;
unsigned int control_VM_entry_MSR_load_address_full;
unsigned int control_VM_entry_MSR_load_address_high;
unsigned int control_Executive_VMCS_pointer_full;
unsigned int control_Executive_VMCS_pointer_high;
unsigned int control_TSC_offset_full;
unsigned int control_TSC_offset_high;
unsigned int control_virtual_APIC_page_address_full;
unsigned int control_virtual_APIC_page_address_high;
// Natural 64-bit Host-State fields
unsigned long long host_CR0;
unsigned long long host_CR3;
unsigned long long host_CR4;
unsigned long long host_FS_base;
unsigned long long host_GS_base;
unsigned long long host_TR_base;
unsigned long long host_GDTR_base;
unsigned long long host_IDTR_base;
unsigned long long host_SYSENTER_ESP;
unsigned long long host_SYSENTER_EIP;
unsigned long long host_RSP;
unsigned long long host_RIP;
// Natural 32-bit Host-State fields
unsigned int host_SYSENTER_CS;
// Natural 16-bit Host-State fields
unsigned short host_ES_selector;
unsigned short host_CS_selector;
unsigned short host_SS_selector;
unsigned short host_DS_selector;
unsigned short host_FS_selector;
unsigned short host_GS_selector;
unsigned short host_TR_selector;
// Natural 64-bit Guest-State fields
unsigned long long guest_CR0;
unsigned long long guest_CR3;
unsigned long long guest_CR4;
unsigned long long guest_ES_base;
unsigned long long guest_CS_base;
unsigned long long guest_SS_base;
unsigned long long guest_DS_base;
unsigned long long guest_FS_base;
unsigned long long guest_GS_base;
unsigned long long guest_LDTR_base;
unsigned long long guest_TR_base;
unsigned long long guest_GDTR_base;
unsigned long long guest_IDTR_base;
unsigned long long guest_DR7;
unsigned long long guest_RSP;
unsigned long long guest_RIP;
unsigned long long guest_RFLAGS;
unsigned long long guest_pending_debug_x;
unsigned long long guest_SYSENTER_ESP;
unsigned long long guest_SYSENTER_EIP;
// Natural 32-bit Guest-State fields
unsigned int guest_ES_limit;
unsigned int guest_CS_limit;
unsigned int guest_SS_limit;
unsigned int guest_DS_limit;
unsigned int guest_FS_limit;
unsigned int guest_GS_limit;
unsigned int guest_LDTR_limit;
unsigned int guest_TR_limit;
unsigned int guest_GDTR_limit;
unsigned int guest_IDTR_limit;
unsigned int guest_ES_access_rights;
unsigned int guest_CS_access_rights;
unsigned int guest_SS_access_rights;
unsigned int guest_DS_access_rights;
unsigned int guest_FS_access_rights;
unsigned int guest_GS_access_rights;
unsigned int guest_LDTR_access_rights;
unsigned int guest_TR_access_rights;
unsigned int guest_interruptibility;
unsigned int guest_activity_state;
unsigned int guest_SMBASE; // <-- Added 23 December 2006
unsigned int guest_SYSENTER_CS;
// Natural 16-bit Guest-State fields
unsigned short guest_ES_selector;
unsigned short guest_CS_selector;
unsigned short guest_SS_selector;
unsigned short guest_DS_selector;
unsigned short guest_FS_selector;
unsigned short guest_GS_selector;
unsigned short guest_LDTR_selector;
unsigned short guest_TR_selector;
// Full 64-bit Guest-State fields
unsigned int guest_VMCS_link_pointer_full;
unsigned int guest_VMCS_link_pointer_high;
unsigned int guest_IA32_DEBUGCTL_full;
unsigned int guest_IA32_DEBUGCTL_high;
//------------------
// Read-Only Fields
//------------------
unsigned int info_vminstr_error;
unsigned int info_vmexit_reason;
unsigned int info_vmexit_interrupt_information;
unsigned int info_vmexit_interrupt_error_code;
unsigned int info_IDT_vectoring_information;
unsigned int info_IDT_vectoring_error_code;
unsigned int info_vmexit_instruction_length;
unsigned int info_vmx_instruction_information;
unsigned long long info_exit_qualification;
unsigned long long info_IO_RCX;
unsigned long long info_IO_RSI;
unsigned long long info_IO_RDI;
unsigned long long info_IO_RIP;
unsigned long long info_guest_linear_address;
VMCS_DEF machine[] = {
//----------------
// Control fields
//----------------
// Natural 32-bit Control fields
{ 0x4000, &control_VMX_pin_based },
{ 0x4002, &control_VMX_cpu_based },
{ 0x4004, &control_exception_bitmap },
{ 0x4006, &control_pagefault_errorcode_mask },
{ 0x4008, &control_pagefault_errorcode_match },
{ 0x400A, &control_CR3_target_count },
{ 0x400C, &control_VM_exit_controls },
{ 0x400E, &control_VM_exit_MSR_store_count },
{ 0x4010, &control_VM_exit_MSR_load_count },
{ 0x4012, &control_VM_entry_controls },
{ 0x4014, &control_VM_entry_MSR_load_count },
{ 0x4016, &control_VM_entry_interruption_information },
{ 0x4018, &control_VM_entry_exception_errorcode },
{ 0x401A, &control_VM_entry_instruction_length },
{ 0x401C, &control_Task_PRivilege_Threshold },
// Natural 64-bit Control fields
{ 0x6000, &control_CR0_mask },
{ 0x6002, &control_CR4_mask },
{ 0x6004, &control_CR0_shadow },
{ 0x6006, &control_CR4_shadow },
{ 0x6008, &control_CR3_target0 },
{ 0x600A, &control_CR3_target1 },
{ 0x600C, &control_CR3_target2 },
{ 0x600E, &control_CR3_target3 },
// Full 64-bit Control fields
{ 0x2000, &control_IO_BitmapA_address_full },
{ 0x2001, &control_IO_BitmapA_address_high },
{ 0x2002, &control_IO_BitmapB_address_full },
{ 0x2003, &control_IO_BitmapB_address_high },
//// { 0x2004, &control_MSR_Bitmaps_address_full },
//// { 0x2005, &control_MSR_Bitmaps_address_high },
{ 0x2006, &control_VM_exit_MSR_store_address_full },
{ 0x2007, &control_VM_exit_MSR_store_address_high },
{ 0x2008, &control_VM_exit_MSR_load_address_full },
{ 0x2009, &control_VM_exit_MSR_load_address_high },
{ 0x200A, &control_VM_entry_MSR_load_address_full },
{ 0x200B, &control_VM_entry_MSR_load_address_high },
{ 0x200C, &control_Executive_VMCS_pointer_full },
{ 0x200D, &control_Executive_VMCS_pointer_high },
{ 0x2010, &control_TSC_offset_full },
{ 0x2011, &control_TSC_offset_high },
//// { 0x2012, &control_virtual_APIC_page_address_full },
//// { 0x2013, &control_virtual_APIC_page_address_high },
//-------------------
// Host-State fields
//-------------------
// Natural 64-bit Host-State fields
{ 0x6C00, &host_CR0 },
{ 0x6C02, &host_CR3 },
{ 0x6C04, &host_CR4 },
{ 0x6C06, &host_FS_base },
{ 0x6C08, &host_GS_base },
{ 0x6C0A, &host_TR_base },
{ 0x6C0C, &host_GDTR_base },
{ 0x6C0E, &host_IDTR_base },
{ 0x6C10, &host_SYSENTER_ESP },
{ 0x6C12, &host_SYSENTER_EIP },
{ 0x6C14, &host_RSP },
{ 0x6C16, &host_RIP },
// Natural 32-bit Host-State fields
{ 0x4C00, &host_SYSENTER_CS },
// Natural 16-bit Host-State fields
{ 0x0C00, &host_ES_selector },
{ 0x0C02, &host_CS_selector },
{ 0x0C04, &host_SS_selector },
{ 0x0C06, &host_DS_selector },
{ 0x0C08, &host_FS_selector },
{ 0x0C0A, &host_GS_selector },
{ 0x0C0C, &host_TR_selector },
//--------------------
// Guest-State fields
//--------------------
// Natural 64-bit Guest-State fields
{ 0x6800, &guest_CR0 },
{ 0x6802, &guest_CR3 },
{ 0x6804, &guest_CR4 },
{ 0x6806, &guest_ES_base },
{ 0x6808, &guest_CS_base },
{ 0x680A, &guest_SS_base },
{ 0x680C, &guest_DS_base },
{ 0x680E, &guest_FS_base },
{ 0x6810, &guest_GS_base },
{ 0x6812, &guest_LDTR_base },
{ 0x6814, &guest_TR_base },
{ 0x6816, &guest_GDTR_base },
{ 0x6818, &guest_IDTR_base },
{ 0x681A, &guest_DR7 },
{ 0x681C, &guest_RSP },
{ 0x681E, &guest_RIP },
{ 0x6820, &guest_RFLAGS },
{ 0x6822, &guest_pending_debug_x },
{ 0x6824, &guest_SYSENTER_ESP },
{ 0x6826, &guest_SYSENTER_EIP },
// Natural 32-bit Guest-State fields
{ 0x4800, &guest_ES_limit },
{ 0x4802, &guest_CS_limit },
{ 0x4804, &guest_SS_limit },
{ 0x4806, &guest_DS_limit },
{ 0x4808, &guest_FS_limit },
{ 0x480A, &guest_GS_limit },
{ 0x480C, &guest_LDTR_limit },
{ 0x480E, &guest_TR_limit },
{ 0x4810, &guest_GDTR_limit },
{ 0x4812, &guest_IDTR_limit },
{ 0x4814, &guest_ES_access_rights },
{ 0x4816, &guest_CS_access_rights },
{ 0x4818, &guest_SS_access_rights },
{ 0x481A, &guest_DS_access_rights },
{ 0x481C, &guest_FS_access_rights },
{ 0x481E, &guest_GS_access_rights },
{ 0x4820, &guest_LDTR_access_rights },
{ 0x4822, &guest_TR_access_rights },
{ 0x4824, &guest_interruptibility },
{ 0x4826, &guest_activity_state },
{ 0x4828, &guest_SMBASE },
{ 0x482A, &guest_SYSENTER_CS },
// Natural 16-bit Guest-State fields
{ 0x0800, &guest_ES_selector },
{ 0x0802, &guest_CS_selector },
{ 0x0804, &guest_SS_selector },
{ 0x0806, &guest_DS_selector },
{ 0x0808, &guest_FS_selector },
{ 0x080A, &guest_GS_selector },
{ 0x080C, &guest_LDTR_selector },
{ 0x080E, &guest_TR_selector },
// Full 64-bit Guest-State fields
{ 0x2800, &guest_VMCS_link_pointer_full },
{ 0x2801, &guest_VMCS_link_pointer_high },
{ 0x2802, &guest_IA32_DEBUGCTL_full },
{ 0x2803, &guest_IA32_DEBUGCTL_high } };
const long elements = ( sizeof( machine ) ) / sizeof( VMCS_DEF );
VMCS_DEF results[ ] = {
{ 0x681C, &guest_RSP },
{ 0x681E, &guest_RIP },
{ 0x6820, &guest_RFLAGS },
{ 0x0800, &guest_ES_selector },
{ 0x0802, &guest_CS_selector },
{ 0x0804, &guest_SS_selector },
{ 0x0806, &guest_DS_selector },
{ 0x0808, &guest_FS_selector },
{ 0x080A, &guest_GS_selector },
{ 0x080C, &guest_LDTR_selector },
{ 0x080E, &guest_TR_selector },
{ 0x4400, &info_vminstr_error },
{ 0x4402, &info_vmexit_reason },
{ 0x4404, &info_vmexit_interrupt_information },
{ 0x4406, &info_vmexit_interrupt_error_code },
{ 0x4408, &info_IDT_vectoring_information },
{ 0x440A, &info_IDT_vectoring_error_code },
{ 0x440C, &info_vmexit_instruction_length },
{ 0x440E, &info_vmx_instruction_information },
{ 0x6400, &info_exit_qualification },
{ 0x6402, &info_IO_RCX },
{ 0x6404, &info_IO_RSI },
{ 0x6406, &info_IO_RDI },
{ 0x6408, &info_IO_RIP },
{ 0x640A, &info_guest_linear_address } };
const long rocount = sizeof( results ) / sizeof( VMCS_DEF );