Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/macppc/stand/ofwboot Use MI loadfile().



details:   https://anonhg.NetBSD.org/src/rev/28926ab8db0c
branches:  trunk
changeset: 472406:28926ab8db0c
user:      tsubai <tsubai%NetBSD.org@localhost>
date:      Thu Apr 29 03:16:20 1999 +0000

description:
Use MI loadfile().

diffstat:

 sys/arch/macppc/stand/ofwboot/Makefile |   16 +-
 sys/arch/macppc/stand/ofwboot/boot.c   |  305 ++------------------------------
 sys/arch/macppc/stand/ofwboot/version  |    7 +-
 3 files changed, 32 insertions(+), 296 deletions(-)

diffs (truncated from 436 to 300 lines):

diff -r 23842b418b51 -r 28926ab8db0c sys/arch/macppc/stand/ofwboot/Makefile
--- a/sys/arch/macppc/stand/ofwboot/Makefile    Thu Apr 29 03:02:20 1999 +0000
+++ b/sys/arch/macppc/stand/ofwboot/Makefile    Thu Apr 29 03:16:20 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.4 1999/02/13 02:54:47 lukem Exp $
+#      $NetBSD: Makefile,v 1.5 1999/04/29 03:16:20 tsubai Exp $
 
 S=     ${.CURDIR}/../../../..
 
@@ -22,12 +22,16 @@
 
 CLEANFILES+=   vers.c vers.o ${PROG}.elf
 
-CPPFLAGS+=     -I${.CURDIR}/../../.. -I${.CURDIR}/../../../..
+CPPFLAGS+=     -I. -I${.CURDIR}/../../.. -I${.CURDIR}/../../../..
 CPPFLAGS+=     -DRELOC=0x${RELOC}
-CPPFLAGS+=     -DPOWERPC_BOOT_AOUT
-CPPFLAGS+=     -DPOWERPC_BOOT_ELF
 #CPPFLAGS+=    -DXCOFF_GLUE            # for booting PCI Powermacs
 
+CLEANFILES+= ${.OBJDIR}/machine ${.OBJDIR}/powerpc
+
+.BEGIN:
+       @[ -h machine ] || ln -s ${S}/arch/${MACHINE}/include machine
+       @[ -h powerpc ] || ln -s ${S}/arch/powerpc/include powerpc
+
 ### find out what to use for libkern
 KERN_AS=       library
 .include "${S}/lib/libkern/Makefile.inc"
@@ -40,7 +44,7 @@
 
 ### find out what to use for libsa
 SA_AS=         library
-SAMISCMAKEFLAGS= SA_USE_CREAD=yes
+SAMISCMAKEFLAGS= SA_USE_CREAD=yes SA_USE_LOADFILE=yes
 .include "${S}/lib/libsa/Makefile.inc"
 LIBSA=         ${SALIB}
 
@@ -50,7 +54,7 @@
        ${LD} -s -N -Ttext ${RELOC} -Bstatic -o ${PROG} \
            ${OBJS} vers.o ${LIBSA} ${LIBZ} ${LIBKERN}
        mv ${PROG} ${PROG}.elf
-       tail -c +117 ${PROG}.elf > ${PROG}
+       ${OBJCOPY} -O binary ${PROG}.elf ${PROG}
 #      ${OBJCOPY} --input-target=elf32-powerpc \
 #          --output-target=xcoff-powermac ${PROG}.elf ${PROG}.xcf
 
diff -r 23842b418b51 -r 28926ab8db0c sys/arch/macppc/stand/ofwboot/boot.c
--- a/sys/arch/macppc/stand/ofwboot/boot.c      Thu Apr 29 03:02:20 1999 +0000
+++ b/sys/arch/macppc/stand/ofwboot/boot.c      Thu Apr 29 03:16:20 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.5 1999/04/17 21:16:47 ws Exp $      */
+/*     $NetBSD: boot.c,v 1.6 1999/04/29 03:16:21 tsubai Exp $  */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -86,6 +86,7 @@
 #include <sys/disklabel.h>
 
 #include <lib/libsa/stand.h>
