Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.1.6.2
      1  1.1.6.2  yamt /*	$NetBSD: boot.c,v 1.1.6.2 2014/05/22 11:39:50 yamt Exp $	*/
      2  1.1.6.2  yamt 
      3  1.1.6.2  yamt /*-
      4  1.1.6.2  yamt  * Copyright (c) 1982, 1986, 1990, 1993
      5  1.1.6.2  yamt  *	The Regents of the University of California.  All rights reserved.
      6  1.1.6.2  yamt  *
      7  1.1.6.2  yamt  * Redistribution and use in source and binary forms, with or without
      8  1.1.6.2  yamt  * modification, are permitted provided that the following conditions
      9  1.1.6.2  yamt  * are met:
     10  1.1.6.2  yamt  * 1. Redistributions of source code must retain the above copyright
     11  1.1.6.2  yamt  *    notice, this list of conditions and the following disclaimer.
     12  1.1.6.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1.6.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     14  1.1.6.2  yamt  *    documentation and/or other materials provided with the distribution.
     15  1.1.6.2  yamt  * 3. Neither the name of the University nor the names of its contributors
     16  1.1.6.2  yamt  *    may be used to endorse or promote products derived from this software
     17  1.1.6.2  yamt  *    without specific prior written permission.
     18  1.1.6.2  yamt  *
     19  1.1.6.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  1.1.6.2  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.1.6.2  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.1.6.2  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  1.1.6.2  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.1.6.2  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.1.6.2  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.1.6.2  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.1.6.2  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.1.6.2  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.1.6.2  yamt  * SUCH DAMAGE.
     30  1.1.6.2  yamt  *
     31  1.1.6.2  yamt  *	@(#)boot.c	8.1 (Berkeley) 6/10/93
     32  1.1.6.2  yamt  */
     33  1.1.6.2  yamt 
     34  1.1.6.2  yamt /*
     35  1.1.6.2  yamt  * Copyright (c) 1998-2004 Michael Shalayeff
     36  1.1.6.2  yamt  * All rights reserved.
     37  1.1.6.2  yamt  *
     38  1.1.6.2  yamt  * Redistribution and use in source and binary forms, with or without
     39  1.1.6.2  yamt  * modification, are permitted provided that the following conditions
     40  1.1.6.2  yamt  * are met:
     41  1.1.6.2  yamt  * 1. Redistributions of source code must retain the above copyright
     42  1.1.6.2  yamt  *    notice, this list of conditions and the following disclaimer.
     43  1.1.6.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     44  1.1.6.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     45  1.1.6.2  yamt  *    documentation and/or other materials provided with the distribution.
     46  1.1.6.2  yamt  *
     47  1.1.6.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     48  1.1.6.2  yamt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     49  1.1.6.2  yamt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     50  1.1.6.2  yamt  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
     51  1.1.6.2  yamt  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     52  1.1.6.2  yamt  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     53  1.1.6.2  yamt  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     54  1.1.6.2  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     55  1.1.6.2  yamt  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     56  1.1.6.2  yamt  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     57  1.1.6.2  yamt  * THE POSSIBILITY OF SUCH DAMAGE.
     58  1.1.6.2  yamt  *
     59  1.1.6.2  yamt  */
     60  1.1.6.2  yamt 
     61  1.1.6.2  yamt #include <sys/param.h>
     62  1.1.6.2  yamt #include <sys/reboot.h>
     63  1.1.6.2  yamt #include <sys/boot_flag.h>
     64  1.1.6.2  yamt 
     65  1.1.6.2  yamt #include <arch/hppa/stand/common/libsa.h>
     66  1.1.6.2  yamt #include <lib/libsa/loadfile.h>
     67  1.1.6.2  yamt 
     68  1.1.6.2  yamt #include <machine/pdc.h>
     69  1.1.6.2  yamt #include <machine/vmparam.h>
     70  1.1.6.2  yamt 
     71  1.1.6.2  yamt #include <arch/hppa/stand/common/dev_hppa.h>
     72  1.1.6.2  yamt 
     73  1.1.6.2  yamt #include "bootinfo.h"
     74  1.1.6.2  yamt 
     75  1.1.6.2  yamt /*
     76  1.1.6.2  yamt  * Boot program... bits in `howto' determine whether boot stops to
     77  1.1.6.2  yamt  * ask for system name.	 Boot device is derived from ROM provided
     78  1.1.6.2  yamt  * information.
     79  1.1.6.2  yamt  */
     80  1.1.6.2  yamt 
     81  1.1.6.2  yamt #define	MAXLEN	100
     82  1.1.6.2  yamt 
     83  1.1.6.2  yamt char line[MAXLEN];
     84  1.1.6.2  yamt char devname_buffer[16];
     85  1.1.6.2  yamt 
     86  1.1.6.2  yamt extern	u_int opendev;
     87  1.1.6.2  yamt extern	char *lowram;
     88  1.1.6.2  yamt extern	int noconsole;
     89  1.1.6.2  yamt 
     90  1.1.6.2  yamt /*
     91  1.1.6.2  yamt  * XXX UFS accepts a /, NFS doesn't.
     92  1.1.6.2  yamt  */
     93  1.1.6.2  yamt char *name;
     94  1.1.6.2  yamt char *names[] = {
     95  1.1.6.2  yamt 	"netbsd",		"netbsd.gz",
     96  1.1.6.2  yamt 	"netbsd.bak",		"netbsd.bak.gz",
     97  1.1.6.2  yamt 	"netbsd.old",		"netbsd.old.gz",
     98  1.1.6.2  yamt 	"onetbsd",		"onetbsd.gz",
     99  1.1.6.2  yamt 	NULL
    100  1.1.6.2  yamt };
    101  1.1.6.2  yamt #define NUMNAMES	(sizeof(names) / sizeof(char *))
    102  1.1.6.2  yamt 
    103  1.1.6.2  yamt void boot(dev_t boot_dev);
    104  1.1.6.2  yamt int main(void);
    105  1.1.6.2  yamt void getbootdev(int *);
    106  1.1.6.2  yamt void exec_hppa(char *, u_long, int);
    107  1.1.6.2  yamt 
    108  1.1.6.2  yamt int tgets(char *);
    109  1.1.6.2  yamt void _rtt(void);
    110  1.1.6.2  yamt 
    111  1.1.6.2  yamt typedef void (*startfuncp)(int, int, int, int, int, void *)
    112  1.1.6.2  yamt     __attribute__ ((noreturn));
    113  1.1.6.2  yamt 
    114  1.1.6.2  yamt int howto;
    115  1.1.6.2  yamt 
    116  1.1.6.2  yamt void
    117  1.1.6.2  yamt boot(dev_t boot_dev)
    118  1.1.6.2  yamt {
    119  1.1.6.2  yamt 	machdep();
    120  1.1.6.2  yamt #ifdef	DEBUGBUG
    121  1.1.6.2  yamt 	debug = 1;
    122  1.1.6.2  yamt #endif
    123  1.1.6.2  yamt 	devboot(boot_dev, devname_buffer);
    124  1.1.6.2  yamt 	main();
    125  1.1.6.2  yamt }
    126  1.1.6.2  yamt 
    127  1.1.6.2  yamt int
    128  1.1.6.2  yamt main(void)
    129  1.1.6.2  yamt {
    130  1.1.6.2  yamt 	int currname = 0;
    131  1.1.6.2  yamt 	char *filename, filename_buffer[MAXLEN];
    132  1.1.6.2  yamt 
    133  1.1.6.2  yamt 	printf("\n");
    134  1.1.6.2  yamt 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
    135  1.1.6.2  yamt 	printf(">> Enter \"reset\" to reset system.\n");
    136  1.1.6.2  yamt 
    137  1.1.6.2  yamt 	for (;;) {
    138  1.1.6.2  yamt 		size_t size;
    139  1.1.6.2  yamt 
    140  1.1.6.2  yamt 		/* reset bootinfo structure */
    141  1.1.6.2  yamt 		bi_init();
    142  1.1.6.2  yamt 
    143  1.1.6.2  yamt 		name = names[currname++];
    144  1.1.6.2  yamt 		if (currname == NUMNAMES)
    145  1.1.6.2  yamt 			currname = 0;
    146  1.1.6.2  yamt 
    147  1.1.6.2  yamt 		if (!noconsole) {
    148  1.1.6.2  yamt 			howto = 0;
    149  1.1.6.2  yamt 			getbootdev(&howto);
    150  1.1.6.2  yamt 		} else
    151  1.1.6.2  yamt 			printf(": %s\n", name);
    152  1.1.6.2  yamt 		if (strchr(name, ':') != 0) {
    153  1.1.6.2  yamt 			filename = name;
    154  1.1.6.2  yamt 		} else {
    155  1.1.6.2  yamt 			strcpy(filename_buffer, devname_buffer);
    156  1.1.6.2  yamt 			strcat(filename_buffer, ":");
    157  1.1.6.2  yamt 			strcat(filename_buffer, name);
    158  1.1.6.2  yamt 			filename = filename_buffer;
    159  1.1.6.2  yamt 		}
    160  1.1.6.2  yamt 
    161  1.1.6.2  yamt 		size = sizeof(struct btinfo_common) + strlen(name) + 1;
    162  1.1.6.2  yamt 	        /* Impose limit (somewhat arbitrary) */
    163  1.1.6.2  yamt 		if (size < BOOTINFO_MAXSIZE / 2) {
    164  1.1.6.2  yamt 			union {
    165  1.1.6.2  yamt 				struct btinfo_kernelfile bi_file;
    166  1.1.6.2  yamt 				char x[size];
    167  1.1.6.2  yamt 			} U;
    168  1.1.6.2  yamt 			strcpy(U.bi_file.name, name);
    169  1.1.6.2  yamt 			BI_ADD(&U.bi_file, BTINFO_KERNELFILE, size);
    170  1.1.6.2  yamt 		}
    171  1.1.6.2  yamt 
    172  1.1.6.2  yamt 		exec_hppa(filename, 0, howto);
    173  1.1.6.2  yamt 		printf("boot: %s\n", strerror(errno));
    174  1.1.6.2  yamt 	}
    175  1.1.6.2  yamt }
    176  1.1.6.2  yamt 
    177  1.1.6.2  yamt void
    178  1.1.6.2  yamt getbootdev(int *boot_howto)
    179  1.1.6.2  yamt {
    180  1.1.6.2  yamt 	char c, *ptr = line;
    181  1.1.6.2  yamt 	int bdev, badapt, bctlr, bunit, bpart;
    182  1.1.6.2  yamt 
    183  1.1.6.2  yamt 	bdev   = B_TYPE(bootdev);
    184  1.1.6.2  yamt 	badapt = B_ADAPTOR(bootdev);
    185  1.1.6.2  yamt 	bctlr  = B_CONTROLLER(bootdev);
    186  1.1.6.2  yamt 	bunit  = B_UNIT(bootdev);
    187  1.1.6.2  yamt 	bpart  = B_PARTITION(bootdev);
    188  1.1.6.2  yamt 
    189  1.1.6.2  yamt 	printf("Boot: [[[%s%d%c:]%s][-a][-c][-d][-s][-v][-q]] :- ",
    190  1.1.6.2  yamt 	    devsw[bdev].dv_name, badapt << 8 | bctlr << 4 | bunit,
    191  1.1.6.2  yamt 	    'a' + bpart, name);
    192  1.1.6.2  yamt 
    193  1.1.6.2  yamt 	if (tgets(line)) {
    194  1.1.6.2  yamt 		if (strcmp(line, "reset") == 0) {
    195  1.1.6.2  yamt 			_rtt();
    196  1.1.6.2  yamt 			printf("panic: can't reboot\n");
    197  1.1.6.2  yamt 			return;
    198  1.1.6.2  yamt 		}
    199  1.1.6.2  yamt 		while ((c = *ptr) != '\0') {
    200  1.1.6.2  yamt 			while (c == ' ')
    201  1.1.6.2  yamt 				c = *++ptr;
    202  1.1.6.2  yamt 			if (!c)
    203  1.1.6.2  yamt 				return;
    204  1.1.6.2  yamt 			if (c == '-')
    205  1.1.6.2  yamt 				while ((c = *++ptr) && c != ' ')
    206  1.1.6.2  yamt 					BOOT_FLAG(c, *boot_howto);
    207  1.1.6.2  yamt 			else {
    208  1.1.6.2  yamt 				name = ptr;
    209  1.1.6.2  yamt 				while ((c = *++ptr) && c != ' ');
    210  1.1.6.2  yamt 				if (c)
    211  1.1.6.2  yamt 					*ptr++ = 0;
    212  1.1.6.2  yamt 			}
    213  1.1.6.2  yamt 		}
    214  1.1.6.2  yamt 	} else
    215  1.1.6.2  yamt 		printf("\n");
    216  1.1.6.2  yamt }
    217  1.1.6.2  yamt 
    218  1.1.6.2  yamt #define	round_to_size(x) \
    219  1.1.6.2  yamt 	(((x) + sizeof(u_long) - 1) & ~(sizeof(u_long) - 1))
    220  1.1.6.2  yamt 
    221  1.1.6.2  yamt void
    222  1.1.6.2  yamt exec_hppa(char *file, u_long loadaddr, int boot_howto)
    223  1.1.6.2  yamt {
    224  1.1.6.2  yamt #ifdef EXEC_DEBUG
    225  1.1.6.2  yamt 	extern int debug;
    226  1.1.6.2  yamt 	int i;
    227  1.1.6.2  yamt #endif
    228  1.1.6.2  yamt 	struct btinfo_symtab bi_syms;
    229  1.1.6.2  yamt 	u_long marks[MARK_MAX];
    230  1.1.6.2  yamt 	int fd;
    231  1.1.6.2  yamt 
    232  1.1.6.2  yamt 	marks[MARK_START] = loadaddr;
    233  1.1.6.2  yamt #ifdef EXEC_DEBUG
    234  1.1.6.2  yamt 	printf("file=%s loadaddr=%lx howto=%x\n",
    235  1.1.6.2  yamt 		file, loadaddr, boot_howto);
    236  1.1.6.2  yamt #endif
    237  1.1.6.2  yamt 	if ((fd = loadfile(file, marks, LOAD_KERNEL)) == -1)
    238  1.1.6.2  yamt 		return;
    239  1.1.6.2  yamt 
    240  1.1.6.2  yamt 	marks[MARK_END] = round_to_size(marks[MARK_END] - loadaddr);
    241  1.1.6.2  yamt 	printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n",
    242  1.1.6.2  yamt 	    marks[MARK_ENTRY], marks[MARK_NSYM],
    243  1.1.6.2  yamt 	    marks[MARK_SYM], marks[MARK_END]);
    244  1.1.6.2  yamt 
    245  1.1.6.2  yamt #ifdef EXEC_DEBUG
    246  1.1.6.2  yamt 	if (debug) {
    247  1.1.6.2  yamt 		printf("ep=0x%lx [", marks[MARK_ENTRY]);
    248  1.1.6.2  yamt 		for (i = 0; i < 10240; i++) {
    249  1.1.6.2  yamt 			if (!(i % 8)) {
    250  1.1.6.2  yamt 				printf("\b\n%p:", &((u_int *)marks[MARK_ENTRY])[i]);
    251  1.1.6.2  yamt 				if (getchar() != ' ')
    252  1.1.6.2  yamt 					break;
    253  1.1.6.2  yamt 			}
    254  1.1.6.2  yamt 			printf("%x,", ((int *)marks[MARK_ENTRY])[i]);
    255  1.1.6.2  yamt 		}
    256  1.1.6.2  yamt 		printf("\b\b ]\n");
    257  1.1.6.2  yamt 	}
    258  1.1.6.2  yamt #endif
    259  1.1.6.2  yamt 
    260  1.1.6.2  yamt 	bi_syms.nsym = marks[MARK_NSYM];
    261  1.1.6.2  yamt 	bi_syms.ssym = marks[MARK_SYM];
    262  1.1.6.2  yamt 	bi_syms.esym = marks[MARK_END];
    263  1.1.6.2  yamt 	BI_ADD(&bi_syms, BTINFO_SYMTAB, sizeof(bi_syms));
    264  1.1.6.2  yamt 
    265  1.1.6.2  yamt 	fcacheall();
    266  1.1.6.2  yamt 
    267  1.1.6.2  yamt 	__asm("mtctl %r0, %cr17");
    268  1.1.6.2  yamt 	__asm("mtctl %r0, %cr17");
    269  1.1.6.2  yamt 
    270  1.1.6.2  yamt 	/* stack and the gung is ok at this point, so, no need for asm setup */
    271  1.1.6.2  yamt 	(*(startfuncp)(marks[MARK_ENTRY])) ((int)pdc, boot_howto, bootdev,
    272  1.1.6.2  yamt 	     marks[MARK_END], BOOTARG_APIVER, &bootinfo);
    273  1.1.6.2  yamt 	/* not reached */
    274  1.1.6.2  yamt }
    275