main.c revision 1.8 1 /* $NetBSD: main.c,v 1.8 2005/06/22 20:42:45 dyoung 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
60 const struct bootblk_command commands[] = {
61 { "help", command_help },
62 { "?", command_help },
63 { "quit", command_quit },
64 { "boot", command_boot },
65 { NULL, NULL },
66 };
67
68 #ifdef COMPAT_OLDBOOT
69 int
70 parsebootfile(const char *fname, char **fsname, char **devname,
71 int *unit, int *partition, const char **file)
72 {
73 return (EINVAL);
74 }
75
76 int
77 biosdisk_gettype(struct open_file *f)
78 {
79 return (0);
80 }
81 #endif
82
83 static int
84 bootit(const char *filename, int howto)
85 {
86 if (exec_netbsd(filename, 0, howto) < 0)
87 printf("boot: %s\n", strerror(errno));
88 else
89 printf("boot returned\n");
90 return (-1);
91 }
92
93 static void
94 print_banner(void)
95 {
96 int base = getbasemem();
97 int ext = getextmem();
98
99 printf("\n"
100 ">> %s, Revision %s\n"
101 ">> (%s, %s)\n"
102 ">> Memory: %d/%d k\n",
103 bootprog_name, bootprog_rev,
104 bootprog_maker, bootprog_date,
105 base, ext);
106 }
107
108 int
109 main(void)
110 {
111 char c;
112
113 #ifdef SUPPORT_SERIAL
114 initio(SUPPORT_SERIAL);
115 #else
116 initio(CONSDEV_PC);
117 #endif
118 gateA20();
119
120 print_banner();
121
122 printf("Press return to boot now, any other key for boot menu\n");
123 printf("Starting in ");
124
125 c = awaitkey(TIMEOUT, 1);
126 if ((c != '\r') && (c != '\n') && (c != '\0')) {
127 printf("type \"?\" or \"help\" for help.\n");
128 bootmenu(); /* does not return */
129 }
130
131 /*
132 * The file name provided here is just a default. If the
133 * DHCP server provides a file name, we'll use that instead.
134 */
135 bootit("netbsd", 0);
136
137 /*
138 * If that fails, let the BIOS try the next boot device.
139 */
140 return (1);
141 }
142
143 /* ARGSUSED */
144 void
145 command_help(char *arg)
146 {
147 printf("commands are:\n"
148 "boot [filename] [-adsqv]\n"
149 " (ex. \"netbsd.old -s\"\n"
150 "help|?\n"
151 "quit\n");
152 }
153
154 /* ARGSUSED */
155 void
156 command_quit(char *arg)
157 {
158 printf("Exiting... goodbye...\n");
159 exit(0);
160 }
161
162 void
163 command_boot(char *arg)
164 {
165 char *filename;
166 int howto;
167
168 if (parseboot(arg, &filename, &howto))
169 bootit(filename, howto);
170 }
171