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