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