Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 399