Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.8
      1 /*	$NetBSD: boot.c,v 1.8 2000/05/25 19:36:20 matt 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(struct rpb *);
     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(struct rpb *prpb)
     95 {
     96 	int io;
     97 	int j, nu;
     98 
     99 	/* First copy rpb/bqo to its new location */
    100 	bcopy((caddr_t)prpb, &bootrpb, sizeof(struct rpb));
    101 	if (prpb->iovec) {
    102 		bootrpb.iovec = (int)alloc(prpb->iovecsz);
    103 		bcopy((caddr_t)prpb->iovec, (caddr_t)bootrpb.iovec,
    104 		    prpb->iovecsz);
    105 	}
    106 	io = 0;
    107 	skip = 1;
    108 	autoconf();
    109 
    110 	askname = bootrpb.rpb_bootr5 & RB_ASKNAME;
    111 	printf("\n\r>> NetBSD/vax boot [%s %s] <<\n", __DATE__, __TIME__);
    112 	printf(">> Press any key to abort autoboot  ");
    113 	sluttid = getsecs() + 5;
    114 	senast = 0;
    115 	skip = 0;
    116 	setjmp(jbuf);
    117 	for (;;) {
    118 		nu = sluttid - getsecs();
    119 		if (senast != nu)
    120 			printf("%c%d", 8, nu);
    121 		if (nu <= 0)
    122 			break;
    123 		senast = nu;
    124 		if ((j = (testkey() & 0177))) {
    125 			skip = 1;
    126 			if (j != 10 && j != 13) {
    127 				printf("\nPress '?' for help");
    128 				askname = 1;
    129 			}
    130 			break;
    131 		}
    132 	}
    133 	skip = 1;
    134 	printf("\n");
    135 
    136 	/* First try to autoboot */
    137 	if (askname == 0) {
    138 		int fileindex;
    139 		for (fileindex = 0; filelist[fileindex].name[0] != '\0'; fileindex++) {
    140 			errno = 0;
    141 			if (!filelist[fileindex].quiet)
    142 				printf("> boot %s\n", filelist[fileindex].name);
    143 			exec(filelist[fileindex].name, 0, 0);
    144 			if (!filelist[fileindex].quiet)
    145 				printf("%s: boot failed: %s\n",
    146 				    filelist[fileindex].name, strerror(errno));
    147 			if (testkey())
    148 				break;
    149 		}
    150 	}
    151 
    152 	/* If any key pressed, go to conversational boot */
    153 	for (;;) {
    154 		const struct vals *v = &val[0];
    155 		char *c, *d;
    156 
    157 		printf("> ");
    158 		gets(line);
    159 
    160 		c = line;
    161 		while (*c == ' ')
    162 			c++;
    163 
    164 		if (c[0] == 0)
    165 			continue;
    166 
    167 		if ((d = index(c, ' ')))
    168 			*d++ = 0;
    169 
    170 		while (v->namn) {
    171 			if (strcmp(v->namn, c) == 0)
    172 				break;
    173 			v++;
    174 		}
    175 		if (v->namn)
    176 			(*v->func)(d);
    177 		else
    178 			printf("Unknown command: %s\n", c);
    179 	}
    180 }
    181 
    182 void
    183 halt(char *hej)
    184 {
    185 	asm("halt");
    186 }
    187 
    188 void
    189 boot(char *arg)
    190 {
    191 	char *fn = "netbsd";
    192 
    193 	if (arg) {
    194 		while (*arg == ' ')
    195 			arg++;
    196 
    197 		if (*arg != '-') {
    198 			fn = arg;
    199 			if ((arg = index(arg, ' '))) {
    200 				*arg++ = 0;
    201 				while (*arg == ' ')
    202 					arg++;
    203 			} else
    204 				goto load;
    205 		}
    206 		if (*arg != '-') {
    207 fail:			printf("usage: boot [filename] [-asd]\n");
    208 			return;
    209 		}
    210 
    211 		while (*++arg) {
    212 			if (*arg == 'a')
    213 				bootrpb.rpb_bootr5 |= RB_ASKNAME;
    214 			else if (*arg == 'd')
    215 				bootrpb.rpb_bootr5 |= RB_KDB;
    216 			else if (*arg == 's')
    217 				bootrpb.rpb_bootr5 |= RB_SINGLE;
    218 			else
    219 				goto fail;
    220 		}
    221 	}
    222 load:	exec(fn, 0, 0);
    223 	printf("Boot failed: %s\n", strerror(errno));
    224 }
    225 
    226 /* 750 Patchable Control Store magic */
    227 
    228 #include "../include/mtpr.h"
    229 #include "../include/cpu.h"
    230 #include "../include/sid.h"
    231 #define	PCS_BITCNT	0x2000		/* number of patchbits */
    232 #define	PCS_MICRONUM	0x400		/* number of ucode locs */
    233 #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
    234 #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
    235 #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
    236 #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
    237 
    238 #define	extzv(one, two, three,four)	\
    239 ({			\
    240 	asm __volatile (" extzv %0,%3,(%1),(%2)+"	\
    241 			:			\
    242 			: "g"(one),"g"(two),"g"(three),"g"(four));	\
    243 })
    244 
    245 
    246 void
    247 loadpcs()
    248 {
    249 	static int pcsdone = 0;
    250 	int mid = mfpr(PR_SID);
    251 	int i, j, *ip, *jp;
    252 	char pcs[100];
    253 	char *cp;
    254 
    255 	if ((mid >> 24) != VAX_750 || ((mid >> 8) & 255) < 95 || pcsdone)
    256 		return;
    257 	printf("Updating 11/750 microcode: ");
    258 	for (cp = line; *cp; cp++)
    259 		if (*cp == ')' || *cp == ':')
    260 			break;
    261 	if (*cp) {
    262 		bcopy(line, pcs, 99);
    263 		pcs[99] = 0;
    264 		i = cp - line + 1;
    265 	} else
    266 		i = 0;
    267 	strcpy(pcs + i, "pcs750.bin");
    268 	i = open(pcs, 0);
    269 	if (i < 0) {
    270 		printf("bad luck - missing pcs750.bin :-(\n");
    271 		return;
    272 	}
    273 	/*
    274 	 * We ask for more than we need to be sure we get only what we expect.
    275 	 * After read:
    276 	 *	locs 0 - 1023	packed patchbits
    277 	 *	 1024 - 11264	packed microcode
    278 	 */
    279 	if (read(i, (char *)0, 23*512) != 22*512) {
    280 		printf("Error reading %s\n", pcs);
    281 		close(i);
    282 		return;
    283 	}
    284 	close(i);
    285 
    286 	/*
    287 	 * Enable patchbit loading and load the bits one at a time.
    288 	 */
    289 	*((int *)PCS_PATCHBIT) = 1;
    290 	ip = (int *)PCS_PATCHADDR;
    291 	jp = (int *)0;
    292 	for (i=0; i < PCS_BITCNT; i++) {
    293 		extzv(i,jp,ip,1);
    294 	}
    295 	*((int *)PCS_PATCHBIT) = 0;
    296 
    297 	/*
    298 	 * Load PCS microcode 20 bits at a time.
    299 	 */
    300 	ip = (int *)PCS_PCSADDR;
    301 	jp = (int *)1024;
    302 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
    303 		extzv(i,jp,ip,20);
    304 	}
    305 
    306 	/*
    307 	 * Enable PCS.
    308 	 */
    309 	i = *jp;		/* get 1st 20 bits of microcode again */
    310 	i &= 0xfffff;
    311 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
    312 	*((int *)PCS_PCSADDR) = i;
    313 
    314 	mid = mfpr(PR_SID);
    315 	printf("new rev level=%d\n", V750UCODE(mid));
    316 	pcsdone = 1;
    317 }
    318 
    319 void
    320 usage(char *hej)
    321 {
    322 	const struct vals *v = &val[0];
    323 
    324 	printf("Commands:\n");
    325 	while (v->namn) {
    326 		printf("%s\t%s\n", v->namn, v->info);
    327 		v++;
    328 	}
    329 }
    330