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 | ␉␉␉␉else if ( MacOSVerCurrent > MacOSVer2Int("10.12") && MacOSVerCurrent < MacOSVer2Int("10.14") )␊ |
426 | ␉␉␉␉{␊ |
427 | ␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kHSierraInstallerDataFolder);␊ |
428 | ␉␉␉␉}␊ |
429 | ␉␉␉}␊ |
430 | ␉␉␉else if (isRecoveryHD)␊ |
431 | ␉␉␉{␊ |
432 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheRecoveryHD);␊ |
433 | ␉␉␉}␊ |
434 | ␉␉␉else␊ |
435 | ␉␉␉{␊ |
436 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);␊ |
437 | ␉␉␉}␊ |
438 | ␊ |
439 | ␉␉␉verbose("Kernel Cache file path (Mac OS X 10.7 and newer): %s\n", kernelCacheFile);␊ |
440 | ␊ |
441 | ␉␉}␊ |
442 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.9") && MacOSVerCurrent < MacOSVer2Int("10.10") )␊ |
443 | ␉␉{␊ |
444 | ␉␉␉// Mavericks prelinked cache file␊ |
445 | ␉␉␉// for 10.9␊ |
446 | ␉␉␉if (isOSXUpgrade)␊ |
447 | ␉␉␉{␊ |
448 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", "/OS X Install Data/");␊ |
449 | ␉␉␉}␊ |
450 | ␉␉␉else if (isInstaller)␊ |
451 | ␉␉␉{␊ |
452 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheInstallerNew);␊ |
453 | ␉␉␉}␊ |
454 | ␉␉␉else if (isRecoveryHD)␊ |
455 | ␉␉␉{␊ |
456 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheRecoveryHD);␊ |
457 | ␉␉␉}␊ |
458 | ␉␉␉else␊ |
459 | ␉␉␉{␊ |
460 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);␊ |
461 | ␉␉␉}␊ |
462 | ␊ |
463 | ␉␉␉verbose("Kernel Cache file path (OS X 10.9): %s\n", kernelCacheFile);␊ |
464 | ␊ |
465 | ␉␉}␊ |
466 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.10") && MacOSVerCurrent < MacOSVer2Int("10.11") )␊ |
467 | ␉␉{␊ |
468 | ␉␉␉// Yosemite prelink kernel cache file␊ |
469 | ␉␉␉// for 10.10 and 10.11␊ |
470 | ␉␉␉if (isOSXUpgrade)␊ |
471 | ␉␉␉{␊ |
472 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", "/OS X Install Data/");␊ |
473 | ␉␉␉}␊ |
474 | ␉␉␉else if (isInstaller)␊ |
475 | ␉␉␉{␊ |
476 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheInstallerNew);␊ |
477 | ␉␉␉}␊ |
478 | ␉␉␉else if (isRecoveryHD)␊ |
479 | ␉␉␉{␊ |
480 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheRecoveryHD);␊ |
481 | ␉␉␉}␊ |
482 | ␉␉␉else␊ |
483 | ␉␉␉{␊ |
484 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCachePathYosemite);␊ |
485 | ␉␉␉}␊ |
486 | ␊ |
487 | ␉␉␉verbose("Kernel Cache file path (OS X 10.10): %s\n", kernelCacheFile);␊ |
488 | ␉␉}␊ |
489 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.11") )␊ |
490 | ␉␉{␊ |
491 | ␉␉␉// El Capitan on prelinked kernel cache file␊ |
492 | ␉␉␉// for 10.10 and 10.11␊ |
493 | ␉␉␉if (isOSXUpgrade)␊ |
494 | ␉␉␉{␊ |
495 | ␉␉␉␉if ( MacOSVerCurrent >= MacOSVer2Int("10.13") )␊ |
496 | ␉␉␉␉{␊ |
497 | ␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile),␊ |
498 | ␉␉␉␉␉␉"%sprelinkedkernel",␊ |
499 | ␉␉␉␉␉␉"/macOS Install Data/Locked Files/Boot Files/");␊ |
500 | ␉␉␉␉}␊ |
501 | ␉␉␉␉else␊ |
502 | ␉␉␉␉{␊ |
503 | ␉␉␉␉␉snprintf(kernelCacheFile,␊ |
504 | ␉␉␉␉␉␉sizeof(kernelCacheFile),␊ |
505 | ␉␉␉␉␉␉"%sprelinkedkernel",␊ |
506 | ␉␉␉␉␉␉"/OS X Install Data/");␊ |
507 | ␉␉␉␉}␊ |
508 | ␊ |
509 | ␉␉␉}␊ |
510 | ␉␉␉else if (isInstaller)␊ |
511 | ␉␉␉{␊ |
512 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCacheInstallerNew);␊ |
513 | ␉␉␉}␊ |
514 | ␉␉␉else if (isRecoveryHD)␊ |
515 | ␉␉␉{␊ |
516 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCacheRecoveryHD);␊ |
517 | ␉␉␉}␊ |
518 | ␉␉␉else␊ |
519 | ␉␉␉{␊ |
520 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCachePathYosemite);␊ |
521 | ␉␉␉}␊ |
522 | ␊ |
523 | ␉␉␉verbose("Kernel Cache file path (OS X 10.11 and newer): %s\n", kernelCacheFile);␊ |
524 | ␉␉}␊ |
525 | ␉}␊ |
526 | ␊ |
527 | ␉// Check if the kernel cache file exists␊ |
528 | ␉ret = -1;␊ |
529 | ␊ |
530 | ␉if (gBootVolume->flags & kBVFlagBooter)␊ |
531 | ␉{␊ |
532 | ␉␉if (isRecoveryHD)␊ |
533 | ␉␉{␊ |
534 | ␉␉␉strncpy(kernelCachePath, "/com.apple.recovery.boot/prelinkedkernel", sizeof(kernelCachePath) );␊ |
535 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
536 | ␊ |
537 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
538 | ␉␉␉{␊ |
539 | ␉␉␉␉strncpy(kernelCachePath, "/com.apple.recovery.boot/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 (isInstaller)␊ |
549 | ␉␉{␊ |
550 | ␉␉␉strncpy(kernelCachePath, "/.IABootFiles/prelinkedkernel", sizeof(kernelCachePath) );␊ |
551 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
552 | ␊ |
553 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
554 | ␉␉␉{␊ |
555 | ␉␉␉␉strncpy(kernelCachePath, "/.IABootFiles/kernelcache", sizeof(kernelCachePath) );␊ |
556 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
557 | ␊ |
558 | ␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
559 | ␉␉␉␉{␊ |
560 | ␉␉␉␉␉ret = -1;␊ |
561 | ␉␉␉␉}␊ |
562 | ␉␉␉}␊ |
563 | ␉␉}␊ |
564 | ␉␉else if (isMacOSXUpgrade)␊ |
565 | ␉␉{␊ |
566 | ␉␉␉strncpy(kernelCachePath, "/Mac OS X Install Data/kernelcache", sizeof(kernelCachePath) );␊ |
567 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
568 | ␊ |
569 | ␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
570 | ␉␉␉{␊ |
571 | ␉␉␉␉ret = -1;␊ |
572 | ␉␉␉}␊ |
573 | ␉␉}␊ |
574 | ␉␉else if (isOSXUpgrade)␊ |
575 | ␉␉{␊ |
576 | ␉␉␉strncpy(kernelCachePath,␊ |
577 | ␉␉␉␉"/macOS Install Data/Locked Files/Boot Files/prelinkedkernel",␊ |
578 | ␉␉␉␉sizeof(kernelCachePath) );␊ |
579 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
580 | ␊ |
581 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
582 | ␉␉␉{␊ |
583 | ␉␉␉␉strncpy(kernelCachePath, "/OS X Install Data/prelinkedkernel", sizeof(kernelCachePath) );␊ |
584 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
585 | ␊ |
586 | ␉␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
587 | ␉␉␉␉{␊ |
588 | ␉␉␉␉␉strncpy(kernelCachePath, "/OS X Install Data/kernelcache", sizeof(kernelCachePath) );␊ |
589 | ␉␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
590 | ␊ |
591 | ␉␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
592 | ␉␉␉␉␉{␊ |
593 | ␉␉␉␉␉␉ret = -1;␊ |
594 | ␉␉␉␉␉}␊ |
595 | ␉␉␉␉}␊ |
596 | ␉␉␉}␊ |
597 | ␉␉}␊ |
598 | ␉␉else␊ |
599 | ␉␉{␊ |
600 | ␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.P/%s", kernelCacheFile);␊ |
601 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
602 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
603 | ␉␉␉{␊ |
604 | ␉␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.R/%s", kernelCacheFile);␊ |
605 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
606 | ␊ |
607 | ␉␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
608 | ␉␉␉␉{␊ |
609 | ␉␉␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.S/%s", kernelCacheFile);␊ |
610 | ␉␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
611 | ␊ |
612 | ␉␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
613 | ␉␉␉␉␉{␊ |
614 | ␉␉␉␉␉␉ret = -1;␊ |
615 | ␉␉␉␉␉}␊ |
616 | ␉␉␉␉}␊ |
617 | ␉␉␉}␊ |
618 | ␉␉}␊ |
619 | ␉}␊ |
620 | ␊ |
621 | ␉// If not found, use the original kernel cache path.␊ |
622 | ␉if (ret == -1)␊ |
623 | ␉{␊ |
624 | ␉␉strlcpy(kernelCachePath, kernelCacheFile, sizeof(kernelCachePath));␊ |
625 | ␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
626 | ␊ |
627 | ␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
628 | ␉␉{␊ |
629 | ␉␉␉ret = -1;␊ |
630 | ␉␉}␊ |
631 | ␉}␊ |
632 | ␊ |
633 | ␉// Exit if kernel cache file wasn't found␊ |
634 | ␉if (ret == -1)␊ |
635 | ␉{␊ |
636 | ␉␉DBG("No Kernel Cache File '%s' found\n", kernelCacheFile);␊ |
637 | ␉␉return -1;␊ |
638 | ␉}␊ |
639 | ␊ |
640 | ␉if ( !isInstaller && !isRecoveryHD && !isMacOSXUpgrade && !isOSXUpgrade )␊ |
641 | ␉{␊ |
642 | ␉␉// Check if the kernel cache file is more recent (mtime)␊ |
643 | ␉␉// than the kernel file or the S/L/E directory␊ |
644 | ␉␉ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);␊ |
645 | ␊ |
646 | ␉␉// Check if the kernel file is more recent than the cache file␊ |
647 | ␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat) && (kerneltime > cachetime))␊ |
648 | ␉␉{␊ |
649 | ␉␉␉DBG("Kernel file '%s' is more recent than Kernel Cache '%s'! Ignoring Kernel Cache.\n", bootInfo->bootFile, kernelCacheFile);␊ |
650 | ␉␉␉return -1;␊ |
651 | ␉␉}␊ |
652 | ␊ |
653 | ␉␉ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);␊ |
654 | ␊ |
655 | ␉␉// Check if the S/L/E directory time is more recent than the cache file␊ |
656 | ␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory) && (exttime > cachetime))␊ |
657 | ␉␉{␊ |
658 | ␉␉␉DBG("Folder '/System/Library/Extensions' is more recent than Kernel Cache file '%s'! Ignoring Kernel Cache.\n", kernelCacheFile);␊ |
659 | ␉␉␉return -1;␊ |
660 | ␉␉}␊ |
661 | ␉}␊ |
662 | ␊ |
663 | ␉// Since the kernel cache file exists and is the most recent try to load it␊ |
664 | ␉DBG("Loading Kernel Cache from: '%s%s' (%s)\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name);␊ |
665 | ␊ |
666 | ␉ret = LoadThinFatFile(kernelCachePath, binary);␊ |
667 | ␉return ret; // ret contain the length of the binary␊ |
668 | }␊ |
669 | ␊ |
670 | //==========================================================================␊ |
671 | // This is the entrypoint from real-mode which functions exactly as it did␊ |
672 | // before. Multiboot does its own runtime initialization, does some of its␊ |
673 | // own things, and then calls common_boot.␊ |
674 | void boot(int biosdev)␊ |
675 | {␊ |
676 | ␉// Enable A20 gate before accessing memory above 1Mb.␊ |
677 | ␉// Note: malloc_init(), called via initialize_runtime() writes␊ |
678 | ␉// memory >= 1Mb, so A20 must be enabled before calling it. - zenith432␊ |
679 | ␉zeroBSS();␊ |
680 | ␉enableA20();␊ |
681 | ␉malloc_init(0, 0, 0, malloc_error);␊ |
682 | ␉common_boot(biosdev);␊ |
683 | }␊ |
684 | ␊ |
685 | //==========================================================================␊ |
686 | // The 'main' function for the booter. Called by boot0 when booting␊ |
687 | // from a block device, or by the network booter.␊ |
688 | //␊ |
689 | // arguments:␊ |
690 | //␉ biosdev - Value passed from boot1/NBP to specify the device␊ |
691 | //␉␉␉ that the booter was loaded from.␊ |
692 | //␊ |
693 | // If biosdev is kBIOSDevNetwork, then this function will return if␊ |
694 | // booting was unsuccessful. This allows the PXE firmware to try the␊ |
695 | // next boot device on its list.␊ |
696 | void common_boot(int biosdev)␊ |
697 | {␊ |
698 | ␉bool␉ ␉␉quiet;␊ |
699 | ␉bool␉ ␉␉firstRun = true;␊ |
700 | ␉bool␉ ␉␉instantMenu;␊ |
701 | ␉bool␉ ␉␉rescanPrompt;␊ |
702 | ␉int␉␉␉status;␊ |
703 | ␉unsigned int␉␉allowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;␊ |
704 | ␉unsigned int␉␉denyBVFlags = kBVFlagEFISystem;␊ |
705 | ␊ |
706 | ␉// Set reminder to unload the PXE base code. Neglect to unload␊ |
707 | ␉// the base code will result in a hang or kernel panic.␊ |
708 | ␉gUnloadPXEOnExit = true;␊ |
709 | ␊ |
710 | ␉// Record the device that the booter was loaded from.␊ |
711 | ␉gBIOSDev = biosdev & kBIOSDevMask;␊ |
712 | ␊ |
713 | ␉// Initialize boot-log␊ |
714 | ␉initBooterLog();␊ |
715 | ␊ |
716 | #if DEBUG_INTERRUPTS␊ |
717 | ␉// Enable interrupts␊ |
718 | ␉interruptsAvailable = SetupInterrupts();␊ |
719 | ␉if (interruptsAvailable)␊ |
720 | ␉{␊ |
721 | ␉␉EnableInterrupts();␊ |
722 | ␉}␊ |
723 | #endif␊ |
724 | ␊ |
725 | ␉// Initialize boot info structure.␊ |
726 | ␉initKernBootStruct();␊ |
727 | ␊ |
728 | ␉// Setup VGA text mode.␊ |
729 | ␉// Not sure if it is safe to call setVideoMode() before the␊ |
730 | ␉// config table has been loaded. Call video_mode() instead.␊ |
731 | #if DEBUG␊ |
732 | ␉printf("before video_mode\n");␊ |
733 | #endif␊ |
734 | ␉video_mode( 2 ); // 80x25 mono text mode.␊ |
735 | #if DEBUG␊ |
736 | ␉printf("after video_mode\n");␊ |
737 | #endif␊ |
738 | ␊ |
739 | ␉// Scan and record the system's hardware information.␊ |
740 | ␉scan_platform();␊ |
741 | ␊ |
742 | ␉// First get info for boot volume.␊ |
743 | ␉scanBootVolumes(gBIOSDev, 0);␊ |
744 | ␉bvChain = getBVChainForBIOSDev(gBIOSDev);␊ |
745 | ␉setBootGlobals(bvChain);␊ |
746 | ␊ |
747 | ␉// Load boot.plist config file␊ |
748 | ␉status = loadChameleonConfig(&bootInfo->chameleonConfig, bvChain);␊ |
749 | ␊ |
750 | ␉if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet)␊ |
751 | ␉{␊ |
752 | ␉␉gBootMode |= kBootModeQuiet;␊ |
753 | ␉}␊ |
754 | ␊ |
755 | ␉// Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config␊ |
756 | ␉if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->chameleonConfig) && instantMenu)␊ |
757 | ␉{␊ |
758 | ␉␉firstRun = false;␊ |
759 | ␉}␊ |
760 | ␊ |
761 | ␉// Loading preboot ramdisk if exists.␊ |
762 | ␉loadPrebootRAMDisk();␊ |
763 | ␊ |
764 | ␉// Disable rescan option by default␊ |
765 | ␉gEnableCDROMRescan = false;␊ |
766 | ␊ |
767 | ␉// Enable it with Rescan=y in system config␊ |
768 | ␉if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->chameleonConfig)␉&& gEnableCDROMRescan)␊ |
769 | ␉{␊ |
770 | ␉␉gEnableCDROMRescan = true;␊ |
771 | ␉}␊ |
772 | ␊ |
773 | ␉// Disable rescanPrompt option by default␊ |
774 | ␉rescanPrompt = false;␊ |
775 | ␊ |
776 | ␉// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.␊ |
777 | ␉if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev))␊ |
778 | ␉{␊ |
779 | ␉␉gEnableCDROMRescan = promptForRescanOption();␊ |
780 | ␉}␊ |
781 | ␊ |
782 | ␉// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.␊ |
783 | ␉if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->chameleonConfig) && gScanSingleDrive)␊ |
784 | ␉{␊ |
785 | ␉␉gScanSingleDrive = true;␊ |
786 | ␉}␊ |
787 | ␊ |
788 | ␉// Create a list of partitions on device(s).␊ |
789 | ␉if (gScanSingleDrive)␊ |
790 | ␉{␊ |
791 | ␉␉scanBootVolumes(gBIOSDev, &bvCount);␊ |
792 | ␉}␊ |
793 | ␉else␊ |
794 | ␉{␊ |
795 | ␉␉scanDisks(gBIOSDev, &bvCount);␊ |
796 | ␉}␊ |
797 | ␊ |
798 | ␉// Create a separated bvr chain using the specified filters.␊ |
799 | ␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
800 | ␊ |
801 | ␉gBootVolume = selectBootVolume(bvChain);␊ |
802 | ␊ |
803 | ␉// Intialize module system␊ |
804 | ␉init_module_system();␊ |
805 | ␊ |
806 | #if DEBUG␊ |
807 | ␉printf("Default: %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",␊ |
808 | ␉␉gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);␊ |
809 | ␉printf("bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",␊ |
810 | ␉␉gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);␊ |
811 | ␉getchar();␊ |
812 | #endif␊ |
813 | ␊ |
814 | ␉useGUI = true;␊ |
815 | ␉// Override useGUI default␊ |
816 | ␉getBoolForKey(kGUIKey, &useGUI, &bootInfo->chameleonConfig);␊ |
817 | ␉if (useGUI && initGUI())␊ |
818 | ␉{␊ |
819 | ␉␉// initGUI() returned with an error, disabling GUI.␊ |
820 | ␉␉useGUI = false;␊ |
821 | ␉}␊ |
822 | ␊ |
823 | ␉setBootGlobals(bvChain);␊ |
824 | ␊ |
825 | ␉// Parse args, load and start kernel.␊ |
826 | ␉while (1)␊ |
827 | ␉{␊ |
828 | ␉␉bool␉␉tryresume, tryresumedefault, forceresume;␊ |
829 | ␉␉bool␉␉useKernelCache = true; // by default try to use the prelinked kernel␊ |
830 | ␉␉const char␉*val;␊ |
831 | ␉␉int␉␉␉len, ret = -1;␊ |
832 | ␉␉long␉␉flags;␊ |
833 | ␉␉u_int32_t␉sleeptime, time;␊ |
834 | ␉␉void␉␉*binary = (void *)kLoadAddr;␊ |
835 | ␊ |
836 | ␉␉char␉␉bootFile[sizeof(bootInfo->bootFile)];␊ |
837 | ␉␉char␉␉bootFilePath[512];␊ |
838 | ␉␉char␉␉kernelCacheFile[512];␊ |
839 | ␊ |
840 | ␉␉// Initialize globals.␊ |
841 | ␉␉sysConfigValid = false;␊ |
842 | ␉␉gErrors␉␉ = false;␊ |
843 | ␊ |
844 | ␉␉status = getBootOptions(firstRun);␊ |
845 | ␉␉firstRun = false;␊ |
846 | ␉␉if (status == -1) continue;␊ |
847 | ␊ |
848 | ␉␉status = processBootOptions();␊ |
849 | ␉␉// Status == 1 means to chainboot␊ |
850 | ␉␉if ( status ==␉1 ) break;␊ |
851 | ␉␉// Status == -1 means that the config file couldn't be loaded or that gBootVolume is NULL␊ |
852 | ␉␉if ( status == -1 )␊ |
853 | ␉␉{␊ |
854 | ␉␉␉// gBootVolume == NULL usually means the user hit escape.␊ |
855 | ␉␉␉if (gBootVolume == NULL)␊ |
856 | ␉␉␉{␊ |
857 | ␉␉␉␉freeFilteredBVChain(bvChain);␊ |
858 | ␊ |
859 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
860 | ␉␉␉␉{␊ |
861 | ␉␉␉␉␉rescanBIOSDevice(gBIOSDev);␊ |
862 | ␉␉␉␉}␊ |
863 | ␊ |
864 | ␉␉␉␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
865 | ␉␉␉␉setBootGlobals(bvChain);␊ |
866 | ␉␉␉␉setupDeviceList(&bootInfo->themeConfig);␊ |
867 | ␉␉␉}␊ |
868 | ␉␉␉continue;␊ |
869 | ␉␉}␊ |
870 | ␊ |
871 | ␉␉// Other status (e.g. 0) means that we should proceed with boot.␊ |
872 | ␊ |
873 | ␉␉// Turn off any GUI elements␊ |
874 | ␉␉if ( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
875 | ␉␉{␊ |
876 | ␉␉␉gui.devicelist.draw = false;␊ |
877 | ␉␉␉gui.bootprompt.draw = false;␊ |
878 | ␉␉␉gui.menu.draw = false;␊ |
879 | ␉␉␉gui.infobox.draw = false;␊ |
880 | ␉␉␉gui.logo.draw = false;␊ |
881 | ␉␉␉drawBackground();␊ |
882 | ␉␉␉updateVRAM();␊ |
883 | ␉␉}␊ |
884 | ␊ |
885 | ␉␉if (platformCPUFeature(CPU_FEATURE_EM64T))␊ |
886 | ␉␉{␊ |
887 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
888 | ␉␉}␊ |
889 | ␉␉else␊ |
890 | ␉␉{␊ |
891 | ␉␉␉archCpuType = CPU_TYPE_I386;␊ |
892 | ␉␉}␊ |
893 | ␊ |
894 | ␉␉if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig))␊ |
895 | ␉␉{␊ |
896 | ␉␉␉if (strncmp(val, "x86_64", sizeof("x86_64") ) == 0)␊ |
897 | ␉␉␉{␊ |
898 | ␉␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
899 | ␉␉␉}␊ |
900 | ␉␉␉else if (strncmp(val, "i386", sizeof("i386") ) == 0)␊ |
901 | ␉␉␉{␊ |
902 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
903 | ␉␉␉}␊ |
904 | ␉␉␉else␊ |
905 | ␉␉␉{␊ |
906 | ␉␉␉␉DBG("Incorrect parameter for option 'arch =' , please use x86_64 or i386\n");␊ |
907 | ␉␉␉}␊ |
908 | ␉␉}␊ |
909 | ␊ |
910 | ␉␉if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig))␊ |
911 | ␉␉{␊ |
912 | ␉␉␉if (strncmp(val, "i386", sizeof("i386") ) == 0)␊ |
913 | ␉␉␉{␊ |
914 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
915 | ␉␉␉}␊ |
916 | ␉␉}␊ |
917 | ␊ |
918 | ␉␉// Notify modules that we are attempting to boot␊ |
919 | ␉␉execute_hook("PreBoot", NULL, NULL, NULL, NULL);␊ |
920 | ␊ |
921 | ␉␉//--------------------------------------␊ |
922 | ␉␉getBoolForKey(kSkipKernelPatcher, &skipKernelPatcher, &bootInfo->chameleonConfig);␊ |
923 | ␊ |
924 | ␉␉// kernel patcher␊ |
925 | ␉␉if (!skipKernelPatcher)␊ |
926 | ␉␉{␊ |
927 | ␉␉␉const char␉*key = NULL;␊ |
928 | ␉␉␉int len = 0;␊ |
929 | ␉␉␉setupKernelConfigFile("kernel.plist");␊ |
930 | ␊ |
931 | ␉␉␉// looking at command line for kernel patcher setting and override where needed␊ |
932 | ␉␉␉if (getValueForKey(kKernelBooter_kexts, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
933 | ␉␉␉{␊ |
934 | ␉␉␉␉getBoolForKey(kKernelBooter_kexts, &KernelBooter_kexts, &bootInfo->chameleonConfig);␊ |
935 | ␉␉␉}␊ |
936 | ␉␉␉key = NULL; len = 0;␊ |
937 | ␊ |
938 | ␉␉␉if (getValueForKey(kKernelPm, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
939 | ␉␉␉{␊ |
940 | ␉␉␉␉getBoolForKey(kKernelPm, &KernelPm, &bootInfo->chameleonConfig);␊ |
941 | ␉␉␉}␊ |
942 | ␉␉␉key = NULL; len = 0;␊ |
943 | ␊ |
944 | ␉␉␉if (getValueForKey(kKernelLapicError, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
945 | ␉␉␉{␊ |
946 | ␉␉␉␉getBoolForKey(kKernelLapicError, &KernelLapicError, &bootInfo->chameleonConfig);␊ |
947 | ␉␉␉}␊ |
948 | ␉␉␉key = NULL; len = 0;␊ |
949 | ␊ |
950 | ␉␉␉if (getValueForKey(kKernelLapicVersion, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
951 | ␉␉␉{␊ |
952 | ␉␉␉␉getBoolForKey(kKernelLapicVersion, &KernelLapicVersion, &bootInfo->chameleonConfig);␊ |
953 | ␉␉␉}␊ |
954 | ␉␉␉key = NULL; len = 0;␊ |
955 | ␊ |
956 | ␉␉␉if (getValueForKey(kKernelHaswell, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
957 | ␉␉␉{␊ |
958 | ␉␉␉␉getBoolForKey(kKernelHaswell, &KernelHaswell, &bootInfo->chameleonConfig);␊ |
959 | ␉␉␉}␊ |
960 | ␉␉␉key = NULL; len = 0;␊ |
961 | ␊ |
962 | ␉␉␉if (getValueForKey(kKernelcpuFamily, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
963 | ␉␉␉{␊ |
964 | ␉␉␉␉getBoolForKey(kKernelcpuFamily, &KernelcpuFamily, &bootInfo->chameleonConfig);␊ |
965 | ␉␉␉}␊ |
966 | ␉␉␉key = NULL; len = 0;␊ |
967 | ␊ |
968 | ␉␉␉if (getValueForKey(kKernelSSE3, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
969 | ␉␉␉{␊ |
970 | ␉␉␉␉getBoolForKey(kKernelSSE3, &KernelSSE3, &bootInfo->chameleonConfig);␊ |
971 | ␉␉␉}␊ |
972 | ␉␉}␊ |
973 | ␊ |
974 | #if KEXTPATCH_SUPPORT␊ |
975 | ␉␉//-------------------------------------- kext patcher␊ |
976 | ␉␉getBoolForKey(kSkipKextsPatcher, &skipKextsPatcher, &bootInfo->chameleonConfig);␊ |
977 | ␊ |
978 | ␉␉// kext patcher␊ |
979 | ␉␉if (!skipKextsPatcher)␊ |
980 | ␉␉{␊ |
981 | ␉␉␉const char␉*key = NULL;␊ |
982 | ␉␉␉int␉␉len = 0;␊ |
983 | ␉␉␉setupKextConfigFile("kexts.plist");␊ |
984 | ␊ |
985 | ␉␉␉// looking at command line for kext patcher setting and override where needed␊ |
986 | ␉␉␉if (getValueForKey(kAICPMPatch, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
987 | ␉␉␉{␊ |
988 | ␉␉␉␉getBoolForKey(kAICPMPatch, &AICPMPatch, &bootInfo->chameleonConfig);␊ |
989 | ␉␉␉}␊ |
990 | ␊ |
991 | ␉␉␉key = NULL;␊ |
992 | ␉␉␉len = 0;␊ |
993 | ␉␉␉if (getValueForKey(kNVIDIAWebDrv, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
994 | ␉␉␉{␊ |
995 | ␉␉␉␉getBoolForKey(kNVIDIAWebDrv, &NVIDIAWebDrv, &bootInfo->chameleonConfig);␊ |
996 | ␉␉␉}␊ |
997 | ␊ |
998 | ␉␉␉key = NULL;␊ |
999 | ␉␉␉len = 0;␊ |
1000 | ␉␉␉if (getValueForKey(kOrangeIconFixSata, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
1001 | ␉␉␉{␊ |
1002 | ␉␉␉␉getBoolForKey(kOrangeIconFixSata, &OrangeIconFixSata, &bootInfo->chameleonConfig);␊ |
1003 | ␉␉␉}␊ |
1004 | ␊ |
1005 | ␉␉␉key = NULL;␊ |
1006 | ␉␉␉len = 0;␊ |
1007 | ␉␉␉if (getValueForKey(kTrimEnablerSata, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
1008 | ␉␉␉{␊ |
1009 | ␉␉␉␉getBoolForKey(kTrimEnablerSata, &TrimEnablerSata, &bootInfo->chameleonConfig);␊ |
1010 | ␉␉␉}␊ |
1011 | ␊ |
1012 | ␉␉␉key = NULL;␊ |
1013 | ␉␉␉len = 0;␊ |
1014 | ␉␉␉if (getValueForKey(kAppleRTCPatch, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
1015 | ␉␉␉{␊ |
1016 | ␉␉␉␉getBoolForKey(kAppleRTCPatch, &AppleRTCPatch, &bootInfo->chameleonConfig);␊ |
1017 | ␉␉␉}␊ |
1018 | ␉␉}␊ |
1019 | ␊ |
1020 | ␉␉// -------------------------------------- kext patcher␊ |
1021 | #endif␊ |
1022 | ␊ |
1023 | ␉␉if (gBootVolume->OSisInstaller)␊ |
1024 | ␉␉{␊ |
1025 | ␉␉␉isInstaller = true;␊ |
1026 | ␉␉}␊ |
1027 | ␊ |
1028 | ␉␉if (gBootVolume->OSisMacOSXUpgrade)␊ |
1029 | ␉␉{␊ |
1030 | ␉␉␉isMacOSXUpgrade = true;␊ |
1031 | ␉␉}␊ |
1032 | ␊ |
1033 | ␉␉if (gBootVolume->OSisOSXUpgrade)␊ |
1034 | ␉␉{␊ |
1035 | ␉␉␉isOSXUpgrade = true;␊ |
1036 | ␉␉}␊ |
1037 | ␊ |
1038 | ␉␉if (gBootVolume->OSisRecovery)␊ |
1039 | ␉␉{␊ |
1040 | ␉␉␉isRecoveryHD = true;␊ |
1041 | ␉␉}␊ |
1042 | ␊ |
1043 | ␉␉if ( !isRecoveryHD && !isInstaller && !isMacOSXUpgrade && !isOSXUpgrade )␊ |
1044 | ␉␉{␊ |
1045 | ␉␉␉if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig))␊ |
1046 | ␉␉␉{␊ |
1047 | ␉␉␉␉tryresume = true;␊ |
1048 | ␉␉␉␉tryresumedefault = true;␊ |
1049 | ␉␉␉}␊ |
1050 | ␉␉␉else␊ |
1051 | ␉␉␉{␊ |
1052 | ␉␉␉␉tryresumedefault = false;␊ |
1053 | ␉␉␉}␊ |
1054 | ␊ |
1055 | ␉␉␉if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig))␊ |
1056 | ␉␉␉{␊ |
1057 | ␉␉␉␉forceresume = false;␊ |
1058 | ␉␉␉}␊ |
1059 | ␊ |
1060 | ␉␉␉if (forceresume)␊ |
1061 | ␉␉␉{␊ |
1062 | ␉␉␉␉tryresume = true;␊ |
1063 | ␉␉␉␉tryresumedefault = false;␊ |
1064 | ␉␉␉}␊ |
1065 | ␊ |
1066 | ␉␉␉while (tryresume)␊ |
1067 | ␉␉␉{␊ |
1068 | ␉␉␉␉const char *tmp;␊ |
1069 | ␉␉␉␉BVRef bvr;␊ |
1070 | ␉␉␉␉if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->chameleonConfig))␊ |
1071 | ␉␉␉␉␉val = "/private/var/vm/sleepimage";␊ |
1072 | ␊ |
1073 | ␉␉␉␉// Do this first to be sure that root volume is mounted␊ |
1074 | ␉␉␉␉ret = GetFileInfo(0, val, &flags, &sleeptime);␊ |
1075 | ␊ |
1076 | ␉␉␉␉if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)␊ |
1077 | ␉␉␉␉␉break;␊ |
1078 | ␊ |
1079 | ␉␉␉␉// Can't check if it was hibernation Wake=y is required␊ |
1080 | ␉␉␉␉if (bvr->modTime == 0 && tryresumedefault)␊ |
1081 | ␉␉␉␉␉break;␊ |
1082 | ␊ |
1083 | ␉␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
1084 | ␉␉␉␉␉break;␊ |
1085 | ␊ |
1086 | ␉␉␉␉if (!forceresume && ((sleeptime+3)<bvr->modTime))␊ |
1087 | ␉␉␉␉{␊ |
1088 | #if DEBUG␊ |
1089 | ␉␉␉␉␉printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",␊ |
1090 | ␉␉␉␉␉␉␉bvr->modTime-sleeptime);␊ |
1091 | #endif␊ |
1092 | ␉␉␉␉␉break;␊ |
1093 | ␉␉␉␉}␊ |
1094 | ␊ |
1095 | ␉␉␉␉HibernateBoot((char *)val);␊ |
1096 | ␉␉␉␉break;␊ |
1097 | ␉␉␉}␊ |
1098 | ␉␉}␊ |
1099 | ␊ |
1100 | ␉␉if (!isRecoveryHD && !isInstaller && !isMacOSXUpgrade && !isOSXUpgrade )␊ |
1101 | ␉␉{␊ |
1102 | ␉␉␉getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);␊ |
1103 | ␉␉}␊ |
1104 | ␊ |
1105 | ␉␉if (useKernelCache)␊ |
1106 | ␉␉{␊ |
1107 | ␉␉␉do␊ |
1108 | ␉␉␉{␊ |
1109 | ␉␉␉␉// Determine the name of the Kernel Cache␊ |
1110 | ␉␉␉␉if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))␊ |
1111 | ␉␉␉␉{␊ |
1112 | ␉␉␉␉␉if (val[0] == '\\')␊ |
1113 | ␉␉␉␉␉{␊ |
1114 | ␉␉␉␉␉␉len--;␊ |
1115 | ␉␉␉␉␉␉val++;␊ |
1116 | ␉␉␉␉␉}␊ |
1117 | ␉␉␉␉␉/* FIXME: check len vs sizeof(kernelCacheFile) */␊ |
1118 | ␉␉␉␉␉strlcpy(kernelCacheFile, val, len + 1);␊ |
1119 | ␉␉␉␉}␊ |
1120 | ␉␉␉␉else␊ |
1121 | ␉␉␉␉{␊ |
1122 | ␉␉␉␉␉kernelCacheFile[0] = 0; // Use default kernel cache file␊ |
1123 | ␉␉␉␉}␊ |
1124 | ␊ |
1125 | ␉␉␉␉if (gOverrideKernel && kernelCacheFile[0] == 0)␊ |
1126 | ␉␉␉␉{␊ |
1127 | ␉␉␉␉␉DBG("Using a non default kernel (%s) without specifying 'Kernel Cache' path, KernelCache will not be used\n", bootInfo->bootFile);␊ |
1128 | ␉␉␉␉␉useKernelCache = false;␊ |
1129 | ␉␉␉␉␉break;␊ |
1130 | ␉␉␉␉}␊ |
1131 | ␊ |
1132 | ␉␉␉␉if (gMKextName[0] != 0)␊ |
1133 | ␉␉␉␉{␊ |
1134 | ␉␉␉␉␉DBG("Using a specific MKext Cache (%s), KernelCache will not be used\n", gMKextName);␊ |
1135 | ␉␉␉␉␉useKernelCache = false;␊ |
1136 | ␉␉␉␉␉break;␊ |
1137 | ␉␉␉␉}␊ |
1138 | ␊ |
1139 | ␉␉␉␉if (gBootFileType != kBlockDeviceType)␊ |
1140 | ␉␉␉␉{␊ |
1141 | ␉␉␉␉␉useKernelCache = false;␊ |
1142 | ␉␉␉␉}␊ |
1143 | ␊ |
1144 | ␉␉␉} while(0);␊ |
1145 | ␉␉}␊ |
1146 | ␉␉else␊ |
1147 | ␉␉{␊ |
1148 | ␉␉␉DBG("Kernel Cache using disabled by user.\n");␊ |
1149 | ␉␉}␊ |
1150 | ␊ |
1151 | ␉␉do␊ |
1152 | ␉␉{␊ |
1153 | ␉␉␉if (useKernelCache)␊ |
1154 | ␉␉␉{␊ |
1155 | ␉␉␉␉ret = LoadKernelCache(kernelCacheFile, &binary);␊ |
1156 | ␉␉␉␉if (ret >= 0)␊ |
1157 | ␉␉␉␉{␊ |
1158 | ␉␉␉␉␉break;␊ |
1159 | ␉␉␉␉}␊ |
1160 | ␉␉␉}␊ |
1161 | ␊ |
1162 | ␉␉␉bool bootFileWithDevice = false;␊ |
1163 | ␉␉␉// Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel␊ |
1164 | ␉␉␉if (strncmp(bootInfo->bootFile, "bt(", sizeof("bt(") ) == 0 ||␊ |
1165 | ␉␉␉␉strncmp(bootInfo->bootFile, "hd(", sizeof("hd(") ) == 0 ||␊ |
1166 | ␉␉␉␉strncmp(bootInfo->bootFile, "rd(", sizeof("rd(") ) == 0)␊ |
1167 | ␉␉␉{␊ |
1168 | ␉␉␉␉bootFileWithDevice = true;␊ |
1169 | ␉␉␉}␊ |
1170 | ␊ |
1171 | ␉␉␉// bootFile must start with a / if it not start with a device name␊ |
1172 | ␉␉␉if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/')␊ |
1173 | ␉␉␉{␊ |
1174 | ␉␉␉␉if ( MacOSVerCurrent < MacOSVer2Int("10.10") ) // Mavericks and older␊ |
1175 | ␉␉␉␉{␊ |
1176 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading /␊ |
1177 | ␉␉␉␉}␊ |
1178 | ␉␉␉␉else␊ |
1179 | ␉␉␉␉{␊ |
1180 | ␉␉␉␉␉// Yosemite and newer␊ |
1181 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), kDefaultKernelPathForYos"%s", bootInfo->bootFile); // Yosemite or El Capitan␊ |
1182 | ␉␉␉␉}␊ |
1183 | ␉␉␉}␊ |
1184 | ␉␉␉else␊ |
1185 | ␉␉␉{␊ |
1186 | ␉␉␉␉strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile));␊ |
1187 | ␉␉␉}␊ |
1188 | ␊ |
1189 | ␉␉␉// Try to load kernel image from alternate locations on boot helper partitions.␊ |
1190 | ␉␉␉ret = -1;␊ |
1191 | ␉␉␉if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice)␊ |
1192 | ␉␉␉{␊ |
1193 | ␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.P%s", bootFile);␊ |
1194 | ␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
1195 | ␉␉␉␉if (ret == -1)␊ |
1196 | ␉␉␉␉{␊ |
1197 | ␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.R%s", bootFile);␊ |
1198 | ␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
1199 | ␉␉␉␉␉if (ret == -1)␊ |
1200 | ␉␉␉␉␉{␊ |
1201 | ␉␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.S%s", bootFile);␊ |
1202 | ␉␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
1203 | ␉␉␉␉␉}␊ |
1204 | ␉␉␉␉}␊ |
1205 | ␉␉␉}␊ |
1206 | ␉␉␉if (ret == -1)␊ |
1207 | ␉␉␉{␊ |
1208 | ␉␉␉␉// No alternate location found, using the original kernel image path.␊ |
1209 | ␉␉␉␉strlcpy(bootFilePath, bootFile, sizeof(bootFilePath));␊ |
1210 | ␉␉␉}␊ |
1211 | ␊ |
1212 | ␉␉␉DBG("Loading kernel from: '%s' (%s)\n", gBootVolume->label, gBootVolume->type_name);␊ |
1213 | ␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
1214 | ␉␉␉if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
1215 | ␉␉␉{␊ |
1216 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
1217 | ␉␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
1218 | ␉␉␉}␊ |
1219 | ␉␉} while (0);␊ |
1220 | ␊ |
1221 | ␉␉clearActivityIndicator();␊ |
1222 | ␊ |
1223 | #if DEBUG␊ |
1224 | ␉␉printf("Pausing...");␊ |
1225 | ␉␉sleep(8);␊ |
1226 | #endif␊ |
1227 | ␊ |
1228 | ␉␉if (ret <= 0)␊ |
1229 | ␉␉{␊ |
1230 | ␉␉␉printf("Can't find boot file: '%s'\n", bootFile);␊ |
1231 | ␉␉␉sleep(1);␊ |
1232 | ␊ |
1233 | ␉␉␉if (gBootFileType == kNetworkDeviceType)␊ |
1234 | ␉␉␉{␊ |
1235 | ␉␉␉␉// Return control back to PXE. Don't unload PXE base code.␊ |
1236 | ␉␉␉␉gUnloadPXEOnExit = false;␊ |
1237 | ␉␉␉␉break;␊ |
1238 | ␉␉␉}␊ |
1239 | ␉␉␉pause();␊ |
1240 | ␊ |
1241 | ␉␉}␊ |
1242 | ␉␉else␊ |
1243 | ␉␉{␊ |
1244 | ␉␉␉/* Won't return if successful. */␊ |
1245 | ␉␉␉ret = ExecKernel(binary);␊ |
1246 | ␉␉}␊ |
1247 | ␉}␊ |
1248 | ␊ |
1249 | ␉// chainboot␊ |
1250 | ␉if (status == 1)␊ |
1251 | ␉{␊ |
1252 | ␉␉// if we are already in graphics-mode,␊ |
1253 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
1254 | ␉␉{␊ |
1255 | ␉␉␉setVideoMode( VGA_TEXT_MODE ); // switch back to text mode.␊ |
1256 | ␉␉}␊ |
1257 | ␉}␊ |
1258 | ␊ |
1259 | ␉if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit)␊ |
1260 | ␉{␊ |
1261 | ␉␉nbpUnloadBaseCode();␊ |
1262 | ␉}␊ |
1263 | ␊ |
1264 | #if DEBUG_INTERRUPTS␊ |
1265 | ␉if (interruptsAvailable)␊ |
1266 | ␉{␊ |
1267 | ␉␉DisableInterrupts();␊ |
1268 | ␉}␊ |
1269 | #endif␊ |
1270 | ␊ |
1271 | }␊ |
1272 | ␊ |
1273 | // =========================================================================␊ |
1274 | //␊ |
1275 | void setupBooterArgs()␊ |
1276 | {␊ |
1277 | ␉bool KPRebootOption␉= false; // I don't want this by default ( It makes me angry because I do not see the reason for the panic)+␊ |
1278 | //␉bool HiDPIOption␉= false; // (Disabled by default) 10.8+␊ |
1279 | //␉bool FlagBlackOption␉= false; // (Disabled by default) 10.10+␊ |
1280 | ␊ |
1281 | ␉// OS X Lion 10.7␊ |
1282 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.7") ) // Lion and Up!␊ |
1283 | ␉{␊ |
1284 | ␉␉// Pike R. Alpha: Adding a 16 KB log space.␊ |
1285 | ␉␉bootArgs->performanceDataSize␉␉= 0;␊ |
1286 | ␉␉bootArgs->performanceDataStart␉␉= 0;␊ |
1287 | ␊ |
1288 | ␉␉// Pike R. Alpha: AppleKeyStore.kext␊ |
1289 | ␉␉bootArgs->keyStoreDataSize␉␉= 0;␊ |
1290 | ␉␉bootArgs->keyStoreDataStart␉␉= 0;␊ |
1291 | ␊ |
1292 | ␉␉bootArgs->bootMemSize␉␉␉= 0;␊ |
1293 | ␉␉bootArgs->bootMemStart␉␉␉= 0;␊ |
1294 | ␉}␊ |
1295 | ␊ |
1296 | ␉// OS X Mountain Lion 10.8␊ |
1297 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.8") ) // Mountain Lion and Up!␊ |
1298 | ␉{␊ |
1299 | ␉␉// cparm␊ |
1300 | ␉␉getBoolForKey(kRebootOnPanic, &KPRebootOption, &bootInfo->chameleonConfig);␊ |
1301 | ␉␉if ( KPRebootOption )␊ |
1302 | ␉␉{␊ |
1303 | ␉␉␉bootArgs->flags |= kBootArgsFlagRebootOnPanic;␊ |
1304 | ␉␉}␊ |
1305 | ␊ |
1306 | ␉␉// cparm␊ |
1307 | ␉␉getBoolForKey(kEnableHiDPI, &HiDPIOption, &bootInfo->chameleonConfig);␊ |
1308 | ␊ |
1309 | ␉␉if ( HiDPIOption )␊ |
1310 | ␉␉{␊ |
1311 | ␉␉␉bootArgs->flags |= kBootArgsFlagHiDPI;␊ |
1312 | ␉␉}␊ |
1313 | ␉}␊ |
1314 | ␊ |
1315 | ␉// OS X Yosemite 10.10␊ |
1316 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.10") ) // Yosemite and Up!␊ |
1317 | ␉{␊ |
1318 | ␉␉// Pike R. Alpha␊ |
1319 | ␉␉getBoolForKey(kBlackMode, &FlagBlackOption, &bootInfo->chameleonConfig);␊ |
1320 | ␉␉if ( FlagBlackOption )␊ |
1321 | ␉␉{␊ |
1322 | ␉␉␉// bootArgs->flags |= kBootArgsFlagBlack;␊ |
1323 | ␉␉␉bootArgs->flags |= kBootArgsFlagBlackBg; // Micky1979␊ |
1324 | ␉␉}␊ |
1325 | ␉}␊ |
1326 | ␊ |
1327 | ␉// OS X El Capitan 10.11␊ |
1328 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.11") ) // El Capitan, Sierra and High Sierra!␊ |
1329 | ␉{␊ |
1330 | ␉␉// ErmaC␊ |
1331 | ␉␉verbose("\n");␊ |
1332 | ␉␉int␉csrValue;␊ |
1333 | ␊ |
1334 | ␉␉/*␊ |
1335 | ␉␉ * A special BootArgs flag "kBootArgsFlagCSRBoot"␊ |
1336 | ␉␉ * is set in the Recovery or Installation environment.␊ |
1337 | ␉␉ * This flag is kind of overkill by turning off all the protections␊ |
1338 | ␉␉ */␊ |
1339 | ␊ |
1340 | ␉␉if (isRecoveryHD || isInstaller || isOSXUpgrade || isMacOSXUpgrade)␊ |
1341 | ␉␉{␊ |
1342 | ␉␉␉// SIP can be controlled with or without FileNVRAM.kext (Pike R. Alpha)␊ |
1343 | ␉␉␉bootArgs->flags␉|=␉(kBootArgsFlagCSRActiveConfig + kBootArgsFlagCSRConfigMode + kBootArgsFlagCSRBoot + kBootArgsFlagInstallUI);␊ |
1344 | ␉␉}␊ |
1345 | ␉␉else␊ |
1346 | ␉␉{␊ |
1347 | ␉␉␉bootArgs->flags␉|= kBootArgsFlagCSRActiveConfig;␊ |
1348 | ␉␉}␊ |
1349 | ␊ |
1350 | ␉␉// Set limit to 8bit␊ |
1351 | ␉␉if ( getIntForKey(kCsrActiveConfig, &csrValue, &bootInfo->chameleonConfig) && (csrValue >= 0 && csrValue <= 255) )␊ |
1352 | ␉␉{␊ |
1353 | ␉␉␉bootArgs->csrActiveConfig␉= csrValue;␊ |
1354 | ␉␉␉csrInfo(csrValue, 1);␊ |
1355 | ␉␉}␊ |
1356 | ␉␉else␊ |
1357 | ␉␉{␊ |
1358 | ␉␉␉// zenith432␊ |
1359 | ␉␉␉bootArgs->csrActiveConfig␉= 0x67;␊ |
1360 | ␉␉␉csrInfo(0x67, 0);␊ |
1361 | ␊ |
1362 | ␉␉}␊ |
1363 | ␊ |
1364 | ␊ |
1365 | // ===============================================================================␊ |
1366 | ␊ |
1367 | ␉␉bootArgs->csrCapabilities␉␉= CSR_VALID_CAPABILITIES; // CSR_VALID_FLAGS␊ |
1368 | ␉␉bootArgs->boot_SMC_plimit␉␉= 0;␊ |
1369 | ␉␉bootArgs->bootProgressMeterStart␉= 0;␊ |
1370 | ␉␉bootArgs->bootProgressMeterEnd␉␉= 0;␊ |
1371 | ␉}␊ |
1372 | }␊ |
1373 | ␊ |
1374 | // =========================================================================␊ |
1375 | // ErmaC␊ |
1376 | void csrInfo(int csrValue, bool custom)␊ |
1377 | {␊ |
1378 | #define CSR_BITS 0x080␊ |
1379 | ␊ |
1380 | ␉int mask = CSR_BITS;␊ |
1381 | ␉verbose("System Integrity Protection status: %s ", (csrValue == 0) ? "enabled":"disabled");␊ |
1382 | ␉verbose("(%s Configuration).\nCsrActiveConfig = 0x%02X (", custom ? "Custom":"Default", csrValue);␊ |
1383 | ␊ |
1384 | ␉// Display integer number into binary using bitwise operator␊ |
1385 | ␉((csrValue & 0x020) == 0) ? verbose("0"): verbose("1");␊ |
1386 | ␉while (mask != 0)␊ |
1387 | ␉{␊ |
1388 | ␉␉( ((csrValue & mask) == 0) ? verbose("0"): verbose("1") );␊ |
1389 | ␉␉mask = mask >> 1; // Right Shift␊ |
1390 | ␉}␊ |
1391 | ␉verbose(")\n");␊ |
1392 | ␉if (csrValue != 0)␊ |
1393 | ␉{␊ |
1394 | ␉␉verbose("\nConfiguration:\n");␊ |
1395 | ␉␉verbose("Kext Signing: %s\n", ((csrValue & 0x001) == 0) ? "enabled":"disabled"); /* (1 << 0) Allow untrusted kexts */␊ |
1396 | ␉␉verbose("Filesystem Protections: %s\n", ((csrValue & 0x002) == 0) ? "enabled":"disabled"); /* (1 << 1) Allow unrestricted file system. */␊ |
1397 | ␉␉verbose("Task for PID: %s\n", ((csrValue & 0x004) == 0) ? "enabled":"disabled"); /* (1 << 2) */␊ |
1398 | ␉␉verbose("Debugging Restrictions: %s\n", ((csrValue & 0x008) == 0) ? "enabled":"disabled"); /* (1 << 3) */␊ |
1399 | ␉␉verbose("Apple Internal: %s\n", ((csrValue & 0x010) == 0) ? "enabled":"disabled"); /* (1 << 4) */␊ |
1400 | ␉␉verbose("DTrace Restrictions: %s\n", ((csrValue & 0x020) == 0) ? "enabled":"disabled"); /* (1 << 5) Allow unrestricted dtrace */␊ |
1401 | ␉␉verbose("NVRAM Protections: %s\n", ((csrValue & 0x040) == 0) ? "enabled":"disabled"); /* (1 << 6) Allow unrestricted NVRAM */␊ |
1402 | ␉␉verbose("Device configuration: %s\n", ((csrValue & 0x080) == 0) ? "enabled":"disabled"); /* (1 << 7) Allow device configuration */␊ |
1403 | ␉␉verbose("BaseSystem Verification: %s\n", ((csrValue & 0x100) == 0) ? "enabled":"disabled"); /* (1 << 8) Allow any Recovery OS */␊ |
1404 | ␉}␊ |
1405 | ␉verbose("\n");␊ |
1406 | }␊ |
1407 | ␊ |
1408 | // =========================================================================␊ |
1409 | ␊ |
1410 | /*!␊ |
1411 | ␉Selects a new BIOS device, taking care to update the global state appropriately.␊ |
1412 | */␊ |
1413 | /*␊ |
1414 | static void selectBiosDevice(void)␊ |
1415 | {␊ |
1416 | ␉struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);␊ |
1417 | ␉CacheReset();␊ |
1418 | ␉diskFreeMap(oldMap);␊ |
1419 | ␉oldMap = NULL;␊ |
1420 | ␊ |
1421 | ␉int dev = selectAlternateBootDevice(gBIOSDev);␊ |
1422 | ␊ |
1423 | ␉BVRef bvchain = scanBootVolumes(dev, 0);␊ |
1424 | ␉BVRef bootVol = selectBootVolume(bvchain);␊ |
1425 | ␉gBootVolume = bootVol;␊ |
1426 | ␉setRootVolume(bootVol);␊ |
1427 | ␉gBIOSDev = dev;␊ |
1428 | }␊ |
1429 | */␊ |
1430 | ␊ |
1431 | // =========================================================================␊ |
1432 | bool checkOSVersion(const char *version)␊ |
1433 | {␊ |
1434 | ␉if ( '\0' != version[4] )␊ |
1435 | ␉{␊ |
1436 | ␉␉return !memcmp(&gMacOSVersion[0], &version[0], 5);␊ |
1437 | ␉}␊ |
1438 | ␉else␊ |
1439 | ␉{␊ |
1440 | ␉␉return !memcmp(&gMacOSVersion[0], &version[0], 4);␊ |
1441 | ␉}␊ |
1442 | }␊ |
1443 | ␊ |
1444 | uint32_t getMacOSVerCurrent()␊ |
1445 | {␊ |
1446 | ␉MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion);␊ |
1447 | ␉return MacOSVerCurrent;␊ |
1448 | }␊ |
1449 | ␊ |
1450 | // =========================================================================␊ |
1451 | unsigned long Adler32(unsigned char *buf, long len)␊ |
1452 | {␊ |
1453 | #define BASE 65521L /* largest prime smaller than 65536 */␊ |
1454 | #define NMAX 5000␊ |
1455 | // NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1␊ |
1456 | ␊ |
1457 | #define DO1(buf, i)␉{s1 += buf[i]; s2 += s1;}␊ |
1458 | #define DO2(buf, i)␉DO1(buf, i); DO1(buf, i + 1);␊ |
1459 | #define DO4(buf, i)␉DO2(buf, i); DO2(buf, i + 2);␊ |
1460 | #define DO8(buf, i)␉DO4(buf, i); DO4(buf, i + 4);␊ |
1461 | #define DO16(buf)␉DO8(buf, 0); DO8(buf, 8);␊ |
1462 | ␊ |
1463 | ␉int k;␊ |
1464 | ␊ |
1465 | ␉unsigned long s1 = 1; // adler & 0xffff;␊ |
1466 | ␉unsigned long s2 = 0; // (adler >> 16) & 0xffff;␊ |
1467 | ␉unsigned long result;␊ |
1468 | ␊ |
1469 | ␉while (len > 0)␊ |
1470 | ␉{␊ |
1471 | ␉␉k = len < NMAX ? len : NMAX;␊ |
1472 | ␉␉len -= k;␊ |
1473 | ␉␉while (k >= 16)␊ |
1474 | ␉␉{␊ |
1475 | ␉␉␉DO16(buf);␊ |
1476 | ␉␉␉buf += 16;␊ |
1477 | ␉␉␉k -= 16;␊ |
1478 | ␉␉}␊ |
1479 | ␊ |
1480 | ␉␉if (k != 0)␊ |
1481 | ␉␉{␊ |
1482 | ␉␉␉do␊ |
1483 | ␉␉␉{␊ |
1484 | ␉␉␉␉s1 += *buf++;␊ |
1485 | ␉␉␉␉s2 += s1;␊ |
1486 | ␉␉␉} while (--k);␊ |
1487 | ␉␉}␊ |
1488 | ␊ |
1489 | ␉␉s1 %= BASE;␊ |
1490 | ␉␉s2 %= BASE;␊ |
1491 | ␉}␊ |
1492 | ␊ |
1493 | ␉result = (s2 << 16) | s1;␊ |
1494 | ␊ |
1495 | ␉return OSSwapHostToBigInt32(result);␊ |
1496 | }␊ |
1497 | |