?? inst2.c
字號:
/* * Author: Christopher G. Phillips * Copyright (C) 1994 All Rights Reserved * * NOTICE * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby granted * provided that the above copyright notice appear in all copies and * that both the copyright notice and this permission notice appear in * supporting documentation. * * The author makes no representations about the suitability of this * software for any purpose. This software is provided ``as is'' * without express or implied warranty. *//* * Most of the functions that determine whether an instruction is valid * and then print it (as necessary) are here. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include "dis.h"#include "addr.h"voidbit_dynamic(m68kword inst){ int destreg = inst & 7; int destmode = (inst >> 3) & 7; int type = (inst >> 6) & 3; int srcreg = (inst >> 9) & 7; int size = (destmode == 0) ? LONGWORD : BYTE; char name[10]; if (type == 0) { /* BTST */ if (!ISDEA(destmode, destreg)) return; } else { /* BCHG, BCLR, BSET */ if (!ISADEA(destmode, destreg)) return; } sprintf(name, "B%s", bitd[type]); if (getea(buf2, destreg, destmode, size)) return; sprintf(buf1, "D%d", srcreg); instprint(ops2f(2) | size2f(size), name, buf1, buf2); valid = 1;}voidbit_static(m68kword inst){ int reg = inst & 7; int mode = (inst >> 3) & 7; int type = (inst >> 6) & 3; int size = (ISDATA(mode)) ? LONGWORD : BYTE; long value; int failure; char name[10]; if (type == 0) { /* BTST */ if (!ISDEAlessIMM(mode, reg)) return; } else { /* BCHG, BCLR, BSET */ if (!ISADEA(mode, reg)) return; } value = getval(/* BYTE */ WORD, &failure); if (failure) return; if (value & 0xff00) return; if (!ISDATA(mode)) value %= 8; sprintf(name, "B%s", bitd[type]); if (getea(buf2, reg, mode, size)) return; immsprintf(buf1, value); instprint(ops2f(2) | size2f(size) | sharp2f(1), name, buf1, buf2); valid = 1;}voidbiti_reg(const char *name, int size, const char *reg){ long value; int failure; value = getval(size, &failure); if (failure) return; immsprintf(buf1, value); instprint(ops2f(2) | size2f(size) | sharp2f(1), name, buf1, reg); if (size == BYTE && (value & 0xff00)) return; valid = 1;}voidbiti_size(const char *name, m68kword inst){ int reg = inst & 7; int mode = (inst >> 3) & 7; int size = (inst >> 6) & 3; long value; int failure; if (name[0] == 'C') { /* CMPI */ if (!ISDEAlessIMM(mode, reg)) return; } else { /* ADDI, ANDI, EORI, ORI, SUBI */ if (!ISADEA(mode, reg)) return; } value = getval(size, &failure); if (failure) return; immsprintf(buf1, value); if (getea(buf2, reg, mode, size)) return; instprint(ops2f(2) | size2f(size) | sharp2f(1), name, buf1, buf2); valid = 1;}voidcmp2_chk2(m68kword inst){ int srcreg = inst & 7; int srcmode = (inst >> 3) & 7; int size = (inst >> 9) & 3; long value; int failure; int destreg; if (!ISCEA(srcmode, srcreg)) return; value = getval(WORD, &failure); if (failure) return; if (getea(buf1, srcreg, srcmode, size)) return; destreg = (value >> 12) & 7; Areg2(buf2, (value & 0x8000) ? 'A' : 'D', destreg); instprint(ops2f(2) | size2f(size), (value & 0x0800) ? "CHK2" : "CMP2", buf1, buf2); if (value & 0x07ff) return; valid = 1;}voidmovep(m68kword inst){ int addrreg = inst & 7; int datareg = (inst >> 9) & 7; int opmode = (inst >> 6) & 7; int size = (opmode & 1) ? LONGWORD : WORD; long value; int failure; value = getval(WORD, &failure); if (failure) return; sprintf(buf1, "D%d", datareg); immsprintf(buf2, value); sprintf(buf2 + strlen(buf2), "(%2.2s)", Areg(addrreg)); if (opmode & 2) instprint(ops2f(2) | size2f(size) | sharp2f(2), "MOVEP", buf1, buf2); else instprint(ops2f(2) | size2f(size) | sharp2f(1), "MOVEP", buf2, buf1); valid = 1;}voidcas(m68kword inst){ int reg = inst & 7; int mode = (inst >> 3) & 7; int size; int comparereg; int updatereg; long value; int failure; if (!ISAMEA(mode, reg)) return; switch ((inst >> 9) & 3) { case 1: size = BYTE; break; case 2: size = WORD; break; case 3: size = LONGWORD; break; } value = getval(WORD, &failure); comparereg = value & 7; updatereg = (value >> 6) & 7; if (failure) return; sprintf(buf1, "D%d", comparereg); sprintf(buf2, "D%d", updatereg); if (getea(buf3, reg, mode, size)) return; instprint(ops2f(3) | size2f(size), "CAS", buf1, buf2, buf3); if (value & 0xfe38) return; valid = 1;}voidcas2(m68kword inst){ int size = (inst & 0x0200) ? LONGWORD : WORD; long value[2]; int failure; int comparereg[2]; int updatereg[2]; int reg[2]; int anotd[2]; int i; for (i = 0; i < 2; i++) { value[i] = getval(WORD, &failure); if (failure) return; comparereg[i] = value[i] & 7; updatereg[i] = (value[i] >> 6) & 7; reg[i] = (value[i] >> 12) & 7; anotd[i] = (value[i] & 0x8000) ? 'A' : 'D'; } sprintf(buf1, "D%d:D%d", comparereg[0], comparereg[1]); sprintf(buf2, "D%d:D%d", updatereg[0], updatereg[1]); Areg2(buf3, anotd[0], reg[0]); buf3[2] = ':'; Areg2(&buf3[3], anotd[1], reg[1]); instprint(ops2f(3) | size2f(size), "CAS2", buf1, buf2, buf3); valid = 1;}voidmoves(m68kword inst){ int srcreg = inst & 7; int srcmode = (inst >> 3) & 7; int size = (inst >> 6) & 3; long value; int failure; int reg; int anotd; char *cp1 = buf1, *cp2 = buf2; if (!ISAMEA(srcmode, srcreg)) return; value = getval(WORD, &failure); if (failure) return; reg = (value >> 12) & 7; anotd = (value & 0x8000) ? 'A' : 'D'; if (getea(buf1, srcreg, srcmode, size)) return; Areg2(buf2, anotd, reg); if (value & 0x0800) { cp1 = buf2; cp2 = buf1; } instprint(ops2f(2) | size2f(size), "MOVES", cp1, cp2); if (value & 0x07ff) return; valid = 1;}voidmove(m68kword inst, int size){ int srcreg, destreg; int srcmode, destmode; srcreg = inst & 7; srcmode = (inst >> 3) & 7; destmode = (inst >> 6) & 7; destreg = (inst >> 9) & 7; if (ISDIRECT(destmode)) { if (size == BYTE) return; } else if (size == BYTE && ISDIRECT(srcmode) || !ISAEA(destmode, destreg)) return; if (getea(buf1, srcreg, srcmode, size)) return; if (ISDIRECT(destmode)) { sprintf(buf2, "%2.2s", Areg(destreg)); instprint(ops2f(2) | size2f(size), "MOVEA", buf1, buf2); } else { if (getea(buf2, destreg, destmode, size)) return; instprint(ops2f(2) | size2f(size), "MOVE", buf1, buf2); } valid = 1;}voidmisc_size(const char *name, m68kword inst){ int reg = inst & 7; int mode = (inst >> 3) & 7; int size = (inst >> 6) & 3; if (name[0] == 'T') { /* TST */ if (size == BYTE && !ISDEAlessIMM(mode, reg)) return; } else { /* CLR, NEG, NEGX, NOT */ if (!ISADEA(mode, reg)) return; } if (getea(buf1, reg, mode, size)) return; instprint(ops2f(1) | size2f(size), name, buf1); valid = 1;}voidmisc_ea(const char *name, m68kword inst, int size){ int reg = inst & 7; int mode = (inst >> 3) & 7; if (name[1] < 'C') { /* NBCD, TAS */ if (!ISADEA(mode, reg)) return; } else { /* JMP, JSR, PEA */ if (!ISCEA(mode, reg)) return; } if (getea(buf1, reg, mode, size)) return; instprint(ops2f(1), name, buf1); valid = 1;}voidchk(m68kword inst){ int srcreg = inst & 7; int srcmode = (inst >> 3) & 7; int destreg = (inst >> 9) & 7; if (!ISDEA(srcmode, srcreg)) return; if (getea(buf1, srcreg, srcmode, WORD)) return; sprintf(buf2, "D%d", destreg); instprint(ops2f(2), "CHK", buf1, buf2); valid = 1;}voidlea(m68kword inst){ int srcreg = inst & 7; int srcmode = (inst >> 3) & 7; int destreg = (inst >> 9) & 7; int retval; if (!ISCEA(srcmode, srcreg)) return; retval = getea(buf1, srcreg, srcmode, LONGWORD); if (retval) return; sprintf(buf2, "%2.2s", Areg(destreg)); instprint(ops2f(2), "LEA", buf1, buf2); valid = 1;}voidlink(m68kword inst, int size){ int reg = inst & 7; long value; int failure; value = getval(size, &failure); if (failure) return; sprintf(buf1, "%2.2s", Areg(reg)); sprintf(buf2, "%ld", value); instprint(ops2f(2) | sharp2f(2), "LINK", buf1, buf2); valid = 1;}voidunlk(m68kword inst){ int reg = inst & 7; sprintf(buf1, "%2.2s", Areg(reg)); instprint(ops2f(1), "UNLK", buf1); valid = 1;}voidswap(m68kword inst){ int reg = inst & 7; sprintf(buf1, "D%d", reg); instprint(ops2f(1), "SWAP", buf1); valid = 1;}voidbkpt(m68kword inst){ int vector = inst & 0xf; sprintf(buf1, "%d", vector); instprint(ops2f(1) | sharp2f(1), "BKPT", buf1); valid = 1;}voidtrap(m68kword inst){ int vector = inst & 0xf; sprintf(buf1, "%d", vector); instprint(ops2f(1) | sharp2f(1), "TRAP", buf1); valid = 1;}voidstop_rtd(const char *name){ int value; int failure; value = getval(WORD, &failure); if (failure) return; sprintf(buf1, "%ld", value); instprint(ops2f(1) | sharp2f(1), name, buf1); valid = 1;}voidmovec(int tocr){ long value; int failure; int reg; int anotd; int controlreg; char *cr; char *cp1; char *cp2; value = getval(WORD, &failure); if (failure) return; reg = (value >> 12) & 7; anotd = (value & 0x8000) ? 'A' : 'D'; controlreg = value & 0x0fff; Areg2(buf1, anotd, reg); switch (controlreg) { case 0x000: cr = "SFC"; break; /* Source Function Code */ case 0x001: cr = "DFC"; break; /* Destination Function Code */ case 0x002: cr = "CACR"; break; /* Cache Control Register */ case 0x800: cr = "USP"; break; /* User Stack Pointer */ case 0x801: cr = "VBR"; break; /* Vector Base Register */ case 0x802: cr = "CAAR"; break; /* Cache Address Register */ case 0x803: cr = "MSP"; break; /* Master Stack Pointer */ case 0x804: cr = "ISP"; break; /* Interrupt Stack Pointer */ default: return; } if (tocr) { cp1 = buf1; cp2 = cr; } else { cp1 = cr; cp2 = buf1; } instprint(ops2f(2), "MOVEC", cp1, cp2); valid = 1;}voidext(m68kword inst){ int reg = inst & 3; int opmode = (inst >> 6) & 3; int size = (opmode == 2) ? WORD : LONGWORD; char sext[5]; sprintf(buf1, "D%d", reg); strcpy(sext, "EXT"); if (inst & 0x0100) strcat(sext, "B"); instprint(ops2f(1) | size2f(size), sext, buf1); valid = 1;}voidmovereg(m68kword inst, const char *regname, int to){ int reg = inst & 7; int mode = (inst >> 3) & 7; const char *cp1, *cp2; if (getea(buf1, reg, mode, WORD)) return; if (to) { if (!ISDEA(mode, reg)) return; cp1 = buf1; cp2 = regname; } else { if (!ISADEA(mode, reg)) return; cp1 = regname; cp2 = buf1; } instprint(ops2f(2) | size2f(WORD), "MOVE", cp1, cp2); valid = 1;}voidmoveusp(m68kword inst, int to){ int reg = inst & 7; char *cp1 = buf1, *cp2 = "USP"; sprintf(buf1, "%2.2s", Areg(reg)); if (!to) { cp1 = cp2; cp2 = buf1; } instprint(ops2f(2) | size2f(LONGWORD), "MOVE", cp1, cp2); valid = 1;}static voidreglist(char *s, unsigned long regmask, int mode){ char *t = s; if (mode == 4) revbits(®mask, 16); s = regbyte(s, regmask & 0xff, "D", 0); s = regbyte(s, regmask >> 8, "A", s != t); if (s == t) strcpy(s, "0");}voidmovem(m68kword inst, int to){ int reg = inst & 7; int mode = (inst >> 3) & 7; int size = (inst & 0x40) ? LONGWORD : WORD; unsigned long regmask; int failure; char *cp1, *cp2; regmask = getval(WORD, &failure) & 0xffff; if (failure)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -