Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/amiga/stand/bootblock/aout2bb Change fixed-size buf...
details: https://anonhg.NetBSD.org/src/rev/a217578d7b84
branches: trunk
changeset: 519416:a217578d7b84
user: mhitch <mhitch%NetBSD.org@localhost>
date: Mon Dec 17 05:43:40 2001 +0000
description:
Change fixed-size buffers to variable, with an option to set the size for
the second stage loader.
Show the number of bytes remaining in the boot file image.
diffstat:
sys/arch/amiga/stand/bootblock/aout2bb/aout2bb.c | 37 ++++++++++++++++-------
1 files changed, 25 insertions(+), 12 deletions(-)
diffs (120 lines):
diff -r da5e7a9c9351 -r a217578d7b84 sys/arch/amiga/stand/bootblock/aout2bb/aout2bb.c
--- a/sys/arch/amiga/stand/bootblock/aout2bb/aout2bb.c Mon Dec 17 05:40:40 2001 +0000
+++ b/sys/arch/amiga/stand/bootblock/aout2bb/aout2bb.c Mon Dec 17 05:43:40 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: aout2bb.c,v 1.4 1999/02/16 23:34:10 is Exp $ */
+/* $NetBSD: aout2bb.c,v 1.5 2001/12/17 05:43:40 mhitch Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -66,10 +66,13 @@
#define BBSIZE 8192
char *progname;
-u_int8_t buffer[BBSIZE];
-u_int32_t relbuf[BBSIZE/sizeof(u_int32_t)];
+int bbsize = BBSIZE;
+u_int8_t *buffer;
+u_int32_t *relbuf;
/* can't have more relocs than that*/
+extern char *optarg;
+
int
intcmp(i, j)
const void *i, *j;
@@ -103,11 +106,14 @@
progname = argv[0];
/* insert getopt here, if needed */
- while ((c = getopt(argc, argv, "F")) != -1)
+ while ((c = getopt(argc, argv, "FS:")) != -1)
switch(c) {
case 'F':
sumsize = 2;
break;
+ case 'S':
+ bbsize = (atoi(optarg) + 511) & ~511;
+ break;
default:
usage();
}
@@ -117,10 +123,16 @@
if (argc < 2)
usage();
+ buffer = malloc(bbsize);
+ relbuf = (u_int32_t *)malloc(bbsize);
+ if (buffer == NULL || relbuf == NULL)
+ err(1, "Unable to allocate memory\n");
+
ifd = open(argv[0], O_RDONLY, 0);
if (ifd < 0)
err(1, "Can't open %s", argv[0]);
+/* XXX stat(ifd, sb), mmap(0, sb.st_size); */
image = mmap(0, 65536, PROT_READ, MAP_FILE|MAP_PRIVATE, ifd, 0);
if (image == 0)
err(1, "Can't mmap %s", argv[1]);
@@ -166,7 +178,7 @@
/*
* We have one contiguous area allocated by the ROM to us.
*/
- if (tsz+dsz+bsz > BBSIZE)
+ if (tsz+dsz+bsz > bbsize)
errx(1, "%s: resulting image too big\n", argv[0]);
memset(buffer, sizeof(buffer), 0);
@@ -185,7 +197,7 @@
/*NOTREACHED*/
case RELVER_RELATIVE_BYTES:
- rpo = buffer + BBSIZE - 1;
+ rpo = buffer + bbsize - 1;
delta = -1;
break;
@@ -304,20 +316,21 @@
oldaddr = relbuf[i];
if (delta < 0 ? rpo <= buffer+tsz+dsz
- : rpo >= buffer + BBSIZE)
+ : rpo >= buffer + bbsize)
errx(1, "Relocs don't fit.");
}
*rpo = 0; rpo += delta;
*rpo = 0; rpo += delta;
*rpo = 0; rpo += delta;
- printf("using %d bytes.\n", delta > 0 ?
- rpo-buffer-tsz-dsz : buffer+BBSIZE-rpo);
+ printf("using %d bytes, %d bytes remaining.\n", delta > 0 ?
+ rpo-buffer-tsz-dsz : buffer+bbsize-rpo, delta > 0 ?
+ buffer + bbsize - rpo : rpo - buffer - tsz - dsz);
/*
* RELOCs must fit into the bss area.
*/
if (delta < 0 ? rpo <= buffer+tsz+dsz
- : rpo >= buffer + BBSIZE)
+ : rpo >= buffer + bbsize)
errx(1, "Relocs don't fit.");
((u_int32_t *)buffer)[1] = 0;
@@ -328,7 +341,7 @@
if (ofd < 0)
err(1, "Can't open %s", argv[1]);
- if (write(ofd, buffer, BBSIZE) != BBSIZE)
+ if (write(ofd, buffer, bbsize) != bbsize)
err(1, "Writing output file");
exit(0);
@@ -337,7 +350,7 @@
void
usage()
{
- fprintf(stderr, "Usage: %s [-F] bootprog bootprog.bin\n",
+ fprintf(stderr, "Usage: %s [-F] [-S bbsize] bootprog bootprog.bin\n",
progname);
exit(1);
/* NOTREACHED */
Home |
Main Index |
Thread Index |
Old Index