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; Azi: not in use
72char gRootDevice[512];
73char gMKextName[512];
74//char gMacOSVersion[8]; //Azi:sysversion - TODO: check why doesn't work here.
75bool gEnableCDROMRescan;
76bool gScanSingleDrive;
77
78int bvCount = 0;
79//intmenucount = 0;
80int gDeviceCount = 0;
81
82BVRef bvr;
83BVRef menuBVR;
84BVRef bvChain;
85bool useGUI;
86
87//static void selectBiosDevice(void);
88static unsigned long Adler32(unsigned char *buffer, long length);
89
90static bool gUnloadPXEOnExit = false;
91
92/*
93 * How long to wait (in seconds) to load the
94 * kernel after displaying the "boot:" prompt.
95 */
96#define kBootErrorTimeout 5
97
98/*
99 * Default path to kernel cache file
100 */
101#define kDefaultCachePath "/System/Library/Caches/com.apple.kernelcaches/kernelcache"
102
103//==========================================================================
104// Zero the BSS.
105
106static void zeroBSS(void)
107{
108extern char _DATA__bss__begin, _DATA__bss__end;
109extern char _DATA__common__begin, _DATA__common__end;
110
111bzero(&_DATA__bss__begin, (&_DATA__bss__end - &_DATA__bss__begin));
112bzero(&_DATA__common__begin, (&_DATA__common__end - &_DATA__common__begin));
113}
114
115//==========================================================================
116// Malloc error function
117
118static void malloc_error(char *addr, size_t size, const char *file, int line)
119{
120stop("\nMemory allocation error! Addr=0x%x, Size=0x%x, File=%s, Line=%d\n", (unsigned)addr, (unsigned)size, file, line);
121}
122
123//==========================================================================
124//Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.
125//
126void initialize_runtime(void)
127{
128zeroBSS();
129malloc_init(0, 0, 0, malloc_error);
130}
131
132//==========================================================================
133// execKernel - Load the kernel image (mach-o) and jump to its entry point.
134
135static int ExecKernel(void *binary)
136{
137 entry_t kernelEntry;
138 int ret;
139
140 bootArgs->kaddr = bootArgs->ksize = 0;
141
142 ret = DecodeKernel(binary,
143 &kernelEntry,
144 (char **) &bootArgs->kaddr,
145 (int *)&bootArgs->ksize );
146
147 if ( ret != 0 )
148 return ret;
149
150 // Reserve space for boot args
151 reserveKernBootStruct();
152
153 // Load boot drivers from the specifed root path.
154
155 if (!gHaveKernelCache) {
156 LoadDrivers("/");
157 }
158
159 clearActivityIndicator();
160
161 if (gErrors) {
162 printf("Errors encountered while starting up the computer.\n");
163 printf("Pausing %d seconds...\n", kBootErrorTimeout);
164 sleep(kBootErrorTimeout);
165 }
166
167 setupFakeEfi();
168
169 md0Ramdisk();
170
171 verbose("Starting Darwin %s\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64");
172
173 // Cleanup the PXE base code.
174
175 if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit ) {
176if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )
177 {
178 printf("nbpUnloadBaseCode error %d\n", (int) ret);
179 sleep(2);
180 }
181 }
182
183 bool dummyVal;
184
185//Azi: Wait=y or any other pause makes my boot hang here, when using UHCIReset fix.
186// (see graphics.c 432, AUTORES_DEBUG/patch). (fixed with usb_loop)
187
188// It's also breaking other keys when typed "after them" at boot prompt.
189// Works properly if Wait=y is typed in first place or used on Boot.plist.
190 if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->bootConfig) && dummyVal) {
191pause();
192 }
193
194usb_loop();
195
196 // If we were in text mode, switch to graphics mode.
197 // This will draw the boot graphics unless we are in
198 // verbose mode.
199
200 if(gVerboseMode)
201 setVideoMode( GRAPHICS_MODE, 0 );
202 else
203 drawBootGraphics();
204
205 finalizeBootStruct();
206
207 // Jump to kernel's entry point. There's no going back now.
208
209 startprog( kernelEntry, bootArgs );
210
211 // Not reached
212
213 return 0;
214}
215
216//==========================================================================
217// This is the entrypoint from real-mode which functions exactly as it did
218// before. Multiboot does its own runtime initialization, does some of its
219// own things, and then calls common_boot.
220void boot(int biosdev)
221{
222initialize_runtime();
223// Enable A20 gate before accessing memory above 1Mb.
224enableA20();
225common_boot(biosdev);
226}
227
228//==========================================================================
229// The 'main' function for the booter. Called by boot0 when booting
230// from a block device, or by the network booter.
231//
232// arguments:
233// biosdev - Value passed from boot1/NBP to specify the device
234// that the booter was loaded from.
235//
236// If biosdev is kBIOSDevNetwork, then this function will return if
237// booting was unsuccessful. This allows the PXE firmware to try the
238// next boot device on its list.
239void common_boot(int biosdev)
240{
241boolinstantMenu, quiet, rescanPrompt;
242boolfirstRun = true;
243char*bootFile;
244intstatus;
245unsigned intallowBVFlags = kBVFlagSystemVolume|kBVFlagForeignBoot;
246unsigned intdenyBVFlags = kBVFlagEFISystem;
247unsigned longadler32;
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.
251gUnloadPXEOnExit = true;
252
253// Record the device that the booter was loaded from.
254gBIOSDev = biosdev & kBIOSDevMask;
255
256// Initialize boot info structure.
257initKernBootStruct();
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)
384{
385/* XXX AsereBLN handle error */
386initGUI();
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
401config_file_t systemVersion;// system.plist of booting partition - Azi:sysversion
402charsysVersion[8]; // replaces gMacOSVersion here, for now.
403
404// additional variable for testing alternate kernel image locations on boot helper partitions.
405charbootFileSpec[512]; //Azi:HelperConfig - kernel
406
407// Initialize globals.
408
409sysConfigValid = false;
410gErrors = false;
411
412status = getBootOptions(firstRun);
413firstRun = false;
414if ( status == -1 ) continue;
415
416//Azi:sysversion related test
417if( bootArgs->Video.v_display == GRAPHICS_MODE )
418{
419drawBackground(); //Azi: just seems repeated and less complete than the next!? though to the eye,
420updateVRAM();//the next seems to do exactly the same??! testing
421}
422
423// Turn off any GUI elements
424/*if ( bootArgs->Video.v_display == GRAPHICS_MODE )
425{
426gui.devicelist.draw = false; // doesn't seem needed
427gui.bootprompt.draw = false; // same as above
428gui.menu.draw = false; // same as above
429gui.infobox.draw = false; // Enter doesn't work with this drawn so...
430drawBackground();
431updateVRAM(); // don't know about this
432}*/
433
434//Azi:autoresolution begin
435/*
436 * AutoResolution - Reapply the patch or cancel if Graphics Mode was incorrect
437 *or EDID Info was insane
438 */
439 getBoolForKey(kAutoResolutionKey, &gAutoResolution, &bootInfo->bootConfig);
440
441//Restore the vbios for Cancelation
442if ((gAutoResolution == false) && map)
443{
444restoreVbios(map);
445closeVbios(map);
446}
447
448if ((gAutoResolution == true) && map)
449{
450// If mode has been switched during boot menu
451// use the new resolution
452if (map->hasSwitched == true)
453{
454params[0] = map->currentX;
455params[1] = map->currentY;
456params[2] = 32;
457}
458else
459{
460//or get resolution from Graphics Mode or EDID
461int count = getNumberArrayFromProperty(kGraphicsModeKey, params, 4);
462if (count < 3)
463getResolution(params);
464else
465{
466if ( params[2] == 256 ) params[2] = 8;
467if ( params[2] == 555 ) params[2] = 16;
468if ( params[2] == 888 ) params[2] = 32;
469}
470}
471
472//Resolution has changed, reapply the patch
473if ((params[0] != 0) && (params[1] != 0) && (params[0] != map->currentX) &&
474(params[1] != map->currentY))
475{
476patchVbios(map, params[0], params[1], params[2], 0, 0);
477}
478closeVbios(map); // doesn't print to screen from here
479}
480//Azi:autoresolution end
481
482status = processBootOptions();
483
484// Status == 1 means to chainboot
485if ( status ==1 ) break;
486
487// Status == -1 means that gBootVolume is NULL - Azi: little edit to reflect current status.
488if ( status == -1 )
489{
490// gBootVolume == NULL usually means the user hit escape.
491if (gBootVolume == NULL) //Azi: hitting escape makes me boot when "at" boot prompt.
492{
493freeFilteredBVChain(bvChain);
494
495if (gEnableCDROMRescan)
496rescanBIOSDevice(gBIOSDev);
497
498bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);
499setBootGlobals(bvChain);
500}
501continue;
502}
503
504// Other status (e.g. 0) means that we should proceed with boot.
505// Found and loaded a config file (Azi: not mandatory anymore).
506
507//Azi:autoresolution old - testing
508
509// Find out which version mac os we're booting. Azi:sysversion
510// To avoid call loadOverrideConfig from here too and since moving this before calling
511// processBootOptions() (which worked on a brief test) doesn't make sense,
512// tried to move it to processBootOptions() on options.c (check there).
513if (!loadConfigFile("/System/Library/CoreServices/SystemVersion.plist", &systemVersion))
514{ //Azi: shouldn't this path start with / ?
515if (getValueForKey(kProductVersion, &val, &len, &systemVersion))
516{
517// getValueForKey uses const char for val
518// so copy it and trim
519strncpy(sysVersion, val, MIN(len, 4));
520sysVersion[MIN(len, 4)] = '\0';
521}
522}
523
524//Azi:sysversion - gMacOSVersion is only initialized above so, this call is only to get
525// system version so we can override Boot.plist from specific OS folders; another plus is verbose.
526// It seems to work fine though i'm not sure how sane is to call it twice?!
527// Can't be called only from here! Need advice. Check above.
528//loadOverrideConfig(&bootInfo->overrideConfig); // call 2
529
530// If cpu does not understand 64 bit instructions,...
531if ( !platformCPUFeature(CPU_FEATURE_EM64T) ||
532// ... user forced i386 kernel architecture on cpu with em64t...
533getValueForKey(kArchI386Flag, &val, &len, &bootInfo->bootConfig) ||
534// ... or forced Legacy Mode... (not needed!)
535getValueForKey(kLegacyModeFlag, &val, &len, &bootInfo->bootConfig) )
536{
537// ... use i386 kernel arch!
538archCpuType = CPU_TYPE_I386;
539}
540else
541{
542// Else use x86_64 kernel arch!
543archCpuType = CPU_TYPE_X86_64;
544}
545// Force x86_64 kernel arch if i386/-legacy are flagged on Boot.plist.
546if (getValueForKey(kArchX86_64Flag, &val, &len, &bootInfo->bootConfig))
547{
548archCpuType = CPU_TYPE_X86_64;
549}
550
551if (!getBoolForKey (kWakeKey, &tryresume, &bootInfo->bootConfig))
552{
553tryresume = true;
554tryresumedefault = true;
555}
556else
557{
558tryresumedefault = false;
559}
560
561if (!getBoolForKey (kForceWakeKey, &forceresume, &bootInfo->bootConfig))
562{
563forceresume = false;
564}
565
566if (forceresume)
567{
568tryresume = true;
569tryresumedefault = false;
570}
571
572while (tryresume)
573{
574const char *tmp;
575BVRef bvr;
576if (!getValueForKey(kWakeImageKey, &val, &len, &bootInfo->bootConfig))
577val="/private/var/vm/sleepimage";
578
579// Do this first to be sure that root volume is mounted
580ret = GetFileInfo(0, val, &flags, &sleeptime);
581
582if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)
583break;
584
585// Can't check if it was hibernation Wake=y is required
586if (bvr->modTime == 0 && tryresumedefault)
587break;
588
589if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))
590break;
591
592if (!forceresume && ((sleeptime+3)<bvr->modTime))
593{
594printf("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",
595bvr->modTime-sleeptime);
596break;
597}
598HibernateBoot((char *)val);
599break;
600}
601
602// Reset cache name.
603bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
604
605sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);
606
607adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
608
609if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))
610{
611strlcpy(gBootKernelCacheFile, val, len+1);
612}
613else
614{
615sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePath, adler32);
616}
617
618// Check for cache file.
619trycache = (((gBootMode & kBootModeSafe) == 0) &&
620!gOverrideKernel &&
621(gBootFileType == kBlockDeviceType) &&
622(gMKextName[0] == '\0') &&
623(gBootKernelCacheFile[0] != '\0'));
624
625verbose("Loading Darwin %s\n", sysVersion); //Azi:sysversion
626
627if (trycache) do
628{
629// if we haven't found the kernel yet, don't use the cache
630ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
631if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))
632{
633trycache = 0;
634break;
635}
636
637ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
638if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)
639|| (cachetime < kerneltime))
640{
641trycache = 0;
642break;
643}
644
645ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);
646if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)
647&& (cachetime < exttime))
648{
649trycache = 0;
650break;
651}
652
653if (kerneltime > exttime)
654{
655exttime = kerneltime;
656}
657
658if (cachetime != (exttime + 1))
659{
660trycache = 0;
661break;
662}
663} while (0);
664
665do
666{
667if (trycache)
668{
669bootFile = gBootKernelCacheFile;
670verbose("Loading kernel cache %s\n", bootFile); //Azi: i never saw this!! check!!!
671ret = LoadFile(bootFile);
672binary = (void *)kLoadAddr;
673if (ret >= 0)
674{
675break;
676}
677}
678
679bootFile = bootInfo->bootFile;
680
681// Try to load kernel image from alternate locations on boot helper partitions.
682sprintf(bootFileSpec, "com.apple.boot.P/%s", bootFile); //Azi:HelperConfig - kernel
683
684ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
685if (ret == -1)
686{
687sprintf(bootFileSpec, "com.apple.boot.R/%s", bootFile);
688
689ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
690if (ret == -1)
691{
692sprintf(bootFileSpec, "com.apple.boot.S/%s", bootFile);
693
694ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
695if (ret == -1)
696{
697// Not found any alternate locations, using the original kernel image path.
698strcpy(bootFileSpec, bootFile);
699}
700}
701}
702
703verbose("Loading kernel %s\n", bootFileSpec);
704
705ret = LoadThinFatFile(bootFileSpec, &binary);
706if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
707{
708archCpuType = CPU_TYPE_I386;
709ret = LoadThinFatFile(bootFileSpec, &binary);
710}
711
712} while (0);
713
714clearActivityIndicator();
715/*#if DEBUG
716printf("Pausing...");
717sleep(8);
718#endif Azi: annoying! Can't see the point atm... */
719
720if (ret <= 0)
721{
722printf("Can't find %s\n", bootFile);
723
724if(gui.initialised)
725{
726sleep(1);
727drawBackground();
728gui.devicelist.draw = true;
729gui.redraw = true;
730}
731
732if (gBootFileType == kNetworkDeviceType) {
733// Return control back to PXE. Don't unload PXE base code.
734gUnloadPXEOnExit = false;
735break;
736}
737}
738else
739{
740/* Won't return if successful. */
741ret = ExecKernel(binary);
742}
743}
744
745// chainboot
746if (status==1)
747{
748if (getVideoMode() == GRAPHICS_MODE)
749{// if we are already in graphics-mode,
750setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode
751}
752}
753
754if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit)
755{
756nbpUnloadBaseCode();
757}
758}
759
760/*!
761 Selects a new BIOS device, taking care to update the global state appropriately.
762 */
763/*
764static void selectBiosDevice(void)
765{
766 struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);
767 CacheReset();
768 diskFreeMap(oldMap);
769 oldMap = NULL;
770
771 int dev = selectAlternateBootDevice(gBIOSDev);
772
773 BVRef bvchain = scanBootVolumes(dev, 0);
774 BVRef bootVol = selectBootVolume(bvchain);
775 gBootVolume = bootVol;
776 setRootVolume(bootVol);
777 gBIOSDev = dev;
778}
779*/
780
781#define BASE 65521L /* largest prime smaller than 65536 */
782#define NMAX 5000
783// NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
784
785#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
786#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
787#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
788#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
789#define DO16(buf) DO8(buf,0); DO8(buf,8);
790
791unsigned long Adler32(unsigned char *buf, long len)
792{
793 unsigned long s1 = 1; // adler & 0xffff;
794 unsigned long s2 = 0; // (adler >> 16) & 0xffff;
795 unsigned long result;
796 int k;
797
798 while (len > 0) {
799 k = len < NMAX ? len : NMAX;
800 len -= k;
801 while (k >= 16) {
802 DO16(buf);
803 buf += 16;
804 k -= 16;
805 }
806 if (k != 0) do {
807 s1 += *buf++;
808 s2 += s1;
809 } while (--k);
810 s1 %= BASE;
811 s2 %= BASE;
812 }
813 result = (s2 << 16) | s1;
814 return OSSwapHostToBigInt32(result);
815}
816

Archive Download this file

Revision: 296