PowerPC/PPCTables: Pass instruction address to GetOpInfo().

This commit is contained in:
Admiral H. Curtiss 2023-03-28 21:59:39 +02:00
parent 6018daa3fa
commit e5941428d1
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
7 changed files with 23 additions and 25 deletions

View File

@ -120,13 +120,13 @@ int Interpreter::SingleStepInner()
// TODO: Does it make sense to use m_prev_inst here?
// It seems like we should use the num_cycles for the instruction at PC instead
// (m_prev_inst has not yet been updated)
return PPCTables::GetOpInfo(m_prev_inst)->num_cycles;
return PPCTables::GetOpInfo(m_prev_inst, m_ppc_state.pc)->num_cycles;
}
m_ppc_state.npc = m_ppc_state.pc + sizeof(UGeckoInstruction);
m_prev_inst.hex = m_mmu.Read_Opcode(m_ppc_state.pc);
const GekkoOPInfo* opinfo = PPCTables::GetOpInfo(m_prev_inst);
const GekkoOPInfo* opinfo = PPCTables::GetOpInfo(m_prev_inst, m_ppc_state.pc);
// Uncomment to trace the interpreter
// if ((m_ppc_state.pc & 0x00FFFFFF) >= 0x000AB54C &&

View File

@ -32,7 +32,7 @@ struct PowerPCState;
// Use these to control the instruction selection
// #define INSTRUCTION_START FallBackToInterpreter(inst); return;
// #define INSTRUCTION_START PPCTables::CountInstruction(inst);
// #define INSTRUCTION_START PPCTables::CountInstruction(inst, m_ppc_state.pc);
#define INSTRUCTION_START
#define FALLBACK_IF(cond) \

View File

@ -297,7 +297,7 @@ void JitInterface::CompileExceptionCheck(ExceptionType type)
// Check in case the code has been replaced since: do we need to do this?
const OpType optype =
PPCTables::GetOpInfo(PowerPC::MMU::HostRead_U32(guard, ppc_state.pc))->type;
PPCTables::GetOpInfo(PowerPC::MMU::HostRead_U32(guard, ppc_state.pc), ppc_state.pc)->type;
if (optype != OpType::Store && optype != OpType::StoreFP && optype != OpType::StorePS)
return;
}

View File

@ -114,7 +114,7 @@ bool AnalyzeFunction(const Core::CPUThreadGuard& guard, u32 startAddr, Common::S
}
const PowerPC::TryReadInstResult read_result = mmu.TryReadInstruction(addr);
const UGeckoInstruction instr = read_result.hex;
if (read_result.valid && PPCTables::IsValidInstruction(instr))
if (read_result.valid && PPCTables::IsValidInstruction(instr, addr))
{
// BLR or RFI
// 4e800021 is blrl, not the end of a function
@ -274,7 +274,7 @@ static void FindFunctionsFromBranches(const Core::CPUThreadGuard& guard, u32 sta
const PowerPC::TryReadInstResult read_result = mmu.TryReadInstruction(addr);
const UGeckoInstruction instr = read_result.hex;
if (read_result.valid && PPCTables::IsValidInstruction(instr))
if (read_result.valid && PPCTables::IsValidInstruction(instr, addr))
{
switch (instr.OPCD)
{
@ -323,7 +323,7 @@ static void FindFunctionsFromHandlers(const Core::CPUThreadGuard& guard, PPCSymb
for (const auto& entry : handlers)
{
const PowerPC::TryReadInstResult read_result = mmu.TryReadInstruction(entry.first);
if (read_result.valid && PPCTables::IsValidInstruction(read_result.hex))
if (read_result.valid && PPCTables::IsValidInstruction(read_result.hex, entry.first))
{
// Check if this function is already mapped
Common::Symbol* f = func_db->AddFunction(guard, entry.first);
@ -357,7 +357,7 @@ static void FindFunctionsAfterReturnInstruction(const Core::CPUThreadGuard& guar
location += 4;
read_result = mmu.TryReadInstruction(location);
}
if (read_result.valid && PPCTables::IsValidInstruction(read_result.hex))
if (read_result.valid && PPCTables::IsValidInstruction(read_result.hex, location))
{
// check if this function is already mapped
Common::Symbol* f = func_db->AddFunction(guard, location);
@ -778,7 +778,7 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer,
num_inst++;
const UGeckoInstruction inst = result.hex;
const GekkoOPInfo* opinfo = PPCTables::GetOpInfo(inst);
const GekkoOPInfo* opinfo = PPCTables::GetOpInfo(inst, address);
code[i] = {};
code[i].opinfo = opinfo;
code[i].address = address;

View File

@ -613,7 +613,7 @@ constexpr Tables s_tables = []() consteval
}
();
const GekkoOPInfo* GetOpInfo(UGeckoInstruction inst)
const GekkoOPInfo* GetOpInfo(UGeckoInstruction inst, u32 pc)
{
const GekkoOPInfo* info = &s_tables.all_instructions[s_tables.primary_table[inst.OPCD]];
if (info->type == OpType::Subtable)
@ -631,8 +631,7 @@ const GekkoOPInfo* GetOpInfo(UGeckoInstruction inst)
case 63:
return &s_tables.all_instructions[s_tables.table63[inst.SUBOP10]];
default:
ASSERT_MSG(POWERPC, 0, "GetOpInfo - invalid subtable op {:08x} @ {:08x}", inst.hex,
PowerPC::ppcState.pc);
ASSERT_MSG(POWERPC, 0, "GetOpInfo - invalid subtable op {:08x} @ {:08x}", inst.hex, pc);
return &s_tables.all_instructions[s_tables.unknown_op_info];
}
}
@ -640,8 +639,7 @@ const GekkoOPInfo* GetOpInfo(UGeckoInstruction inst)
{
if (info->type == OpType::Invalid)
{
ASSERT_MSG(POWERPC, 0, "GetOpInfo - invalid op {:08x} @ {:08x}", inst.hex,
PowerPC::ppcState.pc);
ASSERT_MSG(POWERPC, 0, "GetOpInfo - invalid op {:08x} @ {:08x}", inst.hex, pc);
return &s_tables.all_instructions[s_tables.unknown_op_info];
}
return info;
@ -658,21 +656,21 @@ std::vector<u32> rsplocations;
}
#endif
const char* GetInstructionName(UGeckoInstruction inst)
const char* GetInstructionName(UGeckoInstruction inst, u32 pc)
{
const GekkoOPInfo* info = GetOpInfo(inst);
const GekkoOPInfo* info = GetOpInfo(inst, pc);
return info->opname;
}
bool IsValidInstruction(UGeckoInstruction inst)
bool IsValidInstruction(UGeckoInstruction inst, u32 pc)
{
const GekkoOPInfo* info = GetOpInfo(inst);
const GekkoOPInfo* info = GetOpInfo(inst, pc);
return info->type != OpType::Invalid && info->type != OpType::Unknown;
}
void CountInstruction(UGeckoInstruction inst)
void CountInstruction(UGeckoInstruction inst, u32 pc)
{
const GekkoOPInfo* info = GetOpInfo(inst);
const GekkoOPInfo* info = GetOpInfo(inst, pc);
info->stats->run_count++;
}

View File

@ -118,13 +118,13 @@ struct GekkoOPInfo
namespace PPCTables
{
const GekkoOPInfo* GetOpInfo(UGeckoInstruction inst);
const GekkoOPInfo* GetOpInfo(UGeckoInstruction inst, u32 pc);
bool IsValidInstruction(UGeckoInstruction inst);
bool IsValidInstruction(UGeckoInstruction inst, u32 pc);
void CountInstruction(UGeckoInstruction inst);
void CountInstruction(UGeckoInstruction inst, u32 pc);
void CountInstructionCompile(const GekkoOPInfo* info, u32 pc);
void PrintInstructionRunCounts();
void LogCompiledInstructions();
const char* GetInstructionName(UGeckoInstruction inst);
const char* GetInstructionName(UGeckoInstruction inst, u32 pc);
} // namespace PPCTables

View File

@ -1699,7 +1699,7 @@ void MenuBar::SearchInstruction()
addr += 4)
{
const auto ins_name = QString::fromStdString(
PPCTables::GetInstructionName(PowerPC::MMU::HostRead_U32(guard, addr)));
PPCTables::GetInstructionName(PowerPC::MMU::HostRead_U32(guard, addr), addr));
if (op == ins_name)
{
NOTICE_LOG_FMT(POWERPC, "Found {} at {:08x}", op.toStdString(), addr);