|
|
1.1 ! root 1: /* boot.c 4.6 81/12/01 */ ! 2: ! 3: #include <sys/param.h> ! 4: #include <sys/ino.h> ! 5: #include <sys/inode.h> ! 6: #include <sys/filsys.h> ! 7: #include <sys/dir.h> ! 8: #include <sys/vm.h> ! 9: #include <a.out.h> ! 10: #include "saio.h" ! 11: #include <sys/reboot.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: /* Types in r10 specifying major device */ ! 20: /* these are set by boot block, and should agree with stand/conf.c ! 21: * and dev/conf.c ! 22: */ ! 23: char devname[][2] = { ! 24: 'h','p', /* 0 = hp */ ! 25: 0,0, /* 1 = ht */ ! 26: 'u','p', /* 2 = up */ ! 27: 'h','k', /* 3 = hk */ ! 28: 0,0, /* 4 = sw */ ! 29: 0,0, /* 5 = tm */ ! 30: 0,0, /* 6 = ts */ ! 31: 'r','a', /* 7 = ra */ ! 32: 's', 'a', /* 8 = sa (ra with 1k blocks) */ ! 33: 'u', 't', /* 9 = ut */ ! 34: }; ! 35: ! 36: char line[100] = "xx(0,0)unix"; ! 37: ! 38: int retry = 0; ! 39: ! 40: main() ! 41: { ! 42: register howto, devtype; /* howto=r11, devtype=r10 */ ! 43: int io; ! 44: ! 45: #ifdef lint ! 46: howto = 0; devtype = 0; ! 47: #endif ! 48: printf("\nBoot\n"); ! 49: #ifdef JUSTASK ! 50: howto = RB_ASKNAME|RB_SINGLE; ! 51: #else ! 52: if ((howto&RB_ASKNAME)==0) { ! 53: if (devtype>=0 && devtype<sizeof(devname)/2 ! 54: && devname[devtype][0]) { ! 55: line[0] = devname[devtype][0]; ! 56: line[1] = devname[devtype][1]; ! 57: } else ! 58: howto = RB_SINGLE|RB_ASKNAME; ! 59: } ! 60: #endif ! 61: for (;;) { ! 62: if (howto & RB_ASKNAME) { ! 63: printf(": "); ! 64: gets(line); ! 65: } else ! 66: printf(": %s\n", line); ! 67: io = open(line, 0); ! 68: if (io >= 0) ! 69: copyunix(howto, io); ! 70: if (++retry > 2) ! 71: howto = RB_SINGLE|RB_ASKNAME; ! 72: } ! 73: } ! 74: ! 75: /* ! 76: * read in a file and execute it ! 77: * handles 0407 and 0410 files ! 78: * anything else is assumed to be headerless image ! 79: */ ! 80: ! 81: #define BADMAGIC 0 /* anything not a valid magic number */ ! 82: #define HUGE 1000000L /* big enough to reach EOF */ ! 83: ! 84: /*ARGSUSED*/ ! 85: copyunix(howto, io) ! 86: register howto, io; ! 87: { ! 88: struct exec x; ! 89: register int i; ! 90: register char *addr; ! 91: ! 92: addr = (char *)0; ! 93: if (read(io, (char *)&x, sizeof(x)) != sizeof(x) ! 94: || (x.a_magic != 0410 && x.a_magic != 0407)) { ! 95: /* ! 96: * not a.out. `exec' is part of text ! 97: */ ! 98: *(struct exec *)addr = x; ! 99: x.a_magic = BADMAGIC; ! 100: x.a_text = HUGE; ! 101: x.a_data = 0; ! 102: x.a_bss = 0; ! 103: x.a_entry = 0; ! 104: addr += sizeof(x); ! 105: } ! 106: printf("%d", x.a_text); ! 107: if (read(io, addr, x.a_text) != x.a_text ! 108: && x.a_magic != BADMAGIC) ! 109: goto shread; ! 110: addr += x.a_text; ! 111: if (x.a_magic == 0410) ! 112: while ((int)addr & CLOFSET) ! 113: *addr++ = 0; ! 114: printf("+%d", x.a_data); ! 115: if (read(io, addr, x.a_data) != x.a_data) ! 116: goto shread; ! 117: addr += x.a_data; ! 118: printf("+%d", x.a_bss); ! 119: x.a_bss += 128*512; /* slop */ ! 120: for (i = 0; i < x.a_bss; i++) ! 121: *addr++ = 0; ! 122: x.a_entry &= 0x7fffffff; ! 123: printf(" start 0x%x\n", x.a_entry); ! 124: close(io); ! 125: (*((int (*)()) x.a_entry))(); ! 126: exit(); ! 127: shread: ! 128: _stop("Short read\n"); ! 129: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.