xref: /csrg-svn/sys/vax/stand/boot.c (revision 13163)
1*13163Ssam /*	boot.c	4.10	83/06/16	*/
2315Sbill 
3315Sbill #include "../h/param.h"
4315Sbill #include "../h/inode.h"
56069Smckusic #include "../h/fs.h"
6315Sbill #include "../h/vm.h"
7315Sbill #include <a.out.h>
8315Sbill #include "saio.h"
96069Smckusic #include "../h/reboot.h"
10315Sbill 
111466Sbill /*
121466Sbill  * Boot program... arguments passed in r10 and r11 determine
131466Sbill  * whether boot stops to ask for system name and which device
141466Sbill  * boot comes from.
151466Sbill  */
16315Sbill 
171466Sbill /* Types in r10 specifying major device */
181466Sbill char	devname[][2] = {
191466Sbill 	'h','p',	/* 0 = hp */
201466Sbill 	0,0,		/* 1 = ht */
211466Sbill 	'u','p',	/* 2 = up */
223261Swnj 	'h','k',	/* 3 = hk */
234868Sroot 	0,0,		/* 4 = sw */
244868Sroot 	0,0,		/* 5 = tm */
254868Sroot 	0,0,		/* 6 = ts */
264868Sroot 	0,0,		/* 7 = mt */
274868Sroot 	0,0,		/* 8 = tu */
284868Sroot 	'r','a',	/* 9 = ra */
2911886Sleres 	'u','t',	/* 10 = ut */
3011886Sleres 	'r','b',	/* 11 = rb */
31*13163Ssam 	0,0,		/* 12 = uu */
32*13163Ssam 	0,0,		/* 13 = rx */
33*13163Ssam 	'r','l',	/* 14 = rl */
341466Sbill };
351466Sbill 
361466Sbill char line[100] = "xx(0,0)vmunix";
371466Sbill 
383347Swnj int	retry = 0;
393347Swnj 
40315Sbill main()
41315Sbill {
421466Sbill 	register howto, devtype;	/* howto=r11, devtype=r10 */
433347Swnj 	int io;
44315Sbill 
453274Swnj #ifdef lint
463274Swnj 	howto = 0; devtype = 0;
473274Swnj #endif
48315Sbill 	printf("\nBoot\n");
491575Sbill #ifdef JUSTASK
501593Sbill 	howto = RB_ASKNAME|RB_SINGLE;
511575Sbill #else
521466Sbill 	if ((howto&RB_ASKNAME)==0) {
531466Sbill 		if (devtype>=0 && devtype<sizeof(devname)/2
541466Sbill 		    && devname[devtype][0]) {
551466Sbill 			line[0] = devname[devtype][0];
561466Sbill 			line[1] = devname[devtype][1];
573261Swnj 		} else
581466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
591466Sbill 	}
601575Sbill #endif
611466Sbill 	for (;;) {
621466Sbill 		if (howto & RB_ASKNAME) {
631466Sbill 			printf(": ");
641466Sbill 			gets(line);
651466Sbill 		} else
661466Sbill 			printf(": %s\n", line);
671466Sbill 		io = open(line, 0);
681466Sbill 		if (io >= 0)
693347Swnj 			copyunix(howto, io);
701466Sbill 		if (++retry > 2)
711466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
721466Sbill 	}
73315Sbill }
74315Sbill 
753347Swnj /*ARGSUSED*/
763347Swnj copyunix(howto, io)
773347Swnj 	register howto, io;
78315Sbill {
79315Sbill 	struct exec x;
80315Sbill 	register int i;
81315Sbill 	char *addr;
82315Sbill 
83315Sbill 	i = read(io, (char *)&x, sizeof x);
846069Smckusic 	if (i != sizeof x ||
856069Smckusic 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
86315Sbill 		_stop("Bad format\n");
87315Sbill 	printf("%d", x.a_text);
887444Sroot 	if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
896069Smckusic 		goto shread;
90315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
91315Sbill 		goto shread;
92315Sbill 	addr = (char *)x.a_text;
936069Smckusic 	if (x.a_magic == 0413 || x.a_magic == 0410)
946069Smckusic 		while ((int)addr & CLOFSET)
956069Smckusic 			*addr++ = 0;
96315Sbill 	printf("+%d", x.a_data);
97315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
98315Sbill 		goto shread;
99315Sbill 	addr += x.a_data;
100315Sbill 	printf("+%d", x.a_bss);
101315Sbill 	x.a_bss += 128*512;	/* slop */
102315Sbill 	for (i = 0; i < x.a_bss; i++)
103315Sbill 		*addr++ = 0;
104315Sbill 	x.a_entry &= 0x7fffffff;
105315Sbill 	printf(" start 0x%x\n", x.a_entry);
106315Sbill 	(*((int (*)()) x.a_entry))();
107315Sbill 	_exit();
108315Sbill shread:
109315Sbill 	_stop("Short read\n");
110315Sbill }
111