Chameleon

Chameleon Commit Details

Date:2011-05-20 04:54:11 (12 years 11 months ago)
Author:Azimutz
Commit:840
Parents: 839
Message:Following r820: - removed a duplicate "execute_hook("Kernel Start"..." - checked and added missing "boot_args/boot_args_pre_lion" stuff - small tweaks to "kDefaultCachePath..." and "gMacOSVersion" - enabled masking out of Pic interrupts on asm.s (thanks to DHP) - comment edits - reverted to XCode 3.2.6 build environment Folder is now on a working state :)
Changes:
M/branches/azimutz/Chazi/i386/boot2/options.c
M/branches/azimutz/Chazi/i386/libsaio/stringTable.c
M/branches/azimutz/Chazi/i386/libsaio/asm.s
M/branches/azimutz/Chazi/i386/libsaio/biosfn.c
M/branches/azimutz/Chazi/i386/libsaio/bios.h
M/branches/azimutz/Chazi/i386/modules/Makefile
M/branches/azimutz/Chazi
M/branches/azimutz/Chazi/i386/libsaio/saio_types.h
M/branches/azimutz/Chazi/i386/libsaio/bootargs.h
M/branches/azimutz/Chazi/i386/boot2/boot.c
M/branches/azimutz/Chazi/i386/libsaio/bootstruct.c
M/branches/azimutz/Chazi/i386/libsaio/fake_efi.c
M/branches/azimutz/Chazi/i386/boot2/boot.h
M/branches/azimutz/Chazi/i386/boot2/modules.c
M/branches/azimutz/Chazi/i386/libsaio/bootstruct.h

File differences

