xref: /csrg-svn/sys/vax/stand/boot.c (revision 30547)
123219Smckusick /*
229292Smckusick  * Copyright (c) 1982, 1986 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*30547Skarels  *	@(#)boot.c	7.2 (Berkeley) 02/21/87
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 
23*30547Skarels #define	UNIX	"/vmunix"
2425626Skarels char line[100];
2524217Sbloom 
263347Swnj int	retry = 0;
27*30547Skarels unsigned bootdev;
28*30547Skarels extern	unsigned opendev;
293347Swnj 
30315Sbill main()
31315Sbill {
3226828Skarels 	register unsigned howto, devtype;	/* howto=r11, devtype=r10 */
33*30547Skarels 	int io, type;
34315Sbill 
353274Swnj #ifdef lint
363274Swnj 	howto = 0; devtype = 0;
373274Swnj #endif
38*30547Skarels 	bootdev = devtype;
3925626Skarels 	printf("\nBoot\n");
401575Sbill #ifdef JUSTASK
411593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
421575Sbill #else
4326828Skarels 	if ((howto & RB_ASKNAME) == 0) {
44*30547Skarels 		type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
45*30547Skarels 		if ((unsigned)type < ndevs && devsw[type].dv_name[0])
46*30547Skarels 			strcpy(line, UNIX);
47*30547Skarels 		else
481466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
491466Sbill 	}
501575Sbill #endif
511466Sbill 	for (;;) {
521466Sbill 		if (howto & RB_ASKNAME) {
531466Sbill 			printf(": ");
541466Sbill 			gets(line);
55*30547Skarels 			if (line[0] == 0) {
56*30547Skarels 				strcpy(line, UNIX);
57*30547Skarels 				printf(": %s\n", line);
58*30547Skarels 			}
591466Sbill 		} else
601466Sbill 			printf(": %s\n", line);
611466Sbill 		io = open(line, 0);
6217198Stef 		if (io >= 0) {
6326503Skarels 			loadpcs();
64*30547Skarels 			copyunix(howto, opendev, io);
6525438Skarels 			close(io);
6625438Skarels 			howto = RB_SINGLE|RB_ASKNAME;
6717198Stef 		}
681466Sbill 		if (++retry > 2)
691466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
701466Sbill 	}
71315Sbill }
72315Sbill 
733347Swnj /*ARGSUSED*/
7426828Skarels copyunix(howto, devtype, io)
7526828Skarels 	register howto, devtype, io;	/* howto=r11, devtype=r10 */
76315Sbill {
77315Sbill 	struct exec x;
78315Sbill 	register int i;
79315Sbill 	char *addr;
80315Sbill 
81315Sbill 	i = read(io, (char *)&x, sizeof x);
826069Smckusic 	if (i != sizeof x ||
836069Smckusic 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
84315Sbill 		_stop("Bad format\n");
85315Sbill 	printf("%d", x.a_text);
867444Sroot 	if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
876069Smckusic 		goto shread;
88315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
89315Sbill 		goto shread;
90315Sbill 	addr = (char *)x.a_text;
916069Smckusic 	if (x.a_magic == 0413 || x.a_magic == 0410)
926069Smckusic 		while ((int)addr & CLOFSET)
936069Smckusic 			*addr++ = 0;
94315Sbill 	printf("+%d", x.a_data);
95315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
96315Sbill 		goto shread;
97315Sbill 	addr += x.a_data;
98315Sbill 	printf("+%d", x.a_bss);
99315Sbill 	x.a_bss += 128*512;	/* slop */
100315Sbill 	for (i = 0; i < x.a_bss; i++)
101315Sbill 		*addr++ = 0;
102315Sbill 	x.a_entry &= 0x7fffffff;
103315Sbill 	printf(" start 0x%x\n", x.a_entry);
104315Sbill 	(*((int (*)()) x.a_entry))();
10525438Skarels 	return;
106315Sbill shread:
107315Sbill 	_stop("Short read\n");
108315Sbill }
10917198Stef 
11017198Stef /* 750 Patchable Control Store magic */
11117198Stef 
11217198Stef #include "../vax/mtpr.h"
11317198Stef #include "../vax/cpu.h"
11417198Stef #define	PCS_BITCNT	0x2000		/* number of patchbits */
11517198Stef #define	PCS_MICRONUM	0x400		/* number of ucode locs */
11617198Stef #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
11717198Stef #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
11817198Stef #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
11917198Stef #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
12017198Stef 
12117198Stef loadpcs()
12217198Stef {
12317198Stef 	register int *ip;	/* known to be r11 below */
12417198Stef 	register int i;		/* known to be r10 below */
12517198Stef 	register int *jp;	/* known to be r9 below */
12617198Stef 	register int j;
12726503Skarels 	static int pcsdone = 0;
12817198Stef 	union cpusid sid;
12917198Stef 	char pcs[100];
13024217Sbloom 	char *closeparen;
13124217Sbloom 	char *index();
13217198Stef 
13317198Stef 	sid.cpusid = mfpr(SID);
13426503Skarels 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
13517198Stef 		return;
13617198Stef 	printf("Updating 11/750 microcode: ");
13724217Sbloom 	strncpy(pcs, line, 99);
13824217Sbloom 	pcs[99] = 0;
13924217Sbloom 	closeparen = index(pcs, ')');
14024217Sbloom 	if (closeparen)
14124217Sbloom 		*(++closeparen) = 0;
14224217Sbloom 	else
14324217Sbloom 		return;
14417198Stef 	strcat(pcs, "pcs750.bin");
14517198Stef 	i = open(pcs, 0);
14617198Stef 	if (i < 0)
14717198Stef 		return;
14817198Stef 	/*
14917198Stef 	 * We ask for more than we need to be sure we get only what we expect.
15017198Stef 	 * After read:
15117198Stef 	 *	locs 0 - 1023	packed patchbits
15217198Stef 	 *	 1024 - 11264	packed microcode
15317198Stef 	 */
15417198Stef 	if (read(i, (char *)0, 23*512) != 22*512) {
15517198Stef 		printf("Error reading %s\n", pcs);
15617198Stef 		close(i);
15717198Stef 		return;
15817198Stef 	}
15917198Stef 	close(i);
16017198Stef 
16117198Stef 	/*
16217198Stef 	 * Enable patchbit loading and load the bits one at a time.
16317198Stef 	 */
16417198Stef 	*((int *)PCS_PATCHBIT) = 1;
16517198Stef 	ip = (int *)PCS_PATCHADDR;
16617198Stef 	jp = (int *)0;
16717198Stef 	for (i=0; i < PCS_BITCNT; i++) {
16817198Stef 		asm("	extzv	r10,$1,(r9),(r11)+");
16917198Stef 	}
17017198Stef 	*((int *)PCS_PATCHBIT) = 0;
17117198Stef 
17217198Stef 	/*
17317198Stef 	 * Load PCS microcode 20 bits at a time.
17417198Stef 	 */
17517198Stef 	ip = (int *)PCS_PCSADDR;
17617198Stef 	jp = (int *)1024;
17717198Stef 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
17817198Stef 		asm("	extzv	r10,$20,(r9),(r11)+");
17917198Stef 	}
18017198Stef 
18117198Stef 	/*
18217198Stef 	 * Enable PCS.
18317198Stef 	 */
18417198Stef 	i = *jp;		/* get 1st 20 bits of microcode again */
18517198Stef 	i &= 0xfffff;
18617198Stef 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
18717198Stef 	*((int *)PCS_PCSADDR) = i;
18817198Stef 
18917198Stef 	sid.cpusid = mfpr(SID);
19017198Stef 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
19126503Skarels 	pcsdone = 1;
19217198Stef }
193