From 9eeaa0ea1f94111331ef64d4c8f47e267419ee78 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Sun, 25 Sep 2016 18:39:24 +0000 Subject: [PATCH] Minor fixes for 160-bit disassembly: (1) Print the default segment %ss before adresses relative to %bp. This is too cluttered for me, but so is printing some other default prefixes, and this is a reasonable reminder that %ss is quite likely to be different from %ds in 16-bit mode. db_disasm still handles prefixes poorly, by trying to discard redundant ones. This loses information, and sometimes the result is wrong or misleading. Clean up nearby initializations and dead code. (2) Fix decoding of operand and address size prefixes in 16-bit mode. They reverse the default in all modes. Obtained from: (1) is partly from r1.4 (2003/11/08) in DFlyBSD (?) --- sys/i386/i386/db_disasm.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sys/i386/i386/db_disasm.c b/sys/i386/i386/db_disasm.c index 5728fe5def08..b3a67636dd08 100644 --- a/sys/i386/i386/db_disasm.c +++ b/sys/i386/i386/db_disasm.c @@ -884,6 +884,7 @@ struct i_addr { const char * base; const char * index; int ss; + bool defss; /* set if %ss is the default segment */ }; static const char * const db_index_reg_16[8] = { @@ -955,10 +956,12 @@ db_read_address(loc, short_addr, regmodrm, addrp) } addrp->is_reg = FALSE; addrp->index = NULL; + addrp->ss = 0; + addrp->defss = FALSE; if (short_addr) { - addrp->index = NULL; - addrp->ss = 0; + if (rm == 2 || rm == 3 || (rm == 6 && mod != 0)) + addrp->defss = TRUE; switch (mod) { case 0: if (rm == 6) { @@ -985,7 +988,7 @@ db_read_address(loc, short_addr, regmodrm, addrp) } } else { - if (mod != 3 && rm == 4) { + if (rm == 4) { get_value_inc(sib, loc, 1, FALSE); rm = sib_base(sib); index = sib_index(sib); @@ -1036,6 +1039,9 @@ db_print_address(seg, size, addrp) if (seg) { db_printf("%s:", seg); } + else if (addrp->defss) { + db_printf("%%ss:"); + } db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY); if (addrp->base != NULL || addrp->index != NULL) { @@ -1189,11 +1195,11 @@ db_disasm(db_addr_t loc, bool altfmt) prefix = TRUE; do { switch (inst) { - case 0x66: /* data16 */ - size = WORD; + case 0x66: + size = (altfmt ? LONG : WORD); break; case 0x67: - short_addr = TRUE; + short_addr = !altfmt; break; case 0x26: seg = "%es";