VirtualBox

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

Last change on this file since 12559 was 12305, checked in by vboxsync, 16 years ago

Flush the recompiler's TB cache each time we detect writes to PATM/CSAM monitored pages.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.4 KB
Line 
1/* $Id: EMInternal.h 12305 2008-09-09 15:50:15Z 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 /* Set when the translation blocks in the recompiler cache need to be flushed. */
280 bool fREMFlushTBs;
281
282 uint8_t u8Padding[GC_ARCH_BITS == 64 ? 5 : 1];
283
284 /** Inhibit interrupts for this instruction. Valid only when VM_FF_INHIBIT_INTERRUPTS is set. */
285 RTGCUINTPTR GCPtrInhibitInterrupts;
286
287
288 /** Pointer to the PATM status structure. (HC Ptr) */
289 R3R0PTRTYPE(PPATMGCSTATE) pPatmGCState;
290
291 /** Pointer to the guest CPUM state. (HC Ptr) */
292 R3R0PTRTYPE(PCPUMCTX) pCtx;
293
294#if GC_ARCH_BITS == 64
295 RTGCPTR aPadding1;
296#endif
297
298 union
299 {
300 /** Padding used in the other rings.
301 * This must be larger than jmp_buf on any supported platform. */
302 char achPaddingFatalLongJump[HC_ARCH_BITS == 32 ? 176 : 256];
303#ifdef IN_RING3
304 /** Long buffer jump for fatal VM errors.
305 * It will jump to before the outer EM loop is entered. */
306 jmp_buf FatalLongJump;
307#endif
308 } u;
309
310 /** @name Execution profiling.
311 * @{ */
312 STAMPROFILE StatForcedActions;
313 STAMPROFILE StatHalted;
314 STAMPROFILEADV StatHwAccEntry;
315 STAMPROFILE StatHwAccExec;
316 STAMPROFILE StatREMEmu;
317 STAMPROFILE StatREMExec;
318 STAMPROFILE StatREMSync;
319 STAMPROFILEADV StatREMTotal;
320 STAMPROFILE StatRAWExec;
321 STAMPROFILEADV StatRAWEntry;
322 STAMPROFILEADV StatRAWTail;
323 STAMPROFILEADV StatRAWTotal;
324 STAMPROFILEADV StatTotal;
325 /** @} */
326
327 /** HC: Profiling of emR3RawExecuteIOInstruction. */
328 STAMPROFILE StatIOEmu;
329 /** HC: Profiling of emR3RawPrivileged. */
330 STAMPROFILE StatPrivEmu;
331 /** HC: Profiling of emR3RawExecuteInstruction. */
332 STAMPROFILE StatMiscEmu;
333
334 /** @todo r=bird: Are any of these actually used? */
335 STAMCOUNTER StatPatchTrap;
336 STAMCOUNTER StatPatchInt3;
337 STAMCOUNTER StatPatchIF0;
338 STAMCOUNTER StatPatchEmulate;
339 STAMCOUNTER StatPageOutOfSync;
340 STAMCOUNTER StatHwAccExecuteEntry;
341
342 /** More statistics (HC). */
343 R3R0PTRTYPE(PEMSTATS) pStatsHC;
344 /** More statistics (GC). */
345 RCPTRTYPE(PEMSTATS) pStatsGC;
346#if HC_ARCH_BITS == 64
347 RTRCPTR padding0;
348#endif
349
350 /** Tree for keeping track of cli occurances (debug only). */
351 R3PTRTYPE(PAVLPVNODECORE) pCliStatTree;
352 STAMCOUNTER StatTotalClis;
353#if 0
354 /** 64-bit Visual C++ rounds the struct size up to 16 byte. */
355 uint64_t padding1;
356#endif
357
358} EM;
359/** Pointer to EM VM instance data. */
360typedef EM *PEM;
361
362
363
364/** @} */
365
366__END_DECLS
367
368#endif
369
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