main.c revision 1.8.2.1 1 /* $NetBSD: main.c,v 1.8.2.1 2006/06/21 14:52:44 yamt 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 #ifdef COMPAT_OLDBOOT
75 int
76 parsebootfile(const char *fname, char **fsname, char **devname,
77 int *unit, int *partition, const char **file)
78 {
79 return (EINVAL);
80 }
81
82 int
83 biosdisk_gettype(struct open_file *f)
84 {
85 return (0);
86 }
87 #endif
88
89 static int
90 bootit(const char *filename, int howto)
91 {
92 if (exec_netbsd(filename, 0, howto) < 0)
93 printf("boot: %s\n", strerror(errno));
94 else
95 printf("boot returned\n");
96 return (-1);
97 }
98
99 static void
100 print_banner(void)
101 {
102 int base = getbasemem();
103 int ext = getextmem();
104
105 printf("\n"
106 ">> %s, Revision %s\n"
107 ">> (%s, %s)\n"
108 ">> Memory: %d/%d k\n",
109 bootprog_name, bootprog_rev,
110 bootprog_maker, bootprog_date,
111 base, ext);
112 }
113
114 int
115 main(void)
116 {
117 char c;
118
119 #ifdef SUPPORT_SERIAL
120 initio(SUPPORT_SERIAL);
121 #else
122 initio(CONSDEV_PC);
123 #endif
124 gateA20();
125
126 print_banner();
127
128 printf("Press return to boot now, any other key for boot menu\n");
129 printf("Starting in ");
130
131 c = awaitkey(boot_params.bp_timeout, 1);
132 if ((c != '\r') && (c != '\n') && (c != '\0')) {
133 printf("type \"?\" or \"help\" for help.\n");
134 bootmenu(); /* does not return */
135 }
136
137 /*
138 * The file name provided here is just a default. If the
139 * DHCP server provides a file name, we'll use that instead.
140 */
141 bootit("netbsd", 0);
142
143 /*
144 * If that fails, let the BIOS try the next boot device.
145 */
146 return (1);
147 }
148
149 /* ARGSUSED */
150 void
151 command_help(char *arg)
152 {
153 printf("commands are:\n"
154 "boot [filename] [-adsqv]\n"
155 " (ex. \"netbsd.old -s\"\n"
156 "consdev {pc|com[0123]|com[0123]kbd|auto}\n"
157 "help|?\n"
158 "quit\n");
159 }
160
161 /* ARGSUSED */
162 void
163 command_quit(char *arg)
164 {
165
166 printf("Exiting...\n");
167 delay(1000000);
168 reboot();
169 /* Note: we shouldn't get to this point! */
170 panic("Could not reboot!");
171 exit(0);
172 }
173
174 void
175 command_boot(char *arg)
176 {
177 char *filename;
178 int howto;
179
180 if (parseboot(arg, &filename, &howto))
181 bootit(filename, howto);
182 }
183
184 static const struct cons_devs {
185 const char *name;
186 u_int tag;
187 } cons_devs[] = {
188 { "pc", CONSDEV_PC },
189 { "com0", CONSDEV_COM0 },
190 { "com1", CONSDEV_COM1 },
191 { "com2", CONSDEV_COM2 },
192 { "com3", CONSDEV_COM3 },
193 { "com0kbd", CONSDEV_COM0KBD },
194 { "com1kbd", CONSDEV_COM1KBD },
195 { "com2kbd", CONSDEV_COM2KBD },
196 { "com3kbd", CONSDEV_COM3KBD },
197 { "auto", CONSDEV_AUTO },
198 { 0, 0 } };
199
200 void
201 command_consdev(char *arg)
202 {
203 const struct cons_devs *cdp;
204
205 for (cdp = cons_devs; cdp->name; cdp++) {
206 if (!strcmp(arg, cdp->name)) {
207 initio(cdp->tag);
208 print_banner();
209 return;
210 }
211 }
212 printf("invalid console device.\n");
213 }
214