Commit | Line | Data |
---|---|---|
92e67171 | 1 | /* boot.c 6.1 83/07/29 */ |
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 */ | |
1e549678 CL |
29 | 'u','t', /* 10 = ut */ |
30 | 'r','b', /* 11 = rb */ | |
c079fe19 SL |
31 | 0,0, /* 12 = uu */ |
32 | 0,0, /* 13 = rx */ | |
33 | 'r','l', /* 14 = rl */ | |
8da76047 BJ |
34 | }; |
35 | ||
36 | char line[100] = "xx(0,0)vmunix"; | |
b7e60356 | 37 | |
a889f9b7 BJ |
38 | int retry = 0; |
39 | ||
b7e60356 BJ |
40 | main() |
41 | { | |
8da76047 | 42 | register howto, devtype; /* howto=r11, devtype=r10 */ |
a889f9b7 | 43 | int io; |
b7e60356 | 44 | |
610c6f01 BJ |
45 | #ifdef lint |
46 | howto = 0; devtype = 0; | |
47 | #endif | |
b7e60356 | 48 | printf("\nBoot\n"); |
0bd37f37 | 49 | #ifdef JUSTASK |
aaa709c3 | 50 | howto = RB_ASKNAME|RB_SINGLE; |
0bd37f37 | 51 | #else |
8da76047 BJ |
52 | if ((howto&RB_ASKNAME)==0) { |
53 | if (devtype>=0 && devtype<sizeof(devname)/2 | |
54 | && devname[devtype][0]) { | |
55 | line[0] = devname[devtype][0]; | |
56 | line[1] = devname[devtype][1]; | |
a0761322 | 57 | } else |
8da76047 | 58 | howto = RB_SINGLE|RB_ASKNAME; |
8da76047 | 59 | } |
0bd37f37 | 60 | #endif |
8da76047 BJ |
61 | for (;;) { |
62 | if (howto & RB_ASKNAME) { | |
63 | printf(": "); | |
64 | gets(line); | |
65 | } else | |
66 | printf(": %s\n", line); | |
67 | io = open(line, 0); | |
68 | if (io >= 0) | |
a889f9b7 | 69 | copyunix(howto, io); |
8da76047 BJ |
70 | if (++retry > 2) |
71 | howto = RB_SINGLE|RB_ASKNAME; | |
72 | } | |
b7e60356 BJ |
73 | } |
74 | ||
a889f9b7 BJ |
75 | /*ARGSUSED*/ |
76 | copyunix(howto, io) | |
77 | register howto, io; | |
b7e60356 BJ |
78 | { |
79 | struct exec x; | |
80 | register int i; | |
81 | char *addr; | |
82 | ||
83 | i = read(io, (char *)&x, sizeof x); | |
06254255 KM |
84 | if (i != sizeof x || |
85 | (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) | |
b7e60356 BJ |
86 | _stop("Bad format\n"); |
87 | printf("%d", x.a_text); | |
b5d17f4d | 88 | if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1) |
06254255 | 89 | goto shread; |
b7e60356 BJ |
90 | if (read(io, (char *)0, x.a_text) != x.a_text) |
91 | goto shread; | |
92 | addr = (char *)x.a_text; | |
06254255 KM |
93 | if (x.a_magic == 0413 || x.a_magic == 0410) |
94 | while ((int)addr & CLOFSET) | |
95 | *addr++ = 0; | |
b7e60356 BJ |
96 | printf("+%d", x.a_data); |
97 | if (read(io, addr, x.a_data) != x.a_data) | |
98 | goto shread; | |
99 | addr += x.a_data; | |
100 | printf("+%d", x.a_bss); | |
101 | x.a_bss += 128*512; /* slop */ | |
102 | for (i = 0; i < x.a_bss; i++) | |
103 | *addr++ = 0; | |
104 | x.a_entry &= 0x7fffffff; | |
105 | printf(" start 0x%x\n", x.a_entry); | |
106 | (*((int (*)()) x.a_entry))(); | |
107 | _exit(); | |
108 | shread: | |
109 | _stop("Short read\n"); | |
110 | } |