1 | /* $Id: EMInternal.h 12688 2008-09-24 14:22:18Z 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 | * Cli node structure
|
---|
52 | */
|
---|
53 | typedef struct CLISTAT
|
---|
54 | {
|
---|
55 | /** The key is the cli address. */
|
---|
56 | AVLPVNODECORE Core;
|
---|
57 | /** Occurrences. */
|
---|
58 | STAMCOUNTER Counter;
|
---|
59 | } CLISTAT, *PCLISTAT;
|
---|
60 |
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Excessive EM statistics.
|
---|
64 | */
|
---|
65 | typedef struct EMSTATS
|
---|
66 | {
|
---|
67 | /** GC: Profiling of EMInterpretInstruction(). */
|
---|
68 | STAMPROFILE StatRZEmulate;
|
---|
69 | /** HC: Profiling of EMInterpretInstruction(). */
|
---|
70 | STAMPROFILE StatR3Emulate;
|
---|
71 |
|
---|
72 | /** @name Interpreter Instruction statistics.
|
---|
73 | * @{
|
---|
74 | */
|
---|
75 | STAMCOUNTER StatRZInterpretSucceeded;
|
---|
76 | STAMCOUNTER StatR3InterpretSucceeded;
|
---|
77 |
|
---|
78 | STAMCOUNTER StatRZAnd;
|
---|
79 | STAMCOUNTER StatR3And;
|
---|
80 | STAMCOUNTER StatRZCpuId;
|
---|
81 | STAMCOUNTER StatR3CpuId;
|
---|
82 | STAMCOUNTER StatRZDec;
|
---|
83 | STAMCOUNTER StatR3Dec;
|
---|
84 | STAMCOUNTER StatRZHlt;
|
---|
85 | STAMCOUNTER StatR3Hlt;
|
---|
86 | STAMCOUNTER StatRZInc;
|
---|
87 | STAMCOUNTER StatR3Inc;
|
---|
88 | STAMCOUNTER StatRZInvlPg;
|
---|
89 | STAMCOUNTER StatR3InvlPg;
|
---|
90 | STAMCOUNTER StatRZIret;
|
---|
91 | STAMCOUNTER StatR3Iret;
|
---|
92 | STAMCOUNTER StatRZLLdt;
|
---|
93 | STAMCOUNTER StatR3LLdt;
|
---|
94 | STAMCOUNTER StatRZMov;
|
---|
95 | STAMCOUNTER StatR3Mov;
|
---|
96 | STAMCOUNTER StatRZMovCRx;
|
---|
97 | STAMCOUNTER StatR3MovCRx;
|
---|
98 | STAMCOUNTER StatRZMovDRx;
|
---|
99 | STAMCOUNTER StatR3MovDRx;
|
---|
100 | STAMCOUNTER StatRZOr;
|
---|
101 | STAMCOUNTER StatR3Or;
|
---|
102 | STAMCOUNTER StatRZPop;
|
---|
103 | STAMCOUNTER StatR3Pop;
|
---|
104 | STAMCOUNTER StatRZSti;
|
---|
105 | STAMCOUNTER StatR3Sti;
|
---|
106 | STAMCOUNTER StatRZXchg;
|
---|
107 | STAMCOUNTER StatR3Xchg;
|
---|
108 | STAMCOUNTER StatRZXor;
|
---|
109 | STAMCOUNTER StatR3Xor;
|
---|
110 | STAMCOUNTER StatRZMonitor;
|
---|
111 | STAMCOUNTER StatR3Monitor;
|
---|
112 | STAMCOUNTER StatRZMWait;
|
---|
113 | STAMCOUNTER StatR3MWait;
|
---|
114 | STAMCOUNTER StatRZAdd;
|
---|
115 | STAMCOUNTER StatR3Add;
|
---|
116 | STAMCOUNTER StatRZSub;
|
---|
117 | STAMCOUNTER StatR3Sub;
|
---|
118 | STAMCOUNTER StatRZAdc;
|
---|
119 | STAMCOUNTER StatR3Adc;
|
---|
120 | STAMCOUNTER StatRZRdtsc;
|
---|
121 | STAMCOUNTER StatR3Rdtsc;
|
---|
122 | STAMCOUNTER StatRZBtr;
|
---|
123 | STAMCOUNTER StatR3Btr;
|
---|
124 | STAMCOUNTER StatRZBts;
|
---|
125 | STAMCOUNTER StatR3Bts;
|
---|
126 | STAMCOUNTER StatRZBtc;
|
---|
127 | STAMCOUNTER StatR3Btc;
|
---|
128 | STAMCOUNTER StatRZCmpXchg;
|
---|
129 | STAMCOUNTER StatR3CmpXchg;
|
---|
130 | STAMCOUNTER StatRZCmpXchg8b;
|
---|
131 | STAMCOUNTER StatR3CmpXchg8b;
|
---|
132 | STAMCOUNTER StatRZXAdd;
|
---|
133 | STAMCOUNTER StatR3XAdd;
|
---|
134 | STAMCOUNTER StatRZClts;
|
---|
135 | STAMCOUNTER StatR3Clts;
|
---|
136 | STAMCOUNTER StatRZStosWD;
|
---|
137 | STAMCOUNTER StatR3StosWD;
|
---|
138 | STAMCOUNTER StatR3Rdmsr;
|
---|
139 | STAMCOUNTER StatR3Wrmsr;
|
---|
140 | STAMCOUNTER StatRZRdmsr;
|
---|
141 | STAMCOUNTER StatRZWrmsr;
|
---|
142 |
|
---|
143 | STAMCOUNTER StatRZInterpretFailed;
|
---|
144 | STAMCOUNTER StatR3InterpretFailed;
|
---|
145 |
|
---|
146 | STAMCOUNTER StatRZFailedAnd;
|
---|
147 | STAMCOUNTER StatR3FailedAnd;
|
---|
148 | STAMCOUNTER StatRZFailedCpuId;
|
---|
149 | STAMCOUNTER StatR3FailedCpuId;
|
---|
150 | STAMCOUNTER StatRZFailedDec;
|
---|
151 | STAMCOUNTER StatR3FailedDec;
|
---|
152 | STAMCOUNTER StatRZFailedHlt;
|
---|
153 | STAMCOUNTER StatR3FailedHlt;
|
---|
154 | STAMCOUNTER StatRZFailedInc;
|
---|
155 | STAMCOUNTER StatR3FailedInc;
|
---|
156 | STAMCOUNTER StatRZFailedInvlPg;
|
---|
157 | STAMCOUNTER StatR3FailedInvlPg;
|
---|
158 | STAMCOUNTER StatRZFailedIret;
|
---|
159 | STAMCOUNTER StatR3FailedIret;
|
---|
160 | STAMCOUNTER StatRZFailedLLdt;
|
---|
161 | STAMCOUNTER StatR3FailedLLdt;
|
---|
162 | STAMCOUNTER StatRZFailedMisc;
|
---|
163 | STAMCOUNTER StatR3FailedMisc;
|
---|
164 | STAMCOUNTER StatRZFailedMov;
|
---|
165 | STAMCOUNTER StatR3FailedMov;
|
---|
166 | STAMCOUNTER StatRZFailedMovCRx;
|
---|
167 | STAMCOUNTER StatR3FailedMovCRx;
|
---|
168 | STAMCOUNTER StatRZFailedMovDRx;
|
---|
169 | STAMCOUNTER StatR3FailedMovDRx;
|
---|
170 | STAMCOUNTER StatRZFailedOr;
|
---|
171 | STAMCOUNTER StatR3FailedOr;
|
---|
172 | STAMCOUNTER StatRZFailedPop;
|
---|
173 | STAMCOUNTER StatR3FailedPop;
|
---|
174 | STAMCOUNTER StatRZFailedSti;
|
---|
175 | STAMCOUNTER StatR3FailedSti;
|
---|
176 | STAMCOUNTER StatRZFailedXchg;
|
---|
177 | STAMCOUNTER StatR3FailedXchg;
|
---|
178 | STAMCOUNTER StatRZFailedXor;
|
---|
179 | STAMCOUNTER StatR3FailedXor;
|
---|
180 | STAMCOUNTER StatRZFailedMonitor;
|
---|
181 | STAMCOUNTER StatR3FailedMonitor;
|
---|
182 | STAMCOUNTER StatRZFailedMWait;
|
---|
183 | STAMCOUNTER StatR3FailedMWait;
|
---|
184 | STAMCOUNTER StatR3FailedRdmsr;
|
---|
185 | STAMCOUNTER StatR3FailedWrmsr;
|
---|
186 | STAMCOUNTER StatRZFailedRdmsr;
|
---|
187 | STAMCOUNTER StatRZFailedWrmsr;
|
---|
188 |
|
---|
189 | STAMCOUNTER StatRZFailedAdd;
|
---|
190 | STAMCOUNTER StatR3FailedAdd;
|
---|
191 | STAMCOUNTER StatRZFailedAdc;
|
---|
192 | STAMCOUNTER StatR3FailedAdc;
|
---|
193 | STAMCOUNTER StatRZFailedBtr;
|
---|
194 | STAMCOUNTER StatR3FailedBtr;
|
---|
195 | STAMCOUNTER StatRZFailedBts;
|
---|
196 | STAMCOUNTER StatR3FailedBts;
|
---|
197 | STAMCOUNTER StatRZFailedBtc;
|
---|
198 | STAMCOUNTER StatR3FailedBtc;
|
---|
199 | STAMCOUNTER StatRZFailedCli;
|
---|
200 | STAMCOUNTER StatR3FailedCli;
|
---|
201 | STAMCOUNTER StatRZFailedCmpXchg;
|
---|
202 | STAMCOUNTER StatR3FailedCmpXchg;
|
---|
203 | STAMCOUNTER StatRZFailedCmpXchg8b;
|
---|
204 | STAMCOUNTER StatR3FailedCmpXchg8b;
|
---|
205 | STAMCOUNTER StatRZFailedXAdd;
|
---|
206 | STAMCOUNTER StatR3FailedXAdd;
|
---|
207 | STAMCOUNTER StatR3FailedMovNTPS;
|
---|
208 | STAMCOUNTER StatRZFailedMovNTPS;
|
---|
209 | STAMCOUNTER StatRZFailedStosWD;
|
---|
210 | STAMCOUNTER StatR3FailedStosWD;
|
---|
211 | STAMCOUNTER StatRZFailedSub;
|
---|
212 | STAMCOUNTER StatR3FailedSub;
|
---|
213 | STAMCOUNTER StatRZFailedWbInvd;
|
---|
214 | STAMCOUNTER StatR3FailedWbInvd;
|
---|
215 | STAMCOUNTER StatRZFailedRdtsc;
|
---|
216 | STAMCOUNTER StatR3FailedRdtsc;
|
---|
217 | STAMCOUNTER StatRZFailedClts;
|
---|
218 | STAMCOUNTER StatR3FailedClts;
|
---|
219 |
|
---|
220 | STAMCOUNTER StatRZFailedUserMode;
|
---|
221 | STAMCOUNTER StatR3FailedUserMode;
|
---|
222 | STAMCOUNTER StatRZFailedPrefix;
|
---|
223 | STAMCOUNTER StatR3FailedPrefix;
|
---|
224 | /** @} */
|
---|
225 |
|
---|
226 | /** @name Privileged Instructions Ending Up In HC.
|
---|
227 | * @{ */
|
---|
228 | STAMCOUNTER StatCli;
|
---|
229 | STAMCOUNTER StatSti;
|
---|
230 | STAMCOUNTER StatIn;
|
---|
231 | STAMCOUNTER StatOut;
|
---|
232 | STAMCOUNTER StatInvlpg;
|
---|
233 | STAMCOUNTER StatHlt;
|
---|
234 | STAMCOUNTER StatMovReadCR[USE_REG_CR4 + 1];
|
---|
235 | STAMCOUNTER StatMovWriteCR[USE_REG_CR4 + 1];
|
---|
236 | STAMCOUNTER StatMovDRx;
|
---|
237 | STAMCOUNTER StatIret;
|
---|
238 | STAMCOUNTER StatMovLgdt;
|
---|
239 | STAMCOUNTER StatMovLldt;
|
---|
240 | STAMCOUNTER StatMovLidt;
|
---|
241 | STAMCOUNTER StatMisc;
|
---|
242 | STAMCOUNTER StatSysEnter;
|
---|
243 | STAMCOUNTER StatSysExit;
|
---|
244 | STAMCOUNTER StatSysCall;
|
---|
245 | STAMCOUNTER StatSysRet;
|
---|
246 | /** @} */
|
---|
247 |
|
---|
248 | } EMSTATS;
|
---|
249 | /** Pointer to the excessive EM statistics. */
|
---|
250 | typedef EMSTATS *PEMSTATS;
|
---|
251 |
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * Converts a EM pointer into a VM pointer.
|
---|
255 | * @returns Pointer to the VM structure the EM is part of.
|
---|
256 | * @param pEM Pointer to EM instance data.
|
---|
257 | */
|
---|
258 | #define EM2VM(pEM) ( (PVM)((char*)pEM - pEM->offVM) )
|
---|
259 |
|
---|
260 | /**
|
---|
261 | * EM VM Instance data.
|
---|
262 | * Changes to this must checked against the padding of the cfgm union in VM!
|
---|
263 | */
|
---|
264 | typedef struct EM
|
---|
265 | {
|
---|
266 | /** Offset to the VM structure.
|
---|
267 | * See EM2VM(). */
|
---|
268 | RTUINT offVM;
|
---|
269 |
|
---|
270 | /** Execution Manager State. */
|
---|
271 | EMSTATE volatile enmState;
|
---|
272 | /** Force raw-mode execution.
|
---|
273 | * This is used to prevent REM from trying to execute patch code.
|
---|
274 | * The flag is cleared upon entering emR3RawExecute() and updated in certain return paths. */
|
---|
275 | bool fForceRAW;
|
---|
276 |
|
---|
277 | #ifdef DEBUG_TRACING_ENABLED
|
---|
278 | /** @see DEBUG_TRACING_ENABLED */
|
---|
279 | bool fTracing;
|
---|
280 | #endif
|
---|
281 |
|
---|
282 | /* Set when the translation blocks in the recompiler cache need to be flushed. */
|
---|
283 | bool fREMFlushTBs;
|
---|
284 |
|
---|
285 | uint8_t u8Padding[GC_ARCH_BITS == 64 ? 5 : 1];
|
---|
286 |
|
---|
287 | /** Inhibit interrupts for this instruction. Valid only when VM_FF_INHIBIT_INTERRUPTS is set. */
|
---|
288 | RTGCUINTPTR GCPtrInhibitInterrupts;
|
---|
289 |
|
---|
290 |
|
---|
291 | /** Pointer to the PATM status structure. (R3 Ptr) */
|
---|
292 | R3PTRTYPE(PPATMGCSTATE) pPatmGCState;
|
---|
293 |
|
---|
294 | /** Pointer to the guest CPUM state. (R3 Ptr) */
|
---|
295 | R3PTRTYPE(PCPUMCTX) pCtx;
|
---|
296 |
|
---|
297 | #if GC_ARCH_BITS == 64
|
---|
298 | RTGCPTR aPadding1;
|
---|
299 | #endif
|
---|
300 |
|
---|
301 | union
|
---|
302 | {
|
---|
303 | /** Padding used in the other rings.
|
---|
304 | * This must be larger than jmp_buf on any supported platform. */
|
---|
305 | char achPaddingFatalLongJump[HC_ARCH_BITS == 32 ? 176 : 256];
|
---|
306 | #ifdef IN_RING3
|
---|
307 | /** Long buffer jump for fatal VM errors.
|
---|
308 | * It will jump to before the outer EM loop is entered. */
|
---|
309 | jmp_buf FatalLongJump;
|
---|
310 | #endif
|
---|
311 | } u;
|
---|
312 |
|
---|
313 | /** @name Execution profiling.
|
---|
314 | * @{ */
|
---|
315 | STAMPROFILE StatForcedActions;
|
---|
316 | STAMPROFILE StatHalted;
|
---|
317 | STAMPROFILEADV StatHwAccEntry;
|
---|
318 | STAMPROFILE StatHwAccExec;
|
---|
319 | STAMPROFILE StatREMEmu;
|
---|
320 | STAMPROFILE StatREMExec;
|
---|
321 | STAMPROFILE StatREMSync;
|
---|
322 | STAMPROFILEADV StatREMTotal;
|
---|
323 | STAMPROFILE StatRAWExec;
|
---|
324 | STAMPROFILEADV StatRAWEntry;
|
---|
325 | STAMPROFILEADV StatRAWTail;
|
---|
326 | STAMPROFILEADV StatRAWTotal;
|
---|
327 | STAMPROFILEADV StatTotal;
|
---|
328 | /** @} */
|
---|
329 |
|
---|
330 | /** R3: Profiling of emR3RawExecuteIOInstruction. */
|
---|
331 | STAMPROFILE StatIOEmu;
|
---|
332 | /** R3: Profiling of emR3RawPrivileged. */
|
---|
333 | STAMPROFILE StatPrivEmu;
|
---|
334 | /** R3: Profiling of emR3RawExecuteInstruction. */
|
---|
335 | STAMPROFILE StatMiscEmu;
|
---|
336 | /** R3: Number of time emR3HwAccExecute is called. */
|
---|
337 | STAMCOUNTER StatHwAccExecuteEntry;
|
---|
338 |
|
---|
339 | /** More statistics (R3). */
|
---|
340 | R3PTRTYPE(PEMSTATS) pStatsR3;
|
---|
341 | /** More statistics (R0). */
|
---|
342 | R0PTRTYPE(PEMSTATS) pStatsR0;
|
---|
343 | /** More statistics (RC). */
|
---|
344 | RCPTRTYPE(PEMSTATS) pStatsRC;
|
---|
345 | #if HC_ARCH_BITS == 64
|
---|
346 | RTRCPTR padding0;
|
---|
347 | #endif
|
---|
348 |
|
---|
349 | /** Tree for keeping track of cli occurances (debug only). */
|
---|
350 | R3PTRTYPE(PAVLPVNODECORE) pCliStatTree;
|
---|
351 | STAMCOUNTER StatTotalClis;
|
---|
352 | #if 0
|
---|
353 | /** 64-bit Visual C++ rounds the struct size up to 16 byte. */
|
---|
354 | uint64_t padding1;
|
---|
355 | #endif
|
---|
356 |
|
---|
357 | } EM;
|
---|
358 | /** Pointer to EM VM instance data. */
|
---|
359 | typedef EM *PEM;
|
---|
360 |
|
---|
361 |
|
---|
362 |
|
---|
363 | /** @} */
|
---|
364 |
|
---|
365 | __END_DECLS
|
---|
366 |
|
---|
367 | #endif
|
---|
368 |
|
---|