main.c revision 1.4.4.2 1 1.4.4.2 nathanw /* $NetBSD: main.c,v 1.4.4.2 2002/02/28 04:10:30 nathanw Exp $ */
2 1.4.4.2 nathanw
3 1.4.4.2 nathanw /*
4 1.4.4.2 nathanw * Copyright (c) 1996
5 1.4.4.2 nathanw * Matthias Drochner. All rights reserved.
6 1.4.4.2 nathanw * Copyright (c) 1996
7 1.4.4.2 nathanw * Perry E. Metzger. All rights reserved.
8 1.4.4.2 nathanw *
9 1.4.4.2 nathanw * Redistribution and use in source and binary forms, with or without
10 1.4.4.2 nathanw * modification, are permitted provided that the following conditions
11 1.4.4.2 nathanw * are met:
12 1.4.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
13 1.4.4.2 nathanw * notice, this list of conditions and the following disclaimer.
14 1.4.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
15 1.4.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
16 1.4.4.2 nathanw * documentation and/or other materials provided with the distribution.
17 1.4.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
18 1.4.4.2 nathanw * must display the following acknowledgements:
19 1.4.4.2 nathanw * This product includes software developed for the NetBSD Project
20 1.4.4.2 nathanw * by Matthias Drochner.
21 1.4.4.2 nathanw * This product includes software developed for the NetBSD Project
22 1.4.4.2 nathanw * by Perry E. Metzger.
23 1.4.4.2 nathanw * 4. The names of the authors may not be used to endorse or promote products
24 1.4.4.2 nathanw * derived from this software without specific prior written permission.
25 1.4.4.2 nathanw *
26 1.4.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 1.4.4.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 1.4.4.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 1.4.4.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 1.4.4.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 1.4.4.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 1.4.4.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 1.4.4.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 1.4.4.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 1.4.4.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 1.4.4.2 nathanw *
37 1.4.4.2 nathanw */
38 1.4.4.2 nathanw
39 1.4.4.2 nathanw #include <lib/libkern/libkern.h>
40 1.4.4.2 nathanw
41 1.4.4.2 nathanw #include <lib/libsa/stand.h>
42 1.4.4.2 nathanw
43 1.4.4.2 nathanw #include <libi386.h>
44 1.4.4.2 nathanw #include "pxeboot.h"
45 1.4.4.2 nathanw
46 1.4.4.2 nathanw int errno;
47 1.4.4.2 nathanw int debug;
48 1.4.4.2 nathanw int try_bootp = 1;
49 1.4.4.2 nathanw
50 1.4.4.2 nathanw extern char bootprog_name[], bootprog_rev[], bootprog_date[],
51 1.4.4.2 nathanw bootprog_maker[];
52 1.4.4.2 nathanw
53 1.4.4.2 nathanw #define TIMEOUT 5
54 1.4.4.2 nathanw
55 1.4.4.2 nathanw int main(void);
56 1.4.4.2 nathanw
57 1.4.4.2 nathanw void command_help __P((char *));
58 1.4.4.2 nathanw void command_quit __P((char *));
59 1.4.4.2 nathanw void command_boot __P((char *));
60 1.4.4.2 nathanw
61 1.4.4.2 nathanw const struct bootblk_command commands[] = {
62 1.4.4.2 nathanw { "help", command_help },
63 1.4.4.2 nathanw { "?", command_help },
64 1.4.4.2 nathanw { "quit", command_quit },
65 1.4.4.2 nathanw { "boot", command_boot },
66 1.4.4.2 nathanw { NULL, NULL },
67 1.4.4.2 nathanw };
68 1.4.4.2 nathanw
69 1.4.4.2 nathanw #ifdef COMPAT_OLDBOOT
70 1.4.4.2 nathanw int
71 1.4.4.2 nathanw parsebootfile(const char *fname, char **fsname, char **devname,
72 1.4.4.2 nathanw u_int *unit, u_int *partition, const char **file)
73 1.4.4.2 nathanw {
74 1.4.4.2 nathanw return (EINVAL);
75 1.4.4.2 nathanw }
76 1.4.4.2 nathanw
77 1.4.4.2 nathanw int
78 1.4.4.2 nathanw biosdisk_gettype(struct open_file *f)
79 1.4.4.2 nathanw {
80 1.4.4.2 nathanw return (0);
81 1.4.4.2 nathanw }
82 1.4.4.2 nathanw #endif
83 1.4.4.2 nathanw
84 1.4.4.2 nathanw static int
85 1.4.4.2 nathanw bootit(const char *filename, int howto)
86 1.4.4.2 nathanw {
87 1.4.4.2 nathanw if (exec_netbsd(filename, 0, howto) < 0)
88 1.4.4.2 nathanw printf("boot: %s\n", strerror(errno));
89 1.4.4.2 nathanw else
90 1.4.4.2 nathanw printf("boot returned\n");
91 1.4.4.2 nathanw return (-1);
92 1.4.4.2 nathanw }
93 1.4.4.2 nathanw
94 1.4.4.2 nathanw static void
95 1.4.4.2 nathanw print_banner(void)
96 1.4.4.2 nathanw {
97 1.4.4.2 nathanw int base = getbasemem();
98 1.4.4.2 nathanw int ext = getextmem();
99 1.4.4.2 nathanw
100 1.4.4.2 nathanw printf("\n"
101 1.4.4.2 nathanw ">> %s, Revision %s\n"
102 1.4.4.2 nathanw ">> (%s, %s)\n"
103 1.4.4.2 nathanw ">> Memory: %d/%d k\n",
104 1.4.4.2 nathanw bootprog_name, bootprog_rev,
105 1.4.4.2 nathanw bootprog_maker, bootprog_date,
106 1.4.4.2 nathanw base, ext);
107 1.4.4.2 nathanw }
108 1.4.4.2 nathanw
109 1.4.4.2 nathanw int
110 1.4.4.2 nathanw main(void)
111 1.4.4.2 nathanw {
112 1.4.4.2 nathanw char c;
113 1.4.4.2 nathanw
114 1.4.4.2 nathanw #ifdef SUPPORT_SERIAL
115 1.4.4.2 nathanw initio(SUPPORT_SERIAL);
116 1.4.4.2 nathanw #else
117 1.4.4.2 nathanw initio(CONSDEV_PC);
118 1.4.4.2 nathanw #endif
119 1.4.4.2 nathanw gateA20();
120 1.4.4.2 nathanw
121 1.4.4.2 nathanw print_banner();
122 1.4.4.2 nathanw
123 1.4.4.2 nathanw printf("Press return to boot now, any other key for boot menu\n");
124 1.4.4.2 nathanw printf("Starting in ");
125 1.4.4.2 nathanw
126 1.4.4.2 nathanw c = awaitkey(TIMEOUT, 1);
127 1.4.4.2 nathanw if ((c != '\r') && (c != '\n') && (c != '\0')) {
128 1.4.4.2 nathanw printf("type \"?\" or \"help\" for help.\n");
129 1.4.4.2 nathanw bootmenu(); /* does not return */
130 1.4.4.2 nathanw }
131 1.4.4.2 nathanw
132 1.4.4.2 nathanw /*
133 1.4.4.2 nathanw * The file name provided here is just a default. If the
134 1.4.4.2 nathanw * DHCP server provides a file name, we'll use that instead.
135 1.4.4.2 nathanw */
136 1.4.4.2 nathanw bootit("netbsd", 0);
137 1.4.4.2 nathanw
138 1.4.4.2 nathanw /*
139 1.4.4.2 nathanw * If that fails, let the BIOS try the next boot device.
140 1.4.4.2 nathanw */
141 1.4.4.2 nathanw return (1);
142 1.4.4.2 nathanw }
143 1.4.4.2 nathanw
144 1.4.4.2 nathanw /* ARGSUSED */
145 1.4.4.2 nathanw void
146 1.4.4.2 nathanw command_help(char *arg)
147 1.4.4.2 nathanw {
148 1.4.4.2 nathanw printf("commands are:\n"
149 1.4.4.2 nathanw "boot [filename] [-adsqv]\n"
150 1.4.4.2 nathanw " (ex. \"netbsd.old -s\"\n"
151 1.4.4.2 nathanw "help|?\n"
152 1.4.4.2 nathanw "quit\n");
153 1.4.4.2 nathanw }
154 1.4.4.2 nathanw
155 1.4.4.2 nathanw /* ARGSUSED */
156 1.4.4.2 nathanw void
157 1.4.4.2 nathanw command_quit(char *arg)
158 1.4.4.2 nathanw {
159 1.4.4.2 nathanw printf("Exiting... goodbye...\n");
160 1.4.4.2 nathanw exit(0);
161 1.4.4.2 nathanw }
162 1.4.4.2 nathanw
163 1.4.4.2 nathanw void
164 1.4.4.2 nathanw command_boot(char *arg)
165 1.4.4.2 nathanw {
166 1.4.4.2 nathanw char *filename;
167 1.4.4.2 nathanw int howto;
168 1.4.4.2 nathanw
169 1.4.4.2 nathanw if (parseboot(arg, &filename, &howto))
170 1.4.4.2 nathanw bootit(filename, howto);
171 1.4.4.2 nathanw }
172