From: Michael Buesch Date: Thu, 19 Jun 2008 12:35:00 +0000 (+0200) Subject: b43-dasm: Allow disassembling files without header. X-Git-Tag: b43-fwcutter-013~35 X-Git-Url: https://jxself.org/git/?p=b43-tools.git;a=commitdiff_plain;h=5f64c0b044987477a749708afa6ce673609cd42c b43-dasm: Allow disassembling files without header. Also add a parameter to print the code addresses Signed-off-by: Michael Buesch --- diff --git a/disassembler/args.c b/disassembler/args.c index 2848089..d48100e 100644 --- a/disassembler/args.c +++ b/disassembler/args.c @@ -25,7 +25,9 @@ int _debug; struct cmdline_args cmdargs = { - .arch = 5, /* Default to v5 architecture. */ + .arch = 5, /* Default to v5 architecture. */ + .no_header = 0, /* Input file does not have a header. */ + .print_addresses = 0, /* Print the code addresses in the output. */ }; #define ARG_MATCH 0 @@ -99,6 +101,8 @@ static void usage(int argc, char **argv) fprintf(stderr, "Usage: %s INPUT_FILE OUTPUT_FILE [OPTIONS]\n", argv[0]); fprintf(stderr, " -a|--arch ARCH The architecture type of the input file\n"); fprintf(stderr, " -h|--help Print this help\n"); + fprintf(stderr, " --nohdr The input file does not have a header\n"); + fprintf(stderr, " --paddr Print the code addresses\n"); fprintf(stderr, " -d|--debug Print verbose debugging info\n"); fprintf(stderr, " Repeat for more verbose debugging\n"); } @@ -116,6 +120,10 @@ int parse_args(int argc, char **argv) if ((res = cmp_arg(argv, &i, "--help", "-h", 0)) == ARG_MATCH) { usage(argc, argv); return 1; + } else if ((res = cmp_arg(argv, &i, "--nohdr", 0, 0)) == ARG_MATCH) { + cmdargs.no_header = 1; + } else if ((res = cmp_arg(argv, &i, "--paddr", 0, 0)) == ARG_MATCH) { + cmdargs.print_addresses = 1; } else if ((res = cmp_arg(argv, &i, "--debug", "-d", 0)) == ARG_MATCH) { _debug++; } else if ((res = cmp_arg(argv, &i, "--arch", "-a", ¶m)) == ARG_MATCH) { diff --git a/disassembler/args.h b/disassembler/args.h index d13fa66..8dc69f2 100644 --- a/disassembler/args.h +++ b/disassembler/args.h @@ -3,6 +3,8 @@ struct cmdline_args { unsigned int arch; + int no_header; + int print_addresses; }; int parse_args(int argc, char **argv); diff --git a/disassembler/main.c b/disassembler/main.c index 718e33f..dbd2b5f 100644 --- a/disassembler/main.c +++ b/disassembler/main.c @@ -638,6 +638,7 @@ static void emit_asm(struct disassembler_context *ctx) struct statement *stmt; int first, i; int err; + unsigned int addr = 0; err = open_output_file(); if (err) @@ -647,6 +648,8 @@ static void emit_asm(struct disassembler_context *ctx) list_for_each_entry(stmt, &ctx->stmt_list, list) { switch (stmt->type) { case STMT_INSN: + if (cmdargs.print_addresses) + fprintf(outfile, "/* %03X */", addr); fprintf(outfile, "\t%s", stmt->u.insn.name); first = 1; for (i = 0; i < ARRAY_SIZE(stmt->u.insn.operands); i++) { @@ -665,6 +668,7 @@ static void emit_asm(struct disassembler_context *ctx) stmt->u.insn.operands[i]); } fprintf(outfile, "\n"); + addr++; break; case STMT_LABEL: fprintf(outfile, "%s:\n", stmt->u.label.name); @@ -689,18 +693,20 @@ static int read_input(struct disassembler_context *ctx) if (err) goto error; - ret = fread(&hdr, 1, sizeof(hdr), infile); - if (ret != sizeof(hdr)) { - fprintf(stderr, "Corrupt input file (not fwcutter output)\n"); - goto err_close; - } - if (hdr.type != FW_TYPE_UCODE) { - fprintf(stderr, "Corrupt input file. Not a microcode image.\n"); - goto err_close; - } - if (hdr.ver != FW_HDR_VER) { - fprintf(stderr, "Invalid input file header version.\n"); - goto err_close; + if (!cmdargs.no_header) { + ret = fread(&hdr, 1, sizeof(hdr), infile); + if (ret != sizeof(hdr)) { + fprintf(stderr, "Corrupt input file (not fwcutter output)\n"); + goto err_close; + } + if (hdr.type != FW_TYPE_UCODE) { + fprintf(stderr, "Corrupt input file. Not a microcode image.\n"); + goto err_close; + } + if (hdr.ver != FW_HDR_VER) { + fprintf(stderr, "Invalid input file header version.\n"); + goto err_close; + } } while (1) {