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