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

Archive Download this file

Revision: 2871