1 /* $NetBSD: boot.c,v 1.15 2006/06/10 07:49:29 tsutsui Exp $ */
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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>
49 #define NUMNAMES (sizeof (names) / sizeof (names[0]))
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
;
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 *);
69 boot(void *resp
, u_long loadaddr
)
71 extern char _end
[], _edata
[];
75 char *name
, *cnname
, *p
;
77 /* Clear all of BSS */
78 memset(_edata
, 0, _end
- _edata
);
83 cnname
= cninit(&addr
, &speed
);
85 vga_reset((u_char
*)0xc0000000);
92 btinfo_residual
.common
.next
= sizeof(btinfo_residual
);
93 btinfo_residual
.common
.type
= BTINFO_RESIDUAL
;
95 memcpy(&residual
, resp
, sizeof(residual
));
96 btinfo_residual
.addr
= (void *)&residual
;
98 printf("Warning: no residual data.\n");
99 btinfo_residual
.addr
= 0;
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
;
114 __asm
volatile ("mfpvr %0" : "=r"(cpuvers
));
116 btinfo_clock
.common
.next
= 0;
117 btinfo_clock
.common
.type
= BTINFO_CLOCK
;
118 if (cpuvers
== MPC601
) {
119 btinfo_clock
.ticks_per_sec
= 1000000000;
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
;
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
139 printf(">> %s, Revision %s\n", bootprog_name
, bootprog_rev
);
140 printf(">> (%s, %s)\n", bootprog_maker
, bootprog_date
);
155 exec_kernel(char *name
)
159 u_long marks
[MARK_MAX
];
162 extern int db_monitor(void);
165 #endif /* DBMONITOR */
167 memset(namebuf
, 0, sizeof (namebuf
));
168 if (tgets(namebuf
) == -1)
175 if (*(++ptr
) == NULL
) {
183 #endif /* DBMONITOR */
190 while ((c
= *++ptr
) && c
!= ' ')
194 while ((c
= *++ptr
) && c
!= ' ');
201 printf("Loading %s", name
);
203 printf(" (howto 0x%x)", howto
);
206 marks
[MARK_START
] = 0;
207 if (loadfile(name
, marks
, LOAD_ALL
) == 0) {
213 #endif /* DBMONITOR */
215 printf("start=0x%lx\n\n", marks
[MARK_ENTRY
]);
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
],
224 (void *)marks
[MARK_ENTRY
]);