xref: /csrg-svn/sys/vax/stand/boot.c (revision 33433)
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*33433Sbostic  *	@(#)boot.c	7.6 (Berkeley) 1/28/88
723219Smckusick  */
8315Sbill 
930769Skarels #include "param.h"
1030769Skarels #include "inode.h"
1130769Skarels #include "fs.h"
1230769Skarels #include "vm.h"
1333408Skarels #include "reboot.h"
1433408Skarels 
15315Sbill #include <a.out.h>
16315Sbill #include "saio.h"
17315Sbill 
181466Sbill /*
191466Sbill  * Boot program... arguments passed in r10 and r11 determine
201466Sbill  * whether boot stops to ask for system name and which device
211466Sbill  * boot comes from.
221466Sbill  */
23315Sbill 
2430547Skarels #define	UNIX	"/vmunix"
2525626Skarels char line[100];
2624217Sbloom 
273347Swnj int	retry = 0;
2830547Skarels extern	unsigned opendev;
293347Swnj 
30315Sbill main()
31315Sbill {
3226828Skarels 	register unsigned howto, devtype;	/* howto=r11, devtype=r10 */
3330547Skarels 	int io, type;
34315Sbill 
353274Swnj #ifdef lint
363274Swnj 	howto = 0; devtype = 0;
373274Swnj #endif
3825626Skarels 	printf("\nBoot\n");
391575Sbill #ifdef JUSTASK
401593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
411575Sbill #else
4226828Skarels 	if ((howto & RB_ASKNAME) == 0) {
4330547Skarels 		type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
4433408Skarels 		if ((unsigned)type < ndevs && devsw[type].dv_name)
4530547Skarels 			strcpy(line, UNIX);
4630547Skarels 		else
4730769Skarels 			howto |= RB_SINGLE|RB_ASKNAME;
481466Sbill 	}
491575Sbill #endif
501466Sbill 	for (;;) {
511466Sbill 		if (howto & RB_ASKNAME) {
521466Sbill 			printf(": ");
531466Sbill 			gets(line);
5430547Skarels 			if (line[0] == 0) {
5530547Skarels 				strcpy(line, UNIX);
5630547Skarels 				printf(": %s\n", line);
5730547Skarels 			}
581466Sbill 		} else
591466Sbill 			printf(": %s\n", line);
601466Sbill 		io = open(line, 0);
6117198Stef 		if (io >= 0) {
6233408Skarels #ifdef VAX750
6326503Skarels 			loadpcs();
6433408Skarels #endif
6530547Skarels 			copyunix(howto, opendev, io);
6625438Skarels 			close(io);
6730769Skarels 			howto |= RB_SINGLE|RB_ASKNAME;
6817198Stef 		}
691466Sbill 		if (++retry > 2)
7030769Skarels 			howto |= RB_SINGLE|RB_ASKNAME;
711466Sbill 	}
72315Sbill }
73315Sbill 
743347Swnj /*ARGSUSED*/
7530922Skarels copyunix(howto, devtype, aio)
7630922Skarels 	register howto, devtype;	/* howto=r11, devtype=r10 */
7730922Skarels 	int aio;
78315Sbill {
7930922Skarels 	register int esym;		/* must be r9 */
80315Sbill 	struct exec x;
8130922Skarels 	register int io = aio, i;
82315Sbill 	char *addr;
83315Sbill 
84*33433Sbostic 	i = read(io, (char *)&x, sizeof(x));
85*33433Sbostic 	if (i != sizeof(x) || (x.a_magic != OMAGIC && x.a_magic != ZMAGIC
86*33433Sbostic 	    && x.a_magic != NMAGIC)) {
8730769Skarels 		printf("Bad format\n");
8830769Skarels 		return;
8930769Skarels 	}
90315Sbill 	printf("%d", x.a_text);
91*33433Sbostic 	if (x.a_magic == ZMAGIC && lseek(io, 0x400, L_SET) == -1)
926069Smckusic 		goto shread;
93315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
94315Sbill 		goto shread;
95315Sbill 	addr = (char *)x.a_text;
96*33433Sbostic 	if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC)
976069Smckusic 		while ((int)addr & CLOFSET)
986069Smckusic 			*addr++ = 0;
99315Sbill 	printf("+%d", x.a_data);
100315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
101315Sbill 		goto shread;
102315Sbill 	addr += x.a_data;
103315Sbill 	printf("+%d", x.a_bss);
104315Sbill 	for (i = 0; i < x.a_bss; i++)
105315Sbill 		*addr++ = 0;
10630769Skarels 	if (howto & RB_KDB && x.a_syms) {
10730769Skarels 		*(int *)addr = x.a_syms;		/* symbol table size */
10830769Skarels 		addr += sizeof (int);
10930769Skarels 		printf("[+%d", x.a_syms);
11030769Skarels 		if (read(io, addr, x.a_syms) != x.a_syms)
11130769Skarels 			goto shread;
11230769Skarels 		addr += x.a_syms;
11330769Skarels 		if (read(io, addr, sizeof (int)) != sizeof (int))
11430769Skarels 			goto shread;
11530769Skarels 		i = *(int *)addr - sizeof (int);	/* string table size */
11630769Skarels 		addr += sizeof (int);
11730769Skarels 		printf("+%d]", i);
11830769Skarels 		if (read(io, addr, i) != i)
11930769Skarels 			goto shread;
12030769Skarels 		addr += i;
12130769Skarels 		esym = roundup((int)addr, sizeof (int));
12230769Skarels 		x.a_bss = 0;
12330769Skarels 	} else
12430769Skarels 		howto &= ~RB_KDB;
12530769Skarels 	for (i = 0; i < 128*512; i++)	/* slop */
12630769Skarels 		*addr++ = 0;
127315Sbill 	x.a_entry &= 0x7fffffff;
128315Sbill 	printf(" start 0x%x\n", x.a_entry);
129315Sbill 	(*((int (*)()) x.a_entry))();
13025438Skarels 	return;
131315Sbill shread:
13230769Skarels 	printf("Short read\n");
13330769Skarels 	return;
134315Sbill }
13517198Stef 
13633408Skarels #ifdef VAX750
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;
15426503Skarels 	static int pcsdone = 0;
15517198Stef 	union cpusid sid;
15617198Stef 	char pcs[100];
15732198Skarels 	char *cp;
15817198Stef 
15917198Stef 	sid.cpusid = mfpr(SID);
16026503Skarels 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
16117198Stef 		return;
16217198Stef 	printf("Updating 11/750 microcode: ");
16332198Skarels 	for (cp = line; *cp; cp++)
16432198Skarels 		if (*cp == ')' || *cp == ':')
16532198Skarels 			break;
16632198Skarels 	if (*cp) {
16732198Skarels 		strncpy(pcs, line, 99);
16832198Skarels 		pcs[99] = 0;
16932198Skarels 		i = cp - line + 1;
17032198Skarels 	} else
17132198Skarels 		i = 0;
17232198Skarels 	strcpy(pcs + i, "pcs750.bin");
17317198Stef 	i = open(pcs, 0);
17417198Stef 	if (i < 0)
17517198Stef 		return;
17617198Stef 	/*
17717198Stef 	 * We ask for more than we need to be sure we get only what we expect.
17817198Stef 	 * After read:
17917198Stef 	 *	locs 0 - 1023	packed patchbits
18017198Stef 	 *	 1024 - 11264	packed microcode
18117198Stef 	 */
18217198Stef 	if (read(i, (char *)0, 23*512) != 22*512) {
18317198Stef 		printf("Error reading %s\n", pcs);
18417198Stef 		close(i);
18517198Stef 		return;
18617198Stef 	}
18717198Stef 	close(i);
18817198Stef 
18917198Stef 	/*
19017198Stef 	 * Enable patchbit loading and load the bits one at a time.
19117198Stef 	 */
19217198Stef 	*((int *)PCS_PATCHBIT) = 1;
19317198Stef 	ip = (int *)PCS_PATCHADDR;
19417198Stef 	jp = (int *)0;
19517198Stef 	for (i=0; i < PCS_BITCNT; i++) {
19617198Stef 		asm("	extzv	r10,$1,(r9),(r11)+");
19717198Stef 	}
19817198Stef 	*((int *)PCS_PATCHBIT) = 0;
19917198Stef 
20017198Stef 	/*
20117198Stef 	 * Load PCS microcode 20 bits at a time.
20217198Stef 	 */
20317198Stef 	ip = (int *)PCS_PCSADDR;
20417198Stef 	jp = (int *)1024;
20517198Stef 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
20617198Stef 		asm("	extzv	r10,$20,(r9),(r11)+");
20717198Stef 	}
20817198Stef 
20917198Stef 	/*
21017198Stef 	 * Enable PCS.
21117198Stef 	 */
21217198Stef 	i = *jp;		/* get 1st 20 bits of microcode again */
21317198Stef 	i &= 0xfffff;
21417198Stef 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
21517198Stef 	*((int *)PCS_PCSADDR) = i;
21617198Stef 
21717198Stef 	sid.cpusid = mfpr(SID);
21817198Stef 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
21926503Skarels 	pcsdone = 1;
22017198Stef }
22133408Skarels #endif
222