xref: /csrg-svn/sys/vax/stand/boot.c (revision 24217)
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*24217Sbloom  *	@(#)boot.c	6.4 (Berkeley) 08/08/85
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 
42*24217Sbloom /*
43*24217Sbloom  * constants for converting a "minor" device numbers to unit number
44*24217Sbloom  * and partition number
45*24217Sbloom  */
46*24217Sbloom #define UNITSHIFT	16
47*24217Sbloom #define UNITMASK	0x1ff
48*24217Sbloom #define PARTITIONMASK	0x7
49*24217Sbloom #define PARTITIONSHIFT	3
501466Sbill 
51*24217Sbloom char line[100] = "xx(00,0)vmunix";
52*24217Sbloom 
533347Swnj int	retry = 0;
543347Swnj 
55315Sbill main()
56315Sbill {
571466Sbill 	register howto, devtype;	/* howto=r11, devtype=r10 */
583347Swnj 	int io;
59*24217Sbloom 	register type, part, unit;
60315Sbill 
613274Swnj #ifdef lint
623274Swnj 	howto = 0; devtype = 0;
633274Swnj #endif
64315Sbill 	printf("\nBoot\n");
651575Sbill #ifdef JUSTASK
661593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
671575Sbill #else
68*24217Sbloom 	type = devtype & 0xff;
69*24217Sbloom 	unit = (int)((unsigned)devtype >> UNITSHIFT) & UNITMASK;
70*24217Sbloom 	part = unit & PARTITIONMASK;
71*24217Sbloom 	unit = unit >> PARTITIONSHIFT;
721466Sbill 	if ((howto&RB_ASKNAME)==0) {
73*24217Sbloom 		if (type >= 0 && type < sizeof(devname) / 2
74*24217Sbloom 		    && devname[type][0]) {
75*24217Sbloom 			line[0] = devname[type][0];
76*24217Sbloom 			line[1] = devname[type][1];
77*24217Sbloom 			line[3] = unit / 10 + '0';
78*24217Sbloom 			line[4] = unit % 10 + '0';
79*24217Sbloom 			line[6] = part + '0';
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) {
9217198Stef 			loadpcs();
933347Swnj 			copyunix(howto, io);
9417198Stef 		}
951466Sbill 		if (++retry > 2)
961466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
971466Sbill 	}
98315Sbill }
99315Sbill 
1003347Swnj /*ARGSUSED*/
1013347Swnj copyunix(howto, io)
1023347Swnj 	register howto, io;
103315Sbill {
104315Sbill 	struct exec x;
105315Sbill 	register int i;
106315Sbill 	char *addr;
107315Sbill 
108315Sbill 	i = read(io, (char *)&x, sizeof x);
1096069Smckusic 	if (i != sizeof x ||
1106069Smckusic 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
111315Sbill 		_stop("Bad format\n");
112315Sbill 	printf("%d", x.a_text);
1137444Sroot 	if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
1146069Smckusic 		goto shread;
115315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
116315Sbill 		goto shread;
117315Sbill 	addr = (char *)x.a_text;
1186069Smckusic 	if (x.a_magic == 0413 || x.a_magic == 0410)
1196069Smckusic 		while ((int)addr & CLOFSET)
1206069Smckusic 			*addr++ = 0;
121315Sbill 	printf("+%d", x.a_data);
122315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
123315Sbill 		goto shread;
124315Sbill 	addr += x.a_data;
125315Sbill 	printf("+%d", x.a_bss);
126315Sbill 	x.a_bss += 128*512;	/* slop */
127315Sbill 	for (i = 0; i < x.a_bss; i++)
128315Sbill 		*addr++ = 0;
129315Sbill 	x.a_entry &= 0x7fffffff;
130315Sbill 	printf(" start 0x%x\n", x.a_entry);
131315Sbill 	(*((int (*)()) x.a_entry))();
132315Sbill 	_exit();
133315Sbill shread:
134315Sbill 	_stop("Short read\n");
135315Sbill }
13617198Stef 
13717198Stef /* 750 Patchable Control Store magic */
13817198Stef 
13917198Stef #include "../vax/mtpr.h"
14017198Stef #include "../vax/cpu.h"
14117198Stef #define	PCS_BITCNT	0x2000		/* number of patchbits */
14217198Stef #define	PCS_MICRONUM	0x400		/* number of ucode locs */
14317198Stef #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
14417198Stef #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
14517198Stef #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
14617198Stef #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
14717198Stef 
14817198Stef loadpcs()
14917198Stef {
15017198Stef 	register int *ip;	/* known to be r11 below */
15117198Stef 	register int i;		/* known to be r10 below */
15217198Stef 	register int *jp;	/* known to be r9 below */
15317198Stef 	register int j;
15417198Stef 	static int pcsdone = 0;
15517198Stef 	union cpusid sid;
15617198Stef 	char pcs[100];
157*24217Sbloom 	char *closeparen;
158*24217Sbloom 	char *index();
15917198Stef 
16017198Stef 	sid.cpusid = mfpr(SID);
16117198Stef 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
16217198Stef 		return;
16317198Stef 	printf("Updating 11/750 microcode: ");
164*24217Sbloom 	strncpy(pcs, line, 99);
165*24217Sbloom 	pcs[99] = 0;
166*24217Sbloom 	closeparen = index(pcs, ')');
167*24217Sbloom 	if (closeparen)
168*24217Sbloom 		*(++closeparen) = 0;
169*24217Sbloom 	else
170*24217Sbloom 		return;
17117198Stef 	strcat(pcs, "pcs750.bin");
17217198Stef 	i = open(pcs, 0);
17317198Stef 	if (i < 0)
17417198Stef 		return;
17517198Stef 	/*
17617198Stef 	 * We ask for more than we need to be sure we get only what we expect.
17717198Stef 	 * After read:
17817198Stef 	 *	locs 0 - 1023	packed patchbits
17917198Stef 	 *	 1024 - 11264	packed microcode
18017198Stef 	 */
18117198Stef 	if (read(i, (char *)0, 23*512) != 22*512) {
18217198Stef 		printf("Error reading %s\n", pcs);
18317198Stef 		close(i);
18417198Stef 		return;
18517198Stef 	}
18617198Stef 	close(i);
18717198Stef 
18817198Stef 	/*
18917198Stef 	 * Enable patchbit loading and load the bits one at a time.
19017198Stef 	 */
19117198Stef 	*((int *)PCS_PATCHBIT) = 1;
19217198Stef 	ip = (int *)PCS_PATCHADDR;
19317198Stef 	jp = (int *)0;
19417198Stef 	for (i=0; i < PCS_BITCNT; i++) {
19517198Stef 		asm("	extzv	r10,$1,(r9),(r11)+");
19617198Stef 	}
19717198Stef 	*((int *)PCS_PATCHBIT) = 0;
19817198Stef 
19917198Stef 	/*
20017198Stef 	 * Load PCS microcode 20 bits at a time.
20117198Stef 	 */
20217198Stef 	ip = (int *)PCS_PCSADDR;
20317198Stef 	jp = (int *)1024;
20417198Stef 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
20517198Stef 		asm("	extzv	r10,$20,(r9),(r11)+");
20617198Stef 	}
20717198Stef 
20817198Stef 	/*
20917198Stef 	 * Enable PCS.
21017198Stef 	 */
21117198Stef 	i = *jp;		/* get 1st 20 bits of microcode again */
21217198Stef 	i &= 0xfffff;
21317198Stef 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
21417198Stef 	*((int *)PCS_PCSADDR) = i;
21517198Stef 
21617198Stef 	sid.cpusid = mfpr(SID);
21717198Stef 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
21817198Stef 	pcsdone = 1;
21917198Stef }
220