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
32 Copyright 1988, 1989, 1990, 1991, 1992
\r
33 by Intel Corporation, Santa Clara, California.
\r
37 Permission to use, copy, modify, and distribute this software and
\r
38 its documentation for any purpose and without fee is hereby
\r
39 granted, provided that the above copyright notice appears in all
\r
40 copies and that both the copyright notice and this permission notice
\r
41 appear in supporting documentation, and that the name of Intel
\r
42 not be used in advertising or publicity pertaining to distribution
\r
43 of the software without specific, written prior permission.
\r
45 INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
\r
46 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
\r
47 IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
\r
48 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
\r
49 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
\r
50 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
\r
51 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
\r
55 #include <process.h>
\r
58 #include "bootinfo.h"
\r
59 #include "protmod.h"
\r
66 int openrd(char *kernel);
\r
67 void ufs_read(char *buffer, long count);
\r
68 void xread(unsigned long addr, long size);
\r
70 static struct exec head;
\r
71 static long argv[10];
\r
72 static char buf[__LDPGSZ];
\r
73 static long int startaddr;
\r
75 void pbzero(unsigned long addr, unsigned long size)
\r
79 memset(buf, 0, __LDPGSZ);
\r
81 s = size > __LDPGSZ ? __LDPGSZ : size;
\r
82 pm_copy(buf, addr, s);
\r
88 static long loadprog(long *hsize)
\r
90 long addr; /* physical address.. not directly useable */
\r
94 static int (*x_entry)() = 0;
\r
96 ufs_read(&head, (long) sizeof(head));
\r
97 if (N_BADMAG(head)) {
\r
98 printf("Invalid format!\n");
\r
102 startaddr = (long)head.a_entry;
\r
103 addr = (startaddr & 0x00ffffffl); /* some MEG boundary */
\r
104 printf("Booting @ 0x%lx\n", addr);
\r
105 if(addr < 0x100000l)
\r
107 printf("Start address too low!\n");
\r
111 poff = N_TXTOFF(head)+head.a_text+head.a_data+head.a_syms;
\r
112 ufs_read((void *)&i, sizeof(long));
\r
113 *hsize = head.a_text+head.a_data+head.a_bss;
\r
114 *hsize = (*hsize+NBPG-1)&~(NBPG-1);
\r
115 *hsize += i+4+head.a_syms;
\r
116 addr=hmaddress=get_high_memory(*hsize);
\r
118 printf("Sorry, can't allocate enough memory!\n");
\r
122 poff = N_TXTOFF(head);
\r
124 /********************************************************/
\r
125 /* LOAD THE TEXT SEGMENT */
\r
126 /********************************************************/
\r
127 printf("text=0x%lx ", head.a_text);
\r
128 xread(addr, head.a_text);
\r
129 addr += head.a_text;
\r
131 /********************************************************/
\r
132 /* Load the Initialised data after the text */
\r
133 /********************************************************/
\r
134 while (addr & CLOFSET)
\r
135 pm_copy("\0", addr++, 1);
\r
137 printf("data=0x%lx ", head.a_data);
\r
138 xread(addr, head.a_data);
\r
139 addr += head.a_data;
\r
141 /********************************************************/
\r
142 /* Skip over the uninitialised data */
\r
143 /* (but clear it) */
\r
144 /********************************************************/
\r
145 printf("bss=0x%lx ", head.a_bss);
\r
146 pbzero(addr, head.a_bss);
\r
147 addr += head.a_bss;
\r
149 /* Pad to a page boundary. */
\r
150 pad = (unsigned long)(addr-hmaddress+(startaddr & 0x00ffffffl)) % NBPG;
\r
155 bootinfo.bi_symtab = addr-hmaddress+(startaddr & 0x00ffffffl);
\r
157 /********************************************************/
\r
158 /* Copy the symbol table size */
\r
159 /********************************************************/
\r
160 pm_copy((char *)&head.a_syms, addr, sizeof(head.a_syms));
\r
161 addr += sizeof(head.a_syms);
\r
163 /********************************************************/
\r
164 /* Load the symbol table */
\r
165 /********************************************************/
\r
166 printf("symbols=[+0x%lx+0x%lx+0x%lx", pad, (long) sizeof(head.a_syms),
\r
167 (long) head.a_syms);
\r
168 xread(addr, head.a_syms);
\r
169 addr += head.a_syms;
\r
171 /********************************************************/
\r
172 /* Load the string table size */
\r
173 /********************************************************/
\r
174 ufs_read((void *)&i, sizeof(long));
\r
175 pm_copy((char *)&i, addr, sizeof(long));
\r
177 addr += sizeof(long);
\r
179 /********************************************************/
\r
180 /* Load the string table */
\r
181 /********************************************************/
\r
182 printf("+0x%x+0x%lx] ", sizeof(long), i);
\r
186 bootinfo.bi_esymtab = addr-hmaddress+(startaddr & 0x00ffffffl);
\r
189 * For backwards compatibility, use the previously-unused adaptor
\r
190 * and controller bitfields to hold the slice number.
\r
192 printf("total=0x%lx entry point=0x%lx\n",
\r
193 addr-hmaddress+(startaddr & 0x00ffffffl),
\r
194 startaddr & 0x00ffffffl);
\r
199 void bsdboot(int drive, long loadflags, char *kernel)
\r
201 long hmaddress, size, bootdev;
\r
203 /***************************************************************\
\r
204 * As a default set it to the first partition of the first *
\r
205 * floppy or hard drive *
\r
206 \***************************************************************/
\r
208 maj = (drive&0x80 ? 0 : 2); /* a good first bet */
\r
210 if (openrd(kernel)) {
\r
211 printf("Can't find %s\n", kernel);
\r
214 hmaddress = loadprog(&size);
\r
215 bootdev = MAKEBOOTDEV(maj, (slice >> 4), slice & 0xf, unit, part);
\r
216 startprog(hmaddress, size, ((long)startaddr & 0xffffffl),
\r
217 loadflags | RB_BOOTINFO, bootdev);
\r