minivmac4ios/Mini vMac/mnvm_core/DISAM68K.c

1 line
53 KiB
C
Raw Normal View History

/* DISAM68K.c Copyright (C) 2010 Paul C. Pratt You can redistribute this file and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. You should have received a copy of the license along with this file; see the file COPYING. This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ /* DISAssemble Motorola 68K instructions. */ #ifndef AllFiles #include "SYSDEPNS.h" #include "ENDIANAC.h" #include "MYOSGLUE.h" #include "EMCONFIG.h" #include "GLOBGLUE.h" #include "M68KITAB.h" #endif #include "DISAM68K.h" LOCALVAR ui5r Disasm_pc; /* don't use get_vm_byte/get_vm_word/get_vm_long so as to be sure of no side effects (if pc points to memory mapped device) */ LOCALVAR ui3p Disasm_pcp; LOCALVAR ui5r Disasm_pc_blockmask; LOCALVAR ui3b Disasm_pcp_dummy[2] = { 0, 0 }; IMPORTFUNC ATTep FindATTel(CPTR addr); LOCALPROC Disasm_Find_pcp(void) { ATTep p; p = FindATTel(Disasm_pc); if (0 == (p->Access & kATTA_readreadymask)) { Disasm_pcp = Disasm_pcp_dummy; Disasm_pc_blockmask = 0; } else { Disasm_pc_blockmask = p->usemask & ~ p->cmpmask; Disasm_pc_blockmask = Disasm_pc_blockmask & ~ (Disasm_pc_blockmask + 1); Disasm_pcp = p->usebase + (Disasm_pc & p->usemask); } } LOCALFUNC ui4r Disasm_nextiword(void) /* NOT sign extended */ { ui4r r = do_get_mem_word(Disasm_pcp); Disasm_pcp += 2; Disasm_pc += 2; if (0 == (Disasm_pc_blockmask & Disasm_pc)) { Disasm_Find_pcp(); } return r; } LOCALINLINEFUNC ui3r Disasm_nextibyte(void) { return (ui3b) Disasm_nextiword(); } LOCALFUNC ui5r Disasm_nextilong(void) { ui5r hi = Disasm_nextiword(); ui5r lo = Disasm_nextiword(); ui5r r = ((hi << 16) & 0xFFFF0000) | (lo & 0x0000FFFF); return r; } LOCALPROC Disasm_setpc(CPTR newpc) { if (newpc != Disasm_pc) { Disasm_pc = newpc; Disasm_Find_pcp(); } } LOCALVAR ui5b Disasm_opcode; LOCALVAR ui5b Disasm_opsize; #define Disasm_b76 ((Disasm_opcode >> 6) & 3) #define Disasm_b8 ((Disasm_opcode >> 8) & 1) #define Disasm_mode ((Disasm_opcode >> 3) & 7) #define Disasm_reg (Disasm_opcode & 7) #define Disasm_md6 ((Disasm_opcode >> 6) & 7) #define Disasm_rg9 ((Disasm_opcode >> 9) & 7) LOCALPROC DisasmOpSizeFromb76(void) { Disasm_opsize = 1 << Disasm_b76; switch (Disasm_opsize) { case 1 : dbglog_writeCStr(".B"); break; case 2 : dbglog_writeCStr(".W"); break; case 4 : dbglog_writeCStr(".L"); break; } } LOCALPROC DisasmModeRegister(ui5b themode, ui5b thereg) { switch (themode) { case 0 : dbglog_writeCStr("D"); dbglog_writeHex(thereg); break; case 1 : dbglog_writeCStr("A"); dbglog_writeHex(thereg); break; case 2 : dbglog_writeCStr("(A"); dbglog_writeHex(thereg); dbglog_writeCStr(")"); break; case 3 : dbglog_writeCStr("(A"); dbglog_writeHex(thereg); dbglog_writeCStr(")+"); break; case 4 : dbglog_writeCStr("-(A"); dbglog_writeHex(thereg); dbglog_writeCStr(")"); break; case 5 : dbglog_writeHex(Disasm_nextiword()); dbglog_writeCStr("(A"); dbglog_writeHex(thereg); dbglog_writeCStr(")"); break; case 6 : dbglog_writeCStr("???"); #if 0 ArgKind = AKMemory; ArgAddr.mem = get_disp_ea(m68k_areg(thereg)); #endif break; case 7 : switch (thereg) { case 0 : dbglog_writeCStr("("); dbglog_writeHex(Disasm_nextiword()); dbglog_writeCStr(")"); break; case 1 : dbglog_writeCStr("("); dbglog_writeHex(Disasm_nextilong()); dbglog_writeCStr(")"); break; case 2 : { ui5r s = Disasm_pc; s += ui5r_FromSWord(Disasm_nextiword()); dbglog_writeCStr("("); dbglog_writeHex(s); dbglog_writeCStr(")"); } break; case 3 : dbglog_writeCStr("???"); #if 0 ArgKind = AKMemory; s = get_disp_ea(Disasm_pc); #endif break; case 4 : dbglog_writeCStr("#"); if (Disasm_opsize == 2)