Chameleon

Chameleon Svn Source Tree

Root/branches/diebuche/i386/boot2/boot.c

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

Archive Download this file

Revision: 132