xref: /csrg-svn/sys/vax/stand/boot.c (revision 26872)
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*26872Skarels  *	@(#)boot.c	6.9 (Berkeley) 03/13/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 };
4126828Skarels #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 {
5026828Skarels 	register unsigned howto, devtype;	/* howto=r11, devtype=r10 */
5126828Skarels 	int io, i;
5224217Sbloom 	register type, part, unit;
5325626Skarels 	register char *cp;
5426828Skarels 	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
6326828Skarels 	type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
6426828Skarels 	unit = (devtype >> B_UNITSHIFT) & B_UNITMASK;
6526828Skarels 	unit += 8 * (devtype >> B_ADAPTORSHIFT) & B_ADAPTORMASK;
6626828Skarels 	part = (devtype >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
6726828Skarels 	if ((howto & RB_ASKNAME) == 0) {
6826828Skarels 		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) {
9226828Skarels 			if (howto & RB_ASKNAME) {
9326828Skarels 				/*
9426828Skarels 				 * Build up devtype register to pass on to
9526828Skarels 				 * booted program.
9626828Skarels 				 */
9726828Skarels 				cp = line;
9826828Skarels 				for (i = 0; i <= MAXTYPE; i++)
9926828Skarels 					if ((devname[i][0] == cp[0]) &&
10026828Skarels 					    (devname[i][1] == cp[1]))
10126828Skarels 					    	break;
10226828Skarels 				if (i <= MAXTYPE) {
10326828Skarels 					devtype = i << B_TYPESHIFT;
10426828Skarels 					cp += 3;
10526828Skarels 					i = *cp++ - '0';
10626828Skarels 					if (*cp >= '0' && *cp <= '9')
10726828Skarels 						i = i * 10 + *cp++ - '0';
10826828Skarels 					cp++;
10926828Skarels 					devtype |= ((i % 8) << B_UNITSHIFT);
11026828Skarels 					devtype |= ((i / 8) << B_ADAPTORSHIFT);
11126828Skarels 					devtype |= atol(cp) << B_PARTITIONSHIFT;
11226828Skarels 				}
11326828Skarels 			}
114*26872Skarels 			devtype |= B_DEVMAGIC;
11526503Skarels 			loadpcs();
11626828Skarels 			copyunix(howto, devtype, io);
11725438Skarels 			close(io);
11825438Skarels 			howto = RB_SINGLE|RB_ASKNAME;
11917198Stef 		}
1201466Sbill 		if (++retry > 2)
1211466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
1221466Sbill 	}
123315Sbill }
124315Sbill 
1253347Swnj /*ARGSUSED*/
12626828Skarels copyunix(howto, devtype, io)
12726828Skarels 	register howto, devtype, io;	/* howto=r11, devtype=r10 */
128315Sbill {
129315Sbill 	struct exec x;
130315Sbill 	register int i;
131315Sbill 	char *addr;
132315Sbill 
133315Sbill 	i = read(io, (char *)&x, sizeof x);
1346069Smckusic 	if (i != sizeof x ||
1356069Smckusic 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
136315Sbill 		_stop("Bad format\n");
137315Sbill 	printf("%d", x.a_text);
1387444Sroot 	if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
1396069Smckusic 		goto shread;
140315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
141315Sbill 		goto shread;
142315Sbill 	addr = (char *)x.a_text;
1436069Smckusic 	if (x.a_magic == 0413 || x.a_magic == 0410)
1446069Smckusic 		while ((int)addr & CLOFSET)
1456069Smckusic 			*addr++ = 0;
146315Sbill 	printf("+%d", x.a_data);
147315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
148315Sbill 		goto shread;
149315Sbill 	addr += x.a_data;
150315Sbill 	printf("+%d", x.a_bss);
151315Sbill 	x.a_bss += 128*512;	/* slop */
152315Sbill 	for (i = 0; i < x.a_bss; i++)
153315Sbill 		*addr++ = 0;
154315Sbill 	x.a_entry &= 0x7fffffff;
155315Sbill 	printf(" start 0x%x\n", x.a_entry);
156315Sbill 	(*((int (*)()) x.a_entry))();
15725438Skarels 	return;
158315Sbill shread:
159315Sbill 	_stop("Short read\n");
160315Sbill }
16117198Stef 
16217198Stef /* 750 Patchable Control Store magic */
16317198Stef 
16417198Stef #include "../vax/mtpr.h"
16517198Stef #include "../vax/cpu.h"
16617198Stef #define	PCS_BITCNT	0x2000		/* number of patchbits */
16717198Stef #define	PCS_MICRONUM	0x400		/* number of ucode locs */
16817198Stef #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
16917198Stef #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
17017198Stef #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
17117198Stef #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
17217198Stef 
17317198Stef loadpcs()
17417198Stef {
17517198Stef 	register int *ip;	/* known to be r11 below */
17617198Stef 	register int i;		/* known to be r10 below */
17717198Stef 	register int *jp;	/* known to be r9 below */
17817198Stef 	register int j;
17926503Skarels 	static int pcsdone = 0;
18017198Stef 	union cpusid sid;
18117198Stef 	char pcs[100];
18224217Sbloom 	char *closeparen;
18324217Sbloom 	char *index();
18417198Stef 
18517198Stef 	sid.cpusid = mfpr(SID);
18626503Skarels 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
18717198Stef 		return;
18817198Stef 	printf("Updating 11/750 microcode: ");
18924217Sbloom 	strncpy(pcs, line, 99);
19024217Sbloom 	pcs[99] = 0;
19124217Sbloom 	closeparen = index(pcs, ')');
19224217Sbloom 	if (closeparen)
19324217Sbloom 		*(++closeparen) = 0;
19424217Sbloom 	else
19524217Sbloom 		return;
19617198Stef 	strcat(pcs, "pcs750.bin");
19717198Stef 	i = open(pcs, 0);
19817198Stef 	if (i < 0)
19917198Stef 		return;
20017198Stef 	/*
20117198Stef 	 * We ask for more than we need to be sure we get only what we expect.
20217198Stef 	 * After read:
20317198Stef 	 *	locs 0 - 1023	packed patchbits
20417198Stef 	 *	 1024 - 11264	packed microcode
20517198Stef 	 */
20617198Stef 	if (read(i, (char *)0, 23*512) != 22*512) {
20717198Stef 		printf("Error reading %s\n", pcs);
20817198Stef 		close(i);
20917198Stef 		return;
21017198Stef 	}
21117198Stef 	close(i);
21217198Stef 
21317198Stef 	/*
21417198Stef 	 * Enable patchbit loading and load the bits one at a time.
21517198Stef 	 */
21617198Stef 	*((int *)PCS_PATCHBIT) = 1;
21717198Stef 	ip = (int *)PCS_PATCHADDR;
21817198Stef 	jp = (int *)0;
21917198Stef 	for (i=0; i < PCS_BITCNT; i++) {
22017198Stef 		asm("	extzv	r10,$1,(r9),(r11)+");
22117198Stef 	}
22217198Stef 	*((int *)PCS_PATCHBIT) = 0;
22317198Stef 
22417198Stef 	/*
22517198Stef 	 * Load PCS microcode 20 bits at a time.
22617198Stef 	 */
22717198Stef 	ip = (int *)PCS_PCSADDR;
22817198Stef 	jp = (int *)1024;
22917198Stef 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
23017198Stef 		asm("	extzv	r10,$20,(r9),(r11)+");
23117198Stef 	}
23217198Stef 
23317198Stef 	/*
23417198Stef 	 * Enable PCS.
23517198Stef 	 */
23617198Stef 	i = *jp;		/* get 1st 20 bits of microcode again */
23717198Stef 	i &= 0xfffff;
23817198Stef 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
23917198Stef 	*((int *)PCS_PCSADDR) = i;
24017198Stef 
24117198Stef 	sid.cpusid = mfpr(SID);
24217198Stef 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
24326503Skarels 	pcsdone = 1;
24417198Stef }
245