xref: /netbsd-src/sys/arch/luna68k/stand/boot/init_main.c (revision 6de51c519f1b899da63c1bf576f478920b89083f)
1 /*	$NetBSD: init_main.c,v 1.5 2013/01/21 11:58:12 tsutsui Exp $	*/
2 
3 /*
4  * Copyright (c) 1992 OMRON Corporation.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * OMRON Corporation.
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 acknowledgement:
19  *	This product includes software developed by the University of
20  *	California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *	@(#)init_main.c	8.2 (Berkeley) 8/15/93
38  */
39 /*
40  * Copyright (c) 1992, 1993
41  *	The Regents of the University of California.  All rights reserved.
42  *
43  * This code is derived from software contributed to Berkeley by
44  * OMRON Corporation.
45  *
46  * Redistribution and use in source and binary forms, with or without
47  * modification, are permitted provided that the following conditions
48  * are met:
49  * 1. Redistributions of source code must retain the above copyright
50  *    notice, this list of conditions and the following disclaimer.
51  * 2. Redistributions in binary form must reproduce the above copyright
52  *    notice, this list of conditions and the following disclaimer in the
53  *    documentation and/or other materials provided with the distribution.
54  * 3. Neither the name of the University nor the names of its contributors
55  *    may be used to endorse or promote products derived from this software
56  *    without specific prior written permission.
57  *
58  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68  * SUCH DAMAGE.
69  *
70  *	@(#)init_main.c	8.2 (Berkeley) 8/15/93
71  */
72 
73 #include <sys/param.h>
74 #include <machine/cpu.h>
75 #include <luna68k/stand/boot/samachdep.h>
76 #include <luna68k/stand/boot/stinger.h>
77 #include <luna68k/stand/boot/romvec.h>
78 #include <luna68k/stand/boot/status.h>
79 #include <lib/libsa/loadfile.h>
80 #ifdef SUPPORT_ETHERNET
81 #include <lib/libsa/dev_net.h>
82 #endif
83 
84 static int get_plane_numbers(void);
85 static int reorder_dipsw(int);
86 
87 int cpuspeed;	/* for DELAY() macro */
88 int hz = 60;
89 int machtype;
90 
91 #define	VERS_LOCAL	"Phase-31"
92 
93 int nplane;
94 
95 /* KIFF */
96 
97 struct KernInter  KIFF;
98 struct KernInter *kiff = &KIFF;
99 
100 /* for command parser */
101 
102 #define BUFFSIZE 100
103 #define MAXARGS  30
104 
105 char buffer[BUFFSIZE];
106 
107 int   argc;
108 char *argv[MAXARGS];
109 
110 #define BOOT_TIMEOUT 10
111 int boot_timeout = BOOT_TIMEOUT;
112 
113 char  prompt[16] = "boot> ";
114 
115 void
116 main(void)
117 {
118 	int i, status = 0;
119 	const char *machstr;
120 
121 	/*
122 	 * Initialize the console before we print anything out.
123 	 */
124 	if (cputype == CPU_68030) {
125 		machtype = LUNA_I;
126 		machstr  = "LUNA-I";
127 		cpuspeed = MHZ_25;
128 		hz = 60;
129 	} else {
130 		machtype = LUNA_II;
131 		machstr  = "LUNA-II";
132 		cpuspeed = MHZ_25 * 2;	/* XXX */
133 		hz = 100;
134 	}
135 
136 	nplane   = get_plane_numbers();
137 
138 	cninit();
139 
140 	printf("\n");
141 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
142 	printf(">> (based on Stinger ver 0.0 [%s])\n", VERS_LOCAL);
143 	printf("\n");
144 
145 	kiff->maxaddr = (void *) (ROM_memsize -1);
146 	kiff->dipsw   = ~((dipsw2 << 8) | dipsw1) & 0xFFFF;
147 	kiff->plane   = nplane;
148 
149 	i = (int) kiff->maxaddr + 1;
150 	printf("Machine model   = %s\n", machstr);
151 	printf("Physical Memory = 0x%x  ", i);
152 	i >>= 20;
153 	printf("(%d MB)\n", i);
154 	printf("\n");
155 
156 	/*
157 	 * IO configuration
158 	 */
159 
160 #ifdef SUPPORT_ETHERNET
161 	try_bootp = 1;
162 #endif
163 
164 	find_devs();
165 	configure();
166 	printf("\n");
167 
168 	howto = reorder_dipsw(dipsw2);
169 
170 	if ((howto & 0xFE) == 0) {
171 		char c;
172 
173 		printf("Press return to boot now,"
174 		    " any other key for boot menu\n");
175 		printf("booting %s - starting in ", default_file);
176 		c = awaitkey("%d seconds. ", boot_timeout, true);
177 		if (c == '\r' || c == '\n' || c == 0) {
178 			printf("auto-boot %s\n", default_file);
179 			bootnetbsd(default_file);
180 		}
181 	}
182 
183 	/*
184 	 * Main Loop
185 	 */
186 
187 	printf("type \"help\" for help.\n");
188 
189 	do {
190 		memset(buffer, 0, BUFFSIZE);
191 		if (getline(prompt, buffer) > 0) {
192 			argc = getargs(buffer, argv, sizeof(argv)/sizeof(char *));
193 
194 			status = parse(argc, argv);
195 			if (status == ST_NOTFOUND)
196 				printf("Command \"%s\" is not found !!\n", argv[0]);
197 		}
198 	} while(status != ST_EXIT);
199 
200 	exit(0);
201 }
202 
203 int
204 get_plane_numbers(void)
205 {
206 	int r = ROM_plane;
207 	int n = 0;
208 
209 	for (; r ; r >>= 1)
210 		if (r & 0x1)
211 			n++;
212 
213 	return(n);
214 }
215 
216 int
217 reorder_dipsw(int dipsw)
218 {
219 	int i, sw = 0;
220 
221 	for (i = 0; i < 8; i++) {
222 		if ((dipsw & 0x01) == 0)
223 			sw += 1;
224 
225 		if (i == 7)
226 			break;
227 
228 		sw <<= 1;
229 		dipsw >>= 1;
230 	}
231 
232 	return(sw);
233 }
234