main.c revision 1.11.52.1 1 /* main.c,v 1.11 2005/11/13 22:23:30 dsl 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 <sys/types.h>
40 #include <sys/reboot.h>
41 #include <sys/bootblock.h>
42
43 #include <lib/libkern/libkern.h>
44
45 #include <lib/libsa/stand.h>
46
47 #include <libi386.h>
48 #include "pxeboot.h"
49
50 extern struct x86_boot_params boot_params;
51
52 int errno;
53 int debug;
54
55 extern char bootprog_name[], bootprog_rev[], bootprog_date[],
56 bootprog_maker[];
57
58 int main(void);
59
60 void command_help __P((char *));
61 void command_quit __P((char *));
62 void command_boot __P((char *));
63 void command_consdev(char *);
64
65 const struct bootblk_command commands[] = {
66 { "help", command_help },
67 { "?", command_help },
68 { "quit", command_quit },
69 { "boot", command_boot },
70 { "consdev", command_consdev },
71 { NULL, NULL },
72 };
73
74 static int
75 bootit(const char *filename, int howto)
76 {
77 if (exec_netbsd(filename, 0, howto) < 0)
78 printf("boot: %s\n", strerror(errno));
79 else
80 printf("boot returned\n");
81 return (-1);
82 }
83
84 static void
85 print_banner(void)
86 {
87 int base = getbasemem();
88 int ext = getextmem();
89
90 printf("\n"
91 ">> %s, Revision %s\n"
92 ">> (%s, %s)\n"
93 ">> Memory: %d/%d k\n",
94 bootprog_name, bootprog_rev,
95 bootprog_maker, bootprog_date,
96 base, ext);
97 }
98
99 int
100 main(void)
101 {
102 char c;
103
104 #ifdef SUPPORT_SERIAL
105 initio(SUPPORT_SERIAL);
106 #else
107 initio(CONSDEV_PC);
108 #endif
109 gateA20();
110
111 print_banner();
112
113 printf("Press return to boot now, any other key for boot menu\n");
114 printf("Starting in ");
115
116 c = awaitkey(boot_params.bp_timeout, 1);
117 if ((c != '\r') && (c != '\n') && (c != '\0')) {
118 printf("type \"?\" or \"help\" for help.\n");
119 bootmenu(); /* does not return */
120 }
121
122 /*
123 * The file name provided here is just a default. If the
124 * DHCP server provides a file name, we'll use that instead.
125 */
126 bootit("netbsd", 0);
127
128 /*
129 * If that fails, let the BIOS try the next boot device.
130 */
131 return (1);
132 }
133
134 /* ARGSUSED */
135 void
136 command_help(char *arg)
137 {
138 printf("commands are:\n"
139 "boot [filename] [-adsqv]\n"
140 " (ex. \"netbsd.old -s\"\n"
141 "consdev {pc|com[0123]|com[0123]kbd|auto}\n"
142 "help|?\n"
143 "quit\n");
144 }
145
146 /* ARGSUSED */
147 void
148 command_quit(char *arg)
149 {
150
151 printf("Exiting...\n");
152 delay(1000000);
153 reboot();
154 /* Note: we shouldn't get to this point! */
155 panic("Could not reboot!");
156 exit(0);
157 }
158
159 void
160 command_boot(char *arg)
161 {
162 char *filename;
163 int howto;
164
165 if (parseboot(arg, &filename, &howto))
166 bootit(filename, howto);
167 }
168
169 static const struct cons_devs {
170 const char *name;
171 u_int tag;
172 } cons_devs[] = {
173 { "pc", CONSDEV_PC },
174 { "com0", CONSDEV_COM0 },
175 { "com1", CONSDEV_COM1 },
176 { "com2", CONSDEV_COM2 },
177 { "com3", CONSDEV_COM3 },
178 { "com0kbd", CONSDEV_COM0KBD },
179 { "com1kbd", CONSDEV_COM1KBD },
180 { "com2kbd", CONSDEV_COM2KBD },
181 { "com3kbd", CONSDEV_COM3KBD },
182 { "auto", CONSDEV_AUTO },
183 { 0, 0 } };
184
185 void
186 command_consdev(char *arg)
187 {
188 const struct cons_devs *cdp;
189
190 for (cdp = cons_devs; cdp->name; cdp++) {
191 if (!strcmp(arg, cdp->name)) {
192 initio(cdp->tag);
193 print_banner();
194 return;
195 }
196 }
197 printf("invalid console device.\n");
198 }
199