xref: /csrg-svn/sys/vax/stand/boot.c (revision 3261)
1*3261Swnj /*	boot.c	4.2	81/03/15	*/
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 */
24*3261Swnj 	'h','k',	/* 3 = hk */
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
361593Sbill 	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];
43*3261Swnj 		} else
441466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
451466Sbill 	}
461575Sbill #endif
471466Sbill 	retry = 0;
481466Sbill 	for (;;) {
491466Sbill 		if (howto & RB_ASKNAME) {
501466Sbill 			printf(": ");
511466Sbill 			gets(line);
521466Sbill 		} else
531466Sbill 			printf(": %s\n", line);
541466Sbill 		io = open(line, 0);
551466Sbill 		if (io >= 0)
561466Sbill 			copyunix(howto, io);
571466Sbill 		if (++retry > 2)
581466Sbill 			howto = RB_SINGLE|RB_ASKNAME;
591466Sbill 	}
60315Sbill }
61315Sbill 
621466Sbill copyunix(howto, io)
631466Sbill 	register howto, io;
64315Sbill {
65315Sbill 	struct exec x;
66315Sbill 	register int i;
67315Sbill 	char *addr;
68315Sbill 
69315Sbill 	i = read(io, (char *)&x, sizeof x);
70315Sbill 	if (i != sizeof x || x.a_magic != 0410)
71315Sbill 		_stop("Bad format\n");
72315Sbill 	printf("%d", x.a_text);
73315Sbill 	if (read(io, (char *)0, x.a_text) != x.a_text)
74315Sbill 		goto shread;
75315Sbill 	addr = (char *)x.a_text;
76315Sbill 	while ((int)addr & CLOFSET)
77315Sbill 		*addr++ = 0;
78315Sbill 	printf("+%d", x.a_data);
79315Sbill 	if (read(io, addr, x.a_data) != x.a_data)
80315Sbill 		goto shread;
81315Sbill 	addr += x.a_data;
82315Sbill 	printf("+%d", x.a_bss);
83315Sbill 	x.a_bss += 128*512;	/* slop */
84315Sbill 	for (i = 0; i < x.a_bss; i++)
85315Sbill 		*addr++ = 0;
86315Sbill 	x.a_entry &= 0x7fffffff;
87315Sbill 	printf(" start 0x%x\n", x.a_entry);
88315Sbill 	(*((int (*)()) x.a_entry))();
89315Sbill 	_exit();
90315Sbill shread:
91315Sbill 	_stop("Short read\n");
92315Sbill }
93