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