diff --git a/Source/Project64/N64 System/Recompiler/Code Block.cpp b/Source/Project64/N64 System/Recompiler/Code Block.cpp index 97d677828..5e239f6e6 100644 --- a/Source/Project64/N64 System/Recompiler/Code Block.cpp +++ b/Source/Project64/N64 System/Recompiler/Code Block.cpp @@ -243,11 +243,33 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection ) CurrentSection->SetJumpAddress(TestPC, TestPC + 4,false); if (SetSection(CurrentSection->m_JumpSection, CurrentSection, TestPC + 4,false,TestPC)) { + bool BranchLikelyBranch, BranchEndBlock, BranchIncludeDelaySlot, BranchPermLoop; + DWORD BranchTargetPC, BranchContinuePC; + CCodeSection * JumpSection = CurrentSection->m_JumpSection; + if (!AnalyzeInstruction(JumpSection->m_EnterPC, BranchTargetPC, BranchContinuePC, BranchLikelyBranch, BranchIncludeDelaySlot, BranchEndBlock, BranchPermLoop)) + { + g_Notify->BreakPoint(__FILE__,__LINE__); + return false; + } + + if (BranchLikelyBranch || BranchIncludeDelaySlot || BranchPermLoop) + { + g_Notify->BreakPoint(__FILE__,__LINE__); + return false; + } + JumpSection->m_EndPC = TestPC + 4; - JumpSection->SetJumpAddress(TestPC, TargetPC,false); + if (BranchEndBlock) + { + CPU_Message(__FUNCTION__ ": Jump End Block"); + JumpSection->m_EndSection = true; + TargetPC = (DWORD)-1; + } else { + JumpSection->SetJumpAddress(TestPC, TargetPC,false); + } JumpSection->SetDelaySlot(); - SetSection(JumpSection->m_JumpSection,CurrentSection->m_JumpSection,TargetPC,true,TestPC); + SetSection(JumpSection->m_JumpSection,JumpSection,TargetPC,true,TestPC); } else { g_Notify->BreakPoint(__FILE__,__LINE__); } diff --git a/Source/Project64/N64 System/Recompiler/Loop Analysis.cpp b/Source/Project64/N64 System/Recompiler/Loop Analysis.cpp index c5ac32872..2c7e8c1e1 100644 --- a/Source/Project64/N64 System/Recompiler/Loop Analysis.cpp +++ b/Source/Project64/N64 System/Recompiler/Loop Analysis.cpp @@ -10,7 +10,9 @@ ****************************************************************************/ #include "stdafx.h" +#ifndef EXTERNAL_RELEASE #define CHECKED_BUILD 1 +#endif bool DelaySlotEffectsCompare ( DWORD PC, DWORD Reg1, DWORD Reg2 ); @@ -183,8 +185,8 @@ bool LoopAnalysis::CheckLoopRegisterUsage( CCodeSection * Section) case R4300i_SPECIAL_SRAV: SPECIAL_SRAV(); break; case R4300i_SPECIAL_JR: SPECIAL_JR(); break; case R4300i_SPECIAL_JALR: SPECIAL_JALR(); break; - case R4300i_SPECIAL_SYSCALL: SPECIAL_SYSCALL(); break; - case R4300i_SPECIAL_BREAK: SPECIAL_BREAK(); break; + case R4300i_SPECIAL_SYSCALL: SPECIAL_SYSCALL(Section); break; + case R4300i_SPECIAL_BREAK: SPECIAL_BREAK(Section); break; case R4300i_SPECIAL_MFHI: SPECIAL_MFHI(); break; case R4300i_SPECIAL_MTHI: SPECIAL_MTHI(); break; case R4300i_SPECIAL_MFLO: SPECIAL_MFLO(); break; @@ -896,14 +898,38 @@ void LoopAnalysis::SPECIAL_JALR ( void ) m_NextInstruction = DELAY_SLOT; } -void LoopAnalysis::SPECIAL_SYSCALL ( void ) +void LoopAnalysis::SPECIAL_SYSCALL ( CCodeSection * Section ) { +#ifdef CHECKED_BUILD + if (Section->m_ContinueSection != NULL && + Section->m_Cont.TargetPC != (DWORD)-1) + { + g_Notify->BreakPoint(__FILE__,__LINE__); + } + if (Section->m_JumpSection != NULL && + Section->m_Jump.TargetPC != (DWORD)-1) + { + g_Notify->BreakPoint(__FILE__,__LINE__); + } +#endif m_NextInstruction = END_BLOCK; m_PC -= 4; } -void LoopAnalysis::SPECIAL_BREAK ( void ) +void LoopAnalysis::SPECIAL_BREAK ( CCodeSection * Section ) { +#ifdef CHECKED_BUILD + if (Section->m_ContinueSection != NULL && + Section->m_Cont.TargetPC != (DWORD)-1) + { + g_Notify->BreakPoint(__FILE__,__LINE__); + } + if (Section->m_JumpSection != NULL && + Section->m_Jump.TargetPC != (DWORD)-1) + { + g_Notify->BreakPoint(__FILE__,__LINE__); + } +#endif m_NextInstruction = END_BLOCK; m_PC -= 4; } diff --git a/Source/Project64/N64 System/Recompiler/Loop Analysis.h b/Source/Project64/N64 System/Recompiler/Loop Analysis.h index b505c2b6c..e29f992a4 100644 --- a/Source/Project64/N64 System/Recompiler/Loop Analysis.h +++ b/Source/Project64/N64 System/Recompiler/Loop Analysis.h @@ -41,8 +41,8 @@ private: void SPECIAL_SRAV ( void ); void SPECIAL_JR ( void ); void SPECIAL_JALR ( void ); - void SPECIAL_SYSCALL ( void ); - void SPECIAL_BREAK ( void ); + void SPECIAL_SYSCALL ( CCodeSection * Section ); + void SPECIAL_BREAK ( CCodeSection * Section ); void SPECIAL_MFHI ( void ); void SPECIAL_MTHI ( void ); void SPECIAL_MFLO ( void );