Index: /trunk/src/VBox/VMM/Makefile.kmk
===================================================================
--- /trunk/src/VBox/VMM/Makefile.kmk	(revision 42776)
+++ /trunk/src/VBox/VMM/Makefile.kmk	(revision 42777)
@@ -58,5 +58,5 @@
 # Special IEM debug mode which compares the result with REM.
 ifdef IEM_VERIFICATION_MODE
- VMM_COMMON_DEFS += IEM_VERIFICATION_MODE
+ VMM_COMMON_DEFS += IEM_VERIFICATION_MODE IEM_VERIFICATION_MODE_FULL
 endif
 
Index: /trunk/src/VBox/VMM/VMMAll/EMAll.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/EMAll.cpp	(revision 42776)
+++ /trunk/src/VBox/VMM/VMMAll/EMAll.cpp	(revision 42777)
@@ -47,7 +47,11 @@
 #include <iprt/string.h>
 
+#ifndef IN_RC
+#undef VBOX_WITH_IEM
+#endif
 #ifdef VBOX_WITH_IEM
-# define VBOX_COMPARE_IEM_AND_EM /* debugging... */
-# define VBOX_SAME_AS_EM
+//# define VBOX_COMPARE_IEM_AND_EM /* debugging... */
+//# define VBOX_SAME_AS_EM
+//# define VBOX_COMPARE_IEM_FIRST
 #endif
 
@@ -84,7 +88,21 @@
 *******************************************************************************/
 #ifdef VBOX_COMPARE_IEM_AND_EM
+static const uint32_t g_fInterestingFFs = VMCPU_FF_TO_R3
+    | VMCPU_FF_CSAM_PENDING_ACTION | VMCPU_FF_CSAM_SCAN_PAGE | VMCPU_FF_INHIBIT_INTERRUPTS
+    | VMCPU_FF_SELM_SYNC_LDT | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT
+    | VMCPU_FF_TLB_FLUSH | VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL;
+static uint32_t g_fIncomingFFs;
 static CPUMCTX g_IncomingCtx;
-static CPUMCTX g_EmOutgoingCtx;
-static bool g_fIgnoreRaxRdx = false;
+static bool    g_fIgnoreRaxRdx = false;
+
+static uint32_t g_fEmFFs;
+static CPUMCTX g_EmCtx;
+static uint8_t g_abEmWrote[256];
+static size_t  g_cbEmWrote;
+
+static uint32_t g_fIemFFs;
+static CPUMCTX g_IemCtx;
+extern uint8_t g_abIemWrote[256];
+extern size_t  g_cbIemWrote;
 #endif
 
@@ -441,16 +459,20 @@
 
 #ifdef VBOX_COMPARE_IEM_AND_EM
