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