Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 466