diff --git a/src/disasm.cc b/src/disasm.cc index d239fc6..f2073ea 100644 --- a/src/disasm.cc +++ b/src/disasm.cc @@ -74,6 +74,8 @@ std::shared_ptr Disassembler::decodeInst(Handle f, Entry *entry) { uint32_t addr = entry->org; entry->flags &= IsFlags; // clear changed flags uint32_t oldFlags = entry->flags; + inst->prevWord = entry->prevWord; + entry->prevWord = 0; switch (mode) { case IMP: inst->operType = Opr::None; @@ -94,6 +96,7 @@ std::shared_ptr Disassembler::decodeInst(Handle f, Entry *entry) { } else { inst->oper = f->r16(); inst->operType = Opr::Imm16; + entry->prevWord = inst->oper; } break; case IMMX: @@ -103,11 +106,13 @@ std::shared_ptr Disassembler::decodeInst(Handle f, Entry *entry) { } else { inst->oper = f->r16(); inst->operType = Opr::Imm16; + entry->prevWord = inst->oper; } break; case IMMS: inst->oper = f->r16(); inst->operType = Opr::Imm16; + entry->prevWord = inst->oper; break; case ABS: inst->oper = f->r16(); @@ -267,6 +272,9 @@ std::string Disassembler::printInst(std::shared_ptr inst) { break; case Opr::Imm16: args = "#" + hex(inst->oper, 4); + if (inst->prevWord && inst->oper) { + comment = checkDW(inst->oper, inst->prevWord); + } break; case Opr::Abs: args = hex(inst->oper, 6); @@ -377,6 +385,16 @@ std::string Disassembler::lookup(uint16_t val) { return symbols[addr]; } +std::string Disassembler::checkDW(uint16_t cur, uint16_t prev) { + uint32_t addr = (cur << 16) + prev; + std::string ret = symbols[addr]; + if (ret.empty()) { + addr = (prev << 16) + cur; + ret = symbols[addr]; + } + return ret; +} + std::string Disassembler::hex(uint32_t val, int width) { static const char *digits = "0123456789abcdef"; std::string ret; diff --git a/src/disasm.h b/src/disasm.h index d488d09..ca810d8 100644 --- a/src/disasm.h +++ b/src/disasm.h @@ -39,6 +39,7 @@ struct Inst { Opr operType; uint32_t oper; uint32_t flags; + uint16_t prevWord; }; class Disassembler { @@ -54,6 +55,7 @@ class Disassembler { bool valid(uint32_t address); std::string hex(uint32_t value, int width); std::string lookup(uint16_t value); + std::string checkDW(uint16_t val, uint16_t prev); std::map symbols; std::shared_ptr fingerprints; diff --git a/src/map.h b/src/map.h index 40109ea..f5b36fb 100644 --- a/src/map.h +++ b/src/map.h @@ -27,6 +27,7 @@ class File { struct Entry { uint32_t org; uint32_t flags; + uint16_t prevWord; }; class Map {