-static void emCompareWithIem(PVMCPU pVCpu, PCCPUMCTX pIemCtx, VBOXSTRICTRC rcEm, VBOXSTRICTRC rcIem,
+static void emCompareWithIem(PVMCPU pVCpu, PCCPUMCTX pEmCtx, PCCPUMCTX pIemCtx,
+                             VBOXSTRICTRC rcEm, VBOXSTRICTRC rcIem,
                              uint32_t cbEm, uint32_t cbIem)
 {
     /* Quick compare. */
-    PCCPUMCTX pEmCtx = &g_EmOutgoingCtx;
     if (   rcEm == rcIem
         && cbEm == cbIem
-        && memcmp(pIemCtx, pEmCtx, sizeof(*pIemCtx)) == 0)
+        && g_cbEmWrote == g_cbIemWrote
+        && memcmp(g_abIemWrote, g_abEmWrote, g_cbIemWrote) == 0
+        && memcmp(pIemCtx, pEmCtx, sizeof(*pIemCtx)) == 0
+        && (g_fEmFFs & g_fInterestingFFs) == (g_fIemFFs & g_fInterestingFFs)
+       )
         return;
 
     /* Report exact differences. */
-    RTLogPrintf("!! EM and IEM differs at %04x:%08RGv !!\n", g_IncomingCtx.cs.Sel, g_IncomingCtx.rip);
+    RTLogPrintf("! EM and IEM differs at %04x:%08RGv !\n", g_IncomingCtx.cs.Sel, g_IncomingCtx.rip);
     if (rcEm != rcIem)
         RTLogPrintf(" * rcIem=%Rrc rcEm=%Rrc\n", VBOXSTRICTRC_VAL(rcIem), VBOXSTRICTRC_VAL(rcEm));
@@ -458,6 +480,18 @@
         RTLogPrintf(" * cbIem=%#x cbEm=%#x\n", cbIem, cbEm);
 
-    if (rcEm == rcIem)
-    {
+    if (RT_SUCCESS(rcEm) && RT_SUCCESS(rcIem))
+    {
+        if (g_cbIemWrote != g_cbEmWrote)
+            RTLogPrintf("!! g_cbIemWrote=%#x g_cbEmWrote=%#x\n", g_cbIemWrote, g_cbEmWrote);
+        else if (memcmp(g_abIemWrote, g_abEmWrote, g_cbIemWrote))
+        {
+            RTLogPrintf("!! IemWrote %.*Rhxs\n", RT_MIN(RT_MAX(1, g_cbIemWrote), 64), g_abIemWrote);
+            RTLogPrintf("!! EemWrote  %.*Rhxs\n", RT_MIN(RT_MAX(1, g_cbIemWrote), 64), g_abIemWrote);
+        }
+
+        if ((g_fEmFFs & g_fInterestingFFs) != (g_fIemFFs & g_fInterestingFFs))
+            RTLogPrintf("!! g_fIemFFs=%#x  g_fEmFFs=%#x (diff=%#x)\n", g_fIemFFs & g_fInterestingFFs,
+                        g_fEmFFs & g_fInterestingFFs, (g_fIemFFs ^ g_fEmFFs) & g_fInterestingFFs);
+
 #  define CHECK_FIELD(a_Field) \
         do \
@@ -467,9 +501,9 @@
                 switch (sizeof(pEmCtx->a_Field)) \
                 { \
-                    case 1: RTLogPrintf("  %8s differs - iem=%02x - em=%02x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \
-                    case 2: RTLogPrintf("  %8s differs - iem=%04x - em=%04x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \
-                    case 4: RTLogPrintf("  %8s differs - iem=%08x - em=%08x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \
-                    case 8: RTLogPrintf("  %8s differs - iem=%016llx - em=%016llx\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \
-                    default: RTLogPrintf("  %8s differs\n", #a_Field); break; \
+                    case 1: RTLogPrintf("!! %8s differs - iem=%02x - em=%02x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \
+                    case 2: RTLogPrintf("!! %8s differs - iem=%04x - em=%04x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \
+                    case 4: RTLogPrintf("!! %8s differs - iem=%08x - em=%08x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \
+                    case 8: RTLogPrintf("!! %8s differs - iem=%016llx - em=%016llx\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \
+                    default: RTLogPrintf("!!  %8s differs\n", #a_Field); break; \
                 } \
                 cDiffs++; \
@@ -482,5 +516,5 @@
             if (pEmCtx->a_Field != pIemCtx->a_Field) \
             { \
-                RTLogPrintf("  %8s differs - iem=%02x - em=%02x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); \
+                RTLogPrintf("!! %8s differs - iem=%02x - em=%02x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); \
                 cDiffs++; \
             } \
@@ -544,5 +578,5 @@
         if (pEmCtx->rflags.u != pIemCtx->rflags.u)
         {
-            RTLogPrintf("  rflags differs - iem=%08llx em=%08llx\n", pIemCtx->rflags.u, pEmCtx->rflags.u);
+            RTLogPrintf("!! rflags differs - iem=%08llx em=%08llx\n", pIemCtx->rflags.u, pEmCtx->rflags.u);
             CHECK_BIT_FIELD(rflags.Bits.u1CF);
             CHECK_BIT_FIELD(rflags.Bits.u1Reserved0);
@@ -652,4 +686,19 @@
     PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu);
     g_IncomingCtx = *pCtx;
+    g_fIncomingFFs = pVCpu->fLocalForcedActions;
+    g_cbEmWrote = g_cbIemWrote = 0;
+
+#  ifdef VBOX_COMPARE_IEM_FIRST
+# error
+    /* IEM */
+    VBOXSTRICTRC rcIem = IEMExecOneBypassEx(pVCpu, pRegFrame, NULL);
+    if (RT_UNLIKELY(   rcIem == VERR_IEM_ASPECT_NOT_IMPLEMENTED
+                    || rcIem == VERR_IEM_INSTR_NOT_IMPLEMENTED))
+        rcIem = VERR_EM_INTERPRETER;
+    g_IemCtx = *pCtx;
+    g_fIemFFs = pVCpu->fLocalForcedActions;
+    pVCpu->fLocalForcedActions = (pVCpu->fLocalForcedActions & ~g_fInterestingFFs) | (g_fIncomingFFs & g_fInterestingFFs);
+    *pCtx = g_IncomingCtx;
+#  endif
 
     /* EM */
@@ -682,17 +731,32 @@
     }
 #  endif
-
-    g_EmOutgoingCtx = *pCtx;
+    g_EmCtx = *pCtx;
+    g_fEmFFs = pVCpu->fLocalForcedActions;
+    VBOXSTRICTRC rc = rcEm;
+
+#  ifdef VBOX_COMPARE_IEM_LAST
+# error
+    /* IEM */
+    pVCpu->fLocalForcedActions = (pVCpu->fLocalForcedActions & ~g_fInterestingFFs) | (g_fIncomingFFs & g_fInterestingFFs);
     *pCtx = g_IncomingCtx;
-
-    /* IEM */
-# endif /* VBOX_COMPARE_IEM_AND_EM */
+    VBOXSTRICTRC rcIem = IEMExecOneBypassEx(pVCpu, pRegFrame, NULL);
+    if (RT_UNLIKELY(   rcIem == VERR_IEM_ASPECT_NOT_IMPLEMENTED
+                    || rcIem == VERR_IEM_INSTR_NOT_IMPLEMENTED))
+        rcIem = VERR_EM_INTERPRETER;
+    g_IemCtx = *pCtx;
+    g_fIemFFs = pVCpu->fLocalForcedActions;
+    rc = rcIem;
+#  endif
+
+#  if defined(VBOX_COMPARE_IEM_LAST) || defined(VBOX_COMPARE_IEM_FIRST)
+# error
+    emCompareWithIem(pVCpu, &g_EmCtx, &g_IemCtx, rcEm, rcIem, 0, 0);
+#  endif
+
+# else
     VBOXSTRICTRC rc = IEMExecOneBypassEx(pVCpu, pRegFrame, NULL);
     if (RT_UNLIKELY(   rc == VERR_IEM_ASPECT_NOT_IMPLEMENTED
                     || rc == VERR_IEM_INSTR_NOT_IMPLEMENTED))
         rc = VERR_EM_INTERPRETER;
-
-# ifdef VBOX_COMPARE_IEM_AND_EM
-    emCompareWithIem(pVCpu, pCtx, rcEm, rc, 0, 0);
 # endif
     if (rc != VINF_SUCCESS)
@@ -754,4 +818,19 @@
     PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu);
     g_IncomingCtx = *pCtx;
+    g_fIncomingFFs = pVCpu->fLocalForcedActions;
+    g_cbEmWrote = g_cbIemWrote = 0;
+
+#  ifdef VBOX_COMPARE_IEM_FIRST
+    /* IEM */
+    uint32_t cbIemWritten = 0;
+    VBOXSTRICTRC rcIem = IEMExecOneBypassEx(pVCpu, pRegFrame, &cbIemWritten);
+    if (RT_UNLIKELY(   rcIem == VERR_IEM_ASPECT_NOT_IMPLEMENTED
+                    || rcIem == VERR_IEM_INSTR_NOT_IMPLEMENTED))
+        rcIem = VERR_EM_INTERPRETER;
+    g_IemCtx = *pCtx;
+    g_fIemFFs = pVCpu->fLocalForcedActions;
+    pVCpu->fLocalForcedActions = (pVCpu->fLocalForcedActions & ~g_fInterestingFFs) | (g_fIncomingFFs & g_fInterestingFFs);
+    *pCtx = g_IncomingCtx;
+#  endif
 
     /* EM */
@@ -785,17 +864,33 @@
     }
 #  endif
-
-    g_EmOutgoingCtx = *pCtx;
+    g_EmCtx = *pCtx;
+    g_fEmFFs = pVCpu->fLocalForcedActions;
+    *pcbWritten = cbEmWritten;
+    VBOXSTRICTRC rc = rcEm;
+
+#  ifdef VBOX_COMPARE_IEM_LAST
+    /* IEM */
+    pVCpu->fLocalForcedActions = (pVCpu->fLocalForcedActions & ~g_fInterestingFFs) | (g_fIncomingFFs & g_fInterestingFFs);
     *pCtx = g_IncomingCtx;
-
-    /* IEM */
-# endif /* VBOX_COMPARE_IEM_AND_EM */
+    uint32_t cbIemWritten = 0;
+    VBOXSTRICTRC rcIem = IEMExecOneBypassEx(pVCpu, pRegFrame, &cbIemWritten);
+    if (RT_UNLIKELY(   rcIem == VERR_IEM_ASPECT_NOT_IMPLEMENTED
+                    || rcIem == VERR_IEM_INSTR_NOT_IMPLEMENTED))
+        rcIem = VERR_EM_INTERPRETER;
+    g_IemCtx = *pCtx;
+    g_fIemFFs = pVCpu->fLocalForcedActions;
+    *pcbWritten = cbIemWritten;
+    rc = rcIem;
+#  endif
+
+#  if defined(VBOX_COMPARE_IEM_LAST) || defined(VBOX_COMPARE_IEM_FIRST)
+    emCompareWithIem(pVCpu, &g_EmCtx, &g_IemCtx, rcEm, rcIem, cbEmWritten, cbIemWritten);
+#  endif
+
+# else
     VBOXSTRICTRC rc = IEMExecOneBypassEx(pVCpu, pRegFrame, pcbWritten);
     if (RT_UNLIKELY(   rc == VERR_IEM_ASPECT_NOT_IMPLEMENTED
                     || rc == VERR_IEM_INSTR_NOT_IMPLEMENTED))
         rc = VERR_EM_INTERPRETER;
-
-# ifdef VBOX_COMPARE_IEM_AND_EM
-    emCompareWithIem(pVCpu, pCtx, rcEm, rc, cbEmWritten, *pcbWritten);
 # endif
     if (rc != VINF_SUCCESS)
@@ -866,4 +961,17 @@
     PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu);
     g_IncomingCtx = *pCtx;
+    g_fIncomingFFs = pVCpu->fLocalForcedActions;
+    g_cbEmWrote = g_cbIemWrote = 0;
+
+#  ifdef VBOX_COMPARE_IEM_FIRST
+    VBOXSTRICTRC rcIem = IEMExecOneBypassWithPrefetchedByPC(pVCpu, pRegFrame, pRegFrame->rip, pDis->abInstr, pDis->cbCachedInstr);
+    if (RT_UNLIKELY(   rcIem == VERR_IEM_ASPECT_NOT_IMPLEMENTED
+                    || rcIem == VERR_IEM_INSTR_NOT_IMPLEMENTED))
+        rcIem = VERR_EM_INTERPRETER;
+    g_IemCtx = *pCtx;
+    g_fIemFFs = pVCpu->fLocalForcedActions;
+    pVCpu->fLocalForcedActions = (pVCpu->fLocalForcedActions & ~g_fInterestingFFs) | (g_fIncomingFFs & g_fInterestingFFs);
+    *pCtx = g_IncomingCtx;
+#  endif
 
     /* EM */
@@ -879,18 +987,32 @@
     }
 #  endif
-
-    g_EmOutgoingCtx = *pCtx;
+    g_EmCtx = *pCtx;
+    g_fEmFFs = pVCpu->fLocalForcedActions;
+    VBOXSTRICTRC rc = rcEm;
+
+#  ifdef VBOX_COMPARE_IEM_LAST
+    /* IEM */
+    pVCpu->fLocalForcedActions = (pVCpu->fLocalForcedActions & ~g_fInterestingFFs) | (g_fIncomingFFs & g_fInterestingFFs);
     *pCtx = g_IncomingCtx;
-
-    /* IEM */
-# endif
+    VBOXSTRICTRC rcIem = IEMExecOneBypassWithPrefetchedByPC(pVCpu, pRegFrame, pRegFrame->rip, pDis->abInstr, pDis->cbCachedInstr);
+    if (RT_UNLIKELY(   rcIem == VERR_IEM_ASPECT_NOT_IMPLEMENTED
+                    || rcIem == VERR_IEM_INSTR_NOT_IMPLEMENTED))
+        rcIem = VERR_EM_INTERPRETER;
+    g_IemCtx = *pCtx;
+    g_fIemFFs = pVCpu->fLocalForcedActions;
+    rc = rcIem;
+#  endif
+
+#  if defined(VBOX_COMPARE_IEM_LAST) || defined(VBOX_COMPARE_IEM_FIRST)
+    emCompareWithIem(pVCpu, &g_EmCtx, &g_IemCtx, rcEm, rcIem, 0, 0);
+#  endif
+
+# else
     VBOXSTRICTRC rc = IEMExecOneBypassWithPrefetchedByPC(pVCpu, pRegFrame, pRegFrame->rip, pDis->abInstr, pDis->cbCachedInstr);
     if (RT_UNLIKELY(   rc == VERR_IEM_ASPECT_NOT_IMPLEMENTED
                     || rc == VERR_IEM_INSTR_NOT_IMPLEMENTED))
         rc = VERR_EM_INTERPRETER;
-
-# ifdef VBOX_COMPARE_IEM_AND_EM
-    emCompareWithIem(pVCpu, pCtx, rcEm, rc, 0, 0);
 # endif
+
     if (rc != VINF_SUCCESS)
         Log(("EMInterpretInstructionDisasState: returns %Rrc\n", VBOXSTRICTRC_VAL(rc)));
@@ -1249,5 +1371,5 @@
 #endif
         rc = VINF_SUCCESS;
-#ifndef VBOX_COMPARE_IEM_AND_EM
+#if !defined(VBOX_COMPARE_IEM_AND_EM) || !defined(VBOX_COMPARE_IEM_LAST)
         CPUMSetGuestCR0(pVCpu, val);
 #else
@@ -1579,9 +1701,15 @@
        pages or write monitored pages. */
     NOREF(pVM);
-#ifndef VBOX_COMPARE_IEM_AND_EM
-    return PGMPhysInterpretedWriteNoHandlers(pVCpu, pCtxCore, GCPtrDst, pvSrc, cb, /*fMayTrap*/ false);
+#if !defined(VBOX_COMPARE_IEM_AND_EM) || !defined(VBOX_COMPARE_IEM_LAST)
+    int rc = PGMPhysInterpretedWriteNoHandlers(pVCpu, pCtxCore, GCPtrDst, pvSrc, cb, /*fMayTrap*/ false);
 #else
-    return VINF_SUCCESS;
-#endif
+    int rc = VINF_SUCCESS;
+#endif
+#ifdef VBOX_COMPARE_IEM_AND_EM
+    Log(("EM Wrote: %RGv %.*Rhxs rc=%Rrc\n", GCPtrDst, RT_MAX(RT_MIN(cb, 64), 1), pvSrc, rc));
+    g_cbEmWrote = cb;
+    memcpy(g_abEmWrote, pvSrc, RT_MIN(cb, sizeof(g_abEmWrote)));
+#endif
+    return rc;
 }
 
@@ -2723,4 +2851,5 @@
     }
     eflags = EMEmulateCmpXchg(&u64, &pRegFrame->rax, valpar, pDis->Param2.cb);
+    int rc2 = emRamWrite(pVM, pVCpu, pRegFrame, GCPtrPar1, &u64, pDis->Param2.cb); AssertRCSuccess(rc2);
 #endif /* VBOX_COMPARE_IEM_AND_EM */
 
@@ -2781,4 +2910,5 @@
     uint64_t u64 = *(uint64_t *)pvParam1;
     eflags = EMEmulateCmpXchg8b(&u64, &pRegFrame->eax, &pRegFrame->edx, pRegFrame->ebx, pRegFrame->ecx);
+    int rc2 = emRamWrite(pVM, pVCpu, pRegFrame, GCPtrPar1, &u64, sizeof(u64)); AssertRCSuccess(rc2);
 #endif /* VBOX_COMPARE_IEM_AND_EM */
 
@@ -2863,4 +2993,5 @@
             }
             eflags = EMEmulateXAdd(&u64, pvParamReg2, cbParamReg2);
+            int rc2 = emRamWrite(pVM, pVCpu, pRegFrame, GCPtrPar1, &u64, pDis->Param2.cb); AssertRCSuccess(rc2);
 #endif /* VBOX_COMPARE_IEM_AND_EM */
 
@@ -3624,5 +3755,5 @@
                 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,Failed##Instr)); \
             return rc
-# endif /* VBOX_COMPARE_IEM_AND_EM*/
+# endif /* VBOX_COMPARE_IEM_AND_EM */
 
 #define INTERPRET_CASE_EX_PARAM3(opcode, Instr, InstrFn, pfnEmulate) \
Index: /trunk/src/VBox/VMM/VMMAll/IEMAll.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/IEMAll.cpp	(revision 42776)
+++ /trunk/src/VBox/VMM/VMMAll/IEMAll.cpp	(revision 42777)
@@ -70,4 +70,9 @@
  *
  */
+
+/** @def IEM_VERIFICATION_MODE_MINIMAL
+ * Use for pitting IEM against EM or something else in ring-0 or raw-mode
+ * context. */
+//#define IEM_VERIFICATION_MODE_MINIMAL
 
 /*******************************************************************************
@@ -86,9 +91,9 @@
 # include <VBox/vmm/patm.h>
 #endif
-#ifdef IEM_VERIFICATION_MODE
+#include "IEMInternal.h"
+#ifdef IEM_VERIFICATION_MODE_FULL
 # include <VBox/vmm/rem.h>
 # include <VBox/vmm/mm.h>
 #endif
-#include "IEMInternal.h"
 #include <VBox/vmm/vm.h>
 #include <VBox/log.h>
@@ -173,10 +178,4 @@
 *   Defined Constants And Macros                                               *
 *******************************************************************************/
-/** @def IEM_LOG_MEMORY_ACCESS
- * Can be used to log memory accesses when debugging problematic guest behavior. */
-#if 0
-# define IEM_LOG_MEMORY_ACCESS
-#endif
-
 /** @name IEM status codes.
  *
@@ -634,4 +633,12 @@
     iemAImpl_shrd_u64,
 };
+
+
+#ifdef IEM_VERIFICATION_MODE_MINIMAL
+/** What IEM just wrote. */
+uint8_t g_abIemWrote[256];
+/** How much IEM just wrote. */
+size_t g_cbIemWrote;
+#endif
 
 
@@ -664,5 +671,5 @@
 static uint16_t         iemSRegFetchU16(PIEMCPU pIemCpu, uint8_t iSegReg);
 
-#ifdef IEM_VERIFICATION_MODE
+#if defined(IEM_VERIFICATION_MODE_FULL) && !defined(IEM_VERIFICATION_MODE_MINIMAL)
 static PIEMVERIFYEVTREC iemVerifyAllocRecord(PIEMCPU pIemCpu);
 #endif
@@ -722,5 +729,5 @@
     PVMCPU   pVCpu = IEMCPU_TO_VMCPU(pIemCpu);
 
-#if defined(VBOX_STRICT) && (defined(IEM_VERIFICATION_MODE) || !defined(VBOX_WITH_RAW_MODE_NOT_R0))
+#if defined(VBOX_STRICT) && (defined(IEM_VERIFICATION_MODE_FULL) || defined(VBOX_WITH_RAW_MODE_NOT_R0))
     Assert(CPUMSELREG_ARE_HIDDEN_PARTS_VALID(pVCpu, &pCtx->cs));
     Assert(CPUMSELREG_ARE_HIDDEN_PARTS_VALID(pVCpu, &pCtx->ss));
@@ -737,5 +744,5 @@
 #endif
     pIemCpu->uCpl               = CPUMGetGuestCPL(pVCpu);
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
     if (pIemCpu->uInjectCpl != UINT8_MAX)
         pIemCpu->uCpl           = pIemCpu->uInjectCpl;
@@ -775,5 +782,5 @@
 static VBOXSTRICTRC iemInitDecoderAndPrefetchOpcodes(PIEMCPU pIemCpu, bool fBypassHandlers)
 {
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
     uint8_t const cbOldOpcodes = pIemCpu->cbOpcode;
 #endif
@@ -846,5 +853,5 @@
      *        TLB... */
 
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
     /*
      * Optimistic optimization: Use unconsumed opcode bytes from the previous
@@ -4727,10 +4734,10 @@
 static int iemMemPageMap(PIEMCPU pIemCpu, RTGCPHYS GCPhysMem, uint32_t fAccess, void **ppvMem, PPGMPAGEMAPLOCK pLock)
 {
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
     /* Force the alternative path so we can ignore writes. */
     if ((fAccess & IEM_ACCESS_TYPE_WRITE) && !pIemCpu->fNoRem)
         return VERR_PGM_PHYS_TLB_CATCH_ALL;
 #endif
-#ifdef IEM_LOG_MEMORY_ACCESS
+#ifdef IEM_VERIFICATION_MODE_MINIMAL
     return VERR_PGM_PHYS_TLB_CATCH_ALL;
 #endif
@@ -4839,4 +4846,5 @@
      */
     int rc;
+#ifndef IEM_VERIFICATION_MODE_MINIMAL
     if (   !pIemCpu->aMemBbMappings[iMemMap].fUnassigned
         && !IEM_VERIFICATION_ENABLED(pIemCpu))
@@ -4879,7 +4887,8 @@
     }
     else
+#endif
         rc = VINF_SUCCESS;
 
-#if defined(IEM_VERIFICATION_MODE) && defined(IN_RING3)
+#if defined(IEM_VERIFICATION_MODE_FULL) && defined(IN_RING3)
     /*
      * Record the write(s).
@@ -4915,5 +4924,5 @@
     }
 #endif
-#ifdef IEM_LOG_MEMORY_ACCESS
+#ifdef IEM_VERIFICATION_MODE_MINIMAL
     if (rc == VINF_SUCCESS)
     {
@@ -4924,4 +4933,8 @@
                  RT_MIN(pIemCpu->aMemBbMappings[iMemMap].cbSecond, 64),
                  &pIemCpu->aBounceBuffers[iMemMap].ab[pIemCpu->aMemBbMappings[iMemMap].cbFirst]));
+
+        size_t cbWrote = pIemCpu->aMemBbMappings[iMemMap].cbFirst + pIemCpu->aMemBbMappings[iMemMap].cbSecond;
+        g_cbIemWrote = cbWrote;
+        memcpy(g_abIemWrote, &pIemCpu->aBounceBuffers[iMemMap].ab[0], RT_MIN(cbWrote, sizeof(g_abIemWrote)));
     }
 #endif
@@ -5005,5 +5018,5 @@
         }
 
-#if defined(IEM_VERIFICATION_MODE) && defined(IN_RING3)
+#if defined(IEM_VERIFICATION_MODE_FULL) && defined(IN_RING3)
         if (   !pIemCpu->fNoRem
             && (fAccess & (IEM_ACCESS_TYPE_READ | IEM_ACCESS_TYPE_EXEC)) )
@@ -5103,5 +5116,5 @@
         }
 
-#if defined(IEM_VERIFICATION_MODE) && defined(IN_RING3)
+#if defined(IEM_VERIFICATION_MODE_FULL) && defined(IN_RING3)
         if (   !pIemCpu->fNoRem
             && (fAccess & (IEM_ACCESS_TYPE_READ | IEM_ACCESS_TYPE_EXEC)) )
@@ -7434,5 +7447,5 @@
 
 
-#if defined(IEM_VERIFICATION_MODE) && defined(IN_RING3)
+#if defined(IEM_VERIFICATION_MODE_FULL) && defined(IN_RING3)
 
 /**
@@ -8243,5 +8256,5 @@
 }
 
-#else  /* !IEM_VERIFICATION_MODE || !IN_RING3 */
+#else  /* !IEM_VERIFICATION_MODE_FULL || !IN_RING3 */
 
 /* stubs */
@@ -8258,5 +8271,5 @@
 }
 
