Home | History | Annotate | Line # | Download | only in xxboot
bootxx.c revision 1.9
      1  1.9  ragge /* $NetBSD: bootxx.c,v 1.9 2000/06/04 19:58:17 ragge Exp $ */
      2  1.1  ragge /*-
      3  1.1  ragge  * Copyright (c) 1982, 1986 The Regents of the University of California.
      4  1.1  ragge  * All rights reserved.
      5  1.1  ragge  *
      6  1.1  ragge  * Redistribution and use in source and binary forms, with or without
      7  1.1  ragge  * modification, are permitted provided that the following conditions
      8  1.1  ragge  * are met:
      9  1.1  ragge  * 1. Redistributions of source code must retain the above copyright
     10  1.1  ragge  *    notice, this list of conditions and the following disclaimer.
     11  1.1  ragge  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  ragge  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  ragge  *    documentation and/or other materials provided with the distribution.
     14  1.1  ragge  * 3. All advertising materials mentioning features or use of this software
     15  1.1  ragge  *    must display the following acknowledgement:
     16  1.1  ragge  *	This product includes software developed by the University of
     17  1.1  ragge  *	California, Berkeley and its contributors.
     18  1.1  ragge  * 4. Neither the name of the University nor the names of its contributors
     19  1.1  ragge  *    may be used to endorse or promote products derived from this software
     20  1.1  ragge  *    without specific prior written permission.
     21  1.1  ragge  *
     22  1.1  ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.1  ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1  ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1  ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.1  ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1  ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1  ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1  ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1  ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  ragge  * SUCH DAMAGE.
     33  1.1  ragge  *
     34  1.1  ragge  *	@(#)boot.c	7.15 (Berkeley) 5/4/91
     35  1.1  ragge  */
     36  1.1  ragge 
     37  1.1  ragge #include "sys/param.h"
     38  1.1  ragge #include "sys/reboot.h"
     39  1.1  ragge #include "sys/disklabel.h"
     40  1.1  ragge 
     41  1.1  ragge #include "lib/libsa/stand.h"
     42  1.1  ragge #include "lib/libsa/ufs.h"
     43  1.6  ragge #include "lib/libsa/cd9660.h"
     44  1.6  ragge 
     45  1.6  ragge #include "lib/libkern/libkern.h"
     46  1.1  ragge 
     47  1.1  ragge #include "../include/pte.h"
     48  1.1  ragge #include "../include/sid.h"
     49  1.1  ragge #include "../include/mtpr.h"
     50  1.1  ragge #include "../include/reg.h"
     51  1.1  ragge #include "../include/rpb.h"
     52  1.1  ragge 
     53  1.1  ragge #include "../mba/mbareg.h"
     54  1.1  ragge #include "../mba/hpreg.h"
     55  1.1  ragge 
     56  1.1  ragge #define NRSP 1 /* Kludge */
     57  1.1  ragge #define NCMD 1 /* Kludge */
     58  1.1  ragge 
     59  1.2  ragge #include "dev/mscp/mscp.h"
     60  1.2  ragge #include "dev/mscp/mscpreg.h"
     61  1.1  ragge 
     62  1.6  ragge #include "../boot/data.h"
     63  1.1  ragge 
     64  1.6  ragge void	Xmain(void);
     65  1.6  ragge void	hoppabort(int);
     66  1.6  ragge void	romread_uvax(int lbn, int size, void *buf, struct rpb *rpb);
     67  1.7  ragge void	hpread(int block);
     68  1.6  ragge int	read750(int block, int *regs);
     69  1.6  ragge int	unit_init(int, struct rpb *, int);
     70  1.1  ragge 
     71  1.2  ragge struct open_file file;
     72  1.2  ragge 
     73  1.1  ragge unsigned *bootregs;
     74  1.1  ragge struct	rpb *rpb;
     75  1.6  ragge struct	bqo *bqo;
     76  1.1  ragge int	vax_cputype;
     77  1.6  ragge struct udadevice {u_short udaip;u_short udasa;};
     78  1.6  ragge volatile struct udadevice *csr;
     79  1.6  ragge 
     80  1.6  ragge extern int from;
     81  1.6  ragge #define	FROM750	1
     82  1.6  ragge #define	FROMMV	2
     83  1.6  ragge #define	FROMVMB	4
     84  1.1  ragge 
     85  1.1  ragge /*
     86  1.1  ragge  * The boot block are used by 11/750, 8200, MicroVAX II/III, VS2000,
     87  1.1  ragge  * VS3100/??, VS4000 and VAX6000/???, and only when booting from disk.
     88  1.1  ragge  */
     89  1.6  ragge void
     90  1.1  ragge Xmain()
     91  1.1  ragge {
     92  1.1  ragge 	int io;
     93  1.1  ragge 
     94  1.1  ragge 	vax_cputype = (mfpr(PR_SID) >> 24) & 0xFF;
     95  1.1  ragge 
     96  1.2  ragge 	/*
     97  1.2  ragge 	 */
     98  1.6  ragge 	rpb = (void *)0xf0000; /* Safe address right now */
     99  1.6  ragge 	bqo = (void *)0xf1000;
    100  1.6  ragge         if (from == FROMMV) {
    101  1.1  ragge 		/*
    102  1.1  ragge 		 * now relocate rpb/bqo (which are used by ROM-routines)
    103  1.1  ragge 		 */
    104  1.6  ragge 		bcopy ((void *)bootregs[11], rpb, sizeof(struct rpb));
    105  1.1  ragge 		bcopy ((void*)rpb->iovec, bqo, rpb->iovecsz);
    106  1.4  ragge 		if (rpb->devtyp == BDEV_SDN)
    107  1.4  ragge 			rpb->devtyp = BDEV_SD;	/* XXX until driver fixed */
    108  1.6  ragge 	} else {
    109  1.6  ragge 		bzero(rpb, sizeof(struct rpb));
    110  1.6  ragge 		rpb->devtyp = bootregs[0];
    111  1.6  ragge 		rpb->unit = bootregs[3];
    112  1.6  ragge 		rpb->rpb_bootr5 = bootregs[5];
    113  1.6  ragge 		rpb->csrphy = bootregs[2];
    114  1.6  ragge 		rpb->adpphy = bootregs[1];	/* BI node on 8200 */
    115  1.7  ragge 		if (rpb->devtyp != BDEV_HP && vax_cputype == VAX_TYP_750)
    116  1.7  ragge 			rpb->adpphy =
    117  1.7  ragge 			    (bootregs[1] == 0xffe000 ? 0xf30000 : 0xf32000);
    118  1.1  ragge         }
    119  1.6  ragge 	rpb->rpb_base = rpb;
    120  1.6  ragge 	rpb->iovec = (int)bqo;
    121  1.1  ragge 
    122  1.8   matt 	io = open("/boot.vax", 0);
    123  1.8   matt 	if (io < 0)
    124  1.8   matt 		io = open("/boot", 0);
    125  1.8   matt 	if (io < 0)
    126  1.8   matt 		asm("halt");
    127  1.1  ragge 
    128  1.2  ragge 	read(io, (void *)0x10000, 0x10000);
    129  1.2  ragge 	bcopy((void *) 0x10000, 0, 0xffff);
    130  1.6  ragge 	hoppabort(32);
    131  1.2  ragge 	asm("halt");
    132  1.1  ragge }
    133  1.1  ragge 
    134  1.2  ragge /*
    135  1.2  ragge  * Write an extremely limited version of a (us)tar filesystem, suitable
    136  1.2  ragge  * for loading secondary-stage boot loader.
    137  1.2  ragge  * - Can only load file "boot".
    138  1.2  ragge  * - Must be the first file on tape.
    139  1.2  ragge  */
    140  1.6  ragge struct fs_ops file_system[] = {
    141  1.6  ragge 	{ ufs_open, 0, ufs_read, 0, 0, ufs_stat },
    142  1.6  ragge 	{ cd9660_open, 0, cd9660_read, 0, 0, cd9660_stat },
    143  1.6  ragge #if 0
    144  1.6  ragge 	{ ustarfs_open, 0, ustarfs_read, 0, 0, ustarfs_stat },
    145  1.6  ragge #endif
    146  1.6  ragge };
    147  1.6  ragge 
    148  1.6  ragge int nfsys = (sizeof(file_system) / sizeof(struct fs_ops));
    149  1.6  ragge 
    150  1.6  ragge #if 0
    151  1.2  ragge int tar_open(char *path, struct open_file *f);
    152  1.2  ragge ssize_t tar_read(struct open_file *f, void *buf, size_t size, size_t *resid);
    153  1.1  ragge 
    154  1.2  ragge int
    155  1.2  ragge tar_open(path, f)
    156  1.2  ragge 	char *path;
    157  1.2  ragge 	struct open_file *f;
    158  1.2  ragge {
    159  1.2  ragge 	char *buf = alloc(512);
    160  1.2  ragge 
    161  1.2  ragge 	bzero(buf, 512);
    162  1.2  ragge 	romstrategy(0, 0, 8192, 512, buf, 0);
    163  1.2  ragge 	if (bcmp(buf, "boot", 5) || bcmp(&buf[257], "ustar", 5))
    164  1.2  ragge 		return EINVAL; /* Not a ustarfs with "boot" first */
    165  1.2  ragge 	return 0;
    166  1.2  ragge }
    167  1.2  ragge 
    168  1.2  ragge ssize_t
    169  1.2  ragge tar_read(f, buf, size, resid)
    170  1.2  ragge 	struct open_file *f;
    171  1.2  ragge 	void *buf;
    172  1.2  ragge 	size_t size;
    173  1.2  ragge 	size_t *resid;
    174  1.2  ragge {
    175  1.2  ragge 	romstrategy(0, 0, (8192+512), size, buf, 0);
    176  1.2  ragge 	*resid = size;
    177  1.6  ragge 	return 0; /* XXX */
    178  1.2  ragge }
    179  1.6  ragge #endif
    180  1.1  ragge 
    181  1.1  ragge 
    182  1.6  ragge int
    183  1.1  ragge devopen(f, fname, file)
    184  1.1  ragge 	struct open_file *f;
    185  1.1  ragge 	const char    *fname;
    186  1.1  ragge 	char          **file;
    187  1.1  ragge {
    188  1.1  ragge 	*file = (char *)fname;
    189  1.1  ragge 
    190  1.6  ragge 	if (from == FROM750)
    191  1.6  ragge 		return 0;
    192  1.1  ragge 	/*
    193  1.6  ragge 	 * Reinit the VMB boot device.
    194  1.1  ragge 	 */
    195  1.6  ragge 	if (bqo->unit_init) {
    196  1.6  ragge 		int initfn;
    197  1.6  ragge 
    198  1.6  ragge 		initfn = rpb->iovec + bqo->unit_init;
    199  1.6  ragge 		if (rpb->devtyp == BDEV_UDA || rpb->devtyp == BDEV_TK) {
    200  1.7  ragge 			/*
    201  1.7  ragge 			 * This reset do not seem to be done in the
    202  1.7  ragge 			 * ROM routines, so we have to do it manually.
    203  1.7  ragge 			 */
    204  1.1  ragge 			csr = (struct udadevice *)rpb->csrphy;
    205  1.6  ragge 			csr->udaip = 0;
    206  1.6  ragge 			while ((csr->udasa & MP_STEP1) == 0)
    207  1.6  ragge 				;
    208  1.1  ragge 		}
    209  1.7  ragge 		/*
    210  1.7  ragge 		 * AP (R12) have a pointer to the VMB argument list,
    211  1.7  ragge 		 * wanted by bqo->unit_init.
    212  1.7  ragge 		 */
    213  1.6  ragge 		unit_init(initfn, rpb, bootregs[12]);
    214  1.1  ragge 	}
    215  1.1  ragge 	return 0;
    216  1.1  ragge }
    217  1.1  ragge 
    218  1.6  ragge int
    219  1.1  ragge romstrategy(sc, func, dblk, size, buf, rsize)
    220  1.1  ragge 	void    *sc;
    221  1.1  ragge 	int     func;
    222  1.1  ragge 	daddr_t dblk;
    223  1.1  ragge 	size_t	size;
    224  1.1  ragge 	void    *buf;
    225  1.1  ragge 	size_t	*rsize;
    226  1.1  ragge {
    227  1.1  ragge 	int	block = dblk;
    228  1.1  ragge 	int     nsize = size;
    229  1.1  ragge 
    230  1.6  ragge 	if (from == FROMMV) {
    231  1.6  ragge 		romread_uvax(block, size, buf, rpb);
    232  1.6  ragge 	} else /* if (from == FROM750) */ {
    233  1.7  ragge 		while (size > 0) {
    234  1.7  ragge 			if (rpb->devtyp == BDEV_HP)
    235  1.7  ragge 				hpread(block);
    236  1.7  ragge 			else
    237  1.7  ragge 				read750(block, bootregs);
    238  1.7  ragge 			bcopy(0, buf, 512);
    239  1.7  ragge 			size -= 512;
    240  1.7  ragge 			(char *)buf += 512;
    241  1.7  ragge 			block++;
    242  1.7  ragge 		}
    243  1.1  ragge 	}
    244  1.1  ragge 
    245  1.2  ragge 	if (rsize)
    246  1.2  ragge 		*rsize = nsize;
    247  1.1  ragge 	return 0;
    248  1.1  ragge }
    249  1.1  ragge 
    250  1.7  ragge /*
    251  1.7  ragge  * The 11/750 boot ROM for Massbus disks doesn't seen to have layout info
    252  1.7  ragge  * for all RP disks (not RP07 at least) so therefore a very small and dumb
    253  1.7  ragge  * device driver is used. It assumes that there is a label on the disk
    254  1.7  ragge  * already that has valid layout info. If there is no label, we can't boot
    255  1.7  ragge  * anyway.
    256  1.7  ragge  */
    257  1.9  ragge 
    258  1.9  ragge #define MBA_WCSR(reg, val) \
    259  1.9  ragge 	((void)(*(volatile u_int32_t *)((adpadr) + (reg)) = (val)));
    260  1.9  ragge #define MBA_RCSR(reg) \
    261  1.9  ragge 	(*(volatile u_int32_t *)((adpadr) + (reg)))
    262  1.9  ragge #define HP_WCSR(reg, val) \
    263  1.9  ragge 	((void)(*(volatile u_int32_t *)((unitadr) + (reg)) = (val)));
    264  1.9  ragge #define HP_RCSR(reg) \
    265  1.9  ragge 	(*(volatile u_int32_t *)((unitadr) + (reg)))
    266  1.9  ragge 
    267  1.7  ragge void
    268  1.7  ragge hpread(int bn)
    269  1.1  ragge {
    270  1.9  ragge 	int adpadr = bootregs[1];
    271  1.9  ragge 	int unitadr = adpadr + MUREG(bootregs[3], 0);
    272  1.7  ragge 	u_int cn, sn, tn;
    273  1.6  ragge 	struct disklabel *dp;
    274  1.6  ragge 	extern char start;
    275  1.1  ragge 
    276  1.6  ragge 	dp = (struct disklabel *)(LABELOFFSET + &start);
    277  1.9  ragge 	MBA_WCSR(MAPREG(0), PG_V);
    278  1.1  ragge 
    279  1.9  ragge 	MBA_WCSR(MBA_VAR, 0);
    280  1.9  ragge 	MBA_WCSR(MBA_BC, (~512) + 1);
    281  1.7  ragge #ifdef __GNUC__
    282  1.7  ragge 	/*
    283  1.7  ragge 	 * Avoid four subroutine calls by using hardware division.
    284  1.7  ragge 	 */
    285  1.9  ragge 	asm("clrl r1;movl %3,r0;ediv %4,r0,%0,%1;movl %1,r0;ediv %5,r0,%2,%1"
    286  1.7  ragge 	    : "=g"(cn),"=g"(sn),"=g"(tn)
    287  1.7  ragge 	    : "g"(bn),"g"(dp->d_secpercyl),"g"(dp->d_nsectors)
    288  1.7  ragge 	    : "r0","r1","cc");
    289  1.7  ragge #else
    290  1.1  ragge 	cn = bn / dp->d_secpercyl;
    291  1.1  ragge 	sn = bn % dp->d_secpercyl;
    292  1.1  ragge 	tn = sn / dp->d_nsectors;
    293  1.1  ragge 	sn = sn % dp->d_nsectors;
    294  1.7  ragge #endif
    295  1.9  ragge 	HP_WCSR(HP_DC, cn);
    296  1.9  ragge 	HP_WCSR(HP_DA, (tn << 8) | sn);
    297  1.9  ragge 	HP_WCSR(HP_CS1, HPCS_READ);
    298  1.9  ragge 
    299  1.9  ragge 	while (MBA_RCSR(MBA_SR) & MBASR_DTBUSY)
    300  1.7  ragge 		;
    301  1.7  ragge 	return;
    302  1.1  ragge }
    303  1.1  ragge 
    304  1.2  ragge extern char end[];
    305  1.2  ragge static char *top = (char*)end;
    306  1.1  ragge 
    307  1.2  ragge void *
    308  1.2  ragge alloc(size)
    309  1.2  ragge         unsigned size;
    310  1.2  ragge {
    311  1.2  ragge 	void *ut = top;
    312  1.2  ragge 	top += size;
    313  1.2  ragge 	return ut;
    314  1.1  ragge }
    315  1.1  ragge 
    316  1.1  ragge void
    317  1.2  ragge free(ptr, size)
    318  1.2  ragge         void *ptr;
    319  1.2  ragge         unsigned size;
    320  1.1  ragge {
    321  1.1  ragge }
    322  1.1  ragge 
    323  1.2  ragge int
    324  1.2  ragge romclose(f)
    325  1.2  ragge 	struct open_file *f;
    326  1.1  ragge {
    327  1.2  ragge 	return 0;
    328  1.1  ragge }
    329