about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-01-15 17:48:54 +0100
committerptitSeb <sebastien.chev@gmail.com>2024-01-15 17:48:54 +0100
commit307acee9d32f421616c8b1cc97536848c00a53bc (patch)
tree8abe9f16c7e32aede299263d7af67fd3bb9dd627 /src
parent184b2cc26b0ed736ba1e24556860c940d3381e0b (diff)
downloadbox64-307acee9d32f421616c8b1cc97536848c00a53bc.tar.gz
box64-307acee9d32f421616c8b1cc97536848c00a53bc.zip
[INTERPRETER] Fixed VM Detection (TF trick) for interpreter
Diffstat (limited to 'src')
-rw-r--r--src/emu/x64run.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/emu/x64run.c b/src/emu/x64run.c
index 7faa06c9..b3f3b9d5 100644
--- a/src/emu/x64run.c
+++ b/src/emu/x64run.c
@@ -53,6 +53,7 @@ int Run(x64emu_t *emu, int step)
     int rep;    // 0 none, 1=F2 prefix, 2=F3 prefix
     int unimp = 0;
     int is32bits = (emu->segs[_CS]==0x23);
+    int tf_next = 0;
 
     if(emu->quit)
         return 0;
@@ -822,8 +823,12 @@ x64emurun:
                 Push64(emu, emu->eflags.x64);
             break;
         case 0x9D:                      /* POPF */
+            if(ACCESS_FLAG(F_TF) && !tf_next)
+                --tf_next;
             emu->eflags.x64 = (((rex.is32bits?Pop32(emu):Pop64(emu)) & 0x3F7FD7)/* & (0xffff-40)*/ ) | 0x2; // mask off res2 and res3 and on res1
             RESET_FLAGS(emu);
+            if(ACCESS_FLAG(F_TF))
+                ++tf_next;
             break;
         case 0x9E:                      /* SAHF */
             CHECK_FLAGS(emu);
@@ -1985,9 +1990,13 @@ x64emurun:
 #ifndef TEST_INTERPRETER
         // check the TRACE flag before going to next
         if(ACCESS_FLAG(F_TF)) {
-            R_RIP = addr;
-            emit_signal(emu, SIGTRAP, (void*)addr, 1);
-            if(emu->quit) goto fini;
+            if(tf_next) {
+                tf_next = 0;
+            } else {
+                R_RIP = addr;
+                emit_signal(emu, SIGTRAP, (void*)addr, 1);
+                if(emu->quit) goto fini;
+            }
         }
 #endif
         R_RIP = addr;