VirtualBox

source: vbox/trunk/src/VBox/VMM/EMInternal.h@ 11838

Last change on this file since 11838 was 11424, checked in by vboxsync, 16 years ago

Emulate stosw/d/q ourselves.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.3 KB
Line 
1/* $Id: EMInternal.h 11424 2008-08-14 13:46:06Z vboxsync $ */
2/** @file
3 * EM - 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 ___EMInternal_h
23#define ___EMInternal_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/patm.h>
30#include <VBox/dis.h>
31#include <iprt/avl.h>
32#include <setjmp.h>
33
34__BEGIN_DECLS
35
36
37/** @defgroup grp_em_int Internal
38 * @ingroup grp_em
39 * @internal
40 * @{
41 */
42
43/** The saved state version. */
44#define EM_SAVED_STATE_VERSION 2
45
46/** Enable for tracing in raw mode.
47 * @remark SvL: debugging help primarily for myself. */
48#define DEBUG_TRACING_ENABLED
49
50/**
51 * Converts a EM pointer into a VM pointer.
52 * @returns Pointer to the VM structure the EM is part of.
53 * @param pEM Pointer to EM instance data.
54 */
55#define EM2VM(pEM) ( (PVM)((char*)pEM - pEM->offVM) )
56
57/**
58 * Cli node structure
59 */
60typedef struct CLISTAT
61{
62 /** The key is the cli address. */
63 AVLPVNODECORE Core;
64 /** Occurrences. */
65 STAMCOUNTER Counter;
66} CLISTAT, *PCLISTAT;
67
68
69/**
70 * Excessive EM statistics.
71 */
72typedef struct EMSTATS
73{
74 /** GC: Profiling of EMInterpretInstruction(). */
75 STAMPROFILE StatGCEmulate;
76 /** HC: Profiling of EMInterpretInstruction(). */
77 STAMPROFILE StatHCEmulate;
78
79 /** @name Interpreter Instruction statistics.
80 * @{
81 */
82 STAMCOUNTER StatGCInterpretSucceeded;
83 STAMCOUNTER StatHCInterpretSucceeded;
84
85 STAMCOUNTER StatGCAnd;
86 STAMCOUNTER StatHCAnd;
87 STAMCOUNTER StatGCCpuId;
88 STAMCOUNTER StatHCCpuId;
89 STAMCOUNTER StatGCDec;
90 STAMCOUNTER StatHCDec;
91 STAMCOUNTER StatGCHlt;
92 STAMCOUNTER StatHCHlt;
93 STAMCOUNTER StatGCInc;
94 STAMCOUNTER StatHCInc;
95 STAMCOUNTER StatGCInvlPg;
96 STAMCOUNTER StatHCInvlPg;
97 STAMCOUNTER StatGCIret;
98 STAMCOUNTER StatHCIret;
99 STAMCOUNTER StatGCLLdt;
100 STAMCOUNTER StatHCLLdt;
101 STAMCOUNTER StatGCMov;
102 STAMCOUNTER StatHCMov;
103 STAMCOUNTER StatGCMovCRx;
104 STAMCOUNTER StatHCMovCRx;
105 STAMCOUNTER StatGCMovDRx;
106 STAMCOUNTER StatHCMovDRx;
107 STAMCOUNTER StatGCOr;
108 STAMCOUNTER StatHCOr;
109 STAMCOUNTER StatGCPop;
110 STAMCOUNTER StatHCPop;
111 STAMCOUNTER StatGCSti;
112 STAMCOUNTER StatHCSti;
113 STAMCOUNTER StatGCXchg;
114 STAMCOUNTER StatHCXchg;
115 STAMCOUNTER StatGCXor;
116 STAMCOUNTER StatHCXor;
117 STAMCOUNTER StatGCMonitor;
118 STAMCOUNTER StatHCMonitor;
119 STAMCOUNTER StatGCMWait;
120 STAMCOUNTER StatHCMWait;
121 STAMCOUNTER StatGCAdd;
122 STAMCOUNTER StatHCAdd;
123 STAMCOUNTER StatGCSub;
124 STAMCOUNTER StatHCSub;
125 STAMCOUNTER StatGCAdc;
126 STAMCOUNTER StatHCAdc;
127 STAMCOUNTER StatGCRdtsc;
128 STAMCOUNTER StatHCRdtsc;
129 STAMCOUNTER StatGCBtr;
130 STAMCOUNTER StatHCBtr;
131 STAMCOUNTER StatGCBts;
132 STAMCOUNTER StatHCBts;
133 STAMCOUNTER StatGCBtc;
134 STAMCOUNTER StatHCBtc;
135 STAMCOUNTER StatGCCmpXchg;
136 STAMCOUNTER StatHCCmpXchg;
137 STAMCOUNTER StatGCCmpXchg8b;
138 STAMCOUNTER StatHCCmpXchg8b;
139 STAMCOUNTER StatGCXAdd;
140 STAMCOUNTER StatHCXAdd;
141 STAMCOUNTER StatGCClts;
142 STAMCOUNTER StatHCClts;
143 STAMCOUNTER StatGCStosWD;
144 STAMCOUNTER StatHCStosWD;
145 STAMCOUNTER StatHCRdmsr;
146 STAMCOUNTER StatHCWrmsr;
147 STAMCOUNTER StatGCRdmsr;
148 STAMCOUNTER StatGCWrmsr;
149
150 STAMCOUNTER StatGCInterpretFailed;
151 STAMCOUNTER StatHCInterpretFailed;
152
153 STAMCOUNTER StatGCFailedAnd;
154 STAMCOUNTER StatHCFailedAnd;
155 STAMCOUNTER StatGCFailedCpuId;
156 STAMCOUNTER StatHCFailedCpuId;
157 STAMCOUNTER StatGCFailedDec;
158 STAMCOUNTER StatHCFailedDec;
159 STAMCOUNTER StatGCFailedHlt;
160 STAMCOUNTER StatHCFailedHlt;
161 STAMCOUNTER StatGCFailedInc;
162 STAMCOUNTER StatHCFailedInc;
163 STAMCOUNTER StatGCFailedInvlPg;
164 STAMCOUNTER StatHCFailedInvlPg;
165 STAMCOUNTER StatGCFailedIret;
166 STAMCOUNTER StatHCFailedIret;
167 STAMCOUNTER StatGCFailedLLdt;
168 STAMCOUNTER StatHCFailedLLdt;
169 STAMCOUNTER StatGCFailedMisc;
170 STAMCOUNTER StatHCFailedMisc;
171 STAMCOUNTER StatGCFailedMov;
172 STAMCOUNTER StatHCFailedMov;
173 STAMCOUNTER StatGCFailedMovCRx;
174 STAMCOUNTER StatHCFailedMovCRx;
175 STAMCOUNTER StatGCFailedMovDRx;
176 STAMCOUNTER StatHCFailedMovDRx;
177 STAMCOUNTER StatGCFailedOr;
178 STAMCOUNTER StatHCFailedOr;
179 STAMCOUNTER StatGCFailedPop;
180 STAMCOUNTER StatHCFailedPop;
181 STAMCOUNTER StatGCFailedSti;
182 STAMCOUNTER StatHCFailedSti;
183 STAMCOUNTER StatGCFailedXchg;
184 STAMCOUNTER StatHCFailedXchg;
185 STAMCOUNTER StatGCFailedXor;
186 STAMCOUNTER StatHCFailedXor;
187 STAMCOUNTER StatGCFailedMonitor;
188 STAMCOUNTER StatHCFailedMonitor;
189 STAMCOUNTER StatGCFailedMWait;
190 STAMCOUNTER StatHCFailedMWait;
191 STAMCOUNTER StatHCFailedRdmsr;
192 STAMCOUNTER StatHCFailedWrmsr;
193 STAMCOUNTER StatGCFailedRdmsr;
194 STAMCOUNTER StatGCFailedWrmsr;
195
196 STAMCOUNTER StatGCFailedAdd;
197 STAMCOUNTER StatHCFailedAdd;
198 STAMCOUNTER StatGCFailedAdc;
199 STAMCOUNTER StatHCFailedAdc;
200 STAMCOUNTER StatGCFailedBtr;
201 STAMCOUNTER StatHCFailedBtr;
202 STAMCOUNTER StatGCFailedBts;
203 STAMCOUNTER StatHCFailedBts;
204 STAMCOUNTER StatGCFailedBtc;
205 STAMCOUNTER StatHCFailedBtc;
206 STAMCOUNTER StatGCFailedCli;
207 STAMCOUNTER StatHCFailedCli;
208 STAMCOUNTER StatGCFailedCmpXchg;
209 STAMCOUNTER StatHCFailedCmpXchg;
210 STAMCOUNTER StatGCFailedCmpXchg8b;
211 STAMCOUNTER StatHCFailedCmpXchg8b;
212 STAMCOUNTER StatGCFailedXAdd;
213 STAMCOUNTER StatHCFailedXAdd;
214 STAMCOUNTER StatHCFailedMovNTPS;
215 STAMCOUNTER StatGCFailedMovNTPS;
216 STAMCOUNTER StatGCFailedStosWD;
217 STAMCOUNTER StatHCFailedStosWD;
218 STAMCOUNTER StatGCFailedSub;
219 STAMCOUNTER StatHCFailedSub;
220 STAMCOUNTER StatGCFailedWbInvd;
221 STAMCOUNTER StatHCFailedWbInvd;
222 STAMCOUNTER StatGCFailedRdtsc;
223 STAMCOUNTER StatHCFailedRdtsc;
224 STAMCOUNTER StatGCFailedClts;
225 STAMCOUNTER StatHCFailedClts;
226
227 STAMCOUNTER StatGCFailedUserMode;
228 STAMCOUNTER StatHCFailedUserMode;
229 STAMCOUNTER StatGCFailedPrefix;
230 STAMCOUNTER StatHCFailedPrefix;
231 /** @} */
232
233 /** @name Privileged Instructions Ending Up In HC.
234 * @{ */
235 STAMCOUNTER StatCli;
236 STAMCOUNTER StatSti;
237 STAMCOUNTER StatIn;
238 STAMCOUNTER StatOut;
239 STAMCOUNTER StatInvlpg;
240 STAMCOUNTER StatHlt;
241 STAMCOUNTER StatMovReadCR[USE_REG_CR4 + 1];
242 STAMCOUNTER StatMovWriteCR[USE_REG_CR4 + 1];
243 STAMCOUNTER StatMovDRx;
244 STAMCOUNTER StatIret;
245 STAMCOUNTER StatMovLgdt;
246 STAMCOUNTER StatMovLldt;
247 STAMCOUNTER StatMovLidt;
248 STAMCOUNTER StatMisc;
249 STAMCOUNTER StatSysEnter;
250 STAMCOUNTER StatSysExit;
251 STAMCOUNTER StatSysCall;
252 STAMCOUNTER StatSysRet;
253 /** @} */
254
255} EMSTATS, *PEMSTATS;
256
257/**
258 * EM VM Instance data.
259 * Changes to this must checked against the padding of the cfgm union in VM!
260 */
261typedef struct EM
262{
263 /** Offset to the VM structure.
264 * See EM2VM(). */
265 RTUINT offVM;
266
267 /** Execution Manager State. */
268 volatile EMSTATE enmState;
269 /** Force raw-mode execution.
270 * This is used to prevent REM from trying to execute patch code.
271 * The flag is cleared upon entering emR3RawExecute() and updated in certain return paths. */
272 bool fForceRAW;
273
274#ifdef DEBUG_TRACING_ENABLED
275 /** @see DEBUG_TRACING_ENABLED */
276 bool fTracing;
277#endif
278
279 uint8_t u8Padding[GC_ARCH_BITS == 64 ? 6 : 2];
280
281 /** Inhibit interrupts for this instruction. Valid only when VM_FF_INHIBIT_INTERRUPTS is set. */
282 RTGCUINTPTR GCPtrInhibitInterrupts;
283
284
285 /** Pointer to the PATM status structure. (HC Ptr) */
286 R3R0PTRTYPE(PPATMGCSTATE) pPatmGCState;
287
288 /** Pointer to the guest CPUM state. (HC Ptr) */
289 R3R0PTRTYPE(PCPUMCTX) pCtx;
290
291#if GC_ARCH_BITS == 64
292 RTGCPTR aPadding1;
293#endif
294
295 union
296 {
297 /** Padding used in the other rings.
298 * This must be larger than jmp_buf on any supported platform. */
299 char achPaddingFatalLongJump[HC_ARCH_BITS == 32 ? 176 : 256];
300#ifdef IN_RING3
301 /** Long buffer jump for fatal VM errors.
302 * It will jump to before the outer EM loop is entered. */
303 jmp_buf FatalLongJump;
304#endif
305 } u;
306
307 /** @name Execution profiling.
308 * @{ */
309 STAMPROFILE StatForcedActions;
310 STAMPROFILE StatHalted;
311 STAMPROFILEADV StatHwAccEntry;
312 STAMPROFILE StatHwAccExec;
313 STAMPROFILE StatREMEmu;
314 STAMPROFILE StatREMExec;
315 STAMPROFILE StatREMSync;
316 STAMPROFILEADV StatREMTotal;
317 STAMPROFILE StatRAWExec;
318 STAMPROFILEADV StatRAWEntry;
319 STAMPROFILEADV StatRAWTail;
320 STAMPROFILEADV StatRAWTotal;
321 STAMPROFILEADV StatTotal;
322 /** @} */
323
324 /** HC: Profiling of emR3RawExecuteIOInstruction. */
325 STAMPROFILE StatIOEmu;
326 /** HC: Profiling of emR3RawPrivileged. */
327 STAMPROFILE StatPrivEmu;
328 /** HC: Profiling of emR3RawExecuteInstruction. */
329 STAMPROFILE StatMiscEmu;
330
331 /** @todo r=bird: Are any of these actually used? */
332 STAMCOUNTER StatPatchTrap;
333 STAMCOUNTER StatPatchInt3;
334 STAMCOUNTER StatPatchIF0;
335 STAMCOUNTER StatPatchEmulate;
336 STAMCOUNTER StatPageOutOfSync;
337 STAMCOUNTER StatHwAccExecuteEntry;
338
339 /** More statistics (HC). */
340 R3R0PTRTYPE(PEMSTATS) pStatsHC;
341 /** More statistics (GC). */
342 RCPTRTYPE(PEMSTATS) pStatsGC;
343#if HC_ARCH_BITS == 64
344 RTRCPTR padding0;
345#endif
346
347 /** Tree for keeping track of cli occurances (debug only). */
348 R3PTRTYPE(PAVLPVNODECORE) pCliStatTree;
349 STAMCOUNTER StatTotalClis;
350#if 0
351 /** 64-bit Visual C++ rounds the struct size up to 16 byte. */
352 uint64_t padding1;
353#endif
354
355} EM;
356/** Pointer to EM VM instance data. */
357typedef EM *PEM;
358
359
360
361/** @} */
362
363__END_DECLS
364
365#endif
366
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