+#include <lib/libsa/loadfile.h>
 #include <lib/libkern/libkern.h>
 
 #include <machine/cpu.h>
@@ -99,14 +100,6 @@
 int boothowto;
 int debug;
 
-#ifdef POWERPC_BOOT_ELF
-int    elf_exec __P((int, Elf_Ehdr *, u_int32_t *, void **));
-#endif
-
-#ifdef POWERPC_BOOT_AOUT
-int    aout_exec __P((int, struct exec *, u_int32_t *, void **));
-#endif
-
 static void
 prom2boot(dev)
        char *dev;
@@ -160,10 +153,10 @@
 }
 
 static void
-chain(entry, args, esym)
+chain(entry, args, ssym, esym)
        void (*entry)();
        char *args;
-       void *esym;
+       void *ssym, *esym;
 {
        extern char end[];
        int l, machine_tag;
@@ -175,6 +168,8 @@
         * strings.
         */
        l = strlen(args) + 1;
+       bcopy(&ssym, args + l, sizeof(ssym));
+       l += sizeof(ssym);
        bcopy(&esym, args + l, sizeof(esym));
        l += sizeof(esym);
 
@@ -189,71 +184,6 @@
        panic("chain");
 }
 
-int
-loadfile(fd, args)
-       int fd;
-       char *args;
-{
-       union {
-#ifdef POWERPC_BOOT_AOUT
-               struct exec aout;
-#endif
-#ifdef POWERPC_BOOT_ELF
-               Elf_Ehdr elf;
-#endif
-       } hdr;
-       int rval;
-       u_int32_t entry;
-       void *esym;
-
-       rval = 1;
-       esym = NULL;
-
-       /* Load the header. */
-       if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
-               printf("read header: %s\n", strerror(errno));
-               goto err;
-       }
-
-       /* Determine file type, load kernel. */
-#ifdef POWERPC_BOOT_AOUT
-       if (N_BADMAG(hdr.aout) == 0 && N_GETMID(hdr.aout) == MID_POWERPC) {
-               rval = aout_exec(fd, &hdr.aout, &entry, &esym);
-       } else
-#endif
-#ifdef POWERPC_BOOT_ELF
-       if (memcmp(Elf_e_ident, hdr.elf.e_ident, Elf_e_siz) == 0) {
-               rval = elf_exec(fd, &hdr.elf, &entry, &esym);
-       } else
-#endif
-       {
-               printf("unknown executable format\n");
-       }
-
-       if (rval)
-               goto err;
-
-       printf(" start=0x%x\n", entry);
-
-       close(fd);
-
-#if 0
-       /* XXX this should be replaced w/ a mountroothook. */
-       if (floppyboot) {
-               printf("Please insert root disk and press ENTER ");
-               getchar();
-               printf("\n");
-       }
-#endif
-
-       chain((void *)entry, args, esym);
-       /* NOTREACHED */
-
- err:
-       close(fd);
-       return (rval);
-}
-
 __dead void
 _rtt()
 {
@@ -261,212 +191,6 @@
        OF_exit();
 }
 
