1 | /* $Id: EMR3Nem.cpp 71293 2018-03-09 21:11:20Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * EM - Execution Monitor / Manager - NEM interface.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_EM
|
---|
23 | #include <VBox/vmm/em.h>
|
---|
24 | #include <VBox/vmm/vmm.h>
|
---|
25 | #include <VBox/vmm/csam.h>
|
---|
26 | #include <VBox/vmm/selm.h>
|
---|
27 | #include <VBox/vmm/trpm.h>
|
---|
28 | #include <VBox/vmm/iem.h>
|
---|
29 | #include <VBox/vmm/iom.h>
|
---|
30 | #include <VBox/vmm/nem.h>
|
---|
31 | #include <VBox/vmm/dbgf.h>
|
---|
32 | #include <VBox/vmm/pgm.h>
|
---|
33 | #ifdef VBOX_WITH_REM
|
---|
34 | # include <VBox/vmm/rem.h>
|
---|
35 | #endif
|
---|
36 | #include <VBox/vmm/tm.h>
|
---|
37 | #include <VBox/vmm/mm.h>
|
---|
38 | #include <VBox/vmm/ssm.h>
|
---|
39 | #include <VBox/vmm/pdmapi.h>
|
---|
40 | #include <VBox/vmm/pdmcritsect.h>
|
---|
41 | #include <VBox/vmm/pdmqueue.h>
|
---|
42 | #include "EMInternal.h"
|
---|
43 | #include <VBox/vmm/vm.h>
|
---|
44 | #include <VBox/vmm/gim.h>
|
---|
45 | #include <VBox/vmm/cpumdis.h>
|
---|
46 | #include <VBox/dis.h>
|
---|
47 | #include <VBox/disopcode.h>
|
---|
48 | #include <VBox/vmm/dbgf.h>
|
---|
49 | #include "VMMTracing.h"
|
---|
50 |
|
---|
51 | #include <iprt/asm.h>
|
---|
52 |
|
---|
53 |
|
---|
54 | /*********************************************************************************************************************************
|
---|
55 | * Defined Constants And Macros *
|
---|
56 | *********************************************************************************************************************************/
|
---|
57 | #if 0 /* Disabled till after 2.1.0 when we've time to test it. */
|
---|
58 | #define EM_NOTIFY_HM
|
---|
59 | #endif
|
---|
60 |
|
---|
61 |
|
---|
62 | /*********************************************************************************************************************************
|
---|
63 | * Internal Functions *
|
---|
64 | *********************************************************************************************************************************/
|
---|
65 | DECLINLINE(int) emR3NemExecuteInstruction(PVM pVM, PVMCPU pVCpu, const char *pszPrefix, int rcGC = VINF_SUCCESS);
|
---|
66 | static int emR3NemExecuteIOInstruction(PVM pVM, PVMCPU pVCpu);
|
---|
67 | static int emR3NemForcedActions(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
|
---|
68 |
|
---|
69 | #define EMHANDLERC_WITH_NEM
|
---|
70 | #define emR3ExecuteInstruction emR3NemExecuteInstruction
|
---|
71 | #define emR3ExecuteIOInstruction emR3NemExecuteIOInstruction
|
---|
72 | #include "EMHandleRCTmpl.h"
|
---|
73 |
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Executes instruction in HM mode if we can.
|
---|
77 | *
|
---|
78 | * This is somewhat comparable to REMR3EmulateInstruction.
|
---|
79 | *
|
---|
80 | * @returns VBox strict status code.
|
---|
81 | * @retval VINF_EM_DBG_STEPPED on success.
|
---|
82 | * @retval VERR_EM_CANNOT_EXEC_GUEST if we cannot execute guest instructions in
|
---|
83 | * HM right now.
|
---|
84 | *
|
---|
85 | * @param pVM The cross context VM structure.
|
---|
86 | * @param pVCpu The cross context virtual CPU structure for the calling EMT.
|
---|
87 | * @param fFlags Combinations of EM_ONE_INS_FLAGS_XXX.
|
---|
88 | * @thread EMT.
|
---|
89 | */
|
---|
90 | VBOXSTRICTRC emR3NemSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags)
|
---|
91 | {
|
---|
92 | PCPUMCTX pCtx = pVCpu->em.s.pCtx;
|
---|
93 | Assert(!(fFlags & ~EM_ONE_INS_FLAGS_MASK));
|
---|
94 |
|
---|
95 | if (!NEMR3CanExecuteGuest(pVM, pVCpu, pCtx))
|
---|
96 | return VINF_EM_RESCHEDULE;
|
---|
97 |
|
---|
98 | uint64_t const uOldRip = pCtx->rip;
|
---|
99 | for (;;)
|
---|
100 | {
|
---|
101 | /*
|
---|
102 | * Service necessary FFs before going into HM.
|
---|
103 | */
|
---|
104 | if ( VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_PRE_RAW_MASK)
|
---|
105 | || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK))
|
---|
106 | {
|
---|
107 | VBOXSTRICTRC rcStrict = emR3NemForcedActions(pVM, pVCpu, pCtx);
|
---|
108 | if (rcStrict != VINF_SUCCESS)
|
---|
109 | {
|
---|
110 | Log(("emR3NemSingleInstruction: FFs before -> %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
|
---|
111 | return rcStrict;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * Go execute it.
|
---|
117 | */
|
---|
118 | bool fOld = NEMR3SetSingleInstruction(pVM, pVCpu, true);
|
---|
119 | VBOXSTRICTRC rcStrict = NEMR3RunGC(pVM, pVCpu);
|
---|
120 | NEMR3SetSingleInstruction(pVM, pVCpu, fOld);
|
---|
121 | LogFlow(("emR3NemSingleInstruction: %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * Handle high priority FFs and informational status codes. We don't do
|
---|
125 | * normal FF processing the caller or the next call can deal with them.
|
---|
126 | */
|
---|
127 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_RESUME_GUEST_MASK);
|
---|
128 | if ( VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
|
---|
129 | || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
|
---|
130 | {
|
---|
131 | rcStrict = emR3HighPriorityPostForcedActions(pVM, pVCpu, VBOXSTRICTRC_TODO(rcStrict));
|
---|
132 | LogFlow(("emR3NemSingleInstruction: FFs after -> %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
|
---|
133 | }
|
---|
134 |
|
---|
135 | if (rcStrict != VINF_SUCCESS && (rcStrict < VINF_EM_FIRST || rcStrict > VINF_EM_LAST))
|
---|
136 | {
|
---|
137 | rcStrict = emR3NemHandleRC(pVM, pVCpu, pCtx, VBOXSTRICTRC_TODO(rcStrict));
|
---|
138 | Log(("emR3NemSingleInstruction: emR3NemHandleRC -> %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
|
---|
139 | }
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * Done?
|
---|
143 | */
|
---|
144 | if ( (rcStrict != VINF_SUCCESS && rcStrict != VINF_EM_DBG_STEPPED)
|
---|
145 | || !(fFlags & EM_ONE_INS_FLAGS_RIP_CHANGE)
|
---|
146 | || pCtx->rip != uOldRip)
|
---|
147 | {
|
---|
148 | if (rcStrict == VINF_SUCCESS && pCtx->rip != uOldRip)
|
---|
149 | rcStrict = VINF_EM_DBG_STEPPED;
|
---|
150 | Log(("emR3NemSingleInstruction: returns %Rrc (rip %llx -> %llx)\n", VBOXSTRICTRC_VAL(rcStrict), uOldRip, pCtx->rip));
|
---|
151 | return rcStrict;
|
---|
152 | }
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Executes one (or perhaps a few more) instruction(s).
|
---|
159 | *
|
---|
160 | * @returns VBox status code suitable for EM.
|
---|
161 | *
|
---|
162 | * @param pVM The cross context VM structure.
|
---|
163 | * @param pVCpu The cross context virtual CPU structure.
|
---|
164 | * @param rcRC Return code from RC.
|
---|
165 | * @param pszPrefix Disassembly prefix. If not NULL we'll disassemble the
|
---|
166 | * instruction and prefix the log output with this text.
|
---|
167 | */
|
---|
168 | #if defined(LOG_ENABLED) || defined(DOXYGEN_RUNNING)
|
---|
169 | static int emR3NemExecuteInstructionWorker(PVM pVM, PVMCPU pVCpu, int rcRC, const char *pszPrefix)
|
---|
170 | #else
|
---|
171 | static int emR3NemExecuteInstructionWorker(PVM pVM, PVMCPU pVCpu, int rcRC)
|
---|
172 | #endif
|
---|
173 | {
|
---|
174 | #ifdef LOG_ENABLED
|
---|
175 | PCPUMCTX pCtx = pVCpu->em.s.pCtx;
|
---|
176 | #endif
|
---|
177 | int rc;
|
---|
178 | NOREF(rcRC);
|
---|
179 |
|
---|
180 | #ifdef LOG_ENABLED
|
---|
181 | /*
|
---|
182 | * Log it.
|
---|
183 | */
|
---|
184 | Log(("EMINS: %04x:%RGv RSP=%RGv\n", pCtx->cs.Sel, (RTGCPTR)pCtx->rip, (RTGCPTR)pCtx->rsp));
|
---|
185 | if (pszPrefix)
|
---|
186 | {
|
---|
187 | DBGFR3_INFO_LOG(pVM, pVCpu, "cpumguest", pszPrefix);
|
---|
188 | DBGFR3_DISAS_INSTR_CUR_LOG(pVCpu, pszPrefix);
|
---|
189 | }
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | /*
|
---|
193 | * Use IEM and fallback on REM if the functionality is missing.
|
---|
194 | * Once IEM gets mature enough, nothing should ever fall back.
|
---|
195 | */
|
---|
196 | STAM_PROFILE_START(&pVCpu->em.s.StatIEMEmu, a);
|
---|
197 | rc = VBOXSTRICTRC_TODO(IEMExecOne(pVCpu));
|
---|
198 | STAM_PROFILE_STOP(&pVCpu->em.s.StatIEMEmu, a);
|
---|
199 |
|
---|
200 | if ( rc == VERR_IEM_ASPECT_NOT_IMPLEMENTED
|
---|
201 | || rc == VERR_IEM_INSTR_NOT_IMPLEMENTED)
|
---|
202 | {
|
---|
203 | #ifdef VBOX_WITH_REM
|
---|
204 | STAM_PROFILE_START(&pVCpu->em.s.StatREMEmu, b);
|
---|
205 | EMRemLock(pVM);
|
---|
206 | /* Flush the recompiler TLB if the VCPU has changed. */
|
---|
207 | if (pVM->em.s.idLastRemCpu != pVCpu->idCpu)
|
---|
208 | CPUMSetChangedFlags(pVCpu, CPUM_CHANGED_ALL);
|
---|
209 | pVM->em.s.idLastRemCpu = pVCpu->idCpu;
|
---|
210 |
|
---|
211 | rc = REMR3EmulateInstruction(pVM, pVCpu);
|
---|
212 | EMRemUnlock(pVM);
|
---|
213 | STAM_PROFILE_STOP(&pVCpu->em.s.StatREMEmu, b);
|
---|
214 | #else /* !VBOX_WITH_REM */
|
---|
215 | NOREF(pVM);
|
---|
216 | #endif /* !VBOX_WITH_REM */
|
---|
217 | }
|
---|
218 |
|
---|
219 | #ifdef EM_NOTIFY_HM
|
---|
220 | if (pVCpu->em.s.enmState == EMSTATE_DEBUG_GUEST_HM)
|
---|
221 | HMR3NotifyEmulated(pVCpu);
|
---|
222 | #endif
|
---|
223 | return rc;
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Executes one (or perhaps a few more) instruction(s).
|
---|
229 | * This is just a wrapper for discarding pszPrefix in non-logging builds.
|
---|
230 | *
|
---|
231 | * @returns VBox status code suitable for EM.
|
---|
232 | * @param pVM The cross context VM structure.
|
---|
233 | * @param pVCpu The cross context virtual CPU structure.
|
---|
234 | * @param pszPrefix Disassembly prefix. If not NULL we'll disassemble the
|
---|
235 | * instruction and prefix the log output with this text.
|
---|
236 | * @param rcGC GC return code
|
---|
237 | */
|
---|
238 | DECLINLINE(int) emR3NemExecuteInstruction(PVM pVM, PVMCPU pVCpu, const char *pszPrefix, int rcGC)
|
---|
239 | {
|
---|
240 | #ifdef LOG_ENABLED
|
---|
241 | return emR3NemExecuteInstructionWorker(pVM, pVCpu, rcGC, pszPrefix);
|
---|
242 | #else
|
---|
243 | RT_NOREF_PV(pszPrefix);
|
---|
244 | return emR3NemExecuteInstructionWorker(pVM, pVCpu, rcGC);
|
---|
245 | #endif
|
---|
246 | }
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Executes one (or perhaps a few more) IO instruction(s).
|
---|
250 | *
|
---|
251 | * @returns VBox status code suitable for EM.
|
---|
252 | * @param pVM The cross context VM structure.
|
---|
253 | * @param pVCpu The cross context virtual CPU structure.
|
---|
254 | */
|
---|
255 | static int emR3NemExecuteIOInstruction(PVM pVM, PVMCPU pVCpu)
|
---|
256 | {
|
---|
257 | RT_NOREF_PV(pVM);
|
---|
258 | STAM_PROFILE_START(&pVCpu->em.s.StatIOEmu, a);
|
---|
259 |
|
---|
260 | #if 0
|
---|
261 | PCPUMCTX pCtx = pVCpu->em.s.pCtx;
|
---|
262 |
|
---|
263 | /*
|
---|
264 | * Try to restart the io instruction that was refused in ring-0.
|
---|
265 | */
|
---|
266 | VBOXSTRICTRC rcStrict = HMR3RestartPendingIOInstr(pVM, pVCpu, pCtx);
|
---|
267 | if (IOM_SUCCESS(rcStrict))
|
---|
268 | {
|
---|
269 | STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->StatIoRestarted);
|
---|
270 | STAM_PROFILE_STOP(&pVCpu->em.s.StatIOEmu, a);
|
---|
271 | return VBOXSTRICTRC_TODO(rcStrict); /* rip already updated. */
|
---|
272 | }
|
---|
273 | AssertMsgReturn(rcStrict == VERR_NOT_FOUND, ("%Rrc\n", VBOXSTRICTRC_VAL(rcStrict)),
|
---|
274 | RT_SUCCESS_NP(rcStrict) ? VERR_IPE_UNEXPECTED_INFO_STATUS : VBOXSTRICTRC_TODO(rcStrict));
|
---|
275 | #endif
|
---|
276 |
|
---|
277 | /*
|
---|
278 | * Hand it over to the interpreter.
|
---|
279 | */
|
---|
280 | VBOXSTRICTRC rcStrict = IEMExecOne(pVCpu);
|
---|
281 | LogFlow(("emR3NemExecuteIOInstruction: %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
|
---|
282 | STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->StatIoIem);
|
---|
283 |
|
---|
284 | STAM_PROFILE_STOP(&pVCpu->em.s.StatIOEmu, a);
|
---|
285 | return VBOXSTRICTRC_TODO(rcStrict);
|
---|
286 | }
|
---|
287 |
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * Process NEM specific forced actions.
|
---|
291 | *
|
---|
292 | * This function is called when any FFs in VM_FF_HIGH_PRIORITY_PRE_RAW_MASK
|
---|
293 | * or/and VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK are pending.
|
---|
294 | *
|
---|
295 | * @returns VBox status code. May return VINF_EM_NO_MEMORY but none of the other
|
---|
296 | * EM statuses.
|
---|
297 | * @param pVM The cross context VM structure.
|
---|
298 | * @param pVCpu The cross context virtual CPU structure.
|
---|
299 | * @param pCtx Pointer to the guest CPU context.
|
---|
300 | */
|
---|
301 | static int emR3NemForcedActions(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx)
|
---|
302 | {
|
---|
303 | #ifdef VBOX_WITH_RAW_MODE
|
---|
304 | Assert(!VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT));
|
---|
305 | #endif
|
---|
306 |
|
---|
307 | /*
|
---|
308 | * Sync page directory should not happen in NEM mode.
|
---|
309 | */
|
---|
310 | if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL))
|
---|
311 | {
|
---|
312 | Log(("NEM: TODO: Make VMCPU_FF_PGM_SYNC_CR3 / VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL quiet! (%#x)\n", pVCpu->fLocalForcedActions));
|
---|
313 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL);
|
---|
314 | }
|
---|
315 |
|
---|
316 | /*
|
---|
317 | * Allocate handy pages (just in case the above actions have consumed some pages).
|
---|
318 | */
|
---|
319 | if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_PGM_NEED_HANDY_PAGES, VM_FF_PGM_NO_MEMORY))
|
---|
320 | {
|
---|
321 | int rc = PGMR3PhysAllocateHandyPages(pVM);
|
---|
322 | if (RT_FAILURE(rc))
|
---|
323 | return rc;
|
---|
324 | }
|
---|
325 |
|
---|
326 | /*
|
---|
327 | * Check whether we're out of memory now.
|
---|
328 | *
|
---|
329 | * This may stem from some of the above actions or operations that has been executed
|
---|
330 | * since we ran FFs. The allocate handy pages must for instance always be followed by
|
---|
331 | * this check.
|
---|
332 | */
|
---|
333 | if (VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY))
|
---|
334 | return VINF_EM_NO_MEMORY;
|
---|
335 |
|
---|
336 | RT_NOREF_PV(pCtx);
|
---|
337 | return VINF_SUCCESS;
|
---|
338 | }
|
---|
339 |
|
---|
340 |
|
---|
341 | /**
|
---|
342 | * Executes hardware accelerated raw code. (Intel VT-x & AMD-V)
|
---|
343 | *
|
---|
344 | * This function contains the raw-mode version of the inner
|
---|
345 | * execution loop (the outer loop being in EMR3ExecuteVM()).
|
---|
346 | *
|
---|
347 | * @returns VBox status code. The most important ones are: VINF_EM_RESCHEDULE, VINF_EM_RESCHEDULE_RAW,
|
---|
348 | * VINF_EM_RESCHEDULE_REM, VINF_EM_SUSPEND, VINF_EM_RESET and VINF_EM_TERMINATE.
|
---|
349 | *
|
---|
350 | * @param pVM The cross context VM structure.
|
---|
351 | * @param pVCpu The cross context virtual CPU structure.
|
---|
352 | * @param pfFFDone Where to store an indicator telling whether or not
|
---|
353 | * FFs were done before returning.
|
---|
354 | */
|
---|
355 | VBOXSTRICTRC emR3NemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone)
|
---|
356 | {
|
---|
357 | VBOXSTRICTRC rcStrict = VERR_IPE_UNINITIALIZED_STATUS;
|
---|
358 | PCPUMCTX pCtx = pVCpu->em.s.pCtx;
|
---|
359 |
|
---|
360 | LogFlow(("emR3NemExecute%d: (cs:eip=%04x:%RGv)\n", pVCpu->idCpu, pCtx->cs.Sel, (RTGCPTR)pCtx->rip));
|
---|
361 | *pfFFDone = false;
|
---|
362 |
|
---|
363 | STAM_REL_COUNTER_INC(&pVCpu->em.s.StatNEMExecuteCalled);
|
---|
364 |
|
---|
365 | /*
|
---|
366 | * Spin till we get a forced action which returns anything but VINF_SUCCESS.
|
---|
367 | */
|
---|
368 | for (;;)
|
---|
369 | {
|
---|
370 | STAM_PROFILE_ADV_START(&pVCpu->em.s.StatNEMEntry, a);
|
---|
371 |
|
---|
372 | #if 0
|
---|
373 | /* Check if a forced reschedule is pending. */
|
---|
374 | if (NEMR3IsRescheduleRequired(pVM, pCtx))
|
---|
375 | {
|
---|
376 | rcStrict = VINF_EM_RESCHEDULE;
|
---|
377 | break;
|
---|
378 | }
|
---|
379 | #endif
|
---|
380 |
|
---|
381 | /*
|
---|
382 | * Process high priority pre-execution raw-mode FFs.
|
---|
383 | */
|
---|
384 | if ( VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_PRE_RAW_MASK)
|
---|
385 | || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK))
|
---|
386 | {
|
---|
387 | rcStrict = emR3NemForcedActions(pVM, pVCpu, pCtx);
|
---|
388 | if (rcStrict != VINF_SUCCESS)
|
---|
389 | break;
|
---|
390 | }
|
---|
391 |
|
---|
392 | #ifdef LOG_ENABLED
|
---|
393 | /*
|
---|
394 | * Log important stuff before entering GC.
|
---|
395 | */
|
---|
396 | if (TRPMHasTrap(pVCpu))
|
---|
397 | Log(("CPU%d: Pending hardware interrupt=0x%x cs:rip=%04X:%RGv\n", pVCpu->idCpu, TRPMGetTrapNo(pVCpu), pCtx->cs.Sel, (RTGCPTR)pCtx->rip));
|
---|
398 |
|
---|
399 | uint32_t cpl = CPUMGetGuestCPL(pVCpu);
|
---|
400 | if (pVM->cCpus == 1)
|
---|
401 | {
|
---|
402 | if (pCtx->eflags.Bits.u1VM)
|
---|
403 | Log(("NEMV86: %08X IF=%d\n", pCtx->eip, pCtx->eflags.Bits.u1IF));
|
---|
404 | else if (CPUMIsGuestIn64BitCodeEx(pCtx))
|
---|
405 | Log(("NEMR%d: %04X:%RGv ESP=%RGv IF=%d IOPL=%d CR0=%x CR4=%x EFER=%x\n", cpl, pCtx->cs.Sel, (RTGCPTR)pCtx->rip, pCtx->rsp, pCtx->eflags.Bits.u1IF, pCtx->eflags.Bits.u2IOPL, (uint32_t)pCtx->cr0, (uint32_t)pCtx->cr4, (uint32_t)pCtx->msrEFER));
|
---|
406 | else
|
---|
407 | Log(("NEMR%d: %04X:%08X ESP=%08X IF=%d IOPL=%d CR0=%x CR4=%x EFER=%x\n", cpl, pCtx->cs.Sel, pCtx->eip, pCtx->esp, pCtx->eflags.Bits.u1IF, pCtx->eflags.Bits.u2IOPL, (uint32_t)pCtx->cr0, (uint32_t)pCtx->cr4, (uint32_t)pCtx->msrEFER));
|
---|
408 | }
|
---|
409 | else
|
---|
410 | {
|
---|
411 | if (pCtx->eflags.Bits.u1VM)
|
---|
412 | Log(("NEMV86-CPU%d: %08X IF=%d\n", pVCpu->idCpu, pCtx->eip, pCtx->eflags.Bits.u1IF));
|
---|
413 | else if (CPUMIsGuestIn64BitCodeEx(pCtx))
|
---|
414 | Log(("NEMR%d-CPU%d: %04X:%RGv ESP=%RGv IF=%d IOPL=%d CR0=%x CR4=%x EFER=%x\n", cpl, pVCpu->idCpu, pCtx->cs.Sel, (RTGCPTR)pCtx->rip, pCtx->rsp, pCtx->eflags.Bits.u1IF, pCtx->eflags.Bits.u2IOPL, (uint32_t)pCtx->cr0, (uint32_t)pCtx->cr4, (uint32_t)pCtx->msrEFER));
|
---|
415 | else
|
---|
416 | Log(("NEMR%d-CPU%d: %04X:%08X ESP=%08X IF=%d IOPL=%d CR0=%x CR4=%x EFER=%x\n", cpl, pVCpu->idCpu, pCtx->cs.Sel, pCtx->eip, pCtx->esp, pCtx->eflags.Bits.u1IF, pCtx->eflags.Bits.u2IOPL, (uint32_t)pCtx->cr0, (uint32_t)pCtx->cr4, (uint32_t)pCtx->msrEFER));
|
---|
417 | }
|
---|
418 | #endif /* LOG_ENABLED */
|
---|
419 |
|
---|
420 | /*
|
---|
421 | * Execute the code.
|
---|
422 | */
|
---|
423 | if (RT_LIKELY(emR3IsExecutionAllowed(pVM, pVCpu)))
|
---|
424 | {
|
---|
425 | STAM_PROFILE_ADV_STOP(&pVCpu->em.s.StatNEMEntry, a);
|
---|
426 | STAM_REL_PROFILE_START(&pVCpu->em.s.StatNEMExec, x);
|
---|
427 | rcStrict = NEMR3RunGC(pVM, pVCpu);
|
---|
428 | STAM_REL_PROFILE_STOP(&pVCpu->em.s.StatNEMExec, x);
|
---|
429 | }
|
---|
430 | else
|
---|
431 | {
|
---|
432 | /* Give up this time slice; virtual time continues */
|
---|
433 | STAM_PROFILE_ADV_STOP(&pVCpu->em.s.StatNEMEntry, a);
|
---|
434 | STAM_REL_PROFILE_ADV_START(&pVCpu->em.s.StatCapped, u);
|
---|
435 | RTThreadSleep(5);
|
---|
436 | STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatCapped, u);
|
---|
437 | rcStrict = VINF_SUCCESS;
|
---|
438 | }
|
---|
439 |
|
---|
440 |
|
---|
441 | /*
|
---|
442 | * Deal with high priority post execution FFs before doing anything else.
|
---|
443 | */
|
---|
444 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_RESUME_GUEST_MASK);
|
---|
445 | if ( VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
|
---|
446 | || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
|
---|
447 | rcStrict = emR3HighPriorityPostForcedActions(pVM, pVCpu, VBOXSTRICTRC_TODO(rcStrict));
|
---|
448 |
|
---|
449 | /*
|
---|
450 | * Process the returned status code.
|
---|
451 | */
|
---|
452 | if (rcStrict >= VINF_EM_FIRST && rcStrict <= VINF_EM_LAST)
|
---|
453 | break;
|
---|
454 |
|
---|
455 | rcStrict = emR3NemHandleRC(pVM, pVCpu, pCtx, VBOXSTRICTRC_TODO(rcStrict));
|
---|
456 | if (rcStrict != VINF_SUCCESS)
|
---|
457 | break;
|
---|
458 |
|
---|
459 | /*
|
---|
460 | * Check and execute forced actions.
|
---|
461 | */
|
---|
462 | #ifdef VBOX_HIGH_RES_TIMERS_HACK
|
---|
463 | TMTimerPollVoid(pVM, pVCpu);
|
---|
464 | #endif
|
---|
465 | if ( VM_FF_IS_PENDING(pVM, VM_FF_ALL_MASK)
|
---|
466 | || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_ALL_MASK))
|
---|
467 | {
|
---|
468 | rcStrict = emR3ForcedActions(pVM, pVCpu, VBOXSTRICTRC_TODO(rcStrict));
|
---|
469 | VBOXVMM_EM_FF_ALL_RET(pVCpu, VBOXSTRICTRC_VAL(rcStrict));
|
---|
470 | if ( rcStrict != VINF_SUCCESS
|
---|
471 | && rcStrict != VINF_EM_RESCHEDULE_HM)
|
---|
472 | {
|
---|
473 | *pfFFDone = true;
|
---|
474 | break;
|
---|
475 | }
|
---|
476 | }
|
---|
477 | }
|
---|
478 |
|
---|
479 | /*
|
---|
480 | * Return to outer loop.
|
---|
481 | */
|
---|
482 | #if defined(LOG_ENABLED) && defined(DEBUG)
|
---|
483 | RTLogFlush(NULL);
|
---|
484 | #endif
|
---|
485 | return rcStrict;
|
---|
486 | }
|
---|
487 |
|
---|