Commit | Line | Data |
---|---|---|
06254255 | 1 | /* boot.c 4.7 82/03/07 */ |
b7e60356 BJ |
2 | |
3 | #include "../h/param.h" | |
b7e60356 | 4 | #include "../h/inode.h" |
06254255 | 5 | #include "../h/fs.h" |
b7e60356 BJ |
6 | #include "../h/vm.h" |
7 | #include <a.out.h> | |
8 | #include "saio.h" | |
06254255 | 9 | #include "../h/reboot.h" |
b7e60356 | 10 | |
8da76047 BJ |
11 | /* |
12 | * Boot program... arguments passed in r10 and r11 determine | |
13 | * whether boot stops to ask for system name and which device | |
14 | * boot comes from. | |
15 | */ | |
16 | ||
17 | /* Types in r10 specifying major device */ | |
18 | char devname[][2] = { | |
19 | 'h','p', /* 0 = hp */ | |
20 | 0,0, /* 1 = ht */ | |
21 | 'u','p', /* 2 = up */ | |
a0761322 | 22 | 'h','k', /* 3 = hk */ |
3486ee81 BJ |
23 | 0,0, /* 4 = sw */ |
24 | 0,0, /* 5 = tm */ | |
25 | 0,0, /* 6 = ts */ | |
26 | 0,0, /* 7 = mt */ | |
27 | 0,0, /* 8 = tu */ | |
28 | 'r','a', /* 9 = ra */ | |
ab569e06 | 29 | 'u', 't', /* 10 = ut */ |
8da76047 BJ |
30 | }; |
31 | ||
32 | char line[100] = "xx(0,0)vmunix"; | |
b7e60356 | 33 | |
a889f9b7 BJ |
34 | int retry = 0; |
35 | ||
b7e60356 BJ |
36 | main() |
37 | { | |
8da76047 | 38 | register howto, devtype; /* howto=r11, devtype=r10 */ |
a889f9b7 | 39 | int io; |
b7e60356 | 40 | |
610c6f01 BJ |
41 | #ifdef lint |
42 | howto = 0; devtype = 0; | |
43 | #endif | |
b7e60356 | 44 | printf("\nBoot\n"); |
0bd37f37 | 45 | #ifdef JUSTASK |
aaa709c3 | 46 | howto = RB_ASKNAME|RB_SINGLE; |
0bd37f37 | 47 | #else |
8da76047 BJ |
48 | if ((howto&RB_ASKNAME)==0) { |
49 | if (devtype>=0 && devtype<sizeof(devname)/2 | |
50 | && devname[devtype][0]) { | |
51 | line[0] = devname[devtype][0]; | |
52 | line[1] = devname[devtype][1]; | |
a0761322 | 53 | } else |
8da76047 | 54 | howto = RB_SINGLE|RB_ASKNAME; |
8da76047 | 55 | } |
0bd37f37 | 56 | #endif |
8da76047 BJ |
57 | for (;;) { |
58 | if (howto & RB_ASKNAME) { | |
59 | printf(": "); | |
60 | gets(line); | |
61 | } else | |
62 | printf(": %s\n", line); | |
63 | io = open(line, 0); | |
64 | if (io >= 0) | |
a889f9b7 | 65 | copyunix(howto, io); |
8da76047 BJ |
66 | if (++retry > 2) |
67 | howto = RB_SINGLE|RB_ASKNAME; | |
68 | } | |
b7e60356 BJ |
69 | } |
70 | ||
a889f9b7 BJ |
71 | /*ARGSUSED*/ |
72 | copyunix(howto, io) | |
73 | register howto, io; | |
b7e60356 BJ |
74 | { |
75 | struct exec x; | |
76 | register int i; | |
77 | char *addr; | |
78 | ||
79 | i = read(io, (char *)&x, sizeof x); | |
06254255 KM |
80 | if (i != sizeof x || |
81 | (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) | |
b7e60356 BJ |
82 | _stop("Bad format\n"); |
83 | printf("%d", x.a_text); | |
06254255 KM |
84 | if ((x.a_magic == 0413 || x.a_magic == 0410) && |
85 | lseek(io, 0x400, 0) == -1) | |
86 | goto shread; | |
b7e60356 BJ |
87 | if (read(io, (char *)0, x.a_text) != x.a_text) |
88 | goto shread; | |
89 | addr = (char *)x.a_text; | |
06254255 KM |
90 | if (x.a_magic == 0413 || x.a_magic == 0410) |
91 | while ((int)addr & CLOFSET) | |
92 | *addr++ = 0; | |
b7e60356 BJ |
93 | printf("+%d", x.a_data); |
94 | if (read(io, addr, x.a_data) != x.a_data) | |
95 | goto shread; | |
96 | addr += x.a_data; | |
97 | printf("+%d", x.a_bss); | |
98 | x.a_bss += 128*512; /* slop */ | |
99 | for (i = 0; i < x.a_bss; i++) | |
100 | *addr++ = 0; | |
101 | x.a_entry &= 0x7fffffff; | |
102 | printf(" start 0x%x\n", x.a_entry); | |
103 | (*((int (*)()) x.a_entry))(); | |
104 | _exit(); | |
105 | shread: | |
106 | _stop("Short read\n"); | |
107 | } |