xref: /csrg-svn/sys/vax/stand/boot.c (revision 17198)
1*17198Stef /*	boot.c	6.2	84/09/18	*/
2315Sbill 
3315Sbill #include "../h/param.h"
4315Sbill #include "../h/inode.h"
56069Smckusic #include "../h/fs.h"
6315Sbill #include "../h/vm.h"
7315Sbill #include <a.out.h>
8315Sbill #include "saio.h"
96069Smckusic #include "../h/reboot.h"
10315Sbill 
111466Sbill /*
121466Sbill  * Boot program... arguments passed in r10 and r11 determine
131466Sbill  * whether boot stops to ask for system name and which device
141466Sbill  * boot comes from.
151466Sbill  */
16315Sbill 
171466Sbill /* Types in r10 specifying major device */
181466Sbill char	devname[][2] = {
191466Sbill 	'h','p',	/* 0 = hp */
201466Sbill 	0,0,		/* 1 = ht */
211466Sbill 	'u','p',	/* 2 = up */
223261Swnj 	'h','k',	/* 3 = hk */
234868Sroot 	0,0,		/* 4 = sw */
244868Sroot 	0,0,		/* 5 = tm */
254868Sroot 	0,0,		/* 6 = ts */
264868Sroot 	0,0,		/* 7 = mt */
274868Sroot 	0,0,		/* 8 = tu */
284868Sroot 	'r','a',	/* 9 = ra */
2911886Sleres 	'u','t',	/* 10 = ut */
3011886Sleres 	'r','b',	/* 11 = rb */
3113163Ssam 	0,0,		/* 12 = uu */
3213163Ssam 	0,0,		/* 13 = rx */
3313163Ssam 	'r','l',	/* 14 = rl */
341466Sbill };
351466Sbill 
361466Sbill char line[100] = "xx(0,0)vmunix";
371466Sbill 
383347Swnj int	retry = 0;
393347Swnj 
40315Sbill main()
41315Sbill {
421466Sbill 	register howto, devtype;	/* howto=r11, devtype=r10 */
433347Swnj 	int io;
44315Sbill 
453274Swnj #ifdef lint
463274Swnj 	howto = 0; devtype = 0;
473274Swnj #endif
48315Sbill 	printf("\nBoot\n");
491575Sbill #ifdef JUSTASK
501593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
511575Sbill #else
521466Sbill 	if ((howto&RB_ASKNAME)==0) {
531466Sbill 		if (devtype>=0 && devtype<sizeof(devname)/2
541466Sbill 		    && devname[devtype][0]) {
551466Sbill 			line[0] = devname[devtype][0];
561466Sbill 			line[1] = devname[devtype][1];
573261Swnj 		} else
581466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
591466Sbill 	}
601575Sbill #endif
611466Sbill 	for (;;) {
621466Sbill 		if (howto & RB_ASKNAME) {
631466Sbill 			printf(": ");
641466Sbill 			gets(line);
651466Sbill 		} else
661466Sbill 			printf(": %s\n", line);
671466Sbill 		io = open(line, 0);
68*17198Stef 		if (io >= 0) {
69*17198Stef 			loadpcs();
703347Swnj 			copyunix(howto, io);
71*17198Stef 		}
721466Sbill 		if (++retry > 2)
731466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
741466Sbill 	}
75315Sbill }
76315Sbill 
773347Swnj /*ARGSUSED*/
783347Swnj copyunix(howto, io)
793347Swnj 	register howto, io;
80315Sbill {
81315Sbill 	struct exec x;
82315Sbill 	register int i;
83315Sbill 	char *addr;
84315Sbill 
85315Sbill 	i = read(io, (char *)&x, sizeof x);
866069Smckusic 	if (i != sizeof x ||
876069Smckusic 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
88315Sbill 		_stop("Bad format\n");
89315Sbill 	printf("%d", x.a_text);
907444Sroot 	if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
916069Smckusic 		goto shread;
92315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
93315Sbill 		goto shread;
94315Sbill 	addr = (char *)x.a_text;
956069Smckusic 	if (x.a_magic == 0413 || x.a_magic == 0410)
966069Smckusic 		while ((int)addr & CLOFSET)
976069Smckusic 			*addr++ = 0;
98315Sbill 	printf("+%d", x.a_data);
99315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
100315Sbill 		goto shread;
101315Sbill 	addr += x.a_data;
102315Sbill 	printf("+%d", x.a_bss);
103315Sbill 	x.a_bss += 128*512;	/* slop */
104315Sbill 	for (i = 0; i < x.a_bss; i++)
105315Sbill 		*addr++ = 0;
106315Sbill 	x.a_entry &= 0x7fffffff;
107315Sbill 	printf(" start 0x%x\n", x.a_entry);
108315Sbill 	(*((int (*)()) x.a_entry))();
109315Sbill 	_exit();
110315Sbill shread:
111315Sbill 	_stop("Short read\n");
112315Sbill }
113*17198Stef 
114*17198Stef /* 750 Patchable Control Store magic */
115*17198Stef 
116*17198Stef #include "../vax/mtpr.h"
117*17198Stef #include "../vax/cpu.h"
118*17198Stef #define	PCS_BITCNT	0x2000		/* number of patchbits */
119*17198Stef #define	PCS_MICRONUM	0x400		/* number of ucode locs */
120*17198Stef #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
121*17198Stef #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
122*17198Stef #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
123*17198Stef #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
124*17198Stef 
125*17198Stef loadpcs()
126*17198Stef {
127*17198Stef 	register int *ip;	/* known to be r11 below */
128*17198Stef 	register int i;		/* known to be r10 below */
129*17198Stef 	register int *jp;	/* known to be r9 below */
130*17198Stef 	register int j;
131*17198Stef 	static int pcsdone = 0;
132*17198Stef 	union cpusid sid;
133*17198Stef 	char pcs[100];
134*17198Stef 
135*17198Stef 	sid.cpusid = mfpr(SID);
136*17198Stef 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
137*17198Stef 		return;
138*17198Stef 	printf("Updating 11/750 microcode: ");
139*17198Stef 	strncpy(pcs, line, strlen("xx(0,0)"));
140*17198Stef 	strcat(pcs, "pcs750.bin");
141*17198Stef 	i = open(pcs, 0);
142*17198Stef 	if (i < 0)
143*17198Stef 		return;
144*17198Stef 	/*
145*17198Stef 	 * We ask for more than we need to be sure we get only what we expect.
146*17198Stef 	 * After read:
147*17198Stef 	 *	locs 0 - 1023	packed patchbits
148*17198Stef 	 *	 1024 - 11264	packed microcode
149*17198Stef 	 */
150*17198Stef 	if (read(i, (char *)0, 23*512) != 22*512) {
151*17198Stef 		printf("Error reading %s\n", pcs);
152*17198Stef 		close(i);
153*17198Stef 		return;
154*17198Stef 	}
155*17198Stef 	close(i);
156*17198Stef 
157*17198Stef 	/*
158*17198Stef 	 * Enable patchbit loading and load the bits one at a time.
159*17198Stef 	 */
160*17198Stef 	*((int *)PCS_PATCHBIT) = 1;
161*17198Stef 	ip = (int *)PCS_PATCHADDR;
162*17198Stef 	jp = (int *)0;
163*17198Stef 	for (i=0; i < PCS_BITCNT; i++) {
164*17198Stef 		asm("	extzv	r10,$1,(r9),(r11)+");
165*17198Stef 	}
166*17198Stef 	*((int *)PCS_PATCHBIT) = 0;
167*17198Stef 
168*17198Stef 	/*
169*17198Stef 	 * Load PCS microcode 20 bits at a time.
170*17198Stef 	 */
171*17198Stef 	ip = (int *)PCS_PCSADDR;
172*17198Stef 	jp = (int *)1024;
173*17198Stef 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
174*17198Stef 		asm("	extzv	r10,$20,(r9),(r11)+");
175*17198Stef 	}
176*17198Stef 
177*17198Stef 	/*
178*17198Stef 	 * Enable PCS.
179*17198Stef 	 */
180*17198Stef 	i = *jp;		/* get 1st 20 bits of microcode again */
181*17198Stef 	i &= 0xfffff;
182*17198Stef 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
183*17198Stef 	*((int *)PCS_PCSADDR) = i;
184*17198Stef 
185*17198Stef 	sid.cpusid = mfpr(SID);
186*17198Stef 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
187*17198Stef 	pcsdone = 1;
188*17198Stef }
189