1995-09-17 03:20:22 +04:00
|
|
|
/* $NetBSD: boot.c,v 1.12 1995/09/16 23:20:25 pk Exp $ */
|
1994-11-20 23:51:32 +03:00
|
|
|
|
1994-02-26 13:57:09 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1982, 1986, 1990, 1993
|
|
|
|
* The Regents of the University of California. 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.
|
|
|
|
*
|
1994-11-20 23:51:32 +03:00
|
|
|
* @(#)boot.c 8.1 (Berkeley) 6/10/93
|
1994-02-26 13:57:09 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <a.out.h>
|
1995-09-17 03:20:22 +04:00
|
|
|
#include <stand.h>
|
1994-07-21 00:47:02 +04:00
|
|
|
|
1995-09-17 03:20:22 +04:00
|
|
|
#include "promdev.h"
|
1994-02-26 13:57:09 +03:00
|
|
|
|
1995-09-17 03:20:22 +04:00
|
|
|
static void copyunix __P((int, char *));
|
|
|
|
static void promsyms __P((int, struct exec *));
|
1994-07-01 14:46:55 +04:00
|
|
|
int debug;
|
|
|
|
int netif_debug;
|
|
|
|
|
1994-02-26 13:57:09 +03:00
|
|
|
/*
|
|
|
|
* Boot device is derived from ROM provided information.
|
|
|
|
*/
|
1994-07-30 18:22:11 +04:00
|
|
|
#define DEFAULT_KERNEL "netbsd"
|
1995-09-17 03:20:22 +04:00
|
|
|
|
1994-02-26 13:57:09 +03:00
|
|
|
extern char *version;
|
1994-03-20 12:13:37 +03:00
|
|
|
unsigned long esym;
|
|
|
|
char *strtab;
|
|
|
|
int strtablen;
|
1995-09-17 03:20:22 +04:00
|
|
|
char fbuf[80], dbuf[128];
|
|
|
|
|
|
|
|
void loadfile __P((int, caddr_t));
|
1994-02-26 13:57:09 +03:00
|
|
|
|
1995-09-17 03:20:22 +04:00
|
|
|
main()
|
1994-02-26 13:57:09 +03:00
|
|
|
{
|
|
|
|
int io;
|
1995-09-17 03:20:22 +04:00
|
|
|
char *file;
|
|
|
|
register void (*entry)__P((caddr_t)) = (void (*)__P((caddr_t)))LOADADDR;
|
1994-02-26 13:57:09 +03:00
|
|
|
|
1995-09-17 03:20:22 +04:00
|
|
|
prom_init();
|
1994-02-26 13:57:09 +03:00
|
|
|
|
1995-09-17 03:20:22 +04:00
|
|
|
printf(">> NetBSD BOOT [%s]\n", version);
|
1994-07-21 00:47:02 +04:00
|
|
|
|
1995-09-17 03:20:22 +04:00
|
|
|
file = prom_bootfile;
|
|
|
|
if (file == 0 || *file == 0)
|
|
|
|
file = DEFAULT_KERNEL;
|
1994-02-26 13:57:09 +03:00
|
|
|
|
1995-09-17 03:20:22 +04:00
|
|
|
for (;;) {
|
|
|
|
if (prom_boothow & RB_ASKNAME) {
|
|
|
|
printf("device[%s]: ", prom_bootdevice);
|
|
|
|
gets(dbuf);
|
|
|
|
if (dbuf[0])
|
|
|
|
prom_bootdevice = dbuf;
|
|
|
|
printf("boot: ");
|
|
|
|
gets(fbuf);
|
|
|
|
if (fbuf[0])
|
|
|
|
file = fbuf;
|
|
|
|
}
|
|
|
|
if ((io = open(file, 0)) >= 0)
|
|
|
|
break;
|
|
|
|
printf("open: %s: %s\n", file, strerror(errno));
|
|
|
|
prom_boothow |= RB_ASKNAME;
|
1994-02-26 13:57:09 +03:00
|
|
|
}
|
|
|
|
|
1995-09-17 03:20:22 +04:00
|
|
|
printf("Booting %s @ 0x%x\n", file, LOADADDR);
|
|
|
|
loadfile(io, LOADADDR);
|
|
|
|
|
|
|
|
/* Note: args 2-4 not used due to conflicts with SunOS loaders */
|
|
|
|
(*entry)(cputyp == CPU_SUN4 ? LOADADDR : (caddr_t)promvec,
|
|
|
|
0, 0, 0, esym, DDB_MAGIC);
|
1994-07-01 14:46:55 +04:00
|
|
|
_rtt();
|
1994-02-26 13:57:09 +03:00
|
|
|
}
|
|
|
|
|
1995-09-17 03:20:22 +04:00
|
|
|
void
|
|
|
|
loadfile(io, addr)
|
1994-02-26 13:57:09 +03:00
|
|
|
register int io;
|
1995-09-17 03:20:22 +04:00
|
|
|
register caddr_t addr;
|
1994-02-26 13:57:09 +03:00
|
|
|
{
|
|
|
|
struct exec x;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = read(io, (char *)&x, sizeof(x));
|
|
|
|
if (i != sizeof(x) ||
|
|
|
|
N_BADMAG(x)) {
|
1995-09-17 03:20:22 +04:00
|
|
|
printf("Bad format\n");
|
1994-02-26 13:57:09 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("%d", x.a_text);
|
|
|
|
if (N_GETMAGIC(x) == ZMAGIC) {
|
|
|
|
entry = (void (*)())(addr+sizeof(struct exec));
|
|
|
|
addr += sizeof(struct exec);
|
|
|
|
}
|
|
|
|
if (read(io, (char *)addr, x.a_text) != x.a_text)
|
|
|
|
goto shread;
|
|
|
|
addr += x.a_text;
|
|
|
|
if (N_GETMAGIC(x) == ZMAGIC || N_GETMAGIC(x) == NMAGIC)
|
1994-11-26 02:09:09 +03:00
|
|
|
while ((int)addr & __LDPGSZ)
|
1994-02-26 13:57:09 +03:00
|
|
|
*addr++ = 0;
|
|
|
|
printf("+%d", x.a_data);
|
|
|
|
if (read(io, addr, x.a_data) != x.a_data)
|
|
|
|
goto shread;
|
|
|
|
addr += x.a_data;
|
|
|
|
printf("+%d", x.a_bss);
|
|
|
|
for (i = 0; i < x.a_bss; i++)
|
|
|
|
*addr++ = 0;
|
|
|
|
if (x.a_syms != 0) {
|
|
|
|
bcopy(&x.a_syms, addr, sizeof(x.a_syms));
|
|
|
|
addr += sizeof(x.a_syms);
|
1995-09-17 03:20:22 +04:00
|
|
|
printf("+[%d", x.a_syms);
|
1994-02-26 13:57:09 +03:00
|
|
|
if (read(io, addr, x.a_syms) != x.a_syms)
|
|
|
|
goto shread;
|
|
|
|
addr += x.a_syms;
|
|
|
|
|
1994-03-20 12:13:37 +03:00
|
|
|
if (read(io, &strtablen, sizeof(int)) != sizeof(int))
|
1994-02-26 13:57:09 +03:00
|
|
|
goto shread;
|
|
|
|
|
1994-03-20 12:13:37 +03:00
|
|
|
bcopy(&strtablen, addr, sizeof(int));
|
|
|
|
if (i = strtablen) {
|
1994-02-26 13:57:09 +03:00
|
|
|
i -= sizeof(int);
|
|
|
|
addr += sizeof(int);
|
|
|
|
if (read(io, addr, i) != i)
|
|
|
|
goto shread;
|
|
|
|
addr += i;
|
|
|
|
}
|
1995-09-17 03:20:22 +04:00
|
|
|
printf("+%d]", i);
|
1994-03-20 12:13:37 +03:00
|
|
|
esym = KERNBASE +
|
|
|
|
(((int)addr + sizeof(int) - 1) & ~(sizeof(int) - 1));
|
1995-09-17 03:20:22 +04:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* The FORTH word `loadsyms' is mentioned in the
|
|
|
|
* "Openboot command reference" book, but it seems it has
|
|
|
|
* not been implemented on at least one machine..
|
|
|
|
*/
|
|
|
|
promsyms(io, &x);
|
|
|
|
#endif
|
1994-02-26 13:57:09 +03:00
|
|
|
}
|
1994-12-06 13:39:40 +03:00
|
|
|
printf("=0x%x\n", addr);
|
1995-09-17 03:20:22 +04:00
|
|
|
close(io);
|
1994-02-26 13:57:09 +03:00
|
|
|
return;
|
1995-09-17 03:20:22 +04:00
|
|
|
|
1994-02-26 13:57:09 +03:00
|
|
|
shread:
|
1995-09-17 03:20:22 +04:00
|
|
|
printf("boot: short read\n");
|
1994-02-26 13:57:09 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-09-17 03:20:22 +04:00
|
|
|
#if 0
|
|
|
|
struct syms {
|
|
|
|
u_int32_t value;
|
|
|
|
u_int32_t index;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
sort(syms, n)
|
|
|
|
struct syms *syms;
|
|
|
|
int n;
|
|
|
|
{
|
|
|
|
register struct syms *sj;
|
|
|
|
register int i, j, k;
|
|
|
|
register u_int32_t value, index;
|
|
|
|
|
|
|
|
/* Insertion sort. This is O(n^2), but so what? */
|
|
|
|
for (i = 1; i < n; i++) {
|
|
|
|
/* save i'th entry */
|
|
|
|
value = syms[i].value;
|
|
|
|
index = syms[i].index;
|
|
|
|
/* find j such that i'th entry goes before j'th */
|
|
|
|
for (j = 0, sj = syms; j < i; j++, sj++)
|
|
|
|
if (value < sj->value)
|
|
|
|
break;
|
|
|
|
/* slide up any additional entries */
|
|
|
|
for (k = 0; k < (i - j); k++) {
|
|
|
|
sj[k+1].value = sj[k].value;
|
|
|
|
sj[k+1].index = sj[k].index;
|
|
|
|
}
|
|
|
|
sj->value = value;
|
|
|
|
sj->index = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
promsyms(fd, hp)
|
|
|
|
int fd;
|
|
|
|
struct exec *hp;
|
1994-07-01 14:46:55 +04:00
|
|
|
{
|
1995-09-17 03:20:22 +04:00
|
|
|
int i, n, strtablen;
|
|
|
|
char *str, *p, *cp, buf[128];
|
|
|
|
struct syms *syms;
|
|
|
|
|
|
|
|
lseek(fd, sizeof(*hp)+hp->a_text+hp->a_data, SEEK_SET);
|
|
|
|
n = hp->a_syms/sizeof(struct nlist);
|
|
|
|
if (n == 0)
|
|
|
|
return;
|
|
|
|
syms = (struct syms *)alloc(n * sizeof(struct syms));
|
|
|
|
|
|
|
|
printf("+[%x+", hp->a_syms);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
struct nlist nlist;
|
|
|
|
|
|
|
|
if (read(fd, &nlist, sizeof(nlist)) != sizeof(nlist)) {
|
|
|
|
printf("promsyms: read failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
syms[i].value = nlist.n_value;
|
|
|
|
syms[i].index = nlist.n_un.n_strx - sizeof(strtablen);
|
|
|
|
}
|
|
|
|
|
|
|
|
sort(syms, n);
|
|
|
|
|
|
|
|
if (read(fd, &strtablen, sizeof(strtablen)) != sizeof(strtablen)) {
|
|
|
|
printf("promsym: read failed (strtablen)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strtablen < sizeof(strtablen)) {
|
|
|
|
printf("promsym: string table corrupted\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strtablen -= sizeof(strtablen);
|
|
|
|
str = (char *)alloc(strtablen);
|
|
|
|
|
|
|
|
printf("%x]", strtablen);
|
|
|
|
if (read(fd, str, strtablen) != strtablen) {
|
|
|
|
printf("promsym: read failed (strtab)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(buf, "%x %d %x loadsyms", syms, n, str);
|
|
|
|
(promvec->pv_fortheval.v2_eval)(buf);
|
1994-07-01 14:46:55 +04:00
|
|
|
}
|
1995-09-17 03:20:22 +04:00
|
|
|
#endif
|