VirtualBox

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

Last change on this file since 43624 was 43392, checked in by vboxsync, 12 years ago

VMM: HM cleanup.

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