|
|
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
1.1.1.2 ! root 31: * boot.c,v
! 32: * Revision 1.8 1993/07/11 12:02:21 andrew
! 33: * Fixes from bde, including support for loading @ any MB boundary (e.g. a
! 34: * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead
! 35: * buffering to speed booting from floppies. Also works with aha174x
! 36: * controllers in enhanced mode.
! 37: *
! 38: * Revision 1.7 1993/06/18 06:50:52 cgd
! 39: * convert magic numbers to network byte order, and attendent changes
! 40: *
! 41: * Revision 1.6 1993/06/14 00:47:08 deraadt
! 42: * *whoops*. The previous commit killed a few important characters of code.
! 43: *
! 44: * Revision 1.5 1993/06/05 22:52:11 cgd
! 45: * make sure kernel is small enough; this is a really weird fix from
! 46: * rod, pk patch #159. the comment is:
! 47: *
! 48: * The +28672 is for memory allocated by locore.s that must fit in the bss!
! 49: *
! 50: * this seems way wrong to me, but i'm not going to fix it in locore right
! 51: * now...
! 52: *
! 53: * Revision 1.4 1993/05/04 10:22:39 deraadt
! 54: * if we timeout asking for kernel name, print a \n before proceeding.
! 55: * Funny how one character can bug ya so much, eh?
! 56: *
! 57: * Revision 1.3 1993/04/28 06:37:58 cgd
! 58: * bsd->netbsd
! 59: *
! 60: * Revision 1.2 1993/04/28 05:32:55 cgd
! 61: * new kernel name is "bsd" also, add "o*" to list of kernels to boot.
! 62: *
! 63: * Revision 1.1 1993/03/21 18:08:26 cgd
1.1 root 64: * after 0.2.2 "stable" patches applied
65: *
66: * Revision 2.2 92/04/04 11:34:37 rpd
1.1.1.2 ! root 67: *
! 68: * 93/07/03 bde
! 69: * Write first 4096 bytes to load address, not always to address 0.
! 70: *
! 71: * 93/06/29 bde
! 72: * Don't clobber BIOS variables.
! 73: *
1.1 root 74: * Change date in banner.
75: * [92/04/03 16:51:14 rvb]
76: *
77: * Fix Intel Copyright as per B. Davies authorization.
78: * [92/04/03 rvb]
79: * From 2.5 version.
80: * [92/03/30 mg32]
81: *
82: */
83:
84: /*
85: Copyright 1988, 1989, 1990, 1991, 1992
86: by Intel Corporation, Santa Clara, California.
87:
88: All Rights Reserved
89:
90: Permission to use, copy, modify, and distribute this software and
91: its documentation for any purpose and without fee is hereby
92: granted, provided that the above copyright notice appears in all
93: copies and that both the copyright notice and this permission notice
94: appear in supporting documentation, and that the name of Intel
95: not be used in advertising or publicity pertaining to distribution
96: of the software without specific, written prior permission.
97:
98: INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
99: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
100: IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
101: CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
102: LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
103: NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
104: WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
105: */
106:
107: #include <sys/param.h>
108: #include "boot.h"
109: #include <a.out.h>
110: #include <sys/reboot.h>
111:
112: struct exec head;
113: int argv[10], esym;
114: char *name;
115: char *names[] = {
1.1.1.2 ! root 116: "/netbsd", "/onetbsd", "/netbsd.old",
! 117: "/386bsd", "/o386bsd", "/386bsd.old",
! 118: "/vmunix", "/ovmunix", "/vmunix.old"
1.1 root 119: };
120: #define NUMNAMES (sizeof(names)/sizeof(char *))
121:
122: extern int end;
123: boot(drive)
124: int drive;
125: {
126: int loadflags, currname = 0;
1.1.1.2 ! root 127: char *t;
! 128:
! 129: printf("\n>> NetBSD BOOT @ 0x%x: %d/%d k of memory [%s]\n",
1.1 root 130: ouraddr,
131: argv[7] = memsize(0),
1.1.1.2 ! root 132: argv[8] = memsize(1),
! 133: "1.8");
1.1 root 134: printf("use options hd(1,...... to boot sd0 when wd0 is also installed\n");
135: gateA20();
136: loadstart:
137: /***************************************************************\
138: * As a default set it to the first partition of the first *
139: * floppy or hard drive *
140: \***************************************************************/
141: part = unit = 0;
142: maj = (drive&0x80 ? 0 : 2); /* a good first bet */
143: name = names[currname++];
144:
145: loadflags = 0;
146: if (currname == NUMNAMES)
147: currname = 0;
148: getbootdev(&loadflags);
149: if (openrd()) {
150: printf("Can't find %s\n", name);
151: goto loadstart;
152: }
153: /* if (inode.i_mode&IEXEC)
154: loadflags |= RB_KDB;
155: */
156: loadprog(loadflags);
157: goto loadstart;
158: }
159:
160: loadprog(howto)
161: int howto;
162: {
163: long int startaddr;
164: long int addr; /* physical address.. not directly useable */
1.1.1.2 ! root 165: long int addr0;
1.1 root 166: int i;
167: static int (*x_entry)() = 0;
168: unsigned char tmpbuf[4096]; /* we need to load the first 4k here */
169:
170: argv[3] = 0;
171: argv[4] = 0;
172: read(&head, sizeof(head));
1.1.1.2 ! root 173: if ( N_BADMAG(head)) {
1.1 root 174: printf("Invalid format!\n");
175: return;
176: }
177:
1.1.1.2 ! root 178: poff = N_TXTOFF(head);
! 179: /*if(poff==0)
! 180: poff = 32;*/
! 181:
1.1 root 182: startaddr = (int)head.a_entry;
183: addr = (startaddr & 0x00f00000); /* some MEG boundary */
1.1.1.2 ! root 184: addr0 = addr;
1.1 root 185: printf("Booting %s(%d,%c)%s @ 0x%x\n"
186: , devs[maj]
187: , unit
188: , 'a'+part
189: , name
190: , addr);
191: if(addr < ouraddr)
192: {
193: if((addr + head.a_text + head.a_data) > ouraddr)
194: {
195: printf("kernel will not fit below loader\n");
196: return;
197: }
1.1.1.2 ! root 198: /*
! 199: * The +28672 is for memory allocated by locore.s that must
! 200: * fit in the bss! (XXX - cgd)
! 201: */
! 202: if((addr + head.a_text + head.a_data + head.a_bss + 28672) > 0xa0000)
1.1 root 203: {
204: printf("kernel too big, won't fit in 640K with bss\n");
205: printf("Only hope is to link the kernel for > 1MB\n");
206: return;
207: }
208: if((addr + head.a_text + head.a_data + head.a_bss) > ouraddr)
209: {
210: printf("loader overlaps bss, kernel must bzero\n");
211: }
212: }
1.1.1.2 ! root 213: printf("text=0x%x ", head.a_text);
1.1 root 214: /********************************************************/
215: /* LOAD THE TEXT SEGMENT */
216: /* don't clobber the first 4k yet (BIOS NEEDS IT) */
217: /********************************************************/
218: read(tmpbuf,4096);
219: addr += 4096;
220: xread(addr, head.a_text - 4096);
221: addr += head.a_text - 4096;
222:
223: /********************************************************/
224: /* Load the Initialised data after the text */
225: /********************************************************/
226: while (addr & CLOFSET)
227: *(char *)addr++ = 0;
228:
1.1.1.2 ! root 229: printf("data=0x%x ", head.a_data);
1.1 root 230: xread(addr, head.a_data);
231: addr += head.a_data;
232:
233: /********************************************************/
234: /* Skip over the uninitialised data */
235: /* (but clear it) */
236: /********************************************************/
1.1.1.2 ! root 237: printf("bss=0x%x ", head.a_bss);
1.1 root 238: if( (addr < ouraddr) && ((addr + head.a_bss) > ouraddr))
239: {
240: pbzero(addr,ouraddr - (int)addr);
241: }
242: else
243: {
244: pbzero(addr,head.a_bss);
245: }
246: argv[3] = (addr += head.a_bss);
247:
248: #ifdef LOADSYMS /* not yet, haven't worked this out yet */
249: if (addr > 0x100000)
250: {
251: /********************************************************/
252: /*copy in the symbol header */
253: /********************************************************/
254: pcpy(&head.a_syms, addr, sizeof(head.a_syms));
255: addr += sizeof(head.a_syms);
256:
257: /********************************************************/
258: /* READ in the symbol table */
259: /********************************************************/
1.1.1.2 ! root 260: printf("symbols=[+0x%x", head.a_syms);
1.1 root 261: xread(addr, head.a_syms);
262: addr += head.a_syms;
263:
264: /********************************************************/
265: /* Followed by the next integer (another header) */
266: /* more debug symbols? */
267: /********************************************************/
268: read(&i, sizeof(int));
269: pcpy(&i, addr, sizeof(int));
270: i -= sizeof(int);
271: addr += sizeof(int);
272:
273:
274: /********************************************************/
275: /* and that many bytes of (debug symbols?) */
276: /********************************************************/
1.1.1.2 ! root 277: printf("+0x%x] ", i);
1.1 root 278: xread(addr, i);
279: addr += i;
280: }
281: #endif LOADSYMS
282: /********************************************************/
283: /* and note the end address of all this */
284: /********************************************************/
285:
286: argv[4] = ((addr+sizeof(int)-1))&~(sizeof(int)-1);
1.1.1.2 ! root 287: printf("total=0x%x ",argv[4]);
1.1 root 288:
289:
290: /*
291: * We now pass the various bootstrap parameters to the loaded
292: * image via the argument list
293: * (THIS IS A BIT OF HISTORY FROM MACH.. LEAVE FOR NOW)
294: * arg1 = boot flags
295: * arg2 = boot device
296: * arg3 = start of symbol table (0 if not loaded)
297: * arg4 = end of symbol table (0 if not loaded)
298: * arg5 = transfer address from image
299: * arg6 = transfer address for next image pointer
300: */
301: switch(maj)
302: {
303: case 2:
304: printf("\n\nInsert file system floppy \n");
305: getchar();
306: break;
307: case 4:
308: break;
309: }
310: argv[1] = howto;
311: argv[2] = (MAKEBOOTDEV(maj, 0, 0, unit, part)) ;
312: argv[5] = (head.a_entry &= 0xfffffff);
313: argv[6] = (int) &x_entry;
314: argv[0] = 8;
315: /****************************************************************/
316: /* copy that first page and overwrite any BIOS variables */
317: /****************************************************************/
1.1.1.2 ! root 318: printf("entry point=0x%x\n" ,((int)startaddr) & 0xffffff);
! 319: /* Under no circumstances overwrite precious BIOS variables! */
! 320: pcpy(tmpbuf, addr0, 0x400);
! 321: pcpy(tmpbuf + 0x500, addr0 + 0x500, 4096 - 0x500);
1.1 root 322: startprog(((int)startaddr & 0xffffff),argv);
323: }
324:
325: char namebuf[100];
326: getbootdev(howto)
327: int *howto;
328: {
329: char c, *ptr = namebuf;
330: printf("Boot: [[[%s(%d,%c)]%s][-s][-a][-d]] :- "
331: , devs[maj]
332: , unit
333: , 'a'+part
334: , name);
335: if (gets(namebuf)) {
336: while (c=*ptr) {
337: while (c==' ')
338: c = *++ptr;
339: if (!c)
340: return;
341: if (c=='-')
342: while ((c = *++ptr) && c!=' ')
343: switch (c) {
344: case 'a':
345: *howto |= RB_ASKNAME; continue;
346: case 's':
347: *howto |= RB_SINGLE; continue;
348: case 'd':
349: *howto |= RB_KDB; continue;
350: case 'b':
351: *howto |= RB_HALT; continue;
352: }
353: else {
354: name = ptr;
355: while ((c = *++ptr) && c!=' ');
356: if (c)
357: *ptr++ = 0;
358: }
359: }
1.1.1.2 ! root 360: } else
! 361: printf("\n");
1.1 root 362: }
363:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.