1 /* $OpenBSD: init_main.c,v 1.12 2023/02/23 19:48:22 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 const char version[] = "0.8";
101
102 #include <sys/param.h>
103 #include <lib/libkern/libkern.h>
104 #include <machine/board.h>
105 #include <luna88k/stand/boot/samachdep.h>
106 #include <stand/boot/cmd.h>
107
108 #include "dev_net.h"
109
110 static void get_fuse_rom_data(void);
111 static void get_nvram_data(void);
112 static const char *nvram_by_symbol(char *);
113
114 int cpuspeed; /* for DELAY() macro */
115 int machtype;
116
117 uint32_t bootdev;
118
119 uint16_t dipswitch = 0;
120 int nplane;
121
122 #ifdef DEBUG
123 int debug;
124 #endif
125
126 /*
127 * FUSE ROM and NVRAM data
128 */
129 struct fuse_rom_byte {
130 u_int32_t h;
131 u_int32_t l;
132 };
133 #define FUSE_ROM_SPACE 1024
134 #define FUSE_ROM_BYTES (FUSE_ROM_SPACE / sizeof(struct fuse_rom_byte))
135 char fuse_rom_data[FUSE_ROM_BYTES];
136
137 #define NNVSYM 8
138 #define NVSYMLEN 16
139 #define NVVALLEN 16
140 struct nvram_t {
141 char symbol[1 + NVSYMLEN];
142 char value[1 + NVVALLEN];
143 } nvram[NNVSYM];
144
145 int
main(void)146 main(void)
147 {
148 extern char *progname; /* boot.c */
149 extern int boottimeout; /* boot.c */
150
151 /* Determine the machine type from FUSE ROM data. */
152 get_fuse_rom_data();
153 if (strncmp(fuse_rom_data, "MNAME=LUNA88K+", 14) == 0)
154 machtype = LUNA_88K2;
155 else
156 machtype = LUNA_88K;
157
158 /*
159 * Initialize the console before we print anything out.
160 */
161 if (machtype == LUNA_88K) {
162 progname = "LUNA-88K BOOT";
163 cpuspeed = MHZ_25;
164 } else {
165 progname = "LUNA-88K2 BOOT";
166 cpuspeed = MHZ_33;
167 }
168
169 nplane = *((int *)0x1114); /* 0, 1, 4, or 8 */
170 cninit();
171
172 #ifdef SUPPORT_ETHERNET
173 try_bootp = 1;
174 #endif
175
176 get_nvram_data();
177
178 /* disable timeout if requested */
179 if ((dipswitch & 0x8000) == 0) {
180 boottimeout = 0;
181 }
182
183 boot(0);
184
185 _rtt();
186 /* NOTREACHED */
187 }
188
189 /* Get data from FUSE ROM */
190
191 void
get_fuse_rom_data(void)192 get_fuse_rom_data(void)
193 {
194 int i;
195 struct fuse_rom_byte *p = (struct fuse_rom_byte *)FUSE_ROM_ADDR;
196
197 for (i = 0; i < FUSE_ROM_BYTES; i++) {
198 fuse_rom_data[i] =
199 (char)((((p->h) >> 24) & 0x000000f0) |
200 (((p->l) >> 28) & 0x0000000f));
201 p++;
202 }
203 }
204
205 /* Get data from NVRAM */
206
207 void
get_nvram_data(void)208 get_nvram_data(void)
209 {
210 int i, j;
211 u_int8_t *page;
212 char buf[NVSYMLEN], *data;
213
214 if (machtype == LUNA_88K) {
215 data = (char *)(NVRAM_ADDR + 0x80);
216
217 for (i = 0; i < NNVSYM; i++) {
218 for (j = 0; j < NVSYMLEN; j++) {
219 buf[j] = *data;
220 data += 4;
221 }
222 strncpy(nvram[i].symbol, buf, sizeof(nvram[i].symbol));
223
224 for (j = 0; j < NVVALLEN; j++) {
225 buf[j] = *data;
226 data += 4;
227 }
228 strncpy(nvram[i].value, buf, sizeof(nvram[i].value));
229 }
230 } else if (machtype == LUNA_88K2) {
231 page = (u_int8_t *)(NVRAM_ADDR_88K2 + 0x20);
232
233 for (i = 0; i < NNVSYM; i++) {
234 *page = (u_int8_t)i;
235
236 data = (char *)NVRAM_ADDR_88K2;
237 strncpy(nvram[i].symbol, data, sizeof(nvram[i].symbol));
238
239 data = (char *)(NVRAM_ADDR_88K2 + 0x10);
240 strncpy(nvram[i].value, data, sizeof(nvram[i].value));
241 }
242 }
243 }
244
245 const char *
nvram_by_symbol(symbol)246 nvram_by_symbol(symbol)
247 char *symbol;
248 {
249 const char *value;
250 int i;
251
252 value = NULL;
253
254 for (i = 0; i < NNVSYM; i++) {
255 if (strncmp(nvram[i].symbol, symbol, NVSYMLEN) == 0) {
256 value = nvram[i].value;
257 break;
258 }
259 }
260
261 return value;
262 }
263
264 void
_rtt(void)265 _rtt(void)
266 {
267 *(volatile unsigned int *)RESET_CPU_ALL = 0;
268 for (;;) ;
269 /* NOTREACHED */
270 }
271
272 /*
273 * Return the default boot device.
274 */
275 void
devboot(dev_t dev,char * path)276 devboot(dev_t dev, char *path)
277 {
278 const char *nvv;
279 int unit, part;
280
281 /* Determine the 'auto-boot' device from NVRAM data */
282 nvv = nvram_by_symbol("boot_unit");
283 if (nvv != NULL)
284 unit = (int)strtol(nvv, NULL, 10);
285 else
286 unit = 0;
287 nvv = nvram_by_symbol("boot_partition");
288 if (nvv != NULL)
289 part = (int)strtol(nvv, NULL, 10);
290 else
291 part = 0;
292
293 nvv = nvram_by_symbol("boot_device");
294
295 snprintf(path, BOOTDEVLEN, "%s(%d,%d)",
296 nvv != NULL ? nvv : "sd", unit, part);
297 }
298
299 void
machdep()300 machdep()
301 {
302 /* Nothing to do - everything done in main() already */
303 }
304