about summary refs log tree commit diff stats
path: root/src/emu
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-03-28 13:34:45 +0200
committerptitSeb <sebastien.chev@gmail.com>2023-03-28 13:34:56 +0200
commitd73ff21b27b7f2fdca3f817fb37faefe388439d8 (patch)
treecfe79810c265024864f845bee0d286df03ab7ae0 /src/emu
parent4a90199f63ea2e8ee16d11a20c5b9cc9abd11498 (diff)
downloadbox64-d73ff21b27b7f2fdca3f817fb37faefe388439d8.tar.gz
box64-d73ff21b27b7f2fdca3f817fb37faefe388439d8.zip
[DYNAREC] Improved TEST_INTERPRETER with inter-block testing
Diffstat (limited to 'src/emu')
-rwxr-xr-xsrc/emu/x64emu_private.h3
-rwxr-xr-xsrc/emu/x64run.c8
-rw-r--r--src/emu/x64test.c41
3 files changed, 32 insertions, 20 deletions
diff --git a/src/emu/x64emu_private.h b/src/emu/x64emu_private.h
index 3393986c..3fb43df3 100755
--- a/src/emu/x64emu_private.h
+++ b/src/emu/x64emu_private.h
@@ -31,6 +31,7 @@ typedef struct x64test_s {
     x64emu_t*   emu;
     uintptr_t   memaddr;
     int         memsize;
+    int         test;
     uint8_t     mem[16];
 } x64test_t;
 
@@ -86,6 +87,7 @@ typedef struct x64emu_s {
     int         quitonlongjmp;  // quit if longjmp is called
     int         quitonexit;     // quit if exit/_exit is called
     int         longjmp;        // if quit because of longjmp
+    x64test_t   test;       // used for dynarec testing
     // scratch stack, used for alignement of double and 64bits ints on arm. 200 elements should be enough
     uint64_t    scratch[200];
     // local stack, do be deleted when emu is freed
@@ -96,7 +98,6 @@ typedef struct x64emu_s {
     x64_ucontext_t *uc_link; // to handle setcontext
 
     int         type;       // EMUTYPE_xxx define
-    x64test_t   test;
 } x64emu_t;
 
 #define EMUTYPE_NONE    0
diff --git a/src/emu/x64run.c b/src/emu/x64run.c
index 0f982a77..f064dfd1 100755
--- a/src/emu/x64run.c
+++ b/src/emu/x64run.c
@@ -1581,9 +1581,9 @@ x64emurun:
             break;
         case 0xFF:                      /* GRP 5 Ed */
             nextop = F8;
-            GETED(0);
             switch((nextop>>3)&7) {
                 case 0:                 /* INC Ed */
+                    GETED(0);
                     if(rex.w)
                         ED->q[0] = inc64(emu, ED->q[0]);
                     else {
@@ -1594,6 +1594,7 @@ x64emurun:
                     }
                     break;
                 case 1:                 /* DEC Ed */
+                    GETED(0);
                     if(rex.w)
                         ED->q[0] = dec64(emu, ED->q[0]);
                     else {
@@ -1604,12 +1605,14 @@ x64emurun:
                     }
                     break;
                 case 2:                 /* CALL NEAR Ed */
+                    GETE8(0);
                     tmp64u = (uintptr_t)getAlternate((void*)ED->q[0]);
                     Push(emu, addr);
                     addr = tmp64u;
                     STEP2
                     break;
                 case 3:                 /* CALL FAR Ed */
+                    GETET(0);
                     if(MODREG) {
                         printf_log(LOG_NONE, "Illegal Opcode %p: %02X %02X %02X %02X\n", (void*)R_RIP, opcode, nextop, PK(2), PK(3));
                         emu->quit=1;
@@ -1624,10 +1627,12 @@ x64emurun:
                     }
                     break;
                 case 4:                 /* JMP NEAR Ed */
+                    GETE8(0);
                     addr = (uintptr_t)getAlternate((void*)ED->q[0]);
                     STEP2
                     break;
                 case 5:                 /* JMP FAR Ed */
+                    GETET(0);
                     if(MODREG) {
                         printf_log(LOG_NONE, "Illegal Opcode %p: 0x%02X 0x%02X %02X %02X\n", (void*)R_RIP, opcode, nextop, PK(2), PK(3));
                         emu->quit=1;
@@ -1640,6 +1645,7 @@ x64emurun:
                     }
                     break;
                 case 6:                 /* Push Ed */
+                    GETE8(0);
                     tmp64u = ED->q[0];  // rex.w ignored
                     #ifdef TEST_INTERPRETER
                     R_RSP -=8;
diff --git a/src/emu/x64test.c b/src/emu/x64test.c
index f58e68c4..ee241597 100644
--- a/src/emu/x64test.c
+++ b/src/emu/x64test.c
@@ -7,6 +7,7 @@
 #include <signal.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <stddef.h>
 
 #include "debug.h"
 #include "box64stack.h"
@@ -21,23 +22,6 @@
 #include "bridge.h"
 #include "signals.h"
 
-void x64test_init(x64emu_t* ref, uintptr_t ip, int ok)
-{
-    x64test_t* test = &ref->test;
-    // check if test as a valid emu struct
-    if(!test->emu) {
-        test->emu = NewX64Emu(my_context, ip, (uintptr_t)ref->init_stack, ref->size_stack, 0);
-        CopyEmu(test->emu, ref);
-    }
-    // check if IP is same, else, sync
-    if(ip != test->emu->ip.q[0] || !ok) {
-        CopyEmu(test->emu, ref);
-    }
-    // Do a Dry single Step
-    test->memsize = 0;
-    RunTest(test);
-}
-
 void print_banner(x64emu_t* ref)
 {
     printf_log(LOG_NONE, "Warning, difference between Interpreter and Dynarec in %p\n=======================================\n", (void*)ref->ip.q[0]);
@@ -134,9 +118,30 @@ void x64test_check(x64emu_t* ref, uintptr_t ip)
             printf_log(LOG_NONE, " |");
             for(int i=0; i<test->memsize; ++i)
                 printf_log(LOG_NONE, " %02x", ((uint8_t*)test->memaddr)[i]);
+            printf_log(LOG_NONE, "\n");
         }
     }
     if(banner)  // there was an error, re-sync!
         CopyEmu(emu, ref);
 }
-#undef BANNER
\ No newline at end of file
+#undef BANNER
+
+void x64test_init(x64emu_t* ref, uintptr_t ip)
+{
+    x64test_t* test = &ref->test;
+    // check if test as a valid emu struct
+    if(!test->emu) {
+        test->emu = NewX64Emu(my_context, ip, (uintptr_t)ref->init_stack, ref->size_stack, 0);
+        CopyEmu(test->emu, ref);
+    } else if(test->test) {
+        x64test_check(ref, ip);
+    }
+    // check if IP is same, else, sync
+    if(ip != test->emu->ip.q[0] || !test->test) {
+        CopyEmu(test->emu, ref);
+    }
+    // Do a Dry single Step
+    test->memsize = 0;
+    test->test = 1;
+    RunTest(test);
+}