Chameleon

Chameleon Svn Source Tree

Root/trunk/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 * 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 "ramdisk.h"
59#include "gui.h"
60#include "platform.h"
61
62long gBootMode; /* defaults to 0 == kBootModeNormal */
63bool gOverrideKernel;
64static char gBootKernelCacheFile[512];
65static char gCacheNameAdler[64 + 256];
66char *gPlatformName = gCacheNameAdler;
67char gRootDevice[512];
68char gMKextName[512];
69char gMacOSVersion[8];
70bool gEnableCDROMRescan;
71bool gScanSingleDrive;
72
73int bvCount = 0;
74//intmenucount = 0;
75int gDeviceCount = 0;
76
77BVRef bvr;
78BVRef menuBVR;
79BVRef bvChain;
80bool useGUI;
81
82//static void selectBiosDevice(void);
83static unsigned long Adler32(unsigned char *buffer, long length);
84static bool getOSVersion(char *str);
85
86static bool gUnloadPXEOnExit = false;
87
88/*
89 * How long to wait (in seconds) to load the
90 * kernel after displaying the "boot:" prompt.
91 */
92#define kBootErrorTimeout 5
93
94/*
95 * Default path to kernel cache file
96 */
97//Slice - first one for Leopard
98#define kDefaultCachePathLeo "/System/Library/Caches/com.apple.kernelcaches/"
99#define kDefaultCachePathSnow "/System/Library/Caches/com.apple.kext.caches/Startup/"
100
101//==========================================================================
102// Zero the BSS.
103
104static void zeroBSS(void)
105{
106extern char _DATA__bss__begin, _DATA__bss__end;
107extern char _DATA__common__begin, _DATA__common__end;
108
109bzero(&_DATA__bss__begin, (&_DATA__bss__end - &_DATA__bss__begin));
110bzero(&_DATA__common__begin, (&_DATA__common__end - &_DATA__common__begin));
111}
112
113//==========================================================================
114// Malloc error function
115
116static void malloc_error(char *addr, size_t size, const char *file, int line)
117{
118stop("\nMemory allocation error! Addr=0x%x, Size=0x%x, File=%s, Line=%d\n", (unsigned)addr, (unsigned)size, file, line);
119}
120
121//==========================================================================
122//Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.
123//
124void initialize_runtime(void)
125{
126zeroBSS();
127malloc_init(0, 0, 0, malloc_error);
128}
129
130//==========================================================================
131// execKernel - Load the kernel image (mach-o) and jump to its entry point.
132
133static int ExecKernel(void *binary)
134{
135 entry_t kernelEntry;
136 int ret;
137
138 bootArgs->kaddr = bootArgs->ksize = 0;
139
140 ret = DecodeKernel(binary,
141 &kernelEntry,
142 (char **) &bootArgs->kaddr,
143 (int *)&bootArgs->ksize );
144
145 if ( ret != 0 )
146 return ret;
147
148 // Reserve space for boot args
149 reserveKernBootStruct();
150
151 // Load boot drivers from the specifed root path.
152
153 if (!gHaveKernelCache)
154LoadDrivers("/");
155
156
157 clearActivityIndicator();
158
159 if (gErrors) {
160 printf("Errors encountered while starting up the computer.\n");
161 printf("Pausing %d seconds...\n", kBootErrorTimeout);
162 sleep(kBootErrorTimeout);
163 }
164
165 setupFakeEfi();
166
167 md0Ramdisk();
168
169 verbose("Starting Darwin %s\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64");
170
171 // Cleanup the PXE base code.
172
173 if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit ) {
174if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )
175 {
176 printf("nbpUnloadBaseCode error %d\n", (int) ret);
177 sleep(2);
178 }
179 }
180
181 bool dummyVal;
182if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->bootConfig) && dummyVal) {
183printf("Press any key to continue...");
184getc();
185}
186
187usb_loop();
188
189 // If we were in text mode, switch to graphics mode.
190 // This will draw the boot graphics unless we are in
191 // verbose mode.
192
193 if(gVerboseMode)
194 setVideoMode( GRAPHICS_MODE, 0 );
195 else
196 drawBootGraphics();
197
198setupBooterLog();
199
200 finalizeBootStruct();
201
202if (checkOSVersion("10.7")) {
203
204// Masking out so that Lion doesn't doublefault
205outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
206outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */
207
208// Jump to kernel's entry point. There's no going back now.
209
210startprog( kernelEntry, bootArgs );
211}
212else {
213// Jump to kernel's entry point. There's no going back now.
214
215startprog( kernelEntry, bootArgsPreLion );
216}
217
218
219
220 // Not reached
221
222 return 0;
223}
224
225//==========================================================================
226// This is the entrypoint from real-mode which functions exactly as it did
227// before. Multiboot does its own runtime initialization, does some of its
228// own things, and then calls common_boot.
229void boot(int biosdev)
230{
231initialize_runtime();
232// Enable A20 gate before accessing memory above 1Mb.
233enableA20();
234common_boot(biosdev);
235}
236
237//==========================================================================
238// The 'main' function for the booter. Called by boot0 when booting
239// from a block device, or by the network booter.
240//
241// arguments:
242// biosdev - Value passed from boot1/NBP to specify the device
243// that the booter was loaded from.
244//
245// If biosdev is kBIOSDevNetwork, then this function will return if
246// booting was unsuccessful. This allows the PXE firmware to try the
247// next boot device on its list.
248void common_boot(int biosdev)
249{
250 int status;
251 char *bootFile;
252 unsigned long adler32;
253 bool quiet;
254 bool firstRun = true;
255 bool instantMenu;
256 bool rescanPrompt;
257 unsigned int allowBVFlags = kBVFlagSystemVolume|kBVFlagForeignBoot;
258 unsigned int denyBVFlags = kBVFlagEFISystem;
259
260 // Set reminder to unload the PXE base code. Neglect to unload
261 // the base code will result in a hang or kernel panic.
262 gUnloadPXEOnExit = true;
263
264 // Record the device that the booter was loaded from.
265 gBIOSDev = biosdev & kBIOSDevMask;
266
267 // Initialize boot info structure.
268 initKernBootStruct();
269
270initBooterLog();
271
272 // Setup VGA text mode.
273 // Not sure if it is safe to call setVideoMode() before the
274 // config table has been loaded. Call video_mode() instead.
275#if DEBUG
276 printf("before video_mode\n");
277#endif
278 video_mode( 2 ); // 80x25 mono text mode.
279#if DEBUG
280 printf("after video_mode\n");
281#endif
282
283 // Scan and record the system's hardware information.
284 scan_platform();
285
286 // First get info for boot volume.
287 scanBootVolumes(gBIOSDev, 0);
288 bvChain = getBVChainForBIOSDev(gBIOSDev);
289 setBootGlobals(bvChain);
290
291 // Load boot.plist config file
292 status = loadSystemConfig(&bootInfo->bootConfig);
293
294 if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet) {
295 gBootMode |= kBootModeQuiet;
296 }
297
298 // Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config
299 if (getBoolForKey(kInsantMenuKey, &instantMenu, &bootInfo->bootConfig) && instantMenu) {
300 firstRun = false;
301 }
302
303 // Loading preboot ramdisk if exists.
304 loadPrebootRAMDisk();
305
306 // Disable rescan option by default
307 gEnableCDROMRescan = false;
308
309 // Enable it with Rescan=y in system config
310 if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->bootConfig) && gEnableCDROMRescan) {
311 gEnableCDROMRescan = true;
312 }
313
314 // Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.
315 rescanPrompt = false;
316 if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev)) {
317 gEnableCDROMRescan = promptForRescanOption();
318 }
319
320 // Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.
321 if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig) && gScanSingleDrive) {
322 gScanSingleDrive = true;
323 }
324
325 // Create a list of partitions on device(s).
326 if (gScanSingleDrive) {
327 scanBootVolumes(gBIOSDev, &bvCount);
328 } else {
329 scanDisks(gBIOSDev, &bvCount);
330 }
331
332 // Create a separated bvr chain using the specified filters.
333 bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);
334
335 gBootVolume = selectBootVolume(bvChain);
336
337#if DEBUG
338 printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);
339 printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);
340 getc();
341#endif
342
343useGUI = true;
344// Override useGUI default
345getBoolForKey(kGUIKey, &useGUI, &bootInfo->bootConfig);
346if (useGUI && initGUI())
347{
348// initGUI() returned with an error, disabling GUI.
349useGUI = false;
350}
351
352 setBootGlobals(bvChain);
353
354 // Parse args, load and start kernel.
355 while (1) {
356 const char *val;
357 int len;
358 int trycache;
359 long flags, cachetime, kerneltime, exttime, sleeptime, time;
360 int ret = -1;
361 void *binary = (void *)kLoadAddr;
362 bool tryresume;
363 bool tryresumedefault;
364 bool forceresume;
365
366 // additional variable for testing alternate kernel image locations on boot helper partitions.
367 char bootFileSpec[512];
368
369 // Initialize globals.
370
371 sysConfigValid = false;
372 gErrors = false;
373
374 status = getBootOptions(firstRun);
375 firstRun = false;
376 if (status == -1) continue;
377
378 status = processBootOptions();
379 // Status==1 means to chainboot
380 if ( status == 1 ) break;
381 // Status==-1 means that the config file couldn't be loaded or that gBootVolume is NULL
382 if ( status == -1 )
383 {
384 // gBootVolume == NULL usually means the user hit escape.
385 if(gBootVolume == NULL)
386 {
387 freeFilteredBVChain(bvChain);
388
389 if (gEnableCDROMRescan)
390 rescanBIOSDevice(gBIOSDev);
391
392 bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);
393 setBootGlobals(bvChain);
394 setupDeviceList(&bootInfo->themeConfig);
395 }
396 continue;
397 }
398
399 // Other status (e.g. 0) means that we should proceed with boot.
400
401// Turn off any GUI elements
402if( bootArgs->Video.v_display == GRAPHICS_MODE )
403{
404gui.devicelist.draw = false;
405gui.bootprompt.draw = false;
406gui.menu.draw = false;
407gui.infobox.draw = false;
408gui.logo.draw = false;
409drawBackground();
410updateVRAM();
411}
412
413// Find out which version mac os we're booting.
414getOSVersion(gMacOSVersion);
415
416if (platformCPUFeature(CPU_FEATURE_EM64T)) {
417archCpuType = CPU_TYPE_X86_64;
418} else {
419archCpuType = CPU_TYPE_I386;
420}
421if (getValueForKey(karch, &val, &len, &bootInfo->bootConfig)) {
422if (strncmp(val, "i386", 4) == 0) {
423archCpuType = CPU_TYPE_I386;
424}
425}
426
427if (!getBoolForKey (kWake, &tryresume, &bootInfo->bootConfig)) {
428tryresume = true;
429tryresumedefault = true;
430} else {
431tryresumedefault = false;
432}
433
434if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->bootConfig)) {
435forceresume = false;
436}
437
438if (forceresume) {
439tryresume = true;
440tryresumedefault = false;
441}
442
443while (tryresume) {
444const char *tmp;
445BVRef bvr;
446if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->bootConfig))
447val="/private/var/vm/sleepimage";
448
449// Do this first to be sure that root volume is mounted
450ret = GetFileInfo(0, val, &flags, &sleeptime);
451
452if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)
453break;
454
455// Can't check if it was hibernation Wake=y is required
456if (bvr->modTime == 0 && tryresumedefault)
457break;
458
459if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))
460break;
461
462if (!forceresume && ((sleeptime+3)<bvr->modTime)) {
463printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",bvr->modTime-sleeptime);
464break;
465}
466
467HibernateBoot((char *)val);
468break;
469}
470
471 // Reset cache name.
472 bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
473
474 sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);
475
476 adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
477
478 if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
479 strlcpy(gBootKernelCacheFile, val, len+1);
480 }
481else {
482//Lion
483if (checkOSVersion("10.7")) {
484sprintf(gBootKernelCacheFile, "%skernelcache", kDefaultCachePathSnow);
485}
486// Snow Leopard
487else if (checkOSVersion("10.6")) {
488sprintf(gBootKernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64"); //, adler32);
489int lnam = sizeof(gBootKernelCacheFile) + 9; //with adler32
490//Slice - TODO
491/*
492 - but the name is longer .adler32 and more...
493 kernelcache_i386.E102928C.qSs0
494 so will opendir and scan for some files
495 */
496char* name;
497long prev_time = 0;
498
499struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
500
501while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
502{
503if(((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time && strstr(name, gBootKernelCacheFile) && (name[lnam] != '.'))
504{
505sprintf(gBootKernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
506prev_time = time;
507}
508}
509}
510else sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32);
511}
512
513 // Check for cache file.
514 trycache = (((gBootMode & kBootModeSafe) == 0) &&
515 !gOverrideKernel &&
516 (gBootFileType == kBlockDeviceType) &&
517 (gMKextName[0] == '\0') &&
518 (gBootKernelCacheFile[0] != '\0'));
519
520verbose("Loading Darwin %s\n", gMacOSVersion);
521
522 if (trycache) do {
523
524 // if we haven't found the kernel yet, don't use the cache
525 ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
526 if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
527 trycache = 0;
528 break;
529 }
530 ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
531 if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)
532 || (cachetime < kerneltime)) {
533 trycache = 0;
534 break;
535 }
536 ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);
537 if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)
538 && (cachetime < exttime)) {
539 trycache = 0;
540 break;
541 }
542 if (kerneltime > exttime) {
543 exttime = kerneltime;
544 }
545 if (cachetime != (exttime + 1)) {
546 trycache = 0;
547 break;
548 }
549 } while (0);
550
551if (getValueForKey("-usecache", &val, &len, &bootInfo->bootConfig))
552trycache=1;
553
554 do {
555 if (trycache) {
556 bootFile = gBootKernelCacheFile;
557
558verbose("Loading kernel cache %s\n", bootFile);
559
560 if (checkOSVersion("10.7")) {
561 ret = LoadThinFatFile(bootFile, &binary);
562}
563else {
564 ret = LoadFile(bootFile);
565binary = (void *)kLoadAddr;
566}
567
568 if (ret >= 0)
569 break;
570
571verbose("Kernel cache did not loaded %s\n ", bootFile);
572 }
573
574 bootFile = bootInfo->bootFile;
575
576 // Try to load kernel image from alternate locations on boot helper partitions.
577 sprintf(bootFileSpec, "com.apple.boot.P/%s", bootFile);
578 ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
579 if (ret == -1)
580 {
581 sprintf(bootFileSpec, "com.apple.boot.R/%s", bootFile);
582 ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
583 if (ret == -1)
584 {
585 sprintf(bootFileSpec, "com.apple.boot.S/%s", bootFile);
586 ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
587 if (ret == -1)
588 {
589 // Not found any alternate locations, using the original kernel image path.
590 strcpy(bootFileSpec, bootFile);
591 }
592 }
593 }
594
595 if (checkOSVersion("10.7"))
596 {
597 //Lion, dont load kernel if haz cache
598 if (!trycache) {
599 verbose("Loading kernel %s\n", bootFileSpec);
600 ret = LoadThinFatFile(bootFileSpec, &binary);
601 if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) {
602 archCpuType = CPU_TYPE_I386;
603 ret = LoadThinFatFile(bootFileSpec, &binary);
604 }
605 }
606else ret = 1;
607 }
608else {
609 //Snow leopard or older
610 verbose("Loading kernel %s\n", bootFileSpec);
611 ret = LoadThinFatFile(bootFileSpec, &binary);
612 if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) {
613 archCpuType = CPU_TYPE_I386;
614 ret = LoadThinFatFile(bootFileSpec, &binary);
615 }
616 }
617
618
619 } while (0);
620
621 clearActivityIndicator();
622#if DEBUG
623 printf("Pausing...");
624 sleep(8);
625#endif
626
627 if (ret <= 0) {
628printf("Can't find %s\n", bootFile);
629
630sleep(1);
631
632 if (gBootFileType == kNetworkDeviceType) {
633 // Return control back to PXE. Don't unload PXE base code.
634 gUnloadPXEOnExit = false;
635 break;
636 }
637 } else {
638 /* Won't return if successful. */
639 ret = ExecKernel(binary);
640 }
641 }
642
643 // chainboot
644 if (status==1) {
645if (getVideoMode() == GRAPHICS_MODE) {// if we are already in graphics-mode,
646setVideoMode(VGA_TEXT_MODE, 0);// switch back to text mode
647}
648 }
649
650 if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) {
651nbpUnloadBaseCode();
652 }
653}
654
655/*!
656 Selects a new BIOS device, taking care to update the global state appropriately.
657 */
658/*
659static void selectBiosDevice(void)
660{
661 struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);
662 CacheReset();
663 diskFreeMap(oldMap);
664 oldMap = NULL;
665
666 int dev = selectAlternateBootDevice(gBIOSDev);
667
668 BVRef bvchain = scanBootVolumes(dev, 0);
669 BVRef bootVol = selectBootVolume(bvchain);
670 gBootVolume = bootVol;
671 setRootVolume(bootVol);
672 gBIOSDev = dev;
673}
674*/
675
676static bool getOSVersion(char *str)
677{
678bool valid = false;
679config_file_t systemVersion;
680const char *val;
681int len;
682
683if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion))
684{
685valid = true;
686}
687else if (!loadConfigFile("System/Library/CoreServices/ServerVersion.plist", &systemVersion))
688{
689valid = true;
690}
691
692if (valid)
693{
694if (getValueForKey(kProductVersion, &val, &len, &systemVersion))
695{
696// getValueForKey uses const char for val
697// so copy it and trim
698*str = '\0';
699strncat(str, val, MIN(len, 4));
700}
701else
702valid = false;
703}
704
705return valid;
706}
707
708#define BASE 65521L /* largest prime smaller than 65536 */
709#define NMAX 5000
710// NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
711
712#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
713#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
714#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
715#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
716#define DO16(buf) DO8(buf,0); DO8(buf,8);
717
718unsigned long Adler32(unsigned char *buf, long len)
719{
720 unsigned long s1 = 1; // adler & 0xffff;
721 unsigned long s2 = 0; // (adler >> 16) & 0xffff;
722 unsigned long result;
723 int k;
724
725 while (len > 0) {
726 k = len < NMAX ? len : NMAX;
727 len -= k;
728 while (k >= 16) {
729 DO16(buf);
730 buf += 16;
731 k -= 16;
732 }
733 if (k != 0) do {
734 s1 += *buf++;
735 s2 += s1;
736 } while (--k);
737 s1 %= BASE;
738 s2 %= BASE;
739 }
740 result = (s2 << 16) | s1;
741 return OSSwapHostToBigInt32(result);
742}
743

Archive Download this file

Revision: 758