xref: /csrg-svn/sys/vax/stand/boot.c (revision 25626)
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*25626Skarels  *	@(#)boot.c	6.6 (Berkeley) 12/19/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 
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 
51*25626Skarels #define	UNIX	"vmunix"
52*25626Skarels 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;
61*25626Skarels 	register char *cp;
62315Sbill 
633274Swnj #ifdef lint
643274Swnj 	howto = 0; devtype = 0;
653274Swnj #endif
66*25626Skarels 	printf("\nBoot\n");
6725438Skarels 	loadpcs();
681575Sbill #ifdef JUSTASK
691593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
701575Sbill #else
7124217Sbloom 	type = devtype & 0xff;
7224217Sbloom 	unit = (int)((unsigned)devtype >> UNITSHIFT) & UNITMASK;
7324217Sbloom 	part = unit & PARTITIONMASK;
7424217Sbloom 	unit = unit >> PARTITIONSHIFT;
751466Sbill 	if ((howto&RB_ASKNAME)==0) {
7624217Sbloom 		if (type >= 0 && type < sizeof(devname) / 2
7724217Sbloom 		    && devname[type][0]) {
78*25626Skarels 			cp = line;
79*25626Skarels 			*cp++ = devname[type][0];
80*25626Skarels 			*cp++ = devname[type][1];
81*25626Skarels 			*cp++ = '(';
82*25626Skarels 			if (unit >= 10)
83*25626Skarels 				*cp++ = unit / 10 + '0';
84*25626Skarels 			*cp++ = unit % 10 + '0';
85*25626Skarels 			*cp++ = ',';
86*25626Skarels 			*cp++ = part + '0';
87*25626Skarels 			*cp++ = ')';
88*25626Skarels 			strcpy(cp, UNIX);
893261Swnj 		} else
901466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
911466Sbill 	}
921575Sbill #endif
931466Sbill 	for (;;) {
941466Sbill 		if (howto & RB_ASKNAME) {
951466Sbill 			printf(": ");
961466Sbill 			gets(line);
971466Sbill 		} else
981466Sbill 			printf(": %s\n", line);
991466Sbill 		io = open(line, 0);
10017198Stef 		if (io >= 0) {
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 
14717198Stef /* 750 Patchable Control Store magic */
14817198Stef 
14917198Stef #include "../vax/mtpr.h"
15017198Stef #include "../vax/cpu.h"
15117198Stef #define	PCS_BITCNT	0x2000		/* number of patchbits */
15217198Stef #define	PCS_MICRONUM	0x400		/* number of ucode locs */
15317198Stef #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
15417198Stef #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
15517198Stef #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
15617198Stef #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
15717198Stef 
15817198Stef loadpcs()
15917198Stef {
16017198Stef 	register int *ip;	/* known to be r11 below */
16117198Stef 	register int i;		/* known to be r10 below */
16217198Stef 	register int *jp;	/* known to be r9 below */
16317198Stef 	register int j;
16417198Stef 	union cpusid sid;
16517198Stef 	char pcs[100];
16624217Sbloom 	char *closeparen;
16724217Sbloom 	char *index();
16817198Stef 
16917198Stef 	sid.cpusid = mfpr(SID);
17025438Skarels 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95)
17117198Stef 		return;
17217198Stef 	printf("Updating 11/750 microcode: ");
17324217Sbloom 	strncpy(pcs, line, 99);
17424217Sbloom 	pcs[99] = 0;
17524217Sbloom 	closeparen = index(pcs, ')');
17624217Sbloom 	if (closeparen)
17724217Sbloom 		*(++closeparen) = 0;
17824217Sbloom 	else
17924217Sbloom 		return;
18017198Stef 	strcat(pcs, "pcs750.bin");
18117198Stef 	i = open(pcs, 0);
18217198Stef 	if (i < 0)
18317198Stef 		return;
18417198Stef 	/*
18517198Stef 	 * We ask for more than we need to be sure we get only what we expect.
18617198Stef 	 * After read:
18717198Stef 	 *	locs 0 - 1023	packed patchbits
18817198Stef 	 *	 1024 - 11264	packed microcode
18917198Stef 	 */
19017198Stef 	if (read(i, (char *)0, 23*512) != 22*512) {
19117198Stef 		printf("Error reading %s\n", pcs);
19217198Stef 		close(i);
19317198Stef 		return;
19417198Stef 	}
19517198Stef 	close(i);
19617198Stef 
19717198Stef 	/*
19817198Stef 	 * Enable patchbit loading and load the bits one at a time.
19917198Stef 	 */
20017198Stef 	*((int *)PCS_PATCHBIT) = 1;
20117198Stef 	ip = (int *)PCS_PATCHADDR;
20217198Stef 	jp = (int *)0;
20317198Stef 	for (i=0; i < PCS_BITCNT; i++) {
20417198Stef 		asm("	extzv	r10,$1,(r9),(r11)+");
20517198Stef 	}
20617198Stef 	*((int *)PCS_PATCHBIT) = 0;
20717198Stef 
20817198Stef 	/*
20917198Stef 	 * Load PCS microcode 20 bits at a time.
21017198Stef 	 */
21117198Stef 	ip = (int *)PCS_PCSADDR;
21217198Stef 	jp = (int *)1024;
21317198Stef 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
21417198Stef 		asm("	extzv	r10,$20,(r9),(r11)+");
21517198Stef 	}
21617198Stef 
21717198Stef 	/*
21817198Stef 	 * Enable PCS.
21917198Stef 	 */
22017198Stef 	i = *jp;		/* get 1st 20 bits of microcode again */
22117198Stef 	i &= 0xfffff;
22217198Stef 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
22317198Stef 	*((int *)PCS_PCSADDR) = i;
22417198Stef 
22517198Stef 	sid.cpusid = mfpr(SID);
22617198Stef 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
22717198Stef }
228