boot.c revision 1.4.2.2 1 /* $NetBSD: boot.c,v 1.4.2.2 1997/09/06 18:00:04 thorpej 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
51 #include <machine/pte.h>
52
53 #include "common.h"
54
55 int loadfile __P((char *, u_int64_t *));
56
57 char boot_file[128];
58 char boot_flags[128];
59
60 struct bootinfo bootinfo;
61
62 extern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[];
63
64 vm_offset_t ffp_save, ptbr_save;
65
66 extern vm_offset_t ssym, esym;
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 main()
80 {
81 char *name, **namep;
82 u_int64_t entry;
83 int win;
84
85 /* Init prom callback vector. */
86 init_prom_calls();
87
88 /* print a banner */
89 printf("\n");
90 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
91 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
92 printf("\n");
93
94 /* switch to OSF pal code. */
95 OSFpal();
96
97 printf("\n");
98
99 prom_getenv(PROM_E_BOOTED_FILE, boot_file, sizeof(boot_file));
100 prom_getenv(PROM_E_BOOTED_OSFLAGS, boot_flags, sizeof(boot_flags));
101
102 if (boot_file[0] != 0)
103 (void)printf("Boot file: %s\n", boot_file);
104 (void)printf("Boot flags: %s\n", boot_flags);
105
106 if (boot_file[0] != '\0')
107 win = (loadfile(name = boot_file, &entry) == 0);
108 else
109 for (namep = kernelnames, win = 0; *namep != NULL && !win;
110 namep++)
111 win = (loadfile(name = *namep, &entry) == 0);
112
113 printf("\n");
114 if (win) {
115 /*
116 * Fill in the bootinfo for the kernel.
117 */
118 bzero(&bootinfo, sizeof(bootinfo));
119 bootinfo.version = 1;
120 bootinfo.un.v1.ssym = ssym;
121 bootinfo.un.v1.esym = esym;
122 bcopy(name, bootinfo.un.v1.booted_kernel,
123 sizeof(bootinfo.un.v1.booted_kernel));
124 bcopy(boot_flags, bootinfo.un.v1.boot_flags,
125 sizeof(bootinfo.un.v1.boot_flags));
126 bootinfo.un.v1.hwrpb = NULL;
127 bootinfo.un.v1.hwrpbsize = 0;
128 bootinfo.un.v1.cngetc = NULL;
129 bootinfo.un.v1.cnputc = NULL;
130 bootinfo.un.v1.cnpollc = NULL;
131
132 (void)printf("Entering %s at 0x%lx...\n", name, entry);
133 (*(void (*)())entry)(ffp_save, ptbr_save,
134 BOOTINFO_MAGIC, &bootinfo, 0);
135 }
136
137 (void)printf("Boot failed! Halting...\n");
138 halt();
139 }
140