Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.12
      1 /*	$NetBSD: boot.c,v 1.12 2000/07/19 02:39:11 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 #include "lib/libsa/loadfile.h"
     41 #include "lib/libkern/libkern.h"
     42 
     43 #define V750UCODE(x)    ((x>>8)&255)
     44 
     45 #include "machine/rpb.h"
     46 
     47 #include "vaxstand.h"
     48 
     49 /*
     50  * Boot program... arguments passed in r10 and r11 determine
     51  * whether boot stops to ask for system name and which device
     52  * boot comes from.
     53  */
     54 
     55 char line[100];
     56 int	bootdev, debug;
     57 extern	unsigned opendev;
     58 
     59 void	usage(char *), boot(char *), halt(char *);
     60 void	Xmain(void);
     61 void	autoconf(void);
     62 int	getsecs(void);
     63 int	setjmp(int *);
     64 int	testkey(void);
     65 void	loadpcs(void);
     66 
     67 const struct vals {
     68 	char	*namn;
     69 	void	(*func)(char *);
     70 	char	*info;
     71 } val[] = {
     72 	{"?", usage, "Show this help menu"},
     73 	{"help", usage, "Same as '?'"},
     74 	{"boot", boot, "Load and execute file"},
     75 	{"halt", halt, "Halts the system"},
     76 	{0, 0},
     77 };
     78 
     79 static struct {
     80 	char name[12];
     81 	int quiet;
     82 } filelist[] = {
     83 	{ "netbsd.vax", 1 },
     84 	{ "netbsd", 0 },
     85 	{ "netbsd.gz", 0 },
     86 	{ "netbsd.old", 0 },
     87 	{ "gennetbsd", 0 },
     88 	{ "", 0 },
     89 };
     90 
     91 int jbuf[10];
     92 int sluttid, senast, skip, askname;
     93 struct rpb bootrpb;
     94 
     95 void
     96 Xmain(void)
     97 {
     98 	int io;
     99 	int j, nu;
    100 	u_long marks[MARK_MAX];
    101 
    102 	io = 0;
    103 	skip = 1;
    104 	autoconf();
    105 
    106 	askname = bootrpb.rpb_bootr5 & RB_ASKNAME;
    107 	printf("\n\r>> NetBSD/vax boot [%s %s] <<\n", __DATE__, __TIME__);
    108 	printf(">> Press any key to abort autoboot  ");
    109 	sluttid = getsecs() + 5;
    110 	senast = 0;
    111 	skip = 0;
    112 	setjmp(jbuf);
    113 	for (;;) {
    114 		nu = sluttid - getsecs();
    115 		if (senast != nu)
    116 			printf("%c%d", 8, nu);
    117 		if (nu <= 0)
    118 			break;
    119 		senast = nu;
    120 		if ((j = (testkey() & 0177))) {
    121 			skip = 1;
    122 			if (j != 10 && j != 13) {
    123 				printf("\nPress '?' for help");
    124 				askname = 1;
    125 			}
    126 			break;
    127 		}
    128 	}
    129 	skip = 1;
    130 	printf("\n");
    131 
    132 	/* First try to autoboot */
    133 	if (askname == 0) {
    134 		int fileindex;
    135 		for (fileindex = 0; filelist[fileindex].name[0] != '\0';
    136 		    fileindex++) {
    137 			int err;
    138 			errno = 0;
    139 			if (!filelist[fileindex].quiet)
    140 				printf("> boot %s\n", filelist[fileindex].name);
    141 			marks[MARK_START] = 0;
    142 			err = loadfile(filelist[fileindex].name, marks, LOAD_KERNEL|COUNT_KERNEL);
    143 			if (err == 0) {
    144 				machdep_start((char *)marks[MARK_ENTRY], 0,
    145 					      (void *)marks[MARK_START],
    146 					      (void *)marks[MARK_SYM],
    147 					      (void *)marks[MARK_END]);
    148 			}
    149 			if (!filelist[fileindex].quiet)
    150 				printf("%s: boot failed: %s\n",
    151 				    filelist[fileindex].name, strerror(errno));
    152 #if 0 /* Will hang VAX 4000 machines */
    153 			if (testkey())
    154 				break;
    155 #endif
    156 		}
    157 	}
    158 
    159 	/* If any key pressed, go to conversational boot */
    160 	for (;;) {
    161 		const struct vals *v = &val[0];
    162 		char *c, *d;
    163 
    164 		printf("> ");
    165 		gets(line);
    166 
    167 		c = line;
    168 		while (*c == ' ')
    169 			c++;
    170 
    171 		if (c[0] == 0)
    172 			continue;
    173 
    174 		if ((d = index(c, ' ')))
    175 			*d++ = 0;
    176 
    177 		while (v->namn) {
    178 			if (strcmp(v->namn, c) == 0)
    179 				break;
    180 			v++;
    181 		}
    182 		if (v->namn)
    183 			(*v->func)(d);
    184 		else
    185 			printf("Unknown command: %s\n", c);
    186 	}
    187 }
    188 
    189 void
    190 halt(char *hej)
    191 {
    192 	asm("halt");
    193 }
    194 
    195 void
    196 boot(char *arg)
    197 {
    198 	char *fn = "netbsd";
    199 
    200 	if (arg) {
    201 		while (*arg == ' ')
    202 			arg++;
    203 
    204 		if (*arg != '-') {
    205 			fn = arg;
    206 			if ((arg = index(arg, ' '))) {
    207 				*arg++ = 0;
    208 				while (*arg == ' ')
    209 					arg++;
    210 			} else
    211 				goto load;
    212 		}
    213 		if (*arg != '-') {
    214 fail:			printf("usage: boot [filename] [-asd]\n");
    215 			return;
    216 		}
    217 
    218 		while (*++arg) {
    219 			if (*arg == 'a')
    220 				bootrpb.rpb_bootr5 |= RB_ASKNAME;
    221 			else if (*arg == 'd')
    222 				bootrpb.rpb_bootr5 |= RB_KDB;
    223 			else if (*arg == 's')
    224 				bootrpb.rpb_bootr5 |= RB_SINGLE;
    225 			else
    226 				goto fail;
    227 		}
    228 	}
    229 load:	exec(fn, 0, 0);
    230 	printf("Boot failed: %s\n", strerror(errno));
    231 }
    232 
    233 /* 750 Patchable Control Store magic */
    234 
    235 #include "../include/mtpr.h"
    236 #include "../include/cpu.h"
    237 #include "../include/sid.h"
    238 #define	PCS_BITCNT	0x2000		/* number of patchbits */
    239 #define	PCS_MICRONUM	0x400		/* number of ucode locs */
    240 #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
    241 #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
    242 #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
    243 #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
    244 
    245 #define	extzv(one, two, three,four)	\
    246 ({			\
    247 	asm __volatile (" extzv %0,%3,(%1),(%2)+"	\
    248 			:			\
    249 			: "g"(one),"g"(two),"g"(three),"g"(four));	\
    250 })
    251 
    252 
    253 void
    254 loadpcs()
    255 {
    256 	static int pcsdone = 0;
    257 	int mid = mfpr(PR_SID);
    258 	int i, j, *ip, *jp;
    259 	char pcs[100];
    260 	char *cp;
    261 
    262 	if ((mid >> 24) != VAX_750 || ((mid >> 8) & 255) < 95 || pcsdone)
    263 		return;
    264 	printf("Updating 11/750 microcode: ");
    265 	for (cp = line; *cp; cp++)
    266 		if (*cp == ')' || *cp == ':')
    267 			break;
    268 	if (*cp) {
    269 		bcopy(line, pcs, 99);
    270 		pcs[99] = 0;
    271 		i = cp - line + 1;
    272 	} else
    273 		i = 0;
    274 	strcpy(pcs + i, "pcs750.bin");
    275 	i = open(pcs, 0);
    276 	if (i < 0) {
    277 		printf("bad luck - missing pcs750.bin :-(\n");
    278 		return;
    279 	}
    280 	/*
    281 	 * We ask for more than we need to be sure we get only what we expect.
    282 	 * After read:
    283 	 *	locs 0 - 1023	packed patchbits
    284 	 *	 1024 - 11264	packed microcode
    285 	 */
    286 	if (read(i, (char *)0, 23*512) != 22*512) {
    287 		printf("Error reading %s\n", pcs);
    288 		close(i);
    289 		return;
    290 	}
    291 	close(i);
    292 
    293 	/*
    294 	 * Enable patchbit loading and load the bits one at a time.
    295 	 */
    296 	*((int *)PCS_PATCHBIT) = 1;
    297 	ip = (int *)PCS_PATCHADDR;
    298 	jp = (int *)0;
    299 	for (i=0; i < PCS_BITCNT; i++) {
    300 		extzv(i,jp,ip,1);
    301 	}
    302 	*((int *)PCS_PATCHBIT) = 0;
    303 
    304 	/*
    305 	 * Load PCS microcode 20 bits at a time.
    306 	 */
    307 	ip = (int *)PCS_PCSADDR;
    308 	jp = (int *)1024;
    309 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
    310 		extzv(i,jp,ip,20);
    311 	}
    312 
    313 	/*
    314 	 * Enable PCS.
    315 	 */
    316 	i = *jp;		/* get 1st 20 bits of microcode again */
    317 	i &= 0xfffff;
    318 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
    319 	*((int *)PCS_PCSADDR) = i;
    320 
    321 	mid = mfpr(PR_SID);
    322 	printf("new rev level=%d\n", V750UCODE(mid));
    323 	pcsdone = 1;
    324 }
    325 
    326 void
    327 usage(char *hej)
    328 {
    329 	const struct vals *v = &val[0];
    330 
    331 	printf("Commands:\n");
    332 	while (v->namn) {
    333 		printf("%s\t%s\n", v->namn, v->info);
    334 		v++;
    335 	}
    336 }
    337