VirtualBox

source: vbox/trunk/src/VBox/VMM/EM.cpp@ 25414

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

EM: VINF_EM_SUSPEND should have higher priority than VINF_EM_RESET since EMR3Reset takes care of the important work now.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 97.3 KB
Line 
1/* $Id: EM.cpp 24938 2009-11-25 11:04:36Z vboxsync $ */
2/** @file
3 * EM - Execution Monitor / Manager.
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/** @page pg_em EM - The Execution Monitor / Manager
23 *
24 * The Execution Monitor/Manager is responsible for running the VM, scheduling
25 * the right kind of execution (Raw-mode, Hardware Assisted, Recompiled or
26 * Interpreted), and keeping the CPU states in sync. The function
27 * EMR3ExecuteVM() is the 'main-loop' of the VM, while each of the execution
28 * modes has different inner loops (emR3RawExecute, emR3HwAccExecute, and
29 * emR3RemExecute).
30 *
31 * The interpreted execution is only used to avoid switching between
32 * raw-mode/hwaccm and the recompiler when fielding virtualization traps/faults.
33 * The interpretation is thus implemented as part of EM.
34 *
35 * @see grp_em
36 */
37
38/*******************************************************************************
39* Header Files *
40*******************************************************************************/
41#define LOG_GROUP LOG_GROUP_EM
42#include <VBox/em.h>
43#include <VBox/vmm.h>
44#ifdef VBOX_WITH_VMI
45# include <VBox/parav.h>
46#endif
47#include <VBox/patm.h>
48#include <VBox/csam.h>
49#include <VBox/selm.h>
50#include <VBox/trpm.h>
51#include <VBox/iom.h>
52#include <VBox/dbgf.h>
53#include <VBox/pgm.h>
54#include <VBox/rem.h>
55#include <VBox/tm.h>
56#include <VBox/mm.h>
57#include <VBox/ssm.h>
58#include <VBox/pdmapi.h>
59#include <VBox/pdmcritsect.h>
60#include <VBox/pdmqueue.h>
61#include <VBox/hwaccm.h>
62#include <VBox/patm.h>
63#include "EMInternal.h"
64#include <VBox/vm.h>
65#include <VBox/cpumdis.h>
66#include <VBox/dis.h>
67#include <VBox/disopcode.h>
68#include <VBox/dbgf.h>
69
70#include <iprt/string.h>
71#include <iprt/stream.h>
72
73
74/*******************************************************************************
75* Defined Constants And Macros *
76*******************************************************************************/
77#if 0 /* Disabled till after 2.1.0 when we've time to test it. */
78#define EM_NOTIFY_HWACCM
79#endif
80
81
82/*******************************************************************************
83* Internal Functions *
84*******************************************************************************/
85static DECLCALLBACK(int) emR3Save(PVM pVM, PSSMHANDLE pSSM);
86static DECLCALLBACK(int) emR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
87static const char *emR3GetStateName(EMSTATE enmState);
88static int emR3Debug(PVM pVM, PVMCPU pVCpu, int rc);
89static int emR3RemStep(PVM pVM, PVMCPU pVCpu);
90static int emR3RemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
91DECLINLINE(int) emR3RawExecuteInstruction(PVM pVM, PVMCPU pVCpu, const char *pszPrefix, int rcGC = VINF_SUCCESS);
92int emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
93
94
95/**
96 * Initializes the EM.
97 *
98 * @returns VBox status code.
99 * @param pVM The VM to operate on.
100 */
101VMMR3DECL(int) EMR3Init(PVM pVM)
102{
103 LogFlow(("EMR3Init\n"));
104 /*
105 * Assert alignment and sizes.
106 */
107 AssertCompileMemberAlignment(VM, em.s, 32);
108 AssertCompile(sizeof(pVM->em.s) <= sizeof(pVM->em.padding));
109 AssertCompile(sizeof(pVM->aCpus[0].em.s.u.FatalLongJump) <= sizeof(pVM->aCpus[0].em.s.u.achPaddingFatalLongJump));
110 AssertCompileMemberAlignment(EM, CritSectREM, sizeof(uintptr_t));
111
112 /*
113 * Init the structure.
114 */
115 pVM->em.s.offVM = RT_OFFSETOF(VM, em.s);
116 int rc = CFGMR3QueryBool(CFGMR3GetRoot(pVM), "RawR3Enabled", &pVM->fRawR3Enabled);
117 if (RT_FAILURE(rc))
118 pVM->fRawR3Enabled = true;
119 rc = CFGMR3QueryBool(CFGMR3GetRoot(pVM), "RawR0Enabled", &pVM->fRawR0Enabled);
120 if (RT_FAILURE(rc))
121 pVM->fRawR0Enabled = true;
122 Log(("EMR3Init: fRawR3Enabled=%d fRawR0Enabled=%d\n", pVM->fRawR3Enabled, pVM->fRawR0Enabled));
123
124 /*
125 * Initialize the REM critical section.
126 */
127 rc = PDMR3CritSectInit(pVM, &pVM->em.s.CritSectREM, "EM-REM");
128 AssertRCReturn(rc, rc);
129
130 /*
131 * Saved state.
132 */
133 rc = SSMR3RegisterInternal(pVM, "em", 0, EM_SAVED_STATE_VERSION, 16,
134 NULL, NULL, NULL,
135 NULL, emR3Save, NULL,
136 NULL, emR3Load, NULL);
137 if (RT_FAILURE(rc))
138 return rc;
139
140 for (VMCPUID i = 0; i < pVM->cCpus; i++)
141 {
142 PVMCPU pVCpu = &pVM->aCpus[i];
143
144 pVCpu->em.s.offVMCPU = RT_OFFSETOF(VMCPU, em.s);
145
146 pVCpu->em.s.enmState = (i == 0) ? EMSTATE_NONE : EMSTATE_WAIT_SIPI;
147 pVCpu->em.s.enmPrevState = EMSTATE_NONE;
148 pVCpu->em.s.fForceRAW = false;
149
150 pVCpu->em.s.pCtx = CPUMQueryGuestCtxPtr(pVCpu);
151 pVCpu->em.s.pPatmGCState = PATMR3QueryGCStateHC(pVM);
152 AssertMsg(pVCpu->em.s.pPatmGCState, ("PATMR3QueryGCStateHC failed!\n"));
153
154# define EM_REG_COUNTER(a, b, c) \
155 rc = STAMR3RegisterF(pVM, a, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, c, b, i); \
156 AssertRC(rc);
157
158# define EM_REG_COUNTER_USED(a, b, c) \
159 rc = STAMR3RegisterF(pVM, a, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, c, b, i); \
160 AssertRC(rc);
161
162# define EM_REG_PROFILE(a, b, c) \
163 rc = STAMR3RegisterF(pVM, a, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, c, b, i); \
164 AssertRC(rc);
165
166# define EM_REG_PROFILE_ADV(a, b, c) \
167 rc = STAMR3RegisterF(pVM, a, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, c, b, i); \
168 AssertRC(rc);
169
170 /*
171 * Statistics.
172 */
173#ifdef VBOX_WITH_STATISTICS
174 PEMSTATS pStats;
175 rc = MMHyperAlloc(pVM, sizeof(*pStats), 0, MM_TAG_EM, (void **)&pStats);
176 if (RT_FAILURE(rc))
177 return rc;
178
179 pVCpu->em.s.pStatsR3 = pStats;
180 pVCpu->em.s.pStatsR0 = MMHyperR3ToR0(pVM, pStats);
181 pVCpu->em.s.pStatsRC = MMHyperR3ToRC(pVM, pStats);
182
183 EM_REG_PROFILE(&pStats->StatRZEmulate, "/EM/CPU%d/RZ/Interpret", "Profiling of EMInterpretInstruction.");
184 EM_REG_PROFILE(&pStats->StatR3Emulate, "/EM/CPU%d/R3/Interpret", "Profiling of EMInterpretInstruction.");
185
186 EM_REG_PROFILE(&pStats->StatRZInterpretSucceeded, "/EM/CPU%d/RZ/Interpret/Success", "The number of times an instruction was successfully interpreted.");
187 EM_REG_PROFILE(&pStats->StatR3InterpretSucceeded, "/EM/CPU%d/R3/Interpret/Success", "The number of times an instruction was successfully interpreted.");
188
189 EM_REG_COUNTER_USED(&pStats->StatRZAnd, "/EM/CPU%d/RZ/Interpret/Success/And", "The number of times AND was successfully interpreted.");
190 EM_REG_COUNTER_USED(&pStats->StatR3And, "/EM/CPU%d/R3/Interpret/Success/And", "The number of times AND was successfully interpreted.");
191 EM_REG_COUNTER_USED(&pStats->StatRZAdd, "/EM/CPU%d/RZ/Interpret/Success/Add", "The number of times ADD was successfully interpreted.");
192 EM_REG_COUNTER_USED(&pStats->StatR3Add, "/EM/CPU%d/R3/Interpret/Success/Add", "The number of times ADD was successfully interpreted.");
193 EM_REG_COUNTER_USED(&pStats->StatRZAdc, "/EM/CPU%d/RZ/Interpret/Success/Adc", "The number of times ADC was successfully interpreted.");
194 EM_REG_COUNTER_USED(&pStats->StatR3Adc, "/EM/CPU%d/R3/Interpret/Success/Adc", "The number of times ADC was successfully interpreted.");
195 EM_REG_COUNTER_USED(&pStats->StatRZSub, "/EM/CPU%d/RZ/Interpret/Success/Sub", "The number of times SUB was successfully interpreted.");
196 EM_REG_COUNTER_USED(&pStats->StatR3Sub, "/EM/CPU%d/R3/Interpret/Success/Sub", "The number of times SUB was successfully interpreted.");
197 EM_REG_COUNTER_USED(&pStats->StatRZCpuId, "/EM/CPU%d/RZ/Interpret/Success/CpuId", "The number of times CPUID was successfully interpreted.");
198 EM_REG_COUNTER_USED(&pStats->StatR3CpuId, "/EM/CPU%d/R3/Interpret/Success/CpuId", "The number of times CPUID was successfully interpreted.");
199 EM_REG_COUNTER_USED(&pStats->StatRZDec, "/EM/CPU%d/RZ/Interpret/Success/Dec", "The number of times DEC was successfully interpreted.");
200 EM_REG_COUNTER_USED(&pStats->StatR3Dec, "/EM/CPU%d/R3/Interpret/Success/Dec", "The number of times DEC was successfully interpreted.");
201 EM_REG_COUNTER_USED(&pStats->StatRZHlt, "/EM/CPU%d/RZ/Interpret/Success/Hlt", "The number of times HLT was successfully interpreted.");
202 EM_REG_COUNTER_USED(&pStats->StatR3Hlt, "/EM/CPU%d/R3/Interpret/Success/Hlt", "The number of times HLT was successfully interpreted.");
203 EM_REG_COUNTER_USED(&pStats->StatRZInc, "/EM/CPU%d/RZ/Interpret/Success/Inc", "The number of times INC was successfully interpreted.");
204 EM_REG_COUNTER_USED(&pStats->StatR3Inc, "/EM/CPU%d/R3/Interpret/Success/Inc", "The number of times INC was successfully interpreted.");
205 EM_REG_COUNTER_USED(&pStats->StatRZInvlPg, "/EM/CPU%d/RZ/Interpret/Success/Invlpg", "The number of times INVLPG was successfully interpreted.");
206 EM_REG_COUNTER_USED(&pStats->StatR3InvlPg, "/EM/CPU%d/R3/Interpret/Success/Invlpg", "The number of times INVLPG was successfully interpreted.");
207 EM_REG_COUNTER_USED(&pStats->StatRZIret, "/EM/CPU%d/RZ/Interpret/Success/Iret", "The number of times IRET was successfully interpreted.");
208 EM_REG_COUNTER_USED(&pStats->StatR3Iret, "/EM/CPU%d/R3/Interpret/Success/Iret", "The number of times IRET was successfully interpreted.");
209 EM_REG_COUNTER_USED(&pStats->StatRZLLdt, "/EM/CPU%d/RZ/Interpret/Success/LLdt", "The number of times LLDT was successfully interpreted.");
210 EM_REG_COUNTER_USED(&pStats->StatR3LLdt, "/EM/CPU%d/R3/Interpret/Success/LLdt", "The number of times LLDT was successfully interpreted.");
211 EM_REG_COUNTER_USED(&pStats->StatRZLIdt, "/EM/CPU%d/RZ/Interpret/Success/LIdt", "The number of times LIDT was successfully interpreted.");
212 EM_REG_COUNTER_USED(&pStats->StatR3LIdt, "/EM/CPU%d/R3/Interpret/Success/LIdt", "The number of times LIDT was successfully interpreted.");
213 EM_REG_COUNTER_USED(&pStats->StatRZLGdt, "/EM/CPU%d/RZ/Interpret/Success/LGdt", "The number of times LGDT was successfully interpreted.");
214 EM_REG_COUNTER_USED(&pStats->StatR3LGdt, "/EM/CPU%d/R3/Interpret/Success/LGdt", "The number of times LGDT was successfully interpreted.");
215 EM_REG_COUNTER_USED(&pStats->StatRZMov, "/EM/CPU%d/RZ/Interpret/Success/Mov", "The number of times MOV was successfully interpreted.");
216 EM_REG_COUNTER_USED(&pStats->StatR3Mov, "/EM/CPU%d/R3/Interpret/Success/Mov", "The number of times MOV was successfully interpreted.");
217 EM_REG_COUNTER_USED(&pStats->StatRZMovCRx, "/EM/CPU%d/RZ/Interpret/Success/MovCRx", "The number of times MOV CRx was successfully interpreted.");
218 EM_REG_COUNTER_USED(&pStats->StatR3MovCRx, "/EM/CPU%d/R3/Interpret/Success/MovCRx", "The number of times MOV CRx was successfully interpreted.");
219 EM_REG_COUNTER_USED(&pStats->StatRZMovDRx, "/EM/CPU%d/RZ/Interpret/Success/MovDRx", "The number of times MOV DRx was successfully interpreted.");
220 EM_REG_COUNTER_USED(&pStats->StatR3MovDRx, "/EM/CPU%d/R3/Interpret/Success/MovDRx", "The number of times MOV DRx was successfully interpreted.");
221 EM_REG_COUNTER_USED(&pStats->StatRZOr, "/EM/CPU%d/RZ/Interpret/Success/Or", "The number of times OR was successfully interpreted.");
222 EM_REG_COUNTER_USED(&pStats->StatR3Or, "/EM/CPU%d/R3/Interpret/Success/Or", "The number of times OR was successfully interpreted.");
223 EM_REG_COUNTER_USED(&pStats->StatRZPop, "/EM/CPU%d/RZ/Interpret/Success/Pop", "The number of times POP was successfully interpreted.");
224 EM_REG_COUNTER_USED(&pStats->StatR3Pop, "/EM/CPU%d/R3/Interpret/Success/Pop", "The number of times POP was successfully interpreted.");
225 EM_REG_COUNTER_USED(&pStats->StatRZRdtsc, "/EM/CPU%d/RZ/Interpret/Success/Rdtsc", "The number of times RDTSC was successfully interpreted.");
226 EM_REG_COUNTER_USED(&pStats->StatR3Rdtsc, "/EM/CPU%d/R3/Interpret/Success/Rdtsc", "The number of times RDTSC was successfully interpreted.");
227 EM_REG_COUNTER_USED(&pStats->StatRZRdpmc, "/EM/CPU%d/RZ/Interpret/Success/Rdpmc", "The number of times RDPMC was successfully interpreted.");
228 EM_REG_COUNTER_USED(&pStats->StatR3Rdpmc, "/EM/CPU%d/R3/Interpret/Success/Rdpmc", "The number of times RDPMC was successfully interpreted.");
229 EM_REG_COUNTER_USED(&pStats->StatRZSti, "/EM/CPU%d/RZ/Interpret/Success/Sti", "The number of times STI was successfully interpreted.");
230 EM_REG_COUNTER_USED(&pStats->StatR3Sti, "/EM/CPU%d/R3/Interpret/Success/Sti", "The number of times STI was successfully interpreted.");
231 EM_REG_COUNTER_USED(&pStats->StatRZXchg, "/EM/CPU%d/RZ/Interpret/Success/Xchg", "The number of times XCHG was successfully interpreted.");
232 EM_REG_COUNTER_USED(&pStats->StatR3Xchg, "/EM/CPU%d/R3/Interpret/Success/Xchg", "The number of times XCHG was successfully interpreted.");
233 EM_REG_COUNTER_USED(&pStats->StatRZXor, "/EM/CPU%d/RZ/Interpret/Success/Xor", "The number of times XOR was successfully interpreted.");
234 EM_REG_COUNTER_USED(&pStats->StatR3Xor, "/EM/CPU%d/R3/Interpret/Success/Xor", "The number of times XOR was successfully interpreted.");
235 EM_REG_COUNTER_USED(&pStats->StatRZMonitor, "/EM/CPU%d/RZ/Interpret/Success/Monitor", "The number of times MONITOR was successfully interpreted.");
236 EM_REG_COUNTER_USED(&pStats->StatR3Monitor, "/EM/CPU%d/R3/Interpret/Success/Monitor", "The number of times MONITOR was successfully interpreted.");
237 EM_REG_COUNTER_USED(&pStats->StatRZMWait, "/EM/CPU%d/RZ/Interpret/Success/MWait", "The number of times MWAIT was successfully interpreted.");
238 EM_REG_COUNTER_USED(&pStats->StatR3MWait, "/EM/CPU%d/R3/Interpret/Success/MWait", "The number of times MWAIT was successfully interpreted.");
239 EM_REG_COUNTER_USED(&pStats->StatRZBtr, "/EM/CPU%d/RZ/Interpret/Success/Btr", "The number of times BTR was successfully interpreted.");
240 EM_REG_COUNTER_USED(&pStats->StatR3Btr, "/EM/CPU%d/R3/Interpret/Success/Btr", "The number of times BTR was successfully interpreted.");
241 EM_REG_COUNTER_USED(&pStats->StatRZBts, "/EM/CPU%d/RZ/Interpret/Success/Bts", "The number of times BTS was successfully interpreted.");
242 EM_REG_COUNTER_USED(&pStats->StatR3Bts, "/EM/CPU%d/R3/Interpret/Success/Bts", "The number of times BTS was successfully interpreted.");
243 EM_REG_COUNTER_USED(&pStats->StatRZBtc, "/EM/CPU%d/RZ/Interpret/Success/Btc", "The number of times BTC was successfully interpreted.");
244 EM_REG_COUNTER_USED(&pStats->StatR3Btc, "/EM/CPU%d/R3/Interpret/Success/Btc", "The number of times BTC was successfully interpreted.");
245 EM_REG_COUNTER_USED(&pStats->StatRZCmpXchg, "/EM/CPU%d/RZ/Interpret/Success/CmpXchg", "The number of times CMPXCHG was successfully interpreted.");
246 EM_REG_COUNTER_USED(&pStats->StatR3CmpXchg, "/EM/CPU%d/R3/Interpret/Success/CmpXchg", "The number of times CMPXCHG was successfully interpreted.");
247 EM_REG_COUNTER_USED(&pStats->StatRZCmpXchg8b, "/EM/CPU%d/RZ/Interpret/Success/CmpXchg8b", "The number of times CMPXCHG8B was successfully interpreted.");
248 EM_REG_COUNTER_USED(&pStats->StatR3CmpXchg8b, "/EM/CPU%d/R3/Interpret/Success/CmpXchg8b", "The number of times CMPXCHG8B was successfully interpreted.");
249 EM_REG_COUNTER_USED(&pStats->StatRZXAdd, "/EM/CPU%d/RZ/Interpret/Success/XAdd", "The number of times XADD was successfully interpreted.");
250 EM_REG_COUNTER_USED(&pStats->StatR3XAdd, "/EM/CPU%d/R3/Interpret/Success/XAdd", "The number of times XADD was successfully interpreted.");
251 EM_REG_COUNTER_USED(&pStats->StatR3Rdmsr, "/EM/CPU%d/R3/Interpret/Success/Rdmsr", "The number of times RDMSR was successfully interpreted.");
252 EM_REG_COUNTER_USED(&pStats->StatRZRdmsr, "/EM/CPU%d/RZ/Interpret/Success/Rdmsr", "The number of times RDMSR was successfully interpreted.");
253 EM_REG_COUNTER_USED(&pStats->StatR3Wrmsr, "/EM/CPU%d/R3/Interpret/Success/Wrmsr", "The number of times WRMSR was successfully interpreted.");
254 EM_REG_COUNTER_USED(&pStats->StatRZWrmsr, "/EM/CPU%d/RZ/Interpret/Success/Wrmsr", "The number of times WRMSR was successfully interpreted.");
255 EM_REG_COUNTER_USED(&pStats->StatR3StosWD, "/EM/CPU%d/R3/Interpret/Success/Stoswd", "The number of times STOSWD was successfully interpreted.");
256 EM_REG_COUNTER_USED(&pStats->StatRZStosWD, "/EM/CPU%d/RZ/Interpret/Success/Stoswd", "The number of times STOSWD was successfully interpreted.");
257 EM_REG_COUNTER_USED(&pStats->StatRZWbInvd, "/EM/CPU%d/RZ/Interpret/Success/WbInvd", "The number of times WBINVD was successfully interpreted.");
258 EM_REG_COUNTER_USED(&pStats->StatR3WbInvd, "/EM/CPU%d/R3/Interpret/Success/WbInvd", "The number of times WBINVD was successfully interpreted.");
259 EM_REG_COUNTER_USED(&pStats->StatRZLmsw, "/EM/CPU%d/RZ/Interpret/Success/Lmsw", "The number of times LMSW was successfully interpreted.");
260 EM_REG_COUNTER_USED(&pStats->StatR3Lmsw, "/EM/CPU%d/R3/Interpret/Success/Lmsw", "The number of times LMSW was successfully interpreted.");
261
262 EM_REG_COUNTER(&pStats->StatRZInterpretFailed, "/EM/CPU%d/RZ/Interpret/Failed", "The number of times an instruction was not interpreted.");
263 EM_REG_COUNTER(&pStats->StatR3InterpretFailed, "/EM/CPU%d/R3/Interpret/Failed", "The number of times an instruction was not interpreted.");
264
265 EM_REG_COUNTER_USED(&pStats->StatRZFailedAnd, "/EM/CPU%d/RZ/Interpret/Failed/And", "The number of times AND was not interpreted.");
266 EM_REG_COUNTER_USED(&pStats->StatR3FailedAnd, "/EM/CPU%d/R3/Interpret/Failed/And", "The number of times AND was not interpreted.");
267 EM_REG_COUNTER_USED(&pStats->StatRZFailedCpuId, "/EM/CPU%d/RZ/Interpret/Failed/CpuId", "The number of times CPUID was not interpreted.");
268 EM_REG_COUNTER_USED(&pStats->StatR3FailedCpuId, "/EM/CPU%d/R3/Interpret/Failed/CpuId", "The number of times CPUID was not interpreted.");
269 EM_REG_COUNTER_USED(&pStats->StatRZFailedDec, "/EM/CPU%d/RZ/Interpret/Failed/Dec", "The number of times DEC was not interpreted.");
270 EM_REG_COUNTER_USED(&pStats->StatR3FailedDec, "/EM/CPU%d/R3/Interpret/Failed/Dec", "The number of times DEC was not interpreted.");
271 EM_REG_COUNTER_USED(&pStats->StatRZFailedHlt, "/EM/CPU%d/RZ/Interpret/Failed/Hlt", "The number of times HLT was not interpreted.");
272 EM_REG_COUNTER_USED(&pStats->StatR3FailedHlt, "/EM/CPU%d/R3/Interpret/Failed/Hlt", "The number of times HLT was not interpreted.");
273 EM_REG_COUNTER_USED(&pStats->StatRZFailedInc, "/EM/CPU%d/RZ/Interpret/Failed/Inc", "The number of times INC was not interpreted.");
274 EM_REG_COUNTER_USED(&pStats->StatR3FailedInc, "/EM/CPU%d/R3/Interpret/Failed/Inc", "The number of times INC was not interpreted.");
275 EM_REG_COUNTER_USED(&pStats->StatRZFailedInvlPg, "/EM/CPU%d/RZ/Interpret/Failed/InvlPg", "The number of times INVLPG was not interpreted.");
276 EM_REG_COUNTER_USED(&pStats->StatR3FailedInvlPg, "/EM/CPU%d/R3/Interpret/Failed/InvlPg", "The number of times INVLPG was not interpreted.");
277 EM_REG_COUNTER_USED(&pStats->StatRZFailedIret, "/EM/CPU%d/RZ/Interpret/Failed/Iret", "The number of times IRET was not interpreted.");
278 EM_REG_COUNTER_USED(&pStats->StatR3FailedIret, "/EM/CPU%d/R3/Interpret/Failed/Iret", "The number of times IRET was not interpreted.");
279 EM_REG_COUNTER_USED(&pStats->StatRZFailedLLdt, "/EM/CPU%d/RZ/Interpret/Failed/LLdt", "The number of times LLDT was not interpreted.");
280 EM_REG_COUNTER_USED(&pStats->StatR3FailedLLdt, "/EM/CPU%d/R3/Interpret/Failed/LLdt", "The number of times LLDT was not interpreted.");
281 EM_REG_COUNTER_USED(&pStats->StatRZFailedLIdt, "/EM/CPU%d/RZ/Interpret/Failed/LIdt", "The number of times LIDT was not interpreted.");
282 EM_REG_COUNTER_USED(&pStats->StatR3FailedLIdt, "/EM/CPU%d/R3/Interpret/Failed/LIdt", "The number of times LIDT was not interpreted.");
283 EM_REG_COUNTER_USED(&pStats->StatRZFailedLGdt, "/EM/CPU%d/RZ/Interpret/Failed/LGdt", "The number of times LGDT was not interpreted.");
284 EM_REG_COUNTER_USED(&pStats->StatR3FailedLGdt, "/EM/CPU%d/R3/Interpret/Failed/LGdt", "The number of times LGDT was not interpreted.");
285 EM_REG_COUNTER_USED(&pStats->StatRZFailedMov, "/EM/CPU%d/RZ/Interpret/Failed/Mov", "The number of times MOV was not interpreted.");
286 EM_REG_COUNTER_USED(&pStats->StatR3FailedMov, "/EM/CPU%d/R3/Interpret/Failed/Mov", "The number of times MOV was not interpreted.");
287 EM_REG_COUNTER_USED(&pStats->StatRZFailedMovCRx, "/EM/CPU%d/RZ/Interpret/Failed/MovCRx", "The number of times MOV CRx was not interpreted.");
288 EM_REG_COUNTER_USED(&pStats->StatR3FailedMovCRx, "/EM/CPU%d/R3/Interpret/Failed/MovCRx", "The number of times MOV CRx was not interpreted.");
289 EM_REG_COUNTER_USED(&pStats->StatRZFailedMovDRx, "/EM/CPU%d/RZ/Interpret/Failed/MovDRx", "The number of times MOV DRx was not interpreted.");
290 EM_REG_COUNTER_USED(&pStats->StatR3FailedMovDRx, "/EM/CPU%d/R3/Interpret/Failed/MovDRx", "The number of times MOV DRx was not interpreted.");
291 EM_REG_COUNTER_USED(&pStats->StatRZFailedOr, "/EM/CPU%d/RZ/Interpret/Failed/Or", "The number of times OR was not interpreted.");
292 EM_REG_COUNTER_USED(&pStats->StatR3FailedOr, "/EM/CPU%d/R3/Interpret/Failed/Or", "The number of times OR was not interpreted.");
293 EM_REG_COUNTER_USED(&pStats->StatRZFailedPop, "/EM/CPU%d/RZ/Interpret/Failed/Pop", "The number of times POP was not interpreted.");
294 EM_REG_COUNTER_USED(&pStats->StatR3FailedPop, "/EM/CPU%d/R3/Interpret/Failed/Pop", "The number of times POP was not interpreted.");
295 EM_REG_COUNTER_USED(&pStats->StatRZFailedSti, "/EM/CPU%d/RZ/Interpret/Failed/Sti", "The number of times STI was not interpreted.");
296 EM_REG_COUNTER_USED(&pStats->StatR3FailedSti, "/EM/CPU%d/R3/Interpret/Failed/Sti", "The number of times STI was not interpreted.");
297 EM_REG_COUNTER_USED(&pStats->StatRZFailedXchg, "/EM/CPU%d/RZ/Interpret/Failed/Xchg", "The number of times XCHG was not interpreted.");
298 EM_REG_COUNTER_USED(&pStats->StatR3FailedXchg, "/EM/CPU%d/R3/Interpret/Failed/Xchg", "The number of times XCHG was not interpreted.");
299 EM_REG_COUNTER_USED(&pStats->StatRZFailedXor, "/EM/CPU%d/RZ/Interpret/Failed/Xor", "The number of times XOR was not interpreted.");
300 EM_REG_COUNTER_USED(&pStats->StatR3FailedXor, "/EM/CPU%d/R3/Interpret/Failed/Xor", "The number of times XOR was not interpreted.");
301 EM_REG_COUNTER_USED(&pStats->StatRZFailedMonitor, "/EM/CPU%d/RZ/Interpret/Failed/Monitor", "The number of times MONITOR was not interpreted.");
302 EM_REG_COUNTER_USED(&pStats->StatR3FailedMonitor, "/EM/CPU%d/R3/Interpret/Failed/Monitor", "The number of times MONITOR was not interpreted.");
303 EM_REG_COUNTER_USED(&pStats->StatRZFailedMWait, "/EM/CPU%d/RZ/Interpret/Failed/MWait", "The number of times MONITOR was not interpreted.");
304 EM_REG_COUNTER_USED(&pStats->StatR3FailedMWait, "/EM/CPU%d/R3/Interpret/Failed/MWait", "The number of times MONITOR was not interpreted.");
305 EM_REG_COUNTER_USED(&pStats->StatRZFailedRdtsc, "/EM/CPU%d/RZ/Interpret/Failed/Rdtsc", "The number of times RDTSC was not interpreted.");
306 EM_REG_COUNTER_USED(&pStats->StatR3FailedRdtsc, "/EM/CPU%d/R3/Interpret/Failed/Rdtsc", "The number of times RDTSC was not interpreted.");
307 EM_REG_COUNTER_USED(&pStats->StatRZFailedRdpmc, "/EM/CPU%d/RZ/Interpret/Failed/Rdpmc", "The number of times RDPMC was not interpreted.");
308 EM_REG_COUNTER_USED(&pStats->StatR3FailedRdpmc, "/EM/CPU%d/R3/Interpret/Failed/Rdpmc", "The number of times RDPMC was not interpreted.");
309 EM_REG_COUNTER_USED(&pStats->StatRZFailedRdmsr, "/EM/CPU%d/RZ/Interpret/Failed/Rdmsr", "The number of times RDMSR was not interpreted.");
310 EM_REG_COUNTER_USED(&pStats->StatR3FailedRdmsr, "/EM/CPU%d/R3/Interpret/Failed/Rdmsr", "The number of times RDMSR was not interpreted.");
311 EM_REG_COUNTER_USED(&pStats->StatRZFailedWrmsr, "/EM/CPU%d/RZ/Interpret/Failed/Wrmsr", "The number of times WRMSR was not interpreted.");
312 EM_REG_COUNTER_USED(&pStats->StatR3FailedWrmsr, "/EM/CPU%d/R3/Interpret/Failed/Wrmsr", "The number of times WRMSR was not interpreted.");
313 EM_REG_COUNTER_USED(&pStats->StatRZFailedLmsw, "/EM/CPU%d/RZ/Interpret/Failed/Lmsw", "The number of times LMSW was not interpreted.");
314 EM_REG_COUNTER_USED(&pStats->StatR3FailedLmsw, "/EM/CPU%d/R3/Interpret/Failed/Lmsw", "The number of times LMSW was not interpreted.");
315
316 EM_REG_COUNTER_USED(&pStats->StatRZFailedMisc, "/EM/CPU%d/RZ/Interpret/Failed/Misc", "The number of times some misc instruction was encountered.");
317 EM_REG_COUNTER_USED(&pStats->StatR3FailedMisc, "/EM/CPU%d/R3/Interpret/Failed/Misc", "The number of times some misc instruction was encountered.");
318 EM_REG_COUNTER_USED(&pStats->StatRZFailedAdd, "/EM/CPU%d/RZ/Interpret/Failed/Add", "The number of times ADD was not interpreted.");
319 EM_REG_COUNTER_USED(&pStats->StatR3FailedAdd, "/EM/CPU%d/R3/Interpret/Failed/Add", "The number of times ADD was not interpreted.");
320 EM_REG_COUNTER_USED(&pStats->StatRZFailedAdc, "/EM/CPU%d/RZ/Interpret/Failed/Adc", "The number of times ADC was not interpreted.");
321 EM_REG_COUNTER_USED(&pStats->StatR3FailedAdc, "/EM/CPU%d/R3/Interpret/Failed/Adc", "The number of times ADC was not interpreted.");
322 EM_REG_COUNTER_USED(&pStats->StatRZFailedBtr, "/EM/CPU%d/RZ/Interpret/Failed/Btr", "The number of times BTR was not interpreted.");
323 EM_REG_COUNTER_USED(&pStats->StatR3FailedBtr, "/EM/CPU%d/R3/Interpret/Failed/Btr", "The number of times BTR was not interpreted.");
324 EM_REG_COUNTER_USED(&pStats->StatRZFailedBts, "/EM/CPU%d/RZ/Interpret/Failed/Bts", "The number of times BTS was not interpreted.");
325 EM_REG_COUNTER_USED(&pStats->StatR3FailedBts, "/EM/CPU%d/R3/Interpret/Failed/Bts", "The number of times BTS was not interpreted.");
326 EM_REG_COUNTER_USED(&pStats->StatRZFailedBtc, "/EM/CPU%d/RZ/Interpret/Failed/Btc", "The number of times BTC was not interpreted.");
327 EM_REG_COUNTER_USED(&pStats->StatR3FailedBtc, "/EM/CPU%d/R3/Interpret/Failed/Btc", "The number of times BTC was not interpreted.");
328 EM_REG_COUNTER_USED(&pStats->StatRZFailedCli, "/EM/CPU%d/RZ/Interpret/Failed/Cli", "The number of times CLI was not interpreted.");
329 EM_REG_COUNTER_USED(&pStats->StatR3FailedCli, "/EM/CPU%d/R3/Interpret/Failed/Cli", "The number of times CLI was not interpreted.");
330 EM_REG_COUNTER_USED(&pStats->StatRZFailedCmpXchg, "/EM/CPU%d/RZ/Interpret/Failed/CmpXchg", "The number of times CMPXCHG was not interpreted.");
331 EM_REG_COUNTER_USED(&pStats->StatR3FailedCmpXchg, "/EM/CPU%d/R3/Interpret/Failed/CmpXchg", "The number of times CMPXCHG was not interpreted.");
332 EM_REG_COUNTER_USED(&pStats->StatRZFailedCmpXchg8b, "/EM/CPU%d/RZ/Interpret/Failed/CmpXchg8b", "The number of times CMPXCHG8B was not interpreted.");
333 EM_REG_COUNTER_USED(&pStats->StatR3FailedCmpXchg8b, "/EM/CPU%d/R3/Interpret/Failed/CmpXchg8b", "The number of times CMPXCHG8B was not interpreted.");
334 EM_REG_COUNTER_USED(&pStats->StatRZFailedXAdd, "/EM/CPU%d/RZ/Interpret/Failed/XAdd", "The number of times XADD was not interpreted.");
335 EM_REG_COUNTER_USED(&pStats->StatR3FailedXAdd, "/EM/CPU%d/R3/Interpret/Failed/XAdd", "The number of times XADD was not interpreted.");
336 EM_REG_COUNTER_USED(&pStats->StatRZFailedMovNTPS, "/EM/CPU%d/RZ/Interpret/Failed/MovNTPS", "The number of times MOVNTPS was not interpreted.");
337 EM_REG_COUNTER_USED(&pStats->StatR3FailedMovNTPS, "/EM/CPU%d/R3/Interpret/Failed/MovNTPS", "The number of times MOVNTPS was not interpreted.");
338 EM_REG_COUNTER_USED(&pStats->StatRZFailedStosWD, "/EM/CPU%d/RZ/Interpret/Failed/StosWD", "The number of times STOSWD was not interpreted.");
339 EM_REG_COUNTER_USED(&pStats->StatR3FailedStosWD, "/EM/CPU%d/R3/Interpret/Failed/StosWD", "The number of times STOSWD was not interpreted.");
340 EM_REG_COUNTER_USED(&pStats->StatRZFailedSub, "/EM/CPU%d/RZ/Interpret/Failed/Sub", "The number of times SUB was not interpreted.");
341 EM_REG_COUNTER_USED(&pStats->StatR3FailedSub, "/EM/CPU%d/R3/Interpret/Failed/Sub", "The number of times SUB was not interpreted.");
342 EM_REG_COUNTER_USED(&pStats->StatRZFailedWbInvd, "/EM/CPU%d/RZ/Interpret/Failed/WbInvd", "The number of times WBINVD was not interpreted.");
343 EM_REG_COUNTER_USED(&pStats->StatR3FailedWbInvd, "/EM/CPU%d/R3/Interpret/Failed/WbInvd", "The number of times WBINVD was not interpreted.");
344
345 EM_REG_COUNTER_USED(&pStats->StatRZFailedUserMode, "/EM/CPU%d/RZ/Interpret/Failed/UserMode", "The number of rejections because of CPL.");
346 EM_REG_COUNTER_USED(&pStats->StatR3FailedUserMode, "/EM/CPU%d/R3/Interpret/Failed/UserMode", "The number of rejections because of CPL.");
347 EM_REG_COUNTER_USED(&pStats->StatRZFailedPrefix, "/EM/CPU%d/RZ/Interpret/Failed/Prefix", "The number of rejections because of prefix .");
348 EM_REG_COUNTER_USED(&pStats->StatR3FailedPrefix, "/EM/CPU%d/R3/Interpret/Failed/Prefix", "The number of rejections because of prefix .");
349
350 EM_REG_COUNTER_USED(&pStats->StatCli, "/EM/CPU%d/R3/PrivInst/Cli", "Number of cli instructions.");
351 EM_REG_COUNTER_USED(&pStats->StatSti, "/EM/CPU%d/R3/PrivInst/Sti", "Number of sli instructions.");
352 EM_REG_COUNTER_USED(&pStats->StatIn, "/EM/CPU%d/R3/PrivInst/In", "Number of in instructions.");
353 EM_REG_COUNTER_USED(&pStats->StatOut, "/EM/CPU%d/R3/PrivInst/Out", "Number of out instructions.");
354 EM_REG_COUNTER_USED(&pStats->StatIoRestarted, "/EM/CPU%d/R3/PrivInst/IoRestarted", "Number of restarted i/o instructions.");
355 EM_REG_COUNTER_USED(&pStats->StatHlt, "/EM/CPU%d/R3/PrivInst/Hlt", "Number of hlt instructions not handled in GC because of PATM.");
356 EM_REG_COUNTER_USED(&pStats->StatInvlpg, "/EM/CPU%d/R3/PrivInst/Invlpg", "Number of invlpg instructions.");
357 EM_REG_COUNTER_USED(&pStats->StatMisc, "/EM/CPU%d/R3/PrivInst/Misc", "Number of misc. instructions.");
358 EM_REG_COUNTER_USED(&pStats->StatMovWriteCR[0], "/EM/CPU%d/R3/PrivInst/Mov CR0, X", "Number of mov CR0 read instructions.");
359 EM_REG_COUNTER_USED(&pStats->StatMovWriteCR[1], "/EM/CPU%d/R3/PrivInst/Mov CR1, X", "Number of mov CR1 read instructions.");
360 EM_REG_COUNTER_USED(&pStats->StatMovWriteCR[2], "/EM/CPU%d/R3/PrivInst/Mov CR2, X", "Number of mov CR2 read instructions.");
361 EM_REG_COUNTER_USED(&pStats->StatMovWriteCR[3], "/EM/CPU%d/R3/PrivInst/Mov CR3, X", "Number of mov CR3 read instructions.");
362 EM_REG_COUNTER_USED(&pStats->StatMovWriteCR[4], "/EM/CPU%d/R3/PrivInst/Mov CR4, X", "Number of mov CR4 read instructions.");
363 EM_REG_COUNTER_USED(&pStats->StatMovReadCR[0], "/EM/CPU%d/R3/PrivInst/Mov X, CR0", "Number of mov CR0 write instructions.");
364 EM_REG_COUNTER_USED(&pStats->StatMovReadCR[1], "/EM/CPU%d/R3/PrivInst/Mov X, CR1", "Number of mov CR1 write instructions.");
365 EM_REG_COUNTER_USED(&pStats->StatMovReadCR[2], "/EM/CPU%d/R3/PrivInst/Mov X, CR2", "Number of mov CR2 write instructions.");
366 EM_REG_COUNTER_USED(&pStats->StatMovReadCR[3], "/EM/CPU%d/R3/PrivInst/Mov X, CR3", "Number of mov CR3 write instructions.");
367 EM_REG_COUNTER_USED(&pStats->StatMovReadCR[4], "/EM/CPU%d/R3/PrivInst/Mov X, CR4", "Number of mov CR4 write instructions.");
368 EM_REG_COUNTER_USED(&pStats->StatMovDRx, "/EM/CPU%d/R3/PrivInst/MovDRx", "Number of mov DRx instructions.");
369 EM_REG_COUNTER_USED(&pStats->StatIret, "/EM/CPU%d/R3/PrivInst/Iret", "Number of iret instructions.");
370 EM_REG_COUNTER_USED(&pStats->StatMovLgdt, "/EM/CPU%d/R3/PrivInst/Lgdt", "Number of lgdt instructions.");
371 EM_REG_COUNTER_USED(&pStats->StatMovLidt, "/EM/CPU%d/R3/PrivInst/Lidt", "Number of lidt instructions.");
372 EM_REG_COUNTER_USED(&pStats->StatMovLldt, "/EM/CPU%d/R3/PrivInst/Lldt", "Number of lldt instructions.");
373 EM_REG_COUNTER_USED(&pStats->StatSysEnter, "/EM/CPU%d/R3/PrivInst/Sysenter", "Number of sysenter instructions.");
374 EM_REG_COUNTER_USED(&pStats->StatSysExit, "/EM/CPU%d/R3/PrivInst/Sysexit", "Number of sysexit instructions.");
375 EM_REG_COUNTER_USED(&pStats->StatSysCall, "/EM/CPU%d/R3/PrivInst/Syscall", "Number of syscall instructions.");
376 EM_REG_COUNTER_USED(&pStats->StatSysRet, "/EM/CPU%d/R3/PrivInst/Sysret", "Number of sysret instructions.");
377
378 EM_REG_COUNTER(&pVCpu->em.s.StatTotalClis, "/EM/CPU%d/Cli/Total", "Total number of cli instructions executed.");
379 pVCpu->em.s.pCliStatTree = 0;
380
381 /* these should be considered for release statistics. */
382 EM_REG_COUNTER(&pVCpu->em.s.StatIOEmu, "/PROF/CPU%d/EM/Emulation/IO", "Profiling of emR3RawExecuteIOInstruction.");
383 EM_REG_COUNTER(&pVCpu->em.s.StatPrivEmu, "/PROF/CPU%d/EM/Emulation/Priv", "Profiling of emR3RawPrivileged.");
384 EM_REG_COUNTER(&pVCpu->em.s.StatMiscEmu, "/PROF/CPU%d/EM/Emulation/Misc", "Profiling of emR3RawExecuteInstruction.");
385 EM_REG_PROFILE(&pVCpu->em.s.StatHwAccEntry, "/PROF/CPU%d/EM/HwAccEnter", "Profiling Hardware Accelerated Mode entry overhead.");
386 EM_REG_PROFILE(&pVCpu->em.s.StatHwAccExec, "/PROF/CPU%d/EM/HwAccExec", "Profiling Hardware Accelerated Mode execution.");
387 EM_REG_PROFILE(&pVCpu->em.s.StatREMEmu, "/PROF/CPU%d/EM/REMEmuSingle", "Profiling single instruction REM execution.");
388 EM_REG_PROFILE(&pVCpu->em.s.StatREMExec, "/PROF/CPU%d/EM/REMExec", "Profiling REM execution.");
389 EM_REG_PROFILE(&pVCpu->em.s.StatREMSync, "/PROF/CPU%d/EM/REMSync", "Profiling REM context syncing.");
390 EM_REG_PROFILE(&pVCpu->em.s.StatRAWEntry, "/PROF/CPU%d/EM/RAWEnter", "Profiling Raw Mode entry overhead.");
391 EM_REG_PROFILE(&pVCpu->em.s.StatRAWExec, "/PROF/CPU%d/EM/RAWExec", "Profiling Raw Mode execution.");
392 EM_REG_PROFILE(&pVCpu->em.s.StatRAWTail, "/PROF/CPU%d/EM/RAWTail", "Profiling Raw Mode tail overhead.");
393
394#endif /* VBOX_WITH_STATISTICS */
395
396 EM_REG_COUNTER(&pVCpu->em.s.StatForcedActions, "/PROF/CPU%d/EM/ForcedActions", "Profiling forced action execution.");
397 EM_REG_COUNTER(&pVCpu->em.s.StatHalted, "/PROF/CPU%d/EM/Halted", "Profiling halted state (VMR3WaitHalted).");
398 EM_REG_COUNTER(&pVCpu->em.s.StatREMTotal, "/PROF/CPU%d/EM/REMTotal", "Profiling emR3RemExecute (excluding FFs).");
399 EM_REG_COUNTER(&pVCpu->em.s.StatRAWTotal, "/PROF/CPU%d/EM/RAWTotal", "Profiling emR3RawExecute (excluding FFs).");
400
401 EM_REG_PROFILE_ADV(&pVCpu->em.s.StatTotal, "/PROF/CPU%d/EM/Total", "Profiling EMR3ExecuteVM.");
402 }
403
404 return VINF_SUCCESS;
405}
406
407
408/**
409 * Initializes the per-VCPU EM.
410 *
411 * @returns VBox status code.
412 * @param pVM The VM to operate on.
413 */
414VMMR3DECL(int) EMR3InitCPU(PVM pVM)
415{
416 LogFlow(("EMR3InitCPU\n"));
417 return VINF_SUCCESS;
418}
419
420
421/**
422 * Applies relocations to data and code managed by this
423 * component. This function will be called at init and
424 * whenever the VMM need to relocate it self inside the GC.
425 *
426 * @param pVM The VM.
427 */
428VMMR3DECL(void) EMR3Relocate(PVM pVM)
429{
430 LogFlow(("EMR3Relocate\n"));
431 for (VMCPUID i = 0; i < pVM->cCpus; i++)
432 {
433 PVMCPU pVCpu = &pVM->aCpus[i];
434 if (pVCpu->em.s.pStatsR3)
435 pVCpu->em.s.pStatsRC = MMHyperR3ToRC(pVM, pVCpu->em.s.pStatsR3);
436 }
437}
438
439
440/**
441 * Reset notification.
442 *
443 * @param pVM
444 */
445VMMR3DECL(void) EMR3Reset(PVM pVM)
446{
447 Log(("EMR3Reset: \n"));
448 for (VMCPUID i = 0; i < pVM->cCpus; i++)
449 {
450 PVMCPU pVCpu = &pVM->aCpus[i];
451 pVCpu->em.s.fForceRAW = false;
452
453 /* VMR3Reset may return VINF_EM_RESET or VINF_EM_SUSPEND, so transition
454 out of the HALTED state here so that enmPrevState doesn't end up as
455 HALTED when EMR3Execute returns. */
456 if (pVCpu->em.s.enmState == EMSTATE_HALTED)
457 {
458 Log(("EMR3Reset: Cpu#%u %s -> %s\n", i, emR3GetStateName(pVCpu->em.s.enmState), i == 0 ? "EMSTATE_NONE" : "EMSTATE_WAIT_SIPI"));
459 pVCpu->em.s.enmState = i == 0 ? EMSTATE_NONE : EMSTATE_WAIT_SIPI;
460 }
461 }
462}
463
464
465/**
466 * Terminates the EM.
467 *
468 * Termination means cleaning up and freeing all resources,
469 * the VM it self is at this point powered off or suspended.
470 *
471 * @returns VBox status code.
472 * @param pVM The VM to operate on.
473 */
474VMMR3DECL(int) EMR3Term(PVM pVM)
475{
476 AssertMsg(pVM->em.s.offVM, ("bad init order!\n"));
477
478 PDMR3CritSectDelete(&pVM->em.s.CritSectREM);
479 return VINF_SUCCESS;
480}
481
482/**
483 * Terminates the per-VCPU EM.
484 *
485 * Termination means cleaning up and freeing all resources,
486 * the VM it self is at this point powered off or suspended.
487 *
488 * @returns VBox status code.
489 * @param pVM The VM to operate on.
490 */
491VMMR3DECL(int) EMR3TermCPU(PVM pVM)
492{
493 return 0;
494}
495
496/**
497 * Execute state save operation.
498 *
499 * @returns VBox status code.
500 * @param pVM VM Handle.
501 * @param pSSM SSM operation handle.
502 */
503static DECLCALLBACK(int) emR3Save(PVM pVM, PSSMHANDLE pSSM)
504{
505 for (VMCPUID i = 0; i < pVM->cCpus; i++)
506 {
507 PVMCPU pVCpu = &pVM->aCpus[i];
508
509 int rc = SSMR3PutBool(pSSM, pVCpu->em.s.fForceRAW);
510 AssertRCReturn(rc, rc);
511
512 Assert(pVCpu->em.s.enmState == EMSTATE_SUSPENDED);
513 Assert(pVCpu->em.s.enmPrevState != EMSTATE_SUSPENDED);
514 rc = SSMR3PutU32(pSSM, pVCpu->em.s.enmPrevState);
515 AssertRCReturn(rc, rc);
516 }
517 return VINF_SUCCESS;
518}
519
520
521/**
522 * Execute state load operation.
523 *
524 * @returns VBox status code.
525 * @param pVM VM Handle.
526 * @param pSSM SSM operation handle.
527 * @param uVersion Data layout version.
528 * @param uPass The data pass.
529 */
530static DECLCALLBACK(int) emR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
531{
532 /*
533 * Validate version.
534 */
535 if ( uVersion != EM_SAVED_STATE_VERSION
536 && uVersion != EM_SAVED_STATE_VERSION_PRE_SMP)
537 {
538 AssertMsgFailed(("emR3Load: Invalid version uVersion=%d (current %d)!\n", uVersion, EM_SAVED_STATE_VERSION));
539 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
540 }
541 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
542
543 /*
544 * Load the saved state.
545 */
546 for (VMCPUID i = 0; i < pVM->cCpus; i++)
547 {
548 PVMCPU pVCpu = &pVM->aCpus[i];
549
550 int rc = SSMR3GetBool(pSSM, &pVCpu->em.s.fForceRAW);
551 if (RT_FAILURE(rc))
552 pVCpu->em.s.fForceRAW = false;
553 AssertRCReturn(rc, rc);
554
555 if (uVersion > EM_SAVED_STATE_VERSION_PRE_SMP)
556 {
557 AssertCompile(sizeof(pVCpu->em.s.enmPrevState) == sizeof(uint32_t));
558 rc = SSMR3GetU32(pSSM, (uint32_t *)&pVCpu->em.s.enmPrevState);
559 AssertRCReturn(rc, rc);
560 Assert(pVCpu->em.s.enmPrevState != EMSTATE_SUSPENDED);
561
562 pVCpu->em.s.enmState = EMSTATE_SUSPENDED;
563 }
564 Assert(!pVCpu->em.s.pCliStatTree);
565 }
566 return VINF_SUCCESS;
567}
568
569
570/**
571 * Raise a fatal error.
572 *
573 * Safely terminate the VM with full state report and stuff. This function
574 * will naturally never return.
575 *
576 * @param pVCpu VMCPU handle.
577 * @param rc VBox status code.
578 */
579VMMR3DECL(void) EMR3FatalError(PVMCPU pVCpu, int rc)
580{
581 pVCpu->em.s.enmState = EMSTATE_GURU_MEDITATION;
582 longjmp(pVCpu->em.s.u.FatalLongJump, rc);
583 AssertReleaseMsgFailed(("longjmp returned!\n"));
584}
585
586
587/**
588 * Gets the EM state name.
589 *
590 * @returns pointer to read only state name,
591 * @param enmState The state.
592 */
593static const char *emR3GetStateName(EMSTATE enmState)
594{
595 switch (enmState)
596 {
597 case EMSTATE_NONE: return "EMSTATE_NONE";
598 case EMSTATE_RAW: return "EMSTATE_RAW";
599 case EMSTATE_HWACC: return "EMSTATE_HWACC";
600 case EMSTATE_REM: return "EMSTATE_REM";
601 case EMSTATE_PARAV: return "EMSTATE_PARAV";
602 case EMSTATE_HALTED: return "EMSTATE_HALTED";
603 case EMSTATE_WAIT_SIPI: return "EMSTATE_WAIT_SIPI";
604 case EMSTATE_SUSPENDED: return "EMSTATE_SUSPENDED";
605 case EMSTATE_TERMINATING: return "EMSTATE_TERMINATING";
606 case EMSTATE_DEBUG_GUEST_RAW: return "EMSTATE_DEBUG_GUEST_RAW";
607 case EMSTATE_DEBUG_GUEST_REM: return "EMSTATE_DEBUG_GUEST_REM";
608 case EMSTATE_DEBUG_HYPER: return "EMSTATE_DEBUG_HYPER";
609 case EMSTATE_GURU_MEDITATION: return "EMSTATE_GURU_MEDITATION";
610 default: return "Unknown!";
611 }
612}
613
614
615#ifdef VBOX_WITH_STATISTICS
616/**
617 * Just a braindead function to keep track of cli addresses.
618 * @param pVM VM handle.
619 * @param pVMCPU VMCPU handle.
620 * @param GCPtrInstr The EIP of the cli instruction.
621 */
622static void emR3RecordCli(PVM pVM, PVMCPU pVCpu, RTGCPTR GCPtrInstr)
623{
624 PCLISTAT pRec;
625
626 pRec = (PCLISTAT)RTAvlPVGet(&pVCpu->em.s.pCliStatTree, (AVLPVKEY)GCPtrInstr);
627 if (!pRec)
628 {
629 /* New cli instruction; insert into the tree. */
630 pRec = (PCLISTAT)MMR3HeapAllocZ(pVM, MM_TAG_EM, sizeof(*pRec));
631 Assert(pRec);
632 if (!pRec)
633 return;
634 pRec->Core.Key = (AVLPVKEY)GCPtrInstr;
635
636 char szCliStatName[32];
637 RTStrPrintf(szCliStatName, sizeof(szCliStatName), "/EM/Cli/0x%RGv", GCPtrInstr);
638 STAM_REG(pVM, &pRec->Counter, STAMTYPE_COUNTER, szCliStatName, STAMUNIT_OCCURENCES, "Number of times cli was executed.");
639
640 bool fRc = RTAvlPVInsert(&pVCpu->em.s.pCliStatTree, &pRec->Core);
641 Assert(fRc); NOREF(fRc);
642 }
643 STAM_COUNTER_INC(&pRec->Counter);
644 STAM_COUNTER_INC(&pVCpu->em.s.StatTotalClis);
645}
646#endif /* VBOX_WITH_STATISTICS */
647
648
649/**
650 * Debug loop.
651 *
652 * @returns VBox status code for EM.
653 * @param pVM VM handle.
654 * @param pVCpu VMCPU handle.
655 * @param rc Current EM VBox status code..
656 */
657static int emR3Debug(PVM pVM, PVMCPU pVCpu, int rc)
658{
659 for (;;)
660 {
661 Log(("emR3Debug: rc=%Rrc\n", rc));
662 const int rcLast = rc;
663
664 /*
665 * Debug related RC.
666 */
667 switch (rc)
668 {
669 /*
670 * Single step an instruction.
671 */
672 case VINF_EM_DBG_STEP:
673 if ( pVCpu->em.s.enmState == EMSTATE_DEBUG_GUEST_RAW
674 || pVCpu->em.s.enmState == EMSTATE_DEBUG_HYPER
675 || pVCpu->em.s.fForceRAW /* paranoia */)
676 rc = emR3RawStep(pVM, pVCpu);
677 else
678 {
679 Assert(pVCpu->em.s.enmState == EMSTATE_DEBUG_GUEST_REM);
680 rc = emR3RemStep(pVM, pVCpu);
681 }
682 break;
683
684 /*
685 * Simple events: stepped, breakpoint, stop/assertion.
686 */
687 case VINF_EM_DBG_STEPPED:
688 rc = DBGFR3Event(pVM, DBGFEVENT_STEPPED);
689 break;
690
691 case VINF_EM_DBG_BREAKPOINT:
692 rc = DBGFR3EventBreakpoint(pVM, DBGFEVENT_BREAKPOINT);
693 break;
694
695 case VINF_EM_DBG_STOP:
696 rc = DBGFR3EventSrc(pVM, DBGFEVENT_DEV_STOP, NULL, 0, NULL, NULL);
697 break;
698
699 case VINF_EM_DBG_HYPER_STEPPED:
700 rc = DBGFR3Event(pVM, DBGFEVENT_STEPPED_HYPER);
701 break;
702
703 case VINF_EM_DBG_HYPER_BREAKPOINT:
704 rc = DBGFR3EventBreakpoint(pVM, DBGFEVENT_BREAKPOINT_HYPER);
705 break;
706
707 case VINF_EM_DBG_HYPER_ASSERTION:
708 RTPrintf("\nVINF_EM_DBG_HYPER_ASSERTION:\n%s%s\n", VMMR3GetRZAssertMsg1(pVM), VMMR3GetRZAssertMsg2(pVM));
709 rc = DBGFR3EventAssertion(pVM, DBGFEVENT_ASSERTION_HYPER, VMMR3GetRZAssertMsg1(pVM), VMMR3GetRZAssertMsg2(pVM));
710 break;
711
712 /*
713 * Guru meditation.
714 */
715 case VERR_VMM_RING0_ASSERTION: /** @todo Make a guru meditation event! */
716 rc = DBGFR3EventSrc(pVM, DBGFEVENT_FATAL_ERROR, "VERR_VMM_RING0_ASSERTION", 0, NULL, NULL);
717 break;
718 case VERR_REM_TOO_MANY_TRAPS: /** @todo Make a guru meditation event! */
719 rc = DBGFR3EventSrc(pVM, DBGFEVENT_DEV_STOP, "VERR_REM_TOO_MANY_TRAPS", 0, NULL, NULL);
720 break;
721
722 default: /** @todo don't use default for guru, but make special errors code! */
723 rc = DBGFR3Event(pVM, DBGFEVENT_FATAL_ERROR);
724 break;
725 }
726
727 /*
728 * Process the result.
729 */
730 do
731 {
732 switch (rc)
733 {
734 /*
735 * Continue the debugging loop.
736 */
737 case VINF_EM_DBG_STEP:
738 case VINF_EM_DBG_STOP:
739 case VINF_EM_DBG_STEPPED:
740 case VINF_EM_DBG_BREAKPOINT:
741 case VINF_EM_DBG_HYPER_STEPPED:
742 case VINF_EM_DBG_HYPER_BREAKPOINT:
743 case VINF_EM_DBG_HYPER_ASSERTION:
744 break;
745
746 /*
747 * Resuming execution (in some form) has to be done here if we got
748 * a hypervisor debug event.
749 */
750 case VINF_SUCCESS:
751 case VINF_EM_RESUME:
752 case VINF_EM_SUSPEND:
753 case VINF_EM_RESCHEDULE:
754 case VINF_EM_RESCHEDULE_RAW:
755 case VINF_EM_RESCHEDULE_REM:
756 case VINF_EM_HALT:
757 if (pVCpu->em.s.enmState == EMSTATE_DEBUG_HYPER)
758 {
759 rc = emR3RawResumeHyper(pVM, pVCpu);
760 if (rc != VINF_SUCCESS && RT_SUCCESS(rc))
761 continue;
762 }
763 if (rc == VINF_SUCCESS)
764 rc = VINF_EM_RESCHEDULE;
765 return rc;
766
767 /*
768 * The debugger isn't attached.
769 * We'll simply turn the thing off since that's the easiest thing to do.
770 */
771 case VERR_DBGF_NOT_ATTACHED:
772 switch (rcLast)
773 {
774 case VINF_EM_DBG_HYPER_STEPPED:
775 case VINF_EM_DBG_HYPER_BREAKPOINT:
776 case VINF_EM_DBG_HYPER_ASSERTION:
777 case VERR_TRPM_PANIC:
778 case VERR_TRPM_DONT_PANIC:
779 case VERR_VMM_RING0_ASSERTION:
780 case VERR_VMM_HYPER_CR3_MISMATCH:
781 case VERR_VMM_RING3_CALL_DISABLED:
782 return rcLast;
783 }
784 return VINF_EM_OFF;
785
786 /*
787 * Status codes terminating the VM in one or another sense.
788 */
789 case VINF_EM_TERMINATE:
790 case VINF_EM_OFF:
791 case VINF_EM_RESET:
792 case VINF_EM_NO_MEMORY:
793 case VINF_EM_RAW_STALE_SELECTOR:
794 case VINF_EM_RAW_IRET_TRAP:
795 case VERR_TRPM_PANIC:
796 case VERR_TRPM_DONT_PANIC:
797 case VERR_VMM_RING0_ASSERTION:
798 case VERR_VMM_HYPER_CR3_MISMATCH:
799 case VERR_VMM_RING3_CALL_DISABLED:
800 case VERR_INTERNAL_ERROR:
801 case VERR_INTERNAL_ERROR_2:
802 case VERR_INTERNAL_ERROR_3:
803 case VERR_INTERNAL_ERROR_4:
804 case VERR_INTERNAL_ERROR_5:
805 case VERR_IPE_UNEXPECTED_STATUS:
806 case VERR_IPE_UNEXPECTED_INFO_STATUS:
807 case VERR_IPE_UNEXPECTED_ERROR_STATUS:
808 return rc;
809
810 /*
811 * The rest is unexpected, and will keep us here.
812 */
813 default:
814 AssertMsgFailed(("Unxpected rc %Rrc!\n", rc));
815 break;
816 }
817 } while (false);
818 } /* debug for ever */
819}
820
821/**
822 * Steps recompiled code.
823 *
824 * @returns VBox status code. The most important ones are: VINF_EM_STEP_EVENT,
825 * VINF_EM_RESCHEDULE, VINF_EM_SUSPEND, VINF_EM_RESET and VINF_EM_TERMINATE.
826 *
827 * @param pVM VM handle.
828 * @param pVCpu VMCPU handle.
829 */
830static int emR3RemStep(PVM pVM, PVMCPU pVCpu)
831{
832 LogFlow(("emR3RemStep: cs:eip=%04x:%08x\n", CPUMGetGuestCS(pVCpu), CPUMGetGuestEIP(pVCpu)));
833
834 EMRemLock(pVM);
835
836 /*
837 * Switch to REM, step instruction, switch back.
838 */
839 int rc = REMR3State(pVM, pVCpu);
840 if (RT_SUCCESS(rc))
841 {
842 rc = REMR3Step(pVM, pVCpu);
843 REMR3StateBack(pVM, pVCpu);
844 }
845 EMRemUnlock(pVM);
846
847 LogFlow(("emR3RemStep: returns %Rrc cs:eip=%04x:%08x\n", rc, CPUMGetGuestCS(pVCpu), CPUMGetGuestEIP(pVCpu)));
848 return rc;
849}
850
851
852/**
853 * Executes recompiled code.
854 *
855 * This function contains the recompiler version of the inner
856 * execution loop (the outer loop being in EMR3ExecuteVM()).
857 *
858 * @returns VBox status code. The most important ones are: VINF_EM_RESCHEDULE,
859 * VINF_EM_SUSPEND, VINF_EM_RESET and VINF_EM_TERMINATE.
860 *
861 * @param pVM VM handle.
862 * @param pVCpu VMCPU handle.
863 * @param pfFFDone Where to store an indicator telling wheter or not
864 * FFs were done before returning.
865 *
866 */
867static int emR3RemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone)
868{
869#ifdef LOG_ENABLED
870 PCPUMCTX pCtx = pVCpu->em.s.pCtx;
871 uint32_t cpl = CPUMGetGuestCPL(pVCpu, CPUMCTX2CORE(pCtx));
872
873 if (pCtx->eflags.Bits.u1VM)
874 Log(("EMV86: %04X:%08X IF=%d\n", pCtx->cs, pCtx->eip, pCtx->eflags.Bits.u1IF));
875 else
876 Log(("EMR%d: %04X:%08X ESP=%08X IF=%d CR0=%x\n", cpl, pCtx->cs, pCtx->eip, pCtx->esp, pCtx->eflags.Bits.u1IF, (uint32_t)pCtx->cr0));
877#endif
878 STAM_REL_PROFILE_ADV_START(&pVCpu->em.s.StatREMTotal, a);
879
880#if defined(VBOX_STRICT) && defined(DEBUG_bird)
881 AssertMsg( VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL)
882 || !MMHyperIsInsideArea(pVM, CPUMGetGuestEIP(pVCpu)), /** @todo #1419 - get flat address. */
883 ("cs:eip=%RX16:%RX32\n", CPUMGetGuestCS(pVCpu), CPUMGetGuestEIP(pVCpu)));
884#endif
885
886 /* Big lock, but you are not supposed to own any lock when coming in here. */
887 EMRemLock(pVM);
888
889 /*
890 * Spin till we get a forced action which returns anything but VINF_SUCCESS
891 * or the REM suggests raw-mode execution.
892 */
893 *pfFFDone = false;
894 bool fInREMState = false;
895 int rc = VINF_SUCCESS;
896
897 /* Flush the recompiler TLB if the VCPU has changed. */
898 if (pVM->em.s.idLastRemCpu != pVCpu->idCpu)
899 {
900 REMFlushTBs(pVM);
901 /* Also sync the entire state. */
902 CPUMSetChangedFlags(pVCpu, CPUM_CHANGED_ALL);
903 }
904 pVM->em.s.idLastRemCpu = pVCpu->idCpu;
905
906 for (;;)
907 {
908 /*
909 * Update REM state if not already in sync.
910 */
911 if (!fInREMState)
912 {
913 STAM_PROFILE_START(&pVCpu->em.s.StatREMSync, b);
914 rc = REMR3State(pVM, pVCpu);
915 STAM_PROFILE_STOP(&pVCpu->em.s.StatREMSync, b);
916 if (RT_FAILURE(rc))
917 break;
918 fInREMState = true;
919
920 /*
921 * We might have missed the raising of VMREQ, TIMER and some other
922 * imporant FFs while we were busy switching the state. So, check again.
923 */
924 if ( VM_FF_ISPENDING(pVM, VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_DBGF | VM_FF_TERMINATE | VM_FF_RESET)
925 || VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_TIMER | VMCPU_FF_REQUEST))
926 {
927 LogFlow(("emR3RemExecute: Skipping run, because FF is set. %#x\n", pVM->fGlobalForcedActions));
928 goto l_REMDoForcedActions;
929 }
930 }
931
932
933 /*
934 * Execute REM.
935 */
936 STAM_PROFILE_START(&pVCpu->em.s.StatREMExec, c);
937 rc = REMR3Run(pVM, pVCpu);
938 STAM_PROFILE_STOP(&pVCpu->em.s.StatREMExec, c);
939
940
941 /*
942 * Deal with high priority post execution FFs before doing anything else.
943 */
944 if ( VM_FF_ISPENDING(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
945 || VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
946 rc = emR3HighPriorityPostForcedActions(pVM, pVCpu, rc);
947
948 /*
949 * Process the returned status code.
950 * (Try keep this short! Call functions!)
951 */
952 if (rc != VINF_SUCCESS)
953 {
954 if (rc >= VINF_EM_FIRST && rc <= VINF_EM_LAST)
955 break;
956 if (rc != VINF_REM_INTERRUPED_FF)
957 {
958 /*
959 * Anything which is not known to us means an internal error
960 * and the termination of the VM!
961 */
962 AssertMsg(rc == VERR_REM_TOO_MANY_TRAPS, ("Unknown GC return code: %Rra\n", rc));
963 break;
964 }
965 }
966
967
968 /*
969 * Check and execute forced actions.
970 * Sync back the VM state before calling any of these.
971 */
972#ifdef VBOX_HIGH_RES_TIMERS_HACK
973 TMTimerPollVoid(pVM, pVCpu);
974#endif
975 AssertCompile((VMCPU_FF_ALL_BUT_RAW_MASK & ~(VMCPU_FF_CSAM_PENDING_ACTION | VMCPU_FF_CSAM_SCAN_PAGE)) & VMCPU_FF_TIMER);
976 if ( VM_FF_ISPENDING(pVM, VM_FF_ALL_BUT_RAW_MASK)
977 || VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_ALL_BUT_RAW_MASK & ~(VMCPU_FF_CSAM_PENDING_ACTION | VMCPU_FF_CSAM_SCAN_PAGE)))
978 {
979l_REMDoForcedActions:
980 if (fInREMState)
981 {
982 STAM_PROFILE_START(&pVCpu->em.s.StatREMSync, d);
983 REMR3StateBack(pVM, pVCpu);
984 STAM_PROFILE_STOP(&pVCpu->em.s.StatREMSync, d);
985 fInREMState = false;
986 }
987 STAM_REL_PROFILE_ADV_SUSPEND(&pVCpu->em.s.StatREMTotal, a);
988 rc = emR3ForcedActions(pVM, pVCpu, rc);
989 STAM_REL_PROFILE_ADV_RESUME(&pVCpu->em.s.StatREMTotal, a);
990 if ( rc != VINF_SUCCESS
991 && rc != VINF_EM_RESCHEDULE_REM)
992 {
993 *pfFFDone = true;
994 break;
995 }
996 }
997
998 } /* The Inner Loop, recompiled execution mode version. */
999
1000
1001 /*
1002 * Returning. Sync back the VM state if required.
1003 */
1004 if (fInREMState)
1005 {
1006 STAM_PROFILE_START(&pVCpu->em.s.StatREMSync, e);
1007 REMR3StateBack(pVM, pVCpu);
1008 STAM_PROFILE_STOP(&pVCpu->em.s.StatREMSync, e);
1009 }
1010 EMRemUnlock(pVM);
1011
1012 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatREMTotal, a);
1013 return rc;
1014}
1015
1016
1017#ifdef DEBUG
1018
1019int emR3SingleStepExecRem(PVM pVM, PVMCPU pVCpu, uint32_t cIterations)
1020{
1021 EMSTATE enmOldState = pVCpu->em.s.enmState;
1022
1023 pVCpu->em.s.enmState = EMSTATE_DEBUG_GUEST_REM;
1024
1025 Log(("Single step BEGIN:\n"));
1026 for (uint32_t i = 0; i < cIterations; i++)
1027 {
1028 DBGFR3PrgStep(pVCpu);
1029 DBGFR3DisasInstrCurrentLog(pVCpu, "RSS: ");
1030 emR3RemStep(pVM, pVCpu);
1031 if (emR3Reschedule(pVM, pVCpu, pVCpu->em.s.pCtx) != EMSTATE_REM)
1032 break;
1033 }
1034 Log(("Single step END:\n"));
1035 CPUMSetGuestEFlags(pVCpu, CPUMGetGuestEFlags(pVCpu) & ~X86_EFL_TF);
1036 pVCpu->em.s.enmState = enmOldState;
1037 return VINF_EM_RESCHEDULE;
1038}
1039
1040#endif /* DEBUG */
1041
1042
1043/**
1044 * Decides whether to execute RAW, HWACC or REM.
1045 *
1046 * @returns new EM state
1047 * @param pVM The VM.
1048 * @param pVCpu The VMCPU handle.
1049 * @param pCtx The CPU context.
1050 */
1051EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx)
1052{
1053 /*
1054 * When forcing raw-mode execution, things are simple.
1055 */
1056 if (pVCpu->em.s.fForceRAW)
1057 return EMSTATE_RAW;
1058
1059 /*
1060 * We stay in the wait for SIPI state unless explicitly told otherwise.
1061 */
1062 if (pVCpu->em.s.enmState == EMSTATE_WAIT_SIPI)
1063 return EMSTATE_WAIT_SIPI;
1064
1065 /* !!! THIS MUST BE IN SYNC WITH remR3CanExecuteRaw !!! */
1066 /* !!! THIS MUST BE IN SYNC WITH remR3CanExecuteRaw !!! */
1067 /* !!! THIS MUST BE IN SYNC WITH remR3CanExecuteRaw !!! */
1068
1069 X86EFLAGS EFlags = pCtx->eflags;
1070 if (HWACCMIsEnabled(pVM))
1071 {
1072 /* Hardware accelerated raw-mode:
1073 *
1074 * Typically only 32-bits protected mode, with paging enabled, code is allowed here.
1075 */
1076 if (HWACCMR3CanExecuteGuest(pVM, pCtx) == true)
1077 return EMSTATE_HWACC;
1078
1079 /* Note: Raw mode and hw accelerated mode are incompatible. The latter turns
1080 * off monitoring features essential for raw mode! */
1081 return EMSTATE_REM;
1082 }
1083
1084 /*
1085 * Standard raw-mode:
1086 *
1087 * Here we only support 16 & 32 bits protected mode ring 3 code that has no IO privileges
1088 * or 32 bits protected mode ring 0 code
1089 *
1090 * The tests are ordered by the likelyhood of being true during normal execution.
1091 */
1092 if (EFlags.u32 & (X86_EFL_TF /* | HF_INHIBIT_IRQ_MASK*/))
1093 {
1094 Log2(("raw mode refused: EFlags=%#x\n", EFlags.u32));
1095 return EMSTATE_REM;
1096 }
1097
1098#ifndef VBOX_RAW_V86
1099 if (EFlags.u32 & X86_EFL_VM) {
1100 Log2(("raw mode refused: VM_MASK\n"));
1101 return EMSTATE_REM;
1102 }
1103#endif
1104
1105 /** @todo check up the X86_CR0_AM flag in respect to raw mode!!! We're probably not emulating it right! */
1106 uint32_t u32CR0 = pCtx->cr0;
1107 if ((u32CR0 & (X86_CR0_PG | X86_CR0_PE)) != (X86_CR0_PG | X86_CR0_PE))
1108 {
1109 //Log2(("raw mode refused: %s%s%s\n", (u32CR0 & X86_CR0_PG) ? "" : " !PG", (u32CR0 & X86_CR0_PE) ? "" : " !PE", (u32CR0 & X86_CR0_AM) ? "" : " !AM"));
1110 return EMSTATE_REM;
1111 }
1112
1113 if (pCtx->cr4 & X86_CR4_PAE)
1114 {
1115 uint32_t u32Dummy, u32Features;
1116
1117 CPUMGetGuestCpuId(pVCpu, 1, &u32Dummy, &u32Dummy, &u32Dummy, &u32Features);
1118 if (!(u32Features & X86_CPUID_FEATURE_EDX_PAE))
1119 return EMSTATE_REM;
1120 }
1121
1122 unsigned uSS = pCtx->ss;
1123 if ( pCtx->eflags.Bits.u1VM
1124 || (uSS & X86_SEL_RPL) == 3)
1125 {
1126 if (!EMIsRawRing3Enabled(pVM))
1127 return EMSTATE_REM;
1128
1129 if (!(EFlags.u32 & X86_EFL_IF))
1130 {
1131 Log2(("raw mode refused: IF (RawR3)\n"));
1132 return EMSTATE_REM;
1133 }
1134
1135 if (!(u32CR0 & X86_CR0_WP) && EMIsRawRing0Enabled(pVM))
1136 {
1137 Log2(("raw mode refused: CR0.WP + RawR0\n"));
1138 return EMSTATE_REM;
1139 }
1140 }
1141 else
1142 {
1143 if (!EMIsRawRing0Enabled(pVM))
1144 return EMSTATE_REM;
1145
1146 /* Only ring 0 supervisor code. */
1147 if ((uSS & X86_SEL_RPL) != 0)
1148 {
1149 Log2(("raw r0 mode refused: CPL %d\n", uSS & X86_SEL_RPL));
1150 return EMSTATE_REM;
1151 }
1152
1153 // Let's start with pure 32 bits ring 0 code first
1154 /** @todo What's pure 32-bit mode? flat? */
1155 if ( !(pCtx->ssHid.Attr.n.u1DefBig)
1156 || !(pCtx->csHid.Attr.n.u1DefBig))
1157 {
1158 Log2(("raw r0 mode refused: SS/CS not 32bit\n"));
1159 return EMSTATE_REM;
1160 }
1161
1162 /* Write protection must be turned on, or else the guest can overwrite our hypervisor code and data. */
1163 if (!(u32CR0 & X86_CR0_WP))
1164 {
1165 Log2(("raw r0 mode refused: CR0.WP=0!\n"));
1166 return EMSTATE_REM;
1167 }
1168
1169 if (PATMShouldUseRawMode(pVM, (RTGCPTR)pCtx->eip))
1170 {
1171 Log2(("raw r0 mode forced: patch code\n"));
1172 return EMSTATE_RAW;
1173 }
1174
1175#if !defined(VBOX_ALLOW_IF0) && !defined(VBOX_RUN_INTERRUPT_GATE_HANDLERS)
1176 if (!(EFlags.u32 & X86_EFL_IF))
1177 {
1178 ////Log2(("R0: IF=0 VIF=%d %08X\n", eip, pVMeflags));
1179 //Log2(("RR0: Interrupts turned off; fall back to emulation\n"));
1180 return EMSTATE_REM;
1181 }
1182#endif
1183
1184 /** @todo still necessary??? */
1185 if (EFlags.Bits.u2IOPL != 0)
1186 {
1187 Log2(("raw r0 mode refused: IOPL %d\n", EFlags.Bits.u2IOPL));
1188 return EMSTATE_REM;
1189 }
1190 }
1191
1192 Assert(PGMPhysIsA20Enabled(pVCpu));
1193 return EMSTATE_RAW;
1194}
1195
1196
1197/**
1198 * Executes all high priority post execution force actions.
1199 *
1200 * @returns rc or a fatal status code.
1201 *
1202 * @param pVM VM handle.
1203 * @param pVCpu VMCPU handle.
1204 * @param rc The current rc.
1205 */
1206int emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc)
1207{
1208 if (VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_PDM_CRITSECT))
1209 PDMCritSectFF(pVCpu);
1210
1211 if (VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_CSAM_PENDING_ACTION))
1212 CSAMR3DoPendingAction(pVM, pVCpu);
1213
1214 if (VM_FF_ISPENDING(pVM, VM_FF_PGM_NO_MEMORY))
1215 {
1216 if ( rc > VINF_EM_NO_MEMORY
1217 && rc <= VINF_EM_LAST)
1218 rc = VINF_EM_NO_MEMORY;
1219 }
1220
1221 return rc;
1222}
1223
1224
1225/**
1226 * Executes all pending forced actions.
1227 *
1228 * Forced actions can cause execution delays and execution
1229 * rescheduling. The first we deal with using action priority, so
1230 * that for instance pending timers aren't scheduled and ran until
1231 * right before execution. The rescheduling we deal with using
1232 * return codes. The same goes for VM termination, only in that case
1233 * we exit everything.
1234 *
1235 * @returns VBox status code of equal or greater importance/severity than rc.
1236 * The most important ones are: VINF_EM_RESCHEDULE,
1237 * VINF_EM_SUSPEND, VINF_EM_RESET and VINF_EM_TERMINATE.
1238 *
1239 * @param pVM VM handle.
1240 * @param pVCpu VMCPU handle.
1241 * @param rc The current rc.
1242 *
1243 */
1244int emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc)
1245{
1246 STAM_REL_PROFILE_START(&pVCpu->em.s.StatForcedActions, a);
1247#ifdef VBOX_STRICT
1248 int rcIrq = VINF_SUCCESS;
1249#endif
1250 int rc2;
1251#define UPDATE_RC() \
1252 do { \
1253 AssertMsg(rc2 <= 0 || (rc2 >= VINF_EM_FIRST && rc2 <= VINF_EM_LAST), ("Invalid FF return code: %Rra\n", rc2)); \
1254 if (rc2 == VINF_SUCCESS || rc < VINF_SUCCESS) \
1255 break; \
1256 if (!rc || rc2 < rc) \
1257 rc = rc2; \
1258 } while (0)
1259
1260 /*
1261 * Post execution chunk first.
1262 */
1263 if ( VM_FF_ISPENDING(pVM, VM_FF_NORMAL_PRIORITY_POST_MASK)
1264 || VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_NORMAL_PRIORITY_POST_MASK))
1265 {
1266 /*
1267 * EMT Rendezvous (must be serviced before termination).
1268 */
1269 if (VM_FF_ISPENDING(pVM, VM_FF_EMT_RENDEZVOUS))
1270 {
1271 rc2 = VMMR3EmtRendezvousFF(pVM, pVCpu);
1272 UPDATE_RC();
1273 /** @todo HACK ALERT! The following test is to make sure EM+TM things the VM is
1274 * stopped/reset before the next VM state change is made. We need a better
1275 * solution for this, or at least make it possible to do: (rc >= VINF_EM_FIRST
1276 * && rc >= VINF_EM_SUSPEND). */
1277 if (RT_UNLIKELY(rc == VINF_EM_SUSPEND || rc == VINF_EM_RESET || rc == VINF_EM_OFF))
1278 {
1279 Log2(("emR3ForcedActions: returns %Rrc\n", rc));
1280 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatForcedActions, a);
1281 return rc;
1282 }
1283 }
1284
1285 /*
1286 * Termination request.
1287 */
1288 if (VM_FF_ISPENDING(pVM, VM_FF_TERMINATE))
1289 {
1290 Log2(("emR3ForcedActions: returns VINF_EM_TERMINATE\n"));
1291 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatForcedActions, a);
1292 return VINF_EM_TERMINATE;
1293 }
1294
1295 /*
1296 * Debugger Facility polling.
1297 */
1298 if (VM_FF_ISPENDING(pVM, VM_FF_DBGF))
1299 {
1300 rc2 = DBGFR3VMMForcedAction(pVM);
1301 UPDATE_RC();
1302 }
1303
1304 /*
1305 * Postponed reset request.
1306 */
1307 if (VM_FF_TESTANDCLEAR(pVM, VM_FF_RESET))
1308 {
1309 rc2 = VMR3Reset(pVM);
1310 UPDATE_RC();
1311 }
1312
1313 /*
1314 * CSAM page scanning.
1315 */
1316 if ( !VM_FF_ISPENDING(pVM, VM_FF_PGM_NO_MEMORY)
1317 && VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_CSAM_SCAN_PAGE))
1318 {
1319 PCPUMCTX pCtx = pVCpu->em.s.pCtx;
1320
1321 /** @todo: check for 16 or 32 bits code! (D bit in the code selector) */
1322 Log(("Forced action VMCPU_FF_CSAM_SCAN_PAGE\n"));
1323
1324 CSAMR3CheckCodeEx(pVM, CPUMCTX2CORE(pCtx), pCtx->eip);
1325 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_CSAM_SCAN_PAGE);
1326 }
1327
1328 /*
1329 * Out of memory? Putting this after CSAM as it may in theory cause us to run out of memory.
1330 */
1331 if (VM_FF_ISPENDING(pVM, VM_FF_PGM_NO_MEMORY))
1332 {
1333 rc2 = PGMR3PhysAllocateHandyPages(pVM);
1334 UPDATE_RC();
1335 if (rc == VINF_EM_NO_MEMORY)
1336 return rc;
1337 }
1338
1339 /* check that we got them all */
1340 AssertCompile(VM_FF_NORMAL_PRIORITY_POST_MASK == (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_RESET | VM_FF_PGM_NO_MEMORY | VM_FF_EMT_RENDEZVOUS));
1341 AssertCompile(VMCPU_FF_NORMAL_PRIORITY_POST_MASK == VMCPU_FF_CSAM_SCAN_PAGE);
1342 }
1343
1344 /*
1345 * Normal priority then.
1346 * (Executed in no particular order.)
1347 */
1348 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_NORMAL_PRIORITY_MASK, VM_FF_PGM_NO_MEMORY))
1349 {
1350 /*
1351 * PDM Queues are pending.
1352 */
1353 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_PDM_QUEUES, VM_FF_PGM_NO_MEMORY))
1354 PDMR3QueueFlushAll(pVM);
1355
1356 /*
1357 * PDM DMA transfers are pending.
1358 */
1359 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_PDM_DMA, VM_FF_PGM_NO_MEMORY))
1360 PDMR3DmaRun(pVM);
1361
1362 /*
1363 * EMT Rendezvous (make sure they are handled before the requests).
1364 */
1365 if (VM_FF_ISPENDING(pVM, VM_FF_EMT_RENDEZVOUS))
1366 {
1367 rc2 = VMMR3EmtRendezvousFF(pVM, pVCpu);
1368 UPDATE_RC();
1369 /** @todo HACK ALERT! The following test is to make sure EM+TM things the VM is
1370 * stopped/reset before the next VM state change is made. We need a better
1371 * solution for this, or at least make it possible to do: (rc >= VINF_EM_FIRST
1372 * && rc >= VINF_EM_SUSPEND). */
1373 if (RT_UNLIKELY(rc == VINF_EM_SUSPEND || rc == VINF_EM_RESET || rc == VINF_EM_OFF))
1374 {
1375 Log2(("emR3ForcedActions: returns %Rrc\n", rc));
1376 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatForcedActions, a);
1377 return rc;
1378 }
1379 }
1380
1381 /*
1382 * Requests from other threads.
1383 */
1384 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_REQUEST, VM_FF_PGM_NO_MEMORY))
1385 {
1386 rc2 = VMR3ReqProcessU(pVM->pUVM, VMCPUID_ANY);
1387 if (rc2 == VINF_EM_OFF || rc2 == VINF_EM_TERMINATE) /** @todo this shouldn't be necessary */
1388 {
1389 Log2(("emR3ForcedActions: returns %Rrc\n", rc2));
1390 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatForcedActions, a);
1391 return rc2;
1392 }
1393 UPDATE_RC();
1394 /** @todo HACK ALERT! The following test is to make sure EM+TM things the VM is
1395 * stopped/reset before the next VM state change is made. We need a better
1396 * solution for this, or at least make it possible to do: (rc >= VINF_EM_FIRST
1397 * && rc >= VINF_EM_SUSPEND). */
1398 if (RT_UNLIKELY(rc == VINF_EM_SUSPEND || rc == VINF_EM_RESET || rc == VINF_EM_OFF))
1399 {
1400 Log2(("emR3ForcedActions: returns %Rrc\n", rc));
1401 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatForcedActions, a);
1402 return rc;
1403 }
1404 }
1405
1406 /* Replay the handler notification changes. */
1407 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_REM_HANDLER_NOTIFY, VM_FF_PGM_NO_MEMORY))
1408 {
1409 /* Try not to cause deadlocks. */
1410 if ( pVM->cCpus == 1
1411 || ( !PGMIsLockOwner(pVM)
1412 && !IOMIsLockOwner(pVM))
1413 )
1414 {
1415 EMRemLock(pVM);
1416 REMR3ReplayHandlerNotifications(pVM);
1417 EMRemUnlock(pVM);
1418 }
1419 }
1420
1421 /* check that we got them all */
1422 AssertCompile(VM_FF_NORMAL_PRIORITY_MASK == (VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_REM_HANDLER_NOTIFY | VM_FF_EMT_RENDEZVOUS));
1423 }
1424
1425 /*
1426 * Normal priority then. (per-VCPU)
1427 * (Executed in no particular order.)
1428 */
1429 if ( !VM_FF_ISPENDING(pVM, VM_FF_PGM_NO_MEMORY)
1430 && VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_NORMAL_PRIORITY_MASK))
1431 {
1432 /*
1433 * Requests from other threads.
1434 */
1435 if (VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_REQUEST))
1436 {
1437 rc2 = VMR3ReqProcessU(pVM->pUVM, pVCpu->idCpu);
1438 if (rc2 == VINF_EM_OFF || rc2 == VINF_EM_TERMINATE || rc2 == VINF_EM_RESET)
1439 {
1440 Log2(("emR3ForcedActions: returns %Rrc\n", rc2));
1441 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatForcedActions, a);
1442 return rc2;
1443 }
1444 UPDATE_RC();
1445 /** @todo HACK ALERT! The following test is to make sure EM+TM things the VM is
1446 * stopped/reset before the next VM state change is made. We need a better
1447 * solution for this, or at least make it possible to do: (rc >= VINF_EM_FIRST
1448 * && rc >= VINF_EM_SUSPEND). */
1449 if (RT_UNLIKELY(rc == VINF_EM_SUSPEND || rc == VINF_EM_RESET || rc == VINF_EM_OFF))
1450 {
1451 Log2(("emR3ForcedActions: returns %Rrc\n", rc));
1452 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatForcedActions, a);
1453 return rc;
1454 }
1455 }
1456
1457 /* check that we got them all */
1458 Assert(!(VMCPU_FF_NORMAL_PRIORITY_MASK & ~(VMCPU_FF_REQUEST)));
1459 }
1460
1461 /*
1462 * High priority pre execution chunk last.
1463 * (Executed in ascending priority order.)
1464 */
1465 if ( VM_FF_ISPENDING(pVM, VM_FF_HIGH_PRIORITY_PRE_MASK)
1466 || VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_PRE_MASK))
1467 {
1468 /*
1469 * Timers before interrupts.
1470 */
1471 if ( VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_TIMER)
1472 && !VM_FF_ISPENDING(pVM, VM_FF_PGM_NO_MEMORY))
1473 TMR3TimerQueuesDo(pVM);
1474
1475 /*
1476 * The instruction following an emulated STI should *always* be executed!
1477 */
1478 if ( VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_INHIBIT_INTERRUPTS)
1479 && !VM_FF_ISPENDING(pVM, VM_FF_PGM_NO_MEMORY))
1480 {
1481 Log(("VM_FF_EMULATED_STI at %RGv successor %RGv\n", (RTGCPTR)CPUMGetGuestRIP(pVCpu), EMGetInhibitInterruptsPC(pVCpu)));
1482 if (CPUMGetGuestEIP(pVCpu) != EMGetInhibitInterruptsPC(pVCpu))
1483 {
1484 /* Note: we intentionally don't clear VM_FF_INHIBIT_INTERRUPTS here if the eip is the same as the inhibited instr address.
1485 * Before we are able to execute this instruction in raw mode (iret to guest code) an external interrupt might
1486 * force a world switch again. Possibly allowing a guest interrupt to be dispatched in the process. This could
1487 * break the guest. Sounds very unlikely, but such timing sensitive problem are not as rare as you might think.
1488 */
1489 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INHIBIT_INTERRUPTS);
1490 }
1491 if (HWACCMR3IsActive(pVCpu))
1492 rc2 = VINF_EM_RESCHEDULE_HWACC;
1493 else
1494 rc2 = PATMAreInterruptsEnabled(pVM) ? VINF_EM_RESCHEDULE_RAW : VINF_EM_RESCHEDULE_REM;
1495
1496 UPDATE_RC();
1497 }
1498
1499 /*
1500 * Interrupts.
1501 */
1502 if ( !VM_FF_ISPENDING(pVM, VM_FF_PGM_NO_MEMORY)
1503 && !VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_INHIBIT_INTERRUPTS)
1504 && (!rc || rc >= VINF_EM_RESCHEDULE_HWACC)
1505 && !TRPMHasTrap(pVCpu) /* an interrupt could already be scheduled for dispatching in the recompiler. */
1506 && PATMAreInterruptsEnabled(pVM)
1507 && !HWACCMR3IsEventPending(pVCpu))
1508 {
1509 Assert(pVCpu->em.s.enmState != EMSTATE_WAIT_SIPI);
1510 if (VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC))
1511 {
1512 /* Note: it's important to make sure the return code from TRPMR3InjectEvent isn't ignored! */
1513 /** @todo this really isn't nice, should properly handle this */
1514 rc2 = TRPMR3InjectEvent(pVM, pVCpu, TRPM_HARDWARE_INT);
1515#ifdef VBOX_STRICT
1516 rcIrq = rc2;
1517#endif
1518 UPDATE_RC();
1519 }
1520 /** @todo really ugly; if we entered the hlt state when exiting the recompiler and an interrupt was pending, we previously got stuck in the halted state. */
1521 else if (REMR3QueryPendingInterrupt(pVM, pVCpu) != REM_NO_PENDING_IRQ)
1522 {
1523 rc2 = VINF_EM_RESCHEDULE_REM;
1524 UPDATE_RC();
1525 }
1526 }
1527
1528 /*
1529 * Allocate handy pages.
1530 */
1531 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_PGM_NEED_HANDY_PAGES, VM_FF_PGM_NO_MEMORY))
1532 {
1533 rc2 = PGMR3PhysAllocateHandyPages(pVM);
1534 UPDATE_RC();
1535 }
1536
1537 /*
1538 * Debugger Facility request.
1539 */
1540 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_DBGF, VM_FF_PGM_NO_MEMORY))
1541 {
1542 rc2 = DBGFR3VMMForcedAction(pVM);
1543 UPDATE_RC();
1544 }
1545
1546 /*
1547 * EMT Rendezvous (must be serviced before termination).
1548 */
1549 if (VM_FF_ISPENDING(pVM, VM_FF_EMT_RENDEZVOUS))
1550 {
1551 rc2 = VMMR3EmtRendezvousFF(pVM, pVCpu);
1552 UPDATE_RC();
1553 /** @todo HACK ALERT! The following test is to make sure EM+TM things the VM is
1554 * stopped/reset before the next VM state change is made. We need a better
1555 * solution for this, or at least make it possible to do: (rc >= VINF_EM_FIRST
1556 * && rc >= VINF_EM_SUSPEND). */
1557 if (RT_UNLIKELY(rc == VINF_EM_SUSPEND || rc == VINF_EM_RESET || rc == VINF_EM_OFF))
1558 {
1559 Log2(("emR3ForcedActions: returns %Rrc\n", rc));
1560 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatForcedActions, a);
1561 return rc;
1562 }
1563 }
1564
1565 /*
1566 * Termination request.
1567 */
1568 if (VM_FF_ISPENDING(pVM, VM_FF_TERMINATE))
1569 {
1570 Log2(("emR3ForcedActions: returns VINF_EM_TERMINATE\n"));
1571 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatForcedActions, a);
1572 return VINF_EM_TERMINATE;
1573 }
1574
1575 /*
1576 * Out of memory? Since most of our fellow high priority actions may cause us
1577 * to run out of memory, we're employing VM_FF_IS_PENDING_EXCEPT and putting this
1578 * at the end rather than the start. Also, VM_FF_TERMINATE has higher priority
1579 * than us since we can terminate without allocating more memory.
1580 */
1581 if (VM_FF_ISPENDING(pVM, VM_FF_PGM_NO_MEMORY))
1582 {
1583 rc2 = PGMR3PhysAllocateHandyPages(pVM);
1584 UPDATE_RC();
1585 if (rc == VINF_EM_NO_MEMORY)
1586 return rc;
1587 }
1588
1589 /*
1590 * If the virtual sync clock is still stopped, make TM restart it.
1591 */
1592 if (VM_FF_ISPENDING(pVM, VM_FF_TM_VIRTUAL_SYNC))
1593 TMR3VirtualSyncFF(pVM, pVCpu);
1594
1595#ifdef DEBUG
1596 /*
1597 * Debug, pause the VM.
1598 */
1599 if (VM_FF_ISPENDING(pVM, VM_FF_DEBUG_SUSPEND))
1600 {
1601 VM_FF_CLEAR(pVM, VM_FF_DEBUG_SUSPEND);
1602 Log(("emR3ForcedActions: returns VINF_EM_SUSPEND\n"));
1603 return VINF_EM_SUSPEND;
1604 }
1605#endif
1606
1607 /* check that we got them all */
1608 AssertCompile(VM_FF_HIGH_PRIORITY_PRE_MASK == (VM_FF_TM_VIRTUAL_SYNC | VM_FF_DBGF | VM_FF_TERMINATE | VM_FF_DEBUG_SUSPEND | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY | VM_FF_EMT_RENDEZVOUS));
1609 AssertCompile(VMCPU_FF_HIGH_PRIORITY_PRE_MASK == (VMCPU_FF_TIMER | VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC | VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT | VMCPU_FF_INHIBIT_INTERRUPTS));
1610 }
1611
1612#undef UPDATE_RC
1613 Log2(("emR3ForcedActions: returns %Rrc\n", rc));
1614 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatForcedActions, a);
1615 Assert(rcIrq == VINF_SUCCESS || rcIrq == rc);
1616 return rc;
1617}
1618
1619/**
1620 * Release the IOM lock if owned by the current VCPU
1621 *
1622 * @param pVM The VM to operate on.
1623 */
1624VMMR3DECL(void) EMR3ReleaseOwnedLocks(PVM pVM)
1625{
1626 while (PDMCritSectIsOwner(&pVM->em.s.CritSectREM))
1627 PDMCritSectLeave(&pVM->em.s.CritSectREM);
1628}
1629
1630
1631/**
1632 * Execute VM.
1633 *
1634 * This function is the main loop of the VM. The emulation thread
1635 * calls this function when the VM has been successfully constructed
1636 * and we're ready for executing the VM.
1637 *
1638 * Returning from this function means that the VM is turned off or
1639 * suspended (state already saved) and deconstruction in next in line.
1640 *
1641 * All interaction from other thread are done using forced actions
1642 * and signaling of the wait object.
1643 *
1644 * @returns VBox status code, informational status codes may indicate failure.
1645 * @param pVM The VM to operate on.
1646 * @param pVCpu The VMCPU to operate on.
1647 */
1648VMMR3DECL(int) EMR3ExecuteVM(PVM pVM, PVMCPU pVCpu)
1649{
1650 Log(("EMR3ExecuteVM: pVM=%p enmVMState=%d (%s) enmState=%d (%s) enmPrevState=%d (%s) fForceRAW=%RTbool\n",
1651 pVM,
1652 pVM->enmVMState, VMR3GetStateName(pVM->enmVMState),
1653 pVCpu->em.s.enmState, emR3GetStateName(pVCpu->em.s.enmState),
1654 pVCpu->em.s.enmPrevState, emR3GetStateName(pVCpu->em.s.enmPrevState),
1655 pVCpu->em.s.fForceRAW));
1656 VM_ASSERT_EMT(pVM);
1657 AssertMsg( pVCpu->em.s.enmState == EMSTATE_NONE
1658 || pVCpu->em.s.enmState == EMSTATE_WAIT_SIPI
1659 || pVCpu->em.s.enmState == EMSTATE_SUSPENDED,
1660 ("%s\n", emR3GetStateName(pVCpu->em.s.enmState)));
1661
1662 int rc = setjmp(pVCpu->em.s.u.FatalLongJump);
1663 if (rc == 0)
1664 {
1665 /*
1666 * Start the virtual time.
1667 */
1668 TMR3NotifyResume(pVM, pVCpu);
1669
1670 /*
1671 * The Outer Main Loop.
1672 */
1673 bool fFFDone = false;
1674
1675 /* Reschedule right away to start in the right state. */
1676 rc = VINF_SUCCESS;
1677
1678 /* If resuming after a pause or a state load, restore the previous
1679 state or else we'll start executing code. Else, just reschedule. */
1680 if ( pVCpu->em.s.enmState == EMSTATE_SUSPENDED
1681 && ( pVCpu->em.s.enmPrevState == EMSTATE_WAIT_SIPI
1682 || pVCpu->em.s.enmPrevState == EMSTATE_HALTED))
1683 pVCpu->em.s.enmState = pVCpu->em.s.enmPrevState;
1684 else
1685 pVCpu->em.s.enmState = emR3Reschedule(pVM, pVCpu, pVCpu->em.s.pCtx);
1686
1687 STAM_REL_PROFILE_ADV_START(&pVCpu->em.s.StatTotal, x);
1688 for (;;)
1689 {
1690 /*
1691 * Before we can schedule anything (we're here because
1692 * scheduling is required) we must service any pending
1693 * forced actions to avoid any pending action causing
1694 * immediate rescheduling upon entering an inner loop
1695 *
1696 * Do forced actions.
1697 */
1698 if ( !fFFDone
1699 && rc != VINF_EM_TERMINATE
1700 && rc != VINF_EM_OFF
1701 && ( VM_FF_ISPENDING(pVM, VM_FF_ALL_BUT_RAW_MASK)
1702 || VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_ALL_BUT_RAW_MASK)))
1703 {
1704 rc = emR3ForcedActions(pVM, pVCpu, rc);
1705 if ( ( rc == VINF_EM_RESCHEDULE_REM
1706 || rc == VINF_EM_RESCHEDULE_HWACC)
1707 && pVCpu->em.s.fForceRAW)
1708 rc = VINF_EM_RESCHEDULE_RAW;
1709 }
1710 else if (fFFDone)
1711 fFFDone = false;
1712
1713 /*
1714 * Now what to do?
1715 */
1716 Log2(("EMR3ExecuteVM: rc=%Rrc\n", rc));
1717 switch (rc)
1718 {
1719 /*
1720 * Keep doing what we're currently doing.
1721 */
1722 case VINF_SUCCESS:
1723 break;
1724
1725 /*
1726 * Reschedule - to raw-mode execution.
1727 */
1728 case VINF_EM_RESCHEDULE_RAW:
1729 Log2(("EMR3ExecuteVM: VINF_EM_RESCHEDULE_RAW: %d -> %d (EMSTATE_RAW)\n", pVCpu->em.s.enmState, EMSTATE_RAW));
1730 pVCpu->em.s.enmState = EMSTATE_RAW;
1731 break;
1732
1733 /*
1734 * Reschedule - to hardware accelerated raw-mode execution.
1735 */
1736 case VINF_EM_RESCHEDULE_HWACC:
1737 Log2(("EMR3ExecuteVM: VINF_EM_RESCHEDULE_HWACC: %d -> %d (EMSTATE_HWACC)\n", pVCpu->em.s.enmState, EMSTATE_HWACC));
1738 Assert(!pVCpu->em.s.fForceRAW);
1739 pVCpu->em.s.enmState = EMSTATE_HWACC;
1740 break;
1741
1742 /*
1743 * Reschedule - to recompiled execution.
1744 */
1745 case VINF_EM_RESCHEDULE_REM:
1746 Log2(("EMR3ExecuteVM: VINF_EM_RESCHEDULE_REM: %d -> %d (EMSTATE_REM)\n", pVCpu->em.s.enmState, EMSTATE_REM));
1747 pVCpu->em.s.enmState = EMSTATE_REM;
1748 break;
1749
1750#ifdef VBOX_WITH_VMI
1751 /*
1752 * Reschedule - parav call.
1753 */
1754 case VINF_EM_RESCHEDULE_PARAV:
1755 Log2(("EMR3ExecuteVM: VINF_EM_RESCHEDULE_PARAV: %d -> %d (EMSTATE_PARAV)\n", pVCpu->em.s.enmState, EMSTATE_PARAV));
1756 pVCpu->em.s.enmState = EMSTATE_PARAV;
1757 break;
1758#endif
1759
1760 /*
1761 * Resume.
1762 */
1763 case VINF_EM_RESUME:
1764 Log2(("EMR3ExecuteVM: VINF_EM_RESUME: %d -> VINF_EM_RESCHEDULE\n", pVCpu->em.s.enmState));
1765 /* Don't reschedule in the halted or wait for SIPI case. */
1766 if ( pVCpu->em.s.enmPrevState == EMSTATE_WAIT_SIPI
1767 || pVCpu->em.s.enmPrevState == EMSTATE_HALTED)
1768 break;
1769 /* fall through and get scheduled. */
1770
1771 /*
1772 * Reschedule.
1773 */
1774 case VINF_EM_RESCHEDULE:
1775 {
1776 EMSTATE enmState = emR3Reschedule(pVM, pVCpu, pVCpu->em.s.pCtx);
1777 Log2(("EMR3ExecuteVM: VINF_EM_RESCHEDULE: %d -> %d (%s)\n", pVCpu->em.s.enmState, enmState, emR3GetStateName(enmState)));
1778 pVCpu->em.s.enmState = enmState;
1779 break;
1780 }
1781
1782 /*
1783 * Halted.
1784 */
1785 case VINF_EM_HALT:
1786 Log2(("EMR3ExecuteVM: VINF_EM_HALT: %d -> %d\n", pVCpu->em.s.enmState, EMSTATE_HALTED));
1787 pVCpu->em.s.enmState = EMSTATE_HALTED;
1788 break;
1789
1790 /*
1791 * Switch to the wait for SIPI state (application processor only)
1792 */
1793 case VINF_EM_WAIT_SIPI:
1794 Assert(pVCpu->idCpu != 0);
1795 Log2(("EMR3ExecuteVM: VINF_EM_WAIT_SIPI: %d -> %d\n", pVCpu->em.s.enmState, EMSTATE_WAIT_SIPI));
1796 pVCpu->em.s.enmState = EMSTATE_WAIT_SIPI;
1797 break;
1798
1799
1800 /*
1801 * Suspend.
1802 */
1803 case VINF_EM_SUSPEND:
1804 Log2(("EMR3ExecuteVM: VINF_EM_SUSPEND: %d -> %d\n", pVCpu->em.s.enmState, EMSTATE_SUSPENDED));
1805 pVCpu->em.s.enmPrevState = pVCpu->em.s.enmState;
1806 pVCpu->em.s.enmState = EMSTATE_SUSPENDED;
1807 break;
1808
1809 /*
1810 * Reset.
1811 * We might end up doing a double reset for now, we'll have to clean up the mess later.
1812 */
1813 case VINF_EM_RESET:
1814 {
1815 if (pVCpu->idCpu == 0)
1816 {
1817 EMSTATE enmState = emR3Reschedule(pVM, pVCpu, pVCpu->em.s.pCtx);
1818 Log2(("EMR3ExecuteVM: VINF_EM_RESET: %d -> %d (%s)\n", pVCpu->em.s.enmState, enmState, emR3GetStateName(enmState)));
1819 pVCpu->em.s.enmState = enmState;
1820 }
1821 else
1822 {
1823 /* All other VCPUs go into the wait for SIPI state. */
1824 pVCpu->em.s.enmState = EMSTATE_WAIT_SIPI;
1825 }
1826 break;
1827 }
1828
1829 /*
1830 * Power Off.
1831 */
1832 case VINF_EM_OFF:
1833 pVCpu->em.s.enmState = EMSTATE_TERMINATING;
1834 Log2(("EMR3ExecuteVM: returns VINF_EM_OFF (%d -> %d)\n", pVCpu->em.s.enmState, EMSTATE_TERMINATING));
1835 TMR3NotifySuspend(pVM, pVCpu);
1836 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatTotal, x);
1837 return rc;
1838
1839 /*
1840 * Terminate the VM.
1841 */
1842 case VINF_EM_TERMINATE:
1843 pVCpu->em.s.enmState = EMSTATE_TERMINATING;
1844 Log(("EMR3ExecuteVM returns VINF_EM_TERMINATE (%d -> %d)\n", pVCpu->em.s.enmState, EMSTATE_TERMINATING));
1845 if (pVM->enmVMState < VMSTATE_DESTROYING) /* ugly */
1846 TMR3NotifySuspend(pVM, pVCpu);
1847 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatTotal, x);
1848 return rc;
1849
1850
1851 /*
1852 * Out of memory, suspend the VM and stuff.
1853 */
1854 case VINF_EM_NO_MEMORY:
1855 Log2(("EMR3ExecuteVM: VINF_EM_NO_MEMORY: %d -> %d\n", pVCpu->em.s.enmState, EMSTATE_SUSPENDED));
1856 pVCpu->em.s.enmPrevState = pVCpu->em.s.enmState;
1857 pVCpu->em.s.enmState = EMSTATE_SUSPENDED;
1858 TMR3NotifySuspend(pVM, pVCpu);
1859 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatTotal, x);
1860
1861 rc = VMSetRuntimeError(pVM, VMSETRTERR_FLAGS_SUSPEND, "HostMemoryLow",
1862 N_("Unable to allocate and lock memory. The virtual machine will be paused. Please close applications to free up memory or close the VM"));
1863 if (rc != VINF_EM_SUSPEND)
1864 {
1865 if (RT_SUCCESS_NP(rc))
1866 {
1867 AssertLogRelMsgFailed(("%Rrc\n", rc));
1868 rc = VERR_EM_INTERNAL_ERROR;
1869 }
1870 pVCpu->em.s.enmState = EMSTATE_GURU_MEDITATION;
1871 }
1872 return rc;
1873
1874 /*
1875 * Guest debug events.
1876 */
1877 case VINF_EM_DBG_STEPPED:
1878 AssertMsgFailed(("VINF_EM_DBG_STEPPED cannot be here!"));
1879 case VINF_EM_DBG_STOP:
1880 case VINF_EM_DBG_BREAKPOINT:
1881 case VINF_EM_DBG_STEP:
1882 if (pVCpu->em.s.enmState == EMSTATE_RAW)
1883 {
1884 Log2(("EMR3ExecuteVM: %Rrc: %d -> %d\n", rc, pVCpu->em.s.enmState, EMSTATE_DEBUG_GUEST_RAW));
1885 pVCpu->em.s.enmState = EMSTATE_DEBUG_GUEST_RAW;
1886 }
1887 else
1888 {
1889 Log2(("EMR3ExecuteVM: %Rrc: %d -> %d\n", rc, pVCpu->em.s.enmState, EMSTATE_DEBUG_GUEST_REM));
1890 pVCpu->em.s.enmState = EMSTATE_DEBUG_GUEST_REM;
1891 }
1892 break;
1893
1894 /*
1895 * Hypervisor debug events.
1896 */
1897 case VINF_EM_DBG_HYPER_STEPPED:
1898 case VINF_EM_DBG_HYPER_BREAKPOINT:
1899 case VINF_EM_DBG_HYPER_ASSERTION:
1900 Log2(("EMR3ExecuteVM: %Rrc: %d -> %d\n", rc, pVCpu->em.s.enmState, EMSTATE_DEBUG_HYPER));
1901 pVCpu->em.s.enmState = EMSTATE_DEBUG_HYPER;
1902 break;
1903
1904 /*
1905 * Guru mediations.
1906 */
1907 case VERR_VMM_RING0_ASSERTION:
1908 Log(("EMR3ExecuteVM: %Rrc: %d -> %d (EMSTATE_GURU_MEDITATION)\n", rc, pVCpu->em.s.enmState, EMSTATE_GURU_MEDITATION));
1909 pVCpu->em.s.enmState = EMSTATE_GURU_MEDITATION;
1910 break;
1911
1912 /*
1913 * Any error code showing up here other than the ones we
1914 * know and process above are considered to be FATAL.
1915 *
1916 * Unknown warnings and informational status codes are also
1917 * included in this.
1918 */
1919 default:
1920 if (RT_SUCCESS_NP(rc))
1921 {
1922 AssertMsgFailed(("Unexpected warning or informational status code %Rra!\n", rc));
1923 rc = VERR_EM_INTERNAL_ERROR;
1924 }
1925 Log(("EMR3ExecuteVM: %Rrc: %d -> %d (EMSTATE_GURU_MEDITATION)\n", rc, pVCpu->em.s.enmState, EMSTATE_GURU_MEDITATION));
1926 pVCpu->em.s.enmState = EMSTATE_GURU_MEDITATION;
1927 break;
1928 }
1929
1930 STAM_PROFILE_ADV_STOP(&pVCpu->em.s.StatTotal, x); /* (skip this in release) */
1931 STAM_PROFILE_ADV_START(&pVCpu->em.s.StatTotal, x);
1932
1933 /*
1934 * Act on the state.
1935 */
1936 switch (pVCpu->em.s.enmState)
1937 {
1938 /*
1939 * Execute raw.
1940 */
1941 case EMSTATE_RAW:
1942 rc = emR3RawExecute(pVM, pVCpu, &fFFDone);
1943 break;
1944
1945 /*
1946 * Execute hardware accelerated raw.
1947 */
1948 case EMSTATE_HWACC:
1949 rc = emR3HwAccExecute(pVM, pVCpu, &fFFDone);
1950 break;
1951
1952 /*
1953 * Execute recompiled.
1954 */
1955 case EMSTATE_REM:
1956 rc = emR3RemExecute(pVM, pVCpu, &fFFDone);
1957 Log2(("EMR3ExecuteVM: emR3RemExecute -> %Rrc\n", rc));
1958 break;
1959
1960#ifdef VBOX_WITH_VMI
1961 /*
1962 * Execute PARAV function.
1963 */
1964 case EMSTATE_PARAV:
1965 rc = PARAVCallFunction(pVM);
1966 pVCpu->em.s.enmState = EMSTATE_REM;
1967 break;
1968#endif
1969
1970 /*
1971 * Application processor execution halted until SIPI.
1972 */
1973 case EMSTATE_WAIT_SIPI:
1974 /* no break */
1975 /*
1976 * hlt - execution halted until interrupt.
1977 */
1978 case EMSTATE_HALTED:
1979 {
1980 STAM_REL_PROFILE_START(&pVCpu->em.s.StatHalted, y);
1981 rc = VMR3WaitHalted(pVM, pVCpu, !(CPUMGetGuestEFlags(pVCpu) & X86_EFL_IF));
1982 STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatHalted, y);
1983 break;
1984 }
1985
1986 /*
1987 * Suspended - return to VM.cpp.
1988 */
1989 case EMSTATE_SUSPENDED:
1990 TMR3NotifySuspend(pVM, pVCpu);
1991 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatTotal, x);
1992 Log(("EMR3ExecuteVM: actually returns %Rrc (state %s / %s)\n", rc, emR3GetStateName(pVCpu->em.s.enmState), emR3GetStateName(pVCpu->em.s.enmPrevState)));
1993 return VINF_EM_SUSPEND;
1994
1995 /*
1996 * Debugging in the guest.
1997 */
1998 case EMSTATE_DEBUG_GUEST_REM:
1999 case EMSTATE_DEBUG_GUEST_RAW:
2000 TMR3NotifySuspend(pVM, pVCpu);
2001 rc = emR3Debug(pVM, pVCpu, rc);
2002 TMR3NotifyResume(pVM, pVCpu);
2003 Log2(("EMR3ExecuteVM: enmr3Debug -> %Rrc (state %d)\n", rc, pVCpu->em.s.enmState));
2004 break;
2005
2006 /*
2007 * Debugging in the hypervisor.
2008 */
2009 case EMSTATE_DEBUG_HYPER:
2010 {
2011 TMR3NotifySuspend(pVM, pVCpu);
2012 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatTotal, x);
2013
2014 rc = emR3Debug(pVM, pVCpu, rc);
2015 Log2(("EMR3ExecuteVM: enmr3Debug -> %Rrc (state %d)\n", rc, pVCpu->em.s.enmState));
2016 if (rc != VINF_SUCCESS)
2017 {
2018 /* switch to guru meditation mode */
2019 pVCpu->em.s.enmState = EMSTATE_GURU_MEDITATION;
2020 VMMR3FatalDump(pVM, pVCpu, rc);
2021 Log(("EMR3ExecuteVM: actually returns %Rrc (state %s / %s)\n", rc, emR3GetStateName(pVCpu->em.s.enmState), emR3GetStateName(pVCpu->em.s.enmPrevState)));
2022 return rc;
2023 }
2024
2025 STAM_REL_PROFILE_ADV_START(&pVCpu->em.s.StatTotal, x);
2026 TMR3NotifyResume(pVM, pVCpu);
2027 break;
2028 }
2029
2030 /*
2031 * Guru meditation takes place in the debugger.
2032 */
2033 case EMSTATE_GURU_MEDITATION:
2034 {
2035 TMR3NotifySuspend(pVM, pVCpu);
2036 VMMR3FatalDump(pVM, pVCpu, rc);
2037 emR3Debug(pVM, pVCpu, rc);
2038 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatTotal, x);
2039 Log(("EMR3ExecuteVM: actually returns %Rrc (state %s / %s)\n", rc, emR3GetStateName(pVCpu->em.s.enmState), emR3GetStateName(pVCpu->em.s.enmPrevState)));
2040 return rc;
2041 }
2042
2043 /*
2044 * The states we don't expect here.
2045 */
2046 case EMSTATE_NONE:
2047 case EMSTATE_TERMINATING:
2048 default:
2049 AssertMsgFailed(("EMR3ExecuteVM: Invalid state %d!\n", pVCpu->em.s.enmState));
2050 pVCpu->em.s.enmState = EMSTATE_GURU_MEDITATION;
2051 TMR3NotifySuspend(pVM, pVCpu);
2052 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatTotal, x);
2053 Log(("EMR3ExecuteVM: actually returns %Rrc (state %s / %s)\n", rc, emR3GetStateName(pVCpu->em.s.enmState), emR3GetStateName(pVCpu->em.s.enmPrevState)));
2054 return VERR_EM_INTERNAL_ERROR;
2055 }
2056 } /* The Outer Main Loop */
2057 }
2058 else
2059 {
2060 /*
2061 * Fatal error.
2062 */
2063 Log(("EMR3ExecuteVM: returns %Rrc because of longjmp / fatal error; (state %s / %s)\n", rc, emR3GetStateName(pVCpu->em.s.enmState), emR3GetStateName(pVCpu->em.s.enmPrevState)));
2064 TMR3NotifySuspend(pVM, pVCpu);
2065 VMMR3FatalDump(pVM, pVCpu, rc);
2066 emR3Debug(pVM, pVCpu, rc);
2067 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatTotal, x);
2068 /** @todo change the VM state! */
2069 return rc;
2070 }
2071
2072 /* (won't ever get here). */
2073 AssertFailed();
2074}
2075
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use