1 /* boot.c 7.5 90/12/16 */ 2 3 #include "../include/mtpr.h" 4 5 #include "sys/param.h" 6 #include "sys/time.h" 7 #include "sys/vm.h" 8 #include "sys/reboot.h" 9 #include "stand/saio.h" 10 11 #include <a.out.h> 12 13 /* 14 * Boot program... arguments passed in r10 and r11 determine 15 * whether boot stops to ask for system name and which device 16 * boot comes from. 17 */ 18 19 #define DEV_DFLT 1 /* vd/dk */ 20 /*#define DEV_DFLT 2 /* hd */ 21 22 char line[100]; 23 24 extern unsigned opendev; 25 extern unsigned bootdev; 26 27 main() 28 { 29 register char *cp; /* skip r12 */ 30 register u_int howto, devtype; /* howto=r11, devtype=r10 */ 31 int io = 0, retry, type; 32 33 #ifdef lint 34 howto = 0; devtype = 0; 35 #endif 36 if ((devtype & B_MAGICMASK) != B_DEVMAGIC) 37 devtype = DEV_DFLT << B_TYPESHIFT; /* unit, partition 0 */ 38 bootdev = devtype; 39 #ifdef JUSTASK 40 howto = RB_ASKNAME|RB_SINGLE; 41 #else 42 if ((howto & RB_ASKNAME) == 0) { 43 type = (devtype >> B_TYPESHIFT) & B_TYPEMASK; 44 if ((unsigned)type < ndevs && devsw[type].dv_name) 45 strcpy(line, UNIX); 46 else 47 howto |= RB_SINGLE|RB_ASKNAME; 48 } 49 #endif 50 for (retry = 0;;) { 51 if (io >= 0) 52 printf("\nBoot"); 53 if (howto & RB_ASKNAME) { 54 printf(": "); 55 gets(line); 56 if (line[0] == 0) { 57 strcpy(line, UNIX); 58 printf(": %s\n", line); 59 } 60 } else 61 printf(": %s\n", line); 62 io = open(line, 0); 63 if (io >= 0) { 64 copyunix(howto, opendev, io); 65 close(io); 66 howto |= RB_SINGLE|RB_ASKNAME; 67 } 68 if (++retry > 2) 69 howto |= RB_SINGLE|RB_ASKNAME; 70 } 71 } 72 73 /*ARGSUSED*/ 74 copyunix(howto, devtype, io) 75 register io, howto, devtype; /* NOTE ORDER */ 76 { 77 register int esym; /* must be r9 */ 78 register int i; 79 register char *addr; 80 struct exec x; 81 82 if (read(io, (char *)&x, sizeof(x)) != sizeof(x) || N_BADMAG(x)) { 83 printf("bad magic #\n"); 84 return; 85 } 86 printf("%ld", x.a_text); 87 if (x.a_magic == ZMAGIC && lseek(io, 0x400, 0) == -1) 88 goto shread; 89 if (read(io, (char *)RELOC, x.a_text) != x.a_text) 90 goto shread; 91 addr = (char *)(x.a_text + RELOC); 92 if (x.a_magic == ZMAGIC || x.a_magic == NMAGIC) 93 while ((int)addr & CLOFSET) 94 *addr++ = 0; 95 printf("+%ld", x.a_data); 96 if (read(io, addr, x.a_data) != x.a_data) 97 goto shread; 98 addr += x.a_data; 99 printf("+%ld", x.a_bss); 100 if (howto & RB_KDB && x.a_syms) { 101 for (i = 0; i < x.a_bss; i++) 102 *addr++ = 0; 103 *(int *)addr = x.a_syms; /* symbol table size */ 104 addr += sizeof (int); 105 printf("[+%ld", x.a_syms); 106 if (read(io, addr, x.a_syms) != x.a_syms) 107 goto shread; 108 addr += x.a_syms; 109 if (read(io, addr, sizeof (int)) != sizeof (int)) 110 goto shread; 111 i = *(int *)addr - sizeof (int); /* string table size */ 112 addr += sizeof (int); 113 printf("+%d]", i); 114 if (read(io, addr, i) != i) 115 goto shread; 116 addr += i; 117 esym = roundup((int)addr, sizeof (int)); 118 x.a_bss = 0; 119 } else 120 howto &= ~RB_KDB; 121 x.a_bss += 32*1024; /* slop */ 122 for (i = 0; i < x.a_bss; i++) 123 *addr++ = 0; 124 x.a_entry &= 0x1fffffff; 125 printf(" start 0x%lx\n", x.a_entry); 126 mtpr(PADC, 0); /* Purge data cache */ 127 mtpr(PACC, 0); /* Purge code cache */ 128 mtpr(DCR, 1); /* Enable data cache */ 129 (*((int (*)()) x.a_entry))(); 130 return; 131 shread: 132 printf("short read\n"); 133 return; 134 } 135