/*
- * Copyright (C) 2006-2007 Michael Buesch <mb@bu3sch.de>
+ * Copyright (C) 2006-2007 Michael Buesch <m@bues.ch>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
#include <unistd.h>
-int _debug;
-
struct cmdline_args cmdargs = {
- .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. */
+ .debug = 0,
+ .arch = 5,
+ .informat = FMT_B43,
+ .print_addresses = 0,
+ .unknown_decode = 0,
};
#define ARG_MATCH 0
if (param) {
/* Skip the parameter on the next iteration. */
(*pos)++;
- if (*param == 0) {
+ if (*param == NULL) {
fprintf(stderr, "%s needs a parameter\n", arg);
return ARG_ERROR;
}
return err;
}
-static void usage(int argc, char **argv)
+static void usage(FILE *fd, 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");
+ fprintf(fd, "Usage: %s INPUT_FILE OUTPUT_FILE [OPTIONS]\n", argv[0]);
+ fprintf(fd, " -a|--arch ARCH The architecture type of the input file (5 or 15)\n");
+ fprintf(fd, " -f|--format FMT Input file format. FMT must be one of:\n");
+ fprintf(fd, " raw-le32, raw-be32, b43\n");
+ fprintf(fd, " -p|--paddr Print the code addresses\n");
+ fprintf(fd, " -u|--unkdec Decode operands of unknown instructions\n");
+ fprintf(fd, " -d|--debug Print verbose debugging info\n");
+ fprintf(fd, " Repeat for more verbose debugging\n");
+ fprintf(fd, " -h|--help Print this help\n");
}
int parse_args(int argc, char **argv)
outfile_name = NULL;
for (i = 1; i < argc; i++) {
- if ((res = cmp_arg(argv, &i, "--help", "-h", 0)) == ARG_MATCH) {
- usage(argc, argv);
+ if ((res = cmp_arg(argv, &i, "--help", "-h", NULL)) == ARG_MATCH) {
+ usage(stdout, 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) {
+ } else if ((res = cmp_arg(argv, &i, "--format", "-f", ¶m)) == ARG_MATCH) {
+ if (strcasecmp(param, "raw-le32") == 0)
+ cmdargs.informat = FMT_RAW_LE32;
+ else if (strcasecmp(param, "raw-be32") == 0)
+ cmdargs.informat = FMT_RAW_BE32;
+ else if (strcasecmp(param, "b43") == 0)
+ cmdargs.informat = FMT_B43;
+ else {
+ fprintf(stderr, "Invalid -f|--format\n");
+ return -1;
+ }
+ } else if ((res = cmp_arg(argv, &i, "--paddr", "-p", NULL)) == 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, "--unkdec", "-u", NULL)) == ARG_MATCH) {
+ cmdargs.unknown_decode = 1;
+ } else if ((res = cmp_arg(argv, &i, "--debug", "-d", NULL)) == ARG_MATCH) {
+ cmdargs.debug++;
} else if ((res = cmp_arg(argv, &i, "--arch", "-a", ¶m)) == ARG_MATCH) {
unsigned long arch;
char *tail;
arch = strtol(param, &tail, 0);
- if (strlen(tail) || (arch != 5)) {
+ if (strlen(tail) || (arch != 5 && arch != 15)) {
fprintf(stderr, "Unsupported architecture \"%s\"\n",
param);
return -1;
return 0;
out_usage:
- usage(argc, argv);
+ usage(stderr, argc, argv);
return -1;
}