1 | /* $Id: HWVMXR0.h 14366 2008-11-19 17:20:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * HWACCM VT-x - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ___HWVMXR0_h
|
---|
23 | #define ___HWVMXR0_h
|
---|
24 |
|
---|
25 | #include <VBox/cdefs.h>
|
---|
26 | #include <VBox/types.h>
|
---|
27 | #include <VBox/em.h>
|
---|
28 | #include <VBox/stam.h>
|
---|
29 | #include <VBox/dis.h>
|
---|
30 | #include <VBox/hwaccm.h>
|
---|
31 | #include <VBox/pgm.h>
|
---|
32 | #include <VBox/hwacc_vmx.h>
|
---|
33 |
|
---|
34 | __BEGIN_DECLS
|
---|
35 |
|
---|
36 | /** @defgroup grp_vmx_int Internal
|
---|
37 | * @ingroup grp_vmx
|
---|
38 | * @internal
|
---|
39 | * @{
|
---|
40 | */
|
---|
41 |
|
---|
42 | #ifdef IN_RING0
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Enters the VT-x session
|
---|
46 | *
|
---|
47 | * @returns VBox status code.
|
---|
48 | * @param pVM The VM to operate on.
|
---|
49 | * @param pVCpu The VMCPU to operate on.
|
---|
50 | * @param pCpu CPU info struct
|
---|
51 | */
|
---|
52 | VMMR0DECL(int) VMXR0Enter(PVM pVM, PVMCPU pVCpu, PHWACCM_CPUINFO pCpu);
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Leaves the VT-x session
|
---|
56 | *
|
---|
57 | * @returns VBox status code.
|
---|
58 | * @param pVM The VM to operate on.
|
---|
59 | * @param pVCpu The VMCPU to operate on.
|
---|
60 | * @param pCtx CPU context
|
---|
61 | */
|
---|
62 | VMMR0DECL(int) VMXR0Leave(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Sets up and activates VT-x on the current CPU
|
---|
67 | *
|
---|
68 | * @returns VBox status code.
|
---|
69 | * @param pCpu CPU info struct
|
---|
70 | * @param pVM The VM to operate on. (can be NULL after a resume)
|
---|
71 | * @param pvPageCpu Pointer to the global cpu page
|
---|
72 | * @param pPageCpuPhys Physical address of the global cpu page
|
---|
73 | */
|
---|
74 | VMMR0DECL(int) VMXR0EnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Deactivates VT-x on the current CPU
|
---|
78 | *
|
---|
79 | * @returns VBox status code.
|
---|
80 | * @param pCpu CPU info struct
|
---|
81 | * @param pvPageCpu Pointer to the global cpu page
|
---|
82 | * @param pPageCpuPhys Physical address of the global cpu page
|
---|
83 | */
|
---|
84 | VMMR0DECL(int) VMXR0DisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Does Ring-0 per VM VT-x init.
|
---|
88 | *
|
---|
89 | * @returns VBox status code.
|
---|
90 | * @param pVM The VM to operate on.
|
---|
91 | */
|
---|
92 | VMMR0DECL(int) VMXR0InitVM(PVM pVM);
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Does Ring-0 per VM VT-x termination.
|
---|
96 | *
|
---|
97 | * @returns VBox status code.
|
---|
98 | * @param pVM The VM to operate on.
|
---|
99 | */
|
---|
100 | VMMR0DECL(int) VMXR0TermVM(PVM pVM);
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Sets up VT-x for the specified VM
|
---|
104 | *
|
---|
105 | * @returns VBox status code.
|
---|
106 | * @param pVM The VM to operate on.
|
---|
107 | */
|
---|
108 | VMMR0DECL(int) VMXR0SetupVM(PVM pVM);
|
---|
109 |
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Save the host state
|
---|
113 | *
|
---|
114 | * @returns VBox status code.
|
---|
115 | * @param pVM The VM to operate on.
|
---|
116 | * @param pVCpu The VMCPU to operate on.
|
---|
117 | */
|
---|
118 | VMMR0DECL(int) VMXR0SaveHostState(PVM pVM, PVMCPU pVCpu);
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Loads the guest state
|
---|
122 | *
|
---|
123 | * @returns VBox status code.
|
---|
124 | * @param pVM The VM to operate on.
|
---|
125 | * @param pVCpu The VMCPU to operate on.
|
---|
126 | * @param pCtx Guest context
|
---|
127 | */
|
---|
128 | VMMR0DECL(int) VMXR0LoadGuestState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
|
---|
129 |
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Runs guest code in a VT-x VM.
|
---|
133 | *
|
---|
134 | * @returns VBox status code.
|
---|
135 | * @param pVM The VM to operate on.
|
---|
136 | * @param pVCpu The VMCPU to operate on.
|
---|
137 | * @param pCtx Guest context
|
---|
138 | */
|
---|
139 | VMMR0DECL(int) VMXR0RunGuestCode(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
|
---|
140 |
|
---|
141 |
|
---|
142 | #define VMX_WRITE_SELREG(REG, reg) \
|
---|
143 | { \
|
---|
144 | rc = VMXWriteVMCS(VMX_VMCS_GUEST_FIELD_##REG, pCtx->reg); \
|
---|
145 | rc |= VMXWriteVMCS(VMX_VMCS_GUEST_##REG##_LIMIT, pCtx->reg##Hid.u32Limit); \
|
---|
146 | rc |= VMXWriteVMCS(VMX_VMCS_GUEST_##REG##_BASE, pCtx->reg##Hid.u64Base); \
|
---|
147 | if ((pCtx->eflags.u32 & X86_EFL_VM)) \
|
---|
148 | val = pCtx->reg##Hid.Attr.u; \
|
---|
149 | else \
|
---|
150 | if (CPUMIsGuestInRealModeEx(pCtx)) \
|
---|
151 | { \
|
---|
152 | /* Must override this or else VT-x will fail with invalid guest state errors. */ \
|
---|
153 | /* DPL=3, present, code/data, r/w/accessed. */ \
|
---|
154 | val = 0xf3; \
|
---|
155 | } \
|
---|
156 | else \
|
---|
157 | if ( ((!pCtx->csHid.Attr.n.u1DefBig && !CPUMIsGuestIn64BitCodeEx(pCtx)) || pCtx->reg) \
|
---|
158 | && pCtx->reg##Hid.Attr.n.u1Present == 1) \
|
---|
159 | val = pCtx->reg##Hid.Attr.u | X86_SEL_TYPE_ACCESSED; \
|
---|
160 | else \
|
---|
161 | val = 0x10000; /* Invalid guest state error otherwise. (BIT(16) = Unusable) */ \
|
---|
162 | \
|
---|
163 | rc |= VMXWriteVMCS(VMX_VMCS_GUEST_##REG##_ACCESS_RIGHTS, val); \
|
---|
164 | }
|
---|
165 |
|
---|
166 | #define VMX_READ_SELREG(REG, reg) \
|
---|
167 | { \
|
---|
168 | VMXReadVMCS(VMX_VMCS_GUEST_FIELD_##REG, &val); \
|
---|
169 | pCtx->reg = val; \
|
---|
170 | VMXReadVMCS(VMX_VMCS_GUEST_##REG##_LIMIT, &val); \
|
---|
171 | pCtx->reg##Hid.u32Limit = val; \
|
---|
172 | VMXReadVMCS(VMX_VMCS_GUEST_##REG##_BASE, &val); \
|
---|
173 | pCtx->reg##Hid.u64Base = val; \
|
---|
174 | VMXReadVMCS(VMX_VMCS_GUEST_##REG##_ACCESS_RIGHTS, &val); \
|
---|
175 | pCtx->reg##Hid.Attr.u = val; \
|
---|
176 | }
|
---|
177 |
|
---|
178 | #define VMX_LOG_SELREG(REG, szSelReg) \
|
---|
179 | { \
|
---|
180 | VMXReadVMCS(VMX_VMCS_GUEST_FIELD_##REG, &val); \
|
---|
181 | Log(("%s Selector %x\n", szSelReg, val)); \
|
---|
182 | VMXReadVMCS(VMX_VMCS_GUEST_##REG##_LIMIT, &val); \
|
---|
183 | Log(("%s Limit %x\n", szSelReg, val)); \
|
---|
184 | VMXReadVMCS(VMX_VMCS_GUEST_##REG##_BASE, &val); \
|
---|
185 | Log(("%s Base %RX64\n", szSelReg, val)); \
|
---|
186 | VMXReadVMCS(VMX_VMCS_GUEST_##REG##_ACCESS_RIGHTS, &val); \
|
---|
187 | Log(("%s Attributes %x\n", szSelReg, val)); \
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * Prepares for and executes VMLAUNCH (32 bits guest mode)
|
---|
194 | *
|
---|
195 | * @returns VBox status code
|
---|
196 | * @param fResume vmlauch/vmresume
|
---|
197 | * @param pCtx Guest context
|
---|
198 | */
|
---|
199 | DECLASM(int) VMXR0StartVM32(RTHCUINT fResume, PCPUMCTX pCtx);
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Prepares for and executes VMLAUNCH (64 bits guest mode)
|
---|
203 | *
|
---|
204 | * @returns VBox status code
|
---|
205 | * @param fResume vmlauch/vmresume
|
---|
206 | * @param pCtx Guest context
|
---|
207 | */
|
---|
208 | DECLASM(int) VMXR0StartVM64(RTHCUINT fResume, PCPUMCTX pCtx);
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Prepares for and executes VMLAUNCH (64 bits guest mode)
|
---|
212 | *
|
---|
213 | * @returns VBox status code
|
---|
214 | * @param fResume vmlauch/vmresume
|
---|
215 | * @param pCtx Guest context
|
---|
216 | */
|
---|
217 | DECLASM(int) VMXR0SwitcherStartVM64(RTHCUINT fResume, PCPUMCTX pCtx);
|
---|
218 |
|
---|
219 | #endif /* IN_RING0 */
|
---|
220 |
|
---|
221 | /** @} */
|
---|
222 |
|
---|
223 | __END_DECLS
|
---|
224 |
|
---|
225 | #endif
|
---|
226 |
|
---|