Skip to content

Commit

Permalink
Core: Handle bgezal ra in the recompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Dec 5, 2022
1 parent d35d2e6 commit 6b04b90
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
35 changes: 35 additions & 0 deletions Source/Project64-core/N64System/Recompiler/CodeSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ void CCodeSection::GenerateSectionLinkage()
else if (TargetSection[i] == nullptr && JumpInfo[i]->FallThrough)
{
m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1);
if (JumpInfo[i]->LinkAddress != (uint32_t)-1)
{
JumpInfo[i]->RegSet.UnMap_GPR(31, false);
JumpInfo[i]->RegSet.SetMipsRegLo(31, JumpInfo[i]->LinkAddress);
JumpInfo[i]->RegSet.SetMipsRegState(31, CRegInfo::STATE_CONST_32_SIGN);
JumpInfo[i]->LinkAddress = (uint32_t)-1;
}
m_RecompilerOps->CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->Reason);
JumpInfo[i]->FallThrough = false;
}
Expand All @@ -99,6 +106,13 @@ void CCodeSection::GenerateSectionLinkage()
continue;
}
m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1);
if (JumpInfo[i]->LinkAddress != (uint32_t)-1)
{
JumpInfo[i]->RegSet.UnMap_GPR(31, false);
JumpInfo[i]->RegSet.SetMipsRegLo(31, JumpInfo[i]->LinkAddress);
JumpInfo[i]->RegSet.SetMipsRegState(31, CRegInfo::STATE_CONST_32_SIGN);
JumpInfo[i]->LinkAddress = (uint32_t)-1;
}
m_RecompilerOps->CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->Reason);
//FreeSection(TargetSection[i],Section);
}
Expand Down Expand Up @@ -138,6 +152,13 @@ void CCodeSection::GenerateSectionLinkage()
{
JumpInfo[i]->FallThrough = false;
m_RecompilerOps->LinkJump(*JumpInfo[i], TargetSection[i]->m_SectionID);
if (JumpInfo[i]->LinkAddress != (uint32_t)-1)
{
JumpInfo[i]->RegSet.UnMap_GPR(31, false);
JumpInfo[i]->RegSet.SetMipsRegLo(31, JumpInfo[i]->LinkAddress);
JumpInfo[i]->RegSet.SetMipsRegState(31, CRegInfo::STATE_CONST_32_SIGN);
JumpInfo[i]->LinkAddress = (uint32_t)-1;
}
if (JumpInfo[i]->TargetPC <= m_RecompilerOps->GetCurrentPC())
{
if (JumpInfo[i]->PermLoop)
Expand Down Expand Up @@ -232,6 +253,13 @@ void CCodeSection::GenerateSectionLinkage()
{
m_CodeBlock.Log("ExitBlock (from %d):", m_SectionID);
m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1);
if (JumpInfo[i]->LinkAddress != (uint32_t)-1)
{
JumpInfo[i]->RegSet.UnMap_GPR(31, false);
JumpInfo[i]->RegSet.SetMipsRegLo(31, JumpInfo[i]->LinkAddress);
JumpInfo[i]->RegSet.SetMipsRegState(31, CRegInfo::STATE_CONST_32_SIGN);
JumpInfo[i]->LinkAddress = (uint32_t)-1;
}
m_RecompilerOps->CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->Reason);
continue;
}
Expand All @@ -249,6 +277,13 @@ void CCodeSection::GenerateSectionLinkage()

m_CodeBlock.Log(Label.c_str());
m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1);
if (JumpInfo[i]->LinkAddress != (uint32_t)-1)
{
JumpInfo[i]->RegSet.UnMap_GPR(31, false);
JumpInfo[i]->RegSet.SetMipsRegLo(31, JumpInfo[i]->LinkAddress);
JumpInfo[i]->RegSet.SetMipsRegState(31, CRegInfo::STATE_CONST_32_SIGN);
JumpInfo[i]->LinkAddress = (uint32_t)-1;
}
m_RecompilerOps->SetRegWorkingSet(JumpInfo[i]->RegSet);
if (JumpInfo[i]->TargetPC <= JumpInfo[i]->JumpPC)
{
Expand Down
1 change: 1 addition & 0 deletions Source/Project64-core/N64System/Recompiler/JumpInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CJumpInfo::CJumpInfo(CCodeBlock & CodeBlock) :
{
TargetPC = (uint32_t)-1;
JumpPC = (uint32_t)-1;
LinkAddress = (uint32_t)-1;
BranchLabel = "";
FallThrough = false;
PermLoop = false;
Expand Down
1 change: 1 addition & 0 deletions Source/Project64-core/N64System/Recompiler/JumpInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct CJumpInfo

uint32_t TargetPC;
uint32_t JumpPC;
uint32_t LinkAddress;
std::string BranchLabel;
asmjit::Label LinkLocation;
asmjit::Label LinkLocation2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,21 @@ void CX86RecompilerOps::Compile_Branch(RecompilerBranchCompare CompareType, bool

if (Link)
{
UnMap_GPR(31, false);
m_RegWorkingSet.SetMipsRegLo(31, m_CompilePC + 8);
m_RegWorkingSet.SetMipsRegState(31, CRegInfo::STATE_CONST_32_SIGN);
R4300iInstruction Instruction(m_CompilePC, m_Opcode.Value);
uint32_t ReadReg1, ReadReg2;
Instruction.ReadsGPR(ReadReg1, ReadReg2);

if (ReadReg1 != 31 && ReadReg2 != 31)
{
UnMap_GPR(31, false);
m_RegWorkingSet.SetMipsRegLo(31, m_CompilePC + 8);
m_RegWorkingSet.SetMipsRegState(31, CRegInfo::STATE_CONST_32_SIGN);
}
else
{
m_Section->m_Cont.LinkAddress = m_CompilePC + 8;
m_Section->m_Jump.LinkAddress = m_CompilePC + 8;
}
}
if (m_EffectDelaySlot)
{
Expand Down

0 comments on commit 6b04b90

Please sign in to comment.