Skip to content
Snippets Groups Projects
Commit a189207e authored by Jason Hiser's avatar Jason Hiser :tractor:
Browse files

added fallthrough for uncond branchs/rets for mips due to delay slotting

parent 42d75e71
No related branches found
No related tags found
No related merge requests found
...@@ -68,7 +68,9 @@ void PopulateCFG::populate_instruction_map ...@@ -68,7 +68,9 @@ void PopulateCFG::populate_instruction_map
void PopulateCFG::set_fallthrough void PopulateCFG::set_fallthrough
( (
InstructionMap_t &insnMap, InstructionMap_t &insnMap,
DecodedInstruction_t *disasm, Instruction_t *insn, FileIR_t *firp DecodedInstruction_t *disasm,
Instruction_t *insn,
FileIR_t *firp
) )
{ {
assert(disasm); assert(disasm);
...@@ -77,14 +79,20 @@ void PopulateCFG::set_fallthrough ...@@ -77,14 +79,20 @@ void PopulateCFG::set_fallthrough
if(insn->getFallthrough()) if(insn->getFallthrough())
return; return;
// check for branches with targets const auto is_mips = firp->getArchitecture()->getMachineType() == admtMips32;
if( // always set fallthrough for mips
(disasm->isUnconditionalBranch() ) || // it is a unconditional branch // other platforms can end fallthroughs ofr uncond branches and returns
(disasm->isReturn()) // or a return if(!is_mips)
)
{ {
// this is a branch with no fallthrough instruction // check for branches with targets
return; if(
(disasm->isUnconditionalBranch() ) || // it is a unconditional branch
(disasm->isReturn()) // or a return
)
{
// this is a branch with no fallthrough instruction
return;
}
} }
/* get the address of the next instrution */ /* get the address of the next instrution */
...@@ -127,17 +135,14 @@ void PopulateCFG::set_delay_slots ...@@ -127,17 +135,14 @@ void PopulateCFG::set_delay_slots
if(!is_mips) if(!is_mips)
return; return;
for(auto &insn : firp->getInstructions()) // using df=DecodedInstruction_t::factory;
const auto d=DecodedInstruction_t::factory(insn);
if(d->isBranch())
{ {
// using df=DecodedInstruction_t::factory; const auto branch_addr = insn->getAddress();
const auto d=DecodedInstruction_t::factory(insn); const auto delay_slot_insn = insnMap[ {branch_addr->getFileID(), branch_addr->getVirtualOffset() + 4}];
if(d->isBranch()) assert(delay_slot_insn);
{ (void)firp->addNewRelocation(insn,0,"delay_slot1", delay_slot_insn, 0);
const auto branch_addr = insn->getAddress();
const auto delay_slot_insn = insnMap[ {branch_addr->getFileID(), branch_addr->getVirtualOffset() + 4}];
assert(delay_slot_insn);
(void)firp->addNewRelocation(insn,0,"delay_slot1", delay_slot_insn, 0);
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment