xref: /csrg-svn/sys/vax/stand/boot.c (revision 3274)
1 /*	boot.c	4.3	81/03/16	*/
2 
3 #include "../h/param.h"
4 #include "../h/ino.h"
5 #include "../h/inode.h"
6 #include "../h/filsys.h"
7 #include "../h/dir.h"
8 #include "../h/vm.h"
9 #include <a.out.h>
10 #include "saio.h"
11 #include <sys/reboot.h>
12 
13 /*
14  * Boot program... arguments passed in r10 and r11 determine
15  * whether boot stops to ask for system name and which device
16  * boot comes from.
17  */
18 
19 /* Types in r10 specifying major device */
20 char	devname[][2] = {
21 	'h','p',	/* 0 = hp */
22 	0,0,		/* 1 = ht */
23 	'u','p',	/* 2 = up */
24 	'h','k',	/* 3 = hk */
25 };
26 
27 char line[100] = "xx(0,0)vmunix";
28 
29 main()
30 {
31 	register howto, devtype;	/* howto=r11, devtype=r10 */
32 	int io, retry;
33 
34 #ifdef lint
35 	howto = 0; devtype = 0;
36 #endif
37 	printf("\nBoot\n");
38 #ifdef JUSTASK
39 	howto = RB_ASKNAME|RB_SINGLE;
40 #else
41 	if ((howto&RB_ASKNAME)==0) {
42 		if (devtype>=0 && devtype<sizeof(devname)/2
43 		    && devname[devtype][0]) {
44 			line[0] = devname[devtype][0];
45 			line[1] = devname[devtype][1];
46 		} else
47 			howto = RB_SINGLE|RB_ASKNAME;
48 	}
49 #endif
50 	retry = 0;
51 	for (;;) {
52 		if (howto & RB_ASKNAME) {
53 			printf(": ");
54 			gets(line);
55 		} else
56 			printf(": %s\n", line);
57 		io = open(line, 0);
58 		if (io >= 0)
59 			copyunix(io);
60 		if (++retry > 2)
61 			howto = RB_SINGLE|RB_ASKNAME;
62 	}
63 }
64 
65 copyunix(io)
66 	register io;
67 {
68 	struct exec x;
69 	register int i;
70 	char *addr;
71 
72 	i = read(io, (char *)&x, sizeof x);
73 	if (i != sizeof x || x.a_magic != 0410)
74 		_stop("Bad format\n");
75 	printf("%d", x.a_text);
76 	if (read(io, (char *)0, x.a_text) != x.a_text)
77 		goto shread;
78 	addr = (char *)x.a_text;
79 	while ((int)addr & CLOFSET)
80 		*addr++ = 0;
81 	printf("+%d", x.a_data);
82 	if (read(io, addr, x.a_data) != x.a_data)
83 		goto shread;
84 	addr += x.a_data;
85 	printf("+%d", x.a_bss);
86 	x.a_bss += 128*512;	/* slop */
87 	for (i = 0; i < x.a_bss; i++)
88 		*addr++ = 0;
89 	x.a_entry &= 0x7fffffff;
90 	printf(" start 0x%x\n", x.a_entry);
91 	(*((int (*)()) x.a_entry))();
92 	_exit();
93 shread:
94 	_stop("Short read\n");
95 }
96