Recompiler: Handle stack if it is in IMEM/DMEM

This commit is contained in:
zilmar 2022-10-21 10:03:33 +10:30
parent 4525e8b6f3
commit ae6157427f
3 changed files with 50 additions and 6 deletions

View File

@ -1484,7 +1484,22 @@ void CN64System::SyncCPU(CN64System * const SecondCPU)
#if defined(__aarch64__) || defined(__amd64__) || defined(_M_X64)
g_Notify->BreakPoint(__FILE__, __LINE__);
#else
if (m_Recomp->MemoryStackPos() != (uint32_t)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF)))
uint32_t StackPointer = (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF);
uint32_t TargetStackPos = 0;
if (StackPointer < m_MMU_VM.RdramSize())
{
TargetStackPos = (uint32_t)(m_MMU_VM.Rdram() + StackPointer);
}
else if (StackPointer > 0x04000000 && StackPointer < 0x04001000)
{
TargetStackPos = (uint32_t)(m_MMU_VM.Dmem() + StackPointer - 0x04000000);
}
else if (StackPointer > 0x04001000 && StackPointer < 0x04002000)
{
TargetStackPos = (uint32_t)(m_MMU_VM.Imem() + StackPointer - 0x04001000);
}
if (m_Recomp->MemoryStackPos() != TargetStackPos)
{
ErrorFound = true;
}
@ -1665,8 +1680,23 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
{
#if defined(__aarch64__) || defined(__amd64__) || defined(_M_X64)
g_Notify->BreakPoint(__FILE__, __LINE__);
#else
if (m_Recomp->MemoryStackPos() != (uint32_t)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF)))
#else
uint32_t StackPointer = (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF);
uint32_t TargetStackPos = 0;
if (StackPointer < m_MMU_VM.RdramSize())
{
TargetStackPos = (uint32_t)(m_MMU_VM.Rdram() + StackPointer);
}
else if (StackPointer > 0x04000000 && StackPointer < 0x04001000)
{
TargetStackPos = (uint32_t)(m_MMU_VM.Dmem() + StackPointer - 0x04000000);
}
else if (StackPointer > 0x04001000 && StackPointer < 0x04002000)
{
TargetStackPos = (uint32_t)(m_MMU_VM.Imem() + StackPointer - 0x04001000);
}
if (m_Recomp->MemoryStackPos() != TargetStackPos)
{
Error.LogF("MemoryStack = %X should be: %X\r\n", m_Recomp->MemoryStackPos(), (uint32_t)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF)));
}

View File

@ -531,7 +531,22 @@ void CRecompiler::ResetMemoryStackPos()
uint32_t pAddr = 0;
if (m_MMU.VAddrToPAddr(m_Registers.m_GPR[29].UW[0], pAddr))
{
m_MemoryStack = (uint32_t)(m_MMU.Rdram() + pAddr);
if (pAddr < m_MMU.RdramSize())
{
m_MemoryStack = (uint32_t)(m_MMU.Rdram() + pAddr);
}
else if (pAddr > 0x04000000 && pAddr < 0x04001000)
{
m_MemoryStack = (uint32_t)(m_MMU.Dmem() + pAddr - 0x04000000);
}
else if (pAddr > 0x04001000 && pAddr < 0x04002000)
{
m_MemoryStack = (uint32_t)(m_MMU.Imem() + pAddr - 0x04001000);
}
else
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
}
else
{

View File

@ -3399,8 +3399,7 @@ void CX86RecompilerOps::LW_KnownAddress(CX86Ops::x86Reg Reg, uint32_t VAddr)
}
else if (g_DDRom != nullptr && ((PAddr & 0xFF000000) == 0x06000000 && (PAddr - 0x06000000) < g_DDRom->GetRomSize()))
{
// Read from DDROM (TODO: Is DDROM a disk image or the IPL?)
m_Assembler.MoveVariableToX86reg(PAddr + g_MMU->Rdram(), stdstr_f("RDRAM + %X", PAddr).c_str(), Reg);
m_Assembler.MoveVariableToX86reg(g_DDRom->GetRomAddress() + (PAddr - 0x06000000), stdstr_f("DDRom + %X", (PAddr - 0x06000000)).c_str(), Reg);
}
else
{