mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
GP-3962 fix to correct function bodies with instructions that branch
into the delay slot
This commit is contained in:
parent
10cc91bd8e
commit
6f9d2c3b78
2 changed files with 19 additions and 17 deletions
|
@ -218,6 +218,7 @@ public class InstructionDB extends CodeUnitDB implements Instruction, Instructio
|
||||||
if (alignment < 1) {
|
if (alignment < 1) {
|
||||||
alignment = 1;
|
alignment = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// skip past delay slot instructions
|
// skip past delay slot instructions
|
||||||
try {
|
try {
|
||||||
|
@ -228,8 +229,16 @@ public class InstructionDB extends CodeUnitDB implements Instruction, Instructio
|
||||||
catch (AddressOverflowException e) {
|
catch (AddressOverflowException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// if an instruction is in a delay slot and has references to it,
|
||||||
|
// consider this the fallfrom instruction
|
||||||
|
if (instr != null && instr.isInDelaySlot() && instr.hasFallthrough()) {
|
||||||
|
if (program.getSymbolTable().hasSymbol(instr.getMinAddress())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (instr != null && instr.isInDelaySlot());
|
while (instr != null && instr.isInDelaySlot());
|
||||||
|
|
||||||
if (instr == null) {
|
if (instr == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,6 +349,10 @@ public class FollowFlow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delay adding instructions in delay slots to the functions body
|
||||||
|
// until the end. This allows for branches into the delay slot to be handled correctly.
|
||||||
|
AddressSet delaySlotSet = new AddressSet();
|
||||||
|
|
||||||
while (!monitor.isCancelled() && !instructionStack.isEmpty()) {
|
while (!monitor.isCancelled() && !instructionStack.isEmpty()) {
|
||||||
|
|
||||||
codeUnit = instructionStack.pop();
|
codeUnit = instructionStack.pop();
|
||||||
|
@ -368,35 +372,24 @@ public class FollowFlow {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If code unit is a delay-slot instruction, backup to delayed instruction
|
|
||||||
Instruction instr = currentInstr;
|
Instruction instr = currentInstr;
|
||||||
// while (instr.isInDelaySlot()) {
|
|
||||||
// Address fallFrom = instr.getFallFrom();
|
|
||||||
// if (fallFrom == null) {
|
|
||||||
// // assumes delay slot instructions have no flow
|
|
||||||
// flowAddressSet.addRange(instr.getMinAddress(),
|
|
||||||
// currentInstr.getMaxAddress());
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// instr = program.getListing().getInstructionContaining(fallFrom);
|
|
||||||
// }
|
|
||||||
// if (instr.isInDelaySlot())
|
|
||||||
// continue; // unable to find non-delay-slot instruction
|
|
||||||
// currentInstr = instr;
|
|
||||||
|
|
||||||
// handle instruction - include associated delay slot instructions
|
// handle instruction with delay slot instructions
|
||||||
Address end = instr.getMaxAddress();
|
Address end = instr.getMaxAddress();
|
||||||
int delaySlotDepth = instr.getDelaySlotDepth();
|
int delaySlotDepth = instr.getDelaySlotDepth();
|
||||||
for (int i = 0; i < delaySlotDepth; i++) {
|
for (int i = 0; i < delaySlotDepth; i++) {
|
||||||
instr = instr.getNext();
|
instr = instr.getNext();
|
||||||
if (instr == null)
|
if (instr == null)
|
||||||
break;
|
break;
|
||||||
end = instr.getMaxAddress();
|
delaySlotSet.add(instr.getMinAddress(),instr.getMaxAddress());
|
||||||
}
|
}
|
||||||
flowAddressSet.addRange(currentInstr.getMinAddress(), end);
|
flowAddressSet.addRange(currentInstr.getMinAddress(), end);
|
||||||
followInstruction(instructionStack, flowAddressSet, currentInstr);
|
followInstruction(instructionStack, flowAddressSet, currentInstr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add in any instructions that were in a delayslot
|
||||||
|
flowAddressSet.add(delaySlotSet);
|
||||||
} // followCode
|
} // followCode
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue