Commit | Line | Data |
---|---|---|
8ae0e4b4 | 1 | /* |
0880b18e | 2 | * Copyright (c) 1982, 1986 Regents of the University of California. |
8ae0e4b4 KM |
3 | * All rights reserved. The Berkeley software License Agreement |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
a7ef7c09 | 6 | * @(#)bootxx.c 7.4 (Berkeley) %G% |
8ae0e4b4 | 7 | */ |
b6c81d5e | 8 | |
39c71180 MK |
9 | #include "param.h" |
10 | #include "inode.h" | |
11 | #include "fs.h" | |
12 | #include "vm.h" | |
13 | #include "reboot.h" | |
b6c81d5e RE |
14 | #include <a.out.h> |
15 | #include "saio.h" | |
b6c81d5e | 16 | |
767be6f6 MK |
17 | char bootprog[] = "boot"; |
18 | extern unsigned opendev; | |
b6c81d5e RE |
19 | |
20 | /* | |
21 | * Boot program... arguments passed in r10 and r11 | |
22 | * are passed through to the full boot program. | |
23 | */ | |
24 | ||
25 | main() | |
26 | { | |
24a62d66 MK |
27 | register unsigned howto, devtype; /* howto=r11, devtype=r10 */ |
28 | int io, unit, partition; | |
29 | register char *cp; | |
b6c81d5e RE |
30 | |
31 | #ifdef lint | |
767be6f6 | 32 | howto = 0; devtype = 0; devtype = devtype; |
b6c81d5e | 33 | #endif |
f834e141 | 34 | printf("loading %s\n", bootprog); |
b6c81d5e RE |
35 | io = open(bootprog, 0); |
36 | if (io >= 0) | |
767be6f6 | 37 | copyunix(howto, opendev, io); |
f834e141 | 38 | _stop("boot failed\n"); |
b6c81d5e RE |
39 | } |
40 | ||
41 | /*ARGSUSED*/ | |
42 | copyunix(howto, devtype, io) | |
43 | register howto, devtype, io; /* howto=r11, devtype=r10 */ | |
44 | { | |
45 | struct exec x; | |
46 | register int i; | |
47 | char *addr; | |
48 | ||
49 | i = read(io, (char *)&x, sizeof x); | |
a7ef7c09 | 50 | if (i != sizeof x || N_BADMAG(x)) |
b6c81d5e | 51 | _stop("Bad format\n"); |
a7ef7c09 KB |
52 | if ((x.a_magic == ZMAGIC || x.a_magic == NMAGIC) && |
53 | lseek(io, 0x400, L_SET) == -1) | |
b6c81d5e RE |
54 | goto shread; |
55 | if (read(io, (char *)0, x.a_text) != x.a_text) | |
56 | goto shread; | |
57 | addr = (char *)x.a_text; | |
a7ef7c09 | 58 | if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC) |
b6c81d5e RE |
59 | while ((int)addr & CLOFSET) |
60 | *addr++ = 0; | |
61 | if (read(io, addr, x.a_data) != x.a_data) | |
62 | goto shread; | |
63 | addr += x.a_data; | |
64 | x.a_bss += 128*512; /* slop */ | |
65 | for (i = 0; i < x.a_bss; i++) | |
66 | *addr++ = 0; | |
67 | x.a_entry &= 0x7fffffff; | |
68 | (*((int (*)()) x.a_entry))(); | |
f834e141 | 69 | return; |
b6c81d5e RE |
70 | shread: |
71 | _stop("Short read\n"); | |
72 | } |