1 /* $NetBSD: boot.c,v 1.18 2011/01/22 19:19:22 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/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> 43 #include <powerpc/oea/spr.h> 44 45 #include "boot.h" 46 47 char *names[] = { 48 "in()", 49 }; 50 #define NUMNAMES (sizeof (names) / sizeof (names[0])) 51 52 #define NAMELEN 128 53 char namebuf[NAMELEN]; 54 char nametmp[NAMELEN]; 55 56 char bootinfo[BOOTINFO_MAXSIZE]; 57 struct btinfo_residual btinfo_residual; 58 struct btinfo_console btinfo_console; 59 struct btinfo_clock btinfo_clock; 60 61 RESIDUAL residual; 62 63 extern u_long ns_per_tick; 64 extern char bootprog_name[], bootprog_rev[]; 65 66 void boot(void *, u_long); 67 static void exec_kernel(char *); 68 69 void 70 boot(void *resp, u_long loadaddr) 71 { 72 extern char _end[], _edata[]; 73 int n = 0; 74 int addr, speed; 75 unsigned int cpuvers; 76 char *name, *cnname, *p; 77 78 /* Clear all of BSS */ 79 memset(_edata, 0, _end - _edata); 80 81 /* 82 * console init 83 */ 84 cnname = cninit(&addr, &speed); 85 #ifdef VGA_RESET 86 vga_reset((u_char *)0xc0000000); 87 #endif 88 89 /* make bootinfo */ 90 /* 91 * residual data 92 */ 93 btinfo_residual.common.next = sizeof(btinfo_residual); 94 btinfo_residual.common.type = BTINFO_RESIDUAL; 95 if (resp) { 96 memcpy(&residual, resp, sizeof(residual)); 97 btinfo_residual.addr = (void *)&residual; 98 } else { 99 printf("Warning: no residual data.\n"); 100 btinfo_residual.addr = 0; 101 } 102 103 /* 104 * console 105 */ 106 btinfo_console.common.next = sizeof(btinfo_console); 107 btinfo_console.common.type = BTINFO_CONSOLE; 108 strcpy(btinfo_console.devname, cnname); 109 btinfo_console.addr = addr; 110 btinfo_console.speed = speed; 111 112 /* 113 * clock 114 */ 115 __asm volatile ("mfpvr %0" : "=r"(cpuvers)); 116 cpuvers >>= 16; 117 btinfo_clock.common.next = 0; 118 btinfo_clock.common.type = BTINFO_CLOCK; 119 if (cpuvers == MPC601) { 120 btinfo_clock.ticks_per_sec = 1000000000; 121 } else { 122 btinfo_clock.ticks_per_sec = resp ? 123 residual.VitalProductData.ProcessorBusHz/4 : TICKS_PER_SEC; 124 } 125 ns_per_tick = 1000000000 / btinfo_clock.ticks_per_sec; 126 127 p = bootinfo; 128 memcpy(p, (void *)&btinfo_residual, sizeof(btinfo_residual)); 129 p += sizeof(btinfo_residual); 130 memcpy(p, (void *)&btinfo_console, sizeof(btinfo_console)); 131 p += sizeof(btinfo_console); 132 memcpy(p, (void *)&btinfo_clock, sizeof(btinfo_clock)); 133 134 /* 135 * load kernel if attached 136 */ 137 init_in(loadaddr); 138 139 printf("\n"); 140 printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev); 141 142 for (;;) { 143 name = names[n++]; 144 if (n >= NUMNAMES) 145 n = 0; 146 147 exec_kernel(name); 148 } 149 } 150 151 /* 152 * Exec kernel 153 */ 154 static void 155 exec_kernel(char *name) 156 { 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); 163 164 ret: 165 #endif /* DBMONITOR */ 166 printf("\nBoot: "); 167 memset(namebuf, 0, sizeof (namebuf)); 168 if (tgets(namebuf) == -1) 169 printf("\n"); 170 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++; 181 } 182 } 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; 197 } 198 } 199 200 next: 201 printf("Loading %s", name); 202 if (howto) 203 printf(" (howto 0x%x)", howto); 204 printf("\n"); 205 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"); 212 } 213 #endif /* DBMONITOR */ 214 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]); 219 220 run((void *)marks[MARK_SYM], 221 (void *)marks[MARK_END], 222 (void *)howto, 223 (void *)bootinfo, 224 (void *)marks[MARK_ENTRY]); 225 } 226 } 227