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