VirtualBox

source: vbox/trunk/src/VBox/VMM/EMInternal.h@ 26600

Last change on this file since 26600 was 26260, checked in by vboxsync, 15 years ago

EM: Corrected the pCliStatTree type.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.6 KB
Line 
1/* $Id: EMInternal.h 26260 2010-02-05 01:37:57Z 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 <VBox/pdmcritsect.h>
32#include <iprt/avl.h>
33#include <setjmp.h>
34
35RT_C_DECLS_BEGIN
36
37
38/** @defgroup grp_em_int Internal
39 * @ingroup grp_em
40 * @internal
41 * @{
42 */
43
44/** The saved state version. */
45#define EM_SAVED_STATE_VERSION 3
46#define EM_SAVED_STATE_VERSION_PRE_SMP 2
47
48/**
49 * Cli node structure
50 */
51typedef struct CLISTAT
52{
53 /** The key is the cli address. */
54 AVLGCPTRNODECORE Core;
55 /** Occurrences. */
56 STAMCOUNTER Counter;
57} CLISTAT, *PCLISTAT;
58
59
60/**
61 * Excessive EM statistics.
62 */
63typedef struct EMSTATS
64{
65 /** GC: Profiling of EMInterpretInstruction(). */
66 STAMPROFILE StatRZEmulate;
67 /** HC: Profiling of EMInterpretInstruction(). */
68 STAMPROFILE StatR3Emulate;
69
70 /** @name Interpreter Instruction statistics.
71 * @{
72 */
73 STAMCOUNTER StatRZInterpretSucceeded;
74 STAMCOUNTER StatR3InterpretSucceeded;
75
76 STAMCOUNTER StatRZAnd;
77 STAMCOUNTER StatR3And;
78 STAMCOUNTER StatRZCpuId;
79 STAMCOUNTER StatR3CpuId;
80 STAMCOUNTER StatRZDec;
81 STAMCOUNTER StatR3Dec;
82 STAMCOUNTER StatRZHlt;
83 STAMCOUNTER StatR3Hlt;
84 STAMCOUNTER StatRZInc;
85 STAMCOUNTER StatR3Inc;
86 STAMCOUNTER StatRZInvlPg;
87 STAMCOUNTER StatR3InvlPg;
88 STAMCOUNTER StatRZIret;
89 STAMCOUNTER StatR3Iret;
90 STAMCOUNTER StatRZLLdt;
91 STAMCOUNTER StatR3LLdt;
92 STAMCOUNTER StatRZLIdt;
93 STAMCOUNTER StatR3LIdt;
94 STAMCOUNTER StatRZLGdt;
95 STAMCOUNTER StatR3LGdt;
96 STAMCOUNTER StatRZMov;
97 STAMCOUNTER StatR3Mov;
98 STAMCOUNTER StatRZMovCRx;
99 STAMCOUNTER StatR3MovCRx;
100 STAMCOUNTER StatRZMovDRx;
101 STAMCOUNTER StatR3MovDRx;
102 STAMCOUNTER StatRZOr;
103 STAMCOUNTER StatR3Or;
104 STAMCOUNTER StatRZPop;
105 STAMCOUNTER StatR3Pop;
106 STAMCOUNTER StatRZSti;
107 STAMCOUNTER StatR3Sti;
108 STAMCOUNTER StatRZXchg;
109 STAMCOUNTER StatR3Xchg;
110 STAMCOUNTER StatRZXor;
111 STAMCOUNTER StatR3Xor;
112 STAMCOUNTER StatRZMonitor;
113 STAMCOUNTER StatR3Monitor;
114 STAMCOUNTER StatRZMWait;
115 STAMCOUNTER StatR3MWait;
116 STAMCOUNTER StatRZAdd;
117 STAMCOUNTER StatR3Add;
118 STAMCOUNTER StatRZSub;
119 STAMCOUNTER StatR3Sub;
120 STAMCOUNTER StatRZAdc;
121 STAMCOUNTER StatR3Adc;
122 STAMCOUNTER StatRZRdtsc;
123 STAMCOUNTER StatR3Rdtsc;
124 STAMCOUNTER StatRZRdpmc;
125 STAMCOUNTER StatR3Rdpmc;
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 StatRZFailedRdpmc;
236 STAMCOUNTER StatR3FailedRdpmc;
237 STAMCOUNTER StatRZFailedClts;
238 STAMCOUNTER StatR3FailedClts;
239
240 STAMCOUNTER StatRZFailedUserMode;
241 STAMCOUNTER StatR3FailedUserMode;
242 STAMCOUNTER StatRZFailedPrefix;
243 STAMCOUNTER StatR3FailedPrefix;
244 /** @} */
245
246 /** @name Privileged Instructions Ending Up In HC.
247 * @{ */
248 STAMCOUNTER StatCli;
249 STAMCOUNTER StatSti;
250 STAMCOUNTER StatIn;
251 STAMCOUNTER StatIoRestarted;
252 STAMCOUNTER StatOut;
253 STAMCOUNTER StatInvlpg;
254 STAMCOUNTER StatHlt;
255 STAMCOUNTER StatMovReadCR[USE_REG_CR4 + 1];
256 STAMCOUNTER StatMovWriteCR[USE_REG_CR4 + 1];
257 STAMCOUNTER StatMovDRx;
258 STAMCOUNTER StatIret;
259 STAMCOUNTER StatMovLgdt;
260 STAMCOUNTER StatMovLldt;
261 STAMCOUNTER StatMovLidt;
262 STAMCOUNTER StatMisc;
263 STAMCOUNTER StatSysEnter;
264 STAMCOUNTER StatSysExit;
265 STAMCOUNTER StatSysCall;
266 STAMCOUNTER StatSysRet;
267 /** @} */
268
269} EMSTATS;
270/** Pointer to the excessive EM statistics. */
271typedef EMSTATS *PEMSTATS;
272
273
274/**
275 * Converts a EM pointer into a VM pointer.
276 * @returns Pointer to the VM structure the EM is part of.
277 * @param pEM Pointer to EM instance data.
278 */
279#define EM2VM(pEM) ( (PVM)((char*)pEM - pEM->offVM) )
280
281/**
282 * EM VM Instance data.
283 * Changes to this must checked against the padding of the cfgm union in VM!
284 */
285typedef struct EM
286{
287 /** Offset to the VM structure.
288 * See EM2VM(). */
289 RTUINT offVM;
290
291 /** Id of the VCPU that last executed code in the recompiler. */
292 VMCPUID idLastRemCpu;
293
294 /** REM critical section.
295 * This protects recompiler usage
296 */
297 PDMCRITSECT CritSectREM;
298} EM;
299/** Pointer to EM VM instance data. */
300typedef EM *PEM;
301
302
303/**
304 * EM VMCPU Instance data.
305 */
306typedef struct EMCPU
307{
308 /** Offset to the VM structure.
309 * See EMCPU2VM(). */
310 RTUINT offVMCPU;
311
312 /** Execution Manager State. */
313 EMSTATE volatile enmState;
314
315 /** Previous Execution Manager State. */
316 EMSTATE enmPrevState;
317
318 /** Force raw-mode execution.
319 * This is used to prevent REM from trying to execute patch code.
320 * The flag is cleared upon entering emR3RawExecute() and updated in certain return paths. */
321 bool fForceRAW;
322
323 uint8_t u8Padding[3];
324
325 /** Inhibit interrupts for this instruction. Valid only when VM_FF_INHIBIT_INTERRUPTS is set. */
326 RTGCUINTPTR GCPtrInhibitInterrupts;
327
328 /** Pointer to the PATM status structure. (R3 Ptr) */
329 R3PTRTYPE(PPATMGCSTATE) pPatmGCState;
330
331 /** Pointer to the guest CPUM state. (R3 Ptr) */
332 R3PTRTYPE(PCPUMCTX) pCtx;
333
334#if GC_ARCH_BITS == 64
335 RTGCPTR aPadding1;
336#endif
337
338 union
339 {
340 /** Padding used in the other rings.
341 * This must be larger than jmp_buf on any supported platform. */
342 char achPaddingFatalLongJump[HC_ARCH_BITS == 32 ? 176 : 256];
343#ifdef IN_RING3
344 /** Long buffer jump for fatal VM errors.
345 * It will jump to before the outer EM loop is entered. */
346 jmp_buf FatalLongJump;
347#endif
348 } u;
349
350 /** For saving stack space, the disassembler state is allocated here instead of
351 * on the stack.
352 * @note The DISCPUSTATE structure is not R3/R0/RZ clean! */
353 union
354 {
355 /** The disassembler scratch space. */
356 DISCPUSTATE DisState;
357 /** Padding. */
358 uint8_t abDisStatePadding[DISCPUSTATE_PADDING_SIZE];
359 };
360
361 /** @name Execution profiling.
362 * @{ */
363 STAMPROFILE StatForcedActions;
364 STAMPROFILE StatHalted;
365 STAMPROFILEADV StatHwAccEntry;
366 STAMPROFILE StatHwAccExec;
367 STAMPROFILE StatREMEmu;
368 STAMPROFILE StatREMExec;
369 STAMPROFILE StatREMSync;
370 STAMPROFILEADV StatREMTotal;
371 STAMPROFILE StatRAWExec;
372 STAMPROFILEADV StatRAWEntry;
373 STAMPROFILEADV StatRAWTail;
374 STAMPROFILEADV StatRAWTotal;
375 STAMPROFILEADV StatTotal;
376 /** @} */
377
378 /** R3: Profiling of emR3RawExecuteIOInstruction. */
379 STAMPROFILE StatIOEmu;
380 /** R3: Profiling of emR3RawPrivileged. */
381 STAMPROFILE StatPrivEmu;
382 /** R3: Number of time emR3HwAccExecute is called. */
383 STAMCOUNTER StatHwAccExecuteEntry;
384
385 /** More statistics (R3). */
386 R3PTRTYPE(PEMSTATS) pStatsR3;
387 /** More statistics (R0). */
388 R0PTRTYPE(PEMSTATS) pStatsR0;
389 /** More statistics (RC). */
390 RCPTRTYPE(PEMSTATS) pStatsRC;
391#if HC_ARCH_BITS == 64
392 RTRCPTR padding0;
393#endif
394
395 /** Tree for keeping track of cli occurances (debug only). */
396 R3PTRTYPE(PAVLGCPTRNODECORE) pCliStatTree;
397 STAMCOUNTER StatTotalClis;
398#if 0
399 /** 64-bit Visual C++ rounds the struct size up to 16 byte. */
400 uint64_t padding1;
401#endif
402} EMCPU;
403/** Pointer to EM VM instance data. */
404typedef EMCPU *PEMCPU;
405
406/** @} */
407
408
409int emR3HwAccExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
410int emR3RawExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
411int emR3RawHandleRC(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
412int emR3HwaccmHandleRC(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
413EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
414int emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
415int emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
416int emR3RawUpdateForceFlag(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
417int emR3RawResumeHyper(PVM pVM, PVMCPU pVCpu);
418int emR3RawStep(PVM pVM, PVMCPU pVCpu);
419int emR3SingleStepExecRem(PVM pVM, PVMCPU pVCpu, uint32_t cIterations);
420
421RT_C_DECLS_END
422
423#endif
424
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette