Merge pull request #5242 from sepalani/nop-pad

PPCAnalyst: Skip nop alignment
This commit is contained in:
Anthony 2017-04-29 12:42:38 -07:00 committed by GitHub
commit 78f4ca6d79
1 changed files with 16 additions and 8 deletions

View File

@ -94,7 +94,6 @@ bool AnalyzeFunction(u32 startAddr, Symbol& func, int max_size)
if (func.size >= CODEBUFFER_SIZE * 4) // weird if (func.size >= CODEBUFFER_SIZE * 4) // weird
return false; return false;
const UGeckoInstruction instr = PowerPC::HostRead_Instruction(addr);
if (max_size && func.size > max_size) if (max_size && func.size > max_size)
{ {
func.address = startAddr; func.address = startAddr;
@ -104,7 +103,9 @@ bool AnalyzeFunction(u32 startAddr, Symbol& func, int max_size)
func.flags |= FFLAG_STRAIGHT; func.flags |= FFLAG_STRAIGHT;
return true; return true;
} }
if (PPCTables::IsValidInstruction(instr)) const PowerPC::TryReadInstResult read_result = PowerPC::TryReadInstruction(addr);
const UGeckoInstruction instr = read_result.hex;
if (read_result.valid && PPCTables::IsValidInstruction(instr))
{ {
if (instr.hex == 0x4e800020) // 4e800021 is blrl, not the end of a function if (instr.hex == 0x4e800020) // 4e800021 is blrl, not the end of a function
{ {
@ -271,9 +272,10 @@ static void FindFunctionsFromBranches(u32 startAddr, u32 endAddr, SymbolDB* func
{ {
for (u32 addr = startAddr; addr < endAddr; addr += 4) for (u32 addr = startAddr; addr < endAddr; addr += 4)
{ {
const UGeckoInstruction instr = PowerPC::HostRead_Instruction(addr); const PowerPC::TryReadInstResult read_result = PowerPC::TryReadInstruction(addr);
const UGeckoInstruction instr = read_result.hex;
if (PPCTables::IsValidInstruction(instr)) if (read_result.valid && PPCTables::IsValidInstruction(instr))
{ {
switch (instr.OPCD) switch (instr.OPCD)
{ {
@ -309,11 +311,17 @@ static void FindFunctionsAfterBLR(PPCSymbolDB* func_db)
{ {
while (true) while (true)
{ {
// skip zeroes that sometimes pad function to 16 byte boundary (e.g. Donkey Kong Country // Skip zeroes (e.g. Donkey Kong Country Returns) and nop (e.g. libogc)
// Returns) // that sometimes pad function to 16 byte boundary.
while (PowerPC::HostRead_Instruction(location) == 0 && ((location & 0xf) != 0)) PowerPC::TryReadInstResult read_result = PowerPC::TryReadInstruction(location);
while (read_result.valid && (location & 0xf) != 0)
{
if (read_result.hex != 0 && read_result.hex != 0x60000000)
break;
location += 4; location += 4;
if (PPCTables::IsValidInstruction(PowerPC::HostRead_Instruction(location))) read_result = PowerPC::TryReadInstruction(location);
}
if (read_result.valid && PPCTables::IsValidInstruction(read_result.hex))
{ {
// check if this function is already mapped // check if this function is already mapped
Symbol* f = func_db->AddFunction(location); Symbol* f = func_db->AddFunction(location);