VirtualBox

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

Last change on this file since 13542 was 13514, checked in by vboxsync, 16 years ago

Enabled power notification callbacks to disable VT-x/AMD-V before suspend and to re-enable it after resume.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.2 KB
Line 
1/* $Id: HWVMXR0.h 13514 2008-10-23 07:56:55Z 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 pCpu CPU info struct
50 */
51VMMR0DECL(int) VMXR0Enter(PVM pVMm, PHWACCM_CPUINFO pCpu);
52
53/**
54 * Leaves the VT-x session
55 *
56 * @returns VBox status code.
57 * @param pVM The VM to operate on.
58 * @param pCtx CPU context
59 */
60VMMR0DECL(int) VMXR0Leave(PVM pVM, PCPUMCTX pCtx);
61
62
63/**
64 * Sets up and activates VT-x on the current CPU
65 *
66 * @returns VBox status code.
67 * @param pCpu CPU info struct
68 * @param pVM The VM to operate on. (can be NULL after a resume)
69 * @param pvPageCpu Pointer to the global cpu page
70 * @param pPageCpuPhys Physical address of the global cpu page
71 */
72VMMR0DECL(int) VMXR0EnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
73
74/**
75 * Deactivates VT-x on the current CPU
76 *
77 * @returns VBox status code.
78 * @param pCpu CPU info struct
79 * @param pvPageCpu Pointer to the global cpu page
80 * @param pPageCpuPhys Physical address of the global cpu page
81 */
82VMMR0DECL(int) VMXR0DisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
83
84/**
85 * Does Ring-0 per VM VT-x init.
86 *
87 * @returns VBox status code.
88 * @param pVM The VM to operate on.
89 */
90VMMR0DECL(int) VMXR0InitVM(PVM pVM);
91
92/**
93 * Does Ring-0 per VM VT-x termination.
94 *
95 * @returns VBox status code.
96 * @param pVM The VM to operate on.
97 */
98VMMR0DECL(int) VMXR0TermVM(PVM pVM);
99
100/**
101 * Sets up VT-x for the specified VM
102 *
103 * @returns VBox status code.
104 * @param pVM The VM to operate on.
105 */
106VMMR0DECL(int) VMXR0SetupVM(PVM pVM);
107
108
109/**
110 * Save the host state
111 *
112 * @returns VBox status code.
113 * @param pVM The VM to operate on.
114 */
115VMMR0DECL(int) VMXR0SaveHostState(PVM pVM);
116
117/**
118 * Loads the guest state
119 *
120 * @returns VBox status code.
121 * @param pVM The VM to operate on.
122 * @param pCtx Guest context
123 */
124VMMR0DECL(int) VMXR0LoadGuestState(PVM pVM, CPUMCTX *pCtx);
125
126
127/**
128 * Runs guest code in a VT-x VM.
129 *
130 * @returns VBox status code.
131 * @param pVM The VM to operate on.
132 * @param pCtx Guest context
133 */
134VMMR0DECL(int) VMXR0RunGuestCode(PVM pVM, CPUMCTX *pCtx);
135
136
137#define VMX_WRITE_SELREG(REG, reg) \
138{ \
139 rc = VMXWriteVMCS(VMX_VMCS_GUEST_FIELD_##REG, pCtx->reg); \
140 rc |= VMXWriteVMCS(VMX_VMCS_GUEST_##REG##_LIMIT, pCtx->reg##Hid.u32Limit); \
141 rc |= VMXWriteVMCS(VMX_VMCS_GUEST_##REG##_BASE, pCtx->reg##Hid.u64Base); \
142 if ((pCtx->eflags.u32 & X86_EFL_VM)) \
143 val = pCtx->reg##Hid.Attr.u; \
144 else \
145 if (CPUMIsGuestInRealModeEx(pCtx)) \
146 { \
147 /* Must override this or else VT-x will fail with invalid guest state errors. */ \
148 /* DPL=3, present, code/data, r/w/accessed. */ \
149 val = 0xf3; \
150 } \
151 else \
152 if ( ((!pCtx->csHid.Attr.n.u1DefBig && !CPUMIsGuestIn64BitCodeEx(pCtx)) || pCtx->reg) \
153 && pCtx->reg##Hid.Attr.n.u1Present == 1) \
154 val = pCtx->reg##Hid.Attr.u | X86_SEL_TYPE_ACCESSED; \
155 else \
156 val = 0x10000; /* Invalid guest state error otherwise. (BIT(16) = Unusable) */ \
157 \
158 rc |= VMXWriteVMCS(VMX_VMCS_GUEST_##REG##_ACCESS_RIGHTS, val); \
159}
160
161#define VMX_READ_SELREG(REG, reg) \
162{ \
163 VMXReadVMCS(VMX_VMCS_GUEST_FIELD_##REG, &val); \
164 pCtx->reg = val; \
165 VMXReadVMCS(VMX_VMCS_GUEST_##REG##_LIMIT, &val); \
166 pCtx->reg##Hid.u32Limit = val; \
167 VMXReadVMCS(VMX_VMCS_GUEST_##REG##_BASE, &val); \
168 pCtx->reg##Hid.u64Base = val; \
169 VMXReadVMCS(VMX_VMCS_GUEST_##REG##_ACCESS_RIGHTS, &val); \
170 pCtx->reg##Hid.Attr.u = val; \
171}
172
173#define VMX_LOG_SELREG(REG, szSelReg) \
174{ \
175 VMXReadVMCS(VMX_VMCS_GUEST_FIELD_##REG, &val); \
176 Log(("%s Selector %x\n", szSelReg, val)); \
177 VMXReadVMCS(VMX_VMCS_GUEST_##REG##_LIMIT, &val); \
178 Log(("%s Limit %x\n", szSelReg, val)); \
179 VMXReadVMCS(VMX_VMCS_GUEST_##REG##_BASE, &val); \
180 Log(("%s Base %RX64\n", szSelReg, val)); \
181 VMXReadVMCS(VMX_VMCS_GUEST_##REG##_ACCESS_RIGHTS, &val); \
182 Log(("%s Attributes %x\n", szSelReg, val)); \
183}
184
185
186
187/**
188 * Prepares for and executes VMLAUNCH (32 bits guest mode)
189 *
190 * @returns VBox status code
191 * @param fResume vmlauch/vmresume
192 * @param pCtx Guest context
193 */
194DECLASM(int) VMXR0StartVM32(RTHCUINT fResume, PCPUMCTX pCtx);
195
196/**
197 * Prepares for and executes VMLAUNCH (64 bits guest mode)
198 *
199 * @returns VBox status code
200 * @param fResume vmlauch/vmresume
201 * @param pCtx Guest context
202 */
203DECLASM(int) VMXR0StartVM64(RTHCUINT fResume, PCPUMCTX pCtx);
204
205#endif /* IN_RING0 */
206
207/** @} */
208
209__END_DECLS
210
211#endif
212
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