bootxx.c revision 1.3
11.3Spk/* $NetBSD: bootxx.c,v 1.3 1998/09/05 15:12:26 pk Exp $ */ 21.1Smrg 31.3Spk/*- 41.3Spk * Copyright (c) 1998 The NetBSD Foundation, Inc. 51.1Smrg * All rights reserved. 61.1Smrg * 71.3Spk * This code is derived from software contributed to The NetBSD Foundation 81.3Spk * by Paul Kranenburg. 91.3Spk * 101.1Smrg * Redistribution and use in source and binary forms, with or without 111.1Smrg * modification, are permitted provided that the following conditions 121.1Smrg * are met: 131.1Smrg * 1. Redistributions of source code must retain the above copyright 141.1Smrg * notice, this list of conditions and the following disclaimer. 151.1Smrg * 2. Redistributions in binary form must reproduce the above copyright 161.1Smrg * notice, this list of conditions and the following disclaimer in the 171.1Smrg * documentation and/or other materials provided with the distribution. 181.1Smrg * 3. All advertising materials mentioning features or use of this software 191.1Smrg * must display the following acknowledgement: 201.3Spk * This product includes software developed by the NetBSD 211.3Spk * Foundation, Inc. and its contributors. 221.3Spk * 4. Neither the name of The NetBSD Foundation nor the names of its 231.3Spk * contributors may be used to endorse or promote products derived 241.3Spk * from this software without specific prior written permission. 251.1Smrg * 261.3Spk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.3Spk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.3Spk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.3Spk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.3Spk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.3Spk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.3Spk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.3Spk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.3Spk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.3Spk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.3Spk * POSSIBILITY OF SUCH DAMAGE. 371.1Smrg */ 381.1Smrg 391.1Smrg#include <sys/param.h> 401.1Smrg#include <sys/time.h> 411.1Smrg#include <a.out.h> 421.1Smrg 431.1Smrg#include <lib/libsa/stand.h> 441.1Smrg 451.1Smrg#include <sparc/stand/common/promdev.h> 461.1Smrg 471.1Smrgint debug; 481.1Smrgint netif_debug; 491.1Smrg 501.1Smrg/* 511.1Smrg * Boot device is derived from ROM provided information. 521.1Smrg */ 531.1Smrgconst char progname[] = "bootxx"; 541.1Smrgstruct open_file io; 551.1Smrg 561.1Smrg/* 571.1Smrg * The contents of the block_* variables below is set by installboot(8) 581.1Smrg * to hold the the filesystem data of the second-stage boot program 591.1Smrg * (typically `/boot'): filesystem block size, # of filesystem blocks and 601.1Smrg * the block numbers themselves. 611.1Smrg */ 621.1Smrg#define MAXBLOCKNUM 256 /* enough for a 2MB boot program (bs 8K) */ 631.1Smrgint32_t block_size = 0; 641.1Smrgint32_t block_count = MAXBLOCKNUM; 651.1Smrgdaddr_t block_table[MAXBLOCKNUM] = { 0 }; 661.1Smrg 671.1Smrg 681.1Smrgvoid loadboot __P((struct open_file *, caddr_t)); 691.1Smrg 701.1Smrgint 711.1Smrgmain() 721.1Smrg{ 731.1Smrg char *dummy; 741.1Smrg size_t n; 751.1Smrg register void (*entry)__P((caddr_t)) = (void (*)__P((caddr_t)))LOADADDR; 761.1Smrg 771.1Smrg prom_init(); 781.1Smrg io.f_flags = F_RAW; 791.1Smrg if (devopen(&io, 0, &dummy)) { 801.1Smrg panic("%s: can't open device", progname); 811.1Smrg } 821.1Smrg 831.1Smrg (void)loadboot(&io, LOADADDR); 841.2Spk (io.f_dev->dv_close)(&io); 851.1Smrg (*entry)(cputyp == CPU_SUN4 ? LOADADDR : (caddr_t)promvec); 861.1Smrg _rtt(); 871.1Smrg} 881.1Smrg 891.1Smrgvoid 901.1Smrgloadboot(f, addr) 911.1Smrg register struct open_file *f; 921.1Smrg register char *addr; 931.1Smrg{ 941.1Smrg register int i; 951.1Smrg register char *buf; 961.1Smrg size_t n; 971.1Smrg daddr_t blk; 981.1Smrg 991.1Smrg /* 1001.1Smrg * Allocate a buffer that we can map into DVMA space; only 1011.1Smrg * needed for sun4 architecture, but use it for all machines 1021.1Smrg * to keep code size down as much as possible. 1031.1Smrg */ 1041.1Smrg buf = alloc(block_size); 1051.1Smrg if (buf == NULL) 1061.1Smrg panic("%s: alloc failed", progname); 1071.1Smrg 1081.1Smrg for (i = 0; i < block_count; i++) { 1091.1Smrg if ((blk = block_table[i]) == 0) 1101.1Smrg panic("%s: block table corrupt", progname); 1111.1Smrg 1121.1Smrg#ifdef DEBUG 1131.1Smrg printf("%s: block # %d = %d\n", progname, i, blk); 1141.1Smrg#endif 1151.1Smrg if ((f->f_dev->dv_strategy)(f->f_devdata, F_READ, 1161.1Smrg blk, block_size, buf, &n)) { 1171.1Smrg panic("%s: read failure", progname); 1181.1Smrg } 1191.1Smrg bcopy(buf, addr, block_size); 1201.1Smrg if (n != block_size) 1211.1Smrg panic("%s: short read", progname); 1221.1Smrg if (i == 0) { 1231.1Smrg register int m = N_GETMAGIC(*(struct exec *)addr); 1241.1Smrg if (m == ZMAGIC || m == NMAGIC || m == OMAGIC) { 1251.1Smrg /* Move exec header out of the way */ 1261.1Smrg bcopy(addr, addr - sizeof(struct exec), n); 1271.1Smrg addr -= sizeof(struct exec); 1281.1Smrg } 1291.1Smrg } 1301.1Smrg addr += n; 1311.1Smrg } 1321.1Smrg 1331.1Smrg} 134