summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/macppc/stand/Locore.c19
-rw-r--r--sys/arch/macppc/stand/boot.mac/Makefile22
-rw-r--r--sys/arch/macppc/stand/boot.mac/elf32_powerpc_merge.x (renamed from sys/arch/macppc/stand/boot.mac/ld.script)5
-rw-r--r--sys/arch/macppc/stand/boot.mac/fixcoff.c192
-rw-r--r--sys/arch/macppc/stand/boot.mac/hack-coff.c29
-rw-r--r--sys/arch/macppc/stand/ofwboot/Makefile5
6 files changed, 218 insertions, 54 deletions
diff --git a/sys/arch/macppc/stand/Locore.c b/sys/arch/macppc/stand/Locore.c
index 453889e42bb..0ba69b57d03 100644
--- a/sys/arch/macppc/stand/Locore.c
+++ b/sys/arch/macppc/stand/Locore.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: Locore.c,v 1.10 2006/10/10 20:21:10 mbalmer Exp $ */
+/* $OpenBSD: Locore.c,v 1.11 2006/12/05 20:30:26 gwk Exp $ */
/* $NetBSD: Locore.c,v 1.1 1997/04/16 20:29:11 thorpej Exp $ */
/*
@@ -43,9 +43,7 @@ static int (*openfirmware)(void *);
static void setup(void);
-#ifdef XCOFF_GLUE
asm (".text; .globl _entry; _entry: .long _start,0,0");
-#endif
asm(" .text \n"
" .globl bat_init \n"
"bat_init: \n"
@@ -76,14 +74,25 @@ asm(" .text \n"
" isync \n"
" blr \n");
+#ifdef XCOFF_GLUE
+static int stack[8192/4 + 4] __attribute__((__used__));
+#endif
+
__dead void
_start(void *vpd, int res, int (*openfirm)(void *), char *arg, int argl)
{
extern char etext[];
-#ifdef FIRMWORKSBUGS
- syncicache((void *)RELOC, etext - (char *)RELOC);
+#ifdef XCOFF_GLUE
+ asm(
+ "sync \n"
+ "isync \n"
+ "lis %r1,stack@ha \n"
+ "addi %r1,%r1,stack@l \n"
+ "addi %r1,%r1,8192 \n");
#endif
+ syncicache((void *)RELOC, etext - (char *)RELOC);
+
bat_init();
openfirmware = openfirm; /* Save entry to Open Firmware */
#if 0
diff --git a/sys/arch/macppc/stand/boot.mac/Makefile b/sys/arch/macppc/stand/boot.mac/Makefile
index 4c360f79f45..6242827aa92 100644
--- a/sys/arch/macppc/stand/boot.mac/Makefile
+++ b/sys/arch/macppc/stand/boot.mac/Makefile
@@ -1,36 +1,32 @@
-# $OpenBSD: Makefile,v 1.1 2001/09/01 15:36:37 drahn Exp $
+# $OpenBSD: Makefile,v 1.2 2006/12/05 20:30:26 gwk Exp $
# $NetBSD: Makefile,v 1.1 1996/09/30 16:35:05 ws Exp $
R= ..
.PATH: $(.CURDIR)/$(R)
-RELOC= 6c0000
+RELOC= E00000
ENTRY= _entry
PROG= boot.mac
SRCS= Locore.c boot.c ofdev.c net.c netif_of.c alloc.c cache.c hfs.c
-CFLAGS+= -DDEBUG -DNETIF_DEBUG
NOMAN=
INSTALL_STRIP=
BINDIR= /usr/mdec
OBJCOPY?= objcopy
-OBJCOPY_ARGS= -O aixcoff-rs6000 -R .stab -R .stabstr -R .comment
-LDFLAGS= -X -Ttext ${RELOC} -e $(ENTRY) -T ${.CURDIR}/ld.script
+OBJCOPY_ARGS= -O aixcoff-rs6000 -R .comment -R .note
+LDFLAGS= -X -Ttext ${RELOC} -e $(ENTRY) -T ${.CURDIR}/elf32_powerpc_merge.x -Bstatic
CPPFLAGS+= -I. -I${.CURDIR}/../../.. -I${.CURDIR}/../../../..
CPPFLAGS+= -DRELOC=0x${RELOC}
-CPPFLAGS+= -DFIRMWORKSBUGS
-CPPFLAGS+= -DPOWERPC_BOOT_ELF
CPPFLAGS+= -DXCOFF_GLUE # for booting PCI Powermacs
-
LIBS!= cd $(.CURDIR)/$(R); $(MAKE) libdep
-CLEANFILES= hack-coff
+CLEANFILES= fixcoff
-$(PROG): $(OBJS) $(LIBS) hack-coff
+$(PROG): $(OBJS) $(LIBS) fixcoff
$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o ${.TARGET}
${OBJCOPY} ${OBJCOPY_ARGS} ${.TARGET}
- ${.OBJDIR}/hack-coff ${.TARGET}
+ ${.OBJDIR}/fixcoff ${.TARGET}
-hack-coff: hack-coff.c
- ${HOSTCC} -I${.CURDIR} -o hack-coff ${.CURDIR}/hack-coff.c
+fixcoff: fixcoff.c
+ ${HOSTCC} -I${.CURDIR} -o fixcoff ${.CURDIR}/fixcoff.c
.include <bsd.prog.mk>
diff --git a/sys/arch/macppc/stand/boot.mac/ld.script b/sys/arch/macppc/stand/boot.mac/elf32_powerpc_merge.x
index 2469ed65dcb..a0f378c39a9 100644
--- a/sys/arch/macppc/stand/boot.mac/ld.script
+++ b/sys/arch/macppc/stand/boot.mac/elf32_powerpc_merge.x
@@ -1,7 +1,5 @@
+/* $OpenBSD: */
OUTPUT_ARCH(powerpc)
-SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/local/powerpc-any-elf/lib);
-/* Do we need any of these for elf?
- __DYNAMIC = 0; */
SECTIONS
{
/* Read-only sections, merged into text segment: */
@@ -32,6 +30,7 @@ SECTIONS
{
*(.text)
*(.rodata)
+ *(.rodata.*)
*(.rodata1)
*(.got1)
}
diff --git a/sys/arch/macppc/stand/boot.mac/fixcoff.c b/sys/arch/macppc/stand/boot.mac/fixcoff.c
new file mode 100644
index 00000000000..a23163b7376
--- /dev/null
+++ b/sys/arch/macppc/stand/boot.mac/fixcoff.c
@@ -0,0 +1,192 @@
+/* $OpenBSD: */
+/* $NetBSD: fixcoff.c,v 1.10 2006/04/07 02:34:55 gdamore Exp $ */
+
+/*
+ * Copyright (c) 1999 National Aeronautics & Space Administration
+ * All rights reserved.
+ *
+ * This software was written by William Studenmund of the
+ * Numerical Aerospace Similation Facility, NASA Ames Research Center.
+ *
+ * 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. Neither the name of the National Aeronautics & Space Administration
+ * 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 NATIONAL AERONAUTICS & SPACE ADMINISTRATION
+ * ``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 ADMINISTRATION OR CONTRIB-
+ * UTORS 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.
+ */
+
+/*
+ * This program fixes up the extended xcoff headers generated when an elf
+ * file is turned into an xcoff one with the current objcopy. It should
+ * go away someday, when objcopy will correctly fix up the output xcoff
+ *
+ * Partially inspired by hack-coff, written by Paul Mackerras.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <sys/endian.h>
+
+struct filehdr {
+#define U802WRMAGIC 0730
+#define U802ROMAGIC 0735
+#define U802TOCMAGIC 0737
+ char f_magic[2];
+ char f_nsect[2];
+ char f_time[4];
+ char f_symtab[4];
+ char f_nsyms[4];
+ char f_opthdr[2];
+ char f_flags[2];
+};
+
+struct sectionhdr {
+ char s_name[8];
+ char s_paddr[4];
+ char s_vaddr[4];
+ char s_size[4];
+ char s_section[4];
+ char s_reloc[4];
+ char s_lineno[4];
+ char s_nreloc[2];
+ char s_nlineno[2];
+ char s_flags[4];
+};
+
+struct aouthdr {
+ char magic[2];
+ char vstamp[2];
+ char tsize[4];
+ char dsize[4];
+ char bsize[4];
+ char entry[4];
+ char text_start[4];
+ char data_start[4];
+#define SMALL_AOUTSZ 28
+ char o_toc[4];
+ char o_snentry[2];
+ char o_sntext[2];
+ char o_sndata[2];
+ char o_sntoc[2];
+ char o_snloader[2];
+ char o_snbss[2];
+ char o_algntext[2];
+ char o_algndata[2];
+ char o_modtype[2];
+ char o_cputype[2];
+ char o_maxstack[4];
+ char o_maxdata[4];
+ char o_resv2[12];
+};
+#define RS6K_AOUTHDR_ZMAGIC 0x010B
+
+char *progname;
+
+void
+usage(char *prog)
+{
+ fprintf(stderr, "Usage: %s [-h] | [<file to fix>]\n", prog);
+}
+
+void
+help(char *prog)
+{
+ fprintf(stderr, "%s\tis designed to fix the xcoff headers in a\n",prog);
+ fprintf(stderr,
+"\tbinary generated using objcopy from a non-xcoff source.\n");
+ usage(prog);
+ exit(0);
+}
+
+main(int argc, char *argv[])
+{
+ int fd, i, n, ch;
+ struct filehdr fh;
+ struct aouthdr aoh;
+ struct sectionhdr sh;
+
+ progname = argv[0];
+ while ((ch = getopt(argc, argv, "h")) != -1)
+ switch (ch) {
+ case 'h':
+ help(progname);
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 1) {
+ usage(progname);
+ exit(1);
+ }
+
+ if ((fd = open(argv[0], O_RDWR, 0)) == -1)
+ err(i, "%s", argv[0]);
+
+ /*
+ * Make sure it looks like an xcoff file..
+ */
+ if (read(fd, &fh, sizeof(fh)) != sizeof(fh))
+ err(1, "%s reading header", argv[0]);
+
+ i = betoh16(*(uint16_t *)fh.f_magic);
+ if ((i != U802WRMAGIC) && (i != U802ROMAGIC) && (i != U802TOCMAGIC))
+ errx(1, "%s: not a valid xcoff file", argv[0]);
+
+ /* Does the AOUT "Optional header" make sense? */
+ i = betoh16(*(uint16_t *)fh.f_opthdr);
+
+ if (i == SMALL_AOUTSZ)
+ errx(1, "%s: file has small \"optional\" header, inappropriate for use with %s", argv[0], progname);
+ else if (i != sizeof(aoh))
+ errx(1, "%s: invalid \"optional\" header", argv[0]);
+
+ if (read(fd, &aoh, i) != i)
+ err(1, "%s reading \"optional\" header", argv[0]);
+
+ /* Now start filing in the AOUT header */
+ *(uint16_t *)aoh.magic = htobe16(RS6K_AOUTHDR_ZMAGIC);
+ n = betoh16(*(uint16_t *)fh.f_nsect);
+
+ for (i = 0; i < n; i++) {
+ if (read(fd, &sh, sizeof(sh)) != sizeof(sh))
+ err(1, "%s reading section headers", argv[0]);
+ if (strcmp(sh.s_name, ".text") == 0) {
+ *(uint16_t *)(aoh.o_snentry) = htobe16(i+1);
+ *(uint16_t *)(aoh.o_sntext) = htobe16(i+1);
+ } else if (strcmp(sh.s_name, ".data") == 0) {
+ *(uint16_t *)(aoh.o_sndata) = htobe16(i+1);
+ } else if (strcmp(sh.s_name, ".bss") == 0) {
+ *(uint16_t *)(aoh.o_snbss) = htobe16(i+1);
+ }
+ }
+
+ /* now write it out */
+ if (pwrite(fd, &aoh, sizeof(aoh), sizeof(struct filehdr)) !=
+ sizeof(aoh))
+ err(1, "%s writing modified header", argv[0]);
+ close(fd);
+ exit(0);
+}
diff --git a/sys/arch/macppc/stand/boot.mac/hack-coff.c b/sys/arch/macppc/stand/boot.mac/hack-coff.c
deleted file mode 100644
index 4a01d40a70b..00000000000
--- a/sys/arch/macppc/stand/boot.mac/hack-coff.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* $OpenBSD: hack-coff.c,v 1.1 2001/09/01 15:36:37 drahn Exp $ */
-
-#include <stdio.h>
-
-char magic[2] = { 1, 0xb };
-char snos[12] = { 0, 1, 0, 1, 0, 2, 0, 0, 0, 0, 0, 3 };
-
-main(int ac, char **av)
-{
- int fd;
-
- if (ac != 2) {
- fprintf(stderr, "Usage: hack-coff coff-file\n");
- exit(1);
- }
- if ((fd = open(av[1], 2)) == -1) {
- perror(av[2]);
- exit(1);
- }
- if (lseek(fd, (long) 0x14, 0) == -1
- || write(fd, magic, sizeof(magic)) != sizeof(magic)
- || lseek(fd, (long) 0x34, 0) == -1
- || write(fd, snos, sizeof(snos)) != sizeof(snos)) {
- fprintf(stderr, "%s: write error\n", av[1]);
- exit(1);
- }
- close(fd);
- exit(0);
-}
diff --git a/sys/arch/macppc/stand/ofwboot/Makefile b/sys/arch/macppc/stand/ofwboot/Makefile
index 65913208e75..46b5221d160 100644
--- a/sys/arch/macppc/stand/ofwboot/Makefile
+++ b/sys/arch/macppc/stand/ofwboot/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.2 2003/01/31 20:06:32 drahn Exp $
+# $OpenBSD: Makefile,v 1.3 2006/12/05 20:30:27 gwk Exp $
# $NetBSD: Makefile,v 1.2 1997/04/17 07:46:24 thorpej Exp $
S= ${.CURDIR}/../../../..
@@ -25,9 +25,6 @@ ENTRY= _start
CPPFLAGS+= -I. -I${.CURDIR}/../../.. -I${.CURDIR}/../../../..
CPPFLAGS+= -DRELOC=0x${RELOC}
-CPPFLAGS+= -DFIRMWORKSBUGS
-CPPFLAGS+= -DPOWERPC_BOOT_ELF
-CPPFLAGS+= -DXCOFF_GLUE # for booting PCI Powermacs
LIBS!= cd $(.CURDIR)/$(R); $(MAKE) libdep