xref: /original-bsd/sys/tahoe/stand/boot.c (revision 5f05f1db)
1*5f05f1dbSbostic /*-
2*5f05f1dbSbostic  * Copyright (c) 1991 The Regents of the University of California.
3*5f05f1dbSbostic  * All rights reserved.
4*5f05f1dbSbostic  *
5*5f05f1dbSbostic  * %sccs.include.redist.c%
6*5f05f1dbSbostic  *
7*5f05f1dbSbostic  *	@(#)boot.c	7.6 (Berkeley) 05/04/91
8*5f05f1dbSbostic  */
98e3d4093Ssam 
10efc1a105Sbostic #include "../include/mtpr.h"
118e3d4093Ssam 
1234fde8eeSroot #include "sys/param.h"
1334fde8eeSroot #include "sys/time.h"
1434fde8eeSroot #include "sys/vm.h"
1534fde8eeSroot #include "sys/reboot.h"
16efc1a105Sbostic #include "stand/saio.h"
178e3d4093Ssam 
188e3d4093Ssam #include <a.out.h>
198e3d4093Ssam 
208e3d4093Ssam /*
218e3d4093Ssam  * Boot program... arguments passed in r10 and r11 determine
228e3d4093Ssam  * whether boot stops to ask for system name and which device
238e3d4093Ssam  * boot comes from.
248e3d4093Ssam  */
258e3d4093Ssam 
26977ec1dbSkarels #define	DEV_DFLT	1		/* vd/dk */
2711d23908Sbostic /*#define	DEV_DFLT	2		/* hd */
288e3d4093Ssam 
298e3d4093Ssam char line[100];
308e3d4093Ssam 
3140ca8ffdSkarels extern	unsigned opendev;
3240ca8ffdSkarels extern	unsigned bootdev;
338e3d4093Ssam 
main()348e3d4093Ssam main()
358e3d4093Ssam {
3640ca8ffdSkarels 	register char *cp;		/* skip r12 */
371e26076aSbostic 	register u_int howto, devtype;	/* howto=r11, devtype=r10 */
38ce325219Sbostic 	int io = 0, retry, type;
398e3d4093Ssam 
408e3d4093Ssam #ifdef lint
418e3d4093Ssam 	howto = 0; devtype = 0;
428e3d4093Ssam #endif
4340ca8ffdSkarels 	if ((devtype & B_MAGICMASK) != B_DEVMAGIC)
4440ca8ffdSkarels 		devtype = DEV_DFLT << B_TYPESHIFT;	/* unit, partition 0 */
4540ca8ffdSkarels 	bootdev = devtype;
468e3d4093Ssam #ifdef JUSTASK
478e3d4093Ssam 	howto = RB_ASKNAME|RB_SINGLE;
48988e96f5Ssam #else
49988e96f5Ssam 	if ((howto & RB_ASKNAME) == 0) {
5040ca8ffdSkarels 		type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
511e26076aSbostic 		if ((unsigned)type < ndevs && devsw[type].dv_name)
5240ca8ffdSkarels 			strcpy(line, UNIX);
5340ca8ffdSkarels 		else
5440ca8ffdSkarels 			howto |= RB_SINGLE|RB_ASKNAME;
55988e96f5Ssam 	}
568e3d4093Ssam #endif
571e26076aSbostic 	for (retry = 0;;) {
58ce325219Sbostic 		if (io >= 0)
59ce325219Sbostic 			printf("\nBoot");
608e3d4093Ssam 		if (howto & RB_ASKNAME) {
618e3d4093Ssam 			printf(": ");
628e3d4093Ssam 			gets(line);
6340ca8ffdSkarels 			if (line[0] == 0) {
6440ca8ffdSkarels 				strcpy(line, UNIX);
6540ca8ffdSkarels 				printf(": %s\n", line);
6640ca8ffdSkarels 			}
678e3d4093Ssam 		} else
688e3d4093Ssam 			printf(": %s\n", line);
698e3d4093Ssam 		io = open(line, 0);
70988e96f5Ssam 		if (io >= 0) {
7140ca8ffdSkarels 			copyunix(howto, opendev, io);
72988e96f5Ssam 			close(io);
7340ca8ffdSkarels 			howto |= RB_SINGLE|RB_ASKNAME;
74988e96f5Ssam 		}
758e3d4093Ssam 		if (++retry > 2)
768e3d4093Ssam 			howto |= RB_SINGLE|RB_ASKNAME;
778e3d4093Ssam 	}
788e3d4093Ssam }
798e3d4093Ssam 
808e3d4093Ssam /*ARGSUSED*/
copyunix(howto,devtype,io)81988e96f5Ssam copyunix(howto, devtype, io)
82988e96f5Ssam 	register io, howto, devtype;	/* NOTE ORDER */
838e3d4093Ssam {
84097b37ecSsam 	register int esym;		/* must be r9 */
858e3d4093Ssam 	register int i;
86988e96f5Ssam 	register char *addr;
87097b37ecSsam 	struct exec x;
888e3d4093Ssam 
89ce325219Sbostic 	if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) {
90ce325219Sbostic 		printf("bad magic #\n");
9140ca8ffdSkarels 		return;
9240ca8ffdSkarels 	}
93ce325219Sbostic 	printf("%ld", x.a_text);
94ce325219Sbostic 	if (x.a_magic == ZMAGIC && lseek(io, 0x400, 0) == -1)
958e3d4093Ssam 		goto shread;
9678713aceSkarels 	if (read(io, (char *)RELOC, x.a_text) != x.a_text)
978e3d4093Ssam 		goto shread;
9878713aceSkarels 	addr = (char *)(x.a_text + RELOC);
99ce325219Sbostic 	if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC)
1008e3d4093Ssam 		while ((int)addr & CLOFSET)
1018e3d4093Ssam 			*addr++ = 0;
102ce325219Sbostic 	printf("+%ld", x.a_data);
1038e3d4093Ssam 	if (read(io, addr, x.a_data) != x.a_data)
1048e3d4093Ssam 		goto shread;
1058e3d4093Ssam 	addr += x.a_data;
106ce325219Sbostic 	printf("+%ld", x.a_bss);
107097b37ecSsam 	if (howto & RB_KDB && x.a_syms) {
108097b37ecSsam 		for (i = 0; i < x.a_bss; i++)
109097b37ecSsam 			*addr++ = 0;
110097b37ecSsam 		*(int *)addr = x.a_syms;		/* symbol table size */
111097b37ecSsam 		addr += sizeof (int);
112ce325219Sbostic 		printf("[+%ld", x.a_syms);
113097b37ecSsam 		if (read(io, addr, x.a_syms) != x.a_syms)
114097b37ecSsam 			goto shread;
115097b37ecSsam 		addr += x.a_syms;
116097b37ecSsam 		if (read(io, addr, sizeof (int)) != sizeof (int))
117097b37ecSsam 			goto shread;
118097b37ecSsam 		i = *(int *)addr - sizeof (int);	/* string table size */
119097b37ecSsam 		addr += sizeof (int);
120097b37ecSsam 		printf("+%d]", i);
121097b37ecSsam 		if (read(io, addr, i) != i)
122097b37ecSsam 			goto shread;
123097b37ecSsam 		addr += i;
124097b37ecSsam 		esym = roundup((int)addr, sizeof (int));
125097b37ecSsam 		x.a_bss = 0;
126097b37ecSsam 	} else
127097b37ecSsam 		howto &= ~RB_KDB;
1288e3d4093Ssam 	x.a_bss += 32*1024;	/* slop */
1298e3d4093Ssam 	for (i = 0; i < x.a_bss; i++)
1308e3d4093Ssam 		*addr++ = 0;
1318e3d4093Ssam 	x.a_entry &= 0x1fffffff;
132ce325219Sbostic 	printf(" start 0x%lx\n", x.a_entry);
1338e3d4093Ssam 	mtpr(PADC, 0);		/* Purge data cache */
1348e3d4093Ssam 	mtpr(PACC, 0);		/* Purge code cache */
1358e3d4093Ssam 	mtpr(DCR, 1);		/* Enable data cache */
1368e3d4093Ssam 	(*((int (*)()) x.a_entry))();
137988e96f5Ssam 	return;
1388e3d4093Ssam shread:
139ce325219Sbostic 	printf("short read\n");
14040ca8ffdSkarels 	return;
1418e3d4093Ssam }
142