about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-02-19 23:54:00 +0100
committerptitSeb <sebastien.chev@gmail.com>2023-02-19 23:54:00 +0100
commitd06ff478d188eb4a077041e4b2b628f75ed9eaf8 (patch)
treeafeb72b0d96281ae9f53497e86baf98fac718da9 /src
parent83db04cdce694727c9b3bbb680b54feaae51d98a (diff)
downloadbox64-d06ff478d188eb4a077041e4b2b628f75ed9eaf8.tar.gz
box64-d06ff478d188eb4a077041e4b2b628f75ed9eaf8.zip
[DYNAREC] Introduced BOX64_DYNAREC_FASTPAGE to use an alternate way to handle HotPages (faster but crashy)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/dynarec/dynablock.c15
-rwxr-xr-xsrc/include/debug.h1
-rwxr-xr-xsrc/main.c10
-rw-r--r--src/tools/rcfile.c8
4 files changed, 29 insertions, 5 deletions
diff --git a/src/dynarec/dynablock.c b/src/dynarec/dynablock.c
index 6ff5e53c..9529a91c 100755
--- a/src/dynarec/dynablock.c
+++ b/src/dynarec/dynablock.c
@@ -205,8 +205,19 @@ dynablock_t* DBGetBlock(x64emu_t* emu, uintptr_t addr, int create)
     dynablock_t *db = internalDBGetBlock(emu, addr, addr, create, 1);
     if(db && db->done && db->block && db->need_test) {
         if(AreaInHotPage((uintptr_t)db->x64_addr, (uintptr_t)db->x64_addr + db->x64_size - 1)) {
-            dynarec_log(LOG_INFO, "Not running block %p from %p:%p with for %p because it's in a hotpage\n", db, db->x64_addr, db->x64_addr+db->x64_size-1, (void*)addr);
-            return NULL;
+            if(box64_dynarec_fastpage) {
+                uint32_t hash = X31_hash_code(db->x64_addr, db->x64_size);
+                if(hash==db->hash)  // seems ok, run it without reprotecting it
+                    return db;
+                db->done = 0;   // invalidating the block, it's already not good
+                dynarec_log(LOG_DEBUG, "Invalidating block %p from %p:%p (hash:%X/%X) for %p\n", db, db->x64_addr, db->x64_addr+db->x64_size-1, hash, db->hash, (void*)addr);
+                // Free db, it's now invalid!
+                FreeDynablock(db, 1);
+                return NULL;    // not building a new one, it's still a hotpage
+            } else {
+                dynarec_log(LOG_INFO, "Not running block %p from %p:%p with for %p because it's in a hotpage\n", db, db->x64_addr, db->x64_addr+db->x64_size-1, (void*)addr);
+                return NULL;
+            }
         }
         uint32_t hash = X31_hash_code(db->x64_addr, db->x64_size);
         if(mutex_trylock(&my_context->mutex_dyndump)) {
diff --git a/src/include/debug.h b/src/include/debug.h
index 06ec0d8c..b9729787 100755
--- a/src/include/debug.h
+++ b/src/include/debug.h
@@ -23,6 +23,7 @@ extern int box64_dynarec_safeflags;
 extern int box64_dynarec_callret;
 extern int box64_dynarec_bleeding_edge;
 extern int box64_dynarec_hotpage;
+extern int box64_dynarec_fastpage;
 extern int box64_dynarec_wait;
 #ifdef ARM64
 extern int arm64_asimd;
diff --git a/src/main.c b/src/main.c
index b8ee9f4b..55a18473 100755
--- a/src/main.c
+++ b/src/main.c
@@ -57,6 +57,7 @@ int box64_dynarec_fastround = 1;
 int box64_dynarec_safeflags = 1;
 int box64_dynarec_callret = 0;
 int box64_dynarec_hotpage = 16;
+int box64_dynarec_fastpage = 0;
 int box64_dynarec_bleeding_edge = 1;
 int box64_dynarec_wait = 1;
 uintptr_t box64_nodynarec_start = 0;
@@ -563,6 +564,15 @@ void LoadLogEnv()
         else
             printf_log(LOG_INFO, "Dynarec will not tag HotPage\n");
     }
+    p = getenv("BOX64_DYNAREC_FASTPAGE");
+    if(p) {
+        if(strlen(p)==1) {
+            if(p[0]>='0' && p[0]<='1')
+                box64_dynarec_fastpage = p[0]-'0';
+        }
+        if(box64_dynarec_fastpage)
+            printf_log(LOG_INFO, "Dynarec will use Fast HotPage\n");
+    }
     p = getenv("BOX64_NODYNAREC");
     if(p) {
         if (strchr(p,'-')) {
diff --git a/src/tools/rcfile.c b/src/tools/rcfile.c
index e3789a20..60e1a1e5 100644
--- a/src/tools/rcfile.c
+++ b/src/tools/rcfile.c
@@ -112,7 +112,8 @@ ENTRYINT(BOX64_DYNAREC_SAFEFLAGS, box64_dynarec_safeflags, 0, 2, 2) \
 ENTRYBOOL(BOX64_DYNAREC_CALLRET, box64_dynarec_callret)             \
 ENTRYBOOL(BOX64_DYNAREC_BLEEDING_EDGE, box64_dynarec_bleeding_edge) \
 ENTRYINT(BOX64_DYNAREC_HOTPAGE, box64_dynarec_hotpage, 0, 255, 8)   \
-ENTRYBOOL(box64_dynarec_wait, box64_dynarec_wait)                   \
+ENTRYBOOL(BOX64_DYNAREC_FASTPAGE, box64_dynarec_fastpage)           \
+ENTRYBOOL(BOX64_DYNAREC_WAIT, box64_dynarec_wait)                   \
 ENTRYSTRING_(BOX64_NODYNAREC, box64_nodynarec)                      \
 
 #else
@@ -129,7 +130,8 @@ IGNORE(BOX64_DYNAREC_SAFEFLAGS)                                     \
 IGNORE(BOX64_DYNAREC_CALLRET)                                       \
 IGNORE(BOX64_DYNAREC_BLEEDING_EDGE)                                 \
 IGNORE(BOX64_DYNAREC_HOTPAGE)                                       \
-IGNORE(BOX64_DYNAREC_wait)                                          \
+IGNORE(BOX64_DYNAREC_FASTPAGE)                                      \
+IGNORE(BOX64_DYNAREC_WAIT)                                          \
 IGNORE(BOX64_NODYNAREC)                                             \
 
 #endif
@@ -354,7 +356,7 @@ void LoadRCFile(const char* filename)
             if(0) ;
             SUPER()
             else if(len && current_name) {
-                printf_log(LOG_INFO, "Warning, unsupported %s=%s for [%s] in %s", key, val, current_name, filename);
+                printf_log(LOG_INFO, "Warning, unsupported %s=%s for [%s] in %s\n", key, val, current_name, filename);
             }
             #undef ENTRYBOOL
             #undef CENTRYBOOL