From a51dc7db4ca61a6cfe53926ff900767e7e40c52f Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sat, 15 Feb 2020 19:32:46 +0100 Subject: [PATCH] add syscall headers at the start of functions --- include/fxos/disasm-passes/print.h | 9 +++++---- lib/passes/print.cpp | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/fxos/disasm-passes/print.h b/include/fxos/disasm-passes/print.h index b489976..c300a6f 100644 --- a/include/fxos/disasm-passes/print.h +++ b/include/fxos/disasm-passes/print.h @@ -10,6 +10,7 @@ #include #include +#include namespace FxOS { @@ -59,11 +60,13 @@ public: private: /* Symbol tables to look up names */ std::vector const &m_symtables; - /* Query symbol tables, most recent first */ std::optional symquery(Symbol::Type type, uint32_t value); - /** Internal promotion printing stuff **/ + /* OS for the target, to mark syscalls before instructions */ + std::unique_ptr m_os; + + /** Internal promotion tree printers **/ void queue(std::string, bool = false); void queue_flush(); @@ -75,8 +78,6 @@ private: void syscall(ConcreteInstructionArg const &); void syscallname(ConcreteInstructionArg const &); void symbol(ConcreteInstructionArg const &); - - /* To be removed */ }; } /* namespace FxOS */ diff --git a/lib/passes/print.cpp b/lib/passes/print.cpp index d8f9cc6..3e5138b 100644 --- a/lib/passes/print.cpp +++ b/lib/passes/print.cpp @@ -13,8 +13,12 @@ PrintPass::PrintPass(Disassembly &disasm, std::vector const &symtables): DisassemblyPass(disasm), m_symtables(symtables) { - /* Default parameter set */ - /* All 0 */ + /* Default parameters: all 0 */ + + /* Use an OS observer to describe syscalls in header lines */ + Target &t = disasm.target(); + if(t.covers(MemoryRegion::ROM)) + m_os = std::make_unique(t); } void PrintPass::run(void) @@ -29,6 +33,19 @@ void PrintPass::analyze(uint32_t pc, ConcreteInstruction &ci) { Instruction const &i = ci.inst; + /* Preliminary syscall number */ + + int syscall_id; + if(m_os && (syscall_id = m_os->find_syscall(pc)) >= 0) + { + printf("\n<%%%03x", syscall_id); + + auto maybe_str = symquery(Symbol::Syscall, syscall_id); + if(maybe_str) printf(" %s", (*maybe_str).c_str()); + + printf(">\n"); + } + /* Mnemonic */ static std::map suffixes = {