xref: /csrg-svn/sys/vax/stand/boot.c (revision 11886)
1*11886Sleres /*	boot.c	4.9	83/04/08	*/
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 */
29*11886Sleres 	'u','t',	/* 10 = ut */
30*11886Sleres 	'r','b',	/* 11 = rb */
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);
816069Smckusic 	if (i != sizeof x ||
826069Smckusic 	    (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
83315Sbill 		_stop("Bad format\n");
84315Sbill 	printf("%d", x.a_text);
857444Sroot 	if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
866069Smckusic 		goto shread;
87315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
88315Sbill 		goto shread;
89315Sbill 	addr = (char *)x.a_text;
906069Smckusic 	if (x.a_magic == 0413 || x.a_magic == 0410)
916069Smckusic 		while ((int)addr & CLOFSET)
926069Smckusic 			*addr++ = 0;
93315Sbill 	printf("+%d", x.a_data);
94315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
95315Sbill 		goto shread;
96315Sbill 	addr += x.a_data;
97315Sbill 	printf("+%d", x.a_bss);
98315Sbill 	x.a_bss += 128*512;	/* slop */
99315Sbill 	for (i = 0; i < x.a_bss; i++)
100315Sbill 		*addr++ = 0;
101315Sbill 	x.a_entry &= 0x7fffffff;
102315Sbill 	printf(" start 0x%x\n", x.a_entry);
103315Sbill 	(*((int (*)()) x.a_entry))();
104315Sbill 	_exit();
105315Sbill shread:
106315Sbill 	_stop("Short read\n");
107315Sbill }
108