1999-03-25 08:17:49 +03:00
|
|
|
/* $NetBSD: bootxx.c,v 1.14 1999/03/25 05:17:49 simonb Exp $ */
|
1994-10-27 00:08:38 +03:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/*
|
1994-05-27 12:40:50 +04:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-10-12 06:22:19 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
1994-10-27 00:08:38 +03:00
|
|
|
* @(#)boot.c 8.1 (Berkeley) 6/10/93
|
1993-10-12 06:22:19 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1999-03-25 08:17:49 +03:00
|
|
|
#include <sys/exec_elf.h>
|
1995-06-28 14:22:32 +04:00
|
|
|
#include <stand.h>
|
1999-01-29 08:37:45 +03:00
|
|
|
#include <machine/dec_prom.h>
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1995-01-18 09:53:36 +03:00
|
|
|
#include "byteswap.h"
|
|
|
|
|
1999-03-25 08:16:06 +03:00
|
|
|
int errno;
|
|
|
|
|
|
|
|
int loadfile __P((char *name));
|
|
|
|
extern int clear_cache __P((char *addr, int len));
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This gets arguments from the PROM, calls other routines to open
|
|
|
|
* and load the program to boot, and then transfers execution to that
|
|
|
|
* new program.
|
|
|
|
* Argv[0] should be something like "rz(0,0,0)vmunix" on a DECstation 3100.
|
|
|
|
* Argv[0,1] should be something like "boot 5/rz0/vmunix" on a DECstation 5000.
|
|
|
|
* The argument "-a" means vmunix should do an automatic reboot.
|
|
|
|
*/
|
1995-01-18 09:53:36 +03:00
|
|
|
int
|
1999-03-25 08:16:06 +03:00
|
|
|
main(argc, argv)
|
1993-10-12 06:22:19 +03:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
register char *cp;
|
1999-03-14 03:57:06 +03:00
|
|
|
int entry;
|
1995-06-28 14:22:32 +04:00
|
|
|
|
1994-05-27 12:40:50 +04:00
|
|
|
/* check for DS5000 boot */
|
|
|
|
if (strcmp(argv[0], "boot") == 0) {
|
1993-10-12 06:22:19 +03:00
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
1994-05-27 12:40:50 +04:00
|
|
|
cp = *argv;
|
1999-03-25 08:16:06 +03:00
|
|
|
|
|
|
|
#ifdef notused
|
|
|
|
printf(">> NetBSD/pmax Primary Boot\n");
|
|
|
|
#endif
|
1995-01-18 09:53:36 +03:00
|
|
|
entry = loadfile(cp);
|
|
|
|
if (entry == -1)
|
1999-03-25 08:16:06 +03:00
|
|
|
return (1);
|
1995-01-18 09:53:36 +03:00
|
|
|
|
1999-03-25 08:16:06 +03:00
|
|
|
clear_cache((char *)RELOC, 1024 * 1024);
|
1994-05-27 12:40:50 +04:00
|
|
|
if (callv == &callvec)
|
|
|
|
((void (*)())entry)(argc, argv, 0, 0);
|
|
|
|
else
|
|
|
|
((void (*)())entry)(argc, argv, DEC_PROM_MAGIC, callv);
|
1999-03-25 08:16:06 +03:00
|
|
|
return (1);
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open 'filename', read in program and return the entry point or -1 if error.
|
|
|
|
*/
|
1999-03-25 08:16:06 +03:00
|
|
|
int
|
1993-10-12 06:22:19 +03:00
|
|
|
loadfile(fname)
|
|
|
|
register char *fname;
|
|
|
|
{
|
|
|
|
register int fd, i, n;
|
1999-01-21 15:33:39 +03:00
|
|
|
char *buf;
|
1999-03-25 08:16:06 +03:00
|
|
|
Elf32_Ehdr ehdr;
|
|
|
|
Elf32_Phdr phdr;
|
|
|
|
char bootfname[64];
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1999-03-25 08:16:06 +03:00
|
|
|
strcpy(bootfname, fname);
|
|
|
|
buf = bootfname;
|
|
|
|
while ((n = *buf++) != '\0') {
|
|
|
|
if (n == ')')
|
|
|
|
break;
|
|
|
|
if (n != '/')
|
|
|
|
continue;
|
|
|
|
while ((n = *buf++) != '\0')
|
|
|
|
if (n == '/')
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
strcpy(buf, "boot");
|
|
|
|
if ((fd = open(bootfname, 0)) < 0) {
|
|
|
|
printf("open %s: %d\n", bootfname, errno);
|
1993-10-12 06:22:19 +03:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the exec header */
|
1999-03-25 08:16:06 +03:00
|
|
|
i = read(fd, (char *)&ehdr, sizeof(ehdr));
|
|
|
|
if ((i != sizeof(ehdr)) ||
|
|
|
|
(bcmp(ehdr.e_ident, Elf32_e_ident, Elf32_e_siz) != 0)) {
|
|
|
|
printf("%s: No ELF header\n", bootfname);
|
1993-10-12 06:22:19 +03:00
|
|
|
goto cerr;
|
|
|
|
}
|
|
|
|
|
1999-03-25 08:16:06 +03:00
|
|
|
for (i = 0; i < ehdr.e_phnum; i++) {
|
|
|
|
if (lseek(fd, (off_t) ehdr.e_phoff + i * sizeof(phdr), 0) < 0)
|
|
|
|
goto cerr;
|
|
|
|
if (read(fd, &phdr, sizeof(phdr)) != sizeof(phdr))
|
|
|
|
goto cerr;
|
|
|
|
if (phdr.p_type != Elf_pt_load)
|
|
|
|
continue;
|
|
|
|
if (lseek(fd, (off_t)phdr.p_offset, 0) < 0)
|
|
|
|
goto cerr;
|
|
|
|
if (read(fd, (char *)phdr.p_paddr, phdr.p_filesz) != phdr.p_filesz)
|
|
|
|
goto cerr;
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
1999-03-25 08:16:06 +03:00
|
|
|
return (ehdr.e_entry);
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
cerr:
|
1999-03-25 08:16:06 +03:00
|
|
|
#ifndef UFS_NOCLOSE
|
1993-10-12 06:22:19 +03:00
|
|
|
(void) close(fd);
|
1994-05-27 12:40:50 +04:00
|
|
|
#endif
|
1993-10-12 06:22:19 +03:00
|
|
|
err:
|
1999-03-25 08:16:06 +03:00
|
|
|
printf("Can't load '%s'\n", bootfname);
|
1993-10-12 06:22:19 +03:00
|
|
|
return (-1);
|
|
|
|
}
|