Skip to content

Commit

Permalink
Disassembler cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Jan 6, 2023
1 parent 0a16199 commit 48d1379
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 152 deletions.
14 changes: 7 additions & 7 deletions Emulator/CPU/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,16 +694,16 @@ CPU::disassembleRecordedFlags(isize i)
{
static char result[18];

disassembleSR(debugger.logEntryAbs((int)i).sr, result);
disassembleSR(result, debugger.logEntryAbs((int)i).sr);
return result;
}

const char *
CPU::disassembleRecordedPC(isize i)
{
static char result[16];
Moira::disassemblePC(debugger.logEntryAbs((int)i).pc0, result);

Moira::dump24(result, debugger.logEntryAbs((int)i).pc0);
return result;
}

Expand All @@ -712,7 +712,7 @@ CPU::disassembleAddr(u32 addr)
{
static char result[16];

Moira::disassemblePC(addr, result);
Moira::dump24(result, addr);
return result;
}

Expand All @@ -721,7 +721,7 @@ CPU::disassembleWord(u16 value)
{
static char result[16];

Moira::disassembleWord(value, result);
Moira::dump16(result, value);
return result;
}

Expand All @@ -730,7 +730,7 @@ CPU::disassembleInstr(u32 addr, isize *len)
{
static char result[128];

int l = disassemble(addr, result);
int l = disassemble(result, addr);

if (len) *len = (isize)l;
return result;
Expand All @@ -741,7 +741,7 @@ CPU::disassembleWords(u32 addr, isize len)
{
static char result[64];

disassembleMemory(addr, (int)len, result);
dump16(result, addr, len);
return result;
}

Expand Down
26 changes: 13 additions & 13 deletions Emulator/CPU/Moira/Moira.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,21 @@ class Moira : public SubComponent {
public:

// Disassembles a single instruction and returns the instruction size
int disassemble(u32 addr, char *str) const;
int disassemble(char *str, u32 addr) const;

// Creates a textual representation for the status register
void disassembleSR(char *str) const { disassembleSR(reg.sr, str); }
void disassembleSR(const StatusRegister &sr, char *str) const;

// Returns a textual representation for a single word
void disassembleWord(u32 value, char *str) const;

// Returns a textual representation for one or more words from memory
void disassembleMemory(u32 addr, int cnt, char *str) const;

// Returns a textual representation for the program counter
void disassemblePC(char *str) const { disassemblePC(reg.pc, str); }
void disassemblePC(u32 pc, char *str) const;
void disassembleSR(char *str) const { disassembleSR(str, reg.sr); }
void disassembleSR(char *str, const StatusRegister &sr) const;

// Creates a textual representation for a single data value
void dump8(char *str, u8 value) const;
void dump16(char *str, u16 value) const;
void dump24(char *str, u32 value) const;
void dump32(char *str, u32 value) const;

// Creates a textual representation for multiple data values
void dump16(char *str, u16 values[], isize cnt) const;
void dump16(char *str, u32 addr, isize cnt) const;

// Return an info struct for a certain opcode
InstrInfo getInfo(u16 op) const;
Expand Down
7 changes: 5 additions & 2 deletions Emulator/CPU/Moira/MoiraDasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
// Auxiliary functions
//

// Reads a word from memory and increments addr
template <Size S = Word> u32 dasmRead(u32 &addr) const;
// Reads a data value from memory without side-effects
template <Size S = Word> u32 dasmRead(u32 addr) const;

// Increments addr and reads a data value from memory without side-effects
template <Size S = Word> u32 dasmIncRead(u32 &addr) const;

// Assembles an operand
template <Mode M, Size S = Word> Ea<M, S>Op(u16 reg, u32 &pc) const;
90 changes: 45 additions & 45 deletions Emulator/CPU/Moira/MoiraDasmFPU_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
template <Instr I, Mode M, Size S> void
Moira::dasmFGen(StrWriter &str, u32 &addr, u16 op) const
{
auto ext = dasmRead<Word>(addr);
auto ext = dasmIncRead<Word>(addr);
auto cod = xxx_____________(ext);
auto cmd = _________xxxxxxx(ext);
addr -= 2;
Expand Down Expand Up @@ -128,7 +128,7 @@ template <Instr I, Mode M, Size S> void
Moira::dasmFBcc(StrWriter &str, u32 &addr, u16 op) const
{
auto old = addr;
auto ext = dasmRead<S>(addr);
auto ext = dasmIncRead<S>(addr);
auto cnd = ___________xxxxx (op);

// Check for special FNOP opcode
Expand All @@ -152,7 +152,7 @@ template <Instr I, Mode M, Size S> void
Moira::dasmFDbcc(StrWriter &str, u32 &addr, u16 op) const
{
auto old = addr;
auto ext = dasmRead(addr);
auto ext = dasmIncRead(addr);
auto src = _____________xxx (op);
auto cnd = ___________xxxxx (ext);

Expand All @@ -165,7 +165,7 @@ Moira::dasmFDbcc(StrWriter &str, u32 &addr, u16 op) const
}

auto dst = addr + 2;
U32_INC(dst, SEXT<S>(dasmRead<S>(addr)));
U32_INC(dst, SEXT<S>(dasmIncRead<S>(addr)));

str << Ins<I>{} << Fcc{cnd} << str.tab << Dn{src} << Sep{} << UInt(dst);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ template <Instr I, Mode M, Size S> void
Moira::dasmFScc(StrWriter &str, u32 &addr, u16 op) const
{
auto old = addr;
auto ext = dasmRead(addr);
auto ext = dasmIncRead(addr);
auto reg = _____________xxx (op);
auto cnd = __________xxxxxx (ext);

Expand All @@ -216,7 +216,7 @@ template <Instr I, Mode M, Size S> void
Moira::dasmFTrapcc(StrWriter &str, u32 &addr, u16 op) const
{
auto old = addr;
auto ext = dasmRead(addr);
auto ext = dasmIncRead(addr);
auto cnd = __________xxxxxx (ext);

// Catch illegal extension words
Expand All @@ -237,15 +237,15 @@ Moira::dasmFTrapcc(StrWriter &str, u32 &addr, u16 op) const
case Word:
case Long:

str << Ins<I>{} << Fcc{cnd} << Sz<S>{} << str.tab << Ims<S>(dasmRead<S>(addr));
str << Ins<I>{} << Fcc{cnd} << Sz<S>{} << str.tab << Ims<S>(dasmIncRead<S>(addr));
break;
}
}

template <Instr I, Mode M, Size S> void
Moira::dasmFGeneric(StrWriter &str, u32 &addr, u16 op) const
{
auto ext = dasmRead(addr);
auto ext = dasmIncRead(addr);
auto reg = _____________xxx (op);
auto src = ___xxx__________ (ext);
auto dst = ______xxx_______ (ext);
Expand All @@ -260,34 +260,34 @@ Moira::dasmFGeneric(StrWriter &str, u32 &addr, u16 op) const

case 0: // Long-Word Integer

val = dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
str << Ins<I>{} << Ffmt{src} << str.tab << Ims<Long>(u32(val));
break;

case 1: // Single precision

val = dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
str << Ins<I>{} << Ffmt{src} << str.tab << "#<fixme>";
break;

case 2: // Double precision
case 3: // Packed-Decimal Real

val = dasmRead<Long>(addr);
dasmRead<Long>(addr);
dasmRead<Long>(addr); // Why???
val = dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr); // Why???
str << Ins<I>{} << Ffmt{src} << str.tab << "#<fixme>";
break;

case 5: // Double-precision real

val = dasmRead<Long>(addr);
dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr);
str << Ins<I>{} << Ffmt{src} << str.tab << "#<fixme>";
break;

case 6: // Byte Integer
val = dasmRead<Word>(addr);
val = dasmIncRead<Word>(addr);
str << Ins<I>{} << Ffmt{src} << str.tab << Ims<Byte>(u32(val));
break;

Expand All @@ -308,7 +308,7 @@ Moira::dasmFGeneric(StrWriter &str, u32 &addr, u16 op) const
template <Instr I, Mode M, Size S> void
Moira::dasmFGeneric2(StrWriter &str, u32 &addr, u16 op) const
{
auto ext = dasmRead(addr);
auto ext = dasmIncRead(addr);
auto reg = _____________xxx (op);
auto src = ___xxx__________ (ext);
auto dst = ______xxx_______ (ext);
Expand All @@ -326,35 +326,35 @@ Moira::dasmFGeneric2(StrWriter &str, u32 &addr, u16 op) const

case 0: // Long-Word Integer

val = dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
str << Ims<Long>(u32(val));
break;

case 1: // Single precision

val = dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
str << "#<fixme>";
break;

case 2: // Double precision
case 3: // Packed-Decimal Real

val = dasmRead<Long>(addr);
dasmRead<Long>(addr);
dasmRead<Long>(addr); // Why???
val = dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr); // Why???
str << "#<fixme>";
break;

case 5: // Double-precision real

val = dasmRead<Long>(addr);
dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr);
str << "#<fixme>";
break;

case 6: // Byte Integer

val = dasmRead<Word>(addr);
val = dasmIncRead<Word>(addr);
str << Ims<Byte>(u32(val));
break;

Expand All @@ -375,7 +375,7 @@ Moira::dasmFGeneric2(StrWriter &str, u32 &addr, u16 op) const
template <Instr I, Mode M, Size S> void
Moira::dasmFGeneric3(StrWriter &str, u32 &addr, u16 op) const
{
auto ext = dasmRead(addr);
auto ext = dasmIncRead(addr);
auto reg = _____________xxx (op);
auto src = ___xxx__________ (ext);

Expand All @@ -389,35 +389,35 @@ Moira::dasmFGeneric3(StrWriter &str, u32 &addr, u16 op) const

case 0: // Long-Word Integer

val = dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
str << Ins<I>{} << Ffmt{src} << str.tab << Ims<Long>(u32(val));
break;

case 1: // Single precision

val = dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
str << Ins<I>{} << Ffmt{src} << str.tab << "#<fixme>";
break;

case 2: // Double precision
case 3: // Packed-Decimal Real

val = dasmRead<Long>(addr);
dasmRead<Long>(addr);
dasmRead<Long>(addr); // Why???
val = dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr); // Why???
str << Ins<I>{} << Ffmt{src} << str.tab << "#<fixme>";
break;

case 5: // Double-precision real

val = dasmRead<Long>(addr);
dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr);
str << Ins<I>{} << Ffmt{src} << str.tab << "#<fixme>";
break;

case 6: // Byte Integer

val = dasmRead<Word>(addr);
val = dasmIncRead<Word>(addr);
str << Ins<I>{} << Ffmt{src} << str.tab << Ims<Byte>(u32(val));
break;

Expand All @@ -437,7 +437,7 @@ template <Instr I, Mode M, Size S> void
Moira::dasmFMove(StrWriter &str, u32 &addr, u16 op) const
{
auto old = addr;
auto ext = dasmRead(addr);
auto ext = dasmIncRead(addr);
auto reg = _____________xxx (op);
auto cod = xxx_____________ (ext);
auto src = ___xxx__________ (ext);
Expand Down Expand Up @@ -479,34 +479,34 @@ Moira::dasmFMove(StrWriter &str, u32 &addr, u16 op) const
switch (src) {

case 0: // Long-Word Integer
val = dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
str << str.tab << Ims<Long>(u32(val)) << Sep{} << Fp(dst);
break;

case 1: // Single precision

val = dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
str << str.tab << "#<fixme>" << Sep{} << Fp(dst);
break;

case 2: // Double precision
case 3: // Packed-Decimal Real

val = dasmRead<Long>(addr);
dasmRead<Long>(addr);
dasmRead<Long>(addr); // Why???
val = dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr); // Why???
str << str.tab << "#<fixme>" << Sep{} << Fp(dst);
break;

case 5: // Double-precision real

val = dasmRead<Long>(addr);
dasmRead<Long>(addr);
val = dasmIncRead<Long>(addr);
dasmIncRead<Long>(addr);
str << str.tab << "#<fixme>" << Sep{} << Fp(dst);
break;

case 6: // Byte Integer
val = dasmRead<Word>(addr);
val = dasmIncRead<Word>(addr);
str << str.tab << Ims<Byte>(u32(val)) << Sep{} << Fp(dst);
break;

Expand Down Expand Up @@ -547,7 +547,7 @@ template <Instr I, Mode M, Size S> void
Moira::dasmFMovecr(StrWriter &str, u32 &addr, u16 op) const
{
auto old = addr;
auto ext = dasmRead(addr);
auto ext = dasmIncRead(addr);
auto dst = ______xxx_______ (ext);
auto ofs = _________xxxxxxx (ext);

Expand All @@ -569,7 +569,7 @@ template <Instr I, Mode M, Size S> void
Moira::dasmFMovem(StrWriter &str, u32 &addr, u16 op) const
{
auto old = addr;
auto ext = dasmRead(addr);
auto ext = dasmIncRead(addr);
auto reg = _____________xxx (op);
auto cod = xxx_____________ (ext);
auto mod = ___xx___________ (ext);
Expand Down
Loading

0 comments on commit 48d1379

Please sign in to comment.