From 47604db6b16c6b2ccec7ebd13d2a98d6f1709a4c Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 27 Oct 2022 03:24:02 +0200 Subject: [PATCH] Changed GPF handled on the 64-bit old recompiler. --- src/codegen/codegen_x86-64.c | 15 +++++++++------ src/codegen/codegen_x86-64.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/codegen/codegen_x86-64.c b/src/codegen/codegen_x86-64.c index 0559cc06d..4289235fe 100644 --- a/src/codegen/codegen_x86-64.c +++ b/src/codegen/codegen_x86-64.c @@ -267,6 +267,7 @@ void codegen_block_init(uint32_t phys_addr) void codegen_block_start_recompile(codeblock_t *block) { page_t *page = &pages[block->phys >> 12]; + uintptr_t rip_rel; if (!page->block[(block->phys >> 10) & 3]) mem_flush_write_page(block->phys, cs+cpu_state.pc); @@ -298,15 +299,17 @@ void codegen_block_start_recompile(codeblock_t *block) while (block_pos < BLOCK_EXIT_OFFSET) addbyte(0x90); /*NOP*/ #else - addbyte(0xc6); /* mov byte ptr[&(cpu_state.abrt)],ABRT_GPF */ - addbyte(0x05); - addlong((uint32_t) (uintptr_t) &(cpu_state.abrt)); + addbyte(0xC6); /*MOVB ABRT_GPF,(abrt)*/ + addbyte(0x45); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(ABRT_GPF); addbyte(0x31); /* xor eax,eax */ addbyte(0xc0); - addbyte(0x67); /* mov [&(abrt_error)],eax */ - addbyte(0xa3); - addlong((uint32_t) (uintptr_t) &(abrt_error)); + addbyte(0x89); /*MOVB eax,(abrt_error)*/ + addbyte(0x05); + rip_rel = (uintptr_t) &(codeblock[block_current].data[block_pos]); + rip_rel = ((uintptr_t) &(abrt_error)) - rip_rel; + addlong((uint32_t) rip_rel); #endif block_pos = BLOCK_EXIT_OFFSET; /*Exit code*/ addbyte(0x48); /*ADDL $40,%rsp*/ diff --git a/src/codegen/codegen_x86-64.h b/src/codegen/codegen_x86-64.h index 529be99ae..1ef81ff89 100644 --- a/src/codegen/codegen_x86-64.h +++ b/src/codegen/codegen_x86-64.h @@ -11,7 +11,7 @@ #ifdef OLD_GPF #define BLOCK_GPF_OFFSET (BLOCK_EXIT_OFFSET - 20) #else -#define BLOCK_GPF_OFFSET (BLOCK_EXIT_OFFSET - 15) +#define BLOCK_GPF_OFFSET (BLOCK_EXIT_OFFSET - 12) #endif #define BLOCK_MAX 1620