VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR0/HWVMXR0.h@ 28879

Last change on this file since 28879 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.2 KB
Line 
1/* $Id: HWVMXR0.h 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * HWACCM VT-x - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
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
18#ifndef ___HWVMXR0_h
19#define ___HWVMXR0_h
20
21#include <VBox/cdefs.h>
22#include <VBox/types.h>
23#include <VBox/em.h>
24#include <VBox/stam.h>
25#include <VBox/dis.h>
26#include <VBox/hwaccm.h>
27#include <VBox/pgm.h>
28#include <VBox/hwacc_vmx.h>
29
30RT_C_DECLS_BEGIN
31
32/** @defgroup grp_vmx_int Internal
33 * @ingroup grp_vmx
34 * @internal
35 * @{
36 */
37
38/* Read cache indices. */
39#define VMX_VMCS64_GUEST_RIP_CACHE_IDX 0
40#define VMX_VMCS64_GUEST_RSP_CACHE_IDX 1
41#define VMX_VMCS_GUEST_RFLAGS_CACHE_IDX 2
42#define VMX_VMCS32_GUEST_INTERRUPTIBILITY_STATE_CACHE_IDX 3
43#define VMX_VMCS_CTRL_CR0_READ_SHADOW_CACHE_IDX 4
44#define VMX_VMCS64_GUEST_CR0_CACHE_IDX 5
45#define VMX_VMCS_CTRL_CR4_READ_SHADOW_CACHE_IDX 6
46#define VMX_VMCS64_GUEST_CR4_CACHE_IDX 7
47#define VMX_VMCS64_GUEST_DR7_CACHE_IDX 8
48#define VMX_VMCS32_GUEST_SYSENTER_CS_CACHE_IDX 9
49#define VMX_VMCS64_GUEST_SYSENTER_EIP_CACHE_IDX 10
50#define VMX_VMCS64_GUEST_SYSENTER_ESP_CACHE_IDX 11
51#define VMX_VMCS32_GUEST_GDTR_LIMIT_CACHE_IDX 12
52#define VMX_VMCS64_GUEST_GDTR_BASE_CACHE_IDX 13
53#define VMX_VMCS32_GUEST_IDTR_LIMIT_CACHE_IDX 14
54#define VMX_VMCS64_GUEST_IDTR_BASE_CACHE_IDX 15
55#define VMX_VMCS16_GUEST_FIELD_CS_CACHE_IDX 16
56#define VMX_VMCS32_GUEST_CS_LIMIT_CACHE_IDX 17
57#define VMX_VMCS64_GUEST_CS_BASE_CACHE_IDX 18
58#define VMX_VMCS32_GUEST_CS_ACCESS_RIGHTS_CACHE_IDX 19
59#define VMX_VMCS16_GUEST_FIELD_DS_CACHE_IDX 20
60#define VMX_VMCS32_GUEST_DS_LIMIT_CACHE_IDX 21
61#define VMX_VMCS64_GUEST_DS_BASE_CACHE_IDX 22
62#define VMX_VMCS32_GUEST_DS_ACCESS_RIGHTS_CACHE_IDX 23
63#define VMX_VMCS16_GUEST_FIELD_ES_CACHE_IDX 24
64#define VMX_VMCS32_GUEST_ES_LIMIT_CACHE_IDX 25
65#define VMX_VMCS64_GUEST_ES_BASE_CACHE_IDX 26
66#define VMX_VMCS32_GUEST_ES_ACCESS_RIGHTS_CACHE_IDX 27
67#define VMX_VMCS16_GUEST_FIELD_FS_CACHE_IDX 28
68#define VMX_VMCS32_GUEST_FS_LIMIT_CACHE_IDX 29
69#define VMX_VMCS64_GUEST_FS_BASE_CACHE_IDX 30
70#define VMX_VMCS32_GUEST_FS_ACCESS_RIGHTS_CACHE_IDX 31
71#define VMX_VMCS16_GUEST_FIELD_GS_CACHE_IDX 32
72#define VMX_VMCS32_GUEST_GS_LIMIT_CACHE_IDX 33
73#define VMX_VMCS64_GUEST_GS_BASE_CACHE_IDX 34
74#define VMX_VMCS32_GUEST_GS_ACCESS_RIGHTS_CACHE_IDX 35
75#define VMX_VMCS16_GUEST_FIELD_SS_CACHE_IDX 36
76#define VMX_VMCS32_GUEST_SS_LIMIT_CACHE_IDX 37
77#define VMX_VMCS64_GUEST_SS_BASE_CACHE_IDX 38
78#define VMX_VMCS32_GUEST_SS_ACCESS_RIGHTS_CACHE_IDX 39
79#define VMX_VMCS16_GUEST_FIELD_TR_CACHE_IDX 40
80#define VMX_VMCS32_GUEST_TR_LIMIT_CACHE_IDX 41
81#define VMX_VMCS64_GUEST_TR_BASE_CACHE_IDX 42
82#define VMX_VMCS32_GUEST_TR_ACCESS_RIGHTS_CACHE_IDX 43
83#define VMX_VMCS16_GUEST_FIELD_LDTR_CACHE_IDX 44
84#define VMX_VMCS32_GUEST_LDTR_LIMIT_CACHE_IDX 45
85#define VMX_VMCS64_GUEST_LDTR_BASE_CACHE_IDX 46
86#define VMX_VMCS32_GUEST_LDTR_ACCESS_RIGHTS_CACHE_IDX 47
87#define VMX_VMCS32_RO_EXIT_REASON_CACHE_IDX 48
88#define VMX_VMCS32_RO_VM_INSTR_ERROR_CACHE_IDX 49
89#define VMX_VMCS32_RO_EXIT_INSTR_LENGTH_CACHE_IDX 50
90#define VMX_VMCS32_RO_EXIT_INTERRUPTION_ERRCODE_CACHE_IDX 51
91#define VMX_VMCS32_RO_EXIT_INSTR_INFO_CACHE_IDX 52
92#define VMX_VMCS32_RO_EXIT_INTERRUPTION_INFO_CACHE_IDX 53
93#define VMX_VMCS_RO_EXIT_QUALIFICATION_CACHE_IDX 54
94#define VMX_VMCS32_RO_IDT_INFO_CACHE_IDX 55
95#define VMX_VMCS32_RO_IDT_ERRCODE_CACHE_IDX 56
96#define VMX_VMCS_MAX_CACHE_IDX (VMX_VMCS32_RO_IDT_ERRCODE_CACHE_IDX+1)
97#define VMX_VMCS64_GUEST_CR3_CACHE_IDX 57
98#define VMX_VMCS_EXIT_PHYS_ADDR_FULL_CACHE_IDX 58
99#define VMX_VMCS_MAX_NESTED_PAGING_CACHE_IDX (VMX_VMCS_EXIT_PHYS_ADDR_FULL_CACHE_IDX+1)
100
101
102#ifdef IN_RING0
103
104/**
105 * Enters the VT-x session
106 *
107 * @returns VBox status code.
108 * @param pVM The VM to operate on.
109 * @param pVCpu The VMCPU to operate on.
110 * @param pCpu CPU info struct
111 */
112VMMR0DECL(int) VMXR0Enter(PVM pVM, PVMCPU pVCpu, PHWACCM_CPUINFO pCpu);
113
114/**
115 * Leaves the VT-x session
116 *
117 * @returns VBox status code.
118 * @param pVM The VM to operate on.
119 * @param pVCpu The VMCPU to operate on.
120 * @param pCtx CPU context
121 */
122VMMR0DECL(int) VMXR0Leave(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
123
124
125/**
126 * Sets up and activates VT-x on the current CPU
127 *
128 * @returns VBox status code.
129 * @param pCpu CPU info struct
130 * @param pVM The VM to operate on. (can be NULL after a resume)
131 * @param pvPageCpu Pointer to the global cpu page
132 * @param pPageCpuPhys Physical address of the global cpu page
133 */
134VMMR0DECL(int) VMXR0EnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
135
136/**
137 * Deactivates VT-x on the current CPU
138 *
139 * @returns VBox status code.
140 * @param pCpu CPU info struct
141 * @param pvPageCpu Pointer to the global cpu page
142 * @param pPageCpuPhys Physical address of the global cpu page
143 */
144VMMR0DECL(int) VMXR0DisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
145
146/**
147 * Does Ring-0 per VM VT-x init.
148 *
149 * @returns VBox status code.
150 * @param pVM The VM to operate on.
151 */
152VMMR0DECL(int) VMXR0InitVM(PVM pVM);
153
154/**
155 * Does Ring-0 per VM VT-x termination.
156 *
157 * @returns VBox status code.
158 * @param pVM The VM to operate on.
159 */
160VMMR0DECL(int) VMXR0TermVM(PVM pVM);
161
162/**
163 * Sets up VT-x for the specified VM
164 *
165 * @returns VBox status code.
166 * @param pVM The VM to operate on.
167 */
168VMMR0DECL(int) VMXR0SetupVM(PVM pVM);
169
170
171/**
172 * Save the host state
173 *
174 * @returns VBox status code.
175 * @param pVM The VM to operate on.
176 * @param pVCpu The VMCPU to operate on.
177 */
178VMMR0DECL(int) VMXR0SaveHostState(PVM pVM, PVMCPU pVCpu);
179
180/**
181 * Loads the guest state
182 *
183 * @returns VBox status code.
184 * @param pVM The VM to operate on.
185 * @param pVCpu The VMCPU to operate on.
186 * @param pCtx Guest context
187 */
188VMMR0DECL(int) VMXR0LoadGuestState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
189
190
191/**
192 * Runs guest code in a VT-x VM.
193 *
194 * @returns VBox status code.
195 * @param pVM The VM to operate on.
196 * @param pVCpu The VMCPU to operate on.
197 * @param pCtx Guest context
198 */
199VMMR0DECL(int) VMXR0RunGuestCode(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
200
201
202# if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
203/**
204 * Executes the specified handler in 64 mode
205 *
206 * @returns VBox status code.
207 * @param pVM The VM to operate on.
208 * @param pVCpu The VMCPU to operate on.
209 * @param pCtx Guest context
210 * @param pfnHandler RC handler
211 * @param cbParam Number of parameters
212 * @param paParam Array of 32 bits parameters
213 */
214VMMR0DECL(int) VMXR0Execute64BitsHandler(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, RTRCPTR pfnHandler, uint32_t cbParam, uint32_t *paParam);
215# endif
216
217# define VMX_WRITE_SELREG(REG, reg) \
218{ \
219 rc = VMXWriteVMCS(VMX_VMCS16_GUEST_FIELD_##REG, pCtx->reg); \
220 rc |= VMXWriteVMCS(VMX_VMCS32_GUEST_##REG##_LIMIT, pCtx->reg##Hid.u32Limit); \
221 rc |= VMXWriteVMCS64(VMX_VMCS64_GUEST_##REG##_BASE, pCtx->reg##Hid.u64Base); \
222 if ((pCtx->eflags.u32 & X86_EFL_VM)) \
223 val = pCtx->reg##Hid.Attr.u; \
224 else \
225 if ( CPUMIsGuestInRealModeEx(pCtx) \
226 && !pVM->hwaccm.s.vmx.fUnrestrictedGuest) \
227 { \
228 /* Must override this or else VT-x will fail with invalid guest state errors. */ \
229 /* DPL=3, present, code/data, r/w/accessed. */ \
230 val = 0xf3; \
231 } \
232 else \
233 if ( ((!pCtx->csHid.Attr.n.u1DefBig && !CPUMIsGuestIn64BitCodeEx(pCtx)) || pCtx->reg) \
234 && pCtx->reg##Hid.Attr.n.u1Present == 1) \
235 val = pCtx->reg##Hid.Attr.u | X86_SEL_TYPE_ACCESSED; \
236 else \
237 val = 0x10000; /* Invalid guest state error otherwise. (BIT(16) = Unusable) */ \
238 \
239 rc |= VMXWriteVMCS(VMX_VMCS32_GUEST_##REG##_ACCESS_RIGHTS, val); \
240}
241
242# define VMX_READ_SELREG(REG, reg) \
243{ \
244 VMXReadCachedVMCS(VMX_VMCS16_GUEST_FIELD_##REG, &val); \
245 pCtx->reg = val; \
246 VMXReadCachedVMCS(VMX_VMCS32_GUEST_##REG##_LIMIT, &val); \
247 pCtx->reg##Hid.u32Limit = val; \
248 VMXReadCachedVMCS(VMX_VMCS64_GUEST_##REG##_BASE, &val); \
249 pCtx->reg##Hid.u64Base = val; \
250 VMXReadCachedVMCS(VMX_VMCS32_GUEST_##REG##_ACCESS_RIGHTS, &val); \
251 pCtx->reg##Hid.Attr.u = val; \
252}
253
254/* Don't read from the cache in this macro; used only in case of failure where the cache is out of sync. */
255# define VMX_LOG_SELREG(REG, szSelReg, val) \
256{ \
257 VMXReadVMCS(VMX_VMCS16_GUEST_FIELD_##REG, &(val)); \
258 Log(("%s Selector %x\n", szSelReg, (val))); \
259 VMXReadVMCS(VMX_VMCS32_GUEST_##REG##_LIMIT, &(val)); \
260 Log(("%s Limit %x\n", szSelReg, (val))); \
261 VMXReadVMCS(VMX_VMCS64_GUEST_##REG##_BASE, &(val)); \
262 Log(("%s Base %RX64\n", szSelReg, (uint64_t)(val))); \
263 VMXReadVMCS(VMX_VMCS32_GUEST_##REG##_ACCESS_RIGHTS, &(val)); \
264 Log(("%s Attributes %x\n", szSelReg, (val))); \
265}
266
267/**
268 * Cache VMCS writes for performance reasons (Darwin) and for running 64 bits guests on 32 bits hosts.
269 *
270 * @param pVCpu The VMCPU to operate on.
271 * @param idxField VMCS field
272 * @param u64Val Value
273 */
274VMMR0DECL(int) VMXWriteCachedVMCSEx(PVMCPU pVCpu, uint32_t idxField, uint64_t u64Val);
275
276#ifdef VMX_USE_CACHED_VMCS_ACCESSES
277/**
278 * Return value of cached VMCS read for performance reasons (Darwin) and for running 64 bits guests on 32 bits hosts.
279 *
280 * @param pVCpu The VMCPU to operate on.
281 * @param idxField VMCS cache index (not VMCS field index!)
282 * @param pVal Value
283 */
284DECLINLINE(int) VMXReadCachedVMCSEx(PVMCPU pVCpu, uint32_t idxCache, RTGCUINTREG *pVal)
285{
286 Assert(idxCache <= VMX_VMCS_MAX_NESTED_PAGING_CACHE_IDX);
287 *pVal = pVCpu->hwaccm.s.vmx.VMCSCache.Read.aFieldVal[idxCache];
288 return VINF_SUCCESS;
289}
290#endif
291
292/**
293 * Return value of cached VMCS read for performance reasons (Darwin) and for running 64 bits guests on 32 bits hosts.
294 *
295 * @param idxField VMCS field
296 * @param pVal Value pointer (out)
297 */
298#ifdef VMX_USE_CACHED_VMCS_ACCESSES
299# define VMXReadCachedVMCS(idxField, pVal) VMXReadCachedVMCSEx(pVCpu, idxField##_CACHE_IDX, pVal)
300#else
301# define VMXReadCachedVMCS(idxField, pVal) VMXReadVMCS(idxField, pVal)
302#endif
303
304/**
305 * Setup cached VMCS for performance reasons (Darwin) and for running 64 bits guests on 32 bits hosts.
306 *
307 * @param pCache The cache.
308 * @param idxField VMCS field
309 */
310#define VMXSetupCachedReadVMCS(pCache, idxField) \
311{ \
312 Assert(pCache->Read.aField[idxField##_CACHE_IDX] == 0); \
313 pCache->Read.aField[idxField##_CACHE_IDX] = idxField; \
314 pCache->Read.aFieldVal[idxField##_CACHE_IDX] = 0; \
315}
316
317#define VMX_SETUP_SELREG(REG, pCache) \
318{ \
319 VMXSetupCachedReadVMCS(pCache, VMX_VMCS16_GUEST_FIELD_##REG); \
320 VMXSetupCachedReadVMCS(pCache, VMX_VMCS32_GUEST_##REG##_LIMIT); \
321 VMXSetupCachedReadVMCS(pCache, VMX_VMCS64_GUEST_##REG##_BASE); \
322 VMXSetupCachedReadVMCS(pCache, VMX_VMCS32_GUEST_##REG##_ACCESS_RIGHTS); \
323}
324
325/**
326 * Prepares for and executes VMLAUNCH (32 bits guest mode)
327 *
328 * @returns VBox status code
329 * @param fResume vmlauch/vmresume
330 * @param pCtx Guest context
331 * @param pCache VMCS cache
332 * @param pVM The VM to operate on.
333 * @param pVCpu The VMCPU to operate on.
334 */
335DECLASM(int) VMXR0StartVM32(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu);
336
337/**
338 * Prepares for and executes VMLAUNCH (64 bits guest mode)
339 *
340 * @returns VBox status code
341 * @param fResume vmlauch/vmresume
342 * @param pCtx Guest context
343 * @param pCache VMCS cache
344 * @param pVM The VM to operate on.
345 * @param pVCpu The VMCPU to operate on.
346 */
347DECLASM(int) VMXR0StartVM64(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu);
348
349# if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
350/**
351 * Prepares for and executes VMLAUNCH (64 bits guest mode)
352 *
353 * @returns VBox status code
354 * @param fResume vmlauch/vmresume
355 * @param pCtx Guest context
356 * @param pCache VMCS cache
357 * @param pVM The VM to operate on.
358 * @param pVCpu The VMCPU to operate on.
359 */
360DECLASM(int) VMXR0SwitcherStartVM64(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu);
361# endif
362
363#endif /* IN_RING0 */
364
365/** @} */
366
367RT_C_DECLS_END
368
369#endif
370
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