1997-03-22 07:15:51 +03:00
|
|
|
/* $NetBSD: exec.c,v 1.3 1997/03/22 04:15:51 thorpej Exp $ */
|
1997-03-14 05:40:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1986, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* Copyright (c) 1996
|
|
|
|
* Matthias Drochner. All rights reserved.
|
|
|
|
* Copyright (c) 1996
|
|
|
|
* Perry E. Metzger. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
/*
|
|
|
|
* starts NetBSD a.out kernel needs lowlevel startup from startprog.S
|
1997-03-14 05:40:32 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/exec_aout.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#ifdef COMPAT_OLDBOOT
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <lib/libsa/stand.h>
|
|
|
|
#include "libi386.h"
|
|
|
|
|
|
|
|
#ifdef COMPAT_OLDBOOT
|
|
|
|
static int
|
|
|
|
dev2major(devname, major)
|
1997-03-22 04:48:27 +03:00
|
|
|
char *devname;
|
|
|
|
int *major;
|
1997-03-14 05:40:32 +03:00
|
|
|
{
|
1997-03-22 04:48:27 +03:00
|
|
|
static char *devices[] = {"wd", "", "fd", "", "sd"};
|
1997-03-14 05:40:32 +03:00
|
|
|
#define NUMDEVICES (sizeof(devices)/sizeof(char *))
|
1997-03-22 04:48:27 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUMDEVICES; i++)
|
|
|
|
if (!strcmp(devname, devices[i])) {
|
|
|
|
*major = i;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (-1);
|
1997-03-14 05:40:32 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
int
|
|
|
|
exec_netbsd(file, loadaddr, boothowto, bootdev, consdev)
|
|
|
|
const char *file;
|
|
|
|
physaddr_t loadaddr;
|
|
|
|
int boothowto;
|
|
|
|
char *bootdev, *consdev; /* passed to kernel */
|
1997-03-14 05:40:32 +03:00
|
|
|
{
|
1997-03-22 04:48:27 +03:00
|
|
|
register int io;
|
|
|
|
struct exec x;
|
|
|
|
int cc, magic;
|
|
|
|
physaddr_t entry;
|
1997-03-14 05:40:32 +03:00
|
|
|
register physaddr_t cp;
|
1997-03-22 04:48:27 +03:00
|
|
|
u_long boot_argv[6];
|
1997-03-14 05:40:32 +03:00
|
|
|
|
|
|
|
#ifdef COMPAT_OLDBOOT
|
1997-03-22 04:48:27 +03:00
|
|
|
char *fsname, *devname;
|
|
|
|
int unit, part;
|
|
|
|
const char *filename;
|
|
|
|
int bootdevnr;
|
1997-03-14 05:40:32 +03:00
|
|
|
#else
|
1997-03-22 04:48:27 +03:00
|
|
|
u_long xbootinfo[2];
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("exec: file=%s loadaddr=0x%lx\n", file, loadaddr);
|
|
|
|
#endif
|
|
|
|
io = open(file, 0);
|
|
|
|
if (io < 0)
|
1997-03-22 04:48:27 +03:00
|
|
|
return (-1);
|
1997-03-14 05:40:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in the exec header, and validate it.
|
|
|
|
*/
|
1997-03-22 04:48:27 +03:00
|
|
|
if (read(io, (char *) &x, sizeof(x)) != sizeof(x))
|
|
|
|
goto shread;
|
1997-03-14 05:40:32 +03:00
|
|
|
magic = N_GETMAGIC(x);
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
if ((magic != ZMAGIC) || (N_GETMID(x) != MID_MACHINE)) {
|
1997-03-14 05:40:32 +03:00
|
|
|
#ifdef DEBUG
|
1997-03-22 04:48:27 +03:00
|
|
|
printf("invalid NetBSD kernel (%o/%ld)\n", magic, N_GETMID(x));
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
1997-03-22 04:48:27 +03:00
|
|
|
errno = EFTYPE;
|
|
|
|
goto closeout;
|
1997-03-14 05:40:32 +03:00
|
|
|
}
|
|
|
|
entry = x.a_entry & 0xffffff;
|
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
if (!loadaddr)
|
|
|
|
loadaddr = (entry & 0x100000);
|
1997-03-14 05:40:32 +03:00
|
|
|
|
|
|
|
cp = loadaddr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Leave a copy of the exec header before the text.
|
|
|
|
* The kernel may use this to verify that the
|
|
|
|
* symbols were loaded by this boot program.
|
|
|
|
*/
|
|
|
|
vpbcopy(&x, cp, sizeof(x));
|
|
|
|
cp += sizeof(x);
|
|
|
|
/*
|
|
|
|
* Read in the text segment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
printf("%ld", x.a_text);
|
|
|
|
|
|
|
|
if (pread(io, cp, x.a_text - sizeof(x)) != x.a_text - sizeof(x))
|
|
|
|
goto shread;
|
1997-03-22 04:48:27 +03:00
|
|
|
cp += x.a_text - sizeof(x);
|
1997-03-14 05:40:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in the data segment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
printf("+%ld", x.a_data);
|
|
|
|
|
|
|
|
if (pread(io, cp, x.a_data) != x.a_data)
|
|
|
|
goto shread;
|
|
|
|
cp += x.a_data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Zero out the BSS section.
|
|
|
|
* (Kernel doesn't care, but do it anyway.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
printf("+%ld", x.a_bss);
|
|
|
|
|
|
|
|
pbzero(cp, x.a_bss);
|
|
|
|
cp += x.a_bss;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in the symbol table and strings.
|
|
|
|
* (Always set the symtab size word.)
|
|
|
|
*/
|
|
|
|
vpbcopy(&x.a_syms, cp, sizeof(x.a_syms));
|
|
|
|
cp += sizeof(x.a_syms);
|
|
|
|
|
|
|
|
if (x.a_syms > 0) {
|
|
|
|
|
|
|
|
/* Symbol table and string table length word. */
|
|
|
|
|
|
|
|
printf("+[%ld", x.a_syms);
|
|
|
|
|
|
|
|
if (pread(io, cp, x.a_syms) != x.a_syms)
|
|
|
|
goto shread;
|
|
|
|
cp += x.a_syms;
|
|
|
|
|
|
|
|
read(io, &cc, sizeof(cc));
|
|
|
|
|
|
|
|
vpbcopy(&cc, cp, sizeof(cc));
|
|
|
|
cp += sizeof(cc);
|
|
|
|
|
|
|
|
/* String table. Length word includes itself. */
|
|
|
|
|
|
|
|
printf("+%d]", cc);
|
|
|
|
|
|
|
|
cc -= sizeof(int);
|
|
|
|
if (cc <= 0)
|
|
|
|
goto shread;
|
|
|
|
if (pread(io, cp, cc) != cc)
|
|
|
|
goto shread;
|
|
|
|
cp += cc;
|
|
|
|
}
|
1997-03-22 04:48:27 +03:00
|
|
|
boot_argv[3] = (((u_int) cp + sizeof(int) - 1)) & (-sizeof(int));
|
1997-03-14 05:40:32 +03:00
|
|
|
|
|
|
|
printf("=0x%lx\n", cp - loadaddr);
|
|
|
|
|
|
|
|
boot_argv[0] = boothowto;
|
|
|
|
|
|
|
|
#ifdef COMPAT_OLDBOOT
|
|
|
|
/* prepare boot device information for kernel */
|
1997-03-22 04:48:27 +03:00
|
|
|
if (parsebootfile(file, &fsname, &devname, &unit, &part, &filename)
|
|
|
|
|| strcmp(fsname, "ufs"))
|
|
|
|
bootdevnr = 0; /* XXX error out if parse error??? */
|
1997-03-14 05:40:32 +03:00
|
|
|
else {
|
1997-03-22 04:48:27 +03:00
|
|
|
int major;
|
|
|
|
|
1997-03-22 07:15:51 +03:00
|
|
|
if (strcmp(devname, "hd") == 0) {
|
1997-03-22 04:48:27 +03:00
|
|
|
/* generic BIOS disk, have to guess type */
|
|
|
|
struct open_file *f = &files[io]; /* XXX */
|
|
|
|
|
|
|
|
if (biosdisk_gettype(f) == DTYPE_SCSI)
|
|
|
|
devname = "sd";
|
|
|
|
else
|
|
|
|
devname = "wd";
|
1997-03-22 07:15:51 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The old boot block performed the following
|
|
|
|
* conversion:
|
|
|
|
*
|
|
|
|
* hdN -> Xd0
|
|
|
|
*
|
|
|
|
* where X is the type specified by the label.
|
|
|
|
* We mimmick that here, for lack of any better
|
|
|
|
* way of doing things.
|
|
|
|
*/
|
|
|
|
unit = 0;
|
1997-03-22 04:48:27 +03:00
|
|
|
}
|
1997-03-22 07:15:51 +03:00
|
|
|
|
1997-03-22 04:48:27 +03:00
|
|
|
if (dev2major(devname, &major))
|
|
|
|
bootdevnr = 0; /* XXX error out??? */
|
1997-03-14 05:40:32 +03:00
|
|
|
else
|
1997-03-22 04:48:27 +03:00
|
|
|
bootdevnr = MAKEBOOTDEV(major, 0, 0, unit, part);
|
1997-03-14 05:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
boot_argv[1] = bootdevnr;
|
1997-03-22 04:48:27 +03:00
|
|
|
boot_argv[2] = 0; /* cyl offset, unused */
|
|
|
|
#else /* XXX to be specified */
|
1997-03-14 05:40:32 +03:00
|
|
|
xbootinfo[0] = vtophys(bootdev);
|
|
|
|
xbootinfo[1] = vtophys(consdev);
|
|
|
|
boot_argv[1] = 0;
|
1997-03-22 04:48:27 +03:00
|
|
|
boot_argv[2] = vtophys(xbootinfo); /* XXX cyl offset */
|
1997-03-14 05:40:32 +03:00
|
|
|
#endif
|
1997-03-22 04:48:27 +03:00
|
|
|
/*
|
|
|
|
* boot_argv[3] = end (set above)
|
|
|
|
*/
|
1997-03-14 05:40:32 +03:00
|
|
|
boot_argv[4] = getextmem();
|
|
|
|
boot_argv[5] = getbasemem();
|
|
|
|
|
|
|
|
close(io);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Start @ 0x%lx ...\n", entry);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
startprog(entry, 6, boot_argv, 0x90000);
|
|
|
|
panic("exec returned");
|
|
|
|
|
|
|
|
shread:
|
|
|
|
printf("exec: short read\n");
|
|
|
|
errno = EIO;
|
|
|
|
closeout:
|
|
|
|
close(io);
|
1997-03-22 04:48:27 +03:00
|
|
|
return (-1);
|
1997-03-14 05:40:32 +03:00
|
|
|
}
|