diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1997-01-16 09:27:14 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1997-01-16 09:27:14 +0000 |
commit | e9f16b69855062feac440e972c93cef99ece8bd4 (patch) | |
tree | 5073df0ec395d6ba5b171435054e4eee05fc68a3 /sys/arch/amiga/stand/boot/aout2bb | |
parent | 835aeeacc264a5ba177151c158181779163da7ad (diff) |
Sync to NetBSD 970110
Diffstat (limited to 'sys/arch/amiga/stand/boot/aout2bb')
-rw-r--r-- | sys/arch/amiga/stand/boot/aout2bb/Makefile | 14 | ||||
-rw-r--r-- | sys/arch/amiga/stand/boot/aout2bb/aout2bb.c | 340 | ||||
-rw-r--r-- | sys/arch/amiga/stand/boot/aout2bb/aout2bb.h | 71 | ||||
-rw-r--r-- | sys/arch/amiga/stand/boot/aout2bb/chksum.c | 85 | ||||
-rw-r--r-- | sys/arch/amiga/stand/boot/aout2bb/chksum.h | 39 |
5 files changed, 549 insertions, 0 deletions
diff --git a/sys/arch/amiga/stand/boot/aout2bb/Makefile b/sys/arch/amiga/stand/boot/aout2bb/Makefile new file mode 100644 index 00000000000..7e03937714d --- /dev/null +++ b/sys/arch/amiga/stand/boot/aout2bb/Makefile @@ -0,0 +1,14 @@ +# $OpenBSD: Makefile,v 1.1 1997/01/16 09:26:47 niklas Exp $ + +PROG=aout2bb +SRCS=aout2bb.c chksum.c +NOMAN=notyet +INCLUDES=aout2bb.h chksum.h + +COPTS += -Wall -Wstrict-prototypes -g + + +ci: + ci -l $(SRCS) $(INCLUDES) Makefile + +.include <bsd.prog.mk> diff --git a/sys/arch/amiga/stand/boot/aout2bb/aout2bb.c b/sys/arch/amiga/stand/boot/aout2bb/aout2bb.c new file mode 100644 index 00000000000..3ef98391ecf --- /dev/null +++ b/sys/arch/amiga/stand/boot/aout2bb/aout2bb.c @@ -0,0 +1,340 @@ +/* + * $OpenBSD: aout2bb.c,v 1.1 1997/01/16 09:26:48 niklas Exp $ + * $NetBSD: aout2bb.c,v 1.2 1996/12/31 22:39:58 veego Exp $ + * + * Copyright (c) 1996 Ignatios Souvatzis + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Ignatios Souvatzis + * for the NetBSD project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <sys/types.h> + +#include <err.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <sys/mman.h> /* of the machine we're running on */ +#include <machine/endian.h> /* of the machine we're running on */ + +#include <sys/exec_aout.h> /* TARGET */ + +#include "aout2bb.h" +#include "chksum.h" + +void usage __P((void)); +int intcmp(const void *, const void *); +int main(int argc, char *argv[]); + +#ifdef DEBUG +#define dprintf(x) printf x +#else +#define dprintf(x) +#endif + +#define BBSIZE 8192 + +char *progname; +u_int8_t buffer[BBSIZE]; +u_int32_t relbuf[BBSIZE/sizeof(u_int32_t)]; + /* can't have more relocs than that*/ + +int +intcmp(i, j) + const void *i, *j; +{ + int r; + + r = (*(u_int32_t *)i) < (*(u_int32_t *)j); + + return 2*r-1; +} + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int ifd, ofd; + u_int mid, flags, magic; + caddr_t image; + struct exec *eh; + struct relocation_info_m68k *rpi; + u_int32_t *lptr; + int i, delta; + u_int8_t *rpo; + u_int32_t oldaddr, addrdiff; + u_int32_t tsz, dsz, bsz, trsz, drsz, entry, relver; + int sumsize = 16; + int c; + + + progname = argv[0]; + + /* insert getopt here, if needed */ + while ((c = getopt(argc, argv, "F")) != -1) + switch(c) { + case 'F': + sumsize = 2; + break; + default: + usage(); + } + argv += optind; + argc -= optind; + + if (argc < 2) + usage(); + + ifd = open(argv[0], O_RDONLY, 0); + if (ifd < 0) + err(1, "Can't open %s", argv[0]); + + image = mmap(0, 65536, PROT_READ, MAP_FILE|MAP_PRIVATE, ifd, 0); + if (image == 0) + err(1, "Can't mmap %s", argv[1]); + + eh = (struct exec *)image; /* XXX endianness */ + + magic = N_GETMAGIC(*eh); + if (magic != OMAGIC) + errx(1, "%s isn't an OMAGIC file, but 0%o", argv[0], magic); + + flags = N_GETFLAG(*eh); + if (flags != 0) + errx(1, "%s has strange exec flags 0x%x", argv[0], flags); + + mid = N_GETMID(*eh); + switch(mid) { + case MID_M68K: + break; + default: + errx(1, "%s has strange machine id 0x%x (%d)", argv[0], mid, + mid); + } + + tsz = ntohl(eh->a_text); + dsz = ntohl(eh->a_data); + bsz = ntohl(eh->a_bss); + trsz = ntohl(eh->a_trsize); + drsz = ntohl(eh->a_drsize); + entry = ntohl(eh->a_entry); + + dprintf(("tsz = 0x%x, dsz = 0x%x, bsz = 0x%x, total 0x%x, entry=0x%x\n", + tsz, dsz, bsz, tsz+dsz+bsz, entry)); + + if ((trsz+drsz)==0) + errx(1, "%s has no relocation records.\n", argv[0]); + + dprintf(("%d text relocs, %d data relocs\n", trsz/8, drsz/8)); + if (entry != 12) + errx(1, "%s: entry point 0x%04x is not 0x000c\n", argv[0], + entry); + + /* + * We have one contiguous area allocated by the ROM to us. + */ + if (tsz+dsz+bsz > BBSIZE) + errx(1, "%s: resulting image too big\n", argv[0]); + + memset(buffer, sizeof(buffer), 0); + memcpy(buffer, image + N_TXTOFF(*eh), tsz+dsz); + + /* + * Hm. This tool REALLY should understand more than one + * relocator version. For now, check that the relocator at + * the image start does understand what we output. + */ + relver = ntohl(*(u_int32_t *)(image+0x24)); + switch (relver) { + default: + errx(1, "%s: unrecognized relocator version %d\n", + argv[0], relver); + /*NOTREACHED*/ + + case RELVER_RELATIVE_BYTES: + rpo = buffer + BBSIZE - 1; + delta = -1; + break; + + case RELVER_RELATIVE_BYTES_FORWARD: + rpo = buffer + tsz + dsz; + delta = +1; + *(u_int16_t *)(buffer + 14) = htons(tsz + dsz); + break; + } + + + + i = 0; + + for (rpi = (struct relocation_info_m68k *)(image+N_TRELOFF(*eh)); + (caddr_t)rpi < image+N_TRELOFF(*eh)+trsz; rpi++) { + + NTOHL(((u_int32_t *)rpi)[0]); + NTOHL(((u_int32_t *)rpi)[1]); + + dprintf(("0x%08x 0x%08x %c\n", *(u_int32_t *)rpi, + ((u_int32_t *)rpi)[1], rpi->r_extern ? 'U' : ' ')); + + if (rpi->r_extern) + errx(1, "code accesses unresolved symbol"); + if (rpi->r_copy) + errx(1, "code accesses r_copy symbol"); + if (rpi->r_jmptable) + errx(1, "code accesses r_jmptable symbol"); + if (rpi->r_relative) + errx(1, "code accesses r_relative symbol"); + if (rpi->r_baserel) + errx(1, "code accesses r_baserel symbol"); + + /* + * We don't worry about odd sized symbols which are pc + * relative, so test for pcrel first: + */ + + if (rpi->r_pcrel) + continue; + + if (rpi->r_length != 2) + errx(1, "code accesses size %d symbol", rpi->r_length); + + relbuf[i++] = rpi->r_address; + } + + for (rpi = (struct relocation_info_m68k *)(image+N_DRELOFF(*eh)); + (caddr_t)rpi < image+N_DRELOFF(*eh)+drsz; rpi++) { + + NTOHL(((u_int32_t *)rpi)[0]); + NTOHL(((u_int32_t *)rpi)[1]); + + dprintf(("0x%08x 0x%08x %c\n", *(u_int32_t *)rpi, + ((u_int32_t *)rpi)[1], rpi->r_extern ? 'U' : ' ')); + + if (rpi->r_extern) + errx(1, "data accesses unresolved symbol"); + if (rpi->r_copy) + errx(1, "data accesses r_copy symbol"); + if (rpi->r_jmptable) + errx(1, "data accesses r_jmptable symbol"); + if (rpi->r_relative) + errx(1, "data accesses r_relative symbol"); + if (rpi->r_baserel) + errx(1, "data accesses r_baserel symbol"); + + /* + * We don't worry about odd sized symbols which are pc + * relative, so test for pcrel first: + */ + + if (rpi->r_pcrel) + continue; + + if (rpi->r_length != 2) + errx(1, "data accesses size %d symbol", rpi->r_length); + + + relbuf[i++] = rpi->r_address + tsz; + } + printf("%d absolute reloc%s found, ", i, i==1?"":"s"); + + if (i > 1) + heapsort(relbuf, i, 4, intcmp); + + oldaddr = 0; + + for (--i; i>=0; --i) { + dprintf(("0x%04x: ", relbuf[i])); + lptr = (u_int32_t *)&buffer[relbuf[i]]; + addrdiff = relbuf[i] - oldaddr; + dprintf(("(0x%04x, 0x%04x): ", *lptr, addrdiff)); + if (addrdiff > 255) { + *rpo = 0; + if (delta > 0) { + ++rpo; + *rpo++ = (relbuf[i] >> 8) & 0xff; + *rpo++ = relbuf[i] & 0xff; + dprintf(("%02x%02x%02x\n", + rpo[-3], rpo[-2], rpo[-1])); + } else { + *--rpo = relbuf[i] & 0xff; + *--rpo = (relbuf[i] >> 8) & 0xff; + --rpo; + dprintf(("%02x%02x%02x\n", + rpo[0], rpo[1], rpo[2])); + } + } else { + *rpo = addrdiff; + dprintf(("%02x\n", *rpo)); + rpo += delta; + } + + oldaddr = relbuf[i]; + + if (delta < 0 ? rpo <= buffer+tsz+dsz + : 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); + /* + * RELOCs must fit into the bss area. + */ + if (delta < 0 ? rpo <= buffer+tsz+dsz + : rpo >= buffer + BBSIZE) + errx(1, "Relocs don't fit."); + + ((u_int32_t *)buffer)[1] = 0; + ((u_int32_t *)buffer)[1] = + (0xffffffff - chksum((u_int32_t *)buffer, sumsize * 512 / 4)); + + ofd = open(argv[1], O_CREAT|O_WRONLY, 0644); + if (ofd < 0) + err(1, "Can't open %s", argv[1]); + + if (write(ofd, buffer, BBSIZE) != BBSIZE) + err(1, "Writing output file"); + + exit(0); +} + +void +usage() +{ + fprintf(stderr, "Usage: %s [-F] bootprog bootprog.bin\n", + progname); + exit(1); + /* NOTREACHED */ +} diff --git a/sys/arch/amiga/stand/boot/aout2bb/aout2bb.h b/sys/arch/amiga/stand/boot/aout2bb/aout2bb.h new file mode 100644 index 00000000000..59627748c24 --- /dev/null +++ b/sys/arch/amiga/stand/boot/aout2bb/aout2bb.h @@ -0,0 +1,71 @@ +/* + * $OpenBSD: aout2bb.h,v 1.1 1997/01/16 09:26:49 niklas Exp $ + * $NetBSD: aout2bb.h,v 1.1.1.1 1996/11/29 23:36:30 is Exp $ + * + * Copyright (c) 1996 Ignatios Souvatzis + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Ignatios Souvatzis + * for the NetBSD project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* + * Relocator version definitions for aout to Amiga bootblock converter. + */ + +/* + * All the tables are at the end of the bootblock, with logical start at the + * end. + */ + +/* + * The following formats are for a length of 8 kBytes only. + */ + +/* + * Absolute words in Motorola byte order, end of table marked by 0x0000 + */ +#define RELVER_ABSOLUTE_WORDS 0 + +/* + * Unsigned bytes relative to previous address to relocate; first one to 0. + * If the difference is >255, the logical next two bytes (in Motorola byte + * order) give the absolute address to relocate. + */ +#define RELVER_RELATIVE_BYTES 1 + +/* + * Same as above, but with the bytes stored in forward direction beginning + * with the __relocation_bytes symbol + */ +#define RELVER_RELATIVE_BYTES_FORWARD 2 + +/* + * loader can autoload + */ + +#define RELFLAG_SELFLOADING 0x10 diff --git a/sys/arch/amiga/stand/boot/aout2bb/chksum.c b/sys/arch/amiga/stand/boot/aout2bb/chksum.c new file mode 100644 index 00000000000..1a857e69016 --- /dev/null +++ b/sys/arch/amiga/stand/boot/aout2bb/chksum.c @@ -0,0 +1,85 @@ +/* + * $OpenBSD: chksum.c,v 1.1 1997/01/16 09:26:50 niklas Exp $ + * $NetBSD: chksum.c,v 1.1.1.1 1996/11/29 23:36:30 is Exp $ + * + * Copyright (c) 1996 Ignatios Souvatzis + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Ignatios Souvatzis + * for the NetBSD project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> + +#include "chksum.h" + +u_int32_t +chksum(block, size) + u_int32_t *block; + int size; +{ + u_int32_t sum, lastsum; + int i; + + sum = 0; + + for (i=0; i<size; i++) { + lastsum = sum; + sum += block[i]; + if (sum < lastsum) + ++sum; + } + + return sum; +} + +#ifdef TESTSUM +u_int32_t myblock[8192]; + +int +main(int argc, char *argb[]) { + int bbsize; + u_int32_t cks, cks1; + + bbsize=atol(argb[1]); + bbsize *= (512 / sizeof (u_int32_t)); + + if (4*bbsize != read(0, myblock, sizeof(u_int32_t)*bbsize)) { + fprintf(stderr, "short read\n"); + exit(1); + } + fprintf(stderr, "Cksum field = 0x%x, ", myblock[1]); + cks = chksum(myblock, bbsize); + fprintf(stderr, "cksum = 0x%x\n", cks); + myblock[1] += 0xFFFFFFFF - cks; + fprintf(stderr, "New cksum field = 0x%x, ", myblock[1]); + cks1 = chksum(myblock, bbsize); + fprintf(stderr, "cksum = 0x%x\n", cks1); +} +#endif diff --git a/sys/arch/amiga/stand/boot/aout2bb/chksum.h b/sys/arch/amiga/stand/boot/aout2bb/chksum.h new file mode 100644 index 00000000000..34fddcf8cca --- /dev/null +++ b/sys/arch/amiga/stand/boot/aout2bb/chksum.h @@ -0,0 +1,39 @@ +/* + * $OpenBSD: chksum.h,v 1.1 1997/01/16 09:26:51 niklas Exp $ + * $NetBSD: chksum.h,v 1.1.1.1 1996/11/29 23:36:30 is Exp $ + * + * Copyright (c) 1996 Ignatios Souvatzis + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Ignatios Souvatzis + * for the NetBSD project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define CHKSUMOFFS 1 + +u_int32_t chksum __P((u_int32_t *, int)); + |