|
|
1.1 ! root 1: /* ! 2: * Ported to boot 386BSD by Julian Elischer ([email protected]) Sept 1992 ! 3: * ! 4: * Mach Operating System ! 5: * Copyright (c) 1992, 1991 Carnegie Mellon University ! 6: * All Rights Reserved. ! 7: * ! 8: * Permission to use, copy, modify and distribute this software and its ! 9: * documentation is hereby granted, provided that both the copyright ! 10: * notice and this permission notice appear in all copies of the ! 11: * software, derivative works or modified versions, and any portions ! 12: * thereof, and that both notices appear in supporting documentation. ! 13: * ! 14: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" ! 15: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR ! 16: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ! 17: * ! 18: * Carnegie Mellon requests users of this software to return to ! 19: * ! 20: * Software Distribution Coordinator or [email protected] ! 21: * School of Computer Science ! 22: * Carnegie Mellon University ! 23: * Pittsburgh PA 15213-3890 ! 24: * ! 25: * any improvements or extensions that they make and grant Carnegie Mellon ! 26: * the rights to redistribute these changes. ! 27: */ ! 28: ! 29: /* ! 30: * HISTORY ! 31: * $Log: version.c,v $ ! 32: * Revision 1.1 1993/03/21 18:08:26 cgd ! 33: * after 0.2.2 "stable" patches applied ! 34: * ! 35: * Revision 2.2 92/04/04 11:34:37 rpd ! 36: * Change date in banner. ! 37: * [92/04/03 16:51:14 rvb] ! 38: * ! 39: * Fix Intel Copyright as per B. Davies authorization. ! 40: * [92/04/03 rvb] ! 41: * From 2.5 version. ! 42: * [92/03/30 mg32] ! 43: * ! 44: */ ! 45: ! 46: /* ! 47: Copyright 1988, 1989, 1990, 1991, 1992 ! 48: by Intel Corporation, Santa Clara, California. ! 49: ! 50: All Rights Reserved ! 51: ! 52: Permission to use, copy, modify, and distribute this software and ! 53: its documentation for any purpose and without fee is hereby ! 54: granted, provided that the above copyright notice appears in all ! 55: copies and that both the copyright notice and this permission notice ! 56: appear in supporting documentation, and that the name of Intel ! 57: not be used in advertising or publicity pertaining to distribution ! 58: of the software without specific, written prior permission. ! 59: ! 60: INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE ! 61: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, ! 62: IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR ! 63: CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM ! 64: LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, ! 65: NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION ! 66: WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ! 67: */ ! 68: ! 69: #include <sys/param.h> ! 70: #include "boot.h" ! 71: #include <a.out.h> ! 72: #include <sys/reboot.h> ! 73: ! 74: ! 75: struct exec head; ! 76: int argv[10], esym; ! 77: char *name; ! 78: char *names[] = { ! 79: "/386bsd", "/386bsd.old", ! 80: "/vmunix", "/vmunix.old" ! 81: }; ! 82: #define NUMNAMES (sizeof(names)/sizeof(char *)) ! 83: ! 84: extern int end; ! 85: boot(drive) ! 86: int drive; ! 87: { ! 88: int loadflags, currname = 0; ! 89: printf("\n>> 386bsd BOOT @ 0x%x: %d/%d k of memory [20/9/92]\n", ! 90: ouraddr, ! 91: argv[7] = memsize(0), ! 92: argv[8] = memsize(1)); ! 93: printf("use options hd(1,...... to boot sd0 when wd0 is also installed\n"); ! 94: gateA20(); ! 95: loadstart: ! 96: /***************************************************************\ ! 97: * As a default set it to the first partition of the first * ! 98: * floppy or hard drive * ! 99: \***************************************************************/ ! 100: part = unit = 0; ! 101: maj = (drive&0x80 ? 0 : 2); /* a good first bet */ ! 102: name = names[currname++]; ! 103: ! 104: loadflags = 0; ! 105: if (currname == NUMNAMES) ! 106: currname = 0; ! 107: getbootdev(&loadflags); ! 108: if (openrd()) { ! 109: printf("Can't find %s\n", name); ! 110: goto loadstart; ! 111: } ! 112: /* if (inode.i_mode&IEXEC) ! 113: loadflags |= RB_KDB; ! 114: */ ! 115: loadprog(loadflags); ! 116: goto loadstart; ! 117: } ! 118: ! 119: loadprog(howto) ! 120: int howto; ! 121: { ! 122: long int startaddr; ! 123: long int addr; /* physical address.. not directly useable */ ! 124: int i; ! 125: static int (*x_entry)() = 0; ! 126: unsigned char tmpbuf[4096]; /* we need to load the first 4k here */ ! 127: ! 128: argv[3] = 0; ! 129: argv[4] = 0; ! 130: read(&head, sizeof(head)); ! 131: if (head.a_magic == 0413 ) ! 132: { ! 133: poff = 4096; ! 134: } ! 135: else ! 136: { ! 137: printf("Invalid format!\n"); ! 138: return; ! 139: } ! 140: ! 141: startaddr = (int)head.a_entry; ! 142: addr = (startaddr & 0x00f00000); /* some MEG boundary */ ! 143: printf("Booting %s(%d,%c)%s @ 0x%x\n" ! 144: , devs[maj] ! 145: , unit ! 146: , 'a'+part ! 147: , name ! 148: , addr); ! 149: if(addr < ouraddr) ! 150: { ! 151: if((addr + head.a_text + head.a_data) > ouraddr) ! 152: { ! 153: printf("kernel will not fit below loader\n"); ! 154: return; ! 155: } ! 156: if((addr + head.a_text + head.a_data + head.a_bss) > 0xa0000) ! 157: { ! 158: printf("kernel too big, won't fit in 640K with bss\n"); ! 159: printf("Only hope is to link the kernel for > 1MB\n"); ! 160: return; ! 161: } ! 162: if((addr + head.a_text + head.a_data + head.a_bss) > ouraddr) ! 163: { ! 164: printf("loader overlaps bss, kernel must bzero\n"); ! 165: } ! 166: } ! 167: printf("text=0x%x", head.a_text); ! 168: /********************************************************/ ! 169: /* LOAD THE TEXT SEGMENT */ ! 170: /* don't clobber the first 4k yet (BIOS NEEDS IT) */ ! 171: /********************************************************/ ! 172: read(tmpbuf,4096); ! 173: addr += 4096; ! 174: xread(addr, head.a_text - 4096); ! 175: addr += head.a_text - 4096; ! 176: ! 177: /********************************************************/ ! 178: /* Load the Initialised data after the text */ ! 179: /********************************************************/ ! 180: while (addr & CLOFSET) ! 181: *(char *)addr++ = 0; ! 182: ! 183: printf(" data=0x%x", head.a_data); ! 184: xread(addr, head.a_data); ! 185: addr += head.a_data; ! 186: ! 187: /********************************************************/ ! 188: /* Skip over the uninitialised data */ ! 189: /* (but clear it) */ ! 190: /********************************************************/ ! 191: printf(" bss=0x%x", head.a_bss); ! 192: if( (addr < ouraddr) && ((addr + head.a_bss) > ouraddr)) ! 193: { ! 194: pbzero(addr,ouraddr - (int)addr); ! 195: } ! 196: else ! 197: { ! 198: pbzero(addr,head.a_bss); ! 199: } ! 200: argv[3] = (addr += head.a_bss); ! 201: ! 202: #ifdef LOADSYMS /* not yet, haven't worked this out yet */ ! 203: if (addr > 0x100000) ! 204: { ! 205: /********************************************************/ ! 206: /*copy in the symbol header */ ! 207: /********************************************************/ ! 208: pcpy(&head.a_syms, addr, sizeof(head.a_syms)); ! 209: addr += sizeof(head.a_syms); ! 210: ! 211: /********************************************************/ ! 212: /* READ in the symbol table */ ! 213: /********************************************************/ ! 214: printf(" symbols=[+0x%x", head.a_syms); ! 215: xread(addr, head.a_syms); ! 216: addr += head.a_syms; ! 217: ! 218: /********************************************************/ ! 219: /* Followed by the next integer (another header) */ ! 220: /* more debug symbols? */ ! 221: /********************************************************/ ! 222: read(&i, sizeof(int)); ! 223: pcpy(&i, addr, sizeof(int)); ! 224: i -= sizeof(int); ! 225: addr += sizeof(int); ! 226: ! 227: ! 228: /********************************************************/ ! 229: /* and that many bytes of (debug symbols?) */ ! 230: /********************************************************/ ! 231: printf("+0x%x]", i); ! 232: xread(addr, i); ! 233: addr += i; ! 234: } ! 235: #endif LOADSYMS ! 236: /********************************************************/ ! 237: /* and note the end address of all this */ ! 238: /********************************************************/ ! 239: ! 240: argv[4] = ((addr+sizeof(int)-1))&~(sizeof(int)-1); ! 241: printf(" total=0x%x",argv[4]); ! 242: ! 243: ! 244: /* ! 245: * We now pass the various bootstrap parameters to the loaded ! 246: * image via the argument list ! 247: * (THIS IS A BIT OF HISTORY FROM MACH.. LEAVE FOR NOW) ! 248: * arg1 = boot flags ! 249: * arg2 = boot device ! 250: * arg3 = start of symbol table (0 if not loaded) ! 251: * arg4 = end of symbol table (0 if not loaded) ! 252: * arg5 = transfer address from image ! 253: * arg6 = transfer address for next image pointer ! 254: */ ! 255: switch(maj) ! 256: { ! 257: case 2: ! 258: printf("\n\nInsert file system floppy \n"); ! 259: getchar(); ! 260: break; ! 261: case 4: ! 262: break; ! 263: } ! 264: argv[1] = howto; ! 265: argv[2] = (MAKEBOOTDEV(maj, 0, 0, unit, part)) ; ! 266: argv[5] = (head.a_entry &= 0xfffffff); ! 267: argv[6] = (int) &x_entry; ! 268: argv[0] = 8; ! 269: /****************************************************************/ ! 270: /* copy that first page and overwrite any BIOS variables */ ! 271: /****************************************************************/ ! 272: printf(" entry point=0x%x \n" ,((int)startaddr) & 0xffffff); ! 273: pcpy(tmpbuf, 0, 4096); ! 274: startprog(((int)startaddr & 0xffffff),argv); ! 275: } ! 276: ! 277: char namebuf[100]; ! 278: getbootdev(howto) ! 279: int *howto; ! 280: { ! 281: char c, *ptr = namebuf; ! 282: printf("Boot: [[[%s(%d,%c)]%s][-s][-a][-d]] :- " ! 283: , devs[maj] ! 284: , unit ! 285: , 'a'+part ! 286: , name); ! 287: if (gets(namebuf)) { ! 288: while (c=*ptr) { ! 289: while (c==' ') ! 290: c = *++ptr; ! 291: if (!c) ! 292: return; ! 293: if (c=='-') ! 294: while ((c = *++ptr) && c!=' ') ! 295: switch (c) { ! 296: case 'a': ! 297: *howto |= RB_ASKNAME; continue; ! 298: case 's': ! 299: *howto |= RB_SINGLE; continue; ! 300: case 'd': ! 301: *howto |= RB_KDB; continue; ! 302: case 'b': ! 303: *howto |= RB_HALT; continue; ! 304: } ! 305: else { ! 306: name = ptr; ! 307: while ((c = *++ptr) && c!=' '); ! 308: if (c) ! 309: *ptr++ = 0; ! 310: } ! 311: } ! 312: } ! 313: } ! 314:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.