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