Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.8
      1  1.8        pk /*	$NetBSD: boot.c,v 1.8 1999/06/12 12:49:24 pk Exp $ */
      2  1.1       mrg 
      3  1.1       mrg /*-
      4  1.1       mrg  * Copyright (c) 1982, 1986, 1990, 1993
      5  1.1       mrg  *	The Regents of the University of California.  All rights reserved.
      6  1.1       mrg  *
      7  1.1       mrg  * Redistribution and use in source and binary forms, with or without
      8  1.1       mrg  * modification, are permitted provided that the following conditions
      9  1.1       mrg  * are met:
     10  1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     11  1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     12  1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     14  1.1       mrg  *    documentation and/or other materials provided with the distribution.
     15  1.1       mrg  * 3. All advertising materials mentioning features or use of this software
     16  1.1       mrg  *    must display the following acknowledgement:
     17  1.1       mrg  *	This product includes software developed by the University of
     18  1.1       mrg  *	California, Berkeley and its contributors.
     19  1.1       mrg  * 4. Neither the name of the University nor the names of its contributors
     20  1.1       mrg  *    may be used to endorse or promote products derived from this software
     21  1.1       mrg  *    without specific prior written permission.
     22  1.1       mrg  *
     23  1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1       mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1       mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1       mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1       mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1       mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1       mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1       mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1       mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1       mrg  * SUCH DAMAGE.
     34  1.1       mrg  *
     35  1.1       mrg  * 	@(#)boot.c	8.1 (Berkeley) 6/10/93
     36  1.1       mrg  */
     37  1.1       mrg 
     38  1.1       mrg #include <sys/param.h>
     39  1.1       mrg #include <sys/reboot.h>
     40  1.1       mrg #include <a.out.h>
     41  1.1       mrg 
     42  1.1       mrg #include <lib/libsa/stand.h>
     43  1.5  christos #include <lib/libsa/loadfile.h>
     44  1.1       mrg 
     45  1.4        pk #include <machine/promlib.h>
     46  1.1       mrg #include <sparc/stand/common/promdev.h>
     47  1.1       mrg 
     48  1.6  christos #include "bootinfo.h"
     49  1.6  christos 
     50  1.4        pk static int	bootoptions __P((char *));
     51  1.4        pk #if 0
     52  1.4        pk static void	promsyms __P((int, struct exec *));
     53  1.4        pk #endif
     54  1.4        pk 
     55  1.1       mrg int debug;
     56  1.1       mrg int netif_debug;
     57  1.1       mrg 
     58  1.1       mrg extern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[];
     59  1.1       mrg unsigned long		esym;
     60  1.1       mrg char			*strtab;
     61  1.1       mrg int			strtablen;
     62  1.1       mrg char			fbuf[80], dbuf[128];
     63  1.1       mrg 
     64  1.4        pk int	main __P((void));
     65  1.1       mrg typedef void (*entry_t)__P((caddr_t, int, int, int, long, long));
     66  1.1       mrg 
     67  1.1       mrg 
     68  1.3       mrg /*
     69  1.3       mrg  * Boot device is derived from ROM provided information, or if there is none,
     70  1.3       mrg  * this list is used in sequence, to find a kernel.
     71  1.3       mrg  */
     72  1.3       mrg char *kernels[] = {
     73  1.3       mrg 	"netbsd",
     74  1.3       mrg 	"netbsd.gz",
     75  1.3       mrg 	"netbsd.old",
     76  1.3       mrg 	"netbsd.old.gz",
     77  1.3       mrg 	"onetbsd",
     78  1.3       mrg 	"onetbsd.gz",
     79  1.3       mrg 	"vmunix",
     80  1.3       mrg #ifdef notyet
     81  1.3       mrg 	"netbsd.pl",
     82  1.3       mrg 	"netbsd.pl.gz",
     83  1.3       mrg 	"netbsd.el",
     84  1.3       mrg 	"netbsd.el.gz",
     85  1.3       mrg #endif
     86  1.3       mrg 	NULL
     87  1.3       mrg };
     88  1.3       mrg 
     89  1.4        pk int
     90  1.4        pk bootoptions(ap)
     91  1.4        pk 	char *ap;
     92  1.4        pk {
     93  1.4        pk 	int v = 0;
     94  1.4        pk 	if (ap == NULL || *ap++ != '-')
     95  1.4        pk 		return (0);
     96  1.4        pk 
     97  1.4        pk 	while (*ap != '\0' && *ap != ' ' && *ap != '\t' && *ap != '\n') {
     98  1.4        pk 		switch (*ap) {
     99  1.4        pk 		case 'a':
    100  1.4        pk 			v |= RB_ASKNAME;
    101  1.4        pk 			break;
    102  1.4        pk 		case 's':
    103  1.4        pk 			v |= RB_SINGLE;
    104  1.4        pk 			break;
    105  1.4        pk 		case 'd':
    106  1.4        pk 			v |= RB_KDB;
    107  1.4        pk 			debug = 1;
    108  1.4        pk 			break;
    109  1.4        pk 		}
    110  1.4        pk 		ap++;
    111  1.4        pk 	}
    112  1.4        pk 
    113  1.4        pk 	return (v);
    114  1.4        pk }
    115  1.4        pk 
    116  1.4        pk int
    117  1.1       mrg main()
    118  1.1       mrg {
    119  1.3       mrg 	int	io, i;
    120  1.3       mrg 	char	*kernel;
    121  1.4        pk 	int	how;
    122  1.6  christos 	u_long	marks[MARK_MAX], bootinfo;
    123  1.6  christos 	struct btinfo_symtab bi_sym;
    124  1.5  christos 	void	*arg;
    125  1.1       mrg 
    126  1.8        pk #ifdef HEAP_VARIABLE
    127  1.8        pk 	{
    128  1.8        pk 		extern char end[];
    129  1.8        pk 		setheap((void *)ALIGN(end), (void *)0xffffffff);
    130  1.8        pk 	}
    131  1.8        pk #endif
    132  1.1       mrg 	prom_init();
    133  1.1       mrg 
    134  1.1       mrg 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
    135  1.1       mrg 	printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
    136  1.1       mrg 
    137  1.3       mrg 	/*
    138  1.3       mrg 	 * get default kernel.
    139  1.3       mrg 	 */
    140  1.4        pk 	prom_bootdevice = prom_getbootpath();
    141  1.4        pk 	kernel = prom_getbootfile();
    142  1.4        pk 	how = bootoptions(prom_getbootargs());
    143  1.4        pk 
    144  1.4        pk 	if (kernel != NULL && *kernel != '\0') {
    145  1.3       mrg 		i = -1;	/* not using the kernels */
    146  1.3       mrg 	} else {
    147  1.3       mrg 		i = 0;
    148  1.3       mrg 		kernel = kernels[i];
    149  1.3       mrg 	}
    150  1.1       mrg 
    151  1.1       mrg 	for (;;) {
    152  1.3       mrg 		/*
    153  1.3       mrg 		 * ask for a kernel first ..
    154  1.3       mrg 		 */
    155  1.4        pk 		if (how & RB_ASKNAME) {
    156  1.3       mrg 			printf("device[%s] (\"halt\" to halt): ",
    157  1.4        pk 					prom_bootdevice);
    158  1.1       mrg 			gets(dbuf);
    159  1.3       mrg 			if (strcmp(dbuf, "halt") == 0)
    160  1.3       mrg 				_rtt();
    161  1.1       mrg 			if (dbuf[0])
    162  1.1       mrg 				prom_bootdevice = dbuf;
    163  1.3       mrg 			printf("boot (press RETURN to try default list): ");
    164  1.1       mrg 			gets(fbuf);
    165  1.1       mrg 			if (fbuf[0])
    166  1.3       mrg 				kernel = fbuf;
    167  1.3       mrg 			else {
    168  1.4        pk 				how &= ~RB_ASKNAME;
    169  1.3       mrg 				i = 0;
    170  1.3       mrg 				kernel = kernels[i];
    171  1.3       mrg 			}
    172  1.1       mrg 		}
    173  1.3       mrg 
    174  1.5  christos 		marks[MARK_START] = 0;
    175  1.5  christos 		printf("Booting %s\n", kernel);
    176  1.5  christos 		if ((io = loadfile(kernel, marks, LOAD_KERNEL)) != -1)
    177  1.1       mrg 			break;
    178  1.5  christos 
    179  1.3       mrg 		/*
    180  1.3       mrg 		 * if we have are not in askname mode, and we aren't using the
    181  1.3       mrg 		 * prom bootfile, try the next one (if it exits).  otherwise,
    182  1.3       mrg 		 * go into askname mode.
    183  1.3       mrg 		 */
    184  1.4        pk 		if ((how & RB_ASKNAME) == 0 &&
    185  1.3       mrg 		    i != -1 && kernels[++i]) {
    186  1.3       mrg 			kernel = kernels[i];
    187  1.3       mrg 			printf(": trying %s...\n", kernel);
    188  1.3       mrg 		} else {
    189  1.3       mrg 			printf("\n");
    190  1.4        pk 			how |= RB_ASKNAME;
    191  1.3       mrg 		}
    192  1.1       mrg 	}
    193  1.1       mrg 
    194  1.5  christos 	marks[MARK_END] = (((u_long)marks[MARK_END] + sizeof(int) - 1)) &
    195  1.5  christos 	    (-sizeof(int));
    196  1.7  christos 	arg = (prom_version() == PROM_OLDMON) ? (caddr_t)PROM_LOADADDR : romp;
    197  1.6  christos #if 0
    198  1.6  christos 	/* Old style cruft; works only with a.out */
    199  1.5  christos 	marks[MARK_END] |= 0xf0000000;
    200  1.5  christos 	(*(entry_t)marks[MARK_ENTRY])(arg, 0, 0, 0, marks[MARK_END],
    201  1.5  christos 	    DDB_MAGIC1);
    202  1.6  christos #else
    203  1.6  christos 	/* Should work with both a.out and ELF, but somehow ELF is busted */
    204  1.6  christos 	bootinfo = bi_init(marks[MARK_END]);
    205  1.6  christos 	bi_sym.nsym = marks[MARK_NSYM];
    206  1.6  christos 	bi_sym.ssym = marks[MARK_SYM];
    207  1.6  christos 	bi_sym.esym = marks[MARK_END];
    208  1.6  christos 	bi_add(&bi_sym, BTINFO_SYMTAB, sizeof(bi_sym));
    209  1.6  christos 	(*(entry_t)marks[MARK_ENTRY])(arg, 0, 0, 0, bootinfo, DDB_MAGIC2);
    210  1.6  christos #endif
    211  1.1       mrg 
    212  1.1       mrg 	_rtt();
    213  1.1       mrg }
    214