From bff5026b8b44b5b856784db6294190e838fd03d9 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 27 Oct 2022 04:10:16 +0200 Subject: [PATCH] One last attempt at a fix to my own GPF handler. --- src/codegen/codegen_x86-64.c | 6 +++--- src/codegen/codegen_x86-64.h | 2 +- src/cpu/cpu.c | 3 +++ src/cpu/x86seg.c | 2 -- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/codegen/codegen_x86-64.c b/src/codegen/codegen_x86-64.c index 4ba66d76b..7a9c00519 100644 --- a/src/codegen/codegen_x86-64.c +++ b/src/codegen/codegen_x86-64.c @@ -281,7 +281,7 @@ void codegen_block_start_recompile(codeblock_t *block) block->status = cpu_cur_status; block_pos = BLOCK_GPF_OFFSET; -#ifndef NEW_GPF +#ifdef OLD_GPF #if _WIN64 addbyte(0x48); /*XOR RCX, RCX*/ addbyte(0x31); @@ -306,8 +306,8 @@ void codegen_block_start_recompile(codeblock_t *block) addbyte(0x31); /* xor eax,eax */ addbyte(0xc0); addbyte(0x89); /*MOVB eax,(abrt_error)*/ - addbyte(0x05); - rip_rel = (uintptr_t) &(codeblock[block_current].data[block_pos]); + addbyte(0x85); + rip_rel = ((uintptr_t)&cpu_state) + 128; rip_rel = ((uintptr_t) &(abrt_error)) - rip_rel; addlong((uint32_t) rip_rel); #endif diff --git a/src/codegen/codegen_x86-64.h b/src/codegen/codegen_x86-64.h index 034b17355..1ef81ff89 100644 --- a/src/codegen/codegen_x86-64.h +++ b/src/codegen/codegen_x86-64.h @@ -8,7 +8,7 @@ #define HASH(l) ((l) & 0x1ffff) #define BLOCK_EXIT_OFFSET 0x7e0 -#ifndef NEW_GPF +#ifdef OLD_GPF #define BLOCK_GPF_OFFSET (BLOCK_EXIT_OFFSET - 20) #else #define BLOCK_GPF_OFFSET (BLOCK_EXIT_OFFSET - 12) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 8645801fc..940555dd2 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -73,6 +73,9 @@ enum { /* Make sure this is as low as possible. */ cpu_state_t cpu_state; +/* Place this immediately after. */ +uint32_t abrt_error; + #ifdef USE_DYNAREC const OpFn *x86_dynarec_opcodes, *x86_dynarec_opcodes_0f, *x86_dynarec_opcodes_d8_a16, *x86_dynarec_opcodes_d8_a32, diff --git a/src/cpu/x86seg.c b/src/cpu/x86seg.c index 2fda437e7..6737133ed 100644 --- a/src/cpu/x86seg.c +++ b/src/cpu/x86seg.c @@ -41,8 +41,6 @@ uint8_t opcode2; int cgate16, cgate32; int intgatesize; -uint32_t abrt_error; - void taskswitch286(uint16_t seg, uint16_t *segdat, int is32); void pmodeint(int num, int soft);