Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1174