summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2015-05-11 20:52:25 -0500
committerBobby Bingham <koorogi@koorogi.info>2015-09-15 22:43:32 -0500
commitb22e3a405df560f0c8828c5448aafdf05332e86e (patch)
tree8c6b18196769f13c3b49f7d695468d80b861e0d6
parent35b0f3c11892cbdfc67e484ba2b94c8ffb5d1545 (diff)
add a default initial program
This initial program will simply jump to the address to which the first read file is loaded. This is what 90% of callers will probably want.
-rw-r--r--src/satmkboot.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/satmkboot.c b/src/satmkboot.c
index 71232dc..6abae51 100644
--- a/src/satmkboot.c
+++ b/src/satmkboot.c
@@ -76,6 +76,26 @@ static int write_output(FILE *fp)
return ferror(fp) ? -1 : 0;
}
+static size_t default_ip(char *out)
+{
+ size_t size = 0;
+
+ out[size++] = 0xd0; /* mov.l addr, r0 */
+ out[size++] = 0x01;
+ out[size++] = 0x40; /* jmp @r0 */
+ out[size++] = 0x2b;
+ out[size++] = 0x00; /* nop */
+ out[size++] = 0x09;
+ out[size++] = 0x00; /* nop */
+ out[size++] = 0x09;
+ out[size++] = sysid.load_addr >> 24 & 0xff; /* addr: .long <sysid.load_addr> */
+ out[size++] = sysid.load_addr >> 16 & 0xff;
+ out[size++] = sysid.load_addr >> 8 & 0xff;
+ out[size++] = sysid.load_addr >> 0 & 0xff;
+
+ return size;
+}
+
static size_t load_ip(char *filename, char *out, size_t maxsize)
{
FILE *fp;
@@ -131,10 +151,10 @@ static void usage(const char *progname)
const int width = 20;
fprintf(stderr, "usage: %s -h\n", progname);
- fprintf(stderr, " %s -io[prms]\n\n", progname);
+ fprintf(stderr, " %s -o[iprms]\n\n", progname);
fprintf(stderr, "\t%-*s%s\n", width, "-h", "Show this help text");
- fprintf(stderr, "\t%-*s%s\n", width, "-i ip.bin", "Initial program code file");
fprintf(stderr, "\t%-*s%s\n", width, "-o output", "Output file");
+ fprintf(stderr, "\t%-*s%s\n", width, "-i ip.bin", "Initial program code file");
fprintf(stderr, "\t%-*s%s\n", width, "-p peripherals", "Supported peripherals (default: control pad):");
print_symbols(stderr, width, peripheraldefs);
fprintf(stderr, "\t%-*s%s\n", width, "-r regions", "Geographical regions (default: all):");
@@ -260,7 +280,7 @@ static int process_args(int argc, char **argv)
} else if (!fail) {
if (argv[optind])
errors = show_arg_error(argv[0], errors, ERR_UNKNOWN_OPTION);
- if (!ipfile || !outfile)
+ if (!outfile)
errors = show_arg_error(argv[0], errors, ERR_MISSING_OPTION);
fail = errors;
}
@@ -290,9 +310,10 @@ int main(int argc, char **argv)
if (region) ipout = serialize_region_code(ipout, region);
}
- if ((ipsize = load_ip(ipfile, ipout, sizeof ipbuf - (ipout - ipbuf))) == -1) {
- goto fail;
- }
+ ipsize = ipfile
+ ? load_ip(ipfile, ipout, sizeof ipbuf - (ipout - ipbuf))
+ : default_ip(ipout);
+ if (ipsize == -1) goto fail;
sysid.bootsize += ipsize;
if (!(outfp = fopen(outfile, "wb"))) {