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