-#endif /* !IEM_VERIFICATION_MODE || !IN_RING3 */
+#endif /* !IEM_VERIFICATION_MODE_FULL || !IN_RING3 */
 
 
@@ -8328,5 +8341,5 @@
         else if (rcStrict == VERR_IEM_INSTR_NOT_IMPLEMENTED)
             pIemCpu->cRetInstrNotImplemented++;
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
         else if (rcStrict == VERR_IEM_RESTART_INSTRUCTION)
             rcStrict = VINF_SUCCESS;
@@ -8343,5 +8356,5 @@
     Assert(CPUMSELREG_ARE_HIDDEN_PARTS_VALID(pVCpu, &pIemCpu->CTX_SUFF(pCtx)->cs));
     Assert(CPUMSELREG_ARE_HIDDEN_PARTS_VALID(pVCpu, &pIemCpu->CTX_SUFF(pCtx)->ss));
-#if defined(IEM_VERIFICATION_MODE)
+#if defined(IEM_VERIFICATION_MODE_FULL)
     Assert(CPUMSELREG_ARE_HIDDEN_PARTS_VALID(pVCpu, &pIemCpu->CTX_SUFF(pCtx)->es));
     Assert(CPUMSELREG_ARE_HIDDEN_PARTS_VALID(pVCpu, &pIemCpu->CTX_SUFF(pCtx)->ds));
