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