1 /* $NetBSD: boot.c,v 1.18 2010/08/25 16:35:02 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 Izumi Tsutsui. 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 /*- 28 * Copyright (C) 1999 Tsubai Masanari. All rights reserved. 29 * 30 * Redistribution and use in source and binary forms, with or without 31 * modification, are permitted provided that the following conditions 32 * are met: 33 * 1. Redistributions of source code must retain the above copyright 34 * notice, this list of conditions and the following disclaimer. 35 * 2. Redistributions in binary form must reproduce the above copyright 36 * notice, this list of conditions and the following disclaimer in the 37 * documentation and/or other materials provided with the distribution. 38 * 3. The name of the author may not be used to endorse or promote products 39 * derived from this software without specific prior written permission. 40 * 41 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 42 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 44 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 45 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51 */ 52 53 #include <lib/libkern/libkern.h> 54 #include <lib/libsa/stand.h> 55 #include <lib/libsa/loadfile.h> 56 57 #include <machine/romcall.h> 58 59 void boot(uint32_t, uint32_t, uint32_t, uint32_t); 60 extern void ICIA(void); 61 62 /* version strings in vers.c (generated by newvers.sh) */ 63 extern const char bootprog_name[]; 64 extern const char bootprog_rev[]; 65 extern const char bootprog_kernrev[]; 66 67 char *devs[] = { "hd", "fh", "fd", NULL, NULL, "rd", "st" }; 68 char *kernels[] = { "/netbsd", "/netbsd.gz", NULL }; 69 70 #ifdef BOOT_DEBUG 71 # define DPRINTF printf 72 #else 73 # define DPRINTF while (0) printf 74 #endif 75 76 void 77 boot(uint32_t d4, uint32_t d5, uint32_t d6, uint32_t d7) 78 { 79 int fd, i; 80 int ctlr, unit, part, type; 81 uint32_t bootdev = d6; 82 char *netbsd = (char *)d5; 83 u_long marks[MARK_MAX]; 84 static char devname[32], file[32]; 85 void (*entry)(void); 86 int loadflag; 87 88 printf("%s Secondary Boot, Revision %s (from NetBSD %s)\n", 89 bootprog_name, bootprog_rev, bootprog_kernrev); 90 91 /* bootname is "boot" by default. */ 92 if (netbsd == NULL || strcmp(netbsd, "boot") == 0 || 93 strcmp(netbsd, "/boot") == 0) 94 netbsd = ""; 95 96 DPRINTF("howto = 0x%x\n", d7); 97 DPRINTF("bootdev = 0x%x\n", bootdev); 98 DPRINTF("bootname = %s\n", netbsd); 99 DPRINTF("maxmem = 0x%x\n", d4); 100 101 #define SET_MAGIC(bootdev, magic) ((bootdev & 0x0fffffff)| (magic << 28)) 102 /* PROM monitor passes 0xa, but NEWS-OS /boot passed 0x5... */ 103 bootdev = SET_MAGIC(bootdev, 5); 104 105 ctlr = BOOTDEV_CTLR(bootdev); 106 unit = BOOTDEV_UNIT(bootdev); 107 part = BOOTDEV_PART(bootdev); 108 type = BOOTDEV_TYPE(bootdev); 109 110 marks[MARK_START] = 0; 111 112 if (devs[type] == NULL) { 113 printf("unknown bootdev (0x%x)\n", bootdev); 114 return; 115 } 116 117 sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part); 118 printf("Booting %s%s\n", devname, netbsd); 119 120 /* use user specified kernel name if exists */ 121 if (*netbsd) { 122 kernels[0] = netbsd; 123 kernels[1] = NULL; 124 } 125 126 loadflag = LOAD_KERNEL; 127 if (devname[0] == 'f') /* XXX */ 128 loadflag &= ~LOAD_BACKWARDS; 129 130 for (i = 0; kernels[i]; i++) { 131 sprintf(file, "%s%s", devname, kernels[i]); 132 DPRINTF("trying %s...\n", file); 133 fd = loadfile(file, marks, loadflag); 134 if (fd != -1) 135 break; 136 } 137 if (kernels[i] == NULL) { 138 #if 0 /* bootxx() may be overrided by loaded kernel */ 139 return; 140 #else 141 rom_halt(); 142 /* NOTREACHED */ 143 #endif 144 } 145 146 DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]); 147 DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]); 148 DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]); 149 150 entry = (void *)marks[MARK_ENTRY]; 151 152 printf("\n"); 153 154 ICIA(); 155 __asm volatile ("movl %0,%%d7" : : "m" (d7)); 156 __asm volatile ("movl %0,%%d6" : : "m" (bootdev)); 157 __asm volatile ("movl %0,%%d5" : : "m" (netbsd)); 158 __asm volatile ("movl %0,%%d4" : : "m" (d4)); 159 __asm volatile ("movl %0,%%d2" : : "m" (marks[MARK_END])); 160 (*entry)(); 161 } 162 163 void 164 _rtt(void) 165 { 166 167 rom_halt(); 168 for (;;) 169 ; 170 /* NOTREACHED */ 171 } 172