From e638b161f206eb0000e69d9e0b270fb3dd0ea9b0 Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 18 Oct 2012 20:58:24 +1100 Subject: [PATCH] more bug fixes with ABL refactoring, mario now boots --- .../N64 System/Recompiler/Code Block.cpp | 34 ++++-- .../N64 System/Recompiler/Loop Analysis.cpp | 100 ++++++++---------- 2 files changed, 70 insertions(+), 64 deletions(-) diff --git a/Source/Project64/N64 System/Recompiler/Code Block.cpp b/Source/Project64/N64 System/Recompiler/Code Block.cpp index 23ea99553..91f3e5e7b 100644 --- a/Source/Project64/N64 System/Recompiler/Code Block.cpp +++ b/Source/Project64/N64 System/Recompiler/Code Block.cpp @@ -190,7 +190,10 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection ) { CPU_Message(__FUNCTION__ ": SetContinueAddress TestPC = %X ContinuePC = %X",TestPC,ContinuePC); CurrentSection->SetContinueAddress(TestPC, ContinuePC); - SetSection(CurrentSection->m_ContinueSection, CurrentSection, ContinuePC,true,TestPC); + if (!SetSection(CurrentSection->m_ContinueSection, CurrentSection, ContinuePC,true,TestPC)) + { + ContinuePC = (DWORD)-1; + } } if (LikelyBranch) @@ -498,13 +501,31 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin case R4300i_COP1_S: case R4300i_COP1_D: case R4300i_COP1_W: case R4300i_COP1_L: break; case R4300i_COP1_BC: - TargetPC = PC + ((short)Command.offset << 2) + 4; - if (TargetPC == PC) - { + switch (Command.ft) { + case R4300i_COP1_BC_BCF: + case R4300i_COP1_BC_BCT: + TargetPC = PC + ((short)Command.offset << 2) + 4; + if (TargetPC == PC) + { + _Notify->BreakPoint(__FILE__,__LINE__); + } + ContinuePC = PC + 8; + IncludeDelaySlot = true; + break; + case R4300i_COP1_BC_BCFL: + case R4300i_COP1_BC_BCTL: + TargetPC = PC + ((short)Command.offset << 2) + 4; + if (TargetPC == PC) + { + _Notify->BreakPoint(__FILE__,__LINE__); + } + ContinuePC = PC + 8; + LikelyBranch = true; + IncludeDelaySlot = true; + break; + default: _Notify->BreakPoint(__FILE__,__LINE__); } - ContinuePC = PC + 8; - IncludeDelaySlot = true; break; default: _Notify->BreakPoint(__FILE__,__LINE__); @@ -534,6 +555,7 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin LikelyBranch = true; break; case R4300i_BNEL: + case R4300i_BGTZL: TargetPC = PC + ((short)Command.offset << 2) + 4; if (TargetPC == PC) { diff --git a/Source/Project64/N64 System/Recompiler/Loop Analysis.cpp b/Source/Project64/N64 System/Recompiler/Loop Analysis.cpp index 8dfff3abf..40e8d3bdd 100644 --- a/Source/Project64/N64 System/Recompiler/Loop Analysis.cpp +++ b/Source/Project64/N64 System/Recompiler/Loop Analysis.cpp @@ -225,7 +225,9 @@ bool LoopAnalysis::CheckLoopRegisterUsage( CCodeSection * Section) case R4300i_REGIMM_BGEZ: m_NextInstruction = DELAY_SLOT; #ifdef CHECKED_BUILD - if (Section->m_Cont.TargetPC != m_PC + 8) + if (Section->m_Cont.TargetPC != m_PC + 8 && + Section->m_ContinueSection != NULL && + Section->m_Cont.TargetPC != (DWORD)-1) { _Notify->BreakPoint(__FILE__,__LINE__); } @@ -248,7 +250,9 @@ bool LoopAnalysis::CheckLoopRegisterUsage( CCodeSection * Section) case R4300i_REGIMM_BGEZL: m_NextInstruction = LIKELY_DELAY_SLOT; #ifdef CHECKED_BUILD - if (Section->m_Cont.TargetPC != m_PC + 8) + if (Section->m_Cont.TargetPC != m_PC + 8 && + Section->m_ContinueSection != NULL && + Section->m_Cont.TargetPC != (DWORD)-1) { _Notify->BreakPoint(__FILE__,__LINE__); } @@ -462,17 +466,9 @@ bool LoopAnalysis::CheckLoopRegisterUsage( CCodeSection * Section) m_Reg.MipsRegLo(m_Command.rt) = ((short)m_Command.offset << 16); m_Reg.SetMipsRegState(m_Command.rt,CRegInfo::STATE_CONST_32); break; - case R4300i_ANDI: + case R4300i_ANDI: if (m_Command.rt == 0) { break; } - if (m_Command.rs == m_Command.rt) - { - m_Reg.SetMipsRegState(m_Command.rt,CRegInfo::STATE_UNKNOWN); - } else if (m_Reg.IsConst(m_Command.rs)) { - m_Reg.SetMipsRegState(m_Command.rt,CRegInfo::STATE_CONST_32); - m_Reg.MipsRegLo(m_Command.rt) = m_Reg.MipsRegLo(m_Command.rs) & m_Command.immediate; - } else { - m_Reg.SetMipsRegState(m_Command.rt,CRegInfo::STATE_UNKNOWN); - } + m_Reg.SetMipsRegState(m_Command.rt,CRegInfo::STATE_UNKNOWN); break; case R4300i_ORI: if (m_Command.rt == 0) { break; } @@ -542,62 +538,50 @@ bool LoopAnalysis::CheckLoopRegisterUsage( CCodeSection * Section) case R4300i_COP1_BC_BCFL: case R4300i_COP1_BC_BCTL: m_NextInstruction = LIKELY_DELAY_SLOT; - _Notify->BreakPoint(__FILE__,__LINE__); -#ifdef tofix - Section->m_Cont.TargetPC = m_PC + 8; - Section->m_Jump.TargetPC = m_PC + ((short)m_Command.offset << 2) + 4; - if (m_PC == Section->m_Jump.TargetPC) { - int EffectDelaySlot; - OPCODE NewCommand; - - if (!_MMU->LW_VAddr(m_PC + 4, NewCommand.Hex)) { - _Notify->DisplayError(GS(MSG_FAIL_LOAD_WORD)); - ExitThread(0); - } - - EffectDelaySlot = false; - if (NewCommand.op == R4300i_CP1) { - if (NewCommand.fmt == R4300i_COP1_S && (NewCommand.funct & 0x30) == 0x30 ) { - EffectDelaySlot = true; - } - if (NewCommand.fmt == R4300i_COP1_D && (NewCommand.funct & 0x30) == 0x30 ) { - EffectDelaySlot = true; - } - } - if (!EffectDelaySlot) { - Section->m_Jump.PermLoop = true; +#ifdef CHECKED_BUILD + if (Section->m_Cont.TargetPC != m_PC + 8 && + Section->m_ContinueSection != NULL && + Section->m_Cont.TargetPC != (DWORD)-1) + { + _Notify->BreakPoint(__FILE__,__LINE__); + } + if (m_PC == m_PC + ((short)m_Command.offset << 2) + 4) + { + _Notify->BreakPoint(__FILE__,__LINE__); +#ifdef tofix + if (!DelaySlotEffectsCompare(m_PC,m_Command.rs,m_Command.rt)) + { + if (!Section->m_Jump.PermLoop) + { + _Notify->BreakPoint(__FILE__,__LINE__); + } } +#endif } #endif break; case R4300i_COP1_BC_BCF: case R4300i_COP1_BC_BCT: m_NextInstruction = DELAY_SLOT; - _Notify->BreakPoint(__FILE__,__LINE__); +#ifdef CHECKED_BUILD + if (Section->m_Cont.TargetPC != m_PC + 8 && + Section->m_ContinueSection != NULL && + Section->m_Cont.TargetPC != (DWORD)-1) + { + _Notify->BreakPoint(__FILE__,__LINE__); + } + if (Section->m_Jump.TargetPC != m_PC + ((short)m_Command.offset << 2) + 4) + { + _Notify->BreakPoint(__FILE__,__LINE__); + } + if (m_PC == Section->m_Jump.TargetPC) + { + _Notify->BreakPoint(__FILE__,__LINE__); #ifdef tofix - Section->m_Cont.TargetPC = m_PC + 8; - Section->m_Jump.TargetPC = m_PC + ((short)m_Command.offset << 2) + 4; - if (m_PC == Section->m_Jump.TargetPC) { - int EffectDelaySlot; - OPCODE NewCommand; - - if (!_MMU->LW_VAddr(m_PC + 4, NewCommand.Hex)) { - _Notify->DisplayError(GS(MSG_FAIL_LOAD_WORD)); - ExitThread(0); - } - - EffectDelaySlot = false; - if (NewCommand.op == R4300i_CP1) { - if (NewCommand.fmt == R4300i_COP1_S && (NewCommand.funct & 0x30) == 0x30 ) { - EffectDelaySlot = true; - } - if (NewCommand.fmt == R4300i_COP1_D && (NewCommand.funct & 0x30) == 0x30 ) { - EffectDelaySlot = true; - } - } - if (!EffectDelaySlot) { + if (!DelaySlotEffectsCompare(m_PC,m_Command.rs,m_Command.rt)) { Section->m_Jump.PermLoop = true; } +#endif } #endif break;