Chameleon

Chameleon Commit Details

Date:2014-01-11 22:51:20 (10 years 2 months ago)
Author:Chuck Fry
Commit:2337
Parents: 2336
Message:Merged against trunk r2334
Changes:
M/branches/chucko
M/branches/chucko/i386/libsa/efi_tables.c
M/branches/chucko/i386/libsa/libsa.h
M/branches/chucko/i386/libsaio/nvidia_helper.c
M/branches/chucko/i386/libsaio/dram_controllers.c
M/branches/chucko/i386/libsaio/nvidia.c
M/branches/chucko/i386/libsaio/ntfs.c
M/branches/chucko/i386/libsa/printf.c
M/branches/chucko/i386/libsaio/ext2fs.c
M/branches/chucko/i386/boot2/modules.c
M/branches/chucko/i386/libsaio/bootstruct.h
M/branches/chucko/i386/libsa/string.c
M/branches/chucko/i386/libsaio/load.c
M/branches/chucko/i386/libsaio/freebsd.h
M/branches/chucko/i386/libsaio/aml_generator.c
M/branches/chucko/i386/libsaio/nvidia.h
M/branches/chucko/i386/libsaio/convert.c
M/branches/chucko/i386/boot2/modules.h
M/branches/chucko/i386/libsaio/pci.h
M/branches/chucko/i386/libsaio/acpi_patcher.c
M/branches/chucko/i386/libsaio/sl.h
M/branches/chucko/i386/libsaio/msdos.c
M/branches/chucko/i386/libsaio/platform.h
M/branches/chucko/i386/libsaio/disk.c
M/branches/chucko/i386/libsaio/device_inject.c
M/branches/chucko/i386/libsaio/smbios.c
M/branches/chucko/i386/libsaio/device_inject.h
M/branches/chucko/i386/boot2/picopng.c
M/branches/chucko/doc/BootHelp.txt
M/branches/chucko/CHANGES
M/branches/chucko/i386/libsaio/ati.c
M/branches/chucko/i386/libsaio/device_tree.c
M/branches/chucko/i386/libsaio/pci_root.c
M/branches/chucko/i386/libsaio/sys.c
M/branches/chucko/i386/libsaio/hfs.c
M/branches/chucko/i386/libsaio/vbe.h
M/branches/chucko/i386/libsa/memory.h
M/branches/chucko/i386/libsaio/spd.c
M/branches/chucko/i386/libsaio/hfs_compare.c
M/branches/chucko/i386/libsaio/cpu.c
M/branches/chucko/i386/libsaio/md5c.c
M/branches/chucko/i386/libsaio/smbios_getters.c
M/branches/chucko/i386/libsaio/openbsd.c
M/branches/chucko/i386/libsa/zalloc.c
M/branches/chucko/i386/libsaio/smbios_decode.c
M/branches/chucko/i386/libsaio/openbsd.h
M/branches/chucko/i386/libsa/prf.c

File differences

