Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.1
      1 /*	$NetBSD: boot.c,v 1.1 1999/03/06 16:36:05 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 <a.out.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	devtype, bootdev, howto;
     55 extern	unsigned opendev;
     56 extern  unsigned *bootregs;
     57 
     58 void	usage(), boot();
     59 
     60 struct vals {
     61 	char	*namn;
     62 	void	(*func)();
     63 	char	*info;
     64 } val[] = {
     65 	{"?", usage, "Show this help menu"},
     66 	{"help", usage, "Same as '?'"},
     67 	{"boot", exec, "load and execute file"},
     68 	{0, 0},
     69 };
     70 
     71 char *filer[] = {
     72 	"netbsd",
     73 	"netbsd.gz",
     74 	"netbsd.old",
     75 	"gennetbsd",
     76 	0,
     77 };
     78 
     79 Xmain()
     80 {
     81 	int io, type, sluttid, askname, filindex = 0;
     82 	volatile int i, j;
     83 
     84 	io=0;
     85 	autoconf();
     86 
     87 	askname = howto & RB_ASKNAME;
     88 	printf("\n\r>> NetBSD/vax boot [%s %s] <<\n", __DATE__, __TIME__);
     89 	printf(">> Press any key to abort autoboot  ");
     90 	sluttid = getsecs() + 5;
     91 	for (;;) {
     92 		printf("%c%d", 8, sluttid - getsecs());
     93 		if (sluttid <= getsecs())
     94 			break;
     95 		if ((j = (testkey() & 0177))) {
     96 			if (j != 10 && j != 13) {
     97 				printf("\nPress '?' for help");
     98 				askname = 1;
     99 			}
    100 			break;
    101 		}
    102 		for (i = 10000;i; i--)/* Don't read the timer chip too often */
    103 			;
    104 	}
    105 	printf("\n");
    106 
    107 	if (askname == 0) {
    108 		type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
    109 		if ((unsigned)type < ndevs && devsw[type].dv_name)
    110 			while (filer[filindex]) {
    111 				errno = 0;
    112 				printf("> boot %s\n", filer[filindex]);
    113 				exec(filer[filindex++], 0, 0);
    114 				printf("boot failed: %s\n", strerror(errno));
    115 				if (testkey())
    116 					break;
    117 			}
    118 	}
    119 
    120 	for (;;) {
    121 		struct vals *v = &val[0];
    122 		char *c, *d;
    123 
    124 start:		printf("> ");
    125 		gets(line);
    126 		if (line[0] == 0)
    127 			continue;
    128 
    129 		if ((c = index(line, ' '))) {
    130 			*c++ = 0;
    131 			while (*c == ' ')
    132 				c++;
    133 		}
    134 
    135 		/* If *c != '-' then it is a filename */
    136 		if (c) {
    137 			if (*c == '-') {
    138 				d = c;
    139 				c = filer[0];
    140 			} else {
    141 				d = index(c, ' ');
    142 				if (d) {
    143 					*d++ = 0;
    144 					if (*d != '-')
    145 						goto fail;
    146 				}
    147 			}
    148 
    149 			while (*++d) {
    150 				if (*d == 'a')
    151 					howto |= RB_ASKNAME;
    152 				else if (*d == 'd')
    153 					howto |= RB_KDB;
    154 				else if (*d == 's')
    155 					howto |= RB_SINGLE;
    156 #ifdef notyet
    157 				else if (*d == 'r')
    158 					rawread++;
    159 #endif
    160 				else {
    161 fail:				printf("usage: boot [filename] [-asd]\n");
    162 					goto start;
    163 				}
    164 			}
    165 		} else
    166 			c = filer[0];
    167 		while (v->namn) {
    168 			if (strcmp(v->namn, line) == 0)
    169 				break;
    170 			v++;
    171 		}
    172 		errno = 0;
    173 		if (v->namn)
    174 			(*v->func)(c, 0, 0);
    175 		else
    176 			printf("Unknown command: %s %s\n", line, (c ? c : ""));
    177 		if (errno)
    178 			printf("Command failed: %s\n", strerror(errno));
    179 	}
    180 }
    181 
    182 /* 750 Patchable Control Store magic */
    183 
    184 #include "../include/mtpr.h"
    185 #include "../include/cpu.h"
    186 #include "../include/sid.h"
    187 #define	PCS_BITCNT	0x2000		/* number of patchbits */
    188 #define	PCS_MICRONUM	0x400		/* number of ucode locs */
    189 #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
    190 #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
    191 #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
    192 #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
    193 
    194 #define	extzv(one, two, three,four)	\
    195 ({			\
    196 	asm __volatile (" extzv %0,%3,(%1),(%2)+"	\
    197 			:			\
    198 			: "g"(one),"g"(two),"g"(three),"g"(four));	\
    199 })
    200 
    201 
    202 loadpcs()
    203 {
    204 	static int pcsdone = 0;
    205 	int mid = mfpr(PR_SID);
    206 	int i, j, *ip, *jp;
    207 	char pcs[100];
    208 	char *cp;
    209 
    210 	if ((mid >> 24) != VAX_750 || ((mid >> 8) & 255) < 95 || pcsdone)
    211 		return;
    212 	printf("Updating 11/750 microcode: ");
    213 	for (cp = line; *cp; cp++)
    214 		if (*cp == ')' || *cp == ':')
    215 			break;
    216 	if (*cp) {
    217 		bcopy(line, pcs, 99);
    218 		pcs[99] = 0;
    219 		i = cp - line + 1;
    220 	} else
    221 		i = 0;
    222 	strcpy(pcs + i, "pcs750.bin");
    223 	i = open(pcs, 0);
    224 	if (i < 0) {
    225 		printf("bad luck - missing pcs750.bin :-(\n");
    226 		return;
    227 	}
    228 	/*
    229 	 * We ask for more than we need to be sure we get only what we expect.
    230 	 * After read:
    231 	 *	locs 0 - 1023	packed patchbits
    232 	 *	 1024 - 11264	packed microcode
    233 	 */
    234 	if (read(i, (char *)0, 23*512) != 22*512) {
    235 		printf("Error reading %s\n", pcs);
    236 		close(i);
    237 		return;
    238 	}
    239 	close(i);
    240 
    241 	/*
    242 	 * Enable patchbit loading and load the bits one at a time.
    243 	 */
    244 	*((int *)PCS_PATCHBIT) = 1;
    245 	ip = (int *)PCS_PATCHADDR;
    246 	jp = (int *)0;
    247 	for (i=0; i < PCS_BITCNT; i++) {
    248 		extzv(i,jp,ip,1);
    249 	}
    250 	*((int *)PCS_PATCHBIT) = 0;
    251 
    252 	/*
    253 	 * Load PCS microcode 20 bits at a time.
    254 	 */
    255 	ip = (int *)PCS_PCSADDR;
    256 	jp = (int *)1024;
    257 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
    258 		extzv(i,jp,ip,20);
    259 	}
    260 
    261 	/*
    262 	 * Enable PCS.
    263 	 */
    264 	i = *jp;		/* get 1st 20 bits of microcode again */
    265 	i &= 0xfffff;
    266 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
    267 	*((int *)PCS_PCSADDR) = i;
    268 
    269 	mid = mfpr(PR_SID);
    270 	printf("new rev level=%d\n", V750UCODE(mid));
    271 	pcsdone = 1;
    272 }
    273 
    274 void
    275 usage()
    276 {
    277 	struct vals *v = &val[0];
    278 
    279 	printf("Commands:\n");
    280 	while (v->namn) {
    281 		printf("%s\t%s\n", v->namn, v->info);
    282 		v++;
    283 	}
    284 }
    285