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.redist.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.3 (Berkeley) 05/04/91"; 19 #endif /* not lint */ 20 21 #include "param.h" 22 #include "reboot.h" 23 #include <a.out.h> 24 #include <setjmp.h> 25 #include "saio.h" 26 27 /* 28 * Boot program... arguments from lower-level bootstrap determine 29 * whether boot stops to ask for system name and which device 30 * boot comes from. 31 */ 32 33 char line[100] = UNIX; 34 extern int opendev, bootdev, cyloffset; 35 int retry = 0; 36 extern jmp_buf exception; 37 38 main(howto, dev, off) 39 { 40 int io; 41 42 if((dev&B_MAGICMASK) == B_DEVMAGIC) { 43 bootdev = dev; 44 cyloffset = off; 45 } else goto again; 46 47 if(_setjmp(exception)) { 48 close(io); 49 printf("- load aborted\n"); 50 again: 51 howto = RB_SINGLE|RB_ASKNAME; 52 cyloffset = 0; 53 } 54 55 for (;;) { 56 if (howto & RB_ASKNAME) { 57 char *cp; 58 59 printf("Boot: "); 60 gets(line); 61 62 /* process additional flags if any */ 63 if(cp = (char *)index(line, ' ')) { 64 howto = strtol (cp, 0, 0); 65 *cp = '\0'; 66 } 67 cyloffset = 0; 68 } else 69 printf("Boot: %s\n", line); 70 71 if (line[0] == 0) { 72 strcpy(line, UNIX); 73 printf("Boot: %s\n", line); 74 } 75 76 io = open(line, 0); 77 if (io >= 0) { 78 copyunix(io, howto); 79 goto again; 80 } else if (++retry > 2) 81 goto again; 82 } 83 } 84 85 /*ARGSUSED*/ 86 copyunix(io, howto) 87 register io; 88 { 89 struct exec x; 90 int i; 91 char *addr,c; 92 93 i = read(io, (char *)&x, sizeof x); 94 if (i != sizeof x || 95 (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) { 96 printf("Bad format\n"); 97 return; 98 } 99 100 printf("%d", x.a_text); 101 if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1) 102 goto shread; 103 if (read(io, (char *)0, x.a_text) != x.a_text) 104 goto shread; 105 106 addr = (char *)x.a_text; 107 if (x.a_magic == 0413 || x.a_magic == 0410) 108 while ((int)addr & CLOFSET) 109 *addr++ = 0; 110 printf("+%d", x.a_data); 111 if (read(io, addr, x.a_data) != x.a_data) 112 goto shread; 113 114 addr += x.a_data; 115 printf("+%d", x.a_bss); 116 x.a_bss += 128*512; /* slop */ 117 for (i = 0; i < x.a_bss; i++) 118 *addr++ = 0; 119 120 /* mask high order bits corresponding to relocated system base */ 121 x.a_entry &= 0xfff00000; 122 printf(" start 0x%x\n", x.a_entry); 123 124 if(c=scankbd()) 125 _longjmp(&exception,1); 126 127 i = (*((int (*)()) x.a_entry))(howto, opendev, 0, cyloffset); 128 129 if (i) printf("exit %d\n", i) ; 130 return; 131 shread: 132 printf("Short read\n"); 133 return; 134 } 135