|
|
1.1 ! root 1: /* Generator is (c) James Ponder, 1997-2001 http://www.squish.net/generator/ */ ! 2: ! 3: #include <stdio.h> ! 4: #include <string.h> ! 5: #include <ctype.h> ! 6: ! 7: #include "generator.h" ! 8: #include "cpu68k.h" ! 9: ! 10: /* forward references */ ! 11: ! 12: void diss68k_getoperand(char *text, t_ipc *ipc, t_iib *iib, t_type type); ! 13: ! 14: /* functions */ ! 15: ! 16: int diss68k_gettext(t_ipc *ipc, char *text) ! 17: { ! 18: t_iib *iib; ! 19: char *p, *c; ! 20: char src[64], dst[64]; ! 21: char mnemonic[64]; ! 22: ! 23: *text = '\0'; ! 24: ! 25: iib = cpu68k_iibtable[ipc->opcode]; ! 26: ! 27: if (iib == NULL) ! 28: return 0; ! 29: ! 30: diss68k_getoperand(dst, ipc, iib, tp_dst); ! 31: diss68k_getoperand(src, ipc, iib, tp_src); ! 32: ! 33: if ((iib->mnemonic == i_Bcc) || (iib->mnemonic == i_BSR) || ! 34: (iib->mnemonic == i_DBcc)) { ! 35: sprintf(src, "$%08x", ipc->src); ! 36: } ! 37: ! 38: strcpy(mnemonic, mnemonic_table[iib->mnemonic].name); ! 39: ! 40: if ((p = strstr(mnemonic, "cc")) != NULL) { ! 41: if (iib->mnemonic == i_Bcc && iib->cc == 0) { ! 42: p[0] = 'R'; ! 43: p[1] = 'A'; ! 44: } else { ! 45: c = condition_table[iib->cc]; ! 46: strcpy(p, c); ! 47: } ! 48: } ! 49: ! 50: switch(iib->size) { ! 51: case sz_byte: ! 52: strcat(mnemonic, ".B"); ! 53: break; ! 54: case sz_word: ! 55: strcat(mnemonic, ".W"); ! 56: break; ! 57: case sz_long: ! 58: strcat(mnemonic, ".L"); ! 59: break; ! 60: default: ! 61: break; ! 62: } ! 63: ! 64: sprintf(text, "%-10s %s%s%s", mnemonic, src, dst[0] ? "," : "", dst); ! 65: ! 66: return 1; ! 67: } ! 68: ! 69: void diss68k_getoperand(char *text, t_ipc *ipc, t_iib *iib, t_type type) ! 70: { ! 71: int bitpos; ! 72: uint32 val; ! 73: ! 74: if (type == tp_src) { ! 75: bitpos = iib->sbitpos; ! 76: val = ipc->src; ! 77: } else { ! 78: bitpos = iib->dbitpos; ! 79: val = ipc->dst; ! 80: } ! 81: ! 82: switch(type == tp_src ? iib->stype : iib->dtype) { ! 83: case dt_Dreg: ! 84: sprintf(text, "D%d", (ipc->opcode>>bitpos) & 7); ! 85: break; ! 86: case dt_Areg: ! 87: sprintf(text, "A%d", (ipc->opcode>>bitpos) & 7); ! 88: break; ! 89: case dt_Aind: ! 90: sprintf(text, "(A%d)", (ipc->opcode>>bitpos) & 7); ! 91: break; ! 92: case dt_Ainc: ! 93: sprintf(text, "(A%d)+", (ipc->opcode>>bitpos) & 7); ! 94: break; ! 95: case dt_Adec: ! 96: sprintf(text, "-(A%d)", (ipc->opcode>>bitpos) & 7); ! 97: break; ! 98: case dt_Adis: ! 99: sprintf(text, "$%04x(A%d)", (uint16)val, (ipc->opcode>>bitpos) & 7); ! 100: break; ! 101: case dt_Aidx: ! 102: sprintf(text, "$%02x(A%d,Rx.X)", (uint8)val, (ipc->opcode>>bitpos) & 7); ! 103: break; ! 104: case dt_AbsW: ! 105: sprintf(text, "$%08x", val); ! 106: break; ! 107: case dt_AbsL: ! 108: sprintf(text, "$%08x", val); ! 109: break; ! 110: case dt_Pdis: ! 111: sprintf(text, "$%08x(pc)", val); ! 112: break; ! 113: case dt_Pidx: ! 114: sprintf(text, "$%08x(pc, Rx.X)", val); ! 115: break; ! 116: case dt_ImmB: ! 117: sprintf(text, "#$%02x", val); ! 118: break; ! 119: case dt_ImmW: ! 120: sprintf(text, "#$%04x", val); ! 121: break; ! 122: case dt_ImmL: ! 123: sprintf(text, "#$%08x", val); ! 124: break; ! 125: case dt_ImmS: ! 126: sprintf(text, "#%d", iib->immvalue); ! 127: break; ! 128: case dt_Imm3: ! 129: sprintf(text, "#%d", (ipc->opcode>>bitpos) & 7); ! 130: break; ! 131: case dt_Imm4: ! 132: sprintf(text, "#%d", (ipc->opcode>>bitpos) & 15); ! 133: break; ! 134: case dt_Imm8: ! 135: sprintf(text, "#%d", (ipc->opcode>>bitpos) & 255); ! 136: break; ! 137: case dt_Imm8s: ! 138: sprintf(text, "#%d", (sint32)val); ! 139: break; ! 140: default: ! 141: sprintf(text, ""); ! 142: break; ! 143: } ! 144: } ! 145: ! 146: int diss68k_getdumpline(uint32 addr68k, uint8 *addr, char *dumpline) ! 147: { ! 148: t_ipc ipc; ! 149: t_iib *iibp = cpu68k_iibtable[LOCENDIAN16(*(uint16 *)addr)]; ! 150: int words, i; ! 151: char dissline[64], *p; ! 152: ! 153: if (addr68k < 256) { ! 154: sprintf(dissline, "dc.l $%08x", ! 155: LOCENDIAN32(*(uint32 *)addr)); ! 156: words = 2; ! 157: } else { ! 158: cpu68k_ipc(addr68k, addr, iibp, &ipc); ! 159: if (!diss68k_gettext(&ipc, dissline)) ! 160: strcpy(dissline, "Illegal Instruction"); ! 161: words = ipc.wordlen; ! 162: } ! 163: ! 164: p = dumpline; ! 165: p+= sprintf(p, "%6x : %04x ", addr68k, (addr[0]<<8) + addr[1]); ! 166: for (i = 1; i < words; i++) { ! 167: p+= sprintf(p, "%04x ", (addr[i*2]<<8) + addr[i*2+1]); ! 168: } ! 169: for (i = 29-strlen(dumpline); i > 0; i--) { ! 170: *p++ = ' '; ! 171: } ! 172: p+= sprintf(p, ": "); ! 173: for (i = 0; i < words; i++) { ! 174: if (isalnum(addr[i*2])) { ! 175: *p++ = addr[i*2]; ! 176: } else ! 177: *p++ = '.'; ! 178: if (isalnum(addr[i*2+1])) { ! 179: *p++ = addr[i*2+1]; ! 180: } else ! 181: *p++ = '.'; ! 182: } ! 183: *p = '\0'; ! 184: for (i = 39-strlen(dumpline); i > 0; i--) { ! 185: *p++ = ' '; ! 186: } ! 187: if (iibp) { ! 188: sprintf(p, " : %4d : %s\n", iibp->funcnum, dissline); ! 189: } else { ! 190: sprintf(p, " : : %s\n", dissline); ! 191: } ! 192: ! 193: return words; ! 194: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.