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