VirtualBox

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

Last change on this file since 10817 was 10817, checked in by vboxsync, 17 years ago

Started with EPT support.

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

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