bootxx.c revision 1.1.12.1 1 /* $NetBSD: bootxx.c,v 1.1.12.1 1999/12/27 18:34:11 wrstuden 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 "sys/disklabel.h"
40
41 #include "lib/libsa/stand.h"
42 #include "lib/libsa/ufs.h"
43
44 #include "../include/pte.h"
45 #include "../include/sid.h"
46 #include "../include/mtpr.h"
47 #include "../include/reg.h"
48 #include "../include/rpb.h"
49
50 #include "../mba/mbareg.h"
51 #include "../mba/hpreg.h"
52
53 #define NRSP 1 /* Kludge */
54 #define NCMD 1 /* Kludge */
55
56 #include "dev/mscp/mscp.h"
57 #include "dev/mscp/mscpreg.h"
58
59 int command(int, int);
60
61 /*
62 * Boot program... argume passed in r10 and r11 determine whether boot
63 * stops to ask for system name and which device boot comes from.
64 */
65
66 volatile u_int devtype, bootdev;
67 unsigned opendev, boothowto, bootset, memsz;
68
69 struct open_file file;
70
71 unsigned *bootregs;
72 struct rpb *rpb;
73 int vax_cputype;
74
75 /*
76 * The boot block are used by 11/750, 8200, MicroVAX II/III, VS2000,
77 * VS3100/??, VS4000 and VAX6000/???, and only when booting from disk.
78 */
79 Xmain()
80 {
81 int io;
82 char *scbb;
83 char *new, *bqo;
84 char *hej = "/boot";
85
86 vax_cputype = (mfpr(PR_SID) >> 24) & 0xFF;
87
88 /*
89 */
90 switch (vax_cputype) {
91
92 case VAX_TYP_UV2:
93 case VAX_TYP_CVAX:
94 case VAX_TYP_RIGEL:
95 case VAX_TYP_NVAX:
96 case VAX_TYP_SOC:
97 /*
98 * now relocate rpb/bqo (which are used by ROM-routines)
99 */
100 rpb = (void*)XXRPB;
101 bcopy ((void*)bootregs[11], rpb, 512);
102 rpb->rpb_base = rpb;
103 bqo = (void*)(512+(int)rpb);
104 bcopy ((void*)rpb->iovec, bqo, rpb->iovecsz);
105 rpb->iovec = (int)bqo;
106 bootregs[11] = (int)rpb;
107 bootdev = rpb->devtyp;
108 memsz = rpb->pfncnt << 9;
109
110 break;
111 case VAX_8200:
112 case VAX_750:
113 bootdev = bootregs[10];
114 memsz = 0;
115
116 break;
117 default:
118 asm("halt");
119 }
120
121 bootset = getbootdev();
122
123 io = open(hej, 0);
124
125 read(io, (void *)0x10000, 0x10000);
126 bcopy((void *) 0x10000, 0, 0xffff);
127 hoppabort(32, boothowto, bootset);
128 asm("halt");
129 }
130
131 getbootdev()
132 {
133 int i, adaptor, controller, unit, partition, retval;
134
135 adaptor = controller = unit = partition = 0;
136
137 switch (vax_cputype) {
138 case VAX_TYP_UV2:
139 case VAX_TYP_CVAX:
140 case VAX_TYP_RIGEL:
141 if (rpb->devtyp == BDEV_SD) {
142 unit = rpb->unit / 100;
143 controller = (rpb->csrphy & 0x100 ? 1 : 0);
144 } else {
145 controller = ((rpb->csrphy & 017777) == 0xDC)?1:0;
146 unit = rpb->unit; /* DUC, DUD? */
147 }
148 break;
149
150 case VAX_TYP_8SS:
151 case VAX_TYP_750:
152 controller = bootregs[1];
153 unit = bootregs[3];
154 break;
155 }
156
157 switch (B_TYPE(bootdev)) {
158 case BDEV_HP: /* massbuss boot */
159 adaptor = (bootregs[1] & 0x6000) >> 17;
160 break;
161
162 case BDEV_UDA: /* UDA50 boot */
163 if (vax_cputype == VAX_750)
164 adaptor = (bootregs[1] & 0x40000 ? 0 : 1);
165 break;
166
167 case BDEV_TK: /* TK50 boot */
168 case BDEV_CNSL: /* Console storage boot */
169 case BDEV_RD: /* RD/RX on HDC9224 (MV2000) */
170 case BDEV_ST: /* SCSI-tape on NCR5380 (MV2000) */
171 case BDEV_SD: /* SCSI-disk on NCR5380 (3100/76) */
172 break;
173
174 case BDEV_KDB: /* DSA disk on KDB50 (VAXBI VAXen) */
175 bootdev = (bootdev & ~B_TYPEMASK) | BDEV_UDA;
176 break;
177
178 default:
179 boothowto |= (RB_SINGLE | RB_ASKNAME);
180 }
181 return MAKEBOOTDEV(bootdev, adaptor, controller, unit, partition);
182 }
183
184 int romstrategy __P((void *, int, daddr_t, size_t, void *, size_t *));
185
186 /*
187 * Write an extremely limited version of a (us)tar filesystem, suitable
188 * for loading secondary-stage boot loader.
189 * - Can only load file "boot".
190 * - Must be the first file on tape.
191 */
192 int tar_open(char *path, struct open_file *f);
193 ssize_t tar_read(struct open_file *f, void *buf, size_t size, size_t *resid);
194
195 int
196 tar_open(path, f)
197 char *path;
198 struct open_file *f;
199 {
200 char *buf = alloc(512);
201
202 bzero(buf, 512);
203 romstrategy(0, 0, 8192, 512, buf, 0);
204 if (bcmp(buf, "boot", 5) || bcmp(&buf[257], "ustar", 5))
205 return EINVAL; /* Not a ustarfs with "boot" first */
206 return 0;
207 }
208
209 ssize_t
210 tar_read(f, buf, size, resid)
211 struct open_file *f;
212 void *buf;
213 size_t size;
214 size_t *resid;
215 {
216 romstrategy(0, 0, (8192+512), size, buf, 0);
217 *resid = size;
218 }
219
220 struct disklabel lp;
221 int part_off = 0; /* offset into partition holding /boot */
222 char io_buf[MAXBSIZE];
223 volatile struct uda {
224 struct mscp_1ca uda_ca; /* communications area */
225 struct mscp uda_rsp; /* response packets */
226 struct mscp uda_cmd; /* command packets */
227 } uda;
228 struct udadevice {u_short udaip;u_short udasa;};
229 volatile struct udadevice *csr;
230
231 devopen(f, fname, file)
232 struct open_file *f;
233 const char *fname;
234 char **file;
235 {
236 extern char start;
237 char *msg;
238 int i, err, off;
239 char line[64];
240
241 *file = (char *)fname;
242
243 /*
244 * On uVAX we need to init [T]MSCP ctlr to be able to use it.
245 */
246 if (vax_cputype == VAX_TYP_UV2 || vax_cputype == VAX_TYP_CVAX) {
247 switch (bootdev) {
248 case BDEV_UDA: /* MSCP */
249 case BDEV_TK: /* TMSCP */
250 csr = (struct udadevice *)rpb->csrphy;
251
252 csr->udaip = 0; /* Start init */
253 while((csr->udasa & MP_STEP1) == 0);
254 csr->udasa = 0x8000;
255 while((csr->udasa & MP_STEP2) == 0);
256 csr->udasa = (short)(((u_int)&uda)&0xffff) + 8;
257 while((csr->udasa & MP_STEP3) == 0);
258 csr->udasa = 0x10;
259 while((csr->udasa & MP_STEP4) == 0);
260 csr->udasa = 0x0001;
261
262 uda.uda_ca.ca_rspdsc =
263 (int) &uda.uda_rsp.mscp_cmdref;
264 uda.uda_ca.ca_cmddsc =
265 (int) &uda.uda_cmd.mscp_cmdref;
266 if (bootdev == BDEV_TK)
267 uda.uda_cmd.mscp_vcid = 1;
268 command(M_OP_SETCTLRC, 0);
269 uda.uda_cmd.mscp_unit = rpb->unit;
270 command(M_OP_ONLINE, 0);
271 }
272 }
273
274 /*
275 * the disklabel _shall_ be at address LABELOFFSET + RELOC in
276 * phys memory now, no need at all to reread it again.
277 * Actually disklabel is only needed when using hp disks,
278 * but it doesn't hurt to always get it.
279 */
280 getdisklabel(LABELOFFSET + &start, &lp);
281 return 0;
282 }
283
284 command(cmd, arg)
285 {
286 volatile int hej;
287
288 uda.uda_cmd.mscp_opcode = cmd;
289 uda.uda_cmd.mscp_modifier = arg;
290
291 uda.uda_cmd.mscp_msglen = MSCP_MSGLEN;
292 uda.uda_rsp.mscp_msglen = MSCP_MSGLEN;
293 uda.uda_ca.ca_rspdsc |= MSCP_OWN|MSCP_INT;
294 uda.uda_ca.ca_cmddsc |= MSCP_OWN|MSCP_INT;
295 hej = csr->udaip;
296 while (uda.uda_ca.ca_rspdsc < 0);
297
298 }
299
300 int curblock = 0;
301
302 romstrategy(sc, func, dblk, size, buf, rsize)
303 void *sc;
304 int func;
305 daddr_t dblk;
306 size_t size;
307 void *buf;
308 size_t *rsize;
309 {
310 int i;
311 int block = dblk;
312 int nsize = size;
313
314 switch (vax_cputype) {
315 /*
316 * case VAX_TYP_UV2:
317 * case VAX_TYP_CVAX:
318 * case VAX_TYP_RIGEL:
319 */
320 default:
321 switch (bootdev) {
322
323 case BDEV_UDA: /* MSCP */
324 uda.uda_cmd.mscp_seq.seq_lbn = dblk;
325 uda.uda_cmd.mscp_seq.seq_bytecount = size;
326 uda.uda_cmd.mscp_seq.seq_buffer = (int)buf;
327 uda.uda_cmd.mscp_unit = rpb->unit;
328 command(M_OP_READ, 0);
329 break;
330
331 case BDEV_TK: /* TMSCP */
332 if (dblk < curblock) {
333 uda.uda_cmd.mscp_seq.seq_bytecount =
334 curblock - dblk;
335 command(M_OP_POS, 12);
336 } else {
337 uda.uda_cmd.mscp_seq.seq_bytecount =
338 dblk - curblock;
339 command(M_OP_POS, 4);
340 }
341 curblock = size/512 + dblk;
342 for (i = 0 ; i < size/512 ; i++) {
343 uda.uda_cmd.mscp_seq.seq_lbn = 1;
344 uda.uda_cmd.mscp_seq.seq_bytecount = 512;
345 uda.uda_cmd.mscp_seq.seq_buffer =
346 (int)buf + i * 512;
347 uda.uda_cmd.mscp_unit = rpb->unit;
348 command(M_OP_READ, 0);
349 }
350 break;
351 case BDEV_RD:
352 case BDEV_ST:
353 case BDEV_SD:
354
355 default:
356 romread_uvax(block, size, buf, bootregs);
357 break;
358
359 }
360 break;
361
362 case VAX_8200:
363 case VAX_750:
364 if (bootdev != BDEV_HP) {
365 while (size > 0) {
366 while ((read750(block, bootregs) & 0x01) == 0){
367 }
368 bcopy(0, buf, 512);
369 size -= 512;
370 buf += 512;
371 block++;
372 }
373 } else
374 hpread(block, size, buf);
375 break;
376 }
377
378 if (rsize)
379 *rsize = nsize;
380 return 0;
381 }
382
383 hpread(block, size, buf)
384 char *buf;
385 {
386 volatile struct mba_regs *mr = (void *) bootregs[1];
387 volatile struct hp_drv *hd = (void*)&mr->mba_md[bootregs[3]];
388 struct disklabel *dp = &lp;
389 u_int pfnum, nsize, mapnr, bn, cn, sn, tn;
390
391 pfnum = (u_int) buf >> PGSHIFT;
392
393 for (mapnr = 0, nsize = size; (nsize + NBPG) > 0; nsize -= NBPG)
394 *(int *)&mr->mba_map[mapnr++] = PG_V | pfnum++;
395 mr->mba_var = ((u_int) buf & PGOFSET);
396 mr->mba_bc = (~size) + 1;
397 bn = block;
398 cn = bn / dp->d_secpercyl;
399 sn = bn % dp->d_secpercyl;
400 tn = sn / dp->d_nsectors;
401 sn = sn % dp->d_nsectors;
402 hd->hp_dc = cn;
403 hd->hp_da = (tn << 8) | sn;
404 hd->hp_cs1 = HPCS_READ;
405 while (mr->mba_sr & MBASR_DTBUSY);
406 if (mr->mba_sr & MBACR_ABORT){
407 return 1;
408 }
409 return 0;
410 }
411
412 extern char end[];
413 static char *top = (char*)end;
414
415 void *
416 alloc(size)
417 unsigned size;
418 {
419 void *ut = top;
420 top += size;
421 return ut;
422 }
423
424 void
425 free(ptr, size)
426 void *ptr;
427 unsigned size;
428 {
429 }
430
431 int
432 romclose(f)
433 struct open_file *f;
434 {
435 return 0;
436 }
437