VirtualBox

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

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

Implemented mwait extension for breaking on external interrupt when IF=0; completely untested

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