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