X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=disassembler%2Fmain.c;h=dbd2b5f066aa1a1bbbeb701ec4247b5ffd0ecac8;hb=5f64c0b044987477a749708afa6ce673609cd42c;hp=8ae804077b7055552788cac7fffd80a346a0b958;hpb=2e928c1b94243e38477f113b92d78876a15439be;p=b43-tools.git diff --git a/disassembler/main.c b/disassembler/main.c index 8ae8040..dbd2b5f 100644 --- a/disassembler/main.c +++ b/disassembler/main.c @@ -11,6 +11,7 @@ * GNU General Public License for more details. */ +#include "main.h" #include "list.h" #include "util.h" #include "args.h" @@ -20,20 +21,6 @@ #include #include -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) - -/* The header that fwcutter puts in to every .fw file */ -struct fw_header { - /* Type of the firmware data */ - uint8_t type; - /* Version number of the firmware data format */ - uint8_t ver; - uint8_t __padding[2]; - /* Size of the data. For ucode and PCM this is in bytes. - * For IV this is in number-of-ivs. */ - uint32_t size; -} __attribute__ ((__packed__)); - struct bin_instruction { unsigned int opcode; @@ -552,9 +539,13 @@ static void disasm_opcodes(struct disassembler_context *ctx) snprintf(str, 5, "0x%02X", (bin->opcode & 0x0FF)); stmt->u.insn.operands[0] = str; - disasm_std_operand(stmt, 0, 1, 0); - disasm_std_operand(stmt, 1, 2, 0); - stmt->u.insn.is_labelref = 3; + /* We don't disassemble the first and second operand, as + * that always is a dummy r0 operand. + * disasm_std_operand(stmt, 0, 1, 0); + * disasm_std_operand(stmt, 1, 2, 0); + * stmt->u.insn.is_labelref = 3; + */ + stmt->u.insn.is_labelref = 1; stmt->u.insn.labeladdr = stmt->u.insn.bin->operands[2]; break; case 0x700: @@ -564,9 +555,13 @@ static void disasm_opcodes(struct disassembler_context *ctx) snprintf(str, 5, "0x%02X", (bin->opcode & 0x0FF)); stmt->u.insn.operands[0] = str; - disasm_std_operand(stmt, 0, 1, 0); - disasm_std_operand(stmt, 1, 2, 0); - stmt->u.insn.is_labelref = 3; + /* We don't disassemble the first and second operand, as + * that always is a dummy r0 operand. + * disasm_std_operand(stmt, 0, 1, 0); + * disasm_std_operand(stmt, 1, 2, 0); + * stmt->u.insn.is_labelref = 3; + */ + stmt->u.insn.is_labelref = 1; stmt->u.insn.labeladdr = stmt->u.insn.bin->operands[2]; break; default: @@ -643,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) @@ -652,11 +648,13 @@ 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++) { if (stmt->u.insn.is_labelref == i) { - fprintf(outfile, ",%s", + fprintf(outfile, ", %s", stmt->u.insn.labelref->u.label.name); } if (!stmt->u.insn.operands[i]) @@ -664,12 +662,13 @@ static void emit_asm(struct disassembler_context *ctx) if (first) fprintf(outfile, "\t"); if (!first) - fprintf(outfile, ","); + fprintf(outfile, ", "); first = 0; fprintf(outfile, "%s", stmt->u.insn.operands[i]); } fprintf(outfile, "\n"); + addr++; break; case STMT_LABEL: fprintf(outfile, "%s:\n", stmt->u.label.name); @@ -694,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 != 'u') { - fprintf(stderr, "Corrupt input file. Not a microcode image.\n"); - goto err_close; - } - if (hdr.ver != 1) { - 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) {