xref: /csrg-svn/sys/vax/stand/bootxx.c (revision 26828)
123220Smckusick /*
223220Smckusick  * Copyright (c) 1982 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*26828Skarels  *	@(#)bootxx.c	6.4 (Berkeley) 03/12/86
723220Smckusick  */
87464Skre 
97464Skre #include "../h/param.h"
107464Skre #include "../h/inode.h"
117464Skre #include "../h/fs.h"
127464Skre #include "../h/vm.h"
137464Skre #include <a.out.h>
147464Skre #include "saio.h"
157464Skre #include "../h/reboot.h"
167464Skre 
17*26828Skarels char bootprog[20] = "xx(0,0)boot";
187464Skre 
197464Skre /*
207464Skre  * Boot program... arguments passed in r10 and r11
217464Skre  * are passed through to the full boot program.
227464Skre  */
237464Skre 
247464Skre main()
257464Skre {
26*26828Skarels 	register unsigned howto, devtype;	/* howto=r11, devtype=r10 */
27*26828Skarels 	int io, unit, partition;
28*26828Skarels 	register char *cp;
297464Skre 
307464Skre #ifdef lint
317464Skre 	howto = 0; devtype = 0;
327464Skre #endif
33*26828Skarels 	unit = (devtype >> B_UNITSHIFT) & B_UNITMASK;
34*26828Skarels 	unit += 8 * ((devtype >> B_ADAPTORSHIFT) & B_ADAPTORMASK);
35*26828Skarels 	partition = (devtype >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
36*26828Skarels 	cp = bootprog + 3;
37*26828Skarels 	if (unit >= 10)
38*26828Skarels 		*cp++ = unit / 10 + '0';
39*26828Skarels 	*cp++ = unit % 10 + '0';
40*26828Skarels 	*cp++ = ',';
41*26828Skarels 	if (partition >= 10)
42*26828Skarels 		*cp++ = partition / 10 + '0';
43*26828Skarels 	*cp++ = partition % 10 + '0';
44*26828Skarels 	bcopy((caddr_t) ")boot", cp, 6);
4525438Skarels 	printf("loading %s\n", bootprog);
467464Skre 	io = open(bootprog, 0);
477464Skre 	if (io >= 0)
487464Skre 		copyunix(howto, devtype, io);
4925438Skarels 	_stop("boot failed\n");
507464Skre }
517464Skre 
527464Skre /*ARGSUSED*/
537464Skre copyunix(howto, devtype, io)
547464Skre 	register howto, devtype, io;	/* howto=r11, devtype=r10 */
557464Skre {
567464Skre 	struct exec x;
577464Skre 	register int i;
587464Skre 	char *addr;
597464Skre 
607464Skre 	i = read(io, (char *)&x, sizeof x);
617464Skre 	if (i != sizeof x ||
627464Skre 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
637464Skre 		_stop("Bad format\n");
647464Skre 	if ((x.a_magic == 0413 || x.a_magic == 0410) &&
657464Skre 	    lseek(io, 0x400, 0) == -1)
667464Skre 		goto shread;
677464Skre 	if (read(io, (char *)0, x.a_text) != x.a_text)
687464Skre 		goto shread;
697464Skre 	addr = (char *)x.a_text;
707464Skre 	if (x.a_magic == 0413 || x.a_magic == 0410)
717464Skre 		while ((int)addr & CLOFSET)
727464Skre 			*addr++ = 0;
737464Skre 	if (read(io, addr, x.a_data) != x.a_data)
747464Skre 		goto shread;
757464Skre 	addr += x.a_data;
767464Skre 	x.a_bss += 128*512;	/* slop */
777464Skre 	for (i = 0; i < x.a_bss; i++)
787464Skre 		*addr++ = 0;
797464Skre 	x.a_entry &= 0x7fffffff;
807464Skre 	(*((int (*)()) x.a_entry))();
8125438Skarels 	return;
827464Skre shread:
837464Skre 	_stop("Short read\n");
847464Skre }
85