No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / prep / stand / boot / boot.c
blob5359e8752ac938e087c8f6d4076ddde0ec9f73c9
1 /* $NetBSD: boot.c,v 1.15 2006/06/10 07:49:29 tsutsui Exp $ */
3 /*
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
6 * All rights reserved.
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.
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.
34 #include <lib/libsa/stand.h>
35 #include <lib/libsa/loadfile.h>
36 #include <lib/libkern/libkern.h>
37 #include <sys/reboot.h>
38 #include <sys/boot_flag.h>
39 #include <machine/bootinfo.h>
40 #include <machine/cpu.h>
41 #include <machine/residual.h>
42 #include <powerpc/spr.h>
44 #include "boot.h"
46 char *names[] = {
47 "in()",
49 #define NUMNAMES (sizeof (names) / sizeof (names[0]))
51 #define NAMELEN 128
52 char namebuf[NAMELEN];
53 char nametmp[NAMELEN];
55 char bootinfo[BOOTINFO_MAXSIZE];
56 struct btinfo_residual btinfo_residual;
57 struct btinfo_console btinfo_console;
58 struct btinfo_clock btinfo_clock;
60 RESIDUAL residual;
62 extern u_long ns_per_tick;
63 extern char bootprog_name[], bootprog_rev[], bootprog_maker[], bootprog_date[];
65 void boot(void *, u_long);
66 static void exec_kernel(char *);
68 void
69 boot(void *resp, u_long loadaddr)
71 extern char _end[], _edata[];
72 int n = 0;
73 int addr, speed;
74 unsigned int cpuvers;
75 char *name, *cnname, *p;
77 /* Clear all of BSS */
78 memset(_edata, 0, _end - _edata);
81 * console init
83 cnname = cninit(&addr, &speed);
84 #ifdef VGA_RESET
85 vga_reset((u_char *)0xc0000000);
86 #endif
88 /* make bootinfo */
90 * residual data
92 btinfo_residual.common.next = sizeof(btinfo_residual);
93 btinfo_residual.common.type = BTINFO_RESIDUAL;
94 if (resp) {
95 memcpy(&residual, resp, sizeof(residual));
96 btinfo_residual.addr = (void *)&residual;
97 } else {
98 printf("Warning: no residual data.\n");
99 btinfo_residual.addr = 0;
103 * console
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;
112 * clock
114 __asm volatile ("mfpvr %0" : "=r"(cpuvers));
115 cpuvers >>= 16;
116 btinfo_clock.common.next = 0;
117 btinfo_clock.common.type = BTINFO_CLOCK;
118 if (cpuvers == MPC601) {
119 btinfo_clock.ticks_per_sec = 1000000000;
120 } else {
121 btinfo_clock.ticks_per_sec = resp ?
122 residual.VitalProductData.ProcessorBusHz/4 : TICKS_PER_SEC;
124 ns_per_tick = 1000000000 / btinfo_clock.ticks_per_sec;
126 p = bootinfo;
127 memcpy(p, (void *)&btinfo_residual, sizeof(btinfo_residual));
128 p += sizeof(btinfo_residual);
129 memcpy(p, (void *)&btinfo_console, sizeof(btinfo_console));
130 p += sizeof(btinfo_console);
131 memcpy(p, (void *)&btinfo_clock, sizeof(btinfo_clock));
134 * load kernel if attached
136 init_in(loadaddr);
138 printf("\n");
139 printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
140 printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
142 for (;;) {
143 name = names[n++];
144 if (n >= NUMNAMES)
145 n = 0;
147 exec_kernel(name);
152 * Exec kernel
154 static void
155 exec_kernel(char *name)
157 int howto = 0;
158 char c, *ptr;
159 u_long marks[MARK_MAX];
160 #ifdef DBMONITOR
161 int go_monitor;
162 extern int db_monitor(void);
164 ret:
165 #endif /* DBMONITOR */
166 printf("\nBoot: ");
167 memset(namebuf, 0, sizeof (namebuf));
168 if (tgets(namebuf) == -1)
169 printf("\n");
171 ptr = namebuf;
172 #ifdef DBMONITOR
173 go_monitor = 0;
174 if (*ptr == '!') {
175 if (*(++ptr) == NULL) {
176 db_monitor();
177 printf("\n");
178 goto ret;
179 } else {
180 go_monitor++;
183 #endif /* DBMONITOR */
184 while ((c = *ptr)) {
185 while (c == ' ')
186 c = *++ptr;
187 if (!c)
188 goto next;
189 if (c == '-') {
190 while ((c = *++ptr) && c != ' ')
191 BOOT_FLAG(c, howto);
192 } else {
193 name = ptr;
194 while ((c = *++ptr) && c != ' ');
195 if (c)
196 *ptr++ = 0;
200 next:
201 printf("Loading %s", name);
202 if (howto)
203 printf(" (howto 0x%x)", howto);
204 printf("\n");
206 marks[MARK_START] = 0;
207 if (loadfile(name, marks, LOAD_ALL) == 0) {
208 #ifdef DBMONITOR
209 if (go_monitor) {
210 db_monitor();
211 printf("\n");
213 #endif /* DBMONITOR */
215 printf("start=0x%lx\n\n", marks[MARK_ENTRY]);
216 delay(1000);
217 __syncicache((void *)marks[MARK_ENTRY],
218 (u_int)marks[MARK_SYM] - (u_int)marks[MARK_ENTRY]);
220 run((void *)marks[MARK_SYM],
221 (void *)marks[MARK_END],
222 (void *)howto,
223 (void *)bootinfo,
224 (void *)marks[MARK_ENTRY]);