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