1 /* $NetBSD: main.c,v 1.21 2009/09/14 11:56:27 jmcneill Exp $ */
5 * Matthias Drochner. All rights reserved.
7 * Perry E. Metzger. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
39 #include <sys/types.h>
40 #include <sys/reboot.h>
41 #include <sys/bootblock.h>
43 #include <lib/libkern/libkern.h>
45 #include <lib/libsa/stand.h>
53 extern struct x86_boot_params boot_params
;
58 extern char bootprog_name
[], bootprog_rev
[], bootprog_kernrev
[];
62 void command_help(char *);
63 void command_quit(char *);
64 void command_boot(char *);
65 void command_consdev(char *);
66 void command_modules(char *);
68 const struct bootblk_command commands
[] = {
69 { "help", command_help
},
70 { "?", command_help
},
71 { "quit", command_quit
},
72 { "boot", command_boot
},
73 { "consdev", command_consdev
},
74 { "modules", command_modules
},
75 { "load", module_add
},
76 { "vesa", command_vesa
},
96 bootit(const char *filename
, int howto
)
98 if (exec_netbsd(filename
, 0, howto
, 0, alldone
) < 0)
99 printf("boot: %s\n", strerror(errno
));
101 printf("boot returned\n");
108 int base
= getbasemem();
109 int ext
= getextmem();
113 ">> NetBSD/x86 PXE boot, Revision %s (from NetBSD %s)\n"
114 ">> Memory: %d/%d k\n",
115 bootprog_rev
, bootprog_kernrev
,
122 extern char twiddle_toggle
;
125 twiddle_toggle
= 1; /* no twiddling until we're ready */
127 #ifdef SUPPORT_SERIAL
128 initio(SUPPORT_SERIAL
);
135 parsebootconf(BOOTCONF
);
138 * If console set in boot.cfg, switch to it.
139 * This will print the banner, so we don't need to explicitly do it
141 if (bootconf
.consdev
)
142 command_consdev(bootconf
.consdev
);
146 /* Display the menu, if applicable */
148 if (bootconf
.nummenu
> 0) {
149 /* Does not return */
157 printf("Press return to boot now, any other key for boot menu\n");
158 printf("booting netbsd - starting in ");
161 c
= awaitkey(boot_params
.bp_timeout
, 1);
163 c
= awaitkey((bootconf
.timeout
< 0) ? 0 : bootconf
.timeout
, 1);
165 if ((c
!= '\r') && (c
!= '\n') && (c
!= '\0') &&
166 ((boot_params
.bp_flags
& X86_BP_FLAGS_PASSWORD
) == 0
167 || check_password((char *)boot_params
.bp_password
))) {
168 printf("type \"?\" or \"help\" for help.\n");
169 bootmenu(); /* does not return */
173 * The file name provided here is just a default. If the
174 * DHCP server provides a file name, we'll use that instead.
179 * If that fails, let the BIOS try the next boot device.
186 command_help(char *arg
)
188 printf("commands are:\n"
189 "boot [filename] [-adsqv]\n"
190 " (ex. \"netbsd.old -s\"\n"
191 "consdev {pc|com[0123]|com[0123]kbd|auto}\n"
192 "vesa {enabled|disabled|list|modenum}\n"
193 "modules {enabled|disabled}\n"
194 "load {path_to_module}\n"
201 command_quit(char *arg
)
204 printf("Exiting...\n");
207 /* Note: we shouldn't get to this point! */
208 panic("Could not reboot!");
213 command_boot(char *arg
)
218 if (parseboot(arg
, &filename
, &howto
))
219 bootit(filename
, howto
);
222 static const struct cons_devs
{
226 { "pc", CONSDEV_PC
},
227 { "com0", CONSDEV_COM0
},
228 { "com1", CONSDEV_COM1
},
229 { "com2", CONSDEV_COM2
},
230 { "com3", CONSDEV_COM3
},
231 { "com0kbd", CONSDEV_COM0KBD
},
232 { "com1kbd", CONSDEV_COM1KBD
},
233 { "com2kbd", CONSDEV_COM2KBD
},
234 { "com3kbd", CONSDEV_COM3KBD
},
235 { "auto", CONSDEV_AUTO
},
239 command_consdev(char *arg
)
241 const struct cons_devs
*cdp
;
243 for (cdp
= cons_devs
; cdp
->name
; cdp
++) {
244 if (!strcmp(arg
, cdp
->name
)) {
250 printf("invalid console device.\n");
253 command_modules(char *arg
)
255 if (strcmp(arg
, "enabled") == 0 ||
256 strcmp(arg
, "on") == 0)
257 boot_modules_enabled
= true;
258 else if (strcmp(arg
, "disabled") == 0 ||
259 strcmp(arg
, "off") == 0)
260 boot_modules_enabled
= false;
262 printf("invalid flag, must be 'enabled' or 'disabled'.\n");