xref: /csrg-svn/sys/vax/stand/boot.c (revision 5154)
1*5154Ssam /*	boot.c	4.6	81/12/01	*/
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 */
254868Sroot 	0,0,		/* 4 = sw */
264868Sroot 	0,0,		/* 5 = tm */
274868Sroot 	0,0,		/* 6 = ts */
284868Sroot 	0,0,		/* 7 = mt */
294868Sroot 	0,0,		/* 8 = tu */
304868Sroot 	'r','a',	/* 9 = ra */
31*5154Ssam 	'u', 't',	/* 10 = ut */
321466Sbill };
331466Sbill 
341466Sbill char line[100] = "xx(0,0)vmunix";
351466Sbill 
363347Swnj int	retry = 0;
373347Swnj 
38315Sbill main()
39315Sbill {
401466Sbill 	register howto, devtype;	/* howto=r11, devtype=r10 */
413347Swnj 	int io;
42315Sbill 
433274Swnj #ifdef lint
443274Swnj 	howto = 0; devtype = 0;
453274Swnj #endif
46315Sbill 	printf("\nBoot\n");
471575Sbill #ifdef JUSTASK
481593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
491575Sbill #else
501466Sbill 	if ((howto&RB_ASKNAME)==0) {
511466Sbill 		if (devtype>=0 && devtype<sizeof(devname)/2
521466Sbill 		    && devname[devtype][0]) {
531466Sbill 			line[0] = devname[devtype][0];
541466Sbill 			line[1] = devname[devtype][1];
553261Swnj 		} else
561466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
571466Sbill 	}
581575Sbill #endif
591466Sbill 	for (;;) {
601466Sbill 		if (howto & RB_ASKNAME) {
611466Sbill 			printf(": ");
621466Sbill 			gets(line);
631466Sbill 		} else
641466Sbill 			printf(": %s\n", line);
651466Sbill 		io = open(line, 0);
661466Sbill 		if (io >= 0)
673347Swnj 			copyunix(howto, io);
681466Sbill 		if (++retry > 2)
691466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
701466Sbill 	}
71315Sbill }
72315Sbill 
733347Swnj /*ARGSUSED*/
743347Swnj copyunix(howto, io)
753347Swnj 	register howto, io;
76315Sbill {
77315Sbill 	struct exec x;
78315Sbill 	register int i;
79315Sbill 	char *addr;
80315Sbill 
81315Sbill 	i = read(io, (char *)&x, sizeof x);
82315Sbill 	if (i != sizeof x || x.a_magic != 0410)
83315Sbill 		_stop("Bad format\n");
84315Sbill 	printf("%d", x.a_text);
85315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
86315Sbill 		goto shread;
87315Sbill 	addr = (char *)x.a_text;
88315Sbill 	while ((int)addr & CLOFSET)
89315Sbill 		*addr++ = 0;
90315Sbill 	printf("+%d", x.a_data);
91315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
92315Sbill 		goto shread;
93315Sbill 	addr += x.a_data;
94315Sbill 	printf("+%d", x.a_bss);
95315Sbill 	x.a_bss += 128*512;	/* slop */
96315Sbill 	for (i = 0; i < x.a_bss; i++)
97315Sbill 		*addr++ = 0;
98315Sbill 	x.a_entry &= 0x7fffffff;
99315Sbill 	printf(" start 0x%x\n", x.a_entry);
100315Sbill 	(*((int (*)()) x.a_entry))();
101315Sbill 	_exit();
102315Sbill shread:
103315Sbill 	_stop("Short read\n");
104315Sbill }
105