add syscall headers at the start of functions

This commit is contained in:
Lephenixnoir 2020-02-15 19:32:46 +01:00
parent d5c5fa6aeb
commit a51dc7db4c
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
2 changed files with 24 additions and 6 deletions

View File

@ -10,6 +10,7 @@
#include <fxos/disassembly.h>
#include <fxos/symbols.h>
#include <fxos/os.h>
namespace FxOS {
@ -59,11 +60,13 @@ public:
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);
/** Internal promotion printing stuff **/
/* 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();
@ -75,8 +78,6 @@ private:
void syscall(ConcreteInstructionArg const &);
void syscallname(ConcreteInstructionArg const &);
void symbol(ConcreteInstructionArg const &);
/* To be removed */
};
} /* namespace FxOS */

View File

@ -13,8 +13,12 @@ PrintPass::PrintPass(Disassembly &disasm,
std::vector<SymbolTable> 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<OS>(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<int, std::string> suffixes = {