xref: /original-bsd/sys/vax/stand/boot.c (revision e78e7ec3)
1 /*	boot.c	6.2	84/09/18	*/
2 
3 #include "../h/param.h"
4 #include "../h/inode.h"
5 #include "../h/fs.h"
6 #include "../h/vm.h"
7 #include <a.out.h>
8 #include "saio.h"
9 #include "../h/reboot.h"
10 
11 /*
12  * Boot program... arguments passed in r10 and r11 determine
13  * whether boot stops to ask for system name and which device
14  * boot comes from.
15  */
16 
17 /* Types in r10 specifying major device */
18 char	devname[][2] = {
19 	'h','p',	/* 0 = hp */
20 	0,0,		/* 1 = ht */
21 	'u','p',	/* 2 = up */
22 	'h','k',	/* 3 = hk */
23 	0,0,		/* 4 = sw */
24 	0,0,		/* 5 = tm */
25 	0,0,		/* 6 = ts */
26 	0,0,		/* 7 = mt */
27 	0,0,		/* 8 = tu */
28 	'r','a',	/* 9 = ra */
29 	'u','t',	/* 10 = ut */
30 	'r','b',	/* 11 = rb */
31 	0,0,		/* 12 = uu */
32 	0,0,		/* 13 = rx */
33 	'r','l',	/* 14 = rl */
34 };
35 
36 char line[100] = "xx(0,0)vmunix";
37 
38 int	retry = 0;
39 
40 main()
41 {
42 	register howto, devtype;	/* howto=r11, devtype=r10 */
43 	int io;
44 
45 #ifdef lint
46 	howto = 0; devtype = 0;
47 #endif
48 	printf("\nBoot\n");
49 #ifdef JUSTASK
50 	howto = RB_ASKNAME|RB_SINGLE;
51 #else
52 	if ((howto&RB_ASKNAME)==0) {
53 		if (devtype>=0 && devtype<sizeof(devname)/2
54 		    && devname[devtype][0]) {
55 			line[0] = devname[devtype][0];
56 			line[1] = devname[devtype][1];
57 		} else
58 			howto = RB_SINGLE|RB_ASKNAME;
59 	}
60 #endif
61 	for (;;) {
62 		if (howto & RB_ASKNAME) {
63 			printf(": ");
64 			gets(line);
65 		} else
66 			printf(": %s\n", line);
67 		io = open(line, 0);
68 		if (io >= 0) {
69 			loadpcs();
70 			copyunix(howto, io);
71 		}
72 		if (++retry > 2)
73 			howto = RB_SINGLE|RB_ASKNAME;
74 	}
75 }
76 
77 /*ARGSUSED*/
78 copyunix(howto, io)
79 	register howto, io;
80 {
81 	struct exec x;
82 	register int i;
83 	char *addr;
84 
85 	i = read(io, (char *)&x, sizeof x);
86 	if (i != sizeof x ||
87 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
88 		_stop("Bad format\n");
89 	printf("%d", x.a_text);
90 	if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
91 		goto shread;
92 	if (read(io, (char *)0, x.a_text) != x.a_text)
93 		goto shread;
94 	addr = (char *)x.a_text;
95 	if (x.a_magic == 0413 || x.a_magic == 0410)
96 		while ((int)addr & CLOFSET)
97 			*addr++ = 0;
98 	printf("+%d", x.a_data);
99 	if (read(io, addr, x.a_data) != x.a_data)
100 		goto shread;
101 	addr += x.a_data;
102 	printf("+%d", x.a_bss);
103 	x.a_bss += 128*512;	/* slop */
104 	for (i = 0; i < x.a_bss; i++)
105 		*addr++ = 0;
106 	x.a_entry &= 0x7fffffff;
107 	printf(" start 0x%x\n", x.a_entry);
108 	(*((int (*)()) x.a_entry))();
109 	_exit();
110 shread:
111 	_stop("Short read\n");
112 }
113 
114 /* 750 Patchable Control Store magic */
115 
116 #include "../vax/mtpr.h"
117 #include "../vax/cpu.h"
118 #define	PCS_BITCNT	0x2000		/* number of patchbits */
119 #define	PCS_MICRONUM	0x400		/* number of ucode locs */
120 #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
121 #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
122 #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
123 #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
124 
125 loadpcs()
126 {
127 	register int *ip;	/* known to be r11 below */
128 	register int i;		/* known to be r10 below */
129 	register int *jp;	/* known to be r9 below */
130 	register int j;
131 	static int pcsdone = 0;
132 	union cpusid sid;
133 	char pcs[100];
134 
135 	sid.cpusid = mfpr(SID);
136 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
137 		return;
138 	printf("Updating 11/750 microcode: ");
139 	strncpy(pcs, line, strlen("xx(0,0)"));
140 	strcat(pcs, "pcs750.bin");
141 	i = open(pcs, 0);
142 	if (i < 0)
143 		return;
144 	/*
145 	 * We ask for more than we need to be sure we get only what we expect.
146 	 * After read:
147 	 *	locs 0 - 1023	packed patchbits
148 	 *	 1024 - 11264	packed microcode
149 	 */
150 	if (read(i, (char *)0, 23*512) != 22*512) {
151 		printf("Error reading %s\n", pcs);
152 		close(i);
153 		return;
154 	}
155 	close(i);
156 
157 	/*
158 	 * Enable patchbit loading and load the bits one at a time.
159 	 */
160 	*((int *)PCS_PATCHBIT) = 1;
161 	ip = (int *)PCS_PATCHADDR;
162 	jp = (int *)0;
163 	for (i=0; i < PCS_BITCNT; i++) {
164 		asm("	extzv	r10,$1,(r9),(r11)+");
165 	}
166 	*((int *)PCS_PATCHBIT) = 0;
167 
168 	/*
169 	 * Load PCS microcode 20 bits at a time.
170 	 */
171 	ip = (int *)PCS_PCSADDR;
172 	jp = (int *)1024;
173 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
174 		asm("	extzv	r10,$20,(r9),(r11)+");
175 	}
176 
177 	/*
178 	 * Enable PCS.
179 	 */
180 	i = *jp;		/* get 1st 20 bits of microcode again */
181 	i &= 0xfffff;
182 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
183 	*((int *)PCS_PCSADDR) = i;
184 
185 	sid.cpusid = mfpr(SID);
186 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
187 	pcsdone = 1;
188 }
189