bootxx.c revision 1.5
11.5Schristos/* $NetBSD: bootxx.c,v 1.5 1999/05/03 16:13:16 christos 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.4Spk#include <machine/promlib.h> 461.1Smrg#include <sparc/stand/common/promdev.h> 471.1Smrg 481.1Smrgint debug; 491.1Smrgint netif_debug; 501.1Smrg 511.1Smrg/* 521.1Smrg * Boot device is derived from ROM provided information. 531.1Smrg */ 541.1Smrgconst char progname[] = "bootxx"; 551.1Smrgstruct open_file io; 561.1Smrg 571.1Smrg/* 581.1Smrg * The contents of the block_* variables below is set by installboot(8) 591.1Smrg * to hold the the filesystem data of the second-stage boot program 601.1Smrg * (typically `/boot'): filesystem block size, # of filesystem blocks and 611.1Smrg * the block numbers themselves. 621.1Smrg */ 631.1Smrg#define MAXBLOCKNUM 256 /* enough for a 2MB boot program (bs 8K) */ 641.1Smrgint32_t block_size = 0; 651.1Smrgint32_t block_count = MAXBLOCKNUM; 661.1Smrgdaddr_t block_table[MAXBLOCKNUM] = { 0 }; 671.1Smrg 681.1Smrg 691.4Spkint main __P((void)); 701.1Smrgvoid loadboot __P((struct open_file *, caddr_t)); 711.1Smrg 721.1Smrgint 731.1Smrgmain() 741.1Smrg{ 751.1Smrg char *dummy; 761.4Spk void (*entry)__P((void *)) = (void (*)__P((void *)))PROM_LOADADDR; 771.4Spk void *arg; 781.1Smrg 791.1Smrg prom_init(); 801.4Spk prom_bootdevice = prom_getbootpath(); 811.1Smrg io.f_flags = F_RAW; 821.1Smrg if (devopen(&io, 0, &dummy)) { 831.4Spk panic("%s: can't open device `%s'", progname, 841.4Spk prom_bootdevice != NULL ? prom_bootdevice : "unknown"); 851.1Smrg } 861.1Smrg 871.5Schristos (void)loadboot(&io, (caddr_t)PROM_LOADADDR); 881.2Spk (io.f_dev->dv_close)(&io); 891.4Spk 901.5Schristos arg = (prom_version() == PROM_OLDMON) ? (caddr_t)PROM_LOADADDR : romp; 911.4Spk (*entry)(arg); 921.1Smrg _rtt(); 931.1Smrg} 941.1Smrg 951.1Smrgvoid 961.1Smrgloadboot(f, addr) 971.4Spk struct open_file *f; 981.4Spk char *addr; 991.1Smrg{ 1001.4Spk int i; 1011.4Spk char *buf; 1021.1Smrg size_t n; 1031.1Smrg daddr_t blk; 1041.1Smrg 1051.1Smrg /* 1061.1Smrg * Allocate a buffer that we can map into DVMA space; only 1071.1Smrg * needed for sun4 architecture, but use it for all machines 1081.1Smrg * to keep code size down as much as possible. 1091.1Smrg */ 1101.1Smrg buf = alloc(block_size); 1111.1Smrg if (buf == NULL) 1121.1Smrg panic("%s: alloc failed", progname); 1131.1Smrg 1141.1Smrg for (i = 0; i < block_count; i++) { 1151.1Smrg if ((blk = block_table[i]) == 0) 1161.1Smrg panic("%s: block table corrupt", progname); 1171.1Smrg 1181.1Smrg#ifdef DEBUG 1191.1Smrg printf("%s: block # %d = %d\n", progname, i, blk); 1201.1Smrg#endif 1211.1Smrg if ((f->f_dev->dv_strategy)(f->f_devdata, F_READ, 1221.1Smrg blk, block_size, buf, &n)) { 1231.4Spk printf("%s: read failure", progname); 1241.4Spk _rtt(); 1251.1Smrg } 1261.1Smrg bcopy(buf, addr, block_size); 1271.1Smrg if (n != block_size) 1281.1Smrg panic("%s: short read", progname); 1291.1Smrg if (i == 0) { 1301.4Spk int m = N_GETMAGIC(*(struct exec *)addr); 1311.1Smrg if (m == ZMAGIC || m == NMAGIC || m == OMAGIC) { 1321.1Smrg /* Move exec header out of the way */ 1331.1Smrg bcopy(addr, addr - sizeof(struct exec), n); 1341.1Smrg addr -= sizeof(struct exec); 1351.1Smrg } 1361.1Smrg } 1371.1Smrg addr += n; 1381.1Smrg } 1391.1Smrg 1401.4Spk} 1411.4Spk 1421.4Spk/* 1431.4Spk * We don't need the overlap handling feature that the libkern version 1441.4Spk * of bcopy() provides. We DO need code compactness.. 1451.4Spk */ 1461.4Spkvoid 1471.4Spkbcopy(src, dst, n) 1481.4Spk const void *src; 1491.4Spk void *dst; 1501.4Spk size_t n; 1511.4Spk{ 1521.4Spk const char *p = src; 1531.4Spk char *q = dst; 1541.4Spk 1551.4Spk while (n-- > 0) 1561.4Spk *q++ = *p++; 1571.1Smrg} 158