From 51caf52eb3d0d6831007e38e9d0c481a990b97ab Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 26 Oct 2022 22:58:57 +0200 Subject: [PATCH 1/5] Disabled excess F82C710 logging. --- src/sio/sio_f82c710.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/sio/sio_f82c710.c b/src/sio/sio_f82c710.c index 36f6b00a3..eccf799f4 100644 --- a/src/sio/sio_f82c710.c +++ b/src/sio/sio_f82c710.c @@ -60,6 +60,24 @@ typedef struct upc_t { serial_t *uart[2]; } upc_t; +#ifdef ENABLE_F82C710_LOG +int f82c710_do_log = ENABLE_F82C710_LOG; + +static void +f82c710_log(const char *fmt, ...) +{ + va_list ap; + + if (f82c710_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define f82c710_log(fmt, ...) +#endif + static void f82c710_update_ports(upc_t *dev, int set) { @@ -171,28 +189,28 @@ f82c606_update_ports(upc_t *dev, int set) if (dev->regs[0] & 1) { gameport_remap(dev->gameport, ((uint16_t) dev->regs[7]) << 2); - pclog("Game port at %04X\n", ((uint16_t) dev->regs[7]) << 2); + f82c710_log("Game port at %04X\n", ((uint16_t) dev->regs[7]) << 2); } if (dev->regs[0] & 2) { serial_setup(dev->uart[0], ((uint16_t) dev->regs[4]) << 2, uart1_int); - pclog("UART 1 at %04X, IRQ %i\n", ((uint16_t) dev->regs[4]) << 2, uart1_int); + f82c710_log("UART 1 at %04X, IRQ %i\n", ((uint16_t) dev->regs[4]) << 2, uart1_int); } if (dev->regs[0] & 4) { serial_setup(dev->uart[1], ((uint16_t) dev->regs[5]) << 2, uart2_int); - pclog("UART 2 at %04X, IRQ %i\n", ((uint16_t) dev->regs[5]) << 2, uart2_int); + f82c710_log("UART 2 at %04X, IRQ %i\n", ((uint16_t) dev->regs[5]) << 2, uart2_int); } if (dev->regs[0] & 8) { lpt1_init(((uint16_t) dev->regs[6]) << 2); lpt1_irq(lpt1_int); - pclog("LPT1 at %04X, IRQ %i\n", ((uint16_t) dev->regs[6]) << 2, lpt1_int); + f82c710_log("LPT1 at %04X, IRQ %i\n", ((uint16_t) dev->regs[6]) << 2, lpt1_int); } nvr_at_handler(1, ((uint16_t) dev->regs[3]) << 2, dev->nvr); nvr_irq_set(nvr_int, dev->nvr); - pclog("RTC at %04X, IRQ %i\n", ((uint16_t) dev->regs[3]) << 2, nvr_int); + f82c710_log("RTC at %04X, IRQ %i\n", ((uint16_t) dev->regs[3]) << 2, nvr_int); } static uint8_t From acd4eb5d682017e68e924ccb3194bf7919d1f75b Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 27 Oct 2022 02:39:34 +0200 Subject: [PATCH 2/5] Debug builds no longer use the ACYCS nonsense. --- src/win/Makefile.mingw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 1773198a6..8e0156943 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -298,7 +298,7 @@ else endif endif ifeq ($(DEBUG), y) - DFLAGS += -ggdb -DDEBUG -DUSE_ACYCS + DFLAGS += -ggdb -DDEBUG AOPTIM := ifndef COPTIM COPTIM := -Og From 47604db6b16c6b2ccec7ebd13d2a98d6f1709a4c Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 27 Oct 2022 03:24:02 +0200 Subject: [PATCH 3/5] 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 From 4dc74515e8475f365a3497ff9fc57c7fb881d250 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 27 Oct 2022 03:56:26 +0200 Subject: [PATCH 4/5] Returned back to the PCem GPF handler. --- src/codegen/codegen_x86-64.c | 2 +- src/codegen/codegen_x86-64.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/codegen/codegen_x86-64.c b/src/codegen/codegen_x86-64.c index 4289235fe..4ba66d76b 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; -#ifdef OLD_GPF +#ifndef NEW_GPF #if _WIN64 addbyte(0x48); /*XOR RCX, RCX*/ addbyte(0x31); diff --git a/src/codegen/codegen_x86-64.h b/src/codegen/codegen_x86-64.h index 1ef81ff89..034b17355 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 -#ifdef OLD_GPF +#ifndef NEW_GPF #define BLOCK_GPF_OFFSET (BLOCK_EXIT_OFFSET - 20) #else #define BLOCK_GPF_OFFSET (BLOCK_EXIT_OFFSET - 12) From bff5026b8b44b5b856784db6294190e838fd03d9 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 27 Oct 2022 04:10:16 +0200 Subject: [PATCH 5/5] 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);