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