int _debug;
bool arg_print_sizes;
+const char *initvals_fn_extension = ".initvals";
+const char *real_infile_name;
+
#define ARG_MATCH 0
#define ARG_NOMATCH 1
static int do_cmp_arg(char **argv, int *pos,
const char *template,
int allow_merged,
- char **param)
+ const char **param)
{
char *arg;
char *next_arg;
static int cmp_arg(char **argv, int *pos,
const char *long_template,
const char *short_template,
- char **param)
+ const char **param)
{
int err;
static void usage(int argc, char **argv)
{
- fprintf(stderr, "Usage: %s INPUT_FILE OUTPUT_FILE [OPTIONS]\n", argv[0]);
- fprintf(stderr, " -h|--help Print this help\n");
- fprintf(stderr, " -d|--debug Print verbose debugging info\n");
- fprintf(stderr, " Repeat for more verbose debugging\n");
- fprintf(stderr, " -s|--psize Print the size of the code after assembling\n");
+ printf("Usage: %s INPUT_FILE OUTPUT_FILE [OPTIONS]\n", argv[0]);
+ printf(" -h|--help Print this help\n");
+ printf(" -d|--debug Print verbose debugging info\n");
+ printf(" Repeat for more verbose debugging\n");
+ printf(" -s|--psize Print the size of the code after assembling\n");
+ printf(" -e|--ivalext EXT Filename extension for the initvals\n");
}
int parse_args(int argc, char **argv)
_debug++;
} else if ((res = cmp_arg(argv, &i, "--psize", "-s", 0)) == ARG_MATCH) {
arg_print_sizes = 1;
+ } else if ((res = cmp_arg(argv, &i, "--ivalext", "-e", &initvals_fn_extension)) == ARG_MATCH) {
+ /* initvals_fn_extension is set to the extension. */
+ } else if ((res = cmp_arg(argv, &i, "--__real_infile", 0, &real_infile_name)) == ARG_MATCH) {
+ /* real_infile_name is set. */
} else {
fprintf(stderr, "Unrecognized argument: %s\n", argv[i]);
goto out_usage;
}
}
+ if (!real_infile_name)
+ real_infile_name = infile_name;
+ if (strcmp(real_infile_name, outfile_name) == 0) {
+ fprintf(stderr, "Error: INPUT and OUTPUT filename must not be the same\n");
+ goto out_usage;
+ }
+
return 0;
out_usage:
usage(argc, argv);
hdr.ver = FW_HDR_VER;
hdr.size = cpu_to_be32(ctx->ivals_count);
- fn_len = strlen(outfile_name) + 512;
+ fn_len = strlen(ctx->sect->name) + strlen(initvals_fn_extension ? : "") + 1;
fn = xmalloc(fn_len);
- snprintf(fn, fn_len, "%s.%s.initvals", outfile_name, ctx->sect->name);
+ snprintf(fn, fn_len, "%s%s", ctx->sect->name, initvals_fn_extension ? : "");
fd = fopen(fn, "w+");
if (!fd) {
fprintf(stderr, "Could not open initval output file \"%s\"\n", fn);
static void emit_code(struct assembler_context *ctx)
{
FILE *fd;
- char *fn;
- size_t fn_len;
+ const char *fn;
struct code_output *c;
uint64_t code;
unsigned char outbuf[8];
unsigned int insn_count = 0;
struct fw_header hdr;
- fn_len = strlen(outfile_name) + 20;
- fn = xmalloc(fn_len);
- snprintf(fn, fn_len, "%s.ucode", outfile_name);
+ fn = outfile_name;
fd = fopen(fn, "w+");
if (!fd) {
fprintf(stderr, "Could not open microcode output file \"%s\"\n", fn);
- free(fn);
exit(1);
}
if (IS_VERBOSE_DEBUG)
}
fclose(fd);
- free(fn);
}
static void assemble(void)