bootxx.c revision 1.8
1/* $NetBSD: bootxx.c,v 1.8 2000/03/13 23:52:33 soren Exp $ */ 2 3/*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Paul Kranenburg. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <sys/param.h> 40#include <sys/time.h> 41#include <sys/exec.h> 42 43#include <lib/libsa/stand.h> 44 45#include <machine/promlib.h> 46#include <sparc/stand/common/promdev.h> 47 48int debug; 49int netif_debug; 50 51/* 52 * Boot device is derived from ROM provided information. 53 */ 54const char progname[] = "bootxx"; 55struct open_file io; 56 57/* 58 * The contents of the block_* variables below is set by installboot(8) 59 * to hold the filesystem data of the second-stage boot program 60 * (typically `/boot'): filesystem block size, # of filesystem 61 * blocks and the block numbers themselves. 62 */ 63#define MAXBLOCKNUM 256 /* enough for a 2MB boot program (bs 8K) */ 64int32_t block_size = 0; 65int32_t block_count = MAXBLOCKNUM; 66daddr_t block_table[MAXBLOCKNUM] = { 0 }; 67 68 69int main __P((void)); 70void loadboot __P((struct open_file *, caddr_t)); 71 72int 73main() 74{ 75 char *dummy; 76 void (*entry)__P((void *)) = (void (*)__P((void *)))PROM_LOADADDR; 77 void *arg; 78 79#ifdef HEAP_VARIABLE 80 { 81 extern char end[]; 82 setheap((void *)ALIGN(end), (void *)0xffffffff); 83 } 84#endif 85 prom_init(); 86 prom_bootdevice = prom_getbootpath(); 87 io.f_flags = F_RAW; 88 if (devopen(&io, 0, &dummy)) { 89 panic("%s: can't open device `%s'", progname, 90 prom_bootdevice != NULL ? prom_bootdevice : "unknown"); 91 } 92 93 (void)loadboot(&io, (caddr_t)PROM_LOADADDR); 94 (io.f_dev->dv_close)(&io); 95 96 arg = (prom_version() == PROM_OLDMON) ? (caddr_t)PROM_LOADADDR : romp; 97 (*entry)(arg); 98 _rtt(); 99} 100 101void 102loadboot(f, addr) 103 struct open_file *f; 104 char *addr; 105{ 106 int i; 107 char *buf; 108 size_t n; 109 daddr_t blk; 110 111 /* 112 * Allocate a buffer that we can map into DVMA space; only 113 * needed for sun4 architecture, but use it for all machines 114 * to keep code size down as much as possible. 115 */ 116 buf = alloc(block_size); 117 if (buf == NULL) 118 panic("%s: alloc failed", progname); 119 120 for (i = 0; i < block_count; i++) { 121 if ((blk = block_table[i]) == 0) 122 panic("%s: block table corrupt", progname); 123 124#ifdef DEBUG 125 printf("%s: block # %d = %d\n", progname, i, blk); 126#endif 127 if ((f->f_dev->dv_strategy)(f->f_devdata, F_READ, 128 blk, block_size, buf, &n)) { 129 printf("%s: read failure", progname); 130 _rtt(); 131 } 132 bcopy(buf, addr, block_size); 133 if (n != block_size) 134 panic("%s: short read", progname); 135 if (i == 0) { 136 int m = N_GETMAGIC(*(struct exec *)addr); 137 if (m == ZMAGIC || m == NMAGIC || m == OMAGIC) { 138 /* Move exec header out of the way */ 139 bcopy(addr, addr - sizeof(struct exec), n); 140 addr -= sizeof(struct exec); 141 } 142 } 143 addr += n; 144 } 145 146} 147 148/* 149 * We don't need the overlap handling feature that the libkern version 150 * of bcopy() provides. We DO need code compactness.. 151 */ 152void 153bcopy(src, dst, n) 154 const void *src; 155 void *dst; 156 size_t n; 157{ 158 const char *p = src; 159 char *q = dst; 160 161 while (n-- > 0) 162 *q++ = *p++; 163} 164