VirtualBox

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

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

EMInternal.h: Fixed assertion caused by emR3RecordCli on 32-bit systems, except windows.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.6 KB
Line 
1/* $Id: EMInternal.h 27567 2010-03-22 00:03:02Z 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 4
46#define EM_SAVED_STATE_VERSION_PRE_MWAIT 3
47#define EM_SAVED_STATE_VERSION_PRE_SMP 2
48
49
50/**
51 * MWait state flags.
52 */
53/* MWait activated. */
54#define EMMWAIT_FLAG_ACTIVE RT_BIT(0)
55/* MWait will continue when an interrupt is pending even when IF=0. */
56#define EMMWAIT_FLAG_BREAKIRQIF0 RT_BIT(1)
57/* Monitor instruction was executed previously. */
58#define EMMWAIT_FLAG_MONITOR_ACTIVE RT_BIT(2)
59
60
61/**
62 * Cli node structure
63 */
64typedef struct CLISTAT
65{
66 /** The key is the cli address. */
67 AVLGCPTRNODECORE Core;
68#if HC_ARCH_BITS == 32 && !defined(RT_OS_WINDOWS)
69 /** Padding. */
70 uint32_t u32Padding;
71#endif
72 /** Occurrences. */
73 STAMCOUNTER Counter;
74} CLISTAT, *PCLISTAT;
75AssertCompileMemberAlignment(CLISTAT, Counter, 8);
76
77
78/**
79 * Excessive EM statistics.
80 */
81typedef struct EMSTATS
82{
83 /** GC: Profiling of EMInterpretInstruction(). */
84 STAMPROFILE StatRZEmulate;
85 /** HC: Profiling of EMInterpretInstruction(). */
86 STAMPROFILE StatR3Emulate;
87
88 /** @name Interpreter Instruction statistics.
89 * @{
90 */
91 STAMCOUNTER StatRZInterpretSucceeded;
92 STAMCOUNTER StatR3InterpretSucceeded;
93
94 STAMCOUNTER StatRZAnd;
95 STAMCOUNTER StatR3And;
96 STAMCOUNTER StatRZCpuId;
97 STAMCOUNTER StatR3CpuId;
98 STAMCOUNTER StatRZDec;
99 STAMCOUNTER StatR3Dec;
100 STAMCOUNTER StatRZHlt;
101 STAMCOUNTER StatR3Hlt;
102 STAMCOUNTER StatRZInc;
103 STAMCOUNTER StatR3Inc;
104 STAMCOUNTER StatRZInvlPg;
105 STAMCOUNTER StatR3InvlPg;
106 STAMCOUNTER StatRZIret;
107 STAMCOUNTER StatR3Iret;
108 STAMCOUNTER StatRZLLdt;
109 STAMCOUNTER StatR3LLdt;
110 STAMCOUNTER StatRZLIdt;
111 STAMCOUNTER StatR3LIdt;
112 STAMCOUNTER StatRZLGdt;
113 STAMCOUNTER StatR3LGdt;
114 STAMCOUNTER StatRZMov;
115 STAMCOUNTER StatR3Mov;
116 STAMCOUNTER StatRZMovCRx;
117 STAMCOUNTER StatR3MovCRx;
118 STAMCOUNTER StatRZMovDRx;
119 STAMCOUNTER StatR3MovDRx;
120 STAMCOUNTER StatRZOr;
121 STAMCOUNTER StatR3Or;
122 STAMCOUNTER StatRZPop;
123 STAMCOUNTER StatR3Pop;
124 STAMCOUNTER StatRZSti;
125 STAMCOUNTER StatR3Sti;
126 STAMCOUNTER StatRZXchg;
127 STAMCOUNTER StatR3Xchg;
128 STAMCOUNTER StatRZXor;
129 STAMCOUNTER StatR3Xor;
130 STAMCOUNTER StatRZMonitor;
131 STAMCOUNTER StatR3Monitor;
132 STAMCOUNTER StatRZMWait;
133 STAMCOUNTER StatR3MWait;
134 STAMCOUNTER StatRZAdd;
135 STAMCOUNTER StatR3Add;
136 STAMCOUNTER StatRZSub;
137 STAMCOUNTER StatR3Sub;
138 STAMCOUNTER StatRZAdc;
139 STAMCOUNTER StatR3Adc;
140 STAMCOUNTER StatRZRdtsc;
141 STAMCOUNTER StatR3Rdtsc;
142 STAMCOUNTER StatRZRdpmc;
143 STAMCOUNTER StatR3Rdpmc;
144 STAMCOUNTER StatRZBtr;
145 STAMCOUNTER StatR3Btr;
146 STAMCOUNTER StatRZBts;
147 STAMCOUNTER StatR3Bts;
148 STAMCOUNTER StatRZBtc;
149 STAMCOUNTER StatR3Btc;
150 STAMCOUNTER StatRZCmpXchg;
151 STAMCOUNTER StatR3CmpXchg;
152 STAMCOUNTER StatRZCmpXchg8b;
153 STAMCOUNTER StatR3CmpXchg8b;
154 STAMCOUNTER StatRZXAdd;
155 STAMCOUNTER StatR3XAdd;
156 STAMCOUNTER StatRZClts;
157 STAMCOUNTER StatR3Clts;
158 STAMCOUNTER StatRZStosWD;
159 STAMCOUNTER StatR3StosWD;
160 STAMCOUNTER StatR3Rdmsr;
161 STAMCOUNTER StatR3Wrmsr;
162 STAMCOUNTER StatRZRdmsr;
163 STAMCOUNTER StatRZWrmsr;
164 STAMCOUNTER StatRZWbInvd;
165 STAMCOUNTER StatR3WbInvd;
166 STAMCOUNTER StatRZLmsw;
167 STAMCOUNTER StatR3Lmsw;
168 STAMCOUNTER StatRZSmsw;
169 STAMCOUNTER StatR3Smsw;
170
171 STAMCOUNTER StatRZInterpretFailed;
172 STAMCOUNTER StatR3InterpretFailed;
173
174 STAMCOUNTER StatRZFailedAnd;
175 STAMCOUNTER StatR3FailedAnd;
176 STAMCOUNTER StatRZFailedCpuId;
177 STAMCOUNTER StatR3FailedCpuId;
178 STAMCOUNTER StatRZFailedDec;
179 STAMCOUNTER StatR3FailedDec;
180 STAMCOUNTER StatRZFailedHlt;
181 STAMCOUNTER StatR3FailedHlt;
182 STAMCOUNTER StatRZFailedInc;
183 STAMCOUNTER StatR3FailedInc;
184 STAMCOUNTER StatRZFailedInvlPg;
185 STAMCOUNTER StatR3FailedInvlPg;
186 STAMCOUNTER StatRZFailedIret;
187 STAMCOUNTER StatR3FailedIret;
188 STAMCOUNTER StatRZFailedLLdt;
189 STAMCOUNTER StatR3FailedLLdt;
190 STAMCOUNTER StatRZFailedLGdt;
191 STAMCOUNTER StatR3FailedLGdt;
192 STAMCOUNTER StatRZFailedLIdt;
193 STAMCOUNTER StatR3FailedLIdt;
194 STAMCOUNTER StatRZFailedMisc;
195 STAMCOUNTER StatR3FailedMisc;
196 STAMCOUNTER StatRZFailedMov;
197 STAMCOUNTER StatR3FailedMov;
198 STAMCOUNTER StatRZFailedMovCRx;
199 STAMCOUNTER StatR3FailedMovCRx;
200 STAMCOUNTER StatRZFailedMovDRx;
201 STAMCOUNTER StatR3FailedMovDRx;
202 STAMCOUNTER StatRZFailedOr;
203 STAMCOUNTER StatR3FailedOr;
204 STAMCOUNTER StatRZFailedPop;
205 STAMCOUNTER StatR3FailedPop;
206 STAMCOUNTER StatRZFailedSti;
207 STAMCOUNTER StatR3FailedSti;
208 STAMCOUNTER StatRZFailedXchg;
209 STAMCOUNTER StatR3FailedXchg;
210 STAMCOUNTER StatRZFailedXor;
211 STAMCOUNTER StatR3FailedXor;
212 STAMCOUNTER StatRZFailedMonitor;
213 STAMCOUNTER StatR3FailedMonitor;
214 STAMCOUNTER StatRZFailedMWait;
215 STAMCOUNTER StatR3FailedMWait;
216 STAMCOUNTER StatR3FailedRdmsr;
217 STAMCOUNTER StatR3FailedWrmsr;
218 STAMCOUNTER StatRZFailedRdmsr;
219 STAMCOUNTER StatRZFailedWrmsr;
220 STAMCOUNTER StatRZFailedLmsw;
221 STAMCOUNTER StatR3FailedLmsw;
222 STAMCOUNTER StatRZFailedSmsw;
223 STAMCOUNTER StatR3FailedSmsw;
224
225 STAMCOUNTER StatRZFailedAdd;
226 STAMCOUNTER StatR3FailedAdd;
227 STAMCOUNTER StatRZFailedAdc;
228 STAMCOUNTER StatR3FailedAdc;
229 STAMCOUNTER StatRZFailedBtr;
230 STAMCOUNTER StatR3FailedBtr;
231 STAMCOUNTER StatRZFailedBts;
232 STAMCOUNTER StatR3FailedBts;
233 STAMCOUNTER StatRZFailedBtc;
234 STAMCOUNTER StatR3FailedBtc;
235 STAMCOUNTER StatRZFailedCli;
236 STAMCOUNTER StatR3FailedCli;
237 STAMCOUNTER StatRZFailedCmpXchg;
238 STAMCOUNTER StatR3FailedCmpXchg;
239 STAMCOUNTER StatRZFailedCmpXchg8b;
240 STAMCOUNTER StatR3FailedCmpXchg8b;
241 STAMCOUNTER StatRZFailedXAdd;
242 STAMCOUNTER StatR3FailedXAdd;
243 STAMCOUNTER StatR3FailedMovNTPS;
244 STAMCOUNTER StatRZFailedMovNTPS;
245 STAMCOUNTER StatRZFailedStosWD;
246 STAMCOUNTER StatR3FailedStosWD;
247 STAMCOUNTER StatRZFailedSub;
248 STAMCOUNTER StatR3FailedSub;
249 STAMCOUNTER StatRZFailedWbInvd;
250 STAMCOUNTER StatR3FailedWbInvd;
251 STAMCOUNTER StatRZFailedRdtsc;
252 STAMCOUNTER StatR3FailedRdtsc;
253 STAMCOUNTER StatRZFailedRdpmc;
254 STAMCOUNTER StatR3FailedRdpmc;
255 STAMCOUNTER StatRZFailedClts;
256 STAMCOUNTER StatR3FailedClts;
257
258 STAMCOUNTER StatRZFailedUserMode;
259 STAMCOUNTER StatR3FailedUserMode;
260 STAMCOUNTER StatRZFailedPrefix;
261 STAMCOUNTER StatR3FailedPrefix;
262 /** @} */
263
264 /** @name Privileged Instructions Ending Up In HC.
265 * @{ */
266 STAMCOUNTER StatCli;
267 STAMCOUNTER StatSti;
268 STAMCOUNTER StatIn;
269 STAMCOUNTER StatIoRestarted;
270 STAMCOUNTER StatOut;
271 STAMCOUNTER StatInvlpg;
272 STAMCOUNTER StatHlt;
273 STAMCOUNTER StatMovReadCR[USE_REG_CR4 + 1];
274 STAMCOUNTER StatMovWriteCR[USE_REG_CR4 + 1];
275 STAMCOUNTER StatMovDRx;
276 STAMCOUNTER StatIret;
277 STAMCOUNTER StatMovLgdt;
278 STAMCOUNTER StatMovLldt;
279 STAMCOUNTER StatMovLidt;
280 STAMCOUNTER StatMisc;
281 STAMCOUNTER StatSysEnter;
282 STAMCOUNTER StatSysExit;
283 STAMCOUNTER StatSysCall;
284 STAMCOUNTER StatSysRet;
285 /** @} */
286
287} EMSTATS;
288/** Pointer to the excessive EM statistics. */
289typedef EMSTATS *PEMSTATS;
290
291
292/**
293 * Converts a EM pointer into a VM pointer.
294 * @returns Pointer to the VM structure the EM is part of.
295 * @param pEM Pointer to EM instance data.
296 */
297#define EM2VM(pEM) ( (PVM)((char*)pEM - pEM->offVM) )
298
299/**
300 * EM VM Instance data.
301 * Changes to this must checked against the padding of the cfgm union in VM!
302 */
303typedef struct EM
304{
305 /** Offset to the VM structure.
306 * See EM2VM(). */
307 RTUINT offVM;
308
309 /** Id of the VCPU that last executed code in the recompiler. */
310 VMCPUID idLastRemCpu;
311
312 /** REM critical section.
313 * This protects recompiler usage
314 */
315 PDMCRITSECT CritSectREM;
316} EM;
317/** Pointer to EM VM instance data. */
318typedef EM *PEM;
319
320
321/**
322 * EM VMCPU Instance data.
323 */
324typedef struct EMCPU
325{
326 /** Offset to the VM structure.
327 * See EMCPU2VM(). */
328 RTUINT offVMCPU;
329
330 /** Execution Manager State. */
331 EMSTATE volatile enmState;
332
333 /** Previous Execution Manager State. */
334 EMSTATE enmPrevState;
335
336 /** Force raw-mode execution.
337 * This is used to prevent REM from trying to execute patch code.
338 * The flag is cleared upon entering emR3RawExecute() and updated in certain return paths. */
339 bool fForceRAW;
340
341 uint8_t u8Padding[3];
342
343 /** Inhibit interrupts for this instruction. Valid only when VM_FF_INHIBIT_INTERRUPTS is set. */
344 RTGCUINTPTR GCPtrInhibitInterrupts;
345
346 /** Pointer to the PATM status structure. (R3 Ptr) */
347 R3PTRTYPE(PPATMGCSTATE) pPatmGCState;
348
349 /** Pointer to the guest CPUM state. (R3 Ptr) */
350 R3PTRTYPE(PCPUMCTX) pCtx;
351
352#if GC_ARCH_BITS == 64
353 RTGCPTR aPadding1;
354#endif
355
356 /* MWait halt state. */
357 struct
358 {
359 uint32_t fWait; /* type of mwait; see EMMWAIT_FLAG_* */
360 uint32_t a32Padding[1];
361 RTGCPTR uMWaitEAX; /* mwait hints */
362 RTGCPTR uMWaitECX; /* mwait extensions */
363 RTGCPTR uMonitorEAX; /* monitored address. */
364 RTGCPTR uMonitorECX; /* monitor extension. */
365 RTGCPTR uMonitorEDX; /* monitor hint. */
366 } mwait;
367
368 union
369 {
370 /** Padding used in the other rings.
371 * This must be larger than jmp_buf on any supported platform. */
372 char achPaddingFatalLongJump[HC_ARCH_BITS == 32 ? 176 : 256];
373#ifdef IN_RING3
374 /** Long buffer jump for fatal VM errors.
375 * It will jump to before the outer EM loop is entered. */
376 jmp_buf FatalLongJump;
377#endif
378 } u;
379
380 /** For saving stack space, the disassembler state is allocated here instead of
381 * on the stack.
382 * @note The DISCPUSTATE structure is not R3/R0/RZ clean! */
383 union
384 {
385 /** The disassembler scratch space. */
386 DISCPUSTATE DisState;
387 /** Padding. */
388 uint8_t abDisStatePadding[DISCPUSTATE_PADDING_SIZE];
389 };
390
391 /** @name Execution profiling.
392 * @{ */
393 STAMPROFILE StatForcedActions;
394 STAMPROFILE StatHalted;
395 STAMPROFILEADV StatHwAccEntry;
396 STAMPROFILE StatHwAccExec;
397 STAMPROFILE StatREMEmu;
398 STAMPROFILE StatREMExec;
399 STAMPROFILE StatREMSync;
400 STAMPROFILEADV StatREMTotal;
401 STAMPROFILE StatRAWExec;
402 STAMPROFILEADV StatRAWEntry;
403 STAMPROFILEADV StatRAWTail;
404 STAMPROFILEADV StatRAWTotal;
405 STAMPROFILEADV StatTotal;
406 /** @} */
407
408 /** R3: Profiling of emR3RawExecuteIOInstruction. */
409 STAMPROFILE StatIOEmu;
410 /** R3: Profiling of emR3RawPrivileged. */
411 STAMPROFILE StatPrivEmu;
412 /** R3: Number of time emR3HwAccExecute is called. */
413 STAMCOUNTER StatHwAccExecuteEntry;
414
415 /** More statistics (R3). */
416 R3PTRTYPE(PEMSTATS) pStatsR3;
417 /** More statistics (R0). */
418 R0PTRTYPE(PEMSTATS) pStatsR0;
419 /** More statistics (RC). */
420 RCPTRTYPE(PEMSTATS) pStatsRC;
421#if HC_ARCH_BITS == 64
422 RTRCPTR padding0;
423#endif
424
425 /** Tree for keeping track of cli occurances (debug only). */
426 R3PTRTYPE(PAVLGCPTRNODECORE) pCliStatTree;
427 STAMCOUNTER StatTotalClis;
428#if 0
429 /** 64-bit Visual C++ rounds the struct size up to 16 byte. */
430 uint64_t padding1;
431#endif
432} EMCPU;
433/** Pointer to EM VM instance data. */
434typedef EMCPU *PEMCPU;
435
436/** @} */
437
438
439int emR3HwAccExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
440int emR3RawExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
441int emR3RawHandleRC(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
442int emR3HwaccmHandleRC(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
443EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
444int emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
445int emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
446int emR3RawUpdateForceFlag(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
447int emR3RawResumeHyper(PVM pVM, PVMCPU pVCpu);
448int emR3RawStep(PVM pVM, PVMCPU pVCpu);
449int emR3SingleStepExecRem(PVM pVM, PVMCPU pVCpu, uint32_t cIterations);
450
451RT_C_DECLS_END
452
453#endif
454
Note: See TracBrowser for help on using the repository browser.

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