branches/chucko/i386/libsaio/ext2fs.c
2222
2323
2424
25
25
2626
27
2728
2829
29
30
30
3131
3232
3333
34
35
34
3635
3736
3837
......
4443
4544
4645
47
46
4847
48
4949
5050
51
52
51
5352
5453
5554
56
57
55
5856
5957
6058
{
char * buf=malloc (EX2ProbeSize);
str[0]=0;
if (!buf)
if (!buf) {
return;
}
Seek(ih, 0);
Read(ih, (long)buf, EX2ProbeSize);
if (!EX2Probe (buf))
{
if (!EX2Probe (buf)) {
free (buf);
return;
}
if (OSReadLittleInt32 (buf+0x44c,0)<1)
{
if (OSReadLittleInt32 (buf+0x44c,0)<1) {
free (buf);
return;
}
long EX2GetUUID(CICell ih, char *uuidStr)
{
uint8_t *b, *buf=malloc (EX2ProbeSize);
if (!buf)
if (!buf) {
return -1;
}
Seek(ih, 0);
Read(ih, (long)buf, EX2ProbeSize);
if (!EX2Probe (buf))
{
if (!EX2Probe (buf)) {
free (buf);
return -1;
}
if (OSReadLittleInt32 (buf+0x44c,0)<1)
{
if (OSReadLittleInt32 (buf+0x44c,0)<1) {
free (buf);
return -1;
}
branches/chucko/i386/libsaio/bootstruct.h
3030
3131
3232
33
34
33
34
3535
3636
3737
......
5757
5858
5959
60
61
62
63
64
65
66
67
68
69
70
71
72
73
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
7475
7576
7677
#include "bios.h"
#include "device_tree.h"
/*!
Kernel boot args global also used by booter for its own data.
/*
* Kernel boot args global also used by booter for its own data.
*/
extern boot_args *bootArgs;
extern boot_args_pre_lion *bootArgsPreLion;
* PCI bus information.
*/
typedef struct _PCI_bus_info_t {
union {
struct {
unsigned char configMethod1 :1;
unsigned char configMethod2 :1;
unsigned char :2;
unsigned char specialCycle1 :1;
unsigned char specialCycle2 :1;
} s;
unsigned char d;
} u_bus;
unsigned char maxBusNum;
unsigned char majorVersion;
unsigned char minorVersion;
unsigned char BIOSPresent;
union {
struct {
unsigned char configMethod1 :1;
unsigned char configMethod2 :1;
unsigned char :2;
unsigned char specialCycle1 :1;
unsigned char specialCycle2 :1;
} s;
unsigned char d;
} u_bus;
unsigned char maxBusNum;
unsigned char majorVersion;
unsigned char minorVersion;
unsigned char BIOSPresent;
} PCI_bus_info_t;
typedef struct {
branches/chucko/i386/libsaio/device_tree.c
218218
219219
220220
221
222
221
222
223223
224224
225225
void
DT__FreeNode(Node *node)
{
node->next = freeNodes;
freeNodes = node;
node->next = freeNodes;
freeNodes = node;
}
//==============================================================================
branches/chucko/i386/libsaio/hfs.c
294294
295295
296296
297
298
299
297
298
299
300300
301301
302302
long HFSReadFile(CICell ih, char * filePath, void *base, uint64_t offset, uint64_t length)
{
char entry[512];
char devStr[12];
long dirID, result, flags;
char entry[512];
char devStr[12];
long dirID, result, flags;
if (HFSInitPartition(ih) == -1)
{
branches/chucko/i386/libsaio/vbe.h
5757
5858
5959
60
61
62
63
64
65
66
67
68
69
70
71
60
61
62
63
64
65
66
67
68
69
70
71
7272
7373
7474
* Functions
*/
enum {
funcGetControllerInfo = 0x4F00,
funcGetModeInfo = 0x4F01,
funcSetMode = 0x4F02,
funcGetCurrentMode = 0x4F03,
funcSaveRestoreState = 0x4F04,
funcWindowControl = 0x4F05,
funcGetSetScanLineLength = 0x4F06,
funcGetSetDisplayStart = 0x4F07,
funcGetSetPaletteFormat = 0x4F08,
funcGetSetPaletteData = 0x4F09,
funcGetProtModeInterdace = 0x4F0A,
funcGetSetPixelClock = 0x4F0B
funcGetControllerInfo= 0x4F00,
funcGetModeInfo= 0x4F01,
funcSetMode= 0x4F02,
funcGetCurrentMode= 0x4F03,
funcSaveRestoreState= 0x4F04,
funcWindowControl= 0x4F05,
funcGetSetScanLineLength= 0x4F06,
funcGetSetDisplayStart= 0x4F07,
funcGetSetPaletteFormat= 0x4F08,
funcGetSetPaletteData= 0x4F09,
funcGetProtModeInterdace= 0x4F0A,
funcGetSetPixelClock= 0x4F0B
};
enum {
branches/chucko/i386/libsaio/acpi_patcher.c
512512
513513
514514
515
516
515
517516
518517
519
520
521
518
522519
523520
524521
525522
526
523
527524
525
528526
529527
530528
531529
532530
533531
534
535
532
536533
537534
538535
539536
540537
541
542
543
538
539
544540
545
546
547
541
542
548543
549544
550545
551
546
552547
548
553549
554550
555551
......
592588
593589
594590
595
596
597
591
598592
599593
600594
......
603597
604598
605599
606
607
600
608601
609602
610
611
612
603
613604
614605
615606
616
617
607
618608
619609
620610
621611
622612
623613
624
614
625615
626616
627617
......
632622
633623
634624
635
636
625
637626
638627
639628
......
643632
644633
645634
646
647
635
648636
649637
650638
......
656644
657645
658646
659
660
647
661648
662649
663650
......
683670
684671
685672
686
687
688
673
689674
690675
691676
......
703688
704689
705690
706
707
691
708692
709693
710
711
694
712695
713
714
715
696
716697
717698
718
719
720
699
721700
722701
723702
724703
725
726
704
727705
728706
729707
......
734712
735713
736714
737
738
739
715
740716
741717
742718
743719
744720
745721
746
747
748
749
722
723
750724
751
752
753
725
754726
755727
756728
757
758
759
729
760730
761731
762732
763733
764
765
766
767
734
735
768736
769737
770738
771
772
773
739
774740
775741
776742
......
780746
781747
782748
783
784
785
786
749
750
787751
788752
789753
......
792756
793757
794758
795
796
797
759
798760
799761
800762
......
808770
809771
810772
811
812
773
813774
814775
815776
816
817
777
818778
819779
820780
......
858818
859819
860820
861
862
821
863822
864
865
866
823
867824
868825
869826
......
893850
894851
895852
896
897
853
898854
899855
900856
901857
902
903
858
904859
905
906
907
860
908861
909862
910863
......
918871
919872
920873
921
922
874
923875
924
925
876
926877
927
928
929
878
930879
931880
932881
......
947896
948897
949898
950
951
899
952900
953901
954902
......
959907
960908
961909
962
963
910
964911
965
966
912
967913
968914
969915
......
971917
972918
973919
974
975
920
976921
977922
978923
979924
980
981
925
982926
983927
984
985
928
986929
987930
988931
989932
990933
991934
992
993
935
994936
995937
996938
997939
998940
999
1000
941
1001942
1002943
1003944
......
1006947
1007948
1008949
1009
1010
950
1011951
1012952
1013953
1014954
1015955
1016956
1017
1018
957
1019958
1020959
1021960
......
1036975
1037976
1038977
1039
1040
978
1041979
1042980
1043
981
1044982
983
1045984
1046985
1047986
......
1054993
1055994
1056995
1057
1058
1059
996
1060997
1061998
1062999
10631000
1064
1065
1001
10661002
10671003
10681004
......
10701006
10711007
10721008
1073
1074
1009
10751010
10761011
10771012
......
10831018
10841019
10851020
1086
1087
1021
10881022
1089
1090
1023
10911024
10921025
10931026
10941027
1095
1096
1028
10971029
10981030
10991031
11001032
1101
1102
1033
11031034
11041035
1105
1106
1036
11071037
11081038
11091039
......
11111041
11121042
11131043
1114
1115
1044
11161045
11171046
11181047
11191048
11201049
11211050
1122
1123
1051
11241052
11251053
11261054
......
11311059
11321060
11331061
1134
1135
1062
11361063
11371064
11381065
11391066
11401067
1141
1142
1068
11431069
11441070
11451071
......
11611087
11621088
11631089
1164
1165
1090
11661091
11671092
1168
1093
11691094
1095
11701096
11711097
1172
11731098
11741099
11751100
11761101
11771102
1178
1179
1180
1103
11811104
11821105
11831106
......
12001123
12011124
12021125
1203
1204
1126
12051127
12061128
12071129
12081130
12091131
12101132
1211
12121133
12131134
12141135
1215
1216
1136
12171137
12181138
12191139
1220
1221
1222
1140
12231141
12241142
12251143
minimum.CID = ((minimum.FID & 0x1F) << 1) >> cpu_dynamic_fsb;
// Sanity check
if (maximum.CID < minimum.CID)
{
if (maximum.CID < minimum.CID) {
DBG("P-States: Insane FID values!");
p_states_count = 0;
}
else
{
} else {
// Finalize P-States
// Find how many P-States machine supports
p_states_count = maximum.CID - minimum.CID + 1;
if (p_states_count > 32)
if (p_states_count > 32) {
p_states_count = 32;
}
uint8_t vidstep;
uint8_t i = 0, u, invalid = 0;
vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1);
for (u = 0; u < p_states_count; u++)
{
for (u = 0; u < p_states_count; u++) {
i = u - invalid;
p_states[i].CID = maximum.CID - u;
p_states[i].FID = (p_states[i].CID >> 1);
if (p_states[i].FID < 0x6)
{
if (cpu_dynamic_fsb)
if (p_states[i].FID < 0x6) {
if (cpu_dynamic_fsb) {
p_states[i].FID = (p_states[i].FID << 1) | 0x80;
}
else if (cpu_noninteger_bus_ratio)
{
}
} else if (cpu_noninteger_bus_ratio) {
p_states[i].FID = p_states[i].FID | (0x40 * (p_states[i].CID & 0x1));
}
if (i && p_states[i].FID == p_states[i-1].FID)
if (i && p_states[i].FID == p_states[i-1].FID) {
invalid++;
}
p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2;
(Platform.CPU.Model == CPU_MODEL_HASWELL_ULT) || (Platform.CPU.Model == CPU_MODEL_CRYSTALWELL))
{
maximum.Control = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0xff;
}
else
{
} else {
maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff;
}
verbose("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control);
// Sanity check
if (maximum.Control < minimum.Control)
{
if (maximum.Control < minimum.Control) {
DBG("Insane control values!");
p_states_count = 0;
}
else
{
} else {
uint8_t i;
p_states_count = 0;
for (i = maximum.Control; i >= minimum.Control; i--)
{
for (i = maximum.Control; i >= minimum.Control; i--) {
p_states[p_states_count].Control = i;
p_states[p_states_count].CID = p_states[p_states_count].Control << 1;
p_states[p_states_count].Frequency = (Platform.CPU.FSBFrequency / 1000000) * i;
p_states_count++;
}
}
break;
}
default:
}
// Generating SSDT
if (p_states_count > 0)
{
if (p_states_count > 0) {
int i;
AML_CHUNK* root = aml_create_node(NULL);
AML_CHUNK* name = aml_add_name(scop, "PSS_");
AML_CHUNK* pack = aml_add_package(name);
for (i = 0; i < p_states_count; i++)
{
for (i = 0; i < p_states_count; i++) {
AML_CHUNK* pstt = aml_add_package(pack);
aml_add_dword(pstt, p_states[i].Frequency);
}
// Add aliaces
for (i = 0; i < acpi_cpu_count; i++)
{
for (i = 0; i < acpi_cpu_count; i++) {
char name[9];
sprintf(name, "_PR_%c%c%c%c", acpi_cpu_name[i][0], acpi_cpu_name[i][1], acpi_cpu_name[i][2], acpi_cpu_name[i][3]);
return ssdt;
}
}
else
{
} else {
verbose ("ACPI CPUs not found: P-States not generated !!!\n");
}
const char * value;
// Restart Fix
if (Platform.CPU.Vendor == 0x756E6547)
{/* Intel */
if (Platform.CPU.Vendor == 0x756E6547) { /* Intel */
fix_restart = true;
fix_restart_ps2 = false;
if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2)
{
if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2) {
fix_restart = true;
}
else
{
} else {
getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig);
}
}
else
{
} else {
verbose ("Not an Intel platform: Restart Fix not applied !!!\n");
fix_restart = false;
}
if (fix_restart)
{
if (fix_restart) {
fadt_rev2_needed = true;
}
memcpy(fadt_mod, fadt, fadt->Length);
fadt_mod->Length = 0x84;
fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)
}
else
{
} else {
fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
memcpy(fadt_mod, fadt, fadt->Length);
}
// Determine system type / PM_Model
if ( (value=getStringForKey(kSystemType, &bootInfo->chameleonConfig))!=NULL)
{
if (Platform.Type > 6)
{
if(fadt_mod->PM_Profile<=6)
{
if (Platform.Type > 6) {
if(fadt_mod->PM_Profile<=6) {
Platform.Type = fadt_mod->PM_Profile; // get the fadt if correct
}
else
{
} else {
Platform.Type = 1;/* Set a fixed value (Desktop) */
}
verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);
}
else
{
} else {
Platform.Type = (unsigned char) strtoul(value, NULL, 10);
}
}
// Set PM_Profile from System-type if only user wanted this value to be forced
if (fadt_mod->PM_Profile != Platform.Type)
{
if (value)
{
if (fadt_mod->PM_Profile != Platform.Type) {
if (value) {
// user has overriden the SystemType so take care of it in FACP
verbose("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform.Type);
fadt_mod->PM_Profile = Platform.Type;
}
else
{
} else {
// PM_Profile has a different value and no override has been set, so reflect the user value to ioregs
Platform.Type = fadt_mod->PM_Profile <= 6 ? fadt_mod->PM_Profile : 1;
}
setupSystemType();
// Patch FADT to fix restart
if (fix_restart)
{
if (fix_restart_ps2)
{
if (fix_restart) {
if (fix_restart_ps2) {
fadt_mod->Flags|= 0x400;
fadt_mod->Reset_SpaceID= 0x01; // System I/O
fadt_mod->Reset_BitWidth= 0x08; // 1 byte
fadt_mod->Reset_Address= 0x64; // Address of the register
fadt_mod->Reset_Value= 0xfe; // Value to write to reset the system
msglog("FADT: PS2 Restart Fix applied!\n");
}
else
{
} else {
fadt_mod->Flags|= 0x400;
fadt_mod->Reset_SpaceID= 0x01; // System I/O
fadt_mod->Reset_BitWidth= 0x08; // 1 byte
}
// Patch DSDT Address if we have loaded DSDT.aml
if(new_dsdt)
{
if(new_dsdt) {
DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);
fadt_mod->DSDT=(uint32_t)new_dsdt;
if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)
{
if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length) {
fadt_mod->X_DSDT=(uint32_t)new_dsdt;
}
acpi_cpu_count = 0;
/* Try using the file specified with the DSDT option */
if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "DSDT.aml");
//verbose("dirSpec, DSDT.aml");
}
{
int i;
for (i = 0; i < 30; i++)
{
for (i = 0; i < 30; i++) {
char filename[512];
sprintf(filename, i > 0?"SSDT-%d.aml":"SSDT.aml", i);
if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) )
{
if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) ) {
ssdt_count++;
}
else
{
} else {
break;
}
}
// Find original rsdp
rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable());
if (!rsdp)
{
if (!rsdp) {
DBG("No ACPI version %d found. Ignoring\n", version+1);
if (version)
{
if (version) {
addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");
}
else
{
} else {
addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");
}
continue;
DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);
if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)
{
if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000) {
uint32_t *rsdt_entries;
int rsdt_entries_num;
int dropoffset=0, i;
rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;
rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;
rsdt_entries=(uint32_t *)(rsdt_mod+1);
for (i=0;i<rsdt_entries_num;i++)
{
for (i=0;i<rsdt_entries_num;i++) {
char *table=(char *)(rsdt_entries[i]);
if (!table)
{
if (!table) {
continue;
}
rsdt_entries[i-dropoffset]=rsdt_entries[i];
if (drop_ssdt && tableSign(table, "SSDT"))
{
if (drop_ssdt && tableSign(table, "SSDT")) {
verbose("OEM SSDT tables was dropped\n");
dropoffset++;
continue;
}
if (tableSign(table, "DSDT"))
{
if (tableSign(table, "DSDT")) {
DBG("DSDT found\n");
verbose("Custom DSDT table was found\n");
if(new_dsdt)
{
if(new_dsdt) {
rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
}
continue;
}
if (tableSign(table, "FACP"))
{
if (tableSign(table, "FACP")) {
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)rsdt_entries[i];
DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);
if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)
{
if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000) {
printf("FADT incorrect. Not modified\n");
continue;
}
rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;
// Generate _CST SSDT
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
{
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) {
DBG("C-States generated\n");
generate_cstates = false; // Generate SSDT only once!
ssdt_count++;
}
// Generating _PSS SSDT
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
{
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) {
DBG("P-States generated\n");
generate_pstates = false; // Generate SSDT only once!
ssdt_count++;
rsdt_entries=(uint32_t *)(rsdt_mod+1);
// Mozodojo: Insert additional SSDTs into RSDT
if(ssdt_count>0)
{
if(ssdt_count>0) {
int j;
for (j=0; j<ssdt_count; j++)
for (j=0; j<ssdt_count; j++) {
rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
}
verbose("RSDT: Added %d SSDT table(s)\n", ssdt_count);
rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);
DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);
}
else
{
} else {
rsdp_mod->RsdtAddress=0;
printf("RSDT not found or incorrect\n");
}
if (version)
{
if (version) {
struct acpi_2_xsdt *xsdt, *xsdt_mod;
// FIXME: handle 64-bit address correctly
xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);
DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress, xsdt->Length);
if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)
{
if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000) {
uint64_t *xsdt_entries;
int xsdt_entries_num, i;
int dropoffset=0;
rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;
xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;
xsdt_entries=(uint64_t *)(xsdt_mod+1);
for (i=0;i<xsdt_entries_num;i++)
{
for (i=0;i<xsdt_entries_num;i++) {
char *table=(char *)((uint32_t)(xsdt_entries[i]));
if (!table)
{
if (!table) {
continue;
}
xsdt_entries[i-dropoffset]=xsdt_entries[i];
if (drop_ssdt && tableSign(table, "SSDT"))
{
if (drop_ssdt && tableSign(table, "SSDT")) {
verbose("OEM SSDT tables was dropped\n");
dropoffset++;
continue;
}
if (tableSign(table, "DSDT"))
{
if (tableSign(table, "DSDT")) {
DBG("DSDT found\n");
if (new_dsdt)
{
if (new_dsdt) {
xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
}
continue;
}
if (tableSign(table, "FACP"))
{
if (tableSign(table, "FACP")) {
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];
DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt,
fadt->Length);
if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)
{
if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000) {
verbose("FADT incorrect or after 4GB. Dropping XSDT\n");
goto drop_xsdt;
}
DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);
// Generate _CST SSDT
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
{
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) {
generate_cstates = false; // Generate SSDT only once!
ssdt_count++;
}
// Generating _PSS SSDT
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
{
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) {
generate_pstates = false; // Generate SSDT only once!
ssdt_count++;
}
xsdt_entries=(uint64_t *)(xsdt_mod+1);
// Mozodojo: Insert additional SSDTs into XSDT
if(ssdt_count > 0)
{
if(ssdt_count > 0) {
int j;
for (j=0; j<ssdt_count; j++)
for (j=0; j<ssdt_count; j++) {
xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
}
verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);
}
// Correct the checksum of XSDT
xsdt_mod->Checksum=0;
xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);
}
else
{
} else {
drop_xsdt:
DBG("About to drop XSDT\n");
DBG("New checksum %d\n", rsdp_mod->Checksum);
if (version)
{
if (version) {
DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);
rsdp_mod->ExtendedChecksum=0;
rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);
DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);
}
//verbose("Patched ACPI version %d DSDT\n", version+1);
if (version)
{
if (version) {
/* XXX aserebln why uint32 cast if pointer is uint64 ? */
acpi20_p = (uint32_t)rsdp_mod;
addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
}
else
{
} else {
/* XXX aserebln why uint32 cast if pointer is uint64 ? */
acpi10_p = (uint32_t)rsdp_mod;
addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
branches/chucko/i386/libsaio/hfs_compare.c
123123
124124
125125
126
126
127127
128128
129129
130130
131131
132132
133
133
134134
135135
136136
if (aSortWord < bSortWord)
return -1;
}
/*
* If characters match exactly, then go on to next character
* immediately without doing any extra work.
*/
}
/* if you got to here, then return bestGuess */
/* If you got to here, then return bestGuess */
return bestGuess;
}
branches/chucko/i386/libsaio/spd.c
3030
3131
3232
33
33
3434
35
35
3636
3737
3838
39
40
39
40
4141
4242
4343
......
6969
7070
7171
72
73
74
75
76
77
78
79
80
81
82
83
84
8572
8673
8774
......
124111
125112
126113
114
115
116
117
118
119
120
121
122
123
124
125
127126
128127
129128
......
147146
148147
149148
150
151
152
153
149
150
154151
155152
156153
157
158
159
160
161
162
163
154
155
156
164157
165158
166159
167160
168161
169
170
171
162
172163
173164
174165
175
176
177
178
166
167
179168
180169
181170
182171
183172
184
185
173
186174
187175
188176
......
191179
192180
193181
194
195
196
197
182
183
198184
199185
200186
......
205191
206192
207193
208
209
210
211
212
194
195
213196
214197
215198
......
233216
234217
235218
236
219
237220
238221
239
222
240223
241224
242225
243
226
244227
245228
246229
......
254237
255238
256239
257
258
240
259241
260
261
262
242
263243
264244
265245
266246
267247
268248
269
270
249
271250
272251
273
274
252
275253
276254
277
278
279
255
280256
281257
282258
283
259
284260
285261
286262
......
288264
289265
290266
291
292
293
294
267
268
269
295270
296271
297272
......
313288
314289
315290
316
317
318
291
319292
320293
321
294
322295
323
324
296
325297
326298
327
328299
329300
330301
......
334305
335306
336307
337
338
308
339309
340
310
341311
342312
343313
......
346316
347317
348318
349
350
319
320
351321
352322
353323
......
361331
362332
363333
364
365
334
366335
367336
368337
......
371340
372341
373342
374
375
343
376344
377345
378
346
379347
380
381
348
382349
383350
384351
385
386
352
387353
388354
389355
......
394360
395361
396362
397
363
398364
399365
400366
......
407373
408374
409375
410
376
411377
412378
413379
......
415381
416382
417383
418
419384
420385
421386
......
452417
453418
454419
455
456
420
457421
458422
459423
460424
461425
462426
463
464
465
466
427
428
467429
468430
469431
"RAM", /* 00h Undefined */
"FPM", /* 01h FPM */
"EDO", /* 02h EDO */
"",/* 03h PIPELINE NIBBLE */
"",/* 03h PIPELINE NIBBLE */
"SDRAM", /* 04h SDRAM */
"",/* 05h MULTIPLEXED ROM */
"",/* 05h MULTIPLEXED ROM */
"DDR SGRAM",/* 06h SGRAM DDR */
"DDR SDRAM",/* 07h SDRAM DDR */
"DDR2 SDRAM", /* 08h SDRAM DDR 2 */
"",/* 09h Undefined */
"",/* 0Ah Undefined */
"",/* 09h Undefined */
"",/* 0Ah Undefined */
"DDR3 SDRAM"/* 0Bh SDRAM DDR 3 */
};
#define SMBHSTDAT 5
#define SBMBLKDAT 7
int spd_indexes[] = {
SPD_MEMORY_TYPE,
SPD_DDR3_MEMORY_BANK,
SPD_DDR3_MEMORY_CODE,
SPD_NUM_ROWS,
SPD_NUM_COLUMNS,
SPD_NUM_DIMM_BANKS,
SPD_NUM_BANKS_PER_SDRAM,
4,7,8,9,12,64, /* TODO: give names to these values */
95,96,97,98, 122,123,124,125 /* UIS */
};
#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int))
/** Read one byte from the intel i2c, used for reading SPD on intel chipsets only. */
unsigned char smb_read_byte_intel(uint32_t base, uint8_t adr, uint8_t cmd)
/* SPD i2c read optimization: prefetch only what we need, read non prefetcheable bytes on the fly */
#define READ_SPD(spd, base, slot, x) spd[x] = smb_read_byte_intel(base, 0x50 + slot, x)
int spd_indexes[] = {
SPD_MEMORY_TYPE,
SPD_DDR3_MEMORY_BANK,
SPD_DDR3_MEMORY_CODE,
SPD_NUM_ROWS,
SPD_NUM_COLUMNS,
SPD_NUM_DIMM_BANKS,
SPD_NUM_BANKS_PER_SDRAM,
4,7,8,9,12,64, /* TODO: give names to these values */
95,96,97,98, 122,123,124,125 /* UIS */
};
#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int))
/** Read from spd *used* values only*/
static void init_spd(char * spd, uint32_t base, int slot)
{ // DDR3
bank = (spd[SPD_DDR3_MEMORY_BANK] & 0x07f); // constructors like Patriot use b7=1
code = spd[SPD_DDR3_MEMORY_CODE];
for (i=0; i < VEN_MAP_SIZE; i++)
{
if (bank==vendorMap[i].bank && code==vendorMap[i].code)
{
for (i=0; i < VEN_MAP_SIZE; i++) {
if (bank==vendorMap[i].bank && code==vendorMap[i].code) {
return vendorMap[i].name;
}
}
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR)
{
if(spd[64]==0x7f)
{
for (i=64; i<72 && spd[i]==0x7f;i++)
{
} else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) {
if(spd[64]==0x7f) {
for (i=64; i<72 && spd[i]==0x7f;i++) {
bank++;
READ_SPD(spd, base, slot_num, (uint8_t)(i+1)); // prefetch next spd byte to read for next loop
}
READ_SPD(spd, base, slot_num,(uint8_t)i);
code = spd[i];
}
else
{
} else {
code = spd[64];
bank = 0;
}
for (i=0; i < VEN_MAP_SIZE; i++)
{
if (bank==vendorMap[i].bank && code==vendorMap[i].code)
{
for (i=0; i < VEN_MAP_SIZE; i++) {
if (bank==vendorMap[i].bank && code==vendorMap[i].code) {
return vendorMap[i].name;
}
}
}
/* OK there is no vendor id here lets try to match the partnum if it exists */
if (strstr(slot->PartNo,"GU332") == slot->PartNo) // Unifosa fingerprint
{
if (strstr(slot->PartNo,"GU332") == slot->PartNo) { // Unifosa fingerprint
return "Unifosa";
}
return "NoName";
/* Get Default Memory Module Speed (no overclocking handled) */
int getDDRspeedMhz(const char * spd)
{
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3)
{
switch(spd[12])
{
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) {
switch(spd[12]) {
case 0x0f:
return 1066;
case 0x0c:
default:
return 800;
}
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR)
{
switch(spd[9])
{
} else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) {
switch(spd[9]) {
case 0x50:
return 400;
case 0x3d:
const char *getDDRSerial(const char* spd)
{
static char asciiSerial[16];
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) // DDR3
{
sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125));
snprintf(asciiSerial, sizeof(asciiSerial), "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125));
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) // DDR2 or DDR
{
sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98));
snprintf(asciiSerial, sizeof(asciiSerial), "%X%X%X%X%X%X%X%X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98));
} else {
sprintf(asciiSerial, "000000000000000");
}
static char asciiPartNo[32];
int i, start=0, index = 0;
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3)
{
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) {
start = 128;
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR)
{
} else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) {
start = 73;
}
// Check that the spd part name is zero terminated and that it is ascii:
bzero(asciiPartNo, sizeof(asciiPartNo));
char c;
for (i=start; i < start + sizeof(asciiPartNo); i++)
{
for (i=start; i < start + sizeof(asciiPartNo); i++) {
READ_SPD(spd, base, slot, i); // only read once the corresponding model part (ddr3 or ddr2)
c = spd[i];
if (isalpha(c) || isdigit(c) || ispunct(c))
{
if (isalpha(c) || isdigit(c) || ispunct(c)) {
// It seems that System Profiler likes only letters and digits...
asciiPartNo[index++] = c;
}
else if (!isascii(c))
{
} else if (!isascii(c)) {
break;
}
}
return strdup(asciiPartNo);
}
/* Read from smbus the SPD content and interpret it for detecting memory attributes */
static void read_smb_intel(pci_dt_t *smbus_dev)
{
uint16_t speed;
uint8_t i, spd_size, spd_type;
static void read_smb_intel(pci_dt_t *smbus_dev) {
int i, speed;
uint8_t spd_size, spd_type;
uint32_t base, mmio, hostc;
//bool dump = false;
RamSlotInfo_t* slot;
char spdbuf[MAX_SPD_SIZE];
// Search MAX_RAM_SLOTS slots
for (i = 0; i < MAX_RAM_SLOTS; i++)
{
// ----
for (i = 0; i < MAX_RAM_SLOTS; i++) {
slot = &Platform.RAM.DIMM[i];
spd_size = smb_read_byte_intel(base, 0x50 + i, 0);
DBG("SPD[0] (size): 0x%02x @0x%x\n", spd_size, 0x50 + i);
DBG("SPD[0] (size): %d @0x%x\n", spd_size, 0x50 + i);
// Check spd is present
if (spd_size && (spd_size != 0xff))
{
if (spd_size && (spd_size != 0xff)) {
slot->spd = spdbuf;
// -----
slot->InUse = true;
bzero(slot->spd, spd_size);
//for (x = 0; x < spd_size; x++) slot->spd[x] = smb_read_byte_intel(base, 0x50 + i, x);
init_spd(slot->spd, base, i);
switch (slot->spd[SPD_MEMORY_TYPE])
{
switch (slot->spd[SPD_MEMORY_TYPE]) {
case SPD_MEMORY_TYPE_SDRAM_DDR:
slot->ModuleSize = (((1 << ((slot->spd[SPD_NUM_ROWS] & 0x0f)
+ (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17)) *
((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) *
case SPD_MEMORY_TYPE_SDRAM_DDR2:
slot->ModuleSize = ((1 << ((slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17)) *
((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * slot->spd[SPD_NUM_BANKS_PER_SDRAM]);
slot->ModuleSize = ((1 << ((slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17)) *
((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * slot->spd[SPD_NUM_BANKS_PER_SDRAM]);
break;
case SPD_MEMORY_TYPE_SDRAM_DDR3:
spd_type = (slot->spd[SPD_MEMORY_TYPE] < ((char) 12) ? slot->spd[SPD_MEMORY_TYPE] : 0);
slot->Type = spd_mem_to_smbios[spd_type];
if (slot->Type == UNKNOWN_MEM_TYPE)
{
if (slot->Type == UNKNOWN_MEM_TYPE) {
continue;
}
slot->PartNo = getDDRPartNum(slot->spd, base, i);
// determine spd speed
speed = getDDRspeedMhz(slot->spd);
if (slot->Frequency<speed)
{
if (slot->Frequency < speed) {
slot->Frequency = speed;
}
// pci memory controller if available, is more reliable
if (Platform.RAM.Frequency > 0)
{
if (Platform.RAM.Frequency > 0) {
uint32_t freq = (uint32_t)Platform.RAM.Frequency / 500000;
// now round off special cases
uint32_t fmod100 = freq %100;
switch(fmod100)
{
switch(fmod100) {
case 1:freq--;break;
case 32:freq++;break;
case 65:freq++; break;
}
verbose("Slot: %d Type %d %dMB (%s) %dMHz Vendor=%s\n PartNo=%s SerialNo=%s\n",
i,
i,
(int)slot->Type,
slot->ModuleSize,
spd_memory_types[spd_type],
// laptops sometimes show slot 0 and 2 with slot 1 empty when only 2 slots are presents so:
Platform.DMI.DIMM[i]=
(uint32_t)((i>0 && Platform.RAM.DIMM[1].InUse==false && !fullBanks && Platform.DMI.CntMemorySlots == 2) ?
(uint32_t)((i>0 && Platform.RAM.DIMM[1].InUse==false && fullBanks && Platform.DMI.CntMemorySlots == 2) ?
mapping[i] : i); // for laptops case, mapping setup would need to be more generic than this
slot->spd = NULL;
}
static struct smbus_controllers_t smbus_controllers[] = {
// Info from here: http://cateee.net/lkddb/web-lkddb/I2C_I801.html
{0x8086, 0x1C22, "6 Series", read_smb_intel },
{0x8086, 0x1D22, "C600/X79 Series", read_smb_intel },
pci_dt_t*current = pci_dt;
int i;
while (current)
{
while (current) {
#if 0
printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n",
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, current->vendor_id, current->device_id,
get_pci_dev_path(current));
#endif
for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ )
{
if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device)
{
for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) {
if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device) {
smbus_controllers[i].read_smb(current); // read smb
return true;
}
branches/chucko/i386/libsaio/pci_root.c
5050
5151
5252
53
53
5454
5555
5656
......
7575
7676
7777
78
7978
8079
8180
void *new_dsdt;
const char *val;
int len,fsize;
const char * dsdt_filename=NULL;
const char * dsdt_filename = NULL;
extern int search_and_get_acpi_fd(const char *, const char **);
if (rootuid < 10) return rootuid;
goto out;
}
// Try using the file specified with the DSDT option
if (getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->chameleonConfig))
{
branches/chucko/i386/libsaio/aml_generator.c
3434
3535
3636
37
37
3838
3939
4040
......
4242
4343
4444
45
45
4646
4747
48
48
4949
5050
5151
5252
5353
5454
55
55
5656
57
57
5858
5959
6060
......
6262
6363
6464
65
65
6666
6767
6868
69
69
7070
7171
7272
......
7474
7575
7676
77
77
7878
7979
8080
......
8686
8787
8888
89
89
9090
9191
9292
9393
9494
9595
96
96
9797
9898
9999
100100
101101
102102
103
103
104104
105105
106106
......
113113
114114
115115
116
116
117117
118118
119119
......
127127
128128
129129
130
130
131131
132132
133133
......
143143
144144
145145
146
146
147147
148148
149149
......
199199
200200
201201
202
202
203203
204204
205205
......
209209
210210
211211
212
212
213213
214214
215215
......
223223
224224
225225
226
226
227227
228228
229229
......
235235
236236
237237
238
238
239239
240240
241241
......
420420
421421
422422
423
423
424424
425425
426426
......
430430
431431
432432
433
433
434434
435435
436436
......
439439
440440
441441
442
442
443443
444444
445445
......
618618
619619
620620
621
621
622622
623623
624624
625625
626626
627
627
628628
629629
630630
......
652652
653653
654654
655
655
656656
657
657
658658
659659
660660
default:
break;
}
if (!parent->First) {
parent->First = node;
}
parent->Last->Next = node;
}
parent->Last = node;
return true;
}
return false;
}
AML_CHUNK* aml_create_node(AML_CHUNK* parent)
{
AML_CHUNK* node = (AML_CHUNK*)malloc(sizeof(AML_CHUNK));
aml_add_to_parent(parent, node);
return node;
}
{
// Delete child nodes
AML_CHUNK* child = node->First;
while (child)
{
AML_CHUNK* next = child->Next;
if (child->Buffer) {
free(child->Buffer);
}
child = next;
}
// Free node
if (node->Buffer) {
free(node->Buffer);
AML_CHUNK* aml_add_buffer(AML_CHUNK* parent, char* buffer, uint32_t size)
{
AML_CHUNK* node = aml_create_node(parent);
if (node) {
node->Type = AML_CHUNK_NONE;
node->Length = (uint16_t)size;
node->Buffer = malloc(node->Length);
memcpy(node->Buffer, buffer, node->Length);
}
return node;
}
AML_CHUNK* aml_add_byte(AML_CHUNK* parent, uint8_t value)
{
AML_CHUNK* node = aml_create_node(parent);
if (node) {
node->Type = AML_CHUNK_BYTE;
node->Length = 1;
AML_CHUNK* aml_add_word(AML_CHUNK* parent, uint16_t value)
{
AML_CHUNK* node = aml_create_node(parent);
if (node) {
node->Type = AML_CHUNK_WORD;
node->Length = 2;
AML_CHUNK* aml_add_dword(AML_CHUNK* parent, uint32_t value)
{
AML_CHUNK* node = aml_create_node(parent);
if (node) {
node->Type = AML_CHUNK_DWORD;
node->Length = 4;
AML_CHUNK* aml_add_qword(AML_CHUNK* parent, uint64_t value)
{
AML_CHUNK* node = aml_create_node(parent);
if (node) {
node->Type = AML_CHUNK_QWORD;
node->Length = 8;
offset += 4 + root;
return (uint32_t)offset;
}
if (count == 2) {
node->Length = 2 + 8;
node->Buffer = malloc(node->Length+4);
offset += 8;
return (uint32_t)offset;
}
node->Length = (uint16_t)(3 + (count << 2));
node->Buffer = malloc(node->Length+4);
node->Buffer[offset++] = 0x5c; // Root Char
AML_CHUNK* aml_add_scope(AML_CHUNK* parent, char* name)
{
AML_CHUNK* node = aml_create_node(parent);
if (node) {
node->Type = AML_CHUNK_SCOPE;
AML_CHUNK* aml_add_name(AML_CHUNK* parent, char* name)
{
AML_CHUNK* node = aml_create_node(parent);
if (node) {
node->Type = AML_CHUNK_NAME;
return 2;
else if (size + 3 <= 0xfffff) /* Encode in 4 bits and 2 bytes */
return 3;
return 4; /* Encode 0xfffffff in 4 bits and 2 bytes */
}
// Calculate child nodes size
AML_CHUNK* child = node->First;
uint8_t child_count = 0;
node->Size = 0;
while (child) {
child_count++;
child = child->Next;
}
switch (node->Type) {
case AML_CHUNK_NONE:
case AML_STORE_OP:
child = child->Next;
}
if (offset - old != node->Size) {
verbose("Node size incorrect: type=0x%x size=%x offset=%x\n",
node->Type, node->Size, (offset - old));
}
}
return offset;
}
uint32_t get_size(uint8_t* Buffer, uint32_t adr)
{
uint32_t temp;
temp = Buffer[adr] & 0xF0; //keep bits 0x30 to check if this is valid size field
if(temp <= 0x30) { // 0
temp = Buffer[adr];
} else if(temp == 0x40){// 4
branches/chucko/i386/libsaio/device_inject.c
2525
2626
2727
28
28
2929
3030
3131
......
6868
6969
7070
71
71
7272
7373
7474
......
8282
8383
8484
85
85
8686
87
88
89
87
88
89
9090
9191
9292
......
9797
9898
9999
100
101
100
102101
103102
104103
105104
106
105
107106
108107
109108
......
184183
185184
186185
187
186
188187
189188
190189
191190
192191
193
192
194193
195194
196195
......
199198
200199
201200
202
203
201
204202
205203
206204
......
211209
212210
213211
214
215
212
216213
217214
218215
......
230227
231228
232229
233
234
230
235231
236232
237
238
239
240
233
234
241235
242236
243237
......
248242
249243
250244
251
252
245
253246
254
255
256
247
257248
258249
259250
......
263254
264255
265256
266
257
267258
268259
269260
......
317308
318309
319310
320
311
321312
322313
323
324
314
325315
326316
327317
......
384374
385375
386376
387
377
388378
389379
390380
......
403393
404394
405395
406
396
407397
408398
409399
uint32_t devices_number = 1;
uint32_t builtin_set = 0;
struct DevPropString *string = 0;
DevPropString *string = 0;
uint8_t *stringdata = 0;
uint32_t stringlength = 0;
}
}
struct DevPropString *devprop_create_string(void)
DevPropString *devprop_create_string(void)
{
string = (struct DevPropString*)malloc(sizeof(struct DevPropString));
return string;
}
struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path)
DevPropDevice *devprop_add_device(DevPropString *string, char *path)
{
struct DevPropDevice*device = NULL;
static const charpciroot_string[] = "PciRoot(0x";
static const charpci_device_string[] = "Pci(0x";
DevPropDevice*device = NULL;
const charpciroot_string[] = "PciRoot(0x";
const charpci_device_string[] = "Pci(0x";
if (string == NULL || path == NULL) {
printf("ERROR null device path\n");
printf("ERROR parsing device path\n");
return NULL;
}
if (!(device = malloc(sizeof(struct DevPropDevice)))) {
if (!(device = malloc(sizeof(DevPropDevice)))) {
printf("ERROR malloc failed\n");
return NULL;
}
memset(device, 0, sizeof(struct DevPropDevice));
memset(device, 0, sizeof(DevPropDevice));
device->acpi_dev_path._UID = getPciRootUID();
int numpaths = 0;
/* FIXME: probably needs bounds checking, as well as error handling in event of malloc failure */
string->length += device->length;
string->entries[string->numentries++] = (struct DevPropDevice*)malloc(sizeof(device));
string->entries[string->numentries++] = (DevPropDevice*)malloc(sizeof(device));
string->entries[string->numentries-1] = device;
return device;
}
int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len)
int devprop_add_value(DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len)
{
if(!nm || !vl || !len) {
uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2);
uint8_t *data = (uint8_t*)malloc(length);
{
if(!data)
{
if(!data) {
return 0;
}
off += 4;
uint32_t i=0, l = strlen(nm);
for(i = 0 ; i < l ; i++, off += 2)
{
for(i = 0 ; i < l ; i++, off += 2) {
data[off] = *nm++;
}
uint32_t offset = device->length - (24 + (6 * device->num_pci_devpaths));
uint8_t *newdata = (uint8_t*)malloc((length + offset));
if(!newdata)
{
if(!newdata) {
return 0;
}
if(device->data)
{
if(offset > 1)
{
if(device->data) {
if(offset > 1) {
memcpy(newdata, device->data, offset);
}
}
device->string->length += length;
device->numentries++;
if(!device->data)
{
if(!device->data) {
device->data = (uint8_t*)malloc(sizeof(uint8_t));
}
else
{
} else {
free(device->data);
}
return 1;
}
char *devprop_generate_string(struct DevPropString *string)
char *devprop_generate_string(DevPropString *string)
{
char *buffer = (char*)malloc(string->length * 2);
char *ptr = buffer;
return ptr;
}
void devprop_free_string(struct DevPropString *string)
void devprop_free_string(DevPropString *string)
{
if(!string)
{
if(!string) {
return;
}
/* a fine place for this code */
int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)
int devprop_add_network_template(DevPropDevice *device, uint16_t vendor_id)
{
if(!device)
return 0;
void set_eth_builtin(pci_dt_t *eth_dev)
{
char *devicepath = get_pci_dev_path(eth_dev);
struct DevPropDevice *device = NULL;
DevPropDevice *device = NULL;
verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);
branches/chucko/i386/libsaio/device_inject.h
5353
5454
5555
56
57
5658
5759
5860
......
6163
6264
6365
64
66
67
68
6569
6670
67
68
71
72
73
6974
70
71
72
75
76
77
7378
74
79
7580
81
7682
// ------------------------
};
typedef struct DevPropDevice DevPropDevice;
struct DevPropString {
uint32_t length;
uint32_t WHAT2;// 0x01000000 ?
struct DevPropDevice **entries;
};
extern struct DevPropString *string;
typedef struct DevPropString DevPropString;
extern DevPropString *string;
extern uint8_t *stringdata;
extern uint32_t stringlength;
struct DevPropString*devprop_create_string(void);
struct DevPropDevice*devprop_add_device(struct DevPropString *string, char *path);
DevPropString*devprop_create_string(void);
DevPropDevice*devprop_add_device(DevPropString *string, char *path);
char*efi_inject_get_devprop_string(uint32_t *len);
intdevprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len);
char*devprop_generate_string(struct DevPropString *string);
voiddevprop_free_string(struct DevPropString *string);
intdevprop_add_value(DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len);
char*devprop_generate_string(DevPropString *string);
voiddevprop_free_string(DevPropString *string);
intdevprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id);
intdevprop_add_network_template(DevPropDevice *device, uint16_t vendor_id);
inthex2bin(const char *hex, uint8_t *bin, int len);
#endif /* !__LIBSAIO_DEVICE_INJECT_H */
branches/chucko/i386/libsaio/dram_controllers.c
4040
4141
4242
43
44
43
4544
4645
4746
......
5756
5857
5958
60
61
59
6260
6361
6462
6563
6664
67
68
65
6966
7067
7168
......
9188
9289
9390
94
95
91
9692
9793
9894
......
104100
105101
106102
107
108
103
109104
110
111
105
112106
113107
114108
......
117111
118112
119113
120
121
114
122115
123116
124117
......
129122
130123
131124
132
133
125
134126
135127
136128
......
140132
141133
142134
143
144
135
145136
146137
147138
......
184175
185176
186177
187
188
178
189179
190180
191181
......
193183
194184
195185
196
197
186
198187
199
200
188
201189
202190
203191
......
205193
206194
207195
208
209
196
210197
211198
212199
......
217204
218205
219206
220
221
207
222208
223209
224210
......
227213
228214
229215
230
231
216
232217
233218
234219
......
569554
570555
571556
572
573
574
575
557
558
576559
577560
578561
// Activate MMR I/O
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
if (!(dev0 & 0x1))
{
if (!(dev0 & 0x1)) {
pci_config_write8(dram_dev->dev.addr, 0x48, (dev0 | 1));
}
}
// Nehalem supports Scrubbing
// First, locate the PCI bus where the MCH is located
for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++)
{
for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) {
vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), PCI_VENDOR_ID);
did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), PCI_DEVICE_ID);
vid &= 0xFFFF;
did &= 0xFF00;
if(vid == 0x8086 && did >= 0x2C00)
{
if(vid == 0x8086 && did >= 0x2C00) {
nhm_bus = possible_nhm_bus[i];
}
}
mch_ratio = 100000;
switch (mch_cfg & 7)
{
switch (mch_cfg & 7) {
case 0: mch_fsb = 1066; break;
case 1: mch_fsb = 533; break;
default:
DBG("mch_fsb %d\n", mch_fsb);
switch (mch_fsb)
{
switch (mch_fsb) {
case 533:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 1:mch_ratio = 200000; break;
case 2:mch_ratio = 250000; break;
case 3:mch_ratio = 300000; break;
default:
case 800:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 0:mch_ratio = 100000; break;
case 1:mch_ratio = 125000; break;
case 2:mch_ratio = 166667; break; // 1.666666667
break;
case 1066:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 1:mch_ratio = 100000; break;
case 2:mch_ratio = 125000; break;
case 3:mch_ratio = 150000; break;
break;
case 1333:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 2:mch_ratio = 100000; break;
case 3:mch_ratio = 120000; break;
case 4:mch_ratio = 160000; break;
mch_ratio = 100000;
switch (mch_cfg & 7)
{
switch (mch_cfg & 7) {
case 1: mch_fsb = 533; break;
default:
case 2:mch_fsb = 800; break;
case 6:mch_fsb = 1066; break;
}
switch (mch_fsb)
{
switch (mch_fsb) {
case 533:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 1:mch_ratio = 125000; break;
case 2:mch_ratio = 150000; break;
case 3:mch_ratio = 200000; break;
break;
case 667:
switch ((mch_cfg >> 4)& 7)
{
switch ((mch_cfg >> 4)& 7) {
case 1:mch_ratio = 100000; break;
case 2:mch_ratio = 120000; break;
case 3:mch_ratio = 160000; break;
default:
case 800:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 1:mch_ratio = 83333; break; // 0.833333333
case 2:mch_ratio = 100000; break;
case 3:mch_ratio = 133333; break; // 1.333333333
}
break;
case 1066:
switch ((mch_cfg >> 4)&7)
{
switch ((mch_cfg >> 4)&7) {
case 5:mch_ratio = 150000; break;
case 6:mch_ratio = 200000; break;
}
void scan_dram_controller(pci_dt_t *dram_dev)
{
int i;
for(i = 1; i < sizeof(dram_controllers) / sizeof(dram_controllers[0]); i++)
{
if ((dram_controllers[i].vendor == dram_dev->vendor_id) && (dram_controllers[i].device == dram_dev->device_id))
{
for(i = 1; i < sizeof(dram_controllers) / sizeof(dram_controllers[0]); i++) {
if ((dram_controllers[i].vendor == dram_dev->vendor_id) && (dram_controllers[i].device == dram_dev->device_id)) {
verbose("%s%s DRAM Controller [%4x:%4x] at %02x:%02x.%x\n",
(dram_dev->vendor_id == 0x8086) ? "Intel Corporation " : "" ,
dram_controllers[i].name, dram_dev->vendor_id, dram_dev->device_id,
branches/chucko/i386/libsaio/nvidia.c
14581458
14591459
14601460
1461
1462
1461
14631462
14641463
1465
1466
1464
14671465
14681466
14691467
14701468
14711469
1472
1473
1474
1470
14751471
14761472
14771473
14781474
1479
1480
1475
14811476
14821477
14831478
1484
1485
1486
1479
14871480
14881481
14891482
14901483
14911484
1492
1493
1485
14941486
14951487
14961488
1497
1498
1499
1489
15001490
15011491
15021492
......
15071497
15081498
15091499
1510
1511
1500
15121501
15131502
15141503
15151504
15161505
1517
1518
1506
15191507
15201508
15211509
15221510
1523
1524
1511
15251512
15261513
1527
1528
1514
15291515
15301516
1531
1532
1517
15331518
15341519
15351520
......
15421527
15431528
15441529
1545
1546
1547
1548
1530
1531
15491532
15501533
15511534
......
15541537
15551538
15561539
1557
1558
1559
1560
1561
1562
1540
1541
1542
15631543
15641544
15651545
15661546
15671547
15681548
1569
1570
1571
1549
15721550
15731551
1574
1575
1576
1577
1578
1579
1552
1553
1554
15801555
15811556
15821557
15831558
15841559
1585
1586
1587
1588
1560
1561
15891562
15901563
15911564
15921565
15931566
1594
1595
1567
15961568
15971569
15981570
15991571
1600
1601
1572
16021573
16031574
16041575
......
16101581
16111582
16121583
1613
1614
1584
16151585
16161586
16171587
16181588
1619
1620
1589
16211590
16221591
16231592
......
16371606
16381607
16391608
1640
1641
1642
1643
1609
1610
16441611
1645
1646
1612
16471613
16481614
16491615
16501616
16511617
16521618
1653
1654
1619
16551620
16561621
16571622
......
16611626
16621627
16631628
1664
1665
1666
1667
1629
1630
16681631
1669
1670
1671
1632
16721633
16731634
16741635
......
16821643
16831644
16841645
1685
1686
1687
1688
1646
1647
16891648
16901649
16911650
16921651
16931652
1694
1695
1696
1697
1653
1654
16981655
16991656
17001657
......
17031660
17041661
17051662
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1663
1664
1665
1666
1667
17161668
17171669
17181670
......
17301682
17311683
17321684
1733
1734
1685
17351686
17361687
17371688
17381689
17391690
1740
1741
1691
17421692
17431693
17441694
......
17661716
17671717
17681718
1769
1770
1719
17711720
17721721
1773
1774
1775
1722
17761723
17771724
17781725
17791726
17801727
17811728
1782
1729
17831730
17841731
17851732
......
18541801
18551802
18561803
1857
1858
1859
1860
1804
1805
18611806
18621807
1863
1864
1865
1808
18661809
18671810
18681811
1869
1870
1871
1812
18721813
18731814
18741815
......
19171858
19181859
19191860
1920
1861
19211862
19221863
19231864
19241865
19251866
19261867
1927
1928
1868
19291869
19301870
1931
1932
1933
1871
19341872
19351873
19361874
19371875
1938
1939
1940
1876
19411877
19421878
19431879
......
19481884
19491885
19501886
1951
1952
1887
19531888
19541889
1955
1956
1957
1890
19581891
19591892
19601893
......
19621895
19631896
19641897
1965
1966
1898
19671899
19681900
1969
1970
1971
1901
19721902
19731903
19741904
19751905
1976
1977
1906
19781907
19791908
1980
1981
1982
1909
19831910
19841911
19851912
19861913
19871914
19881915
1989
1990
1916
19911917
1918
19921919
19931920
19941921
19951922
19961923
19971924
1998
1999
2000
2001
1925
1926
20021927
20031928
20041929
20051930
20061931
20071932
2008
2009
2010
1933
20111934
20121935
20131936
......
20251948
20261949
20271950
2028
2029
1951
20301952
20311953
20321954
......
20451967
20461968
20471969
2048
2049
2050
2051
1970
1971
20521972
20531973
2054
2055
1974
20561975
20571976
2058
2059
1977
20601978
2061
2062
1979
20631980
20641981
20651982
2066
2067
1983
20681984
20691985
20701986
......
20781994
20791995
20801996
2081
1997
20821998
2083
2084
1999
20852000
20862001
2087
2088
2002
20892003
20902004
20912005
20922006
20932007
2094
2095
2008
20962009
20972010
2098
2099
2011
21002012
21012013
21022014
......
21052017
21062018
21072019
2108
2109
2020
21102021
21112022
2112
2113
2023
21142024
21152025
21162026
......
21402050
21412051
21422052
2143
2144
2053
21452054
21462055
21472056
......
21532062
21542063
21552064
2156
2157
2065
21582066
21592067
21602068
......
21632071
21642072
21652073
2166
2167
2074
21682075
21692076
21702077
......
21732080
21742081
21752082
2176
2177
2083
21782084
21792085
21802086
uint8_t numentries = 0;
uint8_t recordlength = 0;
if (dcbtable_version >= 0x20)
{
if (dcbtable_version >= 0x20) {
uint32_t sig;
if (dcbtable_version >= 0x30)
{
if (dcbtable_version >= 0x30) {
headerlength = dcbtable[1];
numentries = dcbtable[2];
recordlength = dcbtable[3];
sig = READ_LE_INT(dcbtable, 6);
}
else
{
} else {
sig = READ_LE_INT(dcbtable, 4);
headerlength = 8;
}
if (sig != 0x4edcbdcb)
{
if (sig != 0x4edcbdcb) {
printf("Bad display config block signature (0x%8x)\n", sig); //Azi: issue #48
return PATCH_ROM_FAILED;
}
}
else if (dcbtable_version >= 0x14) /* some NV15/16, and NV11+ */
{
} else if (dcbtable_version >= 0x14) { /* some NV15/16, and NV11+ */
char sig[8] = { 0 };
strncpy(sig, (char *)&dcbtable[-7], 7);
recordlength = 10;
if (strcmp(sig, "DEV_REC"))
{
if (strcmp(sig, "DEV_REC")) {
printf("Bad Display Configuration Block signature (%s)\n", sig);
return PATCH_ROM_FAILED;
}
}
else
{
} else {
printf("ERROR: dcbtable_version is 0x%X\n", dcbtable_version);
return PATCH_ROM_FAILED;
}
uint8_t num_outputs = 0, i = 0;
struct dcbentry
{
struct dcbentry {
uint8_t type;
uint8_t index;
uint8_t *heads;
} entries[numentries];
for (i = 0; i < numentries; i++)
{
for (i = 0; i < numentries; i++) {
uint32_t connection;
connection = READ_LE_INT(dcbtable,headerlength + recordlength * i);
/* Should we allow discontinuous DCBs? Certainly DCB I2C tables can be discontinuous */
if ((connection & 0x0000000f) == 0x0000000f) /* end of records */
{
if ((connection & 0x0000000f) == 0x0000000f) { /* end of records */
continue;
}
if (connection == 0x00000000) /* seen on an NV11 with DCB v1.5 */
{
if (connection == 0x00000000) { /* seen on an NV11 with DCB v1.5 */
continue;
}
if ((connection & 0xf) == 0x6) /* we skip type 6 as it doesnt appear on macbook nvcaps */
{
if ((connection & 0xf) == 0x6) { /* we skip type 6 as it doesnt appear on macbook nvcaps */
continue;
}
int has_lvds = false;
uint8_t channel1 = 0, channel2 = 0;
for (i = 0; i < num_outputs; i++)
{
if (entries[i].type == 3)
{
for (i = 0; i < num_outputs; i++) {
if (entries[i].type == 3) {
has_lvds = true;
//printf("found LVDS\n");
channel1 |= ( 0x1 << entries[i].index);
}
// if we have a LVDS output, we group the rest to the second channel
if (has_lvds)
{
for (i = 0; i < num_outputs; i++)
{
if (entries[i].type == TYPE_GROUPED)
{
if (has_lvds) {
for (i = 0; i < num_outputs; i++) {
if (entries[i].type == TYPE_GROUPED) {
continue;
}
channel2 |= ( 0x1 << entries[i].index);
entries[i].type = TYPE_GROUPED;
}
}
else
{
} else {
int x;
// we loop twice as we need to generate two channels
for (x = 0; x <= 1; x++)
{
for (i=0; i<num_outputs; i++)
{
if (entries[i].type == TYPE_GROUPED)
{
for (x = 0; x <= 1; x++) {
for (i=0; i<num_outputs; i++) {
if (entries[i].type == TYPE_GROUPED) {
continue;
}
// if type is TMDS, the prior output is ANALOG
// we always group ANALOG and TMDS
// if there is a TV output after TMDS, we group it to that channel as well
if (i && entries[i].type == 0x2)
{
switch (x)
{
if (i && entries[i].type == 0x2) {
switch (x) {
case 0:
//printf("group channel 1\n");
channel1 |= ( 0x1 << entries[i].index);
entries[i].type = TYPE_GROUPED;
if (entries[i-1].type == 0x0)
{
if (entries[i-1].type == 0x0) {
channel1 |= ( 0x1 << entries[i-1].index);
entries[i-1].type = TYPE_GROUPED;
}
// group TV as well if there is one
if ( ((i+1) < num_outputs) && (entries[i+1].type == 0x1) )
{
if ( ((i+1) < num_outputs) && (entries[i+1].type == 0x1) ) {
//printf("group tv1\n");
channel1 |= ( 0x1 << entries[i+1].index);
entries[i+1].type = TYPE_GROUPED;
channel2 |= ( 0x1 << entries[i].index);
entries[i].type = TYPE_GROUPED;
if (entries[i - 1].type == 0x0)
{
if (entries[i - 1].type == 0x0) {
channel2 |= ( 0x1 << entries[i-1].index);
entries[i-1].type = TYPE_GROUPED;
}
// group TV as well if there is one
if ( ((i+1) < num_outputs) && (entries[i+1].type == 0x1) )
{
if ( ((i+1) < num_outputs) && (entries[i+1].type == 0x1) ) {
//printf("group tv2\n");
channel2 |= ( 0x1 << entries[i+1].index);
entries[i+1].type = TYPE_GROUPED;
uint8_t *togroup;// = (channel1 ? (channel2 ? NULL : &channel2) : &channel1);
togroup = &channel2;
for (i = 0; i < num_outputs; i++)
{
if (entries[i].type != TYPE_GROUPED)
{
for (i = 0; i < num_outputs; i++) {
if (entries[i].type != TYPE_GROUPED) {
//printf("%d not grouped\n", i);
if (togroup)
{
if (togroup) {
*togroup |= ( 0x1 << entries[i].index);
}
entries[i].type = TYPE_GROUPED;
}
}
if (channel1 > channel2)
{
if (channel1 > channel2) {
uint8_t buff = channel1;
channel1 = channel2;
channel2 = buff;
default_NVCAP[8] = channel2;
// patching HEADS
for (i = 0; i < num_outputs; i++)
{
if (channel1 & (1 << i))
{
for (i = 0; i < num_outputs; i++) {
if (channel1 & (1 << i)) {
*entries[i].heads = 1;
}
else if(channel2 & (1 << i))
{
} else if(channel2 & (1 << i)) {
*entries[i].heads = 2;
}
}
// First check in the plist, (for e.g this can override any hardcoded devices)
cardList_t * nvcard = FindCardWithIds(device_id, subsys_id);
if (nvcard)
{
if (nvcard->model)
{
if (nvcard) {
if (nvcard->model) {
return nvcard->model;
}
}
// Then check the exceptions table
if (subsys_id)
{
for (i = 0; i < (sizeof(nvidia_card_exceptions) / sizeof(nvidia_card_exceptions[0])); i++)
{
if (subsys_id) {
for (i = 0; i < (sizeof(nvidia_card_exceptions) / sizeof(nvidia_card_exceptions[0])); i++) {
if ((nvidia_card_exceptions[i].device == device_id) && (nvidia_card_exceptions[i].subdev == subsys_id))
{
return nvidia_card_exceptions[i].name;
}
// At last try the generic names
for (i = 1; i < (sizeof(nvidia_card_generic) / sizeof(nvidia_card_generic[0])); i++)
{
if (nvidia_card_generic[i].device == device_id)
{
if (subsys_id)
{
for (j = 0; j < (sizeof(nvidia_card_vendors) / sizeof(nvidia_card_vendors[0])); j++)
{
if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000))
{
for (i = 1; i < (sizeof(nvidia_card_generic) / sizeof(nvidia_card_generic[0])); i++) {
if (nvidia_card_generic[i].device == device_id) {
if (subsys_id) {
for (j = 0; j < (sizeof(nvidia_card_vendors) / sizeof(nvidia_card_vendors[0])); j++) {
if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000)) {
snprintf(name_model, sizeof(name_model), "%s %s",
nvidia_card_vendors[j].name, nvidia_card_generic[i].name);
return name_model;
int fd;
int size;
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0)
{
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {
return 0;
}
size = file_size(fd);
if (size)
{
if (size) {
*buf = malloc(size);
size = read(fd, (char *)buf, size);
}
return 0;
if (!DP_ADD_TEMP_VAL(device, nvidia_name_1))
return 0;
if (devices_number == 1)
{
if (devices_number == 1) {
if (!DP_ADD_TEMP_VAL(device, nvidia_device_type_parent))
return 0;
}
else
{
} else {
if (!DP_ADD_TEMP_VAL(device, nvidia_device_type_child))
return 0;
}
// Rek : Dont use sprintf return, it does not WORK !! our custom sprintf() always return 0!
// len = sprintf(tmp, "Slot-%x", devices_number);
sprintf(tmp, "Slot-%x",devices_number);
snprintf(tmp, sizeof(tmp), "Slot-%x",devices_number);
devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp));
devices_number++;
break;
}
if (!vram_size)
{ // Finally, if vram_size still not set do the calculation with our own method
if (nvCardType < NV_ARCH_50)
{
if (!vram_size){ // Finally, if vram_size still not set do the calculation with our own method
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)
{
} else if (nvCardType < NV_ARCH_C0) {
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size |= (vram_size & 0xff) << 32;
vram_size &= 0xffffffff00ll;
}
else // >= NV_ARCH_C0
{
} else { // >= NV_ARCH_C0
vram_size = REG32(NVC0_MEM_CTRLR_RAM_AMOUNT) << 20;
vram_size *= REG32(NVC0_MEM_CTRLR_COUNT);
}
// Amount of VRAM in kilobytes
videoRam = mem_detect(regs, nvCardType, nvda_dev,((nvda_dev->vendor_id << 16) | nvda_dev->device_id),((nvda_dev->subsys_id.subsys.vendor_id << 16) | nvda_dev->subsys_id.subsys.device_id) );
sprintf(nvFilename, "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id);
snprintf(nvFilename, sizeof(nvFilename), "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id);
if (getBoolForKey(kUseNvidiaROM, &doit, &bootInfo->chameleonConfig) && doit)
{
verbose("Looking for nvidia video bios file %s\n", nvFilename);
nvBiosOveride = load_nvidia_bios_file(nvFilename, &rom);
if (nvBiosOveride > 0)
{
if (nvBiosOveride > 0) {
verbose("Using nVidia Video BIOS File %s (%d Bytes)\n", nvFilename, nvBiosOveride);
DBG("%s Signature 0x%02x%02x %d bytes\n", nvFilename, rom[0], rom[1], nvBiosOveride);
}
else
{
} else {
printf("ERROR: unable to open nVidia Video BIOS File %s\n", nvFilename);
free(rom);
return false;
}
}
else
{
} else {
rom = malloc(NVIDIA_ROM_SIZE);
// Otherwise read bios from card
nvBiosOveride = 0;
nvRom = (uint8_t*)&regs[NV_PROM_OFFSET];
// Valid Signature ?
if (checkNvRomSig(nvRom))
{
if (checkNvRomSig(nvRom)) {
bcopy((uint8_t *)nvRom, rom, NVIDIA_ROM_SIZE);
DBG("PROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
else
{
} else {
// disable PROM access
(REG32(NV_PBUS_PCI_NV_20)) = NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED;
//PRAM next
nvRom = (uint8_t*)&regs[NV_PRAMIN_OFFSET];
if(checkNvRomSig(nvRom))
{
if(checkNvRomSig(nvRom)) {
bcopy((uint32_t *)nvRom, rom, NVIDIA_ROM_SIZE);
DBG("PRAM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
else
{
} else {
// 0xC0000 last
bcopy((char *)0xc0000, rom, NVIDIA_ROM_SIZE);
// Valid Signature ?
if (!checkNvRomSig(rom))
{
if (!checkNvRomSig(rom)) {
printf("ERROR: Unable to locate nVidia Video BIOS\n");
return false;
}
else
{
} else {
DBG("ROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
}//end PRAM check
}//end PROM check
}//end load rom from bios
if ((nvPatch = patch_nvidia_rom(rom)) == PATCH_ROM_FAILED)
{
if ((nvPatch = patch_nvidia_rom(rom)) == PATCH_ROM_FAILED) {
printf("ERROR: nVidia ROM Patching Failed!\n");
free(rom);
//return false;
}
rom_pci_header = (option_rom_pci_header_t*)(rom + *(uint16_t *)&rom[24]);
// check for 'PCIR' sig
if (rom_pci_header->signature == 0x50434952)
{
if (rom_pci_header->device_id != nvda_dev->device_id)
{
if (rom_pci_header->signature == 0x50434952) {
if (rom_pci_header->device_id != nvda_dev->device_id) {
// Get Model from the OpROM
model = get_nvidia_model(((rom_pci_header->vendor_id << 16) | rom_pci_header->device_id), 0);
// Get VRAM again
videoRam = mem_detect(regs, nvCardType, nvda_dev, ((rom_pci_header->vendor_id << 16) | rom_pci_header->device_id), 0);
}
else
{
} else {
printf("nVidia incorrect PCI ROM signature: 0x%x\n", rom_pci_header->signature);
}
}
/* FIXME: for primary graphics card only */
boot_display = 1;
if (devices_number == 1)
{
if (devices_number == 1) {
devprop_add_value(device, "@0,AAPL,boot-display", (uint8_t*)&boot_display, 4);
}
int crlf_count = 0;
// only search the first 384 bytes
for (i = 0; i < 0x180; i++)
{
if (rom[i] == 0x0D && rom[i+1] == 0x0A)
{
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 (crlf_count == 2) {
if (rom[i-1] == 0x20) i--; // strip last " "
for (version_start = i; version_start > (i-MAX_BIOS_VERSION_LENGTH); version_start--)
{
for (version_start = i; version_start > (i-MAX_BIOS_VERSION_LENGTH); version_start--) {
// find start
if (rom[version_start] == 0x00)
{
if (rom[version_start] == 0x00) {
version_start++;
// strip "Version "
if (strncmp((const char*)rom+version_start, "Version ", 8) == 0)
{
if (strncmp((const char*)rom+version_start, "Version ", 8) == 0) {
version_start += 8;
}
}
snprintf(biosVersion, sizeof(biosVersion), "%s", (nvBiosOveride > 0) ? nvFilename : version_str);
sprintf(kNVCAP, "NVCAP_%04x", nvda_dev->device_id);
snprintf(kNVCAP, sizeof(kNVCAP), "NVCAP_%04x", nvda_dev->device_id);
if (getValueForKey(kNVCAP, &value, &len, &bootInfo->chameleonConfig) && len == NVCAP_LEN * 2)
{
if (getValueForKey(kNVCAP, &value, &len, &bootInfo->chameleonConfig) && len == NVCAP_LEN * 2) {
uint8_t new_NVCAP[NVCAP_LEN];
if (hex2bin(value, new_NVCAP, NVCAP_LEN) == 0)
{
if (hex2bin(value, new_NVCAP, NVCAP_LEN) == 0) {
verbose("Using user supplied NVCAP for %s :: %s\n", model, devicepath);
memcpy(default_NVCAP, new_NVCAP, NVCAP_LEN);
}
}
if (getValueForKey(kDcfg0, &value, &len, &bootInfo->chameleonConfig) && len == DCFG0_LEN * 2)
{
if (getValueForKey(kDcfg0, &value, &len, &bootInfo->chameleonConfig) && len == DCFG0_LEN * 2) {
uint8_t new_dcfg0[DCFG0_LEN];
if (hex2bin(value, new_dcfg0, DCFG0_LEN) == 0)
{
if (hex2bin(value, new_dcfg0, DCFG0_LEN) == 0) {
memcpy(default_dcfg_0, new_dcfg0, DCFG0_LEN);
verbose("Using user supplied @0,display-cfg\n");
}
}
if (getValueForKey(kDcfg1, &value, &len, &bootInfo->chameleonConfig) && len == DCFG1_LEN * 2)
{
if (getValueForKey(kDcfg1, &value, &len, &bootInfo->chameleonConfig) && len == DCFG1_LEN * 2) {
uint8_t new_dcfg1[DCFG1_LEN];
if (hex2bin(value, new_dcfg1, DCFG1_LEN) == 0)
{
if (hex2bin(value, new_dcfg1, DCFG1_LEN) == 0) {
memcpy(default_dcfg_1, new_dcfg1, DCFG1_LEN);
verbose("Using user supplied @1,display-cfg\n");
/******************** Added Marchrius.**********************/
// For the AppleBacklightDisplay //
/***********************************************************/
if (getBoolForKey(kEnableBacklight, &doit, &bootInfo->chameleonConfig) && doit)
{
if (getBoolForKey(kEnableBacklight, &doit, &bootInfo->chameleonConfig) && doit){
uint8_t AAPL_value[] = {0x01, 0x00, 0x00, 0x00}; //Is the same for all
devprop_add_value(device, "AAPL,HasPanel", AAPL_value, 4);
devprop_add_value(device, "AAPL,Haslid", AAPL_value, 4);
/***********************************************************/
// For the DualLink //
/***********************************************************/
if (getBoolForKey(kEnableDualLink, &doit, &bootInfo->chameleonConfig) && doit)
{
if (getBoolForKey(kEnableDualLink, &doit, &bootInfo->chameleonConfig) && doit) {
uint8_t AAPL00_value[] = {0x01, 0x00, 0x00, 0x00};
devprop_add_value(device, "AAPL00,DualLink", AAPL00_value, 4);
}
/************************ HDMI Audio ***********************/
doit = false;
//http://forge.voodooprojects.org/p/chameleon/issues/67/
if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit)
{
if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit) {
static uint8_t connector_type_1[]= {0x00, 0x08, 0x00, 0x00};
devprop_add_value(device, "@0,connector-type",connector_type_1, 4);
devprop_add_value(device, "@1,connector-type",connector_type_1, 4);
}
/************************ End Audio *************************/
if (getBoolForKey(kVBIOS, &doit, &bootInfo->chameleonConfig) && doit)
{
if (getBoolForKey(kVBIOS, &doit, &bootInfo->chameleonConfig) && doit) {
devprop_add_value(device, "vbios", rom, (nvBiosOveride > 0) ? nvBiosOveride : (rom[2] * 512));
}
branches/chucko/i386/libsaio/ntfs.c
271271
272272
273273
274
274
275275
276276
277277
278278
279
280
279
281280
282281
283282
......
331330
332331
333332
334
333
335334
335
336336
337337
338338
......
344344
345345
346346
347
347
348348
349349
350350
goto error;
}
if (read(fd, buf, mftRecordSize) != mftRecordSize) {
//verbose("NTFS: error reading MFT $Volume record: %s\n", strerror(errno));
//verbose("NTFS: error reading MFT $Volume record: %s\n", strerror(errno));
goto error;
}
#endif
if (ntfs_fixup(buf, mftRecordSize, NTFS_FILEMAGIC, bytesPerSector) != 0)
{
if (ntfs_fixup(buf, mftRecordSize, NTFS_FILEMAGIC, bytesPerSector) != 0) {
//verbose("NTFS: block fixup failed\n");
goto error;
}
}
// Check for non-null volume serial number
if( !boot->bf_volsn )
if( !boot->bf_volsn ) {
return -1;
}
// Use UUID like the one you get on Windows
sprintf(uuidStr, "%04X-%04X",(unsigned short)(boot->bf_volsn >> 16) & 0xFFFF,
bool NTFSProbe(const void * buffer)
{
bool result = false;
const struct bootfile* part_bootfile = buffer;// NTFS boot sector structure
// Looking for NTFS signature.
branches/chucko/i386/libsaio/ati.c
13591359
13601360
13611361
1362
13621363
1364
13631365
13641366
13651367
......
15591561
15601562
15611563
1562
1564
15631565
15641566
15651567
......
15841586
15851587
15861588
1587
1589
15881590
15891591
15901592
{ 0x95C4,0x00000000, CHIP_FAMILY_RV620,"ATI Radeon HD 3470 Series",kIago},
{ 0x95C5,0x00000000, CHIP_FAMILY_RV620,"ATI Radeon HD 3450 Series",kIago},
{ 0x95C6,0x00000000, CHIP_FAMILY_RV620,"ATI Radeon HD 3450 AGP",kIago},
/* IGP */
{ 0x9610,0x00000000, CHIP_FAMILY_RS780,"ATI Radeon HD 3200 Graphics",kNull},
{ 0x9611,0x00000000, CHIP_FAMILY_RS780,"ATI Radeon HD 3100 Graphics", kNull},
{ 0x6808,0x00000000, CHIP_FAMILY_TAHITI,"AMD Radeon HD 7600 Series",kFutomaki}, // ATI7000Controller.kext
//{ 0x6809,0x00000000, CHIP_FAMILY_PITCAIRN,"AMD Radeon HD ??? Series",kNull},
//{ 0x6810,0x00000000, CHIP_FAMILY_PITCAIRN,"AMD Radeon HD ??? Series",kNull},
{ 0x6810,0x00000000, CHIP_FAMILY_PITCAIRN,"AMD Radeon R9 270X",kNull},
{ 0x6818,0x00000000, CHIP_FAMILY_TAHITI,"AMD Radeon HD 7870 Series",kFutomaki}, // CHIP_FAMILY_PITCAIRN ??// ATI7000Controller.kext
{ 0x6819,0x00000000, CHIP_FAMILY_TAHITI,"AMD Radeon HD 7850 Series",kFutomaki},// CHIP_FAMILY_PITCAIRN ??
{ 0x6831,0x00000000, CHIP_FAMILY_VERDE,"AMD Radeon HD 7700 Series", kBuri},
{ 0x6837,0x00000000, CHIP_FAMILY_VERDE,"AMD Radeon HD 7700 Series", kBuri},
//{ 0x6838,0x00000000, CHIP_FAMILY_VERDE,"AMD Radeon HD ??? Series", kBuri},
{ 0x6838,0x00000000, CHIP_FAMILY_VERDE,"AMD Radeon HD 7700 Series", kBuri},
{ 0x6839,0x00000000, CHIP_FAMILY_VERDE,"AMD Radeon HD 7700 Series", kBuri}, // ATI7000Controller.kext
{ 0x683B,0x00000000, CHIP_FAMILY_VERDE,"AMD Radeon HD 7700 Series", kBuri}, // ATI7000Controller.kext
branches/chucko/i386/libsaio/sys.c
8282
8383
8484
85
86
87
88
85
86
87
88
8989
9090
9191
9292
9393
94
95
96
97
98
94
95
96
97
98
9999
100100
101101
......
149149
150150
151151
152
153
152
153
154154
155
155
156156
157
158
157
158
159
159160
160
161
161162
162163
164
165
163166
164167
165
166
168
169
167170
168
169
171
172
173
170174
171
172
175
176
177
173178
174
179
175180
176181
182
183
177184
178185
179
180
181
182
183
184
186
187
188
189
185190
186
187
191
192
193
194
195
196
197
188198
189
190
191
192
199
200
193201
194
202
195203
196
204
197205
198
199
200
201
202
203
206
207
208
209
210
211
212
204213
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
222237
223
238
224239
225240
241
242
226243
227244
228245
229
230
231
246
247
248
232249
233
234
250
251
252
235253
236
237
254
255
256
238257
239
258
240259
241260
242261
243262
263
244264
245265
246266
......
264284
265285
266286
267
268
269
270
271
287
288
272289
273
274
275
276
290
291
292
293
294
277295
278
279
280
281
296
297
298
282299
283
284
285
286
287
288
289
300
290301
291
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
292324
293325
294326
......
299331
300332
301333
302
303
334
335
304336
305
337
306338
307
308
339
340
341
309342
310
343
311344
312345
313346
......
324357
325358
326359
327
328
360
361
329362
330
331
363
364
365
332366
333
334
367
368
335369
336
370
337371
338
339
340
341
342
343
344
345
346
347
348
349
350
372
373
374
375
376
377
378
379
380
381
382
383
351384
352
353
354
355
356
357
385
386
387
388
389
390
391
392
393
394
395
358396
359397
398
399
360400
361401
362
363
402
403
364404
365
405
366406
367
368
369
370
407
408
409
410
371411
372
412
373413
374414
375415
......
398438
399439
400440
401
441
402442
403
404
405
406
407
443
444
445
446
447
408448
409449
410450
......
530570
531571
532572
533
573
534574
535
536
575
576
577
537578
538
579
539580
540
581
541582
542583
543584
......
546587
547588
548589
549
590
550591
551
552
592
593
594
553595
554
596
555597
556
598
557599
558600
559601
......
561603
562604
563605
564
606
565607
566
567
608
609
610
568611
569
612
570613
571614
572615
......
575618
576619
577620
578
579
580
581
621
582622
583
584
623
624
625
585626
586
587
627
628
629
588630
589
631
632
633
590634
591
635
592636
593
637
638
639
594640
595641
596642
......
655701
656702
657703
658
704
659705
660
661
706
707
708
662709
663
710
664711
665712
666713
667714
668715
669716
670
717
671718
672
673
674
719
675720
676
677
678
721
722
679723
680
724
725
726
681727
682
728
683729
730
731
684732
685
686
733
734
735
687736
688737
689738
690739
691740
692741
693
694
695
742
743
744
696745
697746
698747
......
718767
719768
720769
721
722
723
724
770
771
772
773
774
775
776
777
725778
726779
727780
728781
729782
730783
731
784
732785
733
734
735
736
737
786
787
788
789
738790
739791
740792
741793
742794
743
795
744796
745
746
747
748
749
750
797
798
799
800
801
802
751803
752804
753805
754806
755807
756808
757
758
759
809
810
811
812
760813
761814
762815
763816
764817
765818
766
819
767820
768
821
769822
770
771
772
773
774
775
776
777
778
779
780
781
782
823
824
825
826
827
828
829
830
831
783832
784833
785834
786835
787836
788837
789
790
791
838
839
840
792841
793
794
795
796
797
798
842
843
844
845
846
799847
800848
801
802
803
804
805
849
850
851
852
806853
807854
808855
......
814861
815862
816863
817
864
865
866
818867
819
820
821
868
869
870
822871
823
872
873
874
875
824876
825877
826878
827879
828880
829881
830
831
832
833
834
835
836
837
838
839
882
883
884
885
886
887
888
889
890
891
840892
841893
842894
843895
844896
845897
846
847
848
849
850
851
898
899
900
901
902
903
904
905
852906
853907
854908
855909
856910
857
911
858912
913
914
859915
860916
861917
862918
863
919
864920
865
866
867
921
922
923
868924
869925
870926
......
872928
873929
874930
875
876
931
932
933
934
935
936
877937
878938
879939
......
898958
899959
900960
901
902
903
904
905
961
962
963
964
965
966
906967
907968
908969
909970
910
911
971
972
912973
913
914
915
916
974
975
976
977
978
979
917980
918981
919982
......
932995
933996
934997
935
936
937
998
999
1000
1001
1002
9381003
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
9541014
955
1015
1016
1017
9561018
957
1019
9581020
959
960
961
962
963
964
965
966
967
968
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
9691033
970
971
1034
1035
9721036
973
974
975
976
977
978
1037
9791038
1039
1040
1041
1042
1043
9801044
9811045
9821046
9831047
9841048
985
986
1049
1050
1051
9871052
988
1053
9891054
990
991
1055
1056
1057
9921058
993
994
995
1059
1060
1061
9961062
997
1063
9981064
999
1000
1065
1066
1067
1068
1069
10011070
1002
1003
1071
10041072
1005
1006
1007
1008
1009
1010
1073
10111074
1012
1013
1014
1015
1016
1075
1076
1077
1078
1079
10171080
1018
1019
1081
1082
1083
1084
10201085
1021
1086
1087
1088
10221089
1023
1090
1091
1092
1093
1094
1095
10241096
10251097
10261098
......
10321104
10331105
10341106
1035
1036
1037
1038
1039
1040
1041
1042
1043
1107
1108
1109
10441110
1045
1111
1112
1113
1114
1115
10461116
1047
1048
1049
1117
1118
10501119
10511120
10521121
......
10541123
10551124
10561125
1057
1058
1059
1126
1127
1128
1129
10601130
10611131
1062
1132
1133
1134
10631135
10641136
10651137
......
10721144
10731145
10741146
1075
1076
1147
1148
1149
10771150
10781151
10791152
1080
1081
1082
1083
1084
1085
1153
1154
1155
1156
1157
10861158
1087
1088
1159
1160
1161
10891162
10901163
10911164
extern int multiboot_skip_partition_set;
struct devsw {
const char * name;
// size increased from char to short to handle non-BIOS internal devices
unsigned short biosdev;
int type;
const char * name;
// size increased from char to short to handle non-BIOS internal devices
unsigned short biosdev;
int type;
};
// Device entries must be ordered by bios device numbers.
static struct devsw devsw[] =
{
{ "hd", 0x80, kBIOSDevTypeHardDrive }, /* DEV_HD */
{ "en", 0xE0, kBIOSDevTypeNetwork }, /* DEV_EN */
{ "rd", 0x100, kBIOSDevTypeHardDrive },
{ "bt", 0x101, kBIOSDevTypeHardDrive }, // turbo - type for booter partition
{ 0, 0 }
{ "hd", 0x80,kBIOSDevTypeHardDrive }, /* DEV_HD */
{ "en", 0xE0,kBIOSDevTypeNetwork }, /* DEV_EN */
{ "rd", 0x100,kBIOSDevTypeHardDrive },
{ "bt", 0x101,kBIOSDevTypeHardDrive }, // turbo - type for booter partition
{ 0, 0 }
};
// Pseudo BIOS devices
long LoadFile(const char * fileSpec)
{
const char * filePath;
BVRef bvr;
const char * filePath;
BVRef bvr;
// Resolve the boot volume from the file spec.
// Resolve the boot volume from the file spec.
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL)
return -1;
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) {
return -1;
}
return LoadVolumeFile(bvr, filePath);
return LoadVolumeFile(bvr, filePath);
}
//==========================================================================
long ReadFileAtOffset(const char * fileSpec, void *buffer, uint64_t offset, uint64_t length)
{
const char *filePath;
BVRef bvr;
const char *filePath;
BVRef bvr;
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL)
return -1;
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) {
return -1;
}
if (bvr->fs_readfile == NULL)
return -1;
if (bvr->fs_readfile == NULL) {
return -1;
}
return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length);
return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length);
}
//==========================================================================
long LoadThinFatFile(const char *fileSpec, void **binary)
{
const char *filePath;
FSReadFile readFile;
BVRef bvr;
unsigned long length, length2;
// Resolve the boot volume from the file spec.
const char*filePath;
FSReadFilereadFile;
BVRefbvr;
unsigned long length, length2;
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL)
return -1;
// Resolve the boot volume from the file spec.
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) {
return -1;
}
*binary = (void *)kLoadAddr;
*binary = (void *)kLoadAddr;
// Read file into load buffer. The data in the load buffer will be
// overwritten by the next LoadFile() call.
// Read file into load buffer. The data in the load buffer will be
// overwritten by the next LoadFile() call.
gFSLoadAddress = (void *) LOAD_ADDR;
gFSLoadAddress = (void *) LOAD_ADDR;
readFile = bvr->fs_readfile;
readFile = bvr->fs_readfile;
if (readFile != NULL) {
// Read the first 4096 bytes (fat header)
length = readFile(bvr, (char *)filePath, *binary, 0, 0x1000);
if (length > 0) {
if (ThinFatFile(binary, &length) == 0) {
if (length == 0)
if (readFile != NULL) {
// Read the first 4096 bytes (fat header)
length = readFile(bvr, (char *)filePath, *binary, 0, 0x1000);
if (length > 0) {
if (ThinFatFile(binary, &length) == 0) {
if (length == 0) {
return 0;
// We found a fat binary; read only the thin part
length = readFile(bvr, (char *)filePath,
(void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length);
*binary = (void *)kLoadAddr;
} else {
// Not a fat binary; read the rest of the file
length2 = readFile(bvr, (char *)filePath, (void *)(kLoadAddr + length), length, 0);
if (length2 == -1) return -1;
length += length2;
}
}
} else {
length = bvr->fs_loadfile(bvr, (char *)filePath);
if (length > 0) {
ThinFatFile(binary, &length);
}
}
}
// We found a fat binary; read only the thin part
length = readFile(bvr, (char *)filePath, (void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length);
*binary = (void *)kLoadAddr;
} else {
// Not a fat binary; read the rest of the file
length2 = readFile(bvr, (char *)filePath, (void *)(kLoadAddr + length), length, 0);
if (length2 == -1) {
return -1;
}
length += length2;
}
}
} else {
length = bvr->fs_loadfile(bvr, (char *)filePath);
if (length > 0) {
ThinFatFile(binary, &length);
}
}
return length;
return length;
}
//==========================================================================
#if UNUSED
long GetFSUUID(char *spec, char *uuidStr)
{
BVRef bvr;
long rval = -1;
const char *devSpec;
BVRef bvr;
long rval = -1;
const char *devSpec;
if ((bvr = getBootVolumeRef(spec, &devSpec)) == NULL)
return -1;
if ((bvr = getBootVolumeRef(spec, &devSpec)) == NULL) {
return -1;
}
if(bvr->fs_getuuid)
rval = bvr->fs_getuuid(bvr, uuidStr);
if(bvr->fs_getuuid) {
rval = bvr->fs_getuuid(bvr, uuidStr);
}
return rval;
return rval;
}
#endif
// filesystem-specific getUUID functions call this shared string generator
long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr)
{
unsigned fmtbase, fmtidx, i;
// generate the text: e.g. 5EB1869F-C4FA-3502-BDEB-3B8ED5D87292
i = 0; fmtbase = 0;
for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) {
for(i=0; i < uuidfmt[fmtidx]; i++) {
uint8_t byte = mdresult[fmtbase+i];
char nib;
i = 0;
fmtbase = 0;
nib = byte >> 4;
*p = nib + '0'; // 0x4 -> '4'
if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B'
p++;
for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) {
for (i = 0; i < uuidfmt[fmtidx]; i++) {
uint8_t byte = mdresult[fmtbase + i];
char nib = byte >> 4;
*p = nib + '0'; // 0x4 -> '4'
nib = byte & 0xf;
*p = nib + '0'; // 0x4 -> '4'
if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B'
p++;
if (*p > '9') {
*p = (nib - 9 + ('A'-1)); // 0xB -> 'B'
}
}
fmtbase += i;
if(fmtidx < sizeof(uuidfmt)-1)
*(p++) = '-';
else
*p = '\0';
}
p++;
return 0;
nib = byte & 0xf;
*p = nib + '0'; // 0x4 -> '4'
if (*p > '9') {
*p = (nib - 9 + ('A'-1)); // 0xB -> 'B'
}
p++;
}
fmtbase += i;
if (fmtidx < sizeof(uuidfmt) - 1) {
*(p++) = '-';
}
else
{
*p = '\0';
}
}
return 0;
}
long GetDirEntry(const char * dirSpec, long long * dirIndex, const char ** name,
long * flags, long * time)
{
const char * dirPath;
BVRef bvr;
const char * dirPath;
BVRef bvr;
// Resolve the boot volume from the dir spec.
// Resolve the boot volume from the dir spec.
if ((bvr = getBootVolumeRef(dirSpec, &dirPath)) == NULL)
return -1;
if ((bvr = getBootVolumeRef(dirSpec, &dirPath)) == NULL) {
return -1;
}
// Return 0 on success, or -1 if there are no additional entries.
// Returns 0 on success or -1 when there are no additional entries.
return bvr->fs_getdirentry( bvr,
/* dirPath */ (char *)dirPath,
long GetFileInfo(const char * dirSpec, const char * name,
long * flags, long * time)
{
long long index = 0;
const char * entryName;
long long index = 0;
const char * entryName;
if (gMakeDirSpec == 0)
gMakeDirSpec = (char *)malloc(1024);
if (gMakeDirSpec == 0) {
gMakeDirSpec = (char *)malloc(1024);
}
if (!dirSpec) {
long idx, len;
if (!dirSpec) {
long idx, len;
len = strlen(name);
len = strlen(name);
for (idx = len; idx && (name[idx] != '/' && name[idx] != '\\'); idx--) {}
if (idx == 0) {
if(name[idx] == '/' || name[idx] == '\\') ++name; // todo: ensure other functions handel \ properly
gMakeDirSpec[0] = '/';
gMakeDirSpec[1] = '\0';
} else {
idx++;
strncpy(gMakeDirSpec, name, idx);
gMakeDirSpec[idx] = '\0';
name += idx;
}
dirSpec = gMakeDirSpec;
}
for (idx = len; idx && (name[idx] != '/' && name[idx] != '\\'); idx--) {}
if (idx == 0) {
if(name[idx] == '/' || name[idx] == '\\') ++name; // todo: ensure other functions handel \ properly
gMakeDirSpec[0] = '/';
gMakeDirSpec[1] = '\0';
gMakeDirSpec[idx] = '\0';
} else {
idx++;
strncpy(gMakeDirSpec, name, idx);
gMakeDirSpec[idx] = '\0'; // ISSUE: http://forge.voodooprojects.org/p/chameleon/issues/270/
name += idx;
}
while (GetDirEntry(dirSpec, &index, &entryName, flags, time) == 0)
{
if (strcmp(entryName, name) == 0)
return 0; // success
}
return -1; // file not found
dirSpec = gMakeDirSpec;
}
while (GetDirEntry(dirSpec, &index, &entryName, flags, time) == 0)
{
if (strcmp(entryName, name) == 0) {
return 0; // success
}
}
return -1; // file not found
}
//==============================================================================
long GetFileBlock(const char *fileSpec, unsigned long long *firstBlock)
{
const char * filePath;
BVRef bvr;
const char * filePath;
BVRef bvr;
// Resolve the boot volume from the file spec.
// Resolve the boot volume from the file spec.
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) {
printf("Boot volume for '%s' is bogus\n", fileSpec);
return -1;
}
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) {
// printf("Boot volume for '%s' is bogus\n", fileSpec);
return -1;
}
return bvr->fs_getfileblock(bvr, (char *)filePath, firstBlock);
return bvr->fs_getfileblock(bvr, (char *)filePath, firstBlock);
}
//==========================================================================
static struct iob * iob_from_fdesc(int fdesc)
{
register struct iob * io;
register struct iob * io;
if (fdesc < 0 || fdesc >= NFILES ||
((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0)
return NULL;
else
return io;
if (fdesc < 0 || fdesc >= NFILES || ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) {
return NULL;
} else {
return io;
}
}
//==========================================================================
int close(int fdesc)
{
struct iob * io;
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
if ((io = iob_from_fdesc(fdesc)) == NULL) {
return (-1);
}
io->i_flgs = 0;
io->i_flgs = 0;
return 0;
return 0;
}
//==========================================================================
int b_lseek(int fdesc, int offset, int ptr)
{
struct iob * io;
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
if ((io = iob_from_fdesc(fdesc)) == NULL) {
return (-1);
}
io->i_offset = offset;
io->i_offset = offset;
return offset;
return offset;
}
//==========================================================================
int tell(int fdesc)
{
struct iob * io;
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return 0;
if ((io = iob_from_fdesc(fdesc)) == NULL) {
return 0;
}
return io->i_offset;
return io->i_offset;
}
//==========================================================================
int read(int fdesc, char * buf, int count)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
struct iob * io;
if ((io->i_offset + count) > (unsigned int)io->i_filesize)
count = io->i_filesize - io->i_offset;
if ((io = iob_from_fdesc(fdesc)) == NULL) {
return (-1);
}
if (count <= 0)
return 0; // end of file
if ((io->i_offset + count) > (unsigned int)io->i_filesize) {
count = io->i_filesize - io->i_offset;
}
bcopy(io->i_buf + io->i_offset, buf, count);
if (count <= 0) {
return 0; // end of file
}
io->i_offset += count;
bcopy(io->i_buf + io->i_offset, buf, count);
return count;
io->i_offset += count;
return count;
}
//==========================================================================
int file_size(int fdesc)
{
struct iob * io;
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == 0)
return 0;
if ((io = iob_from_fdesc(fdesc)) == 0) {
return 0;
}
return io->i_filesize;
return io->i_filesize;
}
//==========================================================================
struct dirstuff * vol_opendir(BVRef bvr, const char * path)
{
struct dirstuff * dirp = 0;
struct dirstuff * dirp = 0;
dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff));
if (dirp == NULL)
goto error;
dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff));
dirp->dir_path = newString(path);
if (dirp->dir_path == NULL)
goto error;
if (dirp == NULL)
goto error;
dirp->dir_bvr = bvr;
dirp->dir_path = newString(path);
if (dirp->dir_path == NULL)
goto error;
return dirp;
dirp->dir_bvr = bvr;
return dirp;
error:
closedir(dirp);
return NULL;
closedir(dirp);
return NULL;
}
//==========================================================================
struct dirstuff * opendir(const char * path)
{
struct dirstuff * dirp = 0;
const char * dirPath;
BVRef bvr;
struct dirstuff * dirp = 0;
const char * dirPath;
BVRef bvr;
if ((bvr = getBootVolumeRef(path, &dirPath)) == NULL)
goto error;
int closedir(struct dirstuff * dirp)
{
if (dirp) {
if (dirp->dir_path) free(dirp->dir_path);
free(dirp);
}
if (dirp) {
if (dirp->dir_path) {
free(dirp->dir_path);
}
free(dirp);
}
return 0;
}
//==========================================================================
int readdir(struct dirstuff * dirp, const char ** name, long * flags,
long * time)
long * time)
{
return dirp->dir_bvr->fs_getdirentry( dirp->dir_bvr,
/* dirPath */ dirp->dir_path,
/* dirIndex */ &dirp->dir_index,
/* dirEntry */ (char **)name, flags, time,
0, 0);
return dirp->dir_bvr->fs_getdirentry(dirp->dir_bvr,
/* dirPath */ dirp->dir_path,
/* dirIndex */ &dirp->dir_index,
/* dirEntry */ (char **)name, flags, time, 0, 0);
}
//==========================================================================
int readdir_ext(struct dirstuff * dirp, const char ** name, long * flags,
long * time, FinderInfo *finderInfo, long *infoValid)
long * time, FinderInfo *finderInfo, long *infoValid)
{
return dirp->dir_bvr->fs_getdirentry( dirp->dir_bvr,
/* dirPath */ dirp->dir_path,
/* dirIndex */ &dirp->dir_index,
/* dirEntry */ (char **)name,
flags, time,
finderInfo, infoValid);
return dirp->dir_bvr->fs_getdirentry( dirp->dir_bvr,
/* dirPath */ dirp->dir_path,
/* dirIndex */ &dirp->dir_index,
/* dirEntry */ (char **)name,
flags, time,
finderInfo, infoValid);
}
//==========================================================================
const char * systemConfigDir()
{
if (gBootFileType == kNetworkDeviceType)
return "";
return "/Library/Preferences/SystemConfiguration";
if (gBootFileType == kNetworkDeviceType) {
return "";
}
return "/Library/Preferences/SystemConfiguration";
}
//==========================================================================
int gBootFileType;
void scanBootVolumes( int biosdev, int * count )
void scanBootVolumes(int biosdev, int * count)
{
BVRef bvr = 0;
BVRef bvr = 0;
bvr = diskScanBootVolumes(biosdev, count);
if (bvr == NULL)
{
bvr = nbpScanBootVolumes(biosdev, count);
if (bvr != NULL)
{
gBootFileType = kNetworkDeviceType;
}
}
else
{
gBootFileType = kBlockDeviceType;
}
bvr = diskScanBootVolumes(biosdev, count);
if (bvr == NULL) {
bvr = nbpScanBootVolumes(biosdev, count);
if (bvr != NULL) {
gBootFileType = kNetworkDeviceType;
}
} else {
gBootFileType = kBlockDeviceType;
}
}
//==========================================================================
void scanDisks(int biosdev, int *count)
{
#define MAX_HDD_COUNT 32
int bvCount;
int hd = 0;
#define MAX_HDD_COUNT 32
int bvCount;
int hd = 0;
// Testing up to MAX_HDD_COUNT hard drives.
while(!testBiosread(0x80 + hd, 0) && hd < MAX_HDD_COUNT)
{
bvCount = 0;
scanBootVolumes(0x80 + hd, &bvCount);
hd++;
// Testing up to MAX_HDD_COUNT hard drives.
while(!testBiosread(0x80 + hd, 0) && hd < MAX_HDD_COUNT) {
bvCount = 0;
scanBootVolumes(0x80 + hd, &bvCount);
hd++;
}
// Also scanning CD/DVD drive.
if (biosDevIsCDROM(gBIOSDev))
{
bvCount = 0;
scanBootVolumes(gBIOSDev, &bvCount);
// Also scanning CD/DVD drive.
if (biosDevIsCDROM(gBIOSDev)) {
bvCount = 0;
scanBootVolumes(gBIOSDev, &bvCount);
}
}
bool foundPrimary = false;
BVRef bvr, bvr1 = 0, bvr2 = 0;
if (chain->filtered) filteredChain = true;
if (chain->filtered) {
filteredChain = true;
}
if (multiboot_partition_set)
for ( bvr = chain; bvr; bvr = bvr->next )
if ( bvr->part_no == multiboot_partition && bvr->biosdev == gBIOSDev )
if (multiboot_partition_set) {
for ( bvr = chain; bvr; bvr = bvr->next ) {
if ( bvr->part_no == multiboot_partition && bvr->biosdev == gBIOSDev ) {
return bvr;
}
}
}
/*
* Checking "Default Partition" key in system configuration - use format: hd(x,y), the volume UUID or label -
* to override the default selection.
* We accept only kBVFlagSystemVolume or kBVFlagForeignBoot volumes.
*/
char *val = XMLDecode(getStringForKey(kDefaultPartition, &bootInfo->chameleonConfig));
if (val) {
for ( bvr = chain; bvr; bvr = bvr->next ) {
if (matchVolumeToString(bvr, val, false)) {
free(val);
return bvr;
}
}
free(val);
}
if (val) {
for ( bvr = chain; bvr; bvr = bvr->next ) {
if (matchVolumeToString(bvr, val, false)) {
free(val);
return bvr;
}
}
free(val);
}
/*
* Scannig the volume chain backwards and trying to find
* a HFS+ volume with valid boot record signature.
* If not found any active partition then we will
* select this volume as the boot volume.
*/
for ( bvr = chain; bvr; bvr = bvr->next )
{
if (multiboot_skip_partition_set) {
if (bvr->part_no == multiboot_skip_partition) continue;
}
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) foundPrimary = true;
for ( bvr = chain; bvr; bvr = bvr->next ) {
if (multiboot_skip_partition_set) {
if (bvr->part_no == multiboot_skip_partition) continue;
}
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) {
foundPrimary = true;
}
// zhell -- Undo a regression that was introduced from r491 to 492.
// if gBIOSBootVolume is set already, no change is required
if ( bvr->flags & (kBVFlagBootable|kBVFlagSystemVolume)
&& gBIOSBootVolume
&& (!filteredChain || (filteredChain && bvr->visible))
&& bvr->biosdev == gBIOSDev )
&& bvr->biosdev == gBIOSDev ) {
bvr2 = bvr;
}
// zhell -- if gBIOSBootVolume is NOT set, we use the "if" statement
// from r491,
if ( bvr->flags & kBVFlagBootable
&& ! gBIOSBootVolume
&& bvr->biosdev == gBIOSDev )
&& bvr->biosdev == gBIOSDev ) {
bvr2 = bvr;
}
}
}
/*
* Use the standrad method for selecting the boot volume.
*/
{
for ( bvr = chain; bvr; bvr = bvr->next )
{
if ( bvr->flags & kBVFlagNativeBoot && bvr->biosdev == gBIOSDev ) bvr1 = bvr;
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) bvr2 = bvr;
if ( bvr->flags & kBVFlagNativeBoot && bvr->biosdev == gBIOSDev ) {
bvr1 = bvr;
}
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) {
bvr2 = bvr;
}
}
}
void setRootVolume(BVRef volume)
{
gRootVolume = volume;
// Veto non-native FS. Basically that means don't allow the root volume to
// be set to a volume we can't read files from.
if(gRootVolume != NULL && ((gRootVolume->flags & kBVFlagNativeBoot) == 0))
gRootVolume = NULL;
gRootVolume = volume;
// Veto non-native FS. Basically that means don't allow the root volume to
// be set to a volume we can't read files from.
if(gRootVolume != NULL && ((gRootVolume->flags & kBVFlagNativeBoot) == 0)) {
gRootVolume = NULL;
}
}
void setBootGlobals(BVRef chain)
{
// Record default boot device.
gBootVolume = selectBootVolume(chain);
// Record default boot device.
gBootVolume = selectBootVolume(chain);
// turbo - Save the ORIGINAL boot volume too for loading our mkext
if (!gBIOSBootVolume) gBIOSBootVolume = gBootVolume;
setRootVolume(gBootVolume);
// turbo - Save the ORIGINAL boot volume too for loading our mkext
if (!gBIOSBootVolume) {
gBIOSBootVolume = gBootVolume;
}
setRootVolume(gBootVolume);
}
/*!
// Search for left parenthesis in the path specification.
for (cp = path; *cp; cp++) {
if (*cp == LP || *cp == '/') break;
}
for (cp = path; *cp; cp++) {
if (*cp == LP || *cp == '/') {
break;
}
}
if (*cp != LP) // no left paren found
{
// Path is using the implicit current device so if there is
// no current device, then we must fail.
cp = path;
if ( gRootVolume == NULL )
return NULL;
}
else if ((cp - path) == 2) // found "xx("
{
const struct devsw * dp;
const char * xp = path;
int i;
int unit = -1;
int part = -1;
if (*cp != LP) { // no left paren found
cp = path;
// Path is using the implicit current device so if there is
// no current device, then we must fail.
if (gRootVolume == NULL) {
return NULL;
}
} else if ((cp - path) == 2) { // found "xx("
const struct devsw * dp;
const char * xp = path;
cp++;
int i;
int unit = -1;
int part = -1;
// Check the 2 character device name pointed by 'xp'.
cp++;
for (dp = devsw; dp->name; dp++)
{
if ((xp[0] == dp->name[0]) && (xp[1] == dp->name[1]))
break; // found matching entry
}
if (dp->name == NULL)
{
error("Unknown device '%c%c'\n", xp[0], xp[1]);
return NULL;
}
// Check the 2 character device name pointed by 'xp'.
for (dp = devsw; dp->name; dp++) {
if ((xp[0] == dp->name[0]) && (xp[1] == dp->name[1])) {
break;// Found matching entry.
}
}
if (dp->name == NULL) {
error("Unknown device '%c%c'\n", xp[0], xp[1]);
return NULL;
}
// Extract the optional unit number from the specification.
// hd(unit) or hd(unit, part).
// Extract the optional unit number from the specification.
// hd(unit) or hd(unit, part).
i = 0;
while (*cp >= '0' && *cp <= '9')
{
i = i * 10 + *cp++ - '0';
unit = i;
}
i = 0;
while (*cp >= '0' && *cp <= '9') {
i = i * 10 + *cp++ - '0';
unit = i;
}
// Unit is no longer optional and never really was.
// If the user failed to specify it then the unit number from the previous kernDev
// would have been used which makes little sense anyway.
// For example, if the user did fd()/foobar and the current root device was the
// second hard disk (i.e. unit 1) then fd() would select the second floppy drive!
if(unit == -1)
return NULL;
if (unit == -1) {
return NULL;
}
// Extract the optional partition number from the specification.
// Extract the optional partition number from the specification.
if (*cp == ',')
part = atoi(++cp);
if (*cp == ',') {
part = atoi(++cp);
}
// If part is not specified part will be -1 whereas before it would have been
// whatever the last partition was which makes about zero sense if the device
// has been switched.
// If part is not specified part will be -1 whereas before it would have been
// whatever the last partition was which makes about zero sense if the device
// has been switched.
// Skip past the right paren.
// Skip past the right paren.
for ( ; *cp && *cp != RP; cp++) /* LOOP */;
if (*cp == RP) cp++;
for ( ; *cp && *cp != RP; cp++) /* LOOP */;
if (*cp == RP) {
cp++;
}
biosdev = dp->biosdev + unit;
bvr = newBootVolumeRef(biosdev, part);
biosdev = dp->biosdev + unit;
if(bvr == NULL)
return NULL;
}
else
{
// Bad device specifier, skip past the right paren.
bvr = newBootVolumeRef(biosdev, part);
for ( cp++; *cp && *cp != RP; cp++) /* LOOP */;
if (*cp == RP) cp++;
// If gRootVolume was NULL, then bvr will be NULL as well which
// should be caught by the caller.
}
if (bvr == NULL) {
return NULL;
}
} else {
// Bad device specifier, skip past the right paren.
// Returns the file path following the device spec.
// e.g. 'hd(1,b)mach_kernel' is reduced to 'mach_kernel'.
for (cp++; *cp && *cp != RP; cp++) /* LOOP */;
if (*cp == RP) {
cp++;
}
*outPath = cp;
// If gRootVolume was NULL, then bvr will be NULL as well which
// should be caught by the caller.
}
return bvr;
// Returns the file path following the device spec.
// e.g. 'hd(1,b)mach_kernel' is reduced to 'mach_kernel'.
*outPath = cp;
return bvr;
}
//==========================================================================
bvr = bvr1 = NULL;
// Try resolving "rd" and "bt" devices first.
if (biosdev == kPseudoBIOSDevRAMDisk)
{
if (gRAMDiskVolume)
bvr1 = gRAMDiskVolume;
}
else if (biosdev == kPseudoBIOSDevBooter)
{
if (gRAMDiskVolume != NULL && gRAMDiskBTAliased)
// Try resolving "rd" and "bt" devices first.
if (biosdev == kPseudoBIOSDevRAMDisk) {
if (gRAMDiskVolume) {
bvr1 = gRAMDiskVolume;
else
}
} else if (biosdev == kPseudoBIOSDevBooter) {
if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) {
bvr1 = gRAMDiskVolume;
} else {
bvr1 = gBIOSBootVolume;
}
else
{
}
} else {
// Fetch the volume list from the device.
scanBootVolumes( biosdev, NULL );
// Look for a perfect match based on device and partition number.
for ( bvr1 = NULL, bvr = bvrChain; bvr; bvr = bvr->next )
{
if ( ( bvr->flags & kBVFlagNativeBoot ) == 0 ) continue;
for ( bvr1 = NULL, bvr = bvrChain; bvr; bvr = bvr->next ) {
if ( ( bvr->flags & kBVFlagNativeBoot ) == 0 ) {
continue;
}
bvr1 = bvr;
if ( bvr->part_no == partno ) break;
if ( bvr->part_no == partno ) {
break;
}
}
}
// Returns length of the out string
int getDeviceDescription(BVRef bvr, char *str)
{
if(!str)
return 0;
if(!str) {
return 0;
}
*str = '\0';
if (bvr)
{
const struct devsw *dp = devsw;
while(dp->name && bvr->biosdev >= dp->biosdev)
dp++;
if (bvr) {
const struct devsw *dp = devsw;
while(dp->name && bvr->biosdev >= dp->biosdev) {
dp++;
}
dp--;
if (dp->name)
return sprintf(str, "%s(%d,%d)", dp->name, bvr->biosdev - dp->biosdev, bvr->part_no);
if (dp->name) {
return sprintf(str, "%s(%d,%d)", dp->name, bvr->biosdev - dp->biosdev, bvr->part_no);
}
}
return 0;
branches/chucko/i386/libsaio/load.c
4141
4242
4343
44
4544
45
46
47
4648
4749
48
49
50
51
52
53
54
50
51
52
53
54
55
5556
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
57
58
59
60
61
62
63
64
7765
78
79
80
81
82
83
84
85
86
87
88
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
8990
9091
92
93
94
9195
9296
93
94
95
96
97
98
99
100
101
102
103
104
105
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
106122
107123
124
108125
109126
110127
111128
129
112130
113131
132
114133
115
134
135
116136
137
138
117139
118140
119141
120142
143
121144
122145
146
123147
148
124149
125150
126151
127
128
129152
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
153
154
162155
163
164
165
166
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
167183
168
184
169185
170
171
172
173
174
175
176
177
178
179
180
181
182
183
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
184204
185205
186206
187
188
189
190
191
192
207
208
209
210
211
212
213
214
193215
194
216
195217
196218
197
198219
220
221
222
223
199224
200225
201
202
203
204
205
206
207
208
209
210
211
212
213
214
226
227
228
215229
216
230
231
232
233
234
235
236
237
217238
218239
219240
220241
221242
222243
223
224
225
226
227
244
245
246
228247
229
230
231
232
233
234
235
236
248
237249
250
251
252
253
254
255
238256
239
240
241
242
243
244
257
258
259
260
261
245262
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
263
264
265
266
267
269268
270
271
269
270
271
272
272273
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
274292
275293
294
295
276296
277297
278
279
298
280299
281300
282301
283
284
285
286
302
303
287304
288305
289306
......
291308
292309
293310
294
295
296
297
311
298312
299313
300314
......
305319
306320
307321
322
323
324
308325
309326
310
311
312
313
327
328
329
314330
315
316
331
332
333
334
317335
318
319
320
336
337
338
321339
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
338356
339
340
341
357
358
359
342360
bool gHaveKernelCache;/* XXX aserebln: uninitialized? and only set to true, never to false */
cpu_type_t archCpuType=CPU_TYPE_I386;
// Public Functions
//==============================================================================
// Public function.
long ThinFatFile(void **binary, unsigned long *length)
{
unsigned long nfat, swapped, size = 0;
struct fat_header *fhp = (struct fat_header *)*binary;
struct fat_arch *fap =
(struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header));
cpu_type_t fapcputype;
uint32_t fapoffset;
uint32_t fapsize;
unsigned long nfat, swapped, size = 0;
struct fat_header *fhp = (struct fat_header *)*binary;
struct fat_arch *fap = (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header));
cpu_type_t fapcputype;
uint32_t fapoffset;
uint32_t fapsize;
if (fhp->magic == FAT_MAGIC) {
nfat = fhp->nfat_arch;
swapped = 0;
} else if (fhp->magic == FAT_CIGAM) {
nfat = OSSwapInt32(fhp->nfat_arch);
swapped = 1;
} else {
return -1;
}
for (; nfat > 0; nfat--, fap++) {
if (swapped) {
fapcputype = OSSwapInt32(fap->cputype);
fapoffset = OSSwapInt32(fap->offset);
fapsize = OSSwapInt32(fap->size);
}
else
{
fapcputype = fap->cputype;
fapoffset = fap->offset;
fapsize = fap->size;
if (fhp->magic == FAT_MAGIC) {
nfat = fhp->nfat_arch;
swapped = 0;
} else if (fhp->magic == FAT_CIGAM) {
nfat = OSSwapInt32(fhp->nfat_arch);
swapped = 1;
} else {
return -1;
}
if (fapcputype == archCpuType) {
*binary = (void *) ((unsigned long)*binary + fapoffset);
size = fapsize;
break;
}
}
if (length != 0) *length = size;
return 0;
for (; nfat > 0; nfat--, fap++) {
if (swapped) {
fapcputype = OSSwapInt32(fap->cputype);
fapoffset = OSSwapInt32(fap->offset);
fapsize = OSSwapInt32(fap->size);
} else {
fapcputype = fap->cputype;
fapoffset = fap->offset;
fapsize = fap->size;
}
if (fapcputype == archCpuType) {
*binary = (void *) ((unsigned long)*binary + fapoffset);
size = fapsize;
break;
}
}
if (length != 0) {
*length = size;
}
return 0;
}
//==============================================================================
long DecodeMachO(void *binary, entry_t *rentry, char **raddr, int *rsize)
{
struct mach_header *mH;
unsigned long ncmds, cmdBase, cmd, cmdsize, cmdstart;
// long headerBase, headerAddr, headerSize;
unsigned int vmaddr = ~0;
unsigned int vmend = 0;
unsigned long cnt;
long ret = -1;
unsigned int entry = 0;
gBinaryAddress = (unsigned long)binary;
mH = (struct mach_header *)(gBinaryAddress);
switch (archCpuType)
struct mach_header *mH;
unsigned long ncmds, cmdBase, cmd, cmdsize, cmdstart;
// long headerBase, headerAddr, headerSize;
unsigned int vmaddr = ~0;
unsigned int vmend = 0;
unsigned long cnt;
long ret = -1;
unsigned int entry = 0;
gBinaryAddress = (unsigned long)binary;
mH = (struct mach_header *)(gBinaryAddress);
#if DEBUG
printf("magic: %x\n", (unsigned)mH->magic);
printf("cputype: %x\n", (unsigned)mH->cputype);
printf("cpusubtype: %x\n", (unsigned)mH->cpusubtype);
printf("filetype: %x\n", (unsigned)mH->filetype);
printf("ncmds: %x\n", (unsigned)mH->ncmds);
printf("sizeofcmds: %x\n", (unsigned)mH->sizeofcmds);
printf("flags: %x\n", (unsigned)mH->flags);
getchar();
#endif
switch (archCpuType)
{
case CPU_TYPE_I386:
if (mH->magic != MH_MAGIC) {
error("Mach-O file has bad magic number\n");
return -1;
}
cmdstart = (unsigned long)gBinaryAddress + sizeof(struct mach_header);
break;
case CPU_TYPE_X86_64:
if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC)
if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC) {
return -1;
}
if (mH->magic != MH_MAGIC_64) {
error("Mach-O file has bad magic number\n");
return -1;
}
cmdstart = (unsigned long)gBinaryAddress + sizeof(struct mach_header_64);
break;
default:
error("Unknown CPU type\n");
return -1;
}
cmdBase = cmdstart;
#if DEBUG
printf("magic: %x\n", (unsigned)mH->magic);
printf("cputype: %x\n", (unsigned)mH->cputype);
printf("cpusubtype: %x\n", (unsigned)mH->cpusubtype);
printf("filetype: %x\n", (unsigned)mH->filetype);
printf("ncmds: %x\n", (unsigned)mH->ncmds);
printf("sizeofcmds: %x\n", (unsigned)mH->sizeofcmds);
printf("flags: %x\n", (unsigned)mH->flags);
getchar();
#endif
ncmds = mH->ncmds;
for (cnt = 0; cnt < ncmds; cnt++) {
cmd = ((long *)cmdBase)[0];
cmdsize = ((long *)cmdBase)[1];
unsigned int load_addr;
unsigned int load_size;
switch (cmd) {
case LC_SEGMENT_64:
case LC_SEGMENT:
ret = DecodeSegment(cmdBase, &load_addr, &load_size);
if (ret == 0 && load_size != 0 && load_addr >= KERNEL_ADDR) {
vmaddr = MIN(vmaddr, load_addr);
vmend = MAX(vmend, load_addr + load_size);
}
break;
case LC_UNIXTHREAD:
ret = DecodeUnixThread(cmdBase, &entry);
break;
cmdBase = cmdstart;
ncmds = mH->ncmds;
case LC_SYMTAB:
break;
default:
for (cnt = 0; cnt < ncmds; cnt++)
{
cmd = ((long *)cmdBase)[0];
cmdsize = ((long *)cmdBase)[1];
unsigned int load_addr;
unsigned int load_size;
switch (cmd) {
case LC_SEGMENT_64:
case LC_SEGMENT:
ret = DecodeSegment(cmdBase, &load_addr, &load_size);
if (ret == 0 && load_size != 0 && load_addr >= KERNEL_ADDR)
{
vmaddr = MIN(vmaddr, load_addr);
vmend = MAX(vmend, load_addr + load_size);
}
break;
case LC_UNIXTHREAD:
ret = DecodeUnixThread(cmdBase, &entry);
break;
case LC_SYMTAB:
break;
default:
#if NOTDEF
printf("Ignoring cmd type %d.\n", (unsigned)cmd);
printf("Ignoring cmd type %d.\n", (unsigned)cmd);
#endif
break;
}
if (ret != 0) return -1;
cmdBase += cmdsize;
}
*rentry = (entry_t)( (unsigned long) entry & 0x3fffffff );
*rsize = vmend - vmaddr;
*raddr = (char *)vmaddr;
cmdBase = cmdstart;
for (cnt = 0; cnt < ncmds; cnt++) {
break;
}
if (ret != 0) {
return -1;
}
cmdBase += cmdsize;
}
*rentry = (entry_t)( (unsigned long) entry & 0x3fffffff );
*rsize = vmend - vmaddr;
*raddr = (char *)vmaddr;
cmdBase = cmdstart;
for (cnt = 0; cnt < ncmds; cnt++) {
cmd = ((long *)cmdBase)[0];
cmdsize = ((long *)cmdBase)[1];
if(cmd==LC_SYMTAB)
if (DecodeSymbolTable(cmdBase)!=0)
return -1;
cmdBase += cmdsize;
}
if (cmd == LC_SYMTAB) {
if (DecodeSymbolTable(cmdBase) != 0) {
return -1;
}
}
cmdBase += cmdsize;
}
return ret;
return ret;
}
// Private Functions
//==============================================================================
// Private function.
static long DecodeSegment(long cmdBase, unsigned int *load_addr, unsigned int *load_size)
{
unsigned long vmaddr, fileaddr;
long vmsize, filesize;
char *segname;
if (((long *)cmdBase)[0]==LC_SEGMENT_64)
{
struct segment_command_64 *segCmd;
segCmd = (struct segment_command_64 *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
fileaddr = (gBinaryAddress + segCmd->fileoff);
filesize = segCmd->filesize;
char *segname;
long vmsize, filesize;
unsigned long vmaddr, fileaddr;
segname=segCmd->segname;
if (((long *)cmdBase)[0] == LC_SEGMENT_64) {
struct segment_command_64 *segCmd;
segCmd = (struct segment_command_64 *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
fileaddr = (gBinaryAddress + segCmd->fileoff);
filesize = segCmd->filesize;
segname = segCmd->segname;
#ifdef DEBUG
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize,
(unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
#endif
}
else
{
struct segment_command *segCmd;
#endif
} else {
struct segment_command *segCmd;
segCmd = (struct segment_command *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
fileaddr = (gBinaryAddress + segCmd->fileoff);
filesize = segCmd->filesize;
segname=segCmd->segname;
segCmd = (struct segment_command *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
fileaddr = (gBinaryAddress + segCmd->fileoff);
filesize = segCmd->filesize;
segname = segCmd->segname;
#ifdef DEBUG
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize,
(unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
#endif
}
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
#endif
}
if (vmsize == 0 || filesize == 0) {
*load_addr = ~0;
*load_size = 0;
return 0;
}
if (! ((vmaddr >= KERNEL_ADDR &&
(vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) ||
(vmaddr >= HIB_ADDR &&
(vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) {
stop("Kernel overflows available space");
}
if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0)))
gHaveKernelCache = true;
// Copy from file load area.
if (vmsize>0 && filesize>0)
bcopy((char *)fileaddr, (char *)vmaddr, vmsize>filesize?filesize:vmsize);
// Zero space at the end of the segment.
if (vmsize > filesize)
bzero((char *)(vmaddr + filesize), vmsize - filesize);
if (vmsize == 0 || filesize == 0) {
*load_addr = ~0;
*load_size = 0;
return 0;
}
*load_addr = vmaddr;
*load_size = vmsize;
if (! ((vmaddr >= KERNEL_ADDR && (vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) ||
(vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) {
stop("Kernel overflows available space");
}
return 0;
if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) {
gHaveKernelCache = true;
}
// Copy from file load area.
if (vmsize>0 && filesize > 0) {
bcopy((char *)fileaddr, (char *)vmaddr, vmsize > filesize ? filesize : vmsize);
}
// Zero space at the end of the segment.
if (vmsize > filesize) {
bzero((char *)(vmaddr + filesize), vmsize - filesize);
}
*load_addr = vmaddr;
*load_size = vmsize;
return 0;
}
//==============================================================================
static long DecodeUnixThread(long cmdBase, unsigned int *entry)
{
switch (archCpuType)
{
switch (archCpuType) {
case CPU_TYPE_I386:
{
i386_thread_state_t *i386ThreadState;
i386ThreadState = (i386_thread_state_t *)
(cmdBase + sizeof(struct thread_command) + 8);
i386ThreadState = (i386_thread_state_t *) (cmdBase + sizeof(struct thread_command) + 8);
*entry = i386ThreadState->eip;
return 0;
}
case CPU_TYPE_X86_64:
{
x86_thread_state64_t *x86_64ThreadState;
x86_64ThreadState = (x86_thread_state64_t *)
(cmdBase + sizeof(struct thread_command) + 8);
x86_64ThreadState = (x86_thread_state64_t *) (cmdBase + sizeof(struct thread_command) + 8);
*entry = x86_64ThreadState->rip;
return 0;
}
}
}
//==============================================================================
static long DecodeSymbolTable(long cmdBase)
{
struct symtab_command *symTab, *symTableSave;
long tmpAddr, symsSize, totalSize;
long gSymbolTableAddr;
long gSymbolTableSize;
long tmpAddr, symsSize, totalSize;
long gSymbolTableAddr;
long gSymbolTableSize;
symTab = (struct symtab_command *)cmdBase;
struct symtab_command *symTab, *symTableSave;
symTab = (struct symtab_command *)cmdBase;
#if DEBUG
printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n",
symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize);
getchar();
printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n", symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize);
getchar();
#endif
symsSize = symTab->stroff - symTab->symoff;
totalSize = symsSize + symTab->strsize;
gSymbolTableSize = totalSize + sizeof(struct symtab_command);
gSymbolTableAddr = AllocateKernelMemory(gSymbolTableSize);
// Add the SymTab to the memory-map.
AllocateMemoryRange("Kernel-__SYMTAB", gSymbolTableAddr, gSymbolTableSize, -1);
symTableSave = (struct symtab_command *)gSymbolTableAddr;
tmpAddr = gSymbolTableAddr + sizeof(struct symtab_command);
symTableSave->symoff = tmpAddr;
symTableSave->nsyms = symTab->nsyms;
symTableSave->stroff = tmpAddr + symsSize;
symTableSave->strsize = symTab->strsize;
symsSize = symTab->stroff - symTab->symoff;
totalSize = symsSize + symTab->strsize;
gSymbolTableSize = totalSize + sizeof(struct symtab_command);
gSymbolTableAddr = AllocateKernelMemory(gSymbolTableSize);
// Add the SymTab to the memory-map.
AllocateMemoryRange("Kernel-__SYMTAB", gSymbolTableAddr, gSymbolTableSize, -1);
symTableSave = (struct symtab_command *)gSymbolTableAddr;
tmpAddr = gSymbolTableAddr + sizeof(struct symtab_command);
symTableSave->symoff = tmpAddr;
symTableSave->nsyms = symTab->nsyms;
symTableSave->stroff = tmpAddr + symsSize;
symTableSave->strsize = symTab->strsize;
bcopy((char *)(gBinaryAddress + symTab->symoff),
(char *)tmpAddr, totalSize);
return 0;
bcopy((char *)(gBinaryAddress + symTab->symoff), (char *)tmpAddr, totalSize);
return 0;
}
branches/chucko/i386/libsaio/nvidia.h
7777
7878
7979
80
81
80
81
8282
8383
8484
85
86
85
86
8787
8888
8989
uint8_tsize;/* Size in multiples of 512 */
};
#define NV_PMC_OFFSET0x000000
#define NV_PMC_SIZE 0x2ffff
#define NV_PMC_OFFSET0x00000000
#define NV_PMC_SIZE 0x00001000 // 0x2ffff
#define NV_PDISPLAY_OFFSET0x610000
#define NV_PDISPLAY_SIZE0x10000
#define NV_PROM_OFFSET0x300000
#define NV_PROM_SIZE0x0000ffff
#define NV_PROM_OFFSET0x00300000
#define NV_PROM_SIZE0x00010000
#define NV_PRAMIN_OFFSET0x00700000
#define NV_PRAMIN_SIZE0x00100000
#define NV04_PFB_FIFO_DATA0x0010020c
branches/chucko/i386/libsaio/sl.h
3939
4040
4141
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
5858
5959
6060
// File Permissions and Types
enum {
kPermOtherExecute = 1 << 0,
kPermOtherWrite = 1 << 1,
kPermOtherRead = 1 << 2,
kPermGroupExecute = 1 << 3,
kPermGroupWrite = 1 << 4,
kPermGroupRead = 1 << 5,
kPermOwnerExecute = 1 << 6,
kPermOwnerWrite = 1 << 7,
kPermOwnerRead = 1 << 8,
kPermMask = 0x1FF,
kOwnerNotRoot = 1 << 9,
kFileTypeUnknown = 0x0 << 16,
kFileTypeFlat = 0x1 << 16,
kFileTypeDirectory = 0x2 << 16,
kFileTypeLink = 0x3 << 16,
kFileTypeMask = 0x3 << 16
kPermOtherExecute = 1 << 0,
kPermOtherWrite = 1 << 1,
kPermOtherRead = 1 << 2,
kPermGroupExecute = 1 << 3,
kPermGroupWrite = 1 << 4,
kPermGroupRead = 1 << 5,
kPermOwnerExecute = 1 << 6,
kPermOwnerWrite = 1 << 7,
kPermOwnerRead = 1 << 8,
kPermMask = 0x1FF,
kOwnerNotRoot = 1 << 9,
kFileTypeUnknown = 0x0 << 16,
kFileTypeFlat = 0x1 << 16,
kFileTypeDirectory = 0x2 << 16,
kFileTypeLink = 0x3 << 16,
kFileTypeMask = 0x3 << 16
};
#define Seek(c, p) diskSeek(c, p);
branches/chucko/i386/libsaio/cpu.c
415415
416416
417417
418
419
418
420419
421420
422421
......
648647
649648
650649
651
652
650
653651
654652
655653
tscFrequency = measure_tsc_frequency();
/* if usual method failed */
if ( tscFrequency < 1000 )//TEST
{
if ( tscFrequency < 1000 ) { //TEST
tscFrequency = timeRDTSC() * 20;
}
fsbFrequency = 0;
}
#if 0
if (!fsbFrequency)
{
if (!fsbFrequency) {
fsbFrequency = (DEFAULT_FSB * 1000);
cpuFrequency = tscFrequency;
DBG("0 ! using the default value for FSB !\n");
branches/chucko/i386/libsaio/platform.h
177177
178178
179179
180
180
181181
182182
183183
intDIMM[MAX_RAM_SLOTS];// Information and SPD mapping for each slot
} DMI;
uint8_tType; // System Type: 1=Desktop, 2=Portable... according ACPI2.0 (FACP: PM_Profile)
uint8_tType;// System Type: 1=Desktop, 2=Portable... according ACPI2.0 (FACP: PM_Profile)
uint8_t*UUID;
} PlatformInfo_t;
branches/chucko/i386/libsaio/disk.c
222222
223223
224224
225
226
227
225228
226229
227230
{ 0x00, 0 }
};
//==============================================================================
static const char * bios_error(int errnum)
{
static char errorstr[] = "Error 0x00";
branches/chucko/i386/libsaio/openbsd.c
33
44
55
6
67
78
89
9
10
1011
1112
1213
#include "openbsd.h"
#define OpenBSDProbeSize2048
#define DISKMAGIC((uint32_t)0x82564557)/* The disk magic number */
bool OpenBSDProbe (const void *buf)
{
return (OSReadLittleInt32(buf+0x200,0)==0x82564557);
return (OSReadLittleInt32(buf+0x200,0) == DISKMAGIC);
}
void OpenBSDGetDescription(CICell ih, char *str, long strMaxLen)
{
branches/chucko/i386/libsaio/smbios.c
722722
723723
724724
725
726
725
727726
728727
729728
730729
731730
732731
733
734
735
736
732
733
737734
738735
739
740
741
742
743
736
737
744738
745739
746740
......
751745
752746
753747
754
755
748
756749
757750
758751
......
766759
767760
768761
769
770
762
771763
772764
773765
774
775
766
776767
777768
778769
......
780771
781772
782773
783
784
774
785775
786776
787777
788
789
778
790779
791780
792781
......
805794
806795
807796
808
809
797
810798
811799
812800
813
814
801
815802
816803
817804
......
832819
833820
834821
835
836
837
838
822
823
839824
840825
841826
842827
843
844
828
845829
846830
847831
......
852836
853837
854838
855
856
839
857840
858841
859842
860
861
843
862844
863845
864846
865
866
867
868
847
848
869849
870850
871851
......
881861
882862
883863
884
885
886
887
864
865
888866
889867
890868
......
893871
894872
895873
896
897
874
898875
899876
900877
......
913890
914891
915892
916
917
893
918894
919895
920896
......
1020996
1021997
1022998
1023
1024
999
10251000
1026
1027
1001
10281002
10291003
10301004
......
10321006
10331007
10341008
1035
1036
1009
10371010
10381011
10391012
10401013
10411014
1042
1043
1044
1045
1015
1016
10461017
10471018
10481019
10491020
10501021
1051
1052
1022
10531023
10541024
10551025
1056
1057
1026
10581027
10591028
10601029
1061
1062
1063
1030
10641031
10651032
10661033
1067
1068
1034
10691035
10701036
10711037
......
10771043
10781044
10791045
1080
1081
1046
10821047
10831048
10841049
......
10901055
10911056
10921057
1093
1094
1095
1096
1058
1059
10971060
10981061
10991062
......
11141077
11151078
11161079
1117
1118
1080
11191081
11201082
11211083
......
11451107
11461108
11471109
1148
1149
1110
11501111
11511112
11521113
......
11551116
11561117
11571118
1158
1159
1119
11601120
11611121
11621122
11631123
11641124
11651125
1166
1167
1126
11681127
11691128
11701129
1171
1172
1130
11731131
11741132
11751133
11761134
1177
1178
1135
11791136
11801137
11811138
......
11901147
11911148
11921149
1193
1194
1150
11951151
11961152
11971153
11981154
11991155
12001156
1201
1202
1157
12031158
12041159
12051160
12061161
1207
1208
1162
12091163
12101164
12111165
......
12221176
12231177
12241178
1225
1226
1179
12271180
12281181
12291182
......
12501203
12511204
12521205
1253
1254
1206
12551207
12561208
12571209
......
12761228
12771229
12781230
1279
1280
1231
12811232
1282
1283
1233
12841234
12851235
12861236
......
13381288
13391289
13401290
1341
1342
1291
13431292
13441293
1345
1346
1294
13471295
13481296
13491297
......
13551303
13561304
13571305
1358
1359
1306
13601307
13611308
13621309
int len;
char key[24];
if (current != structHeader->handle)
{
if (current != structHeader->handle) {
idx++;
current = structHeader->handle;
}
sprintf(key, "%s%d", keyString, idx);
if (value)
{
if (getIntForKey(key, (int *)&(value->dword), SMBPlist))
{
if (value) {
if (getIntForKey(key, (int *)&(value->dword), SMBPlist)) {
return true;
}
}
else
{
if (getValueForKey(key, string, &len, SMBPlist))
{
} else {
if (getValueForKey(key, string, &len, SMBPlist)) {
return true;
}
}
{
uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
if (!field)
{
if (!field) {
return NULL;
}
{
int strSize;
if (!field)
{
if (!field) {
return;
}
if (!string)
{
if (!string) {
*field = 0;
return;
}
strSize = strlen(string);
// remove any spaces found at the end
while ((strSize != 0) && (string[strSize - 1] == ' '))
{
while ((strSize != 0) && (string[strSize - 1] == ' ')) {
strSize--;
}
if (strSize == 0)
{
if (strSize == 0) {
*field = 0;
return;
}
bool parsed;
int val;
if (numOfSetters <= idx)
{
if (numOfSetters <= idx) {
return false;
}
switch (SMBSetters[idx].valueType)
{
switch (SMBSetters[idx].valueType) {
case kSMBString:
{
if (SMBSetters[idx].keyString)
}
}
if (SMBSetters[idx].getSMBValue)
{
if (SMBSetters[idx].getSMBValue((returnType *)&string))
{
if (SMBSetters[idx].getSMBValue) {
if (SMBSetters[idx].getSMBValue((returnType *)&string)) {
break;
}
}
// if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) Bungo
if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue))
{
if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue)) {
string = *(SMBSetters[idx].defaultValue);
break;
}
case kSMBWord:
case kSMBDWord:
//case kSMBQWord:
if (SMBSetters[idx].keyString)
{
if (SMBSetters[idx].keyString) {
parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
if (!parsed)
{
if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
{
if (structPtr->orig->type == kSMBTypeMemoryDevice) { // MemoryDevice only
parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
}
}
if (parsed)
{
switch (SMBSetters[idx].valueType)
{
if (parsed) {
switch (SMBSetters[idx].valueType) {
case kSMBByte:
value->byte = (uint8_t)val;
break;
}
}
if (SMBSetters[idx].getSMBValue)
{
if (SMBSetters[idx].getSMBValue(value))
{
if (SMBSetters[idx].getSMBValue) {
if (SMBSetters[idx].getSMBValue(value)) {
return true;
}
}
if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue))
{
// value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo
switch (SMBSetters[idx].valueType)
{
switch (SMBSetters[idx].valueType) {
case kSMBByte:
value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue);
break;
}
// if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified"
if ((SMBSetters[idx].valueType == kSMBString) && string)
{
if ((SMBSetters[idx].valueType == kSMBString) && string) {
setSMBStringForField(structPtr->new, string, &value->byte);
}
return true;
/* http://forge.voodooprojects.org/p/chameleon/issues/361/ */
bool forceFullMemInfo = false;
if (structPtr->orig->type == kSMBTypeMemoryDevice)
{
if (structPtr->orig->type == kSMBTypeMemoryDevice) {
getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig);
if (forceFullMemInfo)
{
if (forceFullMemInfo) {
structPtr->orig->length = 27;
}
}
stringIndex = 1;
stringsSize = 0;
if (handle < structPtr->orig->handle)
{
if (handle < structPtr->orig->handle) {
handle = structPtr->orig->handle;
}
memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
for (i = 0; i < numOfSetters; i++)
{
if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))
{
for (i = 0; i < numOfSetters; i++) {
if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length)) {
setterFound = true;
setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
}
}
if (setterFound)
{
if (setterFound) {
ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
for (; ((uint16_t *)ptr)[0] != 0; ptr++);
if (((uint16_t *)ptr)[0] == 0)
{
if (((uint16_t *)ptr)[0] == 0) {
ptr += 2;
}
structSize = ptr - (uint8_t *)structPtr->new;
}
else
{
} else {
ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
for (; ((uint16_t *)ptr)[0] != 0; ptr++);
if (((uint16_t *)ptr)[0] == 0)
{
if (((uint16_t *)ptr)[0] == 0) {
ptr += 2;
}
tableLength += structSize;
if (structSize > maxStructSize)
{
if (structSize > maxStructSize) {
maxStructSize = structSize;
}
uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
structPtr->orig = (SMBStructHeader *)ptr;
for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)
{
switch (structPtr->orig->type)
{
for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));) {
switch (structPtr->orig->type) {
/* Skip all Apple Specific Structures */
case kSMBTypeFirmwareVolume:
case kSMBTypeMemorySPD:
ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
for (; ((uint16_t *)ptr)[0] != 0; ptr++);
if (((uint16_t *)ptr)[0] == 0)
{
if (((uint16_t *)ptr)[0] == 0) {
ptr += 2;
}
ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
for (; ((uint16_t *)ptr)[0] != 0; ptr++);
if (((uint16_t *)ptr)[0] == 0)
{
if (((uint16_t *)ptr)[0] == 0) {
ptr += 2;
}
ptr = ((SMBSystemInformation *)structHeader)->uuid;
if (!sysId || !ret) // no or bad custom UUID,...
{
if (!sysId || !ret) { // no or bad custom UUID,...
sysId = 0;
ret = ((SMBSystemInformation *)structHeader)->uuid; // ...try bios dmi info UUID extraction
}
for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++) // check if empty or setable, means: no uuid present
{
if (ret[i] != 0x00)
{
if (ret[i] != 0x00) {
isZero = 0;
}
if (ret[i] != 0xff)
{
if (ret[i] != 0xff) {
isOnes = 0;
}
}
if (isZero || isOnes) // if empty or setable...
{
if (isZero || isOnes) { // if empty or setable...
verbose("No UUID present in SMBIOS System Information Table\n");
ret = FixedUUID; // ...set a fixed value for system-id = 000102030405060708090A0B0C0D0E0F
}
uint8_t *buffer;
// bool setSMB = true; Bungo
if (!origeps)
{
if (!origeps) {
return;
}
neweps = origeps;
structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
if (!structPtr)
{
if (!structPtr) {
return;
}
buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);
if (!buffer)
{
if (!buffer) {
free(structPtr);
return;
}
setupNewSMBIOSTable(origeps, structPtr);
neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
if (!neweps)
{
if (!neweps) {
free(buffer);
free(structPtr);
return;
neweps->dmi.structureCount= structureCount;
neweps->dmi.bcdRevision= 0x24;
if (!neweps->dmi.tableAddress)
{
if (!neweps->dmi.tableAddress) {
free(buffer);
free(structPtr);
return;
void *getSmbios(int which)
{
switch (which)
{
switch (which) {
case SMBIOS_ORIGINAL:
if (!origeps)
{
if (!origeps) {
origeps = getAddressOfSmbiosTable();
}
return origeps;
case kSMBTypeMemoryDevice:
Platform.DMI.CntMemorySlots++;
if (((SMBMemoryDevice *)structHeader)->memorySize != 0)
{
if (((SMBMemoryDevice *)structHeader)->memorySize != 0){
Platform.DMI.MemoryModules++;
}
if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)
{
if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0){
Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
}
dimmnbr++;
structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
if (((uint16_t *)structPtr)[0] == 0)
{
if (((uint16_t *)structPtr)[0] == 0) {
structPtr += 2;
}
branches/chucko/i386/libsaio/openbsd.h
1
2
3
14
2
5
6
7
#ifndef __LIBSAIO_OPENBSD_H
#define __LIBSAIO_OPENBSD_H
extern bool OpenBSDProbe (const void *buf);
extern void OpenBSDGetDescription(CICell ih, char *str, long strMaxLen);
extern void OpenBSDGetDescription(CICell ih, char *str, long strMaxLen);
#endif /* !__LIBSAIO_OPENBSD_H */
branches/chucko/i386/libsaio/smbios_decode.c
329329
330330
331331
332
333
332
334333
335334
336335
ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
for (; ((uint16_t *)ptr)[0] != 0; ptr++);
if (((uint16_t *)ptr)[0] == 0)
{
if (((uint16_t *)ptr)[0] == 0) {
ptr += 2;
}
branches/chucko/i386/libsaio/nvidia_helper.c
1515
1616
1717
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
4747
4848
4949
......
110110
111111
112112
113
113
114114
115115
116116
NVIDIA card injection usage e.g (to be placed in the boot.plist):
<key>NVIDIA</key>
<array>
<dict>
<key>Chipset Name</key>
<string>Quadro FX 380</string>
<key>IOPCIPrimaryMatch</key>
<string>0x10DE0658</string>
<key>VRam Size</key>
<string>256</string>
</dict>
<dict>
<key>Chipset Name</key>
<string>YOUR_CARD_NAME</string>
<key>IOPCIPrimaryMatch</key>
<string>YOUR_CARD_ID</string>
<key>IOPCISubDevId</key>
<string>YOUR_CARD_SUB_ID(if necessary)</string>
<key>VRam Size</key>
<string>YOUR_CARD_VRAM_SIZE</string>
</dict>
<dict>
<key>Chipset Name</key>
<string>YOUR_SECOND_CARD_NAME</string>
<key>IOPCIPrimaryMatch</key>
<string>YOUR_SECOND_CARD_ID</string>
<key>IOPCISubDevId</key>
<string>YOUR_SECOND_CARD_SUB_ID(if necessary)</string>
<key>VRam Size</key>
<string>YOUR_SECOND_CARD_VRAM_SIZE</string>
</dict>
<array>
<dict>
<key>Chipset Name</key>
<string>Quadro FX 380</string>
<key>IOPCIPrimaryMatch</key>
<string>0x10DE0658</string>
<key>VRam Size</key>
<string>256</string>
</dict>
<dict>
<key>Chipset Name</key>
<string>YOUR_CARD_NAME</string>
<key>IOPCIPrimaryMatch</key>
<string>YOUR_CARD_ID</string>
<key>IOPCISubDevId</key>
<string>YOUR_CARD_SUB_ID(if necessary)</string>
<key>VRam Size</key>
<string>YOUR_CARD_VRAM_SIZE</string>
</dict>
<dict>
<key>Chipset Name</key>
<string>YOUR_SECOND_CARD_NAME</string>
<key>IOPCIPrimaryMatch</key>
<string>YOUR_SECOND_CARD_ID</string>
<key>IOPCISubDevId</key>
<string>YOUR_SECOND_CARD_SUB_ID(if necessary)</string>
<key>VRam Size</key>
<string>YOUR_SECOND_CARD_VRAM_SIZE</string>
</dict>
.
.
.
unsigned inti, count;
TagPtr NVDIATag;
char *model_name = NULL, *match_id = NULL, *sub_id = NULL, *vram_size = NULL;
uint32_t dev_id = 0, subdev_id = 0;
uint32_t dev_id = 0, subdev_id = 0;
uint64_t VramSize = 0;
if ((NVDIATag = XMLCastArray(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"NVIDIA"))))
branches/chucko/i386/libsaio/freebsd.h
1
2
3
14
2
5
6
7
#ifndef __LIBSAIO_FREEBSD_H
#define __LIBSAIO_FREEBSD_H
extern bool FreeBSDProbe (const void *buf);
extern void FreeBSDGetDescription(CICell ih, char *str, long strMaxLen);
extern void FreeBSDGetDescription(CICell ih, char *str, long strMaxLen);
#endif /* !__LIBSAIO_FREEBSD_H */
branches/chucko/i386/libsaio/convert.c
9393
9494
9595
96
97
98
99
100
96
97
98
99
101100
102101
103102
{
hexNibble = hexStr[hexStrIdx];
// ignore all chars except valid hex numbers
if ( (hexNibble >= '0' && hexNibble <= '9') ||
(hexNibble >= 'A' && hexNibble <= 'F') ||
(hexNibble >= 'a' && hexNibble <= 'f') )
{
// ignore all chars except valid hex numbers
if ( (hexNibble >= '0' && hexNibble <= '9') ||
(hexNibble >= 'A' && hexNibble <= 'F') ||
(hexNibble >= 'a' && hexNibble <= 'f') ) {
hexByte[hexNibbleIdx++] = hexNibble;
// found both two nibbles, convert to binary
branches/chucko/i386/libsaio/pci.h
3030
3131
3232
33
3334
3435
36
3537
3638
3739
......
5254
5355
5456
57
58
5559
5660
5761
58
62
5963
64
65
6066
6167
6268
......
6571
6672
6773
68
69
70
71
72
73
74
75
76
77
78
79
7480
7581
7682
} pci_dev_t;
typedef struct pci_dt_t {
uint8_t*regs;
pci_dev_tdev;
uint16_tdevfn; /* encoded device & function index */
uint16_tvendor_id; /* Specifies a vendor ID. The PCI bus configuration code obtains this
vendor ID from the vendor ID device register. */
uint16_tdevice_id; /* Specifies a device ID that identifies the specific device. The PCI
uint16_tclass_id; /* Specifies a class code. This member is a data structure that stores information related to the device's class code device register. */
//uint16_t subclass_id; /* A read-only register that specifies the specific function the device performs. */
struct pci_dt_t*parent;
struct pci_dt_t*children;
struct pci_dt_t*next;
} pci_dt_t;
} pci_dt_t; // Info
/* Have pci_addr in the same format as the values written to 0xcf8
* so register accesses can be made easy. */
#define PCIADDR(bus, dev, func) ((1 << 31) | (bus << 16) | (dev << 11) | (func << 8))
#define PCI_ADDR_REG0xcf8
#define PCI_DATA_REG0xcfc
extern uint8_tpci_config_read8(uint32_t, uint8_t);
extern uint16_tpci_config_read16(uint32_t, uint8_t);
extern uint32_tpci_config_read32(uint32_t, uint8_t);
extern voidpci_config_write8(uint32_t, uint8_t, uint8_t);
extern voidpci_config_write16(uint32_t, uint8_t, uint16_t);
extern voidpci_config_write32(uint32_t, uint8_t, uint32_t);
extern char*get_pci_dev_path(pci_dt_t *);
extern voidbuild_pci_dt(void);
extern voiddump_pci_dt(pci_dt_t *);
extern voidpci_config_write8(uint32_t, uint8_t, uint8_t);
extern voidpci_config_write16(uint32_t, uint8_t, uint16_t);
extern voidpci_config_write32(uint32_t, uint8_t, uint32_t);
extern char*get_pci_dev_path(pci_dt_t *);
extern voidbuild_pci_dt(void);
extern voiddump_pci_dt(pci_dt_t *);
/* Option ROM header */
typedef struct {
branches/chucko/i386/libsaio/msdos.c
130130
131131
132132
133
133
134134
135135
136136
......
188188
189189
190190
191
192
193
191
194192
195193
196194
......
775773
776774
777775
778
776
779777
780778
781779
782780
783781
784782
785
786
783
787784
788785
789786
......
797794
798795
799796
800
801
797
802798
803799
804800
......
840836
841837
842838
843
844
839
845840
846841
847842
......
936931
937932
938933
939
940
934
941935
942936
943937
......
946940
947941
948942
949
943
950944
951945
952946
......
969963
970964
971965
972
973
974
966
975967
976968
977969
......
989981
990982
991983
992
993
984
994985
995986
996987
997
988
998989
999990
1000991
if (!memcmp((char *)((struct extboot *)bsp->bs50.bsExt)->exFileSysType, "FAT12 ", 8))
return 12;
}
return 0;
}
free (buf);
return -1;
}
if (OSSwapLittleToHostInt16(b50->bpbRootDirEnts) == 0)
{
/* It's FAT32 */
if (OSSwapLittleToHostInt16(b50->bpbRootDirEnts) == 0) { /* It's FAT32 */
if (memcmp(((struct extboot *)bsp->bs710.bsExt)->exFileSysType, "FAT32 ", 8))
{
free (buf);
char *ptr = (char *)base;
struct direntry *dirp;
uint64_t i;
char devStr[12];
char devStr[12];
if (MSDOSInitPartition (ih)<0)
return -1;
if (filePath[0] == '/')
filePath++;
buf = malloc(msdosclustersize);
if (!buf)
{
if (!buf) {
return -1;
}
dirp = getdirpfrompath (ih, filePath, buf);
if (msdosfatbits == 32)
cluster |= ((uint32_t)OSReadLittleInt16 ((dirp->deHighClust),0)) <<16;
size = (uint32_t)OSReadLittleInt32 ((dirp->deFileSize),0);
if (size<=offset)
{
if (size<=offset) {
free (buf);
return -1;
}
if (filePath[0] == '/')
filePath++;
buf = malloc(msdosclustersize);
if (!buf)
{
if (!buf) {
return -1;
}
dirp = getdirpfrompath (ih, filePath, buf);
initRoot (&st);
st.buf = malloc(msdosclustersize);
if (!st.buf)
{
if (!st.buf) {
return;
}
while ((dirp = getnextdirent (ih, vfatlabel, &st)))
labelfound = 1;
break;
}
free(st.buf);
if (vfatlabel[0] && labelfound)
union bootsector *bsp = (union bootsector *)buf;
Seek(ih, 0);
Read(ih, (long)buf, 512);
if (msdosfatbits == 32)
{
/* It's FAT32 */
if (msdosfatbits == 32) { /* It's FAT32 */
strncpy((char *)label, (char *)((struct extboot *)bsp->bs710.bsExt)->exVolumeLabel, LABEL_LENGTH);
}
else if (msdosfatbits == 16)
MSDOSGetUUID(CICell ih, char *uuidStr)
{
char *buf = malloc (512);
if (!buf)
{
if (!buf) {
return -1;
}
union bootsector *bsp = (union bootsector *)buf;
if (MSDOSInitPartition (ih)<0)
{
free (buf);
branches/chucko/i386/libsaio/md5c.c
11
2
2
33
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
432
533
634
......
3563
3664
3765
66
67
3868
3969
4070
4171
4272
4373
44
74
75
76
77
4578
4679
4780
4881
4982
50
83
84
85
5186
5287
53
54
55
56
88
89
90
91
5792
5893
5994
6095
6196
97
6298
6399
64100
65101
66102
103
67104
68105
69106
70107
71108
109
72110
73111
74112
......
79117
80118
81119
82
83
120
84121
85122
86
87123
88124
89
125
90126
91127
92128
......
115151
116152
117153
118
119
154
120155
156
157
121158
122159
123160
124161
125162
163
126164
127165
128166
129167
130168
131
169
132170
133
171
134172
173
174
135175
136
137
138176
139177
140178
......
227265
228266
229267
230
268
231269
232270
233271
......
255293
256294
257295
258
296
259297
260298
261299
/*
* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
* Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
* MD5.C - RSA Data Security, Inc., MD5 message-digest algorithm
*
* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
* rights reserved.
*
#define Encode memcpy
#define Decode memcpy
//------------------------------------------------------------------------------
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/* F, G, H and I are basic MD5 functions. */
//------------------------------------------------------------------------------
// F, G, H and I are basic MD5 functions.
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits. */
//------------------------------------------------------------------------------
// ROTATE_LEFT rotates x left n bits.
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/*
* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
* Rotation is separate from addition to prevent recomputation.
*/
//------------------------------------------------------------------------------
// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
// Rotation is separate from addition to prevent recomputation.
#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
void
MD5Init (context)
void MD5Init (context)
MD5_CTX *context;
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants. */
// Load magic initialization constants.
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
if ((context->count[0] += ((u_int32_t)inputLen << 3))
< ((u_int32_t)inputLen << 3))
if ((context->count[0] += ((u_int32_t)inputLen << 3)) < ((u_int32_t)inputLen << 3)) {
context->count[1]++;
}
context->count[1] += ((u_int32_t)inputLen >> 29);
partLen = 64 - index;
/* Transform as many times as possible. */
if (inputLen >= partLen) {
memcpy((void *)&context->buffer[index], (const void *)input,
partLen);
MD5Transform (context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
for (i = partLen; i + 63 < inputLen; i += 64) {
MD5Transform (context->state, &((const unsigned char *)input)[i]);
}
index = 0;
} else {
i = 0;
}
else
i = 0;
/* Buffer remaining input */
memcpy ((void *)&context->buffer[index], (const void *)&((const unsigned char*)input)[i],
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
GG (d, a, b, c, x[10], S22, 0x02441453); /* 22 */
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
HH (b, c, d, a, x[ 6], S34, 0x04881d05); /* 44 */
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
branches/chucko/i386/libsaio/smbios_getters.c
2121
2222
2323
24
25
26
27
24
25
2826
2927
3028
......
5048
5149
5250
53
54
55
51
5652
5753
5854
......
120116
121117
122118
123
124
119
125120
126121
127122
......
371366
372367
373368
374
375
369
376370
377
378
371
379372
380373
381374
382375
383376
384
377
385378
386379
387380
......
399392
400393
401394
402
403
395
404396
405
406
397
407398
408399
409400
......
432423
433424
434425
435
436
426
437427
438428
439429
......
449439
450440
451441
452
453
442
454443
455
456
444
457445
458446
459447
460448
461449
462450
463
464
451
465452
466453
467454
......
474461
475462
476463
477
478
464
479465
480
481
466
482467
483468
484469
485470
486471
487472
488
489
473
490474
491475
492476
bool getProcessorInformationExternalClock(returnType *value)
{
if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
{
switch (Platform.CPU.Family)
{
if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel
switch (Platform.CPU.Family) {
case 0x06:
{
switch (Platform.CPU.Model)
default:
value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000);
}
}
else
{
} else {
value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000);
}
DBG("qpimult %d\n", qpimult);
qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000));
// Rek: rounding decimals to match original mac profile info
if (qpibusspeed%100 != 0)
{
if (qpibusspeed%100 != 0) {
qpibusspeed = ((qpibusspeed+50)/100)*100;
}
DBG("qpibusspeed %d\n", qpibusspeed);
intmap;
idx++;
if (idx < MAX_RAM_SLOTS)
{
if (idx < MAX_RAM_SLOTS) {
map = Platform.DMI.DIMM[idx];
if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
{
if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) {
DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
value->byte = Platform.RAM.DIMM[map].Type;
return true;
}
}
return false;
//value->byte = SMB_MEM_TYPE_DDR2;
//return true;
intmap;
idx++;
if (idx < MAX_RAM_SLOTS)
{
if (idx < MAX_RAM_SLOTS) {
map = Platform.DMI.DIMM[idx];
if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
{
if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0) {
DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
value->dword = Platform.RAM.DIMM[map].Frequency;
return true;
}
}
if (!bootInfo->memDetect)
{
if (!bootInfo->memDetect) {
return false;
}
value->string = NOT_AVAILABLE;
DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
if (idx < MAX_RAM_SLOTS)
{
if (idx < MAX_RAM_SLOTS) {
map = Platform.DMI.DIMM[idx];
if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
{
if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) {
DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
value->string = Platform.RAM.DIMM[map].SerialNo;
return true;
}
}
if (!bootInfo->memDetect)
{
if (!bootInfo->memDetect) {
return false;
}
value->string = NOT_AVAILABLE;
intmap;
idx++;
if (idx < MAX_RAM_SLOTS)
{
if (idx < MAX_RAM_SLOTS) {
map = Platform.DMI.DIMM[idx];
if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
{
if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) {
DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
value->string = Platform.RAM.DIMM[map].PartNo;
return true;
}
}
if (!bootInfo->memDetect)
{
if (!bootInfo->memDetect) {
return false;
}
value->string = NOT_AVAILABLE;
branches/chucko/i386/boot2/picopng.c
6060
6161
6262
63
63
64
65
66
6467
65
68
69
6670
67
71
72
6873
69
74
75
7076
77
7178
7279
7380
......
8188
8289
8390
84
85
91
92
8693
87
88
89
90
91
92
9394
95
96
97
98
99
100
101
102
103
104
105
106
107
108
94109
95110
96111
97112
98113
114
115
116
117
99118
100
101
102
119
120
121
103122
104123
105124
......
157176
158177
159178
179
180
181
160182
161
183
184
185
162186
187
163188
164189
165190
......
211236
212237
213238
239
240
241
242
214243
215244
245
246
247
216248
249
217250
218251
219252
......
221254
222255
223256
257
258
259
260
224261
225262
226263
......
229266
230267
231268
232
269
233270
234
271
235272
236
273
237274
238
275
239276
240277
241278
......
250287
251288
252289
290
291
292
293
253294
254295
255296
......
262303
263304
264305
306
307
308
309
265310
266311
267312
......
289334
290335
291336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
292354
293355
294356
......
362424
363425
364426
427
428
429
430
431
365432
366433
367434
......
370437
371438
372439
373
374
375
376
440
441
442
443
377444
378445
379446
380447
381448
382449
383
450
384451
385452
386
453
387454
455
388456
389
457
390458
391
459
392460
393
394
461
462
463
464
465
466
395467
396468
397469
398470
399
400
471
472
401473
402
474
403475
476
404477
405478
406479
407480
408481
409
482
410483
411
484
412485
486
413487
414488
415489
......
423497
424498
425499
500
426501
502
427503
504
428505
506
429507
430508
431509
......
439517
440518
441519
520
442521
522
443523
524
444525
526
445527
446528
447529
......
479561
480562
481563
564
482565
566
483567
484568
569
485570
571
486572
487
573
574
488575
489
576
577
490578
491579
492580
......
582670
583671
584672
585
673
586674
587675
676
588677
589
678
679
590680
591681
592682
683
593684
594685
595686
......
659750
660751
661752
753
662754
755
663756
757
664758
759
665760
761
666762
763
667764
668765
669766
......
887984
888985
889986
987
988
989
990
890991
891992
892993
......
9371038
9381039
9391040
1041
1042
1043
1044
1045
1046
9401047
9411048
9421049
......
10021109
10031110
10041111
1112
1113
1114
1115
10051116
10061117
10071118
......
10681179
10691180
10701181
1182
1183
1184
10711185
1186
1187
1188
10721189
10731190
10741191
void png_alloc_remove_node(png_alloc_node_t *node)
{
if (node->prev)
if (!node) {
return;
}
if (node->prev) {
node->prev->next = node->next;
if (node->next)
}
if (node->next) {
node->next->prev = node->prev;
if (node == png_alloc_head)
}
if (node == png_alloc_head) {
png_alloc_head = node->next;
if (node == png_alloc_tail)
}
if (node == png_alloc_tail) {
png_alloc_tail = node->prev;
}
node->prev = node->next = node->addr = NULL;
free(node);
}
void *png_alloc_realloc(void *addr, size_t size)
{
void *new_addr;
if (!addr)
void *new_addr = NULL;
if (!addr) {
return png_alloc_malloc(size);
new_addr = realloc(addr, size);
if (new_addr != addr) {
png_alloc_node_t *old_node;
old_node = png_alloc_find_node(addr);
png_alloc_remove_node(old_node);
png_alloc_add_node(new_addr, size);
}
png_alloc_node_t *old_node;
old_node = png_alloc_find_node(addr);
if (old_node)
{
new_addr = realloc(addr, size);
if (new_addr && (new_addr != addr))
{
png_alloc_remove_node(old_node);
png_alloc_add_node(new_addr, size);
}
}
return new_addr;
}
void png_alloc_free(void *addr)
{
if (!addr) {
return;
}
png_alloc_node_t *node = png_alloc_find_node(addr);
if (!node)
return;
png_alloc_remove_node(node);
if (node) {
png_alloc_remove_node(node);
}
free(addr);
}
vector32_t *vector32_new(size_t size, uint32_t value)
{
vector32_t *p = png_alloc_malloc(sizeof (vector32_t));
if (!p) {
return NULL;
}
vector32_init(p);
if (size && !vector32_resizev(p, size, value))
if (size && !vector32_resizev(p, size, value)) {
vector32_cleanup(p);
png_alloc_free(p);
return NULL;
}
return p;
}
vector8_t *vector8_new(size_t size, uint8_t value)
{
vector8_t *p = png_alloc_malloc(sizeof (vector8_t));
if(!p)
{
return NULL;
}
vector8_init(p);
if (size && !vector8_resizev(p, size, value))
{
vector8_cleanup(p);
png_alloc_free(p);
return NULL;
}
return p;
}
{
vector8_t *q = vector8_new(p->size, 0);
uint32_t n;
if (!q)
{
return NULL;
}
for (n = 0; n < q->size; n++)
q->data[n] = p->data[n];
return q;
/*************************************************************************************************/
const uint32_t LENBASE[29] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51,
59, 67, 83, 99, 115, 131, 163, 195, 227, 258 };
59, 67, 83, 99, 115, 131, 163, 195, 227, 258 };
const uint32_t LENEXTRA[29] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
4, 5, 5, 5, 5, 0 };
4, 5, 5, 5, 5, 0 };
const uint32_t DISTBASE[30] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385,
513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 };
513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 };
const uint32_t DISTEXTRA[30] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
10, 10, 11, 11, 12, 12, 13, 13 };
10, 10, 11, 11, 12, 12, 13, 13 };
// code length code lengths
const uint32_t CLCL[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
HuffmanTree *HuffmanTree_new()
{
HuffmanTree *tree = png_alloc_malloc(sizeof (HuffmanTree));
if (!tree)
{
return NULL;
}
tree->tree2d = NULL;
return tree;
}
tree1d = vector32_new(numcodes, 0);
blcount = vector32_new(maxbitlen + 1, 0);
nextcode = vector32_new(maxbitlen + 1, 0);
if (!tree1d || !blcount || !nextcode || !nextcode->data)
{
goto error;
}
for (bits = 0; bits < numcodes; bits++)
blcount->data[bitlen->data[bits]]++; // count number of instances of each code length
for (bits = 1; bits <= maxbitlen; bits++)
treepos = tree2d->data[2 * treepos + bit] - numcodes;
}
return 0;
error:
if (tree1d)
{
vector32_cleanup(tree1d);
png_alloc_free(tree1d);
}
if (blcount)
{
vector32_cleanup(blcount);
png_alloc_free(blcount);
}
if (nextcode)
{
vector32_cleanup(nextcode);
png_alloc_free(nextcode);
}
return 1;
}
int HuffmanTree_decode(const HuffmanTree *tree, bool *decoded, uint32_t *result, size_t *treepos,
{// get the tree of a deflated block with dynamic tree, the tree itself is also Huffman
// compressed with a known tree
size_t i, n;
size_t HLIT;
size_t HDIST;
size_t HCLEN;
size_t replength;
vector32_t *codelengthcode;
HuffmanTree *codelengthcodetree = HuffmanTree_new(); // the code tree for code length codes
vector32_t *bitlen, *bitlenD;
bitlen = vector32_new(288, 0);
Inflator_error = 49; // the bit pointer is or will go past the memory
return;
}
size_t HLIT = Zlib_readBitsFromStream(bp, in, 5) + 257;// number of literal/length codes + 257
size_t HDIST = Zlib_readBitsFromStream(bp, in, 5) + 1;// number of dist codes + 1
size_t HCLEN = Zlib_readBitsFromStream(bp, in, 4) + 4;// number of code length codes + 4
vector32_t *codelengthcode; // lengths of tree to decode the lengths of the dynamic tree
HLIT = Zlib_readBitsFromStream(bp, in, 5) + 257;// number of literal/length codes + 257
HDIST = Zlib_readBitsFromStream(bp, in, 5) + 1;// number of dist codes + 1
HCLEN = Zlib_readBitsFromStream(bp, in, 4) + 4;// number of code length codes + 4
// lengths of tree to decode the lengths of the dynamic tree
codelengthcode = vector32_new(19, 0);
for (i = 0; i < 19; i++)
codelengthcode->data[CLCL[i]] = (i < HCLEN) ? Zlib_readBitsFromStream(bp, in, 3) : 0;
Inflator_error = HuffmanTree_makeFromLengths(codelengthcodetree, codelengthcode, 7);
if (Inflator_error)
return;
size_t replength;
for (i = 0; i < HLIT + HDIST; ) {
uint32_t code = Inflator_huffmanDecodeSymbol(in, bp, codelengthcodetree, inlength);
if (Inflator_error)
if (Inflator_error) {
return;
}
if (code <= 15) { // a length code
if (i < HLIT)
if (i < HLIT) {
bitlen->data[i++] = code;
else
} else {
bitlenD->data[i++ - HLIT] = code;
} else if (code == 16) { // repeat previous
if (*bp >> 3 >= inlength) {
}
} else if (code == 16)
{ // repeat previous
uint32_t value; // set value to the previous code
if (*bp >> 3 >= inlength)
{
Inflator_error = 50; // error, bit pointer jumps past memory
return;
}
replength = 3 + Zlib_readBitsFromStream(bp, in, 2);
uint32_t value; // set value to the previous code
if ((i - 1) < HLIT)
if ((i - 1) < HLIT) {
value = bitlen->data[i - 1];
else
} else {
value = bitlenD->data[i - HLIT - 1];
}
for (n = 0; n < replength; n++) { // repeat this value in the next lengths
if (i >= HLIT + HDIST) {
Inflator_error = 13; // error: i is larger than the amount of codes
return;
}
if (i < HLIT)
if (i < HLIT) {
bitlen->data[i++] = value;
else
} else {
bitlenD->data[i++ - HLIT] = value;
}
}
} else if (code == 17) { // repeat "0" 3-10 times
if (*bp >> 3 >= inlength) {
return;
}
if (i < HLIT)
{
bitlen->data[i++] = 0;
}
else
{
bitlenD->data[i++ - HLIT] = 0;
}
}
} else if (code == 18) { // repeat "0" 11-138 times
if (*bp >> 3 >= inlength) {
return;
}
if (i < HLIT)
{
bitlen->data[i++] = 0;
}
else
{
bitlenD->data[i++ - HLIT] = 0;
}
}
} else {
Inflator_error = 16; // error: an nonexitent code appeared. This can never happen.
if (Inflator_error)
return;
if (code == 256) // end code
{
return;
}
else if (code <= 255) { // literal symbol
if (*pos >= out->size)
{
vector8_resize(out, (*pos + 1) * 2); // reserve more room
}
out->data[(*pos)++] = (uint8_t) code;
} else if (code >= 257 && code <= 285) { // length code
} else if (code >= 257 && code <= 285)
{ // length code
size_t length = LENBASE[code - 257], numextrabits = LENEXTRA[code - 257];
if ((*bp >> 3) >= inlength) {
if ((*bp >> 3) >= inlength)
{
Inflator_error = 51; // error, bit pointer will jump past memory
return;
}
// supposed to be made that way
return 24;
uint32_t CM = in->data[0] & 15, CINFO = (in->data[0] >> 4) & 15, FDICT = (in->data[1] >> 5) & 1;
if (CM != 8 || CINFO > 7)
if (CM != 8 || CINFO > 7){
// error: only compression method 8: inflate with sliding window of 32k is supported by
// the PNG spec
return 25;
if (FDICT != 0)
}
if (FDICT != 0) {
// error: the specification of PNG says about the zlib stream: "The additional flags shall
// not specify a preset dictionary."
return 26;
}
Inflator_inflate(out, in, 2);
return Inflator_error; // note: adler32 checksum was skipped and ignored
}
bitDepth = info->bitDepth;
colorType = info->colorType;
if (colorType == 2)
{
return (3 * bitDepth);
}
else if (colorType >= 4)
{
return (colorType - 2) * bitDepth;
}
else
{
return bitDepth;
}
}
void PNG_readPngHeader(PNG_info_t *info, const uint8_t *in, size_t inlength)
PNG_info_t *PNG_info_new()
{
PNG_info_t *info = png_alloc_malloc(sizeof (PNG_info_t));
if (!info)
{
return NULL;
}
uint32_t i;
for (i = 0; i < sizeof (PNG_info_t); i++)
((uint8_t *) info)[i] = 0;
vector8_resize(idat, offset + chunkLength);
} else
idat = vector8_new(chunkLength, 0);
if (!idat)
{
PNG_error = 1;
return NULL;
}
for (i = 0; i < chunkLength; i++)
idat->data[offset + i] = in[pos + 4 + i];
pos += (4 + chunkLength);
uint32_t bpp = PNG_getBpp(info);
vector8_t *scanlines; // now the out buffer will be filled
scanlines = vector8_new(((info->width * (info->height * bpp + 7)) / 8) + info->height, 0);
if (!scanlines) {
PNG_error = 1;
return NULL;
}
PNG_error = Zlib_decompress(scanlines, idat);
if (PNG_error)
return NULL; // stop if the zlib decompressor returned an error
}
if (info->colorType != 6 || info->bitDepth != 8) { // conversion needed
vector8_t *copy = vector8_copy(info->image); // xxx: is this copy necessary?
if (!copy) {
return NULL;
}
PNG_error = PNG_convert(info, info->image, copy->data);
if (PNG_error) {
return NULL;
}
}
return info;
}
branches/chucko/i386/boot2/modules.c
105105
106106
107107
108
109
108
110109
111110
112111
......
120119
121120
122121
122
123123
124124
125125
......
605605
606606
607607
608
609
608
610609
611610
612611
613612
614
615
613
616614
617615
618616
619617
620618
621
622
619
623620
624621
625622
......
628625
629626
630627
631
632628
633629
634630
635631
636
637
632
638633
639634
640635
641
642
636
643637
644638
645639
......
647641
648642
649643
650
651
644
645
652646
653647
654648
......
660654
661655
662656
663
664
657
665658
666659
667
668
669
660
661
670662
671663
672664
......
678670
679671
680672
681
682
673
683674
684675
685
686
676
687677
688678
689679
......
693683
694684
695685
696
697
686
698687
699688
700
701
689
702690
703691
704692
705693
706
707
694
708695
709696
710
711
712
697
698
713699
714700
715701
......
728714
729715
730716
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
717
718
719
720
721
722
723
724
725
726
727
728
748729
749730
750731
......
830811
831812
832813
833
814
834815
835816
836817
......
984965
985966
986967
987
968
988969
989970
990971
991972
973
992974
993975
994976
long flags;
long time;
struct dirstuff* moduleDir = opendir("/Extra/modules/");
while (readdir(moduleDir, (const char**)&name, &flags, &time) >= 0)
{
while (readdir(moduleDir, (const char**)&name, &flags, &time) >= 0) {
if(strcmp(&name[strlen(name) - sizeof("dylib")], ".dylib") == 0) {
char* tmp = malloc(strlen(name) + 1);
strcpy(tmp, name);
{
DBG("Ignoring %s\n", name);
}
}
closedir(moduleDir);
}
unsigned int binIndex = 0;
index = 0;
do
{
do {
segCommand = base + sizeof(struct mach_header) + binIndex;
binIndex += segCommand->cmdsize;
index++;
}
while(index <= immediate);
} while(index <= immediate);
segmentAddress = segCommand->fileoff;
tmp = 0;
bits = 0;
do
{
do {
tmp |= (rebase_stream[++i] & 0x7f) << bits;
bits += 7;
}
segmentAddress += tmp;
break;
case REBASE_OPCODE_ADD_ADDR_ULEB:
// Add value to rebase address
tmp = 0;
bits = 0;
do
{
do {
tmp <<= bits;
tmp |= rebase_stream[++i] & 0x7f;
bits += 7;
}
while(rebase_stream[i] & 0x80);
} while(rebase_stream[i] & 0x80);
segmentAddress +=tmp;
break;
case REBASE_OPCODE_ADD_ADDR_IMM_SCALED:
segmentAddress += immediate * sizeof(void*);
break;
case REBASE_OPCODE_DO_REBASE_IMM_TIMES:
index = 0;
for (index = 0; index < immediate; ++index) {
case REBASE_OPCODE_DO_REBASE_ULEB_TIMES:
tmp = 0;
bits = 0;
do
{
do {
tmp |= (rebase_stream[++i] & 0x7f) << bits;
bits += 7;
}
while(rebase_stream[i] & 0x80);
} while(rebase_stream[i] & 0x80);
index = 0;
for (index = 0; index < tmp; ++index) {
//DBG("\tRebasing 0x%X\n", segmentAddress);
case REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB:
tmp = 0;
bits = 0;
do
{
do {
tmp |= (rebase_stream[++i] & 0x7f) << bits;
bits += 7;
}
while(rebase_stream[i] & 0x80);
} while(rebase_stream[i] & 0x80);
rebase_location(base + segmentAddress, (char*)base, type);
case REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB:
tmp = 0;
bits = 0;
do
{
do {
tmp |= (rebase_stream[++i] & 0x7f) << bits;
bits += 7;
}
while(rebase_stream[i] & 0x80);
} while(rebase_stream[i] & 0x80);
tmp2 = 0;
bits = 0;
do
{
do {
tmp2 |= (rebase_stream[++i] & 0x7f) << bits;
bits += 7;
}
while(rebase_stream[i] & 0x80);
} while(rebase_stream[i] & 0x80);
index = 0;
for (index = 0; index < tmp; ++index) {
UInt32 read_uleb(UInt8* bind_stream, unsigned int* i)
{
// Read in offset
UInt32 tmp = 0;
UInt8 bits = 0;
do
{
if(bits < sizeof(UInt32)*8) // hack
{
tmp |= (bind_stream[++(*i)] & 0x7f) << bits;
bits += 7;
}
else
{
++(*i);
}
}
while(bind_stream[*i] & 0x80);
return tmp;
// Read in offset
UInt32 tmp = 0;
UInt8 bits = 0;
do {
if(bits < sizeof(UInt32)*8) { // hack
tmp |= (bind_stream[++(*i)] & 0x7f) << bits;
bits += 7;
} else {
++(*i);
}
} while(bind_stream[*i] & 0x80);
return tmp;
}
// Locate address
struct segment_command* segCommand = NULL;// NOTE: 32bit only
unsigned int binIndex = 0;
index = 0;
do
if(addr != 0xFFFFFFFF)
{
//DBG("Replacing %s to point to 0x%x\n", symbol, newAddress);
UInt32* jumpPointer = malloc(sizeof(UInt32*));
UInt32* jumpPointer = malloc(sizeof(UInt32*));
char* binary = (char*)addr;
*binary++ = 0xFF;// Jump
*binary++ = 0x25;// Long Jump
*((UInt32*)binary) = (UInt32)jumpPointer;
*jumpPointer = (UInt32)newAddress;
return 1;
}
branches/chucko/i386/boot2/modules.h
9494
9595
9696
97
9798
9899
99100
long long(*symbol_handler)(char*, long long, char),
char is64);
voidrebase_macho(void* base, char* rebase_stream, UInt32 size);
voidbind_macho(void* base, UInt8* bind_stream, UInt32 size);
branches/chucko/i386/libsa/libsa.h
3737
3838
3939
40
40
4141
4242
4343
4444
45
45
4646
4747
4848
4949
50
50
5151
5252
5353
5454
55
55
5656
5757
5858
5959
60
60
6161
6262
6363
6464
65
65
6666
6767
6868
6969
70
70
7171
7272
7373
7474
75
75
7676
7777
7878
7979
8080
8181
82
82
8383
8484
8585
86
86
8787
8888
8989
......
107107
108108
109109
110
110
111111
112112
113113
......
131131
132132
133133
134
135
134
136135
137136
138137
......
144143
145144
146145
147
146
148147
149148
150149
......
153152
154153
155154
156
157
155
158156
159157
*/
static inline int isupper(int c)
{
return (c >= 'A' && c <= 'Z');
return (c >= 'A' && c <= 'Z');
}
static inline int islower(int c)
{
return (c >= 'a' && c <= 'z');
return (c >= 'a' && c <= 'z');
}
static inline int isalpha(int c)
{
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
}
static inline int isascii(int c)
{
return ( (c >= 0x20) && (c < 0x7f) );
return ( (c >= 0x20) && (c < 0x7f) );
}
static inline int isspace(int c)
{
return (c == ' ' || c == '\t' || c == '\n' || c == '\12');
return (c == ' ' || c == '\t' || c == '\n' || c == '\12');
}
static inline int isdigit(int c)
{
return (c >= '0' && c <= '9');
return (c >= '0' && c <= '9');
}
static inline int isxdigit(int c)
{
return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'));
return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'));
}
static inline int ispunct(int c)
{
return (c == '.' || c == '-');
return (c == '.' || c == '-');
}
/*
* string.c
*/
#ifndef bcopy
extern void bcopy(const void * src, void * dst, size_t len);
extern void bcopy(const void * src, void * dst, size_t len);
#endif
#ifndef bzero
extern void bzero(void * dst, size_t len);
extern void bzero(void * dst, size_t len);
#else
#error bzero is defined.
#endif
extern char * strdup(const char *s1);
#if STRNCASECMP
extern int strncasecmp(const char * s1, const char * s2, size_t n);
extern int strncasecmp(const char *s1, const char *s2, size_t n);
#endif
extern char * strchr(const char *str, int c);
/*
* prf.c
*/
extern void prf(const char * fmt, va_list ap, int (*putfn_p)(),
void * putfn_arg);
extern void prf(const char * fmt, va_list ap, int (*putfn_p)(), void * putfn_arg);
/*
* printf.c
/*
* zalloc.c
*/
#define malloc(size)safe_malloc(size, __FILE__, __LINE__)
#define malloc(size) safe_malloc(size, __FILE__, __LINE__)
extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int));
extern void * safe_malloc(size_t size,const char *file, int line);
extern void free(void * start);
/*
* getsegbyname.c
*/
extern struct segment_command *
getsegbynamefromheader(struct mach_header * mhp, char * segname);
extern struct segment_command * getsegbynamefromheader(struct mach_header * mhp, char * segname);
#endif /* !__BOOT_LIBSA_H */
branches/chucko/i386/libsa/printf.c
3030
3131
3232
33
34
33
34
3535
3636
3737
3838
3939
40
41
42
43
44
45
46
40
41
42
43
44
45
46
47
48
49
4750
4851
4952
5053
5154
5255
53
54
56
57
5558
56
57
58
59
60
61
62
59
60
61
62
63
64
65
6366
6467
6568
......
8083
8184
8285
83
84
85
86
87
88
86
87
88
89
90
91
8992
struct putc_info //Azi: exists on console.c & gui.c
{
char * str;
char * last_str;
char * str;
char * last_str;
};
static int
sputc(int c, struct putc_info * pi) //Azi: same as above
{
if (pi->last_str)
if (pi->str == pi->last_str) {
*(pi->str) = '\0';
return 0;
}
*(pi->str)++ = c;
return c;
if (pi->last_str)
{
if (pi->str == pi->last_str)
{
*(pi->str) = '\0';
return 0;
}
}
*(pi->str)++ = c;
return c;
}
/*VARARGS1*/
/* now slprintf() return the length of the string as in man sprintf()*/
int sprintf(char * str, const char * fmt, ...)
{
va_list ap;
struct putc_info pi;
va_list ap;
struct putc_info pi;
va_start(ap, fmt);
pi.str = str;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
*pi.str = '\0';
va_end(ap);
return (pi.str - str);
va_start(ap, fmt);
pi.str = str;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
*pi.str = '\0';
va_end(ap);
return (pi.str - str);
}
/*VARARGS1*/
/*VARARGS1*/
int slvprintf(char * str, int len, const char * fmt, va_list ap)
{
struct putc_info pi;
pi.str = str;
pi.last_str = str + len - 1;
prf(fmt, ap, sputc, &pi);
*pi.str = '\0';
return (pi.str - str);
struct putc_info pi;
pi.str = str;
pi.last_str = str + len - 1;
prf(fmt, ap, sputc, &pi);
*pi.str = '\0';
return (pi.str - str);
}
branches/chucko/i386/libsa/zalloc.c
4949
5050
5151
52
52
5353
5454
5555
......
6565
6666
6767
68
68
6969
7070
7171
......
7777
7878
7979
80
80
81
82
83
84
8185
82
86
8387
8488
85
89
8690
8791
8892
......
9195
9296
9397
94
95
98
99
96100
97101
98102
......
105109
106110
107111
108
112
113
114
109115
110116
111
112
117
118
113119
114
120
115121
116122
117123
118124
119
125
120126
121127
122128
123129
124130
125131
126
127
128
129
130
131
132
133
134
135
136
132
133
134
135
136
137
137138
138
139
139140
140141
141142
......
143144
144145
145146
146
147
147148
148
149
150
151
152
153
149
150
151
152
153
154154
155155
156156
157
158
159
160
161
162
157
158
159
160
161
162
163
163164
164
165
165166
166
167
167168
168169
169170
170171
171172
172173
173
174
174175
175
176
176177
177178
178179
179
180
181
180
181
182
182183
183
184
184185
185186
186187
187188
188
189
190
191
189192
190193
191194
192
195
193196
194197
195198
196199
197
200
198201
199202
200203
201204
202
205
203206
204207
205208
206209
207
208
209
210
210
211
212
213
214
215
216
211217
212218
213219
214220
215
216
221
217222
218223
219224
......
222227
223228
224229
225
226
227
230
228231
229232
230233
231234
232235
233
234
236
235237
236
237
238
239
240
241
238242
239243
240244
......
242246
243247
244248
245
246
247
249
250
251
252
253
248254
249255
250256
257
251258
252259
253260
254261
255262
256263
264
257265
258266
259267
260268
269
261270
262271
272
263273
264
265
274
275
276
277
266278
267279
268280
......
275287
276288
277289
278
279
280
290
291
281292
282293
283294
......
290301
291302
292303
293
294
295
304
305
296306
297307
298308
......
301311
302312
303313
304
305
306
307
308
309
310
314
315
316
317
311318
312319
313320
static short availableNodes, allocedNodes, totalNodes;
static char * zalloc_base;
static char * zalloc_end;
static void (*zerror)(char *, size_t, const char *, int);
static void (*zerror)(char *, size_t, const char *, int);
static void zallocate(char * start,int size);
static void zinsert(zmem * zp, int ndx);
static void malloc_error(char *addr, size_t size, const char *file, int line)
{
#ifdef i386
asm volatile ("hlt");
asm volatile ("hlt");
#endif
}
zalloced = (zmem *) zalloc_base;
zavailable = (zmem *) zalloc_base + sizeof(zmem) * totalNodes;
zavailable[0].start = (char *)zavailable + sizeof(zmem) * totalNodes;
if (size == 0) size = ZALLOC_LEN;
if (size == 0) {
size = ZALLOC_LEN;
}
zavailable[0].size = size - (zavailable[0].start - zalloc_base);
zalloc_end = zalloc_base + size;
zalloc_end = zalloc_base + size;
availableNodes = 1;
allocedNodes = 0;
zerror = malloc_err_fn ? malloc_err_fn : malloc_error;
zerror = malloc_err_fn ? malloc_err_fn : malloc_error;
}
#define BEST_FIT 1
{
int i;
#if BEST_FIT
int bestFit;
size_t smallestSize;
int bestFit;
size_t smallestSize;
#endif
char * ret = 0;
size = ((size + 0xf) & ~0xf);
if (size == 0) {
if (zerror) (*zerror)((char *)0xdeadbeef, 0, file, line);
if (zerror) {
(*zerror)((char *)0xdeadbeef, 0, file, line);
}
}
#if BEST_FIT
smallestSize = 0;
bestFit = -1;
smallestSize = 0;
bestFit = -1;
#endif
for (i = 0; i < availableNodes; i++)
{
// find node with equal size, or if not found,
// then smallest node that fits.
if ( zavailable[i].size == size )
if (zavailable[i].size == size)
{
zallocate(ret = zavailable[i].start, size);
zdelete(zavailable, i); availableNodes--;
goto done;
}
#if BEST_FIT
else
{
if ((zavailable[i].size > size) &&
((smallestSize == 0) ||
(zavailable[i].size < smallestSize)))
{
bestFit = i;
smallestSize = zavailable[i].size;
}
}
else {
if ((zavailable[i].size > size) && ((smallestSize == 0) || (zavailable[i].size < smallestSize))) {
bestFit = i;
smallestSize = zavailable[i].size;
}
}
#else
else if ( zavailable[i].size > size )
else if (zavailable[i].size > size)
{
zallocate(ret = zavailable[i].start, size);
zavailable[i].start += size;
goto done;
}
#endif
}
}
#if BEST_FIT
if (bestFit != -1)
{
zallocate(ret = zavailable[bestFit].start, size);
zavailable[bestFit].start += size;
zavailable[bestFit].size -= size;
}
if (bestFit != -1) {
zallocate(ret = zavailable[bestFit].start, size);
zavailable[bestFit].start += size;
zavailable[bestFit].size -= size;
}
#endif
done:
if ((ret == 0) || (ret + size >= zalloc_end))
{
if (zerror) (*zerror)(ret, size, file, line);
}
if (ret != 0)
{
if ((ret == 0) || (ret + size >= zalloc_end)) {
if (zerror) {
(*zerror)(ret, size, file, line);
}
}
if (ret != 0) {
bzero(ret, size);
}
}
#if ZDEBUG
zalloced_size += size;
zalloced_size += size;
#endif
return (void *) ret;
}
void free(void * pointer)
{
unsigned long rp;
unsigned long rp;
int i, found = 0;
size_t tsize = 0;
size_t tsize = 0;
char * start = pointer;
#if i386
// Get return address of our caller,
// in case we have to report an error below.
asm volatile ("movl %%esp, %%eax\n\t"
// Get return address of our caller,
// in case we have to report an error below.
asm volatile ("movl %%esp, %%eax\n\t"
"subl $4, %%eax\n\t"
"movl 0(%%eax), %%eax" : "=a" (rp) );
"movl 0(%%eax), %%eax" : "=a" (rp));
#else
rp = 0;
#endif
if ( !start ) return;
if (!start) {
return;
}
for (i = 0; i < allocedNodes; i++)
{
if ( zalloced[i].start == start )
if (zalloced[i].start == start)
{
tsize = zalloced[i].size;
#if ZDEBUG
zout -= tsize;
printf(" zz out %d\n",zout);
printf(" zz out %d\n", zout);
#endif
zdelete(zalloced, i); allocedNodes--;
found = 1;
#if ZDEBUG
memset(pointer, 0x5A, tsize);
memset(pointer, 0x5A, tsize);
#endif
break;
}
}
if ( !found ) {
if (zerror) (*zerror)(pointer, rp, "free", 0);
else return;
}
if (!found) {
if (zerror) {
(*zerror)(pointer, rp, "free", 0);
} else {
return;
}
}
#if ZDEBUG
zalloced_size -= tsize;
#endif
for (i = 0; i < availableNodes; i++)
{
for (i = 0; i < availableNodes; i++) {
if ((start + tsize) == zavailable[i].start) // merge it in
{
zavailable[i].start = start;
return;
}
if ((i > 0) &&
(zavailable[i-1].start + zavailable[i-1].size == start))
{
if ((i > 0) && (zavailable[i-1].start + zavailable[i-1].size == start)) {
zavailable[i-1].size += tsize;
zcoalesce();
return;
}
if ((start + tsize) < zavailable[i].start)
{
if ((start + tsize) < zavailable[i].start) {
if (++availableNodes > totalNodes) {
if (zerror) (*zerror)((char *)0xf000f000, 0, "free", 0);
}
if (zerror) {
(*zerror)((char *)0xf000f000, 0, "free", 0);
}
}
zinsert(zavailable, i);
zavailable[i].start = start;
zavailable[i].size = tsize;
}
}
if (++availableNodes > totalNodes) {
if (zerror) (*zerror)((char *)0xf000f000, 1, "free", 0);
}
if (++availableNodes > totalNodes) {
if (zerror) {
(*zerror)((char *)0xf000f000, 1, "free", 0);
}
}
zavailable[i].start = start;
zavailable[i].size = tsize;
zcoalesce();
return;
}
static void
zallocate(char * start,int size)
{
#if ZDEBUG
zout += size;
printf(" alloc %d, total 0x%x\n",size,zout);
#endif
zalloced[allocedNodes].start = start;
zalloced[allocedNodes].size = size;
if (++allocedNodes > totalNodes) {
if (zerror) (*zerror)((char *)0xf000f000, 2, "zallocate", 0);
};
if (zerror) {
(*zerror)((char *)0xf000f000, 2, "zallocate", 0);
}
};
}
static void
z1 = zp + i;
z2 = z1 + 1;
for (; i >= ndx; i--, z1--, z2--)
{
*z2 = *z1;
for (; i >= ndx; i--, z1--, z2--) {
*z2 = *z1;
}
}
z1 = zp + ndx;
z2 = z1 + 1;
for (i = ndx; i < totalNodes-1; i++, z1++, z2++)
{
*z1 = *z2;
for (i = ndx; i < totalNodes - 1; i++, z1++, z2++) {
*z1 = *z2;
}
}
{
int i;
for (i = 0; i < availableNodes-1; i++)
{
if ( zavailable[i].start + zavailable[i].size ==
zavailable[i+1].start )
{
zavailable[i].size += zavailable[i+1].size;
zdelete(zavailable, i+1); availableNodes--;
for (i = 0; i < availableNodes-1; i++) {
if ( zavailable[i].start + zavailable[i].size == zavailable[i + 1].start ) {
zavailable[i].size += zavailable[i + 1].size;
zdelete(zavailable, i + 1); availableNodes--;
return;
}
}
branches/chucko/i386/libsa/string.c
331331
332332
333333
334
335
336
337
334
335
336
337
338338
339339
uint8_t * cp = (uint8_t *) start;
unsigned int i;
for ( i = 0; i < length; i++)
csum += *cp++;
return csum;
for ( i = 0; i < length; i++) {
csum += *cp++;
}
return csum;
}
branches/chucko/i386/libsa/prf.c
7373
7474
7575
76
76
7777
7878
7979
......
8484
8585
8686
87
87
8888
8989
9090
......
100100
101101
102102
103
103
104104
105105
106106
}
cp = prbuf;
do {
*cp++ = "0123456789abcdef0123456789ABCDEF"[(flag & UCASE) + n%b];
*cp++ = "0123456789abcdef0123456789ABCDEF"[(flag & UCASE) + n%b];
n /= b;
width++;
} while (n);
}
while (width++ < minwidth)
(*putfn_p)( (flag & ZERO) ? '0' : ' ', putfn_arg);
do
(*putfn_p)(*--cp, putfn_arg);
while (cp > prbuf);
int b, c;
char *s;
int flag = 0, width = 0;
int minwidth;
int minwidth;
loop:
while ((c = *fmt++) != '%') {
branches/chucko/i386/libsa/efi_tables.c
129129
130130
131131
132
133
134
135
136
137
138
139
140
141
142
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
143147
144148
145149
......
154158
155159
156160
157
161
162
158163
159164
160165
bool efi_guid_is_null(EFI_GUID const *pGuid)
{
if(pGuid->Data1 == 0 && pGuid->Data2 == 0 && pGuid->Data3 == 0)
{
int i;
for(i=0; i<8; ++i)
{
if(pGuid->Data4[i] != 0)
return false;
}
return true;
}
return false;
if (pGuid->Data1 == 0 && pGuid->Data2 == 0 && pGuid->Data3 == 0)
{
int i;
for (i = 0; i < 8; ++i)
{
if (pGuid->Data4[i] != 0)
{
return false;
}
}
return true;
}
return false;
}
#define COMPARE_MEMBER_AND_RETURN_IF_NE(a,b,mem) \
COMPARE_MEMBER_AND_RETURN_IF_NE(pG1, pG2, Data2);
COMPARE_MEMBER_AND_RETURN_IF_NE(pG1, pG2, Data3);
int i;
for(i=0; i<8; ++i)
for(i = 0; i < 8; ++i)
{
COMPARE_MEMBER_AND_RETURN_IF_NE(pG1, pG2, Data4[i]);
}
branches/chucko/i386/libsa/memory.h
5757
5858
5959
60
60
6161
6262
6363
......
118118
119119
120120
121
122
123
121
122
123
124
124125
125126
126127
......
131132
132133
133134
134
135
135136
136137
137138
......
139140
140141
141142
142
143
143144
144145
#define BOOT2_SEG0x2000
#define BOOT2_OFS0x0200// 512 byte disk sector offset
#define BOOT2_MAX_LENGTH0x6FE00// Maximum size for boot2 is currentl 447kb
#define BOOT2_MAX_LENGTH0x6FE00// Maximum size for boot2 is currentl 447kb
#define BIOS_ADDR0x8000// BIOS disk I/O buffer
#define BIOS_LEN0x8000// 32K - divisible by 512 and 2048
#define OFFSET(addr) ((addr) & 0xFFFF)
#define SEGMENT(addr) (((addr) & 0xF0000) >> 4)
/* Extract segment/offset in normalized form so that the resulting far pointer
will point to something that is very unlikely to straddle a segment.
This is sometimes known as a "huge" pointer.
/*
* Extract segment/offset in normalized form so that the resulting far pointer
* will point to something that is very unlikely to straddle a segment.
* This is sometimes known as a "huge" pointer.
*/
#define NORMALIZED_OFFSET(addr) ((addr) & 0x000F)
#define NORMALIZED_SEGMENT(addr) (((addr) & 0xFFFF0) >> 4)
#define MIN_SYS_MEM_KB (32 * 1024)
/*
* The number of descriptor entries in the GDT.
* The number of descriptor entries in the GDT (Global Descriptor Table).
*/
#define NGDTENT 7
* The total size of the GDT in bytes.
* Each descriptor entry require 8 bytes.
*/
#define GDTLIMIT ( NGDTENT * 8 )
#define GDTLIMIT (NGDTENT * 8)
#endif /* !__BOOT_MEMORY_H */
branches/chucko/doc/BootHelp.txt
150150
151151
152152
153
153154
154155
155156
Rescan=Yes Enable CD-ROM rescan mode.
"Rescan Prompt"=Yes Prompts for enable CD-ROM rescan mode.
SystemId=<UUID> Set the system id manually to UUID.
Deprecated - Now SMsystemuuid in smbios.plist
SMUUID in smbios config (reserved field) isn't used then.
SystemType=<n> Set the system type to n, where n is between 0..6
(default=1 Desktop)
branches/chucko/CHANGES
1
12
23
34
- One of the changes as of rev2284 is boot option SystemId has now been deprecated. Instead use key SMsystemuuid in smbios.plist.
- ErmaC: Port from Enoch the support for IVY Bridge and Haswell Intel Graphics cards. http://www.insanelymac.com/forum/topic/288241-intel-hd4000-and-haswell-inject-aaplig-platform-id/
- 2255: ErmaC add Skip flag key for Intel/nVidia/ATi from Enoch
- 2252: revert define processors name to match with xnu kernel name

Archive Download the corresponding diff file

Revision: 2337