(1) split load-file functionality out from the 'main program' of the
boot block, since it will be shared with the network boot block. (2) Kill a.out support, since it never worked was never used, and will never be. (3) Add support for booting of ELF kernels, from Matt Thomas. (Currently untested, but it compiles.)
This commit is contained in:
parent
67af0bc1f0
commit
886dba6dff
|
@ -1,11 +1,12 @@
|
|||
# $NetBSD: Makefile,v 1.7 1996/06/14 20:02:52 cgd Exp $
|
||||
# $NetBSD: Makefile,v 1.8 1996/09/17 22:00:25 cgd Exp $
|
||||
|
||||
.PATH: ${.CURDIR}/.. ${.CURDIR}/../../../../lib/libsa
|
||||
|
||||
BOOT_PROG = boot
|
||||
BOOT_RELOC = ${SECONDARY_LOAD_ADDRESS}
|
||||
|
||||
BOOT_SRCS = start.S boot.c disk.c conf.c prom.c prom_disp.S OSFpal.c
|
||||
BOOT_SRCS = start.S boot.c loadfile.c disk.c conf.c prom.c prom_disp.S OSFpal.c
|
||||
|
||||
BOOT_SRCS+= alloc.c bzero.c close.c dev.c devopen.c disklabel.c dkcksum.c
|
||||
BOOT_SRCS+= getfile.c gets.c ioctl.c lseek.c open.c printf.c read.c
|
||||
BOOT_SRCS+= strcmp.c ufs.c write.c bcopy.c filesystem.c strlen.c
|
||||
|
@ -14,7 +15,7 @@ BOOT_OBJS = ${BOOT_SRCS:N*.h:R:S/$/.o/g}
|
|||
|
||||
HEADERSIZE_PROG = headersize
|
||||
|
||||
DEFNS= -DCOMPAT_UFS -DALPHA_BOOT_ECOFF
|
||||
DEFNS= -DCOMPAT_UFS -DALPHA_BOOT_ECOFF -DALPHA_BOOT_ELF
|
||||
|
||||
AFLAGS += -DASSEMBLER ${DEFNS}
|
||||
CPPFLAGS += -I${.CURDIR}/../.. -I${.CURDIR}/../../../..
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: boot.c,v 1.7 1996/06/14 20:03:00 cgd Exp $ */
|
||||
/* $NetBSD: boot.c,v 1.8 1996/09/17 22:00:26 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -50,9 +50,7 @@
|
|||
#define _KERNEL
|
||||
#include "include/pte.h"
|
||||
|
||||
static int aout_exec __P((int, struct exec *, u_int64_t *));
|
||||
static int coff_exec __P((int, struct ecoff_exechdr *, u_int64_t *));
|
||||
static int loadfile __P((char *, u_int64_t *));
|
||||
int loadfile __P((char *, u_int64_t *));
|
||||
|
||||
char boot_file[128];
|
||||
char boot_flags[128];
|
||||
|
@ -96,143 +94,3 @@ main()
|
|||
(void)printf("Boot failed! Halting...\n");
|
||||
halt();
|
||||
}
|
||||
|
||||
/*
|
||||
* Open 'filename', read in program and return the entry point or -1 if error.
|
||||
*/
|
||||
static int
|
||||
loadfile(fname, entryp)
|
||||
char *fname;
|
||||
u_int64_t *entryp;
|
||||
{
|
||||
struct devices *dp;
|
||||
union {
|
||||
struct exec aout;
|
||||
struct ecoff_exechdr coff;
|
||||
} hdr;
|
||||
ssize_t nr;
|
||||
int fd, rval;
|
||||
|
||||
/* Open the file. */
|
||||
rval = 1;
|
||||
if ((fd = open(fname, 0)) < 0) {
|
||||
(void)printf("open %s: error %d\n", fname, errno);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Read the exec header. */
|
||||
if ((nr = read(fd, &hdr, sizeof(hdr))) != sizeof(hdr)) {
|
||||
(void)printf("read header: error %d\n", errno);
|
||||
goto err;
|
||||
}
|
||||
|
||||
#ifdef ALPHA_BOOT_ECOFF
|
||||
if (!ECOFF_BADMAG(&hdr.coff)) {
|
||||
rval = coff_exec(fd, &hdr.coff, entryp);
|
||||
} else
|
||||
#endif
|
||||
#ifdef ALPHA_BOOT_AOUT
|
||||
if (XXX) {
|
||||
rval = aout_exec(fd, &hdr.aout, entryp) :
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
(void)printf("%s: unknown executable format\n", fname);
|
||||
}
|
||||
|
||||
err:
|
||||
if (fd >= 0)
|
||||
(void)close(fd);
|
||||
return (rval);
|
||||
}
|
||||
|
||||
#ifdef ALPHA_BOOT_AOUT
|
||||
static int
|
||||
aout_exec(fd, aout, entryp)
|
||||
int fd;
|
||||
struct exec *aout;
|
||||
u_int64_t *entryp;
|
||||
{
|
||||
size_t sz;
|
||||
|
||||
/* Check the magic number. */
|
||||
if (N_GETMAGIC(*aout) != OMAGIC) {
|
||||
(void)printf("bad magic: %o\n", N_GETMAGIC(*aout));
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Read in text, data. */
|
||||
(void)printf("%lu+%lu", aout->a_text, aout->a_data);
|
||||
if (lseek(fd, (off_t)N_TXTOFF(*aout), SEEK_SET) < 0) {
|
||||
(void)printf("lseek: %d\n", errno);
|
||||
return (1);
|
||||
}
|
||||
sz = aout->a_text + aout->a_data;
|
||||
if (read(fd, (void *)aout->a_entry, sz) != sz) {
|
||||
(void)printf("read text/data: %d\n", errno);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Zero out bss. */
|
||||
if (aout->a_bss != 0) {
|
||||
(void)printf("+%lu", aout->a_bss);
|
||||
bzero(aout->a_entry + sz, aout->a_bss);
|
||||
}
|
||||
|
||||
ffp_save = aout->a_entry + aout->a_text + aout->a_data + aout->a_bss;
|
||||
ffp_save = k0segtophys((ffp_save + PGOFSET & ~PGOFSET)) >> PGSHIFT;
|
||||
ffp_save += 2; /* XXX OSF/1 does this, no idea why. */
|
||||
|
||||
(void)printf("\n");
|
||||
*entryp = aout->a_entry;
|
||||
return (0);
|
||||
}
|
||||
#endif /* ALPHA_BOOT_AOUT */
|
||||
|
||||
#ifdef ALPHA_BOOT_ECOFF
|
||||
static int
|
||||
coff_exec(fd, coff, entryp)
|
||||
int fd;
|
||||
struct ecoff_exechdr *coff;
|
||||
u_int64_t *entryp;
|
||||
{
|
||||
|
||||
/* Read in text. */
|
||||
(void)printf("%lu", coff->a.tsize);
|
||||
(void)lseek(fd, ECOFF_TXTOFF(coff), 0);
|
||||
if (read(fd, (void *)coff->a.text_start, coff->a.tsize) !=
|
||||
coff->a.tsize) {
|
||||
(void)printf("read text: %d\n", errno);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Read in data. */
|
||||
if (coff->a.dsize != 0) {
|
||||
(void)printf("+%lu", coff->a.dsize);
|
||||
if (read(fd, (void *)coff->a.data_start, coff->a.dsize) !=
|
||||
coff->a.dsize) {
|
||||
(void)printf("read data: %d\n", errno);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Zero out bss. */
|
||||
if (coff->a.bsize != 0) {
|
||||
(void)printf("+%lu", coff->a.bsize);
|
||||
bzero(coff->a.bss_start, coff->a.bsize);
|
||||
}
|
||||
|
||||
ffp_save = coff->a.text_start + coff->a.tsize;
|
||||
if (ffp_save < coff->a.data_start + coff->a.dsize)
|
||||
ffp_save = coff->a.data_start + coff->a.dsize;
|
||||
if (ffp_save < coff->a.bss_start + coff->a.bsize)
|
||||
ffp_save = coff->a.bss_start + coff->a.bsize;
|
||||
ffp_save = k0segtophys((ffp_save + PGOFSET & ~PGOFSET)) >> PGSHIFT;
|
||||
ffp_save += 2; /* XXX OSF/1 does this, no idea why. */
|
||||
|
||||
(void)printf("\n");
|
||||
*entryp = coff->a.entry;
|
||||
return (0);
|
||||
}
|
||||
#endif /* ALPHA_BOOT_ECOFF */
|
||||
|
|
|
@ -0,0 +1,212 @@
|
|||
/* $NetBSD: loadfile.c,v 1.1 1996/09/17 22:00:24 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Ralph Campbell.
|
||||
*
|
||||
* 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 University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)boot.c 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
#include <lib/libkern/libkern.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/exec.h>
|
||||
#include <sys/exec_ecoff.h>
|
||||
#include <sys/exec_elf.h>
|
||||
|
||||
#include <machine/prom.h>
|
||||
|
||||
#define _KERNEL
|
||||
#include "include/pte.h"
|
||||
|
||||
#ifdef ALPHA_BOOT_ECOFF
|
||||
static int coff_exec __P((int, struct ecoff_exechdr *, u_int64_t *));
|
||||
#endif
|
||||
#ifdef ALPHA_BOOT_ELF
|
||||
static int elf_exec __P((int, Elf_Ehdr *, u_int64_t *));
|
||||
#endif
|
||||
int loadfile __P((char *, u_int64_t *));
|
||||
|
||||
vm_offset_t ffp_save, ptbr_save;
|
||||
|
||||
/*
|
||||
* Open 'filename', read in program and return the entry point or -1 if error.
|
||||
*/
|
||||
int
|
||||
loadfile(fname, entryp)
|
||||
char *fname;
|
||||
u_int64_t *entryp;
|
||||
{
|
||||
struct devices *dp;
|
||||
union {
|
||||
#ifdef ALPHA_BOOT_ECOFF
|
||||
struct ecoff_exechdr coff;
|
||||
#endif
|
||||
#ifdef ALPHA_BOOT_ELF
|
||||
Elf_Ehdr elf;
|
||||
#endif
|
||||
} hdr;
|
||||
ssize_t nr;
|
||||
int fd, rval;
|
||||
|
||||
/* Open the file. */
|
||||
rval = 1;
|
||||
if ((fd = open(fname, 0)) < 0) {
|
||||
(void)printf("open %s: error %d\n", fname, errno);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Read the exec header. */
|
||||
if ((nr = read(fd, &hdr, sizeof(hdr))) != sizeof(hdr)) {
|
||||
(void)printf("read header: error %d\n", errno);
|
||||
goto err;
|
||||
}
|
||||
|
||||
#ifdef ALPHA_BOOT_ECOFF
|
||||
if (!ECOFF_BADMAG(&hdr.coff)) {
|
||||
rval = coff_exec(fd, &hdr.coff, entryp);
|
||||
} else
|
||||
#endif
|
||||
#ifdef ALPHA_BOOT_ELF
|
||||
if (memcmp(Elf_e_ident, hdr.elf.e_ident, Elf_e_siz) == 0) {
|
||||
rval = elf_exec(fd, &hdr.elf, entryp);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
(void)printf("%s: unknown executable format\n", fname);
|
||||
}
|
||||
|
||||
err:
|
||||
if (fd >= 0)
|
||||
(void)close(fd);
|
||||
return (rval);
|
||||
}
|
||||
|
||||
#ifdef ALPHA_BOOT_ECOFF
|
||||
static int
|
||||
coff_exec(fd, coff, entryp)
|
||||
int fd;
|
||||
struct ecoff_exechdr *coff;
|
||||
u_int64_t *entryp;
|
||||
{
|
||||
|
||||
/* Read in text. */
|
||||
(void)printf("%lu", coff->a.tsize);
|
||||
(void)lseek(fd, ECOFF_TXTOFF(coff), 0);
|
||||
if (read(fd, (void *)coff->a.text_start, coff->a.tsize) !=
|
||||
coff->a.tsize) {
|
||||
(void)printf("read text: %d\n", errno);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Read in data. */
|
||||
if (coff->a.dsize != 0) {
|
||||
(void)printf("+%lu", coff->a.dsize);
|
||||
if (read(fd, (void *)coff->a.data_start, coff->a.dsize) !=
|
||||
coff->a.dsize) {
|
||||
(void)printf("read data: %d\n", errno);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Zero out bss. */
|
||||
if (coff->a.bsize != 0) {
|
||||
(void)printf("+%lu", coff->a.bsize);
|
||||
bzero(coff->a.bss_start, coff->a.bsize);
|
||||
}
|
||||
|
||||
ffp_save = coff->a.text_start + coff->a.tsize;
|
||||
if (ffp_save < coff->a.data_start + coff->a.dsize)
|
||||
ffp_save = coff->a.data_start + coff->a.dsize;
|
||||
if (ffp_save < coff->a.bss_start + coff->a.bsize)
|
||||
ffp_save = coff->a.bss_start + coff->a.bsize;
|
||||
ffp_save = ALPHA_K0SEG_TO_PHYS((ffp_save + PGOFSET & ~PGOFSET)) >> PGSHIFT;
|
||||
ffp_save += 2; /* XXX OSF/1 does this, no idea why. */
|
||||
|
||||
(void)printf("\n");
|
||||
*entryp = coff->a.entry;
|
||||
return (0);
|
||||
}
|
||||
#endif /* ALPHA_BOOT_ECOFF */
|
||||
|
||||
#ifdef ALPHA_BOOT_ELF
|
||||
static int
|
||||
elf_exec(fd, elf, entryp)
|
||||
int fd;
|
||||
Elf_Ehdr *elf;
|
||||
u_int64_t *entryp;
|
||||
{
|
||||
int i;
|
||||
int first = 1;
|
||||
|
||||
for (i = 0; i < elf->e_phnum; i++) {
|
||||
Elf_Phdr phdr;
|
||||
(void)lseek(fd, elf->e_phoff + sizeof(phdr) * i, 0);
|
||||
if (read(fd, (void *)&phdr, sizeof(phdr)) != sizeof(phdr)) {
|
||||
(void)printf("read phdr: %d\n", errno);
|
||||
return (1);
|
||||
}
|
||||
if (phdr.p_type != Elf_pt_load)
|
||||
continue;
|
||||
|
||||
/* Read in segment. */
|
||||
(void)printf("%s%lu", first ? "" : "+", phdr.p_filesz);
|
||||
(void)lseek(fd, phdr.p_offset, 0);
|
||||
if (read(fd, (void *)phdr.p_vaddr, phdr.p_filesz) !=
|
||||
phdr.p_filesz) {
|
||||
(void)printf("read text: %d\n", errno);
|
||||
return (1);
|
||||
}
|
||||
if (first || ffp_save < phdr.p_vaddr + phdr.p_memsz)
|
||||
ffp_save = phdr.p_vaddr + phdr.p_memsz;
|
||||
|
||||
/* Zero out bss. */
|
||||
if (phdr.p_filesz < phdr.p_memsz) {
|
||||
(void)printf("+%lu", phdr.p_memsz - phdr.p_filesz);
|
||||
bzero(phdr.p_vaddr + phdr.p_filesz,
|
||||
phdr.p_memsz - phdr.p_filesz);
|
||||
}
|
||||
first = 0;
|
||||
}
|
||||
|
||||
ffp_save = ALPHA_K0SEG_TO_PHYS((ffp_save + PGOFSET & ~PGOFSET)) >> PGSHIFT;
|
||||
ffp_save += 2; /* XXX OSF/1 does this, no idea why. */
|
||||
|
||||
(void)printf("\n");
|
||||
*entryp = elf->e_entry;
|
||||
return (0);
|
||||
}
|
||||
#endif /* ALPHA_BOOT_ELF */
|
Loading…
Reference in New Issue