xref: /csrg-svn/sys/tahoe/stand/boot.c (revision 38118)
1*38118Sbostic /*	boot.c	7.2	89/05/24	*/
225865Ssam 
337504Smckusick #include "machine/mtpr.h"
425865Ssam 
525865Ssam #include "param.h"
625865Ssam #include "inode.h"
725865Ssam #include "fs.h"
825865Ssam #include "vm.h"
925865Ssam #include "saio.h"
1025865Ssam #include "reboot.h"
1125865Ssam 
1225865Ssam #include <a.out.h>
1325865Ssam 
1425865Ssam /*
1525865Ssam  * Boot program... arguments passed in r10 and r11 determine
1625865Ssam  * whether boot stops to ask for system name and which device
1725865Ssam  * boot comes from.
1825865Ssam  */
1925865Ssam 
2030177Skarels #define	DEV_DFLT	1		/* vd/dk */
21*38118Sbostic /*#define	DEV_DFLT	2		/* hd */
2225865Ssam 
2325865Ssam char line[100];
2425865Ssam 
2530758Skarels extern	unsigned opendev;
2630758Skarels extern	unsigned bootdev;
2725865Ssam 
2825865Ssam main()
2925865Ssam {
3030758Skarels 	register char *cp;		/* skip r12 */
3133652Sbostic 	register u_int howto, devtype;	/* howto=r11, devtype=r10 */
3237567Sbostic 	int io = 0, retry, type;
3325865Ssam 
3425865Ssam #ifdef lint
3525865Ssam 	howto = 0; devtype = 0;
3625865Ssam #endif
3730758Skarels 	if ((devtype & B_MAGICMASK) != B_DEVMAGIC)
3830758Skarels 		devtype = DEV_DFLT << B_TYPESHIFT;	/* unit, partition 0 */
3930758Skarels 	bootdev = devtype;
4025865Ssam #ifdef JUSTASK
4125865Ssam 	howto = RB_ASKNAME|RB_SINGLE;
4229565Ssam #else
4329565Ssam 	if ((howto & RB_ASKNAME) == 0) {
4430758Skarels 		type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
4533652Sbostic 		if ((unsigned)type < ndevs && devsw[type].dv_name)
4630758Skarels 			strcpy(line, UNIX);
4730758Skarels 		else
4830758Skarels 			howto |= RB_SINGLE|RB_ASKNAME;
4929565Ssam 	}
5025865Ssam #endif
5133652Sbostic 	for (retry = 0;;) {
5237567Sbostic 		if (io >= 0)
5337567Sbostic 			printf("\nBoot");
5425865Ssam 		if (howto & RB_ASKNAME) {
5525865Ssam 			printf(": ");
5625865Ssam 			gets(line);
5730758Skarels 			if (line[0] == 0) {
5830758Skarels 				strcpy(line, UNIX);
5930758Skarels 				printf(": %s\n", line);
6030758Skarels 			}
6125865Ssam 		} else
6225865Ssam 			printf(": %s\n", line);
6325865Ssam 		io = open(line, 0);
6429565Ssam 		if (io >= 0) {
6530758Skarels 			copyunix(howto, opendev, io);
6629565Ssam 			close(io);
6730758Skarels 			howto |= RB_SINGLE|RB_ASKNAME;
6829565Ssam 		}
6925865Ssam 		if (++retry > 2)
7025865Ssam 			howto |= RB_SINGLE|RB_ASKNAME;
7125865Ssam 	}
7225865Ssam }
7325865Ssam 
7425865Ssam /*ARGSUSED*/
7529565Ssam copyunix(howto, devtype, io)
7629565Ssam 	register io, howto, devtype;	/* NOTE ORDER */
7725865Ssam {
7830182Ssam 	register int esym;		/* must be r9 */
7925865Ssam 	register int i;
8029565Ssam 	register char *addr;
8130182Ssam 	struct exec x;
8225865Ssam 
8337567Sbostic 	if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) {
8437567Sbostic 		printf("bad magic #\n");
8530758Skarels 		return;
8630758Skarels 	}
8737567Sbostic 	printf("%ld", x.a_text);
8837567Sbostic 	if (x.a_magic == ZMAGIC && lseek(io, 0x400, 0) == -1)
8925865Ssam 		goto shread;
9030307Skarels 	if (read(io, (char *)RELOC, x.a_text) != x.a_text)
9125865Ssam 		goto shread;
9230307Skarels 	addr = (char *)(x.a_text + RELOC);
9337567Sbostic 	if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC)
9425865Ssam 		while ((int)addr & CLOFSET)
9525865Ssam 			*addr++ = 0;
9637567Sbostic 	printf("+%ld", x.a_data);
9725865Ssam 	if (read(io, addr, x.a_data) != x.a_data)
9825865Ssam 		goto shread;
9925865Ssam 	addr += x.a_data;
10037567Sbostic 	printf("+%ld", x.a_bss);
10130182Ssam 	if (howto & RB_KDB && x.a_syms) {
10230182Ssam 		for (i = 0; i < x.a_bss; i++)
10330182Ssam 			*addr++ = 0;
10430182Ssam 		*(int *)addr = x.a_syms;		/* symbol table size */
10530182Ssam 		addr += sizeof (int);
10637567Sbostic 		printf("[+%ld", x.a_syms);
10730182Ssam 		if (read(io, addr, x.a_syms) != x.a_syms)
10830182Ssam 			goto shread;
10930182Ssam 		addr += x.a_syms;
11030182Ssam 		if (read(io, addr, sizeof (int)) != sizeof (int))
11130182Ssam 			goto shread;
11230182Ssam 		i = *(int *)addr - sizeof (int);	/* string table size */
11330182Ssam 		addr += sizeof (int);
11430182Ssam 		printf("+%d]", i);
11530182Ssam 		if (read(io, addr, i) != i)
11630182Ssam 			goto shread;
11730182Ssam 		addr += i;
11830182Ssam 		esym = roundup((int)addr, sizeof (int));
11930182Ssam 		x.a_bss = 0;
12030182Ssam 	} else
12130182Ssam 		howto &= ~RB_KDB;
12225865Ssam 	x.a_bss += 32*1024;	/* slop */
12325865Ssam 	for (i = 0; i < x.a_bss; i++)
12425865Ssam 		*addr++ = 0;
12525865Ssam 	x.a_entry &= 0x1fffffff;
12637567Sbostic 	printf(" start 0x%lx\n", x.a_entry);
12725865Ssam 	mtpr(PADC, 0);		/* Purge data cache */
12825865Ssam 	mtpr(PACC, 0);		/* Purge code cache */
12929565Ssam 	mtpr(DCR, 1);		/* Enable data cache */
13025865Ssam 	(*((int (*)()) x.a_entry))();
13129565Ssam 	return;
13225865Ssam shread:
13337567Sbostic 	printf("short read\n");
13430758Skarels 	return;
13525865Ssam }
136