From aa3a52da3cb7349d15d0595d0fc5d67ba1f6bf25 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 26 Aug 2021 13:53:13 +0200 Subject: [PATCH] Reordered some CPU variables and rewrote codegen emitted by the old recompiler's 64-bit version of codegen_accumulate_flush() to not assume 32-bit pointers, fixes 64-bit old recompiler, closes #1615. --- src/codegen/codegen_accumulate_x86-64.c | 13 +++++++++---- src/cpu/cpu.c | 5 +++-- src/cpu/cpu.h | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/codegen/codegen_accumulate_x86-64.c b/src/codegen/codegen_accumulate_x86-64.c index 8e2722b3e..05a728ae5 100644 --- a/src/codegen/codegen_accumulate_x86-64.c +++ b/src/codegen/codegen_accumulate_x86-64.c @@ -48,11 +48,16 @@ void codegen_accumulate(int acc_reg, int delta) void codegen_accumulate_flush(void) { if (acc_regs[0].count) { - addbyte(0x81); /*ADD $acc_regs[0].count,acc_regs[0].dest*/ - addbyte(0x04); - addbyte(0x25); - addlong((uint32_t) acc_regs[0].dest_reg); + addbyte(0x55); /*push rbp*/ + addbyte(0x48); /*mov rbp,val*/ + addbyte(0xbd); + addlong((uint32_t) (acc_regs[0].dest_reg & 0xffffffffULL)); + addlong((uint32_t) (acc_regs[0].dest_reg >> 32ULL)); + addbyte(0x81); /* add d,[rbp][0],val */ + addbyte(0x45); + addbyte(0x00); addlong(acc_regs[0].count); + addbyte(0x5d); /*pop rbp*/ } acc_regs[0].count = 0; diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index e29bca7d5..1664576fb 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -69,6 +69,9 @@ enum { #define CPUID_3DNOW (1UL << 31UL) +/* Make sure this is as low as possible. */ +cpu_state_t cpu_state; + #ifdef USE_DYNAREC const OpFn *x86_dynarec_opcodes, *x86_dynarec_opcodes_0f, *x86_dynarec_opcodes_d8_a16, *x86_dynarec_opcodes_d8_a32, @@ -128,8 +131,6 @@ double cpu_dmulti; msr_t msr; -cpu_state_t cpu_state; - cyrix_t cyrix; cpu_family_t *cpu_f; diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index e4bf676bb..a688b47d7 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -461,6 +461,8 @@ COMPILE_TIME_ASSERT(sizeof(cpu_state_t) <= 128) /* Global variables. */ +extern cpu_state_t cpu_state; + extern const cpu_family_t cpu_families[]; extern const cpu_legacy_machine_t cpu_legacy_table[]; extern cpu_family_t *cpu_f; @@ -505,7 +507,6 @@ extern uint32_t cpu_cur_status; extern uint64_t cpu_CR4_mask; extern uint64_t tsc; extern msr_t msr; -extern cpu_state_t cpu_state; extern uint8_t opcode; extern int cgate16; extern int cpl_override;