VirtualBox

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

Last change on this file since 40274 was 40274, checked in by vboxsync, 13 years ago

Introduced VBOX_WITH_REM in Config.kmk and the VMM.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.0 KB
Line 
1/* $Id: EMInternal.h 40274 2012-02-28 13:17:35Z vboxsync $ */
2/** @file
3 * EM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
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
18#ifndef ___EMInternal_h
19#define ___EMInternal_h
20
21#include <VBox/cdefs.h>
22#include <VBox/types.h>
23#include <VBox/vmm/em.h>
24#include <VBox/vmm/stam.h>
25#include <VBox/vmm/patm.h>
26#include <VBox/dis.h>
27#include <VBox/vmm/pdmcritsect.h>
28#include <iprt/avl.h>
29#include <setjmp.h>
30
31RT_C_DECLS_BEGIN
32
33
34/** @defgroup grp_em_int Internal
35 * @ingroup grp_em
36 * @internal
37 * @{
38 */
39
40/** The saved state version. */
41#define EM_SAVED_STATE_VERSION 4
42#define EM_SAVED_STATE_VERSION_PRE_MWAIT 3
43#define EM_SAVED_STATE_VERSION_PRE_SMP 2
44
45
46/**
47 * MWait state flags.
48 */
49/* MWait activated. */
50#define EMMWAIT_FLAG_ACTIVE RT_BIT(0)
51/* MWait will continue when an interrupt is pending even when IF=0. */
52#define EMMWAIT_FLAG_BREAKIRQIF0 RT_BIT(1)
53/* Monitor instruction was executed previously. */
54#define EMMWAIT_FLAG_MONITOR_ACTIVE RT_BIT(2)
55
56/** EM time slice in ms; used for capping execution time. */
57#define EM_TIME_SLICE 100
58
59/**
60 * Cli node structure
61 */
62typedef struct CLISTAT
63{
64 /** The key is the cli address. */
65 AVLGCPTRNODECORE Core;
66#if HC_ARCH_BITS == 32 && !defined(RT_OS_WINDOWS)
67 /** Padding. */
68 uint32_t u32Padding;
69#endif
70 /** Occurrences. */
71 STAMCOUNTER Counter;
72} CLISTAT, *PCLISTAT;
73#ifdef IN_RING3
74AssertCompileMemberAlignment(CLISTAT, Counter, 8);
75#endif
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#ifdef VBOX_WITH_REM
313 /** REM critical section.
314 * This protects recompiler usage
315 */
316 PDMCRITSECT CritSectREM;
317#endif
318} EM;
319/** Pointer to EM VM instance data. */
320typedef EM *PEM;
321
322
323/**
324 * EM VMCPU Instance data.
325 */
326typedef struct EMCPU
327{
328 /** Offset to the VM structure.
329 * See EMCPU2VM(). */
330 RTUINT offVMCPU;
331
332 /** Execution Manager State. */
333 EMSTATE volatile enmState;
334
335 /** Previous Execution Manager State. */
336 EMSTATE enmPrevState;
337
338 /** Force raw-mode execution.
339 * This is used to prevent REM from trying to execute patch code.
340 * The flag is cleared upon entering emR3RawExecute() and updated in certain return paths. */
341 bool fForceRAW;
342
343 uint8_t u8Padding[3];
344
345 /** Inhibit interrupts for this instruction. Valid only when VM_FF_INHIBIT_INTERRUPTS is set. */
346 RTGCUINTPTR GCPtrInhibitInterrupts;
347
348 /** Pointer to the PATM status structure. (R3 Ptr) */
349 R3PTRTYPE(PPATMGCSTATE) pPatmGCState;
350
351 /** Pointer to the guest CPUM state. (R3 Ptr) */
352 R3PTRTYPE(PCPUMCTX) pCtx;
353
354#if GC_ARCH_BITS == 64
355 RTGCPTR aPadding1;
356#endif
357
358 /** Start of the current time slice in ms. */
359 uint64_t u64TimeSliceStart;
360 /** Start of the current time slice in thread execution time (ms). */
361 uint64_t u64TimeSliceStartExec;
362 /** Current time slice value. */
363 uint64_t u64TimeSliceExec;
364 uint64_t u64Alignment;
365
366 /* MWait halt state. */
367 struct
368 {
369 uint32_t fWait; /* type of mwait; see EMMWAIT_FLAG_* */
370 uint32_t a32Padding[1];
371 RTGCPTR uMWaitEAX; /* mwait hints */
372 RTGCPTR uMWaitECX; /* mwait extensions */
373 RTGCPTR uMonitorEAX; /* monitored address. */
374 RTGCPTR uMonitorECX; /* monitor extension. */
375 RTGCPTR uMonitorEDX; /* monitor hint. */
376 } mwait;
377
378 union
379 {
380 /** Padding used in the other rings.
381 * This must be larger than jmp_buf on any supported platform. */
382 char achPaddingFatalLongJump[HC_ARCH_BITS == 32 ? 176 : 256];
383#ifdef IN_RING3
384 /** Long buffer jump for fatal VM errors.
385 * It will jump to before the outer EM loop is entered. */
386 jmp_buf FatalLongJump;
387#endif
388 } u;
389
390 /** For saving stack space, the disassembler state is allocated here instead of
391 * on the stack.
392 * @note The DISCPUSTATE structure is not R3/R0/RZ clean! */
393 union
394 {
395 /** The disassembler scratch space. */
396 DISCPUSTATE DisState;
397 /** Padding. */
398 uint8_t abDisStatePadding[DISCPUSTATE_PADDING_SIZE];
399 };
400
401 /** @name Execution profiling.
402 * @{ */
403 STAMPROFILE StatForcedActions;
404 STAMPROFILE StatHalted;
405 STAMPROFILEADV StatCapped;
406 STAMPROFILEADV StatHwAccEntry;
407 STAMPROFILE StatHwAccExec;
408 STAMPROFILE StatREMEmu;
409 STAMPROFILE StatREMExec;
410 STAMPROFILE StatREMSync;
411 STAMPROFILEADV StatREMTotal;
412 STAMPROFILE StatRAWExec;
413 STAMPROFILEADV StatRAWEntry;
414 STAMPROFILEADV StatRAWTail;
415 STAMPROFILEADV StatRAWTotal;
416 STAMPROFILEADV StatTotal;
417 /** @} */
418
419 /** R3: Profiling of emR3RawExecuteIOInstruction. */
420 STAMPROFILE StatIOEmu;
421 /** R3: Profiling of emR3RawPrivileged. */
422 STAMPROFILE StatPrivEmu;
423 /** R3: Number of time emR3HwAccExecute is called. */
424 STAMCOUNTER StatHwAccExecuteEntry;
425
426 /** More statistics (R3). */
427 R3PTRTYPE(PEMSTATS) pStatsR3;
428 /** More statistics (R0). */
429 R0PTRTYPE(PEMSTATS) pStatsR0;
430 /** More statistics (RC). */
431 RCPTRTYPE(PEMSTATS) pStatsRC;
432#if HC_ARCH_BITS == 64
433 RTRCPTR padding0;
434#endif
435
436 /** Tree for keeping track of cli occurrences (debug only). */
437 R3PTRTYPE(PAVLGCPTRNODECORE) pCliStatTree;
438 STAMCOUNTER StatTotalClis;
439#if 0
440 /** 64-bit Visual C++ rounds the struct size up to 16 byte. */
441 uint64_t padding1;
442#endif
443} EMCPU;
444/** Pointer to EM VM instance data. */
445typedef EMCPU *PEMCPU;
446
447/** @} */
448
449
450int emR3HwAccExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
451int emR3RawExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
452int emR3RawHandleRC(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
453int emR3HwaccmHandleRC(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
454EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
455int emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
456int emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
457int emR3RawUpdateForceFlag(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
458int emR3RawResumeHyper(PVM pVM, PVMCPU pVCpu);
459int emR3RawStep(PVM pVM, PVMCPU pVCpu);
460int emR3SingleStepExecRem(PVM pVM, PVMCPU pVCpu, uint32_t cIterations);
461
462RT_C_DECLS_END
463
464#endif
465
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