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