Chameleon

Chameleon Svn Source Tree

Root/branches/Chimera/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) {
154 LoadDrivers("/");
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
200finalizeBootStruct();
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 // Not reached
219
220 return 0;
221}
222
223//==========================================================================
224// This is the entrypoint from real-mode which functions exactly as it did
225// before. Multiboot does its own runtime initialization, does some of its
226// own things, and then calls common_boot.
227void boot(int biosdev)
228{
229initialize_runtime();
230// Enable A20 gate before accessing memory above 1Mb.
231enableA20();
232common_boot(biosdev);
233}
234
235//==========================================================================
236// The 'main' function for the booter. Called by boot0 when booting
237// from a block device, or by the network booter.
238//
239// arguments:
240// biosdev - Value passed from boot1/NBP to specify the device
241// that the booter was loaded from.
242//
243// If biosdev is kBIOSDevNetwork, then this function will return if
244// booting was unsuccessful. This allows the PXE firmware to try the
245// next boot device on its list.
246void common_boot(int biosdev)
247{
248 int status;
249 char *bootFile;
250 unsigned long adler32;
251 bool quiet;
252 bool firstRun = true;
253 bool instantMenu;
254 bool rescanPrompt;
255 unsigned int allowBVFlags = kBVFlagSystemVolume|kBVFlagForeignBoot;
256 unsigned int denyBVFlags = kBVFlagEFISystem;
257
258 // Set reminder to unload the PXE base code. Neglect to unload
259 // the base code will result in a hang or kernel panic.
260 gUnloadPXEOnExit = true;
261
262 // Record the device that the booter was loaded from.
263 gBIOSDev = biosdev & kBIOSDevMask;
264
265 // Initialize boot info structure.
266 initKernBootStruct();
267
268initBooterLog();
269
270 // Setup VGA text mode.
271 // Not sure if it is safe to call setVideoMode() before the
272 // config table has been loaded. Call video_mode() instead.
273#if DEBUG
274 printf("before video_mode\n");
275#endif
276 video_mode( 2 ); // 80x25 mono text mode.
277#if DEBUG
278 printf("after video_mode\n");
279#endif
280
281 // Scan and record the system's hardware information.
282 scan_platform();
283
284 // First get info for boot volume.
285 scanBootVolumes(gBIOSDev, 0);
286 bvChain = getBVChainForBIOSDev(gBIOSDev);
287 setBootGlobals(bvChain);
288
289 // Load boot.plist config file
290 status = loadSystemConfig(&bootInfo->bootConfig);
291
292 if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet) {
293 gBootMode |= kBootModeQuiet;
294 }
295
296 // Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config
297 if (getBoolForKey(kInsantMenuKey, &instantMenu, &bootInfo->bootConfig) && instantMenu) {
298 firstRun = false;
299 }
300
301 // Loading preboot ramdisk if exists.
302 loadPrebootRAMDisk();
303
304 // Disable rescan option by default
305 gEnableCDROMRescan = false;
306
307 // Enable it with Rescan=y in system config
308 if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->bootConfig) && gEnableCDROMRescan) {
309 gEnableCDROMRescan = true;
310 }
311
312 // Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.
313 rescanPrompt = false;
314 if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev)) {
315 gEnableCDROMRescan = promptForRescanOption();
316 }
317
318 // Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.
319 if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig) && gScanSingleDrive) {
320 gScanSingleDrive = true;
321 }
322
323 // Create a list of partitions on device(s).
324 if (gScanSingleDrive) {
325 scanBootVolumes(gBIOSDev, &bvCount);
326 } else {
327 scanDisks(gBIOSDev, &bvCount);
328 }
329
330 // Create a separated bvr chain using the specified filters.
331 bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);
332
333 gBootVolume = selectBootVolume(bvChain);
334
335#if DEBUG
336 printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);
337 printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);
338 getc();
339#endif
340
341useGUI = true;
342// Override useGUI default
343getBoolForKey(kGUIKey, &useGUI, &bootInfo->bootConfig);
344if (useGUI && initGUI())
345{
346// initGUI() returned with an error, disabling GUI.
347useGUI = false;
348}
349
350 setBootGlobals(bvChain);
351
352 // Parse args, load and start kernel.
353 while (1) {
354 const char *val;
355 int len;
356 int trycache;
357 long flags, cachetime, kerneltime, exttime, sleeptime, time;
358 int ret = -1;
359 void *binary = (void *)kLoadAddr;
360 bool tryresume;
361 bool tryresumedefault;
362 bool forceresume;
363
364 // additional variable for testing alternate kernel image locations on boot helper partitions.
365 char bootFileSpec[512];
366
367 // Initialize globals.
368
369 sysConfigValid = false;
370 gErrors = false;
371
372 status = getBootOptions(firstRun);
373 firstRun = false;
374 if (status == -1) continue;
375
376 status = processBootOptions();
377 // Status==1 means to chainboot
378 if ( status == 1 ) break;
379 // Status==-1 means that the config file couldn't be loaded or that gBootVolume is NULL
380 if ( status == -1 )
381 {
382 // gBootVolume == NULL usually means the user hit escape.
383 if(gBootVolume == NULL)
384 {
385 freeFilteredBVChain(bvChain);
386
387 if (gEnableCDROMRescan)
388 rescanBIOSDevice(gBIOSDev);
389
390 bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);
391 setBootGlobals(bvChain);
392 setupDeviceList(&bootInfo->themeConfig);
393 }
394 continue;
395 }
396
397 // Other status (e.g. 0) means that we should proceed with boot.
398
399// Turn off any GUI elements
400if( bootArgs->Video.v_display == GRAPHICS_MODE )
401{
402gui.devicelist.draw = false;
403gui.bootprompt.draw = false;
404gui.menu.draw = false;
405gui.infobox.draw = false;
406gui.logo.draw = false;
407drawBackground();
408updateVRAM();
409}
410
411// Find out which version mac os we're booting.
412getOSVersion(gMacOSVersion);
413
414if (platformCPUFeature(CPU_FEATURE_EM64T)) {
415archCpuType = CPU_TYPE_X86_64;
416} else {
417archCpuType = CPU_TYPE_I386;
418}
419if (getValueForKey(karch, &val, &len, &bootInfo->bootConfig)) {
420if (strncmp(val, "i386", 4) == 0) {
421archCpuType = CPU_TYPE_I386;
422}
423}
424
425if (!getBoolForKey (kWake, &tryresume, &bootInfo->bootConfig)) {
426tryresume = true;
427tryresumedefault = true;
428} else {
429tryresumedefault = false;
430}
431
432if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->bootConfig)) {
433forceresume = false;
434}
435
436if (forceresume) {
437tryresume = true;
438tryresumedefault = false;
439}
440
441while (tryresume) {
442const char *tmp;
443BVRef bvr;
444if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->bootConfig))
445val="/private/var/vm/sleepimage";
446
447// Do this first to be sure that root volume is mounted
448ret = GetFileInfo(0, val, &flags, &sleeptime);
449
450if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)
451break;
452
453// Can't check if it was hibernation Wake=y is required
454if (bvr->modTime == 0 && tryresumedefault)
455break;
456
457if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))
458break;
459
460if (!forceresume && ((sleeptime+3)<bvr->modTime)) {
461printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",bvr->modTime-sleeptime);
462break;
463}
464
465HibernateBoot((char *)val);
466break;
467}
468
469 // Reset cache name.
470 bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
471
472 sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);
473
474 adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
475
476 if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
477 strlcpy(gBootKernelCacheFile, val, len+1);
478 } else {
479//Lion
480if (checkOSVersion("10.7")) {
481sprintf(gBootKernelCacheFile, "%skernelcache", kDefaultCachePathSnow);
482}
483// Snow Leopard
484else if (checkOSVersion("10.6")) {
485sprintf(gBootKernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64"); //, adler32);
486int lnam = sizeof(gBootKernelCacheFile) + 9; //with adler32
487//Slice - TODO
488/*
489 - but the name is longer .adler32 and more...
490 kernelcache_i386.E102928C.qSs0
491 so will opendir and scan for some files
492 */
493char* name;
494long prev_time = 0;
495
496struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
497
498while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
499{
500if(((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time && strstr(name, gBootKernelCacheFile) && (name[lnam] != '.'))
501{
502sprintf(gBootKernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
503prev_time = time;
504}
505}
506}
507else sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32);
508 }
509
510 // Check for cache file.
511 trycache = (((gBootMode & kBootModeSafe) == 0) &&
512 !gOverrideKernel &&
513 (gBootFileType == kBlockDeviceType) &&
514 (gMKextName[0] == '\0') &&
515 (gBootKernelCacheFile[0] != '\0'));
516
517verbose("Loading Darwin %s\n", gMacOSVersion);
518
519 if (trycache) do {
520
521 // if we haven't found the kernel yet, don't use the cache
522 ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
523 if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
524 trycache = 0;
525 break;
526 }
527 ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
528 if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)
529 || (cachetime < kerneltime)) {
530 trycache = 0;
531 break;
532 }
533 ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);
534 if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)
535 && (cachetime < exttime)) {
536 trycache = 0;
537 break;
538 }
539 if (kerneltime > exttime) {
540 exttime = kerneltime;
541 }
542 if (cachetime != (exttime + 1)) {
543 trycache = 0;
544 break;
545 }
546 } while (0);
547
548if (getValueForKey("-usecache", &val, &len, &bootInfo->bootConfig))
549trycache=1;
550
551 do {
552 if (trycache) {
553 bootFile = gBootKernelCacheFile;
554
555 verbose("Loading kernel cache %s\n", bootFile);
556
557 if (checkOSVersion("10.7")) {
558 ret = LoadThinFatFile(bootFile, &binary);
559}
560else {
561 ret = LoadFile(bootFile);
562binary = (void *)kLoadAddr;
563}
564
565 if (ret >= 0)
566 break;
567
568verbose("Kernel cache did not loaded %s\n ", bootFile);
569 }
570
571 bootFile = bootInfo->bootFile;
572
573 // Try to load kernel image from alternate locations on boot helper partitions.
574 sprintf(bootFileSpec, "com.apple.boot.P/%s", bootFile);
575 ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
576 if (ret == -1)
577 {
578 sprintf(bootFileSpec, "com.apple.boot.R/%s", bootFile);
579 ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
580 if (ret == -1)
581 {
582 sprintf(bootFileSpec, "com.apple.boot.S/%s", bootFile);
583 ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
584 if (ret == -1)
585 {
586 // Not found any alternate locations, using the original kernel image path.
587 strcpy(bootFileSpec, bootFile);
588 }
589 }
590 }
591
592 if (checkOSVersion("10.7"))
593 {
594 // Lion, dont load kernel if you have cache
595 if (!trycache) {
596 verbose("Loading kernel %s\n", bootFileSpec);
597 ret = LoadThinFatFile(bootFileSpec, &binary);
598 if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) {
599 archCpuType = CPU_TYPE_I386;
600 ret = LoadThinFatFile(bootFileSpec, &binary);
601 }
602 }
603else ret = 1;
604 }
605else {
606 // Snow Leopard or older
607 verbose("Loading kernel %s\n", bootFileSpec);
608 ret = LoadThinFatFile(bootFileSpec, &binary);
609 if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) {
610 archCpuType = CPU_TYPE_I386;
611 ret = LoadThinFatFile(bootFileSpec, &binary);
612 }
613 }
614
615 } while (0);
616
617 clearActivityIndicator();
618#if DEBUG
619 printf("Pausing...");
620 sleep(8);
621#endif
622
623 if (ret <= 0) {
624printf("Can't find %s\n", bootFile);
625
626sleep(1);
627
628 if (gBootFileType == kNetworkDeviceType) {
629 // Return control back to PXE. Don't unload PXE base code.
630 gUnloadPXEOnExit = false;
631 break;
632 }
633 } else {
634 /* Won't return if successful. */
635 ret = ExecKernel(binary);
636 }
637 }
638
639 // chainboot
640 if (status==1) {
641if (getVideoMode() == GRAPHICS_MODE) {// if we are already in graphics-mode,
642setVideoMode(VGA_TEXT_MODE, 0);// switch back to text mode
643}
644 }
645
646 if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) {
647nbpUnloadBaseCode();
648 }
649}
650
651/*!
652 Selects a new BIOS device, taking care to update the global state appropriately.
653 */
654/*
655static void selectBiosDevice(void)
656{
657 struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);
658 CacheReset();
659 diskFreeMap(oldMap);
660 oldMap = NULL;
661
662 int dev = selectAlternateBootDevice(gBIOSDev);
663
664 BVRef bvchain = scanBootVolumes(dev, 0);
665 BVRef bootVol = selectBootVolume(bvchain);
666 gBootVolume = bootVol;
667 setRootVolume(bootVol);
668 gBIOSDev = dev;
669}
670*/
671
672static bool getOSVersion(char *str)
673{
674bool valid = false;
675config_file_t systemVersion;
676const char *val;
677int len;
678
679if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion))
680{
681valid = true;
682}
683else if (!loadConfigFile("System/Library/CoreServices/ServerVersion.plist", &systemVersion))
684{
685valid = true;
686}
687
688if (valid)
689{
690if (getValueForKey(kProductVersion, &val, &len, &systemVersion))
691{
692// getValueForKey uses const char for val
693// so copy it and trim
694*str = '\0';
695strncat(str, val, MIN(len, 4));
696}
697else
698valid = false;
699}
700
701return valid;
702}
703
704#define BASE 65521L /* largest prime smaller than 65536 */
705#define NMAX 5000
706// NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
707
708#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
709#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
710#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
711#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
712#define DO16(buf) DO8(buf,0); DO8(buf,8);
713
714unsigned long Adler32(unsigned char *buf, long len)
715{
716 unsigned long s1 = 1; // adler & 0xffff;
717 unsigned long s2 = 0; // (adler >> 16) & 0xffff;
718 unsigned long result;
719 int k;
720
721 while (len > 0) {
722 k = len < NMAX ? len : NMAX;
723 len -= k;
724 while (k >= 16) {
725 DO16(buf);
726 buf += 16;
727 k -= 16;
728 }
729 if (k != 0) do {
730 s1 += *buf++;
731 s2 += s1;
732 } while (--k);
733 s1 %= BASE;
734 s2 %= BASE;
735 }
736 result = (s2 << 16) | s1;
737 return OSSwapHostToBigInt32(result);
738}
739

Archive Download this file

Revision: 765