allow select on exceptional to check control operations
[unix-history] / usr / src / sys / vax / stand / boot.c
CommitLineData
8ae0e4b4
KM
1/*
2 * Copyright (c) 1982 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 *
5af1bd7a 6 * @(#)boot.c 6.4 (Berkeley) %G%
8ae0e4b4 7 */
b7e60356
BJ
8
9#include "../h/param.h"
b7e60356 10#include "../h/inode.h"
06254255 11#include "../h/fs.h"
b7e60356
BJ
12#include "../h/vm.h"
13#include <a.out.h>
14#include "saio.h"
06254255 15#include "../h/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
23/* Types in r10 specifying major device */
24char devname[][2] = {
25 'h','p', /* 0 = hp */
26 0,0, /* 1 = ht */
27 'u','p', /* 2 = up */
a0761322 28 'h','k', /* 3 = hk */
3486ee81
BJ
29 0,0, /* 4 = sw */
30 0,0, /* 5 = tm */
31 0,0, /* 6 = ts */
32 0,0, /* 7 = mt */
33 0,0, /* 8 = tu */
34 'r','a', /* 9 = ra */
1e549678
CL
35 'u','t', /* 10 = ut */
36 'r','b', /* 11 = rb */
c079fe19
SL
37 0,0, /* 12 = uu */
38 0,0, /* 13 = rx */
39 'r','l', /* 14 = rl */
8da76047
BJ
40};
41
5af1bd7a
JB
42/*
43 * constants for converting a "minor" device numbers to unit number
44 * and partition number
45 */
46#define UNITSHIFT 16
47#define UNITMASK 0x1ff
48#define PARTITIONMASK 0x7
49#define PARTITIONSHIFT 3
50
51char line[100] = "xx(00,0)vmunix";
b7e60356 52
a889f9b7
BJ
53int retry = 0;
54
b7e60356
BJ
55main()
56{
8da76047 57 register howto, devtype; /* howto=r11, devtype=r10 */
a889f9b7 58 int io;
5af1bd7a 59 register type, part, unit;
b7e60356 60
610c6f01
BJ
61#ifdef lint
62 howto = 0; devtype = 0;
63#endif
b7e60356 64 printf("\nBoot\n");
0bd37f37 65#ifdef JUSTASK
aaa709c3 66 howto = RB_ASKNAME|RB_SINGLE;
0bd37f37 67#else
5af1bd7a
JB
68 type = devtype & 0xff;
69 unit = (int)((unsigned)devtype >> UNITSHIFT) & UNITMASK;
70 part = unit & PARTITIONMASK;
71 unit = unit >> PARTITIONSHIFT;
8da76047 72 if ((howto&RB_ASKNAME)==0) {
5af1bd7a
JB
73 if (type >= 0 && type < sizeof(devname) / 2
74 && devname[type][0]) {
75 line[0] = devname[type][0];
76 line[1] = devname[type][1];
77 line[3] = unit / 10 + '0';
78 line[4] = unit % 10 + '0';
79 line[6] = part + '0';
a0761322 80 } else
8da76047 81 howto = RB_SINGLE|RB_ASKNAME;
8da76047 82 }
0bd37f37 83#endif
8da76047
BJ
84 for (;;) {
85 if (howto & RB_ASKNAME) {
86 printf(": ");
87 gets(line);
88 } else
89 printf(": %s\n", line);
90 io = open(line, 0);
e559a17c
TF
91 if (io >= 0) {
92 loadpcs();
a889f9b7 93 copyunix(howto, io);
e559a17c 94 }
8da76047
BJ
95 if (++retry > 2)
96 howto = RB_SINGLE|RB_ASKNAME;
97 }
b7e60356
BJ
98}
99
a889f9b7
BJ
100/*ARGSUSED*/
101copyunix(howto, io)
102 register howto, io;
b7e60356
BJ
103{
104 struct exec x;
105 register int i;
106 char *addr;
107
108 i = read(io, (char *)&x, sizeof x);
06254255
KM
109 if (i != sizeof x ||
110 (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
b7e60356
BJ
111 _stop("Bad format\n");
112 printf("%d", x.a_text);
b5d17f4d 113 if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
06254255 114 goto shread;
b7e60356
BJ
115 if (read(io, (char *)0, x.a_text) != x.a_text)
116 goto shread;
117 addr = (char *)x.a_text;
06254255
KM
118 if (x.a_magic == 0413 || x.a_magic == 0410)
119 while ((int)addr & CLOFSET)
120 *addr++ = 0;
b7e60356
BJ
121 printf("+%d", x.a_data);
122 if (read(io, addr, x.a_data) != x.a_data)
123 goto shread;
124 addr += x.a_data;
125 printf("+%d", x.a_bss);
126 x.a_bss += 128*512; /* slop */
127 for (i = 0; i < x.a_bss; i++)
128 *addr++ = 0;
129 x.a_entry &= 0x7fffffff;
130 printf(" start 0x%x\n", x.a_entry);
131 (*((int (*)()) x.a_entry))();
132 _exit();
133shread:
134 _stop("Short read\n");
135}
e559a17c
TF
136
137/* 750 Patchable Control Store magic */
138
139#include "../vax/mtpr.h"
140#include "../vax/cpu.h"
141#define PCS_BITCNT 0x2000 /* number of patchbits */
142#define PCS_MICRONUM 0x400 /* number of ucode locs */
143#define PCS_PATCHADDR 0xf00000 /* start addr of patchbits */
144#define PCS_PCSADDR (PCS_PATCHADDR+0x8000) /* start addr of pcs */
145#define PCS_PATCHBIT (PCS_PATCHADDR+0xc000) /* patchbits enable reg */
146#define PCS_ENABLE 0xfff00000 /* enable bits for pcs */
147
148loadpcs()
149{
150 register int *ip; /* known to be r11 below */
151 register int i; /* known to be r10 below */
152 register int *jp; /* known to be r9 below */
153 register int j;
154 static int pcsdone = 0;
155 union cpusid sid;
156 char pcs[100];
5af1bd7a
JB
157 char *closeparen;
158 char *index();
e559a17c
TF
159
160 sid.cpusid = mfpr(SID);
161 if (sid.cpuany.cp_type!=VAX_750 || sid.cpu750.cp_urev<95 || pcsdone)
162 return;
163 printf("Updating 11/750 microcode: ");
5af1bd7a
JB
164 strncpy(pcs, line, 99);
165 pcs[99] = 0;
166 closeparen = index(pcs, ')');
167 if (closeparen)
168 *(++closeparen) = 0;
169 else
170 return;
e559a17c
TF
171 strcat(pcs, "pcs750.bin");
172 i = open(pcs, 0);
173 if (i < 0)
174 return;
175 /*
176 * We ask for more than we need to be sure we get only what we expect.
177 * After read:
178 * locs 0 - 1023 packed patchbits
179 * 1024 - 11264 packed microcode
180 */
181 if (read(i, (char *)0, 23*512) != 22*512) {
182 printf("Error reading %s\n", pcs);
183 close(i);
184 return;
185 }
186 close(i);
187
188 /*
189 * Enable patchbit loading and load the bits one at a time.
190 */
191 *((int *)PCS_PATCHBIT) = 1;
192 ip = (int *)PCS_PATCHADDR;
193 jp = (int *)0;
194 for (i=0; i < PCS_BITCNT; i++) {
195 asm(" extzv r10,$1,(r9),(r11)+");
196 }
197 *((int *)PCS_PATCHBIT) = 0;
198
199 /*
200 * Load PCS microcode 20 bits at a time.
201 */
202 ip = (int *)PCS_PCSADDR;
203 jp = (int *)1024;
204 for (i=j=0; j < PCS_MICRONUM * 4; i+=20, j++) {
205 asm(" extzv r10,$20,(r9),(r11)+");
206 }
207
208 /*
209 * Enable PCS.
210 */
211 i = *jp; /* get 1st 20 bits of microcode again */
212 i &= 0xfffff;
213 i |= PCS_ENABLE; /* reload these bits with PCS enable set */
214 *((int *)PCS_PCSADDR) = i;
215
216 sid.cpusid = mfpr(SID);
217 printf("new rev level=%d\n", sid.cpu750.cp_urev);
218 pcsdone = 1;
219}