Added more logging and fixes to the refactoring of ABL

This commit is contained in:
zilmar 2012-10-15 08:37:48 +11:00
parent 347d358e39
commit b83e4dcf7b
3 changed files with 93 additions and 28 deletions

View File

@ -49,6 +49,11 @@ bool CCodeBlock::SetSection ( CCodeSection * & Section, CCodeSection * CurrentSe
_Notify->BreakPoint(__FILE__,__LINE__); _Notify->BreakPoint(__FILE__,__LINE__);
} }
if (TargetPC < m_EnterSection->m_EnterPC)
{
return false;
}
if (LinkAllowed) if (LinkAllowed)
{ {
if (Section != NULL) if (Section != NULL)
@ -79,10 +84,6 @@ bool CCodeBlock::SetSection ( CCodeSection * & Section, CCodeSection * CurrentSe
Section->AddParent(CurrentSection); Section->AddParent(CurrentSection);
if (TargetPC < CurrentPC) if (TargetPC < CurrentPC)
{ {
if (TargetPC < m_EnterSection->m_EnterPC)
{
_Notify->BreakPoint(__FILE__,__LINE__);
}
CCodeSection * SplitSection = m_EnterSection; CCodeSection * SplitSection = m_EnterSection;
for (SectionMap::const_iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++) for (SectionMap::const_iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
{ {
@ -114,6 +115,7 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
{ {
CCodeSection * CurrentSection = EnterSection; CCodeSection * CurrentSection = EnterSection;
CPU_Message("Section %d",CurrentSection->m_SectionID);
for (DWORD TestPC = EnterSection->m_EnterPC, EndPC = ((EnterSection->m_EnterPC + 0x1000) & 0xFFFFF000); TestPC <= EndPC; TestPC += 4) for (DWORD TestPC = EnterSection->m_EnterPC, EndPC = ((EnterSection->m_EnterPC + 0x1000) & 0xFFFFF000); TestPC <= EndPC; TestPC += 4)
{ {
if (TestPC != EndPC) if (TestPC != EndPC)
@ -132,6 +134,7 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
CurrentSection->SetContinueAddress(TestPC - 4, TestPC); CurrentSection->SetContinueAddress(TestPC - 4, TestPC);
} }
CurrentSection = itr->second; CurrentSection = itr->second;
CPU_Message("Section %d",CurrentSection->m_SectionID);
} }
} else { } else {
CurrentSection->m_EndSection = true; CurrentSection->m_EndSection = true;
@ -139,7 +142,7 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
} }
bool LikelyBranch, EndBlock, IncludeDelaySlot; bool LikelyBranch, EndBlock, IncludeDelaySlot;
DWORD TargetPC, ContinuePC; DWORD TargetPC, ContinuePC, SectionCount = m_Sections.size();
if (!AnalyzeInstruction(TestPC, TargetPC, ContinuePC, LikelyBranch, IncludeDelaySlot, EndBlock)) if (!AnalyzeInstruction(TestPC, TargetPC, ContinuePC, LikelyBranch, IncludeDelaySlot, EndBlock))
{ {
@ -154,6 +157,7 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
if (EndBlock) if (EndBlock)
{ {
CPU_Message(__FUNCTION__ ": End Block");
CurrentSection->m_EndSection = true; CurrentSection->m_EndSection = true;
// find other sections that need compiling // find other sections that need compiling
break; break;
@ -161,6 +165,7 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
if (ContinuePC != (DWORD)-1) if (ContinuePC != (DWORD)-1)
{ {
CPU_Message(__FUNCTION__ ": SetContinueAddress TestPC = %X ContinuePC = %X",TestPC,ContinuePC);
CurrentSection->SetContinueAddress(TestPC, ContinuePC); CurrentSection->SetContinueAddress(TestPC, ContinuePC);
SetSection(CurrentSection->m_ContinueSection, CurrentSection, ContinuePC,true,TestPC); SetSection(CurrentSection->m_ContinueSection, CurrentSection, ContinuePC,true,TestPC);
} }
@ -173,32 +178,76 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
CCodeSection * JumpSection = CurrentSection->m_JumpSection; CCodeSection * JumpSection = CurrentSection->m_JumpSection;
JumpSection->SetJumpAddress(TestPC, TargetPC); JumpSection->SetJumpAddress(TestPC, TargetPC);
JumpSection->SetDelaySlot(); JumpSection->SetDelaySlot();
SetSection(JumpSection->m_JumpSection,CurrentSection->m_JumpSection,TargetPC,true,TestPC); if (!SetSection(JumpSection->m_JumpSection,CurrentSection->m_JumpSection,TargetPC,true,TestPC))
{
_Notify->BreakPoint(__FILE__,__LINE__);
}
} else {
_Notify->BreakPoint(__FILE__,__LINE__);
} }
} }
else if (TargetPC != ((DWORD)-1)) else if (TargetPC != ((DWORD)-1))
{ {
CurrentSection->SetJumpAddress(TestPC, TargetPC); CurrentSection->SetJumpAddress(TestPC, TargetPC);
SetSection(CurrentSection->m_JumpSection, CurrentSection, TargetPC,true,TestPC); if (!SetSection(CurrentSection->m_JumpSection, CurrentSection, TargetPC,true,TestPC))
{
if (ContinuePC == (DWORD)-1)
{
CurrentSection->m_EndSection = true;
}
}
} }
TestPC += IncludeDelaySlot ? 8 : 4; TestPC += IncludeDelaySlot ? 8 : 4;
//retest current section if (ContinuePC == (DWORD)-1)
CCodeSection * NewSection = m_EnterSection;
for (SectionMap::const_iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
{ {
if (itr->first > TestPC) //Find the next section
CCodeSection * NewSection = NULL;
for (SectionMap::const_iterator itr = m_SectionMap.begin(); itr != m_SectionMap.end(); itr++)
{
if (itr->first < TestPC)
{
continue;
}
NewSection = itr->second;
break;
}
if (NewSection == NULL)
{ {
break; break;
} }
NewSection = itr->second; if (CurrentSection == NewSection)
{
_Notify->BreakPoint(__FILE__,__LINE__);
}
CurrentSection = NewSection;
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;
TestPC = CurrentSection->m_EnterPC;
CPU_Message("b. Section %d",CurrentSection->m_SectionID);
}
TestPC -= 4;
} }
if (CurrentSection == NewSection)
{
_Notify->BreakPoint(__FILE__,__LINE__);
}
CurrentSection = NewSection;
TestPC -= 4;
} }
for (SectionList::iterator itr = m_Sections.begin(); itr != m_Sections.end(); itr++) for (SectionList::iterator itr = m_Sections.begin(); itr != m_Sections.end(); itr++)
@ -253,7 +302,6 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin
IncludeDelaySlot = false; IncludeDelaySlot = false;
EndBlock = false; EndBlock = false;
OPCODE Command; OPCODE Command;
if (!_MMU->LW_VAddr(PC, Command.Hex)) { if (!_MMU->LW_VAddr(PC, Command.Hex)) {
_Notify->BreakPoint(__FILE__,__LINE__); _Notify->BreakPoint(__FILE__,__LINE__);
@ -262,7 +310,7 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin
#ifdef _DEBUG #ifdef _DEBUG
char * Name = R4300iOpcodeName(Command.Hex,PC); char * Name = R4300iOpcodeName(Command.Hex,PC);
Name = Name; CPU_Message(" 0x%08X %s",PC,Name);
#endif #endif
switch (Command.op) switch (Command.op)
{ {
@ -288,13 +336,23 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin
EndBlock = true; EndBlock = true;
IncludeDelaySlot = true; IncludeDelaySlot = true;
break; break;
case R4300i_SPECIAL_BREAK:
EndBlock = true;
break;
default: default:
_Notify->BreakPoint(__FILE__,__LINE__); _Notify->BreakPoint(__FILE__,__LINE__);
return false; return false;
} }
break; break;
case R4300i_REGIMM: case R4300i_REGIMM:
switch (Command.rt) { switch (Command.rt)
{
case R4300i_REGIMM_BLTZ:
TargetPC = PC + ((short)Command.offset << 2) + 4;
ContinuePC = PC + 8;
IncludeDelaySlot = true;
break;
case R4300i_REGIMM_BGEZ:
case R4300i_REGIMM_BGEZAL: case R4300i_REGIMM_BGEZAL:
TargetPC = PC + ((short)Command.offset << 2) + 4; TargetPC = PC + ((short)Command.offset << 2) + 4;
IncludeDelaySlot = true; IncludeDelaySlot = true;
@ -319,11 +377,14 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin
return false; return false;
} }
break; break;
case R4300i_J:
TargetPC = (PC & 0xF0000000) + (Command.target << 2);
IncludeDelaySlot = true;
break;
case R4300i_JAL: case R4300i_JAL:
EndBlock = true; EndBlock = true;
IncludeDelaySlot = true; IncludeDelaySlot = true;
break; break;
break;
case R4300i_BEQ: case R4300i_BEQ:
TargetPC = PC + ((short)Command.offset << 2) + 4; TargetPC = PC + ((short)Command.offset << 2) + 4;
if (Command.rs != 0 || Command.rt != 0) if (Command.rs != 0 || Command.rt != 0)
@ -351,6 +412,9 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin
case R4300i_COP0_CO_TLBR: case R4300i_COP0_CO_TLBWI: case R4300i_COP0_CO_TLBR: case R4300i_COP0_CO_TLBWI:
case R4300i_COP0_CO_TLBWR: case R4300i_COP0_CO_TLBP: case R4300i_COP0_CO_TLBWR: case R4300i_COP0_CO_TLBP:
break; break;
case R4300i_COP0_CO_ERET:
EndBlock = true;
break;
default: default:
_Notify->BreakPoint(__FILE__,__LINE__); _Notify->BreakPoint(__FILE__,__LINE__);
return false; return false;
@ -365,6 +429,7 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin
case R4300i_CP1: case R4300i_CP1:
switch (Command.fmt) { switch (Command.fmt) {
case R4300i_COP1_MF: case R4300i_COP1_CF: case R4300i_COP1_MT: case R4300i_COP1_CT: case R4300i_COP1_MF: case R4300i_COP1_CF: case R4300i_COP1_MT: case R4300i_COP1_CT:
case R4300i_COP1_S: case R4300i_COP1_D: case R4300i_COP1_W: case R4300i_COP1_L:
break; break;
default: default:
_Notify->BreakPoint(__FILE__,__LINE__); _Notify->BreakPoint(__FILE__,__LINE__);

View File

@ -88,6 +88,7 @@ CCodeSection::CCodeSection( CCodeBlock * CodeBlock, DWORD EnterPC, DWORD ID, boo
m_EndSection(false), m_EndSection(false),
m_DelaySlot(false) m_DelaySlot(false)
{ {
CPU_Message(__FUNCTION__ ": ID %d EnterPC 0x%08X",ID,EnterPC);
} }
CCodeSection::~CCodeSection( void ) CCodeSection::~CCodeSection( void )
@ -1657,7 +1658,7 @@ void CCodeSection::UnlinkParent( CCodeSection * Parent, bool ContinueSection )
Parent->m_JumpSection = NULL; Parent->m_JumpSection = NULL;
} }
bool bDelete = false; bool bRemove = false;
if (m_ParentSection.size() > 0) if (m_ParentSection.size() > 0)
{ {
if (!m_BlockInfo->SectionAccessible(m_SectionID)) if (!m_BlockInfo->SectionAccessible(m_SectionID))
@ -1683,12 +1684,12 @@ void CCodeSection::UnlinkParent( CCodeSection * Parent, bool ContinueSection )
ParentIter->m_JumpSection = NULL; ParentIter->m_JumpSection = NULL;
} }
} }
bDelete = true; bRemove = true;
} }
} else { } else {
bDelete = true; bRemove = true;
} }
if (bDelete) if (bRemove)
{ {
if (m_JumpSection != NULL) if (m_JumpSection != NULL)
{ {
@ -1698,7 +1699,6 @@ void CCodeSection::UnlinkParent( CCodeSection * Parent, bool ContinueSection )
{ {
m_ContinueSection->UnlinkParent(this,true); m_ContinueSection->UnlinkParent(this,true);
} }
delete this;
} }
} }

View File

@ -102,7 +102,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage( CCodeSection * Section, DWORD Test, D
_Notify->BreakPoint(__FILE__,__LINE__); _Notify->BreakPoint(__FILE__,__LINE__);
return false; return false;
} }
//CPU_Message(" %08X: %s",m_PC,R4300iOpcodeName(m_Command.Hex,m_PC)); CPU_Message(" %08X: %s",m_PC,R4300iOpcodeName(m_Command.Hex,m_PC));
switch (m_Command.op) { switch (m_Command.op) {
case R4300i_SPECIAL: case R4300i_SPECIAL:
switch (m_Command.funct) { switch (m_Command.funct) {