VirtualBox

source: vbox/trunk/include/VBox/hwacc_vmx.h@ 11270

Last change on this file since 11270 was 10831, checked in by vboxsync, 16 years ago

Update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.5 KB
Line 
1/** @file
2 * HWACC/VMX - VMX Structures and Definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_vmx_h
31#define ___VBox_vmx_h
32
33#include <VBox/types.h>
34#include <VBox/err.h>
35#include <iprt/assert.h>
36#include <iprt/asm.h>
37
38/** @defgroup grp_vmx vmx Types and Definitions
39 * @ingroup grp_hwaccm
40 * @{
41 */
42
43/**
44 * Extended Page Directory Pointer. Bit view.
45 */
46#pragma pack(1)
47typedef struct VTXEPTPBITS
48{
49 /** EPT Table Memory Type. */
50 uint64_t u3ETMT : 3;
51 /** Guest Address Width. */
52 uint64_t u3GAW : 3;
53 /** Reserved. */
54 uint64_t u6Reserved : 6;
55 /** Address Space Root; page frame address of the first level EPT page. Actual width depends on the maximum physical address width of the CPU. */
56 uint64_t u52ASR : 52;
57} VTXEPTPBITS;
58#pragma pack()
59/** Pointer to an extended page directory pointer. */
60typedef VTXEPTPBITS *PVTXEPTPBITS;
61/** Pointer to a const extended page directory pointer. */
62typedef const VTXEPTPBITS *PCVTXEPTPBITS;
63
64/**
65 * Extended Page Directory Pointer.
66 */
67#pragma pack(1)
68typedef union VTXEPTP
69{
70 VTXEPTPBITS n;
71 /** 64 bit unsigned integer view. */
72 uint64_t au64[1];
73} VTXEPTP;
74#pragma pack()
75/** Pointer to an extended page directory pointer. */
76typedef VTXEPTP *PVTXEPTP;
77/** Pointer to a const extended page directory pointer. */
78typedef const VTXEPTP *PCVTXEPTP;
79
80
81/**
82 * Extended Page Directory Table Entry. Bit view.
83 */
84#pragma pack(1)
85typedef union VTXEPTEBITS
86{
87 /** Readable bit. */
88 uint64_t u1Readable : 1;
89 /** Writable bit. */
90 uint64_t u1Writable : 1;
91 /** Executable bit. */
92 uint64_t u1Executable : 1;
93 /** EPT Table Memory Type. MBZ for non-leaf nodes. */
94 uint64_t u3EMT : 3;
95 /** IGMT (Ignore Guest Memory Type) (leaf nodes). MBZ for non-leaf nodes. */
96 uint64_t u1IGMT : 1;
97 /** Super page (non-leaf) / available (leaf). */
98 uint64_t u1SP : 1;
99 /** Available for software. */
100 uint64_t u4Available : 4;
101 /** Physical address of next leaf/super page. Restricted by maximum physical address width of the cpu. */
102 uint64_t u45PhysAddr : 45;
103 /** Reserved (MBZ). */
104 uint64_t u5Reserved : 5;
105 /** Availabe for software. */
106 uint64_t u2Available : 2;
107} VTXEPTEBITS;
108#pragma pack()
109/** Pointer to an extended page table entry. */
110typedef VTXEPTEBITS *PVTXEPTEBITS;
111/** Pointer to a const extended table entry. */
112typedef const VTXEPTEBITS *PCVTXEPTEBITS;
113
114/**
115 * Extended Page Directory Table Entry.
116 */
117#pragma pack(1)
118typedef union VTXEPTE
119{
120 VTXEPTEBITS n;
121 /** 64 bit unsigned integer view. */
122 uint64_t au64[1];
123} VTXEPTE;
124#pragma pack()
125/** Pointer to an extended page table entry. */
126typedef VTXEPTE *PVTXEPTE;
127/** Pointer to a const extended table entry. */
128typedef const VTXEPTE *PCVTXEPTE;
129
130/**
131 * Number of page table entries in the EPT.
132 */
133#define VTX_PT_ENTRIES 512
134
135/**
136 * Extended Page Directory Table.
137 */
138#pragma pack(1)
139typedef union VTXEPT
140{
141 VTXEPTE a[VTX_PT_ENTRIES];
142} VTXEPT;
143#pragma pack()
144/** Pointer to an extended page table. */
145typedef VTXEPT *PVTXEPT;
146/** Pointer to a const extended table. */
147typedef const VTXEPT *PCVTXEPT;
148
149/** VMX Basic Exit Reasons.
150 * @{
151 */
152/* And-mask for setting reserved bits to zero */
153#define VMX_EFLAGS_RESERVED_0 (~0xffc08028)
154/* Or-mask for setting reserved bits to 1 */
155#define VMX_EFLAGS_RESERVED_1 0x00000002
156/** @} */
157
158/** VMX Basic Exit Reasons.
159 * @{
160 */
161/** 0 Exception or non-maskable interrupt (NMI). */
162#define VMX_EXIT_EXCEPTION 0
163/** 1 External interrupt. */
164#define VMX_EXIT_EXTERNAL_IRQ 1
165/** 2 Triple fault. */
166#define VMX_EXIT_TRIPLE_FAULT 2
167/** 3 INIT signal. */
168#define VMX_EXIT_INIT_SIGNAL 3
169/** 4 Start-up IPI (SIPI). */
170#define VMX_EXIT_SIPI 4
171/** 5 I/O system-management interrupt (SMI). */
172#define VMX_EXIT_IO_SMI_IRQ 5
173/** 6 Other SMI. */
174#define VMX_EXIT_SMI_IRQ 6
175/** 7 Interrupt window. */
176#define VMX_EXIT_IRQ_WINDOW 7
177/** 9 Task switch. */
178#define VMX_EXIT_TASK_SWITCH 9
179/** 10 Guest software attempted to execute CPUID. */
180#define VMX_EXIT_CPUID 10
181/** 12 Guest software attempted to execute HLT. */
182#define VMX_EXIT_HLT 12
183/** 13 Guest software attempted to execute INVD. */
184#define VMX_EXIT_INVD 13
185/** 14 Guest software attempted to execute INVPG. */
186#define VMX_EXIT_INVPG 14
187/** 15 Guest software attempted to execute RDPMC. */
188#define VMX_EXIT_RDPMC 15
189/** 16 Guest software attempted to execute RDTSC. */
190#define VMX_EXIT_RDTSC 16
191/** 17 Guest software attempted to execute RSM in SMM. */
192#define VMX_EXIT_RSM 17
193/** 18 Guest software executed VMCALL. */
194#define VMX_EXIT_VMCALL 18
195/** 19 Guest software executed VMCLEAR. */
196#define VMX_EXIT_VMCLEAR 19
197/** 20 Guest software executed VMLAUNCH. */
198#define VMX_EXIT_VMLAUNCH 20
199/** 21 Guest software executed VMPTRLD. */
200#define VMX_EXIT_VMPTRLD 21
201/** 22 Guest software executed VMPTRST. */
202#define VMX_EXIT_VMPTRST 22
203/** 23 Guest software executed VMREAD. */
204#define VMX_EXIT_VMREAD 23
205/** 24 Guest software executed VMRESUME. */
206#define VMX_EXIT_VMRESUME 24
207/** 25 Guest software executed VMWRITE. */
208#define VMX_EXIT_VMWRITE 25
209/** 26 Guest software executed VMXOFF. */
210#define VMX_EXIT_VMXOFF 26
211/** 27 Guest software executed VMXON. */
212#define VMX_EXIT_VMXON 27
213/** 28 Control-register accesses. */
214#define VMX_EXIT_CRX_MOVE 28
215/** 29 Debug-register accesses. */
216#define VMX_EXIT_DRX_MOVE 29
217/** 30 I/O instruction. */
218#define VMX_EXIT_PORT_IO 30
219/** 31 RDMSR. Guest software attempted to execute RDMSR. */
220#define VMX_EXIT_RDMSR 31
221/** 32 WRMSR. Guest software attempted to execute WRMSR. */
222#define VMX_EXIT_WRMSR 32
223/** 33 VM-entry failure due to invalid guest state. */
224#define VMX_EXIT_ERR_INVALID_GUEST_STATE 33
225/** 34 VM-entry failure due to MSR loading. */
226#define VMX_EXIT_ERR_MSR_LOAD 34
227/** 36 Guest software executed MWAIT. */
228#define VMX_EXIT_MWAIT 36
229/** 39 Guest software attempted to execute MONITOR. */
230#define VMX_EXIT_MONITOR 39
231/** 40 Guest software attempted to execute PAUSE. */
232#define VMX_EXIT_PAUSE 40
233/** 41 VM-entry failure due to machine-check. */
234#define VMX_EXIT_ERR_MACHINE_CHECK 41
235/** 43 TPR below threshold. Guest software executed MOV to CR8. */
236#define VMX_EXIT_TPR 43
237
238/** @} */
239
240
241/** VM Instruction Errors
242 * @{
243 */
244/** 1 VMCALL executed in VMX root operation. */
245#define VMX_ERROR_VMCALL 1
246/** 2 VMCLEAR with invalid physical address. */
247#define VMX_ERROR_VMCLEAR_INVALID_PHYS_ADDR 2
248/** 3 VMCLEAR with VMXON pointer. */
249#define VMX_ERROR_VMCLEAR_INVALID_VMXON_PTR 3
250/** 4 VMLAUNCH with non-clear VMCS. */
251#define VMX_ERROR_VMLAUCH_NON_CLEAR_VMCS 4
252/** 5 VMRESUME with non-launched VMCS. */
253#define VMX_ERROR_VMRESUME_NON_LAUNCHED_VMCS 5
254/** 6 VMRESUME with a corrupted VMCS (indicates corruption of the current VMCS). */
255#define VMX_ERROR_VMRESUME_CORRUPTED_VMCS 6
256/** 7 VM entry with invalid control field(s). */
257#define VMX_ERROR_VMENTRY_INVALID_CONTROL_FIELDS 7
258/** 8 VM entry with invalid host-state field(s). */
259#define VMX_ERROR_VMENTRY_INVALID_HOST_STATE 8
260/** 9 VMPTRLD with invalid physical address. */
261#define VMX_ERROR_VMPTRLD_INVALID_PHYS_ADDR 9
262/** 10 VMPTRLD with VMXON pointer. */
263#define VMX_ERROR_VMPTRLD_VMXON_PTR 10
264/** 11 VMPTRLD with incorrect VMCS revision identifier. */
265#define VMX_ERROR_VMPTRLD_WRONG_VMCS_REVISION 11
266/** 12 VMREAD/VMWRITE from/to unsupported VMCS component. */
267#define VMX_ERROR_VMREAD_INVALID_COMPONENT 12
268#define VMX_ERROR_VMWRITE_INVALID_COMPONENT VMX_ERROR_VMREAD_INVALID_COMPONENT
269/** 13 VMWRITE to read-only VMCS component. */
270#define VMX_ERROR_VMWRITE_READONLY_COMPONENT 13
271/** 15 VMXON executed in VMX root operation. */
272#define VMX_ERROR_VMXON_IN_VMX_ROOT_OP 15
273/** 16 VM entry with invalid executive-VMCS pointer. */
274#define VMX_ERROR_VMENTRY_INVALID_VMCS_EXEC_PTR 16
275/** 17 VM entry with non-launched executive VMCS. */
276#define VMX_ERROR_VMENTRY_NON_LAUNCHED_EXEC_VMCS 17
277/** 18 VM entry with executive-VMCS pointer not VMXON pointer. */
278#define VMX_ERROR_VMENTRY_EXEC_VMCS_PTR 18
279/** 19 VMCALL with non-clear VMCS. */
280#define VMX_ERROR_VMCALL_NON_CLEAR_VMCS 19
281/** 20 VMCALL with invalid VM-exit control fields. */
282#define VMX_ERROR_VMCALL_INVALID_VMEXIT_FIELDS 20
283/** 22 VMCALL with incorrect MSEG revision identifier. */
284#define VMX_ERROR_VMCALL_INVALID_MSEG_REVISION 22
285/** 23 VMXOFF under dual-monitor treatment of SMIs and SMM. */
286#define VMX_ERROR_VMXOFF_DUAL_MONITOR 23
287/** 24 VMCALL with invalid SMM-monitor features. */
288#define VMX_ERROR_VMCALL_INVALID_SMM_MONITOR 24
289/** 25 VM entry with invalid VM-execution control fields in executive VMCS. */
290#define VMX_ERROR_VMENTRY_INVALID_VM_EXEC_CTRL 25
291/** 26 VM entry with events blocked by MOV SS. */
292#define VMX_ERROR_VMENTRY_MOV_SS 26
293
294/** @} */
295
296
297/** VMX MSR bit definitions
298 * @{
299 */
300
301/** Basic VMX information.
302 * @{
303 */
304/** VMCS revision identifier used by the processor. */
305#define MSR_IA32_VMX_BASIC_INFO_VMCS_ID(a) (a & 0x7FFFFFFF)
306/** Size of the VMCS. */
307#define MSR_IA32_VMX_BASIC_INFO_VMCS_SIZE(a) ((a >> 32ULL) & 0xFFF)
308/** Width of physical address used for the VMCS.
309 * 0 -> limited to the available amount of physical ram
310 * 1 -> within the first 4 GB
311 */
312#define MSR_IA32_VMX_BASIC_INFO_VMCS_PHYS_WIDTH(a) ((a >> 48ULL) & 1)
313/** Whether the processor supports the dual-monitor treatment of system-management interrupts and system-management code. (always 1) */
314#define MSR_IA32_VMX_BASIC_INFO_VMCS_DUAL_MON(a) ((a >> 49ULL) & 1)
315/** Memory type that must be used for the VMCS. */
316#define MSR_IA32_VMX_BASIC_INFO_VMCS_MEM_TYPE(a) ((a >> 50ULL) & 0xF)
317/** @} */
318
319
320/** Misc VMX info.
321 * @{
322 */
323/** Activity states supported by the implementation. */
324#define MSR_IA32_VMX_MISC_ACTIVITY_STATES(a) ((a >> 6ULL) & 0x7)
325/** Number of CR3 target values supported by the processor. (0-256) */
326#define MSR_IA32_VMX_MISC_CR3_TARGET(a) ((a >> 16ULL) & 0x1FF)
327/** Maximum nr of MSRs in the VMCS. (N+1)*512. */
328#define MSR_IA32_VMX_MISC_MAX_MSR(a) ((((a >> 25ULL) & 0x7) + 1) * 512)
329/** MSEG revision identifier used by the processor. */
330#define MSR_IA32_VMX_MISC_MSEG_ID(a) (a >> 32ULL)
331/** @} */
332
333
334/** VMCS enumeration field info
335 * @{
336 */
337/** Highest field index. */
338#define MSR_IA32_VMX_VMCS_ENUM_HIGHEST_INDEX(a) ((a >> 1ULL) & 0x1FF)
339
340/** @} */
341
342
343/** MSR_IA32_VMX_EPT_CAPS; EPT capabilities MSR
344 * @{
345 */
346#define MSR_IA32_VMX_EPT_CAPS_RWX_X_ONLY RT_BIT_64(0)
347#define MSR_IA32_VMX_EPT_CAPS_RWX_W_ONLY RT_BIT_64(1)
348#define MSR_IA32_VMX_EPT_CAPS_RWX_WX_ONLY RT_BIT_64(2)
349#define MSR_IA32_VMX_EPT_CAPS_GAW_21_BITS RT_BIT_64(3)
350#define MSR_IA32_VMX_EPT_CAPS_GAW_30_BITS RT_BIT_64(4)
351#define MSR_IA32_VMX_EPT_CAPS_GAW_39_BITS RT_BIT_64(5)
352#define MSR_IA32_VMX_EPT_CAPS_GAW_48_BITS RT_BIT_64(6)
353#define MSR_IA32_VMX_EPT_CAPS_GAW_57_BITS RT_BIT_64(7)
354#define MSR_IA32_VMX_EPT_CAPS_EMT_UC RT_BIT_64(8)
355#define MSR_IA32_VMX_EPT_CAPS_EMT_WC RT_BIT_64(9)
356#define MSR_IA32_VMX_EPT_CAPS_EMT_WT RT_BIT_64(12)
357#define MSR_IA32_VMX_EPT_CAPS_EMT_WP RT_BIT_64(13)
358#define MSR_IA32_VMX_EPT_CAPS_EMT_WB RT_BIT_64(14)
359#define MSR_IA32_VMX_EPT_CAPS_SP_21_BITS RT_BIT_64(16)
360#define MSR_IA32_VMX_EPT_CAPS_SP_30_BITS RT_BIT_64(17)
361#define MSR_IA32_VMX_EPT_CAPS_SP_39_BITS RT_BIT_64(18)
362#define MSR_IA32_VMX_EPT_CAPS_SP_48_BITS RT_BIT_64(19)
363#define MSR_IA32_VMX_EPT_CAPS_INVEPT RT_BIT_64(20)
364#define MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_INDIV RT_BIT_64(24)
365#define MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_CONTEXT RT_BIT_64(25)
366#define MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_ALL RT_BIT_64(26)
367#define MSR_IA32_VMX_EPT_CAPS_INVVPID RT_BIT_64(32)
368#define MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_INDIV RT_BIT_64(40)
369#define MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_CONTEXT RT_BIT_64(41)
370#define MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_ALL RT_BIT_64(42)
371#define MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_CONTEXT_GLOBAL RT_BIT_64(43)
372
373/** @} */
374
375/** @} */
376
377
378/** VMCS field encoding
379 * @{
380 */
381
382/* 16 bits guest fields
383 * @{
384 */
385#define VMX_VMCS_GUEST_FIELD_VPID 0x0
386#define VMX_VMCS_GUEST_FIELD_ES 0x800
387#define VMX_VMCS_GUEST_FIELD_CS 0x802
388#define VMX_VMCS_GUEST_FIELD_SS 0x804
389#define VMX_VMCS_GUEST_FIELD_DS 0x806
390#define VMX_VMCS_GUEST_FIELD_FS 0x808
391#define VMX_VMCS_GUEST_FIELD_GS 0x80A
392#define VMX_VMCS_GUEST_FIELD_LDTR 0x80C
393#define VMX_VMCS_GUEST_FIELD_TR 0x80E
394/** @} */
395
396/** 16 bits host fields
397 * @{
398 */
399#define VMX_VMCS_HOST_FIELD_ES 0xC00
400#define VMX_VMCS_HOST_FIELD_CS 0xC02
401#define VMX_VMCS_HOST_FIELD_SS 0xC04
402#define VMX_VMCS_HOST_FIELD_DS 0xC06
403#define VMX_VMCS_HOST_FIELD_FS 0xC08
404#define VMX_VMCS_HOST_FIELD_GS 0xC0A
405#define VMX_VMCS_HOST_FIELD_TR 0xC0C
406/** @} */
407
408/** 64 bits host fields
409 * @{
410 */
411#define VMX_VMCS_HOST_FIELD_PAT_FULL 0x2C00
412#define VMX_VMCS_HOST_FIELD_PAT_HIGH 0x2C01
413#define VMX_VMCS_HOST_FIELD_EFER_FULL 0x2C02
414#define VMX_VMCS_HOST_FIELD_EFER_HIGH 0x2C03
415#define VMX_VMCS_HOST_PERF_GLOBAL_CTRL_FULL 0x2C04 /* MSR IA32_PERF_GLOBAL_CTRL */
416#define VMX_VMCS_HOST_PERF_GLOBAL_CTRL_HIGH 0x2C05 /* MSR IA32_PERF_GLOBAL_CTRL */
417/** @} */
418
419
420/** 64 Bits control fields
421 * @{
422 */
423#define VMX_VMCS_CTRL_IO_BITMAP_A_FULL 0x2000
424#define VMX_VMCS_CTRL_IO_BITMAP_A_HIGH 0x2001
425#define VMX_VMCS_CTRL_IO_BITMAP_B_FULL 0x2002
426#define VMX_VMCS_CTRL_IO_BITMAP_B_HIGH 0x2003
427
428/* Optional */
429#define VMX_VMCS_CTRL_MSR_BITMAP_FULL 0x2004
430#define VMX_VMCS_CTRL_MSR_BITMAP_HIGH 0x2005
431
432#define VMX_VMCS_CTRL_VMEXIT_MSR_STORE_FULL 0x2006
433#define VMX_VMCS_CTRL_VMEXIT_MSR_STORE_HIGH 0x2007
434#define VMX_VMCS_CTRL_VMEXIT_MSR_LOAD_FULL 0x2008
435#define VMX_VMCS_CTRL_VMEXIT_MSR_LOAD_HIGH 0x2009
436
437#define VMX_VMCS_CTRL_VMENTRY_MSR_LOAD_FULL 0x200A
438#define VMX_VMCS_CTRL_VMENTRY_MSR_LOAD_HIGH 0x200B
439
440#define VMX_VMCS_CTRL_EXEC_VMCS_PTR_FULL 0x200C
441#define VMX_VMCS_CTRL_EXEC_VMCS_PTR_HIGH 0x200D
442
443#define VMX_VMCS_CTRL_TSC_OFFSET_FULL 0x2010
444#define VMX_VMCS_CTRL_TSC_OFFSET_HIGH 0x2011
445
446/* Optional (VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_TPR_SHADOW) */
447#define VMX_VMCS_CTRL_VAPIC_PAGEADDR_FULL 0x2012
448#define VMX_VMCS_CTRL_VAPIC_PAGEADDR_HIGH 0x2013
449
450/* Optional (VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC) */
451#define VMX_VMCS_CTRL_APIC_ACCESSADDR_FULL 0x2014
452#define VMX_VMCS_CTRL_APIC_ACCESSADDR_HIGH 0x2015
453
454/** Extended page table pointer. */
455#define VMX_VMCS_CTRL_EPTP_FULL 0x201a
456#define VMX_VMCS_CTRL_EPTP_HIGH 0x201b
457
458/** VM-exit phyiscal address. */
459#define VMX_VMCS_EXIT_PHYS_ADDR_FULL 0x2400
460#define VMX_VMCS_EXIT_PHYS_ADDR_HIGH 0x2401
461/** @} */
462
463
464/** 64 Bits guest fields
465 * @{
466 */
467#define VMX_VMCS_GUEST_LINK_PTR_FULL 0x2800
468#define VMX_VMCS_GUEST_LINK_PTR_HIGH 0x2801
469#define VMX_VMCS_GUEST_DEBUGCTL_FULL 0x2802 /* MSR IA32_DEBUGCTL */
470#define VMX_VMCS_GUEST_DEBUGCTL_HIGH 0x2803 /* MSR IA32_DEBUGCTL */
471#define VMX_VMCS_GUEST_PAT_FULL 0x2804
472#define VMX_VMCS_GUEST_PAT_HIGH 0x2805
473#define VMX_VMCS_GUEST_EFER_FULL 0x2806
474#define VMX_VMCS_GUEST_EFER_HIGH 0x2807
475#define VMX_VMCS_GUEST_PERF_GLOBAL_CTRL_FULL 0x2808 /* MSR IA32_PERF_GLOBAL_CTRL */
476#define VMX_VMCS_GUEST_PERF_GLOBAL_CTRL_HIGH 0x2809 /* MSR IA32_PERF_GLOBAL_CTRL */
477#define VMX_VMCS_GUEST_PDPTR0_FULL 0x280A
478#define VMX_VMCS_GUEST_PDPTR0_HIGH 0x280B
479#define VMX_VMCS_GUEST_PDPTR1_FULL 0x280C
480#define VMX_VMCS_GUEST_PDPTR1_HIGH 0x280D
481#define VMX_VMCS_GUEST_PDPTR2_FULL 0x280E
482#define VMX_VMCS_GUEST_PDPTR2_HIGH 0x280F
483#define VMX_VMCS_GUEST_PDPTR3_FULL 0x2810
484#define VMX_VMCS_GUEST_PDPTR3_HIGH 0x2811
485/** @} */
486
487
488/** 32 Bits control fields
489 * @{
490 */
491#define VMX_VMCS_CTRL_PIN_EXEC_CONTROLS 0x4000
492#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS 0x4002
493#define VMX_VMCS_CTRL_EXCEPTION_BITMAP 0x4004
494#define VMX_VMCS_CTRL_PAGEFAULT_ERROR_MASK 0x4006
495#define VMX_VMCS_CTRL_PAGEFAULT_ERROR_MATCH 0x4008
496#define VMX_VMCS_CTRL_CR3_TARGET_COUNT 0x400A
497#define VMX_VMCS_CTRL_EXIT_CONTROLS 0x400C
498#define VMX_VMCS_CTRL_EXIT_MSR_STORE_COUNT 0x400E
499#define VMX_VMCS_CTRL_EXIT_MSR_LOAD_COUNT 0x4010
500#define VMX_VMCS_CTRL_ENTRY_CONTROLS 0x4012
501#define VMX_VMCS_CTRL_ENTRY_MSR_LOAD_COUNT 0x4014
502#define VMX_VMCS_CTRL_ENTRY_IRQ_INFO 0x4016
503#define VMX_VMCS_CTRL_ENTRY_EXCEPTION_ERRCODE 0x4018
504#define VMX_VMCS_CTRL_ENTRY_INSTR_LENGTH 0x401A
505/** This field exists only on processors that support the 1-setting of the “use TPR shadow” VM-execution control. */
506#define VMX_VMCS_CTRL_TPR_THRESHOLD 0x401C
507/** This field exists only on processors that support the 1-setting of the “activate secondary controls” VM-execution control. */
508#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS2 0x401E
509/** @} */
510
511
512/** VMX_VMCS_CTRL_PIN_EXEC_CONTROLS
513 * @{
514 */
515/* External interrupts cause VM exits if set; otherwise dispatched through the guest's IDT. */
516#define VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_EXT_INT_EXIT RT_BIT(0)
517/* Non-maskable interrupts cause VM exits if set; otherwise dispatched through the guest's IDT. */
518#define VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_NMI_EXIT RT_BIT(3)
519/* All other bits are reserved and must be set according to MSR IA32_VMX_PROCBASED_CTLS. */
520/** @} */
521
522/** VMX_VMCS_CTRL_PROC_EXEC_CONTROLS
523 * @{
524 */
525/* VM Exit as soon as RFLAGS.IF=1 and no blocking is active. */
526#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_IRQ_WINDOW_EXIT RT_BIT(2)
527/* Use timestamp counter offset. */
528#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_TSC_OFFSET RT_BIT(3)
529/* VM Exit when executing the HLT instruction. */
530#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_HLT_EXIT RT_BIT(7)
531/* VM Exit when executing the INVLPG instruction. */
532#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_INVLPG_EXIT RT_BIT(9)
533/* VM Exit when executing the MWAIT instruction. */
534#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MWAIT_EXIT RT_BIT(10)
535/* VM Exit when executing the RDPMC instruction. */
536#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDPMC_EXIT RT_BIT(11)
537/* VM Exit when executing the RDTSC instruction. */
538#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT RT_BIT(12)
539/* VM Exit on CR8 loads. */
540#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_LOAD_EXIT RT_BIT(19)
541/* VM Exit on CR8 stores. */
542#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_STORE_EXIT RT_BIT(20)
543/* Use TPR shadow. */
544#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_TPR_SHADOW RT_BIT(21)
545/* VM Exit when executing a MOV DRx instruction. */
546#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MOV_DR_EXIT RT_BIT(23)
547/* VM Exit when executing IO instructions. */
548#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_UNCOND_IO_EXIT RT_BIT(24)
549/* Use IO bitmaps. */
550#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_IO_BITMAPS RT_BIT(25)
551/* Use MSR bitmaps. */
552#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_MSR_BITMAPS RT_BIT(28)
553/* VM Exit when executing the MONITOR instruction. */
554#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_EXIT RT_BIT(29)
555/* VM Exit when executing the PAUSE instruction. */
556#define VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_PAUSE_EXIT RT_BIT(30)
557/* Determines whether the secondary processor based VM-execution controls are used. */
558#define VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL RT_BIT(31)
559/** @} */
560
561/** VMX_VMCS_CTRL_PROC_EXEC_CONTROLS2
562 * @{
563 */
564/** Virtualize APIC access. */
565#define VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC RT_BIT(0)
566/** EPT supported/enabled. */
567#define VMX_VMCS_CTRL_PROC_EXEC2_EPT RT_BIT(1)
568/** VPID supported/enabled. */
569#define VMX_VMCS_CTRL_PROC_EXEC2_VPID RT_BIT(5)
570/** VM Exit when executing the WBINVD instruction. */
571#define VMX_VMCS_CTRL_PROC_EXEC2_WBINVD_EXIT RT_BIT(6)
572/** @} */
573
574
575/** VMX_VMCS_CTRL_ENTRY_CONTROLS
576 * @{
577 */
578/** 64 bits guest mode. Must be 0 for CPUs that don't support AMD64. */
579#define VMX_VMCS_CTRL_ENTRY_CONTROLS_IA64_MODE RT_BIT(9)
580/** In SMM mode after VM-entry. */
581#define VMX_VMCS_CTRL_ENTRY_CONTROLS_ENTRY_SMM RT_BIT(10)
582/** Disable dual treatment of SMI and SMM; must be zero for VM-entry outside of SMM. */
583#define VMX_VMCS_CTRL_ENTRY_CONTROLS_DEACTIVATE_DUALMON RT_BIT(11)
584/** @} */
585
586
587/** VMX_VMCS_CTRL_EXIT_CONTROLS
588 * @{
589 */
590/** Return to long mode after a VM-exit. */
591#define VMX_VMCS_CTRL_EXIT_CONTROLS_HOST_AMD64 RT_BIT(9)
592/** Acknowledge external interrupts with the irq controller if one caused a VM-exit. */
593#define VMX_VMCS_CTRL_EXIT_CONTROLS_ACK_EXTERNAL_IRQ RT_BIT(15)
594/** @} */
595
596/** 32 Bits read-only fields
597 * @{
598 */
599#define VMX_VMCS_RO_VM_INSTR_ERROR 0x4400
600#define VMX_VMCS_RO_EXIT_REASON 0x4402
601#define VMX_VMCS_RO_EXIT_INTERRUPTION_INFO 0x4404
602#define VMX_VMCS_RO_EXIT_INTERRUPTION_ERRCODE 0x4406
603#define VMX_VMCS_RO_IDT_INFO 0x4408
604#define VMX_VMCS_RO_IDT_ERRCODE 0x440A
605#define VMX_VMCS_RO_EXIT_INSTR_LENGTH 0x440C
606#define VMX_VMCS_RO_EXIT_INSTR_INFO 0x440E
607/** @} */
608
609/** VMX_VMCS_RO_EXIT_INTERRUPTION_INFO
610 * @{
611 */
612#define VMX_EXIT_INTERRUPTION_INFO_VECTOR(a) (a & 0xff)
613#define VMX_EXIT_INTERRUPTION_INFO_TYPE_SHIFT 8
614#define VMX_EXIT_INTERRUPTION_INFO_TYPE(a) ((a >> VMX_EXIT_INTERRUPTION_INFO_TYPE_SHIFT) & 7)
615#define VMX_EXIT_INTERRUPTION_INFO_ERROR_CODE_VALID RT_BIT(11)
616#define VMX_EXIT_INTERRUPTION_INFO_ERROR_CODE_IS_VALID(a) (a & VMX_EXIT_INTERRUPTION_INFO_ERROR_CODE_VALID)
617#define VMX_EXIT_INTERRUPTION_INFO_NMI_UNBLOCK(a) (a & RT_BIT(12))
618#define VMX_EXIT_INTERRUPTION_INFO_VALID_SHIFT 31
619#define VMX_EXIT_INTERRUPTION_INFO_VALID(a) (a & RT_BIT(31))
620/* Construct an irq event injection value from the exit interruption info value (same except that bit 12 is reserved). */
621#define VMX_VMCS_CTRL_ENTRY_IRQ_INFO_FROM_EXIT_INT_INFO(a) (a & ~RT_BIT(12))
622/** @} */
623
624/** VMX_VMCS_RO_EXIT_INTERRUPTION_INFO_TYPE
625 * @{
626 */
627#define VMX_EXIT_INTERRUPTION_INFO_TYPE_EXT 0
628#define VMX_EXIT_INTERRUPTION_INFO_TYPE_NMI 2
629#define VMX_EXIT_INTERRUPTION_INFO_TYPE_HWEXCPT 3
630#define VMX_EXIT_INTERRUPTION_INFO_TYPE_SW 4 /* int xx */
631#define VMX_EXIT_INTERRUPTION_INFO_TYPE_SWEXCPT 6
632/** @} */
633
634
635/** 32 Bits guest state fields
636 * @{
637 */
638#define VMX_VMCS_GUEST_ES_LIMIT 0x4800
639#define VMX_VMCS_GUEST_CS_LIMIT 0x4802
640#define VMX_VMCS_GUEST_SS_LIMIT 0x4804
641#define VMX_VMCS_GUEST_DS_LIMIT 0x4806
642#define VMX_VMCS_GUEST_FS_LIMIT 0x4808
643#define VMX_VMCS_GUEST_GS_LIMIT 0x480A
644#define VMX_VMCS_GUEST_LDTR_LIMIT 0x480C
645#define VMX_VMCS_GUEST_TR_LIMIT 0x480E
646#define VMX_VMCS_GUEST_GDTR_LIMIT 0x4810
647#define VMX_VMCS_GUEST_IDTR_LIMIT 0x4812
648#define VMX_VMCS_GUEST_ES_ACCESS_RIGHTS 0x4814
649#define VMX_VMCS_GUEST_CS_ACCESS_RIGHTS 0x4816
650#define VMX_VMCS_GUEST_SS_ACCESS_RIGHTS 0x4818
651#define VMX_VMCS_GUEST_DS_ACCESS_RIGHTS 0x481A
652#define VMX_VMCS_GUEST_FS_ACCESS_RIGHTS 0x481C
653#define VMX_VMCS_GUEST_GS_ACCESS_RIGHTS 0x481E
654#define VMX_VMCS_GUEST_LDTR_ACCESS_RIGHTS 0x4820
655#define VMX_VMCS_GUEST_TR_ACCESS_RIGHTS 0x4822
656#define VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE 0x4824
657#define VMX_VMCS_GUEST_ACTIVITY_STATE 0x4826
658#define VMX_VMCS_GUEST_SYSENTER_CS 0x482A /* MSR IA32_SYSENTER_CS */
659/** @} */
660
661
662/** VMX_VMCS_GUEST_ACTIVITY_STATE
663 * @{
664 */
665/* The logical processor is active. */
666#define VMX_CMS_GUEST_ACTIVITY_ACTIVE 0x0
667/* The logical processor is inactive, because executed a HLT instruction. */
668#define VMX_CMS_GUEST_ACTIVITY_HLT 0x1
669/* The logical processor is inactive, because of a triple fault or other serious error. */
670#define VMX_CMS_GUEST_ACTIVITY_SHUTDOWN 0x2
671/* The logical processor is inactive, because it's waiting for a startup-IPI */
672#define VMX_CMS_GUEST_ACTIVITY_SIPI_WAIT 0x3
673/** @} */
674
675
676/** VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE
677 * @{
678 */
679#define VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE_BLOCK_STI RT_BIT(0)
680#define VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE_BLOCK_MOVSS RT_BIT(1)
681#define VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE_BLOCK_SMI RT_BIT(2)
682#define VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE_BLOCK_NMI RT_BIT(3)
683/** @} */
684
685
686/** 32 Bits host state fields
687 * @{
688 */
689#define VMX_VMCS_HOST_SYSENTER_CS 0x4C00
690/** @} */
691
692/** Natural width control fields
693 * @{
694 */
695#define VMX_VMCS_CTRL_CR0_MASK 0x6000
696#define VMX_VMCS_CTRL_CR4_MASK 0x6002
697#define VMX_VMCS_CTRL_CR0_READ_SHADOW 0x6004
698#define VMX_VMCS_CTRL_CR4_READ_SHADOW 0x6006
699#define VMX_VMCS_CTRL_CR3_TARGET_VAL0 0x6008
700#define VMX_VMCS_CTRL_CR3_TARGET_VAL1 0x600A
701#define VMX_VMCS_CTRL_CR3_TARGET_VAL2 0x600C
702#define VMX_VMCS_CTRL_CR3_TARGET_VAL31 0x600E
703/** @} */
704
705
706/** Natural width read-only data fields
707 * @{
708 */
709#define VMX_VMCS_RO_EXIT_QUALIFICATION 0x6400
710#define VMX_VMCS_RO_IO_RCX 0x6402
711#define VMX_VMCS_RO_IO_RSX 0x6404
712#define VMX_VMCS_RO_IO_RDI 0x6406
713#define VMX_VMCS_RO_IO_RIP 0x6408
714#define VMX_VMCS_EXIT_GUEST_LINEAR_ADDR 0x640A
715/** @} */
716
717
718/** VMX_VMCS_RO_EXIT_QUALIFICATION
719 * @{
720 */
721
722/** DRx moves
723 * @{
724 */
725/** 0-2: Debug register number */
726#define VMX_EXIT_QUALIFICATION_DRX_REGISTER(a) (a & 7)
727/** 3: Reserved; cleared to 0. */
728#define VMX_EXIT_QUALIFICATION_DRX_RES1(a) ((a >> 3) & 1)
729/** 4: Direction of move (0 = write, 1 = read) */
730#define VMX_EXIT_QUALIFICATION_DRX_DIRECTION(a) ((a >> 4) & 1)
731/** 5-7: Reserved; cleared to 0. */
732#define VMX_EXIT_QUALIFICATION_DRX_RES2(a) ((a >> 5) & 7)
733/** 8-11: General purpose register number. */
734#define VMX_EXIT_QUALIFICATION_DRX_GENREG(a) ((a >> 8) & 0xF)
735/** Rest: reserved. */
736
737/** VMX_EXIT_QUALIFICATION_DRX_DIRECTION
738 * @{
739 */
740#define VMX_EXIT_QUALIFICATION_DRX_DIRECTION_WRITE 0
741#define VMX_EXIT_QUALIFICATION_DRX_DIRECTION_READ 1
742/** @} */
743
744/** @} */
745
746
747/** CRx accesses
748 * @{
749 */
750/** 0-3: Control register number (0 for CLTS & LMSW) */
751#define VMX_EXIT_QUALIFICATION_CRX_REGISTER(a) (a & 0xF)
752/** 4-5: Access type. */
753#define VMX_EXIT_QUALIFICATION_CRX_ACCESS(a) ((a >> 4) & 3)
754/** 6: LMSW operand type */
755#define VMX_EXIT_QUALIFICATION_CRX_LMSW_OP(a) ((a >> 6) & 1)
756/** 7: Reserved; cleared to 0. */
757#define VMX_EXIT_QUALIFICATION_CRX_RES1(a) ((a >> 7) & 1)
758/** 8-11: General purpose register number (0 for CLTS & LMSW). */
759#define VMX_EXIT_QUALIFICATION_CRX_GENREG(a) ((a >> 8) & 0xF)
760/** 12-15: Reserved; cleared to 0. */
761#define VMX_EXIT_QUALIFICATION_CRX_RES2(a) ((a >> 12) & 0xF)
762/** 16-31: LMSW source data (else 0). */
763#define VMX_EXIT_QUALIFICATION_CRX_LMSW_DATA(a) ((a >> 16) & 0xFFFF)
764/** Rest: reserved. */
765
766
767/** VMX_EXIT_QUALIFICATION_CRX_ACCESS
768 * @{
769 */
770#define VMX_EXIT_QUALIFICATION_CRX_ACCESS_WRITE 0
771#define VMX_EXIT_QUALIFICATION_CRX_ACCESS_READ 1
772#define VMX_EXIT_QUALIFICATION_CRX_ACCESS_CLTS 2
773#define VMX_EXIT_QUALIFICATION_CRX_ACCESS_LMSW 3
774/** @} */
775
776/** @} */
777
778
779/** VMX_EXIT_PORT_IO
780 * @{
781 */
782/** 0-2: IO operation width. */
783#define VMX_EXIT_QUALIFICATION_IO_WIDTH(a) (a & 7)
784/** 3: IO operation direction. */
785#define VMX_EXIT_QUALIFICATION_IO_DIRECTION(a) ((a >> 3) & 1)
786/** 4: String IO operation. */
787#define VMX_EXIT_QUALIFICATION_IO_STRING(a) ((a >> 4) & 1)
788/** 5: Repeated IO operation. */
789#define VMX_EXIT_QUALIFICATION_IO_REP(a) ((a >> 5) & 1)
790/** 6: Operand encoding. */
791#define VMX_EXIT_QUALIFICATION_IO_ENCODING(a) ((a >> 6) & 1)
792/** 16-31: IO Port (0-0xffff). */
793#define VMX_EXIT_QUALIFICATION_IO_PORT(a) ((a >> 16) & 0xffff)
794/* Rest reserved. */
795/** @} */
796
797/** VMX_EXIT_QUALIFICATION_IO_DIRECTION
798 * @{
799 */
800#define VMX_EXIT_QUALIFICATION_IO_DIRECTION_OUT 0
801#define VMX_EXIT_QUALIFICATION_IO_DIRECTION_IN 1
802/** @} */
803
804
805/** VMX_EXIT_QUALIFICATION_IO_ENCODING
806 * @{
807 */
808#define VMX_EXIT_QUALIFICATION_IO_ENCODING_DX 0
809#define VMX_EXIT_QUALIFICATION_IO_ENCODING_IMM 1
810/** @} */
811
812/** @} */
813
814/** Natural width guest state fields
815 * @{
816 */
817#define VMX_VMCS_GUEST_CR0 0x6800
818#define VMX_VMCS_GUEST_CR3 0x6802
819#define VMX_VMCS_GUEST_CR4 0x6804
820#define VMX_VMCS_GUEST_ES_BASE 0x6806
821#define VMX_VMCS_GUEST_CS_BASE 0x6808
822#define VMX_VMCS_GUEST_SS_BASE 0x680A
823#define VMX_VMCS_GUEST_DS_BASE 0x680C
824#define VMX_VMCS_GUEST_FS_BASE 0x680E
825#define VMX_VMCS_GUEST_GS_BASE 0x6810
826#define VMX_VMCS_GUEST_LDTR_BASE 0x6812
827#define VMX_VMCS_GUEST_TR_BASE 0x6814
828#define VMX_VMCS_GUEST_GDTR_BASE 0x6816
829#define VMX_VMCS_GUEST_IDTR_BASE 0x6818
830#define VMX_VMCS_GUEST_DR7 0x681A
831#define VMX_VMCS_GUEST_RSP 0x681C
832#define VMX_VMCS_GUEST_RIP 0x681E
833#define VMX_VMCS_GUEST_RFLAGS 0x6820
834#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS 0x6822
835#define VMX_VMCS_GUEST_SYSENTER_ESP 0x6824 /* MSR IA32_SYSENTER_ESP */
836#define VMX_VMCS_GUEST_SYSENTER_EIP 0x6826 /* MSR IA32_SYSENTER_EIP */
837/** @} */
838
839
840/** VMX_VMCS_GUEST_DEBUG_EXCEPTIONS
841 * @{
842 */
843/* Hardware breakpoint 0 was met. */
844#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_B0 RT_BIT(0)
845/* Hardware breakpoint 1 was met. */
846#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_B1 RT_BIT(1)
847/* Hardware breakpoint 2 was met. */
848#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_B2 RT_BIT(2)
849/* Hardware breakpoint 3 was met. */
850#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_B3 RT_BIT(3)
851/* At least one data or IO breakpoint was hit. */
852#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_BREAKPOINT_ENABLED RT_BIT(12)
853/* A debug exception would have been triggered by single-step execution mode. */
854#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_BS RT_BIT(14)
855/* Bits 4-11, 13 and 15-63 are reserved. */
856
857
858
859
860/** @} */
861
862/** Natural width host state fields
863 * @{
864 */
865#define VMX_VMCS_HOST_CR0 0x6C00
866#define VMX_VMCS_HOST_CR3 0x6C02
867#define VMX_VMCS_HOST_CR4 0x6C04
868#define VMX_VMCS_HOST_FS_BASE 0x6C06
869#define VMX_VMCS_HOST_GS_BASE 0x6C08
870#define VMX_VMCS_HOST_TR_BASE 0x6C0A
871#define VMX_VMCS_HOST_GDTR_BASE 0x6C0C
872#define VMX_VMCS_HOST_IDTR_BASE 0x6C0E
873#define VMX_VMCS_HOST_SYSENTER_ESP 0x6C10
874#define VMX_VMCS_HOST_SYSENTER_EIP 0x6C12
875#define VMX_VMCS_HOST_RSP 0x6C14
876#define VMX_VMCS_HOST_RIP 0x6C16
877/** @} */
878
879/** @} */
880
881
882#if RT_INLINE_ASM_GNU_STYLE
883# define __STR(x) #x
884# define STR(x) __STR(x)
885#endif
886
887
888/** @} */
889
890/** @defgroup grp_vmx_asm vmx assembly helpers
891 * @ingroup grp_vmx
892 * @{
893 */
894
895/**
896 * Executes VMXON
897 *
898 * @returns VBox status code
899 * @param pVMXOn Physical address of VMXON structure
900 */
901#if RT_INLINE_ASM_EXTERNAL || HC_ARCH_BITS == 64
902DECLASM(int) VMXEnable(RTHCPHYS pVMXOn);
903#else
904DECLINLINE(int) VMXEnable(RTHCPHYS pVMXOn)
905{
906 int rc = VINF_SUCCESS;
907# if RT_INLINE_ASM_GNU_STYLE
908 __asm__ __volatile__ (
909 "push %3 \n\t"
910 "push %2 \n\t"
911 ".byte 0xF3, 0x0F, 0xC7, 0x34, 0x24 # VMXON [esp] \n\t"
912 "ja 2f \n\t"
913 "je 1f \n\t"
914 "movl $"STR(VERR_VMX_INVALID_VMXON_PTR)", %0 \n\t"
915 "jmp 2f \n\t"
916 "1: \n\t"
917 "movl $"STR(VERR_VMX_GENERIC)", %0 \n\t"
918 "2: \n\t"
919 "add $8, %%esp \n\t"
920 :"=rm"(rc)
921 :"0"(VINF_SUCCESS),
922 "ir"((uint32_t)pVMXOn), /* don't allow direct memory reference here, */
923 "ir"((uint32_t)(pVMXOn >> 32)) /* this would not work with -fomit-frame-pointer */
924 :"memory"
925 );
926# else
927 __asm
928 {
929 push dword ptr [pVMXOn+4]
930 push dword ptr [pVMXOn]
931 _emit 0xF3
932 _emit 0x0F
933 _emit 0xC7
934 _emit 0x34
935 _emit 0x24 /* VMXON [esp] */
936 jnc vmxon_good
937 mov dword ptr [rc], VERR_VMX_INVALID_VMXON_PTR
938 jmp the_end
939
940vmxon_good:
941 jnz the_end
942 mov dword ptr [rc], VERR_VMX_GENERIC
943the_end:
944 add esp, 8
945 }
946# endif
947 return rc;
948}
949#endif
950
951
952/**
953 * Executes VMXOFF
954 */
955#if RT_INLINE_ASM_EXTERNAL || HC_ARCH_BITS == 64
956DECLASM(void) VMXDisable(void);
957#else
958DECLINLINE(void) VMXDisable(void)
959{
960# if RT_INLINE_ASM_GNU_STYLE
961 __asm__ __volatile__ (
962 ".byte 0x0F, 0x01, 0xC4 # VMXOFF \n\t"
963 );
964# else
965 __asm
966 {
967 _emit 0x0F
968 _emit 0x01
969 _emit 0xC4 /* VMXOFF */
970 }
971# endif
972}
973#endif
974
975
976/**
977 * Executes VMCLEAR
978 *
979 * @returns VBox status code
980 * @param pVMCS Physical address of VM control structure
981 */
982#if RT_INLINE_ASM_EXTERNAL || HC_ARCH_BITS == 64
983DECLASM(int) VMXClearVMCS(RTHCPHYS pVMCS);
984#else
985DECLINLINE(int) VMXClearVMCS(RTHCPHYS pVMCS)
986{
987 int rc = VINF_SUCCESS;
988# if RT_INLINE_ASM_GNU_STYLE
989 __asm__ __volatile__ (
990 "push %3 \n\t"
991 "push %2 \n\t"
992 ".byte 0x66, 0x0F, 0xC7, 0x34, 0x24 # VMCLEAR [esp] \n\t"
993 "jnc 1f \n\t"
994 "movl $"STR(VERR_VMX_INVALID_VMCS_PTR)", %0 \n\t"
995 "1: \n\t"
996 "add $8, %%esp \n\t"
997 :"=rm"(rc)
998 :"0"(VINF_SUCCESS),
999 "ir"((uint32_t)pVMCS), /* don't allow direct memory reference here, */
1000 "ir"((uint32_t)(pVMCS >> 32)) /* this would not work with -fomit-frame-pointer */
1001 :"memory"
1002 );
1003# else
1004 __asm
1005 {
1006 push dword ptr [pVMCS+4]
1007 push dword ptr [pVMCS]
1008 _emit 0x66
1009 _emit 0x0F
1010 _emit 0xC7
1011 _emit 0x34
1012 _emit 0x24 /* VMCLEAR [esp] */
1013 jnc success
1014 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
1015success:
1016 add esp, 8
1017 }
1018# endif
1019 return rc;
1020}
1021#endif
1022
1023
1024/**
1025 * Executes VMPTRLD
1026 *
1027 * @returns VBox status code
1028 * @param pVMCS Physical address of VMCS structure
1029 */
1030#if RT_INLINE_ASM_EXTERNAL || HC_ARCH_BITS == 64
1031DECLASM(int) VMXActivateVMCS(RTHCPHYS pVMCS);
1032#else
1033DECLINLINE(int) VMXActivateVMCS(RTHCPHYS pVMCS)
1034{
1035 int rc = VINF_SUCCESS;
1036# if RT_INLINE_ASM_GNU_STYLE
1037 __asm__ __volatile__ (
1038 "push %3 \n\t"
1039 "push %2 \n\t"
1040 ".byte 0x0F, 0xC7, 0x34, 0x24 # VMPTRLD [esp] \n\t"
1041 "jnc 1f \n\t"
1042 "movl $"STR(VERR_VMX_INVALID_VMCS_PTR)", %0 \n\t"
1043 "1: \n\t"
1044 "add $8, %%esp \n\t"
1045 :"=rm"(rc)
1046 :"0"(VINF_SUCCESS),
1047 "ir"((uint32_t)pVMCS), /* don't allow direct memory reference here, */
1048 "ir"((uint32_t)(pVMCS >> 32)) /* this will not work with -fomit-frame-pointer */
1049 );
1050# else
1051 __asm
1052 {
1053 push dword ptr [pVMCS+4]
1054 push dword ptr [pVMCS]
1055 _emit 0x0F
1056 _emit 0xC7
1057 _emit 0x34
1058 _emit 0x24 /* VMPTRLD [esp] */
1059 jnc success
1060 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
1061
1062success:
1063 add esp, 8
1064 }
1065# endif
1066 return rc;
1067}
1068#endif
1069
1070
1071/**
1072 * Executes VMWRITE
1073 *
1074 * @returns VBox status code
1075 * @param idxField VMCS index
1076 * @param u64Val 16, 32 or 64 bits value
1077 */
1078DECLASM(int) VMXWriteVMCS64(uint32_t idxField, uint64_t u64Val);
1079
1080/**
1081 * Executes VMWRITE
1082 *
1083 * @returns VBox status code
1084 * @param idxField VMCS index
1085 * @param u32Val 32 bits value
1086 */
1087#if RT_INLINE_ASM_EXTERNAL || HC_ARCH_BITS == 64
1088DECLASM(int) VMXWriteVMCS32(uint32_t idxField, uint32_t u32Val);
1089#else
1090DECLINLINE(int) VMXWriteVMCS32(uint32_t idxField, uint32_t u32Val)
1091{
1092 int rc = VINF_SUCCESS;
1093# if RT_INLINE_ASM_GNU_STYLE
1094 __asm__ __volatile__ (
1095 ".byte 0x0F, 0x79, 0xC2 # VMWRITE eax, edx \n\t"
1096 "ja 2f \n\t"
1097 "je 1f \n\t"
1098 "movl $"STR(VERR_VMX_INVALID_VMCS_PTR)", %0 \n\t"
1099 "jmp 2f \n\t"
1100 "1: \n\t"
1101 "movl $"STR(VERR_VMX_INVALID_VMCS_FIELD)", %0 \n\t"
1102 "2: \n\t"
1103 :"=rm"(rc)
1104 :"0"(VINF_SUCCESS),
1105 "a"(idxField),
1106 "d"(u32Val)
1107 );
1108# else
1109 __asm
1110 {
1111 push dword ptr [u32Val]
1112 mov eax, [idxField]
1113 _emit 0x0F
1114 _emit 0x79
1115 _emit 0x04
1116 _emit 0x24 /* VMWRITE eax, [esp] */
1117 jnc valid_vmcs
1118 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
1119 jmp the_end
1120
1121valid_vmcs:
1122 jnz the_end
1123 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_FIELD
1124the_end:
1125 add esp, 4
1126 }
1127# endif
1128 return rc;
1129}
1130#endif
1131
1132#if HC_ARCH_BITS == 64
1133#define VMXWriteVMCS VMXWriteVMCS64
1134#else
1135#define VMXWriteVMCS VMXWriteVMCS32
1136#endif /* HC_ARCH_BITS == 64 */
1137
1138
1139/**
1140 * Executes VMREAD
1141 *
1142 * @returns VBox status code
1143 * @param idxField VMCS index
1144 * @param pData Ptr to store VM field value
1145 */
1146DECLASM(int) VMXReadVMCS64(uint32_t idxField, uint64_t *pData);
1147
1148/**
1149 * Executes VMREAD
1150 *
1151 * @returns VBox status code
1152 * @param idxField VMCS index
1153 * @param pData Ptr to store VM field value
1154 */
1155#if RT_INLINE_ASM_EXTERNAL || HC_ARCH_BITS == 64
1156DECLASM(int) VMXReadVMCS32(uint32_t idxField, uint32_t *pData);
1157#else
1158DECLINLINE(int) VMXReadVMCS32(uint32_t idxField, uint32_t *pData)
1159{
1160 int rc = VINF_SUCCESS;
1161# if RT_INLINE_ASM_GNU_STYLE
1162 __asm__ __volatile__ (
1163 "movl $"STR(VINF_SUCCESS)", %0 \n\t"
1164 ".byte 0x0F, 0x78, 0xc2 # VMREAD eax, edx \n\t"
1165 "ja 2f \n\t"
1166 "je 1f \n\t"
1167 "movl $"STR(VERR_VMX_INVALID_VMCS_PTR)", %0 \n\t"
1168 "jmp 2f \n\t"
1169 "1: \n\t"
1170 "movl $"STR(VERR_VMX_INVALID_VMCS_FIELD)", %0 \n\t"
1171 "2: \n\t"
1172 :"=&r"(rc),
1173 "=d"(*pData)
1174 :"a"(idxField),
1175 "d"(0)
1176 );
1177# else
1178 __asm
1179 {
1180 sub esp, 4
1181 mov dword ptr [esp], 0
1182 mov eax, [idxField]
1183 _emit 0x0F
1184 _emit 0x78
1185 _emit 0x04
1186 _emit 0x24 /* VMREAD eax, [esp] */
1187 mov edx, pData
1188 pop dword ptr [edx]
1189 jnc valid_vmcs
1190 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
1191 jmp the_end
1192
1193valid_vmcs:
1194 jnz the_end
1195 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_FIELD
1196the_end:
1197 }
1198# endif
1199 return rc;
1200}
1201#endif
1202
1203#if HC_ARCH_BITS == 64
1204#define VMXReadVMCS VMXReadVMCS64
1205#else
1206#define VMXReadVMCS VMXReadVMCS32
1207#endif /* HC_ARCH_BITS == 64 */
1208
1209/**
1210 * Gets the last instruction error value from the current VMCS
1211 *
1212 * @returns error value
1213 */
1214DECLINLINE(uint32_t) VMXGetLastError(void)
1215{
1216#if HC_ARCH_BITS == 64
1217 uint64_t uLastError = 0;
1218 int rc = VMXReadVMCS(VMX_VMCS_RO_VM_INSTR_ERROR, &uLastError);
1219 AssertRC(rc);
1220 return (uint32_t)uLastError;
1221
1222#else /* 32-bit host: */
1223 uint32_t lasterr = 0;
1224 int rc;
1225
1226 rc = VMXReadVMCS32(VMX_VMCS_RO_VM_INSTR_ERROR, &lasterr);
1227 AssertRC(rc);
1228 return lasterr;
1229#endif
1230}
1231
1232/** @} */
1233
1234#endif
1235
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette