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