1 | /* $Id: EMInternal.h 3510 2007-07-09 14:37:57Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * EM - 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 __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 | */
|
---|
60 | typedef 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 | */
|
---|
72 | typedef 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 StatGCClts;
|
---|
138 | STAMCOUNTER StatHCClts;
|
---|
139 |
|
---|
140 | STAMCOUNTER StatGCInterpretFailed;
|
---|
141 | STAMCOUNTER StatHCInterpretFailed;
|
---|
142 |
|
---|
143 | STAMCOUNTER StatGCFailedAnd;
|
---|
144 | STAMCOUNTER StatHCFailedAnd;
|
---|
145 | STAMCOUNTER StatGCFailedCpuId;
|
---|
146 | STAMCOUNTER StatHCFailedCpuId;
|
---|
147 | STAMCOUNTER StatGCFailedDec;
|
---|
148 | STAMCOUNTER StatHCFailedDec;
|
---|
149 | STAMCOUNTER StatGCFailedHlt;
|
---|
150 | STAMCOUNTER StatHCFailedHlt;
|
---|
151 | STAMCOUNTER StatGCFailedInc;
|
---|
152 | STAMCOUNTER StatHCFailedInc;
|
---|
153 | STAMCOUNTER StatGCFailedInvlPg;
|
---|
154 | STAMCOUNTER StatHCFailedInvlPg;
|
---|
155 | STAMCOUNTER StatGCFailedIret;
|
---|
156 | STAMCOUNTER StatHCFailedIret;
|
---|
157 | STAMCOUNTER StatGCFailedLLdt;
|
---|
158 | STAMCOUNTER StatHCFailedLLdt;
|
---|
159 | STAMCOUNTER StatGCFailedMisc;
|
---|
160 | STAMCOUNTER StatHCFailedMisc;
|
---|
161 | STAMCOUNTER StatGCFailedMov;
|
---|
162 | STAMCOUNTER StatHCFailedMov;
|
---|
163 | STAMCOUNTER StatGCFailedMovCRx;
|
---|
164 | STAMCOUNTER StatHCFailedMovCRx;
|
---|
165 | STAMCOUNTER StatGCFailedMovDRx;
|
---|
166 | STAMCOUNTER StatHCFailedMovDRx;
|
---|
167 | STAMCOUNTER StatGCFailedOr;
|
---|
168 | STAMCOUNTER StatHCFailedOr;
|
---|
169 | STAMCOUNTER StatGCFailedPop;
|
---|
170 | STAMCOUNTER StatHCFailedPop;
|
---|
171 | STAMCOUNTER StatGCFailedSti;
|
---|
172 | STAMCOUNTER StatHCFailedSti;
|
---|
173 | STAMCOUNTER StatGCFailedXchg;
|
---|
174 | STAMCOUNTER StatHCFailedXchg;
|
---|
175 | STAMCOUNTER StatGCFailedXor;
|
---|
176 | STAMCOUNTER StatHCFailedXor;
|
---|
177 | STAMCOUNTER StatGCFailedMonitor;
|
---|
178 | STAMCOUNTER StatHCFailedMonitor;
|
---|
179 | STAMCOUNTER StatGCFailedMWait;
|
---|
180 | STAMCOUNTER StatHCFailedMWait;
|
---|
181 |
|
---|
182 | STAMCOUNTER StatGCFailedAdd;
|
---|
183 | STAMCOUNTER StatHCFailedAdd;
|
---|
184 | STAMCOUNTER StatGCFailedAdc;
|
---|
185 | STAMCOUNTER StatHCFailedAdc;
|
---|
186 | STAMCOUNTER StatGCFailedBtr;
|
---|
187 | STAMCOUNTER StatHCFailedBtr;
|
---|
188 | STAMCOUNTER StatGCFailedBts;
|
---|
189 | STAMCOUNTER StatHCFailedBts;
|
---|
190 | STAMCOUNTER StatGCFailedBtc;
|
---|
191 | STAMCOUNTER StatHCFailedBtc;
|
---|
192 | STAMCOUNTER StatGCFailedCli;
|
---|
193 | STAMCOUNTER StatHCFailedCli;
|
---|
194 | STAMCOUNTER StatGCFailedCmpXchg;
|
---|
195 | STAMCOUNTER StatHCFailedCmpXchg;
|
---|
196 | STAMCOUNTER StatHCFailedMovNTPS;
|
---|
197 | STAMCOUNTER StatGCFailedMovNTPS;
|
---|
198 | STAMCOUNTER StatGCFailedStosWD;
|
---|
199 | STAMCOUNTER StatHCFailedStosWD;
|
---|
200 | STAMCOUNTER StatGCFailedSub;
|
---|
201 | STAMCOUNTER StatHCFailedSub;
|
---|
202 | STAMCOUNTER StatGCFailedWbInvd;
|
---|
203 | STAMCOUNTER StatHCFailedWbInvd;
|
---|
204 | STAMCOUNTER StatGCFailedRdtsc;
|
---|
205 | STAMCOUNTER StatHCFailedRdtsc;
|
---|
206 | STAMCOUNTER StatGCFailedClts;
|
---|
207 | STAMCOUNTER StatHCFailedClts;
|
---|
208 |
|
---|
209 | STAMCOUNTER StatGCFailedUserMode;
|
---|
210 | STAMCOUNTER StatHCFailedUserMode;
|
---|
211 | STAMCOUNTER StatGCFailedPrefix;
|
---|
212 | STAMCOUNTER StatHCFailedPrefix;
|
---|
213 | /** @} */
|
---|
214 |
|
---|
215 | /** @name Privileged Instructions Ending Up In HC.
|
---|
216 | * @{ */
|
---|
217 | STAMCOUNTER StatCli;
|
---|
218 | STAMCOUNTER StatSti;
|
---|
219 | STAMCOUNTER StatIn;
|
---|
220 | STAMCOUNTER StatOut;
|
---|
221 | STAMCOUNTER StatInvlpg;
|
---|
222 | STAMCOUNTER StatHlt;
|
---|
223 | STAMCOUNTER StatMovReadCR[USE_REG_CR4 + 1];
|
---|
224 | STAMCOUNTER StatMovWriteCR[USE_REG_CR4 + 1];
|
---|
225 | STAMCOUNTER StatMovDRx;
|
---|
226 | STAMCOUNTER StatIret;
|
---|
227 | STAMCOUNTER StatMovLgdt;
|
---|
228 | STAMCOUNTER StatMovLldt;
|
---|
229 | STAMCOUNTER StatMovLidt;
|
---|
230 | STAMCOUNTER StatMisc;
|
---|
231 | STAMCOUNTER StatSysEnter;
|
---|
232 | STAMCOUNTER StatSysExit;
|
---|
233 | STAMCOUNTER StatSysCall;
|
---|
234 | STAMCOUNTER StatSysRet;
|
---|
235 | /** @} */
|
---|
236 |
|
---|
237 | } EMSTATS, *PEMSTATS;
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * EM VM Instance data.
|
---|
241 | * Changes to this must checked against the padding of the cfgm union in VM!
|
---|
242 | */
|
---|
243 | typedef struct EM
|
---|
244 | {
|
---|
245 | /** Offset to the VM structure.
|
---|
246 | * See EM2VM(). */
|
---|
247 | RTUINT offVM;
|
---|
248 |
|
---|
249 | /** Execution Manager State. */
|
---|
250 | volatile EMSTATE enmState;
|
---|
251 | /** Force raw-mode execution.
|
---|
252 | * This is used to prevent REM from trying to execute patch code.
|
---|
253 | * The flag is cleared upon entering emR3RawExecute() and updated in certain return paths. */
|
---|
254 | bool fForceRAW;
|
---|
255 |
|
---|
256 | #ifdef DEBUG_TRACING_ENABLED
|
---|
257 | /** @see DEBUG_TRACING_ENABLED */
|
---|
258 | bool fTracing;
|
---|
259 | #endif
|
---|
260 |
|
---|
261 | /** Inhibit interrupts for this instruction. Valid only when VM_FF_INHIBIT_INTERRUPTS is set. */
|
---|
262 | RTGCUINTPTR GCPtrInhibitInterrupts;
|
---|
263 |
|
---|
264 |
|
---|
265 | /** Pointer to the PATM status structure. (HC Ptr) */
|
---|
266 | HCPTRTYPE(PPATMGCSTATE) pPatmGCState;
|
---|
267 |
|
---|
268 | /** Pointer to the guest CPUM state. (HC Ptr) */
|
---|
269 | HCPTRTYPE(PCPUMCTX) pCtx;
|
---|
270 |
|
---|
271 |
|
---|
272 | union
|
---|
273 | {
|
---|
274 | /** Padding used in the other rings.
|
---|
275 | * This must be larger than jmp_buf on any supported platform. */
|
---|
276 | char achPaddingFatalLongJump[HC_ARCH_BITS == 32 ? 176 : 256];
|
---|
277 | #ifdef IN_RING3
|
---|
278 | /** Long buffer jump for fatal VM errors.
|
---|
279 | * It will jump to before the outer EM loop is entered. */
|
---|
280 | jmp_buf FatalLongJump;
|
---|
281 | #endif
|
---|
282 | } u;
|
---|
283 |
|
---|
284 | /** @name Execution profiling.
|
---|
285 | * @{ */
|
---|
286 | STAMPROFILE StatForcedActions;
|
---|
287 | STAMPROFILE StatHalted;
|
---|
288 | STAMPROFILEADV StatHwAccEntry;
|
---|
289 | STAMPROFILE StatHwAccExec;
|
---|
290 | STAMPROFILE StatREMEmu;
|
---|
291 | STAMPROFILE StatREMExec;
|
---|
292 | STAMPROFILE StatREMSync;
|
---|
293 | STAMPROFILEADV StatREMTotal;
|
---|
294 | STAMPROFILE StatRAWExec;
|
---|
295 | STAMPROFILEADV StatRAWEntry;
|
---|
296 | STAMPROFILEADV StatRAWTail;
|
---|
297 | STAMPROFILEADV StatRAWTotal;
|
---|
298 | STAMPROFILEADV StatTotal;
|
---|
299 | /** @} */
|
---|
300 |
|
---|
301 | /** HC: Profiling of emR3RawExecuteIOInstruction. */
|
---|
302 | STAMPROFILE StatIOEmu;
|
---|
303 | /** HC: Profiling of emR3RawPrivileged. */
|
---|
304 | STAMPROFILE StatPrivEmu;
|
---|
305 | /** HC: Profiling of emR3RawExecuteInstruction. */
|
---|
306 | STAMPROFILE StatMiscEmu;
|
---|
307 |
|
---|
308 | /** @todo r=bird: Are any of these actually used? */
|
---|
309 | STAMCOUNTER StatPatchTrap;
|
---|
310 | STAMCOUNTER StatPatchInt3;
|
---|
311 | STAMCOUNTER StatPatchIF0;
|
---|
312 | STAMCOUNTER StatPatchEmulate;
|
---|
313 | STAMCOUNTER StatPageOutOfSync;
|
---|
314 | STAMCOUNTER StatHwAccExecuteEntry;
|
---|
315 |
|
---|
316 | /** More statistics (HC). */
|
---|
317 | HCPTRTYPE(PEMSTATS) pStatsHC;
|
---|
318 | /** More statistics (GC). */
|
---|
319 | GCPTRTYPE(PEMSTATS) pStatsGC;
|
---|
320 | #if HC_ARCH_BITS != GC_ARCH_BITS && GC_ARCH_BITS == 32
|
---|
321 | RTGCPTR padding0;
|
---|
322 | #endif
|
---|
323 |
|
---|
324 | /** Tree for keeping track of cli occurances (debug only). */
|
---|
325 | HCPTRTYPE(PAVLPVNODECORE) pCliStatTree;
|
---|
326 | STAMCOUNTER StatTotalClis;
|
---|
327 | #if 0
|
---|
328 | /** 64-bit Visual C++ rounds the struct size up to 16 byte. */
|
---|
329 | uint64_t padding1;
|
---|
330 | #endif
|
---|
331 |
|
---|
332 | } EM;
|
---|
333 | /** Pointer to EM VM instance data. */
|
---|
334 | typedef EM *PEM;
|
---|
335 |
|
---|
336 |
|
---|
337 |
|
---|
338 | /** @} */
|
---|
339 |
|
---|
340 | __END_DECLS
|
---|
341 |
|
---|
342 | #endif
|
---|
343 |
|
---|