Chameleon

Chameleon Commit Details

Date:2014-02-02 16:28:40 (5 years 8 months ago)
Author:Jief Luce
Commit:2370
Parents: 2369
Message:Cleaned white spaces
Changes:
M/branches/Jief/i386/boot2/boot.c

File differences

branches/Jief/i386/boot2/boot.c
22
33
44
5
5
66
77
88
......
1010
1111
1212
13
13
1414
1515
1616
......
1818
1919
2020
21
21
2222
2323
2424
25
25
2626
2727
2828
......
3333
3434
3535
36
37
36
37
3838
3939
4040
......
9999
100100
101101
102
102
103103
104104
105
105
106106
107107
108108
......
129129
130130
131131
132
132
133133
134134
135
135
136136
137137
138138
139139
140
140
141141
142142
143
143
144144
145145
146
146
147147
148148
149
149
150150
151
151
152152
153153
154154
155
155
156156
157
157
158158
159
159
160160
161161
162162
163163
164164
165
165
166166
167
167
168168
169169
170170
171171
172
172
173173
174174
175175
......
177177
178178
179179
180
180
181181
182182
183183
184184
185
185
186186
187187
188188
......
192192
193193
194194
195
195
196196
197
197
198198
199
199
200200
201201
202202
......
207207
208208
209209
210
210
211211
212212
213213
......
216216
217217
218218
219
219
220220
221221
222222
......
376376
377377
378378
379
379
380380
381381
382382
383
383
384384
385385
386386
387
387
388388
389389
390
390
391391
392
392
393393
394394
395395
396396
397
397
398398
399399
400
400
401401
402402
403403
404404
405
405
406406
407407
408
408
409409
410410
411411
412
412
413413
414414
415415
416416
417
417
418418
419419
420
420
421421
422422
423
423
424424
425425
426426
427427
428428
429
429
430430
431431
432432
......
434434
435435
436436
437
437
438438
439439
440440
441441
442442
443
443
444444
445445
446446
447447
448448
449449
450
450
451451
452452
453
453
454454
455
456
455
456
457457
458
458
459459
460460
461461
462
462
463463
464464
465465
466466
467
467
468468
469469
470470
......
473473
474474
475475
476
476
477477
478478
479479
......
482482
483483
484484
485
485
486486
487
487
488488
489489
490490
......
494494
495495
496496
497
497
498498
499499
500500
......
502502
503503
504504
505
505
506506
507507
508508
509
509
510510
511511
512512
......
517517
518518
519519
520
520
521521
522522
523
523
524524
525525
526526
527527
528528
529529
530
530
531531
532
532
533533
534534
535535
......
541541
542542
543543
544
544
545545
546546
547
547
548548
549549
550550
551551
552552
553
553
554554
555555
556556
557557
558558
559
559
560560
561561
562562
563563
564564
565
565
566566
567567
568
568
569569
570570
571571
572572
573573
574574
575
575
576576
577577
578578
579
579
580580
581581
582582
583583
584
584
585585
586586
587587
588588
589589
590
590
591591
592592
593
593
594594
595595
596
596
597597
598598
599599
600
600
601601
602602
603
603
604604
605
605
606606
607607
608
608
609609
610610
611
611
612612
613613
614614
615
615
616616
617617
618618
......
646646
647647
648648
649
649
650650
651651
652652
......
687687
688688
689689
690
690
691691
692692
693693
......
696696
697697
698698
699
699
700700
701
701
702702
703703
704704
705705
706
706
707707
708708
709709
710
710
711711
712712
713713
......
720720
721721
722722
723
723
724724
725725
726726
......
728728
729729
730730
731
731
732732
733733
734734
......
744744
745745
746746
747
747
748748
749
749
750750
751751
752752
......
755755
756756
757757
758
758
759759
760760
761761
......
782782
783783
784784
785
785
786786
787787
788788
* Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
*
* Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
/*
* Mach Operating System
* Copyright (c) 1990 Carnegie-Mellon University
* Copyright (c) 1989 Carnegie-Mellon University
/*
*INTEL CORPORATION PROPRIETARY INFORMATION
*
*This software is supplied under the terms of a licenseagreement or
*nondisclosure agreement with Intel Corporation and may not be copied
*This software is supplied under the terms of a licenseagreement or
*nondisclosure agreement with Intel Corporation and may not be copied
*nor disclosed except in accordance with the terms of that agreement.
*
*Copyright 1988, 1989 by Intel Corporation
extern char bss_end __asm("section$end$__DATA$__bss");
extern char common_start __asm("section$start$__DATA$__common");
extern char common_end __asm("section$end$__DATA$__common");
bzero(&bss_start, (&bss_end - &bss_start));
bzero(&common_start, (&common_end - &common_start));
}
}
//==========================================================================
// Malloc error function
{
intret;
entry_tkernelEntry;
bootArgs->kaddr = bootArgs->ksize = 0;
execute_hook("ExecKernel", (void*)binary, NULL, NULL, NULL);
ret = DecodeKernel(binary,
&kernelEntry,
(char **) &bootArgs->kaddr,
(int *)&bootArgs->ksize );
if ( ret != 0 )
return ret;
// Reserve space for boot args
reserveKernBootStruct();
// Notify modules that the kernel has been decoded
execute_hook("DecodedKernel", (void*)binary, (void*)bootArgs->kaddr, (void*)bootArgs->ksize, NULL);
setupFakeEfi();
// Load boot drivers from the specifed root path.
//if (!gHaveKernelCache)
LoadDrivers("/");
execute_hook("DriversLoaded", (void*)binary, NULL, NULL, NULL);
clearActivityIndicator();
if (gErrors) {
printf("Errors encountered while starting up the computer.\n");
printf("Pausing %d seconds...\n", kBootErrorTimeout);
sleep(kBootErrorTimeout);
}
md0Ramdisk();
verbose("Starting Darwin %s\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64");
verbose("Boot Args: %s\n", bootArgs->CommandLine);
// Cleanup the PXE base code.
if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit ) {
if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )
{
sleep(2);
}
}
bool dummyVal;
if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->chameleonConfig) && dummyVal) {
showTextBuffer(msgbuf, strlen(msgbuf));
}
usb_loop();
// If we were in text mode, switch to graphics mode.
setVideoMode( GRAPHICS_MODE, 0 );
else
drawBootGraphics();
setupBooterLog();
finalizeBootStruct();
// Jump to kernel's entry point. There's no going back now.
if ((checkOSVersion("10.7")) || (checkOSVersion("10.8")) || (checkOSVersion("10.9")))
{
// Masking out so that Lion doesn't doublefault
outb(0x21, 0xff);/* Maskout all interrupts Pic1 */
outb(0xa1, 0xff);/* Maskout all interrupts Pic2 */
startprog( kernelEntry, bootArgs );
}
else {
startprog( kernelEntry, bootArgsPreLion );
}
// Not reached
return 0;
}
intstatus;
unsigned intallowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;
unsigned intdenyBVFlags = kBVFlagEFISystem;
// Set reminder to unload the PXE base code. Neglect to unload
// the base code will result in a hang or kernel panic.
gUnloadPXEOnExit = true;
// Record the device that the booter was loaded from.
gBIOSDev = biosDevAndPart & kBIOSDevMask;
gBootPartition = ((biosDevAndPart & 0xFF00) >> 8);
// Initialize boot info structure.
initKernBootStruct();
initBooterLog();
// Setup VGA text mode.
// Not sure if it is safe to call setVideoMode() before the
// config table has been loaded. Call video_mode() instead.
video_mode( 2 ); // 80x25 mono text mode.
// Scan and record the system's hardware information.
scan_platform();
// First get info for boot volume.
scanBootVolumes(gBIOSDev, 0);
bvChain = getBVChainForBIOSDev(gBIOSDev);
setBootGlobals(bvChain);
// Load boot.plist config file
status = loadChameleonConfig(&bootInfo->chameleonConfig);
if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet) {
gBootMode |= kBootModeQuiet;
}
// Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config
if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->chameleonConfig) && instantMenu) {
firstRun = false;
}
// Loading preboot ramdisk if exists.
loadPrebootRAMDisk();
// Disable rescan option by default
gEnableCDROMRescan = false;
// Enable it with Rescan=y in system config
if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->chameleonConfig)
&& gEnableCDROMRescan) {
gEnableCDROMRescan = true;
}
// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.
rescanPrompt = false;
if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig)
{
gEnableCDROMRescan = promptForRescanOption();
}
// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.
if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->chameleonConfig)
&& gScanSingleDrive) {
gScanSingleDrive = true;
}
// Create a list of partitions on device(s).
if (gScanSingleDrive) {
scanBootVolumes(gBIOSDev, &bvCount);
} else {
scanDisks(gBIOSDev, &bvCount);
}
// Create a separated bvr chain using the specified filters.
bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);
gBootVolume = selectBootVolume(bvChain);
// Intialize module system
// Intialize module system
init_module_system();
#if DEBUG
printf("gBIOSDev=%d\n", gBIOSDev);
printf("gBootPartition=%d\n", gBootPartition);
printf(" gBootVolume: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n",
gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);
printf(" gBIOSBootVolume==bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n",
gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);
for (BVRef bvr = bvChain; bvr; bvr = bvr->next)
{
printf(" chain: %d, dev: %d, part: %d, flags: %d, ver:%s vis: %d\n", bvr, bvr->biosdev, bvr->part_no, bvr->flags, bvr->OSVersion, bvr->visible);
getchar();
#endif
useGUI = true;
// Override useGUI default
getBoolForKey(kGUIKey, &useGUI, &bootInfo->chameleonConfig);
// initGUI() returned with an error, disabling GUI.
useGUI = false;
}
setBootGlobals(bvChain);
// Parse args, load and start kernel.
while (1)
{
intlen, ret = -1;
longflags, sleeptime, time;
void*binary = (void *)kLoadAddr;
char bootFile[sizeof(bootInfo->bootFile)];
charbootFilePath[512];
charkernelCacheFile[512];
// Initialize globals.
sysConfigValid = false;
gErrors = false;
status = getBootOptions(firstRun);
firstRun = false;
if (status == -1) continue;
status = processBootOptions();
// Status == 1 means to chainboot
if ( status ==1 ) break;
if (gBootVolume == NULL)
{
freeFilteredBVChain(bvChain);
if (gEnableCDROMRescan)
rescanBIOSDevice(gBIOSDev);
bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);
setBootGlobals(bvChain);
setupDeviceList(&bootInfo->themeConfig);
}
continue;
}
// Other status (e.g. 0) means that we should proceed with boot.
// Turn off any GUI elements
if ( bootArgs->Video.v_display == GRAPHICS_MODE )
{
drawBackground();
updateVRAM();
}
// Find out which version mac os we're booting.
getOSVersion();
if (platformCPUFeature(CPU_FEATURE_EM64T)) {
archCpuType = CPU_TYPE_X86_64;
} else {
archCpuType = CPU_TYPE_I386;
}
if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig)) {
if (strncmp(val, "i386", 4) == 0) {
archCpuType = CPU_TYPE_I386;
}
}
if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig)) {
if (strncmp(val, "i386", 4) == 0) {
archCpuType = CPU_TYPE_I386;
}
}
// Notify modules that we are attempting to boot
execute_hook("PreBoot", NULL, NULL, NULL, NULL);
if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig)) {
tryresume = true;
tryresumedefault = true;
} else {
tryresumedefault = false;
}
if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig)) {
forceresume = false;
}
if (forceresume) {
tryresume = true;
tryresumedefault = false;
}
while (tryresume) {
const char *tmp;
BVRef bvr;
if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->chameleonConfig))
val = "/private/var/vm/sleepimage";
// Do this first to be sure that root volume is mounted
ret = GetFileInfo(0, val, &flags, &sleeptime);
if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)
break;
// Can't check if it was hibernation Wake=y is required
if (bvr->modTime == 0 && tryresumedefault)
break;
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))
break;
if (!forceresume && ((sleeptime+3)<bvr->modTime)) {
#if DEBUG
#if DEBUG
printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",
bvr->modTime-sleeptime);
#endif
#endif
break;
}
HibernateBoot((char *)val);
break;
}
verbose("Loading Darwin %s\n", gMacOSVersion);
getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);
useKernelCache = false;
} while(0);
do {
if (useKernelCache) {
ret = LoadKernelCache(kernelCacheFile, &binary);
// No alternate location found, using the original kernel image path.
strlcpy(bootFilePath, bootFile,sizeof(bootFilePath));
}
verbose("Loading kernel %s\n", bootFilePath);
ret = LoadThinFatFile(bootFilePath, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
ret = LoadThinFatFile(bootFilePath, &binary);
}
} while (0);
clearActivityIndicator();
#if DEBUG
printf("Pausing...");
sleep(8);
#endif
if (ret <= 0) {
printf("Can't find %s\n", bootFile);
sleep(1);
if (gBootFileType == kNetworkDeviceType) {
// Return control back to PXE. Don't unload PXE base code.
gUnloadPXEOnExit = false;
ret = ExecKernel(binary);
}
}
// chainboot
if (status == 1) {
// if we are already in graphics-mode,
setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode.
}
}
if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) {
nbpUnloadBaseCode();
}
CacheReset();
diskFreeMap(oldMap);
oldMap = NULL;
int dev = selectAlternateBootDevice(gBIOSDev);
BVRef bvchain = scanBootVolumes(dev, 0);
BVRef bootVol = selectBootVolume(bvchain);
gBootVolume = bootVol;
}
*/
bool checkOSVersion(const char * version)
bool checkOSVersion(const char * version)
{
return ((gMacOSVersion[0] == version[0]) && (gMacOSVersion[1] == version[1])
&& (gMacOSVersion[2] == version[2]) && (gMacOSVersion[3] == version[3]));
unsigned long s2 = 0; // (adler >> 16) & 0xffff;
unsigned long result;
int k;
while (len > 0) {
k = len < NMAX ? len : NMAX;
len -= k;

Archive Download the corresponding diff file

Revision: 2370