uboot.c revision 1.17
11.17Sdholland/*	$NetBSD: uboot.c,v 1.17 2016/06/11 06:22:11 dholland 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.10Sagc * 3. Neither the name of the University nor the names of its contributors
161.1Sthorpej *    may be used to endorse or promote products derived from this software
171.1Sthorpej *    without specific prior written permission.
181.1Sthorpej *
191.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201.1Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211.1Sthorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221.1Sthorpej * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231.1Sthorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241.1Sthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251.1Sthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261.1Sthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271.1Sthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281.1Sthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291.1Sthorpej * SUCH DAMAGE.
301.1Sthorpej *
311.1Sthorpej *	@(#)boot.c	8.1 (Berkeley) 6/10/93
321.1Sthorpej */
331.1Sthorpej
341.1Sthorpej#include <sys/param.h>
351.4Sjdolecek#include <sys/boot_flag.h>
361.1Sthorpej
371.1Sthorpej#include <lib/libsa/stand.h>
381.11Stsutsui#include <lib/libkern/libkern.h>
391.1Sthorpej
401.1Sthorpej#include <hp300/stand/common/samachdep.h>
411.1Sthorpej
421.1Sthorpej/*
431.1Sthorpej * Boot program... bits in `howto' determine whether boot stops to
441.1Sthorpej * ask for system name.	 Boot device is derived from ROM provided
451.1Sthorpej * information.
461.1Sthorpej */
471.1Sthorpej
481.1Sthorpejchar line[100];
491.1Sthorpej
501.1Sthorpejextern	u_int opendev;
511.1Sthorpejextern	char *lowram;
521.1Sthorpejextern	int noconsole;
531.1Sthorpej
541.1Sthorpej/*
551.1Sthorpej * XXX UFS accepts a /, NFS doesn't.
561.1Sthorpej */
571.1Sthorpejchar *name;
581.1Sthorpejchar *names[] = {
591.2Sthorpej	"netbsd",		"netbsd.gz",
601.2Sthorpej	"netbsd.bak",		"netbsd.bak.gz",
611.2Sthorpej	"netbsd.old",		"netbsd.old.gz",
621.2Sthorpej	"onetbsd",		"onetbsd.gz",
631.1Sthorpej	NULL
641.1Sthorpej};
651.1Sthorpej#define NUMNAMES	(sizeof(names) / sizeof(char *))
661.1Sthorpej
671.1Sthorpejstatic int bdev, badapt, bctlr, bunit, bpart;
681.1Sthorpej
691.12Stsutsuivoid main(void);
701.12Stsutsuivoid getbootdev(int *);
711.5Ssimonb
721.5Ssimonbvoid
731.12Stsutsuimain(void)
741.1Sthorpej{
751.1Sthorpej	int currname = 0;
761.1Sthorpej
771.1Sthorpej	printf("\n");
781.15Stsutsui	printf(">> %s, Revision %s (from NetBSD %s)\n",
791.15Stsutsui	    bootprog_name, bootprog_rev, bootprog_kernrev);
801.3Sthorpej	printf(">> HP 9000/%s SPU\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.5Ssimonb		exec_hp300(name, (u_long)lowram, howto);
1001.1Sthorpej		printf("boot: %s\n", strerror(errno));
1011.1Sthorpej	}
1021.1Sthorpej}
1031.1Sthorpej
1041.5Ssimonbvoid
1051.12Stsutsuigetbootdev(int *howto)
1061.1Sthorpej{
1071.1Sthorpej	char c, *ptr = line;
1081.1Sthorpej
1091.7Sgmcgarry	printf("Boot: [[[%s%d%c:]%s][-a][-c][-d][-s][-v][-q]] :- ",
1101.1Sthorpej	    devsw[bdev].dv_name, bctlr + (8 * badapt), 'a' + bpart, name);
1111.1Sthorpej
1121.17Sdholland	if (tgets(line, sizeof(line))) {
1131.1Sthorpej		if (strcmp(line, "reset") == 0) {
1141.1Sthorpej			call_req_reboot();      /* reset machine */
1151.1Sthorpej			printf("panic: can't reboot, halting\n");
1161.14Sperry			__asm("stop #0x2700");
1171.1Sthorpej		}
1181.5Ssimonb		while ((c = *ptr) != '\0') {
1191.1Sthorpej			while (c == ' ')
1201.1Sthorpej				c = *++ptr;
1211.1Sthorpej			if (!c)
1221.1Sthorpej				return;
1231.1Sthorpej			if (c == '-')
1241.1Sthorpej				while ((c = *++ptr) && c != ' ')
1251.4Sjdolecek					BOOT_FLAG(c, *howto);
1261.1Sthorpej			else {
1271.1Sthorpej				name = ptr;
1281.1Sthorpej				while ((c = *++ptr) && c != ' ');
1291.1Sthorpej				if (c)
1301.1Sthorpej					*ptr++ = 0;
1311.1Sthorpej			}
1321.1Sthorpej		}
1331.1Sthorpej	} else
1341.1Sthorpej		printf("\n");
1351.1Sthorpej}
136