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 | * Mach Operating System␊ |
26 | * Copyright (c) 1990 Carnegie-Mellon University␊ |
27 | * Copyright (c) 1989 Carnegie-Mellon University␊ |
28 | * All rights reserved. The CMU software License Agreement specifies␊ |
29 | * the terms and conditions for use and redistribution.␊ |
30 | */␊ |
31 | ␊ |
32 | /*␊ |
33 | * INTEL CORPORATION PROPRIETARY INFORMATION␊ |
34 | *␊ |
35 | * This software is supplied under the terms of a license agreement or ␊ |
36 | * nondisclosure agreement with Intel Corporation and may not be copied ␊ |
37 | * nor disclosed except in accordance with the terms of that agreement.␊ |
38 | *␊ |
39 | * Copyright 1988, 1989 by Intel Corporation␊ |
40 | */␊ |
41 | ␊ |
42 | /*␊ |
43 | * Copyright 1993 NeXT Computer, Inc.␊ |
44 | * All rights reserved.␊ |
45 | */␊ |
46 | ␊ |
47 | /*␊ |
48 | * Completely reworked by Sam Streeper (sam_s@NeXT.com)␊ |
49 | * Reworked again by Curtis Galloway (galloway@NeXT.com)␊ |
50 | */␊ |
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 "platform.h"␊ |
59 | #include "graphics.h"␊ |
60 | #ifndef OPTION_ROM␊ |
61 | #include "appleboot.h"␊ |
62 | #endif␊ |
63 | #include "modules.h"␊ |
64 | #include "xml.h"␊ |
65 | ␊ |
66 | #ifndef DEBUG_BOOT␊ |
67 | #define DEBUG_BOOT 0␊ |
68 | #endif␊ |
69 | ␊ |
70 | #if DEBUG_BOOT␊ |
71 | #define DBG(x...)␉␉printf(x)␊ |
72 | #else␊ |
73 | #define DBG(x...)␉␉␊ |
74 | #endif␊ |
75 | ␊ |
76 | ␊ |
77 | typedef struct platform_info {␊ |
78 | ␉char platformName[PLATFORM_NAME_LEN];␊ |
79 | ␉char rootPath[ROOT_PATH_LEN];␊ |
80 | } PlatformInfo;␊ |
81 | ␊ |
82 | ␊ |
83 | char *gboardproduct = NULL;␊ |
84 | char *gPlatformName = NULL;␊ |
85 | //char gRootPath[256];␊ |
86 | long gBootMode; /* defaults to 0 == kBootModeNormal */␊ |
87 | bool gOverrideKernel;␊ |
88 | char gBootKernelCacheFile[512];␊ |
89 | char gMKextName[512];␊ |
90 | char gMacOSVersion[8];␊ |
91 | char *gRootDevice = NULL;␊ |
92 | bool uuidSet = false;␊ |
93 | #ifndef OPTION_ROM␊ |
94 | bool gEnableCDROMRescan;␊ |
95 | bool gScanSingleDrive;␊ |
96 | #endif␊ |
97 | ␊ |
98 | int bvCount = 0;␊ |
99 | //int␉menucount = 0;␊ |
100 | int gDeviceCount = 0; ␊ |
101 | ␊ |
102 | BVRef bvr;␊ |
103 | BVRef menuBVR;␊ |
104 | BVRef bvChain;␊ |
105 | ␊ |
106 | //static void selectBiosDevice(void);␊ |
107 | ␊ |
108 | static bool getOSVersion(char *str);␊ |
109 | static void getRootDevice();␊ |
110 | void getKernelCachePath();␊ |
111 | ␊ |
112 | #ifdef NBP_SUPPORT␊ |
113 | static bool gUnloadPXEOnExit = false;␊ |
114 | #endif␊ |
115 | ␊ |
116 | /*␊ |
117 | * How long to wait (in seconds) to load the␊ |
118 | * kernel after displaying the "boot:" prompt.␊ |
119 | */␊ |
120 | #define kBootErrorTimeout 5␊ |
121 | ␊ |
122 | /*␊ |
123 | * Default path to kernel cache file␊ |
124 | */␊ |
125 | #define kDefaultCachePath "/System/Library/Caches/com.apple.kext.caches/Startup/kernelcache"␊ |
126 | ␊ |
127 | //==========================================================================␊ |
128 | // Zero the BSS.␊ |
129 | ␊ |
130 | static void zeroBSS(void)␊ |
131 | {␊ |
132 | ␉extern char _DATA__bss__begin, _DATA__bss__end;␊ |
133 | ␉extern char _DATA__common__begin, _DATA__common__end;␊ |
134 | ␉␊ |
135 | ␉bzero(&_DATA__bss__begin, (&_DATA__bss__end - &_DATA__bss__begin));␊ |
136 | ␉bzero(&_DATA__common__begin, (&_DATA__common__end - &_DATA__common__begin));␊ |
137 | }␊ |
138 | ␊ |
139 | //==========================================================================␊ |
140 | // Malloc error function␊ |
141 | ␊ |
142 | #ifdef SAFE_MALLOC␊ |
143 | static inline void malloc_error(char *addr, size_t size, const char *file, int line)␊ |
144 | {␊ |
145 | stop("\nMemory allocation error! Addr=0x%x, Size=0x%x, File=%s, Line=%d\n", (unsigned)addr, (unsigned)size, file, line);␊ |
146 | }␊ |
147 | #else␊ |
148 | static inline void malloc_error(char *addr, size_t size)␊ |
149 | {␊ |
150 | printf("\nMemory allocation error (0x%x, 0x%x)\n", (unsigned)addr, (unsigned)size);␊ |
151 | asm volatile ("hlt");␊ |
152 | }␊ |
153 | #endif␊ |
154 | ␊ |
155 | //==========================================================================␊ |
156 | //Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.␊ |
157 | //␊ |
158 | void initialize_runtime(void)␊ |
159 | {␊ |
160 | ␉zeroBSS();␊ |
161 | ␉malloc_init(0, 0, 0, malloc_error);␊ |
162 | }␊ |
163 | ␊ |
164 | //==========================================================================␊ |
165 | // execKernel - Load the kernel image (mach-o) and jump to its entry point.␊ |
166 | ␊ |
167 | static int ExecKernel(void *binary)␊ |
168 | {␊ |
169 | entry_t kernelEntry;␊ |
170 | int ret;␊ |
171 | ␉␊ |
172 | bootArgs->kaddr = bootArgs->ksize = 0;␊ |
173 | ␉␊ |
174 | ␉if(gMacOSVersion[3] <= '6')␊ |
175 | ␉{␊ |
176 | ␉␉bootArgs->Version = kBootArgsVersion1;␉␉␊ |
177 | ␉␉bootArgs->Revision = gMacOSVersion[3];␉␊ |
178 | ␉}␊ |
179 | ␉else ␊ |
180 | ␉{␉␉␊ |
181 | #if kBootArgsVersion > 1␊ |
182 | ␉␉␊ |
183 | ␉␉bootArgs->Version = kBootArgsVersion;␉␉␊ |
184 | ␉␉bootArgs->Revision = kBootArgsRevision;␊ |
185 | #else␊ |
186 | ␉␉bootArgs->Version = 2;␊ |
187 | bootArgs->Revision = 0;␊ |
188 | #endif␊ |
189 | ␉}␊ |
190 | ␉␊ |
191 | ␉execute_hook("ExecKernel", (void*)binary, NULL, NULL, NULL, NULL, NULL);␊ |
192 | ␊ |
193 | ret = DecodeKernel(binary,␊ |
194 | &kernelEntry,␊ |
195 | (char **) &bootArgs->kaddr,␊ |
196 | (int *)&bootArgs->ksize );␊ |
197 | ␊ |
198 | if ( ret != 0 )␊ |
199 | return ret;␊ |
200 | ␉␊ |
201 | // Reserve space for boot args for 10.7 only (for 10.6 and earlier, we will convert (to legacy) the structure and reserve kernel memory for it later.)␊ |
202 | ␉if(gMacOSVersion[3] == '7')␊ |
203 | reserveKernBootStruct();␊ |
204 | ␉␊ |
205 | // Load boot drivers from the specifed root path.␊ |
206 | ␉␊ |
207 | if (!gHaveKernelCache) {␊ |
208 | ␉␉LoadDrivers("/");␊ |
209 | }␊ |
210 | ␉␊ |
211 | #if TEXT_SPINNER␊ |
212 | ␉clearActivityIndicator();␊ |
213 | #endif␊ |
214 | ␉␊ |
215 | if (gErrors) {␊ |
216 | printf("Errors encountered while starting up the computer.\n");␊ |
217 | printf("Pausing %d seconds...\n", kBootErrorTimeout);␊ |
218 | sleep(kBootErrorTimeout);␊ |
219 | }␊ |
220 | ␉␊ |
221 | ␉execute_hook("md0Ramdisk", NULL, NULL, NULL, NULL, NULL, NULL);␊ |
222 | ␊ |
223 | setupFakeEfi();␊ |
224 | ␉␉␊ |
225 | verbose("Starting Darwin %s\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64");␊ |
226 | #ifdef NBP_SUPPORT␊ |
227 | // Cleanup the PXE base code.␊ |
228 | ␉␊ |
229 | if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit ) {␊ |
230 | ␉␉if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )␊ |
231 | {␊ |
232 | ␉printf("nbpUnloadBaseCode error %d\n", (int) ret);␊ |
233 | sleep(2);␊ |
234 | }␊ |
235 | }␊ |
236 | #endif ␊ |
237 | bool wait = false;␊ |
238 | ␉const char *strval = 0;␊ |
239 | ␉int dummysize /*= 0*/;␉␊ |
240 | ␉␊ |
241 | ␉getBoolForKey(kWaitForKeypressKey, &wait, &bootInfo->bootConfig);␊ |
242 | ␉␊ |
243 | ␉if (getValueForBootKey(bootArgs->CommandLine, "-wait", &strval, &dummysize))␊ |
244 | ␉{␊ |
245 | ␉␉wait = true;␊ |
246 | ␉␉␊ |
247 | ␉␉if (strval && ((strcmp(strval, "no") == 0) || (strcmp(strval, "No") == 0))) {␊ |
248 | ␉␉␉wait = false;␊ |
249 | ␉␉} ␉␉␊ |
250 | ␉}␊ |
251 | ␉␉␊ |
252 | ␉if (wait == true) {␊ |
253 | ␉␉pause();␊ |
254 | ␉}␊ |
255 | ␉␉␉␊ |
256 | ␉if ((execute_hook("GUI_ExecKernel", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)) // (bootArgs->Video.v_display == VGA_TEXT_MODE)␉␊ |
257 | ␉{␊ |
258 | #if UNUSED␊ |
259 | ␉␉setVideoMode( GRAPHICS_MODE, 0 );␊ |
260 | #else␊ |
261 | ␉␉setVideoMode( GRAPHICS_MODE );␊ |
262 | #endif␊ |
263 | ␉␉␊ |
264 | #ifndef OPTION_ROM␊ |
265 | ␉␉ ␊ |
266 | ␉␉if(!gVerboseMode)␊ |
267 | ␉␉{␉␉␉␊ |
268 | ␉␉␉drawColorRectangle(0, 0, DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 0x01); ␊ |
269 | ␉␉␊ |
270 | ␉␉␉uint8_t *appleBootPict; ␊ |
271 | ␉␉␉uint16_t bootImageWidth = kAppleBootWidth; ␊ |
272 | ␉␉␉uint16_t bootImageHeight = kAppleBootHeight; ␊ |
273 | ␉␉␉uint8_t *bootImageData = NULL; ␉␉ ␊ |
274 | ␉␉␉uint16_t x, y;␊ |
275 | ␉␉␉␊ |
276 | ␉␉␉unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};␉// here we store the used screen resolution␊ |
277 | ␉␉␉// Prepare the data for the default Apple boot image. ␊ |
278 | ␉␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); ␊ |
279 | ␉␉␉if (appleBootPict) { ␊ |
280 | ␉␉␉␉convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData); ␊ |
281 | ␉␉␉␉if (bootImageData) {␉␊ |
282 | ␉␉␉␉␉x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; ␊ |
283 | ␉␉␉␉␉y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; ␊ |
284 | ␉␉␉␉␉drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
285 | ␉␉␉␉␉free(bootImageData);␊ |
286 | ␉␉␉␉}␊ |
287 | ␉␉␉␉free(appleBootPict); ␊ |
288 | ␉␉␉}␊ |
289 | ␉␉␊ |
290 | ␉␉}␊ |
291 | #endif␊ |
292 | ␉}␊ |
293 | ␊ |
294 | finalizeEFIConfigTable();␊ |
295 | ␊ |
296 | ␉setupBooterLog();␊ |
297 | ␉␊ |
298 | finalizeBootStruct(); ␊ |
299 | ␊ |
300 | ␉␊ |
301 | ␉if (gMacOSVersion[3] <= '6') ␊ |
302 | ␉␉reserveKernLegacyBootStruct(); ␉␉␊ |
303 | ␉␊ |
304 | ␉execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL, NULL, NULL);␉// Notify modules that the kernel is about to be started␊ |
305 | #if UNUSED␊ |
306 | ␉turnOffFloppy();␊ |
307 | #endif␊ |
308 | #if BETA␊ |
309 | #include "smp.h"␊ |
310 | #include "apic.h"␊ |
311 | ␉IMPS_LAPIC_WRITE(LAPIC_LVT1, LAPIC_ICR_DM_NMI);␊ |
312 | #endif␊ |
313 | ␉␊ |
314 | ␉if (gMacOSVersion[3] <= '6') {␉␉␊ |
315 | ␉␉␊ |
316 | ␉␉// Jump to kernel's entry point. There's no going back now. XXX LEGACY OS XXX␊ |
317 | ␉␉startprog( kernelEntry, bootArgsLegacy );␊ |
318 | ␉}␉␊ |
319 | ␉␉␉␊ |
320 | ␉outb(0x21, 0xff); /* Maskout all interrupts Pic1 */␊ |
321 | ␉outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */␊ |
322 | ␉␉␊ |
323 | ␉// Jump to kernel's entry point. There's no going back now. XXX LION XXX␊ |
324 | startprog( kernelEntry, bootArgs );␊ |
325 | ␉␊ |
326 | // Not reached␊ |
327 | ␉␊ |
328 | return 0;␊ |
329 | }␊ |
330 | ␊ |
331 | //==========================================================================␊ |
332 | // This is the entrypoint from real-mode which functions exactly as it did␊ |
333 | // before. Multiboot does its own runtime initialization, does some of its␊ |
334 | // own things, and then calls common_boot.␊ |
335 | void boot(int biosdev)␊ |
336 | {␊ |
337 | ␉initialize_runtime();␊ |
338 | ␉// Enable A20 gate before accessing memory above 1Mb.␊ |
339 | ␉enableA20();␊ |
340 | ␉common_boot(biosdev);␊ |
341 | }␊ |
342 | ␊ |
343 | //==========================================================================␊ |
344 | // The 'main' function for the booter. Called by boot0 when booting␊ |
345 | // from a block device, or by the network booter.␊ |
346 | //␊ |
347 | // arguments:␊ |
348 | // biosdev - Value passed from boot1/NBP to specify the device␊ |
349 | // that the booter was loaded from.␊ |
350 | //␊ |
351 | // If biosdev is kBIOSDevNetwork, then this function will return if␊ |
352 | // booting was unsuccessful. This allows the PXE firmware to try the␊ |
353 | // next boot device on its list.␊ |
354 | void common_boot(int biosdev)␊ |
355 | {␊ |
356 | int status;␊ |
357 | char *bootFile;␊ |
358 | bool quiet;␊ |
359 | bool firstRun = true;␊ |
360 | bool instantMenu;␊ |
361 | #ifndef OPTION_ROM␊ |
362 | bool rescanPrompt;␊ |
363 | #endif␊ |
364 | unsigned int allowBVFlags = kBVFlagSystemVolume|kBVFlagForeignBoot;␊ |
365 | unsigned int denyBVFlags = kBVFlagEFISystem;␊ |
366 | ␉␊ |
367 | #ifdef NBP_SUPPORT␊ |
368 | // Set reminder to unload the PXE base code. Neglect to unload␊ |
369 | // the base code will result in a hang or kernel panic.␊ |
370 | gUnloadPXEOnExit = true;␊ |
371 | #endif␊ |
372 | // Record the device that the booter was loaded from.␊ |
373 | gBIOSDev = biosdev & kBIOSDevMask;␊ |
374 | ␉␊ |
375 | ␉␊ |
376 | ␉␊ |
377 | // Setup VGA text mode.␊ |
378 | // Not sure if it is safe to call setVideoMode() before the␊ |
379 | // config table has been loaded. Call video_mode() instead.␊ |
380 | #if DEBUG␊ |
381 | printf("before video_mode\n");␊ |
382 | #endif␊ |
383 | video_mode( 2 ); // 80x25 mono text mode.␊ |
384 | #if DEBUG␊ |
385 | printf("after video_mode\n");␊ |
386 | #endif␊ |
387 | #if !TEXT_SPINNER␊ |
388 | ␉printf("Starting Chameleon ...\n");␊ |
389 | #endif␊ |
390 | ␉␊ |
391 | ␉initBooterLog();␊ |
392 | ␉␊ |
393 | ␉// Initialize boot info structure.␊ |
394 | initKernBootStruct();␊ |
395 | ␉␊ |
396 | ␉␊ |
397 | // Scan and record the system's hardware information.␊ |
398 | scan_platform();␊ |
399 | ␉␊ |
400 | // First get info for boot volume.␊ |
401 | scanBootVolumes(gBIOSDev, 0);␊ |
402 | bvChain = getBVChainForBIOSDev(gBIOSDev);␊ |
403 | setBootGlobals(bvChain);␊ |
404 | ␉␊ |
405 | // Load boot.plist config file␊ |
406 | status = loadSystemConfig(&bootInfo->bootConfig);␊ |
407 | ␉␊ |
408 | ␉Platform->CPU.isServer = false; ␊ |
409 | getBoolForKey(kIsServer, &Platform->CPU.isServer, &bootInfo->bootConfig); // set this as soon as possible␊ |
410 | ␉␊ |
411 | if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet) {␊ |
412 | gBootMode |= kBootModeQuiet;␊ |
413 | }␊ |
414 | ␉␊ |
415 | // Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config␊ |
416 | if (getBoolForKey(kInsantMenuKey, &instantMenu, &bootInfo->bootConfig) && instantMenu) {␊ |
417 | firstRun = false;␊ |
418 | }␊ |
419 | ␉␊ |
420 | #ifndef OPTION_ROM␊ |
421 | ␉// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.␊ |
422 | if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig) && gScanSingleDrive) {␊ |
423 | gScanSingleDrive = true;␊ |
424 | }␊ |
425 | ␉␊ |
426 | ␉// Create a list of partitions on device(s).␊ |
427 | if (gScanSingleDrive)␊ |
428 | ␉{␊ |
429 | ␉␉scanBootVolumes(gBIOSDev, &bvCount);␊ |
430 | } ␊ |
431 | ␉else ␊ |
432 | #endif␊ |
433 | ␉{␊ |
434 | #if UNUSED␊ |
435 | scanDisks(gBIOSDev, &bvCount);␊ |
436 | #else␊ |
437 | scanDisks();␊ |
438 | #endif␊ |
439 | }␊ |
440 | ␉␊ |
441 | ␉// Create a separated bvr chain using the specified filters.␊ |
442 | bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
443 | ␉gBootVolume = selectBootVolume(bvChain);␊ |
444 | ␉␊ |
445 | ␉// Intialize module system␊ |
446 | ␉EFI_STATUS sysinit = init_module_system();␊ |
447 | ␉if((sysinit == EFI_SUCCESS) || (sysinit == EFI_ALREADY_STARTED)/*should never happen*/ ) ␊ |
448 | ␉{␊ |
449 | ␉␉load_all_modules();␊ |
450 | ␉}␊ |
451 | ␉␉␉␊ |
452 | // Loading preboot ramdisk if exists.␊ |
453 | ␉execute_hook("loadPrebootRAMDisk", NULL, NULL, NULL, NULL, NULL, NULL);␉␉␊ |
454 | ␊ |
455 | #ifndef OPTION_ROM␊ |
456 | ␊ |
457 | // Disable rescan option by default␊ |
458 | gEnableCDROMRescan = false;␊ |
459 | ␉␊ |
460 | // Enable it with Rescan=y in system config␊ |
461 | if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->bootConfig) && gEnableCDROMRescan) {␊ |
462 | gEnableCDROMRescan = true;␊ |
463 | }␊ |
464 | ␉␊ |
465 | // Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.␊ |
466 | rescanPrompt = false;␊ |
467 | if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev)) {␊ |
468 | gEnableCDROMRescan = promptForRescanOption();␊ |
469 | }␊ |
470 | #endif␉␊ |
471 | ␉␊ |
472 | #if DEBUG␊ |
473 | printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);␊ |
474 | printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);␊ |
475 | getc();␊ |
476 | #endif␊ |
477 | ␉␉␉␊ |
478 | setBootGlobals(bvChain);␊ |
479 | ␉␊ |
480 | ␉// Display the GUI␊ |
481 | ␉execute_hook("GUI_Display", NULL, NULL, NULL, NULL, NULL, NULL);␊ |
482 | ␊ |
483 | // Parse args, load and start kernel.␊ |
484 | while (1) {␊ |
485 | const char *val;␊ |
486 | int len;␊ |
487 | int trycache = 0;␊ |
488 | long flags, cachetime, kerneltime, exttime;␊ |
489 | #ifdef BOOT_HELPER_SUPPORT␉␉␊ |
490 | ␉␉long time;␊ |
491 | #endif␊ |
492 | int ret = -1;␊ |
493 | void *binary = (void *)kLoadAddr;␊ |
494 | ␉␉␊ |
495 | // additional variable for testing alternate kernel image locations on boot helper partitions.␊ |
496 | char bootFileSpec[512];␊ |
497 | ␉␉␊ |
498 | // Initialize globals.␊ |
499 | ␉␉␊ |
500 | sysConfigValid = false;␊ |
501 | gErrors = false;␊ |
502 | ␉␉␊ |
503 | status = getBootOptions(firstRun);␊ |
504 | firstRun = false;␊ |
505 | if (status == -1) continue;␊ |
506 | ␉␉␊ |
507 | status = processBootOptions();␊ |
508 | // Status==1 means to chainboot␊ |
509 | if ( status == 1 ) break;␊ |
510 | // Status==-1 means that the config file couldn't be loaded or that gBootVolume is NULL␊ |
511 | if ( status == -1 )␊ |
512 | {␊ |
513 | ␉␉␉// gBootVolume == NULL usually means the user hit escape.␊ |
514 | ␉␉␉if(gBootVolume == NULL)␊ |
515 | ␉␉␉{␊ |
516 | ␉␉␉␉freeFilteredBVChain(bvChain);␊ |
517 | #ifndef OPTION_ROM␊ |
518 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
519 | ␉␉␉␉␉rescanBIOSDevice(gBIOSDev);␊ |
520 | #endif␊ |
521 | ␉␉␉␉␊ |
522 | ␉␉␉␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
523 | ␉␉␉␉setBootGlobals(bvChain);␊ |
524 | ␉␉␉}␊ |
525 | ␉␉␉continue;␊ |
526 | }␊ |
527 | ␉␉␉␉␉␉␊ |
528 | // Other status (e.g. 0) means that we should proceed with boot.␊ |
529 | ␉␉execute_hook("GUI_PreBoot", NULL, NULL, NULL, NULL, NULL, NULL);␊ |
530 | ␉␉␊ |
531 | ␉␉// Find out which version mac os we're booting.␊ |
532 | ␉␉getOSVersion(gMacOSVersion);␊ |
533 | ␉␉␊ |
534 | ␉␉//if (platformCPUFeature(CPU_FEATURE_EM64T)) { ␊ |
535 | if (cpu_mode_is64bit()) {␊ |
536 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
537 | ␉␉} else {␊ |
538 | ␉␉␉archCpuType = CPU_TYPE_I386;␊ |
539 | ␉␉}␊ |
540 | ␉␉if (getValueForKey(karch, &val, &len, &bootInfo->bootConfig)) {␊ |
541 | ␉␉␉if (strncmp(val, "i386", 4) == 0) {␊ |
542 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
543 | ␉␉␉}␊ |
544 | ␉␉}␊ |
545 | ␉␉␊ |
546 | ␉␉getRootDevice();␊ |
547 | ␊ |
548 | ␉␉// Notify to all modules that we are attempting to boot␊ |
549 | ␉␉execute_hook("PreBoot", NULL, NULL, NULL, NULL, NULL, NULL); ␊ |
550 | ␉␉␊ |
551 | ␉␉if (execute_hook("getProductNamePatched", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␉␉␉␉␉␊ |
552 | ␉␉␉readSMBIOS(thePlatformName); // read smbios Platform Name␊ |
553 | ␉␉␊ |
554 | ␉␉␊ |
555 | ␉␉if (!getValueForBootKey(bootArgs->CommandLine, kIgnorePrelinkKern, &val, &len)) { ␉␉␊ |
556 | ␉␉␉␉␊ |
557 | ␉␉␉getKernelCachePath(); ␊ |
558 | ␉␉␉␊ |
559 | ␉␉}␊ |
560 | ␉␉␊ |
561 | ␉␉// Check for cache file.␊ |
562 | ␉␉trycache = (((gBootMode & kBootModeSafe) == 0) &&␊ |
563 | ␉␉␉␉␉!gOverrideKernel &&␊ |
564 | ␉␉␉␉␉(gBootFileType == kBlockDeviceType) &&␊ |
565 | ␉␉␉␉␉(gMKextName[0] == '\0') &&␊ |
566 | ␉␉␉␉␉(gBootKernelCacheFile[0] != '\0'));␊ |
567 | ␉␉␊ |
568 | ␉␉verbose("Loading Darwin %s\n", gMacOSVersion);␊ |
569 | ␉␉␊ |
570 | if (trycache ) do {␊ |
571 | ␉␉␉␊ |
572 | // if we haven't found the kernel yet, don't use the cache␊ |
573 | ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);␊ |
574 | if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {␊ |
575 | trycache = 0;␊ |
576 | ␉␉␉␉bootInfo->adler32 = 0;␊ |
577 | break;␊ |
578 | }␊ |
579 | ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);␊ |
580 | if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
581 | || (cachetime < kerneltime)) {␊ |
582 | ␉␉␉␉trycache = 0;␊ |
583 | ␉␉␉␉bootInfo->adler32 = 0;␊ |
584 | ␉␉␉␉break;␉␉␉␉ ␊ |
585 | } ␊ |
586 | ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);␊ |
587 | if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)␊ |
588 | && (cachetime < exttime)) {␊ |
589 | trycache = 0;␊ |
590 | ␉␉␉␉bootInfo->adler32 = 0;␊ |
591 | break;␊ |
592 | }␊ |
593 | if (kerneltime > exttime) {␊ |
594 | exttime = kerneltime;␊ |
595 | }␊ |
596 | if (cachetime != (exttime + 1)) {␊ |
597 | trycache = 0;␊ |
598 | ␉␉␉␉bootInfo->adler32 = 0;␊ |
599 | break;␊ |
600 | }␊ |
601 | } while (0);␊ |
602 | ␉␉␊ |
603 | do {␊ |
604 | if (trycache) {␊ |
605 | bootFile = gBootKernelCacheFile;␊ |
606 | verbose("Loading kernel cache %s\n", bootFile);␊ |
607 | ␉␉␉␉if (gMacOSVersion[3] == '7') {␉␉␉␉␉␊ |
608 | ␉␉␉␉␉ret = LoadThinFatFile(bootFile, &binary);␊ |
609 | ␉␉␉␉␉if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
610 | ␉␉␉␉␉{␊ |
611 | ␉␉␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
612 | ␉␉␉␉␉␉ret = LoadThinFatFile(bootFile, &binary);␉␉␉␉␊ |
613 | ␉␉␉␉␉}␊ |
614 | ␉␉␉␉} else {␊ |
615 | ␉␉␉␉␉ret = LoadFile(bootFile);␊ |
616 | ␉␉␉␉␉binary = (void *)kLoadAddr;␊ |
617 | ␉␉␉␉}␊ |
618 | ␉␉␉␉␊ |
619 | if (ret >= 0) {␊ |
620 | break;␊ |
621 | }␊ |
622 | ␉␉␉␉␊ |
623 | }␊ |
624 | ␉␉␉bootInfo->adler32 = 0;␊ |
625 | bootFile = bootInfo->bootFile;␊ |
626 | #ifdef BOOT_HELPER_SUPPORT␊ |
627 | ␉␉␉␊ |
628 | // Try to load kernel image from alternate locations on boot helper partitions.␊ |
629 | sprintf(bootFileSpec, "com.apple.boot.P/%s", bootFile);␊ |
630 | ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
631 | ␉ ␉ if (ret == -1)␊ |
632 | ␉ ␉ {␊ |
633 | ␉␉␉␉sprintf(bootFileSpec, "com.apple.boot.R/%s", bootFile);␊ |
634 | ␉␉␉␉ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
635 | ␉␉␉␉if (ret == -1)␊ |
636 | ␉␉␉␉{␊ |
637 | ␉␉␉␉␉sprintf(bootFileSpec, "com.apple.boot.S/%s", bootFile);␊ |
638 | ␉␉␉␉␉ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
639 | ␉␉␉␉␉if (ret == -1)␊ |
640 | ␉␉␉␉␉{␊ |
641 | ␉␉␉␉␉␉// Not found any alternate locations, using the original kernel image path.␊ |
642 | ␉␉␉␉␉␉strcpy(bootFileSpec, bootFile);␊ |
643 | ␉␉␉␉␉}␊ |
644 | ␉␉␉␉}␊ |
645 | }␊ |
646 | #else␊ |
647 | ␉␉␉strcpy(bootFileSpec, bootFile);␊ |
648 | #endif␊ |
649 | ␉␉␉␊ |
650 | verbose("Loading kernel %s\n", bootFileSpec);␊ |
651 | ret = LoadThinFatFile(bootFileSpec, &binary);␊ |
652 | if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
653 | {␊ |
654 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
655 | ␉␉␉␉ret = LoadThinFatFile(bootFileSpec, &binary);␉␉␉␉␊ |
656 | }␊ |
657 | ␉␉␉␊ |
658 | } while (0);␊ |
659 | #if TEXT_SPINNER␊ |
660 | clearActivityIndicator();␊ |
661 | #endif␊ |
662 | ␉␉␊ |
663 | #if DEBUG␊ |
664 | printf("Pausing...");␊ |
665 | sleep(8);␊ |
666 | #endif␊ |
667 | ␉␉␊ |
668 | if (ret <= 0) {␊ |
669 | ␉␉␉printf("Can't find %s\n", bootFile);␊ |
670 | ␉␉␉␊ |
671 | ␉␉␉sleep(1);␊ |
672 | #ifdef NBP_SUPPORT␊ |
673 | if (gBootFileType == kNetworkDeviceType) {␊ |
674 | // Return control back to PXE. Don't unload PXE base code.␊ |
675 | gUnloadPXEOnExit = false;␊ |
676 | break;␊ |
677 | }␊ |
678 | #endif␊ |
679 | } else {␊ |
680 | /* Won't return if successful. */␊ |
681 | ret = ExecKernel(binary);␊ |
682 | }␊ |
683 | }␊ |
684 | ␊ |
685 | // chainboot␊ |
686 | if (status==1) {␊ |
687 | ␉␉if (getVideoMode() == GRAPHICS_MODE) {␉// if we are already in graphics-mode,␊ |
688 | #if UNUSED␊ |
689 | ␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␉// switch back to text mode␊ |
690 | #else␊ |
691 | ␉␉␉setVideoMode(VGA_TEXT_MODE);␉// switch back to text mode␊ |
692 | #endif␊ |
693 | ␉␉}␊ |
694 | }␊ |
695 | #ifdef NBP_SUPPORT␊ |
696 | if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) {␊ |
697 | ␉␉nbpUnloadBaseCode();␊ |
698 | }␊ |
699 | #endif␊ |
700 | }␊ |
701 | ␊ |
702 | void getKernelCachePath()␊ |
703 | {␊ |
704 | ␉long flags, cachetime;␊ |
705 | ␉int ret = -1;␊ |
706 | ␉␊ |
707 | ␉if(gMacOSVersion[3] == '7'){␉␉␉␉␉␊ |
708 | ␉␉sprintf(gBootKernelCacheFile, "%s", kDefaultCachePath);␊ |
709 | ␉}␊ |
710 | ␉else if(gMacOSVersion[3] <= '6')␊ |
711 | ␉{␉␉␉ ␊ |
712 | ␉␉␊ |
713 | ␉␉PlatformInfo *platformInfo = malloc(sizeof(PlatformInfo));␊ |
714 | ␉␉if (platformInfo) {␊ |
715 | ␉␉␉␊ |
716 | ␉␉␉bzero(platformInfo, sizeof(PlatformInfo));␊ |
717 | ␉␉␉␊ |
718 | ␉␉␉if (gPlatformName)␊ |
719 | ␉␉␉␉strlcpy(platformInfo->platformName,gPlatformName, sizeof(platformInfo->platformName)+1);␊ |
720 | ␉␉␉␊ |
721 | ␉␉␉if (gRootDevice) {␊ |
722 | ␉␉␉␉char *rootPath_p = platformInfo->rootPath;␊ |
723 | ␉␉␉␉int len = strlen(gRootDevice) + 1;␊ |
724 | ␉␉␉␉if ((unsigned)len > sizeof(platformInfo->rootPath)) {␊ |
725 | ␉␉␉␉␉len = sizeof(platformInfo->rootPath);␊ |
726 | ␉␉␉␉}␊ |
727 | ␉␉␉␉memcpy(rootPath_p, gRootDevice,len);␊ |
728 | ␉␉␉␉␊ |
729 | ␉␉␉␉rootPath_p += len;␊ |
730 | ␉␉␉␉␊ |
731 | ␉␉␉␉len = strlen(bootInfo->bootFile);␊ |
732 | ␉␉␉␉␊ |
733 | ␉␉␉␉if ((unsigned)(rootPath_p - platformInfo->rootPath + len) >=␊ |
734 | ␉␉␉␉␉sizeof(platformInfo->rootPath)) {␊ |
735 | ␉␉␉␉␉␊ |
736 | ␉␉␉␉␉len = sizeof(platformInfo->rootPath) -␊ |
737 | ␉␉␉␉␉(rootPath_p - platformInfo->rootPath);␊ |
738 | ␉␉␉␉} ␊ |
739 | ␉␉␉␉memcpy(rootPath_p, bootInfo->bootFile, len);␉␉␉␉␉␉␉␊ |
740 | ␉␉␉␉␊ |
741 | ␉␉␉}␉␊ |
742 | ␉␉␉␊ |
743 | ␉␉␉if (!platformInfo->platformName[0] || !platformInfo->rootPath[0]) {␊ |
744 | ␉␉␉␉platformInfo->platformName[0] = platformInfo->rootPath[0] = 0;␊ |
745 | ␉␉␉}␊ |
746 | ␉␉␉//memcpy(gRootPath,platformInfo->rootPath, sizeof(platformInfo->rootPath));␊ |
747 | ␉␉␉␊ |
748 | ␉␉␉␊ |
749 | ␉␉␉bootInfo->adler32 = OSSwapHostToBigInt32(local_adler32((unsigned char *)platformInfo, sizeof(*platformInfo)));␊ |
750 | ␉␉␉␊ |
751 | ␉␉␉free(platformInfo);␉␊ |
752 | ␉␉}␊ |
753 | ␉␉␊ |
754 | ␉␉DBG("Adler32: %08lX\n",bootInfo->adler32);␊ |
755 | ␉␉␊ |
756 | ␉␉if (gMacOSVersion[3] < '6') {␊ |
757 | ␉␉␉sprintf(gBootKernelCacheFile, "%s.%08lX", "/System/Library/Caches/com.apple.kernelcaches/kernelcache",bootInfo->adler32);␊ |
758 | ␉␉␉ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);␊ |
759 | ␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {␊ |
760 | ␉␉␉␉bootInfo->adler32 = 0;␊ |
761 | ␉␉␉␉sprintf(gBootKernelCacheFile, "%s", "/System/Library/Caches/com.apple.kernelcaches/kernelcache"); ␊ |
762 | ␉␉␉}␉␉␉␉␉␉␊ |
763 | ␉␉} else␊ |
764 | ␉␉␉sprintf(gBootKernelCacheFile, "%s_%s.%08lX", kDefaultCachePath, (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64", bootInfo->adler32); //Snow Leopard␊ |
765 | ␉␉␊ |
766 | ␉␉␊ |
767 | ␉}␊ |
768 | }␊ |
769 | ␊ |
770 | // Maximum config table value size␊ |
771 | #define VALUE_SIZE 2048␊ |
772 | static void getRootDevice()␊ |
773 | {␊ |
774 | ␉const char *val = 0;␊ |
775 | int cnt = 0;␊ |
776 | ␉␊ |
777 | ␉if (getValueForKey(kBootUUIDKey, &val, &cnt, &bootInfo->bootConfig)){␊ |
778 | ␉␉uuidSet = true;␉␉␊ |
779 | ␉␉␊ |
780 | } else {␊ |
781 | ␉␉if (getValueForBootKey(bootArgs->CommandLine, kRootDeviceKey, &val, &cnt)) {␊ |
782 | ␉␉␉if (*val == '*' && *(val + 1) != '/' && *(val + 1) != 'u') { ␊ |
783 | ␉␉␉␉val += 1; //skip the *␊ |
784 | ␉␉␉␉uuidSet = true;␉␉␉␉␊ |
785 | ␉␉␉␉␊ |
786 | ␉␉␉} else if (*val == '*' && *(val + 1) == 'u') {␊ |
787 | ␉␉␉␉␊ |
788 | ␉␉␉␉if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig)) ␊ |
789 | ␉␉␉␉␉uuidSet = true;␉␉␉␉␊ |
790 | ␉␉␉␉␊ |
791 | ␉␉␉} ␉␉␉␊ |
792 | ␉␉} else {␊ |
793 | #ifdef BOOT_HELPER_SUPPORT␊ |
794 | ␉␉␉//␊ |
795 | ␉␉␉// Try an alternate method for getting the root UUID on boot helper partitions.␊ |
796 | ␉␉␉//␊ |
797 | ␉␉␉if (gBootVolume->flags & kBVFlagBooter)␊ |
798 | ␉␉␉{␊ |
799 | ␉␉␉␉if((loadHelperConfig(&bootInfo->helperConfig) == 0)␊ |
800 | ␉␉␉␉ && getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig) )␊ |
801 | ␉␉␉␉{␊ |
802 | ␉␉␉␉␉getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig);␊ |
803 | ␉␉␉␉␉uuidSet = true;␊ |
804 | ␉␉␉␉␉goto out;␊ |
805 | ␉␉␉␉}␊ |
806 | ␉␉␉}␊ |
807 | #endif␊ |
808 | ␉␉␉␊ |
809 | ␉␉␉if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig)) {␊ |
810 | ␉␉␉␉extern int ArgCntRemaining;␊ |
811 | ␉␉␉␉uuidSet = false;␊ |
812 | ␉␉␉␉char * valueBuffer;␊ |
813 | ␉␉␉␉valueBuffer = malloc(VALUE_SIZE);␊ |
814 | ␉␉␉␉char * argP = bootArgs->CommandLine;␊ |
815 | ␉␉␉␉valueBuffer[0] = '*';␊ |
816 | ␉␉␉␉cnt++;␊ |
817 | ␉␉␉␉strlcpy(valueBuffer + 1, val, cnt);␉␉␉␉␊ |
818 | ␉␉␉␉if (!copyArgument( kRootDeviceKey, valueBuffer, cnt, &argP, &ArgCntRemaining))␊ |
819 | ␉␉␉␉{␊ |
820 | ␉␉␉␉␉free(valueBuffer);␊ |
821 | ␉␉␉␉␉printf("Error: boot arguments too long, unable to set root device !!");␊ |
822 | ␉␉␉␉␉getc();␊ |
823 | ␉␉␉␉␉return;␊ |
824 | ␉␉␉␉}␊ |
825 | ␉␉␉␉free(valueBuffer);␊ |
826 | ␉␉␉␉goto out;␊ |
827 | ␉␉␉}␊ |
828 | ␉␉␉␊ |
829 | ␉␉␉if (gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, bootInfo->uuidStr) == 0) {␊ |
830 | ␉␉␉␉verbose("Setting boot-uuid to: %s\n", bootInfo->uuidStr);␊ |
831 | ␉␉␉␉uuidSet = true;␊ |
832 | ␉␉␉␉gRootDevice = bootInfo->uuidStr;␊ |
833 | ␉␉␉␉return;␊ |
834 | ␉␉␉}␊ |
835 | ␉␉␊ |
836 | ␉␉}␉␊ |
837 | ␉}␊ |
838 | ␉␉␊ |
839 | out:␉␊ |
840 | ␉verbose("Setting %s to: %s\n", uuidSet ? kBootUUIDKey : "root device", (char* )val); ␊ |
841 | ␉gRootDevice = (char* )val;␊ |
842 | }␊ |
843 | ␊ |
844 | static bool getOSVersion(char *str)␊ |
845 | {␊ |
846 | ␉bool valid = false;␊ |
847 | ␉config_file_t systemVersion;␊ |
848 | ␉const char *val;␊ |
849 | ␉int len;␊ |
850 | ␉␊ |
851 | ␉if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion))␊ |
852 | ␉{␊ |
853 | ␉␉valid = true;␊ |
854 | ␉}␊ |
855 | ␉else if (!loadConfigFile("System/Library/CoreServices/ServerVersion.plist", &systemVersion))␊ |
856 | ␉{␊ |
857 | ␉␉valid = true;␊ |
858 | ␉}␊ |
859 | ␉␊ |
860 | ␉if (valid)␊ |
861 | ␉{␊ |
862 | ␉␉if (getValueForKey(kProductVersion, &val, &len, &systemVersion))␊ |
863 | ␉␉{␊ |
864 | ␉␉␉// getValueForKey uses const char for val␊ |
865 | ␉␉␉// so copy it and trim␊ |
866 | ␉␉␉*str = '\0';␊ |
867 | ␉␉␉strncat(str, val, MIN(len, 4));␊ |
868 | ␉␉}␊ |
869 | ␉␉else␊ |
870 | ␉␉␉valid = false;␊ |
871 | ␉}␊ |
872 | ␉␊ |
873 | ␉return valid;␊ |
874 | }␊ |
875 | ␊ |
876 | unsigned long␊ |
877 | local_adler32( unsigned char * buffer, long length )␊ |
878 | {␊ |
879 | long cnt;␊ |
880 | unsigned long result, lowHalf, highHalf;␊ |
881 | ␊ |
882 | lowHalf = 1;␊ |
883 | highHalf = 0;␊ |
884 | ␉␊ |
885 | ␉for ( cnt = 0; cnt < length; cnt++ )␊ |
886 | {␊ |
887 | if ((cnt % 5000) == 0)␊ |
888 | {␊ |
889 | lowHalf %= 65521L;␊ |
890 | highHalf %= 65521L;␊ |
891 | }␊ |
892 | ␉␉␊ |
893 | lowHalf += buffer[cnt];␊ |
894 | highHalf += lowHalf;␊ |
895 | }␊ |
896 | ␉␊ |
897 | ␉lowHalf %= 65521L;␊ |
898 | ␉highHalf %= 65521L;␊ |
899 | ␉␊ |
900 | ␉result = (highHalf << 16) | lowHalf;␊ |
901 | ␉␊ |
902 | ␉return result;␊ |
903 | }␊ |
904 | |