xref: /netbsd-src/sys/arch/alpha/stand/common/boot.c (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /* $NetBSD: boot.c,v 1.30 2009/02/03 12:49:00 tsutsui 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. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	@(#)boot.c	8.1 (Berkeley) 6/10/93
35  */
36 
37 #include <lib/libsa/stand.h>
38 #include <lib/libkern/libkern.h>
39 #include <lib/libsa/loadfile.h>
40 
41 #include <sys/param.h>
42 #include <sys/exec.h>
43 #include <sys/exec_ecoff.h>
44 
45 #include <machine/autoconf.h>
46 #include <machine/prom.h>
47 #include <machine/rpb.h>
48 
49 #include <machine/pte.h>
50 
51 #include "common.h"
52 
53 #if !defined(UNIFIED_BOOTBLOCK) && !defined(SECONDARY_BOOTBLOCK)
54 #error not UNIFIED_BOOTBLOCK and not SECONDARY_BOOTBLOCK
55 #endif
56 
57 char boot_file[128];
58 char boot_flags[128];
59 
60 struct bootinfo_v1 bootinfo_v1;
61 
62 paddr_t ffp_save, ptbr_save;
63 
64 int debug;
65 
66 char *kernelnames[] = {
67 	"netbsd",		"netbsd.gz",
68 	"netbsd.bak",		"netbsd.bak.gz",
69 	"netbsd.old",		"netbsd.old.gz",
70 	"onetbsd",		"onetbsd.gz",
71 	"netbsd.alpha",		"netbsd.alpha.gz",
72 	NULL
73 };
74 
75 void
76 #if defined(UNIFIED_BOOTBLOCK)
77 main(void)
78 #else /* defined(SECONDARY_BOOTBLOCK) */
79 main(long fd)
80 #endif
81 {
82 	char *name, **namep;
83 	u_long marks[MARK_MAX];
84 	u_int64_t entry;
85 	int win, loadflag;
86 
87 	/* Init prom callback vector. */
88 	init_prom_calls();
89 
90 	/* print a banner */
91 	printf("\n");
92 	printf("NetBSD/alpha " NETBSD_VERS " " BOOT_TYPE_NAME " Bootstrap, Revision %s\n",
93 	    bootprog_rev);
94 	printf("(%s, %s)\n", bootprog_maker, bootprog_date);
95 	printf("\n");
96 
97 	/* set up the booted device descriptor */
98 #if defined(UNIFIED_BOOTBLOCK)
99         if (!booted_dev_open()) {
100                 printf("Boot device (%s) open failed.\n",
101 		    booted_dev_name[0] ? booted_dev_name : "unknown");
102                 goto fail;
103         }
104 #else /* defined(SECONDARY_BOOTBLOCK) */
105 	booted_dev_setfd(fd);
106 #endif
107 
108 	/* switch to OSF pal code. */
109 	OSFpal();
110 
111 	printf("\n");
112 
113 	prom_getenv(PROM_E_BOOTED_FILE, boot_file, sizeof(boot_file));
114 	prom_getenv(PROM_E_BOOTED_OSFLAGS, boot_flags, sizeof(boot_flags));
115 
116 	if (boot_file[0] != 0)
117 		(void)printf("Boot file: %s\n", boot_file);
118 	(void)printf("Boot flags: %s\n", boot_flags);
119 
120 	if (strchr(boot_flags, 'i') || strchr(boot_flags, 'I')) {
121 		printf("Boot file: ");
122 		gets(boot_file);
123 	}
124 
125 #ifdef NO_LOAD_NOTE
126 	loadflag = LOAD_KERNEL & ~LOAD_NOTE;
127 #else
128 	loadflag = LOAD_KERNEL;
129 #endif
130 
131 	memset(marks, 0, sizeof marks);
132 	if (boot_file[0] != '\0') {
133 		name = boot_file;
134 		win = loadfile(name, marks, loadflag) == 0;
135 	} else {
136 		name = NULL;	/* XXX gcc -Wuninitialized */
137 		for (namep = kernelnames, win = 0; *namep != NULL && !win;
138 		    namep++) {
139 			name = *namep;
140 			win = loadfile(name, marks, loadflag) == 0;
141 		}
142 	}
143 
144 	entry = marks[MARK_ENTRY];
145 	booted_dev_close();
146 	printf("\n");
147 	if (!win)
148 		goto fail;
149 
150 	/*
151 	 * Fill in the bootinfo for the kernel.
152 	 */
153 	memset(&bootinfo_v1, 0, sizeof(bootinfo_v1));
154 	bootinfo_v1.ssym = marks[MARK_SYM];
155 	bootinfo_v1.esym = marks[MARK_END];
156 	memcpy(bootinfo_v1.booted_kernel, name,
157 	    sizeof(bootinfo_v1.booted_kernel));
158 	memcpy(bootinfo_v1.boot_flags, boot_flags,
159 	    sizeof(bootinfo_v1.boot_flags));
160 	bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
161 	bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
162 	bootinfo_v1.cngetc = NULL;
163 	bootinfo_v1.cnputc = NULL;
164 	bootinfo_v1.cnpollc = NULL;
165 
166 	(void)printf("Entering %s at 0x%lx...\n", name, entry);
167 	alpha_pal_imb();
168 	(*(void (*)(u_int64_t, u_int64_t, u_int64_t, void *, u_int64_t,
169 	    u_int64_t))entry)(ffp_save, ptbr_save, BOOTINFO_MAGIC,
170 	    &bootinfo_v1, 1, 0);
171 
172 	(void)printf("KERNEL RETURNED!\n");
173 
174 fail:
175 	(void)printf("Boot failed!  Halting...\n");
176 	halt();
177 }
178