about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2022-02-28 16:03:28 +0800
committerptitSeb <sebastien.chev@gmail.com>2022-02-28 16:03:28 +0800
commitc3fd9d03ba22beecc06e9bc2b17525a3a9ed65e1 (patch)
treeca8995a6af869a004e65b2d56841e0060edf9d1b /src
parent7a539e4ef750978a7f5ac7bd8e6287113ad23492 (diff)
downloadbox64-c3fd9d03ba22beecc06e9bc2b17525a3a9ed65e1.tar.gz
box64-c3fd9d03ba22beecc06e9bc2b17525a3a9ed65e1.zip
[DYNAREC] still working on multiarch
Diffstat (limited to 'src')
-rw-r--r--src/custommem.c33
-rwxr-xr-xsrc/main.c5
2 files changed, 24 insertions, 14 deletions
diff --git a/src/custommem.c b/src/custommem.c
index 236456a0..e5be3ba9 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -41,8 +41,13 @@ static uintptr_t*          box64_jmptbldefault1[1<<JMPTABL_SHIFT];
 static uintptr_t           box64_jmptbldefault0[1<<JMPTABL_SHIFT];
 #endif
 static pthread_mutex_t     mutex_prot;
+#ifdef LA464
+#define MEMPROT_SHIFT 14
+#define MEMPROT_SHIFT2 (16+14)
+#else
 #define MEMPROT_SHIFT 12
 #define MEMPROT_SHIFT2 (16+12)
+#endif
 #define MEMPROT_SIZE (1<<16)
 static uint8_t *volatile memprot[1<<20];    // x86_64 mem is 48bits, page is 12bits, so memory is tracked as [20][16][page protection]
 static uint8_t memprot_default[MEMPROT_SIZE];
@@ -759,8 +764,8 @@ void protectDB(uintptr_t addr, uintptr_t size)
     dynarec_log(LOG_DEBUG, "protectDB %p -> %p\n", (void*)addr, (void*)(addr+size-1));
     uintptr_t idx = (addr>>MEMPROT_SHIFT);
     uintptr_t end = ((addr+size-1LL)>>MEMPROT_SHIFT);
-    if(end>=(1LL<<(20+16)))
-        end = (1LL<<(20+16))-1;
+    if(end>=(1LL<<(48-MEMPROT_SHIFT)))
+        end = (1LL<<(48-MEMPROT_SHIFT))-1;
     if(end<idx) // memory addresses higher than 48bits are not tracked
         return;
     pthread_mutex_lock(&mutex_prot);
@@ -793,8 +798,8 @@ void unprotectDB(uintptr_t addr, size_t size)
     dynarec_log(LOG_DEBUG, "unprotectDB %p -> %p\n", (void*)addr, (void*)(addr+size-1));
     uintptr_t idx = (addr>>MEMPROT_SHIFT);
     uintptr_t end = ((addr+size-1)>>MEMPROT_SHIFT);
-    if(end>=(1LL<<(20+16)))
-        end = (1LL<<(20+16))-1;
+    if(end>=(1LL<<(48-MEMPROT_SHIFT)))
+        end = (1LL<<(48-MEMPROT_SHIFT))-1;
     if(end<idx) // memory addresses higher than 48bits are not tracked
         return;
     pthread_mutex_lock(&mutex_prot);
@@ -824,8 +829,8 @@ int isprotectedDB(uintptr_t addr, size_t size)
     dynarec_log(LOG_DEBUG, "isprotectedDB %p -> %p => ", (void*)addr, (void*)(addr+size-1));
     uintptr_t idx = (addr>>MEMPROT_SHIFT);
     uintptr_t end = ((addr+size-1LL)>>MEMPROT_SHIFT);
