1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | *␊ |
6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License").␉You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | *␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | *␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | ␊ |
25 | /*␊ |
26 | * Mach Operating System␊ |
27 | * Copyright (c) 1990 Carnegie-Mellon University␊ |
28 | * Copyright (c) 1989 Carnegie-Mellon University␊ |
29 | * All rights reserved.␉ The CMU software License Agreement specifies␊ |
30 | * the terms and conditions for use and redistribution.␊ |
31 | *␊ |
32 | * INTEL CORPORATION PROPRIETARY INFORMATION␊ |
33 | *␊ |
34 | * This software is supplied under the terms of a license agreement or␊ |
35 | * nondisclosure agreement with Intel Corporation and may not be copied␊ |
36 | * nor disclosed except in accordance with the terms of that agreement.␊ |
37 | *␊ |
38 | *␉Copyright 1988, 1989 by Intel Corporation␊ |
39 | *␊ |
40 | *␊ |
41 | * Copyright 1993 NeXT Computer, Inc.␊ |
42 | * All rights reserved.␊ |
43 | *␊ |
44 | * Completely reworked by Sam Streeper (sam_s@NeXT.com)␊ |
45 | * Reworked again by Curtis Galloway (galloway@NeXT.com)␊ |
46 | */␊ |
47 | ␊ |
48 | #include "boot.h"␊ |
49 | #include "bootstruct.h"␊ |
50 | #include "fake_efi.h"␊ |
51 | #include "sl.h"␊ |
52 | #include "libsa.h"␊ |
53 | #include "ramdisk.h"␊ |
54 | #include "gui.h"␊ |
55 | #include "platform.h"␊ |
56 | #include "modules.h"␊ |
57 | #include "device_tree.h"␊ |
58 | ␊ |
59 | #ifndef DEBUG_BOOT2␊ |
60 | ␉#define DEBUG_BOOT2 0␊ |
61 | #endif␊ |
62 | ␊ |
63 | #ifndef DEBUG_INTERRUPTS␊ |
64 | ␉#define DEBUG_INTERRUPTS 0␊ |
65 | #endif␊ |
66 | ␊ |
67 | #if DEBUG_BOOT2␊ |
68 | ␉#define DBG(x...)␉printf(x)␊ |
69 | #else␊ |
70 | ␉#define DBG(x...)␉msglog(x)␊ |
71 | #endif␊ |
72 | ␊ |
73 | /*␊ |
74 | * How long to wait (in seconds) to load the␊ |
75 | * kernel after displaying the "boot:" prompt.␊ |
76 | */␊ |
77 | #define kBootErrorTimeout 5␊ |
78 | ␊ |
79 | bool␉␉gOverrideKernel;␊ |
80 | bool␉␉gEnableCDROMRescan;␊ |
81 | bool␉␉gScanSingleDrive;␊ |
82 | bool␉␉useGUI;␊ |
83 | ␊ |
84 | #if DEBUG_INTERRUPTS␊ |
85 | ␉static int␉interruptsAvailable = 0;␊ |
86 | #endif␊ |
87 | ␊ |
88 | static bool␉gUnloadPXEOnExit = false;␊ |
89 | ␊ |
90 | static char␉gCacheNameAdler[64 + 256];␊ |
91 | char␉␉*gPlatformName = gCacheNameAdler;␊ |
92 | ␊ |
93 | char␉␉gRootDevice[ROOT_DEVICE_SIZE];␊ |
94 | char␉␉gMKextName[512];␊ |
95 | int␉␉bvCount = 0;␊ |
96 | int␉␉gDeviceCount = 0;␊ |
97 | //int␉␉menucount = 0;␊ |
98 | long␉␉gBootMode; /* defaults to 0 == kBootModeNormal */␊ |
99 | ␊ |
100 | BVRef␉␉bvr;␊ |
101 | BVRef␉␉menuBVR;␊ |
102 | BVRef␉␉bvChain;␊ |
103 | ␊ |
104 | static unsigned long␉Adler32(unsigned char *buffer, long length);␊ |
105 | //static void␉␉␉selectBiosDevice(void);␊ |
106 | ␊ |
107 | /** options.c **/␊ |
108 | extern char *msgbuf;␊ |
109 | void showTextBuffer(char *buf, int size);␊ |
110 | ␊ |
111 | //==========================================================================␊ |
112 | // Zero the BSS.␊ |
113 | ␊ |
114 | static void zeroBSS(void)␊ |
115 | {␊ |
116 | ␉extern char bss_start __asm("section$start$__DATA$__bss");␊ |
117 | ␉extern char bss_end __asm("section$end$__DATA$__bss");␊ |
118 | ␉extern char common_start __asm("section$start$__DATA$__common");␊ |
119 | ␉extern char common_end __asm("section$end$__DATA$__common");␊ |
120 | ␊ |
121 | ␉bzero(&bss_start, (&bss_end - &bss_start));␊ |
122 | ␉bzero(&common_start, (&common_end - &common_start));␊ |
123 | }␊ |
124 | ␊ |
125 | //==========================================================================␊ |
126 | // Malloc error function␊ |
127 | ␊ |
128 | static void malloc_error(char *addr, size_t size, const char *file, int line)␊ |
129 | {␊ |
130 | ␉stop("\nMemory allocation error! Addr: 0x%x, Size: 0x%x, File: %s, Line: %d\n",␊ |
131 | ␉␉␉␉␉␉␉␉␉ (unsigned)addr, (unsigned)size, file, line);␊ |
132 | }␊ |
133 | ␊ |
134 | //==========================================================================␊ |
135 | //Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.␊ |
136 | //␊ |
137 | void initialize_runtime(void)␊ |
138 | {␊ |
139 | ␉zeroBSS();␊ |
140 | ␉malloc_init(0, 0, 0, malloc_error);␊ |
141 | }␊ |
142 | ␊ |
143 | //==========================================================================␊ |
144 | // ExecKernel - Load the kernel image (mach-o) and jump to its entry point.␊ |
145 | ␊ |
146 | static int ExecKernel(void *binary)␊ |
147 | {␊ |
148 | ␉int␉␉␉ret;␊ |
149 | ␉entry_t␉␉kernelEntry;␊ |
150 | ␊ |
151 | ␉bootArgs->kaddr = bootArgs->ksize = 0;␊ |
152 | ␉execute_hook("ExecKernel", (void *)binary, NULL, NULL, NULL);␊ |
153 | ␊ |
154 | ␉ret = DecodeKernel(binary,␊ |
155 | ␉␉␉␉␉ &kernelEntry,␊ |
156 | ␉␉␉␉␉ (char **) &bootArgs->kaddr,␊ |
157 | ␉␉␉␉␉ (int *)&bootArgs->ksize);␊ |
158 | ␊ |
159 | ␉if ( ret != 0 )␊ |
160 | ␉{␊ |
161 | ␉␉printf("Decoding kernel failed.\n");␊ |
162 | ␉␉pause();␊ |
163 | ␉␉return ret;␊ |
164 | ␉}␊ |
165 | ␊ |
166 | ␉// Reserve space for boot args␊ |
167 | ␉reserveKernBootStruct();␊ |
168 | ␊ |
169 | ␉// Notify modules that the kernel has been decoded␊ |
170 | ␉execute_hook("DecodedKernel", (void *)binary, (void *)bootArgs->kaddr, (void *)bootArgs->ksize, NULL);␊ |
171 | ␊ |
172 | ␉setupFakeEfi();␊ |
173 | ␊ |
174 | ␉// Load boot drivers from the specifed root path.␊ |
175 | ␉//if (!gHaveKernelCache)␊ |
176 | ␉{␊ |
177 | ␉␉LoadDrivers("/");␊ |
178 | ␉}␊ |
179 | ␊ |
180 | ␉execute_hook("DriversLoaded", (void *)binary, NULL, NULL, NULL);␊ |
181 | ␊ |
182 | ␉clearActivityIndicator();␊ |
183 | ␊ |
184 | ␉if (gErrors)␊ |
185 | ␉{␊ |
186 | ␉␉printf("Errors encountered while starting up the computer.\n");␊ |
187 | ␉␉printf("Pausing %d seconds...\n", kBootErrorTimeout);␊ |
188 | ␉␉sleep(kBootErrorTimeout);␊ |
189 | ␉}␊ |
190 | ␊ |
191 | ␉md0Ramdisk();␊ |
192 | ␊ |
193 | ␉// Cleanup the PXE base code.␊ |
194 | ␊ |
195 | ␉if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit )␊ |
196 | ␉{␊ |
197 | ␉␉if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )␊ |
198 | ␉␉{␊ |
199 | ␉␉␉printf("nbpUnloadBaseCode error %d\n", (int)ret);␊ |
200 | ␉␉␉sleep(2);␊ |
201 | ␉␉}␊ |
202 | ␉}␊ |
203 | ␊ |
204 | ␉bool dummyVal;␊ |
205 | ␉if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->chameleonConfig) && dummyVal)␊ |
206 | ␉{␊ |
207 | ␉␉showTextBuffer(msgbuf, strlen(msgbuf));␊ |
208 | ␉}␊ |
209 | ␊ |
210 | ␉usb_loop();␊ |
211 | ␊ |
212 | #if DEBUG␊ |
213 | ␉if (interruptsAvailable) ShowInterruptCounters();␊ |
214 | #endif␊ |
215 | ␊ |
216 | ␉// If we were in text mode, switch to graphics mode.␊ |
217 | ␉// This will draw the boot graphics unless we are in␊ |
218 | ␉// verbose mode.␊ |
219 | ␉if (gVerboseMode)␊ |
220 | ␉{␊ |
221 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
222 | ␉}␊ |
223 | ␉else␊ |
224 | ␉{␊ |
225 | ␉␉drawBootGraphics();␊ |
226 | ␉}␊ |
227 | ␊ |
228 | ␉DBG("Starting Darwin/%s [%s]\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64", gDarwinBuildVerStr);␊ |
229 | ␉DBG("Boot Args: %s\n", bootArgs->CommandLine);␊ |
230 | ␊ |
231 | ␉setupBooterLog();␊ |
232 | ␊ |
233 | ␉finalizeBootStruct();␊ |
234 | ␊ |
235 | ␉// Jump to kernel's entry point. There's no going back now.␊ |
236 | ␉if ( MacOSVerCurrent < MacOSVer2Int("10.7") )␊ |
237 | ␉{␊ |
238 | ␉␉// Notify modules that the kernel is about to be started␊ |
239 | ␉␉execute_hook("Kernel Start", (void *)kernelEntry, (void *)bootArgsLegacy, NULL, NULL);␊ |
240 | ␊ |
241 | ␉␉startprog( kernelEntry, bootArgsLegacy );␊ |
242 | ␉}␊ |
243 | ␉else␊ |
244 | ␉{␊ |
245 | ␉␉// Notify modules that the kernel is about to be started␊ |
246 | ␉␉execute_hook("Kernel Start", (void *)kernelEntry, (void *)bootArgs, NULL, NULL);␊ |
247 | ␊ |
248 | ␉␉// Masking out so that Lion doesn't doublefault␊ |
249 | ␉␉outb(0x21, 0xff);␉/* Maskout all interrupts Pic1 */␊ |
250 | ␉␉outb(0xa1, 0xff);␉/* Maskout all interrupts Pic2 */␊ |
251 | ␊ |
252 | ␉␉startprog( kernelEntry, bootArgs );␊ |
253 | ␉}␊ |
254 | ␊ |
255 | ␉// Not reached␊ |
256 | ␉__builtin_unreachable();␊ |
257 | }␊ |
258 | ␊ |
259 | //==========================================================================␊ |
260 | // LoadKernelCache - Try to load Kernel Cache.␊ |
261 | // return the length of the loaded cache file or -1 on error␊ |
262 | long LoadKernelCache(const char *cacheFile, void **binary)␊ |
263 | {␊ |
264 | ␉char␉␉kernelCacheFile[512];␊ |
265 | ␉char␉␉kernelCachePath[512];␊ |
266 | ␉long␉␉flags, ret=-1;␊ |
267 | ␉unsigned long␉adler32 = 0;␊ |
268 | ␉u_int32_t time, cachetime, kerneltime, exttime;␊ |
269 | ␊ |
270 | ␉if((gBootMode & kBootModeSafe) != 0)␊ |
271 | ␉{␊ |
272 | ␉␉DBG("Kernel Cache ignored.\n");␊ |
273 | ␉␉return -1;␊ |
274 | ␉}␊ |
275 | ␊ |
276 | ␉// Use specify kernel cache file if not empty␊ |
277 | ␉if (cacheFile[0] != 0)␊ |
278 | ␉{␊ |
279 | ␉␉strlcpy(kernelCacheFile, cacheFile, sizeof(kernelCacheFile));␊ |
280 | ␉␉verbose("Specified kernel cache file path: %s\n", cacheFile);␊ |
281 | ␉}␊ |
282 | ␉else␊ |
283 | ␉{␊ |
284 | ␉␉// Leopard prelink kernel cache file␊ |
285 | ␉␉if ( MacOSVerCurrent >= MacOSVer2Int("10.4") && MacOSVerCurrent <= MacOSVer2Int("10.5") ) // OSX is 10.4 or 10.5␊ |
286 | ␉␉{␊ |
287 | ␉␉␉// Reset cache name.␊ |
288 | ␉␉␉bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);␊ |
289 | ␉␉␉snprintf(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64, "%s,%s", gRootDevice, bootInfo->bootFile);␊ |
290 | ␉␉␉adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));␊ |
291 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32);␊ |
292 | ␉␉␉verbose("Reseted kernel cache file path: %s\n", kernelCacheFile);␊ |
293 | ␊ |
294 | ␉␉}␊ |
295 | ␉␉// Snow Leopard prelink kernel cache file␊ |
296 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.6") && MacOSVerCurrent < MacOSVer2Int("10.7") )␊ |
297 | ␉␉{␊ |
298 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "kernelcache_%s",␊ |
299 | ␉␉␉␉(archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64");␊ |
300 | ␊ |
301 | ␉␉␉int␉␉lnam = strlen(kernelCacheFile) + 9; //with adler32␊ |
302 | ␉␉␉char␉␉*name;␊ |
303 | ␉␉␉u_int32_t␉prev_time = 0;␊ |
304 | ␊ |
305 | ␉␉␉struct dirstuff *cacheDir = opendir(kDefaultCachePathSnow);␊ |
306 | ␊ |
307 | ␉␉␉/* TODO: handle error? */␊ |
308 | ␉␉␉if (cacheDir)␊ |
309 | ␉␉␉{␊ |
310 | ␉␉␉␉while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)␊ |
311 | ␉␉␉␉{␊ |
312 | ␉␉␉␉␉if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time␊ |
313 | ␉␉␉␉␉␉&& strstr(name, kernelCacheFile) && (name[lnam] != '.'))␊ |
314 | ␉␉␉␉␉{␊ |
315 | ␉␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s%s", kDefaultCachePathSnow, name);␊ |
316 | ␉␉␉␉␉␉prev_time = time;␊ |
317 | ␉␉␉␉␉}␊ |
318 | ␉␉␉␉}␊ |
319 | ␉␉␉␉verbose("Kernel Cache file path (Mac OS X 10.6): %s\n", kernelCacheFile);␊ |
320 | ␉␉␉}␊ |
321 | ␉␉␉closedir(cacheDir);␊ |
322 | ␉␉}␊ |
323 | ␉␉else␊ |
324 | ␉␉{␊ |
325 | ␉␉␉// Lion, Mountain Lion, Mavericks, Yosemite and El Capitan prelink kernel cache file␊ |
326 | ␉␉␉// for 10.7 10.8 10.9 10.10 10.11␊ |
327 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);␊ |
328 | ␉␉␉verbose("Kernel Cache file path (Mac OS X 10.7 and newer): %s\n", kernelCacheFile);␊ |
329 | ␊ |
330 | ␉␉}␊ |
331 | ␉}␊ |
332 | ␊ |
333 | ␉// Check if the kernel cache file exists␊ |
334 | ␉ret = -1;␊ |
335 | ␊ |
336 | ␉if (gBootVolume->flags & kBVFlagBooter)␊ |
337 | ␉{␊ |
338 | ␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.P/%s", kernelCacheFile);␊ |
339 | ␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
340 | ␊ |
341 | ␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
342 | ␉␉{␊ |
343 | ␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.R/%s", kernelCacheFile);␊ |
344 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
345 | ␊ |
346 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
347 | ␉␉␉{␊ |
348 | ␉␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.S/%s", kernelCacheFile);␊ |
349 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
350 | ␊ |
351 | ␉␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
352 | ␉␉␉␉{␊ |
353 | ␉␉␉␉␉strncpy(kernelCachePath, "/com.apple.recovery.boot/kernelcache", sizeof(kernelCachePath) );␊ |
354 | ␉␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
355 | ␊ |
356 | ␉␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
357 | ␉␉␉␉␉{␊ |
358 | ␉␉␉␉␉␉ret = -1;␊ |
359 | ␉␉␉␉␉}␊ |
360 | ␉␉␉␉}␊ |
361 | ␉␉␉}␊ |
362 | ␉␉}␊ |
363 | ␉}␊ |
364 | ␊ |
365 | ␉// If not found, use the original kernel cache path.␊ |
366 | ␉if (ret == -1)␊ |
367 | ␉{␊ |
368 | ␉␉strlcpy(kernelCachePath, kernelCacheFile, sizeof(kernelCachePath));␊ |
369 | ␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
370 | ␊ |
371 | ␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
372 | ␉␉{␊ |
373 | ␉␉␉ret = -1;␊ |
374 | ␉␉}␊ |
375 | ␉}␊ |
376 | ␊ |
377 | ␉// Exit if kernel cache file wasn't found␊ |
378 | ␉if (ret == -1)␊ |
379 | ␉{␊ |
380 | ␉␉DBG("No Kernel Cache File '%s' found\n", kernelCacheFile);␊ |
381 | ␉␉return -1;␊ |
382 | ␉}␊ |
383 | ␊ |
384 | ␉// Check if the kernel cache file is more recent (mtime)␊ |
385 | ␉// than the kernel file or the S/L/E directory␊ |
386 | ␉ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);␊ |
387 | ␊ |
388 | ␉// Check if the kernel file is more recent than the cache file␊ |
389 | ␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat) && (kerneltime > cachetime))␊ |
390 | ␉{␊ |
391 | ␉␉DBG("Kernel file '%s' is more recent than Kernel Cache '%s'! Ignoring Kernel Cache.\n", bootInfo->bootFile, kernelCacheFile);␊ |
392 | ␉␉return -1;␊ |
393 | ␉}␊ |
394 | ␊ |
395 | ␉ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);␊ |
396 | ␊ |
397 | ␉// Check if the S/L/E directory time is more recent than the cache file␊ |
398 | ␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory) && (exttime > cachetime))␊ |
399 | ␉{␊ |
400 | ␉␉DBG("Folder '/System/Library/Extensions' is more recent than Kernel Cache file '%s'! Ignoring Kernel Cache.\n", kernelCacheFile);␊ |
401 | ␉␉return -1;␊ |
402 | ␉}␊ |
403 | ␊ |
404 | ␉// Since the kernel cache file exists and is the most recent try to load it␊ |
405 | ␉DBG("Loading Kernel Cache from: '%s%s' (%s)\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name);␊ |
406 | ␊ |
407 | ␉ret = LoadThinFatFile(kernelCachePath, binary);␊ |
408 | ␉return ret; // ret contain the length of the binary␊ |
409 | }␊ |
410 | ␊ |
411 | //==========================================================================␊ |
412 | // This is the entrypoint from real-mode which functions exactly as it did␊ |
413 | // before. Multiboot does its own runtime initialization, does some of its␊ |
414 | // own things, and then calls common_boot.␊ |
415 | void boot(int biosdev)␊ |
416 | {␊ |
417 | ␉initialize_runtime();␊ |
418 | ␉// Enable A20 gate before accessing memory above 1Mb.␊ |
419 | ␉enableA20();␊ |
420 | ␉common_boot(biosdev);␊ |
421 | }␊ |
422 | ␊ |
423 | //==========================================================================␊ |
424 | // The 'main' function for the booter. Called by boot0 when booting␊ |
425 | // from a block device, or by the network booter.␊ |
426 | //␊ |
427 | // arguments:␊ |
428 | //␉ biosdev - Value passed from boot1/NBP to specify the device␊ |
429 | //␉␉␉ that the booter was loaded from.␊ |
430 | //␊ |
431 | // If biosdev is kBIOSDevNetwork, then this function will return if␊ |
432 | // booting was unsuccessful. This allows the PXE firmware to try the␊ |
433 | // next boot device on its list.␊ |
434 | void common_boot(int biosdev)␊ |
435 | {␊ |
436 | ␉bool␉ ␉␉quiet;␊ |
437 | ␉bool␉ ␉␉firstRun = true;␊ |
438 | ␉bool␉ ␉␉instantMenu;␊ |
439 | ␉bool␉ ␉␉rescanPrompt;␊ |
440 | ␉int␉␉␉status;␊ |
441 | ␉unsigned int␉␉allowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;␊ |
442 | ␉unsigned int␉␉denyBVFlags = kBVFlagEFISystem;␊ |
443 | ␊ |
444 | ␉// Set reminder to unload the PXE base code. Neglect to unload␊ |
445 | ␉// the base code will result in a hang or kernel panic.␊ |
446 | ␉gUnloadPXEOnExit = true;␊ |
447 | ␊ |
448 | ␉// Record the device that the booter was loaded from.␊ |
449 | ␉gBIOSDev = biosdev & kBIOSDevMask;␊ |
450 | ␊ |
451 | ␉// Initialize boot-log␊ |
452 | ␉initBooterLog();␊ |
453 | ␊ |
454 | #if DEBUG_INTERRUPTS␊ |
455 | ␉// Enable interrupts␊ |
456 | ␉interruptsAvailable = SetupInterrupts();␊ |
457 | ␉if (interruptsAvailable)␊ |
458 | ␉{␊ |
459 | ␉␉EnableInterrupts();␊ |
460 | ␉}␊ |
461 | #endif␊ |
462 | ␊ |
463 | ␉// Initialize boot info structure.␊ |
464 | ␉initKernBootStruct();␊ |
465 | ␊ |
466 | ␉// Setup VGA text mode.␊ |
467 | ␉// Not sure if it is safe to call setVideoMode() before the␊ |
468 | ␉// config table has been loaded. Call video_mode() instead.␊ |
469 | #if DEBUG␊ |
470 | ␉printf("before video_mode\n");␊ |
471 | #endif␊ |
472 | ␉video_mode( 2 ); // 80x25 mono text mode.␊ |
473 | #if DEBUG␊ |
474 | ␉printf("after video_mode\n");␊ |
475 | #endif␊ |
476 | ␊ |
477 | ␉// Scan and record the system's hardware information.␊ |
478 | ␉scan_platform();␊ |
479 | ␊ |
480 | ␉// First get info for boot volume.␊ |
481 | ␉scanBootVolumes(gBIOSDev, 0);␊ |
482 | ␉bvChain = getBVChainForBIOSDev(gBIOSDev);␊ |
483 | ␉setBootGlobals(bvChain);␊ |
484 | ␊ |
485 | ␉// Load boot.plist config file␊ |
486 | ␉status = loadChameleonConfig(&bootInfo->chameleonConfig, bvChain);␊ |
487 | ␊ |
488 | ␉if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet)␊ |
489 | ␉{␊ |
490 | ␉␉gBootMode |= kBootModeQuiet;␊ |
491 | ␉}␊ |
492 | ␊ |
493 | ␉// Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config␊ |
494 | ␉if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->chameleonConfig) && instantMenu)␊ |
495 | ␉{␊ |
496 | ␉␉firstRun = false;␊ |
497 | ␉}␊ |
498 | ␊ |
499 | ␉// Loading preboot ramdisk if exists.␊ |
500 | ␉loadPrebootRAMDisk();␊ |
501 | ␊ |
502 | ␉// Disable rescan option by default␊ |
503 | ␉gEnableCDROMRescan = false;␊ |
504 | ␊ |
505 | ␉// Enable it with Rescan=y in system config␊ |
506 | ␉if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->chameleonConfig)␉&& gEnableCDROMRescan)␊ |
507 | ␉{␊ |
508 | ␉␉gEnableCDROMRescan = true;␊ |
509 | ␉}␊ |
510 | ␊ |
511 | ␉// Disable rescanPrompt option by default␊ |
512 | ␉rescanPrompt = false;␊ |
513 | ␊ |
514 | ␉// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.␊ |
515 | ␉if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev))␊ |
516 | ␉{␊ |
517 | ␉␉gEnableCDROMRescan = promptForRescanOption();␊ |
518 | ␉}␊ |
519 | ␊ |
520 | ␉// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.␊ |
521 | ␉if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->chameleonConfig) && gScanSingleDrive)␊ |
522 | ␉{␊ |
523 | ␉␉gScanSingleDrive = true;␊ |
524 | ␉}␊ |
525 | ␊ |
526 | ␉// Create a list of partitions on device(s).␊ |
527 | ␉if (gScanSingleDrive)␊ |
528 | ␉{␊ |
529 | ␉␉scanBootVolumes(gBIOSDev, &bvCount);␊ |
530 | ␉}␊ |
531 | ␉else␊ |
532 | ␉{␊ |
533 | ␉␉scanDisks(gBIOSDev, &bvCount);␊ |
534 | ␉}␊ |
535 | ␊ |
536 | ␉// Create a separated bvr chain using the specified filters.␊ |
537 | ␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
538 | ␊ |
539 | ␉gBootVolume = selectBootVolume(bvChain);␊ |
540 | ␊ |
541 | ␉// Intialize module system␊ |
542 | ␉init_module_system();␊ |
543 | ␊ |
544 | #if DEBUG␊ |
545 | ␉printf("Default: %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",␊ |
546 | ␉␉gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);␊ |
547 | ␉printf("bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",␊ |
548 | ␉␉gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);␊ |
549 | ␉getchar();␊ |
550 | #endif␊ |
551 | ␊ |
552 | ␉useGUI = true;␊ |
553 | ␉// Override useGUI default␊ |
554 | ␉getBoolForKey(kGUIKey, &useGUI, &bootInfo->chameleonConfig);␊ |
555 | ␉if (useGUI && initGUI())␊ |
556 | ␉{␊ |
557 | ␉␉// initGUI() returned with an error, disabling GUI.␊ |
558 | ␉␉useGUI = false;␊ |
559 | ␉}␊ |
560 | ␊ |
561 | ␉setBootGlobals(bvChain);␊ |
562 | ␊ |
563 | ␉// Parse args, load and start kernel.␊ |
564 | ␉while (1)␊ |
565 | ␉{␊ |
566 | ␉␉bool␉␉tryresume, tryresumedefault, forceresume;␊ |
567 | ␉␉bool␉␉useKernelCache = true; // by default try to use the prelinked kernel␊ |
568 | ␉␉const char␉*val;␊ |
569 | ␉␉int␉␉␉len, ret = -1;␊ |
570 | ␉␉long␉␉flags;␊ |
571 | ␉␉u_int32_t␉sleeptime, time;␊ |
572 | ␉␉void␉␉*binary = (void *)kLoadAddr;␊ |
573 | ␊ |
574 | ␉␉char␉␉bootFile[sizeof(bootInfo->bootFile)];␊ |
575 | ␉␉char␉␉bootFilePath[512];␊ |
576 | ␉␉char␉␉kernelCacheFile[512];␊ |
577 | ␊ |
578 | ␉␉// Initialize globals.␊ |
579 | ␉␉sysConfigValid = false;␊ |
580 | ␉␉gErrors␉␉ = false;␊ |
581 | ␊ |
582 | ␉␉status = getBootOptions(firstRun);␊ |
583 | ␉␉firstRun = false;␊ |
584 | ␉␉if (status == -1) continue;␊ |
585 | ␊ |
586 | ␉␉status = processBootOptions();␊ |
587 | ␉␉// Status == 1 means to chainboot␊ |
588 | ␉␉if ( status ==␉1 ) break;␊ |
589 | ␉␉// Status == -1 means that the config file couldn't be loaded or that gBootVolume is NULL␊ |
590 | ␉␉if ( status == -1 )␊ |
591 | ␉␉{␊ |
592 | ␉␉␉// gBootVolume == NULL usually means the user hit escape.␊ |
593 | ␉␉␉if (gBootVolume == NULL)␊ |
594 | ␉␉␉{␊ |
595 | ␉␉␉␉freeFilteredBVChain(bvChain);␊ |
596 | ␊ |
597 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
598 | ␉␉␉␉␉rescanBIOSDevice(gBIOSDev);␊ |
599 | ␊ |
600 | ␉␉␉␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
601 | ␉␉␉␉setBootGlobals(bvChain);␊ |
602 | ␉␉␉␉setupDeviceList(&bootInfo->themeConfig);␊ |
603 | ␉␉␉}␊ |
604 | ␉␉␉continue;␊ |
605 | ␉␉}␊ |
606 | ␊ |
607 | ␉␉// Other status (e.g. 0) means that we should proceed with boot.␊ |
608 | ␊ |
609 | ␉␉// Turn off any GUI elements␊ |
610 | ␉␉if ( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
611 | ␉␉{␊ |
612 | ␉␉␉gui.devicelist.draw = false;␊ |
613 | ␉␉␉gui.bootprompt.draw = false;␊ |
614 | ␉␉␉gui.menu.draw = false;␊ |
615 | ␉␉␉gui.infobox.draw = false;␊ |
616 | ␉␉␉gui.logo.draw = false;␊ |
617 | ␉␉␉drawBackground();␊ |
618 | ␉␉␉updateVRAM();␊ |
619 | ␉␉}␊ |
620 | ␊ |
621 | ␉␉if (platformCPUFeature(CPU_FEATURE_EM64T))␊ |
622 | ␉␉{␊ |
623 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
624 | ␉␉}␊ |
625 | ␉␉else␊ |
626 | ␉␉{␊ |
627 | ␉␉␉archCpuType = CPU_TYPE_I386;␊ |
628 | ␉␉}␊ |
629 | ␊ |
630 | ␉␉if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig))␊ |
631 | ␉␉{␊ |
632 | ␉␉␉if (strncmp(val, "x86_64", sizeof("x86_64") ) == 0)␊ |
633 | ␉␉␉{␊ |
634 | ␉␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
635 | ␉␉␉}␊ |
636 | ␉␉␉else if (strncmp(val, "i386", sizeof("i386") ) == 0)␊ |
637 | ␉␉␉{␊ |
638 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
639 | ␉␉␉}␊ |
640 | ␉␉␉else␊ |
641 | ␉␉␉{␊ |
642 | ␉␉␉␉DBG("Incorrect parameter for option 'arch =' , please use x86_64 or i386\n");␊ |
643 | ␉␉␉}␊ |
644 | ␉␉}␊ |
645 | ␊ |
646 | ␉␉if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig))␊ |
647 | ␉␉{␊ |
648 | ␉␉␉if (strncmp(val, "i386", sizeof("i386") ) == 0)␊ |
649 | ␉␉␉{␊ |
650 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
651 | ␉␉␉}␊ |
652 | ␉␉}␊ |
653 | ␊ |
654 | ␉␉// Notify modules that we are attempting to boot␊ |
655 | ␉␉execute_hook("PreBoot", NULL, NULL, NULL, NULL);␊ |
656 | ␊ |
657 | ␉␉if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig))␊ |
658 | ␉␉{␊ |
659 | ␉␉␉tryresume = true;␊ |
660 | ␉␉␉tryresumedefault = true;␊ |
661 | ␉␉}␊ |
662 | ␉␉else␊ |
663 | ␉␉{␊ |
664 | ␉␉␉tryresumedefault = false;␊ |
665 | ␉␉}␊ |
666 | ␊ |
667 | ␉␉if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig))␊ |
668 | ␉␉{␊ |
669 | ␉␉␉forceresume = false;␊ |
670 | ␉␉}␊ |
671 | ␊ |
672 | ␉␉if (forceresume)␊ |
673 | ␉␉{␊ |
674 | ␉␉␉tryresume = true;␊ |
675 | ␉␉␉tryresumedefault = false;␊ |
676 | ␉␉}␊ |
677 | ␊ |
678 | ␉␉while (tryresume)␊ |
679 | ␉␉{␊ |
680 | ␉␉␉const char *tmp;␊ |
681 | ␉␉␉BVRef bvr;␊ |
682 | ␉␉␉if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->chameleonConfig))␊ |
683 | ␉␉␉␉val = "/private/var/vm/sleepimage";␊ |
684 | ␊ |
685 | ␉␉␉// Do this first to be sure that root volume is mounted␊ |
686 | ␉␉␉ret = GetFileInfo(0, val, &flags, &sleeptime);␊ |
687 | ␊ |
688 | ␉␉␉if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)␊ |
689 | ␉␉␉␉break;␊ |
690 | ␊ |
691 | ␉␉␉// Can't check if it was hibernation Wake=y is required␊ |
692 | ␉␉␉if (bvr->modTime == 0 && tryresumedefault)␊ |
693 | ␉␉␉␉break;␊ |
694 | ␊ |
695 | ␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
696 | ␉␉␉␉break;␊ |
697 | ␊ |
698 | ␉␉␉if (!forceresume && ((sleeptime+3)<bvr->modTime))␊ |
699 | ␉␉␉{␊ |
700 | #if DEBUG␊ |
701 | ␉␉␉␉printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",␊ |
702 | ␉␉␉␉␉␉bvr->modTime-sleeptime);␊ |
703 | #endif␊ |
704 | ␉␉␉␉break;␊ |
705 | ␉␉␉}␊ |
706 | ␊ |
707 | ␉␉␉HibernateBoot((char *)val);␊ |
708 | ␉␉␉break;␊ |
709 | ␉␉}␊ |
710 | ␊ |
711 | ␉␉getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);␊ |
712 | ␉␉if (useKernelCache)␊ |
713 | ␉␉{␊ |
714 | ␉␉␉do␊ |
715 | ␉␉␉{␊ |
716 | ␉␉␉␉// Determine the name of the Kernel Cache␊ |
717 | ␉␉␉␉if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))␊ |
718 | ␉␉␉␉{␊ |
719 | ␉␉␉␉␉if (val[0] == '\\')␊ |
720 | ␉␉␉␉␉{␊ |
721 | ␉␉␉␉␉␉len--;␊ |
722 | ␉␉␉␉␉␉val++;␊ |
723 | ␉␉␉␉␉}␊ |
724 | ␉␉␉␉␉/* FIXME: check len vs sizeof(kernelCacheFile) */␊ |
725 | ␉␉␉␉␉strlcpy(kernelCacheFile, val, len + 1);␊ |
726 | ␉␉␉␉}␊ |
727 | ␉␉␉␉else␊ |
728 | ␉␉␉␉{␊ |
729 | ␉␉␉␉␉kernelCacheFile[0] = 0; // Use default kernel cache file␊ |
730 | ␉␉␉␉}␊ |
731 | ␊ |
732 | ␉␉␉␉if (gOverrideKernel && kernelCacheFile[0] == 0)␊ |
733 | ␉␉␉␉{␊ |
734 | ␉␉␉␉␉DBG("Using a non default kernel (%s) without specifying 'Kernel Cache' path, KernelCache will not be used\n", bootInfo->bootFile);␊ |
735 | ␉␉␉␉␉useKernelCache = false;␊ |
736 | ␉␉␉␉␉break;␊ |
737 | ␉␉␉␉}␊ |
738 | ␊ |
739 | ␉␉␉␉if (gMKextName[0] != 0)␊ |
740 | ␉␉␉␉{␊ |
741 | ␉␉␉␉␉DBG("Using a specific MKext Cache (%s), KernelCache will not be used\n", gMKextName);␊ |
742 | ␉␉␉␉␉useKernelCache = false;␊ |
743 | ␉␉␉␉␉break;␊ |
744 | ␉␉␉␉}␊ |
745 | ␊ |
746 | ␉␉␉␉if (gBootFileType != kBlockDeviceType)␊ |
747 | ␉␉␉␉{␊ |
748 | ␉␉␉␉␉useKernelCache = false;␊ |
749 | ␉␉␉␉}␊ |
750 | ␊ |
751 | ␉␉␉} while(0);␊ |
752 | ␉␉}␊ |
753 | ␉␉else␊ |
754 | ␉␉{␊ |
755 | ␉␉␉DBG("Kernel Cache using disabled by user.\n");␊ |
756 | ␉␉}␊ |
757 | ␊ |
758 | ␉␉do␊ |
759 | ␉␉{␊ |
760 | ␉␉␉if (useKernelCache)␊ |
761 | ␉␉␉{␊ |
762 | ␉␉␉␉ret = LoadKernelCache(kernelCacheFile, &binary);␊ |
763 | ␉␉␉␉if (ret >= 0)␊ |
764 | ␉␉␉␉{␊ |
765 | ␉␉␉␉␉break;␊ |
766 | ␉␉␉␉}␊ |
767 | ␉␉␉}␊ |
768 | ␊ |
769 | ␉␉␉bool bootFileWithDevice = false;␊ |
770 | ␉␉␉// Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel␊ |
771 | ␉␉␉if (strncmp(bootInfo->bootFile, "bt(", sizeof("bt(") ) == 0 ||␊ |
772 | ␉␉␉␉strncmp(bootInfo->bootFile, "hd(", sizeof("hd(") ) == 0 ||␊ |
773 | ␉␉␉␉strncmp(bootInfo->bootFile, "rd(", sizeof("rd(") ) == 0)␊ |
774 | ␉␉␉{␊ |
775 | ␉␉␉␉bootFileWithDevice = true;␊ |
776 | ␉␉␉}␊ |
777 | ␊ |
778 | ␉␉␉// bootFile must start with a / if it not start with a device name␊ |
779 | ␉␉␉if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/')␊ |
780 | ␉␉␉{␊ |
781 | ␉␉␉␉if ( !YOSEMITE || !ELCAPITAN ) //Is not Yosemite 10.10 or El Capitan 10.11␊ |
782 | ␉␉␉␉{␊ |
783 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading /␊ |
784 | ␉␉␉␉}␊ |
785 | ␉␉␉␉else␊ |
786 | ␉␉␉␉{␊ |
787 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), kDefaultKernelPathForYos"%s", bootInfo->bootFile); // Yosemite or El Capitan␊ |
788 | ␉␉␉␉}␊ |
789 | ␉␉␉}␊ |
790 | ␉␉␉else␊ |
791 | ␉␉␉{␊ |
792 | ␉␉␉␉strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile));␊ |
793 | ␉␉␉}␊ |
794 | ␊ |
795 | ␉␉␉// Try to load kernel image from alternate locations on boot helper partitions.␊ |
796 | ␉␉␉ret = -1;␊ |
797 | ␉␉␉if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice)␊ |
798 | ␉␉␉{␊ |
799 | ␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.P%s", bootFile);␊ |
800 | ␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
801 | ␉␉␉␉if (ret == -1)␊ |
802 | ␉␉␉␉{␊ |
803 | ␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.R%s", bootFile);␊ |
804 | ␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
805 | ␉␉␉␉␉if (ret == -1)␊ |
806 | ␉␉␉␉␉{␊ |
807 | ␉␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.S%s", bootFile);␊ |
808 | ␉␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
809 | ␉␉␉␉␉}␊ |
810 | ␉␉␉␉}␊ |
811 | ␉␉␉}␊ |
812 | ␉␉␉if (ret == -1)␊ |
813 | ␉␉␉{␊ |
814 | ␉␉␉␉// No alternate location found, using the original kernel image path.␊ |
815 | ␉␉␉␉strlcpy(bootFilePath, bootFile, sizeof(bootFilePath));␊ |
816 | ␉␉␉}␊ |
817 | ␊ |
818 | ␉␉␉DBG("Loading kernel from: '%s' (%s)\n", gBootVolume->label, gBootVolume->type_name);␊ |
819 | ␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
820 | ␉␉␉if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
821 | ␉␉␉{␊ |
822 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
823 | ␉␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
824 | ␉␉␉}␊ |
825 | ␉␉} while (0);␊ |
826 | ␊ |
827 | ␉␉clearActivityIndicator();␊ |
828 | ␊ |
829 | #if DEBUG␊ |
830 | ␉␉printf("Pausing...");␊ |
831 | ␉␉sleep(8);␊ |
832 | #endif␊ |
833 | ␊ |
834 | ␉␉if (ret <= 0)␊ |
835 | ␉␉{␊ |
836 | ␉␉␉printf("Can't find boot file: '%s'\n", bootFile);␊ |
837 | ␉␉␉sleep(1);␊ |
838 | ␊ |
839 | ␉␉␉if (gBootFileType == kNetworkDeviceType)␊ |
840 | ␉␉␉{␊ |
841 | ␉␉␉␉// Return control back to PXE. Don't unload PXE base code.␊ |
842 | ␉␉␉␉gUnloadPXEOnExit = false;␊ |
843 | ␉␉␉␉break;␊ |
844 | ␉␉␉}␊ |
845 | ␉␉␉pause();␊ |
846 | ␊ |
847 | ␉␉}␊ |
848 | ␉␉else␊ |
849 | ␉␉{␊ |
850 | ␉␉␉/* Won't return if successful. */␊ |
851 | ␉␉␉ret = ExecKernel(binary);␊ |
852 | ␉␉}␊ |
853 | ␉}␊ |
854 | ␊ |
855 | ␉// chainboot␊ |
856 | ␉if (status == 1)␊ |
857 | ␉{␊ |
858 | ␉␉// if we are already in graphics-mode,␊ |
859 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
860 | ␉␉{␊ |
861 | ␉␉␉setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode.␊ |
862 | ␉␉}␊ |
863 | ␉}␊ |
864 | ␊ |
865 | ␉if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit)␊ |
866 | ␉{␊ |
867 | ␉␉nbpUnloadBaseCode();␊ |
868 | ␉}␊ |
869 | ␊ |
870 | #if DEBUG_INTERRUPTS␊ |
871 | ␉if (interruptsAvailable)␊ |
872 | ␉{␊ |
873 | ␉␉DisableInterrupts();␊ |
874 | ␉}␊ |
875 | #endif␊ |
876 | ␊ |
877 | }␊ |
878 | ␊ |
879 | ␊ |
880 | // =========================================================================␊ |
881 | ␊ |
882 | /*!␊ |
883 | ␉Selects a new BIOS device, taking care to update the global state appropriately.␊ |
884 | */␊ |
885 | /*␊ |
886 | static void selectBiosDevice(void)␊ |
887 | {␊ |
888 | ␉struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);␊ |
889 | ␉CacheReset();␊ |
890 | ␉diskFreeMap(oldMap);␊ |
891 | ␉oldMap = NULL;␊ |
892 | ␊ |
893 | ␉int dev = selectAlternateBootDevice(gBIOSDev);␊ |
894 | ␊ |
895 | ␉BVRef bvchain = scanBootVolumes(dev, 0);␊ |
896 | ␉BVRef bootVol = selectBootVolume(bvchain);␊ |
897 | ␉gBootVolume = bootVol;␊ |
898 | ␉setRootVolume(bootVol);␊ |
899 | ␉gBIOSDev = dev;␊ |
900 | }␊ |
901 | */␊ |
902 | ␊ |
903 | // =========================================================================␊ |
904 | bool checkOSVersion(const char *version)␊ |
905 | {␊ |
906 | ␉if ( (sizeof(version) > 4) && ('.' != version[4]) && ('\0' != version[4]) )␊ |
907 | ␉{␊ |
908 | ␉␉return ((gMacOSVersion[0] == version[0]) && (gMacOSVersion[1] == version[1])␊ |
909 | ␉␉&& (gMacOSVersion[2] == version[2]) && (gMacOSVersion[3] == version[3])␊ |
910 | ␉␉&& (gMacOSVersion[4] == version[4]));␊ |
911 | ␉}␊ |
912 | ␉else␊ |
913 | ␉{␊ |
914 | ␉␉return ((gMacOSVersion[0] == version[0]) && (gMacOSVersion[1] == version[1])␊ |
915 | ␉␉&& (gMacOSVersion[2] == version[2]) && (gMacOSVersion[3] == version[3]));␊ |
916 | ␉}␊ |
917 | }␊ |
918 | ␊ |
919 | uint32_t getMacOSVerCurrent()␊ |
920 | {␊ |
921 | ␉MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion);␊ |
922 | ␉return MacOSVerCurrent;␊ |
923 | }␊ |
924 | ␊ |
925 | // =========================================================================␊ |
926 | unsigned long Adler32(unsigned char *buf, long len)␊ |
927 | {␊ |
928 | #define BASE 65521L /* largest prime smaller than 65536 */␊ |
929 | #define NMAX 5000␊ |
930 | // NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1␊ |
931 | ␊ |
932 | #define DO1(buf, i)␉{s1 += buf[i]; s2 += s1;}␊ |
933 | #define DO2(buf, i)␉DO1(buf, i); DO1(buf, i + 1);␊ |
934 | #define DO4(buf, i)␉DO2(buf, i); DO2(buf, i + 2);␊ |
935 | #define DO8(buf, i)␉DO4(buf, i); DO4(buf, i + 4);␊ |
936 | #define DO16(buf)␉DO8(buf, 0); DO8(buf, 8);␊ |
937 | ␊ |
938 | ␉int k;␊ |
939 | ␊ |
940 | ␉unsigned long s1 = 1; // adler & 0xffff;␊ |
941 | ␉unsigned long s2 = 0; // (adler >> 16) & 0xffff;␊ |
942 | ␉unsigned long result;␊ |
943 | ␊ |
944 | ␉while (len > 0) {␊ |
945 | ␉␉k = len < NMAX ? len : NMAX;␊ |
946 | ␉␉len -= k;␊ |
947 | ␉␉while (k >= 16)␊ |
948 | ␉␉{␊ |
949 | ␉␉␉DO16(buf);␊ |
950 | ␉␉␉buf += 16;␊ |
951 | ␉␉␉k -= 16;␊ |
952 | ␉␉}␊ |
953 | ␊ |
954 | ␉␉if (k != 0)␊ |
955 | ␉␉{␊ |
956 | ␉␉␉do␊ |
957 | ␉␉␉{␊ |
958 | ␉␉␉␉s1 += *buf++;␊ |
959 | ␉␉␉␉s2 += s1;␊ |
960 | ␉␉␉} while (--k);␊ |
961 | ␉␉}␊ |
962 | ␊ |
963 | ␉␉s1 %= BASE;␊ |
964 | ␉␉s2 %= BASE;␊ |
965 | ␉}␊ |
966 | ␊ |
967 | ␉result = (s2 << 16) | s1;␊ |
968 | ␊ |
969 | ␉return OSSwapHostToBigInt32(result);␊ |
970 | }␊ |
971 | |