86 lines
2.4 KiB
C++
86 lines
2.4 KiB
C++
//---
|
|
// fxos.disasm-passes.print: Concrete program printer
|
|
//
|
|
// This pass prints the program and some to all of its annotations, depending
|
|
// on the specified parameters.
|
|
//---
|
|
|
|
#ifndef LIBFXOS_DISASM_PASSES_PRINT_H
|
|
#define LIBFXOS_DISASM_PASSES_PRINT_H
|
|
|
|
#include <fxos/disassembly.h>
|
|
#include <fxos/symbols.h>
|
|
#include <fxos/os.h>
|
|
|
|
namespace FxOS {
|
|
|
|
class PrintPass: public DisassemblyPass
|
|
{
|
|
public:
|
|
PrintPass(Disassembly &disasm,
|
|
std::vector<SymbolTable> const &symtables);
|
|
void analyze(uint32_t pc, ConcreteInstruction &inst) override;
|
|
|
|
/* This pass uses another entry method that starts at the instruction
|
|
with the smallest address loaded in the disassembly, then goes down.
|
|
The standard run() is not available. */
|
|
void run(void);
|
|
|
|
//---
|
|
// Print pass parameters
|
|
//---
|
|
|
|
/* Promotion parameters. Default is always to append. */
|
|
enum Promotion {
|
|
/* Never promote */
|
|
Never=1,
|
|
/* Promote but keep the lower-level information */
|
|
Append=0,
|
|
/* Promove and hide the lower-level information */
|
|
Promote=2,
|
|
};
|
|
|
|
/** In the following, promote_x always means promote *to x* **/
|
|
|
|
/* In jumps, promote "pc+<disp>" to the target address */
|
|
int promote_pcjump_loc;
|
|
/* In a PC-relative mov, promote "@(<disp>,pc)" to computed address */
|
|
int promote_pcrel_loc;
|
|
/* In a PC-relative mov, promote address to pointed value */
|
|
int promote_pcrel_value;
|
|
/* Promote an integer to a syscall number */
|
|
int promote_syscall;
|
|
/* Promote a syscall number to a syscall name */
|
|
int promote_syscallname;
|
|
/* Promote an integer to a symbol */
|
|
int promote_symbol;
|
|
|
|
/* TODO: More print pass parameters */
|
|
|
|
private:
|
|
/* Symbol tables to look up names */
|
|
std::vector<SymbolTable> const &m_symtables;
|
|
/* Query symbol tables, most recent first */
|
|
std::optional<std::string> symquery(Symbol::Type type, uint32_t value);
|
|
|
|
/* OS for the target, to mark syscalls before instructions */
|
|
std::unique_ptr<OS> m_os;
|
|
|
|
/** Internal promotion tree printers **/
|
|
|
|
void queue(std::string, bool = false);
|
|
void queue_flush();
|
|
std::vector<std::string> m_messages;
|
|
|
|
void pcjumploc(ConcreteInstructionArg const &);
|
|
void pcrelloc(ConcreteInstructionArg const &);
|
|
void pcrelval(ConcreteInstructionArg const &);
|
|
void syscall(ConcreteInstructionArg const &);
|
|
void syscallname(ConcreteInstructionArg const &);
|
|
void symbol(ConcreteInstructionArg const &);
|
|
};
|
|
|
|
} /* namespace FxOS */
|
|
|
|
#endif /* LIBFXOS_DISASM_PASSES_PRINT_H */
|