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