2010-10-23 18:53:01 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
2012-09-25 05:58:06 +00:00
|
|
|
CCodeBlock::CCodeBlock(DWORD VAddrEnter, BYTE * RecompPos) :
|
2010-10-23 18:53:01 +00:00
|
|
|
m_VAddrEnter(VAddrEnter),
|
|
|
|
m_VAddrFirst(VAddrEnter),
|
|
|
|
m_VAddrLast(VAddrEnter),
|
|
|
|
m_CompiledLocation(RecompPos),
|
2012-10-14 01:05:52 +00:00
|
|
|
m_Test(1),
|
|
|
|
m_EnterSection(new CCodeSection(this, VAddrEnter, 1, false))
|
2010-10-23 18:53:01 +00:00
|
|
|
{
|
2012-10-14 01:05:52 +00:00
|
|
|
if (m_EnterSection)
|
|
|
|
{
|
|
|
|
m_EnterSection->AddParent(NULL);
|
|
|
|
m_Sections.push_back(m_EnterSection);
|
|
|
|
}
|
|
|
|
|
2012-09-24 22:07:51 +00:00
|
|
|
if (_TransVaddr->VAddrToRealAddr(VAddrEnter,*(reinterpret_cast<void **>(&m_MemLocation[0]))))
|
|
|
|
{
|
|
|
|
m_MemLocation[1] = m_MemLocation[0] + 1;
|
|
|
|
m_MemContents[0] = *m_MemLocation[0];
|
|
|
|
m_MemContents[1] = *m_MemLocation[1];
|
|
|
|
} else {
|
|
|
|
memset(m_MemLocation,0,sizeof(m_MemLocation));
|
|
|
|
memset(m_MemContents,0,sizeof(m_MemContents));
|
|
|
|
}
|
2010-10-23 18:53:01 +00:00
|
|
|
AnalyseBlock();
|
|
|
|
}
|
|
|
|
|
2012-10-14 06:33:51 +00:00
|
|
|
CCodeBlock::~CCodeBlock()
|
|
|
|
{
|
|
|
|
for (SectionList::iterator itr = m_Sections.begin(); itr != m_Sections.end(); itr++)
|
|
|
|
{
|
|
|
|
CCodeSection * Section = *itr;
|
|
|
|
delete Section;
|
|
|
|
}
|
|
|
|
m_Sections.clear();
|
|
|
|
}
|
|
|
|
|
2012-10-14 01:05:52 +00:00
|
|
|
bool CCodeBlock::SetSection ( CCodeSection * & Section, CCodeSection * CurrentSection, DWORD TargetPC, bool LinkAllowed, DWORD CurrentPC )
|
|
|
|
{
|
|
|
|
if (Section != NULL)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
|
2012-10-17 09:04:11 +00:00
|
|
|
if (TargetPC >= ((CurrentPC + 0x1000) & 0xFFFFF000))
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
2012-10-15 07:41:30 +00:00
|
|
|
return false;
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-14 21:37:48 +00:00
|
|
|
if (TargetPC < m_EnterSection->m_EnterPC)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-14 01:05:52 +00:00
|
|
|
if (LinkAllowed)
|
|
|
|
{
|
|
|
|
if (Section != NULL)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
SectionMap::const_iterator itr = m_SectionMap.find(TargetPC);
|
|
|
|
if (itr != m_SectionMap.end())
|
|
|
|
{
|
|
|
|
Section = itr->second;
|
|
|
|
Section->AddParent(CurrentSection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Section == NULL)
|
|
|
|
{
|
|
|
|
Section = new CCodeSection(this,TargetPC,m_Sections.size() + 1,LinkAllowed);
|
|
|
|
if (Section == NULL)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_Sections.push_back(Section);
|
|
|
|
if (LinkAllowed)
|
|
|
|
{
|
|
|
|
m_SectionMap.insert(SectionMap::value_type(TargetPC,Section));
|
|
|
|
}
|
|
|
|
Section->AddParent(CurrentSection);
|
2012-10-15 07:41:30 +00:00
|
|
|
if (TargetPC < CurrentPC && TargetPC != m_VAddrEnter)
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
|
|
|
CCodeSection * SplitSection = m_EnterSection;
|
|
|
|
for (SectionMap::const_iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
|
|
|
|
{
|
|
|
|
if (itr->first >= TargetPC)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SplitSection = itr->second;
|
|
|
|
}
|
2012-10-17 09:04:11 +00:00
|
|
|
if (SplitSection->m_EndPC == (DWORD)-1)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
if (SplitSection->m_EndPC >= TargetPC)
|
|
|
|
{
|
|
|
|
CCodeSection * BaseSection = Section;
|
|
|
|
BaseSection->m_EndPC = SplitSection->m_EndPC;
|
|
|
|
BaseSection->SetJumpAddress(SplitSection->m_Jump.JumpPC, SplitSection->m_Jump.TargetPC,SplitSection->m_Jump.PermLoop);
|
|
|
|
BaseSection->m_JumpSection = SplitSection->m_JumpSection;
|
|
|
|
BaseSection->SetContinueAddress(SplitSection->m_Cont.JumpPC,SplitSection->m_Cont.TargetPC);
|
|
|
|
BaseSection->m_ContinueSection = SplitSection->m_ContinueSection;
|
|
|
|
BaseSection->m_JumpSection->SwitchParent(SplitSection,BaseSection);
|
|
|
|
BaseSection->m_ContinueSection->SwitchParent(SplitSection,BaseSection);
|
|
|
|
BaseSection->AddParent(SplitSection);
|
2012-10-14 01:05:52 +00:00
|
|
|
|
2012-10-17 09:04:11 +00:00
|
|
|
SplitSection->m_EndPC = TargetPC - 4;
|
|
|
|
SplitSection->m_JumpSection = NULL;
|
|
|
|
SplitSection->m_ContinueSection = BaseSection;
|
|
|
|
SplitSection->SetContinueAddress(TargetPC - 4, TargetPC);
|
|
|
|
SplitSection->SetJumpAddress((DWORD)-1,(DWORD)-1,false);
|
|
|
|
}
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
|
|
|
|
{
|
|
|
|
CCodeSection * CurrentSection = EnterSection;
|
|
|
|
|
2012-10-14 21:37:48 +00:00
|
|
|
CPU_Message("Section %d",CurrentSection->m_SectionID);
|
2012-10-14 06:33:51 +00:00
|
|
|
for (DWORD TestPC = EnterSection->m_EnterPC, EndPC = ((EnterSection->m_EnterPC + 0x1000) & 0xFFFFF000); TestPC <= EndPC; TestPC += 4)
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
2012-10-14 06:33:51 +00:00
|
|
|
if (TestPC != EndPC)
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
|
|
|
SectionMap::const_iterator itr = m_SectionMap.find(TestPC);
|
|
|
|
if (itr != m_SectionMap.end() && CurrentSection != itr->second)
|
|
|
|
{
|
|
|
|
if (CurrentSection->m_ContinueSection != NULL &&
|
|
|
|
CurrentSection->m_ContinueSection != itr->second)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
if (CurrentSection->m_ContinueSection == NULL)
|
|
|
|
{
|
|
|
|
SetSection(CurrentSection->m_ContinueSection, CurrentSection, TestPC,true,TestPC);
|
|
|
|
CurrentSection->SetContinueAddress(TestPC - 4, TestPC);
|
|
|
|
}
|
2012-10-17 09:04:11 +00:00
|
|
|
CurrentSection->m_EndPC = TestPC - 4;
|
2012-10-14 01:05:52 +00:00
|
|
|
CurrentSection = itr->second;
|
2012-10-14 21:37:48 +00:00
|
|
|
CPU_Message("Section %d",CurrentSection->m_SectionID);
|
2012-10-15 07:41:30 +00:00
|
|
|
if (EnterSection != m_EnterSection)
|
|
|
|
{
|
|
|
|
if (CurrentSection->m_JumpSection != NULL ||
|
|
|
|
CurrentSection->m_ContinueSection != NULL ||
|
|
|
|
CurrentSection->m_EndSection)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
2012-10-14 06:33:51 +00:00
|
|
|
} else {
|
|
|
|
CurrentSection->m_EndSection = true;
|
|
|
|
break;
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-15 07:41:30 +00:00
|
|
|
bool LikelyBranch, EndBlock, IncludeDelaySlot, PermLoop;
|
2012-10-14 21:37:48 +00:00
|
|
|
DWORD TargetPC, ContinuePC, SectionCount = m_Sections.size();
|
2012-10-14 01:05:52 +00:00
|
|
|
|
2012-10-17 09:04:11 +00:00
|
|
|
CurrentSection->m_EndPC = TestPC;
|
2012-10-15 07:41:30 +00:00
|
|
|
if (!AnalyzeInstruction(TestPC, TargetPC, ContinuePC, LikelyBranch, IncludeDelaySlot, EndBlock, PermLoop))
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TargetPC == (DWORD)-1 && !EndBlock)
|
|
|
|
{
|
2012-10-17 09:04:11 +00:00
|
|
|
if (ContinuePC != (DWORD)-1)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
2012-10-14 01:05:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EndBlock)
|
|
|
|
{
|
2012-10-14 21:37:48 +00:00
|
|
|
CPU_Message(__FUNCTION__ ": End Block");
|
2012-10-14 01:05:52 +00:00
|
|
|
CurrentSection->m_EndSection = true;
|
|
|
|
// find other sections that need compiling
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ContinuePC != (DWORD)-1)
|
|
|
|
{
|
2012-10-14 21:37:48 +00:00
|
|
|
CPU_Message(__FUNCTION__ ": SetContinueAddress TestPC = %X ContinuePC = %X",TestPC,ContinuePC);
|
2012-10-14 01:05:52 +00:00
|
|
|
CurrentSection->SetContinueAddress(TestPC, ContinuePC);
|
|
|
|
SetSection(CurrentSection->m_ContinueSection, CurrentSection, ContinuePC,true,TestPC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LikelyBranch)
|
|
|
|
{
|
2012-10-17 09:04:11 +00:00
|
|
|
CPU_Message(__FUNCTION__ ": SetJumpAddress TestPC = %X Target = %X",TestPC,TestPC + 4);
|
2012-10-15 07:41:30 +00:00
|
|
|
CurrentSection->SetJumpAddress(TestPC, TestPC + 4,false);
|
2012-10-14 01:05:52 +00:00
|
|
|
if (SetSection(CurrentSection->m_JumpSection, CurrentSection, TestPC + 4,false,TestPC))
|
|
|
|
{
|
|
|
|
CCodeSection * JumpSection = CurrentSection->m_JumpSection;
|
2012-10-17 09:04:11 +00:00
|
|
|
JumpSection->m_EndPC = TestPC + 4;
|
2012-10-15 07:41:30 +00:00
|
|
|
JumpSection->SetJumpAddress(TestPC, TargetPC,false);
|
2012-10-14 01:05:52 +00:00
|
|
|
JumpSection->SetDelaySlot();
|
2012-10-15 21:47:05 +00:00
|
|
|
SetSection(JumpSection->m_JumpSection,CurrentSection->m_JumpSection,TargetPC,true,TestPC);
|
2012-10-14 21:37:48 +00:00
|
|
|
} else {
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (TargetPC != ((DWORD)-1))
|
|
|
|
{
|
2012-10-17 09:04:11 +00:00
|
|
|
CPU_Message(__FUNCTION__ ": SetJumpAddress TestPC = %X Target = %X",TestPC,TargetPC);
|
2012-10-15 07:41:30 +00:00
|
|
|
CurrentSection->SetJumpAddress(TestPC, TargetPC,PermLoop);
|
|
|
|
if (PermLoop || !SetSection(CurrentSection->m_JumpSection, CurrentSection, TargetPC,true,TestPC))
|
2012-10-14 21:37:48 +00:00
|
|
|
{
|
|
|
|
if (ContinuePC == (DWORD)-1)
|
|
|
|
{
|
|
|
|
CurrentSection->m_EndSection = true;
|
|
|
|
}
|
|
|
|
}
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
2012-10-14 21:37:48 +00:00
|
|
|
|
2012-10-14 01:05:52 +00:00
|
|
|
TestPC += IncludeDelaySlot ? 8 : 4;
|
|
|
|
|
2012-10-14 21:37:48 +00:00
|
|
|
if (ContinuePC == (DWORD)-1)
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
2012-10-14 21:37:48 +00:00
|
|
|
//Find the next section
|
|
|
|
CCodeSection * NewSection = NULL;
|
|
|
|
for (SectionMap::const_iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
2012-10-14 21:37:48 +00:00
|
|
|
if (itr->first < TestPC)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
NewSection = itr->second;
|
2012-10-14 01:05:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-10-14 21:37:48 +00:00
|
|
|
if (NewSection == NULL)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (CurrentSection == NewSection)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
CurrentSection = NewSection;
|
2012-10-15 21:47:05 +00:00
|
|
|
if (CurrentSection->m_JumpSection != NULL ||
|
|
|
|
CurrentSection->m_ContinueSection != NULL ||
|
|
|
|
CurrentSection->m_EndSection)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2012-10-14 21:37:48 +00:00
|
|
|
TestPC = CurrentSection->m_EnterPC;
|
|
|
|
CPU_Message("a. Section %d",CurrentSection->m_SectionID);
|
|
|
|
TestPC -= 4;
|
|
|
|
} else {
|
|
|
|
//retest current section if we added a section
|
|
|
|
if (SectionCount != m_Sections.size())
|
|
|
|
{
|
|
|
|
CCodeSection * NewSection = m_EnterSection;
|
|
|
|
for (SectionMap::const_iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
|
|
|
|
{
|
|
|
|
if (itr->first > TestPC)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NewSection = itr->second;
|
|
|
|
}
|
|
|
|
if (CurrentSection == NewSection)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
CurrentSection = NewSection;
|
2012-10-15 21:47:05 +00:00
|
|
|
if (CurrentSection->m_JumpSection != NULL ||
|
|
|
|
CurrentSection->m_ContinueSection != NULL ||
|
|
|
|
CurrentSection->m_EndSection)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2012-10-14 21:37:48 +00:00
|
|
|
TestPC = CurrentSection->m_EnterPC;
|
|
|
|
CPU_Message("b. Section %d",CurrentSection->m_SectionID);
|
|
|
|
}
|
|
|
|
TestPC -= 4;
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (SectionList::iterator itr = m_Sections.begin(); itr != m_Sections.end(); itr++)
|
|
|
|
{
|
|
|
|
CCodeSection * Section = *itr;
|
|
|
|
if (Section->m_JumpSection != NULL ||
|
|
|
|
Section->m_ContinueSection != NULL ||
|
|
|
|
Section->m_EndSection)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!CreateBlockLinkage(Section)) { return false; }
|
|
|
|
break;
|
|
|
|
}
|
2012-10-17 09:04:11 +00:00
|
|
|
if (CurrentSection->m_EndPC == (DWORD)-1)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
2012-10-14 01:05:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeBlock::DetermineLoops ( void )
|
|
|
|
{
|
|
|
|
for (SectionMap::iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
|
|
|
|
{
|
|
|
|
CCodeSection * Section = itr->second;
|
|
|
|
|
|
|
|
DWORD Test = NextTest();
|
|
|
|
Section->DetermineLoop(Test,Test,Section->m_SectionID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCodeBlock::LogSectionInfo ( void )
|
|
|
|
{
|
|
|
|
for (SectionList::iterator itr = m_Sections.begin(); itr != m_Sections.end(); itr++)
|
|
|
|
{
|
|
|
|
CCodeSection * Section = *itr;
|
|
|
|
Section->DisplaySectionInformation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-23 18:53:01 +00:00
|
|
|
bool CCodeBlock::AnalyseBlock ( void )
|
|
|
|
{
|
2012-10-14 01:05:52 +00:00
|
|
|
if (!bLinkBlocks()) { return true; }
|
|
|
|
if (!CreateBlockLinkage(m_EnterSection)) { return false; }
|
|
|
|
DetermineLoops();
|
2012-10-15 21:47:05 +00:00
|
|
|
LogSectionInfo();
|
2012-10-14 01:05:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-15 07:41:30 +00:00
|
|
|
bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & ContinuePC, bool & LikelyBranch, bool & IncludeDelaySlot, bool & EndBlock, bool & PermLoop )
|
2012-10-14 01:05:52 +00:00
|
|
|
{
|
|
|
|
TargetPC = (DWORD)-1;
|
|
|
|
ContinuePC = (DWORD)-1;
|
|
|
|
LikelyBranch = false;
|
|
|
|
IncludeDelaySlot = false;
|
|
|
|
EndBlock = false;
|
2012-10-15 07:41:30 +00:00
|
|
|
PermLoop = false;
|
2012-10-14 01:05:52 +00:00
|
|
|
|
|
|
|
OPCODE Command;
|
|
|
|
if (!_MMU->LW_VAddr(PC, Command.Hex)) {
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
char * Name = R4300iOpcodeName(Command.Hex,PC);
|
2012-10-14 21:37:48 +00:00
|
|
|
CPU_Message(" 0x%08X %s",PC,Name);
|
2012-10-14 01:05:52 +00:00
|
|
|
#endif
|
|
|
|
switch (Command.op)
|
|
|
|
{
|
|
|
|
case R4300i_SPECIAL:
|
|
|
|
switch (Command.funct)
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
break;
|
2012-10-15 21:47:05 +00:00
|
|
|
case R4300i_SPECIAL_JALR:
|
2012-10-14 01:05:52 +00:00
|
|
|
case R4300i_SPECIAL_JR:
|
|
|
|
EndBlock = true;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
2012-10-14 21:37:48 +00:00
|
|
|
case R4300i_SPECIAL_BREAK:
|
|
|
|
EndBlock = true;
|
|
|
|
break;
|
2012-10-14 01:05:52 +00:00
|
|
|
default:
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM:
|
2012-10-14 21:37:48 +00:00
|
|
|
switch (Command.rt)
|
|
|
|
{
|
|
|
|
case R4300i_REGIMM_BLTZ:
|
|
|
|
TargetPC = PC + ((short)Command.offset << 2) + 4;
|
2012-10-15 07:41:30 +00:00
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
2012-10-14 21:37:48 +00:00
|
|
|
ContinuePC = PC + 8;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM_BGEZ:
|
2012-10-14 01:05:52 +00:00
|
|
|
case R4300i_REGIMM_BGEZAL:
|
|
|
|
TargetPC = PC + ((short)Command.offset << 2) + 4;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
if (Command.rs != 0)
|
|
|
|
{
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
}
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
|
|
|
if (Command.rs == 0)
|
|
|
|
{
|
|
|
|
TargetPC = (DWORD)-1;
|
|
|
|
EndBlock = true;
|
|
|
|
} else {
|
|
|
|
//if delay slot effects compare;
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-10-15 21:47:05 +00:00
|
|
|
case R4300i_REGIMM_BLTZL:
|
|
|
|
case R4300i_REGIMM_BGEZL:
|
|
|
|
TargetPC = PC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
LikelyBranch = true;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
2012-10-14 01:05:52 +00:00
|
|
|
default:
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2012-10-14 21:37:48 +00:00
|
|
|
case R4300i_J:
|
|
|
|
TargetPC = (PC & 0xF0000000) + (Command.target << 2);
|
2012-10-15 07:41:30 +00:00
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
|
|
|
PermLoop = true;
|
|
|
|
}
|
2012-10-14 21:37:48 +00:00
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
2012-10-14 06:33:51 +00:00
|
|
|
case R4300i_JAL:
|
|
|
|
EndBlock = true;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
2012-10-14 01:05:52 +00:00
|
|
|
case R4300i_BEQ:
|
|
|
|
TargetPC = PC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Command.rs != 0 || Command.rt != 0)
|
|
|
|
{
|
|
|
|
ContinuePC = PC + 8;
|
2012-10-17 11:34:55 +00:00
|
|
|
} else if (TargetPC == PC) {
|
|
|
|
PermLoop = true;
|
2012-10-14 01:05:52 +00:00
|
|
|
}
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
|
|
|
case R4300i_BNE:
|
2012-10-14 06:33:51 +00:00
|
|
|
case R4300i_BLEZ:
|
|
|
|
case R4300i_BGTZ:
|
2012-10-14 01:05:52 +00:00
|
|
|
TargetPC = PC + ((short)Command.offset << 2) + 4;
|
2012-10-15 07:41:30 +00:00
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
2012-10-14 01:05:52 +00:00
|
|
|
ContinuePC = PC + 8;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
|
|
|
case R4300i_CP0:
|
|
|
|
switch (Command.rs)
|
|
|
|
{
|
|
|
|
case R4300i_COP0_MT: case R4300i_COP0_MF:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ( (Command.rs & 0x10 ) != 0 )
|
|
|
|
{
|
|
|
|
switch( Command.funct ) {
|
|
|
|
case R4300i_COP0_CO_TLBR: case R4300i_COP0_CO_TLBWI:
|
|
|
|
case R4300i_COP0_CO_TLBWR: case R4300i_COP0_CO_TLBP:
|
|
|
|
break;
|
2012-10-14 21:37:48 +00:00
|
|
|
case R4300i_COP0_CO_ERET:
|
|
|
|
EndBlock = true;
|
|
|
|
break;
|
2012-10-14 01:05:52 +00:00
|
|
|
default:
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_CP1:
|
2012-10-14 06:33:51 +00:00
|
|
|
switch (Command.fmt) {
|
|
|
|
case R4300i_COP1_MF: case R4300i_COP1_CF: case R4300i_COP1_MT: case R4300i_COP1_CT:
|
2012-10-14 21:37:48 +00:00
|
|
|
case R4300i_COP1_S: case R4300i_COP1_D: case R4300i_COP1_W: case R4300i_COP1_L:
|
2012-10-14 06:33:51 +00:00
|
|
|
break;
|
2012-10-15 21:47:05 +00:00
|
|
|
case R4300i_COP1_BC:
|
|
|
|
TargetPC = PC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
2012-10-14 06:33:51 +00:00
|
|
|
default:
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2012-10-14 01:05:52 +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_LB: case R4300i_LH:
|
|
|
|
case R4300i_LW: case R4300i_LWL: case R4300i_LWR: case R4300i_LDL:
|
|
|
|
case R4300i_LDR: case R4300i_LBU: case R4300i_LHU: case R4300i_LD:
|
|
|
|
case R4300i_LWC1: case R4300i_LDC1: case R4300i_CACHE: case R4300i_SB:
|
|
|
|
case R4300i_SH: case R4300i_SW: case R4300i_SWR: case R4300i_SWL:
|
|
|
|
case R4300i_SWC1: case R4300i_SDC1: case R4300i_SD:
|
|
|
|
break;
|
2012-10-15 07:41:30 +00:00
|
|
|
case R4300i_BEQL:
|
|
|
|
TargetPC = PC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
if (Command.rs != 0 || Command.rt != 0)
|
|
|
|
{
|
|
|
|
ContinuePC = PC + 8;
|
|
|
|
}
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
LikelyBranch = true;
|
|
|
|
break;
|
2012-10-14 01:05:52 +00:00
|
|
|
case R4300i_BNEL:
|
|
|
|
TargetPC = PC + ((short)Command.offset << 2) + 4;
|
2012-10-15 07:41:30 +00:00
|
|
|
if (TargetPC == PC)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
2012-10-14 01:05:52 +00:00
|
|
|
ContinuePC = PC + 8;
|
|
|
|
LikelyBranch = true;
|
|
|
|
IncludeDelaySlot = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
return false;
|
2010-10-23 18:53:01 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCodeBlock::Compile()
|
|
|
|
{
|
2012-09-25 05:58:06 +00:00
|
|
|
CPU_Message("====== Code Block ======");
|
2010-10-23 18:53:01 +00:00
|
|
|
CPU_Message("x86 code at: %X",CompiledLocation());
|
|
|
|
CPU_Message("Start of Block: %X",VAddrEnter() );
|
|
|
|
CPU_Message("No of Sections: %d",NoOfSections() );
|
|
|
|
CPU_Message("====== recompiled code ======");
|
|
|
|
|
2012-09-25 05:58:06 +00:00
|
|
|
EnterCodeBlock();
|
2010-10-23 18:53:01 +00:00
|
|
|
|
2012-09-25 05:58:06 +00:00
|
|
|
if (_SyncSystem) {
|
|
|
|
//if ((DWORD)BlockInfo.CompiledLocation == 0x60A7B73B) { X86BreakPoint(__FILE__,__LINE__); }
|
|
|
|
//MoveConstToVariable((DWORD)BlockInfo.CompiledLocation,&CurrentBlock,"CurrentBlock");
|
|
|
|
}
|
2010-10-23 18:53:01 +00:00
|
|
|
|
2012-09-25 05:58:06 +00:00
|
|
|
if (bLinkBlocks()) {
|
2012-10-14 01:05:52 +00:00
|
|
|
while (m_EnterSection->GenerateX86Code(NextTest()));
|
2012-09-25 05:58:06 +00:00
|
|
|
} else {
|
2012-10-14 01:05:52 +00:00
|
|
|
if (!m_EnterSection->GenerateX86Code(NextTest()))
|
2012-09-25 05:58:06 +00:00
|
|
|
{
|
|
|
|
return false;
|
2010-10-23 18:53:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CompileExitCode();
|
|
|
|
|
|
|
|
DWORD PAddr;
|
|
|
|
_TransVaddr->TranslateVaddr(VAddrFirst(),PAddr);
|
|
|
|
MD5(_MMU->Rdram() + PAddr,(VAddrLast() - VAddrFirst()) + 4).get_digest(m_Hash);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCodeBlock::CompileExitCode ( void )
|
|
|
|
{
|
|
|
|
for (EXIT_LIST::iterator ExitIter = m_ExitInfo.begin(); ExitIter != m_ExitInfo.end(); ExitIter++)
|
|
|
|
{
|
|
|
|
CPU_Message("");
|
|
|
|
CPU_Message(" $Exit_%d",ExitIter->ID);
|
|
|
|
SetJump32(ExitIter->JumpLoc,(DWORD *)m_RecompPos);
|
|
|
|
m_NextInstruction = ExitIter->NextInstruction;
|
2012-10-14 01:05:52 +00:00
|
|
|
m_EnterSection->CompileExit((DWORD)-1, ExitIter->TargetPC,ExitIter->ExitRegSet,ExitIter->reason,true,NULL);
|
2010-10-23 18:53:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD CCodeBlock::NextTest ( void )
|
|
|
|
{
|
2012-10-14 01:05:52 +00:00
|
|
|
return InterlockedIncrement(&m_Test);
|
2012-10-16 11:17:18 +00:00
|
|
|
}
|