xref: /csrg-svn/sys/vax/stand/boot.c (revision 4868)
1*4868Sroot /*	boot.c	4.5	81/11/12	*/
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 */
243261Swnj 	'h','k',	/* 3 = hk */
25*4868Sroot 	0,0,		/* 4 = sw */
26*4868Sroot 	0,0,		/* 5 = tm */
27*4868Sroot 	0,0,		/* 6 = ts */
28*4868Sroot 	0,0,		/* 7 = mt */
29*4868Sroot 	0,0,		/* 8 = tu */
30*4868Sroot 	'r','a',	/* 9 = ra */
311466Sbill };
321466Sbill 
331466Sbill char line[100] = "xx(0,0)vmunix";
341466Sbill 
353347Swnj int	retry = 0;
363347Swnj 
37315Sbill main()
38315Sbill {
391466Sbill 	register howto, devtype;	/* howto=r11, devtype=r10 */
403347Swnj 	int io;
41315Sbill 
423274Swnj #ifdef lint
433274Swnj 	howto = 0; devtype = 0;
443274Swnj #endif
45315Sbill 	printf("\nBoot\n");
461575Sbill #ifdef JUSTASK
471593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
481575Sbill #else
491466Sbill 	if ((howto&RB_ASKNAME)==0) {
501466Sbill 		if (devtype>=0 && devtype<sizeof(devname)/2
511466Sbill 		    && devname[devtype][0]) {
521466Sbill 			line[0] = devname[devtype][0];
531466Sbill 			line[1] = devname[devtype][1];
543261Swnj 		} else
551466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
561466Sbill 	}
571575Sbill #endif
581466Sbill 	for (;;) {
591466Sbill 		if (howto & RB_ASKNAME) {
601466Sbill 			printf(": ");
611466Sbill 			gets(line);
621466Sbill 		} else
631466Sbill 			printf(": %s\n", line);
641466Sbill 		io = open(line, 0);
651466Sbill 		if (io >= 0)
663347Swnj 			copyunix(howto, io);
671466Sbill 		if (++retry > 2)
681466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
691466Sbill 	}
70315Sbill }
71315Sbill 
723347Swnj /*ARGSUSED*/
733347Swnj copyunix(howto, io)
743347Swnj 	register howto, io;
75315Sbill {
76315Sbill 	struct exec x;
77315Sbill 	register int i;
78315Sbill 	char *addr;
79315Sbill 
80315Sbill 	i = read(io, (char *)&x, sizeof x);
81315Sbill 	if (i != sizeof x || x.a_magic != 0410)
82315Sbill 		_stop("Bad format\n");
83315Sbill 	printf("%d", x.a_text);
84315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
85315Sbill 		goto shread;
86315Sbill 	addr = (char *)x.a_text;
87315Sbill 	while ((int)addr & CLOFSET)
88315Sbill 		*addr++ = 0;
89315Sbill 	printf("+%d", x.a_data);
90315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
91315Sbill 		goto shread;
92315Sbill 	addr += x.a_data;
93315Sbill 	printf("+%d", x.a_bss);
94315Sbill 	x.a_bss += 128*512;	/* slop */
95315Sbill 	for (i = 0; i < x.a_bss; i++)
96315Sbill 		*addr++ = 0;
97315Sbill 	x.a_entry &= 0x7fffffff;
98315Sbill 	printf(" start 0x%x\n", x.a_entry);
99315Sbill 	(*((int (*)()) x.a_entry))();
100315Sbill 	_exit();
101315Sbill shread:
102315Sbill 	_stop("Short read\n");
103315Sbill }
104