Home | History | Annotate | Line # | Download | only in xxboot
bootxx.c revision 1.10
      1 /* $NetBSD: bootxx.c,v 1.10 2000/07/10 09:55:36 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 #include "lib/libsa/cd9660.h"
     44 
     45 #include "lib/libkern/libkern.h"
     46 
     47 #include "../include/pte.h"
     48 #include "../include/sid.h"
     49 #include "../include/mtpr.h"
     50 #include "../include/reg.h"
     51 #include "../include/rpb.h"
     52 #include "../vax/gencons.h"
     53 
     54 #include "../mba/mbareg.h"
     55 #include "../mba/hpreg.h"
     56 
     57 #define NRSP 1 /* Kludge */
     58 #define NCMD 1 /* Kludge */
     59 
     60 #include "dev/mscp/mscp.h"
     61 #include "dev/mscp/mscpreg.h"
     62 
     63 #include "../boot/data.h"
     64 
     65 void	Xmain(void);
     66 void	hoppabort(int);
     67 void	romread_uvax(int lbn, int size, void *buf, struct rpb *rpb);
     68 void	hpread(int block);
     69 int	read750(int block, int *regs);
     70 int	unit_init(int, struct rpb *, int);
     71 
     72 struct open_file file;
     73 
     74 unsigned *bootregs;
     75 struct	rpb *rpb;
     76 struct	bqo *bqo;
     77 int	vax_cputype;
     78 struct udadevice {u_short udaip;u_short udasa;};
     79 volatile struct udadevice *csr;
     80 static int moved;
     81 
     82 extern int from;
     83 #define	FROM750	1
     84 #define	FROMMV	2
     85 #define	FROMVMB	4
     86 
     87 /*
     88  * The boot block are used by 11/750, 8200, MicroVAX II/III, VS2000,
     89  * VS3100/??, VS4000 and VAX6000/???, and only when booting from disk.
     90  */
     91 void
     92 Xmain()
     93 {
     94 	int io;
     95 
     96 	vax_cputype = (mfpr(PR_SID) >> 24) & 0xFF;
     97 	moved = 0;
     98 	/*
     99 	 */
    100 	rpb = (void *)0xf0000; /* Safe address right now */
    101 	bqo = (void *)0xf1000;
    102         if (from == FROMMV) {
    103 		/*
    104 		 * now relocate rpb/bqo (which are used by ROM-routines)
    105 		 */
    106 		bcopy ((void *)bootregs[11], rpb, sizeof(struct rpb));
    107 		bcopy ((void*)rpb->iovec, bqo, rpb->iovecsz);
    108 		if (rpb->devtyp == BDEV_SDN)
    109 			rpb->devtyp = BDEV_SD;	/* XXX until driver fixed */
    110 	} else {
    111 		bzero(rpb, sizeof(struct rpb));
    112 		rpb->devtyp = bootregs[0];
    113 		rpb->unit = bootregs[3];
    114 		rpb->rpb_bootr5 = bootregs[5];
    115 		rpb->csrphy = bootregs[2];
    116 		rpb->adpphy = bootregs[1];	/* BI node on 8200 */
    117 		if (rpb->devtyp != BDEV_HP && vax_cputype == VAX_TYP_750)
    118 			rpb->adpphy =
    119 			    (bootregs[1] == 0xffe000 ? 0xf30000 : 0xf32000);
    120         }
    121 	rpb->rpb_base = rpb;
    122 	rpb->iovec = (int)bqo;
    123 
    124 	io = open("/boot.vax", 0);
    125 	if (io < 0)
    126 		io = open("/boot", 0);
    127 	if (io < 0)
    128 		asm("halt");
    129 
    130 	read(io, (void *)0x10000, 0x10000);
    131 	bcopy((void *) 0x10000, 0, 0xffff);
    132 	hoppabort(32);
    133 	asm("halt");
    134 }
    135 
    136 /*
    137  * Write an extremely limited version of a (us)tar filesystem, suitable
    138  * for loading secondary-stage boot loader.
    139  * - Can only load file "boot".
    140  * - Must be the first file on tape.
    141  */
    142 struct fs_ops file_system[] = {
    143 	{ ufs_open, 0, ufs_read, 0, 0, ufs_stat },
    144 	{ cd9660_open, 0, cd9660_read, 0, 0, cd9660_stat },
    145 #if 0
    146 	{ ustarfs_open, 0, ustarfs_read, 0, 0, ustarfs_stat },
    147 #endif
    148 };
    149 
    150 int nfsys = (sizeof(file_system) / sizeof(struct fs_ops));
    151 
    152 #if 0
    153 int tar_open(char *path, struct open_file *f);
    154 ssize_t tar_read(struct open_file *f, void *buf, size_t size, size_t *resid);
    155 
    156 int
    157 tar_open(path, f)
    158 	char *path;
    159 	struct open_file *f;
    160 {
    161 	char *buf = alloc(512);
    162 
    163 	bzero(buf, 512);
    164 	romstrategy(0, 0, 8192, 512, buf, 0);
    165 	if (bcmp(buf, "boot", 5) || bcmp(&buf[257], "ustar", 5))
    166 		return EINVAL; /* Not a ustarfs with "boot" first */
    167 	return 0;
    168 }
    169 
    170 ssize_t
    171 tar_read(f, buf, size, resid)
    172 	struct open_file *f;
    173 	void *buf;
    174 	size_t size;
    175 	size_t *resid;
    176 {
    177 	romstrategy(0, 0, (8192+512), size, buf, 0);
    178 	*resid = size;
    179 	return 0; /* XXX */
    180 }
    181 #endif
    182 
    183 
    184 int
    185 devopen(f, fname, file)
    186 	struct open_file *f;
    187 	const char    *fname;
    188 	char          **file;
    189 {
    190 	*file = (char *)fname;
    191 
    192 	if (from == FROM750)
    193 		return 0;
    194 	/*
    195 	 * Reinit the VMB boot device.
    196 	 */
    197 	if (bqo->unit_init && (moved++ == 0)) {
    198 		int initfn;
    199 
    200 		initfn = rpb->iovec + bqo->unit_init;
    201 		if (rpb->devtyp == BDEV_UDA || rpb->devtyp == BDEV_TK) {
    202 			/*
    203 			 * This reset do not seem to be done in the
    204 			 * ROM routines, so we have to do it manually.
    205 			 */
    206 			csr = (struct udadevice *)rpb->csrphy;
    207 			csr->udaip = 0;
    208 			while ((csr->udasa & MP_STEP1) == 0)
    209 				;
    210 		}
    211 		/*
    212 		 * AP (R12) have a pointer to the VMB argument list,
    213 		 * wanted by bqo->unit_init.
    214 		 */
    215 		unit_init(initfn, rpb, bootregs[12]);
    216 	}
    217 	return 0;
    218 }
    219 
    220 int
    221 romstrategy(sc, func, dblk, size, buf, rsize)
    222 	void    *sc;
    223 	int     func;
    224 	daddr_t dblk;
    225 	size_t	size;
    226 	void    *buf;
    227 	size_t	*rsize;
    228 {
    229 	int	block = dblk;
    230 	int     nsize = size;
    231 
    232 	if (from == FROMMV) {
    233 		romread_uvax(block, size, buf, rpb);
    234 	} else /* if (from == FROM750) */ {
    235 		while (size > 0) {
    236 			if (rpb->devtyp == BDEV_HP)
    237 				hpread(block);
    238 			else
    239 				read750(block, bootregs);
    240 			bcopy(0, buf, 512);
    241 			size -= 512;
    242 			(char *)buf += 512;
    243 			block++;
    244 		}
    245 	}
    246 
    247 	if (rsize)
    248 		*rsize = nsize;
    249 	return 0;
    250 }
    251 
    252 /*
    253  * The 11/750 boot ROM for Massbus disks doesn't seen to have layout info
    254  * for all RP disks (not RP07 at least) so therefore a very small and dumb
    255  * device driver is used. It assumes that there is a label on the disk
    256  * already that has valid layout info. If there is no label, we can't boot
    257  * anyway.
    258  */
    259 
    260 #define MBA_WCSR(reg, val) \
    261 	((void)(*(volatile u_int32_t *)((adpadr) + (reg)) = (val)));
    262 #define MBA_RCSR(reg) \
    263 	(*(volatile u_int32_t *)((adpadr) + (reg)))
    264 #define HP_WCSR(reg, val) \
    265 	((void)(*(volatile u_int32_t *)((unitadr) + (reg)) = (val)));
    266 #define HP_RCSR(reg) \
    267 	(*(volatile u_int32_t *)((unitadr) + (reg)))
    268 
    269 void
    270 hpread(int bn)
    271 {
    272 	int adpadr = bootregs[1];
    273 	int unitadr = adpadr + MUREG(bootregs[3], 0);
    274 	u_int cn, sn, tn;
    275 	struct disklabel *dp;
    276 	extern char start;
    277 
    278 	dp = (struct disklabel *)(LABELOFFSET + &start);
    279 	MBA_WCSR(MAPREG(0), PG_V);
    280 
    281 	MBA_WCSR(MBA_VAR, 0);
    282 	MBA_WCSR(MBA_BC, (~512) + 1);
    283 #ifdef __GNUC__
    284 	/*
    285 	 * Avoid four subroutine calls by using hardware division.
    286 	 */
    287 	asm("clrl r1;movl %3,r0;ediv %4,r0,%0,%1;movl %1,r0;ediv %5,r0,%2,%1"
    288 	    : "=g"(cn),"=g"(sn),"=g"(tn)
    289 	    : "g"(bn),"g"(dp->d_secpercyl),"g"(dp->d_nsectors)
    290 	    : "r0","r1","cc");
    291 #else
    292 	cn = bn / dp->d_secpercyl;
    293 	sn = bn % dp->d_secpercyl;
    294 	tn = sn / dp->d_nsectors;
    295 	sn = sn % dp->d_nsectors;
    296 #endif
    297 	HP_WCSR(HP_DC, cn);
    298 	HP_WCSR(HP_DA, (tn << 8) | sn);
    299 	HP_WCSR(HP_CS1, HPCS_READ);
    300 
    301 	while (MBA_RCSR(MBA_SR) & MBASR_DTBUSY)
    302 		;
    303 	return;
    304 }
    305 
    306 extern char end[];
    307 static char *top = (char*)end;
    308 
    309 void *
    310 alloc(size)
    311         unsigned size;
    312 {
    313 	void *ut = top;
    314 	top += size;
    315 	return ut;
    316 }
    317 
    318 void
    319 free(ptr, size)
    320         void *ptr;
    321         unsigned size;
    322 {
    323 }
    324 
    325 int
    326 romclose(f)
    327 	struct open_file *f;
    328 {
    329 	return 0;
    330 }
    331 
    332 #ifdef USE_PRINTF
    333 void
    334 putchar(int ch)
    335 {
    336 	/*
    337 	 * On KA88 we may get C-S/C-Q from the console.
    338 	 * Must obey it.
    339 	 */
    340 	while (mfpr(PR_RXCS) & GC_DON) {
    341 		if ((mfpr(PR_RXDB) & 0x7f) == 19) {
    342 			while (1) {
    343 				while ((mfpr(PR_RXCS) & GC_DON) == 0)
    344 					;
    345 				if ((mfpr(PR_RXDB) & 0x7f) == 17)
    346 					break;
    347 			}
    348 		}
    349 	}
    350 
    351 	while ((mfpr(PR_TXCS) & GC_RDY) == 0)
    352 		;
    353 	mtpr(0, PR_TXCS);
    354 	mtpr(ch & 0377, PR_TXDB);
    355 	if (ch == 10)
    356 		putchar(13);
    357 }
    358 #endif
    359