Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.10
      1 /*	$NetBSD: boot.c,v 1.10 2000/07/10 10:38:23 ragge Exp $ */
      2 /*-
      3  * Copyright (c) 1982, 1986 The Regents of the University of California.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by the University of
     17  *	California, Berkeley and its contributors.
     18  * 4. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)boot.c	7.15 (Berkeley) 5/4/91
     35  */
     36 
     37 #include "sys/param.h"
     38 #include "sys/reboot.h"
     39 #include "lib/libsa/stand.h"
     40 
     41 #define V750UCODE(x)    ((x>>8)&255)
     42 
     43 #include "machine/rpb.h"
     44 
     45 #include "vaxstand.h"
     46 
     47 /*
     48  * Boot program... arguments passed in r10 and r11 determine
     49  * whether boot stops to ask for system name and which device
     50  * boot comes from.
     51  */
     52 
     53 char line[100];
     54 int	bootdev, debug;
     55 extern	unsigned opendev;
     56 
     57 void	usage(char *), boot(char *), halt(char *);
     58 void	Xmain(void);
     59 void	autoconf(void);
     60 int	getsecs(void);
     61 int	setjmp(int *);
     62 int	testkey(void);
     63 void	loadpcs(void);
     64 
     65 const struct vals {
     66 	char	*namn;
     67 	void	(*func)(char *);
     68 	char	*info;
     69 } val[] = {
     70 	{"?", usage, "Show this help menu"},
     71 	{"help", usage, "Same as '?'"},
     72 	{"boot", boot, "Load and execute file"},
     73 	{"halt", halt, "Halts the system"},
     74 	{0, 0},
     75 };
     76 
     77 static struct {
     78 	char name[12];
     79 	int quiet;
     80 } filelist[] = {
     81 	{ "netbsd.vax", 1 },
     82 	{ "netbsd", 0 },
     83 	{ "netbsd.gz", 0 },
     84 	{ "netbsd.old", 0 },
     85 	{ "gennetbsd", 0 },
     86 	{ "", 0 },
     87 };
     88 
     89 int jbuf[10];
     90 int sluttid, senast, skip, askname;
     91 struct rpb bootrpb;
     92 
     93 void
     94 Xmain(void)
     95 {
     96 	int io;
     97 	int j, nu;
     98 
     99 	io = 0;
    100 	skip = 1;
    101 	autoconf();
    102 
    103 	askname = bootrpb.rpb_bootr5 & RB_ASKNAME;
    104 	printf("\n\r>> NetBSD/vax boot [%s %s] <<\n", __DATE__, __TIME__);
    105 	printf(">> Press any key to abort autoboot  ");
    106 	sluttid = getsecs() + 5;
    107 	senast = 0;
    108 	skip = 0;
    109 	setjmp(jbuf);
    110 	for (;;) {
    111 		nu = sluttid - getsecs();
    112 		if (senast != nu)
    113 			printf("%c%d", 8, nu);
    114 		if (nu <= 0)
    115 			break;
    116 		senast = nu;
    117 		if ((j = (testkey() & 0177))) {
    118 			skip = 1;
    119 			if (j != 10 && j != 13) {
    120 				printf("\nPress '?' for help");
    121 				askname = 1;
    122 			}
    123 			break;
    124 		}
    125 	}
    126 	skip = 1;
    127 	printf("\n");
    128 
    129 	/* First try to autoboot */
    130 	if (askname == 0) {
    131 		int fileindex;
    132 		for (fileindex = 0; filelist[fileindex].name[0] != '\0';
    133 		    fileindex++) {
    134 			errno = 0;
    135 			if (!filelist[fileindex].quiet)
    136 				printf("> boot %s\n", filelist[fileindex].name);
    137 			exec(filelist[fileindex].name, 0, 0);
    138 			if (!filelist[fileindex].quiet)
    139 				printf("%s: boot failed: %s\n",
    140 				    filelist[fileindex].name, strerror(errno));
    141 #if 0 /* Will hang VAX 4000 machines */
    142 			if (testkey())
    143 				break;
    144 #endif
    145 		}
    146 	}
    147 
    148 	/* If any key pressed, go to conversational boot */
    149 	for (;;) {
    150 		const struct vals *v = &val[0];
    151 		char *c, *d;
    152 
    153 		printf("> ");
    154 		gets(line);
    155 
    156 		c = line;
    157 		while (*c == ' ')
    158 			c++;
    159 
    160 		if (c[0] == 0)
    161 			continue;
    162 
    163 		if ((d = index(c, ' ')))
    164 			*d++ = 0;
    165 
    166 		while (v->namn) {
    167 			if (strcmp(v->namn, c) == 0)
    168 				break;
    169 			v++;
    170 		}
    171 		if (v->namn)
    172 			(*v->func)(d);
    173 		else
    174 			printf("Unknown command: %s\n", c);
    175 	}
    176 }
    177 
    178 void
    179 halt(char *hej)
    180 {
    181 	asm("halt");
    182 }
    183 
    184 void
    185 boot(char *arg)
    186 {
    187 	char *fn = "netbsd";
    188 
    189 	if (arg) {
    190 		while (*arg == ' ')
    191 			arg++;
    192 
    193 		if (*arg != '-') {
    194 			fn = arg;
    195 			if ((arg = index(arg, ' '))) {
    196 				*arg++ = 0;
    197 				while (*arg == ' ')
    198 					arg++;
    199 			} else
    200 				goto load;
    201 		}
    202 		if (*arg != '-') {
    203 fail:			printf("usage: boot [filename] [-asd]\n");
    204 			return;
    205 		}
    206 
    207 		while (*++arg) {
    208 			if (*arg == 'a')
    209 				bootrpb.rpb_bootr5 |= RB_ASKNAME;
    210 			else if (*arg == 'd')
    211 				bootrpb.rpb_bootr5 |= RB_KDB;
    212 			else if (*arg == 's')
    213 				bootrpb.rpb_bootr5 |= RB_SINGLE;
    214 			else
    215 				goto fail;
    216 		}
    217 	}
    218 load:	exec(fn, 0, 0);
    219 	printf("Boot failed: %s\n", strerror(errno));
    220 }
    221 
    222 /* 750 Patchable Control Store magic */
    223 
    224 #include "../include/mtpr.h"
    225 #include "../include/cpu.h"
    226 #include "../include/sid.h"
    227 #define	PCS_BITCNT	0x2000		/* number of patchbits */
    228 #define	PCS_MICRONUM	0x400		/* number of ucode locs */
    229 #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
    230 #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
    231 #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
    232 #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
    233 
    234 #define	extzv(one, two, three,four)	\
    235 ({			\
    236 	asm __volatile (" extzv %0,%3,(%1),(%2)+"	\
    237 			:			\
    238 			: "g"(one),"g"(two),"g"(three),"g"(four));	\
    239 })
    240 
    241 
    242 void
    243 loadpcs()
    244 {
    245 	static int pcsdone = 0;
    246 	int mid = mfpr(PR_SID);
    247 	int i, j, *ip, *jp;
    248 	char pcs[100];
    249 	char *cp;
    250 
    251 	if ((mid >> 24) != VAX_750 || ((mid >> 8) & 255) < 95 || pcsdone)
    252 		return;
    253 	printf("Updating 11/750 microcode: ");
    254 	for (cp = line; *cp; cp++)
    255 		if (*cp == ')' || *cp == ':')
    256 			break;
    257 	if (*cp) {
    258 		bcopy(line, pcs, 99);
    259 		pcs[99] = 0;
    260 		i = cp - line + 1;
    261 	} else
    262 		i = 0;
    263 	strcpy(pcs + i, "pcs750.bin");
    264 	i = open(pcs, 0);
    265 	if (i < 0) {
    266 		printf("bad luck - missing pcs750.bin :-(\n");
    267 		return;
    268 	}
    269 	/*
    270 	 * We ask for more than we need to be sure we get only what we expect.
    271 	 * After read:
    272 	 *	locs 0 - 1023	packed patchbits
    273 	 *	 1024 - 11264	packed microcode
    274 	 */
    275 	if (read(i, (char *)0, 23*512) != 22*512) {
    276 		printf("Error reading %s\n", pcs);
    277 		close(i);
    278 		return;
    279 	}
    280 	close(i);
    281 
    282 	/*
    283 	 * Enable patchbit loading and load the bits one at a time.
    284 	 */
    285 	*((int *)PCS_PATCHBIT) = 1;
    286 	ip = (int *)PCS_PATCHADDR;
    287 	jp = (int *)0;
    288 	for (i=0; i < PCS_BITCNT; i++) {
    289 		extzv(i,jp,ip,1);
    290 	}
    291 	*((int *)PCS_PATCHBIT) = 0;
    292 
    293 	/*
    294 	 * Load PCS microcode 20 bits at a time.
    295 	 */
    296 	ip = (int *)PCS_PCSADDR;
    297 	jp = (int *)1024;
    298 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
    299 		extzv(i,jp,ip,20);
    300 	}
    301 
    302 	/*
    303 	 * Enable PCS.
    304 	 */
    305 	i = *jp;		/* get 1st 20 bits of microcode again */
    306 	i &= 0xfffff;
    307 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
    308 	*((int *)PCS_PCSADDR) = i;
    309 
    310 	mid = mfpr(PR_SID);
    311 	printf("new rev level=%d\n", V750UCODE(mid));
    312 	pcsdone = 1;
    313 }
    314 
    315 void
    316 usage(char *hej)
    317 {
    318 	const struct vals *v = &val[0];
    319 
    320 	printf("Commands:\n");
    321 	while (v->namn) {
    322 		printf("%s\t%s\n", v->namn, v->info);
    323 		v++;
    324 	}
    325 }
    326