Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/i386/boot2/boot.c

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

Archive Download this file

Revision: 2893