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