uboot.c revision 1.5
11.5Ssimonb/* $NetBSD: uboot.c,v 1.5 2001/01/02 04:14:35 simonb Exp $ */ 21.1Sthorpej 31.1Sthorpej/*- 41.1Sthorpej * Copyright (c) 1982, 1986, 1990, 1993 51.1Sthorpej * The Regents of the University of California. All rights reserved. 61.1Sthorpej * 71.1Sthorpej * Redistribution and use in source and binary forms, with or without 81.1Sthorpej * modification, are permitted provided that the following conditions 91.1Sthorpej * are met: 101.1Sthorpej * 1. Redistributions of source code must retain the above copyright 111.1Sthorpej * notice, this list of conditions and the following disclaimer. 121.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 131.1Sthorpej * notice, this list of conditions and the following disclaimer in the 141.1Sthorpej * documentation and/or other materials provided with the distribution. 151.1Sthorpej * 3. All advertising materials mentioning features or use of this software 161.1Sthorpej * must display the following acknowledgement: 171.1Sthorpej * This product includes software developed by the University of 181.1Sthorpej * California, Berkeley and its contributors. 191.1Sthorpej * 4. Neither the name of the University nor the names of its contributors 201.1Sthorpej * may be used to endorse or promote products derived from this software 211.1Sthorpej * without specific prior written permission. 221.1Sthorpej * 231.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241.1Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251.1Sthorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261.1Sthorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271.1Sthorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281.1Sthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291.1Sthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301.1Sthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311.1Sthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321.1Sthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331.1Sthorpej * SUCH DAMAGE. 341.1Sthorpej * 351.1Sthorpej * @(#)boot.c 8.1 (Berkeley) 6/10/93 361.1Sthorpej */ 371.1Sthorpej 381.1Sthorpej#include <sys/param.h> 391.1Sthorpej#include <sys/reboot.h> 401.4Sjdolecek#include <sys/boot_flag.h> 411.1Sthorpej#include <a.out.h> 421.1Sthorpej 431.1Sthorpej#include <lib/libsa/stand.h> 441.5Ssimonb#include <lib/libsa/loadfile.h> 451.1Sthorpej 461.1Sthorpej#include <hp300/stand/common/samachdep.h> 471.1Sthorpej 481.1Sthorpej/* 491.1Sthorpej * Boot program... bits in `howto' determine whether boot stops to 501.1Sthorpej * ask for system name. Boot device is derived from ROM provided 511.1Sthorpej * information. 521.1Sthorpej */ 531.1Sthorpej 541.1Sthorpejchar line[100]; 551.1Sthorpej 561.1Sthorpejextern u_int opendev; 571.1Sthorpejextern char *lowram; 581.1Sthorpejextern int noconsole; 591.1Sthorpej 601.1Sthorpej/* 611.1Sthorpej * XXX UFS accepts a /, NFS doesn't. 621.1Sthorpej */ 631.1Sthorpejchar *name; 641.1Sthorpejchar *names[] = { 651.2Sthorpej "netbsd", "netbsd.gz", 661.2Sthorpej "netbsd.bak", "netbsd.bak.gz", 671.2Sthorpej "netbsd.old", "netbsd.old.gz", 681.2Sthorpej "onetbsd", "onetbsd.gz", 691.1Sthorpej NULL 701.1Sthorpej}; 711.1Sthorpej#define NUMNAMES (sizeof(names) / sizeof(char *)) 721.1Sthorpej 731.1Sthorpejstatic int bdev, badapt, bctlr, bunit, bpart; 741.1Sthorpej 751.5Ssimonbvoid main __P((void)); 761.5Ssimonbvoid getbootdev __P((int *)); 771.5Ssimonbvoid exec_hp300 __P((char *, u_long, int)); 781.5Ssimonb 791.5Ssimonbvoid 801.1Sthorpejmain() 811.1Sthorpej{ 821.1Sthorpej int currname = 0; 831.1Sthorpej 841.1Sthorpej printf("\n"); 851.1Sthorpej printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev); 861.1Sthorpej printf(">> (%s, %s)\n", bootprog_maker, bootprog_date); 871.3Sthorpej printf(">> HP 9000/%s SPU\n", getmachineid()); 881.1Sthorpej printf(">> Enter \"reset\" to reset system.\n"); 891.1Sthorpej 901.1Sthorpej bdev = B_TYPE(bootdev); 911.1Sthorpej badapt = B_ADAPTOR(bootdev); 921.1Sthorpej bctlr = B_CONTROLLER(bootdev); 931.1Sthorpej bunit = B_UNIT(bootdev); 941.1Sthorpej bpart = B_PARTITION(bootdev); 951.1Sthorpej 961.1Sthorpej for (;;) { 971.1Sthorpej name = names[currname++]; 981.1Sthorpej if (currname == NUMNAMES) 991.1Sthorpej currname = 0; 1001.1Sthorpej 1011.1Sthorpej if (!noconsole) { 1021.1Sthorpej howto = 0; 1031.1Sthorpej getbootdev(&howto); 1041.1Sthorpej } else 1051.1Sthorpej printf(": %s\n", name); 1061.5Ssimonb exec_hp300(name, (u_long)lowram, howto); 1071.1Sthorpej printf("boot: %s\n", strerror(errno)); 1081.1Sthorpej } 1091.1Sthorpej} 1101.1Sthorpej 1111.5Ssimonbvoid 1121.1Sthorpejgetbootdev(howto) 1131.1Sthorpej int *howto; 1141.1Sthorpej{ 1151.1Sthorpej char c, *ptr = line; 1161.1Sthorpej 1171.4Sjdolecek printf("Boot: [[[%s%d%c:]%s][-s][-a][-d][-v][-q]] :- ", 1181.1Sthorpej devsw[bdev].dv_name, bctlr + (8 * badapt), 'a' + bpart, name); 1191.1Sthorpej 1201.1Sthorpej if (tgets(line)) { 1211.1Sthorpej if (strcmp(line, "reset") == 0) { 1221.1Sthorpej call_req_reboot(); /* reset machine */ 1231.1Sthorpej printf("panic: can't reboot, halting\n"); 1241.1Sthorpej asm("stop #0x2700"); 1251.1Sthorpej } 1261.5Ssimonb while ((c = *ptr) != '\0') { 1271.1Sthorpej while (c == ' ') 1281.1Sthorpej c = *++ptr; 1291.1Sthorpej if (!c) 1301.1Sthorpej return; 1311.1Sthorpej if (c == '-') 1321.1Sthorpej while ((c = *++ptr) && c != ' ') 1331.4Sjdolecek BOOT_FLAG(c, *howto); 1341.1Sthorpej else { 1351.1Sthorpej name = ptr; 1361.1Sthorpej while ((c = *++ptr) && c != ' '); 1371.1Sthorpej if (c) 1381.1Sthorpej *ptr++ = 0; 1391.1Sthorpej } 1401.1Sthorpej } 1411.1Sthorpej } else 1421.1Sthorpej printf("\n"); 1431.5Ssimonb} 1441.5Ssimonb 1451.5Ssimonb#define round_to_size(x) \ 1461.5Ssimonb (((x) + sizeof(u_long) - 1) & ~(sizeof(u_long) - 1)) 1471.5Ssimonb 1481.5Ssimonbvoid 1491.5Ssimonbexec_hp300(file, loadaddr, howto) 1501.5Ssimonb char *file; 1511.5Ssimonb u_long loadaddr; 1521.5Ssimonb int howto; 1531.5Ssimonb{ 1541.5Ssimonb u_long marks[MARK_MAX]; 1551.5Ssimonb int fd; 1561.5Ssimonb 1571.5Ssimonb marks[MARK_START] = loadaddr; 1581.5Ssimonb if ((fd = loadfile(name, marks, LOAD_KERNEL)) == -1) 1591.5Ssimonb return; 1601.5Ssimonb 1611.5Ssimonb marks[MARK_END] = round_to_size(marks[MARK_END] - loadaddr); 1621.5Ssimonb printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n", 1631.5Ssimonb marks[MARK_ENTRY], marks[MARK_NSYM], 1641.5Ssimonb marks[MARK_SYM], marks[MARK_END]); 1651.5Ssimonb 1661.5Ssimonb machdep_start((char *)marks[MARK_ENTRY], howto, 1671.5Ssimonb (char *)loadaddr, (char *)marks[MARK_SYM], 1681.5Ssimonb (char *)marks[MARK_END]); 1691.1Sthorpej} 170