@@ -8363,5 +8376,5 @@
     PIEMCPU  pIemCpu = &pVCpu->iem.s;
 
-#if defined(IEM_VERIFICATION_MODE) && defined(IN_RING3)
+#if defined(IEM_VERIFICATION_MODE_FULL) && defined(IN_RING3)
     iemExecVerificationModeSetup(pIemCpu);
 #endif
@@ -8407,5 +8420,5 @@
         rcStrict = iemExecOneInner(pVCpu, pIemCpu, true);
 
-#if defined(IEM_VERIFICATION_MODE) && defined(IN_RING3)
+#if defined(IEM_VERIFICATION_MODE_FULL) && defined(IN_RING3)
     /*
      * Assert some sanity.
Index: /trunk/src/VBox/VMM/VMMAll/IEMAllCImpl.cpp.h
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/IEMAllCImpl.cpp.h	(revision 42776)
+++ /trunk/src/VBox/VMM/VMMAll/IEMAllCImpl.cpp.h	(revision 42777)
@@ -1025,7 +1025,6 @@
         if (rcStrict != VINF_SUCCESS)
             return rcStrict;
-#ifdef IEM_VERIFICATION_MODE /** @todo check what VT-x and AMD-V does. */
+        /** @todo check what VT-x and AMD-V does. */
         Desc.Legacy.Gen.u4Type |= X86_SEL_TYPE_ACCESSED;
