From 4919f161cc7a0cfa31f91b0d1e2d0ff600044ff6 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 14 Mar 2021 17:58:04 +0100 Subject: [DYNAREC] Added Basic blocks for dynarec --- src/include/box64context.h | 2 ++ src/include/custommem.h | 8 ++++---- src/include/debug.h | 7 +++++++ src/include/dynablock.h | 31 +++++++++++++++++++++++++++++++ src/include/dynarec_arm64.h | 9 +++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100755 src/include/dynablock.h create mode 100755 src/include/dynarec_arm64.h (limited to 'src/include') diff --git a/src/include/box64context.h b/src/include/box64context.h index 6e4d9052..c52ac53b 100755 --- a/src/include/box64context.h +++ b/src/include/box64context.h @@ -27,6 +27,8 @@ typedef struct dynablocklist_s dynablocklist_t; typedef struct mmaplist_s mmaplist_t; typedef struct kh_dynablocks_s kh_dynablocks_t; #endif +#define DYNAMAP_SHIFT 16 +#define JMPTABL_SHIFT 16 typedef void* (*procaddess_t)(const char* name); typedef void* (*vkprocaddess_t)(void* instance, const char* name); diff --git a/src/include/custommem.h b/src/include/custommem.h index a018fd37..d5e8a09a 100644 --- a/src/include/custommem.h +++ b/src/include/custommem.h @@ -27,10 +27,10 @@ void addDBFromAddressRange(uintptr_t addr, uintptr_t size); void cleanDBFromAddressRange(uintptr_t addr, uintptr_t size, int destroy); dynablocklist_t* getDB(uintptr_t idx); -void addJumpTableIfDefault(void* addr, void* jmp); -void setJumpTableDefault(void* addr); -uintptr_t getJumpTable(); -uintptr_t getJumpTableAddress(uintptr_t addr); +void addJumpTableIfDefault64(void* addr, void* jmp); +void setJumpTableDefault64(void* addr); +uintptr_t getJumpTable64(); +uintptr_t getJumpTableAddress64(uintptr_t addr); #endif #define PROT_DYNAREC 0x80 diff --git a/src/include/debug.h b/src/include/debug.h index 873db669..61071b48 100755 --- a/src/include/debug.h +++ b/src/include/debug.h @@ -7,6 +7,13 @@ extern int box64_log; // log level extern int box64_dynarec_log; extern int box64_dynarec; extern int box64_pagesize; +#ifdef DYNAREC +extern int box64_dynarec_dump; +extern int box64_dynarec_trace; +extern int box64_dynarec_forced; +extern int box64_dynarec_largest; +extern uintptr_t box64_nodynarec_start, box64_nodynarec_end; +#endif extern int dlsym_error; // log dlsym error extern int trace_xmm; // include XMM reg in trace? extern int trace_emm; // include EMM reg in trace? diff --git a/src/include/dynablock.h b/src/include/dynablock.h new file mode 100755 index 00000000..76f1e5e0 --- /dev/null +++ b/src/include/dynablock.h @@ -0,0 +1,31 @@ +#ifndef __DYNABLOCK_H_ +#define __DYNABLOCK_H_ + +typedef struct x64emu_s x64emu_t; +typedef struct dynablock_s dynablock_t; +typedef struct dynablocklist_s dynablocklist_t; +typedef struct kh_dynablocks_s kh_dynablocks_t; + +uint32_t X31_hash_code(void* addr, int len); +dynablocklist_t* NewDynablockList(uintptr_t text, int textsz, int direct); +void FreeDynablockList(dynablocklist_t** dynablocks); +void FreeDynablock(dynablock_t* db); +void MarkDynablock(dynablock_t* db); +void FreeRangeDynablock(dynablocklist_t* dynablocks, uintptr_t addr, uintptr_t size); +void MarkRangeDynablock(dynablocklist_t* dynablocks, uintptr_t addr, uintptr_t size); + +dynablock_t* FindDynablockFromNativeAddress(void* addr); // defined in box64context.h +dynablock_t* FindDynablockDynablocklist(void* addr, kh_dynablocks_t* dynablocks); + +uintptr_t StartDynablockList(dynablocklist_t* db); +uintptr_t EndDynablockList(dynablocklist_t* db); +void MarkDirectDynablock(dynablocklist_t* dynablocks, uintptr_t addr, uintptr_t size); + +// Handling of Dynarec block (i.e. an exectable chunk of x64 translated code) +dynablock_t* DBGetBlock(x64emu_t* emu, uintptr_t addr, int create, dynablock_t** current); // return NULL if block is not found / cannot be created. Don't create if create==0 +dynablock_t* DBAlternateBlock(x64emu_t* emu, uintptr_t addr, uintptr_t filladdr); + +// Create and Add an new dynablock in the list, handling direct/map +dynablock_t *AddNewDynablock(dynablocklist_t* dynablocks, uintptr_t addr, int* created); + +#endif //__DYNABLOCK_H_ \ No newline at end of file diff --git a/src/include/dynarec_arm64.h b/src/include/dynarec_arm64.h new file mode 100755 index 00000000..1225153d --- /dev/null +++ b/src/include/dynarec_arm64.h @@ -0,0 +1,9 @@ +#ifndef __DYNAREC_ARM_H_ +#define __DYNAREC_ARM_H_ + +typedef struct dynablock_s dynablock_t; +typedef struct x64emu_s x64emu_t; + +void* FillBlock64(dynablock_t* block, uintptr_t addr); + +#endif //__DYNAREC_ARM_H_ \ No newline at end of file -- cgit 1.4.1