From 10615526cd7edc4c31523c41e736611320b1be4e Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 1 Jun 2024 04:29:59 -0700 Subject: [PATCH] supports 32bit labels on pea or ldx/lda pairs --- src/disasm.cc | 18 ++++++++++++++++++ src/disasm.h | 2 ++ src/map.h | 1 + 3 files changed, 21 insertions(+) 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 {