-#endif
     }
 
@@ -1221,7 +1220,6 @@
         if (rcStrict != VINF_SUCCESS)
             return rcStrict;
-#ifdef IEM_VERIFICATION_MODE /** @todo check what VT-x and AMD-V does. */
+        /** @todo check what VT-x and AMD-V does. */
         Desc.Legacy.Gen.u4Type |= X86_SEL_TYPE_ACCESSED;
-#endif
     }
 
@@ -1529,7 +1527,6 @@
             if (rcStrict != VINF_SUCCESS)
                 return rcStrict;
-#ifdef IEM_VERIFICATION_MODE /** @todo check what VT-x and AMD-V does. */
+            /** @todo check what VT-x and AMD-V does. */
             DescCs.Legacy.Gen.u4Type |= X86_SEL_TYPE_ACCESSED;
-#endif
         }
         /** @todo Testcase: Need to check WHEN exactly the SS accessed bit is set. */
@@ -1539,7 +1536,6 @@
             if (rcStrict != VINF_SUCCESS)
                 return rcStrict;
-#ifdef IEM_VERIFICATION_MODE /** @todo check what VT-x and AMD-V does. */
+            /** @todo check what VT-x and AMD-V does. */
             DescSs.Legacy.Gen.u4Type |= X86_SEL_TYPE_ACCESSED;
