1 /* $NetBSD: boot.c,v 1.4 1999/12/23 06:52:31 tsubai Exp $ */ 2 3 /*- 4 * Copyright (C) 1999 Tsubai Masanari. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <lib/libkern/libkern.h> 30 #include <lib/libsa/stand.h> 31 #include <lib/libsa/loadfile.h> 32 33 #include <machine/apcall.h> 34 #include <machine/bootinfo.h> 35 #include <machine/cpu.h> 36 #include <machine/romcall.h> 37 38 void mips1_flushicache __P((void *, int)); 39 extern char _edata[], _end[]; 40 41 struct apbus_sysinfo *_sip; 42 int apbus; 43 44 char *devs[] = { "sd", "fh", "fd", NULL, NULL, "rd", "st" }; 45 char *kernels[] = { "/netbsd", "/netbsd.gz", NULL }; 46 47 #ifdef BOOT_DEBUG 48 # define DPRINTF printf 49 #else 50 # define DPRINTF while (0) printf 51 #endif 52 53 void 54 boot(a0, a1, a2, a3, a4, a5) 55 u_int a0, a1, a2, a3, a4, a5; 56 { 57 int fd, i; 58 char *netbsd = ""; 59 int maxmem; 60 u_long marks[MARK_MAX]; 61 char devname[32], file[32]; 62 void (*entry)(); 63 struct btinfo_symtab bi_sym; 64 struct btinfo_bootarg bi_arg; 65 struct btinfo_bootpath bi_bpath; 66 struct btinfo_systype bi_sys; 67 68 /* Clear BSS. */ 69 bzero(_edata, _end - _edata); 70 71 /* 72 * XXX a3 contains: 73 * maxmem (nws-3xxx) 74 * argv (apbus-based machine) 75 */ 76 if (a3 >= 0x80000000) 77 apbus = 1; 78 else 79 apbus = 0; 80 81 if (apbus) 82 _sip = (void *)a4; 83 84 printf("\n"); 85 printf("NetBSD/newsmips Secondary Boot\n"); 86 87 if (apbus) { 88 char *bootdev = (char *)a1; 89 int argc = a2; 90 char **argv = (char **)a3; 91 92 DPRINTF("APbus-based system\n"); 93 94 DPRINTF("argc = %d\n", argc); 95 for (i = 0; i < argc; i++) { 96 DPRINTF("argv[%d] = %s\n", i, argv[i]); 97 if (argv[i][0] != '-' && *netbsd == 0) 98 netbsd = argv[i]; 99 } 100 maxmem = _sip->apbsi_memsize; 101 maxmem -= 0x100000; /* reserve 1MB for ROM monitor */ 102 103 DPRINTF("howto = 0x%x\n", a0); 104 DPRINTF("bootdev = %s\n", (char *)a1); 105 DPRINTF("bootname = %s\n", netbsd); 106 DPRINTF("maxmem = 0x%x\n", maxmem); 107 108 /* XXX use "sonic()" instead of "tftp()" */ 109 if (strncmp(bootdev, "tftp", 4) == 0) 110 bootdev = "sonic"; 111 112 strcpy(devname, bootdev); 113 if (strchr(devname, '(') == NULL) 114 strcat(devname, "()"); 115 } else { 116 int bootdev = a1; 117 char *bootname = (char *)a2; 118 int ctlr, unit, part, type; 119 120 DPRINTF("HB system.\n"); 121 122 /* bootname is "/boot" by default on HB system. */ 123 if (bootname && strcmp(bootname, "/boot") != 0) 124 netbsd = bootname; 125 maxmem = a3; 126 127 DPRINTF("howto = 0x%x\n", a0); 128 DPRINTF("bootdev = 0x%x\n", a1); 129 DPRINTF("bootname = %s\n", netbsd); 130 DPRINTF("maxmem = 0x%x\n", maxmem); 131 132 ctlr = BOOTDEV_CTLR(bootdev); 133 unit = BOOTDEV_UNIT(bootdev); 134 part = BOOTDEV_PART(bootdev); 135 type = BOOTDEV_TYPE(bootdev); 136 137 if (devs[type] == NULL) { 138 printf("unknown bootdev (0x%x)\n", bootdev); 139 _rtt(); 140 } 141 142 sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part); 143 } 144 145 printf("Booting %s%s\n", devname, netbsd); 146 147 /* use user specified kernel name if exists */ 148 if (*netbsd) { 149 kernels[0] = netbsd; 150 kernels[1] = NULL; 151 } 152 153 marks[MARK_START] = 0; 154 155 for (i = 0; kernels[i]; i++) { 156 sprintf(file, "%s%s", devname, kernels[i]); 157 DPRINTF("trying %s...\n", file); 158 fd = loadfile(file, marks, LOAD_KERNEL); 159 if (fd != -1) 160 break; 161 } 162 if (fd == -1) 163 _rtt(); 164 165 DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]); 166 DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]); 167 DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]); 168 169 bi_init(BOOTINFO_ADDR); 170 171 bi_sym.nsym = marks[MARK_NSYM]; 172 bi_sym.ssym = marks[MARK_SYM]; 173 bi_sym.esym = marks[MARK_END]; 174 bi_add(&bi_sym, BTINFO_SYMTAB, sizeof(bi_sym)); 175 176 bi_arg.howto = a0; 177 bi_arg.bootdev = a1; 178 bi_arg.maxmem = maxmem; 179 bi_arg.sip = (int)_sip; 180 bi_add(&bi_arg, BTINFO_BOOTARG, sizeof(bi_arg)); 181 182 strcpy(bi_bpath.bootpath, file); 183 bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath)); 184 185 bi_sys.type = apbus ? NEWS5000 : NEWS3400; /* XXX */ 186 bi_add(&bi_sys, BTINFO_SYSTYPE, sizeof(bi_sys)); 187 188 entry = (void *)marks[MARK_ENTRY]; 189 190 if (apbus) 191 apcall_flushcache(); 192 else 193 mips1_flushicache(entry, marks[MARK_SYM] - marks[MARK_ENTRY]); 194 195 printf("\n"); 196 (*entry)(a0, a1, a2, a3, a4, a5); 197 } 198 199 void 200 putchar(x) 201 int x; 202 { 203 char c = x; 204 205 if (apbus) 206 apcall_write(1, &c, 1); 207 else 208 rom_write(1, &c, 1); 209 } 210 211 void halt __P((void)); 212 213 void 214 _rtt() 215 { 216 if (apbus) 217 apcall_exit(8); 218 else 219 halt(); 220 221 for (;;); 222 } 223