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/elf2bb The ELF counterpart to...
details: https://anonhg.NetBSD.org/src/rev/7d90a8ec1dee
branches: trunk
changeset: 519505:7d90a8ec1dee
user: mhitch <mhitch%NetBSD.org@localhost>
date: Wed Dec 19 06:51:05 2001 +0000
description:
The ELF counterpart to aout2bb: convert a relocatable ELF object file
to the simple relocatable image used for the amiga bootblock loader.
diffstat:
sys/arch/amiga/stand/bootblock/elf2bb/Makefile | 8 +
sys/arch/amiga/stand/bootblock/elf2bb/chksum.c | 88 +++++
sys/arch/amiga/stand/bootblock/elf2bb/chksum.h | 42 ++
sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c | 410 +++++++++++++++++++++++++
sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.h | 74 ++++
5 files changed, 622 insertions(+), 0 deletions(-)
diffs (truncated from 642 to 300 lines):
diff -r e76b7290b922 -r 7d90a8ec1dee sys/arch/amiga/stand/bootblock/elf2bb/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amiga/stand/bootblock/elf2bb/Makefile Wed Dec 19 06:51:05 2001 +0000
@@ -0,0 +1,8 @@
+# $NetBSD: Makefile,v 1.1 2001/12/19 06:51:05 mhitch Exp $
+#
+CPPFLAGS+= -I.
+HOSTPROG= elf2bb
+MKMAN= no
+SRCS= elf2bb.c chksum.c
+
+.include <bsd.hostprog.mk>
diff -r e76b7290b922 -r 7d90a8ec1dee sys/arch/amiga/stand/bootblock/elf2bb/chksum.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amiga/stand/bootblock/elf2bb/chksum.c Wed Dec 19 06:51:05 2001 +0000
@@ -0,0 +1,88 @@
+/* $NetBSD: chksum.c,v 1.1 2001/12/19 06:51:05 mhitch Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Ignatios Souvatzis.
+ *
+ * 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 the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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 += htobe32(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 -r e76b7290b922 -r 7d90a8ec1dee sys/arch/amiga/stand/bootblock/elf2bb/chksum.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amiga/stand/bootblock/elf2bb/chksum.h Wed Dec 19 06:51:05 2001 +0000
@@ -0,0 +1,42 @@
+/* $NetBSD: chksum.h,v 1.1 2001/12/19 06:51:05 mhitch Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Ignatios Souvatzis.
+ *
+ * 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 the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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));
+
diff -r e76b7290b922 -r 7d90a8ec1dee sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c Wed Dec 19 06:51:05 2001 +0000
@@ -0,0 +1,410 @@
+/* $NetBSD: elf2bb.c,v 1.1 2001/12/19 06:51:05 mhitch Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Ignatios Souvatzis.
+ *
+ * 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 the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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 <elf.h> /* TARGET */
+#ifndef R_68K_32 /* XXX host not m68k XXX */
+#define R_68K_32 1
+#define R_68K_PC32 4
+#define R_68K_PC16 5
+#endif
+
+#include "elf2bb.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) if (debug) printf x
+#else
+#define dprintf(x)
+#endif
+int debug;
+
+#define BBSIZE 8192
+
+char *progname;
+int bbsize = BBSIZE;
+u_int8_t *buffer;
+u_int32_t *relbuf;
+ /* 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;
+ Elf32_Ehdr *eh;
+ Elf32_Shdr *sh;
+ char *shstrtab;
+ Elf32_Sym *symtab;
+ char *strtab;
+ int eval(Elf32_Sym *, u_int32_t *);
+ u_int32_t *lptr;
+ int i, l, delta;
+ u_int8_t *rpo;
+ u_int32_t oldaddr, addrdiff;
+ u_int32_t tsz, dsz, bsz, trsz, drsz, entry, relver;
+ u_int32_t pcrelsz, r32sz;
+ int sumsize = 16;
+ int c;
+ u_int32_t *sect_offset;
+
+
+ progname = argv[0];
+
+ /* insert getopt here, if needed */
+ while ((c = getopt(argc, argv, "dFS:")) != -1)
+ switch(c) {
+ case 'F':
+ sumsize = 2;
+ break;
+ case 'S':
+ bbsize = (atoi(optarg) + 511) & ~511;
+ sumsize = bbsize / 512;
+ break;
+ case 'd':
+ debug = 1;
+ break;
+ default:
+ usage();
+ }
+ argv += optind;
+ argc -= optind;
+
+ 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)
Home |
Main Index |
Thread Index |
Old Index