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