xref: /csrg-svn/sys/vax/stand/boot.c (revision 3261)
1 /*	boot.c	4.2	81/03/15	*/
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 	printf("\nBoot\n");
35 #ifdef JUSTASK
36 	howto = RB_ASKNAME|RB_SINGLE;
37 #else
38 	if ((howto&RB_ASKNAME)==0) {
39 		if (devtype>=0 && devtype<sizeof(devname)/2
40 		    && devname[devtype][0]) {
41 			line[0] = devname[devtype][0];
42 			line[1] = devname[devtype][1];
43 		} else
44 			howto = RB_SINGLE|RB_ASKNAME;
45 	}
46 #endif
47 	retry = 0;
48 	for (;;) {
49 		if (howto & RB_ASKNAME) {
50 			printf(": ");
51 			gets(line);
52 		} else
53 			printf(": %s\n", line);
54 		io = open(line, 0);
55 		if (io >= 0)
56 			copyunix(howto, io);
57 		if (++retry > 2)
58 			howto = RB_SINGLE|RB_ASKNAME;
59 	}
60 }
61 
62 copyunix(howto, io)
63 	register howto, io;
64 {
65 	struct exec x;
66 	register int i;
67 	char *addr;
68 
69 	i = read(io, (char *)&x, sizeof x);
70 	if (i != sizeof x || x.a_magic != 0410)
71 		_stop("Bad format\n");
72 	printf("%d", x.a_text);
73 	if (read(io, (char *)0, x.a_text) != x.a_text)
74 		goto shread;
75 	addr = (char *)x.a_text;
76 	while ((int)addr & CLOFSET)
77 		*addr++ = 0;
78 	printf("+%d", x.a_data);
79 	if (read(io, addr, x.a_data) != x.a_data)
80 		goto shread;
81 	addr += x.a_data;
82 	printf("+%d", x.a_bss);
83 	x.a_bss += 128*512;	/* slop */
84 	for (i = 0; i < x.a_bss; i++)
85 		*addr++ = 0;
86 	x.a_entry &= 0x7fffffff;
87 	printf(" start 0x%x\n", x.a_entry);
88 	(*((int (*)()) x.a_entry))();
89 	_exit();
90 shread:
91 	_stop("Short read\n");
92 }
93