xref: /csrg-svn/sys/vax/stand/boot.c (revision 33522)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)boot.c	7.9 (Berkeley) 02/22/88
7  */
8 
9 #include "param.h"
10 #include "inode.h"
11 #include "fs.h"
12 #include "vm.h"
13 #include "reboot.h"
14 
15 #include <a.out.h>
16 #include "saio.h"
17 
18 /*
19  * Boot program... arguments passed in r10 and r11 determine
20  * whether boot stops to ask for system name and which device
21  * boot comes from.
22  */
23 
24 #define	UNIX	"/vmunix"
25 char line[100];
26 
27 extern	unsigned opendev;
28 
29 main()
30 {
31 	register unsigned howto, devtype;	/* howto=r11, devtype=r10 */
32 	int io, retry, type;
33 
34 #ifdef lint
35 	howto = 0; devtype = 0;
36 #endif
37 	printf("\nBoot\n");
38 #ifdef JUSTASK
39 	howto = RB_ASKNAME|RB_SINGLE;
40 #else
41 	if ((howto & RB_ASKNAME) == 0) {
42 		type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
43 		if ((unsigned)type < ndevs && devsw[type].dv_name)
44 			strcpy(line, UNIX);
45 		else
46 			howto |= RB_SINGLE|RB_ASKNAME;
47 	}
48 #endif
49 	for (retry = 0;;) {
50 		if (howto & RB_ASKNAME) {
51 			printf(": ");
52 			gets(line);
53 			if (line[0] == 0) {
54 				strcpy(line, UNIX);
55 				printf(": %s\n", line);
56 			}
57 		} else
58 			printf(": %s\n", line);
59 		io = open(line, 0);
60 		if (io >= 0) {
61 #ifdef VAX750
62 			loadpcs();
63 #endif
64 			copyunix(howto, opendev, io);
65 			close(io);
66 			howto |= RB_SINGLE|RB_ASKNAME;
67 		}
68 		if (++retry > 2)
69 			howto |= RB_SINGLE|RB_ASKNAME;
70 	}
71 }
72 
73 /*ARGSUSED*/
74 copyunix(howto, devtype, aio)
75 	register howto, devtype;	/* howto=r11, devtype=r10 */
76 	int aio;
77 {
78 	register int esym;		/* must be r9 */
79 	struct exec x;
80 	register int io = aio, i;
81 	char *addr;
82 
83 	i = read(io, (char *)&x, sizeof(x));
84 	if (i != sizeof(x) || (x.a_magic != OMAGIC && x.a_magic != ZMAGIC
85 	    && x.a_magic != NMAGIC)) {
86 		printf("Bad format\n");
87 		return;
88 	}
89 	printf("%d", x.a_text);
90 	if (x.a_magic == ZMAGIC && lseek(io, 0x400, L_SET) == -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 == ZMAGIC || x.a_magic == NMAGIC)
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 	for (i = 0; i < x.a_bss; i++)
104 		*addr++ = 0;
105 	if (howto & RB_KDB && x.a_syms) {
106 		*(int *)addr = x.a_syms;		/* symbol table size */
107 		addr += sizeof (int);
108 		printf("[+%d", x.a_syms);
109 		if (read(io, addr, x.a_syms) != x.a_syms)
110 			goto shread;
111 		addr += x.a_syms;
112 		if (read(io, addr, sizeof (int)) != sizeof (int))
113 			goto shread;
114 		i = *(int *)addr - sizeof (int);	/* string table size */
115 		addr += sizeof (int);
116 		printf("+%d]", i);
117 		if (read(io, addr, i) != i)
118 			goto shread;
119 		addr += i;
120 		esym = roundup((int)addr, sizeof (int));
121 		x.a_bss = 0;
122 	} else
123 		howto &= ~RB_KDB;
124 	for (i = 0; i < 128*512; i++)	/* slop */
125 		*addr++ = 0;
126 	x.a_entry &= 0x7fffffff;
127 	printf(" start 0x%x\n", x.a_entry);
128 	(*((int (*)()) x.a_entry))();
129 	return;
130 shread:
131 	printf("Short read\n");
132 	return;
133 }
134 
135 #ifdef VAX750
136 /* 750 Patchable Control Store magic */
137 
138 #include "../vax/mtpr.h"
139 #include "../vax/cpu.h"
140 #define	PCS_BITCNT	0x2000		/* number of patchbits */
141 #define	PCS_MICRONUM	0x400		/* number of ucode locs */
142 #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
143 #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
144 #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
145 #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
146 
147 loadpcs()
148 {
149 	register int *ip;	/* known to be r11 below */
150 	register int i;		/* known to be r10 below */
151 	register int *jp;	/* known to be r9 below */
152 	register int j;
153 	static int pcsdone = 0;
154 	union cpusid sid;
155 	char pcs[100];
156 	char *cp;
157 
158 	sid.cpusid = mfpr(SID);
159 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
160 		return;
161 	printf("Updating 11/750 microcode: ");
162 	for (cp = line; *cp; cp++)
163 		if (*cp == ')' || *cp == ':')
164 			break;
165 	if (*cp) {
166 		strncpy(pcs, line, 99);
167 		pcs[99] = 0;
168 		i = cp - line + 1;
169 	} else
170 		i = 0;
171 	strcpy(pcs + i, "pcs750.bin");
172 	i = open(pcs, 0);
173 	if (i < 0)
174 		return;
175 	/*
176 	 * We ask for more than we need to be sure we get only what we expect.
177 	 * After read:
178 	 *	locs 0 - 1023	packed patchbits
179 	 *	 1024 - 11264	packed microcode
180 	 */
181 	if (read(i, (char *)0, 23*512) != 22*512) {
182 		printf("Error reading %s\n", pcs);
183 		close(i);
184 		return;
185 	}
186 	close(i);
187 
188 	/*
189 	 * Enable patchbit loading and load the bits one at a time.
190 	 */
191 	*((int *)PCS_PATCHBIT) = 1;
192 	ip = (int *)PCS_PATCHADDR;
193 	jp = (int *)0;
194 	for (i=0; i < PCS_BITCNT; i++) {
195 		asm("	extzv	r10,$1,(r9),(r11)+");
196 	}
197 	*((int *)PCS_PATCHBIT) = 0;
198 
199 	/*
200 	 * Load PCS microcode 20 bits at a time.
201 	 */
202 	ip = (int *)PCS_PCSADDR;
203 	jp = (int *)1024;
204 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
205 		asm("	extzv	r10,$20,(r9),(r11)+");
206 	}
207 
208 	/*
209 	 * Enable PCS.
210 	 */
211 	i = *jp;		/* get 1st 20 bits of microcode again */
212 	i &= 0xfffff;
213 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
214 	*((int *)PCS_PCSADDR) = i;
215 
216 	sid.cpusid = mfpr(SID);
217 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
218 	pcsdone = 1;
219 }
220 #endif
221