41 #include "../../cs_priv.h"
42 #include "../../utils.h"
44 #include "../../MCInst.h"
45 #include "../../MCInstrDesc.h"
46 #include "../../MCRegisterInfo.h"
52 #define DECL_SPEC __cdecl
64 #define uint unsigned int
67 #define BIT_0(A) ((A) & 0x00000001)
68 #define BIT_1(A) ((A) & 0x00000002)
69 #define BIT_2(A) ((A) & 0x00000004)
70 #define BIT_3(A) ((A) & 0x00000008)
71 #define BIT_4(A) ((A) & 0x00000010)
72 #define BIT_5(A) ((A) & 0x00000020)
73 #define BIT_6(A) ((A) & 0x00000040)
74 #define BIT_7(A) ((A) & 0x00000080)
75 #define BIT_8(A) ((A) & 0x00000100)
76 #define BIT_9(A) ((A) & 0x00000200)
77 #define BIT_A(A) ((A) & 0x00000400)
78 #define BIT_B(A) ((A) & 0x00000800)
79 #define BIT_C(A) ((A) & 0x00001000)
80 #define BIT_D(A) ((A) & 0x00002000)
81 #define BIT_E(A) ((A) & 0x00004000)
82 #define BIT_F(A) ((A) & 0x00008000)
83 #define BIT_10(A) ((A) & 0x00010000)
84 #define BIT_11(A) ((A) & 0x00020000)
85 #define BIT_12(A) ((A) & 0x00040000)
86 #define BIT_13(A) ((A) & 0x00080000)
87 #define BIT_14(A) ((A) & 0x00100000)
88 #define BIT_15(A) ((A) & 0x00200000)
89 #define BIT_16(A) ((A) & 0x00400000)
90 #define BIT_17(A) ((A) & 0x00800000)
91 #define BIT_18(A) ((A) & 0x01000000)
92 #define BIT_19(A) ((A) & 0x02000000)
93 #define BIT_1A(A) ((A) & 0x04000000)
94 #define BIT_1B(A) ((A) & 0x08000000)
95 #define BIT_1C(A) ((A) & 0x10000000)
96 #define BIT_1D(A) ((A) & 0x20000000)
97 #define BIT_1E(A) ((A) & 0x40000000)
98 #define BIT_1F(A) ((A) & 0x80000000)
105 #define TYPE_68040 16
107 #define M68000_ONLY TYPE_68000
109 #define M68010_ONLY TYPE_68010
110 #define M68010_LESS (TYPE_68000 | TYPE_68010)
111 #define M68010_PLUS (TYPE_68010 | TYPE_68020 | TYPE_68030 | TYPE_68040)
113 #define M68020_ONLY TYPE_68020
114 #define M68020_LESS (TYPE_68010 | TYPE_68020)
115 #define M68020_PLUS (TYPE_68020 | TYPE_68030 | TYPE_68040)
117 #define M68030_ONLY TYPE_68030
118 #define M68030_LESS (TYPE_68010 | TYPE_68020 | TYPE_68030)
119 #define M68030_PLUS (TYPE_68030 | TYPE_68040)
121 #define M68040_PLUS TYPE_68040
134 #define EXT_8BIT_DISPLACEMENT(A) ((A)&0xff)
135 #define EXT_FULL(A) BIT_8(A)
136 #define EXT_EFFECTIVE_ZERO(A) (((A)&0xe4) == 0xc4 || ((A)&0xe2) == 0xc0)
137 #define EXT_BASE_REGISTER_PRESENT(A) (!BIT_7(A))
138 #define EXT_INDEX_REGISTER_PRESENT(A) (!BIT_6(A))
139 #define EXT_INDEX_REGISTER(A) (((A)>>12)&7)
140 #define EXT_INDEX_PRE_POST(A) (EXT_INDEX_PRESENT(A) && (A)&3)
141 #define EXT_INDEX_PRE(A) (EXT_INDEX_PRESENT(A) && ((A)&7) < 4 && ((A)&7) != 0)
142 #define EXT_INDEX_POST(A) (EXT_INDEX_PRESENT(A) && ((A)&7) > 4)
143 #define EXT_INDEX_SCALE(A) (((A)>>9)&3)
144 #define EXT_INDEX_LONG(A) BIT_B(A)
145 #define EXT_INDEX_AR(A) BIT_F(A)
146 #define EXT_BASE_DISPLACEMENT_PRESENT(A) (((A)&0x30) > 0x10)
147 #define EXT_BASE_DISPLACEMENT_WORD(A) (((A)&0x30) == 0x20)
148 #define EXT_BASE_DISPLACEMENT_LONG(A) (((A)&0x30) == 0x30)
149 #define EXT_OUTER_DISPLACEMENT_PRESENT(A) (((A)&3) > 1 && ((A)&0x47) < 0x44)
150 #define EXT_OUTER_DISPLACEMENT_WORD(A) (((A)&3) == 2 && ((A)&0x47) < 0x44)
151 #define EXT_OUTER_DISPLACEMENT_LONG(A) (((A)&3) == 3 && ((A)&0x47) < 0x44)
153 #define IS_BITSET(val,b) ((val) & (1 << (b)))
154 #define BITFIELD_MASK(sb,eb) (((1 << ((sb) + 1))-1) & (~((1 << (eb))-1)))
155 #define BITFIELD(val,sb,eb) ((BITFIELD_MASK(sb,eb) & (val)) >> (eb))
163 return (v0 << 8) | v1;
172 return (v0 << 24) | (v1 << 16) | (v2 << 8) | v3;
185 return (v0 << 56) | (v1 << 48) | (v2 << 40) | (v3 << 32) | (v4 << 24) | (v5 << 16) | (v6 << 8) | v7;
210 return 0xaaaaaaaaaaaaaaaa
LL;
257 32, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
258 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
293 #define LIMIT_CPU_TYPES(info, ALLOWED_CPU_TYPES) \
295 if (!(info->type & ALLOWED_CPU_TYPES)) { \
296 d68000_invalid(info); \
312 #define get_ea_mode_str_8(instruction) get_ea_mode_str(instruction, 0)
313 #define get_ea_mode_str_16(instruction) get_ea_mode_str(instruction, 1)
314 #define get_ea_mode_str_32(instruction) get_ea_mode_str(instruction, 2)
316 #define get_imm_str_s8() get_imm_str_s(0)
317 #define get_imm_str_s16() get_imm_str_s(1)
318 #define get_imm_str_s32() get_imm_str_s(2)
320 #define get_imm_str_u8() get_imm_str_u(0)
321 #define get_imm_str_u16() get_imm_str_u(1)
322 #define get_imm_str_u32() get_imm_str_u(2)
386 }
else if (postindex) {
427 switch (instruction & 0x3f) {
428 case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x07:
435 case 0x08:
case 0x09:
case 0x0a:
case 0x0b:
case 0x0c:
case 0x0d:
case 0x0e:
case 0x0f:
442 case 0x10:
case 0x11:
case 0x12:
case 0x13:
case 0x14:
case 0x15:
case 0x16:
case 0x17:
448 case 0x18:
case 0x19:
case 0x1a:
case 0x1b:
case 0x1c:
case 0x1d:
case 0x1e:
case 0x1f:
454 case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24:
case 0x25:
case 0x26:
case 0x27:
460 case 0x28:
case 0x29:
case 0x2a:
case 0x2b:
case 0x2c:
case 0x2d:
case 0x2e:
case 0x2f:
467 case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34:
case 0x35:
case 0x36:
case 0x37:
541 op0 = &
ext->operands[0];
542 op1 = &
ext->operands[1];
566 op0 = &
ext->operands[0];
567 op1 = &
ext->operands[1];
587 op0 = &
ext->operands[0];
588 op1 = &
ext->operands[1];
589 op2 = &
ext->operands[2];
611 op0 = &
ext->operands[0];
612 op1 = &
ext->operands[1];
627 op0 = &
ext->operands[0];
628 op1 = &
ext->operands[1];
643 op0 = &
ext->operands[0];
644 op1 = &
ext->operands[1];
660 op0 = &
ext->operands[0];
661 op1 = &
ext->operands[1];
677 op0 = &
ext->operands[0];
678 op1 = &
ext->operands[1];
679 op2 = &
ext->operands[2];
707 op0 = &
ext->operands[0];
708 op1 = &
ext->operands[1];
722 op0 = &
ext->operands[0];
723 op1 = &
ext->operands[1];
735 op0 = &
ext->operands[0];
736 op1 = &
ext->operands[1];
751 op0 = &
ext->operands[0];
752 op1 = &
ext->operands[1];
767 op = &
ext->operands[0];
771 op->br_disp.disp = displacement;
772 op->br_disp.disp_size =
size;
783 op = &
ext->operands[0];
808 op0 = &
ext->operands[0];
809 op1 = &
ext->operands[1];
836 op0 = &
ext->operands[0];
837 op1 = &
ext->operands[1];
838 op2 = &
ext->operands[2];
858 op_ea = &
ext->operands[0];
859 op1 = &
ext->operands[1];
889 op = &
ext->operands[0];
900 for (
v >>= 1;
v;
v >>= 1) {
914 for (
v >>= 1;
v;
v >>= 1) {
930 op0 = &
ext->operands[0];
931 op1 = &
ext->operands[1];
948 op0 = &
ext->operands[0];
949 op1 = &
ext->operands[1];
964 op = &
ext->operands[0];
996 op0 = &
ext->operands[0];
997 op1 = &
ext->operands[1];
998 op2 = &
ext->operands[2];
1034 op0 = &
ext->operands[0];
1035 op1 = &
ext->operands[1];
1049 for (
i = 0;
i < 2; ++
i) {
1057 op->address_mode =
m;
1060 op->address_mode =
m;
1072 op0 = &
ext->operands[0];
1073 op1 = &
ext->operands[1];
1089 switch ((info->
ir >> 3) & 3) {
1109 op0 = &
ext->operands[0];
1110 op1 = &
ext->operands[1];
1114 op0->
imm = (info->
ir >> 6) & 3;
1127 op0 = &
ext->operands[0];
1128 op1 = &
ext->operands[1];
1144 op0 = &
ext->operands[0];
1145 op1 = &
ext->operands[1];
1162 op0 = &
ext->operands[0];
1163 op1 = &
ext->operands[1];
1557 ext->operands[0] =
ext->operands[1];
1803 op->br_disp.disp = displacement;
1804 op->br_disp.disp_size =
size;
1817 op0 = &
ext->operands[0];
1838 op0 = &
ext->operands[0];
1862 op0 = &
ext->operands[0];
1863 op1 = &
ext->operands[1];
1883 special = &
ext->operands[0];
1884 op_ea = &
ext->operands[1];
1896 else if (regsel & 2)
1898 else if (regsel & 1)
1911 op_reglist = &
ext->operands[0];
1912 op_ea = &
ext->operands[1];
1948 bool supports_single_op;
1950 int rm, src,
dst, opmode;
1955 supports_single_op =
true;
1960 src = (
next >> 10) & 0x7;
1962 opmode =
next & 0x3f;
1971 op0 = &
ext->operands[0];
1972 op1 = &
ext->operands[1];
1985 switch ((
next >> 13) & 0x7) {
2001 if ((
next >> 6) & 1)
2052 if ((
next >> 6) & 1) {
2053 if ((
next >> 2) & 1)
2063 ext->op_size.cpu_size = 0;
2065 op0 = &
ext->operands[0];
2066 op1 = &
ext->operands[1];
2068 if (
rm == 0 && supports_single_op && src ==
dst) {
2164 uint extension1, extension2;
2178 op0 = &
ext->operands[0];
2182 op0->
imm = extension2;
2187 uint extension1, extension2;
2201 op0 = &
ext->operands[0];
2205 op0->
imm = extension2;
2252 op0 = &
ext->operands[0];
2253 op1 = &
ext->operands[1];
2322 op0 = &
ext->operands[0];
2323 op1 = &
ext->operands[1];
2338 op0 = &
ext->operands[0];
2339 op1 = &
ext->operands[1];
2495 op0 = &
ext->operands[0];
2496 op1 = &
ext->operands[1];
2514 op0 = &
ext->operands[0];
2515 op1 = &
ext->operands[1];
2529 op0 = &
ext->operands[0];
2530 op1 = &
ext->operands[1];
2544 op0 = &
ext->operands[0];
2545 op1 = &
ext->operands[1];
2559 op0 = &
ext->operands[0];
2560 op1 = &
ext->operands[1];
2575 op0 = &
ext->operands[0];
2576 op1 = &
ext->operands[1];
2601 op0 = &
ext->operands[0];
2602 op1 = &
ext->operands[1];
2708 op0 = &
ext->operands[0];
2709 op1 = &
ext->operands[1];
2713 op0->
imm = (info->
ir & 0xff);
2798 op0 = &
ext->operands[0];
2799 op1 = &
ext->operands[1];
3114 op = &
ext->operands[0];
3385 op = &
ext->operands[0];
3480 {
d68020_bfchg , 0xffc0, 0xeac0, 0xa78, 0xf000, 0x0000},
3481 {
d68020_bfclr , 0xffc0, 0xecc0, 0xa78, 0xf000, 0x0000},
3484 {
d68020_bfffo , 0xffc0, 0xedc0, 0xa7b, 0x8000, 0x0000},
3485 {
d68020_bfins , 0xffc0, 0xefc0, 0xa78, 0x8000, 0x0000},
3486 {
d68020_bfset , 0xffc0, 0xeec0, 0xa78, 0xf000, 0x0000},
3487 {
d68020_bftst , 0xffc0, 0xe8c0, 0xa7b, 0xf000, 0x0000},
3499 {
d68020_callm , 0xffc0, 0x06c0, 0x27b, 0xff00, 0x0000},
3500 {
d68020_cas_8 , 0xffc0, 0x0ac0, 0x3f8, 0xfe38, 0x0000},
3546 {
d68020_divl , 0xff80, 0x4c00, 0xbff, 0x83f8, 0x0000},
3614 {
d68020_mull , 0xffc0, 0x4c00, 0xbff, 0x83f8, 0x0000},
3732 case 0x00:
case 0x01:
case 0x02:
case 0x03:
3733 case 0x04:
case 0x05:
case 0x06:
case 0x07:
3734 return (mask & 0x800) != 0;
3735 case 0x08:
case 0x09:
case 0x0a:
case 0x0b:
3736 case 0x0c:
case 0x0d:
case 0x0e:
case 0x0f:
3737 return (mask & 0x400) != 0;
3738 case 0x10:
case 0x11:
case 0x12:
case 0x13:
3739 case 0x14:
case 0x15:
case 0x16:
case 0x17:
3740 return (mask & 0x200) != 0;
3741 case 0x18:
case 0x19:
case 0x1a:
case 0x1b:
3742 case 0x1c:
case 0x1d:
case 0x1e:
case 0x1f:
3743 return (mask & 0x100) != 0;
3744 case 0x20:
case 0x21:
case 0x22:
case 0x23:
3745 case 0x24:
case 0x25:
case 0x26:
case 0x27:
3746 return (mask & 0x080) != 0;
3747 case 0x28:
case 0x29:
case 0x2a:
case 0x2b:
3748 case 0x2c:
case 0x2d:
case 0x2e:
case 0x2f:
3749 return (mask & 0x040) != 0;
3750 case 0x30:
case 0x31:
case 0x32:
case 0x33:
3751 case 0x34:
case 0x35:
case 0x36:
case 0x37:
3752 return (mask & 0x020) != 0;
3754 return (mask & 0x010) != 0;
3756 return (mask & 0x008) != 0;
3758 return (mask & 0x002) != 0;
3760 return (mask & 0x001) != 0;
3762 return (mask & 0x004) != 0;
3774 a = ((
a & 0xAAAA) >> 1) + (
a & 0x5555);
3775 a = ((
a & 0xCCCC) >> 2) + (
a & 0x3333);
3776 a = ((
a & 0xF0F0) >> 4) + (
a & 0x0F0F);
3777 a = ((
a & 0xFF00) >> 8) + (
a & 0x00FF);
3779 b = ((
b & 0xAAAA) >> 1) + (
b & 0x5555);
3780 b = ((
b & 0xCCCC) >> 2) + (
b & 0x3333);
3781 b = ((
b & 0xF0F0) >> 4) + (
b & 0x0F0F);
3782 b = ((
b & 0xFF00) >> 8) + (
b & 0x00FF);
3793 uint opcode_info_length = 0;
3801 opcode_info_length++;
3805 for(
i=0;
i<0x10000;
i++) {
3831 const unsigned int instruction = info->
ir;
3834 if ( (
i->word2_mask && ((word_check &
i->word2_mask) !=
i->word2_match)) ||
3880 switch (
op->address_mode) {
3918 for (
i = 0;
i < 8; ++
i) {
3919 if (
bits & (1 <<
i)) {
3935 switch ((
int)
op->type) {
3979 info->
type = cpu_type;
3982 switch(info->
type) {
4042 info->
pc = (
unsigned int)pc;
4102 if (s > (
int)code_len)