xref: /netbsd/sys/arch/bebox/stand/boot/boot.c (revision bf9ec67e)
1 /*	$NetBSD: boot.c,v 1.14 2002/04/09 15:59:35 sakamoto 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 #include <stand.h>
34 #include <loadfile.h>
35 #include <sys/boot_flag.h>
36 #include <sys/reboot.h>
37 #include <machine/bootinfo.h>
38 #include "boot.h"
39 
40 char *names[] = {
41 	"in()",
42 	"fd(0,1,0)netbsd", "fd(0,1,0)netbsd.gz",
43 	"fd(0,1,0)netbsd.old", "fd(0,1,0)netbsd.old.gz",
44 	"fd(0,1,0)onetbsd", "fd(0,1,0)onetbsd.gz"
45 };
46 #define	NUMNAMES (sizeof (names) / sizeof (names[0]))
47 
48 #define	NAMELEN	128
49 char namebuf[NAMELEN];
50 char nametmp[NAMELEN];
51 
52 struct btinfo_memory btinfo_memory;
53 struct btinfo_console btinfo_console;
54 struct btinfo_clock btinfo_clock;
55 
56 extern char bootprog_name[], bootprog_rev[], bootprog_maker[], bootprog_date[];
57 
58 void exec_kernel __P((char *, void *));
59 
60 void
61 main()
62 {
63 	int n = 0;
64 	int addr, speed;
65 	char *name, *cnname;
66 	void *p, *bootinfo;
67 
68 	if (whichCPU() == 1)
69 		cpu1();
70 	resetCPU1();
71 
72 	/*
73 	 * console init
74 	 */
75 	cnname = cninit(&addr, &speed);
76 
77 	/*
78 	 * make bootinfo
79 	 */
80 	bootinfo = (void *)0x3030;
81 
82 	/*
83 	 * memory
84 	 */
85 	btinfo_memory.common.next = sizeof (btinfo_memory);
86 	btinfo_memory.common.type = BTINFO_MEMORY;
87 	btinfo_memory.memsize = *(int *)0x3010;
88 
89 	/*
90 	 * console
91 	 */
92 	btinfo_console.common.next = sizeof (btinfo_console);
93 	btinfo_console.common.type = BTINFO_CONSOLE;
94 	strcpy(btinfo_console.devname, cnname);
95 	btinfo_console.addr = addr;
96 	btinfo_console.speed = speed;
97 
98 	/*
99 	 * clock
100 	 */
101 	btinfo_clock.common.next = 0;
102 	btinfo_clock.common.type = BTINFO_CLOCK;
103 	btinfo_clock.ticks_per_sec = TICKS_PER_SEC;
104 
105 	p = bootinfo;
106 	memcpy(p, (void *)&btinfo_memory, sizeof (btinfo_memory));
107 	p += sizeof (btinfo_memory);
108 	memcpy(p, (void *)&btinfo_console, sizeof (btinfo_console));
109 	p += sizeof (btinfo_console);
110 	memcpy(p, (void *)&btinfo_clock, sizeof (btinfo_clock));
111 
112 	/*
113 	 * attached kernel check
114 	 */
115 	init_in();
116 
117 	runCPU1((void *)start_CPU1);
118 	wait_for(&CPU1_alive);
119 
120 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
121 	printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
122 	printf(">> Memory: %d k\n", btinfo_memory.memsize / 1024);
123 
124 	for (;;) {
125 		name = names[n++];
126 		if (n >= NUMNAMES)
127 			n = 0;
128 
129 		exec_kernel(name, bootinfo);
130 	}
131 }
132 
133 /*
134  * Exec kernel
135  */
136 void
137 exec_kernel(name, bootinfo)
138 	char *name;
139 	void *bootinfo;
140 {
141 	int howto = 0;
142 	char c, *ptr;
143 	u_long marks[MARK_MAX];
144 #ifdef DBMONITOR
145 	int go_monitor;
146 	extern int db_monitor __P((void));
147 #endif /* DBMONITOR */
148 	extern int tgets __P((char *buf));
149 
150 ret:
151 	printf("\nBoot: ");
152 	memset(namebuf, 0, sizeof (namebuf));
153 	(void)tgets(namebuf);
154 
155 	ptr = namebuf;
156 #ifdef DBMONITOR
157 	go_monitor = 0;
158 	if (*ptr == '!') {
159 		if (*(++ptr) == NULL) {
160 			db_monitor();
161 			printf("\n");
162 			goto ret;
163 		} else {
164 			go_monitor++;
165 		}
166 	}
167 #endif /* DBMONITOR */
168 	while ((c = *ptr)) {
169 		while (c == ' ')
170 			c = *++ptr;
171 		if (!c)
172 			goto next;
173 		if (c == '-') {
174 			while ((c = *++ptr) && c != ' ')
175 				BOOT_FLAG(c, howto);
176 		} else {
177 			name = ptr;
178 			while ((c = *++ptr) && c != ' ');
179 			if (c)
180 				*ptr++ = 0;
181 		}
182 	}
183 
184 next:
185 	printf("Loading %s\n", name);
186 
187 	marks[MARK_START] = 0;
188 	if (loadfile(name, marks, LOAD_ALL) == 0) {
189 #ifdef DBMONITOR
190 		if (go_monitor) {
191 			db_monitor();
192 			printf("\n");
193 		}
194 #endif /* DBMONITOR */
195 
196 		printf("start=0x%x\n\n", marks[MARK_ENTRY]);
197 		delay(1000);
198 		__syncicache((void *)marks[MARK_ENTRY],
199 			(u_int)marks[MARK_SYM] - (u_int)marks[MARK_ENTRY]);
200 
201 		*(volatile u_long *)0x0080 = marks[MARK_ENTRY];
202 		run((void *)marks[MARK_SYM],
203 		    (void *)marks[MARK_END],
204 		    (void *)howto,
205 		    bootinfo,
206 		    (void *)marks[MARK_ENTRY]);
207 	}
208 }
209