bootxx.c revision 1.1
11.1Smrg/*	$NetBSD: bootxx.c,v 1.1 1997/06/01 03:39:31 mrg Exp $ */
21.1Smrg
31.1Smrg/*
41.1Smrg * Copyright (c) 1994 Paul Kranenburg
51.1Smrg * All rights reserved.
61.1Smrg *
71.1Smrg * Redistribution and use in source and binary forms, with or without
81.1Smrg * modification, are permitted provided that the following conditions
91.1Smrg * are met:
101.1Smrg * 1. Redistributions of source code must retain the above copyright
111.1Smrg *    notice, this list of conditions and the following disclaimer.
121.1Smrg * 2. Redistributions in binary form must reproduce the above copyright
131.1Smrg *    notice, this list of conditions and the following disclaimer in the
141.1Smrg *    documentation and/or other materials provided with the distribution.
151.1Smrg * 3. All advertising materials mentioning features or use of this software
161.1Smrg *    must display the following acknowledgement:
171.1Smrg *      This product includes software developed by Paul Kranenburg.
181.1Smrg * 4. The name of the author may not be used to endorse or promote products
191.1Smrg *    derived from this software without specific prior written permission
201.1Smrg *
211.1Smrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
221.1Smrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
231.1Smrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
241.1Smrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
251.1Smrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
261.1Smrg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
271.1Smrg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
281.1Smrg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
291.1Smrg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
301.1Smrg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311.1Smrg */
321.1Smrg
331.1Smrg#include <sys/param.h>
341.1Smrg#include <sys/time.h>
351.1Smrg#include <a.out.h>
361.1Smrg
371.1Smrg#include <lib/libsa/stand.h>
381.1Smrg
391.1Smrg#include <sparc/stand/common/promdev.h>
401.1Smrg
411.1Smrgint debug;
421.1Smrgint netif_debug;
431.1Smrg
441.1Smrg/*
451.1Smrg * Boot device is derived from ROM provided information.
461.1Smrg */
471.1Smrgconst char		progname[] = "bootxx";
481.1Smrgstruct open_file	io;
491.1Smrg
501.1Smrg/*
511.1Smrg * The contents of the block_* variables below is set by installboot(8)
521.1Smrg * to hold the the filesystem data of the second-stage boot program
531.1Smrg * (typically `/boot'): filesystem block size, # of filesystem blocks and
541.1Smrg * the block numbers themselves.
551.1Smrg */
561.1Smrg#define MAXBLOCKNUM	256	/* enough for a 2MB boot program (bs 8K) */
571.1Smrgint32_t			block_size = 0;
581.1Smrgint32_t			block_count = MAXBLOCKNUM;
591.1Smrgdaddr_t			block_table[MAXBLOCKNUM] = { 0 };
601.1Smrg
611.1Smrg
621.1Smrgvoid	loadboot __P((struct open_file *, caddr_t));
631.1Smrg
641.1Smrgint
651.1Smrgmain()
661.1Smrg{
671.1Smrg	char	*dummy;
681.1Smrg	size_t	n;
691.1Smrg	register void (*entry)__P((caddr_t)) = (void (*)__P((caddr_t)))LOADADDR;
701.1Smrg
711.1Smrg	prom_init();
721.1Smrg	io.f_flags = F_RAW;
731.1Smrg	if (devopen(&io, 0, &dummy)) {
741.1Smrg		panic("%s: can't open device", progname);
751.1Smrg	}
761.1Smrg
771.1Smrg	(void)loadboot(&io, LOADADDR);
781.1Smrg	(*entry)(cputyp == CPU_SUN4 ? LOADADDR : (caddr_t)promvec);
791.1Smrg	_rtt();
801.1Smrg}
811.1Smrg
821.1Smrgvoid
831.1Smrgloadboot(f, addr)
841.1Smrg	register struct open_file	*f;
851.1Smrg	register char			*addr;
861.1Smrg{
871.1Smrg	register int	i;
881.1Smrg	register char	*buf;
891.1Smrg	size_t		n;
901.1Smrg	daddr_t		blk;
911.1Smrg
921.1Smrg	/*
931.1Smrg	 * Allocate a buffer that we can map into DVMA space; only
941.1Smrg	 * needed for sun4 architecture, but use it for all machines
951.1Smrg	 * to keep code size down as much as possible.
961.1Smrg	 */
971.1Smrg	buf = alloc(block_size);
981.1Smrg	if (buf == NULL)
991.1Smrg		panic("%s: alloc failed", progname);
1001.1Smrg
1011.1Smrg	for (i = 0; i < block_count; i++) {
1021.1Smrg		if ((blk = block_table[i]) == 0)
1031.1Smrg			panic("%s: block table corrupt", progname);
1041.1Smrg
1051.1Smrg#ifdef DEBUG
1061.1Smrg		printf("%s: block # %d = %d\n", progname, i, blk);
1071.1Smrg#endif
1081.1Smrg		if ((f->f_dev->dv_strategy)(f->f_devdata, F_READ,
1091.1Smrg					    blk, block_size, buf, &n)) {
1101.1Smrg			panic("%s: read failure", progname);
1111.1Smrg		}
1121.1Smrg		bcopy(buf, addr, block_size);
1131.1Smrg		if (n != block_size)
1141.1Smrg			panic("%s: short read", progname);
1151.1Smrg		if (i == 0) {
1161.1Smrg			register int m = N_GETMAGIC(*(struct exec *)addr);
1171.1Smrg			if (m == ZMAGIC || m == NMAGIC || m == OMAGIC) {
1181.1Smrg				/* Move exec header out of the way */
1191.1Smrg				bcopy(addr, addr - sizeof(struct exec), n);
1201.1Smrg				addr -= sizeof(struct exec);
1211.1Smrg			}
1221.1Smrg		}
1231.1Smrg		addr += n;
1241.1Smrg	}
1251.1Smrg
1261.1Smrg}
127