Chameleon

Chameleon Commit Details

Date:2010-08-11 23:39:39 (9 years 12 days ago)
Author:Azimutz
Commit:353
Parents: 352
Message:Trunk it, rev 352. Porting some changes from CleanCut.
Changes:
M/branches/azimutz/Chazileon/i386/boot2/drivers.c
M/branches/azimutz/Chazileon/i386/libsaio/acpi_patcher.c
M/branches/azimutz/Chazileon/doc/BootHelp.txt
M/branches/azimutz/Chazileon/i386/boot2/boot.c
M/branches/azimutz/Chazileon/i386/libsaio/nvidia.c
M/branches/azimutz/Chazileon/i386/boot2/boot.h
M/branches/azimutz/Chazileon/i386/libsaio/pci_root.c
M/branches/azimutz/Chazileon/i386/libsaio/stringTable.c
M/branches/azimutz/Chazileon/i386/libsaio/nvidia.h

File differences

branches/azimutz/Chazileon/doc/BootHelp.txt
11
22
3
43
54
65
......
1918
2019
2120
22
23
21
22
23
24
2425
2526
2627
TODO:
- add TAB, change between textmode/gui??
- add arch & -legacy
- add ramdisk stuff
The boot: prompt waits for you to type advanced startup options.
kernel: kernel name (e.g. "mach_kernel" - must be in "/" )
flags: -v (verbose) -s (single user mode),
-x (safe mode) -F (ignore boot configuration file)
flags: -v (verbose) -s (single user mode),
-x (safe mode) -F (ignore boot configuration file)
32 (i386 arch) -legacy (no 64 bit apps - kernel flag)
64 (x86_64 arch)
"Graphics Mode"="WIDTHxHEIGHTxDEPTH" (e.g. "1024x768x32")
branches/azimutz/Chazileon/i386/libsaio/acpi_patcher.c
9494
9595
9696
97
98
97
98
9999
100100
101101
102102
103
103
104104
105105
106
107
106
107
108108
109109
110110
111111
112112
113
114
113
114
115115
116116
117
118
117
118
119119
120120
121121
122122
123
124
123
124
125125
126126
127127
128128
129129
130130
131
132
133
131
132
133
134134
135135
136136
......
141141
142142
143143
144
144
145145
146146
147147
148148
149149
150150
151
151
152152
153153
154154
......
353353
354354
355355
356
356
357357
358358
359359
......
508508
509509
510510
511
512511
513512
513
514
514515
515516
516517
/** The following ACPI Table search algo, should be reused anywhere needed: */
int search_and_get_acpi_fd(const char * filename, const char ** outDirspec) //Azi:searchalgo
{
chardirSpecExtraDsdt[128] = ""; //Azi:alloc - was 512
const char *override_pathfile = NULL;
chardirSpecDSDT[128] = ""; //Azi:alloc - was 512
const char *override_pathname = NULL;
intlen = 0, fd = 0;
extern char gMacOSVersion;
// Take in account user overriding
if (getValueForKey(kDSDTKey, &override_pathfile, &len, &bootInfo->bootConfig))
if (getValueForKey(kDSDTKey, &override_pathname, &len, &bootInfo->bootConfig))
{
// Specify a path to a file, e.g. /Extra/test.aml
sprintf(dirSpecExtraDsdt, override_pathfile);
fd = open(dirSpecExtraDsdt, 0);
sprintf(dirSpecDSDT, override_pathname);
fd = open(dirSpecDSDT, 0);
if (fd >= 0) goto success_fd;
}
// Check drivers.c, LoadDrivers, for more comments on these.
sprintf(dirSpecExtraDsdt, "rd(0,0)/%s", filename);
fd = open(dirSpecExtraDsdt, 0);
sprintf(dirSpecDSDT, "rd(0,0)/%s", filename);
fd = open(dirSpecDSDT, 0);
if (fd >= 0) goto success_fd;
sprintf(dirSpecExtraDsdt, "bt(0,0)/Extra/%s/%s", &gMacOSVersion, filename);
fd = open(dirSpecExtraDsdt, 0);
sprintf(dirSpecDSDT, "bt(0,0)/Extra/%s/%s", &gMacOSVersion, filename);
fd = open(dirSpecDSDT, 0);
if (fd >= 0) goto success_fd;
// Removed /Extra path from search algo. If needed can be specified on override key!
sprintf(dirSpecExtraDsdt, "bt(0,0)/Extra/%s", filename);
fd = open(dirSpecExtraDsdt, 0);
sprintf(dirSpecDSDT, "bt(0,0)/Extra/%s", filename);
fd = open(dirSpecDSDT, 0);
if (fd >= 0) goto success_fd;
// Add helper partitions??
// Azi: ok, one gone.. let's kill this one too?
// All "config" files go in Extra!
/*sprintf(dirspec, "/%s", filename); // search root
fd=open (dirspec,0);
if (fd>=0) goto success_fd;*/
//sprintf(dirspec, "/%s", filename); // search root
//fd=open (dirspec,0);
//if (fd>=0) goto success_fd;
// NOT FOUND:
//Azi: handling this only on pci_root.c, getPciRootUID() (it's enough to check if .aml file exists),
return -1;
// FOUND
success_fd:
if (outDirspec) *outDirspec = dirSpecExtraDsdt;
if (outDirspec) *outDirspec = dirSpecDSDT;
return fd;
}
void *loadACPITable (const char * filename) //Azi: called on setupAcpi()
{
void *tableAddr;
const char * dsdt_filename = NULL; //Azi: = dirSpecExtraDsdt
const char * dsdt_filename = NULL; //Azi: = dirSpecDSDT
//Azi:dsdt - call 2; call 1 on pci_root.c (getPciRootUID), changed dirspec to dsdt_filename according (review this!!!).
int fd = search_and_get_acpi_fd(filename, &dsdt_filename);
}
struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt* dsdt)
{
{
char ssdt_header[] =
{
0x53, 0x53, 0x44, 0x54, 0x7E, 0x00, 0x00, 0x00, /* SSDT.... */
}
} break;
case CPU_MODEL_FIELDS:
case CPU_MODEL_NEHALEM:
case CPU_MODEL_DALES:
case CPU_MODEL_DALES_32NM:
case CPU_MODEL_NEHALEM:
case CPU_MODEL_NEHALEM_EX:
case CPU_MODEL_WESTMERE:
case CPU_MODEL_WESTMERE_EX:
default:
branches/azimutz/Chazileon/i386/libsaio/pci_root.c
5757
5858
5959
60
60
6161
6262
6363
......
110110
111111
112112
113
113
114114
115115
116116
if (rootuid < 10) return rootuid;
// If user supplied a key...
if (getValueForKey(kPciRootKey, &val, &len, &bootInfo->bootConfig))
if (getValueForKey(kPCIRootUIDKey, &val, &len, &bootInfo->bootConfig))
{
if (isdigit(val[0]))
rootuid = val[0] - '0';
rootuid = 0; // ... default uid to 0.
}
else
printf("Found UID value on user supplied ACPI Table...\n");
printf("Found UID value on ACPI Table provided by user...\n");
out:
verbose("Using PCI-Root-UID value: %d\n", rootuid);
out_out:
branches/azimutz/Chazileon/i386/libsaio/nvidia.c
663663
664664
665665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
666688
667689
668690
669
691
670692
671
693
672694
673695
674
696
697
675698
676699
677700
678
679
701
702
680703
681704
682705
......
687710
688711
689712
713
714
715
716
717
690718
691719
692
720
693721
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710722
711723
712
713
714
724
725
726
715727
716728
717729
......
797809
798810
799811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
800846
801
802
803
804847
805848
806849
return 0;
}
unsigned long long mem_detect(volatile uint8_t *regs, uint8_t nvCardType, pci_dt_t *nvda_dev)
{
unsigned long long vram_size = 0;
if (nvCardType < NV_ARCH_50) {
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size &= NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK;
}
else if (nvCardType >= NV_ARCH_C0) {
vram_size = REG32(NVC0_MEM_CTRLR_COUNT);
vram_size *= REG32(NVC0_MEM_CTRLR_RAM_AMOUNT);
vram_size <<= 20;
}
else {
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size |= (vram_size & 0xff) << 32;
vram_size &= 0xffffffff00ll;
}
return vram_size;
}
bool setup_nvidia_devprop(pci_dt_t *nvda_dev)
{
struct DevPropDevice*device;
char*devicepath;
char*devicepath;
struct pci_rom_pci_header_t*rom_pci_header;
volatile uint8_t*regs;
volatile uint8_t*regs;
uint8_t*rom;
uint8_t*nvRom;
uint32_tvideoRam;
uint8_tnvCardType;
unsigned long longvideoRam;
uint32_tnvBiosOveride;
uint32_tbar[7];
uint32_tboot_display;
intnvPatch;
intlen;
intnvPatch;
intlen;
charbiosVersion[32];
charnvFilename[32];
charkNVCAP[12];
devicepath = get_pci_dev_path(nvda_dev);
bar[0] = pci_config_read32(nvda_dev->dev.addr, 0x10 );
regs = (uint8_t *) (bar[0] & ~0x0f);
delay(50);
// get card type
nvCardType = (REG32(0) >> 20) & 0x1ff;
// Amount of VRAM in kilobytes
videoRam = (REG32(0x10020c) & 0xfff00000) >> 10;
videoRam = mem_detect(regs, nvCardType, nvda_dev);
model = get_nvidia_model((nvda_dev->vendor_id << 16) | nvda_dev->device_id);
// FIXME: dirty fermi hack
if((nvda_dev->device_id & 0xFFE0) == 0x06C0 ||
(nvda_dev->device_id & 0xFFE0) == 0x0E20) {
switch (nvda_dev->device_id) {
case 0x06C0: videoRam = 1572864; break; // gtx 480
case 0x06CD: videoRam = 1310720; break; // gtx 470
case 0x06C4: videoRam = 1048576; break; // gtx 465
case 0x06CA: videoRam = 2097152; break; // gtx 480m
case 0x0E22: videoRam = 1048576; break; // gtx 460
case 0x0E24: videoRam = 1048576; break; // gtx 460
case 0x06D1: videoRam = 3145728; break; // tesla c2050/c2070
case 0x06DE: videoRam = 3145728; break; // tesla m2050/m2070
default: break;
}
}
verbose("nVidia %s %dMB NV%02x [%04x:%04x] :: %s\n",
model, (videoRam / 1024),
(REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id,
devicepath);
model, (uint32_t)(videoRam / 1024 / 1024),
(REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id,
devicepath);
rom = malloc(NVIDIA_ROM_SIZE);
sprintf(nvFilename, "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id);
uint8_t built_in = 0x01;
devprop_add_value(device, "@0,built-in", &built_in, 1);
}
// get bios version
const int MAX_BIOS_VERSION_LENGTH = 32;
char* version_str = (char*)malloc(MAX_BIOS_VERSION_LENGTH);
memset(version_str, 0, MAX_BIOS_VERSION_LENGTH);
int i, version_start;
int crlf_count = 0;
// only search the first 384 bytes
for(i = 0; i < 0x180; i++) {
if(rom[i] == 0x0D && rom[i+1] == 0x0A) {
crlf_count++;
// second 0x0D0A was found, extract bios version
if(crlf_count == 2) {
if(rom[i-1] == 0x20) i--; // strip last " "
for(version_start = i; version_start > (i-MAX_BIOS_VERSION_LENGTH); version_start--) {
// find start
if(rom[version_start] == 0x00) {
version_start++;
// strip "Version "
if(strncmp((const char*)rom+version_start, "Version ", 8) == 0) {
version_start += 8;
}
strncpy(version_str, (const char*)rom+version_start, i-version_start);
break;
}
}
break;
}
}
}
sprintf(biosVersion, "%s", (nvBiosOveride > 0) ? nvFilename : version_str);
videoRam *= 1024;
sprintf(biosVersion, "xx.xx.xx - %s", (nvBiosOveride > 0) ? nvFilename : "internal");
sprintf(kNVCAP, "NVCAP_%04x", nvda_dev->device_id);
if (getValueForKey(kNVCAP, &value, &len, &bootInfo->bootConfig) && len == NVCAP_LEN * 2) {
uint8_tnew_NVCAP[NVCAP_LEN];
branches/azimutz/Chazileon/i386/libsaio/nvidia.h
6767
6868
6969
70
71
72
73
70
71
72
73
74
75
76
77
78
7479
7580
7681
......
8792
8893
8994
95
9096
9197
9298
uint8_tsize;/* Size in multiples of 512 */
};
#define NV_PROM_OFFSET0x300000
#define NV_PROM_SIZE0x0000ffff
#define NV_PRAMIN_OFFSET0x00700000
#define NV_PRAMIN_SIZE0x00100000
#define NV_PROM_OFFSET0x300000
#define NV_PROM_SIZE0x0000ffff
#define NV_PRAMIN_OFFSET0x00700000
#define NV_PRAMIN_SIZE0x00100000
#define NV04_PFB_FIFO_DATA0x0010020c
#define NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK0xfff00000
#define NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_SHIFT20
#define NVC0_MEM_CTRLR_COUNT0x00121c74
#define NVC0_MEM_CTRLR_RAM_AMOUNT0x0010f20c
#define NV_PBUS_PCI_NV_200x00001850
#define NV_PBUS_PCI_NV_20_ROM_SHADOW_DISABLED(0 << 0)
#define NV_ARCH_30 0x30
#define NV_ARCH_40 0x40
#define NV_ARCH_50 0x50
#define NV_ARCH_C0 0xC0
#define CHIPSET_NV03 0x0010
#define CHIPSET_NV04 0x0020
branches/azimutz/Chazileon/i386/libsaio/stringTable.c
659659
660660
661661
662
662
663663
664664
665665
......
671671
672672
673673
674
674
675675
676676
677677
char dirSpecExtraBplist[128] = ""; //Azi:alloc
const char*override_pathfile = NULL;
const char*filename = "com.apple.Boot.plist";
int fd, count, ret, len = 0/*???*/;
int count, ret, fd, len = 0;
extern char gMacOSVersion;
//Azi: This Override stuff messed with my mind a lot of times; was totally unaware of it. Payback time!! :)
// Keys that are not present on the default Boot.plist will be used with existing ones.
// Take in account user overriding the override :P
if (getValueForKey(kTestConfigFileKey, &override_pathfile, &len, &bootInfo->bootConfig))
if (getValueForKey(kTestConfigKey, &override_pathfile, &len, &bootInfo->bootConfig))
{
// Specify a path to a file, e.g. /Extra/test.plist
strcpy(dirSpecExtraBplist, override_pathfile);
branches/azimutz/Chazileon/i386/boot2/boot.c
380380
381381
382382
383
383
384384
385
386
385
386
387387
388388
389389
......
413413
414414
415415
416
416
417417
418418
419
420
419
420
421
421422
422423
423424
424425
425426
426
427
427
428
428429
429430
430431
......
527528
528529
529530
530
531
532
531
532
533
534
533535
534
535
536
537
536538
537
539
538540
539541
540542
541543
542
544
543545
544546
545
547
546548
547549
548550
}
//Azi:autoresolution end
if (useGUI)
if (useGUI && initGUI())
{
/* XXX AsereBLN handle error */
initGUI();
// initGUI() returned with an error, disabling GUI.
useGUI = false;
}
setBootGlobals(bvChain);
firstRun = false;
if ( status == -1 ) continue;
//Azi:sysversion related test
//Azi:sysversion related test
if( bootArgs->Video.v_display == GRAPHICS_MODE )
{
drawBackground(); //Azi: just seems repeated and less complete than the next!? though to the eye,
updateVRAM();//the next seems to do exactly the same??! testing
gui.devicelist.draw = false; // Needed for when the verbose flips the screen.
drawBackground();
updateVRAM();
}
// Turn off any GUI elements
/*if ( bootArgs->Video.v_display == GRAPHICS_MODE )
{
gui.devicelist.draw = false; // doesn't seem needed
gui.bootprompt.draw = false; // same as above
gui.devicelist.draw = false;
gui.bootprompt.draw = false; // doesn't seem needed
gui.menu.draw = false; // same as above
gui.infobox.draw = false; // Enter doesn't work with this drawn so...
drawBackground();
// Can't be called only from here! Need advice. Check above.
//loadOverrideConfig(&bootInfo->overrideConfig); // call 2
// If cpu does not understand 64 bit instructions,...
if ( !platformCPUFeature(CPU_FEATURE_EM64T) ||
// ... user forced i386 kernel architecture on cpu with em64t...
//Azi: default to x86_64 arch
// If cpu doesn't handle 64 bit instructions,...
if (!platformCPUFeature(CPU_FEATURE_EM64T) ||
// ... user forced i386 kernel architecture on cpu with "em64t"...
getValueForKey(kArchI386Flag, &val, &len, &bootInfo->bootConfig) ||
// ... or forced Legacy Mode... (not needed!)
getValueForKey(kLegacyModeFlag, &val, &len, &bootInfo->bootConfig) )
// ... or forced Legacy Mode... (not needed! but handy for some processors/situations)
getValueForKey(kLegacyModeFlag, &val, &len, &bootInfo->bootConfig))
{
// ... use i386 kernel arch!
// ... use i386 kernel arch.
archCpuType = CPU_TYPE_I386;
}
else
{
// Else use x86_64 kernel arch!
// Else use x86_64 kernel arch.
archCpuType = CPU_TYPE_X86_64;
}
// Force x86_64 kernel arch if i386/-legacy are flagged on Boot.plist.
// Override i386/-legacy, if flagged on Boot.plist.
if (getValueForKey(kArchX86_64Flag, &val, &len, &bootInfo->bootConfig))
{
archCpuType = CPU_TYPE_X86_64;
branches/azimutz/Chazileon/i386/boot2/boot.h
116116
117117
118118
119
119
120120
121121
122122
......
137137
138138
139139
140
140
141141
142142
143143
// Common: firstrun or secondrun
#define kWaitForKeypressKey"Wait"// * boot.c, getBollFKturn this into flag?
#define kTestConfigFileKey"config"// # stringTable.c, getValFK
#define kTestConfigKey"config"// # stringTable.c, getValFK
#define kKernelNameKey"Kernel"// * options.c, getValFK,override default name; at boot prompt typing the name is enough.
#define kKernelCacheKey"Kernel Cache"// boot.c, getValFKtest this
#define kKernelFlagsKey"Kernel Flags"// * options.c, getValFK
#define kWakeKey"Wake"// * boot.c, getBollFKfirstrun?
#define kForceWakeKey"ForceWake"// * boot.c, getBollFKfirstrun?
#define kWakeImageKey"WakeImage"// * boot.c, getValFKfirstrun?
#define kPciRootKey"PciRoot"// * pci_root.c, getValFK,
#define kPCIRootUIDKey"PciRoot"// * pci_root.c, getValFK,
#define kUseAtiROMKey"UseAtiROM"// # ati.c, getBollFKfirstrun?
#define kUseNvidiaROMKey"UseNvidiaROM"// # nvidia.c, getBollFKfirstrun?
#define kVBIOSKey"VBIOS"// nvidia.c, getBollFKfirstrun?
branches/azimutz/Chazileon/i386/boot2/drivers.c
186186
187187
188188
189
189
190190
191191
192192
else if ( gBootFileType == kBlockDeviceType )
{
// Take in account user overriding.
if (getValueForKey( kExtensionsKey, &override_pathfolder, &len, &bootInfo->bootConfig ))
if (getValueForKey(kExtensionsKey, &override_pathfolder, &len, &bootInfo->bootConfig))
{
// Specify a path to a folder ending with /, e.g. /Extra/testkext/
strcpy(dirSpecExtra, override_pathfolder);

Archive Download the corresponding diff file

Revision: 353