diff --git a/Source/BasicBlock.cpp b/Source/BasicBlock.cpp index ff8bc65d5..5e074ad35 100644 --- a/Source/BasicBlock.cpp +++ b/Source/BasicBlock.cpp @@ -206,6 +206,10 @@ void CBasicBlock::CompileRange(CMipsJitter* jitter) return false; } uint32 target = m_context.m_pArch->GetInstructionEffectiveAddress(&m_context, branchInstAddr, inst); + if(target == MIPS_INVALID_PC) + { + return false; + } return target == m_begin; }(); diff --git a/Source/GenericMipsExecutor.h b/Source/GenericMipsExecutor.h index d604a1551..0d9c6c130 100644 --- a/Source/GenericMipsExecutor.h +++ b/Source/GenericMipsExecutor.h @@ -172,7 +172,7 @@ protected: } } - if((branchAddress != 0) && block->HasLinkSlot(LINK_SLOT_BRANCH)) + if((branchAddress != MIPS_INVALID_PC) && block->HasLinkSlot(LINK_SLOT_BRANCH)) { branchAddress &= m_addressMask; const auto linkSlot = LINK_SLOT_BRANCH; @@ -210,7 +210,7 @@ protected: virtual void PartitionFunction(uint32 startAddress) { uint32 endAddress = startAddress + MAX_BLOCK_SIZE; - uint32 branchAddress = 0; + uint32 branchAddress = MIPS_INVALID_PC; for(uint32 address = startAddress; address < endAddress; address += 4) { uint32 opcode = m_context.m_pMemoryMap->GetInstruction(address); diff --git a/Source/MA_MIPSIV_Reflection.cpp b/Source/MA_MIPSIV_Reflection.cpp index 1a4fd2e17..13274933d 100644 --- a/Source/MA_MIPSIV_Reflection.cpp +++ b/Source/MA_MIPSIV_Reflection.cpp @@ -230,7 +230,7 @@ uint32 CMA_MIPSIV::ReflCOPEffeAddr(INSTRUCTION* pInstr, CMIPS* pCtx, uint32 nAdd } else { - return 0; + return MIPS_INVALID_PC; } } diff --git a/Source/MIPSAnalysis.cpp b/Source/MIPSAnalysis.cpp index 255e292c9..de9cec6dd 100644 --- a/Source/MIPSAnalysis.cpp +++ b/Source/MIPSAnalysis.cpp @@ -269,6 +269,7 @@ void CMIPSAnalysis::ExpandSubroutines(uint32 executableStart, uint32 executableE if(branchType != MIPS_BRANCH_NORMAL) continue; uint32 branchTarget = m_ctx->m_pArch->GetInstructionEffectiveAddress(m_ctx, address, opcode); + if(branchTarget == MIPS_INVALID_PC) continue; //Check if pointing inside our subroutine. If so, don't bother if(branchTarget >= subroutine.start && branchTarget <= subroutine.end) continue; diff --git a/Source/MIPSReflection.cpp b/Source/MIPSReflection.cpp index a47b9026d..448a380c4 100644 --- a/Source/MIPSReflection.cpp +++ b/Source/MIPSReflection.cpp @@ -1,7 +1,6 @@ #include "MIPSReflection.h" #include - -class CMIPS; +#include "MIPS.h" using namespace MIPSReflection; @@ -64,7 +63,7 @@ uint32 MIPSReflection::SubTableEffAddr(INSTRUCTION* pInstr, CMIPS* pCtx, uint32 pInstr = DereferenceInstruction(pInstr->pSubTable, nOpcode); if(pInstr->pGetEffectiveAddress == NULL) { - return 0; + return MIPS_INVALID_PC; } return pInstr->pGetEffectiveAddress(pInstr, pCtx, nAddress, nOpcode); } diff --git a/Source/ee/EeBasicBlock.cpp b/Source/ee/EeBasicBlock.cpp index f2a17aa4b..31442303f 100644 --- a/Source/ee/EeBasicBlock.cpp +++ b/Source/ee/EeBasicBlock.cpp @@ -40,6 +40,7 @@ bool CEeBasicBlock::IsIdleLoopBlock() const //Check that the branch target is ourself uint32 branchTarget = m_context.m_pArch->GetInstructionEffectiveAddress(&m_context, endInstructionAddress, endInstruction); + if(branchTarget == MIPS_INVALID_PC) return false; if(branchTarget != m_begin) return false; uint32 compareRs = 0; diff --git a/Source/ee/MA_VU_LowerReflection.cpp b/Source/ee/MA_VU_LowerReflection.cpp index bf97f81c6..d6d6d4800 100644 --- a/Source/ee/MA_VU_LowerReflection.cpp +++ b/Source/ee/MA_VU_LowerReflection.cpp @@ -1349,12 +1349,12 @@ uint32 CMA_VU::CLower::GetInstructionEffectiveAddress(CMIPS* context, uint32 add { if(IsLOI(context, address)) { - return 0; + return MIPS_INVALID_PC; } if(opcode == OPCODE_NOP) { - return 0; + return MIPS_INVALID_PC; } INSTRUCTION instr; diff --git a/Source/ee/VuAnalysis.cpp b/Source/ee/VuAnalysis.cpp index f453c4454..0b3573ebe 100644 --- a/Source/ee/VuAnalysis.cpp +++ b/Source/ee/VuAnalysis.cpp @@ -105,7 +105,7 @@ void CVuAnalysis::Analyse(CMIPS* ctx, uint32 begin, uint32 end) if(branchType == MIPS_BRANCH_NORMAL) { uint32 branchTarget = ctx->m_pArch->GetInstructionEffectiveAddress(ctx, address, lowerInstruction); - if(branchTarget != 0) + if(branchTarget != MIPS_INVALID_PC) { auto subroutine = ctx->m_analysis->FindSubroutine(branchTarget); if(subroutine) diff --git a/Source/ee/VuBasicBlock.cpp b/Source/ee/VuBasicBlock.cpp index 869fcad69..11a2017fa 100644 --- a/Source/ee/VuBasicBlock.cpp +++ b/Source/ee/VuBasicBlock.cpp @@ -230,9 +230,7 @@ void CVuBasicBlock::CompileRange(CMipsJitter* jitter) return false; } uint32 target = m_context.m_pArch->GetInstructionEffectiveAddress(&m_context, branchInstAddr, inst); - //TODO: GetInstructionEffectiveAddress should return something else when the EA can't be computed - //statically as 0 is a valid address. There's some other implications to this though. - if(target == 0) + if(target == MIPS_INVALID_PC) { return false; } @@ -321,6 +319,7 @@ bool CVuBasicBlock::CheckIsSpecialIntegerLoop(unsigned int regI) const { assert(IsConditionalBranch(opcodeLo)); uint32 branchTarget = arch->GetInstructionEffectiveAddress(&m_context, address, opcodeLo); + if(branchTarget == MIPS_INVALID_PC) return false; if(branchTarget != m_begin) return false; } else diff --git a/Source/ee/VuExecutor.cpp b/Source/ee/VuExecutor.cpp index 9376ec021..2e175124d 100644 --- a/Source/ee/VuExecutor.cpp +++ b/Source/ee/VuExecutor.cpp @@ -70,7 +70,7 @@ BasicBlockPtr CVuExecutor::BlockFactory(CMIPS& context, uint32 begin, uint32 end void CVuExecutor::PartitionFunction(uint32 startAddress) { uint32 endAddress = startAddress + MAX_BLOCK_SIZE - 4; - uint32 branchAddress = 0; + uint32 branchAddress = MIPS_INVALID_PC; for(uint32 address = startAddress; address < endAddress; address += 8) { uint32 addrLo = address + 0; diff --git a/Source/ui_qt/DebugSupport/DisAsmWnd.cpp b/Source/ui_qt/DebugSupport/DisAsmWnd.cpp index d8e6427f1..2cfb62377 100644 --- a/Source/ui_qt/DebugSupport/DisAsmWnd.cpp +++ b/Source/ui_qt/DebugSupport/DisAsmWnd.cpp @@ -186,11 +186,14 @@ void CDisAsmWnd::ShowContextMenu(const QPoint& pos) { char sTemp[256]; uint32 nAddress = m_ctx->m_pArch->GetInstructionEffectiveAddress(m_ctx, m_selected, nOpcode); - snprintf(sTemp, countof(sTemp), ("Go to 0x%08X"), nAddress); - QAction* goToEaAction = new QAction(this); - goToEaAction->setText(sTemp); - connect(goToEaAction, &QAction::triggered, std::bind(&CDisAsmWnd::GotoEA, this)); - rightClickMenu->addAction(goToEaAction); + if(nAddress != MIPS_INVALID_PC) + { + snprintf(sTemp, countof(sTemp), ("Go to 0x%08X"), nAddress); + QAction* goToEaAction = new QAction(this); + goToEaAction->setText(sTemp); + connect(goToEaAction, &QAction::triggered, std::bind(&CDisAsmWnd::GotoEA, this)); + rightClickMenu->addAction(goToEaAction); + } } } } @@ -368,6 +371,7 @@ void CDisAsmWnd::GotoEA() if(m_ctx->m_pArch->IsInstructionBranch(m_ctx, m_selected, nOpcode) == MIPS_BRANCH_NORMAL) { uint32 nAddress = m_ctx->m_pArch->GetInstructionEffectiveAddress(m_ctx, m_selected, nOpcode); + assert(nAddress != MIPS_INVALID_PC); if(m_address != nAddress) { diff --git a/Source/ui_qt/DebugSupport/QtDebugger.cpp b/Source/ui_qt/DebugSupport/QtDebugger.cpp index 03d393c61..35e8b4e9c 100644 --- a/Source/ui_qt/DebugSupport/QtDebugger.cpp +++ b/Source/ui_qt/DebugSupport/QtDebugger.cpp @@ -632,6 +632,7 @@ std::vector QtDebugger::FindCallers(CMIPS* context, uint32 address) { uint32 opcode = context->m_pMemoryMap->GetInstruction(i); uint32 ea = context->m_pArch->GetInstructionEffectiveAddress(context, i, opcode); + if(ea == MIPS_INVALID_PC) continue; if(ea == address) { callers.push_back(i); diff --git a/Source/ui_qt/DebugSupport/QtDisAsmTableModel.cpp b/Source/ui_qt/DebugSupport/QtDisAsmTableModel.cpp index b9b4d065c..32f0e4389 100644 --- a/Source/ui_qt/DebugSupport/QtDisAsmTableModel.cpp +++ b/Source/ui_qt/DebugSupport/QtDisAsmTableModel.cpp @@ -312,12 +312,15 @@ std::string CQtDisAsmTableModel::GetInstructionMetadata(uint32 address) const if(m_ctx->m_pArch->IsInstructionBranch(m_ctx, address, opcode) == MIPS_BRANCH_NORMAL) { uint32 effAddr = m_ctx->m_pArch->GetInstructionEffectiveAddress(m_ctx, address, opcode); - const char* tag = m_ctx->m_Functions.Find(effAddr); - if(tag != nullptr) + if(effAddr != MIPS_INVALID_PC) { - disAsm += ("-> "); - disAsm += tag; - commentDrawn = true; + const char* tag = m_ctx->m_Functions.Find(effAddr); + if(tag != nullptr) + { + disAsm += ("-> "); + disAsm += tag; + commentDrawn = true; + } } } }