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 | ␊ |
33 | /*␊ |
34 | *␉␉␉INTEL CORPORATION PROPRIETARY INFORMATION␊ |
35 | *␊ |
36 | *␉This software is supplied under the terms of a license␉agreement or ␊ |
37 | *␉nondisclosure agreement with Intel Corporation and may not be copied ␊ |
38 | *␉nor disclosed except in accordance with the terms of that agreement.␊ |
39 | *␊ |
40 | *␉Copyright 1988, 1989 by Intel Corporation␊ |
41 | */␊ |
42 | ␊ |
43 | /*␊ |
44 | * Copyright 1993 NeXT Computer, Inc.␊ |
45 | * All rights reserved.␊ |
46 | */␊ |
47 | ␊ |
48 | /*␊ |
49 | * Completely reworked by Sam Streeper (sam_s@NeXT.com)␊ |
50 | * Reworked again by Curtis Galloway (galloway@NeXT.com)␊ |
51 | */␊ |
52 | ␊ |
53 | #include "boot.h"␊ |
54 | #include "bootstruct.h"␊ |
55 | #include "fake_efi.h"␊ |
56 | #include "sl.h"␊ |
57 | #include "libsa.h"␊ |
58 | #include "ramdisk.h"␊ |
59 | #include "gui.h"␊ |
60 | #include "platform.h"␊ |
61 | #include "modules.h"␊ |
62 | #include "device_tree.h"␊ |
63 | ␊ |
64 | #ifndef DEBUG_BOOT2␊ |
65 | #define DEBUG_BOOT2 0␊ |
66 | #endif␊ |
67 | ␊ |
68 | #if DEBUG_BOOT2␊ |
69 | #define DBG(x...)␉printf(x)␊ |
70 | #else␊ |
71 | #define DBG(x...)␉msglog(x)␊ |
72 | #endif␊ |
73 | ␊ |
74 | /*␊ |
75 | * How long to wait (in seconds) to load the␊ |
76 | * kernel after displaying the "boot:" prompt.␊ |
77 | */␊ |
78 | #define kBootErrorTimeout 5␊ |
79 | ␊ |
80 | bool␉␉gOverrideKernel, gEnableCDROMRescan, gScanSingleDrive, useGUI;␊ |
81 | static bool␉gUnloadPXEOnExit = false;␊ |
82 | ␊ |
83 | static char␉gCacheNameAdler[64 + 256];␊ |
84 | char␉␉*gPlatformName = gCacheNameAdler;␊ |
85 | ␊ |
86 | char␉␉gRootDevice[ROOT_DEVICE_SIZE];␊ |
87 | char␉␉gMKextName[512];␊ |
88 | char␉␉gMacOSVersion[8];␊ |
89 | int␉␉bvCount = 0, gDeviceCount = 0;␊ |
90 | //int␉␉menucount = 0;␊ |
91 | long␉␉gBootMode; /* defaults to 0 == kBootModeNormal */␊ |
92 | BVRef␉␉bvr, menuBVR, bvChain;␊ |
93 | ␊ |
94 | static unsigned long␉Adler32(unsigned char *buffer, long length);␊ |
95 | //static void␉␉␉selectBiosDevice(void);␊ |
96 | ␊ |
97 | /** options.c **/␊ |
98 | extern char* msgbuf;␊ |
99 | void showTextBuffer(char *buf, int size);␊ |
100 | ␊ |
101 | ␊ |
102 | //==========================================================================␊ |
103 | // Zero the BSS.␊ |
104 | ␊ |
105 | static void zeroBSS(void)␊ |
106 | {␊ |
107 | ␉extern char bss_start __asm("section$start$__DATA$__bss");␊ |
108 | ␉extern char bss_end __asm("section$end$__DATA$__bss");␊ |
109 | ␉extern char common_start __asm("section$start$__DATA$__common");␊ |
110 | ␉extern char common_end __asm("section$end$__DATA$__common");␊ |
111 | ␊ |
112 | ␉bzero(&bss_start, (&bss_end - &bss_start));␊ |
113 | ␉bzero(&common_start, (&common_end - &common_start));␊ |
114 | }␊ |
115 | ␊ |
116 | //==========================================================================␊ |
117 | // Malloc error function␊ |
118 | ␊ |
119 | static void malloc_error(char *addr, size_t size, const char *file, int line)␊ |
120 | {␊ |
121 | ␉stop("\nMemory allocation error! Addr: 0x%x, Size: 0x%x, File: %s, Line: %d\n",␊ |
122 | ␉␉␉␉␉␉␉␉␉ (unsigned)addr, (unsigned)size, file, line);␊ |
123 | }␊ |
124 | ␊ |
125 | //==========================================================================␊ |
126 | //Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.␊ |
127 | //␊ |
128 | void initialize_runtime(void)␊ |
129 | {␊ |
130 | ␉zeroBSS();␊ |
131 | ␉malloc_init(0, 0, 0, malloc_error);␊ |
132 | }␊ |
133 | ␊ |
134 | //==========================================================================␊ |
135 | // execKernel - Load the kernel image (mach-o) and jump to its entry point.␊ |
136 | ␊ |
137 | static int ExecKernel(void *binary)␊ |
138 | {␊ |
139 | ␉int␉␉␉ret;␊ |
140 | ␉entry_t␉␉kernelEntry;␊ |
141 | ␊ |
142 | ␉bootArgs->kaddr = bootArgs->ksize = 0;␊ |
143 | ␉execute_hook("ExecKernel", (void*)binary, NULL, NULL, NULL);␊ |
144 | ␊ |
145 | ␉ret = DecodeKernel(binary,␊ |
146 | ␉␉␉␉␉ &kernelEntry,␊ |
147 | ␉␉␉␉␉ (char **) &bootArgs->kaddr,␊ |
148 | ␉␉␉␉␉ (int *)&bootArgs->ksize );␊ |
149 | ␊ |
150 | ␉if ( ret != 0 )␊ |
151 | ␉␉return ret;␊ |
152 | ␊ |
153 | ␉// Reserve space for boot args␊ |
154 | ␉reserveKernBootStruct();␊ |
155 | ␊ |
156 | ␉// Notify modules that the kernel has been decoded␊ |
157 | ␉execute_hook("DecodedKernel", (void*)binary, (void*)bootArgs->kaddr, (void*)bootArgs->ksize, NULL);␊ |
158 | ␊ |
159 | ␉setupFakeEfi();␊ |
160 | ␊ |
161 | ␉// Load boot drivers from the specifed root path.␊ |
162 | ␉//if (!gHaveKernelCache)␊ |
163 | ␉LoadDrivers("/");␊ |
164 | ␊ |
165 | ␉execute_hook("DriversLoaded", (void*)binary, NULL, NULL, NULL);␊ |
166 | ␊ |
167 | ␉clearActivityIndicator();␊ |
168 | ␊ |
169 | ␉if (gErrors)␊ |
170 | ␉{␊ |
171 | ␉␉printf("Errors encountered while starting up the computer.\n");␊ |
172 | ␉␉printf("Pausing %d seconds...\n", kBootErrorTimeout);␊ |
173 | ␉␉sleep(kBootErrorTimeout);␊ |
174 | ␉}␊ |
175 | ␊ |
176 | ␉md0Ramdisk();␊ |
177 | ␊ |
178 | ␉// Cleanup the PXE base code.␊ |
179 | ␊ |
180 | ␉if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit )␊ |
181 | ␉{␊ |
182 | ␉␉if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )␊ |
183 | ␉␉{␊ |
184 | ␉␉␉printf("nbpUnloadBaseCode error %d\n", (int) ret);␊ |
185 | ␉␉␉sleep(2);␊ |
186 | ␉␉}␊ |
187 | ␉}␊ |
188 | ␊ |
189 | ␉bool dummyVal;␊ |
190 | ␉if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->chameleonConfig) && dummyVal)␊ |
191 | ␉{␊ |
192 | ␉␉showTextBuffer(msgbuf, strlen(msgbuf));␊ |
193 | ␉}␊ |
194 | ␊ |
195 | ␉usb_loop();␊ |
196 | ␊ |
197 | ␉// If we were in text mode, switch to graphics mode.␊ |
198 | ␉// This will draw the boot graphics unless we are in␊ |
199 | ␉// verbose mode.␊ |
200 | ␉if (gVerboseMode)␊ |
201 | ␉{␊ |
202 | ␉␉setVideoMode( GRAPHICS_MODE, 0 );␊ |
203 | ␉}␊ |
204 | ␉else␊ |
205 | ␉{␊ |
206 | ␉␉drawBootGraphics();␊ |
207 | ␉}␊ |
208 | ␊ |
209 | ␉DBG("Starting Darwin/%s [%s]\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64", gDarwinBuildVerStr);␊ |
210 | ␉DBG("Boot Args: %s\n", bootArgs->CommandLine);␊ |
211 | ␊ |
212 | ␉setupBooterLog();␊ |
213 | ␊ |
214 | ␉finalizeBootStruct();␊ |
215 | ␊ |
216 | ␉// Jump to kernel's entry point. There's no going back now.␊ |
217 | ␉if (TIGER || LEOPARD || SNOW_LEOPARD)␊ |
218 | ␉{␊ |
219 | ␉␉// Notify modules that the kernel is about to be started␊ |
220 | ␉␉execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgsPreLion, NULL, NULL);␊ |
221 | ␊ |
222 | ␉␉startprog( kernelEntry, bootArgsPreLion );␊ |
223 | ␊ |
224 | ␉}␊ |
225 | ␉else␊ |
226 | ␉{␊ |
227 | ␉␉// Notify modules that the kernel is about to be started␊ |
228 | ␉␉execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL);␊ |
229 | ␊ |
230 | ␉␉// Masking out so that Lion doesn't doublefault␊ |
231 | ␉␉outb(0x21, 0xff);␉/* Maskout all interrupts Pic1 */␊ |
232 | ␉␉outb(0xa1, 0xff);␉/* Maskout all interrupts Pic2 */␊ |
233 | ␊ |
234 | ␉␉startprog( kernelEntry, bootArgs );␊ |
235 | ␉}␊ |
236 | ␊ |
237 | ␉// Not reached␊ |
238 | ␉return 0;␊ |
239 | }␊ |
240 | ␊ |
241 | ␊ |
242 | //==========================================================================␊ |
243 | // LoadKernelCache - Try to load Kernel Cache.␊ |
244 | // return the length of the loaded cache file or -1 on error␊ |
245 | long LoadKernelCache(const char* cacheFile, void **binary)␊ |
246 | {␊ |
247 | ␉char␉␉kernelCacheFile[512];␊ |
248 | ␉char␉␉kernelCachePath[512];␊ |
249 | ␉long␉␉flags, ret=-1;␊ |
250 | ␉unsigned long adler32;␊ |
251 | u_int32_t time, cachetime, kerneltime, exttime;␊ |
252 | ␊ |
253 | ␉if((gBootMode & kBootModeSafe) != 0) {␊ |
254 | ␉␉DBG("Kernel Cache ignored.\n");␊ |
255 | ␉␉return -1;␊ |
256 | ␉}␊ |
257 | ␊ |
258 | ␉// Use specify kernel cache file if not empty␊ |
259 | ␉if (cacheFile[0] != 0)␊ |
260 | ␉{␊ |
261 | ␉␉strlcpy(kernelCacheFile, cacheFile, sizeof(kernelCacheFile));␊ |
262 | ␉␉verbose("Specified kernel cache file path = %s\n", cacheFile);␊ |
263 | ␉} else {␊ |
264 | ␉␉// Leopard prelink kernel cache file␊ |
265 | ␉␉if (TIGER || LEOPARD)␊ |
266 | ␉␉{␊ |
267 | ␉␉␉// Reset cache name.␊ |
268 | ␉␉␉bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);␊ |
269 | ␉␉␉snprintf(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64, "%s,%s", gRootDevice, bootInfo->bootFile);␊ |
270 | ␉␉␉adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));␊ |
271 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32);␊ |
272 | ␉␉␉verbose("Reseted kernel cache file path = %s\n", kernelCacheFile);␊ |
273 | ␉␉}␊ |
274 | ␉␉// Snow Leopard prelink kernel cache file␊ |
275 | ␉␉else if ( SNOW_LEOPARD ) {␊ |
276 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "kernelcache_%s",␊ |
277 | ␉␉␉␉(archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64");␊ |
278 | ␊ |
279 | ␉␉␉int␉lnam = strlen(kernelCacheFile) + 9; //with adler32␊ |
280 | ␉␉␉char *name;␊ |
281 | ␉␉␉u_int32_t prev_time = 0;␊ |
282 | ␊ |
283 | ␉␉␉struct␉dirstuff* cacheDir = opendir(kDefaultCachePathSnow);␊ |
284 | ␊ |
285 | ␉␉␉/* TODO: handle error? */␊ |
286 | ␉␉␉if (cacheDir) {␊ |
287 | ␉␉␉␉while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0) {␊ |
288 | ␉␉␉␉␉if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time␊ |
289 | ␉␉␉␉␉␉&& strstr(name, kernelCacheFile) && (name[lnam] != '.')) {␊ |
290 | ␉␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s%s", kDefaultCachePathSnow, name);␊ |
291 | ␉␉␉␉␉␉prev_time = time;␊ |
292 | ␉␉␉␉␉}␊ |
293 | ␉␉␉␉}␊ |
294 | ␉␉␉␉verbose("Snow Leopard kernel cache file path = %s\n", kernelCacheFile);␊ |
295 | ␉␉␉}␊ |
296 | ␉␉␉closedir(cacheDir);␊ |
297 | ␉␉} else {␊ |
298 | ␉␉␉// Lion, Mountain Lion, Mavericks, and Yosemite prelink kernel cache file␊ |
299 | ␉␉␉// for 10.7 10.8 10.9 10.10␊ |
300 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);␊ |
301 | ␉␉␉verbose("10.7, 10.8, 10.9 & 10.10 kernel cache file path = %s\n", kernelCacheFile);␊ |
302 | ␉␉}␊ |
303 | ␉}␊ |
304 | ␊ |
305 | ␉// Check if the kernel cache file exists␊ |
306 | ␉ret = -1;␊ |
307 | ␊ |
308 | ␉// If boot from a boot helper partition check the kernel cache file on it␊ |
309 | ␉if (gBootVolume->flags & kBVFlagBooter)␊ |
310 | ␉{␊ |
311 | ␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "com.apple.boot.P%s", kernelCacheFile);␊ |
312 | ␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
313 | ␊ |
314 | ␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
315 | ␉␉{␊ |
316 | ␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "com.apple.boot.R%s", kernelCacheFile);␊ |
317 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
318 | ␊ |
319 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
320 | ␉␉␉{␊ |
321 | ␉␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "com.apple.boot.S%s", kernelCacheFile);␊ |
322 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
323 | ␊ |
324 | ␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
325 | ␉␉␉␉{␊ |
326 | ␉␉␉␉␉ret = -1;␊ |
327 | ␉␉␉␉}␊ |
328 | ␉␉␉}␊ |
329 | ␉␉}␊ |
330 | ␉}␊ |
331 | ␊ |
332 | ␉// If not found, use the original kernel cache path.␊ |
333 | ␉if (ret == -1)␊ |
334 | ␉{␊ |
335 | ␉␉strlcpy(kernelCachePath, kernelCacheFile, sizeof(kernelCachePath));␊ |
336 | ␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
337 | ␊ |
338 | ␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
339 | ␉␉{␊ |
340 | ␉␉␉ret = -1;␊ |
341 | ␉␉}␊ |
342 | ␉}␊ |
343 | ␊ |
344 | ␉// Exit if kernel cache file wasn't found␊ |
345 | ␉if (ret == -1)␊ |
346 | ␉{␊ |
347 | ␉␉DBG("No Kernel Cache File '%s' found\n", kernelCacheFile);␊ |
348 | ␉␉return -1;␊ |
349 | ␉}␊ |
350 | ␊ |
351 | ␉// Check if the kernel cache file is more recent (mtime)␊ |
352 | ␉// than the kernel file or the S/L/E directory␊ |
353 | ␉ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);␊ |
354 | ␊ |
355 | ␉// Check if the kernel file is more recent than the cache file␊ |
356 | ␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat) && (kerneltime > cachetime))␊ |
357 | ␉{␊ |
358 | ␉␉DBG("Kernel file (%s) is more recent than Kernel Cache (%s)! Ignoring Kernel Cache.\n", bootInfo->bootFile, kernelCacheFile);␊ |
359 | ␉␉return -1;␊ |
360 | ␉}␊ |
361 | ␊ |
362 | ␉ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);␊ |
363 | ␊ |
364 | ␉// Check if the S/L/E directory time is more recent than the cache file␊ |
365 | ␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory) && (exttime > cachetime))␊ |
366 | ␉{␊ |
367 | ␉␉DBG("Folder: '/System/Library/Extensions' is more recent than Kernel Cache file (%s)! Ignoring Kernel Cache.\n", kernelCacheFile);␊ |
368 | ␉␉return -1;␊ |
369 | ␉}␊ |
370 | ␊ |
371 | ␉// Since the kernel cache file exists and is the most recent try to load it␊ |
372 | ␉DBG("Loading kernel cache: '%s'\n", kernelCachePath);␊ |
373 | ␊ |
374 | ␉ret = LoadThinFatFile(kernelCachePath, binary);␊ |
375 | ␉return ret; // ret contain the length of the binary␊ |
376 | }␊ |
377 | ␊ |
378 | //==========================================================================␊ |
379 | // This is the entrypoint from real-mode which functions exactly as it did␊ |
380 | // before. Multiboot does its own runtime initialization, does some of its␊ |
381 | // own things, and then calls common_boot.␊ |
382 | void boot(int biosdev)␊ |
383 | {␊ |
384 | ␉initialize_runtime();␊ |
385 | ␉// Enable A20 gate before accessing memory above 1Mb.␊ |
386 | ␉enableA20();␊ |
387 | ␉common_boot(biosdev);␊ |
388 | }␊ |
389 | ␊ |
390 | //==========================================================================␊ |
391 | // The 'main' function for the booter. Called by boot0 when booting␊ |
392 | // from a block device, or by the network booter.␊ |
393 | //␊ |
394 | // arguments:␊ |
395 | //␉ biosdev - Value passed from boot1/NBP to specify the device␊ |
396 | //␉␉␉ that the booter was loaded from.␊ |
397 | //␊ |
398 | // If biosdev is kBIOSDevNetwork, then this function will return if␊ |
399 | // booting was unsuccessful. This allows the PXE firmware to try the␊ |
400 | // next boot device on its list.␊ |
401 | void common_boot(int biosdev)␊ |
402 | {␊ |
403 | ␉bool␉ ␉␉quiet;␊ |
404 | ␉bool␉ ␉␉firstRun = true;␊ |
405 | ␉bool␉ ␉␉instantMenu;␊ |
406 | ␉bool␉ ␉␉rescanPrompt;␊ |
407 | ␉int␉␉␉␉status;␊ |
408 | ␉unsigned int␉allowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;␊ |
409 | ␉unsigned int␉denyBVFlags = kBVFlagEFISystem;␊ |
410 | ␊ |
411 | ␉// Set reminder to unload the PXE base code. Neglect to unload␊ |
412 | ␉// the base code will result in a hang or kernel panic.␊ |
413 | ␉gUnloadPXEOnExit = true;␊ |
414 | ␊ |
415 | ␉// Record the device that the booter was loaded from.␊ |
416 | ␉gBIOSDev = biosdev & kBIOSDevMask;␊ |
417 | ␊ |
418 | ␉// Initialize boot-log␊ |
419 | ␉initBooterLog();␊ |
420 | ␊ |
421 | ␉// Initialize boot info structure.␊ |
422 | ␉initKernBootStruct();␊ |
423 | ␊ |
424 | ␉// Setup VGA text mode.␊ |
425 | ␉// Not sure if it is safe to call setVideoMode() before the␊ |
426 | ␉// config table has been loaded. Call video_mode() instead.␊ |
427 | #if DEBUG␊ |
428 | ␉printf("before video_mode\n");␊ |
429 | #endif␊ |
430 | ␉video_mode( 2 ); // 80x25 mono text mode.␊ |
431 | #if DEBUG␊ |
432 | ␉printf("after video_mode\n");␊ |
433 | #endif␊ |
434 | ␊ |
435 | ␉// Scan and record the system's hardware information.␊ |
436 | ␉scan_platform();␊ |
437 | ␊ |
438 | ␉// First get info for boot volume.␊ |
439 | ␉scanBootVolumes(gBIOSDev, 0);␊ |
440 | ␉bvChain = getBVChainForBIOSDev(gBIOSDev);␊ |
441 | ␉setBootGlobals(bvChain);␊ |
442 | ␊ |
443 | ␉// Load boot.plist config file␊ |
444 | ␉status = loadChameleonConfig(&bootInfo->chameleonConfig, bvChain);␊ |
445 | ␊ |
446 | ␉if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet)␊ |
447 | ␉{␊ |
448 | ␉␉gBootMode |= kBootModeQuiet;␊ |
449 | ␉}␊ |
450 | ␊ |
451 | ␉// Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config␊ |
452 | ␉if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->chameleonConfig) && instantMenu)␊ |
453 | ␉{␊ |
454 | ␉␉firstRun = false;␊ |
455 | ␉}␊ |
456 | ␊ |
457 | ␉// Loading preboot ramdisk if exists.␊ |
458 | ␉loadPrebootRAMDisk();␊ |
459 | ␊ |
460 | ␉// Disable rescan option by default␊ |
461 | ␉gEnableCDROMRescan = false;␊ |
462 | ␊ |
463 | ␉// Enable it with Rescan=y in system config␊ |
464 | ␉if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->chameleonConfig)␉&& gEnableCDROMRescan)␊ |
465 | ␉{␊ |
466 | ␉␉gEnableCDROMRescan = true;␊ |
467 | ␉}␊ |
468 | ␊ |
469 | ␉// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.␊ |
470 | ␉rescanPrompt = false;␊ |
471 | ␉if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev))␊ |
472 | ␉{␊ |
473 | ␉␉gEnableCDROMRescan = promptForRescanOption();␊ |
474 | ␉}␊ |
475 | ␊ |
476 | ␉// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.␊ |
477 | ␉if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->chameleonConfig) && gScanSingleDrive)␊ |
478 | ␉{␊ |
479 | ␉␉gScanSingleDrive = true;␊ |
480 | ␉}␊ |
481 | ␊ |
482 | ␉// Create a list of partitions on device(s).␊ |
483 | ␉if (gScanSingleDrive)␊ |
484 | ␉{␊ |
485 | ␉␉scanBootVolumes(gBIOSDev, &bvCount);␊ |
486 | ␉}␊ |
487 | ␉else␊ |
488 | ␉{␊ |
489 | ␉␉scanDisks(gBIOSDev, &bvCount);␊ |
490 | ␉}␊ |
491 | ␊ |
492 | ␉// Create a separated bvr chain using the specified filters.␊ |
493 | ␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
494 | ␊ |
495 | ␉gBootVolume = selectBootVolume(bvChain);␊ |
496 | ␊ |
497 | ␉// Intialize module system␊ |
498 | ␉init_module_system();␊ |
499 | ␊ |
500 | #if DEBUG␊ |
501 | ␉printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n",␊ |
502 | ␉␉␉ gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);␊ |
503 | ␉printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n",␊ |
504 | ␉␉␉ gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);␊ |
505 | ␉getchar();␊ |
506 | #endif␊ |
507 | ␊ |
508 | ␉useGUI = true;␊ |
509 | ␉// Override useGUI default␊ |
510 | ␉getBoolForKey(kGUIKey, &useGUI, &bootInfo->chameleonConfig);␊ |
511 | ␉if (useGUI && initGUI())␊ |
512 | ␉{␊ |
513 | ␉␉// initGUI() returned with an error, disabling GUI.␊ |
514 | ␉␉useGUI = false;␊ |
515 | ␉}␊ |
516 | ␊ |
517 | ␉setBootGlobals(bvChain);␊ |
518 | ␊ |
519 | ␉// Parse args, load and start kernel.␊ |
520 | ␉while (1)␊ |
521 | ␉{␊ |
522 | ␉␉bool␉␉tryresume, tryresumedefault, forceresume;␊ |
523 | ␉␉bool␉␉useKernelCache = true; // by default try to use the prelinked kernel␊ |
524 | ␉␉const char␉*val;␊ |
525 | ␉␉int␉␉␉len, ret = -1;␊ |
526 | ␉␉long␉␉flags;␊ |
527 | u_int32_t sleeptime, time;␊ |
528 | ␉␉void␉␉*binary = (void *)kLoadAddr;␊ |
529 | ␊ |
530 | ␉␉char bootFile[sizeof(bootInfo->bootFile)];␊ |
531 | ␉␉char␉␉bootFilePath[512];␊ |
532 | ␉␉char␉␉kernelCacheFile[512];␊ |
533 | ␊ |
534 | ␉␉// Initialize globals.␊ |
535 | ␉␉sysConfigValid = false;␊ |
536 | ␉␉gErrors␉␉ = false;␊ |
537 | ␊ |
538 | ␉␉status = getBootOptions(firstRun);␊ |
539 | ␉␉firstRun = false;␊ |
540 | ␉␉if (status == -1) continue;␊ |
541 | ␊ |
542 | ␉␉status = processBootOptions();␊ |
543 | ␉␉// Status == 1 means to chainboot␊ |
544 | ␉␉if ( status ==␉1 ) break;␊ |
545 | ␉␉// Status == -1 means that the config file couldn't be loaded or that gBootVolume is NULL␊ |
546 | ␉␉if ( status == -1 )␊ |
547 | ␉␉{␊ |
548 | ␉␉␉// gBootVolume == NULL usually means the user hit escape.␊ |
549 | ␉␉␉if (gBootVolume == NULL)␊ |
550 | ␉␉␉{␊ |
551 | ␉␉␉␉freeFilteredBVChain(bvChain);␊ |
552 | ␊ |
553 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
554 | ␉␉␉␉␉rescanBIOSDevice(gBIOSDev);␊ |
555 | ␊ |
556 | ␉␉␉␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
557 | ␉␉␉␉setBootGlobals(bvChain);␊ |
558 | ␉␉␉␉setupDeviceList(&bootInfo->themeConfig);␊ |
559 | ␉␉␉}␊ |
560 | ␉␉␉continue;␊ |
561 | ␉␉}␊ |
562 | ␊ |
563 | ␉␉// Other status (e.g. 0) means that we should proceed with boot.␊ |
564 | ␊ |
565 | ␉␉// Turn off any GUI elements␊ |
566 | ␉␉if ( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
567 | ␉␉{␊ |
568 | ␉␉␉gui.devicelist.draw = false;␊ |
569 | ␉␉␉gui.bootprompt.draw = false;␊ |
570 | ␉␉␉gui.menu.draw = false;␊ |
571 | ␉␉␉gui.infobox.draw = false;␊ |
572 | ␉␉␉gui.logo.draw = false;␊ |
573 | ␉␉␉drawBackground();␊ |
574 | ␉␉␉updateVRAM();␊ |
575 | ␉␉}␊ |
576 | ␊ |
577 | ␉␉if (platformCPUFeature(CPU_FEATURE_EM64T)) {␊ |
578 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
579 | ␉␉} else {␊ |
580 | ␉␉␉archCpuType = CPU_TYPE_I386;␊ |
581 | ␉␉}␊ |
582 | ␊ |
583 | ␉␉if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig)) {␊ |
584 | ␉␉␉if (strncmp(val, "i386", 4) == 0) {␊ |
585 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
586 | ␉␉␉}␊ |
587 | ␉␉}␊ |
588 | ␊ |
589 | ␉␉if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig)) {␊ |
590 | ␉␉␉if (strncmp(val, "i386", 4) == 0) {␊ |
591 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
592 | ␉␉␉}␊ |
593 | ␉␉}␊ |
594 | ␊ |
595 | ␉␉// Notify modules that we are attempting to boot␊ |
596 | ␉␉execute_hook("PreBoot", NULL, NULL, NULL, NULL);␊ |
597 | ␊ |
598 | ␉␉if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig)) {␊ |
599 | ␉␉␉tryresume = true;␊ |
600 | ␉␉␉tryresumedefault = true;␊ |
601 | ␉␉} else {␊ |
602 | ␉␉␉tryresumedefault = false;␊ |
603 | ␉␉}␊ |
604 | ␊ |
605 | ␉␉if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig)) {␊ |
606 | ␉␉␉forceresume = false;␊ |
607 | ␉␉}␊ |
608 | ␊ |
609 | ␉␉if (forceresume) {␊ |
610 | ␉␉␉tryresume = true;␊ |
611 | ␉␉␉tryresumedefault = false;␊ |
612 | ␉␉}␊ |
613 | ␊ |
614 | ␉␉while (tryresume) {␊ |
615 | ␉␉␉const char *tmp;␊ |
616 | ␉␉␉BVRef bvr;␊ |
617 | ␉␉␉if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->chameleonConfig))␊ |
618 | ␉␉␉␉val = "/private/var/vm/sleepimage";␊ |
619 | ␊ |
620 | ␉␉␉// Do this first to be sure that root volume is mounted␊ |
621 | ␉␉␉ret = GetFileInfo(0, val, &flags, &sleeptime);␊ |
622 | ␊ |
623 | ␉␉␉if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)␊ |
624 | ␉␉␉␉break;␊ |
625 | ␊ |
626 | ␉␉␉// Can't check if it was hibernation Wake=y is required␊ |
627 | ␉␉␉if (bvr->modTime == 0 && tryresumedefault)␊ |
628 | ␉␉␉␉break;␊ |
629 | ␊ |
630 | ␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
631 | ␉␉␉␉break;␊ |
632 | ␊ |
633 | ␉␉␉if (!forceresume && ((sleeptime+3)<bvr->modTime)) {␊ |
634 | #if DEBUG␊ |
635 | ␉␉␉␉printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",␊ |
636 | ␉␉␉␉␉␉bvr->modTime-sleeptime);␊ |
637 | #endif␊ |
638 | ␉␉␉␉break;␊ |
639 | ␉␉␉}␊ |
640 | ␊ |
641 | ␉␉␉HibernateBoot((char *)val);␊ |
642 | ␉␉␉break;␊ |
643 | ␉␉}␊ |
644 | ␊ |
645 | ␉␉getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);␊ |
646 | ␉␉if (useKernelCache) do {␊ |
647 | ␊ |
648 | ␉␉␉// Determine the name of the Kernel Cache␊ |
649 | ␉␉␉if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {␊ |
650 | ␉␉␉␉if (val[0] == '\\')␊ |
651 | ␉␉␉␉{␊ |
652 | ␉␉␉␉␉len--;␊ |
653 | ␉␉␉␉␉val++;␊ |
654 | ␉␉␉␉}␊ |
655 | ␉␉␉␉/* FIXME: check len vs sizeof(kernelCacheFile) */␊ |
656 | ␉␉␉␉strlcpy(kernelCacheFile, val, len + 1);␊ |
657 | ␉␉␉} else {␊ |
658 | ␉␉␉␉kernelCacheFile[0] = 0; // Use default kernel cache file␊ |
659 | ␉␉␉}␊ |
660 | ␊ |
661 | ␉␉␉if (gOverrideKernel && kernelCacheFile[0] == 0) {␊ |
662 | ␉␉␉␉DBG("Using a non default kernel (%s) without specifying 'Kernel Cache' path, KernelCache will not be used\n", bootInfo->bootFile);␊ |
663 | ␉␉␉␉useKernelCache = false;␊ |
664 | ␉␉␉␉break;␊ |
665 | ␉␉␉}␊ |
666 | ␉␉␉if (gMKextName[0] != 0) {␊ |
667 | ␉␉␉␉DBG("Using a specific MKext Cache (%s), KernelCache will not be used\n",␊ |
668 | ␉␉␉␉␉␉gMKextName);␊ |
669 | ␉␉␉␉useKernelCache = false;␊ |
670 | ␉␉␉␉break;␊ |
671 | ␉␉␉}␊ |
672 | ␉␉␉if (gBootFileType != kBlockDeviceType)␊ |
673 | ␉␉␉␉useKernelCache = false;␊ |
674 | ␊ |
675 | ␉␉} while(0);␊ |
676 | ␊ |
677 | ␉␉do {␊ |
678 | ␉␉␉if (useKernelCache) {␊ |
679 | ␉␉␉␉ret = LoadKernelCache(kernelCacheFile, &binary);␊ |
680 | ␉␉␉␉if (ret >= 0)␊ |
681 | ␉␉␉␉␉break;␊ |
682 | ␉␉␉}␊ |
683 | ␊ |
684 | ␉␉␉bool bootFileWithDevice = false;␊ |
685 | ␉␉␉// Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel␊ |
686 | ␉␉␉if (strncmp(bootInfo->bootFile,"bt(",3) == 0 ||␊ |
687 | ␉␉␉␉strncmp(bootInfo->bootFile,"hd(",3) == 0 ||␊ |
688 | ␉␉␉␉strncmp(bootInfo->bootFile,"rd(",3) == 0)␊ |
689 | ␉␉␉␉bootFileWithDevice = true;␊ |
690 | ␊ |
691 | ␉␉␉// bootFile must start with a / if it not start with a device name␊ |
692 | ␉␉␉if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/')␊ |
693 | ␉␉␉{␊ |
694 | ␉␉␉␉if (!YOSEMITE)␊ |
695 | ␉␉␉␉{␊ |
696 | ␉␉␉␉␉//printf(HEADER " (%s).\n", bootInfo->bootFile);␊ |
697 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading /␊ |
698 | ␉␉␉␉␉//sleep(1);␊ |
699 | ␉␉␉␉} else {␊ |
700 | ␊ |
701 | ␉␉␉␉␉//printf(HEADER " (%s).\n", bootInfo->bootFile);␊ |
702 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), kDefaultKernelPathForYos"%s", bootInfo->bootFile); // Yosemite␊ |
703 | ␉␉␉␉␉//sleep(1);␊ |
704 | ␉␉␉␉}␊ |
705 | ␉␉␉} else {␊ |
706 | ␉␉␉␉strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile));␊ |
707 | ␉␉␉}␊ |
708 | ␊ |
709 | ␉␉␉// Try to load kernel image from alternate locations on boot helper partitions.␊ |
710 | ␉␉␉ret = -1;␊ |
711 | ␉␉␉if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice) {␊ |
712 | ␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.P%s", bootFile);␊ |
713 | ␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
714 | ␉␉␉␉if (ret == -1)␊ |
715 | ␉␉␉␉{␊ |
716 | ␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.R%s", bootFile);␊ |
717 | ␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
718 | ␉␉␉␉␉if (ret == -1)␊ |
719 | ␉␉␉␉␉{␊ |
720 | ␉␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.S%s", bootFile);␊ |
721 | ␉␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
722 | ␉␉␉␉␉}␊ |
723 | ␉␉␉␉}␊ |
724 | ␉␉␉}␊ |
725 | ␉␉␉if (ret == -1) {␊ |
726 | ␉␉␉␉// No alternate location found, using the original kernel image path.␊ |
727 | ␉␉␉␉strlcpy(bootFilePath, bootFile, sizeof(bootFilePath));␊ |
728 | ␉␉␉}␊ |
729 | ␊ |
730 | ␉␉␉DBG("Loading kernel: '%s'\n", bootFilePath);␊ |
731 | ␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
732 | ␉␉␉if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
733 | ␉␉␉{␊ |
734 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
735 | ␉␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
736 | ␉␉␉}␊ |
737 | ␉␉} while (0);␊ |
738 | ␊ |
739 | ␉␉clearActivityIndicator();␊ |
740 | ␊ |
741 | #if DEBUG␊ |
742 | ␉␉printf("Pausing...");␊ |
743 | ␉␉sleep(8);␊ |
744 | #endif␊ |
745 | ␊ |
746 | ␉␉if (ret <= 0)␊ |
747 | ␉␉{␊ |
748 | ␉␉␉printf("Can't find %s\n", bootFile);␊ |
749 | ␉␉␉sleep(1);␊ |
750 | ␊ |
751 | ␉␉␉if (gBootFileType == kNetworkDeviceType)␊ |
752 | ␉␉␉{␊ |
753 | ␉␉␉␉// Return control back to PXE. Don't unload PXE base code.␊ |
754 | ␉␉␉␉gUnloadPXEOnExit = false;␊ |
755 | ␉␉␉␉break;␊ |
756 | ␉␉␉}␊ |
757 | ␉␉␉pause();␊ |
758 | ␊ |
759 | ␉␉} else {␊ |
760 | ␉␉␉/* Won't return if successful. */␊ |
761 | ␉␉␉ret = ExecKernel(binary);␊ |
762 | ␉␉}␊ |
763 | ␉}␊ |
764 | ␊ |
765 | ␉// chainboot␊ |
766 | ␉if (status == 1) {␊ |
767 | ␉␉// if we are already in graphics-mode,␊ |
768 | ␉␉if (getVideoMode() == GRAPHICS_MODE) {␊ |
769 | ␉␉␉setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode.␊ |
770 | ␉␉}␊ |
771 | ␉}␊ |
772 | ␊ |
773 | ␉if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) {␊ |
774 | ␉␉nbpUnloadBaseCode();␊ |
775 | ␉}␊ |
776 | }␊ |
777 | ␊ |
778 | /*!␊ |
779 | ␉Selects a new BIOS device, taking care to update the global state appropriately.␊ |
780 | */␊ |
781 | /*␊ |
782 | static void selectBiosDevice(void)␊ |
783 | {␊ |
784 | ␉struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);␊ |
785 | ␉CacheReset();␊ |
786 | ␉diskFreeMap(oldMap);␊ |
787 | ␉oldMap = NULL;␊ |
788 | ␊ |
789 | ␉int dev = selectAlternateBootDevice(gBIOSDev);␊ |
790 | ␊ |
791 | ␉BVRef bvchain = scanBootVolumes(dev, 0);␊ |
792 | ␉BVRef bootVol = selectBootVolume(bvchain);␊ |
793 | ␉gBootVolume = bootVol;␊ |
794 | ␉setRootVolume(bootVol);␊ |
795 | ␉gBIOSDev = dev;␊ |
796 | }␊ |
797 | */␊ |
798 | ␊ |
799 | bool checkOSVersion(const char * version)␊ |
800 | {␊ |
801 | ␉if ( (sizeof(version) > 4) && (version[3] == '1') ) {␊ |
802 | ␉␉return ((gMacOSVersion[0] == version[0]) && (gMacOSVersion[1] == version[1])␊ |
803 | ␉␉&& (gMacOSVersion[2] == version[2]) && (gMacOSVersion[3] == version[3])␊ |
804 | ␉␉&& (gMacOSVersion[4] == version[4]));␊ |
805 | ␉} else {␊ |
806 | ␉␉return ((gMacOSVersion[0] == version[0]) && (gMacOSVersion[1] == version[1])␊ |
807 | ␉␉&& (gMacOSVersion[2] == version[2]) && (gMacOSVersion[3] == version[3]));␊ |
808 | ␉}␊ |
809 | }␊ |
810 | ␊ |
811 | #define BASE 65521L /* largest prime smaller than 65536 */␊ |
812 | #define NMAX 5000␊ |
813 | // NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1␊ |
814 | ␊ |
815 | #define DO1(buf, i)␉{s1 += buf[i]; s2 += s1;}␊ |
816 | #define DO2(buf, i)␉DO1(buf, i); DO1(buf, i + 1);␊ |
817 | #define DO4(buf, i)␉DO2(buf, i); DO2(buf, i + 2);␊ |
818 | #define DO8(buf, i)␉DO4(buf, i); DO4(buf, i + 4);␊ |
819 | #define DO16(buf)␉DO8(buf, 0); DO8(buf, 8);␊ |
820 | ␊ |
821 | unsigned long Adler32(unsigned char *buf, long len)␊ |
822 | {␊ |
823 | ␉unsigned long s1 = 1; // adler & 0xffff;␊ |
824 | ␉unsigned long s2 = 0; // (adler >> 16) & 0xffff;␊ |
825 | ␉unsigned long result;␊ |
826 | ␉int k;␊ |
827 | ␊ |
828 | ␉while (len > 0) {␊ |
829 | ␉␉k = len < NMAX ? len : NMAX;␊ |
830 | ␉␉len -= k;␊ |
831 | ␉␉while (k >= 16) {␊ |
832 | ␉␉␉DO16(buf);␊ |
833 | ␉␉␉buf += 16;␊ |
834 | ␉␉␉k -= 16;␊ |
835 | ␉␉}␊ |
836 | ␉␉if (k != 0) do {␊ |
837 | ␉␉␉s1 += *buf++;␊ |
838 | ␉␉␉s2 += s1;␊ |
839 | ␉␉} while (--k);␊ |
840 | ␉␉s1 %= BASE;␊ |
841 | ␉␉s2 %= BASE;␊ |
842 | ␉}␊ |
843 | ␉result = (s2 << 16) | s1;␊ |
844 | ␉return OSSwapHostToBigInt32(result);␊ |
845 | }␊ |
846 | |