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