From c5e27d0d9231595512f3d9fa0c83580aa4f66256 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 27 Sep 2013 16:53:51 -0700 Subject: [PATCH] disasm: add support for emitting split EA format Add support for emitting split EA format in the disassembler, indicated by the MIB instruction flag. Signed-off-by: H. Peter Anvin Signed-off-by: Jin Kyu Song --- disasm.c | 17 +++++++++++++++-- insns.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/disasm.c b/disasm.c index 9a5f9ad4..f50ceb91 100644 --- a/disasm.c +++ b/disasm.c @@ -955,7 +955,7 @@ int32_t disasm(uint8_t *data, char *output, int outbufsize, int segsize, uint8_t *origdata; int works; insn tmp_ins, ins; - iflags_t goodness, best; + iflags_t goodness, best, flags; int best_pref; struct prefix_info prefix; bool end_prefix; @@ -1174,6 +1174,7 @@ int32_t disasm(uint8_t *data, char *output, int outbufsize, int segsize, /* Pick the best match */ p = best_p; length = best_length; + flags = (*p)->flags; slen = 0; @@ -1331,7 +1332,7 @@ int32_t disasm(uint8_t *data, char *output, int outbufsize, int segsize, nasm_reg_names[(o->basereg-EXPR_REG_START)]); started = true; } - if (o->indexreg != -1) { + if (o->indexreg != -1 && !(flags & IF_MIB)) { if (started) output[slen++] = '+'; slen += snprintf(output + slen, outbufsize - slen, "%s", @@ -1395,6 +1396,18 @@ int32_t disasm(uint8_t *data, char *output, int outbufsize, int segsize, "%s0x%"PRIx32"", prefix, offset); } } + + if (o->indexreg != -1 && (flags & IF_MIB)) { + output[slen++] = ','; + slen += snprintf(output + slen, outbufsize - slen, "%s", + nasm_reg_names[(o->indexreg-EXPR_REG_START)]); + if (o->scale > 1) + slen += + snprintf(output + slen, outbufsize - slen, "*%d", + o->scale); + started = true; + } + output[slen++] = ']'; } else { slen += diff --git a/insns.h b/insns.h index b12d4ebb..61b04cce 100644 --- a/insns.h +++ b/insns.h @@ -104,6 +104,7 @@ extern const uint8_t nasm_bytecodes[]; #define IF_NOLONG 0x00000800UL /* it's not available in long mode */ #define IF_LONG 0x00001000UL /* long mode instruction */ #define IF_NOHLE 0x00002000UL /* HLE prefixes forbidden */ +#define IF_MIB 0x00004000UL /* Disassemble with split EA */ /* These flags are currently not used for anything - intended for insn set */ #define IF_UNDOC 0x8000000000UL /* it's an undocumented instruction */ #define IF_HLE 0x4000000000UL /* HACK NEED TO REORGANIZE THESE BITS */ -- 2.11.4.GIT