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