xref: /csrg-svn/sys/vax/stand/boot.c (revision 26503)
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*26503Skarels  *	@(#)boot.c	6.7 (Berkeley) 03/08/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 };
411466Sbill 
4224217Sbloom /*
4324217Sbloom  * constants for converting a "minor" device numbers to unit number
4424217Sbloom  * and partition number
4524217Sbloom  */
4624217Sbloom #define UNITSHIFT	16
4724217Sbloom #define UNITMASK	0x1ff
4824217Sbloom #define PARTITIONMASK	0x7
4924217Sbloom #define PARTITIONSHIFT	3
501466Sbill 
5125626Skarels #define	UNIX	"vmunix"
5225626Skarels char line[100];
5324217Sbloom 
543347Swnj int	retry = 0;
553347Swnj 
56315Sbill main()
57315Sbill {
581466Sbill 	register howto, devtype;	/* howto=r11, devtype=r10 */
593347Swnj 	int io;
6024217Sbloom 	register type, part, unit;
6125626Skarels 	register char *cp;
62315Sbill 
633274Swnj #ifdef lint
643274Swnj 	howto = 0; devtype = 0;
653274Swnj #endif
6625626Skarels 	printf("\nBoot\n");
671575Sbill #ifdef JUSTASK
681593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
691575Sbill #else
7024217Sbloom 	type = devtype & 0xff;
7124217Sbloom 	unit = (int)((unsigned)devtype >> UNITSHIFT) & UNITMASK;
7224217Sbloom 	part = unit & PARTITIONMASK;
7324217Sbloom 	unit = unit >> PARTITIONSHIFT;
741466Sbill 	if ((howto&RB_ASKNAME)==0) {
7524217Sbloom 		if (type >= 0 && type < sizeof(devname) / 2
7624217Sbloom 		    && devname[type][0]) {
7725626Skarels 			cp = line;
7825626Skarels 			*cp++ = devname[type][0];
7925626Skarels 			*cp++ = devname[type][1];
8025626Skarels 			*cp++ = '(';
8125626Skarels 			if (unit >= 10)
8225626Skarels 				*cp++ = unit / 10 + '0';
8325626Skarels 			*cp++ = unit % 10 + '0';
8425626Skarels 			*cp++ = ',';
8525626Skarels 			*cp++ = part + '0';
8625626Skarels 			*cp++ = ')';
8725626Skarels 			strcpy(cp, UNIX);
883261Swnj 		} else
891466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
901466Sbill 	}
911575Sbill #endif
921466Sbill 	for (;;) {
931466Sbill 		if (howto & RB_ASKNAME) {
941466Sbill 			printf(": ");
951466Sbill 			gets(line);
961466Sbill 		} else
971466Sbill 			printf(": %s\n", line);
981466Sbill 		io = open(line, 0);
9917198Stef 		if (io >= 0) {
100*26503Skarels 			loadpcs();
1013347Swnj 			copyunix(howto, io);
10225438Skarels 			close(io);
10325438Skarels 			howto = RB_SINGLE|RB_ASKNAME;
10417198Stef 		}
1051466Sbill 		if (++retry > 2)
1061466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
1071466Sbill 	}
108315Sbill }
109315Sbill 
1103347Swnj /*ARGSUSED*/
1113347Swnj copyunix(howto, io)
1123347Swnj 	register howto, io;
113315Sbill {
114315Sbill 	struct exec x;
115315Sbill 	register int i;
116315Sbill 	char *addr;
117315Sbill 
118315Sbill 	i = read(io, (char *)&x, sizeof x);
1196069Smckusic 	if (i != sizeof x ||
1206069Smckusic 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
121315Sbill 		_stop("Bad format\n");
122315Sbill 	printf("%d", x.a_text);
1237444Sroot 	if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
1246069Smckusic 		goto shread;
125315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
126315Sbill 		goto shread;
127315Sbill 	addr = (char *)x.a_text;
1286069Smckusic 	if (x.a_magic == 0413 || x.a_magic == 0410)
1296069Smckusic 		while ((int)addr & CLOFSET)
1306069Smckusic 			*addr++ = 0;
131315Sbill 	printf("+%d", x.a_data);
132315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
133315Sbill 		goto shread;
134315Sbill 	addr += x.a_data;
135315Sbill 	printf("+%d", x.a_bss);
136315Sbill 	x.a_bss += 128*512;	/* slop */
137315Sbill 	for (i = 0; i < x.a_bss; i++)
138315Sbill 		*addr++ = 0;
139315Sbill 	x.a_entry &= 0x7fffffff;
140315Sbill 	printf(" start 0x%x\n", x.a_entry);
141315Sbill 	(*((int (*)()) x.a_entry))();
14225438Skarels 	return;
143315Sbill shread:
144315Sbill 	_stop("Short read\n");
145315Sbill }
14617198Stef 
147*26503Skarels #ifndef SMALL
14817198Stef /* 750 Patchable Control Store magic */
14917198Stef 
15017198Stef #include "../vax/mtpr.h"
15117198Stef #include "../vax/cpu.h"
15217198Stef #define	PCS_BITCNT	0x2000		/* number of patchbits */
15317198Stef #define	PCS_MICRONUM	0x400		/* number of ucode locs */
15417198Stef #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
15517198Stef #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
15617198Stef #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
15717198Stef #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
15817198Stef 
15917198Stef loadpcs()
16017198Stef {
16117198Stef 	register int *ip;	/* known to be r11 below */
16217198Stef 	register int i;		/* known to be r10 below */
16317198Stef 	register int *jp;	/* known to be r9 below */
16417198Stef 	register int j;
165*26503Skarels 	static int pcsdone = 0;
16617198Stef 	union cpusid sid;
16717198Stef 	char pcs[100];
16824217Sbloom 	char *closeparen;
16924217Sbloom 	char *index();
17017198Stef 
17117198Stef 	sid.cpusid = mfpr(SID);
172*26503Skarels 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
17317198Stef 		return;
17417198Stef 	printf("Updating 11/750 microcode: ");
17524217Sbloom 	strncpy(pcs, line, 99);
17624217Sbloom 	pcs[99] = 0;
17724217Sbloom 	closeparen = index(pcs, ')');
17824217Sbloom 	if (closeparen)
17924217Sbloom 		*(++closeparen) = 0;
18024217Sbloom 	else
18124217Sbloom 		return;
18217198Stef 	strcat(pcs, "pcs750.bin");
18317198Stef 	i = open(pcs, 0);
18417198Stef 	if (i < 0)
18517198Stef 		return;
18617198Stef 	/*
18717198Stef 	 * We ask for more than we need to be sure we get only what we expect.
18817198Stef 	 * After read:
18917198Stef 	 *	locs 0 - 1023	packed patchbits
19017198Stef 	 *	 1024 - 11264	packed microcode
19117198Stef 	 */
19217198Stef 	if (read(i, (char *)0, 23*512) != 22*512) {
19317198Stef 		printf("Error reading %s\n", pcs);
19417198Stef 		close(i);
19517198Stef 		return;
19617198Stef 	}
19717198Stef 	close(i);
19817198Stef 
19917198Stef 	/*
20017198Stef 	 * Enable patchbit loading and load the bits one at a time.
20117198Stef 	 */
20217198Stef 	*((int *)PCS_PATCHBIT) = 1;
20317198Stef 	ip = (int *)PCS_PATCHADDR;
20417198Stef 	jp = (int *)0;
20517198Stef 	for (i=0; i < PCS_BITCNT; i++) {
20617198Stef 		asm("	extzv	r10,$1,(r9),(r11)+");
20717198Stef 	}
20817198Stef 	*((int *)PCS_PATCHBIT) = 0;
20917198Stef 
21017198Stef 	/*
21117198Stef 	 * Load PCS microcode 20 bits at a time.
21217198Stef 	 */
21317198Stef 	ip = (int *)PCS_PCSADDR;
21417198Stef 	jp = (int *)1024;
21517198Stef 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
21617198Stef 		asm("	extzv	r10,$20,(r9),(r11)+");
21717198Stef 	}
21817198Stef 
21917198Stef 	/*
22017198Stef 	 * Enable PCS.
22117198Stef 	 */
22217198Stef 	i = *jp;		/* get 1st 20 bits of microcode again */
22317198Stef 	i &= 0xfffff;
22417198Stef 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
22517198Stef 	*((int *)PCS_PCSADDR) = i;
22617198Stef 
22717198Stef 	sid.cpusid = mfpr(SID);
22817198Stef 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
229*26503Skarels 	pcsdone = 1;
23017198Stef }
231*26503Skarels #endif SMALL
232