VirtualBox

source: vbox/trunk/src/VBox/VMM/HWACCMInternal.h@ 3840

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

Double underscore cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.6 KB
Line 
1/* $Id: HWACCMInternal.h 3723 2007-07-19 18:46:00Z vboxsync $ */
2/** @file
3 * HWACCM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef ___HWACCMInternal_h
23#define ___HWACCMInternal_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
33__BEGIN_DECLS
34
35
36/** @defgroup grp_hwaccm_int Internal
37 * @ingroup grp_hwaccm
38 * @internal
39 * @{
40 */
41
42
43/**
44 * Converts a HWACCM pointer into a VM pointer.
45 * @returns Pointer to the VM structure the EM is part of.
46 * @param pHWACCM Pointer to HWACCM instance data.
47 */
48#define HWACCM2VM(pHWACCM) ( (PVM)((char*)pHWACCM - pHWACCM->offVM) )
49
50/** Maximum number of exit reason statistics counters. */
51#define MAX_EXITREASON_STAT 0x100
52#define MASK_EXITREASON_STAT 0xff
53
54/** @name Changed flags
55 * These flags are used to keep track of which important registers that
56 * have been changed since last they were reset.
57 * @{
58 */
59#define HWACCM_CHANGED_GUEST_FPU BIT(0)
60#define HWACCM_CHANGED_GUEST_CR0 BIT(1)
61#define HWACCM_CHANGED_GUEST_CR3 BIT(2)
62#define HWACCM_CHANGED_GUEST_CR4 BIT(3)
63#define HWACCM_CHANGED_GUEST_GDTR BIT(4)
64#define HWACCM_CHANGED_GUEST_IDTR BIT(5)
65#define HWACCM_CHANGED_GUEST_LDTR BIT(6)
66#define HWACCM_CHANGED_GUEST_TR BIT(7)
67#define HWACCM_CHANGED_GUEST_SYSENTER_MSR BIT(8)
68#define HWACCM_CHANGED_GUEST_SEGMENT_REGS BIT(9)
69#define HWACCM_CHANGED_GUEST_DEBUG BIT(10)
70#define HWACCM_CHANGED_HOST_CONTEXT BIT(11)
71
72#define HWACCM_CHANGED_ALL ( HWACCM_CHANGED_GUEST_SEGMENT_REGS \
73 | HWACCM_CHANGED_GUEST_CR0 \
74 | HWACCM_CHANGED_GUEST_CR3 \
75 | HWACCM_CHANGED_GUEST_CR4 \
76 | HWACCM_CHANGED_GUEST_GDTR \
77 | HWACCM_CHANGED_GUEST_IDTR \
78 | HWACCM_CHANGED_GUEST_LDTR \
79 | HWACCM_CHANGED_GUEST_TR \
80 | HWACCM_CHANGED_GUEST_SYSENTER_MSR \
81 | HWACCM_CHANGED_GUEST_FPU \
82 | HWACCM_CHANGED_GUEST_DEBUG \
83 | HWACCM_CHANGED_HOST_CONTEXT)
84
85#define HWACCM_CHANGED_ALL_GUEST ( HWACCM_CHANGED_GUEST_SEGMENT_REGS \
86 | HWACCM_CHANGED_GUEST_CR0 \
87 | HWACCM_CHANGED_GUEST_CR3 \
88 | HWACCM_CHANGED_GUEST_CR4 \
89 | HWACCM_CHANGED_GUEST_GDTR \
90 | HWACCM_CHANGED_GUEST_IDTR \
91 | HWACCM_CHANGED_GUEST_LDTR \
92 | HWACCM_CHANGED_GUEST_TR \
93 | HWACCM_CHANGED_GUEST_SYSENTER_MSR \
94 | HWACCM_CHANGED_GUEST_DEBUG \
95 | HWACCM_CHANGED_GUEST_FPU)
96
97/** @} */
98
99/** @name Intercepted traps
100 * Traps that need to be intercepted so we can correctly dispatch them to the guest if required.
101 * Currently #NM and #PF only
102 */
103#ifdef VBOX_STRICT
104#define HWACCM_VMX_TRAP_MASK BIT(0) | BIT(7) | BIT(14) | BIT(6) | BIT(11) | BIT(12) | BIT(13) | BIT(16)
105#define HWACCM_SVM_TRAP_MASK HWACCM_VMX_TRAP_MASK
106#else
107#define HWACCM_VMX_TRAP_MASK BIT(7) | BIT(14)
108#define HWACCM_SVM_TRAP_MASK HWACCM_VMX_TRAP_MASK
109#endif
110/** @} */
111
112
113/** @name HWACCM SSM version
114 */
115#define HWACCM_SSM_VERSION 3
116
117/**
118 * HWACCM VM Instance data.
119 * Changes to this must checked against the padding of the cfgm union in VM!
120 */
121typedef struct HWACCM
122{
123 /** Offset to the VM structure.
124 * See HWACCM2VM(). */
125 RTUINT offVM;
126
127 /** Set when we've initialized VMX or SVM. */
128 bool fInitialized;
129 /** Set when we're using VMX/SVN at that moment. */
130 bool fActive;
131
132 /** Set when hardware acceleration is allowed. */
133 bool fAllowed;
134
135 /** HWACCM_CHANGED_* flags. */
136 uint32_t fContextUseFlags;
137
138 /** Old style FPU reporting trap mask override performed (optimization) */
139 uint32_t fFPUOldStyleOverride;
140
141 struct
142 {
143 /** Set by the ring-0 driver to indicate VMX is supported by the CPU. */
144 bool fSupported;
145
146 /** Set when we've enabled VMX. */
147 bool fEnabled;
148
149 /** Set if we can use VMXResume to execute guest code. */
150 bool fResumeVM;
151
152 /** Physical address of the VM control structure (VMCS). */
153 RTHCPHYS pVMCSPhys;
154 /** Virtual address of the VM control structure (VMCS). */
155 void *pVMCS;
156
157 /** Physical address of the VMXON page. */
158 RTHCPHYS pVMXONPhys;
159 /** Virtual address of the VMXON page. */
160 void *pVMXON;
161
162 /** Physical address of the TSS page used for real mode emulation. */
163 RTHCPHYS pRealModeTSSPhys;
164 /** Virtual address of the TSS page used for real mode emulation. */
165 PVBOXTSS pRealModeTSS;
166
167 /** Host CR4 value (set by ring-0 VMX init) */
168 uint32_t hostCR4;
169
170 /** Current VMX_VMCS_CTRL_PROC_EXEC_CONTROLS. */
171 uint64_t proc_ctls;
172
173 /** Current CR0 mask. */
174 uint64_t cr0_mask;
175 /** Current CR4 mask. */
176 uint64_t cr4_mask;
177
178 /** VMX MSR values */
179 struct
180 {
181 uint64_t feature_ctrl;
182 uint64_t vmx_basic_info;
183 uint64_t vmx_pin_ctls;
184 uint64_t vmx_proc_ctls;
185 uint64_t vmx_exit;
186 uint64_t vmx_entry;
187 uint64_t vmx_misc;
188 uint64_t vmx_cr0_fixed0;
189 uint64_t vmx_cr0_fixed1;
190 uint64_t vmx_cr4_fixed0;
191 uint64_t vmx_cr4_fixed1;
192 uint64_t vmx_vmcs_enum;
193 } msr;
194
195 /* Last instruction error */
196 uint32_t ulLastInstrError;
197 } vmx;
198
199 struct
200 {
201 /** Set by the ring-0 driver to indicate SVM is supported by the CPU. */
202 bool fSupported;
203
204 /** Set when we've enabled SVM. */
205 bool fEnabled;
206
207 /** Set if we don't have to flush the TLB on VM entry. */
208 bool fResumeVM;
209
210 /** Physical address of the VM control block (VMCB). */
211 RTHCPHYS pVMCBPhys;
212 /** Virtual address of the VM control block (VMCB). */
213 void *pVMCB;
214
215 /** Physical address of the host VM control block (VMCB). */
216 RTHCPHYS pVMCBHostPhys;
217 /** Virtual address of the host VM control block (VMCB). */
218 void *pVMCBHost;
219
220 /** Physical address of the Host State page. */
221 RTHCPHYS pHStatePhys;
222 /** Virtual address of the Host State page. */
223 void *pHState;
224
225 /** Physical address of the IO bitmap (12kb). */
226 RTHCPHYS pIOBitmapPhys;
227 /** Virtual address of the IO bitmap. */
228 void *pIOBitmap;
229
230 /** Physical address of the MSR bitmap (8kb). */
231 RTHCPHYS pMSRBitmapPhys;
232 /** Virtual address of the MSR bitmap. */
233 void *pMSRBitmap;
234
235 /** SVM revision. */
236 uint32_t u32Rev;
237
238 /** Maximum ASID allowed. */
239 uint32_t u32MaxASID;
240 } svm;
241
242 struct
243 {
244 uint32_t u32AMDFeatureECX;
245 uint32_t u32AMDFeatureEDX;
246 } cpuid;
247
248 /* Event injection state. */
249 struct
250 {
251 uint32_t fPending;
252 uint32_t errCode;
253 uint64_t intInfo;
254 } Event;
255
256 /** Saved error from detection */
257 uint32_t ulLastError;
258
259 /** HWACCMR0Init was run */
260 bool fHWACCMR0Init;
261
262 /** Currenty shadow paging mode. */
263 PGMMODE enmShadowMode;
264
265 STAMPROFILEADV StatEntry;
266 STAMPROFILEADV StatExit;
267 STAMPROFILEADV StatInGC;
268
269 STAMCOUNTER StatIntInject;
270
271 STAMCOUNTER StatExitShadowNM;
272 STAMCOUNTER StatExitGuestNM;
273 STAMCOUNTER StatExitShadowPF;
274 STAMCOUNTER StatExitGuestPF;
275 STAMCOUNTER StatExitGuestUD;
276 STAMCOUNTER StatExitGuestSS;
277 STAMCOUNTER StatExitGuestNP;
278 STAMCOUNTER StatExitGuestGP;
279 STAMCOUNTER StatExitGuestDE;
280 STAMCOUNTER StatExitGuestMF;
281 STAMCOUNTER StatExitInvpg;
282 STAMCOUNTER StatExitInvd;
283 STAMCOUNTER StatExitCpuid;
284 STAMCOUNTER StatExitRdtsc;
285 STAMCOUNTER StatExitCRxWrite;
286 STAMCOUNTER StatExitCRxRead;
287 STAMCOUNTER StatExitDRxWrite;
288 STAMCOUNTER StatExitDRxRead;
289 STAMCOUNTER StatExitCLTS;
290 STAMCOUNTER StatExitLMSW;
291 STAMCOUNTER StatExitIOWrite;
292 STAMCOUNTER StatExitIORead;
293 STAMCOUNTER StatExitIOStringWrite;
294 STAMCOUNTER StatExitIOStringRead;
295 STAMCOUNTER StatExitIrqWindow;
296 STAMCOUNTER StatIntReinject;
297 STAMCOUNTER StatPendingHostIrq;
298
299 STAMCOUNTER StatSwitchGuestIrq;
300 STAMCOUNTER StatSwitchToR3;
301
302 R3PTRTYPE(PSTAMCOUNTER) pStatExitReason;
303 R0PTRTYPE(PSTAMCOUNTER) pStatExitReasonR0;
304} HWACCM;
305/** Pointer to HWACCM VM instance data. */
306typedef HWACCM *PHWACCM;
307
308
309#ifdef IN_RING0
310
311#ifdef VBOX_STRICT
312HWACCMR0DECL(void) HWACCMDumpRegs(PCPUMCTX pCtx);
313HWACCMR0DECL(void) HWACCMR0DumpDescriptor(PX86DESCHC Desc, RTSEL Sel, const char *pszMsg);
314#else
315#define HWACCMDumpRegs(a) do { } while (0)
316#define HWACCMR0DumpDescriptor(a, b, c) do { } while (0)
317#endif
318
319#endif
320
321/** @} */
322
323__END_DECLS
324
325#endif
326
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