From 25959448ab2f74d35b31b4491700e2bbe3d4b5f4 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 16 Jul 2018 21:31:35 -0700 Subject: [PATCH] Fix repeated disassemble - An odd disassemble length is rounded up to the next even length. - A repeated disassemble starts from the next possible instrunction address. --- ui/devcmd.c | 8 +++++--- util/output_util.c | 7 ++++++- util/output_util.h | 7 +++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ui/devcmd.c b/ui/devcmd.c index fa40bfa..fc15343 100644 --- a/ui/devcmd.c +++ b/ui/devcmd.c @@ -399,7 +399,9 @@ int cmd_dis(char **arg) len_text); return -1; } - } else if (offset < 0x10000 && offset + length > 0x10000) { + } + length += (length & 1); + if (offset < 0x10000 && offset + length > 0x10000) { length = 0x10000 - offset; } @@ -414,8 +416,8 @@ int cmd_dis(char **arg) return -1; } - reader_set_repeat("dis 0x%x 0x%x", offset + length, length); - disassemble(offset, buf, length, device_default->power_buf); + offset = disassemble(offset, buf, length, device_default->power_buf); + reader_set_repeat("dis 0x%x 0x%x", offset, length); free(buf); return 0; } diff --git a/util/output_util.c b/util/output_util.c index 76c38f7..e66b985 100644 --- a/util/output_util.c +++ b/util/output_util.c @@ -205,12 +205,13 @@ static int dis_format(const struct msp430_instruction *insn) return len; } -void disassemble(address_t offset, const uint8_t *data, int length, +address_t disassemble(address_t offset, const uint8_t *data, int length, powerbuf_t power) { int first_line = 1; unsigned long long ua_total = 0; int samples_total = 0; + address_t next_offset = offset; while (length) { struct msp430_instruction insn = {0}; @@ -231,6 +232,8 @@ void disassemble(address_t offset, const uint8_t *data, int length, first_line = 0; retval = dis_decode(data, offset, length, &insn); + if (retval > 0) + next_offset = offset + retval; count = retval > 0 ? retval : 2; if (count > length) count = length; @@ -279,6 +282,8 @@ void disassemble(address_t offset, const uint8_t *data, int length, (double)(ua_total * power->interval_us) / 1000000.0, (double)(samples_total * power->interval_us) / 1000.0, (double)ua_total / (double)samples_total); + + return next_offset; } void hexdump(address_t addr, const uint8_t *data, int data_len) diff --git a/util/output_util.h b/util/output_util.h index eac99fd..1815d1f 100644 --- a/util/output_util.h +++ b/util/output_util.h @@ -23,8 +23,11 @@ #include "util.h" #include "powerbuf.h" -/* Print colorized disassembly on command processor standard output */ -void disassemble(address_t addr, const uint8_t *buf, int len, +/* Print colorized disassembly on command processor standard output. + * + * Returns the next possible instruction address. + */ +address_t disassemble(address_t addr, const uint8_t *buf, int len, powerbuf_t power); /* Print colorized hexdump on standard output */