main.c revision 1.1 1 /* $NetBSD: main.c,v 1.1 2002/02/16 03:37:40 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 __asm __volatile(".globl breakme; breakme:");
101
102 printf("\n"
103 ">> %s, Revision %s\n"
104 ">> (%s, %s)\n"
105 ">> Memory: %d/%d k\n",
106 bootprog_name, bootprog_rev,
107 bootprog_maker, bootprog_date,
108 base, ext);
109 }
110
111 int
112 main(void)
113 {
114 char c;
115
116 initio(CONSDEV_AUTO);
117 gateA20();
118
119 print_banner();
120
121 pxe_init();
122
123 printf("Press return to boot now, any other key for boot menu\n");
124 printf("Starting in ");
125
126 c = awaitkey(TIMEOUT, 1);
127 if ((c != '\r') && (c != '\n') && (c != '\0')) {
128 printf("type \"?\" or \"help\" for help.\n");
129 bootmenu(); /* does not return */
130 }
131
132 bootit("netbsd", 0);
133
134 /*
135 * If that fails, let the BIOS try the next boot device.
136 */
137 return (1);
138 }
139
140 /* ARGSUSED */
141 void
142 command_help(char *arg)
143 {
144 printf("commands are:\n"
145 "boot [filename] [-adsqv]\n"
146 " (ex. \"netbsd.old -s\"\n"
147 "help|?\n"
148 "quit\n");
149 }
150
151 /* ARGSUSED */
152 void
153 command_quit(char *arg)
154 {
155 printf("Exiting... goodbye...\n");
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