xref: /csrg-svn/sys/vax/stand/boot.c (revision 1593)
1*1593Sbill /*	boot.c	1.4	10/21/80 */
2315Sbill 
3315Sbill #include "../h/param.h"
4315Sbill #include "../h/ino.h"
5315Sbill #include "../h/inode.h"
6315Sbill #include "../h/filsys.h"
7315Sbill #include "../h/dir.h"
8315Sbill #include "../h/vm.h"
9315Sbill #include <a.out.h>
10315Sbill #include "saio.h"
111466Sbill #include <sys/reboot.h>
12315Sbill 
131466Sbill /*
141466Sbill  * Boot program... arguments passed in r10 and r11 determine
151466Sbill  * whether boot stops to ask for system name and which device
161466Sbill  * boot comes from.
171466Sbill  */
18315Sbill 
191466Sbill /* Types in r10 specifying major device */
201466Sbill char	devname[][2] = {
211466Sbill 	'h','p',	/* 0 = hp */
221466Sbill 	0,0,		/* 1 = ht */
231466Sbill 	'u','p',	/* 2 = up */
241466Sbill 	'r','k',	/* 3 = rk */
251466Sbill };
261466Sbill 
271466Sbill char line[100] = "xx(0,0)vmunix";
281466Sbill 
29315Sbill main()
30315Sbill {
311466Sbill 	register howto, devtype;	/* howto=r11, devtype=r10 */
321466Sbill 	int io, retry;
33315Sbill 
34315Sbill 	printf("\nBoot\n");
351575Sbill #ifdef JUSTASK
36*1593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
371575Sbill #else
381466Sbill 	if ((howto&RB_ASKNAME)==0) {
391466Sbill 		if (devtype>=0 && devtype<sizeof(devname)/2
401466Sbill 		    && devname[devtype][0]) {
411466Sbill 			line[0] = devname[devtype][0];
421466Sbill 			line[1] = devname[devtype][1];
431466Sbill 		} else {
441466Sbill 			printf("DID YOU MEAN ``BOOT ANY?'' (Bad devtype (r10=%x))\n", devtype);
451466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
461466Sbill 		}
471466Sbill 	}
481575Sbill #endif
491466Sbill 	retry = 0;
501466Sbill 	for (;;) {
511466Sbill 		if (howto & RB_ASKNAME) {
521466Sbill 			printf(": ");
531466Sbill 			gets(line);
541466Sbill 		} else
551466Sbill 			printf(": %s\n", line);
561466Sbill 		io = open(line, 0);
571466Sbill 		if (io >= 0)
581466Sbill 			copyunix(howto, io);
591466Sbill 		if (++retry > 2)
601466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
611466Sbill 	}
62315Sbill }
63315Sbill 
641466Sbill copyunix(howto, io)
651466Sbill 	register howto, io;
66315Sbill {
67315Sbill 	struct exec x;
68315Sbill 	register int i;
69315Sbill 	char *addr;
70315Sbill 
71315Sbill 	i = read(io, (char *)&x, sizeof x);
72315Sbill 	if (i != sizeof x || x.a_magic != 0410)
73315Sbill 		_stop("Bad format\n");
74315Sbill 	printf("%d", x.a_text);
75315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
76315Sbill 		goto shread;
77315Sbill 	addr = (char *)x.a_text;
78315Sbill 	while ((int)addr & CLOFSET)
79315Sbill 		*addr++ = 0;
80315Sbill 	printf("+%d", x.a_data);
81315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
82315Sbill 		goto shread;
83315Sbill 	addr += x.a_data;
84315Sbill 	printf("+%d", x.a_bss);
85315Sbill 	x.a_bss += 128*512;	/* slop */
86315Sbill 	for (i = 0; i < x.a_bss; i++)
87315Sbill 		*addr++ = 0;
88315Sbill 	x.a_entry &= 0x7fffffff;
89315Sbill 	printf(" start 0x%x\n", x.a_entry);
90315Sbill 	(*((int (*)()) x.a_entry))();
91315Sbill 	_exit();
92315Sbill shread:
93315Sbill 	_stop("Short read\n");
94315Sbill }
95