xref: /original-bsd/sys/vax/stand/boot.c (revision dfa70498)
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.12 (Berkeley) 03/21/89
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 char line[100];
25 
26 extern	unsigned opendev;
27 
28 main()
29 {
30 	register unsigned howto, devtype;	/* howto=r11, devtype=r10 */
31 	int io = 0, retry, type;
32 
33 #ifdef lint
34 	howto = 0; devtype = 0;
35 #endif
36 #ifdef JUSTASK
37 	howto = RB_ASKNAME|RB_SINGLE;
38 #else
39 	if ((howto & RB_ASKNAME) == 0) {
40 		type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
41 		if ((unsigned)type < ndevs && devsw[type].dv_name)
42 			strcpy(line, UNIX);
43 		else
44 			howto |= RB_SINGLE|RB_ASKNAME;
45 	}
46 #endif
47 	for (retry = 0;;) {
48 		if (io >= 0)
49 			printf("\nBoot\n");
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 	if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) {
84 		printf("Bad format\n");
85 		return;
86 	}
87 	printf("%d", x.a_text);
88 	if (x.a_magic == ZMAGIC && lseek(io, 0x400, L_SET) == -1)
89 		goto shread;
90 	if (read(io, (char *)0, x.a_text) != x.a_text)
91 		goto shread;
92 	addr = (char *)x.a_text;
93 	if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC)
94 		while ((int)addr & CLOFSET)
95 			*addr++ = 0;
96 	printf("+%d", x.a_data);
97 	if (read(io, addr, x.a_data) != x.a_data)
98 		goto shread;
99 	addr += x.a_data;
100 	printf("+%d", x.a_bss);
101 	for (i = 0; i < x.a_bss; i++)
102 		*addr++ = 0;
103 	if (howto & RB_KDB && x.a_syms) {
104 		*(int *)addr = x.a_syms;		/* symbol table size */
105 		addr += sizeof (int);
106 		printf("[+%d", x.a_syms);
107 		if (read(io, addr, x.a_syms) != x.a_syms)
108 			goto shread;
109 		addr += x.a_syms;
110 		if (read(io, addr, sizeof (int)) != sizeof (int))
111 			goto shread;
112 		i = *(int *)addr - sizeof (int);	/* string table size */
113 		addr += sizeof (int);
114 		printf("+%d]", i);
115 		if (read(io, addr, i) != i)
116 			goto shread;
117 		addr += i;
118 		esym = roundup((int)addr, sizeof (int));
119 		x.a_bss = 0;
120 	} else
121 		howto &= ~RB_KDB;
122 	for (i = 0; i < 128*512; i++)	/* slop */
123 		*addr++ = 0;
124 	x.a_entry &= 0x7fffffff;
125 	printf(" start 0x%x\n", x.a_entry);
126 	(*((int (*)()) x.a_entry))();
127 	return;
128 shread:
129 	printf("Short read\n");
130 	return;
131 }
132 
133 #ifdef VAX750
134 /* 750 Patchable Control Store magic */
135 
136 #include "../vax/mtpr.h"
137 #include "../vax/cpu.h"
138 #define	PCS_BITCNT	0x2000		/* number of patchbits */
139 #define	PCS_MICRONUM	0x400		/* number of ucode locs */
140 #define	PCS_PATCHADDR	0xf00000	/* start addr of patchbits */
141 #define	PCS_PCSADDR	(PCS_PATCHADDR+0x8000)	/* start addr of pcs */
142 #define	PCS_PATCHBIT	(PCS_PATCHADDR+0xc000)	/* patchbits enable reg */
143 #define	PCS_ENABLE	0xfff00000	/* enable bits for pcs */
144 
145 loadpcs()
146 {
147 	register int *ip;	/* known to be r11 below */
148 	register int i;		/* known to be r10 below */
149 	register int *jp;	/* known to be r9 below */
150 	register int j;
151 	static int pcsdone = 0;
152 	union cpusid sid;
153 	char pcs[100];
154 	char *cp;
155 
156 	sid.cpusid = mfpr(SID);
157 	if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
158 		return;
159 	printf("Updating 11/750 microcode: ");
160 	for (cp = line; *cp; cp++)
161 		if (*cp == ')' || *cp == ':')
162 			break;
163 	if (*cp) {
164 		strncpy(pcs, line, 99);
165 		pcs[99] = 0;
166 		i = cp - line + 1;
167 	} else
168 		i = 0;
169 	strcpy(pcs + i, "pcs750.bin");
170 	i = open(pcs, 0);
171 	if (i < 0)
172 		return;
173 	/*
174 	 * We ask for more than we need to be sure we get only what we expect.
175 	 * After read:
176 	 *	locs 0 - 1023	packed patchbits
177 	 *	 1024 - 11264	packed microcode
178 	 */
179 	if (read(i, (char *)0, 23*512) != 22*512) {
180 		printf("Error reading %s\n", pcs);
181 		close(i);
182 		return;
183 	}
184 	close(i);
185 
186 	/*
187 	 * Enable patchbit loading and load the bits one at a time.
188 	 */
189 	*((int *)PCS_PATCHBIT) = 1;
190 	ip = (int *)PCS_PATCHADDR;
191 	jp = (int *)0;
192 	for (i=0; i < PCS_BITCNT; i++) {
193 		asm("	extzv	r10,$1,(r9),(r11)+");
194 	}
195 	*((int *)PCS_PATCHBIT) = 0;
196 
197 	/*
198 	 * Load PCS microcode 20 bits at a time.
199 	 */
200 	ip = (int *)PCS_PCSADDR;
201 	jp = (int *)1024;
202 	for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
203 		asm("	extzv	r10,$20,(r9),(r11)+");
204 	}
205 
206 	/*
207 	 * Enable PCS.
208 	 */
209 	i = *jp;		/* get 1st 20 bits of microcode again */
210 	i &= 0xfffff;
211 	i |= PCS_ENABLE;	/* reload these bits with PCS enable set */
212 	*((int *)PCS_PCSADDR) = i;
213 
214 	sid.cpusid = mfpr(SID);
215 	printf("new rev level=%d\n", sid.cpu750.cp_urev);
216 	pcsdone = 1;
217 }
218 #endif
219