From 6ffa5bffabe2e0f11a5a40feff7c0249b4834c15 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 11 Nov 2024 16:26:51 +1000 Subject: [PATCH] CPU: Handle mirrors of BIOS syscalls --- src/core/cpu_core.cpp | 6 ++++-- src/core/cpu_newrec_compiler.cpp | 5 +++-- src/core/cpu_recompiler_code_generator.cpp | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/cpu_core.cpp b/src/core/cpu_core.cpp index 2d36a68ac..fa63fc6b6 100644 --- a/src/core/cpu_core.cpp +++ b/src/core/cpu_core.cpp @@ -2422,9 +2422,11 @@ template if (s_trace_to_log) LogInstruction(g_state.current_instruction.bits, g_state.current_instruction_pc, true); - if (g_state.current_instruction_pc == 0xA0) [[unlikely]] + // handle all mirrors of the syscall trampoline + const u32 masked_pc = (g_state.current_instruction_pc & PHYSICAL_MEMORY_ADDRESS_MASK); + if (masked_pc == 0xA0) [[unlikely]] HandleA0Syscall(); - else if (g_state.current_instruction_pc == 0xB0) [[unlikely]] + else if (masked_pc == 0xB0) [[unlikely]] HandleB0Syscall(); } diff --git a/src/core/cpu_newrec_compiler.cpp b/src/core/cpu_newrec_compiler.cpp index 8f0aef3f3..887cb49ab 100644 --- a/src/core/cpu_newrec_compiler.cpp +++ b/src/core/cpu_newrec_compiler.cpp @@ -84,9 +84,10 @@ void CPU::NewRec::Compiler::BeginBlock() if (g_settings.bios_tty_logging) { - if (m_block->pc == 0xa0) + const u32 masked_pc = (m_block->pc & PHYSICAL_MEMORY_ADDRESS_MASK); + if (masked_pc == 0xa0) GenerateCall(reinterpret_cast(&CPU::HandleA0Syscall)); - else if (m_block->pc == 0xb0) + else if (masked_pc == 0xb0) GenerateCall(reinterpret_cast(&CPU::HandleB0Syscall)); } diff --git a/src/core/cpu_recompiler_code_generator.cpp b/src/core/cpu_recompiler_code_generator.cpp index 50c413918..517276ec9 100644 --- a/src/core/cpu_recompiler_code_generator.cpp +++ b/src/core/cpu_recompiler_code_generator.cpp @@ -1000,9 +1000,10 @@ void CodeGenerator::BlockPrologue() if (g_settings.bios_tty_logging) { - if (m_pc == 0xa0) + const u32 masked_pc = (m_pc & PHYSICAL_MEMORY_ADDRESS_MASK); + if (masked_pc == 0xa0) EmitFunctionCall(nullptr, &CPU::HandleA0Syscall); - else if (m_pc == 0xb0) + else if (masked_pc == 0xb0) EmitFunctionCall(nullptr, &CPU::HandleB0Syscall); }