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