VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/EMHM.cpp@ 47548

最後變更 在這個檔案從47548是 47548,由 vboxsync 提交於 12 年 前

IEM: Bunch of fixes, mostly DOS related.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 21.2 KB
 
1/* $Id: EMHM.cpp 47548 2013-08-06 03:58:21Z vboxsync $ */
2/** @file
3 * EM - Execution Monitor / Manager - hardware virtualization
4 */
5
6/*
7 * Copyright (C) 2006-2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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* Header Files *
20*******************************************************************************/
21#define LOG_GROUP LOG_GROUP_EM
22#include <VBox/vmm/em.h>
23#include <VBox/vmm/vmm.h>
24#include <VBox/vmm/csam.h>
25#include <VBox/vmm/selm.h>
26#include <VBox/vmm/trpm.h>
27#include <VBox/vmm/iem.h>
28#include <VBox/vmm/iom.h>
29#include <VBox/vmm/dbgf.h>
30#include <VBox/vmm/pgm.h>
31#ifdef VBOX_WITH_REM
32# include <VBox/vmm/rem.h>
33#endif
34#include <VBox/vmm/tm.h>
35#include <VBox/vmm/mm.h>
36#include <VBox/vmm/ssm.h>
37#include <VBox/vmm/pdmapi.h>
38#include <VBox/vmm/pdmcritsect.h>
39#include <VBox/vmm/pdmqueue.h>
40#include <VBox/vmm/hm.h>
41#include "EMInternal.h"
42#include <VBox/vmm/vm.h>
43#include <VBox/vmm/cpumdis.h>
44#include <VBox/dis.h>
45#include <VBox/disopcode.h>
46#include <VBox/vmm/dbgf.h>
47#include "VMMTracing.h"
48
49#include <iprt/asm.h>
50
51
52/*******************************************************************************
53* Defined Constants And Macros *
54*******************************************************************************/
55#if 0 /* Disabled till after 2.1.0 when we've time to test it. */
56#define EM_NOTIFY_HM
57#endif
58
59
60/*******************************************************************************
61* Internal Functions *
62*******************************************************************************/
63DECLINLINE(int) emR3ExecuteInstruction(PVM pVM, PVMCPU pVCpu, const char *pszPrefix, int rcGC = VINF_SUCCESS);
64static int emR3ExecuteIOInstruction(PVM pVM, PVMCPU pVCpu);
65static int emR3HmForcedActions(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
66
67#define EMHANDLERC_WITH_HM
68#include "EMHandleRCTmpl.h"
69
70
71#if defined(DEBUG) && defined(SOME_UNUSED_FUNCTIONS)
72
73/**
74 * Steps hardware accelerated mode.
75 *
76 * @returns VBox status code.
77 * @param pVM Pointer to the VM.
78 * @param pVCpu Pointer to the VMCPU.
79 */
80static int emR3HmStep(PVM pVM, PVMCPU pVCpu)
81{
82 Assert(pVCpu->em.s.enmState == EMSTATE_DEBUG_GUEST_HM);
83
84 int rc;
85 PCPUMCTX pCtx = pVCpu->em.s.pCtx;
86# ifdef VBOX_WITH_RAW_MODE
87 Assert(!VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT | VMCPU_FF_TRPM_SYNC_IDT | VMCPU_FF_SELM_SYNC_TSS));
88# endif
89
90 /*
91 * Check vital forced actions, but ignore pending interrupts and timers.
92 */
93 if ( VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_PRE_RAW_MASK)
94 || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK))
95 {
96 rc = emR3HmForcedActions(pVM, pVCpu, pCtx);
97 if (rc != VINF_SUCCESS)
98 return rc;
99 }
100 /*
101 * Set flags for single stepping.
102 */
103 CPUMSetGuestEFlags(pVCpu, CPUMGetGuestEFlags(pVCpu) | X86_EFL_TF | X86_EFL_RF);
104
105 /*
106 * Single step.
107 * We do not start time or anything, if anything we should just do a few nanoseconds.
108 */
109 do
110 {
111 rc = VMMR3HmRunGC(pVM, pVCpu);
112 } while ( rc == VINF_SUCCESS
113 || rc == VINF_EM_RAW_INTERRUPT);
114 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_RESUME_GUEST_MASK);
115
116 /*
117 * Make sure the trap flag is cleared.
118 * (Too bad if the guest is trying to single step too.)
119 */
120 CPUMSetGuestEFlags(pVCpu, CPUMGetGuestEFlags(pVCpu) & ~X86_EFL_TF);
121
122 /*
123 * Deal with the return codes.
124 */
125 rc = emR3HighPriorityPostForcedActions(pVM, pVCpu, rc);
126 rc = emR3HmHandleRC(pVM, pVCpu, pCtx, rc);
127 return rc;
128}
129
130
131static int emR3SingleStepExecHm(PVM pVM, PVMCPU pVCpu, uint32_t cIterations)
132{
133 int rc = VINF_SUCCESS;
134 EMSTATE enmOldState = pVCpu->em.s.enmState;
135 pVCpu->em.s.enmState = EMSTATE_DEBUG_GUEST_HM;
136
137 Log(("Single step BEGIN:\n"));
138 for (uint32_t i = 0; i < cIterations; i++)
139 {
140 DBGFR3PrgStep(pVCpu);
141 DBGFR3_DISAS_INSTR_CUR_LOG(pVCpu, "RSS");
142 rc = emR3HmStep(pVM, pVCpu);
143 if ( rc != VINF_SUCCESS
144 || !HMR3CanExecuteGuest(pVM, pVCpu->em.s.pCtx))
145 break;
146 }
147 Log(("Single step END: rc=%Rrc\n", rc));
148 CPUMSetGuestEFlags(pVCpu, CPUMGetGuestEFlags(pVCpu) & ~X86_EFL_TF);
149 pVCpu->em.s.enmState = enmOldState;
150 return rc == VINF_SUCCESS ? VINF_EM_RESCHEDULE_REM : rc;
151}
152
153#endif /* DEBUG */
154
155
156/**
157 * Executes one (or perhaps a few more) instruction(s).
158 *
159 * @returns VBox status code suitable for EM.
160 *
161 * @param pVM Pointer to the VM.
162 * @param pVCpu Pointer to the VMCPU.
163 * @param rcRC Return code from RC.
164 * @param pszPrefix Disassembly prefix. If not NULL we'll disassemble the
165 * instruction and prefix the log output with this text.
166 */
167#ifdef LOG_ENABLED
168static int emR3ExecuteInstructionWorker(PVM pVM, PVMCPU pVCpu, int rcRC, const char *pszPrefix)
169#else
170static int emR3ExecuteInstructionWorker(PVM pVM, PVMCPU pVCpu, int rcRC)
171#endif
172{
173#ifdef LOG_ENABLED
174 PCPUMCTX pCtx = pVCpu->em.s.pCtx;
175#endif
176 int rc;
177 NOREF(rcRC);
178
179 /*
180 *
181 * The simple solution is to use the recompiler.
182 * The better solution is to disassemble the current instruction and
183 * try handle as many as possible without using REM.
184 *
185 */
186
187#ifdef LOG_ENABLED
188 /*
189 * Disassemble the instruction if requested.
190 */
191 if (pszPrefix)
192 {
193 DBGFR3_INFO_LOG(pVM, "cpumguest", pszPrefix);
194 DBGFR3_DISAS_INSTR_CUR_LOG(pVCpu, pszPrefix);
195 }
196#endif /* LOG_ENABLED */
197
198#if 0
199 /* Try our own instruction emulator before falling back to the recompiler. */
200 DISCPUSTATE Cpu;
201 rc = CPUMR3DisasmInstrCPU(pVM, pVCpu, pCtx, pCtx->rip, &Cpu, "GEN EMU");
202 if (RT_SUCCESS(rc))
203 {
204 switch (Cpu.pCurInstr->uOpcode)
205 {
206 /* @todo we can do more now */
207 case OP_MOV:
208 case OP_AND:
209 case OP_OR:
210 case OP_XOR:
211 case OP_POP:
212 case OP_INC:
213 case OP_DEC:
214 case OP_XCHG:
215 STAM_PROFILE_START(&pVCpu->em.s.StatMiscEmu, a);
216 rc = EMInterpretInstructionCpuUpdtPC(pVM, pVCpu, &Cpu, CPUMCTX2CORE(pCtx), 0);
217 if (RT_SUCCESS(rc))
218 {
219#ifdef EM_NOTIFY_HM
220 if (pVCpu->em.s.enmState == EMSTATE_DEBUG_GUEST_HM)
221 HMR3NotifyEmulated(pVCpu);
222#endif
223 STAM_PROFILE_STOP(&pVCpu->em.s.StatMiscEmu, a);
224 return rc;
225 }
226 if (rc != VERR_EM_INTERPRETER)
227 AssertMsgFailedReturn(("rc=%Rrc\n", rc), rc);
228 STAM_PROFILE_STOP(&pVCpu->em.s.StatMiscEmu, a);
229 break;
230 }
231 }
232#endif /* 0 */
233 STAM_PROFILE_START(&pVCpu->em.s.StatREMEmu, a);
234 Log(("EMINS: %04x:%RGv RSP=%RGv\n", pCtx->cs.Sel, (RTGCPTR)pCtx->rip, (RTGCPTR)pCtx->rsp));
235#ifdef VBOX_WITH_REM
236 EMRemLock(pVM);
237 /* Flush the recompiler TLB if the VCPU has changed. */
238 if (pVM->em.s.idLastRemCpu != pVCpu->idCpu)
239 CPUMSetChangedFlags(pVCpu, CPUM_CHANGED_ALL);
240 pVM->em.s.idLastRemCpu = pVCpu->idCpu;
241
242 rc = REMR3EmulateInstruction(pVM, pVCpu);
243 EMRemUnlock(pVM);
244#else
245 rc = VBOXSTRICTRC_TODO(IEMExecOne(pVCpu)); NOREF(pVM);
246#endif
247 STAM_PROFILE_STOP(&pVCpu->em.s.StatREMEmu, a);
248
249#ifdef EM_NOTIFY_HM
250 if (pVCpu->em.s.enmState == EMSTATE_DEBUG_GUEST_HM)
251 HMR3NotifyEmulated(pVCpu);
252#endif
253 return rc;
254}
255
256
257/**
258 * Executes one (or perhaps a few more) instruction(s).
259 * This is just a wrapper for discarding pszPrefix in non-logging builds.
260 *
261 * @returns VBox status code suitable for EM.
262 * @param pVM Pointer to the VM.
263 * @param pVCpu Pointer to the VMCPU.
264 * @param pszPrefix Disassembly prefix. If not NULL we'll disassemble the
265 * instruction and prefix the log output with this text.
266 * @param rcGC GC return code
267 */
268DECLINLINE(int) emR3ExecuteInstruction(PVM pVM, PVMCPU pVCpu, const char *pszPrefix, int rcGC)
269{
270#ifdef LOG_ENABLED
271 return emR3ExecuteInstructionWorker(pVM, pVCpu, rcGC, pszPrefix);
272#else
273 return emR3ExecuteInstructionWorker(pVM, pVCpu, rcGC);
274#endif
275}
276
277/**
278 * Executes one (or perhaps a few more) IO instruction(s).
279 *
280 * @returns VBox status code suitable for EM.
281 * @param pVM Pointer to the VM.
282 * @param pVCpu Pointer to the VMCPU.
283 */
284static int emR3ExecuteIOInstruction(PVM pVM, PVMCPU pVCpu)
285{
286 PCPUMCTX pCtx = pVCpu->em.s.pCtx;
287
288 STAM_PROFILE_START(&pVCpu->em.s.StatIOEmu, a);
289
290 /* Try to restart the io instruction that was refused in ring-0. */
291 VBOXSTRICTRC rcStrict = HMR3RestartPendingIOInstr(pVM, pVCpu, pCtx);
292 if (IOM_SUCCESS(rcStrict))
293 {
294 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->StatIoRestarted);
295 STAM_PROFILE_STOP(&pVCpu->em.s.StatIOEmu, a);
296 return VBOXSTRICTRC_TODO(rcStrict); /* rip already updated. */
297 }
298 AssertMsgReturn(rcStrict == VERR_NOT_FOUND, ("%Rrc\n", VBOXSTRICTRC_VAL(rcStrict)),
299 RT_SUCCESS_NP(rcStrict) ? VERR_IPE_UNEXPECTED_INFO_STATUS : VBOXSTRICTRC_TODO(rcStrict));
300
301#ifdef VBOX_WITH_FIRST_IEM_STEP
302 /* Hand it over to the interpreter. */
303 rcStrict = IEMExecOne(pVCpu);
304 LogFlow(("emR3ExecuteIOInstruction: %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
305 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->StatIoIem);
306 STAM_PROFILE_STOP(&pVCpu->em.s.StatIOEmu, a);
307 return VBOXSTRICTRC_TODO(rcStrict);
308
309#else
310 /** @todo probably we should fall back to the recompiler; otherwise we'll go back and forth between HC & GC
311 * as io instructions tend to come in packages of more than one
312 */
313 DISCPUSTATE Cpu;
314 int rc2 = CPUMR3DisasmInstrCPU(pVM, pVCpu, pCtx, pCtx->rip, &Cpu, "IO EMU");
315 if (RT_SUCCESS(rc2))
316 {
317 rcStrict = VINF_EM_RAW_EMULATE_INSTR;
318
319 if (!(Cpu.fPrefix & (DISPREFIX_REP | DISPREFIX_REPNE)))
320 {
321 switch (Cpu.pCurInstr->uOpcode)
322 {
323 case OP_IN:
324 {
325 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->StatIn);
326 rcStrict = IOMInterpretIN(pVM, pVCpu, CPUMCTX2CORE(pCtx), &Cpu);
327 break;
328 }
329
330 case OP_OUT:
331 {
332 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->StatOut);
333 rcStrict = IOMInterpretOUT(pVM, pVCpu, CPUMCTX2CORE(pCtx), &Cpu);
334 break;
335 }
336 }
337 }
338 else if (Cpu.fPrefix & DISPREFIX_REP)
339 {
340 switch (Cpu.pCurInstr->uOpcode)
341 {
342 case OP_INSB:
343 case OP_INSWD:
344 {
345 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->StatIn);
346 rcStrict = IOMInterpretINS(pVM, pVCpu, CPUMCTX2CORE(pCtx), &Cpu);
347 break;
348 }
349
350 case OP_OUTSB:
351 case OP_OUTSWD:
352 {
353 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->StatOut);
354 rcStrict = IOMInterpretOUTS(pVM, pVCpu, CPUMCTX2CORE(pCtx), &Cpu);
355 break;
356 }
357 }
358 }
359
360 /*
361 * Handled the I/O return codes.
362 * (The unhandled cases end up with rcStrict == VINF_EM_RAW_EMULATE_INSTR.)
363 */
364 if (IOM_SUCCESS(rcStrict))
365 {
366 pCtx->rip += Cpu.cbInstr;
367 STAM_PROFILE_STOP(&pVCpu->em.s.StatIOEmu, a);
368 LogFlow(("emR3ExecuteIOInstruction: %Rrc 1\n", VBOXSTRICTRC_VAL(rcStrict)));
369 return VBOXSTRICTRC_TODO(rcStrict);
370 }
371
372 if (rcStrict == VINF_EM_RAW_GUEST_TRAP)
373 {
374 /* The active trap will be dispatched. */
375 Assert(TRPMHasTrap(pVCpu));
376 STAM_PROFILE_STOP(&pVCpu->em.s.StatIOEmu, a);
377 LogFlow(("emR3ExecuteIOInstruction: VINF_SUCCESS 2\n"));
378 return VINF_SUCCESS;
379 }
380 AssertMsg(rcStrict != VINF_TRPM_XCPT_DISPATCHED, ("Handle VINF_TRPM_XCPT_DISPATCHED\n"));
381
382 if (RT_FAILURE(rcStrict))
383 {
384 STAM_PROFILE_STOP(&pVCpu->em.s.StatIOEmu, a);
385 LogFlow(("emR3ExecuteIOInstruction: %Rrc 3\n", VBOXSTRICTRC_VAL(rcStrict)));
386 return VBOXSTRICTRC_TODO(rcStrict);
387 }
388 AssertMsg(rcStrict == VINF_EM_RAW_EMULATE_INSTR || rcStrict == VINF_EM_RESCHEDULE_REM, ("rcStrict=%Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
389 }
390
391 STAM_PROFILE_STOP(&pVCpu->em.s.StatIOEmu, a);
392 int rc3 = emR3ExecuteInstruction(pVM, pVCpu, "IO: ");
393 LogFlow(("emR3ExecuteIOInstruction: %Rrc 4 (rc2=%Rrc, rc3=%Rrc)\n", VBOXSTRICTRC_VAL(rcStrict), rc2, rc3));
394 return rc3;
395#endif
396}
397
398
399/**
400 * Process raw-mode specific forced actions.
401 *
402 * This function is called when any FFs in the VM_FF_HIGH_PRIORITY_PRE_RAW_MASK is pending.
403 *
404 * @returns VBox status code. May return VINF_EM_NO_MEMORY but none of the other
405 * EM statuses.
406 * @param pVM Pointer to the VM.
407 * @param pVCpu Pointer to the VMCPU.
408 * @param pCtx Pointer to the guest CPU context.
409 */
410static int emR3HmForcedActions(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx)
411{
412 /*
413 * Sync page directory.
414 */
415 if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL))
416 {
417 Assert(pVCpu->em.s.enmState != EMSTATE_WAIT_SIPI);
418 int rc = PGMSyncCR3(pVCpu, pCtx->cr0, pCtx->cr3, pCtx->cr4, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3));
419 if (RT_FAILURE(rc))
420 return rc;
421
422#ifdef VBOX_WITH_RAW_MODE
423 Assert(!VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT));
424#endif
425
426 /* Prefetch pages for EIP and ESP. */
427 /** @todo This is rather expensive. Should investigate if it really helps at all. */
428 rc = PGMPrefetchPage(pVCpu, SELMToFlat(pVM, DISSELREG_CS, CPUMCTX2CORE(pCtx), pCtx->rip));
429 if (rc == VINF_SUCCESS)
430 rc = PGMPrefetchPage(pVCpu, SELMToFlat(pVM, DISSELREG_SS, CPUMCTX2CORE(pCtx), pCtx->rsp));
431 if (rc != VINF_SUCCESS)
432 {
433 if (rc != VINF_PGM_SYNC_CR3)
434 {
435 AssertLogRelMsgReturn(RT_FAILURE(rc), ("%Rrc\n", rc), VERR_IPE_UNEXPECTED_INFO_STATUS);
436 return rc;
437 }
438 rc = PGMSyncCR3(pVCpu, pCtx->cr0, pCtx->cr3, pCtx->cr4, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3));
439 if (RT_FAILURE(rc))
440 return rc;
441 }
442 /** @todo maybe prefetch the supervisor stack page as well */
443#ifdef VBOX_WITH_RAW_MODE
444 Assert(!VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT));
445#endif
446 }
447
448 /*
449 * Allocate handy pages (just in case the above actions have consumed some pages).
450 */
451 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_PGM_NEED_HANDY_PAGES, VM_FF_PGM_NO_MEMORY))
452 {
453 int rc = PGMR3PhysAllocateHandyPages(pVM);
454 if (RT_FAILURE(rc))
455 return rc;
456 }
457
458 /*
459 * Check whether we're out of memory now.
460 *
461 * This may stem from some of the above actions or operations that has been executed
462 * since we ran FFs. The allocate handy pages must for instance always be followed by
463 * this check.
464 */
465 if (VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY))
466 return VINF_EM_NO_MEMORY;
467
468 return VINF_SUCCESS;
469}
470
471
472/**
473 * Executes hardware accelerated raw code. (Intel VT-x & AMD-V)
474 *
475 * This function contains the raw-mode version of the inner
476 * execution loop (the outer loop being in EMR3ExecuteVM()).
477 *
478 * @returns VBox status code. The most important ones are: VINF_EM_RESCHEDULE, VINF_EM_RESCHEDULE_RAW,
479 * VINF_EM_RESCHEDULE_REM, VINF_EM_SUSPEND, VINF_EM_RESET and VINF_EM_TERMINATE.
480 *
481 * @param pVM Pointer to the VM.
482 * @param pVCpu Pointer to the VMCPU.
483 * @param pfFFDone Where to store an indicator telling whether or not
484 * FFs were done before returning.
485 */
486int emR3HmExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone)
487{
488 int rc = VERR_IPE_UNINITIALIZED_STATUS;
489 PCPUMCTX pCtx = pVCpu->em.s.pCtx;
490
491 LogFlow(("emR3HmExecute%d: (cs:eip=%04x:%RGv)\n", pVCpu->idCpu, pCtx->cs.Sel, (RTGCPTR)pCtx->rip));
492 *pfFFDone = false;
493
494 STAM_COUNTER_INC(&pVCpu->em.s.StatHmExecuteEntry);
495
496#ifdef EM_NOTIFY_HM
497 HMR3NotifyScheduled(pVCpu);
498#endif
499
500 /*
501 * Spin till we get a forced action which returns anything but VINF_SUCCESS.
502 */
503 for (;;)
504 {
505 STAM_PROFILE_ADV_START(&pVCpu->em.s.StatHmEntry, a);
506
507 /* Check if a forced reschedule is pending. */
508 if (HMR3IsRescheduleRequired(pVM, pCtx))
509 {
510 rc = VINF_EM_RESCHEDULE;
511 break;
512 }
513
514 /*
515 * Process high priority pre-execution raw-mode FFs.
516 */
517#ifdef VBOX_WITH_RAW_MODE
518 Assert(!VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT));
519#endif
520 if ( VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_PRE_RAW_MASK)
521 || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK))
522 {
523 rc = emR3HmForcedActions(pVM, pVCpu, pCtx);
524 if (rc != VINF_SUCCESS)
525 break;
526 }
527
528#ifdef LOG_ENABLED
529 /*
530 * Log important stuff before entering GC.
531 */
532 if (TRPMHasTrap(pVCpu))
533 Log(("CPU%d: Pending hardware interrupt=0x%x cs:rip=%04X:%RGv\n", pVCpu->idCpu, TRPMGetTrapNo(pVCpu), pCtx->cs.Sel, (RTGCPTR)pCtx->rip));
534
535 uint32_t cpl = CPUMGetGuestCPL(pVCpu);
536
537 if (pVM->cCpus == 1)
538 {
539 if (pCtx->eflags.Bits.u1VM)
540 Log(("HWV86: %08X IF=%d\n", pCtx->eip, pCtx->eflags.Bits.u1IF));
541 else if (CPUMIsGuestIn64BitCodeEx(pCtx))
542 Log(("HWR%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));
543 else
544 Log(("HWR%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));
545 }
546 else
547 {
548 if (pCtx->eflags.Bits.u1VM)
549 Log(("HWV86-CPU%d: %08X IF=%d\n", pVCpu->idCpu, pCtx->eip, pCtx->eflags.Bits.u1IF));
550 else if (CPUMIsGuestIn64BitCodeEx(pCtx))
551 Log(("HWR%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));
552 else
553 Log(("HWR%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));
554 }
555#endif /* LOG_ENABLED */
556
557 /*
558 * Execute the code.
559 */
560 STAM_PROFILE_ADV_STOP(&pVCpu->em.s.StatHmEntry, a);
561
562 if (RT_LIKELY(emR3IsExecutionAllowed(pVM, pVCpu)))
563 {
564 STAM_PROFILE_START(&pVCpu->em.s.StatHmExec, x);
565 rc = VMMR3HmRunGC(pVM, pVCpu);
566 STAM_PROFILE_STOP(&pVCpu->em.s.StatHmExec, x);
567 }
568 else
569 {
570 /* Give up this time slice; virtual time continues */
571 STAM_REL_PROFILE_ADV_START(&pVCpu->em.s.StatCapped, u);
572 RTThreadSleep(5);
573 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatCapped, u);
574 rc = VINF_SUCCESS;
575 }
576
577
578 /*
579 * Deal with high priority post execution FFs before doing anything else.
580 */
581 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_RESUME_GUEST_MASK);
582 if ( VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
583 || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
584 rc = emR3HighPriorityPostForcedActions(pVM, pVCpu, rc);
585
586 /*
587 * Process the returned status code.
588 */
589 if (rc >= VINF_EM_FIRST && rc <= VINF_EM_LAST)
590 break;
591
592 rc = emR3HmHandleRC(pVM, pVCpu, pCtx, rc);
593 if (rc != VINF_SUCCESS)
594 break;
595
596 /*
597 * Check and execute forced actions.
598 */
599#ifdef VBOX_HIGH_RES_TIMERS_HACK
600 TMTimerPollVoid(pVM, pVCpu);
601#endif
602 if ( VM_FF_IS_PENDING(pVM, VM_FF_ALL_MASK)
603 || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_ALL_MASK))
604 {
605 rc = emR3ForcedActions(pVM, pVCpu, rc);
606 VBOXVMM_EM_FF_ALL_RET(pVCpu, rc);
607 if ( rc != VINF_SUCCESS
608 && rc != VINF_EM_RESCHEDULE_HM)
609 {
610 *pfFFDone = true;
611 break;
612 }
613 }
614 }
615
616 /*
617 * Return to outer loop.
618 */
619#if defined(LOG_ENABLED) && defined(DEBUG)
620 RTLogFlush(NULL);
621#endif
622 return rc;
623}
624
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette