xref: /netbsd-src/sys/arch/bebox/stand/boot/boot.c (revision ccd9df534e375a4366c5b55f23782053c7a98d82)
1 /*	$NetBSD: boot.c,v 1.27 2014/08/08 19:45:48 joerg Exp $	*/
2 
3 /*
4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5  * Copyright (C) 1995, 1996 TooLs GmbH.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by TooLs GmbH.
19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <lib/libsa/stand.h>
35 #include <lib/libsa/loadfile.h>
36 #include <lib/libkern/libkern.h>
37 #include <sys/boot_flag.h>
38 #include <sys/reboot.h>
39 #include <machine/bootinfo.h>
40 #include <machine/cpu.h>
41 
42 #include "boot.h"
43 #include "sdvar.h"
44 #include "wdvar.h"
45 
46 char *names[] = {
47 	"/dev/disk/scsi/000/0_0:/netbsd",
48 	"/dev/disk/ide/0/master/0_0:/netbsd",
49 	"/dev/disk/floppy:netbsd",	"/dev/disk/floppy:netbsd.gz",
50 	"/dev/disk/scsi/000/0_0:/onetbsd",
51 	"/dev/disk/ide/0/master/0_0:/onetbsd",
52 	"/dev/disk/floppy:onetbsd",	"/dev/disk/floppy:onetbsd.gz"
53 	"in",
54 };
55 #define	NUMNAMES (sizeof (names) / sizeof (names[0]))
56 
57 #define	NAMELEN	128
58 char namebuf[NAMELEN];
59 char nametmp[NAMELEN];
60 
61 struct btinfo_memory btinfo_memory;
62 struct btinfo_console btinfo_console;
63 struct btinfo_clock btinfo_clock;
64 struct btinfo_rootdevice btinfo_rootdevice;
65 
66 extern char bootprog_name[], bootprog_rev[];
67 
68 void main(void);
69 void exec_kernel(char *, void *);
70 
71 void
72 main(void)
73 {
74 	int n = 0;
75 	int addr, speed;
76 	char *name, *cnname;
77 	void *bootinfo;
78 
79 	if (whichCPU() == 1)
80 		cpu1();
81 	resetCPU1();
82 
83 	scanPCI();
84 
85 	/*
86 	 * console init
87 	 */
88 	cnname = cninit(&addr, &speed);
89 
90 	/*
91 	 * make bootinfo
92 	 */
93 	bootinfo = (void *)0x3030;
94 
95 	/*
96 	 * memory
97 	 */
98 	btinfo_memory.common.next = sizeof (btinfo_memory);
99 	btinfo_memory.common.type = BTINFO_MEMORY;
100 	btinfo_memory.memsize = *(int *)0x3010;
101 
102 	/*
103 	 * console
104 	 */
105 	btinfo_console.common.next = sizeof (btinfo_console);
106 	btinfo_console.common.type = BTINFO_CONSOLE;
107 	strcpy(btinfo_console.devname, cnname);
108 	btinfo_console.addr = addr;
109 	btinfo_console.speed = speed;
110 
111 	/*
112 	 * clock
113 	 */
114 	btinfo_clock.common.next = 0;
115 	btinfo_clock.common.type = BTINFO_CLOCK;
116 	btinfo_clock.ticks_per_sec = TICKS_PER_SEC;
117 
118 	runCPU1((void *)start_CPU1);
119 	wait_for(&CPU1_alive);
120 
121 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
122 	printf(">> Memory: %d k\n", btinfo_memory.memsize / 1024);
123 
124 	/*
125 	 * attached kernel check and copy.
126 	 */
127 	init_in();
128 
129 	printf("\n");
130 
131 	/* Initialize siop@pci0 dev 12 func 0 */
132 	siop_init(0, 12, 0);
133 
134 	/* Initialize wdc@isa port 0x1f0 */
135 	wdc_init(0x1f0);
136 
137 	for (;;) {
138 		name = names[n++];
139 		if (n >= NUMNAMES)
140 			n = 0;
141 
142 		exec_kernel(name, bootinfo);
143 	}
144 }
145 
146 /*
147  * Exec kernel
148  */
149 void
150 exec_kernel(char *name, void *bootinfo)
151 {
152 	int howto = 0, i;
153 	char c, *ptr;
154 	u_long marks[MARK_MAX];
155 	void *p;
156 #ifdef DBMONITOR
157 	int go_monitor;
158 
159 ret:
160 #endif /* DBMONITOR */
161 	printf("\nBoot: ");
162 	memset(namebuf, 0, sizeof (namebuf));
163 	(void)tgets(namebuf);
164 
165 	ptr = namebuf;
166 #ifdef DBMONITOR
167 	go_monitor = 0;
168 	if (*ptr == '!') {
169 		if (*(++ptr) == NULL) {
170 			db_monitor();
171 			printf("\n");
172 			goto ret;
173 		} else {
174 			go_monitor++;
175 		}
176 	}
177 #endif /* DBMONITOR */
178 	while ((c = *ptr)) {
179 		while (c == ' ')
180 			c = *++ptr;
181 		if (!c)
182 			goto next;
183 		if (c == '-') {
184 			while ((c = *++ptr) && c != ' ')
185 				BOOT_FLAG(c, howto);
186 		} else {
187 			name = ptr;
188 			while ((c = *++ptr) && c != ' ');
189 			if (c)
190 				*ptr++ = 0;
191 		}
192 	}
193 
194 next:
195 	printf("Loading %s\n", name);
196 
197 	marks[MARK_START] = 0;
198 	if (loadfile(name, marks, LOAD_ALL) == 0) {
199 #ifdef DBMONITOR
200 		if (go_monitor) {
201 			db_monitor();
202 			printf("\n");
203 		}
204 #endif /* DBMONITOR */
205 
206 		p = bootinfo;
207 
208 		/*
209 		 * root device
210 		 */
211 		btinfo_rootdevice.common.next = sizeof (btinfo_rootdevice);
212 		btinfo_rootdevice.common.type = BTINFO_ROOTDEVICE;
213 		strncpy(btinfo_rootdevice.rootdevice, name,
214 		    sizeof (btinfo_rootdevice.rootdevice));
215 		i = 0;
216 		while (btinfo_rootdevice.rootdevice[i] != '\0') {
217 			if (btinfo_rootdevice.rootdevice[i] == ':')
218 				break;
219 			i++;
220 		}
221 		if (btinfo_rootdevice.rootdevice[i] == ':') {
222 			/* It is NOT in-kernel. */
223 
224 			btinfo_rootdevice.rootdevice[i] = '\0';
225 
226 			memcpy(p, (void *)&btinfo_rootdevice,
227 			    sizeof (btinfo_rootdevice));
228 			p += sizeof (btinfo_rootdevice);
229 		}
230 
231 		memcpy(p, (void *)&btinfo_memory, sizeof (btinfo_memory));
232 		p += sizeof (btinfo_memory);
233 		memcpy(p, (void *)&btinfo_console, sizeof (btinfo_console));
234 		p += sizeof (btinfo_console);
235 		memcpy(p, (void *)&btinfo_clock, sizeof (btinfo_clock));
236 
237 		printf("start=0x%lx\n\n", marks[MARK_ENTRY]);
238 		delay(1000);
239 		__syncicache((void *)marks[MARK_ENTRY],
240 			(u_int)marks[MARK_SYM] - (u_int)marks[MARK_ENTRY]);
241 
242 		*(volatile u_long *)0x0080 = marks[MARK_ENTRY];
243 		run((void *)marks[MARK_SYM],
244 		    (void *)marks[MARK_END],
245 		    (void *)howto,
246 		    bootinfo,
247 		    (void *)marks[MARK_ENTRY]);
248 	}
249 }
250 
251 void
252 _rtt(void)
253 {
254 
255 	/* XXXX */
256 	__unreachable();
257 }
258