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