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