  
  #if BX_SUPPORT_X86_64
    if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64)
-@@ -149,26 +228,14 @@
+@@ -142,26 +221,14 @@
      ret = fetchDecode32(fetchPtr, i, maxFetch);
  
    if (ret==0) {

     }
   }
 
@@ -2697,6 +2705,13 @@
   if (BX_NULL_SEG_REG(instruction->seg()))
      instruction->setSeg(BX_SEG_REG_DS);
 

+      CHECK_MAX_INSTRUCTIONS(max_instr_count);
+
+#if BX_SUPPORT_ICACHE
+      if (trace && trace->writeStamp != *(BX_CPU_THIS_PTR currPageWriteStampPtr))
+        break; // probably it is self modifying code ...
+#endif
+
+      if (BX_CPU_THIS_PTR async_event) break;