-#endif
         }
 
@@ -1622,7 +1618,6 @@
             if (rcStrict != VINF_SUCCESS)
                 return rcStrict;
-#ifdef IEM_VERIFICATION_MODE /** @todo check what VT-x and AMD-V does. */
+            /** @todo check what VT-x and AMD-V does. */
             DescCs.Legacy.Gen.u4Type |= X86_SEL_TYPE_ACCESSED;
-#endif
         }
 
@@ -3743,5 +3738,5 @@
     pCtx->rax = (uint32_t)uTicks;
     pCtx->rdx = uTicks >> 32;
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
     pIemCpu->fIgnoreRaxRdx = true;
 #endif
Index: /trunk/src/VBox/VMM/include/IEMInternal.h
===================================================================
--- /trunk/src/VBox/VMM/include/IEMInternal.h	(revision 42776)
+++ /trunk/src/VBox/VMM/include/IEMInternal.h	(revision 42777)
@@ -32,4 +32,12 @@
  * @{
  */
+
+/** @def IEM_VERIFICATION_MODE_FULL
+ * Shorthand for:
+ *    defined(IEM_VERIFICATION_MODE) && !defined(IEM_VERIFICATION_MODE_MINIMAL)
+ */
+#if defined(IEM_VERIFICATION_MODE) && !defined(IEM_VERIFICATION_MODE_MINIMAL) && !defined(IEM_VERIFICATION_MODE_FULL)
+# define IEM_VERIFICATION_MODE_FULL
+#endif
 
 
@@ -121,5 +129,5 @@
 
 
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
 
 /**
@@ -184,5 +192,5 @@
 typedef IEMVERIFYEVTREC *PIEMVERIFYEVTREC;
 
-#endif /* IEM_VERIFICATION_MODE */
+#endif /* IEM_VERIFICATION_MODE_FULL */
 
 
@@ -247,5 +255,5 @@
     /** Number of times rcPassUp has been used. */
     uint32_t                cRetPassUpStatus;
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
     /** The Number of I/O port reads that has been performed. */
     uint32_t                cIOReads;
@@ -369,5 +377,5 @@
     } aBounceBuffers[3];
 
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
     /** The event verification records for what IEM did (LIFO). */
     R3PTRTYPE(PIEMVERIFYEVTREC)     pIemEvtRecHead;
