From 102fa567cc0402fa118a39bb462cb83052978bec Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 22 May 2024 03:33:23 -0700 Subject: [PATCH] added bank lookups --- README.md | 3 +++ src/disasm.cc | 9 +++++---- src/disasm.h | 5 +++-- src/main.cc | 2 +- src/map.cc | 16 +++++++++++++--- src/map.h | 1 + 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 28116bd..27c4c3f 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ Each line in this file starts with an address. This address is of the format `$ If the address is followed by an exclamation point `!`, it means this address is used as the point in memory the executable is loaded at. (OMF files will ignore this). If more than one address is followed by an exclamation point, only the first address encountered will be used. +If the address is followed by an asterisk `*`, it means this *bank* is used for +B address lookups. + If the address is followed by a colon `:`, it means this address is considered an entrypoint. Disassembly will start at this address. There can be as many entrypoints as you wish. In fact, as you disassemble a file, you may notice that disassembly is halted by indirect jumps. You can add entrypoints to the `.regs` file to continue disassembly at the destination of those jumps. After the colon, you can optionally specify "e" "m", "x" or any combination of those characters to force the disassembler state when disassembly starts at that entry point. diff --git a/src/disasm.cc b/src/disasm.cc index 264fe55..d239fc6 100644 --- a/src/disasm.cc +++ b/src/disasm.cc @@ -12,8 +12,8 @@ namespace ph = std::placeholders; static std::map sizes; Disassembler::Disassembler(std::shared_ptr prints, - std::map symbols) - : symbols(symbols), fingerprints(prints) { + std::map symbols, uint8_t b) + : symbols(symbols), fingerprints(prints), b(b) { for (int i = 0; i < numAddressSizes; i++) { sizes[addressSizes[i].mode] = addressSizes[i].length; } @@ -372,8 +372,9 @@ std::string Disassembler::printInst(std::shared_ptr inst) { return r; } -std::string Disassembler::lookup(uint32_t val) { - return symbols[val]; +std::string Disassembler::lookup(uint16_t val) { + uint32_t addr = (b << 16) + val; + return symbols[addr]; } std::string Disassembler::hex(uint32_t val, int width) { diff --git a/src/disasm.h b/src/disasm.h index 5b67f49..d488d09 100644 --- a/src/disasm.h +++ b/src/disasm.h @@ -44,7 +44,7 @@ struct Inst { class Disassembler { public: Disassembler(std::shared_ptr prints, - std::map symbols); + std::map symbols, uint8_t b); bool disassemble(std::vector segments, std::vector entries); @@ -53,8 +53,9 @@ class Disassembler { std::shared_ptr decodeInst(Handle f, Entry *entry); bool valid(uint32_t address); std::string hex(uint32_t value, int width); - std::string lookup(uint32_t value); + std::string lookup(uint16_t value); std::map symbols; std::shared_ptr fingerprints; + uint8_t b; }; diff --git a/src/main.cc b/src/main.cc index c57cbd1..166f8c4 100644 --- a/src/main.cc +++ b/src/main.cc @@ -189,6 +189,6 @@ int main(int argc, char **argv) { } } - Disassembler d(prints, map.getSymbols()); + Disassembler d(prints, map.getSymbols(), map.b); d.disassemble(segments, map.getEntries()); } diff --git a/src/map.cc b/src/map.cc index 5435f02..963ce10 100644 --- a/src/map.cc +++ b/src/map.cc @@ -5,10 +5,11 @@ #include struct Field { - uint32_t org; + uint32_t org = 0; std::string flags; - bool isEntry; - bool isOrg; + bool isEntry = false; + bool isOrg = false; + bool isB = false; std::string symbol; }; @@ -29,6 +30,9 @@ Map::Map(const char *filename, uint32_t org) : org(org) { this->org = ofs; } } + if (file.check('*')) { + this->b = ofs >> 16; + } if (file.check(':')) { Entry entry; entry.org = ofs; @@ -64,6 +68,9 @@ static bool compareFields(const Field &a, const Field &b) { void Map::save() { std::map fields; fields[this->org].isOrg = true; + if (b) { + fields[b << 16].isB = true; + } for (auto & entryPoint : entryPoints) { auto org = entryPoint.org; fields[org].isEntry = true; @@ -93,6 +100,9 @@ void Map::save() { if (field.isOrg) { f << "!"; } + if (field.isB) { + f << "*"; + } if (field.isEntry) { f << ":"; } diff --git a/src/map.h b/src/map.h index bd0a0f7..40109ea 100644 --- a/src/map.h +++ b/src/map.h @@ -39,6 +39,7 @@ class Map { void addEntry(uint32_t entry, uint32_t flags); void addSymbol(uint32_t org, std::string name); uint32_t org; + uint8_t b; private: std::string mapname;