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