2 * Mach Operating System
\r
3 * Copyright (c) 1992, 1991 Carnegie Mellon University
\r
4 * All Rights Reserved.
\r
6 * Permission to use, copy, modify and distribute this software and its
\r
7 * documentation is hereby granted, provided that both the copyright
\r
8 * notice and this permission notice appear in all copies of the
\r
9 * software, derivative works or modified versions, and any portions
\r
10 * thereof, and that both notices appear in supporting documentation.
\r
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
\r
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
\r
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
\r
16 * Carnegie Mellon requests users of this software to return to
\r
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
\r
19 * School of Computer Science
\r
20 * Carnegie Mellon University
\r
21 * Pittsburgh PA 15213-3890
\r
23 * any improvements or extensions that they make and grant Carnegie Mellon
\r
24 * the rights to redistribute these changes.
\r
26 * from: Mach, [92/04/03 16:51:14 rvb]
\r
27 * $FreeBSD: src/sys/i386/boot/dosboot/boot.c,v 1.5 1999/08/28 00:43:19 peter Exp $
\r
28 * $DragonFly: src/sys/platform/pc32/boot/dosboot/Attic/boot.c,v 1.2 2003/06/17 04:28:34 dillon Exp $
\r
33 Copyright 1988, 1989, 1990, 1991, 1992
\r
34 by Intel Corporation, Santa Clara, California.
\r
38 Permission to use, copy, modify, and distribute this software and
\r
39 its documentation for any purpose and without fee is hereby
\r
40 granted, provided that the above copyright notice appears in all
\r
41 copies and that both the copyright notice and this permission notice
\r
42 appear in supporting documentation, and that the name of Intel
\r
43 not be used in advertising or publicity pertaining to distribution
\r
44 of the software without specific, written prior permission.
\r
46 INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
\r
47 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
\r
48 IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
\r
49 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
\r
50 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
\r
51 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
\r
52 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
\r
56 #include <process.h>
\r
59 #include "bootinfo.h"
\r
60 #include "protmod.h"
\r
67 int openrd(char *kernel);
\r
68 void ufs_read(char *buffer, long count);
\r
69 void xread(unsigned long addr, long size);
\r
71 static struct exec head;
\r
72 static long argv[10];
\r
73 static char buf[__LDPGSZ];
\r
74 static long int startaddr;
\r
76 void pbzero(unsigned long addr, unsigned long size)
\r
80 memset(buf, 0, __LDPGSZ);
\r
82 s = size > __LDPGSZ ? __LDPGSZ : size;
\r
83 pm_copy(buf, addr, s);
\r
89 static long loadprog(long *hsize)
\r
91 long addr; /* physical address.. not directly useable */
\r
95 static int (*x_entry)() = 0;
\r
97 ufs_read(&head, (long) sizeof(head));
\r
98 if (N_BADMAG(head)) {
\r
99 printf("Invalid format!\n");
\r
103 startaddr = (long)head.a_entry;
\r
104 addr = (startaddr & 0x00ffffffl); /* some MEG boundary */
\r
105 printf("Booting @ 0x%lx\n", addr);
\r
106 if(addr < 0x100000l)
\r
108 printf("Start address too low!\n");
\r
112 poff = N_TXTOFF(head)+head.a_text+head.a_data+head.a_syms;
\r
113 ufs_read((void *)&i, sizeof(long));
\r
114 *hsize = head.a_text+head.a_data+head.a_bss;
\r
115 *hsize = (*hsize+NBPG-1)&~(NBPG-1);
\r
116 *hsize += i+4+head.a_syms;
\r
117 addr=hmaddress=get_high_memory(*hsize);
\r
119 printf("Sorry, can't allocate enough memory!\n");
\r
123 poff = N_TXTOFF(head);
\r
125 /********************************************************/
\r
126 /* LOAD THE TEXT SEGMENT */
\r
127 /********************************************************/
\r
128 printf("text=0x%lx ", head.a_text);
\r
129 xread(addr, head.a_text);
\r
130 addr += head.a_text;
\r
132 /********************************************************/
\r
133 /* Load the Initialised data after the text */
\r
134 /********************************************************/
\r
135 while (addr & CLOFSET)
\r
136 pm_copy("\0", addr++, 1);
\r
138 printf("data=0x%lx ", head.a_data);
\r
139 xread(addr, head.a_data);
\r
140 addr += head.a_data;
\r
142 /********************************************************/
\r
143 /* Skip over the uninitialised data */
\r
144 /* (but clear it) */
\r
145 /********************************************************/
\r
146 printf("bss=0x%lx ", head.a_bss);
\r
147 pbzero(addr, head.a_bss);
\r
148 addr += head.a_bss;
\r
150 /* Pad to a page boundary. */
\r
151 pad = (unsigned long)(addr-hmaddress+(startaddr & 0x00ffffffl)) % NBPG;
\r
156 bootinfo.bi_symtab = addr-hmaddress+(startaddr & 0x00ffffffl);
\r
158 /********************************************************/
\r
159 /* Copy the symbol table size */
\r
160 /********************************************************/
\r
161 pm_copy((char *)&head.a_syms, addr, sizeof(head.a_syms));
\r
162 addr += sizeof(head.a_syms);
\r
164 /********************************************************/
\r
165 /* Load the symbol table */
\r
166 /********************************************************/
\r
167 printf("symbols=[+0x%lx+0x%lx+0x%lx", pad, (long) sizeof(head.a_syms),
\r
168 (long) head.a_syms);
\r
169 xread(addr, head.a_syms);
\r
170 addr += head.a_syms;
\r
172 /********************************************************/
\r
173 /* Load the string table size */
\r
174 /********************************************************/
\r
175 ufs_read((void *)&i, sizeof(long));
\r
176 pm_copy((char *)&i, addr, sizeof(long));
\r
178 addr += sizeof(long);
\r
180 /********************************************************/
\r
181 /* Load the string table */
\r
182 /********************************************************/
\r
183 printf("+0x%x+0x%lx] ", sizeof(long), i);
\r
187 bootinfo.bi_esymtab = addr-hmaddress+(startaddr & 0x00ffffffl);
\r
190 * For backwards compatibility, use the previously-unused adaptor
\r
191 * and controller bitfields to hold the slice number.
\r
193 printf("total=0x%lx entry point=0x%lx\n",
\r
194 addr-hmaddress+(startaddr & 0x00ffffffl),
\r
195 startaddr & 0x00ffffffl);
\r
200 void bsdboot(int drive, long loadflags, char *kernel)
\r
202 long hmaddress, size, bootdev;
\r
204 /***************************************************************\
\r
205 * As a default set it to the first partition of the first *
\r
206 * floppy or hard drive *
\r
207 \***************************************************************/
\r
209 maj = (drive&0x80 ? 0 : 2); /* a good first bet */
\r
211 if (openrd(kernel)) {
\r
212 printf("Can't find %s\n", kernel);
\r
215 hmaddress = loadprog(&size);
\r
216 bootdev = MAKEBOOTDEV(maj, (slice >> 4), slice & 0xf, unit, part);
\r
217 startprog(hmaddress, size, ((long)startaddr & 0xffffffl),
\r
218 loadflags | RB_BOOTINFO, bootdev);
\r