From 685afa230291d64f350afbfdfa8fc82536d99f82 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 8 Jun 2025 14:16:45 +0200 Subject: [DYNAREC] Modified JumpTable slightly so 32bits and 48bits address space jmp can be done with only 2 and 3 memory fetch (todo: RV64 and LA64 handling of 48bits) --- src/custommem.c | 57 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 14 deletions(-) (limited to 'src/custommem.c') diff --git a/src/custommem.c b/src/custommem.c index 6e99bcdd..96e1130e 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -31,12 +31,23 @@ static mmaplist_t *mmaplist = NULL; static rbtree_t *rbt_dynmem = NULL; static uint64_t jmptbl_allocated = 0, jmptbl_allocated1 = 0, jmptbl_allocated2 = 0, jmptbl_allocated3 = 0; +#if JMPTABL_SHIFTMAX != 16 +#error Incorect value for jumptable shift max that should be 16 +#endif #ifdef JMPTABL_SHIFT4 +#if JMPTABL_SHIFT3 != 16 +#error Incorect value for jumptable shift3 that should be 16 +#endif static uint64_t jmptbl_allocated4 = 0; static uintptr_t**** box64_jmptbl4[1<>JMPTABL_START1)&JMPTABLE_MASK1; idx0 = (((uintptr_t)addr) )&JMPTABLE_MASK0; #ifdef JMPTABL_SHIFT4 - return (native_lock_storeifref(create_jmptbl(idx0, idx1, idx2, idx3, idx4), jmp, ref)==jmp)?1:0; + return (native_lock_storeifref(create_jmptbl(0, idx0, idx1, idx2, idx3, idx4), jmp, ref)==jmp)?1:0; #else - return (native_lock_storeifref(create_jmptbl(idx0, idx1, idx2, idx3), jmp, ref)==jmp)?1:0; + return (native_lock_storeifref(create_jmptbl(0, idx0, idx1, idx2, idx3), jmp, ref)==jmp)?1:0; #endif } int isJumpTableDefault64(void* addr) @@ -1491,13 +1504,19 @@ uintptr_t getJumpTable64() return (uintptr_t)box64_jmptbl3; #endif } +uintptr_t getJumpTable48() +{ + return (uintptr_t)box64_jmptbl_48; +} uintptr_t getJumpTable32() { #ifdef JMPTABL_SHIFT4 + create_jmptbl(1, 0, 0, 0, 0, 0); return (uintptr_t)box64_jmptbl4[0][0]; #else - return (uintptr_t)box64_jmptbl3[0]; + create_jmptbl(1, 0, 0, 0, 0); + return (uintptr_t)box64_jmptbl3[0][0]; #endif } @@ -1512,9 +1531,9 @@ uintptr_t getJumpTableAddress64(uintptr_t addr) idx1 = ((addr)>>JMPTABL_START1)&JMPTABLE_MASK1; idx0 = ((addr) )&JMPTABLE_MASK0; #ifdef JMPTABL_SHIFT4 - return (uintptr_t)create_jmptbl(idx0, idx1, idx2, idx3, idx4); + return (uintptr_t)create_jmptbl(0, idx0, idx1, idx2, idx3, idx4); #else - return (uintptr_t)create_jmptbl(idx0, idx1, idx2, idx3); + return (uintptr_t)create_jmptbl(0, idx0, idx1, idx2, idx3); #endif } @@ -2242,11 +2261,17 @@ void init_custommem_helper(box64context_t* ctx) #ifdef JMPTABL_SHIFT4 for(int i=0; i<(1<