branches/azimutz/Chazi/i386/libsaio/asm.s
339339
340340
341341
342
342
343
343344
344345
345346
......
347348
348349
349350
350
351
351352
352
353
353354
354
355
355
356
356357
357
358
359
358
359
360
360361
361
362
362363
363
364
364365
365366
366367
......
369370
370371
371372
372
373
373374
374375
375376
jmp _halt
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// disableIRQs() - Azi: DHP (see boot.c/ExecKernel)
// disableIRQs() - Azi: DHP
// http://www.insanelymac.com/forum/index.php?s=&showtopic=255866&view=findpost&p=1677779
//
// Port of original patch by: CPARM (who basically did this in boot.c) Thanks!
//
// must be disabled (that is, masked) when enabling the ACPI APIC operation
// but this isn't done (apparently) on all mobo's and thus we do that here.
//
//LABEL(_disableIRQs)
LABEL(_disableIRQs)
//push %eax // Saving register data
push %eax // Saving register data
//movb $0x80, %al // Block NMI
//outb %al, $0x70
movb $0x80, %al // Block NMI
outb %al, $0x70
//movb $0xff, %al // Load mask
//outb %al, $0x21 // Disable IRQ's 0-7 on Master PIC
//outb %al, $0xa1 // Disable IRQ's 8-15 on Slave PIC
movb $0xff, %al // Load mask
outb %al, $0x21 // Disable IRQ's 0-7 on Master PIC
outb %al, $0xa1 // Disable IRQ's 8-15 on Slave PIC
//popl %eax // Restore register data
popl %eax // Restore register data
//ret
ret
#ifndef BOOT1
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Passes arg to the program in %eax.
//
LABEL(_startprog)
// call _disableIRQs // Taking care of a ACPI bug. (Azi: calling the above - disabled for now)
call _disableIRQs // Taking care of a ACPI bug. (Azi: calling the above)
push %ebp
mov %esp, %ebp
branches/azimutz/Chazi/i386/libsaio/bootstruct.c
4040
4141
4242
43
43
4444
4545
46
4647
4748
4849
......
107108
108109
109110
110
111
112
111
112
113113
114114
115115
116
116
117117
118
119
120
121
122
118123
119124
120125
121126
122
123
124
125
126
127127
128128
129129
130
130131
131132
132133
......
190191
191192
192193
193
194
194195
195196
196197
Node*gMemoryMapNode;
//Node *efiPlatformNode; //Azi: test
//static Azi: modules ??????????????????????
//static Azi: modules ?? doesn't seem so.
static char platformName[64];
//Azi: bootargs - we can't retrive OS version at this point...
void initKernBootStruct( void )
{
Node *node;
}
/* Copy boot args after kernel and record address. */
//Azi: ... but here we can... (done)
/** Copy boot args after kernel and record address. */
void
reserveKernBootStruct(void)
{
if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0') && (gMacOSVersion[2] == '.') && (gMacOSVersion[3] == '7'))
if (gMacOSVersion[3] <= '6')
{
void *oldAddr = bootArgsPreLion;
bootArgsPreLion = (boot_args_pre_lion *)AllocateKernelMemory(sizeof(boot_args_pre_lion));
bcopy(oldAddr, bootArgsPreLion, sizeof(boot_args_pre_lion));
}
else {
void *oldAddr = bootArgs;
bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));
bcopy(oldAddr, bootArgs, sizeof(boot_args));
}
else {
void *oldAddr = bootArgsPreLion;
bootArgsPreLion = (boot_args_pre_lion *)AllocateKernelMemory(sizeof(boot_args_pre_lion));
bcopy(oldAddr, bootArgsPreLion, sizeof(boot_args_pre_lion));
}
}
//Azi: ... and here too.
void
finalizeBootStruct(void)
{
bootArgs->deviceTreeLength = size;
// Copy BootArgs values to older structure
//Azi: Ok, stuff that uses same naming for both bootargs versions... neat ;)
memcpy(&bootArgsPreLion->CommandLine, &bootArgs->CommandLine, BOOT_LINE_LENGTH);
memcpy(&bootArgsPreLion->Video, &bootArgs->Video, sizeof(Boot_Video));
branches/azimutz/Chazi/i386/libsaio/bootstruct.h
2828
2929
3030
31
3132
3233
3334
3435
35
3636
3737
3838
//Azi: this is acting now as a mini libsaio.h :P
//#include "libsaio.h"
//#include "bios.h"
//#include "bootargs.h" - included on saio_types.h
#include "libsa.h"
#include "saio_types.h"
#include "saio_internal.h"
#include "device_tree.h"
#include "bootargs.h"
/*!
Kernel boot args global also used by booter for its own data.
branches/azimutz/Chazi/i386/libsaio/bootargs.h
188188
189189
190190
191
191
192192
193193
} boot_args_pre_lion;
extern char gMacOSVersion[8];
extern char gMacOSVersion[8]; // options.c
#endif /* _PEXPERT_I386_BOOT_H */
branches/azimutz/Chazi/i386/libsaio/bios.h
2929
3030
3131
32
32
3333
3434
3535
#ifndef __LIBSAIO_BIOS_H
#define __LIBSAIO_BIOS_H
#include "bootargs.h"
//#include "bootargs.h"
typedef union {
unsigned int rx;
branches/azimutz/Chazi/i386/libsaio/stringTable.c
493493
494494
495495
496
496
497497
498498
499499
......
666666
667667
668668
669
669
670670
671671
672672
......
693693
694694
695695
696
696
697697
698698
699699
......
726726
727727
728728
729
729730
730731
731732
const char *overrideVal;
int overrideSize;
bool override, ret;
//Azi: bootargs
if (getValueForBootKey(bootArgs->CommandLine, key, val, size))
return true;
// Take in account user overriding the override :P
// Damn thing doesn't work anymore ?????? :-/
if (getValueForKey(kAltConfigKey, &override_pathname, &len, config))
if (getValueForKey(kAltConfigKey, &override_pathname, &len, config)) // config ??
{
// Specify a path to a file, e.g. config=/Extra/test.plist
strcpy(dirSpecBplist, override_pathname);
// "/Extra/com.apple.Boot.plist"
// "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
// These i have no way to test, need advice.
//Azi: RESTORE THESE PATHS!
// "/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
// "/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
// "/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
*/
int loadHelperConfig(config_file_t *config)
{
//Azi: UPDATE WITH MEK'S CODE!
char *dirspec[] = {
"/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
branches/azimutz/Chazi/i386/libsaio/biosfn.c
782782
783783
784784
785
785
786786
787787
788788
......
800800
801801
802802
803
803804
804805
805806
}
#endif
//Azi: Advanced Power Management
#ifdef APM_SUPPORT
#define APM_INTNO 0x15
(bb.ebx.r.h == 'P') &&
(bb.ebx.r.l == 'M')) {
/* Success */
//Azi: apmConfig not on boot_args
bootArgs->apmConfig.major_vers = bb.eax.r.h;
bootArgs->apmConfig.minor_vers = bb.eax.r.l;
bootArgs->apmConfig.flags.data = bb.ecx.rr;
branches/azimutz/Chazi/i386/libsaio/saio_types.h
3131
3232
3333
34
3435
3536
3637
#include "bios.h"
#include "nbp_cmd.h"
#include "bootargs.h"
//Azi: shouldn't this be on disk.c ??
#if DEBUG
#define DEBUG_DISK(x) printf x
branches/azimutz/Chazi/i386/libsaio/fake_efi.c
262262
263263
264264
265
265266
266267
267268
......
371372
372373
373374
375
374376
375377
376378
// --------------------------------------------------------------------
// Finish filling in the rest of the boot args that we need.
//Azi: bootargs
bootArgs->efiSystemTable = (uint32_t)efiSystemTable;
bootArgs->efiMode = kBootArgsEfiMode32;
// --------------------------------------------------------------------
// Finish filling in the rest of the boot args that we need.
//Azi: bootargs
bootArgs->efiSystemTable = (uint32_t)efiSystemTable;
bootArgs->efiMode = kBootArgsEfiMode64;
branches/azimutz/Chazi/i386/boot2/boot.c
102102
103103
104104
105
106
105
106
107107
108
108
109109
110110
111111
......
128128
129129
130130
131
131
132132
133133
134134
......
149149
150150
151151
152
152
153
154
153155
154156
155157
......
207209
208210
209211
210
211212
212213
213214
......
219220
220221
221222
222
223
224
225
226
227
223228
224229
225230
......
233238
234239
235240
236
237
238
239
241
242
240243
241244
242
243245
246
247
248
249
250
251
244252
245
246253
247254
248255
......
328335
329336
330337
338
339
331340
332341
333342
......
554563
555564
556565
566
567
557568
558569
559
570
560571
561572
562573
563
574
564575
565576
577
578
579
580
581
566582
567583
568584
569585
570586
571
587
572588
573589
574590
......
581597
582598
583599
600
584601
602
585603
586604
587605
......
590608
591609
592610
593
611
594612
595
613
596614
597
615
598616
599617
600618
601619
602
620
603621
604622
605623
......
741759
742760
743761
744
745
746
747762
748763
749764
/*
* Default path to kernel cache file
*/
// OS X 10.5 & 10.4
#define kDefaultCachePath "/System/Library/Caches/com.apple.kernelcaches/kernelcache"
// OS X 10.4 & 10.5
#define kCachePathTigerLeopard "/System/Library/Caches/com.apple.kernelcaches/kernelcache"
// OS X 10.6
#define kDefaultCachePathSnow "/System/Library/Caches/com.apple.kext.caches/Startup/kernelcache"
#define kCachePathSnowLion "/System/Library/Caches/com.apple.kext.caches/Startup/kernelcache"
//==========================================================================
// Zero the BSS.
}
//==========================================================================
//Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.
//Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.
//
void initialize_runtime(void)
{
int ret;
bootArgs->kaddr = bootArgs->ksize = 0;
//Azi: here we get to know if we have a kernel or a prelinked kernel
execute_hook("ExecKernel", (void*)binary, NULL, NULL, NULL);
//Azi: gHaveKernelCache is set here
ret = DecodeKernel(binary,
&kernelEntry,
(char **) &bootArgs->kaddr,
// we can't check the plist here if we have AutoResolution=n there and we anabled it
// at boot prompt...?????
//getBoolForKey(kAutoResolutionKey, &gAutoResolution, &bootInfo->bootConfig);
finishAutoRes();
//Azi: closing Vbios after "if (gVerboseMode)" stuff eliminates the need for setting
// Notify modules that the kernel is about to be started
// testing...
execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL);
if (gMacOSVersion[3] <= '6')
execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgsPreLion, NULL, NULL);
else
execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL);
// If we were in text mode, switch to graphics mode.
// This will draw the boot graphics unless we are in
setupBooterLog();
finalizeBootStruct();
// Jump to kernel's entry point. There's no going back now.
//Azi: Lion - http://netkas.org/?p=745
// see asm.s - same stuff by DHP http://www.insanelymac.com/forum/index.php?s=&showtopic=255866&view=findpost&p=1677779
//Azi: see asm.s LABEL(_disableIRQs)
//outb(0x21, 0xff);
//outb(0xa1, 0xff);
startprog( kernelEntry, bootArgs );
// Jump to kernel's entry point. There's no going back now.
if (gMacOSVersion[3] <= '6')
startprog( kernelEntry, bootArgsPreLion );
else
startprog( kernelEntry, bootArgs );
// Not reached
return 0;
}
loadPrebootRAMDisk();
// Load boot.plist config file
//Azi: on this first check, boot.plist acts as both "booter config file"
// and bootargs/options "carrier".*****
status = loadSystemConfig(&bootInfo->bootConfig);
if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet) {
}
//Azi:kernelcache stuff
bool patchKernel = false;
getBoolForKey(kKPatcherKey, &patchKernel, &bootInfo->bootConfig);
//Azi: avoiding having to use -f to ignore kernel cache
//Azi: ignore kernel cache but still use kext cache (E/E.mkext & S/L/E.mkext). - explain...
getBoolForKey(kIgnoreKCKey, &ignoreKC, &bootInfo->bootConfig);
getBoolForKey(kIgnoreKCKey, &ignoreKC, &bootInfo->bootConfig); // equivalent to UseKernelCache
if (ignoreKC)
{
verbose("KC: cache ignored by user.\n");
// make sure the damn thing get's cleaned, just in case... :)*
// make sure the damn thing get's zeroed, just in case... :)*
bzero(gBootKernelCacheFile, sizeof(gBootKernelCacheFile));
}
else if (patchKernel) // to be moved..?
{
verbose("KC: kernel patcher enabled, ignore cache.\n");
bzero(gBootKernelCacheFile, sizeof(gBootKernelCacheFile));
}
else if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))
{
strlcpy(gBootKernelCacheFile, val, len + 1);
verbose("KC: path set by user = %s\n", gBootKernelCacheFile);
//Azi: bypass time check when user sets path ???
// cache is still ignored if time doesn't match... (e.g. usb stick)
// cache is still ignored if time doesn't match... (e.g. booter on usb stick)
}
else
{
const char *ProductName = getStringForKey("SMproductname", &bootInfo->smbiosConfig);
sprintf(gCacheNameAdler, ProductName); // well, at least the smbios.plist can be loaded this early...
// to set/get "ProductName" this early, booter needs complete rewrite!!
// see DHP's Revolution booter rework example!
verbose("KC: gCacheNameAdler 1 = %s\n", gCacheNameAdler);
//Azi: check the validity of this, e.g. on Helper Partitions
sprintf(gCacheNameAdler + 64, "%s", "\\System\\Library\\CoreServices\\boot.efi");
verbose("KC: gCacheNameAdler 2 = %s\n", gCacheNameAdler + 64);
sprintf(gCacheNameAdler + (64 + 38), "%s", bootInfo->bootFile);
// generate adler
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
verbose("KC: Adler32 = %08X\n", adler32);
//Azi: no check for OS version here ?? - yes there is :)
// append arch and/or adler (checksum) to kc path...
if (gMacOSVersion[3] < '6') // change to >= for Lion?
if (gMacOSVersion[3] <= '5')
{
sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePath, adler32);
sprintf(gBootKernelCacheFile, "%s.%08lX", kCachePathTigerLeopard, adler32);
verbose("KC: adler added to path = %s\n", gBootKernelCacheFile);
}
else
{
sprintf(gBootKernelCacheFile, "%s_%s.%08X", kDefaultCachePathSnow,
sprintf(gBootKernelCacheFile, "%s_%s.%08X", kCachePathSnowLion,
(archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64", adler32);
verbose("KC: arch & adler added to path = %s\n", gBootKernelCacheFile);
}
else
{
// Won't return if successful.
// Notify modules that ExecKernel is about to be called
execute_hook("ExecKernel", binary, NULL, NULL, NULL);
ret = ExecKernel(binary);
}
} // while (1)
branches/azimutz/Chazi/i386/boot2/boot.h
100100
101101
102102
103
103104
104
105
105106
106107
107108
......
187188
188189
189190
190
191191
192192
193193
// it's to be passed via "kernel Flags" ?? - "man com.apple.Boot.plist"
#define kKernelNameKey "Kernel" // options.cgetValFK- kFlag*** bFlag ?
#define kKernelCacheKey "Kernel Cache" // boot.cgetValFK- kFlag
#define kKernelFlagsKey "Kernel Flags" // options.cgetValFK- kFlags***
#define kIgnoreKCKey "ignoreKC" // boot.cgetBoolFK- testing***
#define kKernelFlagsKey "Kernel Flags" // options.cgetValFK- kFlags***
#define kKPatcherKey "PatchKernel" // kernel_patcher.cgetBoolFK
#define kAltExtensionsKey "kext" // drivers.cgetValFK
#define kMKextCacheKey "MKext Cache" // options.cgetValFK- kFlag
extern bool gOverrideKernel;
extern char *gPlatformName; // disabled ??
extern char gMKextName[];
extern char gMacOSVersion[];
extern char gRootDevice[];
extern bool gEnableCDROMRescan;
extern bool gScanSingleDrive;
branches/azimutz/Chazi/i386/boot2/modules.c
44
55
66
7
7
88
99
1010
......
340340
341341
342342
343
343344
344345
345346
*/
#ifndef DEBUG_MODULES
#define DEBUG_MODULES 1
#define DEBUG_MODULES 0
#endif
//#include "boot.h"
}
else
{
//Azi: this is double printing when using kernelcache - that's new!
verbose("Invalid mach magic 0x%X\n", ((struct mach_header*)binary)->magic);
//getc();
return NULL;
branches/azimutz/Chazi/i386/boot2/options.c
4141
4242
4343
44
44
4545
4646
4747
......
164164
165165
166166
167
167
168168
169169
170170
......
12131213
12141214
12151215
1216
1216
12171217
12181218
12191219
......
13731373
13741374
13751375
1376
1376
13771377
13781378
13791379
//extern intmenucount;
//extern intgDeviceCount; //Azi: header
chargMacOSVersion[8]; //Azi: moved from boot.c ??? declared on boot.h as extern :-/
chargMacOSVersion[8]; //Azi: moved from boot.c - extern on boot.h/bootargs.h
static bool getOSVersion(char *str); //||
intselectIndex = 0;
}
//==========================================================================
//Azi: bootargs reminder
static char gBootArgs[BOOT_STRING_LEN];
static char * gBootArgsPtr = gBootArgs;
static char * gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;
// Moved here to enable search for override Boot.plist on OS specific folders.
// Find out which Mac OS version we're booting.
// make sure the damn thing get's cleaned, just in case... :)*
// make sure the damn thing get's zeroed, just in case... :)*
bzero(gMacOSVersion, sizeof(gMacOSVersion)); // do this to argP ??... check it*****
getOSVersion(gMacOSVersion);
}
strncpy(&argP[cnt], cp, userCnt);
verbose("BootArgs = %s\n", argP); //Azi: checking...
argP[cnt+userCnt] = '\0';
argP[cnt+userCnt] = '\0'; // shouldn't this null argP ?? see getOSVersion***
verbose("BootArgs check = %s\n", argP); // ||
if (!shouldboot)
branches/azimutz/Chazi/i386/modules/Makefile
11
22
33
4
4
55
66
77
88
99
10
1011
1112
1213
1314
14
15
1516
17
1618
19
1720
1821
1922
#Makefile for i386 modules
# The order of building is important.
SUBDIRS = klibc uClibc++ GraphicsEnablerLegacy KernelPatcher HPET
SUBDIRS = klibc uClibc++ GraphicsEnablerLegacy KernelPatcher Memory HPET
#SUBDIRS = HelloWorld
#-- Resolution (only tested on Meklort's branch, never did any good for my resolution;
#conflicts with AutoResolution)
#-- GraphicsEnabler (no support for ATI legacy cards, e.g. 1000 series)
#testing = http://www.insanelymac.com/forum/index.php?s=&showtopic=231075&view=findpost&p=1683785
#-- Memory ("Attempting to execute hook ScanMemory"
#Divide by 0
#"This is a non recoverable error! System HALTED!!!")
# (Based on previous tests whith Meklort's branch; here just instant reboots. XCode 4 specific)
# (Based on previous tests whith Meklort's branch; here just instant reboots. XCode 4 SPECIFIC!!)
#-- KernelPatcher (hangs right after loading the kernel. XCode 4 SPECIFIC!!)
CFLAGS= -O $(MORECPP) -arch i386 -g -static
DEFINES=
CONFIG = hd

Archive Download the corresponding diff file

Revision: 840