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