Chameleon

Chameleon Commit Details

Date:2014-01-11 19:40:36 (5 years 11 months ago)
Author:ErmaC
Commit:2331
Parents: 2330
Message:Second pass general update (typo, indent) replace sprintf with snprintf in spd.
Changes:
M/trunk/i386/libsa/efi_tables.c
M/trunk/i386/libsa/libsa.h
M/trunk/i386/libsaio/dram_controllers.c
M/trunk/i386/libsaio/nvidia_helper.c
M/trunk/i386/libsa/printf.c
M/trunk/i386/libsaio/ntfs.c
M/trunk/i386/libsaio/nvidia.c
M/trunk/i386/libsaio/ext2fs.c
M/trunk/i386/boot2/modules.c
M/trunk/i386/libsaio/bootstruct.h
M/trunk/i386/libsa/string.c
M/trunk/i386/libsaio/load.c
M/trunk/i386/libsaio/nvidia.h
M/trunk/i386/libsaio/freebsd.h
M/trunk/i386/libsaio/aml_generator.c
M/trunk/i386/boot2/modules.h
M/trunk/i386/libsaio/convert.c
M/trunk/i386/libsaio/pci.h
M/trunk/i386/libsaio/acpi_patcher.c
M/trunk/i386/libsaio/sl.h
M/trunk/i386/libsaio/msdos.c
M/trunk/i386/libsaio/platform.h
M/trunk/i386/libsaio/disk.c
M/trunk/i386/libsaio/device_inject.c
M/trunk/i386/libsaio/smbios.c
M/trunk/i386/libsaio/device_inject.h
M/trunk/i386/libsaio/xml.c
M/trunk/i386/boot2/picopng.c
M/trunk/i386/libsaio/ati.c
M/trunk/i386/libsaio/sys.c
M/trunk/i386/libsaio/device_tree.c
M/trunk/i386/libsaio/pci_root.c
M/trunk/i386/libsaio/hfs.c
M/trunk/i386/libsaio/vbe.h
M/trunk/i386/libsa/memory.h
M/trunk/i386/libsaio/hfs_compare.c
M/trunk/i386/libsaio/spd.c
M/trunk/i386/libsaio/cpu.c
M/trunk/i386/libsaio/md5c.c
M/trunk/i386/libsaio/smbios_getters.c
M/trunk/i386/libsaio/openbsd.c
M/trunk/i386/libsa/zalloc.c
M/trunk/i386/libsa/prf.c
M/trunk/i386/libsaio/openbsd.h
M/trunk/i386/libsaio/smbios_decode.c

File differences

