xref: /netbsd/sys/arch/i386/stand/netboot/main.c (revision bf9ec67e)
1 /*	$NetBSD: main.c,v 1.10 2001/07/05 00:58:45 itojun 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 
40 #include <lib/libkern/libkern.h>
41 
42 #include <lib/libsa/stand.h>
43 
44 #include <libi386.h>
45 
46 int errno;
47 
48 extern char	bootprog_name[], bootprog_rev[], bootprog_date[],
49 		bootprog_maker[];
50 
51 #define TIMEOUT 5
52 
53 void	command_help __P((char *));
54 void	command_quit __P((char *));
55 void	command_boot __P((char *));
56 
57 const struct bootblk_command commands[] = {
58 	{ "help",	command_help },
59 	{ "?",		command_help },
60 	{ "quit",	command_quit },
61 	{ "boot",	command_boot },
62 	{ NULL,		NULL },
63 };
64 
65 int
66 bootit(filename, howto)
67 	const char     *filename;
68 	int             howto;
69 {
70 	if (exec_netbsd(filename, 0, howto) < 0)
71 		printf("boot: %s\n", strerror(errno));
72 	else
73 		printf("boot returned\n");
74 	return (-1);
75 }
76 
77 static void
78 print_banner(void)
79 {
80 
81 	printf("\n"
82 	       ">> %s, Revision %s\n"
83 	       ">> (%s, %s)\n"
84 	       ">> Memory: %d/%d k\n"
85 	       "Press return to boot now, any other key for boot menu\n"
86 	       "starting in ",
87 	       bootprog_name, bootprog_rev,
88 	       bootprog_maker, bootprog_date,
89 	       getbasemem(), getextmem());
90 }
91 
92 int
93 main()
94 {
95         char c;
96 
97 	initio(CONSDEV_AUTO);
98 	gateA20();
99 
100 	print_banner();
101 
102 	c = awaitkey(TIMEOUT, 1);
103 	if ((c != '\r') && (c != '\n') && (c != '\0')) {
104 		printf("type \"?\" or \"help\" for help.\n");
105 		bootmenu();	/* does not return */
106 	}
107 
108 	bootit("netbsd", 0);
109 
110 	/* if that fails, let BIOS look for boot device */
111 	return (1);
112 }
113 
114 /* ARGSUSED */
115 void
116 command_help(arg)
117 	char *arg;
118 {
119 	printf("commands are:\n"
120 	       "boot [filename] [-acdqsv]\n"
121 	       "     (ex. \"netbsd.old -s\"\n"
122 	       "help|?\n"
123 	       "quit\n");
124 }
125 
126 /* ARGSUSED */
127 void
128 command_quit(arg)
129 	char *arg;
130 {
131 	printf("Exiting... goodbye...\n");
132 	exit(0);
133 }
134 
135 void
136 command_boot(arg)
137 	char *arg;
138 {
139 	char *filename;
140 	int howto;
141 
142 	if (parseboot(arg, &filename, &howto))
143 		bootit(filename, howto);
144 }
145