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