Add support for selectively loading sections, and make this compile in
userland with -DINSTALLBOOT
This commit is contained in:
parent
9f32ccf21d
commit
f1fd49f426
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: exec.c,v 1.6 1999/01/28 20:21:24 christos Exp $ */
|
||||
/* $NetBSD: exec.c,v 1.7 1999/01/28 22:45:06 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1990, 1993
|
||||
|
@ -89,7 +89,7 @@ exec_netbsd(file, loadaddr, boothowto)
|
|||
int unit, part;
|
||||
const char *filename;
|
||||
int bootdevnr;
|
||||
u_long marks[LOAD_MAX];
|
||||
u_long marks[MARK_MAX];
|
||||
struct btinfo_symtab btinfo_symtab;
|
||||
#endif
|
||||
|
||||
|
@ -101,16 +101,16 @@ exec_netbsd(file, loadaddr, boothowto)
|
|||
|
||||
BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
|
||||
|
||||
marks[LOAD_START] = loadaddr;
|
||||
if ((fd = loadfile(file, marks)) == -1)
|
||||
marks[MARK_START] = loadaddr;
|
||||
if ((fd = loadfile(file, marks, LOAD_ALL)) == -1)
|
||||
goto out;
|
||||
|
||||
marks[LOAD_END] = (((u_long) marks[LOAD_END] + sizeof(int) - 1)) &
|
||||
marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
|
||||
(-sizeof(int));
|
||||
|
||||
btinfo_symtab.nsym = marks[LOAD_NSYM];
|
||||
btinfo_symtab.ssym = marks[LOAD_SYM];
|
||||
btinfo_symtab.esym = marks[LOAD_END];
|
||||
btinfo_symtab.nsym = marks[MARK_NSYM];
|
||||
btinfo_symtab.ssym = marks[MARK_SYM];
|
||||
btinfo_symtab.esym = marks[MARK_END];
|
||||
BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab));
|
||||
|
||||
boot_argv[0] = boothowto;
|
||||
|
@ -159,18 +159,18 @@ exec_netbsd(file, loadaddr, boothowto)
|
|||
bi_getbiosgeom();
|
||||
#endif
|
||||
boot_argv[2] = vtophys(bootinfo); /* old cyl offset */
|
||||
boot_argv[3] = marks[LOAD_END];
|
||||
boot_argv[3] = marks[MARK_END];
|
||||
boot_argv[4] = getextmem();
|
||||
boot_argv[5] = getbasemem();
|
||||
|
||||
close(fd);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[LOAD_START],
|
||||
marks[LOAD_NSYM], marks[LOAD_SYM], marks[LOAD_END]);
|
||||
printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", marks[MARK_START],
|
||||
marks[MARK_NSYM], marks[MARK_SYM], marks[MARK_END]);
|
||||
#endif
|
||||
|
||||
startprog(marks[LOAD_START], BOOT_NARGS, boot_argv, 0x90000);
|
||||
startprog(marks[MARK_START], BOOT_NARGS, boot_argv, 0x90000);
|
||||
panic("exec returned");
|
||||
|
||||
out:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: loadfile.c,v 1.1 1999/01/28 20:18:31 christos Exp $ */
|
||||
/* $NetBSD: loadfile.c,v 1.2 1999/01/28 22:45:07 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||
|
@ -75,8 +75,18 @@
|
|||
* @(#)boot.c 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef INSTALLBOOT
|
||||
#include <lib/libsa/stand.h>
|
||||
#include <lib/libkern/libkern.h>
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <err.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/exec.h>
|
||||
|
@ -85,15 +95,15 @@
|
|||
|
||||
#ifdef BOOT_ECOFF
|
||||
#include <sys/exec_ecoff.h>
|
||||
static int coff_exec __P((int, struct ecoff_exechdr *, u_long *));
|
||||
static int coff_exec __P((int, struct ecoff_exechdr *, u_long *, int));
|
||||
#endif
|
||||
#ifdef BOOT_ELF
|
||||
#include <sys/exec_elf.h>
|
||||
static int elf_exec __P((int, Elf_Ehdr *, u_long *));
|
||||
static int elf_exec __P((int, Elf_Ehdr *, u_long *, int));
|
||||
#endif
|
||||
#ifdef BOOT_AOUT
|
||||
#include <sys/exec_aout.h>
|
||||
static int aout_exec __P((int, struct exec *, u_long *));
|
||||
static int aout_exec __P((int, struct exec *, u_long *, int));
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -101,9 +111,10 @@ static int aout_exec __P((int, struct exec *, u_long *));
|
|||
* Fill in entryp and endp.
|
||||
*/
|
||||
int
|
||||
loadfile(fname, marks)
|
||||
loadfile(fname, marks, flags)
|
||||
const char *fname;
|
||||
u_long *marks;
|
||||
int flags;
|
||||
{
|
||||
union {
|
||||
#ifdef BOOT_ECOFF
|
||||
|
@ -122,39 +133,40 @@ loadfile(fname, marks)
|
|||
|
||||
/* Open the file. */
|
||||
if ((fd = open(fname, 0)) < 0) {
|
||||
(void)printf("open %s: %s\n", fname, strerror(errno));
|
||||
WARN(("open %s", fname));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Read the exec header. */
|
||||
if ((nr = read(fd, &hdr, sizeof(hdr))) != sizeof(hdr)) {
|
||||
(void)printf("read header: %s\n", strerror(errno));
|
||||
WARN(("read header"));
|
||||
goto err;
|
||||
}
|
||||
|
||||
#ifdef BOOT_ECOFF
|
||||
if (!ECOFF_BADMAG(&hdr.coff)) {
|
||||
rval = coff_exec(fd, &hdr.coff, marks);
|
||||
rval = coff_exec(fd, &hdr.coff, marks, flags);
|
||||
} else
|
||||
#endif
|
||||
#ifdef BOOT_ELF
|
||||
if (memcmp(Elf_e_ident, hdr.elf.e_ident, Elf_e_siz) == 0) {
|
||||
rval = elf_exec(fd, &hdr.elf, marks);
|
||||
rval = elf_exec(fd, &hdr.elf, marks, flags);
|
||||
} else
|
||||
#endif
|
||||
#ifdef BOOT_AOUT
|
||||
if (N_GETMAGIC(hdr.aout) == ZMAGIC &&
|
||||
if (OKMAGIC(N_GETMAGIC(hdr.aout)) &&
|
||||
N_GETMID(hdr.aout) == MID_MACHINE) {
|
||||
rval = aout_exec(fd, &hdr.aout, marks);
|
||||
rval = aout_exec(fd, &hdr.aout, marks, flags);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
rval = 1;
|
||||
(void)printf("%s: unknown executable format\n", fname);
|
||||
errno = EFTYPE;
|
||||
WARN(("%s", fname));
|
||||
}
|
||||
|
||||
if (rval == 0)
|
||||
(void)printf("=0x%lx\n", marks[LOAD_END] - marks[LOAD_START]);
|
||||
PROGRESS(("=0x%lx\n", marks[MARK_END] - marks[MARK_START]));
|
||||
return fd;
|
||||
err:
|
||||
(void)close(fd);
|
||||
|
@ -163,62 +175,73 @@ err:
|
|||
|
||||
#ifdef BOOT_ECOFF
|
||||
static int
|
||||
coff_exec(fd, coff, marks)
|
||||
coff_exec(fd, coff, marks, flags)
|
||||
int fd;
|
||||
struct ecoff_exechdr *coff;
|
||||
u_long *marks;
|
||||
int flags;
|
||||
{
|
||||
paddr_t ffp_save;
|
||||
paddr_t ffp_save = marks[MARK_START];
|
||||
|
||||
/* Read in text. */
|
||||
(void)printf("%lu", coff->a.tsize);
|
||||
if (lseek(fd, ECOFF_TXTOFF(coff), SEEK_SET) == -1) {
|
||||
(void)printf("lseek text: %s\n", strerror(errno));
|
||||
WARN(("lseek text"));
|
||||
return (1);
|
||||
}
|
||||
if (READ(fd, coff->a.text_start, coff->a.tsize) !=
|
||||
coff->a.tsize) {
|
||||
(void)printf("read text: %s\n", strerror(errno));
|
||||
return (1);
|
||||
if (flags & LOAD_TEXT) {
|
||||
PROGRESS(("%lu", coff->a.tsize));
|
||||
if (READ(fd, coff->a.text_start, ffp_save, coff->a.tsize) !=
|
||||
coff->a.tsize) {
|
||||
WARN(("read text"));
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Read in data. */
|
||||
if (coff->a.dsize != 0) {
|
||||
(void)printf("+%lu", coff->a.dsize);
|
||||
if (READ(fd, coff->a.data_start, coff->a.dsize) !=
|
||||
coff->a.dsize) {
|
||||
(void)printf("read data: %s\n", strerror(errno));
|
||||
else {
|
||||
if (lseek(fd, coff->a.tsize, SEEK_CUR) == -1) {
|
||||
WARN(("read text"));
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Zero out bss. */
|
||||
if (coff->a.bsize != 0) {
|
||||
(void)printf("+%lu", coff->a.bsize);
|
||||
BZERO(coff->a.bss_start, coff->a.bsize);
|
||||
/* Read in data. */
|
||||
if (coff->a.dsize != 0 && (flags & LOAD_DATA)) {
|
||||
PROGRESS(("+%lu", coff->a.dsize));
|
||||
if (READ(fd, coff->a.data_start, ffp_save, coff->a.dsize) !=
|
||||
coff->a.dsize) {
|
||||
WARN(("read data"));
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Zero out bss. */
|
||||
if (coff->a.bsize != 0 && (flags & LOAD_BSS)) {
|
||||
PROGRESS(("+%lu", coff->a.bsize));
|
||||
BZERO(coff->a.bss_start, ffp_save, coff->a.bsize);
|
||||
}
|
||||
|
||||
#ifndef INSTALLBOOT
|
||||
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;
|
||||
#endif
|
||||
|
||||
marks[LOAD_START] = LOADADDR(coff->a.entry);
|
||||
marks[LOAD_NSYM] = 1; /* XXX: Kernel needs >= 0 */
|
||||
marks[LOAD_SYM] = LOADADDR(ffp_save);
|
||||
marks[LOAD_END] = LOADADDR(ffp_save);
|
||||
marks[MARK_START] = LOADADDR(coff->a.entry);
|
||||
marks[MARK_NSYM] = 1; /* XXX: Kernel needs >= 0 */
|
||||
marks[MARK_SYM] = LOADADDR(ffp_save);
|
||||
marks[MARK_END] = LOADADDR(ffp_save);
|
||||
return (0);
|
||||
}
|
||||
#endif /* BOOT_ECOFF */
|
||||
|
||||
#ifdef BOOT_ELF
|
||||
static int
|
||||
elf_exec(fd, elf, marks)
|
||||
elf_exec(fd, elf, marks, flags)
|
||||
int fd;
|
||||
Elf_Ehdr *elf;
|
||||
u_long *marks;
|
||||
int flags;
|
||||
{
|
||||
Elf_Shdr *shp;
|
||||
Elf_Off off;
|
||||
|
@ -226,18 +249,18 @@ elf_exec(fd, elf, marks)
|
|||
size_t sz;
|
||||
int first = 1;
|
||||
int havesyms;
|
||||
paddr_t ffp_save = marks[LOAD_START], shp_save;
|
||||
paddr_t ffp_save = marks[MARK_START], shp_save;
|
||||
vaddr_t elf_save;
|
||||
|
||||
for (i = 0; i < elf->e_phnum; i++) {
|
||||
Elf_Phdr phdr;
|
||||
if (lseek(fd, elf->e_phoff + sizeof(phdr) * i, SEEK_SET)
|
||||
== -1) {
|
||||
(void)printf("lseek phdr: %s\n", strerror(errno));
|
||||
WARN(("lseek phdr"));
|
||||
return (1);
|
||||
}
|
||||
if (read(fd, (void *)&phdr, sizeof(phdr)) != sizeof(phdr)) {
|
||||
(void)printf("read phdr: %s\n", strerror(errno));
|
||||
WARN(("read phdr"));
|
||||
return (1);
|
||||
}
|
||||
if (phdr.p_type != Elf_pt_load ||
|
||||
|
@ -245,25 +268,31 @@ elf_exec(fd, elf, marks)
|
|||
continue;
|
||||
|
||||
/* Read in segment. */
|
||||
(void)printf("%s%lu", first ? "" : "+", (u_long)phdr.p_filesz);
|
||||
PROGRESS(("%s%lu", first ? "" : "+", (u_long)phdr.p_filesz));
|
||||
if (lseek(fd, phdr.p_offset, SEEK_SET) == -1) {
|
||||
(void)printf("lseek text: %s\n", strerror(errno));
|
||||
WARN(("lseek text"));
|
||||
return (1);
|
||||
}
|
||||
if (READ(fd, phdr.p_vaddr, phdr.p_filesz) !=
|
||||
phdr.p_filesz) {
|
||||
(void)printf("read text: %s\n", strerror(errno));
|
||||
return (1);
|
||||
/* XXX: Assume text comes before data! */
|
||||
if ((first && (flags & LOAD_TEXT)) ||
|
||||
(!first && (flags & LOAD_DATA))) {
|
||||
if (READ(fd, phdr.p_vaddr, ffp_save, phdr.p_filesz) !=
|
||||
phdr.p_filesz) {
|
||||
WARN(("read text"));
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef INSTALLBOOT
|
||||
if (first || ffp_save < phdr.p_vaddr + phdr.p_memsz)
|
||||
ffp_save = phdr.p_vaddr + phdr.p_memsz;
|
||||
#endif
|
||||
|
||||
/* Zero out bss. */
|
||||
if (phdr.p_filesz < phdr.p_memsz) {
|
||||
(void)printf("+%lu",
|
||||
(u_long)(phdr.p_memsz - phdr.p_filesz));
|
||||
BZERO((phdr.p_vaddr + phdr.p_filesz),
|
||||
if (phdr.p_filesz < phdr.p_memsz && (flags & LOAD_BSS)) {
|
||||
PROGRESS(("+%lu",
|
||||
(u_long)(phdr.p_memsz - phdr.p_filesz)));
|
||||
BZERO((phdr.p_vaddr + phdr.p_filesz), ffp_save,
|
||||
phdr.p_memsz - phdr.p_filesz);
|
||||
}
|
||||
first = 0;
|
||||
|
@ -272,105 +301,112 @@ elf_exec(fd, elf, marks)
|
|||
* Copy the ELF and section headers.
|
||||
*/
|
||||
ffp_save = roundup(ffp_save, sizeof(long));
|
||||
elf_save = ffp_save;
|
||||
ffp_save += sizeof(Elf_Ehdr);
|
||||
|
||||
if (lseek(fd, elf->e_shoff, SEEK_SET) == -1) {
|
||||
(void)printf("lseek section headers: %s\n", strerror(errno));
|
||||
return (1);
|
||||
}
|
||||
sz = elf->e_shnum * sizeof(Elf_Shdr);
|
||||
|
||||
shp = alloc(sz);
|
||||
|
||||
if (read(fd, shp, sz) != sz) {
|
||||
(void)printf("read section headers: %s\n", strerror(errno));
|
||||
return (1);
|
||||
if (flags & LOAD_HDR) {
|
||||
elf_save = ffp_save;
|
||||
ffp_save += sizeof(Elf_Ehdr);
|
||||
}
|
||||
|
||||
shp_save = ffp_save;
|
||||
ffp_save += roundup(sz, sizeof(long));
|
||||
|
||||
/*
|
||||
* Now load the symbol sections themselves. Make sure the
|
||||
* sections are aligned. Don't bother with string tables if
|
||||
* there are no symbol sections.
|
||||
*/
|
||||
off = roundup((sizeof(Elf_Ehdr) + sz), sizeof(long));
|
||||
|
||||
for (havesyms = i = 0; i < elf->e_shnum; i++)
|
||||
if (shp[i].sh_type == Elf_sht_symtab)
|
||||
havesyms = 1;
|
||||
|
||||
for (first = 1, i = 0; i < elf->e_shnum; i++) {
|
||||
if (shp[i].sh_type == Elf_sht_symtab ||
|
||||
shp[i].sh_type == Elf_sht_strtab) {
|
||||
(void)printf("%s%ld", first ? " [" : "+",
|
||||
(u_long)shp[i].sh_size);
|
||||
if (havesyms) {
|
||||
if (lseek(fd, shp[i].sh_offset, SEEK_SET)
|
||||
== -1) {
|
||||
(void)printf("\nlseek symbols: %s\n",
|
||||
strerror(errno));
|
||||
free(shp, sz);
|
||||
return (1);
|
||||
}
|
||||
if (READ(fd, ffp_save, shp[i].sh_size)
|
||||
!= shp[i].sh_size) {
|
||||
(void)printf("\nread symbols: %s\n",
|
||||
strerror(errno));
|
||||
free(shp, sz);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
ffp_save += roundup(shp[i].sh_size, sizeof(long));
|
||||
shp[i].sh_offset = off;
|
||||
off += roundup(shp[i].sh_size, sizeof(long));
|
||||
first = 0;
|
||||
if (flags & LOAD_SYM) {
|
||||
if (lseek(fd, elf->e_shoff, SEEK_SET) == -1) {
|
||||
WARN(("lseek section headers"));
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
BCOPY(shp, shp_save, sz);
|
||||
free(shp, sz);
|
||||
sz = elf->e_shnum * sizeof(Elf_Shdr);
|
||||
|
||||
if (first == 0)
|
||||
(void)printf("]");
|
||||
shp = ALLOC(sz);
|
||||
|
||||
if (read(fd, shp, sz) != sz) {
|
||||
WARN(("read section headers"));
|
||||
return (1);
|
||||
}
|
||||
|
||||
shp_save = ffp_save;
|
||||
ffp_save += roundup(sz, sizeof(long));
|
||||
|
||||
/*
|
||||
* Now load the symbol sections themselves. Make sure the
|
||||
* sections are aligned. Don't bother with string tables if
|
||||
* there are no symbol sections.
|
||||
*/
|
||||
off = roundup((sizeof(Elf_Ehdr) + sz), sizeof(long));
|
||||
|
||||
for (havesyms = i = 0; i < elf->e_shnum; i++)
|
||||
if (shp[i].sh_type == Elf_sht_symtab)
|
||||
havesyms = 1;
|
||||
|
||||
for (first = 1, i = 0; i < elf->e_shnum; i++) {
|
||||
if (shp[i].sh_type == Elf_sht_symtab ||
|
||||
shp[i].sh_type == Elf_sht_strtab) {
|
||||
PROGRESS(("%s%ld", first ? " [" : "+",
|
||||
(u_long)shp[i].sh_size));
|
||||
if (havesyms) {
|
||||
if (lseek(fd, shp[i].sh_offset,
|
||||
SEEK_SET)
|
||||
== -1) {
|
||||
WARN(("lseek symbols"));
|
||||
FREE(shp, sz);
|
||||
return (1);
|
||||
}
|
||||
if (READ(fd, ffp_save, ffp_save,
|
||||
shp[i].sh_size) != shp[i].sh_size) {
|
||||
WARN(("read symbols"));
|
||||
FREE(shp, sz);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
ffp_save += roundup(shp[i].sh_size,
|
||||
sizeof(long));
|
||||
shp[i].sh_offset = off;
|
||||
off += roundup(shp[i].sh_size, sizeof(long));
|
||||
first = 0;
|
||||
}
|
||||
}
|
||||
BCOPY(shp, shp_save, shp_save, sz);
|
||||
FREE(shp, sz);
|
||||
|
||||
if (first == 0)
|
||||
PROGRESS(("]"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Frob the copied ELF header to give information relative
|
||||
* to elf_save.
|
||||
*/
|
||||
elf->e_phoff = 0;
|
||||
elf->e_shoff = sizeof(Elf_Ehdr);
|
||||
elf->e_phentsize = 0;
|
||||
elf->e_phnum = 0;
|
||||
BCOPY(elf, elf_save, sizeof(*elf));
|
||||
if (flags & LOAD_HDR) {
|
||||
elf->e_phoff = 0;
|
||||
elf->e_shoff = sizeof(Elf_Ehdr);
|
||||
elf->e_phentsize = 0;
|
||||
elf->e_phnum = 0;
|
||||
BCOPY(elf, elf_save, elf_save, sizeof(*elf));
|
||||
}
|
||||
|
||||
marks[LOAD_START] = LOADADDR(elf->e_entry);
|
||||
marks[LOAD_NSYM] = 1; /* XXX: Kernel needs >= 0 */
|
||||
marks[LOAD_SYM] = LOADADDR(elf_save);
|
||||
marks[LOAD_END] = LOADADDR(ffp_save);
|
||||
marks[MARK_START] = LOADADDR(elf->e_entry);
|
||||
marks[MARK_NSYM] = 1; /* XXX: Kernel needs >= 0 */
|
||||
marks[MARK_SYM] = LOADADDR(elf_save);
|
||||
marks[MARK_END] = LOADADDR(ffp_save);
|
||||
return (0);
|
||||
}
|
||||
#endif /* BOOT_ELF */
|
||||
|
||||
#ifdef BOOT_AOUT
|
||||
static int
|
||||
aout_exec(fd, x, marks)
|
||||
aout_exec(fd, x, marks, flags)
|
||||
int fd;
|
||||
struct exec *x;
|
||||
u_long *marks;
|
||||
int flags;
|
||||
{
|
||||
u_long entry = x->a_entry;
|
||||
paddr_t ffp_save, aout_save;
|
||||
paddr_t ffp_save, aout_save = 0;
|
||||
int cc;
|
||||
|
||||
if (marks[LOAD_START] == 0)
|
||||
if (marks[MARK_START] == 0)
|
||||
ffp_save = ALIGNENTRY(entry);
|
||||
else
|
||||
ffp_save = marks[LOAD_START];
|
||||
ffp_save = marks[MARK_START];
|
||||
|
||||
if (lseek(fd, sizeof(*x), SEEK_SET) == -1) {
|
||||
(void)printf("lseek a.out: %s\n", strerror(errno));
|
||||
WARN(("lseek text"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -379,88 +415,100 @@ aout_exec(fd, x, marks)
|
|||
* The kernel may use this to verify that the
|
||||
* symbols were loaded by this boot program.
|
||||
*/
|
||||
BCOPY(x, ffp_save, sizeof(*x));
|
||||
ffp_save += sizeof(*x);
|
||||
if (flags & LOAD_HDR) {
|
||||
BCOPY(x, ffp_save, ffp_save, sizeof(*x));
|
||||
ffp_save += sizeof(*x);
|
||||
}
|
||||
/*
|
||||
* Read in the text segment.
|
||||
*/
|
||||
if (flags & LOAD_TEXT) {
|
||||
PROGRESS(("%ld", x->a_text));
|
||||
|
||||
(void)printf("%ld", x->a_text);
|
||||
|
||||
if (READ(fd, ffp_save, x->a_text - sizeof(*x)) !=
|
||||
x->a_text - sizeof(*x)) {
|
||||
(void)printf("read text: %s\n", strerror(errno));
|
||||
return 1;
|
||||
if (READ(fd, ffp_save, ffp_save, x->a_text - sizeof(*x)) !=
|
||||
x->a_text - sizeof(*x)) {
|
||||
WARN(("read text"));
|
||||
return 1;
|
||||
}
|
||||
ffp_save += x->a_text - sizeof(*x);
|
||||
} else {
|
||||
if (lseek(fd, x->a_text - sizeof(*x), SEEK_CUR) == -1) {
|
||||
WARN(("seek text"));
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
ffp_save += x->a_text - sizeof(*x);
|
||||
|
||||
/*
|
||||
* Read in the data segment.
|
||||
*/
|
||||
if (flags & LOAD_DATA) {
|
||||
PROGRESS(("+%ld", x->a_data));
|
||||
|
||||
(void)printf("+%ld", x->a_data);
|
||||
|
||||
if (READ(fd, ffp_save, x->a_data) != x->a_data) {
|
||||
(void)printf("read data: %s\n", strerror(errno));
|
||||
return 1;
|
||||
if (READ(fd, ffp_save, ffp_save, x->a_data) != x->a_data) {
|
||||
WARN(("read data"));
|
||||
return 1;
|
||||
}
|
||||
ffp_save += x->a_data;
|
||||
}
|
||||
ffp_save += x->a_data;
|
||||
|
||||
/*
|
||||
* Zero out the BSS section.
|
||||
* (Kernel doesn't care, but do it anyway.)
|
||||
*/
|
||||
if (flags & LOAD_BSS) {
|
||||
PROGRESS(("+%ld", x->a_bss));
|
||||
|
||||
|
||||
(void)printf("+%ld", x->a_bss);
|
||||
|
||||
BZERO(ffp_save, x->a_bss);
|
||||
ffp_save += x->a_bss;
|
||||
BZERO(ffp_save, ffp_save, x->a_bss);
|
||||
ffp_save += x->a_bss;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read in the symbol table and strings.
|
||||
* (Always set the symtab size word.)
|
||||
*/
|
||||
BCOPY(&x->a_syms, ffp_save, sizeof(x->a_syms));
|
||||
ffp_save += sizeof(x->a_syms);
|
||||
aout_save = ffp_save;
|
||||
if (flags & LOAD_SYM) {
|
||||
BCOPY(&x->a_syms, ffp_save, ffp_save, sizeof(x->a_syms));
|
||||
ffp_save += sizeof(x->a_syms);
|
||||
aout_save = ffp_save;
|
||||
|
||||
if (x->a_syms > 0) {
|
||||
/* Symbol table and string table length word. */
|
||||
if (x->a_syms > 0) {
|
||||
/* Symbol table and string table length word. */
|
||||
|
||||
(void)printf("+[%ld", x->a_syms);
|
||||
PROGRESS(("+[%ld", x->a_syms));
|
||||
|
||||
if (READ(fd, ffp_save, x->a_syms) != x->a_syms) {
|
||||
(void)printf("read symbols: %s\n", strerror(errno));
|
||||
return 1;
|
||||
if (READ(fd, ffp_save, ffp_save, x->a_syms) !=
|
||||
x->a_syms) {
|
||||
WARN(("read symbols"));
|
||||
return 1;
|
||||
}
|
||||
ffp_save += x->a_syms;
|
||||
|
||||
read(fd, &cc, sizeof(cc));
|
||||
|
||||
BCOPY(&cc, ffp_save, ffp_save, sizeof(cc));
|
||||
ffp_save += sizeof(cc);
|
||||
|
||||
/* String table. Length word includes itself. */
|
||||
|
||||
PROGRESS(("+%d]", cc));
|
||||
|
||||
cc -= sizeof(int);
|
||||
if (cc <= 0) {
|
||||
WARN(("symbol table too short"));
|
||||
return 1;
|
||||
}
|
||||
if (READ(fd, ffp_save, ffp_save, cc) != cc) {
|
||||
WARN(("read strings"));
|
||||
return 1;
|
||||
}
|
||||
ffp_save += cc;
|
||||
}
|
||||
ffp_save += x->a_syms;
|
||||
|
||||
read(fd, &cc, sizeof(cc));
|
||||
|
||||
BCOPY(&cc, ffp_save, sizeof(cc));
|
||||
ffp_save += sizeof(cc);
|
||||
|
||||
/* String table. Length word includes itself. */
|
||||
|
||||
(void)printf("+%d]", cc);
|
||||
|
||||
cc -= sizeof(int);
|
||||
if (cc <= 0) {
|
||||
(void)printf("symbol table too short\n");
|
||||
return 1;
|
||||
}
|
||||
if (READ(fd, ffp_save, cc) != cc) {
|
||||
(void)printf("read strings: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
ffp_save += cc;
|
||||
}
|
||||
|
||||
marks[LOAD_START] = LOADADDR(entry);
|
||||
marks[LOAD_NSYM] = x->a_syms;
|
||||
marks[LOAD_SYM] = LOADADDR(aout_save);
|
||||
marks[LOAD_END] = LOADADDR(ffp_save);
|
||||
marks[MARK_START] = LOADADDR(entry);
|
||||
marks[MARK_NSYM] = x->a_syms;
|
||||
marks[MARK_SYM] = LOADADDR(aout_save);
|
||||
marks[MARK_END] = LOADADDR(ffp_save);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: loadfile.h,v 1.1 1999/01/28 20:18:31 christos Exp $ */
|
||||
/* $NetBSD: loadfile.h,v 1.2 1999/01/28 22:45:07 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -40,19 +40,61 @@
|
|||
#define BOOT_ELF
|
||||
#define ELFSIZE 32
|
||||
|
||||
#define LOADADDR(a) ((u_long)(a) & 0x00ffffff)
|
||||
#define ALIGNENTRY(a) ((u_long)(a) & 0x00100000)
|
||||
#define READ(f, b, c) pread((f), (void *)LOADADDR(b), (c))
|
||||
#define BCOPY(s, d, c) vpbcopy((s), (void *)LOADADDR(d), (c))
|
||||
#define BZERO(d, c) pbzero((void *)LOADADDR(d), (c))
|
||||
/*
|
||||
* Array indices in the u_long position array
|
||||
*/
|
||||
#define MARK_START 0
|
||||
#define MARK_NSYM 1
|
||||
#define MARK_SYM 2
|
||||
#define MARK_END 3
|
||||
#define MARK_MAX 4
|
||||
|
||||
int loadfile __P((const char *, u_long *));
|
||||
#define LOAD_START 0
|
||||
#define LOAD_NSYM 1
|
||||
#define LOAD_SYM 2
|
||||
#define LOAD_END 3
|
||||
#define LOAD_MAX 4
|
||||
/*
|
||||
* Bit flags for sections to load
|
||||
*/
|
||||
#define LOAD_TEXT 0x01
|
||||
#define LOAD_DATA 0x02
|
||||
#define LOAD_BSS 0x04
|
||||
#define LOAD_SYM 0x08
|
||||
#define LOAD_HDR 0x10
|
||||
#define LOAD_ALL 0x1f
|
||||
|
||||
int loadfile __P((const char *, u_long *, int));
|
||||
|
||||
#ifndef INSTALLBOOT
|
||||
|
||||
#define LOADADDR(a) ((u_long)(a) & 0x00ffffff)
|
||||
#define ALIGNENTRY(a) ((u_long)(a) & 0x00100000)
|
||||
#define READ(f, b, v, c) pread((f), (void *)LOADADDR(b), (c))
|
||||
#define BCOPY(s, d, v, c) vpbcopy((s), (void *)LOADADDR(d), (c))
|
||||
#define BZERO(d, v, c) pbzero((void *)LOADADDR(d), (c))
|
||||
#define WARN(a) (void)(printf a, \
|
||||
printf((errno ? ": %s\n" : "\n"), \
|
||||
strerror(errno)))
|
||||
#define PROGRESS(a) (void) printf a
|
||||
#define ALLOC(a) alloc(a)
|
||||
#define FREE(a, b) free(a, b)
|
||||
#define OKMAGIC(a) ((a) == NMAGIC)
|
||||
|
||||
void vpbcopy __P((const void *, void *, size_t));
|
||||
void pbzero __P((void *, size_t));
|
||||
ssize_t pread __P((int, void *, size_t));
|
||||
|
||||
#else
|
||||
|
||||
#define LOADADDR(a) ((u_long)(a))
|
||||
#define ALIGNENTRY(a) ((u_long)(a))
|
||||
#define READ(f, b, v, c) vread((u_long)(f), (b), &(v), (c))
|
||||
#define BCOPY(s, d, v, c) vcopy((u_long)(s), (d), &(v), (c))
|
||||
#define BZERO(d, v, c) vzero((u_long)(d), &(v), (c))
|
||||
#define WARN(a) warn a
|
||||
#define PROGRESS(a) /* nothing */
|
||||
#define ALLOC(a) malloc(a)
|
||||
#define FREE(a, b) free(a)
|
||||
#define OKMAGIC(a) ((a) == OMAGIC)
|
||||
|
||||
ssize_t vread __P((int, u_long, u_long *, size_t));
|
||||
void vcopy __P((u_long, u_long, u_long *, size_t));
|
||||
void vzero __P((u_long, u_long *, size_t));
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue