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