From 0660f12da409e3bb8470b4b7e2a914bc94b940a1 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 29 Oct 2022 13:39:02 +0200 Subject: [PATCH 1/2] JitArm64: Move MMIO handler result before popping stack Otherwise we might throw the result away. Fixes https://bugs.dolphin-emu.org/issues/13083. --- Source/Core/Core/PowerPC/JitArm64/Jit_Util.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit_Util.cpp b/Source/Core/Core/PowerPC/JitArm64/Jit_Util.cpp index 4799e35c13..1a76814162 100644 --- a/Source/Core/Core/PowerPC/JitArm64/Jit_Util.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/Jit_Util.cpp @@ -78,9 +78,11 @@ private: m_emit->ABI_PushRegisters(m_gprs_in_use); float_emit.ABI_PushRegisters(m_fprs_in_use, ARM64Reg::X1); + m_emit->MOVI2R(ARM64Reg::W1, m_address); m_emit->MOV(ARM64Reg::W2, m_src_reg); m_emit->BLR(m_emit->ABI_SetupLambda(lambda)); + float_emit.ABI_PopRegisters(m_fprs_in_use, ARM64Reg::X1); m_emit->ABI_PopRegisters(m_gprs_in_use); } @@ -173,15 +175,16 @@ private: m_emit->ABI_PushRegisters(m_gprs_in_use); float_emit.ABI_PushRegisters(m_fprs_in_use, ARM64Reg::X1); + m_emit->MOVI2R(ARM64Reg::W1, m_address); m_emit->BLR(m_emit->ABI_SetupLambda(lambda)); - float_emit.ABI_PopRegisters(m_fprs_in_use, ARM64Reg::X1); - m_emit->ABI_PopRegisters(m_gprs_in_use); - if (m_sign_extend) m_emit->SBFM(m_dst_reg, ARM64Reg::W0, 0, sbits - 1); else m_emit->UBFM(m_dst_reg, ARM64Reg::W0, 0, sbits - 1); + + float_emit.ABI_PopRegisters(m_fprs_in_use, ARM64Reg::X1); + m_emit->ABI_PopRegisters(m_gprs_in_use); } ARM64XEmitter* m_emit; From 431ee1c48a805433ea7b0cd8d611d29ead6fa2b7 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 29 Oct 2022 13:54:41 +0200 Subject: [PATCH 2/2] JitArm64: Improve register handling for MMIO loadstores MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because of the previous commit, `regs_in_use` must not include `dest_reg` when calling MMIOLoadToReg. There are also some other registers we can skip including in regs_in_use just for efficiency's sake. The `addr_reg_set = false` statements that I've added in this commit are technically redundant – if `mmio_address` is non-zero then `addr_reg_set` is already false – but it's just a coincidence that that's the case. --- Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp index be39929f21..12c0bfe26c 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp @@ -141,8 +141,12 @@ void JitArm64::SafeLoadToReg(u32 dest, s32 addr, s32 offsetReg, u32 flags, s32 o } else if (mmio_address) { + regs_in_use[DecodeReg(ARM64Reg::W0)] = 0; + regs_in_use[DecodeReg(ARM64Reg::W30)] = 0; + regs_in_use[DecodeReg(dest_reg)] = 0; MMIOLoadToReg(Memory::mmio_mapping.get(), this, &m_float_emit, regs_in_use, fprs_in_use, dest_reg, mmio_address, flags); + addr_reg_set = false; } else { @@ -308,8 +312,13 @@ void JitArm64::SafeStoreFromReg(s32 dest, u32 value, s32 regOffset, u32 flags, s } else if (mmio_address) { + regs_in_use[DecodeReg(ARM64Reg::W0)] = 0; + regs_in_use[DecodeReg(ARM64Reg::W1)] = 0; + regs_in_use[DecodeReg(ARM64Reg::W30)] = 0; + regs_in_use[DecodeReg(RS)] = 0; MMIOWriteRegToAddr(Memory::mmio_mapping.get(), this, &m_float_emit, regs_in_use, fprs_in_use, RS, mmio_address, flags); + addr_reg_set = false; } else {