Home | History | Annotate | Line # | Download | only in common
boot.c revision 1.20.2.2
      1  1.20.2.2  cgd /* $NetBSD: boot.c,v 1.20.2.2 1999/04/05 22:03:57 cgd Exp $ */
      2  1.20.2.2  cgd 
      3  1.20.2.2  cgd /*
      4  1.20.2.2  cgd  * Copyright (c) 1992, 1993
      5  1.20.2.2  cgd  *	The Regents of the University of California.  All rights reserved.
      6  1.20.2.2  cgd  *
      7  1.20.2.2  cgd  * This code is derived from software contributed to Berkeley by
      8  1.20.2.2  cgd  * Ralph Campbell.
      9  1.20.2.2  cgd  *
     10  1.20.2.2  cgd  * Redistribution and use in source and binary forms, with or without
     11  1.20.2.2  cgd  * modification, are permitted provided that the following conditions
     12  1.20.2.2  cgd  * are met:
     13  1.20.2.2  cgd  * 1. Redistributions of source code must retain the above copyright
     14  1.20.2.2  cgd  *    notice, this list of conditions and the following disclaimer.
     15  1.20.2.2  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.20.2.2  cgd  *    notice, this list of conditions and the following disclaimer in the
     17  1.20.2.2  cgd  *    documentation and/or other materials provided with the distribution.
     18  1.20.2.2  cgd  * 3. All advertising materials mentioning features or use of this software
     19  1.20.2.2  cgd  *    must display the following acknowledgement:
     20  1.20.2.2  cgd  *	This product includes software developed by the University of
     21  1.20.2.2  cgd  *	California, Berkeley and its contributors.
     22  1.20.2.2  cgd  * 4. Neither the name of the University nor the names of its contributors
     23  1.20.2.2  cgd  *    may be used to endorse or promote products derived from this software
     24  1.20.2.2  cgd  *    without specific prior written permission.
     25  1.20.2.2  cgd  *
     26  1.20.2.2  cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.20.2.2  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.20.2.2  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.20.2.2  cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.20.2.2  cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.20.2.2  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.20.2.2  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.20.2.2  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.20.2.2  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.20.2.2  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.20.2.2  cgd  * SUCH DAMAGE.
     37  1.20.2.2  cgd  *
     38  1.20.2.2  cgd  *	@(#)boot.c	8.1 (Berkeley) 6/10/93
     39  1.20.2.2  cgd  */
     40  1.20.2.2  cgd 
     41  1.20.2.2  cgd #include <lib/libsa/stand.h>
     42  1.20.2.2  cgd #include <lib/libkern/libkern.h>
     43  1.20.2.2  cgd 
     44  1.20.2.2  cgd #include <sys/param.h>
     45  1.20.2.2  cgd #include <sys/exec.h>
     46  1.20.2.2  cgd #include <sys/exec_ecoff.h>
     47  1.20.2.2  cgd 
     48  1.20.2.2  cgd #include <machine/autoconf.h>
     49  1.20.2.2  cgd #include <machine/prom.h>
     50  1.20.2.2  cgd #include <machine/rpb.h>
     51  1.20.2.2  cgd 
     52  1.20.2.2  cgd #include <machine/pte.h>
     53  1.20.2.2  cgd 
     54  1.20.2.2  cgd #include "common.h"
     55  1.20.2.2  cgd 
     56  1.20.2.2  cgd #if !defined(UNIFIED_BOOTBLOCK) && !defined(SECONDARY_BOOTBLOCK)
     57  1.20.2.2  cgd #error not UNIFIED_BOOTBLOCK and not SECONDARY_BOOTBLOCK
     58  1.20.2.2  cgd #endif
     59  1.20.2.2  cgd 
     60  1.20.2.2  cgd int loadfile __P((char *, u_int64_t *));
     61  1.20.2.2  cgd 
     62  1.20.2.2  cgd char boot_file[128];
     63  1.20.2.2  cgd char boot_flags[128];
     64  1.20.2.2  cgd 
     65  1.20.2.2  cgd struct bootinfo_v1 bootinfo_v1;
     66  1.20.2.2  cgd 
     67  1.20.2.2  cgd extern char bootprog_rev[], bootprog_date[], bootprog_maker[];
     68  1.20.2.2  cgd 
     69  1.20.2.2  cgd paddr_t ffp_save, ptbr_save;
     70  1.20.2.2  cgd 
     71  1.20.2.2  cgd extern vaddr_t ssym, esym;
     72  1.20.2.2  cgd 
     73  1.20.2.2  cgd int debug;
     74  1.20.2.2  cgd 
     75  1.20.2.2  cgd char *kernelnames[] = {
     76  1.20.2.2  cgd 	"netbsd",		"netbsd.gz",
     77  1.20.2.2  cgd 	"netbsd.bak",		"netbsd.bak.gz",
     78  1.20.2.2  cgd 	"netbsd.old",		"netbsd.old.gz",
     79  1.20.2.2  cgd 	"onetbsd",		"onetbsd.gz",
     80  1.20.2.2  cgd 	NULL
     81  1.20.2.2  cgd };
     82  1.20.2.2  cgd 
     83  1.20.2.2  cgd void
     84  1.20.2.2  cgd #if defined(UNIFIED_BOOTBLOCK)
     85  1.20.2.2  cgd main(void)
     86  1.20.2.2  cgd #else /* defined(SECONDARY_BOOTBLOCK) */
     87  1.20.2.2  cgd main(long fd)
     88  1.20.2.2  cgd #endif
     89  1.20.2.2  cgd {
     90  1.20.2.2  cgd 	char *name, **namep;
     91  1.20.2.2  cgd 	u_int64_t entry;
     92  1.20.2.2  cgd 	int win;
     93  1.20.2.2  cgd 
     94  1.20.2.2  cgd 	/* Init prom callback vector. */
     95  1.20.2.2  cgd 	init_prom_calls();
     96  1.20.2.2  cgd 
     97  1.20.2.2  cgd 	/* print a banner */
     98  1.20.2.2  cgd 	printf("\n");
     99  1.20.2.2  cgd 	printf("NetBSD/alpha " NETBSD_VERS " " BOOT_TYPE_NAME " Bootstrap, Revision %s\n",
    100  1.20.2.2  cgd 	    bootprog_rev);
    101  1.20.2.2  cgd 	printf("(%s, %s)\n", bootprog_maker, bootprog_date);
    102  1.20.2.2  cgd 	printf("\n");
    103  1.20.2.2  cgd 
    104  1.20.2.2  cgd 	/* set up the booted device descriptor */
    105  1.20.2.2  cgd #if defined(UNIFIED_BOOTBLOCK)
    106  1.20.2.2  cgd         if (!booted_dev_open()) {
    107  1.20.2.2  cgd                 printf("Boot device (%s) open failed.\n",
    108  1.20.2.2  cgd 		    booted_dev_name[0] ? booted_dev_name : "unknown");
    109  1.20.2.2  cgd                 goto fail;
    110  1.20.2.2  cgd         }
    111  1.20.2.2  cgd #else /* defined(SECONDARY_BOOTBLOCK) */
    112  1.20.2.2  cgd 	booted_dev_setfd(fd);
    113  1.20.2.2  cgd #endif
    114  1.20.2.2  cgd 
    115  1.20.2.2  cgd 	/* switch to OSF pal code. */
    116  1.20.2.2  cgd 	OSFpal();
    117  1.20.2.2  cgd 
    118  1.20.2.2  cgd 	printf("\n");
    119  1.20.2.2  cgd 
    120  1.20.2.2  cgd 	prom_getenv(PROM_E_BOOTED_FILE, boot_file, sizeof(boot_file));
    121  1.20.2.2  cgd 	prom_getenv(PROM_E_BOOTED_OSFLAGS, boot_flags, sizeof(boot_flags));
    122  1.20.2.2  cgd 
    123  1.20.2.2  cgd 	if (boot_file[0] != 0)
    124  1.20.2.2  cgd 		(void)printf("Boot file: %s\n", boot_file);
    125  1.20.2.2  cgd 	(void)printf("Boot flags: %s\n", boot_flags);
    126  1.20.2.2  cgd 
    127  1.20.2.2  cgd 	if (strchr(boot_flags, 'i') || strchr(boot_flags, 'I')) {
    128  1.20.2.2  cgd 		printf("Boot file: ");
    129  1.20.2.2  cgd 		gets(boot_file);
    130  1.20.2.2  cgd 	}
    131  1.20.2.2  cgd 
    132  1.20.2.2  cgd 	if (boot_file[0] != '\0')
    133  1.20.2.2  cgd 		win = (loadfile(name = boot_file, &entry) == 0);
    134  1.20.2.2  cgd 	else
    135  1.20.2.2  cgd 		for (namep = kernelnames, win = 0; *namep != NULL && !win;
    136  1.20.2.2  cgd 		    namep++)
    137  1.20.2.2  cgd 			win = (loadfile(name = *namep, &entry) == 0);
    138  1.20.2.2  cgd 
    139  1.20.2.2  cgd 	booted_dev_close();
    140  1.20.2.2  cgd 	printf("\n");
    141  1.20.2.2  cgd 	if (!win) {
    142  1.20.2.2  cgd 		goto fail;
    143  1.20.2.2  cgd 	}
    144  1.20.2.2  cgd 
    145  1.20.2.2  cgd 	/*
    146  1.20.2.2  cgd 	 * Fill in the bootinfo for the kernel.
    147  1.20.2.2  cgd 	 */
    148  1.20.2.2  cgd 	bzero(&bootinfo_v1, sizeof(bootinfo_v1));
    149  1.20.2.2  cgd 	bootinfo_v1.ssym = ssym;
    150  1.20.2.2  cgd 	bootinfo_v1.esym = esym;
    151  1.20.2.2  cgd 	bcopy(name, bootinfo_v1.booted_kernel,
    152  1.20.2.2  cgd 	    sizeof(bootinfo_v1.booted_kernel));
    153  1.20.2.2  cgd 	bcopy(boot_flags, bootinfo_v1.boot_flags,
    154  1.20.2.2  cgd 	    sizeof(bootinfo_v1.boot_flags));
    155  1.20.2.2  cgd 	bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
    156  1.20.2.2  cgd 	bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
    157  1.20.2.2  cgd 	bootinfo_v1.cngetc = NULL;
    158  1.20.2.2  cgd 	bootinfo_v1.cnputc = NULL;
    159  1.20.2.2  cgd 	bootinfo_v1.cnpollc = NULL;
    160  1.20.2.2  cgd 
    161  1.20.2.2  cgd 	(void)printf("Entering %s at 0x%lx...\n", name, entry);
    162  1.20.2.2  cgd 	alpha_pal_imb();
    163  1.20.2.2  cgd 	(*(void (*)(u_int64_t, u_int64_t, u_int64_t, void *, u_int64_t,
    164  1.20.2.2  cgd 	    u_int64_t))entry)(ffp_save, ptbr_save, BOOTINFO_MAGIC,
    165  1.20.2.2  cgd 	    &bootinfo_v1, 1, 0);
    166  1.20.2.2  cgd 
    167  1.20.2.2  cgd 	(void)printf("KERNEL RETURNED!\n");
    168  1.20.2.2  cgd 
    169  1.20.2.2  cgd fail:
    170  1.20.2.2  cgd 	(void)printf("Boot failed!  Halting...\n");
    171  1.20.2.2  cgd 	halt();
    172  1.20.2.2  cgd }
    173