uboot.c revision 1.2
11.2Sthorpej/* $NetBSD: uboot.c,v 1.2 1997/02/04 19:40:07 thorpej 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.1Sthorpej#include <a.out.h> 411.1Sthorpej 421.1Sthorpej#include <lib/libsa/stand.h> 431.1Sthorpej 441.1Sthorpej#include <hp300/stand/common/samachdep.h> 451.1Sthorpej 461.1Sthorpej/* 471.1Sthorpej * Boot program... bits in `howto' determine whether boot stops to 481.1Sthorpej * ask for system name. Boot device is derived from ROM provided 491.1Sthorpej * information. 501.1Sthorpej */ 511.1Sthorpej 521.1Sthorpejchar line[100]; 531.1Sthorpej 541.1Sthorpejextern u_int opendev; 551.1Sthorpejextern char *lowram; 561.1Sthorpejextern int noconsole; 571.1Sthorpej 581.1Sthorpej/* 591.1Sthorpej * XXX UFS accepts a /, NFS doesn't. 601.1Sthorpej */ 611.1Sthorpejchar *name; 621.1Sthorpejchar *names[] = { 631.2Sthorpej "netbsd", "netbsd.gz", 641.2Sthorpej "netbsd.bak", "netbsd.bak.gz", 651.2Sthorpej "netbsd.old", "netbsd.old.gz", 661.2Sthorpej "onetbsd", "onetbsd.gz", 671.1Sthorpej NULL 681.1Sthorpej}; 691.1Sthorpej#define NUMNAMES (sizeof(names) / sizeof(char *)) 701.1Sthorpej 711.1Sthorpejstatic int bdev, badapt, bctlr, bunit, bpart; 721.1Sthorpej 731.1Sthorpejmain() 741.1Sthorpej{ 751.1Sthorpej int currname = 0; 761.1Sthorpej 771.1Sthorpej printf("\n"); 781.1Sthorpej printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev); 791.1Sthorpej printf(">> (%s, %s)\n", bootprog_maker, bootprog_date); 801.1Sthorpej printf(">> HP 9000/%s CPU\n", getmachineid()); 811.1Sthorpej printf(">> Enter \"reset\" to reset system.\n"); 821.1Sthorpej 831.1Sthorpej bdev = B_TYPE(bootdev); 841.1Sthorpej badapt = B_ADAPTOR(bootdev); 851.1Sthorpej bctlr = B_CONTROLLER(bootdev); 861.1Sthorpej bunit = B_UNIT(bootdev); 871.1Sthorpej bpart = B_PARTITION(bootdev); 881.1Sthorpej 891.1Sthorpej for (;;) { 901.1Sthorpej name = names[currname++]; 911.1Sthorpej if (currname == NUMNAMES) 921.1Sthorpej currname = 0; 931.1Sthorpej 941.1Sthorpej if (!noconsole) { 951.1Sthorpej howto = 0; 961.1Sthorpej getbootdev(&howto); 971.1Sthorpej } else 981.1Sthorpej printf(": %s\n", name); 991.1Sthorpej 1001.1Sthorpej exec(name, lowram, howto); 1011.1Sthorpej printf("boot: %s\n", strerror(errno)); 1021.1Sthorpej } 1031.1Sthorpej} 1041.1Sthorpej 1051.1Sthorpejgetbootdev(howto) 1061.1Sthorpej int *howto; 1071.1Sthorpej{ 1081.1Sthorpej char c, *ptr = line; 1091.1Sthorpej 1101.1Sthorpej printf("Boot: [[[%s%d%c:]%s][-s][-a][-d]] :- ", 1111.1Sthorpej devsw[bdev].dv_name, bctlr + (8 * badapt), 'a' + bpart, name); 1121.1Sthorpej 1131.1Sthorpej if (tgets(line)) { 1141.1Sthorpej if (strcmp(line, "reset") == 0) { 1151.1Sthorpej call_req_reboot(); /* reset machine */ 1161.1Sthorpej printf("panic: can't reboot, halting\n"); 1171.1Sthorpej asm("stop #0x2700"); 1181.1Sthorpej } 1191.1Sthorpej while (c = *ptr) { 1201.1Sthorpej while (c == ' ') 1211.1Sthorpej c = *++ptr; 1221.1Sthorpej if (!c) 1231.1Sthorpej return; 1241.1Sthorpej if (c == '-') 1251.1Sthorpej while ((c = *++ptr) && c != ' ') 1261.1Sthorpej switch (c) { 1271.1Sthorpej case 'a': 1281.1Sthorpej *howto |= RB_ASKNAME; 1291.1Sthorpej continue; 1301.1Sthorpej case 's': 1311.1Sthorpej *howto |= RB_SINGLE; 1321.1Sthorpej continue; 1331.1Sthorpej case 'd': 1341.1Sthorpej *howto |= RB_KDB; 1351.1Sthorpej continue; 1361.1Sthorpej case 'b': 1371.1Sthorpej *howto |= RB_HALT; 1381.1Sthorpej continue; 1391.1Sthorpej } 1401.1Sthorpej else { 1411.1Sthorpej name = ptr; 1421.1Sthorpej while ((c = *++ptr) && c != ' '); 1431.1Sthorpej if (c) 1441.1Sthorpej *ptr++ = 0; 1451.1Sthorpej } 1461.1Sthorpej } 1471.1Sthorpej } else 1481.1Sthorpej printf("\n"); 1491.1Sthorpej} 150