Open SteveFosdick opened 5 years ago
On tracing what is happening with gdb I came upon this:
m68k_disassemble (str_buff=0x7fffffffe10a "", pc=pc@entry=4294902272,
cpu_type=cpu_type@entry=4) at musahi/m68kdasm.c:3482
3482 g_cpu_ir = read_imm_16();
(gdb) s
dasm_read_imm_16 (advance=2) at musahi/m68kdasm.c:273
273 result = m68k_read_disassembler_16(g_cpu_pc & g_address_mask) & 0xff;
So this is correctly reading a 16bit opcode from memory but is then discarding the most significant byte. That means for any opode with a non-zero most significant byte the wrong mnemonics will be reported.
Applying the attached patch corrects this and gives the following output for the same section of code:
FFFF0200: suba.l A0, A0
FFFF0202: movea.l #$ffff0000, A1
FFFF0208: move.w #$3f, D0
FFFF020C: move.l (A1)+, (A0)+
FFFF020E: dbra D0, $ffff020c
FFFF0212: move.w #$bf, D0
FFFF0216: move.l #$ffff0734, (A0)+
FFFF021C: dbra D0, $ffff0216
FFFF0220: move.w #$3f, D0
FFFF0224: movea.w #$400, A0
FFFF0228: movea.l #$ffff0100, A1
FFFF022E: move.l (A1)+, (A0)+
This is an improvment, the the first instruction still appears incorrect. m68k_dmasm_patch1.txt
On checking the 68000 programmer's reference it seems the first instruction being disassembled as sub.l A0, A0
is correct. The address 'vector_table' in the instruction as presented to the assembler is zero and the assembler has optimised this to the subtract instead.
In 68020 mode, and maybe others too, the assemble is incorrectly disassembling some instructions. Using as an example the following code in ROM, the assembler reports the assembled code as:
In each case the generated output is on the line immediately after the line being assembled. This is written to an ROM being emulated in an emulator with the corresponding section of the ROM having the following hexdump:
The m68kdasm module disassembles this as:
There is some similarity suggesting it is looking at the right region in memory but seems to be getting the instruction mnemonics completely wrong.