regs/src/disasm.h

61 lines
1.3 KiB
C
Raw Normal View History

2020-02-15 00:08:27 +00:00
/** @copyright 2020 Sean Kasun */
#pragma once
#include <cstdint>
2020-02-19 00:03:29 +00:00
#include <map>
#include "omf.h"
#include "api.h"
2020-02-15 00:08:27 +00:00
enum {
IsX8 = 0x10,
IsM8 = 0x20,
IsEmu = 0x100,
IsFlags = 0xff0130,
IsX8Changed = 0x200,
IsM8Changed = 0x400,
IsEmuChanged = 0x2000,
};
2020-02-19 00:03:29 +00:00
enum InsType : uint16_t {
Normal = 0x00,
Call = 0x01,
Jump = 0x02,
Return = 0x03,
Branch = 0x04,
Special = 0x05, // fingerprint
Invalid = 0xff,
};
2020-02-20 03:23:23 +00:00
enum class Opr {
2020-02-21 23:57:11 +00:00
None = 0, Imm8, Imm16, Abs, AbsB, AbsD, AbsX, AbsXB, AbsXD,
AbsY, AbsYB, AbsYD, AbsS, Ind, IndB, IndD, IndX, IndXB, IndXD,
2020-02-21 23:57:11 +00:00
IndY, IndL, IndLY, IndS, Bank,
2020-02-20 03:23:23 +00:00
};
2020-02-19 00:03:29 +00:00
struct Inst {
std::string name;
InsType type;
uint16_t length;
2020-02-20 03:23:23 +00:00
Opr operType;
uint32_t oper;
uint32_t flags;
2020-02-19 00:03:29 +00:00
};
class Disassembler {
public:
2020-02-20 03:23:23 +00:00
Disassembler(std::shared_ptr<Fingerprints> prints,
std::map<uint32_t, std::string> symbols);
bool disassemble(std::vector<struct Segment> segments,
std::vector<struct Entry> entries);
2020-02-19 00:03:29 +00:00
private:
2020-02-20 20:51:00 +00:00
std::string printInst(std::shared_ptr<Inst> inst);
2020-02-20 03:23:23 +00:00
std::shared_ptr<Inst> decodeInst(Handle f, Entry *entry);
bool valid(uint32_t address);
2020-02-21 23:57:11 +00:00
std::string hex(uint32_t value, int width);
std::string lookup(uint32_t value);
2020-02-19 00:03:29 +00:00
2020-02-20 03:23:23 +00:00
std::map<uint32_t, std::string> symbols;
2020-02-19 00:03:29 +00:00
std::shared_ptr<Fingerprints> fingerprints;
};