From ddc7c5b78afdeff85f3f77b0e7a7b06a40e5142f Mon Sep 17 00:00:00 2001 From: OBattler Date: Fri, 27 Aug 2021 13:31:47 +0200 Subject: [PATCH] Reorganized some CPU structures a bit and fixed inappropriate behavior of some mem.c functions on 64-bit binaries (and made mem.c aware of ARM64 as well), fixes both 64-bit recompilers, closes #1215. --- src/codegen_new/codegen_allocator.c | 9 +- src/codegen_new/codegen_backend_arm.c | 4 - src/codegen_new/codegen_backend_arm64.c | 4 - src/codegen_new/codegen_backend_arm_uops.c | 4 +- src/codegen_new/codegen_backend_x86-64.c | 9 +- src/codegen_new/codegen_backend_x86-64_defs.h | 2 +- src/codegen_new/codegen_backend_x86-64_ops.c | 4 +- src/codegen_new/codegen_backend_x86-64_uops.c | 18 +-- src/codegen_new/codegen_backend_x86.c | 8 -- src/codegen_new/codegen_ops_fpu_arith.c | 4 +- src/codegen_new/codegen_ops_helpers.c | 14 +- src/codegen_new/codegen_ops_jump.c | 6 +- src/codegen_new/codegen_ops_logic.c | 24 ++-- src/codegen_new/codegen_reg.c | 131 +++++++++--------- src/codegen_new/codegen_reg.h | 6 +- src/cpu/386_common.c | 8 +- src/cpu/386_dynarec.c | 36 +++-- src/cpu/cpu.h | 27 ++-- src/mem/mem.c | 30 ++-- src/win/Makefile.mingw | 9 +- 20 files changed, 181 insertions(+), 176 deletions(-) diff --git a/src/codegen_new/codegen_allocator.c b/src/codegen_new/codegen_allocator.c index 259cd4046..f441c2c4b 100644 --- a/src/codegen_new/codegen_allocator.c +++ b/src/codegen_new/codegen_allocator.c @@ -1,6 +1,7 @@ #if defined(__linux__) || defined(__APPLE__) #include #include +#include #endif #if defined WIN32 || defined _WIN32 || defined _WIN32 #include @@ -35,6 +36,10 @@ void codegen_allocator_init() #if defined WIN32 || defined _WIN32 || defined _WIN32 mem_block_alloc = VirtualAlloc(NULL, MEM_BLOCK_NR * MEM_BLOCK_SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + /* TODO: check deployment target: older Intel-based versions of macOS don't play + nice with MAP_JIT. */ +#elif defined(__APPLE__) && defined(MAP_JIT) + mem_block_alloc = mmap(0, MEM_BLOCK_NR * MEM_BLOCK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE|MAP_JIT, 0, 0); #else mem_block_alloc = mmap(0, MEM_BLOCK_NR * MEM_BLOCK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, 0, 0); #endif @@ -115,11 +120,7 @@ void codegen_allocator_clean_blocks(struct mem_block_t *block) #if defined __ARM_EABI__ || defined _ARM_ || defined __aarch64__ || defined _M_ARM || defined _M_ARM64 while (1) { -#ifndef _MSC_VER __clear_cache(&mem_block_alloc[block->offset], &mem_block_alloc[block->offset + MEM_BLOCK_SIZE]); -#else - FlushInstructionCache(GetCurrentProcess(), &mem_block_alloc[block->offset], MEM_BLOCK_SIZE); -#endif if (block->next) block = &mem_blocks[block->next - 1]; else diff --git a/src/codegen_new/codegen_backend_arm.c b/src/codegen_new/codegen_backend_arm.c index 794a16525..f423f72d8 100644 --- a/src/codegen_new/codegen_backend_arm.c +++ b/src/codegen_new/codegen_backend_arm.c @@ -327,13 +327,9 @@ printf("block_pos=%i\n", block_pos); block_write_data = NULL; //fatal("block_pos=%i\n", block_pos); -#if !defined _MSC_VER || defined __clang__ asm("vmrs %0, fpscr\n" : "=r" (cpu_state.old_fp_control) ); -#else - cpu_state.old_fp_control = _controlfp(); -#endif if ((cpu_state.old_fp_control >> 22) & 3) fatal("VFP not in nearest rounding mode\n"); } diff --git a/src/codegen_new/codegen_backend_arm64.c b/src/codegen_new/codegen_backend_arm64.c index fab1a310d..6571a0ad3 100644 --- a/src/codegen_new/codegen_backend_arm64.c +++ b/src/codegen_new/codegen_backend_arm64.c @@ -332,13 +332,9 @@ void codegen_backend_init() codegen_allocator_clean_blocks(block->head_mem_block); -#if !defined _MSC_VER || defined __clang__ asm("mrs %0, fpcr\n" : "=r" (cpu_state.old_fp_control) ); -#else - cpu_state.old_fp_control = _controlfp(); -#endif } void codegen_set_rounding_mode(int mode) diff --git a/src/codegen_new/codegen_backend_arm_uops.c b/src/codegen_new/codegen_backend_arm_uops.c index eff83a6f8..6beab7232 100644 --- a/src/codegen_new/codegen_backend_arm_uops.c +++ b/src/codegen_new/codegen_backend_arm_uops.c @@ -913,8 +913,8 @@ static int codegen_MMX_ENTER(codeblock_t *block, uop_t *uop) *branch_ptr |= ((((uintptr_t)&block_write_data[block_pos] - (uintptr_t)branch_ptr) - 8) & 0x3fffffc) >> 2; host_arm_MOV_IMM(block, REG_TEMP, 0x01010101); - host_arm_STR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.tag[0] - (uintptr_t)&cpu_state); - host_arm_STR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.tag[4] - (uintptr_t)&cpu_state); + host_arm_STR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.tag[0] - (uintptr_t)&cpu_state); + host_arm_STR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.tag[4] - (uintptr_t)&cpu_state); host_arm_MOV_IMM(block, REG_TEMP, 0); host_arm_STR_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.TOP - (uintptr_t)&cpu_state); host_arm_STRB_IMM(block, REG_TEMP, REG_CPUSTATE, (uintptr_t)&cpu_state.ismmx - (uintptr_t)&cpu_state); diff --git a/src/codegen_new/codegen_backend_x86-64.c b/src/codegen_new/codegen_backend_x86-64.c index b9919e899..e1a188310 100644 --- a/src/codegen_new/codegen_backend_x86-64.c +++ b/src/codegen_new/codegen_backend_x86-64.c @@ -22,8 +22,6 @@ #include #endif -#include - void *codegen_mem_load_byte; void *codegen_mem_load_word; void *codegen_mem_load_long; @@ -326,7 +324,6 @@ void codegen_backend_init() host_x86_XOR32_REG_REG(block, REG_EDI, REG_EDI); host_x86_XOR32_REG_REG(block, REG_ESI, REG_ESI); #endif - /* host_x86_CALL(block, (uintptr_t)x86gpf); */ host_x86_CALL(block, (void *)x86gpf); codegen_exit_rout = &codeblock[block_current].data[block_pos]; host_x86_ADD64_REG_IMM(block, REG_RSP, 0x38); @@ -342,7 +339,11 @@ void codegen_backend_init() block_write_data = NULL; - cpu_state.trunc_fp_control = _mm_getcsr() | 0x6000; + asm( + "stmxcsr %0\n" + : "=m" (cpu_state.old_fp_control) + ); + cpu_state.trunc_fp_control = cpu_state.old_fp_control | 0x6000; } void codegen_set_rounding_mode(int mode) diff --git a/src/codegen_new/codegen_backend_x86-64_defs.h b/src/codegen_new/codegen_backend_x86-64_defs.h index a21f62902..8955773cd 100644 --- a/src/codegen_new/codegen_backend_x86-64_defs.h +++ b/src/codegen_new/codegen_backend_x86-64_defs.h @@ -44,7 +44,7 @@ #define REG_XMM6 6 #define REG_XMM7 7 -#define REG_XMM_TEMP REG_XMM7 +#define REG_XMM_TEMP REG_XMM0 #define CODEGEN_HOST_REGS 3 #define CODEGEN_HOST_FP_REGS 7 diff --git a/src/codegen_new/codegen_backend_x86-64_ops.c b/src/codegen_new/codegen_backend_x86-64_ops.c index bf3b77112..784bfa03d 100644 --- a/src/codegen_new/codegen_backend_x86-64_ops.c +++ b/src/codegen_new/codegen_backend_x86-64_ops.c @@ -32,7 +32,7 @@ static inline void call(codeblock_t *block, uintptr_t func) codegen_alloc_bytes(block, 5); diff = func - (uintptr_t)&block_write_data[block_pos + 5]; - if (diff >= -0x80000000ULL && diff < 0x7fffffffULL) + if (diff >= -0x80000000 && diff < 0x7fffffff) { codegen_addbyte(block, 0xE8); /*CALL*/ codegen_addlong(block, (uint32_t)diff); @@ -53,7 +53,7 @@ static inline void jmp(codeblock_t *block, uintptr_t func) codegen_alloc_bytes(block, 5); diff = func - (uintptr_t)&block_write_data[block_pos + 5]; - if (diff >= -0x80000000ULL && diff < 0x7fffffffULL) + if (diff >= -0x80000000 && diff < 0x7fffffff) { codegen_addbyte(block, 0xe9); /*JMP*/ codegen_addlong(block, (uint32_t)diff); diff --git a/src/codegen_new/codegen_backend_x86-64_uops.c b/src/codegen_new/codegen_backend_x86-64_uops.c index 8ac9251e5..471f982e8 100644 --- a/src/codegen_new/codegen_backend_x86-64_uops.c +++ b/src/codegen_new/codegen_backend_x86-64_uops.c @@ -199,9 +199,9 @@ static int codegen_CALL_FUNC(codeblock_t *block, uop_t *uop) static int codegen_CALL_FUNC_RESULT(codeblock_t *block, uop_t *uop) { int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); - /* int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); */ #ifdef RECOMPILER_DEBUG + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); if (!REG_IS_L(dest_size)) fatal("CALL_FUNC_RESULT %02x\n", uop->dest_reg_a_real); #endif @@ -922,9 +922,9 @@ static int codegen_LOAD_FUNC_ARG3_IMM(codeblock_t *block, uop_t *uop) static int codegen_LOAD_SEG(codeblock_t *block, uop_t *uop) { int src_reg = HOST_REG_GET(uop->src_reg_a_real); - /* int src_size = IREG_GET_SIZE(uop->src_reg_a_real); */ #ifdef RECOMPILER_DEBUG + int src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (!REG_IS_W(src_size)) fatal("LOAD_SEG %02x %p\n", uop->src_reg_a_real, uop->p); #endif @@ -1033,9 +1033,9 @@ static int codegen_MEM_LOAD_REG(codeblock_t *block, uop_t *uop) static int codegen_MEM_LOAD_SINGLE(codeblock_t *block, uop_t *uop) { int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real); - /* int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); */ #ifdef RECOMPILER_DEBUG + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); if (!REG_IS_D(dest_size)) fatal("MEM_LOAD_SINGLE - %02x\n", uop->dest_reg_a_real); #endif @@ -1052,9 +1052,9 @@ static int codegen_MEM_LOAD_SINGLE(codeblock_t *block, uop_t *uop) static int codegen_MEM_LOAD_DOUBLE(codeblock_t *block, uop_t *uop) { int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real); - /* int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); */ #ifdef RECOMPILER_DEBUG + int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); if (!REG_IS_D(dest_size)) fatal("MEM_LOAD_DOUBLE - %02x\n", uop->dest_reg_a_real); #endif @@ -1178,9 +1178,9 @@ static int codegen_MEM_STORE_REG(codeblock_t *block, uop_t *uop) static int codegen_MEM_STORE_SINGLE(codeblock_t *block, uop_t *uop) { int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real), src_reg = HOST_REG_GET(uop->src_reg_c_real); - /* int src_size = IREG_GET_SIZE(uop->src_reg_c_real); */ #ifdef RECOMPILER_DEBUG + int src_size = IREG_GET_SIZE(uop->src_reg_c_real); if (!REG_IS_D(src_size)) fatal("MEM_STORE_SINGLE - %02x\n", uop->src_reg_b_real); #endif @@ -1197,9 +1197,9 @@ static int codegen_MEM_STORE_SINGLE(codeblock_t *block, uop_t *uop) static int codegen_MEM_STORE_DOUBLE(codeblock_t *block, uop_t *uop) { int seg_reg = HOST_REG_GET(uop->src_reg_a_real), addr_reg = HOST_REG_GET(uop->src_reg_b_real), src_reg = HOST_REG_GET(uop->src_reg_c_real); - /* int src_size = IREG_GET_SIZE(uop->src_reg_c_real); */ #ifdef RECOMPILER_DEBUG + int src_size = IREG_GET_SIZE(uop->src_reg_c_real); if (!REG_IS_D(src_size)) fatal("MEM_STORE_DOUBLE - %02x\n", uop->src_reg_b_real); #endif @@ -1499,7 +1499,7 @@ static int codegen_OR(codeblock_t *block, uop_t *uop) } static int codegen_OR_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real)/*, src_reg = HOST_REG_GET(uop->src_reg_a_real)*/; + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) @@ -2770,7 +2770,7 @@ static int codegen_TEST_JS_DEST(codeblock_t *block, uop_t *uop) static int codegen_XOR(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real)/*, src_reg_a = HOST_REG_GET(uop->src_reg_a_real)*/, src_reg_b = HOST_REG_GET(uop->src_reg_b_real); + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real), src_reg_b = HOST_REG_GET(uop->src_reg_b_real); int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size_a = IREG_GET_SIZE(uop->src_reg_a_real), src_size_b = IREG_GET_SIZE(uop->src_reg_b_real); if (REG_IS_Q(dest_size) && REG_IS_Q(src_size_a) && REG_IS_Q(src_size_b) && uop->dest_reg_a_real == uop->src_reg_a_real) @@ -2797,7 +2797,7 @@ static int codegen_XOR(codeblock_t *block, uop_t *uop) } static int codegen_XOR_IMM(codeblock_t *block, uop_t *uop) { - int dest_reg = HOST_REG_GET(uop->dest_reg_a_real)/*, src_reg = HOST_REG_GET(uop->src_reg_a_real)*/; + int dest_reg = HOST_REG_GET(uop->dest_reg_a_real); int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real), src_size = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_L(dest_size) && REG_IS_L(src_size)) diff --git a/src/codegen_new/codegen_backend_x86.c b/src/codegen_new/codegen_backend_x86.c index 036e8a621..1e22caa2e 100644 --- a/src/codegen_new/codegen_backend_x86.c +++ b/src/codegen_new/codegen_backend_x86.c @@ -304,20 +304,12 @@ void codegen_backend_init() block_write_data = NULL; cpu_state.old_fp_control = 0; -#ifndef _MSC_VER asm( "fstcw %0\n" "stmxcsr %1\n" : "=m" (cpu_state.old_fp_control2), "=m" (cpu_state.old_fp_control) ); -#else - __asm - { - fstcw cpu_state.old_fp_control2 - stmxcsr cpu_state.old_fp_control - } -#endif cpu_state.trunc_fp_control = cpu_state.old_fp_control | 0x6000; } diff --git a/src/codegen_new/codegen_ops_fpu_arith.c b/src/codegen_new/codegen_ops_fpu_arith.c index 3500397e3..d4ba9aebb 100644 --- a/src/codegen_new/codegen_ops_fpu_arith.c +++ b/src/codegen_new/codegen_ops_fpu_arith.c @@ -277,8 +277,8 @@ uint32_t ropFADD ## name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint { \ x86seg *target_seg; \ \ - if ((cpu_state.npxc >> 10) & 3) \ - return 0; \ + if ((cpu_state.npxc >> 10) & 3) \ + return 0; \ uop_FP_ENTER(ir); \ uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ op_pc--; \ diff --git a/src/codegen_new/codegen_ops_helpers.c b/src/codegen_new/codegen_ops_helpers.c index a7a67ce7a..6a3e8f6d8 100644 --- a/src/codegen_new/codegen_ops_helpers.c +++ b/src/codegen_new/codegen_ops_helpers.c @@ -52,17 +52,17 @@ int codegen_can_unroll_full(codeblock_t *block, ir_data_t *ir, uint32_t next_pc, return 0; } else - { + { start = ir->wr_pos; - TOP = cpu_state.TOP; - } + TOP = cpu_state.TOP; + } } - - if (TOP != cpu_state.TOP) - return 0; + + if (TOP != cpu_state.TOP) + return 0; max_unroll = UNROLL_MAX_UOPS / ((ir->wr_pos-start)+6); - if ((max_version_refcount != 0) && (max_unroll > (UNROLL_MAX_REG_REFERENCES / max_version_refcount))) + if (max_unroll > (UNROLL_MAX_REG_REFERENCES / max_version_refcount)) max_unroll = (UNROLL_MAX_REG_REFERENCES / max_version_refcount); if (max_unroll > UNROLL_MAX_COUNT) max_unroll = UNROLL_MAX_COUNT; diff --git a/src/codegen_new/codegen_ops_jump.c b/src/codegen_new/codegen_ops_jump.c index f56018d76..f7a5145a0 100644 --- a/src/codegen_new/codegen_ops_jump.c +++ b/src/codegen_new/codegen_ops_jump.c @@ -13,7 +13,7 @@ uint32_t ropJMP_r8(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) { - int32_t offset = (int32_t)(int8_t)fastreadb(cs + op_pc); + uint32_t offset = (int32_t)(int8_t)fastreadb(cs + op_pc); uint32_t dest_addr = op_pc+1+offset; if (!(op_32 & 0x100)) @@ -26,7 +26,7 @@ uint32_t ropJMP_r8(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t f } uint32_t ropJMP_r16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) { - int32_t offset = (int32_t)(int16_t)fastreadw(cs + op_pc); + uint32_t offset = (int32_t)(int16_t)fastreadw(cs + op_pc); uint32_t dest_addr = op_pc+2+offset; dest_addr &= 0xffff; @@ -38,7 +38,7 @@ uint32_t ropJMP_r16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t } uint32_t ropJMP_r32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) { - int32_t offset = fastreadl(cs + op_pc); + uint32_t offset = fastreadl(cs + op_pc); uint32_t dest_addr = op_pc+4+offset; if (offset < 0) diff --git a/src/codegen_new/codegen_ops_logic.c b/src/codegen_new/codegen_ops_logic.c index 2b1ee8379..5d50423c1 100644 --- a/src/codegen_new/codegen_ops_logic.c +++ b/src/codegen_new/codegen_ops_logic.c @@ -65,7 +65,7 @@ uint32_t ropAND_b_rm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t { int src_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_AND(ir, IREG_8(dest_reg), IREG_8(dest_reg), IREG_8(src_reg)); + uop_AND(ir, IREG_8(dest_reg), IREG_8(dest_reg), IREG_8(src_reg)); } else { @@ -93,7 +93,7 @@ uint32_t ropAND_b_rmw(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_ { int dest_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_AND(ir, IREG_8(dest_reg), IREG_8(dest_reg), IREG_8(src_reg)); + uop_AND(ir, IREG_8(dest_reg), IREG_8(dest_reg), IREG_8(src_reg)); uop_MOVZX(ir, IREG_flags_res, IREG_8(dest_reg)); } else @@ -124,7 +124,7 @@ uint32_t ropAND_w_rm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t { int src_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_AND(ir, IREG_16(dest_reg), IREG_16(dest_reg), IREG_16(src_reg)); + uop_AND(ir, IREG_16(dest_reg), IREG_16(dest_reg), IREG_16(src_reg)); } else { @@ -152,7 +152,7 @@ uint32_t ropAND_w_rmw(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_ { int dest_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_AND(ir, IREG_16(dest_reg), IREG_16(dest_reg), IREG_16(src_reg)); + uop_AND(ir, IREG_16(dest_reg), IREG_16(dest_reg), IREG_16(src_reg)); uop_MOVZX(ir, IREG_flags_res, IREG_16(dest_reg)); } else @@ -183,7 +183,7 @@ uint32_t ropAND_l_rm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t { int src_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_AND(ir, IREG_32(dest_reg), IREG_32(dest_reg), IREG_32(src_reg)); + uop_AND(ir, IREG_32(dest_reg), IREG_32(dest_reg), IREG_32(src_reg)); } else { @@ -211,7 +211,7 @@ uint32_t ropAND_l_rmw(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_ { int dest_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_AND(ir, IREG_32(dest_reg), IREG_32(dest_reg), IREG_32(src_reg)); + uop_AND(ir, IREG_32(dest_reg), IREG_32(dest_reg), IREG_32(src_reg)); uop_MOV(ir, IREG_flags_res, IREG_32(dest_reg)); } else @@ -288,7 +288,7 @@ uint32_t ropOR_b_rm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t { int src_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_OR(ir, IREG_8(dest_reg), IREG_8(dest_reg), IREG_8(src_reg)); + uop_OR(ir, IREG_8(dest_reg), IREG_8(dest_reg), IREG_8(src_reg)); } else { @@ -316,7 +316,7 @@ uint32_t ropOR_b_rmw(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t { int dest_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_OR(ir, IREG_8(dest_reg), IREG_8(dest_reg), IREG_8(src_reg)); + uop_OR(ir, IREG_8(dest_reg), IREG_8(dest_reg), IREG_8(src_reg)); uop_MOVZX(ir, IREG_flags_res, IREG_8(dest_reg)); } else @@ -347,7 +347,7 @@ uint32_t ropOR_w_rm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t { int src_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_OR(ir, IREG_16(dest_reg), IREG_16(dest_reg), IREG_16(src_reg)); + uop_OR(ir, IREG_16(dest_reg), IREG_16(dest_reg), IREG_16(src_reg)); } else { @@ -375,7 +375,7 @@ uint32_t ropOR_w_rmw(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t { int dest_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_OR(ir, IREG_16(dest_reg), IREG_16(dest_reg), IREG_16(src_reg)); + uop_OR(ir, IREG_16(dest_reg), IREG_16(dest_reg), IREG_16(src_reg)); uop_MOVZX(ir, IREG_flags_res, IREG_16(dest_reg)); } else @@ -406,7 +406,7 @@ uint32_t ropOR_l_rm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t { int src_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_OR(ir, IREG_32(dest_reg), IREG_32(dest_reg), IREG_32(src_reg)); + uop_OR(ir, IREG_32(dest_reg), IREG_32(dest_reg), IREG_32(src_reg)); } else { @@ -434,7 +434,7 @@ uint32_t ropOR_l_rmw(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t { int dest_reg = fetchdat & 7; - if(src_reg != dest_reg) uop_OR(ir, IREG_32(dest_reg), IREG_32(dest_reg), IREG_32(src_reg)); + uop_OR(ir, IREG_32(dest_reg), IREG_32(dest_reg), IREG_32(src_reg)); uop_MOV(ir, IREG_flags_res, IREG_32(dest_reg)); } else diff --git a/src/codegen_new/codegen_reg.c b/src/codegen_new/codegen_reg.c index 4a866ae8b..04fd88ce8 100644 --- a/src/codegen_new/codegen_reg.c +++ b/src/codegen_new/codegen_reg.c @@ -278,93 +278,94 @@ static void codegen_reg_load(host_reg_set_t *reg_set, codeblock_t *block, int c, { case REG_WORD: #ifndef RELEASE_BUILD - if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) - fatal("codegen_reg_load - REG_WORD !REG_INTEGER\n"); + if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) + fatal("codegen_reg_load - REG_WORD !REG_INTEGER\n"); #endif - if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) - codegen_direct_read_16_stack(block, reg_set->reg_list[c].reg, (int)(uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); - else + if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) + codegen_direct_read_16_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); + else codegen_direct_read_16(block, reg_set->reg_list[c].reg, ireg_data[IREG_GET_REG(ir_reg.reg)].p); - break; - - case REG_DWORD: + break; + + case REG_DWORD: #ifndef RELEASE_BUILD - if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) - fatal("codegen_reg_load - REG_DWORD !REG_INTEGER\n"); + if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) + fatal("codegen_reg_load - REG_DWORD !REG_INTEGER\n"); #endif - if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) - codegen_direct_read_32_stack(block, reg_set->reg_list[c].reg, (int)(uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); - else + if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) + codegen_direct_read_32_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); + else codegen_direct_read_32(block, reg_set->reg_list[c].reg, ireg_data[IREG_GET_REG(ir_reg.reg)].p); - break; - - case REG_QWORD: + break; + + case REG_QWORD: #ifndef RELEASE_BUILD - if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) - fatal("codegen_reg_load - REG_QWORD !REG_FP\n"); + if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) + fatal("codegen_reg_load - REG_QWORD !REG_FP\n"); #endif - if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) - codegen_direct_read_64_stack(block, reg_set->reg_list[c].reg, (int)(uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); - else + if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) + codegen_direct_read_64_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); + else codegen_direct_read_64(block, reg_set->reg_list[c].reg, ireg_data[IREG_GET_REG(ir_reg.reg)].p); - break; - - case REG_POINTER: + break; + + case REG_POINTER: #ifndef RELEASE_BUILD - if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) - fatal("codegen_reg_load - REG_POINTER !REG_INTEGER\n"); + if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) + fatal("codegen_reg_load - REG_POINTER !REG_INTEGER\n"); #endif - if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) - codegen_direct_read_pointer_stack(block, reg_set->reg_list[c].reg, (int)(uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); - else + if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) + codegen_direct_read_pointer_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); + else codegen_direct_read_pointer(block, reg_set->reg_list[c].reg, ireg_data[IREG_GET_REG(ir_reg.reg)].p); - break; - - case REG_DOUBLE: + break; + + case REG_DOUBLE: #ifndef RELEASE_BUILD - if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) - fatal("codegen_reg_load - REG_DOUBLE !REG_FP\n"); + if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) + fatal("codegen_reg_load - REG_DOUBLE !REG_FP\n"); #endif - if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) - codegen_direct_read_double_stack(block, reg_set->reg_list[c].reg, (int)(uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); - else + if ((uintptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p < 256) + codegen_direct_read_double_stack(block, reg_set->reg_list[c].reg, (intptr_t)ireg_data[IREG_GET_REG(ir_reg.reg)].p); + else codegen_direct_read_double(block, reg_set->reg_list[c].reg, ireg_data[IREG_GET_REG(ir_reg.reg)].p); - break; - - case REG_FPU_ST_BYTE: + break; + + case REG_FPU_ST_BYTE: #ifndef RELEASE_BUILD - if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) - fatal("codegen_reg_load - REG_FPU_ST_BYTE !REG_INTEGER\n"); + if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_INTEGER) + fatal("codegen_reg_load - REG_FPU_ST_BYTE !REG_INTEGER\n"); #endif - if (block->flags & CODEBLOCK_STATIC_TOP) + if (block->flags & CODEBLOCK_STATIC_TOP) codegen_direct_read_8(block, reg_set->reg_list[c].reg, &cpu_state.tag[ir_reg.reg & 7]); - else + else codegen_direct_read_st_8(block, reg_set->reg_list[c].reg, &cpu_state.tag[0], ir_reg.reg & 7); - break; - - case REG_FPU_ST_QWORD: + break; + + case REG_FPU_ST_QWORD: #ifndef RELEASE_BUILD - if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) - fatal("codegen_reg_load - REG_FPU_ST_QWORD !REG_FP\n"); + if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) + fatal("codegen_reg_load - REG_FPU_ST_QWORD !REG_FP\n"); #endif - if (block->flags & CODEBLOCK_STATIC_TOP) + if (block->flags & CODEBLOCK_STATIC_TOP) codegen_direct_read_64(block, reg_set->reg_list[c].reg, &cpu_state.MM[ir_reg.reg & 7]); - else + else codegen_direct_read_st_64(block, reg_set->reg_list[c].reg, &cpu_state.MM[0], ir_reg.reg & 7); - break; - - case REG_FPU_ST_DOUBLE: + break; + + case REG_FPU_ST_DOUBLE: #ifndef RELEASE_BUILD - if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) - fatal("codegen_reg_load - REG_FPU_ST_DOUBLE !REG_FP\n"); + if (ireg_data[IREG_GET_REG(ir_reg.reg)].type != REG_FP) + fatal("codegen_reg_load - REG_FPU_ST_DOUBLE !REG_FP\n"); #endif - if (block->flags & CODEBLOCK_STATIC_TOP) + if (block->flags & CODEBLOCK_STATIC_TOP) codegen_direct_read_double(block, reg_set->reg_list[c].reg, &cpu_state.ST[ir_reg.reg & 7]); - else + else codegen_direct_read_st_double(block, reg_set->reg_list[c].reg, &cpu_state.ST[0], ir_reg.reg & 7); - break; - - default: fatal("codegen_reg_load - native_size=%i reg=%i\n", ireg_data[IREG_GET_REG(ir_reg.reg)].native_size, IREG_GET_REG(ir_reg.reg)); + break; + + default: + fatal("codegen_reg_load - native_size=%i reg=%i\n", ireg_data[IREG_GET_REG(ir_reg.reg)].native_size, IREG_GET_REG(ir_reg.reg)); } reg_set->regs[c] = ir_reg; @@ -407,7 +408,7 @@ static void codegen_reg_writeback(host_reg_set_t *reg_set, codeblock_t *block, i fatal("codegen_reg_writeback - REG_DWORD !REG_INTEGER\n"); #endif if ((uintptr_t)p < 256) - codegen_direct_write_32_stack(block, (int)(uintptr_t)p, reg_set->reg_list[c].reg); + codegen_direct_write_32_stack(block, (intptr_t)p, reg_set->reg_list[c].reg); else codegen_direct_write_32(block, p, reg_set->reg_list[c].reg); break; @@ -418,7 +419,7 @@ static void codegen_reg_writeback(host_reg_set_t *reg_set, codeblock_t *block, i fatal("codegen_reg_writeback - REG_QWORD !REG_FP\n"); #endif if ((uintptr_t)p < 256) - codegen_direct_write_64_stack(block, (int)(uintptr_t)p, reg_set->reg_list[c].reg); + codegen_direct_write_64_stack(block, (intptr_t)p, reg_set->reg_list[c].reg); else codegen_direct_write_64(block, p, reg_set->reg_list[c].reg); break; @@ -439,7 +440,7 @@ static void codegen_reg_writeback(host_reg_set_t *reg_set, codeblock_t *block, i fatal("codegen_reg_writeback - REG_DOUBLE !REG_FP\n"); #endif if ((uintptr_t)p < 256) - codegen_direct_write_double_stack(block, (int)(uintptr_t)p, reg_set->reg_list[c].reg); + codegen_direct_write_double_stack(block, (intptr_t)p, reg_set->reg_list[c].reg); else codegen_direct_write_double(block, p, reg_set->reg_list[c].reg); break; @@ -512,7 +513,7 @@ void codegen_reg_write_imm(codeblock_t *block, ir_reg_t ir_reg, uint32_t imm_dat case REG_DWORD: if ((uintptr_t)p < 256) - codegen_direct_write_32_imm_stack(block, (int)(intptr_t)p, imm_data); + codegen_direct_write_32_imm_stack(block, (int)p, imm_data); else codegen_direct_write_32_imm(block, p, imm_data); break; diff --git a/src/codegen_new/codegen_reg.h b/src/codegen_new/codegen_reg.h index 32ce54b3b..8bb84e5f9 100644 --- a/src/codegen_new/codegen_reg.h +++ b/src/codegen_new/codegen_reg.h @@ -339,10 +339,11 @@ static inline ir_reg_t codegen_reg_read(int reg) fatal("codegen_reg_read - refcount overflow\n"); else #endif - if (version->refcount > REG_REFCOUNT_MAX) + if (version->refcount > REG_REFCOUNT_MAX) CPU_BLOCK_END(); if (version->refcount > max_version_refcount) max_version_refcount = version->refcount; +// pclog("codegen_reg_read: %i %i %i\n", reg & IREG_REG_MASK, ireg.version, reg_version_refcount[IREG_GET_REG(ireg.reg)][ireg.version]); return ireg; } @@ -374,7 +375,7 @@ static inline ir_reg_t codegen_reg_write(int reg, int uop_nr) fatal("codegen_reg_write - version overflow\n"); else #endif - if (reg_last_version[IREG_GET_REG(reg)] > REG_VERSION_MAX) + if (reg_last_version[IREG_GET_REG(reg)] > REG_VERSION_MAX) CPU_BLOCK_END(); if (reg_last_version[IREG_GET_REG(reg)] > max_version_refcount) max_version_refcount = reg_last_version[IREG_GET_REG(reg)]; @@ -383,6 +384,7 @@ static inline ir_reg_t codegen_reg_write(int reg, int uop_nr) version->refcount = 0; version->flags = 0; version->parent_uop = uop_nr; +// pclog("codegen_reg_write: %i\n", reg & IREG_REG_MASK); return ireg; } diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index 1c5fa8b3e..467ea01eb 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -65,9 +65,8 @@ uint32_t old_rammask = 0xffffffff; int soft_reset_mask = 0; -int in_smm = 0, smi_line = 0, smi_latched = 0, smm_in_hlt = 0; -int smi_block = 0; -uint32_t smbase = 0x30000; +int smi_latched = 0; +int smm_in_hlt = 0, smi_block = 0; uint32_t addr64, addr64_2; uint32_t addr64a[8], addr64a_2[8]; @@ -1845,7 +1844,6 @@ sysret(uint32_t fetchdat) /* This is for compatibility with new x87 code. */ void codegen_set_rounding_mode(int mode) { - /* cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00) | (cpu_state.npxc & 0xc00); */ - cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00) | (mode << 10); + /* cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00) | (mode << 10); */ } #endif diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index ab1572c85..a15e7a291 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -391,10 +391,10 @@ exec386_dynarec_dyn(void) codeblock_t *block = codeblock_hash[hash]; #endif int valid_block = 0; + #ifdef USE_NEW_DYNAREC if (!cpu_state.abrt) #else - if (block && !cpu_state.abrt) #endif { @@ -535,6 +535,9 @@ exec386_dynarec_dyn(void) cpu_block_end = 0; x86_was_reset = 0; +#if defined(__APPLE__) && defined(__aarch64__) + pthread_jit_write_protect_np(0); +#endif codegen_block_start_recompile(block); codegen_in_recompile = 1; @@ -585,21 +588,21 @@ exec386_dynarec_dyn(void) #endif CPU_BLOCK_END(); + if (cpu_state.flags & T_FLAG) + CPU_BLOCK_END(); + if (smi_line) + CPU_BLOCK_END(); + if (nmi && nmi_enable && nmi_mask) + CPU_BLOCK_END(); + if ((cpu_state.flags & I_FLAG) && pic.int_pending && !cpu_end_block_after_ins) + CPU_BLOCK_END(); + if (cpu_end_block_after_ins) { cpu_end_block_after_ins--; if (!cpu_end_block_after_ins) CPU_BLOCK_END(); } - if (smi_line) - CPU_BLOCK_END(); - else if (cpu_state.flags & T_FLAG) - CPU_BLOCK_END(); - else if (nmi && nmi_enable && nmi_mask) - CPU_BLOCK_END(); - else if ((cpu_state.flags & I_FLAG) && pic.int_pending && !cpu_end_block_after_ins) - CPU_BLOCK_END(); - if (cpu_state.abrt) { if (!(cpu_state.abrt & ABRT_EXPECTED)) codegen_block_remove(); @@ -616,6 +619,9 @@ exec386_dynarec_dyn(void) codegen_reset(); codegen_in_recompile = 0; +#if defined(__APPLE__) && defined(__aarch64__) + pthread_jit_write_protect_np(1); +#endif } else if (!cpu_state.abrt) { /* Mark block but do not recompile */ #ifdef USE_NEW_DYNAREC @@ -642,8 +648,8 @@ exec386_dynarec_dyn(void) cpu_state.ssegs = 0; codegen_endpc = (cs + cpu_state.pc) + 8; - fetchdat = fastreadl(cs + cpu_state.pc); + #ifdef ENABLE_386_DYNAREC_LOG if (in_smm) x386_dynarec_log("[%04X:%08X] fetchdat = %08X\n", CS, cpu_state.pc, fetchdat); @@ -677,13 +683,13 @@ exec386_dynarec_dyn(void) #endif CPU_BLOCK_END(); + if (cpu_state.flags & T_FLAG) + CPU_BLOCK_END(); if (smi_line) CPU_BLOCK_END(); - else if (cpu_state.flags & T_FLAG) + if (nmi && nmi_enable && nmi_mask) CPU_BLOCK_END(); - else if (nmi && nmi_enable && nmi_mask) - CPU_BLOCK_END(); - else if ((cpu_state.flags & I_FLAG) && pic.int_pending && !cpu_end_block_after_ins) + if ((cpu_state.flags & I_FLAG) && pic.int_pending && !cpu_end_block_after_ins) CPU_BLOCK_END(); if (cpu_end_block_after_ins) { diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index a688b47d7..83664828c 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -210,11 +210,12 @@ typedef union { } x86reg; typedef struct { + uint32_t base; + uint32_t limit; uint8_t access, ar_high; - int8_t checked; /*Non-zero if selector is known to be valid*/ uint16_t seg; - uint32_t base, limit, - limit_low, limit_high; + uint32_t limit_low, limit_high; + int checked; /*Non-zero if selector is known to be valid*/ } x86seg; typedef union { @@ -352,9 +353,9 @@ typedef struct { } rm_data; uint8_t ssegs, ismmx, - abrt, pad; + abrt, _smi_line; - int _cycles; + int _cycles, _in_smm; uint16_t npxs, npxc; @@ -364,8 +365,6 @@ typedef struct { MMX_REG MM[8]; - uint16_t old_npxc, new_npxc; - #ifdef USE_NEW_DYNAREC uint32_t old_fp_control, new_fp_control; #if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 @@ -374,6 +373,8 @@ typedef struct { #if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 || defined __amd64__ || defined _M_X64 uint32_t trunc_fp_control; #endif +#else + uint16_t old_npxc, new_npxc; #endif x86seg seg_cs, seg_ds, seg_es, seg_ss, @@ -385,8 +386,17 @@ typedef struct { } CR0; uint16_t flags, eflags; + + uint32_t _smbase; } cpu_state_t; + +#define in_smm cpu_state._in_smm +#define smi_line cpu_state._smi_line + +#define smbase cpu_state._smbase + + /*The cpu_state.flags below must match in both cpu_cur_status and block->status for a block to be valid*/ #define CPU_STATUS_USE32 (1 << 0) @@ -495,9 +505,8 @@ extern int hasfpu; extern uint32_t cpu_features; -extern int in_smm, smi_line, smi_latched, smm_in_hlt; +extern int smi_latched, smm_in_hlt; extern int smi_block; -extern uint32_t smbase; #ifdef USE_NEW_DYNAREC extern uint16_t cpu_cur_status; diff --git a/src/mem/mem.c b/src/mem/mem.c index cac528a59..4a3a9145f 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -244,10 +244,15 @@ mem_flush_write_page(uint32_t addr, uint32_t virt) { page_t *page_target = &pages[addr >> 12]; int c; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) uint32_t a; +#endif for (c = 0; c < 256; c++) { if (writelookup[c] != (int) 0xffffffff) { +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + uintptr_t target = (uintptr_t)&ram[(uintptr_t)(addr & ~0xfff) - (virt & ~0xfff)]; +#else a = (uintptr_t)(addr & ~0xfff) - (virt & ~0xfff); uintptr_t target; @@ -255,6 +260,7 @@ mem_flush_write_page(uint32_t addr, uint32_t virt) target = (uintptr_t)&ram2[a - (1 << 30)]; else target = (uintptr_t)&ram[a]; +#endif if (writelookup2[writelookup[c]] == target || page_lookup[writelookup[c]] == page_target) { writelookup2[writelookup[c]] = LOOKUP_INV; @@ -556,9 +562,7 @@ mem_addr_translate(uint32_t addr, uint32_t chunk_start, uint32_t len) void addreadlookup(uint32_t virt, uint32_t phys) { -#if (defined __amd64__ || defined _M_X64) - uint64_t a; -#else +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) uint32_t a; #endif @@ -572,16 +576,16 @@ addreadlookup(uint32_t virt, uint32_t phys) readlookup2[readlookup[readlnext]] = LOOKUP_INV; } -#if (defined __amd64__ || defined _M_X64) - a = ((uint64_t)(phys & ~0xfff) - (uint64_t)(virt & ~0xfff)); +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + readlookup2[virt>>12] = (uintptr_t)&ram[(uintptr_t)(phys & ~0xFFF) - (uintptr_t)(virt & ~0xfff)]; #else a = ((uint32_t)(phys & ~0xfff) - (uint32_t)(virt & ~0xfff)); -#endif if ((phys & ~0xfff) >= (1 << 30)) readlookup2[virt>>12] = (uintptr_t)&ram2[a - (1 << 30)]; else readlookup2[virt>>12] = (uintptr_t)&ram[a]; +#endif readlookupp[virt>>12] = mmu_perm; readlookup[readlnext++] = virt >> 12; @@ -594,9 +598,7 @@ addreadlookup(uint32_t virt, uint32_t phys) void addwritelookup(uint32_t virt, uint32_t phys) { -#if (defined __amd64__ || defined _M_X64) - uint64_t a; -#else +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) uint32_t a; #endif @@ -625,16 +627,16 @@ addwritelookup(uint32_t virt, uint32_t phys) page_lookup[virt >> 12] = &pages[phys >> 12]; page_lookupp[virt >> 12] = mmu_perm; } else { -#if (defined __amd64__ || defined _M_X64) - a = ((uint64_t)(phys & ~0xfff) - (uint64_t)(virt & ~0xfff)); +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) + writelookup2[virt>>12] = (uintptr_t)&ram[(uintptr_t)(phys & ~0xFFF) - (uintptr_t)(virt & ~0xfff)]; #else a = ((uint32_t)(phys & ~0xfff) - (uint32_t)(virt & ~0xfff)); -#endif if ((phys & ~0xfff) >= (1 << 30)) writelookup2[virt>>12] = (uintptr_t)&ram2[a - (1 << 30)]; else writelookup2[virt>>12] = (uintptr_t)&ram[a]; +#endif } writelookupp[virt>>12] = mmu_perm; @@ -2607,7 +2609,7 @@ mem_reset(void) free(ram); ram = NULL; } -#if (!(defined __amd64__ || defined _M_X64)) +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) if (ram2 != NULL) { free(ram2); ram2 = NULL; @@ -2619,7 +2621,7 @@ mem_reset(void) m = 1024UL * mem_size; -#if (!(defined __amd64__ || defined _M_X64)) +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) if (mem_size > 1048576) { ram = (uint8_t *)malloc(1 << 30); /* allocate and clear the RAM block of the first 1 GB */ if (ram == NULL) { diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 39078ae7a..b6e7fe4b0 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -605,10 +605,11 @@ MAINOBJ := 86box.o config.o random.o timer.o io.o acpi.o apm.o dma.o ddma.o \ MEMOBJ := catalyst_flash.o i2c_eeprom.o intel_flash.o mem.o rom.o smram.o spd.o sst_flash.o -CPUOBJ := cpu.o cpu_table.o fpu.o x86.o \ - 808x.o 386.o 386_common.o 386_dynarec.o 386_dynarec_ops.o $(CGTOBJ) \ - x86seg.o x87.o x87_timings.o \ - $(DYNARECOBJ) +CPUOBJ := $(DYNARECOBJ) \ + $(CGTOBJ) \ + cpu.o cpu_table.o fpu.o x86.o \ + 808x.o 386.o 386_common.o 386_dynarec.o 386_dynarec_ops.o \ + x86seg.o x87.o x87_timings.o CHIPSETOBJ := acc2168.o cs8230.o ali1217.o ali1429.o ali1489.o et6000.o headland.o intel_82335.o cs4031.o \ intel_420ex.o intel_4x0.o intel_sio.o intel_piix.o ioapic.o \