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 "config.h"␊ |
49 | #include "boot.h"␊ |
50 | #include "bootstruct.h"␊ |
51 | #include "fake_efi.h"␊ |
52 | #include "sl.h"␊ |
53 | #include "libsa.h"␊ |
54 | #include "ramdisk.h"␊ |
55 | #include "gui.h"␊ |
56 | #include "platform.h"␊ |
57 | #include "modules.h"␊ |
58 | #include "device_tree.h"␊ |
59 | #include "xml.h" ␊ |
60 | ␊ |
61 | #if DEBUG_BOOT2␊ |
62 | ␉#define DBG(x...)␉printf(x)␊ |
63 | #else␊ |
64 | ␉#define DBG(x...)␉msglog(x)␊ |
65 | #endif␊ |
66 | ␊ |
67 | /*␊ |
68 | * How long to wait (in seconds) to load the␊ |
69 | * kernel after displaying the "boot:" prompt.␊ |
70 | */␊ |
71 | #define kBootErrorTimeout 5␊ |
72 | ␊ |
73 | bool␉␉gOverrideKernel;␊ |
74 | bool␉␉gEnableCDROMRescan;␊ |
75 | bool␉␉gScanSingleDrive;␊ |
76 | bool␉␉useGUI;␊ |
77 | ␊ |
78 | /* recovery or installer ? */␊ |
79 | bool isInstaller;␊ |
80 | bool isRecoveryHD;␊ |
81 | bool isMacOSXUpgrade;␊ |
82 | bool isOSXUpgrade;␊ |
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 | // Load the Kernel.plist override config file if any␊ |
145 | static void setupKernelConfigFile(const char *filename)␊ |
146 | {␊ |
147 | ␉char␉␉dirSpec[128];␊ |
148 | ␉const char␉*override_pathname = NULL;␊ |
149 | ␉int␉␉len = 0, err = 0;␊ |
150 | ␊ |
151 | ␉// Take in account user overriding␊ |
152 | ␉if (getValueForKey(kKERNELKey, &override_pathname, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
153 | ␉{␊ |
154 | ␉␉// Specify a path to a file, e.g. KERNELPlist=/Extra/Kernel2.plist␊ |
155 | ␉␉strcpy(dirSpec, override_pathname);␊ |
156 | ␉␉err = loadConfigFile(dirSpec, &bootInfo->kernelConfig);␊ |
157 | ␉}␊ |
158 | ␉else␊ |
159 | ␉{␊ |
160 | ␉␉// Check selected volume's Extra.␊ |
161 | ␉␉sprintf(dirSpec, "/Extra/%s", filename);␊ |
162 | ␉␉err = loadConfigFile(dirSpec, &bootInfo->kernelConfig);␊ |
163 | ␉}␊ |
164 | ␊ |
165 | ␉if (!err)␊ |
166 | ␉{␊ |
167 | ␉␉getBoolForKey(kKernelBooter_kexts, &KernelBooter_kexts, KERNELPlist);␊ |
168 | ␉␉getBoolForKey(kKernelPm, &KernelPm, KERNELPlist);␊ |
169 | ␉␉getBoolForKey(kKernelLapicError, &KernelLapicError, KERNELPlist);␊ |
170 | ␉␉getBoolForKey(kKernelLapicVersion, &KernelLapicVersion, KERNELPlist);␊ |
171 | ␉␉getBoolForKey(kKernelHaswell, &KernelHaswell, KERNELPlist);␊ |
172 | ␉␉getBoolForKey(kKernelcpuFamily, &KernelcpuFamily, KERNELPlist);␊ |
173 | ␉␉getBoolForKey(kKernelSSE3, &KernelSSE3, KERNELPlist);␊ |
174 | ␉}␊ |
175 | ␉else␊ |
176 | ␉{␊ |
177 | ␉␉verbose("No %s replacement found.\n", filename);␊ |
178 | ␉}␊ |
179 | }␊ |
180 | ␊ |
181 | #if KEXTPATCH_SUPPORT␊ |
182 | // =========================================================================␊ |
183 | // Load the Kexts.plist override config file if any␊ |
184 | static void setupKextConfigFile(const char *filename)␊ |
185 | {␊ |
186 | ␉char␉␉dirSpec[128];␊ |
187 | ␉const char␉*override_pathname = NULL;␊ |
188 | ␉int␉␉len = 0, err = 0;␊ |
189 | ␊ |
190 | ␉AppleRTCPatch = false;␊ |
191 | ␉AICPMPatch = false;␊ |
192 | ␉OrangeIconFixSata = false;␊ |
193 | ␉NVIDIAWebDrv = false;␊ |
194 | ␉TrimEnablerSata = false;␊ |
195 | ␊ |
196 | ␉// Take in account user overriding␊ |
197 | ␉if (getValueForKey(kKEXTKey, &override_pathname, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
198 | ␉{␊ |
199 | ␉␉// Specify a path to a file, e.g. KEXTPlist=/Extra/Kext2.plist␊ |
200 | ␉␉strcpy(dirSpec, override_pathname);␊ |
201 | ␉␉err = loadConfigFile(dirSpec, &bootInfo->kextConfig);␊ |
202 | ␉} else {␊ |
203 | ␉␉// Check selected volume's Extra.␊ |
204 | ␉␉sprintf(dirSpec, "/Extra/%s", filename);␊ |
205 | ␉␉err = loadConfigFile(dirSpec, &bootInfo->kextConfig);␊ |
206 | ␉}␊ |
207 | ␊ |
208 | ␉if (!err)␊ |
209 | ␉{␊ |
210 | ␉␉getBoolForKey(kAppleRTCPatch, &AppleRTCPatch, KEXTPlist);␊ |
211 | ␉␉getBoolForKey(kAICPMPatch, &AICPMPatch, KEXTPlist);␊ |
212 | ␉␉getBoolForKey(kNVIDIAWebDrv, &NVIDIAWebDrv, KEXTPlist);␊ |
213 | ␉␉getBoolForKey(kOrangeIconFixSata, &OrangeIconFixSata, KEXTPlist);␊ |
214 | ␉␉getBoolForKey(kTrimEnablerSata, &TrimEnablerSata, KEXTPlist);␊ |
215 | ␉} else {␊ |
216 | ␉␉verbose("No %s replacement found.\n", filename);␊ |
217 | ␉}␊ |
218 | }␊ |
219 | #endif␊ |
220 | ␊ |
221 | //==========================================================================␊ |
222 | // ExecKernel - Load the kernel image (mach-o) and jump to its entry point.␊ |
223 | ␊ |
224 | static int ExecKernel(void *binary)␊ |
225 | {␊ |
226 | ␉int␉␉␉ret;␊ |
227 | ␉entry_t␉␉kernelEntry;␊ |
228 | ␊ |
229 | ␉bootArgs->kaddr = bootArgs->ksize = 0;␊ |
230 | ␊ |
231 | // ===============================================================================␊ |
232 | ␊ |
233 | ␉gMacOSVersion[0] = 0;␊ |
234 | ␉verbose("Booting on %s %s (%s)\n", (MacOSVerCurrent < MacOSVer2Int("10.8")) ? "Mac OS X" : (MacOSVerCurrent < MacOSVer2Int("10.12")) ? "OS X" : "macOS", gBootVolume->OSFullVer, gBootVolume->OSBuildVer );␊ |
235 | ␊ |
236 | ␉setupBooterArgs();␊ |
237 | ␊ |
238 | // ===============================================================================␊ |
239 | ␊ |
240 | ␉execute_hook("ExecKernel", (void *)binary, NULL, NULL, NULL);␊ |
241 | ␊ |
242 | ␉ret = DecodeKernel(binary,␊ |
243 | ␉␉␉␉␉ &kernelEntry,␊ |
244 | ␉␉␉␉␉ (char **) &bootArgs->kaddr,␊ |
245 | ␉␉␉␉␉ (int *)&bootArgs->ksize);␊ |
246 | ␊ |
247 | ␉if ( ret != 0 )␊ |
248 | ␉{␊ |
249 | ␉␉printf("Decoding kernel failed.\n");␊ |
250 | ␉␉pause();␊ |
251 | ␉␉return ret;␊ |
252 | ␉}␊ |
253 | ␊ |
254 | ␉// Reserve space for boot args␊ |
255 | ␉reserveKernBootStruct();␊ |
256 | ␊ |
257 | ␉// Notify modules that the kernel has been decoded␊ |
258 | ␉execute_hook("DecodedKernel", (void *)binary, (void *)bootArgs->kaddr, (void *)bootArgs->ksize, NULL);␊ |
259 | ␊ |
260 | ␉setupFakeEfi();␊ |
261 | ␊ |
262 | ␉// Load boot drivers from the specifed root path.␊ |
263 | ␉//if (!gHaveKernelCache)␊ |
264 | ␉{␊ |
265 | ␉␉LoadDrivers("/");␊ |
266 | ␉}␊ |
267 | ␊ |
268 | ␉execute_hook("DriversLoaded", (void *)binary, NULL, NULL, NULL);␊ |
269 | ␊ |
270 | ␉clearActivityIndicator();␊ |
271 | ␊ |
272 | ␉if (gErrors)␊ |
273 | ␉{␊ |
274 | ␉␉printf("Errors encountered while starting up the computer.\n");␊ |
275 | ␉␉printf("Pausing %d seconds...\n", kBootErrorTimeout);␊ |
276 | ␉␉sleep(kBootErrorTimeout);␊ |
277 | ␉}␊ |
278 | ␊ |
279 | ␉md0Ramdisk();␊ |
280 | ␊ |
281 | ␉// Cleanup the PXE base code.␊ |
282 | ␊ |
283 | ␉if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit )␊ |
284 | ␉{␊ |
285 | ␉␉if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )␊ |
286 | ␉␉{␊ |
287 | ␉␉␉printf("nbpUnloadBaseCode error %d\n", (int)ret);␊ |
288 | ␉␉␉sleep(2);␊ |
289 | ␉␉}␊ |
290 | ␉}␊ |
291 | ␊ |
292 | ␉bool dummyVal;␊ |
293 | ␉if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->chameleonConfig) && dummyVal)␊ |
294 | ␉{␊ |
295 | ␉␉showTextBuffer(msgbuf, strlen(msgbuf));␊ |
296 | ␉}␊ |
297 | ␊ |
298 | ␉usb_loop();␊ |
299 | ␊ |
300 | #if DEBUG␊ |
301 | ␉if (interruptsAvailable) ShowInterruptCounters();␊ |
302 | #endif␊ |
303 | ␊ |
304 | ␉// If we were in text mode, switch to graphics mode.␊ |
305 | ␉// This will draw the boot graphics unless we are in␊ |
306 | ␉// verbose mode.␊ |
307 | ␉if (gVerboseMode)␊ |
308 | ␉{␊ |
309 | ␉␉setVideoMode( GRAPHICS_MODE );␊ |
310 | ␉}␊ |
311 | ␉else␊ |
312 | ␉{␊ |
313 | ␉␉drawBootGraphics();␊ |
314 | ␉}␊ |
315 | ␊ |
316 | ␉DBG("Starting Darwin/%s [%s]\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64", gDarwinBuildVerStr);␊ |
317 | ␉DBG("Boot Args: %s\n", bootArgs->CommandLine);␊ |
318 | ␊ |
319 | ␉setupBooterLog();␊ |
320 | ␊ |
321 | ␉finalizeBootStruct();␊ |
322 | ␊ |
323 | ␉// Jump to kernel's entry point. There's no going back now.␊ |
324 | ␉if ( MacOSVerCurrent < MacOSVer2Int("10.7") )␊ |
325 | ␉{␊ |
326 | ␉␉// Notify modules that the kernel is about to be started␊ |
327 | ␉␉execute_hook("Kernel Start", (void *)kernelEntry, (void *)bootArgsLegacy, NULL, NULL);␊ |
328 | ␊ |
329 | ␉␉startprog( kernelEntry, bootArgsLegacy );␊ |
330 | ␉}␊ |
331 | ␉else␊ |
332 | ␉{␊ |
333 | ␉␉// Notify modules that the kernel is about to be started␊ |
334 | ␉␉execute_hook("Kernel Start", (void *)kernelEntry, (void *)bootArgs, NULL, NULL);␊ |
335 | ␊ |
336 | ␉␉startprog( kernelEntry, bootArgs );␊ |
337 | ␉}␊ |
338 | ␊ |
339 | ␉// Not reached␊ |
340 | ␉__builtin_unreachable();␊ |
341 | }␊ |
342 | ␊ |
343 | //==========================================================================␊ |
344 | // LoadKernelCache - Try to load Kernel Cache.␊ |
345 | // return the length of the loaded cache file or -1 on error␊ |
346 | long LoadKernelCache(const char *cacheFile, void **binary)␊ |
347 | {␊ |
348 | ␉char␉␉kernelCacheFile[512];␊ |
349 | ␉char␉␉kernelCachePath[512];␊ |
350 | ␉long␉␉flags, ret=-1;␊ |
351 | ␉unsigned long␉adler32 = 0;␊ |
352 | ␉u_int32_t time, cachetime, kerneltime, exttime;␊ |
353 | ␊ |
354 | ␉if((gBootMode & kBootModeSafe) != 0)␊ |
355 | ␉{␊ |
356 | ␉␉DBG("Kernel Cache ignored.\n");␊ |
357 | ␉␉return -1;␊ |
358 | ␉}␊ |
359 | ␊ |
360 | ␉// Use specify kernel cache file if not empty␊ |
361 | ␉if (cacheFile[0] != 0)␊ |
362 | ␉{␊ |
363 | ␉␉strlcpy(kernelCacheFile, cacheFile, sizeof(kernelCacheFile));␊ |
364 | ␉␉verbose("Specified kernel cache file path: %s\n", cacheFile);␊ |
365 | ␉}␊ |
366 | ␉else␊ |
367 | ␉{␊ |
368 | ␉␉// Leopard prelink kernel cache file␊ |
369 | ␉␉if ( MacOSVerCurrent >= MacOSVer2Int("10.4") && MacOSVerCurrent <= MacOSVer2Int("10.5") ) // OSX is 10.4 or 10.5␊ |
370 | ␉␉{␊ |
371 | ␉␉␉// Reset cache name.␊ |
372 | ␉␉␉bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);␊ |
373 | ␉␉␉snprintf(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64, "%s,%s", gRootDevice, bootInfo->bootFile);␊ |
374 | ␉␉␉adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));␊ |
375 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32);␊ |
376 | ␉␉␉verbose("Reseted kernel cache file path: %s\n", kernelCacheFile);␊ |
377 | ␊ |
378 | ␉␉}␊ |
379 | ␉␉// Snow Leopard prelink kernel cache file␊ |
380 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.6") && MacOSVerCurrent < MacOSVer2Int("10.7") )␊ |
381 | ␉␉{␊ |
382 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "kernelcache_%s",␊ |
383 | ␉␉␉␉(archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64");␊ |
384 | ␊ |
385 | ␉␉␉int␉␉lnam = strlen(kernelCacheFile) + 9; //with adler32␊ |
386 | ␉␉␉char␉␉*name;␊ |
387 | ␉␉␉u_int32_t␉prev_time = 0;␊ |
388 | ␊ |
389 | ␉␉␉struct dirstuff *cacheDir = opendir(kDefaultCachePathSnow);␊ |
390 | ␊ |
391 | ␉␉␉/* TODO: handle error? */␊ |
392 | ␉␉␉if (cacheDir)␊ |
393 | ␉␉␉{␊ |
394 | ␉␉␉␉while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)␊ |
395 | ␉␉␉␉{␊ |
396 | ␉␉␉␉␉if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time␊ |
397 | ␉␉␉␉␉␉&& strstr(name, kernelCacheFile) && (name[lnam] != '.'))␊ |
398 | ␉␉␉␉␉{␊ |
399 | ␉␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s%s", kDefaultCachePathSnow, name);␊ |
400 | ␉␉␉␉␉␉prev_time = time;␊ |
401 | ␉␉␉␉␉}␊ |
402 | ␉␉␉␉}␊ |
403 | ␉␉␉␉verbose("Kernel Cache file path (Mac OS X 10.6): %s\n", kernelCacheFile);␊ |
404 | ␉␉␉}␊ |
405 | ␉␉␉closedir(cacheDir);␊ |
406 | ␉␉}␊ |
407 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.7") && MacOSVerCurrent < MacOSVer2Int("10.9") )␊ |
408 | ␉␉{␊ |
409 | ␉␉␉// Lion, Mountain Lion␊ |
410 | ␉␉␉// for 10.7 10.8␊ |
411 | ␉␉␉if (isMacOSXUpgrade)␊ |
412 | ␉␉␉{␊ |
413 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", "/Mac OS X Install Data/");␊ |
414 | ␉␉␉}␊ |
415 | ␉␉␉else if (isInstaller)␊ |
416 | ␉␉␉{␊ |
417 | ␉␉␉␉if (MacOSVerCurrent >= MacOSVer2Int("10.7") && MacOSVerCurrent < MacOSVer2Int("10.8") )␊ |
418 | ␉␉␉␉{␊ |
419 | ␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kLionInstallerDataFolder);␊ |
420 | ␉␉␉␉}␊ |
421 | ␉␉␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.8") && MacOSVerCurrent < MacOSVer2Int("10.9") )␊ |
422 | ␉␉␉␉{␊ |
423 | ␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kMLionInstallerDataFolder);␊ |
424 | ␉␉␉␉}␊ |
425 | ␊ |
426 | ␉␉␉}␊ |
427 | ␉␉␉else if (isRecoveryHD)␊ |
428 | ␉␉␉{␊ |
429 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheRecoveryHD);␊ |
430 | ␉␉␉}␊ |
431 | ␉␉␉else␊ |
432 | ␉␉␉{␊ |
433 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);␊ |
434 | ␉␉␉}␊ |
435 | ␊ |
436 | ␉␉␉verbose("Kernel Cache file path (Mac OS X 10.7 and newer): %s\n", kernelCacheFile);␊ |
437 | ␊ |
438 | ␉␉}␊ |
439 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.9") && MacOSVerCurrent < MacOSVer2Int("10.10") )␊ |
440 | ␉␉{␊ |
441 | ␉␉␉// Mavericks prelinked cache file␊ |
442 | ␉␉␉// for 10.9␊ |
443 | ␉␉␉if (isOSXUpgrade)␊ |
444 | ␉␉␉{␊ |
445 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", "/OS X Install Data/");␊ |
446 | ␉␉␉}␊ |
447 | ␉␉␉else if (isInstaller)␊ |
448 | ␉␉␉{␊ |
449 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheInstallerNew);␊ |
450 | ␉␉␉}␊ |
451 | ␉␉␉else if (isRecoveryHD)␊ |
452 | ␉␉␉{␊ |
453 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheRecoveryHD);␊ |
454 | ␉␉␉}␊ |
455 | ␉␉␉else␊ |
456 | ␉␉␉{␊ |
457 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);␊ |
458 | ␉␉␉}␊ |
459 | ␊ |
460 | ␉␉␉verbose("Kernel Cache file path (OS X 10.9): %s\n", kernelCacheFile);␊ |
461 | ␊ |
462 | ␉␉}␊ |
463 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.10") && MacOSVerCurrent < MacOSVer2Int("10.11") )␊ |
464 | ␉␉{␊ |
465 | ␉␉␉// Yosemite prelink kernel cache file␊ |
466 | ␉␉␉// for 10.10 and 10.11␊ |
467 | ␉␉␉if (isOSXUpgrade)␊ |
468 | ␉␉␉{␊ |
469 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", "/OS X Install Data/");␊ |
470 | ␉␉␉}␊ |
471 | ␉␉␉else if (isInstaller)␊ |
472 | ␉␉␉{␊ |
473 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheInstallerNew);␊ |
474 | ␉␉␉}␊ |
475 | ␉␉␉else if (isRecoveryHD)␊ |
476 | ␉␉␉{␊ |
477 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheRecoveryHD);␊ |
478 | ␉␉␉}␊ |
479 | ␉␉␉else␊ |
480 | ␉␉␉{␊ |
481 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCachePathYosemite);␊ |
482 | ␉␉␉}␊ |
483 | ␊ |
484 | ␉␉␉verbose("Kernel Cache file path (OS X 10.10): %s\n", kernelCacheFile);␊ |
485 | ␉␉}␊ |
486 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.11") )␊ |
487 | ␉␉{␊ |
488 | ␉␉␉// El Capitan on prelinked kernel cache file␊ |
489 | ␉␉␉// for 10.10 and 10.11␊ |
490 | ␉␉␉if (isOSXUpgrade)␊ |
491 | ␉␉␉{␊ |
492 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", "/OS X Install Data/");␊ |
493 | ␉␉␉}␊ |
494 | ␉␉␉else if (isInstaller)␊ |
495 | ␉␉␉{␊ |
496 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCacheInstallerNew);␊ |
497 | ␉␉␉}␊ |
498 | ␉␉␉else if (isRecoveryHD)␊ |
499 | ␉␉␉{␊ |
500 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCacheRecoveryHD);␊ |
501 | ␉␉␉}␊ |
502 | ␉␉␉else␊ |
503 | ␉␉␉{␊ |
504 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCachePathYosemite);␊ |
505 | ␉␉␉}␊ |
506 | ␊ |
507 | ␉␉␉verbose("Kernel Cache file path (OS X 10.11 and newer): %s\n", kernelCacheFile);␊ |
508 | ␉␉}␊ |
509 | ␉}␊ |
510 | ␊ |
511 | ␉// Check if the kernel cache file exists␊ |
512 | ␉ret = -1;␊ |
513 | ␊ |
514 | ␉if (gBootVolume->flags & kBVFlagBooter)␊ |
515 | ␉{␊ |
516 | ␉␉if (isRecoveryHD)␊ |
517 | ␉␉{␊ |
518 | ␉␉␉strncpy(kernelCachePath, "/com.apple.recovery.boot/prelinkedkernel", sizeof(kernelCachePath) );␊ |
519 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
520 | ␊ |
521 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
522 | ␉␉␉{␊ |
523 | ␉␉␉␉strncpy(kernelCachePath, "/com.apple.recovery.boot/kernelcache", sizeof(kernelCachePath) );␊ |
524 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
525 | ␊ |
526 | ␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
527 | ␉␉␉␉{␊ |
528 | ␉␉␉␉␉ret = -1;␊ |
529 | ␉␉␉␉}␊ |
530 | ␉␉␉}␊ |
531 | ␉␉}␊ |
532 | ␉␉else if (isInstaller)␊ |
533 | ␉␉{␊ |
534 | ␉␉␉strncpy(kernelCachePath, "/.IABootFiles/prelinkedkernel", sizeof(kernelCachePath) );␊ |
535 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
536 | ␊ |
537 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
538 | ␉␉␉{␊ |
539 | ␉␉␉␉strncpy(kernelCachePath, "/.IABootFiles/kernelcache", sizeof(kernelCachePath) );␊ |
540 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
541 | ␊ |
542 | ␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
543 | ␉␉␉␉{␊ |
544 | ␉␉␉␉␉ret = -1;␊ |
545 | ␉␉␉␉}␊ |
546 | ␉␉␉}␊ |
547 | ␉␉}␊ |
548 | ␉␉else if (isMacOSXUpgrade)␊ |
549 | ␉␉{␊ |
550 | ␉␉␉strncpy(kernelCachePath, "/Mac OS X Install Data/kernelcache", sizeof(kernelCachePath) );␊ |
551 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
552 | ␊ |
553 | ␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
554 | ␉␉␉{␊ |
555 | ␉␉␉␉ret = -1;␊ |
556 | ␉␉␉}␊ |
557 | ␉␉}␊ |
558 | ␉␉else if (isOSXUpgrade)␊ |
559 | ␉␉{␊ |
560 | ␉␉␉strncpy(kernelCachePath, "/OS X Install Data/prelinkedkernel", sizeof(kernelCachePath) );␊ |
561 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
562 | ␊ |
563 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
564 | ␉␉␉{␊ |
565 | ␉␉␉␉strncpy(kernelCachePath, "/OS X Install Data/kernelcache", sizeof(kernelCachePath) );␊ |
566 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
567 | ␊ |
568 | ␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
569 | ␉␉␉␉{␊ |
570 | ␉␉␉␉␉ret = -1;␊ |
571 | ␉␉␉␉}␊ |
572 | ␉␉␉}␊ |
573 | ␉␉}␊ |
574 | ␉␉else␊ |
575 | ␉␉{␊ |
576 | ␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.P/%s", kernelCacheFile);␊ |
577 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
578 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
579 | ␉␉␉{␊ |
580 | ␉␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.R/%s", kernelCacheFile);␊ |
581 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
582 | ␊ |
583 | ␉␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
584 | ␉␉␉␉{␊ |
585 | ␉␉␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.S/%s", kernelCacheFile);␊ |
586 | ␉␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
587 | ␊ |
588 | ␉␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
589 | ␉␉␉␉␉{␊ |
590 | ␉␉␉␉␉␉ret = -1;␊ |
591 | ␉␉␉␉␉}␊ |
592 | ␉␉␉␉}␊ |
593 | ␉␉␉}␊ |
594 | ␉␉}␊ |
595 | ␉}␊ |
596 | ␊ |
597 | ␉// If not found, use the original kernel cache path.␊ |
598 | ␉if (ret == -1)␊ |
599 | ␉{␊ |
600 | ␉␉strlcpy(kernelCachePath, kernelCacheFile, sizeof(kernelCachePath));␊ |
601 | ␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
602 | ␊ |
603 | ␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
604 | ␉␉{␊ |
605 | ␉␉␉ret = -1;␊ |
606 | ␉␉}␊ |
607 | ␉}␊ |
608 | ␊ |
609 | ␉// Exit if kernel cache file wasn't found␊ |
610 | ␉if (ret == -1)␊ |
611 | ␉{␊ |
612 | ␉␉DBG("No Kernel Cache File '%s' found\n", kernelCacheFile);␊ |
613 | ␉␉return -1;␊ |
614 | ␉}␊ |
615 | ␊ |
616 | ␉if ( !isInstaller && !isRecoveryHD && !isMacOSXUpgrade && !isOSXUpgrade )␊ |
617 | ␉{␊ |
618 | ␉␉// Check if the kernel cache file is more recent (mtime)␊ |
619 | ␉␉// than the kernel file or the S/L/E directory␊ |
620 | ␉␉ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);␊ |
621 | ␊ |
622 | ␉␉// Check if the kernel file is more recent than the cache file␊ |
623 | ␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat) && (kerneltime > cachetime))␊ |
624 | ␉␉{␊ |
625 | ␉␉␉DBG("Kernel file '%s' is more recent than Kernel Cache '%s'! Ignoring Kernel Cache.\n", bootInfo->bootFile, kernelCacheFile);␊ |
626 | ␉␉␉return -1;␊ |
627 | ␉␉}␊ |
628 | ␊ |
629 | ␉␉ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);␊ |
630 | ␊ |
631 | ␉␉// Check if the S/L/E directory time is more recent than the cache file␊ |
632 | ␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory) && (exttime > cachetime))␊ |
633 | ␉␉{␊ |
634 | ␉␉␉DBG("Folder '/System/Library/Extensions' is more recent than Kernel Cache file '%s'! Ignoring Kernel Cache.\n", kernelCacheFile);␊ |
635 | ␉␉␉return -1;␊ |
636 | ␉␉}␊ |
637 | ␉}␊ |
638 | ␊ |
639 | ␉// Since the kernel cache file exists and is the most recent try to load it␊ |
640 | ␉DBG("Loading Kernel Cache from: '%s%s' (%s)\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name);␊ |
641 | ␊ |
642 | ␉ret = LoadThinFatFile(kernelCachePath, binary);␊ |
643 | ␉return ret; // ret contain the length of the binary␊ |
644 | }␊ |
645 | ␊ |
646 | //==========================================================================␊ |
647 | // This is the entrypoint from real-mode which functions exactly as it did␊ |
648 | // before. Multiboot does its own runtime initialization, does some of its␊ |
649 | // own things, and then calls common_boot.␊ |
650 | void boot(int biosdev)␊ |
651 | {␊ |
652 | ␉// Enable A20 gate before accessing memory above 1Mb.␊ |
653 | ␉// Note: malloc_init(), called via initialize_runtime() writes␊ |
654 | ␉// memory >= 1Mb, so A20 must be enabled before calling it. - zenith432␊ |
655 | ␉zeroBSS();␊ |
656 | ␉enableA20();␊ |
657 | ␉malloc_init(0, 0, 0, malloc_error);␊ |
658 | ␉common_boot(biosdev);␊ |
659 | }␊ |
660 | ␊ |
661 | //==========================================================================␊ |
662 | // The 'main' function for the booter. Called by boot0 when booting␊ |
663 | // from a block device, or by the network booter.␊ |
664 | //␊ |
665 | // arguments:␊ |
666 | //␉ biosdev - Value passed from boot1/NBP to specify the device␊ |
667 | //␉␉␉ that the booter was loaded from.␊ |
668 | //␊ |
669 | // If biosdev is kBIOSDevNetwork, then this function will return if␊ |
670 | // booting was unsuccessful. This allows the PXE firmware to try the␊ |
671 | // next boot device on its list.␊ |
672 | void common_boot(int biosdev)␊ |
673 | {␊ |
674 | ␉bool␉ ␉␉quiet;␊ |
675 | ␉bool␉ ␉␉firstRun = true;␊ |
676 | ␉bool␉ ␉␉instantMenu;␊ |
677 | ␉bool␉ ␉␉rescanPrompt;␊ |
678 | ␉int␉␉␉status;␊ |
679 | ␉unsigned int␉␉allowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;␊ |
680 | ␉unsigned int␉␉denyBVFlags = kBVFlagEFISystem;␊ |
681 | ␊ |
682 | ␉// Set reminder to unload the PXE base code. Neglect to unload␊ |
683 | ␉// the base code will result in a hang or kernel panic.␊ |
684 | ␉gUnloadPXEOnExit = true;␊ |
685 | ␊ |
686 | ␉// Record the device that the booter was loaded from.␊ |
687 | ␉gBIOSDev = biosdev & kBIOSDevMask;␊ |
688 | ␊ |
689 | ␉// Initialize boot-log␊ |
690 | ␉initBooterLog();␊ |
691 | ␊ |
692 | #if DEBUG_INTERRUPTS␊ |
693 | ␉// Enable interrupts␊ |
694 | ␉interruptsAvailable = SetupInterrupts();␊ |
695 | ␉if (interruptsAvailable)␊ |
696 | ␉{␊ |
697 | ␉␉EnableInterrupts();␊ |
698 | ␉}␊ |
699 | #endif␊ |
700 | ␊ |
701 | ␉// Initialize boot info structure.␊ |
702 | ␉initKernBootStruct();␊ |
703 | ␊ |
704 | ␉// Setup VGA text mode.␊ |
705 | ␉// Not sure if it is safe to call setVideoMode() before the␊ |
706 | ␉// config table has been loaded. Call video_mode() instead.␊ |
707 | #if DEBUG␊ |
708 | ␉printf("before video_mode\n");␊ |
709 | #endif␊ |
710 | ␉video_mode( 2 ); // 80x25 mono text mode.␊ |
711 | #if DEBUG␊ |
712 | ␉printf("after video_mode\n");␊ |
713 | #endif␊ |
714 | ␊ |
715 | ␉// Scan and record the system's hardware information.␊ |
716 | ␉scan_platform();␊ |
717 | ␊ |
718 | ␉// First get info for boot volume.␊ |
719 | ␉scanBootVolumes(gBIOSDev, 0);␊ |
720 | ␉bvChain = getBVChainForBIOSDev(gBIOSDev);␊ |
721 | ␉setBootGlobals(bvChain);␊ |
722 | ␊ |
723 | ␉// Load boot.plist config file␊ |
724 | ␉status = loadChameleonConfig(&bootInfo->chameleonConfig, bvChain);␊ |
725 | ␊ |
726 | ␉if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet)␊ |
727 | ␉{␊ |
728 | ␉␉gBootMode |= kBootModeQuiet;␊ |
729 | ␉}␊ |
730 | ␊ |
731 | ␉// Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config␊ |
732 | ␉if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->chameleonConfig) && instantMenu)␊ |
733 | ␉{␊ |
734 | ␉␉firstRun = false;␊ |
735 | ␉}␊ |
736 | ␊ |
737 | ␉// Loading preboot ramdisk if exists.␊ |
738 | ␉loadPrebootRAMDisk();␊ |
739 | ␊ |
740 | ␉// Disable rescan option by default␊ |
741 | ␉gEnableCDROMRescan = false;␊ |
742 | ␊ |
743 | ␉// Enable it with Rescan=y in system config␊ |
744 | ␉if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->chameleonConfig)␉&& gEnableCDROMRescan)␊ |
745 | ␉{␊ |
746 | ␉␉gEnableCDROMRescan = true;␊ |
747 | ␉}␊ |
748 | ␊ |
749 | ␉// Disable rescanPrompt option by default␊ |
750 | ␉rescanPrompt = false;␊ |
751 | ␊ |
752 | ␉// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.␊ |
753 | ␉if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev))␊ |
754 | ␉{␊ |
755 | ␉␉gEnableCDROMRescan = promptForRescanOption();␊ |
756 | ␉}␊ |
757 | ␊ |
758 | ␉// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.␊ |
759 | ␉if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->chameleonConfig) && gScanSingleDrive)␊ |
760 | ␉{␊ |
761 | ␉␉gScanSingleDrive = true;␊ |
762 | ␉}␊ |
763 | ␊ |
764 | ␉// Create a list of partitions on device(s).␊ |
765 | ␉if (gScanSingleDrive)␊ |
766 | ␉{␊ |
767 | ␉␉scanBootVolumes(gBIOSDev, &bvCount);␊ |
768 | ␉}␊ |
769 | ␉else␊ |
770 | ␉{␊ |
771 | ␉␉scanDisks(gBIOSDev, &bvCount);␊ |
772 | ␉}␊ |
773 | ␊ |
774 | ␉// Create a separated bvr chain using the specified filters.␊ |
775 | ␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
776 | ␊ |
777 | ␉gBootVolume = selectBootVolume(bvChain);␊ |
778 | ␊ |
779 | ␉// Intialize module system␊ |
780 | ␉init_module_system();␊ |
781 | ␊ |
782 | #if DEBUG␊ |
783 | ␉printf("Default: %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",␊ |
784 | ␉␉gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);␊ |
785 | ␉printf("bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",␊ |
786 | ␉␉gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);␊ |
787 | ␉getchar();␊ |
788 | #endif␊ |
789 | ␊ |
790 | ␉useGUI = true;␊ |
791 | ␉// Override useGUI default␊ |
792 | ␉getBoolForKey(kGUIKey, &useGUI, &bootInfo->chameleonConfig);␊ |
793 | ␉if (useGUI && initGUI())␊ |
794 | ␉{␊ |
795 | ␉␉// initGUI() returned with an error, disabling GUI.␊ |
796 | ␉␉useGUI = false;␊ |
797 | ␉}␊ |
798 | ␊ |
799 | ␉setBootGlobals(bvChain);␊ |
800 | ␊ |
801 | ␉// Parse args, load and start kernel.␊ |
802 | ␉while (1)␊ |
803 | ␉{␊ |
804 | ␉␉bool␉␉tryresume, tryresumedefault, forceresume;␊ |
805 | ␉␉bool␉␉useKernelCache = true; // by default try to use the prelinked kernel␊ |
806 | ␉␉const char␉*val;␊ |
807 | ␉␉int␉␉␉len, ret = -1;␊ |
808 | ␉␉long␉␉flags;␊ |
809 | ␉␉u_int32_t␉sleeptime, time;␊ |
810 | ␉␉void␉␉*binary = (void *)kLoadAddr;␊ |
811 | ␊ |
812 | ␉␉char␉␉bootFile[sizeof(bootInfo->bootFile)];␊ |
813 | ␉␉char␉␉bootFilePath[512];␊ |
814 | ␉␉char␉␉kernelCacheFile[512];␊ |
815 | ␊ |
816 | ␉␉// Initialize globals.␊ |
817 | ␉␉sysConfigValid = false;␊ |
818 | ␉␉gErrors␉␉ = false;␊ |
819 | ␊ |
820 | ␉␉status = getBootOptions(firstRun);␊ |
821 | ␉␉firstRun = false;␊ |
822 | ␉␉if (status == -1) continue;␊ |
823 | ␊ |
824 | ␉␉status = processBootOptions();␊ |
825 | ␉␉// Status == 1 means to chainboot␊ |
826 | ␉␉if ( status ==␉1 ) break;␊ |
827 | ␉␉// Status == -1 means that the config file couldn't be loaded or that gBootVolume is NULL␊ |
828 | ␉␉if ( status == -1 )␊ |
829 | ␉␉{␊ |
830 | ␉␉␉// gBootVolume == NULL usually means the user hit escape.␊ |
831 | ␉␉␉if (gBootVolume == NULL)␊ |
832 | ␉␉␉{␊ |
833 | ␉␉␉␉freeFilteredBVChain(bvChain);␊ |
834 | ␊ |
835 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
836 | ␉␉␉␉{␊ |
837 | ␉␉␉␉␉rescanBIOSDevice(gBIOSDev);␊ |
838 | ␉␉␉␉}␊ |
839 | ␊ |
840 | ␉␉␉␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
841 | ␉␉␉␉setBootGlobals(bvChain);␊ |
842 | ␉␉␉␉setupDeviceList(&bootInfo->themeConfig);␊ |
843 | ␉␉␉}␊ |
844 | ␉␉␉continue;␊ |
845 | ␉␉}␊ |
846 | ␊ |
847 | ␉␉// Other status (e.g. 0) means that we should proceed with boot.␊ |
848 | ␊ |
849 | ␉␉// Turn off any GUI elements␊ |
850 | ␉␉if ( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
851 | ␉␉{␊ |
852 | ␉␉␉gui.devicelist.draw = false;␊ |
853 | ␉␉␉gui.bootprompt.draw = false;␊ |
854 | ␉␉␉gui.menu.draw = false;␊ |
855 | ␉␉␉gui.infobox.draw = false;␊ |
856 | ␉␉␉gui.logo.draw = false;␊ |
857 | ␉␉␉drawBackground();␊ |
858 | ␉␉␉updateVRAM();␊ |
859 | ␉␉}␊ |
860 | ␊ |
861 | ␉␉if (platformCPUFeature(CPU_FEATURE_EM64T))␊ |
862 | ␉␉{␊ |
863 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
864 | ␉␉}␊ |
865 | ␉␉else␊ |
866 | ␉␉{␊ |
867 | ␉␉␉archCpuType = CPU_TYPE_I386;␊ |
868 | ␉␉}␊ |
869 | ␊ |
870 | ␉␉if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig))␊ |
871 | ␉␉{␊ |
872 | ␉␉␉if (strncmp(val, "x86_64", sizeof("x86_64") ) == 0)␊ |
873 | ␉␉␉{␊ |
874 | ␉␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
875 | ␉␉␉}␊ |
876 | ␉␉␉else if (strncmp(val, "i386", sizeof("i386") ) == 0)␊ |
877 | ␉␉␉{␊ |
878 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
879 | ␉␉␉}␊ |
880 | ␉␉␉else␊ |
881 | ␉␉␉{␊ |
882 | ␉␉␉␉DBG("Incorrect parameter for option 'arch =' , please use x86_64 or i386\n");␊ |
883 | ␉␉␉}␊ |
884 | ␉␉}␊ |
885 | ␊ |
886 | ␉␉if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig))␊ |
887 | ␉␉{␊ |
888 | ␉␉␉if (strncmp(val, "i386", sizeof("i386") ) == 0)␊ |
889 | ␉␉␉{␊ |
890 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
891 | ␉␉␉}␊ |
892 | ␉␉}␊ |
893 | ␊ |
894 | ␉␉// Notify modules that we are attempting to boot␊ |
895 | ␉␉execute_hook("PreBoot", NULL, NULL, NULL, NULL);␊ |
896 | ␊ |
897 | ␉␉//--------------------------------------␊ |
898 | ␉␉getBoolForKey(kSkipKernelPatcher, &skipKernelPatcher, &bootInfo->chameleonConfig);␊ |
899 | ␊ |
900 | ␉␉// kernel patcher␊ |
901 | ␉␉if (!skipKernelPatcher)␊ |
902 | ␉␉{␊ |
903 | ␉␉␉const char␉*key = NULL;␊ |
904 | ␉␉␉int len = 0;␊ |
905 | ␉␉␉setupKernelConfigFile("kernel.plist");␊ |
906 | ␊ |
907 | ␉␉␉// looking at command line for kernel patcher setting and override where needed␊ |
908 | ␉␉␉if (getValueForKey(kKernelBooter_kexts, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
909 | ␉␉␉{␊ |
910 | ␉␉␉␉getBoolForKey(kKernelBooter_kexts, &KernelBooter_kexts, &bootInfo->chameleonConfig);␊ |
911 | ␉␉␉}␊ |
912 | ␉␉␉key = NULL; len = 0;␊ |
913 | ␊ |
914 | ␉␉␉if (getValueForKey(kKernelPm, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
915 | ␉␉␉{␊ |
916 | ␉␉␉␉getBoolForKey(kKernelPm, &KernelPm, &bootInfo->chameleonConfig);␊ |
917 | ␉␉␉}␊ |
918 | ␉␉␉key = NULL; len = 0;␊ |
919 | ␊ |
920 | ␉␉␉if (getValueForKey(kKernelLapicError, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
921 | ␉␉␉{␊ |
922 | ␉␉␉␉getBoolForKey(kKernelLapicError, &KernelLapicError, &bootInfo->chameleonConfig);␊ |
923 | ␉␉␉}␊ |
924 | ␉␉␉key = NULL; len = 0;␊ |
925 | ␊ |
926 | ␉␉␉if (getValueForKey(kKernelLapicVersion, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
927 | ␉␉␉{␊ |
928 | ␉␉␉␉getBoolForKey(kKernelLapicVersion, &KernelLapicVersion, &bootInfo->chameleonConfig);␊ |
929 | ␉␉␉}␊ |
930 | ␉␉␉key = NULL; len = 0;␊ |
931 | ␊ |
932 | ␉␉␉if (getValueForKey(kKernelHaswell, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
933 | ␉␉␉{␊ |
934 | ␉␉␉␉getBoolForKey(kKernelHaswell, &KernelHaswell, &bootInfo->chameleonConfig);␊ |
935 | ␉␉␉}␊ |
936 | ␉␉␉key = NULL; len = 0;␊ |
937 | ␊ |
938 | ␉␉␉if (getValueForKey(kKernelcpuFamily, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
939 | ␉␉␉{␊ |
940 | ␉␉␉␉getBoolForKey(kKernelcpuFamily, &KernelcpuFamily, &bootInfo->chameleonConfig);␊ |
941 | ␉␉␉}␊ |
942 | ␉␉␉key = NULL; len = 0;␊ |
943 | ␊ |
944 | ␉␉␉if (getValueForKey(kKernelSSE3, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
945 | ␉␉␉{␊ |
946 | ␉␉␉␉getBoolForKey(kKernelSSE3, &KernelSSE3, &bootInfo->chameleonConfig);␊ |
947 | ␉␉␉}␊ |
948 | ␉␉}␊ |
949 | ␊ |
950 | #if KEXTPATCH_SUPPORT␊ |
951 | ␉␉//-------------------------------------- kext patcher␊ |
952 | ␉␉getBoolForKey(kSkipKextsPatcher, &skipKextsPatcher, &bootInfo->chameleonConfig);␊ |
953 | ␊ |
954 | ␉␉// kext patcher␊ |
955 | ␉␉if (!skipKextsPatcher)␊ |
956 | ␉␉{␊ |
957 | ␉␉␉const char␉*key = NULL;␊ |
958 | ␉␉␉int␉␉len = 0;␊ |
959 | ␉␉␉setupKextConfigFile("kexts.plist");␊ |
960 | ␊ |
961 | ␉␉␉// looking at command line for kext patcher setting and override where needed␊ |
962 | ␉␉␉if (getValueForKey(kAICPMPatch, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
963 | ␉␉␉{␊ |
964 | ␉␉␉␉getBoolForKey(kAICPMPatch, &AICPMPatch, &bootInfo->chameleonConfig);␊ |
965 | ␉␉␉}␊ |
966 | ␊ |
967 | ␉␉␉key = NULL;␊ |
968 | ␉␉␉len = 0;␊ |
969 | ␉␉␉if (getValueForKey(kNVIDIAWebDrv, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
970 | ␉␉␉{␊ |
971 | ␉␉␉␉getBoolForKey(kNVIDIAWebDrv, &NVIDIAWebDrv, &bootInfo->chameleonConfig);␊ |
972 | ␉␉␉}␊ |
973 | ␊ |
974 | ␉␉␉key = NULL;␊ |
975 | ␉␉␉len = 0;␊ |
976 | ␉␉␉if (getValueForKey(kOrangeIconFixSata, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
977 | ␉␉␉{␊ |
978 | ␉␉␉␉getBoolForKey(kOrangeIconFixSata, &OrangeIconFixSata, &bootInfo->chameleonConfig);␊ |
979 | ␉␉␉}␊ |
980 | ␊ |
981 | ␉␉␉key = NULL;␊ |
982 | ␉␉␉len = 0;␊ |
983 | ␉␉␉if (getValueForKey(kTrimEnablerSata, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
984 | ␉␉␉{␊ |
985 | ␉␉␉␉getBoolForKey(kTrimEnablerSata, &TrimEnablerSata, &bootInfo->chameleonConfig);␊ |
986 | ␉␉␉}␊ |
987 | ␊ |
988 | ␉␉␉key = NULL;␊ |
989 | ␉␉␉len = 0;␊ |
990 | ␉␉␉if (getValueForKey(kAppleRTCPatch, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
991 | ␉␉␉{␊ |
992 | ␉␉␉␉getBoolForKey(kAppleRTCPatch, &AppleRTCPatch, &bootInfo->chameleonConfig);␊ |
993 | ␉␉␉}␊ |
994 | ␉␉}␊ |
995 | ␊ |
996 | ␉␉// -------------------------------------- kext patcher␊ |
997 | #endif␊ |
998 | ␊ |
999 | ␉␉if (gBootVolume->OSisInstaller)␊ |
1000 | ␉␉{␊ |
1001 | ␉␉␉isInstaller = true;␊ |
1002 | ␉␉}␊ |
1003 | ␊ |
1004 | ␉␉if (gBootVolume->OSisMacOSXUpgrade)␊ |
1005 | ␉␉{␊ |
1006 | ␉␉␉isMacOSXUpgrade = true;␊ |
1007 | ␉␉}␊ |
1008 | ␊ |
1009 | ␉␉if (gBootVolume->OSisOSXUpgrade)␊ |
1010 | ␉␉{␊ |
1011 | ␉␉␉isOSXUpgrade = true;␊ |
1012 | ␉␉}␊ |
1013 | ␊ |
1014 | ␉␉if (gBootVolume->OSisRecovery)␊ |
1015 | ␉␉{␊ |
1016 | ␉␉␉isRecoveryHD = true;␊ |
1017 | ␉␉}␊ |
1018 | ␊ |
1019 | ␉␉if ( !isRecoveryHD && !isInstaller && !isMacOSXUpgrade && !isOSXUpgrade )␊ |
1020 | ␉␉{␊ |
1021 | ␉␉␉if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig))␊ |
1022 | ␉␉␉{␊ |
1023 | ␉␉␉␉tryresume = true;␊ |
1024 | ␉␉␉␉tryresumedefault = true;␊ |
1025 | ␉␉␉}␊ |
1026 | ␉␉␉else␊ |
1027 | ␉␉␉{␊ |
1028 | ␉␉␉␉tryresumedefault = false;␊ |
1029 | ␉␉␉}␊ |
1030 | ␊ |
1031 | ␉␉␉if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig))␊ |
1032 | ␉␉␉{␊ |
1033 | ␉␉␉␉forceresume = false;␊ |
1034 | ␉␉␉}␊ |
1035 | ␊ |
1036 | ␉␉␉if (forceresume)␊ |
1037 | ␉␉␉{␊ |
1038 | ␉␉␉␉tryresume = true;␊ |
1039 | ␉␉␉␉tryresumedefault = false;␊ |
1040 | ␉␉␉}␊ |
1041 | ␊ |
1042 | ␉␉␉while (tryresume)␊ |
1043 | ␉␉␉{␊ |
1044 | ␉␉␉␉const char *tmp;␊ |
1045 | ␉␉␉␉BVRef bvr;␊ |
1046 | ␉␉␉␉if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->chameleonConfig))␊ |
1047 | ␉␉␉␉␉val = "/private/var/vm/sleepimage";␊ |
1048 | ␊ |
1049 | ␉␉␉␉// Do this first to be sure that root volume is mounted␊ |
1050 | ␉␉␉␉ret = GetFileInfo(0, val, &flags, &sleeptime);␊ |
1051 | ␊ |
1052 | ␉␉␉␉if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)␊ |
1053 | ␉␉␉␉␉break;␊ |
1054 | ␊ |
1055 | ␉␉␉␉// Can't check if it was hibernation Wake=y is required␊ |
1056 | ␉␉␉␉if (bvr->modTime == 0 && tryresumedefault)␊ |
1057 | ␉␉␉␉␉break;␊ |
1058 | ␊ |
1059 | ␉␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
1060 | ␉␉␉␉␉break;␊ |
1061 | ␊ |
1062 | ␉␉␉␉if (!forceresume && ((sleeptime+3)<bvr->modTime))␊ |
1063 | ␉␉␉␉{␊ |
1064 | #if DEBUG␊ |
1065 | ␉␉␉␉␉printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",␊ |
1066 | ␉␉␉␉␉␉␉bvr->modTime-sleeptime);␊ |
1067 | #endif␊ |
1068 | ␉␉␉␉␉break;␊ |
1069 | ␉␉␉␉}␊ |
1070 | ␊ |
1071 | ␉␉␉␉HibernateBoot((char *)val);␊ |
1072 | ␉␉␉␉break;␊ |
1073 | ␉␉␉}␊ |
1074 | ␉␉}␊ |
1075 | ␊ |
1076 | ␉␉if (!isRecoveryHD && !isInstaller && !isMacOSXUpgrade && !isOSXUpgrade )␊ |
1077 | ␉␉{␊ |
1078 | ␉␉␉getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);␊ |
1079 | ␉␉}␊ |
1080 | ␊ |
1081 | ␉␉if (useKernelCache)␊ |
1082 | ␉␉{␊ |
1083 | ␉␉␉do␊ |
1084 | ␉␉␉{␊ |
1085 | ␉␉␉␉// Determine the name of the Kernel Cache␊ |
1086 | ␉␉␉␉if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))␊ |
1087 | ␉␉␉␉{␊ |
1088 | ␉␉␉␉␉if (val[0] == '\\')␊ |
1089 | ␉␉␉␉␉{␊ |
1090 | ␉␉␉␉␉␉len--;␊ |
1091 | ␉␉␉␉␉␉val++;␊ |
1092 | ␉␉␉␉␉}␊ |
1093 | ␉␉␉␉␉/* FIXME: check len vs sizeof(kernelCacheFile) */␊ |
1094 | ␉␉␉␉␉strlcpy(kernelCacheFile, val, len + 1);␊ |
1095 | ␉␉␉␉}␊ |
1096 | ␉␉␉␉else␊ |
1097 | ␉␉␉␉{␊ |
1098 | ␉␉␉␉␉kernelCacheFile[0] = 0; // Use default kernel cache file␊ |
1099 | ␉␉␉␉}␊ |
1100 | ␊ |
1101 | ␉␉␉␉if (gOverrideKernel && kernelCacheFile[0] == 0)␊ |
1102 | ␉␉␉␉{␊ |
1103 | ␉␉␉␉␉DBG("Using a non default kernel (%s) without specifying 'Kernel Cache' path, KernelCache will not be used\n", bootInfo->bootFile);␊ |
1104 | ␉␉␉␉␉useKernelCache = false;␊ |
1105 | ␉␉␉␉␉break;␊ |
1106 | ␉␉␉␉}␊ |
1107 | ␊ |
1108 | ␉␉␉␉if (gMKextName[0] != 0)␊ |
1109 | ␉␉␉␉{␊ |
1110 | ␉␉␉␉␉DBG("Using a specific MKext Cache (%s), KernelCache will not be used\n", gMKextName);␊ |
1111 | ␉␉␉␉␉useKernelCache = false;␊ |
1112 | ␉␉␉␉␉break;␊ |
1113 | ␉␉␉␉}␊ |
1114 | ␊ |
1115 | ␉␉␉␉if (gBootFileType != kBlockDeviceType)␊ |
1116 | ␉␉␉␉{␊ |
1117 | ␉␉␉␉␉useKernelCache = false;␊ |
1118 | ␉␉␉␉}␊ |
1119 | ␊ |
1120 | ␉␉␉} while(0);␊ |
1121 | ␉␉}␊ |
1122 | ␉␉else␊ |
1123 | ␉␉{␊ |
1124 | ␉␉␉DBG("Kernel Cache using disabled by user.\n");␊ |
1125 | ␉␉}␊ |
1126 | ␊ |
1127 | ␉␉do␊ |
1128 | ␉␉{␊ |
1129 | ␉␉␉if (useKernelCache)␊ |
1130 | ␉␉␉{␊ |
1131 | ␉␉␉␉ret = LoadKernelCache(kernelCacheFile, &binary);␊ |
1132 | ␉␉␉␉if (ret >= 0)␊ |
1133 | ␉␉␉␉{␊ |
1134 | ␉␉␉␉␉break;␊ |
1135 | ␉␉␉␉}␊ |
1136 | ␉␉␉}␊ |
1137 | ␊ |
1138 | ␉␉␉bool bootFileWithDevice = false;␊ |
1139 | ␉␉␉// Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel␊ |
1140 | ␉␉␉if (strncmp(bootInfo->bootFile, "bt(", sizeof("bt(") ) == 0 ||␊ |
1141 | ␉␉␉␉strncmp(bootInfo->bootFile, "hd(", sizeof("hd(") ) == 0 ||␊ |
1142 | ␉␉␉␉strncmp(bootInfo->bootFile, "rd(", sizeof("rd(") ) == 0)␊ |
1143 | ␉␉␉{␊ |
1144 | ␉␉␉␉bootFileWithDevice = true;␊ |
1145 | ␉␉␉}␊ |
1146 | ␊ |
1147 | ␉␉␉// bootFile must start with a / if it not start with a device name␊ |
1148 | ␉␉␉if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/')␊ |
1149 | ␉␉␉{␊ |
1150 | ␉␉␉␉if ( MacOSVerCurrent < MacOSVer2Int("10.10") ) // Mavericks and older␊ |
1151 | ␉␉␉␉{␊ |
1152 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading /␊ |
1153 | ␉␉␉␉}␊ |
1154 | ␉␉␉␉else␊ |
1155 | ␉␉␉␉{␊ |
1156 | ␉␉␉␉␉// Yosemite and newer␊ |
1157 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), kDefaultKernelPathForYos"%s", bootInfo->bootFile); // Yosemite or El Capitan␊ |
1158 | ␉␉␉␉}␊ |
1159 | ␉␉␉}␊ |
1160 | ␉␉␉else␊ |
1161 | ␉␉␉{␊ |
1162 | ␉␉␉␉strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile));␊ |
1163 | ␉␉␉}␊ |
1164 | ␊ |
1165 | ␉␉␉// Try to load kernel image from alternate locations on boot helper partitions.␊ |
1166 | ␉␉␉ret = -1;␊ |
1167 | ␉␉␉if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice)␊ |
1168 | ␉␉␉{␊ |
1169 | ␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.P%s", bootFile);␊ |
1170 | ␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
1171 | ␉␉␉␉if (ret == -1)␊ |
1172 | ␉␉␉␉{␊ |
1173 | ␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.R%s", bootFile);␊ |
1174 | ␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
1175 | ␉␉␉␉␉if (ret == -1)␊ |
1176 | ␉␉␉␉␉{␊ |
1177 | ␉␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.S%s", bootFile);␊ |
1178 | ␉␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
1179 | ␉␉␉␉␉}␊ |
1180 | ␉␉␉␉}␊ |
1181 | ␉␉␉}␊ |
1182 | ␉␉␉if (ret == -1)␊ |
1183 | ␉␉␉{␊ |
1184 | ␉␉␉␉// No alternate location found, using the original kernel image path.␊ |
1185 | ␉␉␉␉strlcpy(bootFilePath, bootFile, sizeof(bootFilePath));␊ |
1186 | ␉␉␉}␊ |
1187 | ␊ |
1188 | ␉␉␉DBG("Loading kernel from: '%s' (%s)\n", gBootVolume->label, gBootVolume->type_name);␊ |
1189 | ␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
1190 | ␉␉␉if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
1191 | ␉␉␉{␊ |
1192 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
1193 | ␉␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
1194 | ␉␉␉}␊ |
1195 | ␉␉} while (0);␊ |
1196 | ␊ |
1197 | ␉␉clearActivityIndicator();␊ |
1198 | ␊ |
1199 | #if DEBUG␊ |
1200 | ␉␉printf("Pausing...");␊ |
1201 | ␉␉sleep(8);␊ |
1202 | #endif␊ |
1203 | ␊ |
1204 | ␉␉if (ret <= 0)␊ |
1205 | ␉␉{␊ |
1206 | ␉␉␉printf("Can't find boot file: '%s'\n", bootFile);␊ |
1207 | ␉␉␉sleep(1);␊ |
1208 | ␊ |
1209 | ␉␉␉if (gBootFileType == kNetworkDeviceType)␊ |
1210 | ␉␉␉{␊ |
1211 | ␉␉␉␉// Return control back to PXE. Don't unload PXE base code.␊ |
1212 | ␉␉␉␉gUnloadPXEOnExit = false;␊ |
1213 | ␉␉␉␉break;␊ |
1214 | ␉␉␉}␊ |
1215 | ␉␉␉pause();␊ |
1216 | ␊ |
1217 | ␉␉}␊ |
1218 | ␉␉else␊ |
1219 | ␉␉{␊ |
1220 | ␉␉␉/* Won't return if successful. */␊ |
1221 | ␉␉␉ret = ExecKernel(binary);␊ |
1222 | ␉␉}␊ |
1223 | ␉}␊ |
1224 | ␊ |
1225 | ␉// chainboot␊ |
1226 | ␉if (status == 1)␊ |
1227 | ␉{␊ |
1228 | ␉␉// if we are already in graphics-mode,␊ |
1229 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
1230 | ␉␉{␊ |
1231 | ␉␉␉setVideoMode( VGA_TEXT_MODE ); // switch back to text mode.␊ |
1232 | ␉␉}␊ |
1233 | ␉}␊ |
1234 | ␊ |
1235 | ␉if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit)␊ |
1236 | ␉{␊ |
1237 | ␉␉nbpUnloadBaseCode();␊ |
1238 | ␉}␊ |
1239 | ␊ |
1240 | #if DEBUG_INTERRUPTS␊ |
1241 | ␉if (interruptsAvailable)␊ |
1242 | ␉{␊ |
1243 | ␉␉DisableInterrupts();␊ |
1244 | ␉}␊ |
1245 | #endif␊ |
1246 | ␊ |
1247 | }␊ |
1248 | ␊ |
1249 | // =========================================================================␊ |
1250 | //␊ |
1251 | void setupBooterArgs()␊ |
1252 | {␊ |
1253 | ␉bool KPRebootOption␉= false; // I don't want this by default ( It makes me angry because I do not see the reason for the panic)+␊ |
1254 | //␉bool HiDPIOption␉= false; // (Disabled by default) 10.8+␊ |
1255 | //␉bool FlagBlackOption␉= false; // (Disabled by default) 10.10+␊ |
1256 | ␊ |
1257 | ␉// OS X Lion 10.7␊ |
1258 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.7") ) // Lion and Up!␊ |
1259 | ␉{␊ |
1260 | ␉␉// Pike R. Alpha: Adding a 16 KB log space.␊ |
1261 | ␉␉bootArgs->performanceDataSize␉␉= 0;␊ |
1262 | ␉␉bootArgs->performanceDataStart␉␉= 0;␊ |
1263 | ␊ |
1264 | ␉␉// Pike R. Alpha: AppleKeyStore.kext␊ |
1265 | ␉␉bootArgs->keyStoreDataSize␉␉= 0;␊ |
1266 | ␉␉bootArgs->keyStoreDataStart␉␉= 0;␊ |
1267 | ␊ |
1268 | ␉␉bootArgs->bootMemSize␉␉␉= 0;␊ |
1269 | ␉␉bootArgs->bootMemStart␉␉␉= 0;␊ |
1270 | ␉}␊ |
1271 | ␊ |
1272 | ␉// OS X Mountain Lion 10.8␊ |
1273 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.8") ) // Mountain Lion and Up!␊ |
1274 | ␉{␊ |
1275 | ␉␉// cparm␊ |
1276 | ␉␉getBoolForKey(kRebootOnPanic, &KPRebootOption, &bootInfo->chameleonConfig);␊ |
1277 | ␉␉if ( KPRebootOption )␊ |
1278 | ␉␉{␊ |
1279 | ␉␉␉bootArgs->flags |= kBootArgsFlagRebootOnPanic;␊ |
1280 | ␉␉}␊ |
1281 | ␊ |
1282 | ␉␉// cparm␊ |
1283 | ␉␉getBoolForKey(kEnableHiDPI, &HiDPIOption, &bootInfo->chameleonConfig);␊ |
1284 | ␊ |
1285 | ␉␉if ( HiDPIOption )␊ |
1286 | ␉␉{␊ |
1287 | ␉␉␉bootArgs->flags |= kBootArgsFlagHiDPI;␊ |
1288 | ␉␉}␊ |
1289 | ␉}␊ |
1290 | ␊ |
1291 | ␉// OS X Yosemite 10.10␊ |
1292 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.10") ) // Yosemite and Up!␊ |
1293 | ␉{␊ |
1294 | ␉␉// Pike R. Alpha␊ |
1295 | ␉␉getBoolForKey(kBlackMode, &FlagBlackOption, &bootInfo->chameleonConfig);␊ |
1296 | ␉␉if ( FlagBlackOption )␊ |
1297 | ␉␉{␊ |
1298 | ␉␉␉// bootArgs->flags |= kBootArgsFlagBlack;␊ |
1299 | ␉␉␉bootArgs->flags |= kBootArgsFlagBlackBg; // Micky1979␊ |
1300 | ␉␉}␊ |
1301 | ␉}␊ |
1302 | ␊ |
1303 | ␉// OS X El Capitan 10.11␊ |
1304 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.11") ) // El Capitan, Sierra and High Sierra!␊ |
1305 | ␉{␊ |
1306 | ␉␉// ErmaC␊ |
1307 | ␉␉verbose("\n");␊ |
1308 | ␉␉int␉csrValue;␊ |
1309 | ␊ |
1310 | ␉␉/*␊ |
1311 | ␉␉ * A special BootArgs flag "kBootArgsFlagCSRBoot"␊ |
1312 | ␉␉ * is set in the Recovery or Installation environment.␊ |
1313 | ␉␉ * This flag is kind of overkill by turning off all the protections␊ |
1314 | ␉␉ */␊ |
1315 | ␊ |
1316 | ␉␉if (isRecoveryHD || isInstaller || isOSXUpgrade || isMacOSXUpgrade)␊ |
1317 | ␉␉{␊ |
1318 | ␉␉␉// SIP can be controlled with or without FileNVRAM.kext (Pike R. Alpha)␊ |
1319 | ␉␉␉bootArgs->flags␉|=␉(kBootArgsFlagCSRActiveConfig + kBootArgsFlagCSRConfigMode + kBootArgsFlagCSRBoot + kBootArgsFlagInstallUI);␊ |
1320 | ␉␉}␊ |
1321 | ␉␉else␊ |
1322 | ␉␉{␊ |
1323 | ␉␉␉bootArgs->flags␉|= kBootArgsFlagCSRActiveConfig;␊ |
1324 | ␉␉}␊ |
1325 | ␊ |
1326 | ␉␉// Set limit to 8bit␊ |
1327 | ␉␉if ( getIntForKey(kCsrActiveConfig, &csrValue, &bootInfo->chameleonConfig) && (csrValue >= 0 && csrValue <= 255) )␊ |
1328 | ␉␉{␊ |
1329 | ␉␉␉bootArgs->csrActiveConfig␉= csrValue;␊ |
1330 | ␉␉␉csrInfo(csrValue, 1);␊ |
1331 | ␉␉}␊ |
1332 | ␉␉else␊ |
1333 | ␉␉{␊ |
1334 | ␉␉␉// zenith432␊ |
1335 | ␉␉␉bootArgs->csrActiveConfig␉= 0x67;␊ |
1336 | ␉␉␉csrInfo(0x67, 0);␊ |
1337 | ␊ |
1338 | ␉␉}␊ |
1339 | ␊ |
1340 | ␊ |
1341 | // ===============================================================================␊ |
1342 | ␊ |
1343 | ␉␉bootArgs->csrCapabilities␉␉= CSR_VALID_FLAGS;␊ |
1344 | ␉␉bootArgs->boot_SMC_plimit␉␉= 0;␊ |
1345 | ␉}␊ |
1346 | }␊ |
1347 | ␊ |
1348 | // =========================================================================␊ |
1349 | // ErmaC␊ |
1350 | void csrInfo(int csrValue, bool custom)␊ |
1351 | {␊ |
1352 | #define CSR_BITS 0x080␊ |
1353 | ␊ |
1354 | ␉int mask = CSR_BITS;␊ |
1355 | ␉verbose("System Integrity Protection status: %s ", (csrValue == 0) ? "enabled":"disabled");␊ |
1356 | ␉verbose("(%s Configuration).\nCsrActiveConfig = 0x%02X (", custom ? "Custom":"Default", csrValue);␊ |
1357 | ␊ |
1358 | ␉// Display integer number into binary using bitwise operator␊ |
1359 | ␉((csrValue & 0x020) == 0) ? verbose("0"): verbose("1");␊ |
1360 | ␉while (mask != 0)␊ |
1361 | ␉{␊ |
1362 | ␉␉( ((csrValue & mask) == 0) ? verbose("0"): verbose("1") );␊ |
1363 | ␉␉mask = mask >> 1; // Right Shift␊ |
1364 | ␉}␊ |
1365 | ␉verbose(")\n");␊ |
1366 | ␉if (csrValue != 0)␊ |
1367 | ␉{␊ |
1368 | ␉␉verbose("\nConfiguration:\n");␊ |
1369 | ␉␉verbose("Kext Signing: %s\n", ((csrValue & 0x001) == 0) ? "enabled":"disabled"); /* (1 << 0) Allow untrusted kexts */␊ |
1370 | ␉␉verbose("Filesystem Protections: %s\n", ((csrValue & 0x002) == 0) ? "enabled":"disabled"); /* (1 << 1) Allow unrestricted file system. */␊ |
1371 | ␉␉verbose("Task for PID: %s\n", ((csrValue & 0x004) == 0) ? "enabled":"disabled"); /* (1 << 2) */␊ |
1372 | ␉␉verbose("Debugging Restrictions: %s\n", ((csrValue & 0x008) == 0) ? "enabled":"disabled"); /* (1 << 3) */␊ |
1373 | ␉␉verbose("Apple Internal: %s\n", ((csrValue & 0x010) == 0) ? "enabled":"disabled"); /* (1 << 4) */␊ |
1374 | ␉␉verbose("DTrace Restrictions: %s\n", ((csrValue & 0x020) == 0) ? "enabled":"disabled"); /* (1 << 5) Allow unrestricted dtrace */␊ |
1375 | ␉␉verbose("NVRAM Protections: %s\n", ((csrValue & 0x040) == 0) ? "enabled":"disabled"); /* (1 << 6) Allow unrestricted NVRAM */␊ |
1376 | ␉␉verbose("Device configuration: %s\n", ((csrValue & 0x080) == 0) ? "enabled":"disabled"); /* (1 << 7) Allow device configuration */␊ |
1377 | ␉␉verbose("BaseSystem Verification: %s\n", ((csrValue & 0x100) == 0) ? "enabled":"disabled"); /* (1 << 8) Allow any Recovery OS */␊ |
1378 | ␉}␊ |
1379 | ␉verbose("\n");␊ |
1380 | }␊ |
1381 | ␊ |
1382 | // =========================================================================␊ |
1383 | ␊ |
1384 | /*!␊ |
1385 | ␉Selects a new BIOS device, taking care to update the global state appropriately.␊ |
1386 | */␊ |
1387 | /*␊ |
1388 | static void selectBiosDevice(void)␊ |
1389 | {␊ |
1390 | ␉struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);␊ |
1391 | ␉CacheReset();␊ |
1392 | ␉diskFreeMap(oldMap);␊ |
1393 | ␉oldMap = NULL;␊ |
1394 | ␊ |
1395 | ␉int dev = selectAlternateBootDevice(gBIOSDev);␊ |
1396 | ␊ |
1397 | ␉BVRef bvchain = scanBootVolumes(dev, 0);␊ |
1398 | ␉BVRef bootVol = selectBootVolume(bvchain);␊ |
1399 | ␉gBootVolume = bootVol;␊ |
1400 | ␉setRootVolume(bootVol);␊ |
1401 | ␉gBIOSDev = dev;␊ |
1402 | }␊ |
1403 | */␊ |
1404 | ␊ |
1405 | // =========================================================================␊ |
1406 | bool checkOSVersion(const char *version)␊ |
1407 | {␊ |
1408 | ␉if ( '\0' != version[4] )␊ |
1409 | ␉{␊ |
1410 | ␉␉return !memcmp(&gMacOSVersion[0], &version[0], 5);␊ |
1411 | ␉}␊ |
1412 | ␉else␊ |
1413 | ␉{␊ |
1414 | ␉␉return !memcmp(&gMacOSVersion[0], &version[0], 4);␊ |
1415 | ␉}␊ |
1416 | }␊ |
1417 | ␊ |
1418 | uint32_t getMacOSVerCurrent()␊ |
1419 | {␊ |
1420 | ␉MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion);␊ |
1421 | ␉return MacOSVerCurrent;␊ |
1422 | }␊ |
1423 | ␊ |
1424 | // =========================================================================␊ |
1425 | unsigned long Adler32(unsigned char *buf, long len)␊ |
1426 | {␊ |
1427 | #define BASE 65521L /* largest prime smaller than 65536 */␊ |
1428 | #define NMAX 5000␊ |
1429 | // NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1␊ |
1430 | ␊ |
1431 | #define DO1(buf, i)␉{s1 += buf[i]; s2 += s1;}␊ |
1432 | #define DO2(buf, i)␉DO1(buf, i); DO1(buf, i + 1);␊ |
1433 | #define DO4(buf, i)␉DO2(buf, i); DO2(buf, i + 2);␊ |
1434 | #define DO8(buf, i)␉DO4(buf, i); DO4(buf, i + 4);␊ |
1435 | #define DO16(buf)␉DO8(buf, 0); DO8(buf, 8);␊ |
1436 | ␊ |
1437 | ␉int k;␊ |
1438 | ␊ |
1439 | ␉unsigned long s1 = 1; // adler & 0xffff;␊ |
1440 | ␉unsigned long s2 = 0; // (adler >> 16) & 0xffff;␊ |
1441 | ␉unsigned long result;␊ |
1442 | ␊ |
1443 | ␉while (len > 0)␊ |
1444 | ␉{␊ |
1445 | ␉␉k = len < NMAX ? len : NMAX;␊ |
1446 | ␉␉len -= k;␊ |
1447 | ␉␉while (k >= 16)␊ |
1448 | ␉␉{␊ |
1449 | ␉␉␉DO16(buf);␊ |
1450 | ␉␉␉buf += 16;␊ |
1451 | ␉␉␉k -= 16;␊ |
1452 | ␉␉}␊ |
1453 | ␊ |
1454 | ␉␉if (k != 0)␊ |
1455 | ␉␉{␊ |
1456 | ␉␉␉do␊ |
1457 | ␉␉␉{␊ |
1458 | ␉␉␉␉s1 += *buf++;␊ |
1459 | ␉␉␉␉s2 += s1;␊ |
1460 | ␉␉␉} while (--k);␊ |
1461 | ␉␉}␊ |
1462 | ␊ |
1463 | ␉␉s1 %= BASE;␊ |
1464 | ␉␉s2 %= BASE;␊ |
1465 | ␉}␊ |
1466 | ␊ |
1467 | ␉result = (s2 << 16) | s1;␊ |
1468 | ␊ |
1469 | ␉return OSSwapHostToBigInt32(result);␊ |
1470 | }␊ |
1471 | |