@@ -464,10 +472,19 @@
  * should therefore cause the compiler to eliminate the verification branch
  * of an if statement.  */
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
 # define IEM_VERIFICATION_ENABLED(a_pIemCpu)    (!(a_pIemCpu)->fNoRem)
+#elif defined(IEM_VERIFICATION_MODE_MINIMAL)
+# define IEM_VERIFICATION_ENABLED(a_pIemCpu)    (true)
 #else
 # define IEM_VERIFICATION_ENABLED(a_pIemCpu)    (false)
 #endif
 
+/** @def IEM_VERIFICATION_MODE
+ * Indicates that one of the verfication modes are enabled.
+ */
+#if (defined(IEM_VERIFICATION_MODE_FULL) || defined(IEM_VERIFICATION_MODE_MINIMAL)) && !defined(IEM_VERIFICATION_MODE)
+# define IEM_VERIFICATION_MODE
+#endif
+
 /**
  * Indicates to the verifier that the given flag set is undefined.
@@ -477,5 +494,5 @@
  * This is a NOOP if the verifier isn't compiled in.
  */
-#ifdef IEM_VERIFICATION_MODE
+#ifdef IEM_VERIFICATION_MODE_FULL
 # define IEMOP_VERIFICATION_UNDEFINED_EFLAGS(a_fEfl) do { pIemCpu->fUndefinedEFlags |= (a_fEfl); } while (0)
 #else
