From 422606bb693ed02cd662b1426d00622416c15ef4 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 1 May 2024 16:36:02 -0400 Subject: xexamine: handle embedded run/init addresses in segments >2 bytes. --- xexamine.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/xexamine.c b/xexamine.c index 64ecb8b..567f5fd 100644 --- a/xexamine.c +++ b/xexamine.c @@ -309,7 +309,7 @@ int main(int argc, char **argv) { xex_segment seg; unsigned char buffer[65536]; char *filename; - int opt, offset, segcount = 0, only_segment = 0, header_printed = 0, decimal = 0, print_filenames = 0; + int opt, offset, segcount = 0, only_segment = 0, header_printed = 0, decimal = 0, print_filenames = 0, r, i; uint32_t crc; while((opt = getopt(argc, argv, "vhs:d")) != -1) { @@ -363,22 +363,26 @@ int main(int argc, char **argv) { if(!only_segment || (only_segment == segcount)) { if(!header_printed) { - printf("Seg | Offset | Start | End | Bytes | CRC32 | Type\n"); + printf("Seg | Offset | Start | End | Bytes | CRC32 | Code%% | Run/Init?\n"); header_printed++; } printf((decimal ? "%3d | %6d | %5d | %5d | %5d | %08x | " : - "%3d | %6d | $%04x | $%04x | %5d | %08x | "), - segcount, offset, seg.start_addr, seg.end_addr, seg.len, crc); - - /* TODO: what if there's a >=4 byte segment that loads at RUNAD? - the next 2 bytes are INITAD, we would silently ignore that fact. */ - if(seg.start_addr == XEX_RUNAD && seg.len > 1) - printf((decimal ? "Run %5d" : "Run $%04x"), (seg.object[0] | (seg.object[1] << 8))); - else if(seg.start_addr == XEX_INITAD && seg.len > 1) + "%3d | %6d | $%04x | $%04x | %5d | %08x | %4d%% | "), + segcount, offset, seg.start_addr, seg.end_addr, seg.len, crc, + classify_seg(seg)); + + r = xex_get_run_addr(&seg); + i = xex_get_init_addr(&seg); + if(r != -1) { + if(i == -1) putchar(' '); + printf((decimal ? "Run %5d" : "Run $%04x"), (seg.object[0] | (seg.object[1] << 8))); + } + if(i != -1) { + if(r != -1) printf(", "); printf((decimal ? "Init %5d" : "Init $%04x"), (seg.object[0] | (seg.object[1] << 8))); - else printf("%d%% code", classify_seg(seg)); + } putchar('\n'); } -- cgit v1.2.3