fxos/lib/passes/cfg.cpp
Lephenixnoir 468495856d
implement more of the meat of the tool
* Separate OS and Target conceptually; now an OS is created on an
  existing target which must have ROM bound.
* Add a configuration file with a data library and description files
  which are automatically loaded at startup.
* As a first application, implement target descriptions. It is now
  possible (given the proper library) to type [fxos info fx@3.10] to get
  information on the fx OS version 3.10.
* Set up the pass infrastructure and the first few easy passes. This
  is still a Work In Progress and not yet called from the command-line.
* Improve the copy/move behavior of classes (C++ concerns).
* Add instruction metadata, which will make it easier to write actual
  useful analysis passes.
2019-12-28 17:18:13 +01:00

38 lines
832 B
C++

//---
// fxos.passes.cfg: CFG construction, as used by other passes
//---
#include <fxos/disassembly.h>
#include <cassert>
namespace FxOS {
CfgPass::CfgPass(Disassembly &disasm):
DisassemblyPass(disasm)
{
}
void CfgPass::analyze(uint32_t pc, ConcreteInstruction &ci)
{
std::vector<std::string> jump_mnemonics {
"bra", "bf", "bf.s", "bf/s", "bt", "bt.s", "bt/s",
};
/* Set the jmptarget fields whenever needed. This is easy because jump
instructions have trivially computable destinations */
for(auto mnemonic: jump_mnemonics)
{
if(ci.inst.mnemonic != mnemonic) continue;
auto &args = ci.inst.args;
assert((args.size() < 1 || args[0].kind != Argument::PcJump)
&& "invalid use of a jump instruction\n");
ci.jmptarget = pc + args[0].disp;
}
enqueue_unseen_successors(pc, ci);
}
} /* namespace FxOS */