xref: /csrg-svn/sys/vax/stand/bootxx.c (revision 45803)
123220Smckusick /*
229293Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
323220Smckusick  * All rights reserved.  The Berkeley software License Agreement
423220Smckusick  * specifies the terms and conditions for redistribution.
523220Smckusick  *
6*45803Sbostic  *	@(#)bootxx.c	7.6 (Berkeley) 12/16/90
723220Smckusick  */
87464Skre 
9*45803Sbostic #include "sys/param.h"
10*45803Sbostic #include "sys/vm.h"
11*45803Sbostic #include "sys/reboot.h"
127464Skre #include <a.out.h>
13*45803Sbostic #include "stand/saio.h"
147464Skre 
1532199Skarels char bootprog[] = "boot";
1632199Skarels extern	unsigned opendev;
177464Skre 
187464Skre /*
197464Skre  * Boot program... arguments passed in r10 and r11
207464Skre  * are passed through to the full boot program.
217464Skre  */
227464Skre 
237464Skre main()
247464Skre {
2526828Skarels 	register unsigned howto, devtype;	/* howto=r11, devtype=r10 */
2626828Skarels 	int io, unit, partition;
2726828Skarels 	register char *cp;
287464Skre 
297464Skre #ifdef lint
3032199Skarels 	howto = 0; devtype = 0; devtype = devtype;
317464Skre #endif
3225438Skarels 	printf("loading %s\n", bootprog);
337464Skre 	io = open(bootprog, 0);
347464Skre 	if (io >= 0)
3532199Skarels 		copyunix(howto, opendev, io);
3625438Skarels 	_stop("boot failed\n");
377464Skre }
387464Skre 
397464Skre /*ARGSUSED*/
407464Skre copyunix(howto, devtype, io)
417464Skre 	register howto, devtype, io;	/* howto=r11, devtype=r10 */
427464Skre {
437464Skre 	struct exec x;
447464Skre 	register int i;
457464Skre 	char *addr;
467464Skre 
477464Skre 	i = read(io, (char *)&x, sizeof x);
4833430Sbostic 	if (i != sizeof x || N_BADMAG(x))
497464Skre 		_stop("Bad format\n");
5033430Sbostic 	if ((x.a_magic == ZMAGIC || x.a_magic == NMAGIC) &&
5133430Sbostic 	    lseek(io, 0x400, L_SET) == -1)
527464Skre 		goto shread;
537464Skre 	if (read(io, (char *)0, x.a_text) != x.a_text)
547464Skre 		goto shread;
557464Skre 	addr = (char *)x.a_text;
5633430Sbostic 	if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC)
577464Skre 		while ((int)addr & CLOFSET)
587464Skre 			*addr++ = 0;
597464Skre 	if (read(io, addr, x.a_data) != x.a_data)
607464Skre 		goto shread;
617464Skre 	addr += x.a_data;
627464Skre 	x.a_bss += 128*512;	/* slop */
637464Skre 	for (i = 0; i < x.a_bss; i++)
647464Skre 		*addr++ = 0;
657464Skre 	x.a_entry &= 0x7fffffff;
667464Skre 	(*((int (*)()) x.a_entry))();
6725438Skarels 	return;
687464Skre shread:
697464Skre 	_stop("Short read\n");
707464Skre }
71