xref: /csrg-svn/sys/vax/stand/boot.c (revision 30922)
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*30922Skarels  *	@(#)boot.c	7.4 (Berkeley) 04/17/87
723219Smckusick  */
8315Sbill 
930769Skarels #include "param.h"
1030769Skarels #include "inode.h"
1130769Skarels #include "fs.h"
1230769Skarels #include "vm.h"
13315Sbill #include <a.out.h>
14315Sbill #include "saio.h"
1530769Skarels #include "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 
2330547Skarels #define	UNIX	"/vmunix"
2425626Skarels char line[100];
2524217Sbloom 
263347Swnj int	retry = 0;
2730547Skarels extern	unsigned opendev;
283347Swnj 
29315Sbill main()
30315Sbill {
3126828Skarels 	register unsigned howto, devtype;	/* howto=r11, devtype=r10 */
3230547Skarels 	int io, type;
33315Sbill 
343274Swnj #ifdef lint
353274Swnj 	howto = 0; devtype = 0;
363274Swnj #endif
3725626Skarels 	printf("\nBoot\n");
381575Sbill #ifdef JUSTASK
391593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
401575Sbill #else
4126828Skarels 	if ((howto & RB_ASKNAME) == 0) {
4230547Skarels 		type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
4330547Skarels 		if ((unsigned)type < ndevs && devsw[type].dv_name[0])
4430547Skarels 			strcpy(line, UNIX);
4530547Skarels 		else
4630769Skarels 			howto |= RB_SINGLE|RB_ASKNAME;
471466Sbill 	}
481575Sbill #endif
491466Sbill 	for (;;) {
501466Sbill 		if (howto & RB_ASKNAME) {
511466Sbill 			printf(": ");
521466Sbill 			gets(line);
5330547Skarels 			if (line[0] == 0) {
5430547Skarels 				strcpy(line, UNIX);
5530547Skarels 				printf(": %s\n", line);
5630547Skarels 			}
571466Sbill 		} else
581466Sbill 			printf(": %s\n", line);
591466Sbill 		io = open(line, 0);
6017198Stef 		if (io >= 0) {
6126503Skarels 			loadpcs();
6230547Skarels 			copyunix(howto, opendev, io);
6325438Skarels 			close(io);
6430769Skarels 			howto |= RB_SINGLE|RB_ASKNAME;
6517198Stef 		}
661466Sbill 		if (++retry > 2)
6730769Skarels 			howto |= RB_SINGLE|RB_ASKNAME;
681466Sbill 	}
69315Sbill }
70315Sbill 
713347Swnj /*ARGSUSED*/
72*30922Skarels copyunix(howto, devtype, aio)
73*30922Skarels 	register howto, devtype;	/* howto=r11, devtype=r10 */
74*30922Skarels 	int aio;
75315Sbill {
76*30922Skarels 	register int esym;		/* must be r9 */
77315Sbill 	struct exec x;
78*30922Skarels 	register int io = aio, i;
79315Sbill 	char *addr;
80315Sbill 
81315Sbill 	i = read(io, (char *)&x, sizeof x);
826069Smckusic 	if (i != sizeof x ||
8330769Skarels 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) {
8430769Skarels 		printf("Bad format\n");
8530769Skarels 		return;
8630769Skarels 	}
87315Sbill 	printf("%d", x.a_text);
887444Sroot 	if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
896069Smckusic 		goto shread;
90315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
91315Sbill 		goto shread;
92315Sbill 	addr = (char *)x.a_text;
936069Smckusic 	if (x.a_magic == 0413 || x.a_magic == 0410)
946069Smckusic 		while ((int)addr & CLOFSET)
956069Smckusic 			*addr++ = 0;
96315Sbill 	printf("+%d", x.a_data);
97315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
98315Sbill 		goto shread;
99315Sbill 	addr += x.a_data;
100315Sbill 	printf("+%d", x.a_bss);
101315Sbill 	for (i = 0; i < x.a_bss; i++)
102315Sbill 		*addr++ = 0;
10330769Skarels 	if (howto & RB_KDB && x.a_syms) {
10430769Skarels 		*(int *)addr = x.a_syms;		/* symbol table size */
10530769Skarels 		addr += sizeof (int);
10630769Skarels 		printf("[+%d", x.a_syms);
10730769Skarels 		if (read(io, addr, x.a_syms) != x.a_syms)
10830769Skarels 			goto shread;
10930769Skarels 		addr += x.a_syms;
11030769Skarels 		if (read(io, addr, sizeof (int)) != sizeof (int))
11130769Skarels 			goto shread;
11230769Skarels 		i = *(int *)addr - sizeof (int);	/* string table size */
11330769Skarels 		addr += sizeof (int);
11430769Skarels 		printf("+%d]", i);
11530769Skarels 		if (read(io, addr, i) != i)
11630769Skarels 			goto shread;
11730769Skarels 		addr += i;
11830769Skarels 		esym = roundup((int)addr, sizeof (int));
11930769Skarels 		x.a_bss = 0;
12030769Skarels 	} else
12130769Skarels 		howto &= ~RB_KDB;
12230769Skarels 	for (i = 0; i < 128*512; i++)	/* slop */
12330769Skarels 		*addr++ = 0;
124315Sbill 	x.a_entry &= 0x7fffffff;
125315Sbill 	printf(" start 0x%x\n", x.a_entry);
126315Sbill 	(*((int (*)()) x.a_entry))();
12725438Skarels 	return;
128315Sbill shread:
12930769Skarels 	printf("Short read\n");
13030769Skarels 	return;
131315Sbill }
13217198Stef 
13317198Stef /* 750 Patchable Control Store magic */
13417198Stef 
13517198Stef #include "../vax/mtpr.h"
13617198Stef #include "../vax/cpu.h"
13717198Stef #define	PCS_BITCNT	0x2000		/* number of patchbits */
13817198Stef #define	PCS_MICRONUM	0x400		/* number of ucode locs */
13917198Stef #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
14017198Stef #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
14117198Stef #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
14217198Stef #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
14317198Stef 
14417198Stef loadpcs()
14517198Stef {
14617198Stef 	register int *ip;	/* known to be r11 below */
14717198Stef 	register int i;		/* known to be r10 below */
14817198Stef 	register int *jp;	/* known to be r9 below */
14917198Stef 	register int j;
15026503Skarels 	static int pcsdone = 0;
15117198Stef 	union cpusid sid;
15217198Stef 	char pcs[100];
15324217Sbloom 	char *closeparen;
15424217Sbloom 	char *index();
15517198Stef 
15617198Stef 	sid.cpusid = mfpr(SID);
15726503Skarels 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
15817198Stef 		return;
15917198Stef 	printf("Updating 11/750 microcode: ");
16024217Sbloom 	strncpy(pcs, line, 99);
16124217Sbloom 	pcs[99] = 0;
16224217Sbloom 	closeparen = index(pcs, ')');
16324217Sbloom 	if (closeparen)
16424217Sbloom 		*(++closeparen) = 0;
16524217Sbloom 	else
16624217Sbloom 		return;
16717198Stef 	strcat(pcs, "pcs750.bin");
16817198Stef 	i = open(pcs, 0);
16917198Stef 	if (i < 0)
17017198Stef 		return;
17117198Stef 	/*
17217198Stef 	 * We ask for more than we need to be sure we get only what we expect.
17317198Stef 	 * After read:
17417198Stef 	 *	locs 0 - 1023	packed patchbits
17517198Stef 	 *	 1024 - 11264	packed microcode
17617198Stef 	 */
17717198Stef 	if (read(i, (char *)0, 23*512) != 22*512) {
17817198Stef 		printf("Error reading %s\n", pcs);
17917198Stef 		close(i);
18017198Stef 		return;
18117198Stef 	}
18217198Stef 	close(i);
18317198Stef 
18417198Stef 	/*
18517198Stef 	 * Enable patchbit loading and load the bits one at a time.
18617198Stef 	 */
18717198Stef 	*((int *)PCS_PATCHBIT) = 1;
18817198Stef 	ip = (int *)PCS_PATCHADDR;
18917198Stef 	jp = (int *)0;
19017198Stef 	for (i=0; i < PCS_BITCNT; i++) {
19117198Stef 		asm("	extzv	r10,$1,(r9),(r11)+");
19217198Stef 	}
19317198Stef 	*((int *)PCS_PATCHBIT) = 0;
19417198Stef 
19517198Stef 	/*
19617198Stef 	 * Load PCS microcode 20 bits at a time.
19717198Stef 	 */
19817198Stef 	ip = (int *)PCS_PCSADDR;
19917198Stef 	jp = (int *)1024;
20017198Stef 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
20117198Stef 		asm("	extzv	r10,$20,(r9),(r11)+");
20217198Stef 	}
20317198Stef 
20417198Stef 	/*
20517198Stef 	 * Enable PCS.
20617198Stef 	 */
20717198Stef 	i = *jp;		/* get 1st 20 bits of microcode again */
20817198Stef 	i &= 0xfffff;
20917198Stef 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
21017198Stef 	*((int *)PCS_PCSADDR) = i;
21117198Stef 
21217198Stef 	sid.cpusid = mfpr(SID);
21317198Stef 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
21426503Skarels 	pcsdone = 1;
21517198Stef }
216