Skip to content

Commit fcd6d67

Browse files
committed
fix get_with_index_address_mode
1 parent 96bfa47 commit fcd6d67

6 files changed

Lines changed: 804 additions & 285 deletions

File tree

arch/M68K/M68KDisassembler.c

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -460,26 +460,17 @@ static void get_with_index_address_mode(m68k_info *info, cs_m68k_op *op,
460460
EXT_INDEX_REGISTER(extension);
461461
op->mem.index_size = EXT_INDEX_LONG(extension) ? 1 : 0;
462462

463-
if (EXT_8BIT_DISPLACEMENT(extension) == 0) {
464-
if (is_pc) {
465-
op->mem.base_reg = M68K_REG_PC;
466-
op->address_mode = M68K_AM_PCI_INDEX_BASE_DISP;
467-
} else {
468-
op->mem.base_reg = M68K_REG_A0 + (instruction & 7);
469-
}
463+
if (is_pc) {
464+
op->mem.base_reg = M68K_REG_PC;
465+
op->address_mode = M68K_AM_PCI_INDEX_8_BIT_DISP;
470466
} else {
471-
if (is_pc) {
472-
op->mem.base_reg = M68K_REG_PC;
473-
op->address_mode = M68K_AM_PCI_INDEX_8_BIT_DISP;
474-
} else {
475-
op->mem.base_reg = M68K_REG_A0 + (instruction & 7);
476-
op->address_mode = M68K_AM_AREGI_INDEX_8_BIT_DISP;
477-
}
478-
479-
op->mem.disp = (int8_t)(extension & 0xff);
480-
op->mem.disp_size = 0;
467+
op->mem.base_reg = M68K_REG_A0 + (instruction & 7);
468+
op->address_mode = M68K_AM_AREGI_INDEX_8_BIT_DISP;
481469
}
482470

471+
op->mem.disp = (int8_t)(extension & 0xff);
472+
op->mem.disp_size = 0;
473+
483474
if (EXT_INDEX_SCALE(extension)) {
484475
op->mem.scale = 1 << EXT_INDEX_SCALE(extension);
485476
}
@@ -754,7 +745,7 @@ static void build_imm_ea(m68k_info *info, int opcode, uint8_t size, int imm)
754745

755746
op0->type = M68K_OP_IMM;
756747
op0->address_mode = M68K_AM_IMMEDIATE;
757-
op0->imm = (unsigned int) imm;
748+
op0->imm = (unsigned int)imm;
758749

759750
get_ea_mode_op(info, op1, info->ir, size);
760751
}
@@ -1774,30 +1765,53 @@ static void d68020_cas_8(m68k_info *info)
17741765
/*
17751766
* MC68060 traps CAS/CAS2/CHK2/CMP2 for software emulation, but they remain
17761767
* valid opcodes and must still disassemble successfully.
1768+
* CAS/CAS2 are NOT available on CPU32 despite its TYPE_68020 overlap.
17771769
*/
17781770
LIMIT_CPU_TYPES(info, M68020_PLUS);
1771+
if (info->type & TYPE_CPU32) {
1772+
d68000_invalid(info);
1773+
return;
1774+
}
17791775
build_d_d_ea(info, M68K_INS_CAS, 1);
17801776
}
17811777

17821778
static void d68020_cas_16(m68k_info *info)
17831779
{
17841780
LIMIT_CPU_TYPES(info, M68020_PLUS);
1781+
if (info->type & TYPE_CPU32) {
1782+
d68000_invalid(info);
1783+
return;
1784+
}
17851785
build_d_d_ea(info, M68K_INS_CAS, 2);
17861786
}
17871787

17881788
static void d68020_cas_32(m68k_info *info)
17891789
{
17901790
LIMIT_CPU_TYPES(info, M68020_PLUS);
1791+
if (info->type & TYPE_CPU32) {
1792+
d68000_invalid(info);
1793+
return;
1794+
}
17911795
build_d_d_ea(info, M68K_INS_CAS, 4);
17921796
}
17931797

17941798
static void d68020_cas2_16(m68k_info *info)
17951799
{
1800+
LIMIT_CPU_TYPES(info, M68020_PLUS);
1801+
if (info->type & TYPE_CPU32) {
1802+
d68000_invalid(info);
1803+
return;
1804+
}
17961805
build_cas2(info, 2);
17971806
}
17981807

17991808
static void d68020_cas2_32(m68k_info *info)
18001809
{
1810+
LIMIT_CPU_TYPES(info, M68020_PLUS);
1811+
if (info->type & TYPE_CPU32) {
1812+
d68000_invalid(info);
1813+
return;
1814+
}
18011815
build_cas2(info, 4);
18021816
}
18031817

arch/M68K/M68KInstPrinter.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,25 @@ static void printAddressingMode(SStream *O, unsigned int pc,
230230
SStream_concat(O, "#$%" PRIx64, op->imm);
231231
break;
232232
case M68K_AM_PCI_INDEX_8_BIT_DISP:
233-
SStream_concat(O, "$%" PRIx32 "(pc,%s%s.%c)",
233+
SStream_concat(O, "$%" PRIx32 "(pc,%s%s.%c",
234234
pc + 2 + op->mem.disp, s_spacing,
235235
getRegName(op->mem.index_reg),
236236
op->mem.index_size ? 'l' : 'w');
237+
if (op->mem.scale > 1)
238+
SStream_concat(O, "%s*%s%" PRId8, s_spacing, s_spacing,
239+
op->mem.scale);
240+
SStream_concat0(O, ")");
237241
break;
238242
case M68K_AM_AREGI_INDEX_8_BIT_DISP:
239-
SStream_concat(O, "%s$%" PRIx16 "(%s,%s%s.%c)",
243+
SStream_concat(O, "%s$%" PRIx16 "(%s,%s%s.%c",
240244
op->mem.disp < 0 ? "-" : "", abs(op->mem.disp),
241245
getRegName(op->mem.base_reg), s_spacing,
242246
getRegName(op->mem.index_reg),
243247
op->mem.index_size ? 'l' : 'w');
248+
if (op->mem.scale > 1)
249+
SStream_concat(O, "%s*%s%" PRId8, s_spacing, s_spacing,
250+
op->mem.scale);
251+
SStream_concat0(O, ")");
244252
break;
245253
case M68K_AM_PCI_INDEX_BASE_DISP:
246254
case M68K_AM_AREGI_INDEX_BASE_DISP:

0 commit comments

Comments
 (0)