Commit | Line | Data |
---|---|---|
3fd40431 WN |
1 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * William Jolitz. | |
7 | * | |
8 | * %sccs.include.noredist.c% | |
9 | */ | |
10 | ||
11 | #ifndef lint | |
12 | char copyright[] = | |
13 | "@(#) Copyright (c) 1990 The Regents of the University of California.\n\ | |
14 | All rights reserved.\n"; | |
15 | #endif /* not lint */ | |
16 | ||
17 | #ifndef lint | |
18 | static char sccsid[] = "@(#)boot.c 7.1 (Berkeley) %G%"; | |
19 | #endif /* not lint */ | |
20 | ||
21 | #include "../h/param.h" | |
22 | #include "../h/inode.h" | |
23 | #include "../h/fs.h" | |
24 | #include "../h/dir.h" | |
25 | #include "../h/reboot.h" | |
26 | #include "../h/disk.h" | |
27 | #include <a.out.h> | |
28 | #include "saio.h" | |
29 | ||
30 | /* | |
31 | * Boot program... arguments passed in r6 and r7 determine | |
32 | * whether boot stops to ask for system name and which device | |
33 | * boot comes from. | |
34 | */ | |
35 | ||
36 | #define UNIX "/vmunix" | |
37 | ||
38 | char line[100] = UNIX; | |
39 | char line2[100] = "/stand/"; | |
40 | extern int howto, bootdev, unit, cyloffset, boottype; | |
41 | extern int opendev, openfirst; | |
42 | int retry = 0; | |
43 | ||
44 | main() | |
45 | { | |
46 | int io; | |
47 | ||
48 | howto = RB_SINGLE|RB_ASKNAME; | |
49 | for (;;) { | |
50 | if (howto & RB_ASKNAME) { | |
51 | printf("Boot: "); | |
52 | gets(line); | |
53 | } else | |
54 | printf("Boot: %s\n", line); | |
55 | if (line[0] == 0) { | |
56 | strcpy(line, UNIX); | |
57 | printf("Boot: %s\n", line); | |
58 | } | |
59 | ||
60 | io = open(line, 0); | |
61 | /*if (io < 0) { | |
62 | strcat(line2,line) ; | |
63 | io = open(line2, 0); | |
64 | }*/ | |
65 | if (io >= 0) { | |
66 | bootdev = opendev; | |
67 | copyunix(io); | |
68 | } | |
69 | openfirst = 1; | |
70 | if (++retry > 2) | |
71 | howto = RB_SINGLE|RB_ASKNAME; | |
72 | } | |
73 | } | |
74 | ||
75 | /*ARGSUSED*/ | |
76 | copyunix(io) | |
77 | register io; | |
78 | { | |
79 | struct exec x; | |
80 | int i; | |
81 | char *addr; | |
82 | ||
83 | i = read(io, (char *)&x, sizeof x); | |
84 | if (i != sizeof x || | |
85 | (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) | |
86 | _stop("Bad format\n"); | |
87 | printf("%d", x.a_text); | |
88 | if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1) | |
89 | goto shread; | |
90 | if (read(io, (char *)0, x.a_text) != x.a_text) | |
91 | goto shread; | |
92 | addr = (char *)x.a_text; | |
93 | if (x.a_magic == 0413 || x.a_magic == 0410) | |
94 | while ((int)addr & CLOFSET) | |
95 | *addr++ = 0; | |
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 | printf(" start 0x%x\n", x.a_entry); | |
105 | setregs() ; | |
106 | i = (*((int (*)()) x.a_entry))(); | |
107 | if (i) printf("exit %d\n", i) ; | |
108 | return; | |
109 | shread: | |
110 | _stop("Short read\n"); | |
111 | } |