Swap between instructions in absoluteSwitch for tag 2 pattern

This commit is contained in:
Dennis Stanistan 2025-03-04 02:47:49 +02:00 committed by GitHub
parent da9d2e950a
commit c7d9e1e1b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,11 +26,11 @@ void ReadTable(Image& image, SwitchTable& table)
uint32_t pOffset;
ppc_insn insn;
auto* code = (uint32_t*)image.Find(table.base);
ppc::Disassemble(code, table.base, insn);
pOffset = insn.operands[1] << 16;
ppc::Disassemble(code, table.base, insn); // lis
pOffset = insn.operands[1] << 16; // Upper 16 bits
ppc::Disassemble(code + 1, table.base + 4, insn);
pOffset += insn.operands[2];
ppc::Disassemble(code + 2, table.base + 8, insn); // addi (skip rlwinm at +4)
pOffset += insn.operands[2]; // Lower 16 bits
if (table.type == SWITCH_ABSOLUTE)
{
@ -250,15 +250,16 @@ int main(int argc, char** argv)
}
};
uint32_t absoluteSwitch[] =
{
PPC_INST_LIS,
PPC_INST_ADDI,
PPC_INST_RLWINM,
PPC_INST_LWZX,
PPC_INST_MTCTR,
PPC_INST_BCTR,
};
// adjusted for tag 2
uint32_t absoluteSwitch[] =
{
PPC_INST_LIS,
PPC_INST_RLWINM, // (slwi alias)
PPC_INST_ADDI,
PPC_INST_LWZX,
PPC_INST_MTCTR,
PPC_INST_BCTR
};
uint32_t computedSwitch[] =
{