|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution is only permitted until one year after the first shipment ! 6: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and ! 7: * binary forms are permitted provided that: (1) source distributions retain ! 8: * this entire copyright notice and comment, and (2) distributions including ! 9: * binaries display the following acknowledgement: This product includes ! 10: * software developed by the University of California, Berkeley and its ! 11: * contributors'' in the documentation or other materials provided with the ! 12: * distribution and in all advertising materials mentioning features or use ! 13: * of this software. Neither the name of the University nor the names of ! 14: * its contributors may be used to endorse or promote products derived from ! 15: * this software without specific prior written permission. ! 16: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 19: * ! 20: * @(#)boot.c 7.1 (Berkeley) 5/8/90 ! 21: */ ! 22: ! 23: #include <a.out.h> ! 24: #include "saio.h" ! 25: #include "../sys/reboot.h" ! 26: ! 27: #ifndef INSECURE ! 28: #include "../sys/stat.h" ! 29: struct stat sb; ! 30: #endif ! 31: ! 32: #define B_MAKEDEV(a,u,p,t) \ ! 33: (((a) << B_ADAPTORSHIFT) | ((u) << B_UNITSHIFT) | \ ! 34: ((p) << B_PARTITIONSHIFT) | ((t) << B_TYPESHIFT)) ! 35: ! 36: /* ! 37: * Boot program... arguments in `devtype' and `howto' determine ! 38: * whether boot stops to ask for system name and which device ! 39: * boot comes from. ! 40: */ ! 41: ! 42: /* Types in `devtype' specifying major device */ ! 43: char devname[][2] = { ! 44: 0,0, /* 0 = ct */ ! 45: 0,0, /* 1 = fd */ ! 46: 'r','d', /* 2 = rd */ ! 47: 0,0, /* 3 = sw */ ! 48: 's','d', /* 4 = sd */ ! 49: }; ! 50: #define MAXTYPE (sizeof(devname) / sizeof(devname[0])) ! 51: ! 52: #define UNIX "vmunix" ! 53: char line[100]; ! 54: ! 55: int retry = 0; ! 56: extern char *lowram; ! 57: extern int noconsole; ! 58: extern int howto, devtype; ! 59: ! 60: #define MSUS (0xfffffedc) ! 61: ! 62: char rom2mdev[] = { ! 63: 0, /* 0 - none */ ! 64: 0, /* 1 - none */ ! 65: 0, /* 2 - none */ ! 66: 0, /* 3 - none */ ! 67: 0, /* 4 - none */ ! 68: 0, /* 5 - none */ ! 69: 0, /* 6 - none */ ! 70: 0, /* 7 - none */ ! 71: 0, /* 8 - none */ ! 72: 0, /* 9 - none */ ! 73: 0, /* 10 - none */ ! 74: 0, /* 11 - none */ ! 75: 0, /* 12 - none */ ! 76: 0, /* 13 - none */ ! 77: 4, /* 14 - SCSI disk */ ! 78: 0, /* 15 - none */ ! 79: 2, /* 16 - CS/80 device on HPIB */ ! 80: 2, /* 17 - CS/80 device on HPIB */ ! 81: 0, /* 18 - none */ ! 82: 0, /* 19 - none */ ! 83: 0, /* 20 - none */ ! 84: 0, /* 21 - none */ ! 85: 0, /* 22 - none */ ! 86: 0, /* 23 - none */ ! 87: 0, /* 24 - none */ ! 88: 0, /* 25 - none */ ! 89: 0, /* 26 - none */ ! 90: 0, /* 27 - none */ ! 91: 0, /* 28 - none */ ! 92: 0, /* 29 - none */ ! 93: 0, /* 30 - none */ ! 94: 0, /* 31 - none */ ! 95: }; ! 96: ! 97: main() ! 98: { ! 99: register type, part, unit, io; ! 100: register char *cp; ! 101: ! 102: printf("\nBoot\n"); ! 103: #ifdef JUSTASK ! 104: howto = RB_ASKNAME|RB_SINGLE; ! 105: #else ! 106: type = (devtype >> B_TYPESHIFT) & B_TYPEMASK; ! 107: unit = (devtype >> B_UNITSHIFT) & B_UNITMASK; ! 108: unit += 8 * ((devtype >> B_ADAPTORSHIFT) & B_ADAPTORMASK); ! 109: part = (devtype >> B_PARTITIONSHIFT) & B_PARTITIONMASK; ! 110: if ((howto & RB_ASKNAME) == 0) { ! 111: if ((devtype & B_MAGICMASK) != B_DEVMAGIC) { ! 112: /* ! 113: * we have to map the ROM device type codes ! 114: * to Unix major device numbers. ! 115: */ ! 116: type = rom2mdev[*(char *)MSUS & 0x1f]; ! 117: devtype = (devtype &~ (B_TYPEMASK << B_TYPESHIFT)) ! 118: | (type << B_TYPESHIFT); ! 119: } ! 120: if (type >= 0 && type <= MAXTYPE && devname[type][0]) { ! 121: cp = line; ! 122: *cp++ = devname[type][0]; ! 123: *cp++ = devname[type][1]; ! 124: *cp++ = '('; ! 125: if (unit >= 10) ! 126: *cp++ = unit / 10 + '0'; ! 127: *cp++ = unit % 10 + '0'; ! 128: *cp++ = ','; ! 129: *cp++ = part + '0'; ! 130: *cp++ = ')'; ! 131: strcpy(cp, UNIX); ! 132: } else ! 133: howto = RB_SINGLE|RB_ASKNAME; ! 134: } ! 135: #endif ! 136: for (;;) { ! 137: if (!noconsole && (howto & RB_ASKNAME)) { ! 138: printf(": "); ! 139: gets(line); ! 140: } else ! 141: printf(": %s\n", line); ! 142: io = open(line, 0); ! 143: if (io >= 0) { ! 144: #ifndef INSECURE ! 145: (void) fstat(io, &sb); ! 146: if (sb.st_uid || (sb.st_mode & 2)) { ! 147: printf("non-secure file, will not load\n"); ! 148: howto = RB_SINGLE|RB_ASKNAME; ! 149: continue; ! 150: } ! 151: #endif ! 152: if (howto & RB_ASKNAME) { ! 153: /* ! 154: * Build up devtype register to pass on to ! 155: * booted program. ! 156: */ ! 157: cp = line; ! 158: for (type = 0; type <= MAXTYPE; type++) ! 159: if ((devname[type][0] == cp[0]) && ! 160: (devname[type][1] == cp[1])) ! 161: break; ! 162: if (type <= MAXTYPE) { ! 163: cp += 3; ! 164: unit = *cp++ - '0'; ! 165: if (*cp >= '0' && *cp <= '9') ! 166: unit = unit * 10 + *cp++ - '0'; ! 167: cp++; ! 168: part = atol(cp); ! 169: devtype = B_MAKEDEV(unit >> 3, unit & 7, part, type); ! 170: } ! 171: } ! 172: devtype |= B_DEVMAGIC; ! 173: copyunix(howto, devtype, io); ! 174: close(io); ! 175: howto = RB_SINGLE|RB_ASKNAME; ! 176: } ! 177: bad: ! 178: if (++retry > 2) ! 179: howto = RB_SINGLE|RB_ASKNAME; ! 180: } ! 181: } ! 182: ! 183: /*ARGSUSED*/ ! 184: copyunix(howto, devtype, io) ! 185: register howto; /* d7 contains boot flags */ ! 186: register devtype; /* d6 contains boot device */ ! 187: register io; ! 188: { ! 189: struct exec x; ! 190: register int i; ! 191: register char *load; /* a5 contains load addr for unix */ ! 192: register char *addr; ! 193: ! 194: i = read(io, (char *)&x, sizeof x); ! 195: if (i != sizeof x || ! 196: (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410)) ! 197: _stop("Bad format\n"); ! 198: printf("%d", x.a_text); ! 199: if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1) ! 200: goto shread; ! 201: load = addr = lowram; ! 202: if (read(io, (char *)addr, x.a_text) != x.a_text) ! 203: goto shread; ! 204: addr += x.a_text; ! 205: if (x.a_magic == 0413 || x.a_magic == 0410) ! 206: while ((int)addr & CLOFSET) ! 207: *addr++ = 0; ! 208: printf("+%d", x.a_data); ! 209: if (read(io, addr, x.a_data) != x.a_data) ! 210: goto shread; ! 211: addr += x.a_data; ! 212: printf("+%d", x.a_bss); ! 213: x.a_bss += 128*512; /* slop */ ! 214: for (i = 0; i < x.a_bss; i++) ! 215: *addr++ = 0; ! 216: x.a_entry += (int)lowram; ! 217: printf(" start 0x%x\n", x.a_entry); ! 218: #ifdef __GNUC__ ! 219: asm(" movl %0,d7" : : "m" (howto)); ! 220: asm(" movl %0,d6" : : "m" (devtype)); ! 221: asm(" movl %0,a5" : : "a" (load)); ! 222: #endif ! 223: (*((int (*)()) x.a_entry))(); ! 224: exit(); ! 225: shread: ! 226: _stop("Short read\n"); ! 227: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.