date and time created 91/05/12 22:30:02 by william
[unix-history] / usr / src / sys / tahoe / stand / boot.c
CommitLineData
65dfbdd2
KB
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 *
7 * @(#)boot.c 7.6 (Berkeley) %G%
8 */
0f7a3e72 9
b28b3a13 10#include "../include/mtpr.h"
0f7a3e72 11
ec3296ac
BJ
12#include "sys/param.h"
13#include "sys/time.h"
ec3296ac
BJ
14#include "sys/vm.h"
15#include "sys/reboot.h"
b28b3a13 16#include "stand/saio.h"
0f7a3e72
SL
17
18#include <a.out.h>
19
20/*
21 * Boot program... arguments passed in r10 and r11 determine
22 * whether boot stops to ask for system name and which device
23 * boot comes from.
24 */
25
e694b431 26#define DEV_DFLT 1 /* vd/dk */
4d3223cd 27/*#define DEV_DFLT 2 /* hd */
0f7a3e72 28
0f7a3e72 29char line[100];
0f7a3e72 30
b026ac14
MK
31extern unsigned opendev;
32extern unsigned bootdev;
0f7a3e72
SL
33
34main()
35{
b026ac14 36 register char *cp; /* skip r12 */
1d4970c1 37 register u_int howto, devtype; /* howto=r11, devtype=r10 */
3e2e0d63 38 int io = 0, retry, type;
0f7a3e72
SL
39
40#ifdef lint
41 howto = 0; devtype = 0;
42#endif
b026ac14
MK
43 if ((devtype & B_MAGICMASK) != B_DEVMAGIC)
44 devtype = DEV_DFLT << B_TYPESHIFT; /* unit, partition 0 */
45 bootdev = devtype;
0f7a3e72
SL
46#ifdef JUSTASK
47 howto = RB_ASKNAME|RB_SINGLE;
08143a36 48#else
08143a36 49 if ((howto & RB_ASKNAME) == 0) {
b026ac14 50 type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
1d4970c1 51 if ((unsigned)type < ndevs && devsw[type].dv_name)
b026ac14
MK
52 strcpy(line, UNIX);
53 else
54 howto |= RB_SINGLE|RB_ASKNAME;
08143a36 55 }
0f7a3e72 56#endif
1d4970c1 57 for (retry = 0;;) {
3e2e0d63
KB
58 if (io >= 0)
59 printf("\nBoot");
0f7a3e72
SL
60 if (howto & RB_ASKNAME) {
61 printf(": ");
62 gets(line);
b026ac14
MK
63 if (line[0] == 0) {
64 strcpy(line, UNIX);
65 printf(": %s\n", line);
66 }
0f7a3e72
SL
67 } else
68 printf(": %s\n", line);
69 io = open(line, 0);
08143a36 70 if (io >= 0) {
b026ac14 71 copyunix(howto, opendev, io);
08143a36 72 close(io);
b026ac14 73 howto |= RB_SINGLE|RB_ASKNAME;
08143a36 74 }
0f7a3e72
SL
75 if (++retry > 2)
76 howto |= RB_SINGLE|RB_ASKNAME;
77 }
78}
79
80/*ARGSUSED*/
08143a36
SL
81copyunix(howto, devtype, io)
82 register io, howto, devtype; /* NOTE ORDER */
0f7a3e72 83{
b52d5981 84 register int esym; /* must be r9 */
0f7a3e72 85 register int i;
08143a36 86 register char *addr;
b52d5981 87 struct exec x;
0f7a3e72 88
3e2e0d63
KB
89 if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) {
90 printf("bad magic #\n");
b026ac14
MK
91 return;
92 }
3e2e0d63
KB
93 printf("%ld", x.a_text);
94 if (x.a_magic == ZMAGIC && lseek(io, 0x400, 0) == -1)
0f7a3e72 95 goto shread;
924840db 96 if (read(io, (char *)RELOC, x.a_text) != x.a_text)
0f7a3e72 97 goto shread;
924840db 98 addr = (char *)(x.a_text + RELOC);
3e2e0d63 99 if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC)
0f7a3e72
SL
100 while ((int)addr & CLOFSET)
101 *addr++ = 0;
3e2e0d63 102 printf("+%ld", x.a_data);
0f7a3e72
SL
103 if (read(io, addr, x.a_data) != x.a_data)
104 goto shread;
105 addr += x.a_data;
3e2e0d63 106 printf("+%ld", x.a_bss);
b52d5981
SL
107 if (howto & RB_KDB && x.a_syms) {
108 for (i = 0; i < x.a_bss; i++)
109 *addr++ = 0;
110 *(int *)addr = x.a_syms; /* symbol table size */
111 addr += sizeof (int);
3e2e0d63 112 printf("[+%ld", x.a_syms);
b52d5981
SL
113 if (read(io, addr, x.a_syms) != x.a_syms)
114 goto shread;
115 addr += x.a_syms;
116 if (read(io, addr, sizeof (int)) != sizeof (int))
117 goto shread;
118 i = *(int *)addr - sizeof (int); /* string table size */
119 addr += sizeof (int);
120 printf("+%d]", i);
121 if (read(io, addr, i) != i)
122 goto shread;
123 addr += i;
124 esym = roundup((int)addr, sizeof (int));
125 x.a_bss = 0;
126 } else
127 howto &= ~RB_KDB;
0f7a3e72
SL
128 x.a_bss += 32*1024; /* slop */
129 for (i = 0; i < x.a_bss; i++)
130 *addr++ = 0;
131 x.a_entry &= 0x1fffffff;
3e2e0d63 132 printf(" start 0x%lx\n", x.a_entry);
0f7a3e72
SL
133 mtpr(PADC, 0); /* Purge data cache */
134 mtpr(PACC, 0); /* Purge code cache */
08143a36 135 mtpr(DCR, 1); /* Enable data cache */
0f7a3e72 136 (*((int (*)()) x.a_entry))();
08143a36 137 return;
0f7a3e72 138shread:
3e2e0d63 139 printf("short read\n");
b026ac14 140 return;
0f7a3e72 141}