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