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