Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 130