xref: /csrg-svn/sys/vax/stand/boot.c (revision 26828)
123219Smckusick /*
223219Smckusick  * Copyright (c) 1982 Regents of the University of California.
323219Smckusick  * All rights reserved.  The Berkeley software License Agreement
423219Smckusick  * specifies the terms and conditions for redistribution.
523219Smckusick  *
6*26828Skarels  *	@(#)boot.c	6.8 (Berkeley) 03/12/86
723219Smckusick  */
8315Sbill 
9315Sbill #include "../h/param.h"
10315Sbill #include "../h/inode.h"
116069Smckusic #include "../h/fs.h"
12315Sbill #include "../h/vm.h"
13315Sbill #include <a.out.h>
14315Sbill #include "saio.h"
156069Smckusic #include "../h/reboot.h"
16315Sbill 
171466Sbill /*
181466Sbill  * Boot program... arguments passed in r10 and r11 determine
191466Sbill  * whether boot stops to ask for system name and which device
201466Sbill  * boot comes from.
211466Sbill  */
22315Sbill 
231466Sbill /* Types in r10 specifying major device */
241466Sbill char	devname[][2] = {
251466Sbill 	'h','p',	/* 0 = hp */
261466Sbill 	0,0,		/* 1 = ht */
271466Sbill 	'u','p',	/* 2 = up */
283261Swnj 	'h','k',	/* 3 = hk */
294868Sroot 	0,0,		/* 4 = sw */
304868Sroot 	0,0,		/* 5 = tm */
314868Sroot 	0,0,		/* 6 = ts */
324868Sroot 	0,0,		/* 7 = mt */
334868Sroot 	0,0,		/* 8 = tu */
344868Sroot 	'r','a',	/* 9 = ra */
3511886Sleres 	'u','t',	/* 10 = ut */
3611886Sleres 	'r','b',	/* 11 = rb */
3713163Ssam 	0,0,		/* 12 = uu */
3813163Ssam 	0,0,		/* 13 = rx */
3913163Ssam 	'r','l',	/* 14 = rl */
401466Sbill };
41*26828Skarels #define	MAXTYPE	(sizeof(devname) / sizeof(devname[0]))
421466Sbill 
4325626Skarels #define	UNIX	"vmunix"
4425626Skarels char line[100];
4524217Sbloom 
463347Swnj int	retry = 0;
473347Swnj 
48315Sbill main()
49315Sbill {
50*26828Skarels 	register unsigned howto, devtype;	/* howto=r11, devtype=r10 */
51*26828Skarels 	int io, i;
5224217Sbloom 	register type, part, unit;
5325626Skarels 	register char *cp;
54*26828Skarels 	long atol();
55315Sbill 
563274Swnj #ifdef lint
573274Swnj 	howto = 0; devtype = 0;
583274Swnj #endif
5925626Skarels 	printf("\nBoot\n");
601575Sbill #ifdef JUSTASK
611593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
621575Sbill #else
63*26828Skarels 	type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
64*26828Skarels 	unit = (devtype >> B_UNITSHIFT) & B_UNITMASK;
65*26828Skarels 	unit += 8 * (devtype >> B_ADAPTORSHIFT) & B_ADAPTORMASK;
66*26828Skarels 	part = (devtype >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
67*26828Skarels 	if ((howto & RB_ASKNAME) == 0) {
68*26828Skarels 		if (type >= 0 && type <= MAXTYPE && devname[type][0]) {
6925626Skarels 			cp = line;
7025626Skarels 			*cp++ = devname[type][0];
7125626Skarels 			*cp++ = devname[type][1];
7225626Skarels 			*cp++ = '(';
7325626Skarels 			if (unit >= 10)
7425626Skarels 				*cp++ = unit / 10 + '0';
7525626Skarels 			*cp++ = unit % 10 + '0';
7625626Skarels 			*cp++ = ',';
7725626Skarels 			*cp++ = part + '0';
7825626Skarels 			*cp++ = ')';
7925626Skarels 			strcpy(cp, UNIX);
803261Swnj 		} else
811466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
821466Sbill 	}
831575Sbill #endif
841466Sbill 	for (;;) {
851466Sbill 		if (howto & RB_ASKNAME) {
861466Sbill 			printf(": ");
871466Sbill 			gets(line);
881466Sbill 		} else
891466Sbill 			printf(": %s\n", line);
901466Sbill 		io = open(line, 0);
9117198Stef 		if (io >= 0) {
92*26828Skarels 			if (howto & RB_ASKNAME) {
93*26828Skarels 				/*
94*26828Skarels 				 * Build up devtype register to pass on to
95*26828Skarels 				 * booted program.
96*26828Skarels 				 */
97*26828Skarels 				cp = line;
98*26828Skarels 				for (i = 0; i <= MAXTYPE; i++)
99*26828Skarels 					if ((devname[i][0] == cp[0]) &&
100*26828Skarels 					    (devname[i][1] == cp[1]))
101*26828Skarels 					    	break;
102*26828Skarels 				if (i <= MAXTYPE) {
103*26828Skarels 					devtype = i << B_TYPESHIFT;
104*26828Skarels 					cp += 3;
105*26828Skarels 					i = *cp++ - '0';
106*26828Skarels 					if (*cp >= '0' && *cp <= '9')
107*26828Skarels 						i = i * 10 + *cp++ - '0';
108*26828Skarels 					cp++;
109*26828Skarels 					devtype |= ((i % 8) << B_UNITSHIFT);
110*26828Skarels 					devtype |= ((i / 8) << B_ADAPTORSHIFT);
111*26828Skarels 					devtype |= atol(cp) << B_PARTITIONSHIFT;
112*26828Skarels 				}
113*26828Skarels 			}
11426503Skarels 			loadpcs();
115*26828Skarels 			copyunix(howto, devtype, io);
11625438Skarels 			close(io);
11725438Skarels 			howto = RB_SINGLE|RB_ASKNAME;
11817198Stef 		}
1191466Sbill 		if (++retry > 2)
1201466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
1211466Sbill 	}
122315Sbill }
123315Sbill 
1243347Swnj /*ARGSUSED*/
125*26828Skarels copyunix(howto, devtype, io)
126*26828Skarels 	register howto, devtype, io;	/* howto=r11, devtype=r10 */
127315Sbill {
128315Sbill 	struct exec x;
129315Sbill 	register int i;
130315Sbill 	char *addr;
131315Sbill 
132315Sbill 	i = read(io, (char *)&x, sizeof x);
1336069Smckusic 	if (i != sizeof x ||
1346069Smckusic 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
135315Sbill 		_stop("Bad format\n");
136315Sbill 	printf("%d", x.a_text);
1377444Sroot 	if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
1386069Smckusic 		goto shread;
139315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
140315Sbill 		goto shread;
141315Sbill 	addr = (char *)x.a_text;
1426069Smckusic 	if (x.a_magic == 0413 || x.a_magic == 0410)
1436069Smckusic 		while ((int)addr & CLOFSET)
1446069Smckusic 			*addr++ = 0;
145315Sbill 	printf("+%d", x.a_data);
146315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
147315Sbill 		goto shread;
148315Sbill 	addr += x.a_data;
149315Sbill 	printf("+%d", x.a_bss);
150315Sbill 	x.a_bss += 128*512;	/* slop */
151315Sbill 	for (i = 0; i < x.a_bss; i++)
152315Sbill 		*addr++ = 0;
153315Sbill 	x.a_entry &= 0x7fffffff;
154315Sbill 	printf(" start 0x%x\n", x.a_entry);
155315Sbill 	(*((int (*)()) x.a_entry))();
15625438Skarels 	return;
157315Sbill shread:
158315Sbill 	_stop("Short read\n");
159315Sbill }
16017198Stef 
16117198Stef /* 750 Patchable Control Store magic */
16217198Stef 
16317198Stef #include "../vax/mtpr.h"
16417198Stef #include "../vax/cpu.h"
16517198Stef #define	PCS_BITCNT	0x2000		/* number of patchbits */
16617198Stef #define	PCS_MICRONUM	0x400		/* number of ucode locs */
16717198Stef #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
16817198Stef #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
16917198Stef #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
17017198Stef #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
17117198Stef 
17217198Stef loadpcs()
17317198Stef {
17417198Stef 	register int *ip;	/* known to be r11 below */
17517198Stef 	register int i;		/* known to be r10 below */
17617198Stef 	register int *jp;	/* known to be r9 below */
17717198Stef 	register int j;
17826503Skarels 	static int pcsdone = 0;
17917198Stef 	union cpusid sid;
18017198Stef 	char pcs[100];
18124217Sbloom 	char *closeparen;
18224217Sbloom 	char *index();
18317198Stef 
18417198Stef 	sid.cpusid = mfpr(SID);
18526503Skarels 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
18617198Stef 		return;
18717198Stef 	printf("Updating 11/750 microcode: ");
18824217Sbloom 	strncpy(pcs, line, 99);
18924217Sbloom 	pcs[99] = 0;
19024217Sbloom 	closeparen = index(pcs, ')');
19124217Sbloom 	if (closeparen)
19224217Sbloom 		*(++closeparen) = 0;
19324217Sbloom 	else
19424217Sbloom 		return;
19517198Stef 	strcat(pcs, "pcs750.bin");
19617198Stef 	i = open(pcs, 0);
19717198Stef 	if (i < 0)
19817198Stef 		return;
19917198Stef 	/*
20017198Stef 	 * We ask for more than we need to be sure we get only what we expect.
20117198Stef 	 * After read:
20217198Stef 	 *	locs 0 - 1023	packed patchbits
20317198Stef 	 *	 1024 - 11264	packed microcode
20417198Stef 	 */
20517198Stef 	if (read(i, (char *)0, 23*512) != 22*512) {
20617198Stef 		printf("Error reading %s\n", pcs);
20717198Stef 		close(i);
20817198Stef 		return;
20917198Stef 	}
21017198Stef 	close(i);
21117198Stef 
21217198Stef 	/*
21317198Stef 	 * Enable patchbit loading and load the bits one at a time.
21417198Stef 	 */
21517198Stef 	*((int *)PCS_PATCHBIT) = 1;
21617198Stef 	ip = (int *)PCS_PATCHADDR;
21717198Stef 	jp = (int *)0;
21817198Stef 	for (i=0; i < PCS_BITCNT; i++) {
21917198Stef 		asm("	extzv	r10,$1,(r9),(r11)+");
22017198Stef 	}
22117198Stef 	*((int *)PCS_PATCHBIT) = 0;
22217198Stef 
22317198Stef 	/*
22417198Stef 	 * Load PCS microcode 20 bits at a time.
22517198Stef 	 */
22617198Stef 	ip = (int *)PCS_PCSADDR;
22717198Stef 	jp = (int *)1024;
22817198Stef 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
22917198Stef 		asm("	extzv	r10,$20,(r9),(r11)+");
23017198Stef 	}
23117198Stef 
23217198Stef 	/*
23317198Stef 	 * Enable PCS.
23417198Stef 	 */
23517198Stef 	i = *jp;		/* get 1st 20 bits of microcode again */
23617198Stef 	i &= 0xfffff;
23717198Stef 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
23817198Stef 	*((int *)PCS_PCSADDR) = i;
23917198Stef 
24017198Stef 	sid.cpusid = mfpr(SID);
24117198Stef 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
24226503Skarels 	pcsdone = 1;
24317198Stef }
244