trunk/i386/libsaio/xml.c
130130
131131
132132
133
133
134134
135
136
137
138
139
140
141
142
143
135
136
137
138
139
140
141
142
143
144
144145
145146
146147
......
149150
150151
151152
152
153153
154154
155155
......
362362
363363
364364
365
366
365
367366
368367
369368
......
372371
373372
374373
375
376
377
374
378375
379
380
381
376
382377
383378
384379
385
386
380
387381
388382
389383
390384
391
392
385
393386
394
395
396
387
397388
398
399
389
400390
401391
402392
403393
404394
405395
406
407
408
409
396
397
410398
411
412
413
399
414400
415401
416402
......
419405
420406
421407
422
423
424
408
425409
426410
427411
428412
429413
430414
431
432
433
434
415
416
435417
436
437
438
418
439419
440420
441421
......
457437
458438
459439
460
461
440
462441
463
464
465
466
467
442
443
468444
469445
470446
471447
472448
473449
474
475
476
477
450
451
478452
479
480
481
453
482454
483455
484456
......
487459
488460
489461
490
491
492
462
493463
494464
495465
496466
497467
498468
499
500
501
502
469
470
503471
504
505
506
472
507473
508474
509475
......
517483
518484
519485
520
486
521487
522488
523489
524490
525
526
527
491
528492
529493
530494
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545495
546
547
548
549
550
551496
552497
553
554
498
555499
556500
501
557502
558
559
503
560504
561505
562506
563
564
565
566
507
508
509
510
511
512
513
514
515
516
517
518
519
567520
568
569
521
522
523
524
525
526
570527
571528
572
573
529
530
531
574532
575533
576534
577535
578
579
536
580537
581538
582539
......
601558
602559
603560
604
605
606
607
561
562
608563
609564
610565
......
620575
621576
622577
623
624
578
625579
626580
627581
628582
629583
630584
631
632
585
633586
634587
635588
......
735688
736689
737690
738
691
739692
740693
741694
......
753706
754707
755708
756
709
710
711
757712
758713
759
760714
715
716
717
761718
762719
763
764
720
765721
766
767
768
769
722
723
724
770725
771
772
773
726
774727
775
776
777
778
779
780
781
728
729
730
782731
783732
784733
785734
786735
787736
788
789
790
791
792
737
738
793739
794740
795741
796742
797743
798
799
800
801
802
803
744
745
746
804747
805748
806749
807750
808
751
809752
810753
811754
812755
813
756
814757
758
815759
816760
817761
......
916860
917861
918862
919
863
864
865
920866
921
867
922868
923869
924
870
871
872
925873
926874
927875
928
876
877
878
929879
930880
931881
932882
933
883
884
885
934886
935887
936888
......
1006958
1007959
1008960
1009
1010
961
1011962
1012963
1013964
1014
1015
965
1016966
1017967
1018968
......
10591009
10601010
10611011
1062
1063
1012
10641013
1065
1066
1014
10671015
10681016
10691017
......
10791027
10801028
10811029
1082
1083
1030
10841031
10851032
10861033
......
10991046
11001047
11011048
1102
1103
1049
11041050
11051051
11061052
11071053
11081054
11091055
1110
1111
1056
11121057
11131058
11141059
11151060
1116
1117
1061
11181062
1119
1120
1121
1063
11221064
11231065
11241066
......
11381080
11391081
11401082
1141
1142
1143
1144
1083
1084
11451085
11461086
11471087
......
11491089
11501090
11511091
1152
1153
1092
11541093
11551094
11561095
......
11591098
11601099
11611100
1162
1163
1101
11641102
11651103
11661104
......
11741112
11751113
11761114
1177
1178
1115
11791116
11801117
1181
1182
1183
1118
11841119
1185
1186
1187
1120
11881121
11891122
11901123
......
12011134
12021135
12031136
1204
1205
1137
12061138
12071139
1208
1209
1210
1140
12111141
1212
1213
1214
1142
12151143
12161144
12171145
......
12231151
12241152
12251153
1226
1227
1154
12281155
12291156
12301157
1231
1232
1158
12331159
12341160
12351161
......
12381164
12391165
12401166
1241
1242
1167
12431168
12441169
12451170
1246
1247
1171
12481172
12491173
12501174
......
12551179
12561180
12571181
1258
1259
1182
12601183
1261
1262
1263
1184
12641185
12651186
12661187
......
12721193
12731194
12741195
1275
1276
1196
12771197
12781198
1279
1280
1281
1199
12821200
12831201
1284
12851202
12861203
12871204
......
12921209
12931210
12941211
1295
1296
1212
12971213
12981214
12991215
1300
1301
1216
13021217
13031218
1304
13051219
13061220
13071221
13081222
13091223
1310
1311
1224
13121225
13131226
13141227
......
13161229
13171230
13181231
1319
1320
1232
13211233
13221234
13231235
13241236
1325
1326
1237
13271238
13281239
13291240
......
13351246
13361247
13371248
1338
1339
1249
13401250
13411251
13421252
13431253
13441254
1345
1346
1255
13471256
13481257
13491258
TagPtr
XMLGetProperty(TagPtr dict, const char * key)
{
TagPtr tagList, tag;
TagPtr tagList, tag;
if (dict->type != kTagTypeDict) return 0;
tag = 0;
tagList = dict->tag;
while (tagList)
{
tag = tagList;
tagList = tag->tagNext;
if (dict->type != kTagTypeDict) {
return 0;
}
tag = 0;
tagList = dict->tag;
while (tagList) {
tag = tagList;
tagList = tag->tagNext;
if ((tag->type != kTagTypeKey) || (tag->string == 0)) {
continue;
}
return tag->tag;
}
}
return 0;
}
}
pos = length;
if (!strncmp(tagName, kXMLTagPList, 6))
{
if (!strncmp(tagName, kXMLTagPList, 6)) {
length = 0;
// just a header; nothing to parse
// return-via-reference tag should be left alone
else if (!strcmp(tagName, kXMLTagDict))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/')
{
} else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/') {
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
}
else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " ")))
{
} else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " "))) {
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
/***** key ****/
else if (!strcmp(tagName, kXMLTagKey))
{
else if (!strcmp(tagName, kXMLTagKey)) {
length = ParseTagKey(buffer + pos, tag);
}
/***** string ****/
else if (!strcmp(tagName, kXMLTagString))
{
else if (!strcmp(tagName, kXMLTagString)) {
length = ParseTagString(buffer + pos, tag);
}
else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " ")))
{
} else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " "))) {
// TODO: save tag if if found
if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID)))
{
if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID))) {
// ID=
int id = 0;
int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\"");
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
id = (id * 10) + (*val++ - '0');
}
else
{
} else {
printf("ParseStringID error (0x%x)\n", *val);
getchar();
return -1;
length = ParseTagString(buffer + pos, tag);
SaveRefString(buffer + pos, id);
}
else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
{
} else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) {
// IDREF=
int id = 0;
int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\"");
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
id = (id * 10) + (*val++ - '0');
}
else
{
} else {
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
}
/***** integer ****/
else if (!strcmp(tagName, kXMLTagInteger))
{
else if (!strcmp(tagName, kXMLTagInteger)) {
length = ParseTagInteger(buffer + pos, tag);
}
else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " ")))
{
if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID)))
{
} else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " "))) {
if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID))) {
// ID=
int id = 0;
int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\"");
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
id = (id * 10) + (*val++ - '0');
}
else
{
} else {
printf("ParseIntegerID error (0x%x)\n", *val);
getchar();
return -1;
length = ParseTagInteger(buffer + pos, tag);
SaveRefString((*tag)->string, id);
}
else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
{
} else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) {
// IDREF=
int id = 0;
int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\"");
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
id = (id * 10) + (*val++ - '0');
}
else
{
} else {
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
tmpTag->tag = 0;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
}
else
{
} else {
length = ParseTagInteger(buffer + pos, tag);
}
}
/***** data ****/
else if (!strcmp(tagName, kXMLTagData))
{
length = ParseTagData(buffer + pos, tag);
}
else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " ")))
{
length = ParseTagData(buffer + pos, tag);
}
else if (!strcmp(tagName, kXMLTagDate))
{
length = ParseTagDate(buffer + pos, tag);
}
/***** date ****/
else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " ")))
{
length = ParseTagDate(buffer + pos, tag);
}
/***** false ****/
else if (!strcmp(tagName, kXMLTagFalse))
{
else if (!strcmp(tagName, kXMLTagFalse)) {
length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
}
/***** true ****/
else if (!strcmp(tagName, kXMLTagTrue))
{
else if (!strcmp(tagName, kXMLTagTrue)) {
length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
}
/***** array ****/
else if (!strcmp(tagName, kXMLTagArray))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
/***** plist ****/
/***** dict ****/
/***** data ****/
else if (!strcmp(tagName, kXMLTagData)) {
length = ParseTagData(buffer + pos, tag);
} else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " "))) {
length = ParseTagData(buffer + pos, tag);
} else if (!strcmp(tagName, kXMLTagDate)) {
length = ParseTagDate(buffer + pos, tag);
}
else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " ")))
{
/***** date ****/
else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " "))) {
length = ParseTagDate(buffer + pos, tag);
}/***** array ****/
else if (!strcmp(tagName, kXMLTagArray)) {
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
}
else if (!strcmp(tagName, kXMLTagArray "/"))
{
else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " "))) {
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
} else if (!strcmp(tagName, kXMLTagArray "/")) {
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
}
/***** unknown ****/
else
{
else {
// it wasn't parsed so we consumed no additional characters
*tag = 0;
length = 0;
tagList = 0;
pos = 0;
if (!empty)
{
while (1)
{
if (!empty) {
while (1) {
length = XMLParseNextTag(buffer + pos, &tmpTag);
if (length == -1) {
break;
tagList = tmpTag;
}
if (length == -1)
{
if (length == -1) {
XMLFreeTag(tagList);
return -1;
}
}
tmpTag = NewTag();
if (tmpTag == 0)
{
if (tmpTag == 0) {
XMLFreeTag(tagList);
return -1;
}
TagPtr tmpTag;
char* val = buffer;
int size;
if(buffer[0] == '<')
{
printf("Warning integer is non existant\n");
}
size = length = FixDataMatchingTag(buffer, kXMLTagInteger);
if (length == -1) return -1;
if (length == -1) {
return -1;
}
tmpTag = NewTag();
if (tmpTag == 0) return -1;
if (tmpTag == 0) {
return -1;
}
integer = 0;
if(size > 1 && (val[1] == 'x' || val[1] == 'X'))// Hex value
{
if(size > 1 && (val[1] == 'x' || val[1] == 'X')) { // Hex value
val += 2;
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
integer = (integer * 16) + (*val++ - '0');
}
else if ((*val >= 'a' && *val <= 'f'))// a - f
{
} else if ((*val >= 'a' && *val <= 'f')) { // a - f
integer = (integer * 16) + (*val++ - 'a' + 10);
}
else if ((*val >= 'A' && *val <= 'F'))// A - F
{
integer = (integer * 16) + (*val++ - 'a' + 10);
}
else
{
} else if ((*val >= 'A' && *val <= 'F')) { // A - F
integer = (integer * 16) + (*val++ - 'A' + 10);
} else {
printf("ParseTagInteger hex error (0x%x) in buffer %s\n", *val, buffer);
getchar();
XMLFreeTag(tmpTag);
return -1;
}
}
}
else if ( size )// Decimal value
{
if (*val == '-')
{
} else if ( size ) { // Decimal value
if (*val == '-') {
negative = true;
val++;
size--;
}
for (integer = 0; size > 0; size--)
{
if(*val) // UGLY HACK, fix me.
{
if (*val < '0' || *val > '9')
{
for (integer = 0; size > 0; size--) {
if(*val) { // UGLY HACK, fix me.
if (*val < '0' || *val > '9') {
printf("ParseTagInteger decimal error (0x%x) in buffer %s\n", *val, buffer);
getchar();
return -1;
}
integer = (integer * 10) + (*val++ - '0');
}
}
if (negative)
if (negative) {
integer = -integer;
}
}
tmpTag->type = kTagTypeInteger;
{
long cnt, cnt2;
if (tag == 0) return -1;
if (tag == 0) {
return -1;
}
// Find the start of the tag.
// Find the start of the tag.
cnt = 0;
while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++;
if (buffer[cnt] == '\0') return -1;
if (buffer[cnt] == '\0') {
return -1;
}
// Find the end of the tag.
cnt2 = cnt + 1;
while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++;
if (buffer[cnt2] == '\0') return -1;
if (buffer[cnt2] == '\0') {
return -1;
}
// Fix the tag data.
*tag = buffer + cnt + 1;
buffer[cnt2] = '\0';
if (start) *start = cnt;
if (start) {
*start = cnt;
}
return cnt2 + 1;
}
XMLFreeTag( TagPtr tag )
{
#if DOFREE
if (tag == 0)
{
if (tag == 0) {
return;
}
if (!XMLIsInteger(tag) && tag->string)
{
if (!XMLIsInteger(tag) && tag->string) {
FreeSymbol(tag->string);
}
symbol = FindSymbol(string, 0);
// Add the new symbol.
if (symbol == 0)
{
if (symbol == 0) {
symbol = (SymbolPtr)malloc(sizeof(Symbol) + 1 + strlen(string));
if (symbol == 0) //return 0;
{
if (symbol == 0) { //return 0;
stop("NULL symbol!");
}
// Update the refCount and return the string.
symbol->refCount++;
if (lastGuy && lastGuy->next != 0)
{
if (lastGuy && lastGuy->next != 0) {
stop("last guy not last!");
}
// Look for string in the list of symbols.
symbol = FindSymbol(string, &prev);
if (symbol == 0)
{
if (symbol == 0) {
return;
}
// Update the refCount.
symbol->refCount--;
if (symbol->refCount != 0)
{
if (symbol->refCount != 0) {
return;
}
// Remove the symbol from the list.
if (prev != 0)
{
if (prev != 0) {
prev->next = symbol->next;
}
else
{
} else {
gSymbolsHead = symbol->next;
}
symbol = gSymbolsHead;
prev = 0;
while (symbol != 0)
{
if (!strcmp(symbol->string, string))
{
while (symbol != 0) {
if (!strcmp(symbol->string, string)) {
break;
}
symbol = symbol->next;
}
if ((symbol != 0) && (prevSymbol != 0))
{
if ((symbol != 0) && (prevSymbol != 0)) {
*prevSymbol = prev;
}
bool XMLIsType(TagPtr dict, enum xmltype type)
{
if(!dict)
{
if(!dict) {
return (type == kTagTypeNone);
}
return (dict->type == type);
TagPtr XMLCastArray(TagPtr dict)
{
if(!dict)
{
if(!dict) {
return NULL;
}
if(dict->type == kTagTypeArray)
{
if(dict->type == kTagTypeArray) {
return dict;
}
else
{
} else {
return NULL;
}
}
TagPtr XMLCastDict(TagPtr dict)
{
if(!dict)
{
if(!dict) {
return NULL;
}
if(dict->type == kTagTypeDict)
{
if(dict->type == kTagTypeDict) {
return dict;
}
else
{
} else {
return NULL;
}
}
char* XMLCastString(TagPtr dict)
{
if(!dict)
{
if(!dict) {
return NULL;
}
if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))
{
if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)) {
return dict->string;
}
char* XMLCastData(TagPtr dict, int* length)
{
if(!dict)
{
if(!dict) {
return NULL;
}
if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey))
{
if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey)) {
*length = dict->offset;
return dict->string;
}
long XMLCastStringOffset(TagPtr dict)
{
if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)))
{
if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))) {
return dict->offset;
}
else
{
} else {
return -1;
}
}
bool XMLCastBoolean(TagPtr dict)
{
if(!dict)
{
if(!dict) {
return false;
}
if(dict->type == kTagTypeTrue)
{
if(dict->type == kTagTypeTrue) {
return true;
}
return false;
}
int XMLCastInteger(TagPtr dict)
{
if(!dict)
{
if(!dict) {
//printf("XMLCastInteger: null dict\n");
return 0;
}
if(dict->type == kTagTypeInteger)
{
if(dict->type == kTagTypeInteger) {
return (int)(dict->string);
}
return 0;
}
bool XMLAddTagToDictionary(TagPtr dict, char* key, TagPtr value)
{
if (!dict || dict->type != kTagTypeDict)
{
if (!dict || dict->type != kTagTypeDict) {
return false;
}
char* string;
tmpTag = NewTag();
if (tmpTag == 0)
{
if (tmpTag == 0) {
return false;
}
string = NewSymbol(key);
if (string == 0)
{
if (string == 0) {
XMLFreeTag(tmpTag);
return false;
}
tmpTag->tagNext = 0;
TagPtr tagList = dict->tag;
if(!tagList)
{
if(!tagList) {
// First tag
dict->tag = tmpTag;
return true;
}
while(tagList && tagList->tagNext) tagList = tagList->tagNext;
if(tagList)
{
if(tagList) {
tagList->tagNext = tmpTag;
return true;
}
trunk/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;
}
trunk/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 {
trunk/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;
}
//==============================================================================
trunk/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)
{
trunk/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 {
trunk/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");
trunk/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;
}
trunk/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
245
228
246229
247230
248231
......
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, "0000000000000000");
sprintf(asciiSerial, "000000000000000");
}
return strdup(asciiSerial);
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;
}
trunk/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))
{
trunk/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
trunk/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);
trunk/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 */
trunk/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,
trunk/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));
}
trunk/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.
trunk/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
trunk/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
1085
1086
10201087
1021
1088
1089
1090
10221091
1023
1092
1093
1094
1095
1096
1097
10241098
10251099
10261100
......
10321106
10331107
10341108
1035
1036
1037
1038
1039
1040
1041
1042
1043
1109
1110
1111
10441112
1045
1113
1114
1115
1116
1117
10461118
1047
1048
1049
1119
1120
10501121
10511122
10521123
......
10541125
10551126
10561127
1057
1058
1059
1128
1129
1130
1131
10601132
10611133
1062
1134
1135
1136
10631137
10641138
10651139
......
10721146
10731147
10741148
1075
1076
1149
1150
1151
10771152
10781153
10791154
1080
1081
1082
1083
1084
1085
1155
1156
1157
1158
1159
10861160
1087
1088
1161
1162
1163
10891164
10901165
10911166
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;
}