boot.c revision 1.13 1 /* $NetBSD: boot.c,v 1.13 2000/08/30 18:16:09 jdolecek 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 #include "lib/libsa/loadfile.h"
41 #include "lib/libkern/libkern.h"
42
43 #define V750UCODE(x) ((x>>8)&255)
44
45 #include "machine/rpb.h"
46
47 #include "vaxstand.h"
48
49 /*
50 * Boot program... arguments passed in r10 and r11 determine
51 * whether boot stops to ask for system name and which device
52 * boot comes from.
53 */
54
55 char line[100];
56 int bootdev, debug;
57 extern unsigned opendev;
58
59 void usage(char *), boot(char *), halt(char *);
60 void Xmain(void);
61 void autoconf(void);
62 int getsecs(void);
63 int setjmp(int *);
64 int testkey(void);
65 void loadpcs(void);
66
67 const struct vals {
68 char *namn;
69 void (*func)(char *);
70 char *info;
71 } val[] = {
72 {"?", usage, "Show this help menu"},
73 {"help", usage, "Same as '?'"},
74 {"boot", boot, "Load and execute file"},
75 {"halt", halt, "Halts the system"},
76 {0, 0},
77 };
78
79 static struct {
80 char name[12];
81 int quiet;
82 } filelist[] = {
83 { "netbsd.vax", 1 },
84 { "netbsd", 0 },
85 { "netbsd.gz", 0 },
86 { "netbsd.old", 0 },
87 { "gennetbsd", 0 },
88 { "", 0 },
89 };
90
91 int jbuf[10];
92 int sluttid, senast, skip, askname;
93 struct rpb bootrpb;
94
95 void
96 Xmain(void)
97 {
98 int io;
99 int j, nu;
100 u_long marks[MARK_MAX];
101 extern const char *bootprog_rev, *bootprog_date;
102
103 io = 0;
104 skip = 1;
105 autoconf();
106
107 askname = bootrpb.rpb_bootr5 & RB_ASKNAME;
108 printf("\n\r>> NetBSD/vax boot [%s %s] <<\n", bootprog_rev,
109 bootprog_date);
110 printf(">> Press any key to abort autoboot ");
111 sluttid = getsecs() + 5;
112 senast = 0;
113 skip = 0;
114 setjmp(jbuf);
115 for (;;) {
116 nu = sluttid - getsecs();
117 if (senast != nu)
118 printf("%c%d", 8, nu);
119 if (nu <= 0)
120 break;
121 senast = nu;
122 if ((j = (testkey() & 0177))) {
123 skip = 1;
124 if (j != 10 && j != 13) {
125 printf("\nPress '?' for help");
126 askname = 1;
127 }
128 break;
129 }
130 }
131 skip = 1;
132 printf("\n");
133
134 /* First try to autoboot */
135 if (askname == 0) {
136 int fileindex;
137 for (fileindex = 0; filelist[fileindex].name[0] != '\0';
138 fileindex++) {
139 int err;
140 errno = 0;
141 if (!filelist[fileindex].quiet)
142 printf("> boot %s\n", filelist[fileindex].name);
143 marks[MARK_START] = 0;
144 err = loadfile(filelist[fileindex].name, marks, LOAD_KERNEL|COUNT_KERNEL);
145 if (err == 0) {
146 machdep_start((char *)marks[MARK_ENTRY], 0,
147 (void *)marks[MARK_START],
148 (void *)marks[MARK_SYM],
149 (void *)marks[MARK_END]);
150 }
151 if (!filelist[fileindex].quiet)
152 printf("%s: boot failed: %s\n",
153 filelist[fileindex].name, strerror(errno));
154 #if 0 /* Will hang VAX 4000 machines */
155 if (testkey())
156 break;
157 #endif
158 }
159 }
160
161 /* If any key pressed, go to conversational boot */
162 for (;;) {
163 const struct vals *v = &val[0];
164 char *c, *d;
165
166 printf("> ");
167 gets(line);
168
169 c = line;
170 while (*c == ' ')
171 c++;
172
173 if (c[0] == 0)
174 continue;
175
176 if ((d = index(c, ' ')))
177 *d++ = 0;
178
179 while (v->namn) {
180 if (strcmp(v->namn, c) == 0)
181 break;
182 v++;
183 }
184 if (v->namn)
185 (*v->func)(d);
186 else
187 printf("Unknown command: %s\n", c);
188 }
189 }
190
191 void
192 halt(char *hej)
193 {
194 asm("halt");
195 }
196
197 void
198 boot(char *arg)
199 {
200 char *fn = "netbsd";
201
202 if (arg) {
203 while (*arg == ' ')
204 arg++;
205
206 if (*arg != '-') {
207 fn = arg;
208 if ((arg = index(arg, ' '))) {
209 *arg++ = 0;
210 while (*arg == ' ')
211 arg++;
212 } else
213 goto load;
214 }
215 if (*arg != '-') {
216 fail: printf("usage: boot [filename] [-asd]\n");
217 return;
218 }
219
220 while (*++arg) {
221 if (*arg == 'a')
222 bootrpb.rpb_bootr5 |= RB_ASKNAME;
223 else if (*arg == 'd')
224 bootrpb.rpb_bootr5 |= RB_KDB;
225 else if (*arg == 's')
226 bootrpb.rpb_bootr5 |= RB_SINGLE;
227 else
228 goto fail;
229 }
230 }
231 load: exec(fn, 0, 0);
232 printf("Boot failed: %s\n", strerror(errno));
233 }
234
235 /* 750 Patchable Control Store magic */
236
237 #include "../include/mtpr.h"
238 #include "../include/cpu.h"
239 #include "../include/sid.h"
240 #define PCS_BITCNT 0x2000 /* number of patchbits */
241 #define PCS_MICRONUM 0x400 /* number of ucode locs */
242 #define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */
243 #define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */
244 #define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */
245 #define PCS_ENABLE 0xfff00000 /* enable bits for pcs */
246
247 #define extzv(one, two, three,four) \
248 ({ \
249 asm __volatile (" extzv %0,%3,(%1),(%2)+" \
250 : \
251 : "g"(one),"g"(two),"g"(three),"g"(four)); \
252 })
253
254
255 void
256 loadpcs()
257 {
258 static int pcsdone = 0;
259 int mid = mfpr(PR_SID);
260 int i, j, *ip, *jp;
261 char pcs[100];
262 char *cp;
263
264 if ((mid >> 24) != VAX_750 || ((mid >> 8) & 255) < 95 || pcsdone)
265 return;
266 printf("Updating 11/750 microcode: ");
267 for (cp = line; *cp; cp++)
268 if (*cp == ')' || *cp == ':')
269 break;
270 if (*cp) {
271 bcopy(line, pcs, 99);
272 pcs[99] = 0;
273 i = cp - line + 1;
274 } else
275 i = 0;
276 strcpy(pcs + i, "pcs750.bin");
277 i = open(pcs, 0);
278 if (i < 0) {
279 printf("bad luck - missing pcs750.bin :-(\n");
280 return;
281 }
282 /*
283 * We ask for more than we need to be sure we get only what we expect.
284 * After read:
285 * locs 0 - 1023 packed patchbits
286 * 1024 - 11264 packed microcode
287 */
288 if (read(i, (char *)0, 23*512) != 22*512) {
289 printf("Error reading %s\n", pcs);
290 close(i);
291 return;
292 }
293 close(i);
294
295 /*
296 * Enable patchbit loading and load the bits one at a time.
297 */
298 *((int *)PCS_PATCHBIT) = 1;
299 ip = (int *)PCS_PATCHADDR;
300 jp = (int *)0;
301 for (i=0; i < PCS_BITCNT; i++) {
302 extzv(i,jp,ip,1);
303 }
304 *((int *)PCS_PATCHBIT) = 0;
305
306 /*
307 * Load PCS microcode 20 bits at a time.
308 */
309 ip = (int *)PCS_PCSADDR;
310 jp = (int *)1024;
311 for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
312 extzv(i,jp,ip,20);
313 }
314
315 /*
316 * Enable PCS.
317 */
318 i = *jp; /* get 1st 20 bits of microcode again */
319 i &= 0xfffff;
320 i |= PCS_ENABLE; /* reload these bits with PCS enable set */
321 *((int *)PCS_PCSADDR) = i;
322
323 mid = mfpr(PR_SID);
324 printf("new rev level=%d\n", V750UCODE(mid));
325 pcsdone = 1;
326 }
327
328 void
329 usage(char *hej)
330 {
331 const struct vals *v = &val[0];
332
333 printf("Commands:\n");
334 while (v->namn) {
335 printf("%s\t%s\n", v->namn, v->info);
336 v++;
337 }
338 }
339