88
88
static int emR3Debug(PVM pVM, PVMCPU pVCpu, int rc);
89
89
static int emR3RemStep(PVM pVM, PVMCPU pVCpu);
90
90
static int emR3RemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
91
DECLINLINE(int) emR3RawExecuteInstruction(PVM pVM, PVMCPU pVCpu, const char *pszPrefix, int rcGC = VINF_SUCCESS);
92
91
int emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
381
380
/* these should be considered for release statistics. */
382
381
EM_REG_COUNTER(&pVCpu->em.s.StatIOEmu, "/PROF/CPU%d/EM/Emulation/IO", "Profiling of emR3RawExecuteIOInstruction.");
383
382
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
383
EM_REG_PROFILE(&pVCpu->em.s.StatHwAccEntry, "/PROF/CPU%d/EM/HwAccEnter", "Profiling Hardware Accelerated Mode entry overhead.");
386
384
EM_REG_PROFILE(&pVCpu->em.s.StatHwAccExec, "/PROF/CPU%d/EM/HwAccExec", "Profiling Hardware Accelerated Mode execution.");
387
385
EM_REG_PROFILE(&pVCpu->em.s.StatREMEmu, "/PROF/CPU%d/EM/REMEmuSingle", "Profiling single instruction REM execution.");
851
* emR3RemExecute helper that syncs the state back from REM and leave the REM
854
* @returns false - new fInREMState value.
855
* @param pVM The VM handle.
856
* @param pVCpu The virtual CPU handle.
858
DECLINLINE(bool) emR3RemExecuteSyncBack(PVM pVM, PVMCPU pVCpu)
860
STAM_PROFILE_START(&pVCpu->em.s.StatREMSync, a);
861
REMR3StateBack(pVM, pVCpu);
862
STAM_PROFILE_STOP(&pVCpu->em.s.StatREMSync, a);
853
870
* Executes recompiled code.
855
872
* This function contains the recompiler version of the inner
883
900
("cs:eip=%RX16:%RX32\n", CPUMGetGuestCS(pVCpu), CPUMGetGuestEIP(pVCpu)));
886
/* Big lock, but you are not supposed to own any lock when coming in here. */
890
904
* Spin till we get a forced action which returns anything but VINF_SUCCESS
891
905
* or the REM suggests raw-mode execution.
893
907
*pfFFDone = false;
894
908
bool fInREMState = false;
895
int rc = VINF_SUCCESS;
897
/* Flush the recompiler TLB if the VCPU has changed. */
898
if (pVM->em.s.idLastRemCpu != pVCpu->idCpu)
901
/* Also sync the entire state. */
902
CPUMSetChangedFlags(pVCpu, CPUM_CHANGED_ALL);
904
pVM->em.s.idLastRemCpu = pVCpu->idCpu;
909
int rc = VINF_SUCCESS;
909
* Update REM state if not already in sync.
913
* Lock REM and update the state if not already in sync.
915
* Note! Big lock, but you are not supposed to own any lock when
911
918
if (!fInREMState)
913
921
STAM_PROFILE_START(&pVCpu->em.s.StatREMSync, b);
923
/* Flush the recompiler translation blocks if the VCPU has changed,
924
also force a full CPU state resync. */
925
if (pVM->em.s.idLastRemCpu != pVCpu->idCpu)
928
CPUMSetChangedFlags(pVCpu, CPUM_CHANGED_ALL);
930
pVM->em.s.idLastRemCpu = pVCpu->idCpu;
914
932
rc = REMR3State(pVM, pVCpu);
915
934
STAM_PROFILE_STOP(&pVCpu->em.s.StatREMSync, b);
916
935
if (RT_FAILURE(rc))
942
* Deal with high priority post execution FFs before doing anything else.
961
* Deal with high priority post execution FFs before doing anything
962
* else. Sync back the state and leave the lock to be on the safe side.
944
964
if ( VM_FF_ISPENDING(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
945
965
|| VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
967
fInREMState = emR3RemExecuteSyncBack(pVM, pVCpu);
946
968
rc = emR3HighPriorityPostForcedActions(pVM, pVCpu, rc);
949
972
* Process the returned status code.
950
* (Try keep this short! Call functions!)
952
974
if (rc != VINF_SUCCESS)
969
991
* Check and execute forced actions.
970
* Sync back the VM state before calling any of these.
993
* Sync back the VM state and leave the lock before calling any of
994
* these, you never know what's going to happen here.
972
996
#ifdef VBOX_HIGH_RES_TIMERS_HACK
973
997
TMTimerPollVoid(pVM, pVCpu);
979
1003
l_REMDoForcedActions:
980
1004
if (fInREMState)
982
STAM_PROFILE_START(&pVCpu->em.s.StatREMSync, d);
983
REMR3StateBack(pVM, pVCpu);
984
STAM_PROFILE_STOP(&pVCpu->em.s.StatREMSync, d);
1005
fInREMState = emR3RemExecuteSyncBack(pVM, pVCpu);
987
1006
STAM_REL_PROFILE_ADV_SUSPEND(&pVCpu->em.s.StatREMTotal, a);
988
1007
rc = emR3ForcedActions(pVM, pVCpu, rc);
989
1008
STAM_REL_PROFILE_ADV_RESUME(&pVCpu->em.s.StatREMTotal, a);
1002
1021
* Returning. Sync back the VM state if required.
1004
1023
if (fInREMState)
1006
STAM_PROFILE_START(&pVCpu->em.s.StatREMSync, e);
1007
REMR3StateBack(pVM, pVCpu);
1008
STAM_PROFILE_STOP(&pVCpu->em.s.StatREMSync, e);
1024
fInREMState = emR3RemExecuteSyncBack(pVM, pVCpu);
1012
1026
STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatREMTotal, a);