boot.c revision 1.3 1 /* $NetBSD: boot.c,v 1.3 1999/06/30 18:33:33 ragge Exp $ */
2 /*-
3 * Copyright (c) 1982, 1986 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)boot.c 7.15 (Berkeley) 5/4/91
35 */
36
37 #include "sys/param.h"
38 #include "sys/reboot.h"
39 #include "lib/libsa/stand.h"
40
41 #define V750UCODE(x) ((x>>8)&255)
42
43 #include <a.out.h>
44
45 #include "vaxstand.h"
46
47 /*
48 * Boot program... arguments passed in r10 and r11 determine
49 * whether boot stops to ask for system name and which device
50 * boot comes from.
51 */
52
53 char line[100];
54 int devtype, bootdev, howto, debug;
55 extern unsigned opendev;
56 extern unsigned *bootregs;
57
58 void usage(), boot(), halt();
59
60 struct vals {
61 char *namn;
62 void (*func)();
63 char *info;
64 } val[] = {
65 {"?", usage, "Show this help menu"},
66 {"help", usage, "Same as '?'"},
67 {"boot", boot, "Load and execute file"},
68 {"halt", halt, "Halts the system"},
69 {0, 0},
70 };
71
72 char *filer[] = {
73 "netbsd",
74 "netbsd.gz",
75 "netbsd.old",
76 "gennetbsd",
77 0,
78 };
79
80 Xmain()
81 {
82 int io, type, sluttid, askname, filindex = 0;
83 int j, senast = 0, nu;
84
85 io=0;
86 autoconf();
87
88 askname = howto & RB_ASKNAME;
89 printf("\n\r>> NetBSD/vax boot [%s %s] <<\n", __DATE__, __TIME__);
90 printf(">> Press any key to abort autoboot ");
91 sluttid = getsecs() + 5;
92 for (;;) {
93 nu = sluttid - getsecs();
94 if (senast != nu)
95 printf("%c%d", 8, nu);
96 if (nu <= 0)
97 break;
98 senast = nu;
99 if ((j = (testkey() & 0177))) {
100 if (j != 10 && j != 13) {
101 printf("\nPress '?' for help");
102 askname = 1;
103 }
104 break;
105 }
106 }
107 printf("\n");
108
109 /* First try to autoboot */
110 if (askname == 0) {
111 type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
112 if ((unsigned)type < ndevs && devsw[type].dv_name)
113 while (filer[filindex]) {
114 errno = 0;
115 printf("> boot %s\n", filer[filindex]);
116 exec(filer[filindex++], 0, 0);
117 printf("boot failed: %s\n", strerror(errno));
118 if (testkey())
119 break;
120 }
121 }
122
123 /* If any key pressed, go to conversational boot */
124 for (;;) {
125 struct vals *v = &val[0];
126 char *c, *d;
127
128 printf("> ");
129 gets(line);
130
131 c = line;
132 while (*c == ' ')
133 c++;
134
135 if (c[0] == 0)
136 continue;
137
138 if ((d = index(c, ' ')))
139 *d++ = 0;
140
141 while (v->namn) {
142 if (strcmp(v->namn, c) == 0)
143 break;
144 v++;
145 }
146 if (v->namn)
147 (*v->func)(d);
148 else
149 printf("Unknown command: %s\n", c);
150
151 }
152 }
153
154 void
155 halt()
156 {
157 asm("halt");
158 }
159
160 void
161 boot(arg)
162 char *arg;
163 {
164 char *fn = "netbsd";
165
166 if (arg) {
167 while (*arg == ' ')
168 arg++;
169
170 if (*arg != '-') {
171 fn = arg;
172 if ((arg = index(arg, ' '))) {
173 *arg++ = 0;
174 while (*arg == ' ')
175 arg++;
176 } else
177 goto load;
178 }
179 if (*arg != '-') {
180 fail: printf("usage: boot [filename] [-asd]\n");
181 return;
182 }
183
184 while (*++arg) {
185 if (*arg == 'a')
186 howto |= RB_ASKNAME;
187 else if (*arg == 'd')
188 howto |= RB_KDB;
189 else if (*arg == 's')
190 howto |= RB_SINGLE;
191 else
192 goto fail;
193 }
194 }
195 load: exec(fn, 0, 0);
196 printf("Boot failed: %s\n", strerror(errno));
197 }
198
199 /* 750 Patchable Control Store magic */
200
201 #include "../include/mtpr.h"
202 #include "../include/cpu.h"
203 #include "../include/sid.h"
204 #define PCS_BITCNT 0x2000 /* number of patchbits */
205 #define PCS_MICRONUM 0x400 /* number of ucode locs */
206 #define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */
207 #define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */
208 #define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */
209 #define PCS_ENABLE 0xfff00000 /* enable bits for pcs */
210
211 #define extzv(one, two, three,four) \
212 ({ \
213 asm __volatile (" extzv %0,%3,(%1),(%2)+" \
214 : \
215 : "g"(one),"g"(two),"g"(three),"g"(four)); \
216 })
217
218
219 loadpcs()
220 {
221 static int pcsdone = 0;
222 int mid = mfpr(PR_SID);
223 int i, j, *ip, *jp;
224 char pcs[100];
225 char *cp;
226
227 if ((mid >> 24) != VAX_750 || ((mid >> 8) & 255) < 95 || pcsdone)
228 return;
229 printf("Updating 11/750 microcode: ");
230 for (cp = line; *cp; cp++)
231 if (*cp == ')' || *cp == ':')
232 break;
233 if (*cp) {
234 bcopy(line, pcs, 99);
235 pcs[99] = 0;
236 i = cp - line + 1;
237 } else
238 i = 0;
239 strcpy(pcs + i, "pcs750.bin");
240 i = open(pcs, 0);
241 if (i < 0) {
242 printf("bad luck - missing pcs750.bin :-(\n");
243 return;
244 }
245 /*
246 * We ask for more than we need to be sure we get only what we expect.
247 * After read:
248 * locs 0 - 1023 packed patchbits
249 * 1024 - 11264 packed microcode
250 */
251 if (read(i, (char *)0, 23*512) != 22*512) {
252 printf("Error reading %s\n", pcs);
253 close(i);
254 return;
255 }
256 close(i);
257
258 /*
259 * Enable patchbit loading and load the bits one at a time.
260 */
261 *((int *)PCS_PATCHBIT) = 1;
262 ip = (int *)PCS_PATCHADDR;
263 jp = (int *)0;
264 for (i=0; i < PCS_BITCNT; i++) {
265 extzv(i,jp,ip,1);
266 }
267 *((int *)PCS_PATCHBIT) = 0;
268
269 /*
270 * Load PCS microcode 20 bits at a time.
271 */
272 ip = (int *)PCS_PCSADDR;
273 jp = (int *)1024;
274 for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
275 extzv(i,jp,ip,20);
276 }
277
278 /*
279 * Enable PCS.
280 */
281 i = *jp; /* get 1st 20 bits of microcode again */
282 i &= 0xfffff;
283 i |= PCS_ENABLE; /* reload these bits with PCS enable set */
284 *((int *)PCS_PCSADDR) = i;
285
286 mid = mfpr(PR_SID);
287 printf("new rev level=%d\n", V750UCODE(mid));
288 pcsdone = 1;
289 }
290
291 void
292 usage()
293 {
294 struct vals *v = &val[0];
295
296 printf("Commands:\n");
297 while (v->namn) {
298 printf("%s\t%s\n", v->namn, v->info);
299 v++;
300 }
301 }
302