Home | History | Annotate | Line # | Download | only in xxboot
bootxx.c revision 1.7
      1  1.7  ragge /* $NetBSD: bootxx.c,v 1.7 2000/05/21 09:44:16 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 	char *hej = "/boot";
     94  1.1  ragge 
     95  1.1  ragge 	vax_cputype = (mfpr(PR_SID) >> 24) & 0xFF;
     96  1.1  ragge 
     97  1.2  ragge 	/*
     98  1.2  ragge 	 */
     99  1.6  ragge 	rpb = (void *)0xf0000; /* Safe address right now */
    100  1.6  ragge 	bqo = (void *)0xf1000;
    101  1.6  ragge         if (from == FROMMV) {
    102  1.1  ragge 		/*
    103  1.1  ragge 		 * now relocate rpb/bqo (which are used by ROM-routines)
    104  1.1  ragge 		 */
    105  1.6  ragge 		bcopy ((void *)bootregs[11], rpb, sizeof(struct rpb));
    106  1.1  ragge 		bcopy ((void*)rpb->iovec, bqo, rpb->iovecsz);
    107  1.4  ragge 		if (rpb->devtyp == BDEV_SDN)
    108  1.4  ragge 			rpb->devtyp = BDEV_SD;	/* XXX until driver fixed */
    109  1.6  ragge 	} else {
    110  1.6  ragge 		bzero(rpb, sizeof(struct rpb));
    111  1.6  ragge 		rpb->devtyp = bootregs[0];
    112  1.6  ragge 		rpb->unit = bootregs[3];
    113  1.6  ragge 		rpb->rpb_bootr5 = bootregs[5];
    114  1.6  ragge 		rpb->csrphy = bootregs[2];
    115  1.6  ragge 		rpb->adpphy = bootregs[1];	/* BI node on 8200 */
    116  1.7  ragge 		if (rpb->devtyp != BDEV_HP && vax_cputype == VAX_TYP_750)
    117  1.7  ragge 			rpb->adpphy =
    118  1.7  ragge 			    (bootregs[1] == 0xffe000 ? 0xf30000 : 0xf32000);
    119  1.1  ragge         }
    120  1.6  ragge 	rpb->rpb_base = rpb;
    121  1.6  ragge 	rpb->iovec = (int)bqo;
    122  1.1  ragge 
    123  1.1  ragge 	io = open(hej, 0);
    124  1.1  ragge 
    125  1.2  ragge 	read(io, (void *)0x10000, 0x10000);
    126  1.2  ragge 	bcopy((void *) 0x10000, 0, 0xffff);
    127  1.6  ragge 	hoppabort(32);
    128  1.2  ragge 	asm("halt");
    129  1.1  ragge }
    130  1.1  ragge 
    131  1.2  ragge /*
    132  1.2  ragge  * Write an extremely limited version of a (us)tar filesystem, suitable
    133  1.2  ragge  * for loading secondary-stage boot loader.
    134  1.2  ragge  * - Can only load file "boot".
    135  1.2  ragge  * - Must be the first file on tape.
    136  1.2  ragge  */
    137  1.6  ragge struct fs_ops file_system[] = {
    138  1.6  ragge 	{ ufs_open, 0, ufs_read, 0, 0, ufs_stat },
    139  1.6  ragge 	{ cd9660_open, 0, cd9660_read, 0, 0, cd9660_stat },
    140  1.6  ragge #if 0
    141  1.6  ragge 	{ ustarfs_open, 0, ustarfs_read, 0, 0, ustarfs_stat },
    142  1.6  ragge #endif
    143  1.6  ragge };
    144  1.6  ragge 
    145  1.6  ragge int nfsys = (sizeof(file_system) / sizeof(struct fs_ops));
    146  1.6  ragge 
    147  1.6  ragge #if 0
    148  1.2  ragge int tar_open(char *path, struct open_file *f);
    149  1.2  ragge ssize_t tar_read(struct open_file *f, void *buf, size_t size, size_t *resid);
    150  1.1  ragge 
    151  1.2  ragge int
    152  1.2  ragge tar_open(path, f)
    153  1.2  ragge 	char *path;
    154  1.2  ragge 	struct open_file *f;
    155  1.2  ragge {
    156  1.2  ragge 	char *buf = alloc(512);
    157  1.2  ragge 
    158  1.2  ragge 	bzero(buf, 512);
    159  1.2  ragge 	romstrategy(0, 0, 8192, 512, buf, 0);
    160  1.2  ragge 	if (bcmp(buf, "boot", 5) || bcmp(&buf[257], "ustar", 5))
    161  1.2  ragge 		return EINVAL; /* Not a ustarfs with "boot" first */
    162  1.2  ragge 	return 0;
    163  1.2  ragge }
    164  1.2  ragge 
    165  1.2  ragge ssize_t
    166  1.2  ragge tar_read(f, buf, size, resid)
    167  1.2  ragge 	struct open_file *f;
    168  1.2  ragge 	void *buf;
    169  1.2  ragge 	size_t size;
    170  1.2  ragge 	size_t *resid;
    171  1.2  ragge {
    172  1.2  ragge 	romstrategy(0, 0, (8192+512), size, buf, 0);
    173  1.2  ragge 	*resid = size;
    174  1.6  ragge 	return 0; /* XXX */
    175  1.2  ragge }
    176  1.6  ragge #endif
    177  1.1  ragge 
    178  1.1  ragge 
    179  1.6  ragge int
    180  1.1  ragge devopen(f, fname, file)
    181  1.1  ragge 	struct open_file *f;
    182  1.1  ragge 	const char    *fname;
    183  1.1  ragge 	char          **file;
    184  1.1  ragge {
    185  1.1  ragge 	*file = (char *)fname;
    186  1.1  ragge 
    187  1.6  ragge 	if (from == FROM750)
    188  1.6  ragge 		return 0;
    189  1.1  ragge 	/*
    190  1.6  ragge 	 * Reinit the VMB boot device.
    191  1.1  ragge 	 */
    192  1.6  ragge 	if (bqo->unit_init) {
    193  1.6  ragge 		int initfn;
    194  1.6  ragge 
    195  1.6  ragge 		initfn = rpb->iovec + bqo->unit_init;
    196  1.6  ragge 		if (rpb->devtyp == BDEV_UDA || rpb->devtyp == BDEV_TK) {
    197  1.7  ragge 			/*
    198  1.7  ragge 			 * This reset do not seem to be done in the
    199  1.7  ragge 			 * ROM routines, so we have to do it manually.
    200  1.7  ragge 			 */
    201  1.1  ragge 			csr = (struct udadevice *)rpb->csrphy;
    202  1.6  ragge 			csr->udaip = 0;
    203  1.6  ragge 			while ((csr->udasa & MP_STEP1) == 0)
    204  1.6  ragge 				;
    205  1.1  ragge 		}
    206  1.7  ragge 		/*
    207  1.7  ragge 		 * AP (R12) have a pointer to the VMB argument list,
    208  1.7  ragge 		 * wanted by bqo->unit_init.
    209  1.7  ragge 		 */
    210  1.6  ragge 		unit_init(initfn, rpb, bootregs[12]);
    211  1.1  ragge 	}
    212  1.1  ragge 	return 0;
    213  1.1  ragge }
    214  1.1  ragge 
    215  1.6  ragge int
    216  1.1  ragge romstrategy(sc, func, dblk, size, buf, rsize)
    217  1.1  ragge 	void    *sc;
    218  1.1  ragge 	int     func;
    219  1.1  ragge 	daddr_t dblk;
    220  1.1  ragge 	size_t	size;
    221  1.1  ragge 	void    *buf;
    222  1.1  ragge 	size_t	*rsize;
    223  1.1  ragge {
    224  1.1  ragge 	int	block = dblk;
    225  1.1  ragge 	int     nsize = size;
    226  1.1  ragge 
    227  1.6  ragge 	if (from == FROMMV) {
    228  1.6  ragge 		romread_uvax(block, size, buf, rpb);
    229  1.6  ragge 	} else /* if (from == FROM750) */ {
    230  1.7  ragge 		while (size > 0) {
    231  1.7  ragge 			if (rpb->devtyp == BDEV_HP)
    232  1.7  ragge 				hpread(block);
    233  1.7  ragge 			else
    234  1.7  ragge 				read750(block, bootregs);
    235  1.7  ragge 			bcopy(0, buf, 512);
    236  1.7  ragge 			size -= 512;
    237  1.7  ragge 			(char *)buf += 512;
    238  1.7  ragge 			block++;
    239  1.7  ragge 		}
    240  1.1  ragge 	}
    241  1.1  ragge 
    242  1.2  ragge 	if (rsize)
    243  1.2  ragge 		*rsize = nsize;
    244  1.1  ragge 	return 0;
    245  1.1  ragge }
    246  1.1  ragge 
    247  1.7  ragge /*
    248  1.7  ragge  * The 11/750 boot ROM for Massbus disks doesn't seen to have layout info
    249  1.7  ragge  * for all RP disks (not RP07 at least) so therefore a very small and dumb
    250  1.7  ragge  * device driver is used. It assumes that there is a label on the disk
    251  1.7  ragge  * already that has valid layout info. If there is no label, we can't boot
    252  1.7  ragge  * anyway.
    253  1.7  ragge  */
    254  1.7  ragge void
    255  1.7  ragge hpread(int bn)
    256  1.1  ragge {
    257  1.1  ragge 	volatile struct mba_regs *mr = (void *) bootregs[1];
    258  1.1  ragge 	volatile struct hp_drv *hd = (void*)&mr->mba_md[bootregs[3]];
    259  1.7  ragge 	u_int cn, sn, tn;
    260  1.6  ragge 	struct disklabel *dp;
    261  1.6  ragge 	extern char start;
    262  1.1  ragge 
    263  1.6  ragge 	dp = (struct disklabel *)(LABELOFFSET + &start);
    264  1.7  ragge 	*(int *)&mr->mba_map[0] = PG_V;
    265  1.1  ragge 
    266  1.7  ragge 	mr->mba_var = 0;
    267  1.7  ragge 	mr->mba_bc = (~512) + 1;
    268  1.7  ragge #ifdef __GNUC__
    269  1.7  ragge 	/*
    270  1.7  ragge 	 * Avoid four subroutine calls by using hardware division.
    271  1.7  ragge 	 */
    272  1.7  ragge 	asm("clrl r1;ediv %4,%3,%0,%1;movl %1,r0;ediv %5,r0,%2,%1"
    273  1.7  ragge 	    : "=g"(cn),"=g"(sn),"=g"(tn)
    274  1.7  ragge 	    : "g"(bn),"g"(dp->d_secpercyl),"g"(dp->d_nsectors)
    275  1.7  ragge 	    : "r0","r1","cc");
    276  1.7  ragge #else
    277  1.1  ragge 	cn = bn / dp->d_secpercyl;
    278  1.1  ragge 	sn = bn % dp->d_secpercyl;
    279  1.1  ragge 	tn = sn / dp->d_nsectors;
    280  1.1  ragge 	sn = sn % dp->d_nsectors;
    281  1.7  ragge #endif
    282  1.1  ragge 	hd->hp_dc = cn;
    283  1.1  ragge 	hd->hp_da = (tn << 8) | sn;
    284  1.1  ragge 	hd->hp_cs1 = HPCS_READ;
    285  1.7  ragge 	while (mr->mba_sr & MBASR_DTBUSY)
    286  1.7  ragge 		;
    287  1.7  ragge 	return;
    288  1.1  ragge }
    289  1.1  ragge 
    290  1.2  ragge extern char end[];
    291  1.2  ragge static char *top = (char*)end;
    292  1.1  ragge 
    293  1.2  ragge void *
    294  1.2  ragge alloc(size)
    295  1.2  ragge         unsigned size;
    296  1.2  ragge {
    297  1.2  ragge 	void *ut = top;
    298  1.2  ragge 	top += size;
    299  1.2  ragge 	return ut;
    300  1.1  ragge }
    301  1.1  ragge 
    302  1.1  ragge void
    303  1.2  ragge free(ptr, size)
    304  1.2  ragge         void *ptr;
    305  1.2  ragge         unsigned size;
    306  1.1  ragge {
    307  1.1  ragge }
    308  1.1  ragge 
    309  1.2  ragge int
    310  1.2  ragge romclose(f)
    311  1.2  ragge 	struct open_file *f;
    312  1.1  ragge {
    313  1.2  ragge 	return 0;
    314  1.1  ragge }
    315