xref: /openbsd-src/sys/arch/luna88k/stand/boot/init_main.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: init_main.c,v 1.6 2014/02/23 20:01:04 miod Exp $	*/
2 /*	$NetBSD: init_main.c,v 1.6 2013/03/05 15:34:53 tsutsui Exp $	*/
3 
4 /*
5  * Copyright (c) 1992 OMRON Corporation.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * OMRON Corporation.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)init_main.c	8.2 (Berkeley) 8/15/93
39  */
40 /*
41  * Copyright (c) 1992, 1993
42  *	The Regents of the University of California.  All rights reserved.
43  *
44  * This code is derived from software contributed to Berkeley by
45  * OMRON Corporation.
46  *
47  * Redistribution and use in source and binary forms, with or without
48  * modification, are permitted provided that the following conditions
49  * are met:
50  * 1. Redistributions of source code must retain the above copyright
51  *    notice, this list of conditions and the following disclaimer.
52  * 2. Redistributions in binary form must reproduce the above copyright
53  *    notice, this list of conditions and the following disclaimer in the
54  *    documentation and/or other materials provided with the distribution.
55  * 3. Neither the name of the University nor the names of its contributors
56  *    may be used to endorse or promote products derived from this software
57  *    without specific prior written permission.
58  *
59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69  * SUCH DAMAGE.
70  *
71  *	@(#)init_main.c	8.2 (Berkeley) 8/15/93
72  */
73 /*
74  * Mach Operating System
75  * Copyright (c) 1993-1991 Carnegie Mellon University
76  * Copyright (c) 1991 OMRON Corporation
77  * All Rights Reserved.
78  *
79  * Permission to use, copy, modify and distribute this software and its
80  * documentation is hereby granted, provided that both the copyright
81  * notice and this permission notice appear in all copies of the
82  * software, derivative works or modified versions, and any portions
83  * thereof, and that both notices appear in supporting documentation.
84  *
85  * CARNEGIE MELLON AND OMRON ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS"
86  * CONDITION.  CARNEGIE MELLON AND OMRON DISCLAIM ANY LIABILITY OF ANY KIND
87  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
88  *
89  * Carnegie Mellon requests users of this software to return to
90  *
91  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
92  *  School of Computer Science
93  *  Carnegie Mellon University
94  *  Pittsburgh PA 15213-3890
95  *
96  * any improvements or extensions that they make and grant Carnegie the
97  * rights to redistribute these changes.
98  */
99 
100 #include <sys/param.h>
101 #include <machine/board.h>
102 #include <luna88k/stand/boot/samachdep.h>
103 #include <luna88k/stand/boot/status.h>
104 #include <lib/libsa/loadfile.h>
105 #include "dev_net.h"
106 
107 static void get_fuse_rom_data(void);
108 static void get_nvram_data(void);
109 static int get_plane_numbers(void);
110 static const char *nvram_by_symbol(char *);
111 
112 int cpuspeed;	/* for DELAY() macro */
113 int machtype;
114 char default_file[64];
115 
116 uint16_t dipswitch = 0;
117 int nplane;
118 
119 /* for command parser */
120 
121 #define BUFFSIZE 100
122 #define MAXARGS  30
123 
124 char buffer[BUFFSIZE];
125 
126 int   argc;
127 char *argv[MAXARGS];
128 
129 #define BOOT_TIMEOUT 5
130 int boot_timeout = BOOT_TIMEOUT;
131 
132 static const char prompt[] = "boot> ";
133 
134 int debug;
135 
136 /*
137  * FUSE ROM and NVRAM data
138  */
139 struct fuse_rom_byte {
140 	u_int32_t h;
141 	u_int32_t l;
142 };
143 #define	FUSE_ROM_SPACE		1024
144 #define FUSE_ROM_BYTES		(FUSE_ROM_SPACE / sizeof(struct fuse_rom_byte))
145 char fuse_rom_data[FUSE_ROM_BYTES];
146 
147 #define NNVSYM		8
148 #define NVSYMLEN	16
149 #define NVVALLEN	16
150 struct nvram_t {
151 	char symbol[1 + NVSYMLEN];
152 	char value[1 + NVVALLEN];
153 } nvram[NNVSYM];
154 
155 int
156 main(void)
157 {
158 	int status = ST_NORMAL;
159 	const char *machstr;
160 	const char *nvv;
161 	int unit, part;
162 
163 	/* Determine the machine type from FUSE ROM data.  */
164 	get_fuse_rom_data();
165 	if (strncmp(fuse_rom_data, "MNAME=LUNA88K+", 14) == 0)
166 		machtype = LUNA_88K2;
167 	else
168 		machtype = LUNA_88K;
169 
170 	/*
171 	 * Initialize the console before we print anything out.
172 	 */
173 	if (machtype == LUNA_88K) {
174 		machstr  = "LUNA-88K";
175 		cpuspeed = MHZ_25;
176 	} else {
177 		machstr  = "LUNA-88K2";
178 		cpuspeed = MHZ_33;
179 	}
180 
181 	nplane = get_plane_numbers();
182 	cninit();
183 
184 	printf("\nOpenBSD/" MACHINE " (%s) boot 0.4\n\n", machstr);
185 
186 #ifdef SUPPORT_ETHERNET
187 	try_bootp = 1;
188 #endif
189 
190         /* Determine the 'auto-boot' device from NVRAM data */
191         get_nvram_data();
192 
193 	nvv = nvram_by_symbol("boot_unit");
194 	if (nvv != NULL)
195 		unit = (int)strtol(nvv, NULL, 10);
196 	else
197 		unit = 0;
198 	nvv = nvram_by_symbol("boot_partition");
199 	if (nvv != NULL)
200 		part = (int)strtol(nvv, NULL, 10);
201 	else
202 		part = 0;
203 
204 	nvv = nvram_by_symbol("boot_device");
205 
206 	snprintf(default_file, sizeof(default_file),
207 	    "%s(%d,%d)%s", nvv != NULL ? nvv : "sd", unit, part, "bsd");
208 
209 	/* auto-boot? (SW1) */
210 	if ((dipswitch & 0x8000) != 0) {
211 		char c;
212 
213 		printf("Press return to boot now,"
214 		    " any other key for boot menu\n");
215 		printf("booting %s - starting in ", default_file);
216 		c = awaitkey("%d seconds. ", boot_timeout, 1);
217 		if (c == '\r' || c == '\n' || c == 0) {
218 			printf("auto-boot %s\n", default_file);
219 			bootunix(default_file);
220 		}
221 	}
222 
223 	/*
224 	 * Main Loop
225 	 */
226 
227 	printf("type \"help\" for help.\n");
228 
229 	do {
230 		memset(buffer, 0, BUFFSIZE);
231 		if (getline(prompt, buffer) > 0) {
232 			argc = getargs(buffer, argv, sizeof(argv)/sizeof(char *));
233 
234 			status = parse(argc, argv);
235 			if (status == ST_NOTFOUND)
236 				printf("unknown command \"%s\"\n", argv[0]);
237 		}
238 	} while (status != ST_EXIT);
239 
240 	_rtt();
241 	/* NOTREACHED */
242 }
243 
244 int
245 get_plane_numbers(void)
246 {
247 	int r = *((int *)0x1114);
248 	int n = 0;
249 
250 	for (; r ; r >>= 1)
251 		if (r & 0x1)
252 			n++;
253 
254 	return(n);
255 }
256 
257 /* Get data from FUSE ROM */
258 
259 void
260 get_fuse_rom_data(void)
261 {
262 	int i;
263 	struct fuse_rom_byte *p = (struct fuse_rom_byte *)FUSE_ROM_ADDR;
264 
265 	for (i = 0; i < FUSE_ROM_BYTES; i++) {
266 		fuse_rom_data[i] =
267 		    (char)((((p->h) >> 24) & 0x000000f0) |
268 		           (((p->l) >> 28) & 0x0000000f));
269 		p++;
270 	}
271 }
272 
273 /* Get data from NVRAM */
274 
275 void
276 get_nvram_data(void)
277 {
278 	int i, j;
279 	u_int8_t *page;
280 	char buf[NVSYMLEN], *data;
281 
282 	if (machtype == LUNA_88K) {
283 		data = (char *)(NVRAM_ADDR + 0x80);
284 
285 		for (i = 0; i < NNVSYM; i++) {
286 			for (j = 0; j < NVSYMLEN; j++) {
287 				buf[j] = *data;
288 				data += 4;
289 			}
290 			strncpy(nvram[i].symbol, buf, sizeof(nvram[i].symbol));
291 
292 			for (j = 0; j < NVVALLEN; j++) {
293 				buf[j] = *data;
294 				data += 4;
295 			}
296 			strncpy(nvram[i].value, buf, sizeof(nvram[i].value));
297 		}
298 	} else if (machtype == LUNA_88K2) {
299 		page = (u_int8_t *)(NVRAM_ADDR_88K2 + 0x20);
300 
301 		for (i = 0; i < NNVSYM; i++) {
302 			*page = (u_int8_t)i;
303 
304 			data = (char *)NVRAM_ADDR_88K2;
305 			strncpy(nvram[i].symbol, data, sizeof(nvram[i].symbol));
306 
307 			data = (char *)(NVRAM_ADDR_88K2 + 0x10);
308 			strncpy(nvram[i].value, data, sizeof(nvram[i].value));
309 		}
310 	}
311 }
312 
313 const char *
314 nvram_by_symbol(symbol)
315 	char *symbol;
316 {
317 	const char *value;
318 	int i;
319 
320 	value = NULL;
321 
322 	for (i = 0; i < NNVSYM; i++) {
323 		if (strncmp(nvram[i].symbol, symbol, NVSYMLEN) == 0) {
324 			value = nvram[i].value;
325 			break;
326 		}
327 	}
328 
329 	return value;
330 }
331 
332 void
333 _rtt(void)
334 {
335 	*(volatile unsigned int *)RESET_CPU_ALL = 0;
336 	for (;;) ;
337 	/* NOTREACHED */
338 }
339