bootxx.c revision 1.4
1/* $NetBSD: bootxx.c,v 1.4 1999/02/15 18:59:36 pk 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 <a.out.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 the filesystem data of the second-stage boot program 60 * (typically `/boot'): filesystem block size, # of filesystem blocks and 61 * 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 prom_init(); 80 prom_bootdevice = prom_getbootpath(); 81 io.f_flags = F_RAW; 82 if (devopen(&io, 0, &dummy)) { 83 panic("%s: can't open device `%s'", progname, 84 prom_bootdevice != NULL ? prom_bootdevice : "unknown"); 85 } 86 87 (void)loadboot(&io, PROM_LOADADDR); 88 (io.f_dev->dv_close)(&io); 89 90 arg = (prom_version() == PROM_OLDMON) ? PROM_LOADADDR : romp; 91 (*entry)(arg); 92 _rtt(); 93} 94 95void 96loadboot(f, addr) 97 struct open_file *f; 98 char *addr; 99{ 100 int i; 101 char *buf; 102 size_t n; 103 daddr_t blk; 104 105 /* 106 * Allocate a buffer that we can map into DVMA space; only 107 * needed for sun4 architecture, but use it for all machines 108 * to keep code size down as much as possible. 109 */ 110 buf = alloc(block_size); 111 if (buf == NULL) 112 panic("%s: alloc failed", progname); 113 114 for (i = 0; i < block_count; i++) { 115 if ((blk = block_table[i]) == 0) 116 panic("%s: block table corrupt", progname); 117 118#ifdef DEBUG 119 printf("%s: block # %d = %d\n", progname, i, blk); 120#endif 121 if ((f->f_dev->dv_strategy)(f->f_devdata, F_READ, 122 blk, block_size, buf, &n)) { 123 printf("%s: read failure", progname); 124 _rtt(); 125 } 126 bcopy(buf, addr, block_size); 127 if (n != block_size) 128 panic("%s: short read", progname); 129 if (i == 0) { 130 int m = N_GETMAGIC(*(struct exec *)addr); 131 if (m == ZMAGIC || m == NMAGIC || m == OMAGIC) { 132 /* Move exec header out of the way */ 133 bcopy(addr, addr - sizeof(struct exec), n); 134 addr -= sizeof(struct exec); 135 } 136 } 137 addr += n; 138 } 139 140} 141 142/* 143 * We don't need the overlap handling feature that the libkern version 144 * of bcopy() provides. We DO need code compactness.. 145 */ 146void 147bcopy(src, dst, n) 148 const void *src; 149 void *dst; 150 size_t n; 151{ 152 const char *p = src; 153 char *q = dst; 154 155 while (n-- > 0) 156 *q++ = *p++; 157} 158