From fa57ce7fb8793957af3c177f39b5db57f05a37cd Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 20 Feb 2025 13:25:44 +1030 Subject: [PATCH] core: make CX86RecompilerOps::SPECIAL_JALR handle 64bit PC --- .../N64System/Recompiler/x86/x86RecompilerOps.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index 7fc41c518..cb493a329 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -4621,15 +4621,24 @@ void CX86RecompilerOps::SPECIAL_JALR() { if (m_RegWorkingSet.IsConst(m_Opcode.rs)) { - m_Assembler.MoveConstToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", m_RegWorkingSet.GetMipsRegLo(m_Opcode.rs)); + if (((int)m_CompilePC >> 31) != (m_RegWorkingSet.Is64Bit(m_Opcode.rs) ? (int)m_RegWorkingSet.GetMipsRegHi(m_Opcode.rs) : (m_RegWorkingSet.GetMipsRegLo_S(m_Opcode.rs) >> 31))) + { + m_Assembler.MoveConst64ToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", m_RegWorkingSet.Is64Bit(m_Opcode.rs) ? m_RegWorkingSet.GetMipsReg(m_Opcode.rs) : (int)m_RegWorkingSet.GetMipsRegLo_S(m_Opcode.rs)); + } + else + { + m_Assembler.MoveConstToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", m_RegWorkingSet.GetMipsRegLo(m_Opcode.rs)); + } } else if (m_RegWorkingSet.IsMapped(m_Opcode.rs)) { m_Assembler.MoveX86regToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", m_RegWorkingSet.GetMipsRegMapLo(m_Opcode.rs)); + m_Assembler.MoveX86regToVariable(((uint8_t *)&m_Reg.m_PROGRAM_COUNTER) + 4, "PROGRAM_COUNTER + 4", m_RegWorkingSet.Is64Bit(m_Opcode.rs) ? m_RegWorkingSet.GetMipsRegMapHi(m_Opcode.rs) : m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false)); } else { m_Assembler.MoveX86regToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false)); + m_Assembler.MoveX86regToVariable(((uint8_t *)&m_Reg.m_PROGRAM_COUNTER) + 4, "PROGRAM_COUNTER + 4", m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false)); } } m_RegWorkingSet.UnMap_GPR(m_Opcode.rd, false); @@ -4640,12 +4649,14 @@ void CX86RecompilerOps::SPECIAL_JALR() if (m_RegWorkingSet.IsMapped(m_Opcode.rs)) { m_Assembler.MoveX86regToVariable(&g_System->m_JumpToLocation, "System::m_JumpToLocation", m_RegWorkingSet.GetMipsRegMapLo(m_Opcode.rs)); + m_Assembler.MoveX86regToVariable(((uint8_t *)&g_System->m_JumpToLocation) + 4, "System::m_JumpToLocation + 4", m_RegWorkingSet.Is64Bit(m_Opcode.rs) ? m_RegWorkingSet.GetMipsRegMapHi(m_Opcode.rs) : m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false)); m_RegWorkingSet.WriteBackRegisters(); } else { m_RegWorkingSet.WriteBackRegisters(); m_Assembler.MoveX86regToVariable(&g_System->m_JumpToLocation, "System::m_JumpToLocation", m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false)); + m_Assembler.MoveX86regToVariable(((uint8_t *)&g_System->m_JumpToLocation) + 4, "System::m_JumpToLocation + 4", m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false)); } OverflowDelaySlot(true); return;