1 /* bootxx.c 4.1 82/07/19 */ 2 3 #include "../h/param.h" 4 #include "../h/inode.h" 5 #include "../h/fs.h" 6 #include "../h/vm.h" 7 #include <a.out.h> 8 #include "saio.h" 9 #include "../h/reboot.h" 10 11 #ifdef BOOTRK 12 char bootprog[] = "hk(0,0)boot"; 13 #endif 14 #ifdef BOOTHP 15 char bootprog[] = "hp(0,0)boot"; 16 #endif 17 #ifdef BOOTUP 18 char bootprog[] = "up(0,0)boot"; 19 #endif 20 21 /* 22 * Boot program... arguments passed in r10 and r11 23 * are passed through to the full boot program. 24 */ 25 26 main() 27 { 28 register howto, devtype; /* howto=r11, devtype=r10 */ 29 int io; 30 31 #ifdef lint 32 howto = 0; devtype = 0; 33 #endif 34 printf("loading %s", bootprog); 35 io = open(bootprog, 0); 36 if (io >= 0) 37 copyunix(howto, devtype, io); 38 printf("boot failed"); 39 _exit(); 40 } 41 42 /*ARGSUSED*/ 43 copyunix(howto, devtype, io) 44 register howto, devtype, io; /* howto=r11, devtype=r10 */ 45 { 46 struct exec x; 47 register int i; 48 char *addr; 49 50 i = read(io, (char *)&x, sizeof x); 51 if (i != sizeof x || 52 (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) 53 _stop("Bad format\n"); 54 if ((x.a_magic == 0413 || x.a_magic == 0410) && 55 lseek(io, 0x400, 0) == -1) 56 goto shread; 57 if (read(io, (char *)0, x.a_text) != x.a_text) 58 goto shread; 59 addr = (char *)x.a_text; 60 if (x.a_magic == 0413 || x.a_magic == 0410) 61 while ((int)addr & CLOFSET) 62 *addr++ = 0; 63 if (read(io, addr, x.a_data) != x.a_data) 64 goto shread; 65 addr += x.a_data; 66 x.a_bss += 128*512; /* slop */ 67 for (i = 0; i < x.a_bss; i++) 68 *addr++ = 0; 69 x.a_entry &= 0x7fffffff; 70 (*((int (*)()) x.a_entry))(); 71 _exit(); 72 shread: 73 _stop("Short read\n"); 74 } 75