-    if(end>=(1LL<<(20+16)))
-        end = (1LL<<(20+16))-1LL;
+    if(end>=(1LL<<(48-MEMPROT_SHIFT)))
+        end = (1LL<<(48-MEMPROT_SHIFT))-1LL;
     if(end<idx) { // memory addresses higher than 48bits are not tracked
         dynarec_log(LOG_DEBUG, "00\n");
         return 0;
@@ -848,8 +853,8 @@ void updateProtection(uintptr_t addr, size_t size, uint32_t prot)
     dynarec_log(LOG_DEBUG, "updateProtection %p:%p 0x%x\n", (void*)addr, (void*)(addr+size-1), prot);
     uintptr_t idx = (addr>>MEMPROT_SHIFT);
     uintptr_t end = ((addr+size-1)>>MEMPROT_SHIFT);
-    if(end>=(1LL<<(20+16)))
-        end = (1LL<<(20+16))-1;
+    if(end>=(1LL<<(48-MEMPROT_SHIFT)))
+        end = (1LL<<(48-MEMPROT_SHIFT))-1;
     if(end<idx) // memory addresses higher than 48bits are not tracked
         return;
     pthread_mutex_lock(&mutex_prot);
@@ -877,8 +882,8 @@ void setProtection(uintptr_t addr, size_t size, uint32_t prot)
 {
     uintptr_t idx = (addr>>MEMPROT_SHIFT);
     uintptr_t end = ((addr+size-1)>>MEMPROT_SHIFT);
-    if(end>=(1LL<<(20+16)))
-        end = (1LL<<(20+16))-1;
+    if(end>=(1LL<<(48-MEMPROT_SHIFT)))
+        end = (1LL<<(48-MEMPROT_SHIFT))-1;
     if(end<idx) // memory addresses higher than 48bits are not tracked
         return;
     pthread_mutex_lock(&mutex_prot);
@@ -903,8 +908,8 @@ void allocProtection(uintptr_t addr, size_t size, uint32_t prot)
     dynarec_log(LOG_DEBUG, "allocProtection %p:%p 0x%x\n", (void*)addr, (void*)(addr+size-1), prot);
     uintptr_t idx = (addr>>MEMPROT_SHIFT);
     uintptr_t end = ((addr+size-1LL)>>MEMPROT_SHIFT);
-    if(end>=(1LL<<(20+16)))
-        end = (1LL<<(20+16))-1;
+    if(end>=(1LL<<(48-MEMPROT_SHIFT)))
+        end = (1LL<<(48-MEMPROT_SHIFT))-1;
     if(end<idx) // memory addresses higher than 48bits are not tracked
         return;
     pthread_mutex_lock(&mutex_prot);
@@ -965,8 +970,8 @@ void freeProtection(uintptr_t addr, size_t size)
     dynarec_log(LOG_DEBUG, "freeProtection %p:%p\n", (void*)addr, (void*)(addr+size-1));
     uintptr_t idx = (addr>>MEMPROT_SHIFT);
     uintptr_t end = ((addr+size-1LL)>>MEMPROT_SHIFT);
-    if(end>=(1LL<<(20+16)))
-        end = (1LL<<(20+16))-1;
+    if(end>=(1LL<<(48-MEMPROT_SHIFT)))
+        end = (1LL<<(48-MEMPROT_SHIFT))-1;
     if(end<idx) // memory addresses higher than 48bits are not tracked
         return;
     pthread_mutex_lock(&mutex_prot);
diff --git a/src/main.c b/src/main.c
index 9a9f1aba..d1b6e8fe 100755
--- a/src/main.c
+++ b/src/main.c
@@ -281,6 +281,11 @@ HWCAP2_ECV
     if(arm64_atomics)
         printf_log(LOG_INFO, " ATOMICS");
     printf_log(LOG_INFO, " PageSize:%d\n", box64_pagesize);
+#elif defined(LA464)
+    printf_log(LOG_INFO, "Dynarec for LoongArch");
+    printf_log(LOG_INFO, " PageSize:%d\n", box64_pagesize);
+#else
+#error Unsupported architecture
 #endif
 }
 #endif