2010-10-23 18:53:01 +00:00
|
|
|
#include "stdafx.h"
|
2022-10-10 00:22:17 +00:00
|
|
|
|
|
|
|
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
|
|
|
|
#include <Project64-core/N64System/N64System.h>
|
|
|
|
#include <Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h>
|
2016-01-13 11:15:30 +00:00
|
|
|
#include <Project64-core/N64System/Recompiler/CodeBlock.h>
|
2016-06-27 11:49:15 +00:00
|
|
|
#include <Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/SystemGlobals.h>
|
2022-10-10 00:22:17 +00:00
|
|
|
#include <string.h>
|
2010-10-23 18:53:01 +00:00
|
|
|
|
2016-08-11 11:09:21 +00:00
|
|
|
#if defined(ANDROID) && (defined(__arm__) || defined(_M_ARM))
|
|
|
|
/* bug-fix to implement __clear_cache (missing in Android; http://code.google.com/p/android/issues/detail?id=1803) */
|
2022-10-10 00:22:17 +00:00
|
|
|
extern "C" void __clear_cache_android(uint8_t * begin, uint8_t * end);
|
2016-08-11 11:09:21 +00:00
|
|
|
#endif
|
|
|
|
|
2022-05-01 22:06:50 +00:00
|
|
|
CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * CompiledLocation) :
|
|
|
|
m_MMU(MMU),
|
2022-02-01 02:54:25 +00:00
|
|
|
m_VAddrEnter(VAddrEnter),
|
|
|
|
m_VAddrFirst(VAddrEnter),
|
|
|
|
m_VAddrLast(VAddrEnter),
|
|
|
|
m_CompiledLocation(CompiledLocation),
|
|
|
|
m_EnterSection(nullptr),
|
|
|
|
m_RecompilerOps(nullptr),
|
|
|
|
m_Test(1)
|
2010-10-23 18:53:01 +00:00
|
|
|
{
|
2016-08-11 11:09:21 +00:00
|
|
|
#if defined(__arm__) || defined(_M_ARM)
|
2021-05-18 11:51:36 +00:00
|
|
|
// Make sure function starts at an odd address so that the system knows it is in thumb mode
|
2016-08-11 11:09:21 +00:00
|
|
|
if (((uint32_t)m_CompiledLocation % 2) == 0)
|
|
|
|
{
|
2022-10-10 00:22:17 +00:00
|
|
|
m_CompiledLocation += 1;
|
2016-08-11 11:09:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-07-06 20:14:12 +00:00
|
|
|
#if defined(__i386__) || defined(_M_IX86)
|
2022-08-08 10:52:51 +00:00
|
|
|
m_RecompilerOps = new CX86RecompilerOps(MMU, *this);
|
2016-08-11 11:09:21 +00:00
|
|
|
#elif defined(__arm__) || defined(_M_ARM)
|
2022-09-12 13:14:42 +00:00
|
|
|
m_RecompilerOps = new CArmRecompilerOps(MMU, *this);
|
2022-08-29 08:27:17 +00:00
|
|
|
#else
|
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2016-07-06 20:14:12 +00:00
|
|
|
#endif
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_RecompilerOps == nullptr)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2016-08-11 11:09:21 +00:00
|
|
|
return;
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
2022-08-08 10:52:51 +00:00
|
|
|
CCodeSection * baseSection = new CCodeSection(*this, VAddrEnter, 0, false);
|
2021-04-12 11:35:39 +00:00
|
|
|
if (baseSection == nullptr)
|
2016-07-03 05:22:14 +00:00
|
|
|
{
|
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
|
|
|
}
|
2016-06-28 11:22:30 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
m_Sections.push_back(baseSection);
|
2021-04-12 11:35:39 +00:00
|
|
|
baseSection->AddParent(nullptr);
|
2015-11-08 21:00:16 +00:00
|
|
|
baseSection->m_CompiledLocation = (uint8_t *)-1;
|
|
|
|
baseSection->m_Cont.JumpPC = VAddrEnter;
|
|
|
|
baseSection->m_Cont.FallThrough = true;
|
|
|
|
baseSection->m_Cont.RegSet = baseSection->m_RegEnter;
|
|
|
|
|
2022-08-08 10:52:51 +00:00
|
|
|
m_EnterSection = new CCodeSection(*this, VAddrEnter, 1, true);
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_EnterSection == nullptr)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
baseSection->m_ContinueSection = m_EnterSection;
|
|
|
|
m_EnterSection->AddParent(baseSection);
|
|
|
|
m_Sections.push_back(m_EnterSection);
|
2016-07-04 07:51:11 +00:00
|
|
|
m_SectionMap.insert(SectionMap::value_type(VAddrEnter, m_EnterSection));
|
2015-11-08 21:00:16 +00:00
|
|
|
|
2022-05-16 05:56:20 +00:00
|
|
|
memset(m_MemLocation, 0, sizeof(m_MemLocation));
|
|
|
|
memset(m_MemContents, 0, sizeof(m_MemContents));
|
|
|
|
|
|
|
|
m_MemLocation[0] = (uint64_t *)MMU.MemoryPtr(VAddrEnter, 16, true);
|
|
|
|
if (m_MemLocation[0] != 0)
|
2022-05-01 22:06:50 +00:00
|
|
|
{
|
2015-11-08 21:00:16 +00:00
|
|
|
m_MemLocation[1] = m_MemLocation[0] + 1;
|
|
|
|
m_MemContents[0] = *m_MemLocation[0];
|
|
|
|
m_MemContents[1] = *m_MemLocation[1];
|
2022-05-16 05:56:20 +00:00
|
|
|
AnalyseBlock();
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
2010-10-23 18:53:01 +00:00
|
|
|
}
|
|
|
|
|
2012-10-14 06:33:51 +00:00
|
|
|
CCodeBlock::~CCodeBlock()
|
|
|
|
{
|
2015-11-08 21:00:16 +00:00
|
|
|
for (SectionList::iterator itr = m_Sections.begin(); itr != m_Sections.end(); itr++)
|
|
|
|
{
|
|
|
|
CCodeSection * Section = *itr;
|
|
|
|
delete Section;
|
|
|
|
}
|
|
|
|
m_Sections.clear();
|
2016-07-03 05:22:14 +00:00
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_RecompilerOps != nullptr)
|
2016-07-03 05:22:14 +00:00
|
|
|
{
|
2016-07-06 20:14:12 +00:00
|
|
|
#if defined(__i386__) || defined(_M_IX86)
|
2016-07-05 10:32:10 +00:00
|
|
|
delete (CX86RecompilerOps *)m_RecompilerOps;
|
2022-08-29 08:27:17 +00:00
|
|
|
#else
|
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2016-07-06 20:14:12 +00:00
|
|
|
#endif
|
2021-04-12 11:35:39 +00:00
|
|
|
m_RecompilerOps = nullptr;
|
2016-07-03 05:22:14 +00:00
|
|
|
}
|
2012-10-14 06:33:51 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 00:22:17 +00:00
|
|
|
bool CCodeBlock::SetSection(CCodeSection *& Section, CCodeSection * CurrentSection, uint32_t TargetPC, bool LinkAllowed, uint32_t CurrentPC)
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (Section != nullptr)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (TargetPC >= ((CurrentPC + 0x1000) & 0xFFFFF000))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TargetPC < m_EnterSection->m_EnterPC)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LinkAllowed)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (Section != nullptr)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
SectionMap::const_iterator itr = m_SectionMap.find(TargetPC);
|
|
|
|
if (itr != m_SectionMap.end())
|
|
|
|
{
|
|
|
|
Section = itr->second;
|
|
|
|
Section->AddParent(CurrentSection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
if (Section == nullptr)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2022-08-08 10:52:51 +00:00
|
|
|
Section = new CCodeSection(*this, TargetPC, (uint32_t)m_Sections.size(), LinkAllowed);
|
2021-04-12 11:35:39 +00:00
|
|
|
if (Section == nullptr)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_Sections.push_back(Section);
|
|
|
|
if (LinkAllowed)
|
|
|
|
{
|
2016-07-04 07:51:11 +00:00
|
|
|
m_SectionMap.insert(SectionMap::value_type(TargetPC, Section));
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
Section->AddParent(CurrentSection);
|
|
|
|
if (TargetPC <= CurrentPC && TargetPC != m_VAddrEnter)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
CCodeSection * SplitSection = nullptr;
|
2015-11-08 21:00:16 +00:00
|
|
|
for (SectionMap::const_iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
|
|
|
|
{
|
|
|
|
if (itr->first >= TargetPC)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SplitSection = itr->second;
|
|
|
|
}
|
2021-04-12 11:35:39 +00:00
|
|
|
if (SplitSection == nullptr)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
if (SplitSection->m_EndPC == (uint32_t)-1)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
if (SplitSection->m_EndPC >= TargetPC)
|
|
|
|
{
|
2022-08-08 10:52:51 +00:00
|
|
|
Log("%s: Split Section: %d with section: %d", __FUNCTION__, SplitSection->m_SectionID, Section->m_SectionID);
|
2015-11-08 21:00:16 +00:00
|
|
|
CCodeSection * BaseSection = Section;
|
|
|
|
BaseSection->m_EndPC = SplitSection->m_EndPC;
|
2016-07-04 07:51:11 +00:00
|
|
|
BaseSection->SetJumpAddress(SplitSection->m_Jump.JumpPC, SplitSection->m_Jump.TargetPC, SplitSection->m_Jump.PermLoop);
|
2015-11-08 21:00:16 +00:00
|
|
|
BaseSection->m_JumpSection = SplitSection->m_JumpSection;
|
2016-07-04 07:51:11 +00:00
|
|
|
BaseSection->SetContinueAddress(SplitSection->m_Cont.JumpPC, SplitSection->m_Cont.TargetPC);
|
2015-11-08 21:00:16 +00:00
|
|
|
BaseSection->m_ContinueSection = SplitSection->m_ContinueSection;
|
2016-11-27 20:34:02 +00:00
|
|
|
if (BaseSection->m_JumpSection)
|
|
|
|
{
|
|
|
|
BaseSection->m_JumpSection->SwitchParent(SplitSection, BaseSection);
|
|
|
|
}
|
|
|
|
if (BaseSection->m_ContinueSection)
|
|
|
|
{
|
|
|
|
BaseSection->m_ContinueSection->SwitchParent(SplitSection, BaseSection);
|
|
|
|
}
|
2015-11-08 21:00:16 +00:00
|
|
|
BaseSection->AddParent(SplitSection);
|
|
|
|
|
|
|
|
SplitSection->m_EndPC = TargetPC - 4;
|
2021-04-12 11:35:39 +00:00
|
|
|
SplitSection->m_JumpSection = nullptr;
|
2015-11-08 21:00:16 +00:00
|
|
|
SplitSection->m_ContinueSection = BaseSection;
|
|
|
|
SplitSection->SetContinueAddress(TargetPC - 4, TargetPC);
|
2016-07-04 07:51:11 +00:00
|
|
|
SplitSection->SetJumpAddress((uint32_t)-1, (uint32_t)-1, false);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 07:51:11 +00:00
|
|
|
bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection)
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
2015-11-08 21:00:16 +00:00
|
|
|
CCodeSection * CurrentSection = EnterSection;
|
|
|
|
|
2022-08-08 10:52:51 +00:00
|
|
|
Log("Section %d", CurrentSection->m_SectionID);
|
2015-11-08 21:00:16 +00:00
|
|
|
for (uint32_t TestPC = EnterSection->m_EnterPC, EndPC = ((EnterSection->m_EnterPC + 0x1000) & 0xFFFFF000); TestPC <= EndPC; TestPC += 4)
|
|
|
|
{
|
|
|
|
if (TestPC != EndPC)
|
|
|
|
{
|
|
|
|
SectionMap::const_iterator itr = m_SectionMap.find(TestPC);
|
|
|
|
if (itr != m_SectionMap.end() && CurrentSection != itr->second)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (CurrentSection->m_ContinueSection != nullptr &&
|
2015-11-08 21:00:16 +00:00
|
|
|
CurrentSection->m_ContinueSection != itr->second)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
2021-04-12 11:35:39 +00:00
|
|
|
if (CurrentSection->m_ContinueSection == nullptr)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2016-07-04 07:51:11 +00:00
|
|
|
SetSection(CurrentSection->m_ContinueSection, CurrentSection, TestPC, true, TestPC);
|
2015-11-08 21:00:16 +00:00
|
|
|
CurrentSection->SetContinueAddress(TestPC - 4, TestPC);
|
|
|
|
}
|
|
|
|
CurrentSection->m_EndPC = TestPC - 4;
|
|
|
|
CurrentSection = itr->second;
|
|
|
|
|
2022-08-08 10:52:51 +00:00
|
|
|
Log("Section %d", CurrentSection->m_SectionID);
|
2015-11-08 21:00:16 +00:00
|
|
|
if (EnterSection != m_EnterSection)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (CurrentSection->m_JumpSection != nullptr ||
|
|
|
|
CurrentSection->m_ContinueSection != nullptr ||
|
2015-11-08 21:00:16 +00:00
|
|
|
CurrentSection->m_EndSection)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurrentSection->m_EndSection = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LikelyBranch, EndBlock, IncludeDelaySlot, PermLoop;
|
|
|
|
uint32_t TargetPC, ContinuePC;
|
|
|
|
|
|
|
|
CurrentSection->m_EndPC = TestPC;
|
|
|
|
if (!AnalyzeInstruction(TestPC, TargetPC, ContinuePC, LikelyBranch, IncludeDelaySlot, EndBlock, PermLoop))
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TestPC + 4 == EndPC && IncludeDelaySlot)
|
|
|
|
{
|
|
|
|
TargetPC = (uint32_t)-1;
|
|
|
|
ContinuePC = (uint32_t)-1;
|
|
|
|
EndBlock = true;
|
|
|
|
}
|
|
|
|
if (TargetPC == (uint32_t)-1 && !EndBlock)
|
|
|
|
{
|
|
|
|
if (ContinuePC != (uint32_t)-1)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EndBlock)
|
|
|
|
{
|
2022-08-08 10:52:51 +00:00
|
|
|
Log("%s: End Block", __FUNCTION__);
|
2015-11-08 21:00:16 +00:00
|
|
|
CurrentSection->m_EndSection = true;
|
2021-05-18 11:51:36 +00:00
|
|
|
// Find other sections that need compiling
|
2015-11-08 21:00:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ContinuePC != (uint32_t)-1)
|
|
|
|
{
|
2022-08-08 10:52:51 +00:00
|
|
|
Log("%s: SetContinueAddress TestPC = %X ContinuePC = %X", __FUNCTION__, TestPC, ContinuePC);
|
2015-11-08 21:00:16 +00:00
|
|
|
CurrentSection->SetContinueAddress(TestPC, ContinuePC);
|
2016-07-04 07:51:11 +00:00
|
|
|
if (!SetSection(CurrentSection->m_ContinueSection, CurrentSection, ContinuePC, true, TestPC))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
ContinuePC = (uint32_t)-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LikelyBranch)
|
|
|
|
{
|
2022-08-08 10:52:51 +00:00
|
|
|
Log("%s: SetJumpAddress TestPC = %X Target = %X", __FUNCTION__, TestPC, TestPC + 4);
|
2016-07-04 07:51:11 +00:00
|
|
|
CurrentSection->SetJumpAddress(TestPC, TestPC + 4, false);
|
|
|
|
if (SetSection(CurrentSection->m_JumpSection, CurrentSection, TestPC + 4, false, TestPC))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
bool BranchLikelyBranch, BranchEndBlock, BranchIncludeDelaySlot, BranchPermLoop;
|
|
|
|
uint32_t BranchTargetPC, BranchContinuePC;
|
|
|
|
|
|
|
|
CCodeSection * JumpSection = CurrentSection->m_JumpSection;
|
|
|
|
if (!AnalyzeInstruction(JumpSection->m_EnterPC, BranchTargetPC, BranchContinuePC, BranchLikelyBranch, BranchIncludeDelaySlot, BranchEndBlock, BranchPermLoop))
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BranchLikelyBranch || BranchIncludeDelaySlot || BranchPermLoop)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JumpSection->m_EndPC = TestPC + 4;
|
|
|
|
if (BranchEndBlock)
|
|
|
|
{
|
2022-08-08 10:52:51 +00:00
|
|
|
Log("%s: Jump End Block", __FUNCTION__);
|
2015-11-08 21:00:16 +00:00
|
|
|
JumpSection->m_EndSection = true;
|
|
|
|
TargetPC = (uint32_t)-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-04 07:51:11 +00:00
|
|
|
JumpSection->SetJumpAddress(TestPC, TargetPC, false);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
JumpSection->SetDelaySlot();
|
2016-07-04 07:51:11 +00:00
|
|
|
SetSection(JumpSection->m_JumpSection, JumpSection, TargetPC, true, TestPC);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (TargetPC != ((uint32_t)-1))
|
|
|
|
{
|
2022-08-08 10:52:51 +00:00
|
|
|
Log("%s: SetJumpAddress TestPC = %X Target = %X", __FUNCTION__, TestPC, TargetPC);
|
2016-07-04 07:51:11 +00:00
|
|
|
CurrentSection->SetJumpAddress(TestPC, TargetPC, PermLoop);
|
|
|
|
if (PermLoop || !SetSection(CurrentSection->m_JumpSection, CurrentSection, TargetPC, true, TestPC))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
if (ContinuePC == (uint32_t)-1)
|
|
|
|
{
|
|
|
|
CurrentSection->m_EndSection = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TestPC += IncludeDelaySlot ? 8 : 4;
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Find the next section
|
2021-04-12 11:35:39 +00:00
|
|
|
CCodeSection * NewSection = nullptr;
|
2015-11-08 21:00:16 +00:00
|
|
|
for (SectionMap::const_iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (CurrentSection->m_JumpSection != nullptr ||
|
|
|
|
CurrentSection->m_ContinueSection != nullptr ||
|
2015-11-08 21:00:16 +00:00
|
|
|
CurrentSection->m_EndSection)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
NewSection = itr->second;
|
|
|
|
break;
|
|
|
|
}
|
2021-04-12 11:35:39 +00:00
|
|
|
if (NewSection == nullptr)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (CurrentSection == NewSection)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
CurrentSection = NewSection;
|
2021-04-12 11:35:39 +00:00
|
|
|
if (CurrentSection->m_JumpSection != nullptr ||
|
|
|
|
CurrentSection->m_ContinueSection != nullptr ||
|
2015-11-08 21:00:16 +00:00
|
|
|
CurrentSection->m_EndSection)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TestPC = CurrentSection->m_EnterPC;
|
2022-08-08 10:52:51 +00:00
|
|
|
Log("a. Section %d", CurrentSection->m_SectionID);
|
2015-11-08 21:00:16 +00:00
|
|
|
TestPC -= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (SectionMap::iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
|
|
|
|
{
|
|
|
|
CCodeSection * Section = itr->second;
|
2021-04-12 11:35:39 +00:00
|
|
|
if (Section->m_JumpSection != nullptr ||
|
|
|
|
Section->m_ContinueSection != nullptr ||
|
2015-11-08 21:00:16 +00:00
|
|
|
Section->m_EndSection)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!CreateBlockLinkage(Section))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (CurrentSection->m_EndPC == (uint32_t)-1)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
return true;
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CCodeBlock::DetermineLoops()
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
2015-11-08 21:00:16 +00:00
|
|
|
for (SectionMap::iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
|
|
|
|
{
|
|
|
|
CCodeSection * Section = itr->second;
|
2012-10-14 01:05:52 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
uint32_t Test = NextTest();
|
2016-11-27 20:34:02 +00:00
|
|
|
if (Section)
|
|
|
|
{
|
|
|
|
Section->DetermineLoop(Test, Test, Section->m_SectionID);
|
|
|
|
}
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CCodeBlock::LogSectionInfo()
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
2015-11-08 21:00:16 +00:00
|
|
|
for (SectionList::iterator itr = m_Sections.begin(); itr != m_Sections.end(); itr++)
|
|
|
|
{
|
|
|
|
CCodeSection * Section = *itr;
|
|
|
|
Section->DisplaySectionInformation();
|
|
|
|
}
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
bool CCodeBlock::AnalyseBlock()
|
2010-10-23 18:53:01 +00:00
|
|
|
{
|
2015-11-08 21:00:16 +00:00
|
|
|
if (!g_System->bLinkBlocks())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!CreateBlockLinkage(m_EnterSection))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
DetermineLoops();
|
|
|
|
LogSectionInfo();
|
|
|
|
return true;
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 07:51:11 +00:00
|
|
|
bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t & ContinuePC, bool & LikelyBranch, bool & IncludeDelaySlot, bool & EndBlock, bool & PermLoop)
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
2015-11-08 21:00:16 +00:00
|
|
|
TargetPC = (uint32_t)-1;
|
|
|
|
ContinuePC = (uint32_t)-1;
|
|
|
|
LikelyBranch = false;
|
|
|
|
IncludeDelaySlot = false;
|
|
|
|
EndBlock = false;
|
|
|
|
PermLoop = false;
|
|
|
|
|
2022-07-18 08:31:00 +00:00
|
|
|
R4300iOpcode Command;
|
|
|
|
if (!g_MMU->MemoryValue32(PC, Command.Value))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-14 01:05:52 +00:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2022-07-18 08:31:00 +00:00
|
|
|
R4300iInstruction Instruction(PC, Command.Value);
|
2022-08-08 10:52:51 +00:00
|
|
|
Log(" 0x%08X %s %s", PC, Instruction.Name(), Instruction.Param());
|
2012-10-14 01:05:52 +00:00
|
|
|
#endif
|
2015-11-08 21:00:16 +00:00
|
|
|
switch (Command.op)
|
|
|
|
{
|
|
|
|
case R4300i_SPECIAL:
|
|
|
|
switch (Command.funct)
|
|
|
|
{
|
2022-10-10 00:22:17 +00:00
|
|
|
case R4300i_SPECIAL_SLL:
|
|
|
|
case R4300i_SPECIAL_SRL:
|
|
|
|
case R4300i_SPECIAL_SRA:
|
|
|
|
case R4300i_SPECIAL_SLLV:
|
|
|
|
case R4300i_SPECIAL_SRLV:
|
|
|
|
case R4300i_SPECIAL_SRAV:
|
|
|
|
case R4300i_SPECIAL_MFHI:
|
|
|
|
case R4300i_SPECIAL_MTHI:
|
|
|
|
case R4300i_SPECIAL_MFLO:
|
|
|
|
case R4300i_SPECIAL_MTLO:
|
|
|
|
case R4300i_SPECIAL_DSLLV:
|
|
|
|
case R4300i_SPECIAL_DSRLV:
|
|
|
|
case R4300i_SPECIAL_DSRAV:
|
|
|
|
case R4300i_SPECIAL_ADD:
|
|
|
|
case R4300i_SPECIAL_ADDU:
|
|
|
|
case R4300i_SPECIAL_SUB:
|
|
|
|
case R4300i_SPECIAL_SUBU:
|
|
|
|
case R4300i_SPECIAL_AND:
|
|
|
|
case R4300i_SPECIAL_OR:
|
|
|
|
case R4300i_SPECIAL_XOR:
|
|
|
|
case R4300i_SPECIAL_NOR:
|
|
|
|
case R4300i_SPECIAL_SLT:
|
|
|
|
case R4300i_SPECIAL_SLTU:
|
|
|
|
case R4300i_SPECIAL_DADD:
|
|
|
|
case R4300i_SPECIAL_DADDU:
|
|
|
|
case R4300i_SPECIAL_DSUB:
|
|
|
|
case R4300i_SPECIAL_DSUBU:
|
|
|
|
case R4300i_SPECIAL_DSLL:
|
|
|
|
case R4300i_SPECIAL_DSRL:
|
|
|
|
case R4300i_SPECIAL_DSRA:
|
|
|
|
case R4300i_SPECIAL_DSLL32:
|
|
|
|
case R4300i_SPECIAL_DSRL32:
|
|
|
|
case R4300i_SPECIAL_DSRA32:
|
|
|
|
case R4300i_SPECIAL_MULT:
|
|
|
|
case R4300i_SPECIAL_MULTU:
|
|
|
|
case R4300i_SPECIAL_DIV:
|
|
|
|
case R4300i_SPECIAL_DIVU:
|
|
|
|
case R4300i_SPECIAL_DMULT:
|
|
|
|
case R4300i_SPECIAL_DMULTU:
|
|
|
|
case R4300i_SPECIAL_DDIV:
|
|
|
|
case R4300i_SPECIAL_DDIVU:
|
|
|
|
case R4300i_SPECIAL_TEQ:
|
|
|
|
case R4300i_SPECIAL_TNE:
|
|
|
|
case R4300i_SPECIAL_TGE:
|
|
|
|
case R4300i_SPECIAL_TGEU:
|
|
|
|
case R4300i_SPECIAL_TLT:
|
|
|
|
case R4300i_SPECIAL_TLTU:
|
2015-11-08 21:00:16 +00:00
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_JALR:
|
|
|
|
case R4300i_SPECIAL_JR:
|
|
|
|
EndBlock = true;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SYSCALL:
|
|
|
|
case R4300i_SPECIAL_BREAK:
|
|
|
|
EndBlock = true;
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM:
|
|
|
|
switch (Command.rt)
|
|
|
|
{
|
|
|
|
case R4300i_REGIMM_BLTZ:
|
|
|
|
case R4300i_REGIMM_BLTZAL:
|
|
|
|
TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC + 8)
|
|
|
|
{
|
|
|
|
TargetPC = (uint32_t)-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-25 07:05:42 +00:00
|
|
|
R4300iOpcode DelaySlot;
|
|
|
|
if (!g_MMU->MemoryValue32(PC + 4, DelaySlot.Value))
|
|
|
|
{
|
|
|
|
g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TargetPC == PC && !R4300iInstruction(PC, Command.Value).DelaySlotEffectsCompare(DelaySlot.Value))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
PermLoop = true;
|
|
|
|
}
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM_BGEZ:
|
|
|
|
case R4300i_REGIMM_BGEZAL:
|
|
|
|
TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC + 8)
|
|
|
|
{
|
|
|
|
TargetPC = (uint32_t)-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
|
|
|
if (Command.rs == 0)
|
|
|
|
{
|
|
|
|
TargetPC = (uint32_t)-1;
|
|
|
|
EndBlock = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-25 07:05:42 +00:00
|
|
|
R4300iOpcode DelaySlot;
|
|
|
|
if (!g_MMU->MemoryValue32(PC + 4, DelaySlot.Value))
|
|
|
|
{
|
|
|
|
g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD));
|
|
|
|
}
|
|
|
|
if (!R4300iInstruction(PC, Command.Value).DelaySlotEffectsCompare(DelaySlot.Value))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Command.rs != 0)
|
|
|
|
{
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
}
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM_BLTZL:
|
|
|
|
case R4300i_REGIMM_BGEZL:
|
|
|
|
TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
2022-07-25 07:05:42 +00:00
|
|
|
R4300iOpcode DelaySlot;
|
|
|
|
if (!g_MMU->MemoryValue32(PC + 4, DelaySlot.Value))
|
|
|
|
{
|
|
|
|
g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD));
|
|
|
|
}
|
|
|
|
if (!R4300iInstruction(PC, Command.Value).DelaySlotEffectsCompare(DelaySlot.Value))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
LikelyBranch = true;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
2022-10-10 00:22:17 +00:00
|
|
|
case R4300i_REGIMM_TEQI:
|
|
|
|
case R4300i_REGIMM_TNEI:
|
|
|
|
case R4300i_REGIMM_TGEI:
|
|
|
|
case R4300i_REGIMM_TGEIU:
|
|
|
|
case R4300i_REGIMM_TLTI:
|
|
|
|
case R4300i_REGIMM_TLTIU:
|
2019-12-17 15:08:15 +00:00
|
|
|
break;
|
2015-11-08 21:00:16 +00:00
|
|
|
default:
|
2022-07-18 08:31:00 +00:00
|
|
|
if (Command.Value == 0x0407000D)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
EndBlock = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_J:
|
|
|
|
TargetPC = (PC & 0xF0000000) + (Command.target << 2);
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
|
|
|
PermLoop = true;
|
|
|
|
}
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
|
|
|
case R4300i_JAL:
|
|
|
|
EndBlock = true;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
|
|
|
case R4300i_BEQ:
|
|
|
|
TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC + 8)
|
|
|
|
{
|
|
|
|
TargetPC = (uint32_t)-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Command.rs != 0 || Command.rt != 0)
|
|
|
|
{
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
}
|
2022-07-25 07:05:42 +00:00
|
|
|
R4300iOpcode DelaySlot;
|
2022-10-10 00:22:17 +00:00
|
|
|
if (TargetPC == PC &&
|
|
|
|
g_MMU->MemoryValue32(PC + 4, DelaySlot.Value) &&
|
2022-08-22 03:32:25 +00:00
|
|
|
!R4300iInstruction(PC, Command.Value).DelaySlotEffectsCompare(DelaySlot.Value))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
PermLoop = true;
|
|
|
|
}
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_BNE:
|
|
|
|
case R4300i_BLEZ:
|
|
|
|
case R4300i_BGTZ:
|
|
|
|
TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC + 8)
|
|
|
|
{
|
|
|
|
TargetPC = (uint32_t)-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
2022-07-25 07:05:42 +00:00
|
|
|
R4300iOpcode DelaySlot;
|
|
|
|
if (!g_MMU->MemoryValue32(PC + 4, DelaySlot.Value))
|
|
|
|
{
|
|
|
|
g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD));
|
|
|
|
}
|
|
|
|
if (!R4300iInstruction(PC, Command.Value).DelaySlotEffectsCompare(DelaySlot.Value))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_CP0:
|
|
|
|
switch (Command.rs)
|
|
|
|
{
|
2022-10-10 00:22:17 +00:00
|
|
|
case R4300i_COP0_MT:
|
2022-10-10 01:08:55 +00:00
|
|
|
case R4300i_COP0_DMT:
|
2022-10-10 00:22:17 +00:00
|
|
|
case R4300i_COP0_MF:
|
2022-10-10 01:08:55 +00:00
|
|
|
case R4300i_COP0_DMF:
|
2015-11-08 21:00:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
2016-07-04 07:51:11 +00:00
|
|
|
if ((Command.rs & 0x10) != 0)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2016-07-04 07:51:11 +00:00
|
|
|
switch (Command.funct)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
2022-10-10 00:22:17 +00:00
|
|
|
case R4300i_COP0_CO_TLBR:
|
|
|
|
case R4300i_COP0_CO_TLBWI:
|
|
|
|
case R4300i_COP0_CO_TLBWR:
|
|
|
|
case R4300i_COP0_CO_TLBP:
|
2015-11-08 21:00:16 +00:00
|
|
|
break;
|
|
|
|
case R4300i_COP0_CO_ERET:
|
|
|
|
EndBlock = true;
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_CP1:
|
|
|
|
switch (Command.fmt)
|
|
|
|
{
|
2022-10-10 00:22:17 +00:00
|
|
|
case R4300i_COP1_MF:
|
|
|
|
case R4300i_COP1_DMF:
|
|
|
|
case R4300i_COP1_CF:
|
|
|
|
case R4300i_COP1_MT:
|
|
|
|
case R4300i_COP1_DMT:
|
|
|
|
case R4300i_COP1_CT:
|
|
|
|
case R4300i_COP1_S:
|
|
|
|
case R4300i_COP1_D:
|
|
|
|
case R4300i_COP1_W:
|
|
|
|
case R4300i_COP1_L:
|
2015-11-08 21:00:16 +00:00
|
|
|
break;
|
|
|
|
case R4300i_COP1_BC:
|
2022-10-10 00:22:17 +00:00
|
|
|
switch (Command.ft)
|
|
|
|
{
|
2015-11-08 21:00:16 +00:00
|
|
|
case R4300i_COP1_BC_BCF:
|
|
|
|
case R4300i_COP1_BC_BCT:
|
|
|
|
TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC + 8)
|
|
|
|
{
|
|
|
|
TargetPC = (uint32_t)-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_BC_BCFL:
|
|
|
|
case R4300i_COP1_BC_BCTL:
|
|
|
|
TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
LikelyBranch = true;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2022-10-10 00:22:17 +00:00
|
|
|
case R4300i_ANDI:
|
|
|
|
case R4300i_ORI:
|
|
|
|
case R4300i_XORI:
|
|
|
|
case R4300i_LUI:
|
|
|
|
case R4300i_ADDI:
|
|
|
|
case R4300i_ADDIU:
|
|
|
|
case R4300i_SLTI:
|
|
|
|
case R4300i_SLTIU:
|
|
|
|
case R4300i_DADDI:
|
|
|
|
case R4300i_DADDIU:
|
|
|
|
case R4300i_LDL:
|
|
|
|
case R4300i_LDR:
|
|
|
|
case R4300i_LB:
|
|
|
|
case R4300i_LH:
|
|
|
|
case R4300i_LWL:
|
|
|
|
case R4300i_LW:
|
|
|
|
case R4300i_LBU:
|
|
|
|
case R4300i_LHU:
|
|
|
|
case R4300i_LWR:
|
|
|
|
case R4300i_LWU:
|
|
|
|
case R4300i_SB:
|
|
|
|
case R4300i_SH:
|
|
|
|
case R4300i_SWL:
|
|
|
|
case R4300i_SW:
|
|
|
|
case R4300i_SDL:
|
|
|
|
case R4300i_SDR:
|
|
|
|
case R4300i_SWR:
|
|
|
|
case R4300i_CACHE:
|
|
|
|
case R4300i_LL:
|
|
|
|
case R4300i_LWC1:
|
|
|
|
case R4300i_LDC1:
|
|
|
|
case R4300i_LD:
|
|
|
|
case R4300i_SC:
|
|
|
|
case R4300i_SWC1:
|
|
|
|
case R4300i_SDC1:
|
|
|
|
case R4300i_SD:
|
2015-11-08 21:00:16 +00:00
|
|
|
break;
|
|
|
|
case R4300i_BEQL:
|
|
|
|
TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
2022-07-25 07:05:42 +00:00
|
|
|
R4300iOpcode DelaySlot;
|
|
|
|
if (!g_MMU->MemoryValue32(PC + 4, DelaySlot.Value))
|
|
|
|
{
|
|
|
|
g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD));
|
|
|
|
}
|
|
|
|
if (!R4300iInstruction(PC, Command.Value).DelaySlotEffectsCompare(DelaySlot.Value))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Command.rs != 0 || Command.rt != 0)
|
|
|
|
{
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
}
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
LikelyBranch = true;
|
|
|
|
break;
|
|
|
|
case R4300i_BNEL:
|
|
|
|
case R4300i_BLEZL:
|
|
|
|
case R4300i_BGTZL:
|
|
|
|
TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
2022-07-25 07:05:42 +00:00
|
|
|
R4300iOpcode DelaySlot;
|
|
|
|
if (!g_MMU->MemoryValue32(PC + 4, DelaySlot.Value))
|
|
|
|
{
|
|
|
|
g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD));
|
|
|
|
}
|
|
|
|
if (!R4300iInstruction(PC, Command.Value).DelaySlotEffectsCompare(DelaySlot.Value))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LikelyBranch = true;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
|
|
|
default:
|
2022-07-18 08:31:00 +00:00
|
|
|
if (Command.Value == 0x7C1C97C0 ||
|
|
|
|
Command.Value == 0xF1F3F5F7)
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
EndBlock = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 21:00:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2010-10-23 18:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCodeBlock::Compile()
|
|
|
|
{
|
2022-08-08 10:52:51 +00:00
|
|
|
Log("====== Code block ======");
|
|
|
|
Log("Native entry point: %X", CompiledLocation());
|
|
|
|
Log("Start of block: %X", VAddrEnter());
|
|
|
|
Log("Number of sections: %d", NoOfSections());
|
|
|
|
Log("====== Recompiled code ======");
|
2015-11-08 21:00:16 +00:00
|
|
|
|
2016-07-03 05:22:14 +00:00
|
|
|
m_RecompilerOps->EnterCodeBlock();
|
2015-11-08 21:00:16 +00:00
|
|
|
if (g_System->bLinkBlocks())
|
|
|
|
{
|
2022-10-10 00:22:17 +00:00
|
|
|
while (m_EnterSection != nullptr && m_EnterSection->GenerateNativeCode(NextTest()))
|
|
|
|
;
|
2015-11-08 21:00:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_EnterSection == nullptr || !m_EnterSection->GenerateNativeCode(NextTest()))
|
2015-11-08 21:00:16 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-07-03 05:22:14 +00:00
|
|
|
m_RecompilerOps->CompileExitCode();
|
2017-01-10 07:01:59 +00:00
|
|
|
m_CompiledLocationEnd = *g_RecompPos;
|
2015-11-08 21:00:16 +00:00
|
|
|
|
2022-05-30 10:50:25 +00:00
|
|
|
uint32_t BlockSize = (VAddrLast() - VAddrFirst()) + 4;
|
|
|
|
uint8_t * BlockPtr = m_MMU.MemoryPtr(VAddrFirst(), BlockSize, true);
|
|
|
|
if (BlockPtr == nullptr)
|
|
|
|
{
|
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MD5(BlockPtr, BlockSize).get_digest(m_Hash);
|
2016-08-11 11:09:21 +00:00
|
|
|
#if defined(ANDROID) && (defined(__arm__) || defined(_M_ARM))
|
2022-10-10 00:22:17 +00:00
|
|
|
__clear_cache((uint8_t *)((uint32_t)m_CompiledLocation & ~1), m_CompiledLocationEnd);
|
2016-08-11 11:09:21 +00:00
|
|
|
#endif
|
2015-11-08 21:00:16 +00:00
|
|
|
return true;
|
2010-10-23 18:53:01 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
uint32_t CCodeBlock::NextTest()
|
2010-10-23 18:53:01 +00:00
|
|
|
{
|
2015-11-08 21:00:16 +00:00
|
|
|
uint32_t next_test = m_Test;
|
|
|
|
m_Test += 1;
|
|
|
|
return next_test;
|
2022-08-08 10:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeBlock::Log(_Printf_format_string_ const char * Text, ...)
|
|
|
|
{
|
|
|
|
if (!CDebugSettings::bRecordRecompilerAsm())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, Text);
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4996)
|
|
|
|
size_t nlen = _vscprintf(Text, args) + 1;
|
2022-10-10 00:22:17 +00:00
|
|
|
char * buffer = (char *)alloca(nlen * sizeof(char));
|
2022-08-08 10:52:51 +00:00
|
|
|
buffer[nlen - 1] = 0;
|
|
|
|
if (buffer != nullptr)
|
|
|
|
{
|
|
|
|
vsprintf(buffer, Text, args);
|
|
|
|
m_CodeLog += buffer;
|
|
|
|
m_CodeLog += "\n";
|
|
|
|
}
|
|
|
|
#pragma warning(pop)
|
|
|
|
va_end(args);
|
|
|
|
}
|