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