xref: /csrg-svn/sys/vax/stand/bootxx.c (revision 7464)
1*7464Skre /*	bootxx.c	4.1	82/07/19	*/
2*7464Skre 
3*7464Skre #include "../h/param.h"
4*7464Skre #include "../h/inode.h"
5*7464Skre #include "../h/fs.h"
6*7464Skre #include "../h/vm.h"
7*7464Skre #include <a.out.h>
8*7464Skre #include "saio.h"
9*7464Skre #include "../h/reboot.h"
10*7464Skre 
11*7464Skre #ifdef	BOOTRK
12*7464Skre char bootprog[] = "hk(0,0)boot";
13*7464Skre #endif
14*7464Skre #ifdef	BOOTHP
15*7464Skre char bootprog[] = "hp(0,0)boot";
16*7464Skre #endif
17*7464Skre #ifdef	BOOTUP
18*7464Skre char bootprog[] = "up(0,0)boot";
19*7464Skre #endif
20*7464Skre 
21*7464Skre /*
22*7464Skre  * Boot program... arguments passed in r10 and r11
23*7464Skre  * are passed through to the full boot program.
24*7464Skre  */
25*7464Skre 
26*7464Skre main()
27*7464Skre {
28*7464Skre 	register howto, devtype;	/* howto=r11, devtype=r10 */
29*7464Skre 	int io;
30*7464Skre 
31*7464Skre #ifdef lint
32*7464Skre 	howto = 0; devtype = 0;
33*7464Skre #endif
34*7464Skre 	printf("loading %s", bootprog);
35*7464Skre 	io = open(bootprog, 0);
36*7464Skre 	if (io >= 0)
37*7464Skre 		copyunix(howto, devtype, io);
38*7464Skre 	printf("boot failed");
39*7464Skre 	_exit();
40*7464Skre }
41*7464Skre 
42*7464Skre /*ARGSUSED*/
43*7464Skre copyunix(howto, devtype, io)
44*7464Skre 	register howto, devtype, io;	/* howto=r11, devtype=r10 */
45*7464Skre {
46*7464Skre 	struct exec x;
47*7464Skre 	register int i;
48*7464Skre 	char *addr;
49*7464Skre 
50*7464Skre 	i = read(io, (char *)&x, sizeof x);
51*7464Skre 	if (i != sizeof x ||
52*7464Skre 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
53*7464Skre 		_stop("Bad format\n");
54*7464Skre 	if ((x.a_magic == 0413 || x.a_magic == 0410) &&
55*7464Skre 	    lseek(io, 0x400, 0) == -1)
56*7464Skre 		goto shread;
57*7464Skre 	if (read(io, (char *)0, x.a_text) != x.a_text)
58*7464Skre 		goto shread;
59*7464Skre 	addr = (char *)x.a_text;
60*7464Skre 	if (x.a_magic == 0413 || x.a_magic == 0410)
61*7464Skre 		while ((int)addr & CLOFSET)
62*7464Skre 			*addr++ = 0;
63*7464Skre 	if (read(io, addr, x.a_data) != x.a_data)
64*7464Skre 		goto shread;
65*7464Skre 	addr += x.a_data;
66*7464Skre 	x.a_bss += 128*512;	/* slop */
67*7464Skre 	for (i = 0; i < x.a_bss; i++)
68*7464Skre 		*addr++ = 0;
69*7464Skre 	x.a_entry &= 0x7fffffff;
70*7464Skre 	(*((int (*)()) x.a_entry))();
71*7464Skre 	_exit();
72*7464Skre shread:
73*7464Skre 	_stop("Short read\n");
74*7464Skre }
75