Home | History | Annotate | Line # | Download | only in common
boot.c revision 1.22.8.1
      1 /* $NetBSD: boot.c,v 1.22.8.1 1999/12/27 18:31:29 wrstuden 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 #include <lib/libsa/loadfile.h>
     44 
     45 #include <sys/param.h>
     46 #include <sys/exec.h>
     47 #include <sys/exec_ecoff.h>
     48 
     49 #include <machine/autoconf.h>
     50 #include <machine/prom.h>
     51 #include <machine/rpb.h>
     52 
     53 #include <machine/pte.h>
     54 
     55 #include "common.h"
     56 
     57 #if !defined(UNIFIED_BOOTBLOCK) && !defined(SECONDARY_BOOTBLOCK)
     58 #error not UNIFIED_BOOTBLOCK and not SECONDARY_BOOTBLOCK
     59 #endif
     60 
     61 char boot_file[128];
     62 char boot_flags[128];
     63 
     64 struct bootinfo_v1 bootinfo_v1;
     65 
     66 paddr_t ffp_save, ptbr_save;
     67 
     68 int debug;
     69 
     70 char *kernelnames[] = {
     71 	"netbsd",		"netbsd.gz",
     72 	"netbsd.bak",		"netbsd.bak.gz",
     73 	"netbsd.old",		"netbsd.old.gz",
     74 	"onetbsd",		"onetbsd.gz",
     75 	NULL
     76 };
     77 
     78 void
     79 #if defined(UNIFIED_BOOTBLOCK)
     80 main(void)
     81 #else /* defined(SECONDARY_BOOTBLOCK) */
     82 main(long fd)
     83 #endif
     84 {
     85 	char *name, **namep;
     86 	u_long marks[MARK_MAX];
     87 	u_int64_t entry;
     88 	int win;
     89 
     90 	/* Init prom callback vector. */
     91 	init_prom_calls();
     92 
     93 	/* print a banner */
     94 	printf("\n");
     95 	printf("NetBSD/alpha " NETBSD_VERS " " BOOT_TYPE_NAME " Bootstrap, Revision %s\n",
     96 	    bootprog_rev);
     97 	printf("(%s, %s)\n", bootprog_maker, bootprog_date);
     98 	printf("\n");
     99 
    100 	/* set up the booted device descriptor */
    101 #if defined(UNIFIED_BOOTBLOCK)
    102         if (!booted_dev_open()) {
    103                 printf("Boot device (%s) open failed.\n",
    104 		    booted_dev_name[0] ? booted_dev_name : "unknown");
    105                 goto fail;
    106         }
    107 #else /* defined(SECONDARY_BOOTBLOCK) */
    108 	booted_dev_setfd(fd);
    109 #endif
    110 
    111 	/* switch to OSF pal code. */
    112 	OSFpal();
    113 
    114 	printf("\n");
    115 
    116 	prom_getenv(PROM_E_BOOTED_FILE, boot_file, sizeof(boot_file));
    117 	prom_getenv(PROM_E_BOOTED_OSFLAGS, boot_flags, sizeof(boot_flags));
    118 
    119 	if (boot_file[0] != 0)
    120 		(void)printf("Boot file: %s\n", boot_file);
    121 	(void)printf("Boot flags: %s\n", boot_flags);
    122 
    123 	if (strchr(boot_flags, 'i') || strchr(boot_flags, 'I')) {
    124 		printf("Boot file: ");
    125 		gets(boot_file);
    126 	}
    127 
    128 	memset(marks, 0, sizeof marks);
    129 	if (boot_file[0] != '\0')
    130 		win = loadfile(name = boot_file, marks, LOAD_KERNEL) == 0;
    131 	else
    132 		for (namep = kernelnames, win = 0; *namep != NULL && !win;
    133 		    namep++)
    134 			win = loadfile(name = *namep, marks, LOAD_KERNEL) == 0;
    135 
    136 	entry = marks[MARK_ENTRY];
    137 	booted_dev_close();
    138 	printf("\n");
    139 	if (!win)
    140 		goto fail;
    141 
    142 	/*
    143 	 * Fill in the bootinfo for the kernel.
    144 	 */
    145 	bzero(&bootinfo_v1, sizeof(bootinfo_v1));
    146 	bootinfo_v1.ssym = marks[MARK_SYM];
    147 	bootinfo_v1.esym = marks[MARK_END];
    148 	bcopy(name, bootinfo_v1.booted_kernel,
    149 	    sizeof(bootinfo_v1.booted_kernel));
    150 	bcopy(boot_flags, bootinfo_v1.boot_flags,
    151 	    sizeof(bootinfo_v1.boot_flags));
    152 	bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
    153 	bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
    154 	bootinfo_v1.cngetc = NULL;
    155 	bootinfo_v1.cnputc = NULL;
    156 	bootinfo_v1.cnpollc = NULL;
    157 
    158 	(void)printf("Entering %s at 0x%lx...\n", name, entry);
    159 	alpha_pal_imb();
    160 	(*(void (*)(u_int64_t, u_int64_t, u_int64_t, void *, u_int64_t,
    161 	    u_int64_t))entry)(ffp_save, ptbr_save, BOOTINFO_MAGIC,
    162 	    &bootinfo_v1, 1, 0);
    163 
    164 	(void)printf("KERNEL RETURNED!\n");
    165 
    166 fail:
    167 	(void)printf("Boot failed!  Halting...\n");
    168 	halt();
    169 }
    170