-#ifdef POWERPC_BOOT_AOUT
-int
-aout_exec(fd, hdr, entryp, esymp)
-       int fd;
-       struct exec *hdr;
-       u_int32_t *entryp;
-       void **esymp;
-{
-       void *addr;
-       int n, *paddr;
-
-       /* Display the load address (entry point) for a.out. */
-       printf("Booting %s @ 0x%lx\n", opened_name, hdr->a_entry);
-       addr = (void *)(hdr->a_entry);
-
-       /*
-        * Determine memory needed for kernel and allocate it from
-        * the firmware.
-        */
-       n = hdr->a_text + hdr->a_data + hdr->a_bss + hdr->a_syms + sizeof(int);
-       if ((paddr = OF_claim(addr, n, 0)) == (int *)-1)
-               panic("cannot claim memory");
-
-       /* Load text. */
-       lseek(fd, N_TXTOFF(*hdr), SEEK_SET);
-       printf("%lu", hdr->a_text);
-       if (read(fd, paddr, hdr->a_text) != hdr->a_text) {
-               printf("read text: %s\n", strerror(errno));
-               return (1);
-       }
-       __syncicache((void *)paddr, hdr->a_text);
-
-       /* Load data. */
-       printf("+%lu", hdr->a_data);
-       if (read(fd, (void *)paddr + hdr->a_text, hdr->a_data) != hdr->a_data) {
-               printf("read data: %s\n", strerror(errno));
-               return (1);
-       }
-
-       /* Zero BSS. */
-       printf("+%lu", hdr->a_bss);
-       bzero((void *)paddr + hdr->a_text + hdr->a_data, hdr->a_bss);
-
-       /* Symbols. */
-       *esymp = paddr;
-       paddr = (int *)((void *)paddr + hdr->a_text + hdr->a_data + hdr->a_bss);
-       *paddr++ = hdr->a_syms;
-       if (hdr->a_syms) {
-               printf(" [%lu", hdr->a_syms);
-               if (read(fd, paddr, hdr->a_syms) != hdr->a_syms) {
-                       printf("read symbols: %s\n", strerror(errno));
-                       return (1);
-               }
-               paddr = (int *)((void *)paddr + hdr->a_syms);
-               if (read(fd, &n, sizeof(int)) != sizeof(int)) {
-                       printf("read symbols: %s\n", strerror(errno));
-                       return (1);
-               }
-               if (OF_claim((void *)paddr, n + sizeof(int), 0) == (void *)-1)
-                       panic("cannot claim memory");
-               *paddr++ = n;
-               if (read(fd, paddr, n - sizeof(int)) != n - sizeof(int)) {
-                       printf("read symbols: %s\n", strerror(errno));
-                       return (1);
-               }
-               printf("+%d]", n - sizeof(int));
-               *esymp = paddr + (n - sizeof(int));
-       }
-
-       *entryp = hdr->a_entry;
-       return (0);
-}
-#endif /* POWERPC_BOOT_AOUT */
-
-#ifdef POWERPC_BOOT_ELF
-int
-elf_exec(fd, elf, entryp, esymp)
-       int fd;
-       Elf_Ehdr *elf;
-       u_int32_t *entryp;
-       void **esymp;
-{
-       Elf32_Shdr *shp;
-       Elf32_Off off;
-       void *addr;
-       size_t size;
-       int i, first = 1;
-       int n;
-
-       /*
-        * Don't display load address for ELF; it's encoded in
-        * each section.
-        */
-       printf("Booting %s\n", opened_name);
-
-       for (i = 0; i < elf->e_phnum; i++) {
-               Elf_Phdr phdr;
-               (void)lseek(fd, elf->e_phoff + sizeof(phdr) * i, SEEK_SET);
-               if (read(fd, (void *)&phdr, sizeof(phdr)) != sizeof(phdr)) {
-                       printf("read phdr: %s\n", strerror(errno));
-                       return (1);
-               }
-               if (phdr.p_type != Elf_pt_load ||
-                   (phdr.p_flags & (Elf_pf_w|Elf_pf_x)) == 0)
-                       continue;
-
-               /* Read in segment. */
-               printf("%s%lu@0x%lx", first ? "" : "+", phdr.p_filesz,
-                   (u_long)phdr.p_vaddr);
-               (void)lseek(fd, phdr.p_offset, SEEK_SET);
-               if (OF_claim((void *)phdr.p_vaddr, phdr.p_memsz, 0) ==
-                   (void *)-1)
-                       panic("cannot claim memory");
-               if (read(fd, (void *)phdr.p_vaddr, phdr.p_filesz) !=
-                   phdr.p_filesz) {
-                       printf("read segment: %s\n", strerror(errno));
-                       return (1);
-               }
-               __syncicache((void *)phdr.p_vaddr, phdr.p_filesz);
-
-               /* Zero BSS. */
-               if (phdr.p_filesz < phdr.p_memsz) {
-                       printf("+%lu@0x%lx", phdr.p_memsz - phdr.p_filesz,



Home | Main Index | Thread Index | Old Index