Chameleon

Chameleon Commit Details

Date:2014-01-20 13:59:39 (10 years 1 month ago)
Author:ErmaC
Commit:2341
Parents: 2340
Message:Fix error introduced with rev 2327. Add lzss compression. Merge latest Bungo's SMBIOS improvements. Typos...
Changes:
M/branches/ErmaC/Enoch/i386/libsaio/smbios.c
M/branches/ErmaC/Enoch/i386/boot2/lzss.c
M/branches/ErmaC/Enoch/i386/libsa/prf.c
M/branches/ErmaC/Enoch/i386/libsaio/smbios_decode.c
M/branches/ErmaC/Enoch/i386/libsaio/hpet.c
M/branches/ErmaC/Enoch/i386/libsaio/smbios.h
M/branches/ErmaC/Enoch/i386/boot2/graphics.c
M/branches/ErmaC/Enoch/i386/libsa/libsa.h
M/branches/ErmaC/Enoch/CHANGES
M/branches/ErmaC/Enoch/i386/libsaio/biosfn.c
M/branches/ErmaC/Enoch/i386/libsaio/convert.c
M/branches/ErmaC/Enoch/i386/boot2/modules.h
M/branches/ErmaC/Enoch/i386/libsaio/pci.h
M/branches/ErmaC/Enoch/i386/libsaio/msdos.c
M/branches/ErmaC/Enoch/i386/boot2/gui.c
M/branches/ErmaC/Enoch/i386/libsaio/md5c.c
M/branches/ErmaC/Enoch/i386/libsaio/smbios_getters.c
M/branches/ErmaC/Enoch/i386/libsaio/fake_efi.c
M/branches/ErmaC/Enoch/i386/config/nconf.h
M/branches/ErmaC/Enoch/i386/libsaio/device_inject.c
M/branches/ErmaC/Enoch/i386/libsa/zalloc.c
M/branches/ErmaC/Enoch/i386/libsaio/smbios_getters.h
M/branches/ErmaC/Enoch/i386/boot2/options.c
M/branches/ErmaC/Enoch/i386/libsa/strtol.c
M/branches/ErmaC/Enoch/i386/libsaio/device_inject.h
M/branches/ErmaC/Enoch/i386/libsaio/xml.c
M/branches/ErmaC/Enoch/i386/config/confdata.c
M/branches/ErmaC/Enoch/doc/BootHelp.txt
M/branches/ErmaC/Enoch/i386/boot2/resume.c
M/branches/ErmaC/Enoch/i386/libsaio/xml.h
M/branches/ErmaC/Enoch/i386/boot2/boot.c
M/branches/ErmaC/Enoch/i386/libsaio/dram_controllers.c
M/branches/ErmaC/Enoch/i386/libsaio/nvidia.c
M/branches/ErmaC/Enoch/i386/libsaio/ext2fs.c
M/branches/ErmaC/Enoch/i386/boot2/boot.h
M/branches/ErmaC/Enoch/i386/include/string.h
M/branches/ErmaC/Enoch/i386/libsaio/sys.c
M/branches/ErmaC/Enoch/i386/libsaio/device_tree.c
M/branches/ErmaC/Enoch/i386/libsa/string.c
M/branches/ErmaC/Enoch/i386/libsaio/load.c
M/branches/ErmaC/Enoch/i386/boot2/drivers.c
M/branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c
M/branches/ErmaC/Enoch/i386/libsaio/spd.c
M/branches/ErmaC/Enoch/i386/libsaio/cpu.c
M/branches/ErmaC/Enoch/i386/libsaio/platform.h
M/branches/ErmaC/Enoch/i386/libsaio/disk.c
M/branches/ErmaC/Enoch/i386/libsaio/pci_setup.c

File differences

branches/ErmaC/Enoch/i386/libsaio/smbios_getters.h
1010
1111
1212
13
13
1414
1515
1616
#define SMBIOS_RANGE_START 0x000F0000
#define SMBIOS_RANGE_END 0x000FFFFF
#define NOT_AVAILABLE"N/A"
#define NOT_AVAILABLE"N/A"
typedef enum
{
branches/ErmaC/Enoch/i386/libsaio/xml.c
2727
2828
2929
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
3058
3159
3260
......
130158
131159
132160
133
161
134162
135
136
137
138
139
140
141
142
143
163
164
165
166
167
168
169
170
171
172
144173
145174
146175
......
149178
150179
151180
152
153181
154182
155183
......
362390
363391
364392
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
393
394
395
384396
385
386
397
387398
388399
389400
390401
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
402
403
419404
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
436423
437
438
439
440
441
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442442
443
444
443
445444
446
447
448
449
450
451
452
453
445
446
447
448
449
450
451
452
453
454
455
456
457
454458
455
456459
457460
458461
459462
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
463
464
487465
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
504482
505
506
507
508
509
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
510501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
511517
512
513
514
515
516
517
518
519
520
521
522
518
519
523520
524
525521
526
527
528
529
530522
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545523
546
547
548
549
550
551524
552525
553
554
526
555527
556528
529
557530
558
559
531
560532
561533
562534
563
564
565
566
535
536
537
567538
568
569
570
539
540
541
542
543
544
545
546
547
548
549
571550
572
573
574
551
552
553
554
555
556
575557
576558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
577579
578
579
580
580
581581
582582
583583
......
601601
602602
603603
604
605
606
607
604
605
608606
609607
610608
......
620618
621619
622620
623
624
621
625622
626623
627624
628625
629626
630627
631
632
628
633629
634630
635631
......
735731
736732
737733
738
734
739735
740736
741737
......
753749
754750
755751
756
752
753
754
757755
758756
759
760757
758
759
760
761761
762762
763
764
763
765764
766
767
768
769
765
766
767
770768
771
772
773
769
774770
775
776
777
778
779
780
781
771
772
773
782774
783775
784776
785777
786778
787779
788
789
790
791
792
780
781
793782
794783
795784
796785
797786
798
799
800
801
802
803
787
788
789
804790
805791
806792
807793
808
794
809795
810796
811797
812798
813
799
814800
801
815802
816803
817804
......
914901
915902
916903
917
904
905
906
918907
919
908
909
910
920911
921
922
923
924
925
926
927
928
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
929934
930
931
932
933
935
936
937
938
934939
935
940
941
942
943
944
945
946
936947
937948
938949
......
10061017
10071018
10081019
1009
1010
1020
10111021
10121022
10131023
1014
1015
1024
10161025
10171026
10181027
......
10591068
10601069
10611070
1062
1063
1071
10641072
1065
1066
1073
10671074
10681075
10691076
......
10791086
10801087
10811088
1082
1083
1089
10841090
10851091
10861092
......
10991105
11001106
11011107
1102
1103
1108
11041109
11051110
11061111
11071112
11081113
11091114
1110
1111
1115
11121116
11131117
11141118
11151119
1116
1117
1120
11181121
1119
1120
1121
1122
11221123
11231124
11241125
......
11381139
11391140
11401141
1141
1142
1143
1144
1142
1143
11451144
11461145
11471146
......
11491148
11501149
11511150
1152
1153
1151
11541152
11551153
11561154
......
11591157
11601158
11611159
1162
1163
1160
11641161
11651162
11661163
......
11741171
11751172
11761173
1177
1178
1174
11791175
11801176
1181
1182
1183
1177
11841178
1185
1186
1187
1179
11881180
11891181
11901182
......
12011193
12021194
12031195
1204
1205
1196
12061197
12071198
1208
1209
1210
1199
12111200
1212
1213
1214
1201
12151202
12161203
12171204
......
12231210
12241211
12251212
1226
1227
1213
12281214
12291215
12301216
1231
1232
1217
12331218
12341219
12351220
......
12381223
12391224
12401225
1241
1242
1226
12431227
12441228
12451229
1246
1247
1230
12481231
12491232
12501233
......
12551238
12561239
12571240
1258
1259
1241
12601242
1261
1262
1263
1243
12641244
12651245
12661246
......
12721252
12731253
12741254
1275
1276
1255
12771256
12781257
1279
1280
1281
1258
12821259
12831260
1284
12851261
12861262
12871263
......
12921268
12931269
12941270
1295
1296
1271
12971272
12981273
12991274
1300
1301
1275
13021276
13031277
1304
13051278
13061279
13071280
13081281
13091282
1310
1311
1283
13121284
13131285
13141286
......
13161288
13171289
13181290
1319
1320
1291
13211292
13221293
13231294
13241295
1325
1326
1296
13271297
13281298
13291299
......
13351305
13361306
13371307
1338
1339
1308
13401309
13411310
13421311
13431312
13441313
1345
1346
1314
13471315
13481316
13491317
#include "sl.h"
#include "xml.h"
#define kXMLTagPList "plist "
#define kXMLTagPListLen (sizeof(kXMLTagPList) - 1)
#define kXMLTagDict "dict"
#define kXMLTagDictLen (sizeof(kXMLTagDict) - 1)
#define kXMLTagKey "key"
#define kXMLTagKeyLen (sizeof(kXMLTagKey) - 1)
#define kXMLTagString "string"
#define kXMLTagStringLen (sizeof(kXMLTagString) - 1)
#define kXMLTagInteger "integer"
#define kXMLTagIntegerLen (sizeof(kXMLTagInteger) - 1)
#define kXMLTagData "data"
#define kXMLTagDataLen (sizeof(kXMLTagData) - 1)
#define kXMLTagDate "date"
#define kXMLTagDateLen (sizeof(kXMLTagDate) - 1)
#define kXMLTagFalse "false/"
#define kXMLTagFalseLen (sizeof(kXMLTagFalse) - 1)
#define kXMLTagTrue "true/"
#define kXMLTagTrueLen (sizeof(kXMLTagTrue) - 1)
#define kXMLTagArray "array"
#define kXMLTagArrayLen (sizeof(kXMLTagArray) - 1)
// for back-references used by libkern serializer
#define kXMLTagReference "reference"
#define kXMLTagReferenceLen (sizeof(kXMLTagReference) - 1)
#define kXMLStringID "ID="
#define kXMLStringIDLen (sizeof(kXMLStringID) - 1)
#define kXMLStringIDRef "IDREF="
#define kXMLStringIDRefLen (sizeof(kXMLStringIDRef) - 1)
string_ref *ref_strings = NULL;
/// TODO: remove below
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))
{
length = 0;
// just a header; nothing to parse
// return-via-reference tag should be left alone
}
/***** dict ****/
else if (!strcmp(tagName, kXMLTagDict))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
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 " ")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
/* Check most common cases first, make them fast */
/***** key ****/
else if (!strcmp(tagName, kXMLTagKey))
{
if (!strcmp(tagName, kXMLTagKey)) {
length = ParseTagKey(buffer + pos, tag);
}
/***** string ****/
else if (!strcmp(tagName, kXMLTagString))
{
length = ParseTagString(buffer + pos, tag);
}
else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " ")))
{
// TODO: save tag if if found
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
{
id = (id * 10) + (*val++ - '0');
}
else
{
printf("ParseStringID error (0x%x)\n", *val);
getchar();
return -1;
}
}
else if (!strncmp(tagName, kXMLTagString, kXMLTagStringLen)) {
if (!tagName[kXMLTagStringLen]) { /* <string> */
length = ParseTagString(buffer + pos, tag);
SaveRefString(buffer + pos, id);
}
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
{
id = (id * 10) + (*val++ - '0');
} else if (' ' == tagName[kXMLTagStringLen]) { /* <string ...> */
// TODO: save tag if if found
if(!strncmp(tagName + kXMLTagStringLen + 1, (kXMLStringID "\""), kXMLStringIDLen + 1)) { /* <string ID="...> */
// ID=
int id = 0;
/* find end of ID string */
int cnt = kXMLTagStringLen + 1 + kXMLStringIDLen + 2;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + kXMLTagStringLen + 1 + kXMLStringIDLen + 1;
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
id = (id * 10) + (*val++ - '0');
} else {
printf("ParseStringID error (0x%x)\n", *val);
getchar();
return -1;
}
}
else
{
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
length = ParseTagString(buffer + pos, tag);
SaveRefString(buffer + pos, id);
} else if(!strncmp(tagName + kXMLTagStringLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) { /* <string IDREF= ...> */
// 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
id = (id * 10) + (*val++ - '0');
} else {
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
}
}
}
char* str = GetRefString(id);
char* str = GetRefString(id);
TagPtr tmpTag = NewTag();
tmpTag->type = kTagTypeString;
tmpTag->string = str;
tmpTag->tag = 0;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
TagPtr tmpTag = NewTag();
tmpTag->type = kTagTypeString;
tmpTag->string = str;
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 { /* unrecognized <string...> */
*tag = 0;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
}
}
/***** integer ****/
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)))
{
// 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
{
id = (id * 10) + (*val++ - '0');
}
else
{
printf("ParseIntegerID error (0x%x)\n", *val);
getchar();
return -1;
}
}
else if (!strncmp(tagName, kXMLTagInteger, kXMLTagIntegerLen)) {
if (!tagName[kXMLTagIntegerLen]) { /* <integer> */
length = ParseTagInteger(buffer + pos, tag);
SaveRefString((*tag)->string, id);
}
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
{
id = (id * 10) + (*val++ - '0');
} else if (' ' == tagName[kXMLTagIntegerLen]) { /* <integer ...> */
if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringID, kXMLStringIDLen)) { /* <integer ID=...> */
// 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
id = (id * 10) + (*val++ - '0');
} else {
printf("ParseIntegerID error (0x%x)\n", *val);
getchar();
return -1;
}
}
else
{
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
length = ParseTagInteger(buffer + pos, tag);
SaveRefString((*tag)->string, id);
} else if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) { /* <integer IDREF=...> */
// 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
id = (id * 10) + (*val++ - '0');
} else {
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
}
}
int integer = (int)GetRefString(id);
TagPtr tmpTag = NewTag();
tmpTag->type = kTagTypeInteger;
tmpTag->string = (char*) integer;
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 {
length = ParseTagInteger(buffer + pos, tag);
}
int integer = (int)GetRefString(id);
TagPtr tmpTag = NewTag();
tmpTag->type = kTagTypeInteger;
tmpTag->string = (char*) integer;
tmpTag->tag = 0;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
} else { /* unrecognized <integer...> */
*tag = 0;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
}
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 ****/
else if (!strncmp(tagName, kXMLTagPList, kXMLTagPListLen)) {
length = 0;
}
else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " ")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
/***** dict ****/
else if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen)) {
if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen) && tagName[strlen(tagName)-1] == '/') { /* <dict.../> */
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
} else if (!tagName[kXMLTagDictLen] || ' ' == tagName[kXMLTagDictLen]) { /* <dict> or<dict ...> */
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
} else { /* unrecognized <dict...> */
*tag = 0;
length = 0;
}
}
else if (!strcmp(tagName, kXMLTagArray "/"))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
/***** data ****/
else if ((!strncmp(tagName, kXMLTagData, kXMLTagDataLen))
&& (!tagName[kXMLTagDataLen] /* <data> */
|| ' ' == tagName[kXMLTagDataLen])) { /* <data ...> */
length = ParseTagData(buffer + pos, tag);
}
/***** date ****/
else if ((!strncmp(tagName, kXMLTagDate, kXMLTagDateLen))
&& (!tagName[kXMLTagDateLen] /* <date> */
|| ' ' == tagName[kXMLTagDateLen])) { /* <date ...> */
length = ParseTagDate(buffer + pos, tag);
}
/***** array ****/
else if (!strncmp(tagName, kXMLTagArray, kXMLTagArrayLen)) { /* <array...> */
char c = tagName[kXMLTagArrayLen];
if ('/' == c) { /* <array/> */
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
}
else if ('\0' == c || ' ' == c) { /* <array> or <array ...> */
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
} else { /* unrecognized <array...> */
*tag = 0;
length = 0;
}
}
/***** unknown ****/
else
{
// it wasn't parsed so we consumed no additional characters
else {
*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;
static long
GetNextTag( char * buffer, char ** tag, long * start )
{
long cnt, cnt2;
char* tagStart = buffer;
char* tagEnd;
char c;
if (tag == 0) return -1;
if (!tag) {
return -1;
}
// Find the start of the tag.
cnt = 0;
while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++;
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;
/* Find the start of the tag. */
do {
c = *tagStart++;
if (c == '<') {
break;
}
} while (c);
if (!c) {
return -1;
}
/* tagStart points just past the '<' */
/* Find the end of the tag. */
tagEnd = tagStart;
do {
c = *tagEnd++;
if (c == '>') {
break;
}
} while (c);
if (!c) {
return -1;
}
// Fix the tag data.
*tag = buffer + cnt + 1;
buffer[cnt2] = '\0';
if (start) *start = cnt;
/* tagEnd points just past the '>' */
/* Fix up tag data by nulling out the '>' */
--tagEnd;
*tagEnd = '\0';
return cnt2 + 1;
*tag = tagStart; /* first char after initial '<' */
if (start) {
*start = (long) (tagStart - buffer) - 1; /* offset of the initial '<' itself */
}
/* Return offset to the char after '>' */
return (long) (tagEnd - buffer) + 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;
}
branches/ErmaC/Enoch/i386/libsaio/xml.h
4848
4949
5050
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
6651
6752
6853
extern string_ref* ref_strings;
#define kXMLTagPList "plist "
#define kXMLTagDict "dict"
#define kXMLTagKey "key"
#define kXMLTagString "string"
#define kXMLTagInteger "integer"
#define kXMLTagData "data"
#define kXMLTagDate "date"
#define kXMLTagFalse "false/"
#define kXMLTagTrue "true/"
#define kXMLTagArray "array"
// for back-references used by libkern serializer
#define kXMLTagReference "reference"
#define kXMLStringID "ID="
#define kXMLStringIDRef "IDREF="
#define kPropCFBundleIdentifier ("CFBundleIdentifier")
#define kPropCFBundleExecutable ("CFBundleExecutable")
#define kPropOSBundleRequired ("OSBundleRequired")
branches/ErmaC/Enoch/i386/libsaio/ext2fs.c
1818
1919
2020
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
2143
2244
2345
24
46
2547
48
2649
2750
28
29
51
3052
3153
3254
33
34
55
3556
3657
3758
......
4667
4768
4869
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
return (OSReadLittleInt16(buf+0x438,0)==0xEF53);
}
void EX2GetDescription(CICell ih, char *str, long strMaxLen)
{
char * buf=malloc (EX2ProbeSize);
str[0]=0;
if (!buf) {
return;
}
Seek(ih, 0);
Read(ih, (long)buf, EX2ProbeSize);
if (!EX2Probe (buf)) {
free (buf);
return;
}
if (OSReadLittleInt32 (buf+0x44c,0)<1) {
free (buf);
return;
}
str[strMaxLen]=0;
strncpy (str, buf+0x478, MIN(strMaxLen, 16));
free (buf);
}
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;
}
free (buf);
return 0;
}
void EX2GetDescription(CICell ih, char *str, long strMaxLen)
{
char * buf=malloc (EX2ProbeSize);
str[0]=0;
if (!buf)
return;
Seek(ih, 0);
Read(ih, (long)buf, EX2ProbeSize);
if (!EX2Probe (buf))
{
free (buf);
return;
}
if (OSReadLittleInt32 (buf+0x44c,0)<1)
{
free (buf);
return;
}
str[strMaxLen]=0;
strncpy (str, buf+0x478, MIN(strMaxLen, 16));
free (buf);
}
branches/ErmaC/Enoch/i386/libsaio/device_tree.c
297297
298298
299299
300
300
301301
302302
303303
for (count = 0, prop = node->properties; prop != 0; count++, prop = prop->next)
{
flatProp = (DeviceTreeNodeProperty *)buffer;
strcpy(flatProp->name, prop->name);
strncpy(flatProp->name, prop->name, kPropNameLength);
flatProp->length = prop->length;
buffer += sizeof(DeviceTreeNodeProperty);
bcopy(prop->value, buffer, prop->length);
branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c
516516
517517
518518
519
520
519
521520
522521
523
524
525
522
526523
527524
528525
529526
530
527
531528
529
532530
533531
534532
535533
536534
537535
538
539
536
540537
541538
542539
543540
544541
545
546
547
542
543
548544
549
550
551
545
546
552547
553548
554549
555
550
556551
552
557553
558554
559555
......
596592
597593
598594
599
600
601
595
602596
603597
604598
......
607601
608602
609603
610
611
604
612605
613606
614
615
616
607
617608
618609
619610
620
621
611
622612
623613
624614
625615
626616
627617
628
618
629619
630620
631621
......
636626
637627
638628
639
640
629
641630
642631
643632
......
647636
648637
649638
650
651
639
652640
653641
654642
......
660648
661649
662650
663
664
651
665652
666653
667654
......
687674
688675
689676
690
691
692
677
693678
694679
695680
......
707692
708693
709694
710
711
695
712696
713697
714
715
698
716699
717
718
719
700
720701
721702
722
723
724
703
725704
726705
727706
728707
729
730
708
731709
732710
733711
......
738716
739717
740718
741
742
743
719
744720
745721
746722
747723
748724
749725
750
751
752
753
726
727
754728
755
756
757
729
758730
759731
760732
761
762
763
733
764734
765735
766736
767737
768
769
770
771
738
739
772740
773741
774742
775
776
777
743
778744
779745
780746
......
784750
785751
786752
787
788
789
790
753
754
791755
792756
793757
......
796760
797761
798762
799
800
801
763
802764
803765
804766
......
812774
813775
814776
815
816
777
817778
818779
819780
820
821
781
822782
823783
824784
......
868828
869829
870830
871
872
831
873832
874
875
876
833
877834
878835
879836
......
882839
883840
884841
885
886
842
887843
888
889
890
844
891845
892846
893847
894848
895849
896850
897
898
851
899852
900
901
902
853
903854
904855
905856
906857
907858
908859
909
910
860
911861
912
913
914
862
915863
916864
917865
918866
919867
920868
921
922
869
923870
924
925
926
871
927872
928873
929874
930875
931876
932877
933
934
878
935879
936
937
938
880
939881
940882
941883
942884
943885
944886
945
946
887
947888
948
949
950
889
951890
952891
953892
954893
955894
956895
957
958
896
959897
960
961
962
898
963899
964900
965901
......
998934
999935
1000936
1001
1002
937
1003938
1004939
1005940
1006941
1007
1008
942
1009943
1010
1011
1012
944
1013945
1014946
1015947
......
1023955
1024956
1025957
1026
1027
958
1028959
1029
1030
960
1031961
1032
1033
1034
962
1035963
1036964
1037965
......
1052980
1053981
1054982
1055
1056
983
1057984
1058985
1059986
......
1064991
1065992
1066993
1067
1068
994
1069995
1070
1071
996
1072997
1073998
1074999
......
10761001
10771002
10781003
1079
1080
1004
10811005
10821006
10831007
10841008
10851009
1086
1087
1010
10881011
10891012
10901013
10911014
10921015
1093
1094
1016
10951017
10961018
10971019
10981020
10991021
1100
1101
1022
11021023
11031024
11041025
11051026
11061027
1107
1108
1028
11091029
11101030
11111031
11121032
11131033
1114
1115
1034
11161035
11171036
11181037
11191038
11201039
1121
1122
1040
11231041
11241042
11251043
11261044
11271045
1128
1129
1046
11301047
11311048
1132
1133
1049
11341050
11351051
11361052
11371053
11381054
1139
1140
1055
11411056
11421057
1143
1144
1058
11451059
11461060
11471061
11481062
11491063
1150
1151
1064
11521065
11531066
1154
1155
1067
11561068
11571069
11581070
11591071
11601072
1161
1162
1073
11631074
11641075
1165
1166
1076
11671077
11681078
11691079
11701080
11711081
1172
1173
1082
11741083
11751084
1176
1177
1085
11781086
11791087
11801088
11811089
11821090
1183
1184
1091
11851092
11861093
1187
1188
1094
11891095
11901096
11911097
11921098
11931099
1194
1195
1100
11961101
11971102
1198
1199
1103
12001104
12011105
12021106
12031107
12041108
1205
1206
1109
12071110
12081111
1209
1210
1112
12111113
12121114
12131115
12141116
12151117
12161118
1217
1218
1119
12191120
12201121
12211122
12221123
12231124
1224
1225
1125
12261126
12271127
12281128
......
12311131
12321132
12331133
1234
1235
1134
12361135
12371136
12381137
12391138
12401139
12411140
1242
1243
1141
12441142
12451143
12461144
......
12611159
12621160
12631161
1264
1265
1162
12661163
12671164
1268
1165
12691166
1167
12701168
12711169
12721170
......
12791177
12801178
12811179
1282
1283
1284
1180
12851181
12861182
12871183
12881184
1289
1290
1185
12911186
12921187
12931188
......
12951190
12961191
12971192
1298
1299
1193
13001194
13011195
13021196
......
13081202
13091203
13101204
1311
1312
1205
13131206
1314
1315
1207
13161208
13171209
13181210
13191211
1320
1321
1212
13221213
13231214
13241215
13251216
13261217
1327
1328
1218
13291219
13301220
13311221
13321222
13331223
1334
1335
1224
13361225
13371226
13381227
13391228
13401229
1341
1342
1230
13431231
13441232
13451233
13461234
13471235
1348
1349
1236
13501237
13511238
13521239
1353
1240
13541241
1355
1356
1242
13571243
13581244
13591245
13601246
13611247
1362
1363
1248
13641249
13651250
13661251
13671252
13681253
1369
1370
1254
13711255
13721256
1373
1374
1257
13751258
13761259
13771260
......
13801263
13811264
13821265
1383
1384
1266
13851267
13861268
1387
1388
1269
13891270
13901271
13911272
......
13941275
13951276
13961277
1397
1398
1278
13991279
14001280
1401
1402
1281
14031282
14041283
14051284
......
14081287
14091288
14101289
1411
1412
1290
14131291
14141292
1415
1416
1293
14171294
14181295
14191296
......
14221299
14231300
14241301
1425
1426
1302
14271303
1428
1429
1430
1304
1305
14311306
14321307
14331308
......
14361311
14371312
14381313
1439
1440
1314
14411315
14421316
1443
1444
1317
14451318
14461319
14471320
......
14501323
14511324
14521325
1453
1454
1326
14551327
14561328
1457
1458
1329
14591330
14601331
14611332
......
14641335
14651336
14661337
1467
1468
1338
14691339
14701340
1471
1472
1341
14731342
14741343
14751344
......
14781347
14791348
14801349
1481
1482
1350
14831351
14841352
14851353
14861354
14871355
14881356
1489
1490
1357
14911358
14921359
14931360
......
14981365
14991366
15001367
1501
1502
1368
15031369
15041370
15051371
15061372
15071373
1508
1509
1374
15101375
15111376
15121377
......
15341399
15351400
15361401
1537
1538
1402
15391403
15401404
1541
1405
15421406
1407
15431408
15441409
1545
15461410
15471411
15481412
15491413
15501414
1551
1552
1553
1415
15541416
15551417
15561418
......
15731435
15741436
15751437
1576
1577
1438
15781439
15791440
15801441
15811442
15821443
15831444
1584
15851445
15861446
15871447
1588
1589
1448
15901449
15911450
15921451
1593
1594
1595
1452
15961453
15971454
15981455
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");
}
new_dsdt = loadACPITable(dirSpec);
/* Try using the file specified with the HPET option */
if (getValueForKey(kHPET, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kHPET, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "HPET.aml");
}
// Load replacement HPET
new_hpet = loadACPITable(dirSpec);
/* Try using the file specified with the SBST option */
if (getValueForKey(kSBST, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kSBST, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "SBST.aml");
}
// Load replacement SBST
new_sbst = loadACPITable(dirSpec);
/* Try using the file specified with the ECDT option */
if (getValueForKey(kECDT, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kECDT, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "ECDT.aml");
}
// Load replacement ECDT
new_ecdt = loadACPITable(dirSpec);
/* Try using the file specified with the ASF! option */
if (getValueForKey(kASFT, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kASFT, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "ASFT.aml");
}
// Load replacement ASF!
new_asft = loadACPITable(dirSpec);
/* Try using the file specified with the DMAR option */
if (getValueForKey(kDMAR, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kDMAR, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "DMAR.aml");
}
// Load replacement DMAR
new_dmar = loadACPITable(dirSpec);
/* Try using the file specified with the APIC option */
if (getValueForKey(kAPIC, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kAPIC, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "APIC.aml");
}
// Load replacement APIC
new_apic = loadACPITable(dirSpec);
// Try using the file specified with the MCFG option */
if (getValueForKey(kMCFG, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kMCFG, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "MCFG.aml");
}
// Load replacement MCFG
{
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 (drop_hpet && tableSign(table, "HPET"))
{
if (drop_hpet && tableSign(table, "HPET")) {
verbose("OEM HPET table was dropped\n");
dropoffset++;
continue;
}
if (drop_slic && tableSign(table, "SLIC"))
{
if (drop_slic && tableSign(table, "SLIC")) {
verbose("OEM SLIC table was dropped\n");
dropoffset++;
continue;
}
if (drop_sbst && tableSign(table, "SBST"))
{
if (drop_sbst && tableSign(table, "SBST")) {
verbose("OEM SBST table was dropped\n");
dropoffset++;
continue;
}
if (drop_ecdt && tableSign(table, "ECDT"))
{
if (drop_ecdt && tableSign(table, "ECDT")) {
verbose("OEM ECDT table was dropped\n");
dropoffset++;
continue;
}
if (drop_asft && tableSign(table, "ASF!"))
{
if (drop_asft && tableSign(table, "ASF!")) {
verbose("OEM ASF! table was dropped\n");
dropoffset++;
continue;
}
if (drop_dmar && tableSign(table, "DMAR"))
{
if (drop_dmar && tableSign(table, "DMAR")) {
verbose("OEM DMAR table was dropped\n");
dropoffset++;
continue;
}
if (tableSign(table, "HPET"))
{
if (tableSign(table, "HPET")) {
DBG("HPET found\n");
verbose("Custom HPET table was found\n");
if(new_hpet)
{
if(new_hpet) {
rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;
}
continue;
}
if (tableSign(table, "SBST"))
{
if (tableSign(table, "SBST")) {
DBG("SBST found\n");
verbose("Custom SBST table was found\n");
if(new_sbst)
{
if(new_sbst) {
rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;
}
continue;
}
if (tableSign(table, "ECDT"))
{
if (tableSign(table, "ECDT")) {
DBG("ECDT found\n");
verbose("Custom ECDT table was found\n");
if(new_ecdt)
{
if(new_ecdt) {
rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;
}
continue;
}
if (tableSign(table, "ASF!"))
{
if (tableSign(table, "ASF!")) {
DBG("ASF! found\n");
verbose("Custom ASF! table was found\n");
if(new_asft)
{
if(new_asft) {
rsdt_entries[i-dropoffset]=(uint32_t)new_asft;
}
continue;
}
if (tableSign(table, "DMAR"))
{
if (tableSign(table, "DMAR")) {
DBG("DMAR found\n");
verbose("Custom DMAR table was found\n");
if(new_dmar)
{
if(new_dmar) {
rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;
}
continue;
}
if (tableSign(table, "APIC"))
{
if (tableSign(table, "APIC")) {
DBG("APIC found\n");
verbose("Custom APIC table was found\n");
if(new_apic)
{
if(new_apic) {
rsdt_entries[i-dropoffset]=(uint32_t)new_apic;
}
continue;
}
if (tableSign(table, "MCFG"))
{
if (tableSign(table, "MCFG")) {
DBG("MCFG found\n");
verbose("Custom MCFG table was found\n");
if(new_mcfg)
{
if(new_mcfg) {
rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;
}
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 (drop_hpet && tableSign(table, "HPET"))
{
if (drop_hpet && tableSign(table, "HPET")) {
verbose("OEM HPET table was dropped\n");
dropoffset++;
continue;
}
if (drop_slic && tableSign(table, "SLIC"))
{
if (drop_slic && tableSign(table, "SLIC")) {
verbose("OEM SLIC table was dropped\n");
dropoffset++;
continue;
}
if (drop_sbst && tableSign(table, "SBST"))
{
if (drop_sbst && tableSign(table, "SBST")) {
verbose("OEM SBST table was dropped\n");
dropoffset++;
continue;
}
if (drop_ecdt && tableSign(table, "ECDT"))
{
if (drop_ecdt && tableSign(table, "ECDT")) {
verbose("OEM ECDT table was dropped\n");
dropoffset++;
continue;
}
}
if (drop_asft && tableSign(table, "ASF!"))
{
if (drop_asft && tableSign(table, "ASF!")) {
verbose("OEM ASF! table was dropped\n");
dropoffset++;
continue;
}
if (drop_dmar && tableSign(table, "DMAR"))
{
if (drop_dmar && tableSign(table, "DMAR")) {
verbose("OEM DMAR table 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, "HPET"))
{
if (tableSign(table, "HPET")) {
DBG("HPET found\n");
if (new_hpet)
{
if (new_hpet) {
xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;
}
continue;
}
if (tableSign(table, "SBST"))
{
if (tableSign(table, "SBST")) {
DBG("SBST found\n");
if (new_sbst)
{
if (new_sbst) {
xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;
}
continue;
}
if (tableSign(table, "ECDT"))
{
if (tableSign(table, "ECDT")) {
DBG("ECDT found\n");
if (new_ecdt)
{
if (new_ecdt) {
xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;
}
continue;
}
if (tableSign(table, "ASF!"))
{
if (tableSign(table, "ASF!")) {
DBG("ASF! found\n");
;
if (new_asft)
{
if (new_asft) {
xsdt_entries[i-dropoffset]=(uint32_t)new_asft;
}
continue;
}
if (tableSign(table, "DMAR"))
{
if (tableSign(table, "DMAR")) {
DBG("DMAR found\n");
if (new_dmar)
{
if (new_dmar) {
xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;
}
continue;
}
if (tableSign(table, "APIC"))
{
if (tableSign(table, "APIC")) {
DBG("APIC found\n");
if (new_apic)
{
if (new_apic) {
xsdt_entries[i-dropoffset]=(uint32_t)new_apic;
}
continue;
}
if (tableSign(table, "MCFG"))
{
if (tableSign(table, "MCFG")) {
DBG("MCFG found\n");
if (new_mcfg)
{
if (new_mcfg) {
xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;
}
continue;
}
if (tableSign(table, "FACP"))
{
if (tableSign(table, "FACP")) {
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];
DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt,
fadt->Length);
if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)
{
if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000) {
verbose("FADT incorrect or after 4GB. Dropping XSDT\n");
goto drop_xsdt;
}
DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);
// Generate _CST SSDT
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
{
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) {
generate_cstates = false; // Generate SSDT only once!
ssdt_count++;
}
// Generating _PSS SSDT
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
{
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) {
generate_pstates = false; // Generate SSDT only once!
ssdt_count++;
}
xsdt_entries=(uint64_t *)(xsdt_mod+1);
// Mozodojo: Insert additional SSDTs into XSDT
if(ssdt_count > 0)
{
if(ssdt_count > 0) {
int j;
for (j=0; j<ssdt_count; j++)
for (j=0; j<ssdt_count; j++) {
xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
}
verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);
}
// Correct the checksum of XSDT
xsdt_mod->Checksum=0;
xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);
}
else
{
} else {
drop_xsdt:
DBG("About to drop XSDT\n");
DBG("New checksum %d\n", rsdp_mod->Checksum);
if (version)
{
if (version) {
DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);
rsdp_mod->ExtendedChecksum=0;
rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);
DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);
}
//verbose("Patched ACPI version %d DSDT\n", version+1);
if (version)
{
if (version) {
/* XXX aserebln why uint32 cast if pointer is uint64 ? */
acpi20_p = (uint32_t)rsdp_mod;
addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
}
else
{
} else {
/* XXX aserebln why uint32 cast if pointer is uint64 ? */
acpi10_p = (uint32_t)rsdp_mod;
addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
branches/ErmaC/Enoch/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
......
452418
453419
454420
455
456
421
457422
458423
459424
460425
461426
462427
463
464
465
466
428
429
467430
468431
469432
"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;
pci_dt_t*current = pci_dt;
int i;
while (current)
{
while (current) {
#if 0
printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n",
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, current->vendor_id, current->device_id,
get_pci_dev_path(current));
#endif
for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ )
{
if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device)
{
for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) {
if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device) {
smbus_controllers[i].read_smb(current); // read smb
return true;
}
branches/ErmaC/Enoch/i386/libsaio/device_inject.c
159159
160160
161161
162
163
162
164163
165164
166165
......
196195
197196
198197
199
200
201
202
203
204198
205
206
207
208
209
210
211
212
213
214
215
199
200
201
216202
217
218
219
220
221
222
223
224
225
203
204
205
206
207
208
209
210
211
226212
213
214
215
216
217
218
219
220
221
227222
228223
229224
230225
231
232
226
233227
234228
235
236
237
238
229
230
239231
240232
241233
......
246238
247239
248240
249
250
241
251242
252
253
254
243
255244
256245
257246
......
318307
319308
320309
321
322
310
323311
324312
325313
326314
327
328
329
330
331
332
315
316
317
333318
334319
335320
......
355340
356341
357342
358
359
343
360344
361345
362346
......
364348
365349
366350
367
368
369
370
351
352
371353
372354
373355
inti;
for(i = 0; i < numpaths; i++)
{
for(i = 0; i < numpaths; i++) {
device->pci_dev_path[i].length = 0x06;
device->pci_dev_path[i].type = 0x01;
device->pci_dev_path[i].subtype = 0x01;
}
uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2);
uint8_t *data = (uint8_t*)malloc(length);
{
if(!data)
{
return 0;
}
memset(data, 0, length);
uint32_t off= 0;
data[off+1] = ((strlen(nm) * 2) + 6) >> 8;
data[off] = ((strlen(nm) * 2) + 6) & 0x00FF;
off += 4;
uint32_t i=0, l = strlen(nm);
for(i = 0 ; i < l ; i++, off += 2)
{
data[off] = *nm++;
}
if(!data) {
return 0;
}
off += 2;
l = len;
uint32_t *datalength = (uint32_t*)&data[off];
*datalength = (uint32_t)(l + 4);
off += 4;
for(i = 0 ; i < l ; i++, off++)
{
data[off] = *vl++;
}
memset(data, 0, length);
uint32_t off= 0;
data[off+1] = ((strlen(nm) * 2) + 6) >> 8;
data[off] = ((strlen(nm) * 2) + 6) & 0x00FF;
off += 4;
uint32_t i=0, l = strlen(nm);
for(i = 0 ; i < l ; i++, off += 2) {
data[off] = *nm++;
}
off += 2;
l = len;
uint32_t *datalength = (uint32_t*)&data[off];
*datalength = (uint32_t)(l + 4);
off += 4;
for(i = 0 ; i < l ; i++, off++) {
data[off] = *vl++;
}
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);
}
void devprop_free_string(DevPropString *string)
{
if(!string)
{
if(!string) {
return;
}
int i;
for(i = 0; i < string->numentries; i++)
{
if(string->entries[i])
{
if(string->entries[i]->data)
{
for(i = 0; i < string->numentries; i++) {
if(string->entries[i]) {
if(string->entries[i]->data) {
free(string->entries[i]->data);
string->entries[i]->data = NULL;
}
inti;
charbuf[3];
if (hex == NULL || bin == NULL || len <= 0 || strlen(hex) != len * 2)
{
if (hex == NULL || bin == NULL || len <= 0 || strlen(hex) != len * 2) {
printf("[ERROR] bin2hex input error\n");
return -1;
}
buf[2] = '\0';
p = (char *) hex;
for (i = 0; i < len; i++)
{
if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1]))
{
for (i = 0; i < len; i++) {
if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) {
printf("[ERROR] bin2hex '%s' syntax error\n", hex);
return -2;
}
branches/ErmaC/Enoch/i386/libsaio/device_inject.h
8080
8181
8282
83
8384
intdevprop_add_network_template(DevPropDevice *device, uint16_t vendor_id);
inthex2bin(const char *hex, uint8_t *bin, int len);
#endif /* !__LIBSAIO_DEVICE_INJECT_H */
branches/ErmaC/Enoch/i386/libsaio/dram_controllers.c
3737
3838
3939
40
40
4141
4242
43
44
43
4544
4645
4746
......
5756
5857
5958
60
61
59
6260
6361
6462
6563
66
67
68
64
65
6966
7067
7168
......
8279
8380
8481
85
82
8683
8784
8885
8986
9087
91
88
9289
93
94
95
90
91
9692
9793
98
94
9995
100
96
10197
102
98
10399
104
100
105101
106
107
108
102
103
109104
110
111
105
112106
113107
114108
115109
116110
117
111
118112
119113
120
121
114
122115
123116
124117
......
127120
128121
129122
130
123
131124
132
133
125
134126
135127
136128
......
138130
139131
140132
141
133
142134
143
144
135
145136
146137
147138
148139
149140
150141
151
142
152143
153144
154145
......
159150
160151
161152
162
153
163154
164155
165156
166157
167
158
168159
169160
170161
......
175166
176167
177168
178
169
179170
180171
181172
182173
183174
184
175
185176
186
187
188
177
178
189179
190180
191181
192
193
182
183
194184
195
196
197
185
186
198187
199
200
188
201189
202190
203191
204192
205193
206
194
207195
208
209
196
210197
211198
212199
......
214201
215202
216203
217
204
218205
219206
220
221
207
222208
223209
224210
......
227213
228214
229215
230
231
216
232217
233218
234219
235
220
236221
237
222
238223
239224
225
226
240227
241228
242229
......
244231
245232
246233
247
234
248235
249236
250237
251
238
252239
253240
241
254242
255243
256244
......
259247
260248
261249
262
250
263251
264252
265253
266254
267255
268
256
269257
270258
271259
272
260
273261
274262
275
263
276264
277265
278
266
279267
280268
281
269
282270
283271
284
272
285273
286274
287
275
288276
289277
290
278
291279
292280
293
281
294282
295283
296
284
297285
298286
299
287
300288
301289
302
290
303291
304292
305
293
306294
307295
308
296
309297
310298
311
299
312300
313301
314302
......
322310
323311
324312
325
313
326314
327315
328316
329
317
330318
331319
332
320
333321
334322
335
323
336324
337325
338
326
339327
340328
341
329
342330
343331
344
332
345333
346334
347
335
348336
349337
350
338
351339
352340
353
341
354342
355343
356
344
357345
358346
359
347
360348
361349
362350
......
366354
367355
368356
369
357
370358
371359
372360
373361
374
362
375363
376364
377
365
378366
379367
380368
381
369
382370
383
384
371
372
385373
386374
387
375
388376
389377
390
378
391379
392380
393
394
381
382
395383
396
384
397385
398386
399
387
400388
401389
402
390
403391
404392
405
393
406394
407
408
395
396
409397
410398
411399
412
400
413401
414402
415403
416404
417405
418
406
419407
420
408
421409
422410
423411
......
434422
435423
436424
437
425
438426
439427
440
428
441429
442430
443
431
444432
445433
446434
......
454442
455443
456444
457
445
458446
459447
460448
461
449
462450
463451
464
452
465453
466454
467455
......
474462
475463
476464
477
465
478466
479467
480
468
481469
482470
483
471
484472
485473
486
474
487475
488476
489
477
490478
491479
492480
......
564552
565553
566554
567
555
568556
569557
570558
571559
572
573
574
575
560
561
576562
577563
578564
579565
580
566
581567
582568
583569
......
596582
597583
598584
599
585
600586
601587
602588
static void setup_p35(pci_dt_t *dram_dev)
{
uint32_t dev0;
// 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];
}
}
uint32_t dev0, mch_ratio, mch_cfg, mch_fsb;
long *ptr;
// Find Ratio
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
dev0 &= 0xFFFFC000;
ptr = (long*)(dev0 + 0xC00);
mch_cfg = *ptr & 0xFFFF;
mch_ratio = 100000;
switch (mch_cfg & 7)
{
switch (mch_cfg & 7) {
case 0: mch_fsb = 1066; break;
case 1: mch_fsb = 533; break;
default:
default:
case 2: mch_fsb = 800; break;
case 3: mch_fsb = 667; break;
case 3: mch_fsb = 667; break;
case 4: mch_fsb = 1333; break;
case 6: mch_fsb = 1600; break;
case 6: mch_fsb = 1600; break;
}
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;
}
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
case 5:mch_ratio = 333333; break; // 3.333333333
}
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;
case 5:mch_ratio = 250000; 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;
case 5:mch_ratio = 200000; break;
}
break;
case 1600:
switch ((mch_cfg >> 4) & 7)
{
}
break;
}
DBG("mch_ratio %d\n", mch_ratio);
// Compute RAM Frequency
Platform.RAM.Frequency = (Platform.CPU.FSBFrequency * mch_ratio) / 100000;
DBG("ram_fsb %d\n", Platform.RAM.Frequency);
}
uint32_t dev0, mch_ratio, mch_cfg, mch_fsb;
long *ptr;
// Find Ratio
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
dev0 &= 0xFFFFC000;
ptr = (long*)(dev0 + 0xC00);
mch_cfg = *ptr & 0xFFFF;
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 3:mch_fsb = 667; break;
case 6:mch_fsb = 1066; break;
case 3:mch_fsb = 667; 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;
case 5:mch_ratio = 240000; break;
}
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;
}
}
// Compute RAM Frequency
Platform.RAM.Frequency = (Platform.CPU.FSBFrequency * mch_ratio) / 100000;
DBG("ram_fsb %d\n", Platform.RAM.Frequency);
}
static void get_fsb_nhm(pci_dt_t *dram_dev)
{
uint32_t mch_ratio, mc_dimm_clk_ratio;
// Get the clock ratio
mc_dimm_clk_ratio = pci_config_read16(PCIADDR(nhm_bus, 3, 4), 0x54 );
mch_ratio = (mc_dimm_clk_ratio & 0x1F);
// Compute RAM Frequency
Platform.RAM.Frequency = Platform.CPU.FSBFrequency * mch_ratio / 2;
DBG("ram_fsb %d\n", Platform.RAM.Frequency);
}
/*
// Get i965 Memory Timings
static void get_timings_i965(pci_dt_t *dram_dev)
{
{
// Thanks for CDH optis
uint32_t dev0, c0ckectrl, c1ckectrl, offset;
uint32_t ODT_Control_Register, Precharge_Register, ACT_Register, Read_Register, Misc_Register;
long *ptr;
// Read MMR Base Address
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
dev0 &= 0xFFFFC000;
ptr = (long*)(dev0 + 0x260);
c0ckectrl = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + 0x660);
c1ckectrl = *ptr & 0xFFFFFFFF;
// If DIMM 0 not populated, check DIMM 1
((c0ckectrl) >> 20 & 0xF) ? (offset = 0) : (offset = 0x400);
ptr = (long*)(dev0 + offset + 0x29C);
ODT_Control_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x250);
Precharge_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x252);
ACT_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x258);
Read_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x244);
Misc_Register = *ptr & 0xFFFFFFFF;
// 965 Series only support DDR2
Platform.RAM.Type = SMB_MEM_TYPE_DDR2;
// CAS Latency (tCAS)
Platform.RAM.CAS = ((ODT_Control_Register >> 17) & 7) + 3;
// RAS-To-CAS (tRCD)
Platform.RAM.TRC = (Read_Register >> 16) & 0xF;
// RAS Precharge (tRP)
Platform.RAM.TRP = (ACT_Register >> 13) & 0xF;
// RAS Active to precharge (tRAS)
Platform.RAM.RAS = (Precharge_Register >> 11) & 0x1F;
if ((c0ckectrl >> 20 & 0xF) && (c1ckectrl >> 20 & 0xF)) {
Platform.RAM.Channels = SMB_MEM_CHANNEL_DUAL;
} else {
// Thanks for CDH optis
uint32_t dev0, c0ckectrl, c1ckectrl, offset, ODT_Control_Register, Precharge_Register;
long *ptr;
// Read MMR Base Address
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
dev0 &= 0xFFFFC000;
ptr = (long*)(dev0 + 0x1200);
c0ckectrl = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + 0x1300);
c1ckectrl = *ptr & 0xFFFFFFFF;
// If DIMM 0 not populated, check DIMM 1
((c0ckectrl) >> 20 & 0xF) ? (offset = 0) : (offset = 0x100);
ptr = (long*)(dev0 + offset + 0x121C);
ODT_Control_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x1214);
Precharge_Register = *ptr & 0xFFFFFFFF;
// Series only support DDR2
Platform.RAM.Type = SMB_MEM_TYPE_DDR2;
// CAS Latency (tCAS)
Platform.RAM.CAS = ((ODT_Control_Register >> 23) & 7) + 3;
// RAS-To-CAS (tRCD)
Platform.RAM.TRC = ((Precharge_Register >> 5) & 7) + 2;
// RAS Precharge (tRP)
Platform.RAM.TRP= (Precharge_Register & 7) + 2;
// RAS Active to precharge (tRAS)
Platform.RAM.RAS = (Precharge_Register >> 21) & 0x1F;
if ((c0ckectrl >> 20 & 0xF) && (c1ckectrl >> 20 & 0xF)) {
Platform.RAM.Channels = SMB_MEM_CHANNEL_DUAL;
} else {
// Get P35 Memory Timings
static void get_timings_p35(pci_dt_t *dram_dev)
{
{
// Thanks for CDH optis
unsigned long dev0, Memory_Check, c0ckectrl, c1ckectrl, offset;
unsigned long ODT_Control_Register, Precharge_Register, ACT_Register, Read_Register, Misc_Register;
long *ptr;
//Device_ID = pci_config_read16(dram_dev->dev.addr, 0x02);
//Device_ID &= 0xFFFF;
// Now, read MMR Base Address
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
dev0 &= 0xFFFFC000;
ptr = (long*)(dev0 + 0x260);
c0ckectrl = *ptr & 0xFFFFFFFF;
c0ckectrl = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + 0x660);
c1ckectrl = *ptr & 0xFFFFFFFF;
// If DIMM 0 not populated, check DIMM 1
((c0ckectrl) >> 20 & 0xF) ? (offset = 0) : (offset = 0x400);
ptr = (long*)(dev0 + offset + 0x265);
ODT_Control_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x25D);
ptr = (long*)(dev0 + offset + 0x25D);
Precharge_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x252);
ACT_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x258);
Read_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x244);
Misc_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x1E8);
Memory_Check = *ptr & 0xFFFFFFFF;
Memory_Check = *ptr & 0xFFFFFFFF;
// On P45, check 1A8
if(dram_dev->device_id > 0x2E00) {
ptr = (long*)(dev0 + offset + 0x1A8);
Memory_Check = *ptr & 0xFFFFFFFF;
Memory_Check = *ptr & 0xFFFFFFFF;
Memory_Check >>= 2;
Memory_Check &= 1;
Memory_Check = !Memory_Check;
} else {
ptr = (long*)(dev0 + offset + 0x1E8);
Memory_Check = *ptr & 0xFFFFFFFF;
Memory_Check = *ptr & 0xFFFFFFFF;
}
// Determine DDR-II or DDR-III
if (Memory_Check & 1) {
Platform.RAM.Type = SMB_MEM_TYPE_DDR2;
// RAS-To-CAS (tRCD)
Platform.RAM.TRC = (Read_Register >> 17) & 0xF;
// RAS Precharge (tRP)
Platform.RAM.TRP = (ACT_Register >> 13) & 0xF;
// RAS Active to precharge (tRAS)
Platform.RAM.RAS = Precharge_Register & 0x3F;
// Channel configuration
if (((c0ckectrl >> 20) & 0xF) && ((c1ckectrl >> 20) & 0xF)) {
Platform.RAM.Channels = SMB_MEM_CHANNEL_DUAL;
{
unsigned long mc_channel_bank_timing, mc_control, mc_channel_mrs_value;
int fvc_bn = 4;
// Find which channels are populated
mc_control = pci_config_read16(PCIADDR(nhm_bus, 3, 0), 0x48);
mc_control = (mc_control >> 8) & 0x7;
// DDR-III
Platform.RAM.Type = SMB_MEM_TYPE_DDR3;
// Get the first valid channel
if(mc_control & 1) {
fvc_bn = 4;
// Now, detect timings
mc_channel_bank_timing = pci_config_read32(PCIADDR(nhm_bus, fvc_bn, 0), 0x88);
mc_channel_mrs_value = pci_config_read32(PCIADDR(nhm_bus, fvc_bn, 0), 0x70);
// CAS Latency (tCAS)
Platform.RAM.CAS = ((mc_channel_mrs_value >> 4) & 0xF ) + 4;
// RAS-To-CAS (tRCD)
Platform.RAM.TRC = (mc_channel_bank_timing >> 9) & 0xF;
// RAS Active to precharge (tRAS)
Platform.RAM.RAS = (mc_channel_bank_timing >> 4) & 0x1F;
// RAS Precharge (tRP)
Platform.RAM.TRP = mc_channel_bank_timing & 0xF;
// Single , Dual or Triple Channels
if (mc_control == 1 || mc_control == 2 || mc_control == 4 ) {
Platform.RAM.Channels = SMB_MEM_CHANNEL_SINGLE;
static const char *memory_channel_types[] =
{
"Unknown", "Single", "Dual", "Triple"
};
};
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,
dram_dev->dev.bits.bus, dram_dev->dev.bits.dev, dram_dev->dev.bits.func);
if (dram_controllers[i].initialise != NULL) {
dram_controllers[i].initialise(dram_dev);
}
memory_channel_types[Platform.RAM.Channels]
,Platform.RAM.CAS, Platform.RAM.TRC, Platform.RAM.TRP, Platform.RAM.RAS
,Platform.RAM.CAS, Platform.RAM.TRC, Platform.RAM.TRP, Platform.RAM.RAS);
//getchar();
//getchar();
}
}
}
branches/ErmaC/Enoch/i386/libsaio/nvidia.c
7777
7878
7979
80
8081
8182
8283
......
14581459
14591460
14601461
1461
1462
1462
14631463
14641464
1465
1466
1465
14671466
14681467
14691468
14701469
14711470
1472
1473
1474
1471
14751472
14761473
14771474
14781475
1479
1480
1476
14811477
14821478
14831479
1484
1485
1486
1480
14871481
14881482
14891483
14901484
14911485
1492
1493
1486
14941487
14951488
14961489
1497
1498
1499
1490
15001491
15011492
15021493
......
15071498
15081499
15091500
1510
1511
1501
15121502
15131503
15141504
15151505
15161506
1517
1518
1507
15191508
15201509
15211510
15221511
1523
1524
1512
15251513
15261514
1527
1528
1515
15291516
15301517
1531
1532
1518
15331519
15341520
15351521
......
15421528
15431529
15441530
1545
1546
1547
1548
1531
1532
15491533
15501534
15511535
......
15541538
15551539
15561540
1557
1558
1559
1560
1561
1562
1541
1542
1543
15631544
15641545
15651546
15661547
15671548
15681549
1569
1570
1571
1550
15721551
15731552
1574
1575
1576
1577
1578
1579
1553
1554
1555
15801556
15811557
15821558
15831559
15841560
1585
1586
1587
1588
1561
1562
15891563
15901564
15911565
15921566
15931567
1594
1595
1568
15961569
15971570
15981571
15991572
1600
1601
1573
16021574
16031575
16041576
......
16101582
16111583
16121584
1613
1614
1585
16151586
16161587
16171588
16181589
1619
1620
1590
16211591
16221592
16231593
......
16371607
16381608
16391609
1640
1641
1642
1643
1610
1611
16441612
1645
1646
1613
16471614
16481615
16491616
16501617
16511618
16521619
1653
1654
1620
16551621
16561622
16571623
......
16611627
16621628
16631629
1664
1665
1666
1667
1630
1631
16681632
1669
1670
1671
1633
16721634
16731635
16741636
......
16781640
16791641
16801642
1681
1643
16821644
16831645
16841646
1685
1686
1687
1688
1647
1648
16891649
16901650
16911651
16921652
1653
1654
1655
1656
1657
16931658
1694
1695
1696
1697
1698
1699
1659
1660
1661
17001662
1663
17011664
17021665
17031666
17041667
17051668
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1669
1670
1671
1672
1673
1674
17171675
1718
1676
17191677
17201678
17211679
......
17301688
17311689
17321690
1733
1734
1691
17351692
17361693
17371694
17381695
17391696
1740
1741
1697
17421698
17431699
17441700
......
17661722
17671723
17681724
1769
1770
1725
17711726
17721727
1773
1774
1775
1728
17761729
17771730
17781731
17791732
17801733
17811734
1782
1735
17831736
17841737
17851738
......
18541807
18551808
18561809
1857
1858
1859
1860
1810
1811
18611812
18621813
1863
1864
1865
1814
18661815
18671816
18681817
1869
1870
1871
1818
18721819
18731820
18741821
......
19171864
19181865
19191866
1920
1867
19211868
19221869
19231870
19241871
19251872
19261873
1927
1928
1874
19291875
19301876
1931
1932
1933
1877
19341878
19351879
19361880
19371881
1938
1939
1940
1882
19411883
19421884
19431885
......
19481890
19491891
19501892
1951
1952
1893
19531894
19541895
1955
1956
1957
1896
19581897
19591898
19601899
......
19621901
19631902
19641903
1965
1966
1904
19671905
19681906
1969
1970
1971
1907
19721908
19731909
19741910
19751911
1976
1977
1912
19781913
19791914
1980
1981
1982
1915
19831916
19841917
19851918
19861919
19871920
19881921
1989
1990
1922
19911923
1924
19921925
19931926
19941927
19951928
19961929
19971930
1998
1999
2000
2001
1931
1932
20021933
20031934
20041935
20051936
20061937
20071938
2008
2009
2010
1939
20111940
20121941
20131942
......
20251954
20261955
20271956
2028
2029
1957
20301958
20311959
20321960
......
20451973
20461974
20471975
2048
2049
2050
2051
1976
1977
20521978
20531979
2054
2055
1980
20561981
20571982
2058
2059
1983
20601984
2061
2062
1985
20631986
20641987
20651988
2066
2067
1989
20681990
20691991
20701992
......
20782000
20792001
20802002
2081
2003
20822004
2083
2084
2005
20852006
20862007
2087
2088
2008
20892009
20902010
20912011
20922012
20932013
2094
2095
2014
20962015
20972016
2098
2099
2017
21002018
21012019
21022020
......
21052023
21062024
21072025
2108
2109
2026
21102027
21112028
2112
2113
2029
21142030
21152031
21162032
......
21402056
21412057
21422058
2143
2144
2059
21452060
21462061
21472062
......
21532068
21542069
21552070
2156
2157
2071
21582072
21592073
21602074
......
21632077
21642078
21652079
2166
2167
2080
21682081
21692082
21702083
......
21732086
21742087
21752088
2176
2177
2089
21782090
21792091
21802092
#define WRITE_LE_SHORT(data) (((data) << 8 & 0xff00) | ((data) >> 8 & 0x00ff ))
#define WRITE_LE_INT(data) (WRITE_LE_SHORT(data) << 16 | WRITE_LE_SHORT(data >> 16))
char generic_name[128];
extern uint32_t devices_number;
const char *nvidia_compatible_0[] ={ "@0,compatible","NVDA,NVMac" };
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;
}
}
static char *get_nvidia_model(uint32_t device_id, uint32_t subsys_id)
{
int i, j;
static char name_model[128];
bool showGeneric = false;
// 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;
}
}
//ErmaC added selector for Chameleon "old" style in System Profiler
if ((getBoolForKey(kNvidiaGeneric, &showGeneric, &bootInfo->chameleonConfig) && showGeneric) == true) {
DBG("- TEST - NOT YET IMPLEMENTED.\n");
}
// Then check the exceptions table
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))
{
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;
break;
}
}
}
// 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))
{
snprintf(name_model, sizeof(name_model), "%s %s",
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(generic_name, 128, "%s %s", // sizeof(generic_name), "%s %s",
nvidia_card_vendors[j].name, nvidia_card_generic[i].name);
return name_model;
return &generic_name[0];
}
}
}
int fd;
int size;
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0)
{
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {
return 0;
}
size = file_size(fd);
if (size)
{
if (size) {
*buf = malloc(size);
size = read(fd, (char *)buf, size);
}
return 0;
if (!DP_ADD_TEMP_VAL(device, nvidia_name_1))
return 0;
if (devices_number == 1)
{
if (devices_number == 1) {
if (!DP_ADD_TEMP_VAL(device, nvidia_device_type_parent))
return 0;
}
else
{
} else {
if (!DP_ADD_TEMP_VAL(device, nvidia_device_type_child))
return 0;
}
// Rek : Dont use sprintf return, it does not WORK !! our custom sprintf() always return 0!
// len = sprintf(tmp, "Slot-%x", devices_number);
sprintf(tmp, "Slot-%x",devices_number);
snprintf(tmp, sizeof(tmp), "Slot-%x",devices_number);
devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp));
devices_number++;
break;
}
if (!vram_size)
{ // Finally, if vram_size still not set do the calculation with our own method
if (nvCardType < NV_ARCH_50)
{
if (!vram_size){ // Finally, if vram_size still not set do the calculation with our own method
if (nvCardType < NV_ARCH_50) {
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size &= NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK;
}
else if (nvCardType < NV_ARCH_C0)
{
} else if (nvCardType < NV_ARCH_C0) {
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size |= (vram_size & 0xff) << 32;
vram_size &= 0xffffffff00ll;
}
else // >= NV_ARCH_C0
{
} else { // >= NV_ARCH_C0
vram_size = REG32(NVC0_MEM_CTRLR_RAM_AMOUNT) << 20;
vram_size *= REG32(NVC0_MEM_CTRLR_COUNT);
}
// Amount of VRAM in kilobytes
videoRam = mem_detect(regs, nvCardType, nvda_dev,((nvda_dev->vendor_id << 16) | nvda_dev->device_id),((nvda_dev->subsys_id.subsys.vendor_id << 16) | nvda_dev->subsys_id.subsys.device_id) );
sprintf(nvFilename, "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id);
snprintf(nvFilename, sizeof(nvFilename), "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id);
if (getBoolForKey(kUseNvidiaROM, &doit, &bootInfo->chameleonConfig) && doit)
{
verbose("Looking for nvidia video bios file %s\n", nvFilename);
nvBiosOveride = load_nvidia_bios_file(nvFilename, &rom);
if (nvBiosOveride > 0)
{
if (nvBiosOveride > 0) {
verbose("Using nVidia Video BIOS File %s (%d Bytes)\n", nvFilename, nvBiosOveride);
DBG("%s Signature 0x%02x%02x %d bytes\n", nvFilename, rom[0], rom[1], nvBiosOveride);
}
else
{
} else {
printf("ERROR: unable to open nVidia Video BIOS File %s\n", nvFilename);
free(rom);
return false;
}
}
else
{
} else {
rom = malloc(NVIDIA_ROM_SIZE);
// Otherwise read bios from card
nvBiosOveride = 0;
nvRom = (uint8_t*)&regs[NV_PROM_OFFSET];
// Valid Signature ?
if (checkNvRomSig(nvRom))
{
if (checkNvRomSig(nvRom)) {
bcopy((uint8_t *)nvRom, rom, NVIDIA_ROM_SIZE);
DBG("PROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
else
{
} else {
// disable PROM access
(REG32(NV_PBUS_PCI_NV_20)) = NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED;
//PRAM next
nvRom = (uint8_t*)&regs[NV_PRAMIN_OFFSET];
if(checkNvRomSig(nvRom))
{
if(checkNvRomSig(nvRom)) {
bcopy((uint32_t *)nvRom, rom, NVIDIA_ROM_SIZE);
DBG("PRAM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
else
{
} else {
// 0xC0000 last
bcopy((char *)0xc0000, rom, NVIDIA_ROM_SIZE);
// Valid Signature ?
if (!checkNvRomSig(rom))
{
if (!checkNvRomSig(rom)) {
printf("ERROR: Unable to locate nVidia Video BIOS\n");
return false;
}
else
{
} else {
DBG("ROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
}//end PRAM check
}//end PROM check
}//end load rom from bios
if ((nvPatch = patch_nvidia_rom(rom)) == PATCH_ROM_FAILED)
{
if ((nvPatch = patch_nvidia_rom(rom)) == PATCH_ROM_FAILED) {
printf("ERROR: nVidia ROM Patching Failed!\n");
free(rom);
//return false;
}
rom_pci_header = (option_rom_pci_header_t*)(rom + *(uint16_t *)&rom[24]);
// check for 'PCIR' sig
if (rom_pci_header->signature == 0x50434952)
{
if (rom_pci_header->device_id != nvda_dev->device_id)
{
if (rom_pci_header->signature == 0x50434952) {
if (rom_pci_header->device_id != nvda_dev->device_id) {
// Get Model from the OpROM
model = get_nvidia_model(((rom_pci_header->vendor_id << 16) | rom_pci_header->device_id), 0);
// Get VRAM again
videoRam = mem_detect(regs, nvCardType, nvda_dev, ((rom_pci_header->vendor_id << 16) | rom_pci_header->device_id), 0);
}
else
{
} else {
printf("nVidia incorrect PCI ROM signature: 0x%x\n", rom_pci_header->signature);
}
}
/* FIXME: for primary graphics card only */
boot_display = 1;
if (devices_number == 1)
{
if (devices_number == 1) {
devprop_add_value(device, "@0,AAPL,boot-display", (uint8_t*)&boot_display, 4);
}
int crlf_count = 0;
// only search the first 384 bytes
for (i = 0; i < 0x180; i++)
{
if (rom[i] == 0x0D && rom[i+1] == 0x0A)
{
for (i = 0; i < 0x180; i++) {
if (rom[i] == 0x0D && rom[i+1] == 0x0A) {
crlf_count++;
// second 0x0D0A was found, extract bios version
if (crlf_count == 2)
{
if (crlf_count == 2) {
if (rom[i-1] == 0x20) i--; // strip last " "
for (version_start = i; version_start > (i-MAX_BIOS_VERSION_LENGTH); version_start--)
{
for (version_start = i; version_start > (i-MAX_BIOS_VERSION_LENGTH); version_start--) {
// find start
if (rom[version_start] == 0x00)
{
if (rom[version_start] == 0x00) {
version_start++;
// strip "Version "
if (strncmp((const char*)rom+version_start, "Version ", 8) == 0)
{
if (strncmp((const char*)rom+version_start, "Version ", 8) == 0) {
version_start += 8;
}
}
snprintf(biosVersion, sizeof(biosVersion), "%s", (nvBiosOveride > 0) ? nvFilename : version_str);
sprintf(kNVCAP, "NVCAP_%04x", nvda_dev->device_id);
snprintf(kNVCAP, sizeof(kNVCAP), "NVCAP_%04x", nvda_dev->device_id);
if (getValueForKey(kNVCAP, &value, &len, &bootInfo->chameleonConfig) && len == NVCAP_LEN * 2)
{
if (getValueForKey(kNVCAP, &value, &len, &bootInfo->chameleonConfig) && len == NVCAP_LEN * 2) {
uint8_t new_NVCAP[NVCAP_LEN];
if (hex2bin(value, new_NVCAP, NVCAP_LEN) == 0)
{
if (hex2bin(value, new_NVCAP, NVCAP_LEN) == 0) {
verbose("Using user supplied NVCAP for %s :: %s\n", model, devicepath);
memcpy(default_NVCAP, new_NVCAP, NVCAP_LEN);
}
}
if (getValueForKey(kDcfg0, &value, &len, &bootInfo->chameleonConfig) && len == DCFG0_LEN * 2)
{
if (getValueForKey(kDcfg0, &value, &len, &bootInfo->chameleonConfig) && len == DCFG0_LEN * 2) {
uint8_t new_dcfg0[DCFG0_LEN];
if (hex2bin(value, new_dcfg0, DCFG0_LEN) == 0)
{
if (hex2bin(value, new_dcfg0, DCFG0_LEN) == 0) {
memcpy(default_dcfg_0, new_dcfg0, DCFG0_LEN);
verbose("Using user supplied @0,display-cfg\n");
}
}
if (getValueForKey(kDcfg1, &value, &len, &bootInfo->chameleonConfig) && len == DCFG1_LEN * 2)
{
if (getValueForKey(kDcfg1, &value, &len, &bootInfo->chameleonConfig) && len == DCFG1_LEN * 2) {
uint8_t new_dcfg1[DCFG1_LEN];
if (hex2bin(value, new_dcfg1, DCFG1_LEN) == 0)
{
if (hex2bin(value, new_dcfg1, DCFG1_LEN) == 0) {
memcpy(default_dcfg_1, new_dcfg1, DCFG1_LEN);
verbose("Using user supplied @1,display-cfg\n");
/******************** Added Marchrius.**********************/
// For the AppleBacklightDisplay //
/***********************************************************/
if (getBoolForKey(kEnableBacklight, &doit, &bootInfo->chameleonConfig) && doit)
{
if (getBoolForKey(kEnableBacklight, &doit, &bootInfo->chameleonConfig) && doit){
uint8_t AAPL_value[] = {0x01, 0x00, 0x00, 0x00}; //Is the same for all
devprop_add_value(device, "AAPL,HasPanel", AAPL_value, 4);
devprop_add_value(device, "AAPL,Haslid", AAPL_value, 4);
/***********************************************************/
// For the DualLink //
/***********************************************************/
if (getBoolForKey(kEnableDualLink, &doit, &bootInfo->chameleonConfig) && doit)
{
if (getBoolForKey(kEnableDualLink, &doit, &bootInfo->chameleonConfig) && doit) {
uint8_t AAPL00_value[] = {0x01, 0x00, 0x00, 0x00};
devprop_add_value(device, "AAPL00,DualLink", AAPL00_value, 4);
}
/************************ HDMI Audio ***********************/
doit = false;
//http://forge.voodooprojects.org/p/chameleon/issues/67/
if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit)
{
if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit) {
static uint8_t connector_type_1[]= {0x00, 0x08, 0x00, 0x00};
devprop_add_value(device, "@0,connector-type",connector_type_1, 4);
devprop_add_value(device, "@1,connector-type",connector_type_1, 4);
}
/************************ End Audio *************************/
if (getBoolForKey(kVBIOS, &doit, &bootInfo->chameleonConfig) && doit)
{
if (getBoolForKey(kVBIOS, &doit, &bootInfo->chameleonConfig) && doit) {
devprop_add_value(device, "vbios", rom, (nvBiosOveride > 0) ? nvBiosOveride : (rom[2] * 512));
}
branches/ErmaC/Enoch/i386/libsaio/sys.c
121121
122122
123123
124
124
125125
126126
127127
......
129129
130130
131131
132
132
133133
134134
135135
......
143143
144144
145145
146
146
147147
148148
149149
......
162162
163163
164164
165
165
166166
167167
168168
......
180180
181181
182182
183
183
184184
185185
186186
187
187
188188
189189
190190
......
239239
240240
241241
242
242
243243
244244
245245
......
324324
325325
326326
327
327
328
328329
329330
330331
331
332
333
332334
333335
334336
......
347349
348350
349351
350
352
351353
352354
353355
354356
355357
356
358
359
357360
358361
359362
......
410413
411414
412415
413
416
414417
415418
416419
......
428431
429432
430433
431
434
432435
433436
434437
......
445448
446449
447450
448
451
449452
450453
451454
......
467470
468471
469472
470
473
471474
472475
473476
......
487490
488491
489492
490
491493
492
493494
494
495495
496496
497497
......
500500
501501
502502
503
504503
505504
506
507505
508506
509507
510508
511
512509
513510
514511
......
569566
570567
571568
572
569
573570
574571
575572
......
585582
586583
587584
588
589
585
590586
591587
592588
......
603599
604600
605601
606
607
602
608603
609604
610605
......
618613
619614
620615
621
622
616
623617
624618
625619
......
646640
647641
648642
649
650
643
651644
652645
653646
......
703696
704697
705698
706
699
707700
708701
709702
......
718711
719712
720713
714
721715
722
723
724716
725717
726718
......
744736
745737
746738
739
747740
748
749
750741
751742
752743
......
773764
774765
775766
767
776768
777
778
779769
780770
781771
......
789779
790780
791781
782
792783
793
794
795784
796785
797786
......
801790
802791
803792
804
793
805794
806795
807796
......
814803
815804
816805
817
806
818807
819808
820809
......
824813
825814
826815
827
816
828817
829818
830819
......
843832
844833
845834
846
835
847836
848837
849838
......
865854
866855
867856
868
857
869858
870859
871860
......
955944
956945
957946
958
947
959948
960949
961950
......
999988
1000989
1001990
1002
991
1003992
1004993
1005994
1006
995
1007996
1008997
1009998
......
10911080
10921081
10931082
1094
1095
1096
1097
1083
1084
10981085
10991086
11001087
//static BVRef getBootVolumeRef( const char * path, const char ** outPath );
static BVRef newBootVolumeRef( int biosdev, int partno );
//==============================================================================
//==========================================================================
// LoadVolumeFile - LOW-LEVEL FILESYSTEM FUNCTION.
// Load the specified file from the specified volume
// to the load buffer at LOAD_ADDR.
long LoadVolumeFile(BVRef bvr, const char *filePath)
{
long fileSize;
long fileSize;
// Read file into load buffer. The data in the load buffer will be
// overwritten by the next LoadFile() call.
return fileSize;
}
//==============================================================================
//==========================================================================
// LoadFile - LOW-LEVEL FILESYSTEM FUNCTION.
// Load the specified file to the load buffer at LOAD_ADDR.
// If the file is fat, load only the i386 portion.
return LoadVolumeFile(bvr, filePath);
}
//==============================================================================
//==========================================================================
long ReadFileAtOffset(const char * fileSpec, void *buffer, uint64_t offset, uint64_t length)
{
return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length);
}
//==============================================================================
//==========================================================================
long LoadThinFatFile(const char *fileSpec, void **binary)
{
const char* filePath;
const char*filePath;
FSReadFilereadFile;
BVRefbvr;
unsigned long length, length2;
return length;
}
//==============================================================================
//==========================================================================
#if UNUSED
long GetFSUUID(char *spec, char *uuidStr)
return 0;
}
//==============================================================================
//==========================================================================
// GetDirEntry - LOW-LEVEL FILESYSTEM FUNCTION.
// Fetch the next directory entry for the given directory.
long GetDirEntry(const char * dirSpec, long long * dirIndex, const char ** name, long * flags, long * time)
long GetDirEntry(const char * dirSpec, long long * dirIndex, const char ** name,
long * flags, long * time)
{
const char * dirPath;
BVRef bvr;
/* dirEntry */ (char **)name, flags, time, 0, 0 );
}
//==============================================================================
//==========================================================================
// GetFileInfo - LOW-LEVEL FILESYSTEM FUNCTION.
// Get attributes for the specified file.
static char* gMakeDirSpec;
long GetFileInfo(const char * dirSpec, const char * name, long * flags, long * time)
long GetFileInfo(const char * dirSpec, const char * name,
long * flags, long * time)
{
long long index = 0;
const char * entryName;
return bvr->fs_getfileblock(bvr, (char *)filePath, firstBlock);
}
//==============================================================================
//==========================================================================
// GetFreeFD()
static int GetFreeFd(void)
return -1;
}
//==============================================================================
//==========================================================================
// iob_from_fdesc()
//
// Return a pointer to an allocated 'iob' based on the file descriptor
}
}
//==============================================================================
//==========================================================================
// openmem()
int openmem(char * buf, int len)
return fdesc;
}
//==============================================================================
//==========================================================================
// open() - Open the file specified by 'path' for reading.
static int open_bvr(BVRef bvr, const char *filePath, int flags)
// Mark the descriptor as taken.
io->i_flgs = F_ALLOC;
// Find the next available memory block in the download buffer.
io->i_buf = (char *) LOAD_ADDR;
for (i = 0; i < NFILES; i++) {
if ((iob[i].i_flgs != F_ALLOC) || (i == fdesc)) {
continue;
}
// Load entire file into memory. Unnecessary open() calls must be avoided.
gFSLoadAddress = io->i_buf;
io->i_filesize = bvr->fs_loadfile(bvr, (char *)filePath);
if (io->i_filesize < 0) {
close(fdesc);
return -1;
}
return fdesc;
}
return -1;
}
//==============================================================================
//==========================================================================
// close() - Close a file descriptor.
int close(int fdesc)
return 0;
}
//==============================================================================
//==========================================================================
// lseek() - Reposition the byte offset of the file descriptor from the
// beginning of the file. Returns the relocated offset.
return offset;
}
//==============================================================================
//==========================================================================
// tell() - Returns the byte offset of the file descriptor.
int tell(int fdesc)
return io->i_offset;
}
//==============================================================================
//==========================================================================
// read() - Read up to 'count' bytes of data from the file descriptor
// into the buffer pointed to by buf.
return count;
}
//==============================================================================
//==========================================================================
// write() - Write up to 'count' bytes of data to the file descriptor
// from the buffer pointed to by buf.
return 4;
}
//==============================================================================
//==========================================================================
// file_size() - Returns the size of the file described by the file
// descriptor.
return io->i_filesize;
}
//==========================================================================
//==============================================================================
struct dirstuff * vol_opendir(BVRef bvr, const char * path)
{
struct dirstuff * dirp = 0;
return NULL;
}
//==========================================================================
//==============================================================================
struct dirstuff * opendir(const char * path)
{
struct dirstuff * dirp = 0;
return NULL;
}
//==========================================================================
//==============================================================================
int closedir(struct dirstuff * dirp)
{
if (dirp) {
return 0;
}
//==========================================================================
//==============================================================================
int readdir(struct dirstuff * dirp, const char ** name, long * flags,
long * time)
{
/* dirEntry */ (char **)name, flags, time, 0, 0);
}
//==============================================================================
//==========================================================================
int readdir_ext(struct dirstuff * dirp, const char ** name, long * flags,
long * time, FinderInfo *finderInfo, long *infoValid)
finderInfo, infoValid);
}
//==============================================================================
//==========================================================================
const char * systemConfigDir()
{
return "/Library/Preferences/SystemConfiguration";
}
//==============================================================================
//==========================================================================
int gBootFileType;
}
}
//==============================================================================
//==========================================================================
void scanDisks(int biosdev, int *count)
{
}
}
//==============================================================================
//==========================================================================
BVRef selectBootVolume( BVRef chain )
{
return bvr;
}
//==============================================================================
//==========================================================================
#define LP '('
#define RP ')'
is changed to the selected volume unless the volume selector is
that of a ramdisk.
*/
BVRef getBootVolumeRef(const char * path, const char ** outPath)
BVRef getBootVolumeRef( const char * path, const char ** outPath )
{
const char * cp;
BVRef bvr = gRootVolume;
int biosdev = gBIOSDev;
int biosdev = gBIOSDev;
// Search for left parenthesis in the path specification.
// Bad device specifier, skip past the right paren.
for (cp++; *cp && *cp != RP; cp++) /* LOOP */;
{
if (*cp == RP) {
cp++;
}
if (*cp == RP) {
cp++;
}
// If gRootVolume was NULL, then bvr will be NULL as well which
branches/ErmaC/Enoch/i386/libsaio/load.c
3232
3333
3434
35
36
37
38
39
40
41
42
43
4435
4536
4637
......
6354
6455
6556
66
67
57
6858
6959
70
71
72
60
7361
7462
75
76
77
63
7864
7965
8066
81
82
83
84
67
68
8569
8670
8771
88
89
90
72
9173
9274
9375
9476
9577
96
97
78
9879
9980
10081
10182
10283
10384
104
105
85
10686
10787
10888
......
124104
125105
126106
107
127108
128109
129110
......
141122
142123
143124
144
145
125
146126
147127
148128
......
152132
153133
154134
155
156
135
157136
158137
159138
160
161
139
162140
163141
164142
......
182160
183161
184162
185
186
187
163
188164
189
165
190166
191167
192168
......
196172
197173
198174
199
200175
201176
202177
......
212187
213188
214189
215
216
190
217191
218192
219193
......
226200
227201
228202
229
230
203
231204
232205
233206
234
235
236
237
207
208
238209
239210
240211
......
256227
257228
258229
259
260
230
261231
262232
263233
......
272242
273243
274244
275
276
277
245
278246
279247
280248
......
292260
293261
294262
295
296
263
297264
298265
299266
300267
301268
302269
303
304
305
270
271
306272
307273
308
309
274
310275
311276
312277
313278
314
315
279
316280
317281
318282
319283
320
321
284
322285
323286
324287
......
328291
329292
330293
331
332294
333295
334296
335297
336
337
298
338299
339300
340301
#include <sl.h>
/*
* Backward compatibility fix for the SDK 10.7 version of loader.h
*/
#ifndef LC_MAIN
#define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */
#endif
static long DecodeSegment(long cmdBase, unsigned int*load_addr, unsigned int *load_size);
static long DecodeUnixThread(long cmdBase, unsigned int *entry);
static long DecodeSymbolTable(long cmdBase);
uint32_t fapoffset;
uint32_t fapsize;
if (fhp->magic == FAT_MAGIC)
{
if (fhp->magic == FAT_MAGIC) {
nfat = fhp->nfat_arch;
swapped = 0;
}
else if (fhp->magic == FAT_CIGAM)
{
} else if (fhp->magic == FAT_CIGAM) {
nfat = OSSwapInt32(fhp->nfat_arch);
swapped = 1;
}
else
{
} else {
return -1;
}
for (; nfat > 0; nfat--, fap++)
{
if (swapped)
{
for (; nfat > 0; nfat--, fap++) {
if (swapped) {
fapcputype = OSSwapInt32(fap->cputype);
fapoffset = OSSwapInt32(fap->offset);
fapsize = OSSwapInt32(fap->size);
}
else
{
} else {
fapcputype = fap->cputype;
fapoffset = fap->offset;
fapsize = fap->size;
}
if (fapcputype == archCpuType)
{
if (fapcputype == archCpuType) {
*binary = (void *) ((unsigned long)*binary + fapoffset);
size = fapsize;
break;
}
}
if (length != 0)
{
if (length != 0) {
*length = size;
}
unsigned int entry = 0;
gBinaryAddress = (unsigned long)binary;
mH = (struct mach_header *)(gBinaryAddress);
#if DEBUG
{
case CPU_TYPE_I386:
if (mH->magic != MH_MAGIC)
{
if (mH->magic != MH_MAGIC) {
error("Mach-O file has bad magic number\n");
return -1;
}
case CPU_TYPE_X86_64:
if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC)
{
if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC) {
return -1;
}
if (mH->magic != MH_MAGIC_64)
{
if (mH->magic != MH_MAGIC_64) {
error("Mach-O file has bad magic number\n");
return -1;
}
unsigned int load_addr;
unsigned int load_size;
switch (cmd)
{
case LC_SEGMENT:
switch (cmd) {
case LC_SEGMENT_64:
case LC_SEGMENT:
ret = DecodeSegment(cmdBase, &load_addr, &load_size);
if (ret == 0 && load_size != 0 && load_addr >= KERNEL_ADDR)
}
break;
case LC_MAIN:/* Mountain Lion's replacement for LC_UNIXTHREAD */
case LC_UNIXTHREAD:
ret = DecodeUnixThread(cmdBase, &entry);
break;
}
if (ret != 0)
{
if (ret != 0) {
return -1;
}
cmdBase = cmdstart;
for (cnt = 0; cnt < ncmds; cnt++)
{
for (cnt = 0; cnt < ncmds; cnt++) {
cmd = ((long *)cmdBase)[0];
cmdsize = ((long *)cmdBase)[1];
if (cmd == LC_SYMTAB)
{
if (DecodeSymbolTable(cmdBase) != 0)
{
if (cmd == LC_SYMTAB) {
if (DecodeSymbolTable(cmdBase) != 0) {
return -1;
}
}
long vmsize, filesize;
unsigned long vmaddr, fileaddr;
if (((long *)cmdBase)[0] == LC_SEGMENT_64)
{
if (((long *)cmdBase)[0] == LC_SEGMENT_64) {
struct segment_command_64 *segCmd;
segCmd = (struct segment_command_64 *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
(unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
#endif
}
else
{
} else {
struct segment_command *segCmd;
segCmd = (struct segment_command *)cmdBase;
#endif
}
if (vmsize == 0 || filesize == 0)
{
if (vmsize == 0 || filesize == 0) {
*load_addr = ~0;
*load_size = 0;
return 0;
}
if (! ((vmaddr >= KERNEL_ADDR && (vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) ||
(vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN))))
{
stop("Kernel overflows available space");
(vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) {
stop("Kernel overflows available space");
}
if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0)))
{
if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) {
gHaveKernelCache = true;
}
// Copy from file load area.
if (vmsize>0 && filesize > 0)
{
if (vmsize>0 && filesize > 0) {
bcopy((char *)fileaddr, (char *)vmaddr, vmsize > filesize ? filesize : vmsize);
}
// Zero space at the end of the segment.
if (vmsize > filesize)
{
if (vmsize > filesize) {
bzero((char *)(vmaddr + filesize), vmsize - filesize);
}
return 0;
}
//==============================================================================
static long DecodeUnixThread(long cmdBase, unsigned int *entry)
{
switch (archCpuType)
{
switch (archCpuType) {
case CPU_TYPE_I386:
{
i386_thread_state_t *i386ThreadState;
branches/ErmaC/Enoch/i386/libsaio/cpu.c
266266
267267
268268
269
270
269
271270
272271
273
274
272
275273
276274
277
278
275
279276
280277
281
282
283
278
284279
285280
286281
......
288283
289284
290285
291
292
286
293287
294288
295289
......
313307
314308
315309
310
316311
312
317313
314
318315
319
316
317
318
320319
320
321321
322322
323323
......
326326
327327
328328
329
330
329
331330
332331
333332
334
335
336
333
337334
338335
339
340
341
336
342337
343338
344339
......
346341
347342
348343
349
350
344
351345
352346
353347
......
360354
361355
362356
363
364
365
366
357
358
367359
368360
369361
370362
371363
372364
373
374
365
375366
376367
377368
......
381372
382373
383374
384
385
375
386376
387377
388
389
378
390379
391380
392
393
381
394382
395383
396
397
384
398385
399386
400
401
387
402388
403389
404
405
390
406391
407392
408
409
393
410394
411395
412
413
396
414397
415398
416399
417
418
400
419401
420402
421403
422404
423405
424406
425
426
407
427408
428409
429
430
431
410
432411
433412
434413
......
461440
462441
463442
464
465
443
466444
467445
468446
......
472450
473451
474452
475
476
453
477454
478455
479456
480457
481
482
483
484
485
458
459
486460
487461
488462
489463
490464
491
492
465
493466
494467
495468
496
497
469
498470
499471
500472
501
502
503
473
504474
505475
506
507
476
508477
509478
510
511
479
512480
513481
514482
515483
516484
517485
518
519
486
520487
521
522
488
523489
524
525
526
490
527491
528492
529
530
531
493
532494
533495
534496
......
538500
539501
540502
541
503
542504
543505
544506
545507
546
508
547509
548510
549511
550512
551513
552514
553
554
515
555516
556517
557
558
559
518
560519
561520
562521
563522
564523
565
566
567
568
524
525
569526
570
571
572
527
573528
574529
575
576
530
577531
578
579
580
532
581533
582534
583535
......
660612
661613
662614
663
664
615
665616
666617
667618
......
688639
689640
690641
691
692
642
693643
694644
695645
......
704654
705655
706656
707
657
708658
709659
710660
do_cpuid(0x00000003, p->CPU.CPUID[CPUID_3]);
do_cpuid2(0x00000004, 0, p->CPU.CPUID[CPUID_4]);
do_cpuid(0x80000000, p->CPU.CPUID[CPUID_80]);
if (p->CPU.CPUID[CPUID_0][0] >= 0x5)
{
if (p->CPU.CPUID[CPUID_0][0] >= 0x5) {
do_cpuid(5, p->CPU.CPUID[CPUID_5]);
}
if (p->CPU.CPUID[CPUID_0][0] >= 6)
{
if (p->CPU.CPUID[CPUID_0][0] >= 6) {
do_cpuid(6, p->CPU.CPUID[CPUID_6]);
}
if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 8)
{
if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 8) {
do_cpuid(0x80000008, p->CPU.CPUID[CPUID_88]);
do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]);
}
else if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1)
{
} else if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) {
do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]);
}
{
inti;
printf("CPUID Raw Values:\n");
for (i=0; i<CPUID_MAX; i++)
{
for (i=0; i<CPUID_MAX; i++) {
printf("%02d: %08x-%08x-%08x-%08x\n", i,
p->CPU.CPUID[i][0], p->CPU.CPUID[i][1],
p->CPU.CPUID[i][2], p->CPU.CPUID[i][3]);
p->CPU.Vendor= p->CPU.CPUID[CPUID_0][1];
p->CPU.Signature= p->CPU.CPUID[CPUID_1][0];
// stepping = cpu_feat_eax & 0xF;
p->CPU.Stepping= bitfield(p->CPU.CPUID[CPUID_1][0], 3, 0);
// model = (cpu_feat_eax >> 4) & 0xF;
p->CPU.Model= bitfield(p->CPU.CPUID[CPUID_1][0], 7, 4);
// family = (cpu_feat_eax >> 8) & 0xF;
p->CPU.Family= bitfield(p->CPU.CPUID[CPUID_1][0], 11, 8);
p->CPU.Type = bitfield(p->CPU.CPUID[CPUID_1][0], 13, 12);
// type = (cpu_feat_eax >> 12) & 0x3;
//p->CPU.Type= bitfield(p->CPU.CPUID[CPUID_1][0], 13, 12);
// ext_model = (cpu_feat_eax >> 16) & 0xF;
p->CPU.ExtModel= bitfield(p->CPU.CPUID[CPUID_1][0], 19, 16);
// ext_family = (cpu_feat_eax >> 20) & 0xFF;
p->CPU.ExtFamily= bitfield(p->CPU.CPUID[CPUID_1][0], 27, 20);
p->CPU.Model += (p->CPU.ExtModel << 4);
p->CPU.Family == 0x06 &&
p->CPU.Model >= CPU_MODEL_NEHALEM &&
p->CPU.Model != CPU_MODEL_ATOM// MSR is *NOT* available on the Intel Atom CPU
)
{
) {
msr = rdmsr64(MSR_CORE_THREAD_COUNT);// Undocumented MSR in Nehalem and newer CPUs
p->CPU.NoCores= bitfield((uint32_t)msr, 31, 16);// Using undocumented MSR to get actual values
p->CPU.NoThreads= bitfield((uint32_t)msr, 15, 0);// Using undocumented MSR to get actual values
}
else if (p->CPU.Vendor == CPUID_VENDOR_AMD)
{
} else if (p->CPU.Vendor == CPUID_VENDOR_AMD) {
p->CPU.NoThreads= bitfield(p->CPU.CPUID[CPUID_1][1], 23, 16);
p->CPU.NoCores= bitfield(p->CPU.CPUID[CPUID_88][2], 7, 0) + 1;
}
else
{
} else {
// Use previous method for Cores and Threads
p->CPU.NoThreads= bitfield(p->CPU.CPUID[CPUID_1][1], 23, 16);
p->CPU.NoCores= bitfield(p->CPU.CPUID[CPUID_4][0], 31, 26) + 1;
/* get brand string (if supported) */
/* Copyright: from Apple's XNU cpuid.c */
if (p->CPU.CPUID[CPUID_80][0] > 0x80000004)
{
if (p->CPU.CPUID[CPUID_80][0] > 0x80000004) {
uint32_treg[4];
charstr[128], *s;
/*
bcopy((char *)reg, &str[16], 16);
do_cpuid(0x80000004, reg);
bcopy((char *)reg, &str[32], 16);
for (s = str; *s != '\0'; s++)
{
if (*s != ' ')
{
for (s = str; *s != '\0'; s++) {
if (*s != ' ') {
break;
}
}
strlcpy(p->CPU.BrandString, s, sizeof(p->CPU.BrandString));
if (!strncmp(p->CPU.BrandString, CPU_STRING_UNKNOWN, MIN(sizeof(p->CPU.BrandString), strlen(CPU_STRING_UNKNOWN) + 1)))
{
if (!strncmp(p->CPU.BrandString, CPU_STRING_UNKNOWN, MIN(sizeof(p->CPU.BrandString), strlen(CPU_STRING_UNKNOWN) + 1))) {
/*
* This string means we have a firmware-programmable brand string,
* and the firmware couldn't figure out what sort of CPU we have.
}
/* setup features */
if ((bit(23) & p->CPU.CPUID[CPUID_1][3]) != 0)
{
if ((bit(23) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_MMX;
}
if ((bit(25) & p->CPU.CPUID[CPUID_1][3]) != 0)
{
if ((bit(25) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE;
}
if ((bit(26) & p->CPU.CPUID[CPUID_1][3]) != 0)
{
if ((bit(26) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE2;
}
if ((bit(0) & p->CPU.CPUID[CPUID_1][2]) != 0)
{
if ((bit(0) & p->CPU.CPUID[CPUID_1][2]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE3;
}
if ((bit(19) & p->CPU.CPUID[CPUID_1][2]) != 0)
{
if ((bit(19) & p->CPU.CPUID[CPUID_1][2]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE41;
}
if ((bit(20) & p->CPU.CPUID[CPUID_1][2]) != 0)
{
if ((bit(20) & p->CPU.CPUID[CPUID_1][2]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE42;
}
if ((bit(29) & p->CPU.CPUID[CPUID_81][3]) != 0)
{
if ((bit(29) & p->CPU.CPUID[CPUID_81][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_EM64T;
}
if ((bit(5) & p->CPU.CPUID[CPUID_1][3]) != 0)
{
if ((bit(5) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_MSR;
}
//if ((bit(28) & p->CPU.CPUID[CPUID_1][3]) != 0) {
if (p->CPU.NoThreads > p->CPU.NoCores)
{
if (p->CPU.NoThreads > p->CPU.NoCores) {
p->CPU.Features |= CPU_FEATURE_HTT;
}
tscFrequency = measure_tsc_frequency();
DBG("cpu freq classic = 0x%016llx\n", tscFrequency);
/* if usual method failed */
if ( tscFrequency < 1000 )//TEST
{
if ( tscFrequency < 1000 ) { //TEST
tscFrequency = timeRDTSC() * 20;//measure_tsc_frequency();
// DBG("cpu freq timeRDTSC = 0x%016llx\n", tscFrequency);
}
else
{
} else {
// DBG("cpu freq timeRDTSC = 0x%016llxn", timeRDTSC() * 20);
}
fsbFrequency = 0;
bus_ratio_min = bitfield(msr, 47, 40); //valv: not sure about this one (Remarq.1)
msr = rdmsr64(MSR_FLEX_RATIO);
DBG("msr(%d): flex_ratio %08x\n", __LINE__, bitfield(msr, 31, 0));
if (bitfield(msr, 16, 16))
{
if (bitfield(msr, 16, 16)) {
flex_ratio = bitfield(msr, 15, 8);
/* bcc9: at least on the gigabyte h67ma-ud2h,
where the cpu multipler can't be changed to
causing the system to crash since tscGranularity
is inadvertently set to 0.
*/
if (flex_ratio == 0)
{
if (flex_ratio == 0) {
/* Clear bit 16 (evidently the presence bit) */
wrmsr64(MSR_FLEX_RATIO, (msr & 0xFFFFFFFFFFFEFFFFULL));
msr = rdmsr64(MSR_FLEX_RATIO);
verbose("Unusable flex ratio detected. Patched MSR now %08x\n", bitfield(msr, 31, 0));
}
else
{
if (bus_ratio_max > flex_ratio)
{
} else {
if (bus_ratio_max > flex_ratio) {
bus_ratio_max = flex_ratio;
}
}
}
if (bus_ratio_max)
{
if (bus_ratio_max) {
fsbFrequency = (tscFrequency / bus_ratio_max);
}
//valv: Turbo Ratio Limit
if ((intelCPU != 0x2e) && (intelCPU != 0x2f))
{
if ((intelCPU != 0x2e) && (intelCPU != 0x2f)) {
msr = rdmsr64(MSR_TURBO_RATIO_LIMIT);
cpuFrequency = bus_ratio_max * fsbFrequency;
max_ratio = bus_ratio_max * 10;
}
else
{
} else {
cpuFrequency = tscFrequency;
}
if ((getValueForKey(kbusratio, &newratio, &len, &bootInfo->chameleonConfig)) && (len <= 4))
{
if ((getValueForKey(kbusratio, &newratio, &len, &bootInfo->chameleonConfig)) && (len <= 4)) {
max_ratio = atoi(newratio);
max_ratio = (max_ratio * 10);
if (len >= 3)
{
if (len >= 3) {
max_ratio = (max_ratio + 5);
}
verbose("Bus-Ratio: min=%d, max=%s\n", bus_ratio_min, newratio);
// extreme overclockers may love 320 ;)
if ((max_ratio >= min_ratio) && (max_ratio <= 320))
{
if ((max_ratio >= min_ratio) && (max_ratio <= 320)) {
cpuFrequency = (fsbFrequency * max_ratio) / 10;
if (len >= 3)
{
if (len >= 3) {
maxdiv = 1;
}
else
{
} else {
maxdiv = 0;
}
}
else
{
} else {
max_ratio = (bus_ratio_max * 10);
}
}
p->CPU.MinRatio = min_ratio;
myfsb = fsbFrequency / 1000000;
verbose("Sticking with [BCLK: %dMhz, Bus-Ratio: %d]\n", myfsb, max_ratio/10);
verbose("Sticking with [BCLK: %dMhz, Bus-Ratio: %d]\n", myfsb, max_ratio/10); // Bungo: fixed wrong Bus-Ratio readout
currcoef = bus_ratio_max;
} else {
msr = rdmsr64(MSR_IA32_PERF_STATUS);
DBG("msr(%d): ia32_perf_stat 0x%08x\n", __LINE__, bitfield(msr, 31, 0));
currcoef = bitfield(msr, 12, 8);
currcoef = bitfield(msr, 12, 8); // Bungo: reverted to 2263 state because of wrong old CPUs freq. calculating
/* Non-integer bus ratio for the max-multi*/
maxdiv = bitfield(msr, 46, 46);
/* Non-integer bus ratio for the current-multi (undocumented)*/
currdiv = bitfield(msr, 14, 14);
// This will always be model >= 3
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f))
{
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f)) {
/* On these models, maxcoef defines TSC freq */
maxcoef = bitfield(msr, 44, 40);
}
else
{
} else {
/* On lower models, currcoef defines TSC freq */
/* XXX */
maxcoef = currcoef;
}
if (maxcoef)
{
if (maxdiv)
{
if (maxcoef) {
if (maxdiv) {
fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1));
}
else
{
} else {
fsbFrequency = (tscFrequency / maxcoef);
}
if (currdiv)
{
if (currdiv) {
cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2);
}
else
{
} else {
cpuFrequency = (fsbFrequency * currcoef);
}
DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : "");
}
#if 0
if (!fsbFrequency)
{
if (!fsbFrequency) {
fsbFrequency = (DEFAULT_FSB * 1000);
cpuFrequency = tscFrequency;
DBG("0 ! using the default value for FSB !\n");
DBG("Family: 0x%x\n", p->CPU.Family); // Family ex: 6 (06h)
DBG("ExtFamily: 0x%x\n", p->CPU.ExtFamily);
DBG("Signature: %x\n", p->CPU.Signature); // CPUID signature
switch (p->CPU.Type)
{
/*switch (p->CPU.CpuType) {
case PT_OEM:
DBG("Processor type: Intel Original OEM Processor\n");
break;
break;
default:
break;
}
}*/
DBG("Model: 0x%x\n", p->CPU.Model); // Model ex: 37 (025h)
DBG("ExtModel: 0x%x\n", p->CPU.ExtModel);
DBG("Stepping: 0x%x\n", p->CPU.Stepping); // Stepping ex: 5 (05h)
branches/ErmaC/Enoch/i386/libsaio/platform.h
137137
138138
139139
140
140
141141
142142
143143
uint32_tVendor;// Vendor
uint32_tSignature;// Processor Signature
uint32_tStepping;// Stepping
uint32_tType;// Type
//uint32_tType;// Type
uint32_tModel;// Model
uint32_tExtModel;// Extended Model
uint32_tFamily;// Family
branches/ErmaC/Enoch/i386/libsaio/disk.c
222222
223223
224224
225
226
227
225228
226229
227230
......
15881591
15891592
15901593
1594
15911595
15921596
15931597
{ 0x00, 0 }
};
//==============================================================================
static const char * bios_error(int errnum)
{
static char errorstr[] = "Error 0x00";
valid = true;
bvr->OSisInstaller = true;
strcpy(bvr->OSVersion, "10.7"); // 10.7 +
close(fh);
} else {
close(fh);
}
branches/ErmaC/Enoch/i386/libsaio/pci_setup.c
22
33
44
5
6
7
85
9
106
117
128
......
2521
2622
2723
28
29
3024
3125
3226
......
3428
3529
3630
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
8531
8632
8733
#include "boot.h"
#include "bootstruct.h"
#include "pci.h"
//#include "gma.h"
//#include "nvidia.h"
//#include "hda.h"
#include "modules.h"
//#include "device_inject.h"
extern bool setup_ati_devprop(pci_dt_t *ati_dev);
extern bool setup_nvidia_devprop(pci_dt_t *nvda_dev);
bool doit, do_eth_devprop, do_wifi_devprop, do_usb_devprop, do_gfx_devprop, do_enable_hpet, do_hda_devprop = false;
pci_dt_t *current = pci_dt;
//do_eth_devprop = do_wifi_devprop = do_usb_devprop = do_gfx_devprop = do_enable_hpet = do_hda_devprop = false;
getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->chameleonConfig);
getBoolForKey(kEnableWifi, &do_wifi_devprop, &bootInfo->chameleonConfig);
getBoolForKey(kGraphicsEnabler, &do_gfx_devprop, &bootInfo->chameleonConfig);
getBoolForKey(kHDAEnabler, &do_hda_devprop, &bootInfo->chameleonConfig);
getBoolForKey(kForceHPET, &do_enable_hpet, &bootInfo->chameleonConfig);
/* tennisgeek http://forum.voodooprojects.org/index.php/topic,1333.0.html
// Get some PCI stuff
if (hasPciToEfiMapping == -1) {
hasPciToEfiMapping = (loadSystemConfig("", &bootInfo->pciConfig, "pci.plist", true) == 0 ? 1 : 0);
if (hasPciToEfiMapping) {
verbose("pci.plist is found.\n");
}
}
if (hasPciToEfiMapping) {
// Device ID override injection
memset(id_array, sizeof(id_array), 0);
sprintf(override_key, "pci%04x,%04x", current->vendor_id, current->device_id);
id_count = PciToEfiOverride(override_key, id_array, 4);
device = NULL;
for (i = 0; i < id_count; i++) {
uint8_t fourOctets[4];
uint32_t id = id_array[i];
if (id == 0) {
if (i == 0) {
id = current->vendor_id;
} else if (i == 1) {
id = current->device_id;
} else {
continue;
}
}
fourOctets[0] = id;
fourOctets[1] = id >> 8;
fourOctets[2] = 0;
fourOctets[3] = 0;
if (id != 0) {
if (device == NULL) {
device = devprop_find_device(devicepath);
if (device == NULL) {
deviceString = devprop_create_string();
device = devprop_add_device(deviceString, devicepath);
}
}
devprop_add_value(device, id_keys[i], fourOctets, sizeof(fourOctets));
verbose("%s: %s 0x%02x\n", override_key, id_keys[i], id);
}
}
current = current->next;
}
*/ // tennisgeek http://forum.voodooprojects.org/index.php/topic,1333.0.html
while (current) {
devicepath = get_pci_dev_path(current);
branches/ErmaC/Enoch/i386/libsaio/smbios.c
6262
6363
6464
65
65
6666
67
68
6769
6870
6971
......
7476
7577
7678
77
79
7880
7981
8082
......
9092
9193
9294
93
95
9496
9597
9698
......
165167
166168
167169
168
170
169171
170172
171173
......
174176
175177
176178
177
178
179
180
181
179
180
181
182
183
182184
183185
184186
......
257259
258260
259261
260
261
262
263
262264
263265
264266
......
282284
283285
284286
285
287
286288
287289
288290
289291
290
291
292
293
292294
293295
294296
......
317319
318320
319321
320
322
321323
322324
323325
324
326
325327
326328
327329
328330
329
331
330332
331333
332334
......
393395
394396
395397
396
398
397399
398400
399401
400
402
401403
402404
403405
......
456458
457459
458460
459
461
460462
461463
462464
......
490492
491493
492494
493
495
494496
495497
496498
......
503505
504506
505507
506
508
507509
508510
509511
......
521523
522524
523525
524
526
525527
526528
527529
528530
529
530
531
532
531533
532
534
533535
534536
535537
......
542544
543545
544546
545
546
547
548
547549
548550
549551
......
578580
579581
580582
581
583
582584
583585
584586
585
587
586588
587589
588590
589591
590592
591593
592
593
594
595
596
597
598
594
595
596
597
598
599
600
599601
600602
601603
602
603
604
605
606
607
608
604
605
606
607
608
609
610
609611
610612
611613
......
613615
614616
615617
616
617
618
619
618
619
620
621
620622
621623
622624
623625
624626
625627
626
627
628
629
628
629
630
631
630632
631633
632634
......
654656
655657
656658
657
658
659
660
659661
660
662
661663
662664
663665
......
722724
723725
724726
725
726
727
727728
728729
729730
730731
731732
732733
733
734
735
736
734
735
737736
738737
739
740
741
742
743
738
739
744740
745741
746742
......
751747
752748
753749
754
755
750
756751
757752
758753
......
766761
767762
768763
769
770
764
771765
772766
773767
774
775
768
776769
777770
778771
......
780773
781774
782775
783
784
776
785777
786778
787779
788
789
780
790781
791782
792783
......
805796
806797
807798
808
809
799
810800
811801
812802
813
814
803
815804
816805
817806
......
832821
833822
834823
835
836
837
838
824
825
839826
840827
841828
842829
843
844
830
845831
846832
847833
......
852838
853839
854840
855
856
841
857842
858843
859844
860
861
845
862846
863847
864848
865
866
867
868
849
850
869851
870852
871853
......
881863
882864
883865
884
885
886
887
866
867
888868
889869
890870
891871
892872
893
873
894874
895875
896
897
876
898877
899878
900879
......
913892
914893
915894
916
917
895
918896
919897
920898
......
1020998
1021999
10221000
1023
1024
1001
10251002
1026
1027
1003
10281004
10291005
10301006
......
10321008
10331009
10341010
1035
1036
1011
10371012
10381013
10391014
10401015
10411016
1042
1043
1044
1045
1017
1018
10461019
10471020
10481021
10491022
10501023
1051
1052
1024
10531025
10541026
10551027
1056
1057
1028
10581029
10591030
10601031
1061
1062
1063
1032
10641033
10651034
10661035
1067
1068
1036
10691037
10701038
10711039
......
10771045
10781046
10791047
1080
1081
1048
10821049
10831050
10841051
......
10901057
10911058
10921059
1093
1094
1095
1096
1060
1061
10971062
10981063
10991064
......
11141079
11151080
11161081
1117
1118
1082
11191083
11201084
11211085
......
11361100
11371101
11381102
1139
1103
11401104
11411105
11421106
......
11451109
11461110
11471111
1148
1149
1112
11501113
11511114
11521115
......
11551118
11561119
11571120
1158
1159
1121
11601122
1161
1123
11621124
11631125
11641126
11651127
1166
1167
1128
11681129
11691130
11701131
1171
1172
1132
11731133
11741134
11751135
11761136
1177
1178
1137
11791138
11801139
11811140
......
11901149
11911150
11921151
1193
1194
1152
11951153
11961154
11971155
11981156
11991157
12001158
1201
1202
1159
12031160
12041161
12051162
12061163
1207
1208
1164
12091165
12101166
12111167
......
12151171
12161172
12171173
1218
1219
1220
1221
1174
1175
1176
12221177
12231178
12241179
1225
1226
1180
12271181
12281182
12291183
......
12361190
12371191
12381192
1239
1193
12401194
12411195
12421196
......
12481202
12491203
12501204
1251
1205
12521206
1253
1254
1207
12551208
12561209
12571210
......
12591212
12601213
12611214
1262
12631215
12641216
12651217
......
12761228
12771229
12781230
1279
1280
1231
12811232
1282
1283
1233
12841234
12851235
12861236
......
13061256
13071257
13081258
1309
13101259
1311
1260
13121261
1313
1262
13141263
13151264
13161265
......
13381287
13391288
13401289
1341
1342
1290
13431291
13441292
1345
1346
1293
13471294
13481295
13491296
......
13551302
13561303
13571304
1358
1359
1305
13601306
13611307
13621308
// Bungo
#define kSMBBaseBoardVersionKey "SMboardversion" // MacPro3,1
#define kSMBBaseBoardSerialNumberKey "SMboardserial" // C02140302D5DMT31M
#define kSMBBaseBoardAssetTagNumberKey "SMboardassettag" // Base Board Asset Tag#
#define kSMBBaseBoardAssetTagKey "SMboardassettag" // Base Board Asset Tag# Bungo: renamed folowing convention
#define kSMBBaseBoardLocationInChassisKey "SMboardlocation" // Part Component
// ErmaC BoardType 0x0a(10) or 0x0b(11) MacPro Family
#define kSMBBaseBoardTypeKey "SMboardtype" // 10 (Motherboard) all model, 11 (Processor+Memory Module) MacPro
// Bungo
#define kSMBSystemEnclosureTypeKey "SMchassistype" // 7 Desktop
#define kSMBSystemEnclosureVersionKey "SMchassisversion" // Mac-F42C88C8
#define kSMBSystemEnclosureSerialNumberKey "SMchassisserial" // Serial number
#define kSMBSystemEnclosureAssetTagNumberKey "SMchassisassettag" // Pro-Enclosure
#define kSMBSystemEnclosureAssetTagKey "SMchassisassettag" // Pro-Enclosure Bungo: renamed folowing convention
/* ============================
Processor Information (Type 4)
#define kSMBProcessorInformationCurrentClockKey "SMcurrentclock"
#define kSMBProcessorInformationUpgradeKey "SMcpuupgrade"
#define kSMBProcessorInformationSerialNumberKey "SMcpuserial"
#define kSMBProcessorInformationAssetTagNumberKey "SMcpuassettag"
#define kSMBProcessorInformationAssetTagKey "SMcpuassettag" // Bungo: renamed folowing convention
#define kSMBProcessorInformationPartNumberKey "SMcpupartnumber"
/* =====================
char *product;
char *version;// Bungo
char *serialNumber;// ErmaC
char *assetTagNumber;// ErmaC
char *assetTag;// ErmaC Bungo: renamed folowing convention
char *locationInChassis;// ErmaC
uint8_t boardType;// ErmaC
} defaultBaseBoard_t;
// Bungo
typedef struct {
char *manufacturer;
uint8_t chassisType;
char *version;
char *serialNumber;
char *assetTagNumber;
char*manufacturer;
uint8_tchassisType;
char*version;
char*serialNumber;
char*assetTag; // Bungo: renamed folowing convention
} defaultChassis_t;
defaultChassis_t defaultChassis;
{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, serialNumber),
kSMBBaseBoardSerialNumberKey, NULL, &defaultBaseBoard.serialNumber }, // SMboardserial - C02140302D5DMT31M
{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, assetTagNumber),
kSMBBaseBoardAssetTagNumberKey, NULL, &defaultBaseBoard.assetTagNumber }, // SMboardassetag - Base Board Asset Tag#
{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, assetTag),
kSMBBaseBoardAssetTagKey, NULL, &defaultBaseBoard.assetTag }, // SMboardassetag - Base Board Asset Tag#
{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, locationInChassis),
kSMBBaseBoardLocationInChassisKey, NULL, &defaultBaseBoard.locationInChassis }, // SMboardlocation - Part Component
kSMBSystemEnclosureTypeKey, NULL, (char **)&defaultChassis.chassisType}, // SMchassistype - 7
{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, version),
kSMBSystemEnclosureVersionKey, NULL, &defaultBaseBoard.product }, // SMchassisversion - Mac-F42C88C8
kSMBSystemEnclosureVersionKey, NULL, &defaultChassis.version }, // SMchassisversion - Mac-F42C88C8
{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, serialNumber),
kSMBSystemEnclosureSerialNumberKey, NULL, &defaultChassis.serialNumber }, // SMchassisserial
{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, assetTagNumber),
kSMBSystemEnclosureAssetTagNumberKey, NULL, &defaultChassis.assetTagNumber }, // SMchassisassettag - Pro Enclosure
{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, assetTag),
kSMBSystemEnclosureAssetTagKey, NULL, &defaultChassis.assetTag }, // SMchassisassettag - Pro Enclosure
/* ============================
Processor Information (Type 4)
//
{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, serialNumber),
NULL, NULL, NULL},
kSMBProcessorInformationSerialNumberKey, NULL, NULL},
// Bungo
{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, assetTag),
kSMBProcessorInformationAssetTagNumberKey, NULL, NULL}, // SMcpuassettag
kSMBProcessorInformationAssetTagKey, NULL, NULL}, // SMcpuassettag
//
{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, partNumber),
NULL, NULL, NULL},
kSMBProcessorInformationPartNumberKey, NULL, NULL},
/* =====================
Memory Device (Type 17)
// Bungo: suggest to not mixing data from different Mac models, use real Mac SMBIOS dumps
#define kDefaultVendorManufacturer"Apple Inc."
//#define kDefaultBIOSReleaseDate"11/06/2009"
//#define kDefaultBIOSReleaseDate"11/06/2009"
#define kDefaultSerialNumber"SOMESRLNMBR"
//Bungo
#define kDefaultSkuNumber"Default SKU#"
#define kDefaultAssetTagNumber"Default Asset Tag#"
#define kDefaultAssetTag"Default Asset Tag#"
//#define kDefaultBoardType"10" // 0xA
//#define kDefaultBoardProcessorType"11" // 0xB
#define kDefaultSystemVersion"1.0"
//#define kDefaultMacBookProBoardAssetTagNumber"MacBook-Aluminum"
#define kDefaultMacBookPro"MacBookPro4,1"
#define kDefaultMacBookProBIOSVersion" MBP41.88Z.0073.B00.0903051113"
#define kDefaultMacBookProBIOSVersion" MBP41.88Z.00C1.B03.0802271651"
#define kDefaultMacBookProBIOSReleaseDate"02/27/08"
#define kDefaultMacBookProBoardProduct"Mac-F42C89C8"
// iMac11,1 core i3/i5/i7
#define kDefaultiMacNehalem"iMac11,1"
#define kDefaultiMacNehalemBIOSVersion" IM111.88Z.0034.B02.1003171314"
#define kDefaultiMacNehalemBIOSReleaseDate"10/30/09"
#define kDefaultiMacNehalemBIOSReleaseDate"03/30/10"
#define kDefaultiMacNehalemBoardProduct"Mac-F2268DAE"
// iMac11,2
// iMac11,3
// iMac12,2 Mac-942B59F58194171B
//#define kDefaultiMacSandy"iMac12,2"
//#define kDefaultiMacSandyBIOSVersion" IM121.88Z.0047.B1D.1110171110"
//#define kDefaultiMacSandyBIOSReleaseDate"10/17/2011"
//#define kDefaultiMacSandyBIOSReleaseDate"10/17/11"
//#define kDefaultiMacSandyBoardProduct"Mac-942B59F58194171B"
// iMac13,2
#define kDefaultMacProBIOSVersion" MP31.88Z.006C.B05.0903051113"
#define kDefaultMacProBIOSReleaseDate"08/03/2010"
//#define kDefaultMacProSystemVersion"1.3"
#define kDefaultMacProBoardProduct"Mac-F2268DC8"
#define kDefaultMacProBoardProduct"Mac-F42C88C8"
//#define KDefaultMacProBoardSerialNumber"J593902RA4MFE"
// Mac Pro 4,1 core i7/Xeon
#define kDefaultMacProNehalem"MacPro4,1"
#define kDefaultMacProNehalemBIOSVersion" MP41.88Z.0081.B04.0903051113"
#define kDefaultMacProNehalemBIOSReleaseDate"11/06/2009"
#define kDefaultMacProNehalemBIOSVersion" MP41.88Z.0081.B07.0910130729"
#define kDefaultMacProNehalemBIOSReleaseDate"10/13/09"
//#define kDefaultMacProNehalemSystemVersion"1.4"
#define kDefaultMacProNehalemBoardProduct"Mac-F4238CC8"
#define kDefaultMacProNehalemBoardProduct"Mac-F221BEC8"
//#define KDefaultMacProNehalemBoardSerialNumber"J593004RB1LUE"
// Mac Pro 5,1 core i7/Xeon
// Mac Pro 6,1
#define kDefaultMacProHaswell"MacPro6,1"
#define kDefaultMacProHaswellBIOSVersion" MP61.88Z.0116.B00.1311020956"
#define kDefaultMacProHaswellBIOSReleaseDate"06/12/13"
#define kDefaultMacProHaswellBIOSVersion" MP61.88Z.0116.B04.1312061508"
#define kDefaultMacProHaswellBIOSReleaseDate"12/06/2013"
//#define kDefaultMacProHaswellSystemVersion"1.?"
#define kDefaultMacProHaswellBoardProduct"Mac-F60DEB81FF30ACF6"
//#define KDefaultMacProHaswellBoardSerialNumber"?????????????"
defaultBaseBoard.manufacturer = kDefaultVendorManufacturer;
defaultBaseBoard.serialNumber = kDefaultSerialNumber;
defaultBaseBoard.assetTagNumber = kDefaultAssetTagNumber;
defaultBaseBoard.assetTag = kDefaultAssetTag;
defaultChassis.manufacturer = kDefaultVendorManufacturer;
defaultChassis.serialNumber = kDefaultSerialNumber;
defaultChassis.assetTagNumber = kDefaultAssetTagNumber;
defaultChassis.assetTag = kDefaultAssetTag;
// if (platformCPUFeature(CPU_FEATURE_MOBILE)) Bungo: doesn't recognise correctly
if (PlatformType == 2) // this method works
{
if (Platform.CPU.NoCores > 1)
{
defaultSystemInfo.productName= kDefaultMacBookPro;
defaultBIOSInfo.version= kDefaultMacBookProBIOSVersion;
defaultBIOSInfo.releaseDate= kDefaultMacBookProBIOSReleaseDate;
defaultSystemInfo.family= kDefaultMacBookProFamily;
defaultBaseBoard.product = kDefaultMacBookProBoardProduct;
defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
defaultChassis.chassisType = kSMBchassisUnknown;
defaultSystemInfo.productName = kDefaultMacBookPro;
defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion;
defaultBIOSInfo.releaseDate = kDefaultMacBookProBIOSReleaseDate;
defaultSystemInfo.family = kDefaultMacBookProFamily;
defaultBaseBoard.product = kDefaultMacBookProBoardProduct;
defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
defaultChassis.chassisType = kSMBchassisUnknown;
}
else
{
defaultSystemInfo.productName= kDefaultMacBook;
defaultBIOSInfo.version= kDefaultMacBookBIOSVersion;
defaultBIOSInfo.releaseDate= kDefaultMacBookBIOSReleaseDate;
defaultSystemInfo.family= kDefaultMacBookFamily;
defaultBaseBoard.product = kDefaultMacBookBoardProduct;
defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
defaultChassis.chassisType = kSMBchassisUnknown;
defaultSystemInfo.productName = kDefaultMacBook;
defaultBIOSInfo.version = kDefaultMacBookBIOSVersion;
defaultBIOSInfo.releaseDate = kDefaultMacBookBIOSReleaseDate;
defaultSystemInfo.family = kDefaultMacBookFamily;
defaultBaseBoard.product = kDefaultMacBookBoardProduct;
defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
defaultChassis.chassisType = kSMBchassisUnknown;
}
}
else
switch (Platform.CPU.NoCores)
{
case 1:
defaultBIOSInfo.version= kDefaultMacMiniBIOSVersion;
defaultBIOSInfo.releaseDate= kDefaultMacMiniBIOSReleaseDate;
defaultSystemInfo.productName= kDefaultMacMini;
defaultSystemInfo.family= kDefaultMacMiniFamily;
defaultBIOSInfo.version = kDefaultMacMiniBIOSVersion;
defaultBIOSInfo.releaseDate = kDefaultMacMiniBIOSReleaseDate;
defaultSystemInfo.productName = kDefaultMacMini;
defaultSystemInfo.family = kDefaultMacMiniFamily;
defaultBaseBoard.product = kDefaultMacMiniBoardProduct;
defaultBaseBoard.boardType = kSMBBaseBoardUnknown;
defaultChassis.chassisType = kSMBchassisLPDesktop;
break;
case 2:
defaultBIOSInfo.version= kDefaultiMacBIOSVersion;
defaultBIOSInfo.releaseDate= kDefaultiMacBIOSReleaseDate;
defaultSystemInfo.productName= kDefaultiMac;
defaultSystemInfo.family= kDefaultiMacFamily;
defaultBIOSInfo.version = kDefaultiMacBIOSVersion;
defaultBIOSInfo.releaseDate = kDefaultiMacBIOSReleaseDate;
defaultSystemInfo.productName = kDefaultiMac;
defaultSystemInfo.family = kDefaultiMacFamily;
defaultBaseBoard.product = kDefaultiMacBoardProduct;
defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
defaultChassis.chassisType = kSMBchassisAllInOne;
case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
case CPU_MODEL_IVYBRIDGE_XEON:
defaultBIOSInfo.version= kDefaultiMacSandyBIOSVersion;
defaultBIOSInfo.releaseDate= kDefaultiMacSandyBIOSReleaseDate;
defaultBIOSInfo.version = kDefaultiMacSandyBIOSVersion;
defaultBIOSInfo.releaseDate = kDefaultiMacSandyBIOSReleaseDate;
defaultSystemInfo.productName= kDefaultiMacSandy;
defaultSystemInfo.family= kDefaultiMacFamily;
defaultSystemInfo.family = kDefaultiMacFamily;
defaultBaseBoard.product = kDefaultiMacSandyBoardProduct;
defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
defaultChassis.chassisType = kSMBchassisAllInOne;
int len;
char key[24];
if (current != structHeader->handle)
{
if (current != structHeader->handle) {
idx++;
current = structHeader->handle;
}
sprintf(key, "%s%d", keyString, idx);
if (value)
{
if (getIntForKey(key, (int *)&(value->dword), SMBPlist))
{
if (value) {
if (getIntForKey(key, (int *)&(value->dword), SMBPlist)) {
return true;
}
}
else
{
if (getValueForKey(key, string, &len, SMBPlist))
{
} else {
if (getValueForKey(key, string, &len, SMBPlist)) {
return true;
}
}
{
uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
if (!field)
{
if (!field) {
return NULL;
}
{
int strSize;
if (!field)
{
if (!field) {
return;
}
if (!string)
{
if (!string) {
*field = 0;
return;
}
strSize = strlen(string);
// remove any spaces found at the end
while ((strSize != 0) && (string[strSize - 1] == ' '))
{
while ((strSize != 0) && (string[strSize - 1] == ' ')) {
strSize--;
}
if (strSize == 0)
{
if (strSize == 0) {
*field = 0;
return;
}
bool parsed;
int val;
if (numOfSetters <= idx)
{
if (numOfSetters <= idx) {
return false;
}
switch (SMBSetters[idx].valueType)
{
switch (SMBSetters[idx].valueType) {
case kSMBString:
{
if (SMBSetters[idx].keyString)
}
}
if (SMBSetters[idx].getSMBValue)
{
if (SMBSetters[idx].getSMBValue((returnType *)&string))
{
if (SMBSetters[idx].getSMBValue) {
if (SMBSetters[idx].getSMBValue((returnType *)&string)) {
break;
}
}
// if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) Bungo
if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue))
{
if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) {
string = *(SMBSetters[idx].defaultValue);
break;
}
case kSMBWord:
case kSMBDWord:
//case kSMBQWord:
if (SMBSetters[idx].keyString)
{
if (SMBSetters[idx].keyString) {
parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
if (!parsed)
{
if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
{
if (structPtr->orig->type == kSMBTypeMemoryDevice) { // MemoryDevice only
parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
}
}
if (parsed)
{
switch (SMBSetters[idx].valueType)
{
if (parsed) {
switch (SMBSetters[idx].valueType) {
case kSMBByte:
value->byte = (uint8_t)val;
break;
}
}
if (SMBSetters[idx].getSMBValue)
{
if (SMBSetters[idx].getSMBValue(value))
{
if (SMBSetters[idx].getSMBValue) {
if (SMBSetters[idx].getSMBValue(value)) {
return true;
}
}
// #if 0 Bungo: enables code below
// if (*(SMBSetters[idx].defaultValue)) Bungo
if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue))
if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue))
{
// value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo
switch (SMBSetters[idx].valueType)
{
switch (SMBSetters[idx].valueType) {
case kSMBByte:
value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue);
break;
}
// if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified"
if ((SMBSetters[idx].valueType == kSMBString) && string)
{
if ((SMBSetters[idx].valueType == kSMBString) && string) {
setSMBStringForField(structPtr->new, string, &value->byte);
}
return true;
/* http://forge.voodooprojects.org/p/chameleon/issues/361/ */
bool forceFullMemInfo = false;
if (structPtr->orig->type == kSMBTypeMemoryDevice)
{
if (structPtr->orig->type == kSMBTypeMemoryDevice) {
getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig);
if (forceFullMemInfo)
{
if (forceFullMemInfo) {
structPtr->orig->length = 27;
}
}
stringIndex = 1;
stringsSize = 0;
if (handle < structPtr->orig->handle)
{
if (handle < structPtr->orig->handle) {
handle = structPtr->orig->handle;
}
memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
for (i = 0; i < numOfSetters; i++)
{
if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))
{
for (i = 0; i < numOfSetters; i++) {
if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length)) {
setterFound = true;
setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
}
}
if (setterFound)
{
if (setterFound) {
ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
for (; ((uint16_t *)ptr)[0] != 0; ptr++);
if (((uint16_t *)ptr)[0] == 0)
{
if (((uint16_t *)ptr)[0] == 0) {
ptr += 2;
}
structSize = ptr - (uint8_t *)structPtr->new;
}
else
{
} else {
ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
for (; ((uint16_t *)ptr)[0] != 0; ptr++);
if (((uint16_t *)ptr)[0] == 0)
{
if (((uint16_t *)ptr)[0] == 0) {
ptr += 2;
}
tableLength += structSize;
if (structSize > maxStructSize)
{
if (structSize > maxStructSize) {
maxStructSize = structSize;
}
uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
structPtr->orig = (SMBStructHeader *)ptr;
for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)
{
switch (structPtr->orig->type)
{
for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));) {
switch (structPtr->orig->type) {
/* Skip all Apple Specific Structures */
case kSMBTypeFirmwareVolume:
case kSMBTypeMemorySPD:
ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
for (; ((uint16_t *)ptr)[0] != 0; ptr++);
if (((uint16_t *)ptr)[0] == 0)
{
if (((uint16_t *)ptr)[0] == 0) {
ptr += 2;
}
uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress;
SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
int i, isZero, isOnes;
uint8_t FixedUUID[UUID_LEN] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
uint8_t FixedUUID[UUID_LEN] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist);
uint8_t *ret = (uint8_t *)getUUIDFromString(sysId);
ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
for (; ((uint16_t *)ptr)[0] != 0; ptr++);
if (((uint16_t *)ptr)[0] == 0)
{
if (((uint16_t *)ptr)[0] == 0) {
ptr += 2;
}
ptr = ((SMBSystemInformation *)structHeader)->uuid;
if (!sysId || !ret) // no or bad custom UUID,...
{
if (!sysId || !ret) { // no or bad custom UUID,...
sysId = 0;
ret = ((SMBSystemInformation *)structHeader)->uuid; // ...try bios dmi info UUID extraction
ret = Platform.UUID; // ...try bios dmi system uuid extraction
}
for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++) // check if empty or setable, means: no uuid present
{
if (ret[i] != 0x00)
{
if (ret[i] != 0x00) {
isZero = 0;
}
if (ret[i] != 0xff)
{
if (ret[i] != 0xff) {
isOnes = 0;
}
}
if (isZero || isOnes) // if empty or setable...
{
if (isZero || isOnes) { // if empty or setable...
verbose("No UUID present in SMBIOS System Information Table\n");
ret = FixedUUID; // ...set a fixed value for system-id = 000102030405060708090A0B0C0D0E0F
}
uint8_t *buffer;
// bool setSMB = true; Bungo
if (!origeps)
{
if (!origeps) {
return;
}
neweps = origeps;
structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
if (!structPtr)
{
if (!structPtr) {
return;
}
buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);
if (!buffer)
{
if (!buffer) {
free(structPtr);
return;
}
// getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig); Bungo
getBoolForKey(kSMBIOSdefaults, &useSMBIOSdefaults, &bootInfo->chameleonConfig);
// if (setSMB)
setDefaultSMBData();
// Bungo
// if (setSMB) Bungo
setDefaultSMBData();
setupNewSMBIOSTable(origeps, structPtr);
neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
if (!neweps)
{
if (!neweps) {
free(buffer);
free(structPtr);
return;
neweps->anchor[3]= '_';
neweps->entryPointLength= sizeof(SMBEntryPoint);
neweps->majorVersion= 2; // Bungo:
neweps->minorVersion= 4; // We're using 2.4 SMBIOS rev. as real Macs
neweps->minorVersion= 4; // Here we're using 2.4 SMBIOS rev. as real Macs
neweps->maxStructureSize= maxStructSize;
neweps->entryPointRevision= 0;
neweps->dmi.tableLength= tableLength;
neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
neweps->dmi.structureCount= structureCount;
neweps->dmi.bcdRevision= 0x24;
neweps->dmi.bcdRevision= 0x24; // ... and 2.4 DMI rev. as real Macs
if (!neweps->dmi.tableAddress)
{
if (!neweps->dmi.tableAddress) {
free(buffer);
free(structPtr);
return;
memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
// Bungo
Platform.UUID = FixSystemUUID(); // Bungo: fix System UUID
neweps->dmi.checksum= 0;
void *getSmbios(int which)
{
switch (which)
{
switch (which) {
case SMBIOS_ORIGINAL:
if (!origeps)
{
if (!origeps) {
origeps = getAddressOfSmbiosTable();
}
return origeps;
{
switch (structHeader->type)
{
/* Bungo: fixed in smbios now
case kSMBTypeSystemInformation:
Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid;
Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; // get factory system uuid
break;
*/
case kSMBTypeSystemEnclosure: // Bungo: determine platform type
switch (((SMBSystemEnclosure *)structHeader)->chassisType) {
case kSMBchassisDesktop:
case kSMBTypeMemoryDevice:
Platform.DMI.CntMemorySlots++;
if (((SMBMemoryDevice *)structHeader)->memorySize != 0)
{
if (((SMBMemoryDevice *)structHeader)->memorySize != 0){
Platform.DMI.MemoryModules++;
}
if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)
{
if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0){
Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
}
dimmnbr++;
structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
if (((uint16_t *)structPtr)[0] == 0)
{
if (((uint16_t *)structPtr)[0] == 0) {
structPtr += 2;
}
branches/ErmaC/Enoch/i386/libsaio/smbios_decode.c
77
88
99
10
11
12
1013
1114
1215
......
1821
1922
2023
21
24
25
26
27
28
2229
2330
2431
25
26
32
33
34
35
36
37
38
2739
28
40
2941
30
31
32
33
42
43
44
45
46
47
48
3449
3550
3651
37
3852
39
40
41
42
43
44
45
46
47
53
54
55
56
4857
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
5867
5968
60
61
62
63
69
6470
6571
66
72
6773
68
6974
7075
7176
......
8186
8287
8388
84
85
86
8789
8890
8991
90
92
9193
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
122123
123124
124
125
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
126175
127176
128177
......
130179
131180
132181
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
159208
160209
161210
......
167216
168217
169218
170
171
219
220
172221
173
222
223
174224
175225
176226
......
188238
189239
190240
191
192
193
194
241
242
243
244
195245
196
246
197247
248
249
198250
199251
200
201
202
252
253
254
255
256
257
258
203259
204
205260
206
261
262
263
264
265
266
207267
208
209
268
269
270
271
210272
211273
212274
......
216278
217279
218280
219
220
221
222
223
281
282
283
284
285
224286
225
287
226288
227
289
290
291
292
293
228294
229295
230296
......
236302
237303
238304
239
240
241
242
243
305
306
307
308
309
310
311
312
313
314
244315
245316
246317
......
260331
261332
262333
263
334
264335
265336
266
337
267338
268
339
269340
270341
271342
272343
273344
274
345
275346
276
277
278
347
348
349
350
351
279352
280353
281354
......
314387
315388
316389
317
318
390
391
319392
320393
321
394
322395
396
323397
324398
325
326
327
328
399
400
401
402
329403
330404
331405
......
334408
335409
336410
337
338
411
412
339413
340414
341415
342416
343417
344
345
418
419
346420
347421
348422
......
356430
357431
358432
433
434
435
359436
437
438
360439
440
441
361442
362443
363
444
364445
365446
366447
......
397478
398479
399480
481
482
400483
401484
402485
......
410493
411494
412495
496
497
413498
414499
415500
......
421506
422507
423508
424
425
509
426510
427511
428512
#include "libsaio.h"
#include "smbios.h"
// Bungo:
#include "boot.h"
#include "bootstruct.h"
#ifndef DEBUG_SMBIOS
#define DEBUG_SMBIOS 0
#define DBG(x...)msglog(x)
#endif
static SMBWord minorVersion;
static SMBByte minorVersion; // SMBIOS rev. minor
// Bungo:
static SMBByte majorVersion; // SMBIOS rev. major
static SMBByte bcdRevisionLo; // DMI rev. minor
static SMBByte bcdRevisionHi; // DMI rev. major
extern char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field);
// Bungo: fixes random string readout if null in smbios to "Not Specified" as dmidecode dispays
#define NotSpecifiedStr "Not Specified"
// Bungo:
#define NotSpecifiedStr "Not Specified" // no string
#define OutOfSpecStr "<OUT OF SPEC>" // value out of smbios spec. range
#define PrivateStr "** PRIVATE **" // masking private data
#define alwaysMask true
#define neverMask false
static bool privateData = true;
char *SMBStringForField(SMBStructHeader *structHeader, uint8_t field)
char *SMBStringForField(SMBStructHeader *structHeader, uint8_t field, const bool mask) // Bungo: fixes random string readout if null in smbios to "Not Specified" as dmidecode displays
{
char *str;
str = getSMBStringForField(structHeader, field);
if (str == 0)
str = NotSpecifiedStr;
char *str = NULL;
str = getSMBStringForField(structHeader, field);
if (!field) {
str = NotSpecifiedStr;
} else if (mask) {
str = PrivateStr;
}
return str;
};
//
// http://www.on-time.com/rtos-32-docs/rttarget-32/reference-manual/smbios/rtsmbios-oem-string.htm
// http://cvs.savannah.gnu.org/viewvc/dmidecode/dmidecode/
#define out_of_spec "<OUT OF SPEC>"
/*===
7.2.2
===*/
static const char *dmi_system_wake_up_type[] =
/*====
7.2.2
===*/
static const char *SMBWakeUpTypes[] = // Bungo: strings for wake-up type (Table Type 1 - System Information)
{
"Reserved", /* 00h */
"Other", /* 01h */
"Unknown", /* 02h */
"APM Timer", /* 03h */
"Modem Ring", /* 04h */
"LAN Remote", /* 05h */
"Power Switch", /* 06h */
"PCI PME#", /* 07h */
"AC Power Restored" /* 08h */
"Reserved", /* 00h */
"Other", /* 01h */
"Unknown", /* 02h */
"APM Timer", /* 03h */
"Modem Ring", /* 04h */
"LAN Remote", /* 05h */
"Power Switch", /* 06h */
"PCI PME#", /* 07h */
"AC Power Restored" /* 08h */
};
static const int kdmi_system_wake_up_typeCount = sizeof(dmi_system_wake_up_type) /
sizeof(dmi_system_wake_up_type[0]);
/*===
/*====
7.3.2
===*/
static const char *dmi_base_board_type[] =
static const char *SMBBaseBoardTypes[] = // Bungo: strings for base board type (Table Type 2 - Base Board Information)
{
"Reserved", /* 00h */
"Unknown", /* 01h */
"Other", /* 02h */
"Server Blade", /* 03h */
"Interconnect Board" /* 0Dh */
};
static const int kdmi_base_board_type = sizeof(dmi_base_board_type) /
sizeof(dmi_base_board_type[0]);
/*===
7.4.1
===*/
static const char *dmi_chassis_type[] =
static const char *SMBChassisTypes[] = // Bungo: strings for chassis type (Table Type 3 - Chassis Information)
{
"Reserved", /* 00h */
"Other", /* 01h */
"Unknown", /* 02h */
"Desktop", /* 03h */
"Low Profile Desktop", /* 04h */
"Pizza Box", /* 05h */
"Mini Tower", /* 06h */
"Tower", /* 07h */
"Portable", /* 08h */
"Laptop", /* 09h */
"Notebook", /* 0Ah */
"Hand Held", /* 0Bh */
"Docking Station", /* 0Ch */
"All in One", /* 0Dh */
"Sub Notebook", /* 0Eh */
"Space-saving", /* 0Fh */
"Lunch Box", /* 10h */
"Main Server Chassis", /* 11h */
"Expansion Chassis", /* 12h */
"SubChassis", /* 13h */
"Bus Expansion Chassis",/* 14h */
"Peripheral Chassis", /* 15h */
"RAID Chassis", /* 16h */
"Rack Mount Chassis", /* 17h */
"Sealed-case PC", /* 18h */
"Multi-system chassis", /* 19h */
"Compact PCI", /* 1Ah */
"Advanced TCA", /* 1Bh */
"Blade", /* 1Ch */ // An SMBIOS implementation for a Blade would contain a Type 3 Chassis structure
"Blade Enclosing" /* 1Dh */ // A Blade Enclosure is a specialized chassis that contains a set of Blades.
"Other", /* 01h */
"Unknown", /* 02h */
"Desktop", /* 03h */
"Low Profile Desktop", /* 04h */
"Pizza Box", /* 05h */
"Mini Tower", /* 06h */
"Tower", /* 07h */
"Portable", /* 08h */
"Laptop", /* 09h */
"Notebook", /* 0Ah */
"Hand Held", /* 0Bh */
"Docking Station", /* 0Ch */
"All in One", /* 0Dh */
"Sub Notebook", /* 0Eh */
"Space-saving", /* 0Fh */
"Lunch Box",/* 10h */
"Main Server Chassis",/* 11h */
"Expansion Chassis",/* 12h */
"SubChassis",/* 13h */
"Bus Expansion Chassis",/* 14h */
"Peripheral Chassis",/* 15h */
"RAID Chassis",/* 16h */
"Rack Mount Chassis", /* 17h */
"Sealed-case PC",/* 18h */
"Multi-system Chassis", /* 19h */
"Compact PCI",/* 1Ah */
"Advanced TCA",/* 1Bh */
"Blade",/* 1Ch */ // An SMBIOS implementation for a Blade would contain a Type 3 Chassis structure
"Blade Enclosing"/* 1Dh */ // A Blade Enclosure is a specialized chassis that contains a set of Blades.
};
static const int kdmi_chassis_typeCount = sizeof(dmi_chassis_type) /
sizeof(dmi_chassis_type[0]);
/*====
7.5.5
===*/
/*static const char *SMBCpuSocket[] = // ErmaC: strings for (Table Type 4 - Processor Information )
{
"Other", // 01h
"Unknown",
"Daughter Board",
"ZIF Socket",
"Replaceable Piggy Back",
"None",
"LIF Socket",
"Slot 1",
"Slot 2",
"370-pin Socket",
"Slot A",
"Slot M",
"Socket 423",
"Socket A (Socket 462)",
"Socket 478",
"Socket 754",
"Socket 940",
"Socket 939",
"Socket mPGA604",
"Socket LGA771",
"Socket LGA775",
"Socket S1",
"Socket AM2",
"Socket F (1207)",
"Socket LGA1366",
"Socket G34",
"Socket AM3",
"Socket C32",
"Socket LGA1156",
"Socket LGA1567",
"Socket PGA988A",
"Socket BGA1288",
"Socket rPGA988B",
"Socket BGA1023",
"Socket BGA1224",
"Socket BGA1155",
"Socket LGA1356",
"Socket LGA2011",
"Socket FS1",
"Socket FS2",
"Socket FM1",
"Socket FM2",
"Socket LGA2011-3",
"Socket LGA1356-3"// 2Ch
};*/
/*=====
7.18.2
static const char *
SMBMemoryDeviceTypes[] =
{
"RAM", /* 00h Undefined */
"RAM", /* 01h Other */
"RAM", /* 02h Unknown */
"DRAM", /* 03h DRAM */
"EDRAM", /* 04h EDRAM */
"VRAM", /* 05h VRAM */
"SRAM", /* 06h SRAM */
"RAM", /* 07h RAM */
"ROM", /* 08h ROM */
"FLASH", /* 09h FLASH */
"EEPROM", /* 0Ah EEPROM */
"FEPROM", /* 0Bh FEPROM */
"EPROM", /* 0Ch EPROM */
"CDRAM", /* 0Dh CDRAM */
"3DRAM", /* 0Eh 3DRAM */
"SDRAM", /* 0Fh SDRAM */
"SGRAM", /* 10h SGRAM */
"RDRAM", /* 11h RDRAM */
"DDR SDRAM", /* 12h DDR */
"DDR2 SDRAM", /* 13h DDR2 */
"DDR2 FB-DIMM", /* 14h DDR2 FB-DIMM */
"RAM",/* 15h unused */
"RAM",/* 16h unused */
"RAM",/* 17h unused */
"DDR3",/* 18h DDR3, chosen in [5776134] */
"FBD2"/* 19h FBD2 */
"RAM", /* 00h Undefined */
"RAM", /* 01h Other */
"RAM", /* 02h Unknown */
"DRAM", /* 03h DRAM */
"EDRAM", /* 04h EDRAM */
"VRAM", /* 05h VRAM */
"SRAM", /* 06h SRAM */
"RAM", /* 07h RAM */
"ROM", /* 08h ROM */
"FLASH", /* 09h FLASH */
"EEPROM", /* 0Ah EEPROM */
"FEPROM", /* 0Bh FEPROM */
"EPROM", /* 0Ch EPROM */
"CDRAM", /* 0Dh CDRAM */
"3DRAM", /* 0Eh 3DRAM */
"SDRAM", /* 0Fh SDRAM */
"SGRAM", /* 10h SGRAM */
"RDRAM", /* 11h RDRAM */
"DDR SDRAM", /* 12h DDR */
"DDR2 SDRAM", /* 13h DDR2 */
"DDR2 FB-DIMM", /* 14h DDR2 FB-DIMM */
"RAM",/* 15h unused */
"RAM",/* 16h unused */
"RAM",/* 17h unused */
"DDR3",/* 18h DDR3, chosen in [5776134] */
"FBD2"/* 19h FBD2 */
};
static const int kSMBMemoryDeviceTypeCount = sizeof(SMBMemoryDeviceTypes) /
void decodeBIOSInformation(SMBBIOSInformation *structHeader)
{
DBG("BIOS Information:\n");
DBG("\tVendor: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->vendor));
DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBG("\tVendor: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->vendor, neverMask));
DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version, neverMask));
// Address Segment
DBG("\tRelease Date: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->releaseDate));
DBG("\tRelease Date: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->releaseDate, neverMask));
DBG("\tBIOS Revision: %d.%d\n", structHeader->releaseMajor, structHeader->releaseMinor);
// ROM Size
//DBG("\tSupported BIOS functions: (0x%llX) %s\n", structHeader->characteristics, SMBBIOSInfoChar0[structHeader->characteristics]);
// Major Release
void decodeSystemInformation(SMBSystemInformation *structHeader)
{
DBG("System Information:\n");
DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBG("\tProduct Name: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->productName));
DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBG("\tSerial Number: ** PRIVATE **\n"); //%s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer, neverMask));
DBG("\tProduct Name: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->productName, neverMask));
DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version, neverMask));
DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber, privateData));
if (minorVersion < 1 || structHeader->header.length < 25)
if (minorVersion < 1 || structHeader->header.length < 25) {
return;
}
uint8_t *uuid = structHeader->uuid;
if (uuid) {
DBG("\tuuid: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02x%02X-%02X%02X%02X%02X%02X%02X\n",
uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
if (privateData) {
DBG("\tUUID: %s\n", PrivateStr);
} else {
DBG("\tUUID: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02x%02X-%02X%02X%02X%02X%02X%02X\n",
uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
}
}
DBG("\tWake-up Type: 0x%x\n", structHeader->wakeupReason);
if (minorVersion < 4 || structHeader->header.length < 27)
if (structHeader->wakeupReason > 8) {
DBG("\tWake-up Type: %s\n", OutOfSpecStr);
} else {
DBG("\tWake-up Type: %s\n", SMBWakeUpTypes[structHeader->wakeupReason]);
}
if (minorVersion < 4 || structHeader->header.length < 27) {
return;
DBG("\tSKU Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->skuNumber)); // System SKU#
DBG("\tFamily: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->family));
}
DBG("\tSKU Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->skuNumber, neverMask)); // System SKU#
DBG("\tFamily: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->family, neverMask));
DBG("\n");
}
void decodeBaseBoard(SMBBaseBoard *structHeader)
{
DBG("Base Board Information:\n");
DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBG("\tProduct Name: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->product));
DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber));
DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer, neverMask));
DBG("\tProduct Name: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->product, neverMask));
DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version, neverMask));
DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber, privateData));
DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag, neverMask));
// Feature Flags (BYTE)
DBG("\tLocation In Chassis: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->locationInChassis)); // Part Component
DBG("\tLocation In Chassis: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->locationInChassis, neverMask)); // Part Component
// Chassis Handle (WORD)
DBG("\tType: 0x%X\n", structHeader->boardType);
if ((structHeader->boardType < kSMBBaseBoardUnknown) || (structHeader->boardType > kSMBBaseBoardInterconnect)) {
DBG("\tType: %s\n", OutOfSpecStr);
} else {
DBG("\tType: %s\n", SMBBaseBoardTypes[(structHeader->boardType - 1)]);
}
// Number of Contained Object Handles (n) (BYTE)
// Contained Object Handles n(WORDs)
DBG("\n");
void decodeSystemEnclosure(SMBSystemEnclosure *structHeader)
{
DBG("Chassis Information:\n");
DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBG("\tType: 0x%X\n", structHeader->chassisType);
DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBG("\tSerial Number: ** PRIVATE **\n"); //%s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBG("\tAsset Tag Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber));
DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer, neverMask));
// DBG("\tType: 0x%X\n", structHeader->chassisType);
if ((structHeader->chassisType < kSMBchassisOther) || (structHeader->chassisType > kSMBchassisBladeEnclosing)) {
DBG("\tType: %s\n", OutOfSpecStr);
} else {
DBG("\tType: %s\n", SMBChassisTypes[(structHeader->chassisType - 1)]);
}
DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version, neverMask));
DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber, privateData));
DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag, neverMask));
// Boot-up State:
// Power Supply State
// Thermal State
void decodeProcessorInformation(SMBProcessorInformation *structHeader)
{
DBG("Processor Information:\n");
DBG("\tSocket Designation: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->socketDesignation));
DBG("\tSocket Designation: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->socketDesignation, neverMask));
DBG("\tType: %d\n", structHeader->processorType);
DBG("\tFamily: 0x%X\n", structHeader->processorFamily);
DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer, neverMask));
DBG("\tID: 0x%llX\n", structHeader->processorID);
DBG("\tProcessor Version: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->processorVersion));
DBG("\tProcessor Version: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->processorVersion, neverMask));
//DBG("\tVoltage: 0.%xV\n", structHeader->voltage);
DBG("\tExternal Clock: %dMHz\n", structHeader->externalClock);
DBG("\tMaximum Clock: %dMHz\n", structHeader->maximumClock);
DBG("\tCurrent Clock: %dMHz\n", structHeader->currentClock);
if (minorVersion < 3 || structHeader->header.length < 35)
if (minorVersion < 3 || structHeader->header.length < 35) {
return;
DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag));
DBG("\tPart Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber));
}
DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber, privateData));
DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag, neverMask));
DBG("\tPart Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber, neverMask));
//DBG("\tProcessor Family 2: %d\n", structHeader->processorFamily2);
DBG("\n");
}
void decodeMemoryDevice(SMBMemoryDevice *structHeader)
{
DBG("Memory Device:\n");
DBG("\tDevice Locator: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->deviceLocator));
DBG("\tBank Locator: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->bankLocator));
DBG("\tDevice Locator: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->deviceLocator, neverMask));
DBG("\tBank Locator: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->bankLocator, neverMask));
DBG("\tMemory Type: %s\n", SMBMemoryDeviceTypes[structHeader->memoryType]);
if (minorVersion < 3 || structHeader->header.length < 27)
if (minorVersion < 3 || structHeader->header.length < 27) {
return;
}
DBG("\tSpeed: %d MHz\n", structHeader->memorySpeed);
DBG("\tError Handle: %x\n", structHeader->errorHandle);
DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag));
DBG("\tPart Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber));
DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer, neverMask));
DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber, privateData));
DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag, neverMask));
DBG("\tPart Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber, neverMask));
DBG("\n");
}
//-------------------------------------------------------------------------------------------------------------------------
void decodeOemProcessorType(SMBOemProcessorType *structHeader)
{
DBG("AppleProcessorType:\n");
DBG("\tProcessorType: 0x%x\n", ((SMBOemProcessorType *)structHeader)->ProcessorType);
DBG("Apple specific Processor Type:\n");
DBG("\tCpu-type: 0x%x\n", ((SMBOemProcessorType *)structHeader)->ProcessorType);
DBG("\n");
}
void decodeOemProcessorBusSpeed(SMBOemProcessorBusSpeed *structHeader)
{
DBG("AppleProcessorBusSpeed:\n");
DBG("\tProcessorBusSpeed (QPI): %d.%dGT/s\n",
DBG("Apple specific Processor Interconnect Speed:\n");
DBG("\tQPI = %d.%dGT/s\n",
((SMBOemProcessorBusSpeed *)structHeader)->ProcessorBusSpeed / 1000,
(((SMBOemProcessorBusSpeed *)structHeader)->ProcessorBusSpeed / 100) % 10);
DBG("\n");
SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
minorVersion = eps->minorVersion;
majorVersion = eps->majorVersion;
bcdRevisionHi = eps->dmi.bcdRevision >> 4;
bcdRevisionLo = eps->dmi.bcdRevision & 0x0F;
getBoolForKey(kPrivateData, &privateData, &bootInfo->chameleonConfig); // Bungo: chek if mask some data
DBG("\n");
DBG("SMBIOS rev. %d.%d, DMI rev. %d.%d\n", majorVersion, minorVersion, bcdRevisionHi, bcdRevisionLo);
DBG("\n");
for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
{
DBG("Type: %d, Length: %d, Handle: 0x%x\n",
DBG("Type: %d, Length: %d, Handle: 0x%04x\n",
structHeader->type, structHeader->length, structHeader->handle);
switch (structHeader->type)
decodeMemoryDevice((SMBMemoryDevice *)structHeader);
break;
//kSMBTypeMemoryArrayMappedAddress: // Type 19
/* Skip all Apple Specific Structures */
case kSMBTypeFirmwareVolume: // Type 128
case kSMBTypeMemorySPD: // Type 130
decodeOemProcessorBusSpeed((SMBOemProcessorBusSpeed *)structHeader);
break;
//kSMBTypeOemPlatformFeature: // Type 133
case kSMBTypeEndOfTable: // Type 127
/* Skip, to be added at the end */
break;
ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
for (; ((uint16_t *)ptr)[0] != 0; ptr++);
if (((uint16_t *)ptr)[0] == 0)
{
if (((uint16_t *)ptr)[0] == 0) {
ptr += 2;
}
branches/ErmaC/Enoch/i386/libsaio/hpet.c
130130
131131
132132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158133
159134
160135
......
162137
163138
164139
165
166
167
168
140
141
169142
170143
171144
172145
173146
174147
175
176
148
177149
178
179
180
150
181151
182
183
152
184153
185154
186155
187156
188
189
190
157
191158
192159
193160
......
197164
198165
199166
200
201
167
202168
203169
204170
......
212178
213179
214180
215
216
217
218
181
182
219183
220184
221185
222186
223187
224
225
188
226189
227190
228
229
230
191
231192
232193
233194
234
235
195
236196
237197
238
239
240
198
241199
242200
243201
......
252210
253211
254212
255
256
257
258
213
214
259215
260216
261217
262218
263219
264220
265
266
221
267222
268
269
270
223
271224
272
273
225
274226
275227
276228
277229
278
279
280
230
281231
282232
283233
......
287237
288238
289239
290
291
240
292241
293242
294243
......
297246
298247
299248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
{ 0x1106, 0x3372, "VT8237S" },
};
void force_enable_hpet(pci_dt_t *lpc_dev)
{
switch(lpc_dev->vendor_id)
{
case 0x8086:
force_enable_hpet_intel(lpc_dev);
break;
case 0x10de:
force_enable_hpet_nvidia(lpc_dev);
break;
case 0x1106:
force_enable_hpet_via(lpc_dev);
break;
}
#if DEBUG_HPET
printf("Press [Enter] to continue...\n");
getchar();
#endif
}
/* ErmaC add lpc for nVidia */
void force_enable_hpet_nvidia(pci_dt_t *lpc_dev)
{
int i;
void*rcba;
for(i = 1; i < sizeof(lpc_controllers_nvidia) / sizeof(lpc_controllers_nvidia[0]); i++)
{
if ((lpc_controllers_nvidia[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_nvidia[i].device == lpc_dev->device_id))
{
for(i = 1; i < sizeof(lpc_controllers_nvidia) / sizeof(lpc_controllers_nvidia[0]); i++){
if ((lpc_controllers_nvidia[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_nvidia[i].device == lpc_dev->device_id)) {
rcba = (void *)(pci_config_read32(lpc_dev->dev.addr, 0xF0) & 0xFFFFC000);
DBG("nVidia(R) %s LPC Interface [%04x:%04x], MMIO @ 0x%lx\n",
lpc_controllers_nvidia[i].name, lpc_dev->vendor_id, lpc_dev->device_id, rcba);
if (rcba == 0)
{
if (rcba == 0) {
printf(" RCBA disabled; cannot force enable HPET\n");
}
else
{
} else {
val = REG32(rcba, 0x3404);
if (val & 0x80)
{
if (val & 0x80) {
// HPET is enabled in HPTC. Just not reported by BIOS
DBG(" HPET is enabled in HPTC, just not reported by BIOS\n");
hpet_address |= (val & 3) << 12 ;
DBG(" HPET MMIO @ 0x%lx\n", hpet_address);
}
else
{
} else {
// HPET disabled in HPTC. Trying to enable
DBG(" HPET is disabled in HPTC, trying to enable\n");
REG32(rcba, 0x3404) = val | 0x80;
// verify if the job is done
val = REG32(rcba, 0x3404);
if (!(val & 0x80))
{
if (!(val & 0x80)) {
printf(" Failed to force enable HPET\n");
}
}
uint32_tval, hpet_address = 0xFED00000;
int i;
for(i = 1; i < sizeof(lpc_controllers_via) / sizeof(lpc_controllers_via[0]); i++)
{
if ((lpc_controllers_via[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_via[i].device == lpc_dev->device_id))
{
for(i = 1; i < sizeof(lpc_controllers_via) / sizeof(lpc_controllers_via[0]); i++) {
if ((lpc_controllers_via[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_via[i].device == lpc_dev->device_id)) {
val = pci_config_read32(lpc_dev->dev.addr, 0x68);
DBG("VIA %s LPC Interface [%04x:%04x], MMIO\n",
lpc_controllers_via[i].name, lpc_dev->vendor_id, lpc_dev->device_id);
if (val & 0x80)
{
if (val & 0x80) {
hpet_address = (val & ~0x3ff);
DBG("HPET at 0x%lx\n", hpet_address);
}
else
{
} else {
val = 0xfed00000 | 0x80;
pci_config_write32(lpc_dev->dev.addr, 0x68, val);
val = pci_config_read32(lpc_dev->dev.addr, 0x68);
if (val & 0x80)
{
if (val & 0x80) {
hpet_address = (val & ~0x3ff);
DBG("Force enabled HPET at 0x%lx\n", hpet_address);
}
else
{
} else {
DBG("Unable to enable HPET");
}
}
void*rcba;
/* LPC on Intel ICH is always (?) at 00:1f.0 */
for(i = 1; i < sizeof(lpc_controllers_intel) / sizeof(lpc_controllers_intel[0]); i++)
{
if ((lpc_controllers_intel[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_intel[i].device == lpc_dev->device_id))
{
for(i = 1; i < sizeof(lpc_controllers_intel) / sizeof(lpc_controllers_intel[0]); i++) {
if ((lpc_controllers_intel[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_intel[i].device == lpc_dev->device_id)) {
rcba = (void *)(pci_config_read32(lpc_dev->dev.addr, 0xF0) & 0xFFFFC000);
DBG("Intel(R) %s LPC Interface [%04x:%04x], MMIO @ 0x%lx\n",
lpc_controllers_intel[i].name, lpc_dev->vendor_id, lpc_dev->device_id, rcba);
if (rcba == 0)
{
if (rcba == 0) {
printf(" RCBA disabled; cannot force enable HPET\n");
}
else
{
} else {
val = REG32(rcba, 0x3404);
if (val & 0x80)
{
if (val & 0x80) {
// HPET is enabled in HPTC. Just not reported by BIOS
DBG(" HPET is enabled in HPTC, just not reported by BIOS\n");
hpet_address |= (val & 3) << 12 ;
DBG(" HPET MMIO @ 0x%lx\n", hpet_address);
}
else
{
} else {
// HPET disabled in HPTC. Trying to enable
DBG(" HPET is disabled in HPTC, trying to enable\n");
REG32(rcba, 0x3404) = val | 0x80;
// verify if the job is done
val = REG32(rcba, 0x3404);
if (!(val & 0x80))
{
if (!(val & 0x80)) {
printf(" Failed to force enable HPET\n");
}
}
}
}
void force_enable_hpet(pci_dt_t *lpc_dev)
{
switch(lpc_dev->vendor_id) {
case 0x8086:
force_enable_hpet_intel(lpc_dev);
break;
case 0x10de:
force_enable_hpet_nvidia(lpc_dev);
break;
case 0x1106:
force_enable_hpet_via(lpc_dev);
break;
}
#if DEBUG_HPET
printf("Press [Enter] to continue...\n");
getchar();
#endif
}
branches/ErmaC/Enoch/i386/libsaio/smbios.h
191191
192192
193193
194
194
195195
196196
197197
......
231231
232232
233233
234
235234
236235
237236
238
237
239238
240239
241240
......
265264
266265
267266
268
269
270
267
268
269
270
271271
272272
273273
SMBStringproduct;
SMBStringversion;
SMBStringserialNumber;
SMBStringassetTagNumber;
SMBStringassetTag;// Bungo: renamed from assetTagNumber folowing convention
SMBByte featureFlags;// Collection of flag that identify features of this baseboard
SMBStringlocationInChassis;
SMBWord chassisHandle;
{
SMB_STRUCT_HEADER // Type 3
SMBString manufacturer;
//SMBByte type;Bungo: renamed to chassisType - convention
SMBByte chassisType;// System Enclosure Indicator
SMBString version;// Board Number?
SMBString serialNumber;
SMBString assetTagNumber;
SMBString assetTag;// Bungo: renamed from assetTagNumber folowing convention
SMBByte bootupState;// State of enclosure when when it was last booted
SMBByte powerSupplyState;// State of enclosure's power supply when last booted
SMBByte thermalState;// Thermal state of the enclosure when last booted
kSMBchassisDockingStation = 0x0C,
kSMBchassisAllInOne = 0x0D,
kSMBchassisSubNotebook = 0x0E,
// ...
kSMBchassisLunchBox = 0x10
// fill up if needed ;-)
// ... fill up if needed ;-)
kSMBchassisLunchBox = 0x10,
// ... fill up if needed ;-)
kSMBchassisBladeEnclosing = 0x1D
};
/* ============================
branches/ErmaC/Enoch/i386/libsaio/biosfn.c
396396
397397
398398
399
400399
401400
402401
......
903902
904903
905904
906
907905
908906
909907
bb.eax.r.h = 0x00;
bios(&bb);
}
return bb.eax.r.h;
}
}
checked = true;
}
return (isEISA);
}
branches/ErmaC/Enoch/i386/libsaio/convert.c
104104
105105
106106
107
108
109
110
107
108
109
110
111
111112
112113
113114
{
binChar = 0;
for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++)
{
if (hexNibbleIdx > 0) binChar = binChar << 4;
for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) {
if (hexNibbleIdx > 0) {
binChar = binChar << 4;
}
if (hexByte[hexNibbleIdx] <= '9') binChar += hexByte[hexNibbleIdx] - '0';
else if (hexByte[hexNibbleIdx] <= 'F') binChar += hexByte[hexNibbleIdx] - ('A' - 10);
else if (hexByte[hexNibbleIdx] <= 'f') binChar += hexByte[hexNibbleIdx] - ('a' - 10);
branches/ErmaC/Enoch/i386/libsaio/pci.h
3030
3131
3232
33
33
3434
3535
3636
......
7171
7272
7373
74
75
76
77
78
79
74
75
76
77
78
79
8080
81
82
81
82
83
84
85
86
87
88
89
90
8391
8492
8593
......
97105
98106
99107
108
109
100110
101111
102112
......
116126
117127
118128
119
120
121
122
123
124
125
126
127
128
129
130
131129
132130
133131
} pci_dev_t;
typedef struct pci_dt_t {
uint8_t* regs;
uint8_t*regs;
pci_dev_tdev;
uint16_tdevfn; /* encoded device & function index */
extern uint8_tpci_config_read8(uint32_t, uint8_t);
extern uint16_tpci_config_read16(uint32_t, uint8_t);
extern uint32_tpci_config_read32(uint32_t, uint8_t);
extern voidpci_config_write8(uint32_t, uint8_t, uint8_t);
extern voidpci_config_write16(uint32_t, uint8_t, uint16_t);
extern voidpci_config_write32(uint32_t, uint8_t, uint32_t);
extern char*get_pci_dev_path(pci_dt_t *);
extern voidbuild_pci_dt(void);
extern voiddump_pci_dt(pci_dt_t *);
extern voidpci_config_write8(uint32_t, uint8_t, uint8_t);
extern voidpci_config_write16(uint32_t, uint8_t, uint16_t);
extern voidpci_config_write32(uint32_t, uint8_t, uint32_t);
extern char*get_pci_dev_path(pci_dt_t *);
extern voidbuild_pci_dt(void);
extern voiddump_pci_dt(pci_dt_t *);
//-----------------------------------------------------------------------------
// added by iNDi
/* Option ROM header */
typedef struct {
uint16_tsignature; // 0xAA55
uint8_trom_size; //in 512 bytes blocks
uint8_tjump; //0xE9 for ATI and Intel, 0xEB for NVidia
uint32_tentry_point;
uint8_treserved[16];
uint16_tpci_header_offset; //@0x18
uint16_texpansion_header_offset;
} option_rom_header_t;
/* Option ROM PCI Data Structure */
typedef struct {
uint16_treserved;
} option_rom_pci_header_t;
//-----------------------------------------------------------------------------
// added by iNDi
typedef struct {
uint32_tsignature;// 0x24506E50 '$PnP'
uint16_tresource_vector;
} option_rom_pnp_header_t;
/* Option ROM header */
typedef struct {
uint16_tsignature; // 0xAA55
uint8_trom_size; //in 512 bytes blocks
uint8_tjump; //0xE9 for ATI and Intel, 0xEB for NVidia
uint8_tentry_point[4]; //offset to
uint8_treserved[16];
uint16_tpci_header_offset; //@0x18
uint16_texpansion_header_offset;
} option_rom_header_t;
/*
* Under PCI, each device has 256 bytes of configuration address space,
* of which the first 64 bytes are standardized as follows:
branches/ErmaC/Enoch/i386/libsaio/msdos.c
130130
131131
132132
133
133
134134
135135
136136
......
188188
189189
190190
191
192
193
191
194192
195193
196194
......
775773
776774
777775
778
776
779777
780778
781779
782780
783781
784782
785
786
783
787784
788785
789786
......
797794
798795
799796
800
801
797
802798
803799
804800
......
842838
843839
844840
845
846
841
847842
848843
849844
......
938933
939934
940935
941
942
936
943937
944938
945939
......
948942
949943
950944
951
945
952946
953947
954948
......
971965
972966
973967
974
975
976
968
977969
978970
979971
......
991983
992984
993985
994
995
986
996987
997988
998989
......
10131004
10141005
10151006
1016
1007
10171008
if (!memcmp((char *)((struct extboot *)bsp->bs50.bsExt)->exFileSysType, "FAT12 ", 8))
return 12;
}
return 0;
}
free (buf);
return -1;
}
if (OSSwapLittleToHostInt16(b50->bpbRootDirEnts) == 0)
{
/* It's FAT32 */
if (OSSwapLittleToHostInt16(b50->bpbRootDirEnts) == 0) { /* It's FAT32 */
if (memcmp(((struct extboot *)bsp->bs710.bsExt)->exFileSysType, "FAT32 ", 8))
{
free (buf);
char *ptr = (char *)base;
struct direntry *dirp;
uint64_t i;
char devStr[12];
char devStr[12];
if (MSDOSInitPartition (ih)<0)
return -1;
if (filePath[0] == '/')
filePath++;
buf = malloc(msdosclustersize);
if (!buf)
{
if (!buf) {
return -1;
}
dirp = getdirpfrompath (ih, filePath, buf);
if (msdosfatbits == 32)
cluster |= ((uint32_t)OSReadLittleInt16 ((dirp->deHighClust),0)) <<16;
size = (uint32_t)OSReadLittleInt32 ((dirp->deFileSize),0);
if (size<=offset)
{
if (size<=offset) {
free (buf);
return -1;
}
if (filePath[0] == '/')
filePath++;
buf = malloc(msdosclustersize);
if (!buf)
{
if (!buf) {
return -1;
}
dirp = getdirpfrompath (ih, filePath, buf);
initRoot (&st);
st.buf = malloc(msdosclustersize);
if (!st.buf)
{
if (!st.buf) {
return;
}
while ((dirp = getnextdirent (ih, vfatlabel, &st)))
labelfound = 1;
break;
}
free(st.buf);
if (vfatlabel[0] && labelfound)
union bootsector *bsp = (union bootsector *)buf;
Seek(ih, 0);
Read(ih, (long)buf, 512);
if (msdosfatbits == 32)
{
/* It's FAT32 */
if (msdosfatbits == 32) { /* It's FAT32 */
strncpy((char *)label, (char *)((struct extboot *)bsp->bs710.bsExt)->exVolumeLabel, LABEL_LENGTH);
}
else if (msdosfatbits == 16)
MSDOSGetUUID(CICell ih, char *uuidStr)
{
char *buf = malloc (512);
if (!buf)
{
if (!buf) {
return -1;
}
union bootsector *bsp = (union bootsector *)buf;
}
free (buf);
return 0;
}
branches/ErmaC/Enoch/i386/libsaio/md5c.c
151151
152152
153153
154
155
154
156155
157156
158157
......
162161
163162
164163
165
166
164
167165
168166
169167
170168
171
169
172170
173
171
174172
175
176
173
177174
175
178176
179177
180178
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
if ((context->count[0] += ((u_int32_t)inputLen << 3)) < ((u_int32_t)inputLen << 3))
{
if ((context->count[0] += ((u_int32_t)inputLen << 3)) < ((u_int32_t)inputLen << 3)) {
context->count[1]++;
}
/* Transform as many times as possible. */
if (inputLen >= partLen)
{
if (inputLen >= partLen) {
memcpy((void *)&context->buffer[index], (const void *)input,
partLen);
MD5Transform (context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
for (i = partLen; i + 63 < inputLen; i += 64) {
MD5Transform (context->state, &((const unsigned char *)input)[i]);
}
index = 0;
}
else
} else {
i = 0;
}
/* Buffer remaining input */
memcpy ((void *)&context->buffer[index], (const void *)&((const unsigned char*)input)[i],
branches/ErmaC/Enoch/i386/libsaio/fake_efi.c
7373
7474
7575
76
76
7777
7878
7979
......
628628
629629
630630
631
632
631
633632
634633
635634
636
637
638635
636
637
639638
640639
641640
*/
/* Identify ourselves as the EFI firmware vendor */
static EFI_CHAR16 const FIRMWARE_VENDOR[] = { 'E', 'n', 'o', 'c', 'h', '\0' };
static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'E','n','o','c','h', 0};
static EFI_UINT32 const FIRMWARE_REVISION = 132; /* FIXME: Find a constant for this. */
// Bungo
// Bungo
/* Export system-id. Can be disabled with SystemId=No in com.apple.Boot.plist
if ((ret=getSystemID()))
{
if ((ret=getSystemID())) {
DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) ret);
}
*/
DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, Platform.UUID);
//
DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32 *)Platform.UUID);
// Export SystemSerialNumber if present
if ((ret16=getSmbiosChar16("SMserial", &len)))
{
branches/ErmaC/Enoch/i386/libsaio/smbios_getters.c
2121
2222
2323
24
25
26
27
24
25
2826
2927
3028
......
5048
5149
5250
53
54
55
51
5652
5753
5854
......
7167
7268
7369
74
75
70
7671
7772
7873
......
10398
10499
105100
106
107
101
108102
109103
110104
111105
112106
113
107
114108
109
115110
116111
117112
......
120115
121116
122117
123
124
118
125119
126120
127121
......
143137
144138
145139
146
147
140
148141
149142
150143
......
157150
158151
159152
160
161
162
163
153
154
164155
165156
166157
......
168159
169160
170161
171
172
162
173163
174164
175165
......
186176
187177
188178
189
190
179
191180
192181
193182
......
197186
198187
199188
200
201
189
202190
203191
204
205
192
206193
207194
208195
209196
210197
211
212
198
213199
214200
215
216
201
217202
218203
219
220
204
221205
222206
223207
224208
225209
226
227
210
228211
229212
230
231
213
232214
233215
234
235
216
236217
237218
238
239
219
240220
241221
242222
243223
244224
245
246
225
247226
248227
249
250
228
251229
252230
253
254
231
255232
256233
257
258
234
259235
260236
261
262
237
263238
264239
265240
266241
267242
268243
269
270
244
271245
272246
273
274
247
275248
276249
277250
278251
279252
280253
281
282
254
283255
284256
285
286
257
287258
288259
289
290
260
291261
292262
293
294
263
295264
296265
297
298
266
299267
300268
301269
302270
303271
304
305
272
306273
307274
308
309
275
310276
311277
312
313
278
314279
315280
316
317
281
318282
319283
320284
321285
322
286
323287
324288
325289
......
327291
328292
329293
330
331
294
332295
333296
334
335
297
336298
337299
338
339
300
340301
341302
342
343
303
344304
345305
346306
......
371331
372332
373333
374
375
334
376335
377
378
336
379337
380338
381339
382340
383341
384
342
385343
386344
387345
......
399357
400358
401359
402
403
360
404361
405
406
362
407363
408364
409365
......
421377
422378
423379
424
425
380
426381
427
428
382
429383
430384
431385
432386
433387
434388
435
436
389
437390
438391
439392
......
449402
450403
451404
452
453
405
454406
455
456
407
457408
458409
459410
460411
461412
462413
463
464
414
465415
466416
467417
......
474424
475425
476426
477
478
427
479428
480
481
429
482430
483431
484432
485433
486434
487435
488
489
436
490437
491438
492439
bool getProcessorInformationExternalClock(returnType *value)
{
if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
{
switch (Platform.CPU.Family)
{
if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel
switch (Platform.CPU.Family) {
case 0x06:
{
switch (Platform.CPU.Model)
default:
value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000);
}
}
else
{
} else {
value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000);
}
switch (Platform.CPU.Family) {
case 0x06:
{
switch (Platform.CPU.Model)
{
switch (Platform.CPU.Model) {
case CPU_MODEL_PENTIUM_M:
case CPU_MODEL_DOTHAN:// Intel Pentium M
case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
// 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), 0x00);
did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02);
vid &= 0xFFFF;
did &= 0xFF00;
if(vid == 0x8086 && did >= 0x2C00)
if(vid == 0x8086 && did >= 0x2C00) {
nhm_bus = possible_nhm_bus[i];
}
}
unsigned long qpimult, qpibusspeed;
DBG("qpimult %d\n", qpimult);
qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000));
// Rek: rounding decimals to match original mac profile info
if (qpibusspeed%100 != 0)
{
if (qpibusspeed%100 != 0) {
qpibusspeed = ((qpibusspeed+50)/100)*100;
}
DBG("qpibusspeed %d\n", qpibusspeed);
{
if (Platform.CPU.NoCores >= 4) {
return 0x0501;// Quad-Core Xeon
}
else if (Platform.CPU.NoCores == 1) {
} else if (Platform.CPU.NoCores == 1) {
return 0x0201;// Core Solo
};
value->word = simpleGetSMBOemProcessorType();
if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
{
if (!done)
{
if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel
if (!done) {
verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, (uint32_t)Platform.CPU.Family, (uint32_t)Platform.CPU.Model);
done = true;
}
switch (Platform.CPU.Family) {
case 0x06:
{
switch (Platform.CPU.Model)
{
switch (Platform.CPU.Model) {
case CPU_MODEL_DOTHAN:// 0x0D - Intel Pentium M model D
value->word = 0x101;
case CPU_MODEL_MEROM:// 0x0F - Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
case CPU_MODEL_PENRYN:// 0x17 - Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
{
if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
value->word = 0x402;// Xeon
}
case CPU_MODEL_PENTIUM_M:// 0x09 - Banias
case CPU_MODEL_NEHALEM_EX:// 0x2E - Nehalem-ex, "Beckton", 45nm
case CPU_MODEL_NEHALEM:// 0x1A - Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
{
if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
value->word = 0x501;// Xeon
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
value->word = 0x701;// Core i7
}
return true;
case CPU_MODEL_FIELDS:// 0x1E - Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
{
if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
value->word = 0x501;// Lynnfiled Quad-Core Xeon
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
value->word = 0x701;// Core i7
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
value->word = 0x601;// Core i5
}
return true;
case CPU_MODEL_DALES:// 0x1F - Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale)
if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
value->word = 0x901;// Core i3
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
value->word = 0x602;// Core i5
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
value->word = 0x702;// Core i7
}
if (Platform.CPU.NoCores <= 2)
{
if (Platform.CPU.NoCores <= 2) {
value->word = 0x602;// Core i5
}
return true;
case CPU_MODEL_DALES_32NM:// 0x25 - Intel Core i3, i5 LGA1156 (32nm) (Clarkdale, Arrandale)
if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
value->word = 0x901;// Core i3
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
value->word = 0x601;// Core i5
}
if(strstr(Platform.CPU.BrandString, "Core(TM) i5 CPU M 540"))
{
if(strstr(Platform.CPU.BrandString, "Core(TM) i5 CPU M 540")) {
value->word = 0x602;// Core i5
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
value->word = 0x701;// Core i7
}
if (Platform.CPU.NoCores <= 2)
{
if (Platform.CPU.NoCores <= 2) {
value->word = 0x602;// Core i5
}
return true;
case CPU_MODEL_WESTMERE:// 0x2C - Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
case CPU_MODEL_WESTMERE_EX:// 0x2F - Intel Xeon E7
if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
{
if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
value->word = 0x501;// Xeon
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
value->word = 0x701;// Core i7
}
return true;
case CPU_MODEL_JAKETOWN:// 0x2D - Intel Core i7, Xeon E5-xxxx LGA2011 (32nm)
case CPU_MODEL_SANDYBRIDGE:// 0x2A - Intel Core i3, i5, i7 LGA1155 (32nm)
if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
{
if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
value->word = 0x501;// Xeon
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
value->word = 0x903;// Core i3
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
value->word = 0x603;// Core i5
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
value->word = 0x703;// Core i7
}
if (Platform.CPU.NoCores <= 2)
{
if (Platform.CPU.NoCores <= 2) {
value->word = 0x603;// Core i5
}
return true;
case CPU_MODEL_IVYBRIDGE:// 0x3A - Intel Core i3, i5, i7 LGA1155 (22nm)
if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
value->word = 0x903;// Core i3 - Apple doesn't use it
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
value->word = 0x604;// Core i5
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
value->word = 0x704;// Core i7
}
if (Platform.CPU.NoCores <= 2)
{
if (Platform.CPU.NoCores <= 2) {
value->word = 0x604;// Core i5
}
return true;
case CPU_MODEL_IVYBRIDGE_XEON:// 0x3E -
case CPU_MODEL_IVYBRIDGE_XEON:// 0x3E - Mac Pro 6,1 - shouldn't be Sandy Bridge EP refering to intel spec.?
value->word = 0xA01;
return true;
case CPU_MODEL_HASWELL_MB:// 0x3F -
case CPU_MODEL_HASWELL_ULT:// 0x45 -
case CPU_MODEL_CRYSTALWELL:// 0x46
if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
value->word = 0x905;// Core i3 - Apple doesn't use it
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
value->word = 0x605;// Core i5
}
if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
{
if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
value->word = 0x705;// Core i7
}
if (Platform.CPU.NoCores <= 2)
{
if (Platform.CPU.NoCores <= 2) {
value->word = 0x605;// Core i5
}
return true;
intmap;
idx++;
if (idx < MAX_RAM_SLOTS)
{
if (idx < MAX_RAM_SLOTS) {
map = Platform.DMI.DIMM[idx];
if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
{
if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) {
DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
value->byte = Platform.RAM.DIMM[map].Type;
return true;
}
}
return false;
//value->byte = SMB_MEM_TYPE_DDR2;
//return true;
intmap;
idx++;
if (idx < MAX_RAM_SLOTS)
{
if (idx < MAX_RAM_SLOTS) {
map = Platform.DMI.DIMM[idx];
if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
{
if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0) {
DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
value->dword = Platform.RAM.DIMM[map].Frequency;
return true;
intmap;
idx++;
if (idx < MAX_RAM_SLOTS)
{
if (idx < MAX_RAM_SLOTS) {
map = Platform.DMI.DIMM[idx];
if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0)
{
if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0) {
DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
value->string = Platform.RAM.DIMM[map].Vendor;
return true;
}
}
if (!bootInfo->memDetect)
{
if (!bootInfo->memDetect) {
return false;
}
value->string = NOT_AVAILABLE;
DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
if (idx < MAX_RAM_SLOTS)
{
if (idx < MAX_RAM_SLOTS) {
map = Platform.DMI.DIMM[idx];
if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
{
if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) {
DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
value->string = Platform.RAM.DIMM[map].SerialNo;
return true;
}
}
if (!bootInfo->memDetect)
{
if (!bootInfo->memDetect) {
return false;
}
value->string = NOT_AVAILABLE;
intmap;
idx++;
if (idx < MAX_RAM_SLOTS)
{
if (idx < MAX_RAM_SLOTS) {
map = Platform.DMI.DIMM[idx];
if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
{
if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) {
DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
value->string = Platform.RAM.DIMM[map].PartNo;
return true;
}
}
if (!bootInfo->memDetect)
{
if (!bootInfo->memDetect) {
return false;
}
value->string = NOT_AVAILABLE;
branches/ErmaC/Enoch/i386/include/string.h
108108
109109
110110
111
111112
112113
113114
int strncmp(const char *, const char *, size_t);
char*strncpy(char *, const char *, size_t);
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
char*stpncpy(char *, const char *, size_t);
char*strnstr(const char *, const char *, size_t);
#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
char*strpbrk(const char *, const char *);
branches/ErmaC/Enoch/i386/boot2/graphics.c
107107
108108
109109
110
111
112
113
114
115
110
111
112
113
114
115
116116
117117
118
119
120
121
118
119
120
121
122
122123
123
124
124125
125
126
127
128
126
127
128
129
129130
130131
131132
void
printVBEModeInfo()
{
VBEInfoBlock vbeInfo;
unsigned short * modePtr;
VBEModeInfoBlock modeInfo;
int err;
int line;
char* vbeInfoString = NULL;
VBEInfoBlock vbeInfo;
unsigned short * modePtr;
VBEModeInfoBlock modeInfo;
int err;
int line;
char* vbeInfoString = NULL;
bzero( &vbeInfo, sizeof(vbeInfo) );
strcpy( (char*)&vbeInfo, "VBE2" );
err = getVBEInfo( &vbeInfo );
if ( err != errSuccess )
return;
strcpy( (char*)&vbeInfo, "VBE2" );
err = getVBEInfo( &vbeInfo );
if ( err != errSuccess ) {
return;
}
line = 0;
line = 0;
// Activate and clear page 1
setActiveDisplayPage(1);
clearScreenRows(0, 24);
setCursorPosition( 0, 0, 1 );
// Activate and clear page 1
setActiveDisplayPage(1);
clearScreenRows(0, 24);
setCursorPosition( 0, 0, 1 );
vbeInfoString = getVBEInfoString();
if (!vbeInfoString) {
branches/ErmaC/Enoch/i386/boot2/drivers.c
703703
704704
705705
706
707
706
708707
709708
710709
711
712
713
714
710
711
715712
716713
717
718
714
719715
720716
721
722
717
723718
724719
725
726
720
727721
728722
729
730
731
732
723
724
733725
734726
735727
......
763755
764756
765757
766
767
758
768759
769760
770761
......
814805
815806
816807
817
818
808
819809
820810
821811
......
863853
864854
865855
866
867
868
869
856
857
870858
871859
872860
873861
874
875
862
876863
877864
878
879
865
880866
881867
882868
......
892878
893879
894880
895
896
881
897882
898883
899884
900885
901886
902887
903
904
888
905889
906890
907891
......
910894
911895
912896
913
914
897
915898
916899
917900
ModulePtr module, module2;
long done;
do
{
do {
done = 1;
module = gModuleHead;
while (module != 0)
{
if (module->willLoad == 1)
{
while (module != 0) {
if (module->willLoad == 1) {
prop = XMLGetProperty(module->dict, kPropOSBundleLibraries);
if (prop != 0)
{
if (prop != 0) {
prop = prop->tag;
while (prop != 0)
{
while (prop != 0) {
module2 = gModuleHead;
while (module2 != 0)
{
while (module2 != 0) {
prop2 = XMLGetProperty(module2->dict, kPropCFBundleIdentifier);
if ((prop2 != 0) && (!strcmp(prop->string, prop2->string)))
{
if (module2->willLoad == 0)
{
if ((prop2 != 0) && (!strcmp(prop->string, prop2->string))) {
if (module2->willLoad == 0) {
module2->willLoad = 1;
}
break;
module = gModuleHead;
while (module != 0)
{
while (module != 0) {
prop = GetProperty(module->dict, kPropCFBundleIdentifier);
if ((prop != 0) && !strcmp(name, prop->string)) {
required = XMLGetProperty(moduleDict, kPropOSBundleRequired);
if ( (required == 0) || (required->type != kTagTypeString) || !strcmp(required->string, "Safe Boot"))
{
if ( (required == 0) || (required->type != kTagTypeString) || !strcmp(required->string, "Safe Boot")) {
XMLFreeTag(moduleDict);
return -2;
}
getchar();
#endif
if (kernel_header->signature == OSSwapBigToHostConstInt32('comp'))
{
if (kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss'))
{
if (kernel_header->signature == OSSwapBigToHostConstInt32('comp')) {
if (kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss')) {
error("kernel compression is bad\n");
return -1;
}
#if NOTDEF
if (kernel_header->platform_name[0] && strcmp(gPlatformName, kernel_header->platform_name))
{
if (kernel_header->platform_name[0] && strcmp(gPlatformName, kernel_header->platform_name)) {
return -1;
}
if (kernel_header->root_path[0] && strcmp(gBootFile, kernel_header->root_path))
{
if (kernel_header->root_path[0] && strcmp(gBootFile, kernel_header->root_path)) {
return -1;
}
#endif
}
if (OSSwapBigToHostInt32(kernel_header->adler32) !=
Adler32(binary, uncompressed_size))
{
Adler32(binary, uncompressed_size)) {
printf("adler mismatch\n");
return -1;
}
}
ret = ThinFatFile(&binary, &len);
if (ret == 0 && len == 0 && archCpuType==CPU_TYPE_X86_64)
{
if (ret == 0 && len == 0 && archCpuType==CPU_TYPE_X86_64) {
archCpuType=CPU_TYPE_I386;
ret = ThinFatFile(&binary, &len);
}
execute_hook("DecodeKernel", (void*)binary, NULL, NULL, NULL);
ret = DecodeMachO(binary, rentry, raddr, rsize);
if (ret<0 && archCpuType==CPU_TYPE_X86_64)
{
if (ret<0 && archCpuType==CPU_TYPE_X86_64) {
archCpuType=CPU_TYPE_I386;
ret = DecodeMachO(binary, rentry, raddr, rsize);
}
branches/ErmaC/Enoch/i386/boot2/resume.c
2828
2929
3030
31
32
33
34
31
32
3533
3634
3735
......
6967
7068
7169
72
73
70
7471
7572
7673
// Activate and clear page 1
line = 1;
for (i = 0; i < bootInfo->memoryMapCount; i++)
{
if((mp->type == 1) && ((unsigned long)mp->base == 0x100000))
{
for (i = 0; i < bootInfo->memoryMapCount; i++) {
if((mp->type == 1) && ((unsigned long)mp->base == 0x100000)) {
return (unsigned long)(mp->base + mp->length);
}
mp++;
lowHalf = 1;
highHalf = 0;
for (cnt = 0; cnt < compressedSize; cnt += 0x20)
{
for (cnt = 0; cnt < compressedSize; cnt += 0x20) {
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
branches/ErmaC/Enoch/i386/boot2/boot.c
271271
272272
273273
274
275
276
277
278
279
280
281
282
283
284
285
286
274
287275
288276
289277
snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32);
}
}
/* Issue: http://forge.voodooprojects.org/p/chameleon/issues/270/
// kernelCacheFile must start with a /
if (kernelCacheFile[0] != '/')
{
char *str = strdup(kernelCacheFile);
if (str == NULL)
{
return -1;
}
sprintf(kernelCacheFile, "/%s", str);
free(str);
}
*/
// Check if the kernel cache file exists
ret = -1;
branches/ErmaC/Enoch/i386/boot2/boot.h
179179
180180
181181
182
183182
184183
185184
......
188187
189188
190189
190
191
192
193
191194
192195
193196
#define kHDAEnabler"HDAEnabler"/* pci_setup.c */
#define kHDEFLayoutID"HDEFLayoutID"/* hda.c */
#define kHDAULayoutID"HDAULayoutID"/* hda.c */
//#define kHDAPinConf"HDEFPinConfiguration"/* hda.c */
#define kBGRT"BGRT"/* acpi_patcher.c */
#define kDropBGRT"DropBGRT"/* acpi_patcher.c */
#define kDropMCFG"DropMCFG"/* acpi_patcher.c */
/* Karas: added these keys */
#define kMemFullInfo"ForceFullMemInfo"/* smbios.c */
/* Bungo: added these keys */
// mask private data or no
#define kPrivateData"PrivateData"/* smbios_decode.c */
/*
* Flags to the booter or kernel
*/
branches/ErmaC/Enoch/i386/boot2/modules.h
9898
9999
100100
101
102101
103102
104103
voidbind_macho(void* base, UInt8* bind_stream, UInt32 size);
/********************************************************************************/
/*Module Interface*/
/********************************************************************************/
branches/ErmaC/Enoch/i386/boot2/gui.c
256256
257257
258258
259
260
261
262
259
260
263261
264262
265263
......
279277
280278
281279
282
283
284
285
280
281
286282
287
288
289
283
290284
291285
292286
293287
294
295
296
297
288
289
298290
299
300
301
291
302292
303293
304294
......
517507
518508
519509
520
521
522
523
510
511
524512
525513
526514
......
530518
531519
532520
533
534
521
535522
536523
537524
538
539
525
540526
541527
542528
......
551537
552538
553539
554
555
540
556541
557542
558543
559544
560
561
545
562546
563547
564548
......
10781062
10791063
10801064
1081
1082
1065
10831066
10841067
10851068
......
11061089
11071090
11081091
1109
1110
1092
11111093
11121094
11131095
1114
1115
1116
1117
1096
1097
11181098
1119
1120
1121
1099
11221100
1123
1124
1101
11251102
11261103
11271104
11281105
1129
1130
1106
11311107
11321108
11331109
11341110
1135
1136
1111
11371112
11381113
11391114
......
11561131
11571132
11581133
1159
1160
1134
11611135
11621136
1163
1164
1137
11651138
11661139
11671140
11681141
11691142
1170
1171
1143
11721144
11731145
11741146
1175
1176
1147
11771148
11781149
11791150
......
11891160
11901161
11911162
1192
1193
1163
11941164
11951165
11961166
......
12281198
12291199
12301200
1231
1232
1201
12331202
1234
1235
1236
1203
12371204
12381205
1239
1240
1241
1242
1206
1207
12431208
12441209
12451210
1246
1247
1211
12481212
12491213
12501214
......
12671231
12681232
12691233
1270
1271
1272
1273
1234
1235
12741236
12751237
1276
1277
1238
12781239
12791240
1280
1281
1241
12821242
12831243
1284
1285
1244
12861245
12871246
12881247
12891248
12901249
12911250
1292
1293
1251
12941252
12951253
12961254
......
13051263
13061264
13071265
1308
1309
1310
1311
1266
1267
13121268
13131269
13141270
......
13491305
13501306
13511307
1352
1353
1308
13541309
13551310
13561311
13571312
13581313
1359
1360
1314
13611315
13621316
13631317
1364
1365
1318
13661319
13671320
13681321
13691322
13701323
13711324
1372
1373
1325
13741326
13751327
13761328
......
13821334
13831335
13841336
1385
1386
1337
13871338
13881339
13891340
......
14001351
14011352
14021353
1403
14041354
14051355
14061356
......
14391389
14401390
14411391
1442
1443
1392
14441393
14451394
14461395
14471396
14481397
1449
1450
1398
14511399
14521400
14531401
1454
1455
1402
14561403
14571404
14581405
14591406
14601407
14611408
1462
1463
1409
14641410
14651411
14661412
1467
1468
1413
14691414
14701415
14711416
14721417
14731418
1474
1475
1419
14761420
14771421
14781422
14791423
14801424
1481
1482
1425
14831426
14841427
14851428
......
15201463
15211464
15221465
1523
1524
1466
15251467
15261468
15271469
15281470
1529
1530
1471
15311472
15321473
1533
1534
1474
15351475
15361476
15371477
......
15411481
15421482
15431483
1544
1545
1484
15461485
15471486
15481487
15491488
15501489
15511490
1552
1553
1491
15541492
15551493
15561494
15571495
15581496
1559
1560
1497
15611498
15621499
15631500
15641501
15651502
1566
1567
1503
15681504
15691505
15701506
......
15791515
15801516
15811517
1582
1583
1518
15841519
15851520
15861521
......
15891524
15901525
15911526
1592
1593
1527
15941528
15951529
1596
1597
1598
1530
15991531
16001532
16011533
......
16051537
16061538
16071539
1608
1609
1540
16101541
1611
1612
1542
16131543
16141544
16151545
16161546
16171547
16181548
1619
1620
1549
16211550
16221551
16231552
......
16351564
16361565
16371566
1638
1639
1567
16401568
16411569
1642
1643
1644
1570
16451571
1646
1647
1648
1572
16491573
1650
1651
1574
16521575
16531576
16541577
1655
1656
1578
16571579
16581580
16591581
......
16671589
16681590
16691591
1670
1671
1672
1673
1674
1675
1592
1593
1594
16761595
16771596
16781597
......
16921611
16931612
16941613
1695
1696
1614
16971615
16981616
16991617
1700
1701
1618
17021619
17031620
1704
1705
1621
17061622
17071623
17081624
1709
1710
1625
17111626
17121627
1713
1714
1715
1716
1628
1629
17171630
17181631
17191632
17201633
17211634
1722
1723
1635
17241636
17251637
17261638
......
17321644
17331645
17341646
1735
1736
1647
17371648
17381649
17391650
1740
1741
1651
17421652
17431653
17441654
......
17491659
17501660
17511661
1752
1753
1662
17541663
17551664
17561665
......
17581667
17591668
17601669
1761
1762
1670
17631671
17641672
1765
1766
1767
1768
1673
1674
17691675
1770
1771
1676
17721677
17731678
17741679
......
18011706
18021707
18031708
1804
1805
1806
1807
1709
1710
18081711
1809
1810
1712
18111713
18121714
18131715
......
18451747
18461748
18471749
1848
1849
1850
1851
1750
1751
18521752
18531753
18541754
......
18681768
18691769
18701770
1871
1872
1771
18731772
1874
1875
1876
1877
1773
1774
18781775
18791776
1880
1881
1777
18821778
18831779
18841780
18851781
18861782
1887
1888
1889
1890
1783
1784
18911785
18921786
1893
1894
1787
18951788
18961789
18971790
......
19021795
19031796
19041797
1905
1906
1798
19071799
19081800
19091801
19101802
19111803
19121804
1913
1914
1805
19151806
19161807
19171808
19181809
19191810
1920
1921
1811
19221812
19231813
19241814
19251815
1926
1927
1816
19281817
19291818
19301819
......
19371826
19381827
19391828
1940
1941
1942
1943
1829
1830
19441831
19451832
19461833
19471834
1948
1949
1950
1951
1835
1836
19521837
19531838
19541839
19551840
1956
1957
1841
19581842
19591843
19601844
19611845
19621846
19631847
1964
1965
1966
1967
1848
1849
19681850
19691851
1970
1971
1852
19721853
19731854
19741855
......
19801861
19811862
19821863
1983
1984
1864
19851865
19861866
19871867
......
19901870
19911871
19921872
1993
1994
1873
19951874
19961875
19971876
......
20251904
20261905
20271906
2028
2029
2030
2031
2032
2033
1907
1908
1909
20341910
20351911
20361912
......
20381914
20391915
20401916
2041
2042
2043
2044
2045
2046
1917
1918
1919
20471920
20481921
20491922
20501923
2051
2052
1924
20531925
20541926
20551927
2056
2057
1928
20581929
20591930
20601931
......
20841955
20851956
20861957
2087
2088
2089
2090
1958
1959
20911960
20921961
20931962
20941963
2095
2096
1964
20971965
20981966
2099
2100
2101
1967
21021968
21031969
21041970
......
21301996
21311997
21321998
2133
2134
2135
2136
1999
2000
21372001
2138
2139
2140
2002
21412003
21422004
21432005
21442006
21452007
2146
2147
2148
2008
21492009
21502010
21512011
......
21572017
21582018
21592019
2160
2161
2020
21622021
21632022
21642023
2165
2166
2167
2024
21682025
21692026
21702027
......
21742031
21752032
21762033
2177
2178
2034
21792035
2180
2181
2182
2036
21832037
2184
2185
2186
2038
21872039
2188
2189
2190
2040
21912041
21922042
21932043
......
22652115
22662116
22672117
2268
2269
2118
22702119
22712120
22722121
static int getImageIndexByName(const char *name)
{
int i;
for (i = 0; i < sizeof(images) / sizeof(images[0]); i++)
{
if (strcmp(name, images[i].name) == 0)
{
for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) {
if (strcmp(name, images[i].name) == 0) {
return i; // found the name
}
}
// generated manualy, this *will* fail to work properly.
while((result = strcmp(name, embeddedImages[compareIndex].name)) != 0)
{
if (result > 0)// We need to search a HIGHER index
{
if (compareIndex != lowerLimit)
{
if (result > 0){ // We need to search a HIGHER index
if (compareIndex != lowerLimit) {
lowerLimit = compareIndex;
}
else
{
} else {
return -1;
}
compareIndex = (upperLimit + lowerLimit + 1) >> 1;// Midpoint, round up
}
else // We Need to search a LOWER index
{
if (compareIndex != upperLimit)
{
else { // We Need to search a LOWER index
if (compareIndex != upperLimit) {
upperLimit = compareIndex;
}
else
{
} else {
return -1;
}
compareIndex = (upperLimit + lowerLimit) >> 1;// Midpoint, round down
int destx = 0, desty = 0;
int srcx = pos.x, srcy = pos.y;
for( ; desty < height; desty++, srcy++)
{
for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ )
{
for( ; desty < height; desty++, srcy++) {
for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ ) {
pixel( cropped, destx, desty ).value = pixel( from, srcx, srcy ).value;
}
}
int createBackBuffer( window_t *window )
{
gui.backbuffer = malloc(sizeof(pixmap_t));
if(!gui.backbuffer)
{
if(!gui.backbuffer) {
return 1;
}
gui.backbuffer->pixels = malloc( window->width * window->height * 4 );
if(!gui.backbuffer->pixels)
{
if(!gui.backbuffer->pixels) {
free(gui.backbuffer);
gui.backbuffer = 0;
return 1;
int createWindowBuffer( window_t *window )
{
window->pixmap = malloc(sizeof(pixmap_t));
if(!window->pixmap)
{
if(!window->pixmap) {
return 1;
}
window->pixmap->pixels = malloc( window->width * window->height * 4 );
if(!window->pixmap->pixels)
{
if(!window->pixmap->pixels) {
free(window->pixmap);
window->pixmap = 0;
return 1;
makeRoundedCorners( gui.devicelist.pixmap);
switch (gui.layout)
{
switch (gui.layout) {
case VerticalLayout:
p.x = (gui.devicelist.width /2);
}
// draw visible device icons
for (i = 0; i < gui.maxdevices; i++)
{
for (i = 0; i < gui.maxdevices; i++) {
BVRef param = menuItems[start + i].param;
bool isSelected = ((start + i) == selection) ? true : false;
if (isSelected)
{
if (param->flags & kBVFlagNativeBoot)
{
if (isSelected) {
if (param->flags & kBVFlagNativeBoot) {
infoMenuNativeBoot = true;
}
else
{
} else {
infoMenuNativeBoot = false;
if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
{
if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) {
infoMenuSelection = 0;
}
}
if (gui.menu.draw)
{
if (gui.menu.draw) {
drawInfoMenuItems();
}
getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig);
if (shoWinfo && showBootBanner)
{
if (shoWinfo && showBootBanner) {
gui.debug.cursor = pos( 10, 100);
dprintf( &gui.screen, "label: %s\n", param->label );
dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );
drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
if (gui.layout == HorizontalLayout)
{
if (gui.layout == HorizontalLayout) {
p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
}
if (gui.layout == VerticalLayout)
{
if (gui.layout == VerticalLayout) {
p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
}
}
// draw prev indicator
if (start)
{
if (start) {
blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
}
// draw next indicator
if ( end < gDeviceCount - 1 )
{
if ( end < gDeviceCount - 1 ) {
blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
}
gui.redraw = true;
//prompt_pos=0;
if( gui.bootprompt.draw == true )
{
if( gui.bootprompt.draw == true ) {
gui.bootprompt.draw = false;
gui.redraw = true;
// this causes extra frames to be drawn
static inline
void vramwrite (void *data, int width, int height)
{
if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
{
if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) {
memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
}
else
{
} else {
uint32_t r, g, b;
int i, j;
for (i = 0; i < VIDEO (height); i++)
{
for (j = 0; j < VIDEO (width); j++)
{
for (i = 0; i < VIDEO (height); i++) {
for (j = 0; j < VIDEO (width); j++) {
b = ((uint8_t *) data)[4*i*width + 4*j];
g = ((uint8_t *) data)[4*i*width + 4*j + 1];
r = ((uint8_t *) data)[4*i*width + 4*j + 2];
switch (VIDEO (depth))
{
switch (VIDEO (depth)) {
case 32:
*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
break;
void updateVRAM()
{
if (gui.redraw)
{
if (gui.devicelist.draw)
{
if (gui.redraw) {
if (gui.devicelist.draw) {
blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
}
if (gui.bootprompt.draw)
{
if (gui.bootprompt.draw) {
blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
}
if (gui.menu.draw)
{
if (gui.menu.draw) {
blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
}
if (gui.infobox.draw)
{
if (gui.infobox.draw) {
blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
}
}
vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
if (gui.redraw)
{
if (gui.redraw) {
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
gui.redraw = false;
}
static int
sputc(int c, struct putc_info * pi) //Azi: same as above
{
if (pi->last_str)
{
if (pi->str == pi->last_str)
{
if (pi->last_str) {
if (pi->str == pi->last_str) {
*(pi->str) = '\0';
return 0;
}
font_t *font = &font_console;
for( i=0; i< strlen(formattedtext); i++ )
{
for( i=0; i< strlen(formattedtext); i++ ) {
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' )
{
if( formattedtext[i] == '\n' ) {
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y )
{
if ( cursor.y > bounds.y ) {
cursor.y = origin.y;
}
continue;
}
// tab ?
if( formattedtext[i] == '\t' )
{
if( formattedtext[i] == '\t' ) {
cursor.x += ( font->chars[0]->width * 5 );
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x )
{
if ( cursor.x > bounds.x ) {
cursor.x = origin.x;
cursor.y += font->height;
}
free(formattedtext);
return 0;
}
return 1;
}
font_t *font = &font_console;
for( i=0; i< strlen(formattedtext); i++ )
{
for( i=0; i< strlen(formattedtext); i++ ) {
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' )
{
if( formattedtext[i] == '\n' ) {
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y )
{
if ( cursor.y > bounds.y ) {
cursor.y = origin.y;
}
continue;
}
// tab ?
if( formattedtext[i] == '\t' )
{
if( formattedtext[i] == '\t' ) {
cursor.x += ( font->chars[0]->width * 5 );
}
// draw the character
if( font->chars[character])
{
if( font->chars[character]) {
blend(font->chars[character], gui.backbuffer, cursor);
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x )
{
if ( cursor.x > bounds.x ) {
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > bounds.y )
{
if ( cursor.y > bounds.y ) {
cursor.y = origin.y;
}
}
bounds.y = ( window->height - ( window->vborder * 2 ) );
cursor = origin;
for( i=0; i< strlen(formattedtext); i++ )
{
for( i=0; i< strlen(formattedtext); i++ ) {
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' )
{
if( formattedtext[i] == '\n' ) {
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y )
{
if ( cursor.y > bounds.y ) {
gui.redraw = true;
updateVRAM();
cursor.y = window->vborder;
}
// tab ?
if( formattedtext[i] == '\t' )
{
if( formattedtext[i] == '\t' ) {
cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
continue;
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x )
{
if ( cursor.x > bounds.x ) {
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > ( bounds.y + font->chars[0]->height) )
{
if ( cursor.y > ( bounds.y + font->chars[0]->height) ) {
gui.redraw = true;
updateVRAM();
cursor.y = window->vborder;
}
// draw the character
if( font->chars[character])
{
if( font->chars[character]) {
blend(font->chars[character], gui.backbuffer, cursor);
}
}
pixmap_t* charToPixmap(unsigned char ch, font_t *font) {
unsigned int cha = (unsigned int)ch - 32;
if (cha >= font->count)
{
if (cha >= font->count) {
// return ? if the font for the char doesn't exists
cha = '?' - 32;
}
position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {
pixmap_t* pm = charToPixmap(ch, font);
if (pm && ((p.x + pm->width) < blendInto->width))
{
if (pm && ((p.x + pm->width) < blendInto->width)) {
blend(pm, blendInto, p);
return pos(p.x + pm->width, p.y);
}
else
{
} else {
return p;
}
}
int i=0;
position_t current_pos = pos(p.x, p.y);
for (i=0; i < strlen(ch); i++)
{
for (i=0; i < strlen(ch); i++) {
// newline ?
if ( ch[i] == '\n' )
{
if ( ch[i] == '\n' ) {
current_pos.x = p.x;
current_pos.y += font->height;
continue;
}
// tab ?
if ( ch[i] == '\t' )
{
if ( ch[i] == '\t' ) {
current_pos.x += TAB_PIXELS_WIDTH;
continue;
}
// calculate the width in pixels
for (i=0; i < strlen(text); i++) {
if (text[i] == '\n')
{
if (text[i] == '\n') {
width = 0;
height += font->height;
}
else if (text[i] == '\t')
{
} else if (text[i] == '\t') {
width += TAB_PIXELS_WIDTH;
}
else
{
} else {
pixmap_t* pm = charToPixmap(text[i], font);
if (pm)
{
if (pm){
width += pm->width;
}
}
if (width > max_width)
{
if (width > max_width) {
max_width = width;
}
}
int destroyFont(font_t *font)
{
int i;
for (i = 0; i < CHARACTERS_COUNT; i++)
{
if (font->chars[i])
{
if (font->chars[i]->pixels)
{
for (i = 0; i < CHARACTERS_COUNT; i++) {
if (font->chars[i]) {
if (font->chars[i]->pixels) {
free (font->chars[i]->pixels);
}
free (font->chars[i]);
font->height = data->image->height;
for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)
{
for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) {
start = end;
// if the pixel is red we've reached the end of the char
if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
{
if( pixel( data->image, x, 0 ).value == 0xFFFF0000) {
end = x + 1;
if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
{
if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) {
font->chars[count]->width = ( end - start) - 1;
font->chars[count]->height = font->height;
if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
{
if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) {
space += ( font->chars[count]->width * data->image->height * 4 );
// we skip the first line because there are just the red pixels for the char width
for( y = 1; y< (font->height); y++)
{
for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
{
for( y = 1; y< (font->height); y++) {
for( x2 = start, x3 = 0; x2 < end; x2++, x3++) {
pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
}
}
// check if font is monospaced
if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
{
if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) {
monospaced = true;
}
}
}
for (x = count; x < CHARACTERS_COUNT; x++)
{
for (x = count; x < CHARACTERS_COUNT; x++) {
font->chars[x] = NULL;
}
if(monospaced)
{
if(monospaced) {
font->width = 0;
}
void colorFont(font_t *font, uint32_t color)
{
if( !color )
{
if( !color ) {
return;
}
int count = 0;
pixel_t *buff;
while( font->chars[count++] )
{
while( font->chars[count++] ) {
width = font->chars[count-1]->width;
height = font->chars[count-1]->height;
for( y = 0; y < height; y++ )
{
for( x = 0; x < width; x++ )
{
for( y = 0; y < height; y++ ) {
for( x = 0; x < width; x++ ) {
buff = &(pixel( font->chars[count-1], x, y ));
if( buff->ch.a )
{
if( buff->ch.a ) {
buff->ch.r = (color & 0xFFFF0000) >> 16;
buff->ch.g = (color & 0xFF00FF00) >> 8;
buff->ch.b = (color & 0xFF0000FF);
uint8_t alpha=0;
for( y=0; y<10; y++)
{
for( x=0; x<10; x++)
{
for( y=0; y<10; y++) {
for( x=0; x<10; x++) {
// skip if the pixel should be visible
if(roundedCorner[y][x] != 0xFF)
{
if(roundedCorner[y][x] != 0xFF){
alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
// Upper left corner
pixel(p, x, y).ch.a = alpha;
position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
// calculate number of lines in the title
for ( i = 0, lines = 1; i<strlen(title); i++ )
{
if( title[i] == '\n')
{
for ( i = 0, lines = 1; i<strlen(title); i++ ) {
if( title[i] == '\n') {
lines++;
}
}
visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
// lets display the text and allow scroll thru using up down / arrows
while(1)
{
while(1) {
// move to current line in text
for( offset = 0, i = 0; offset < strlen(text); offset++ )
{
if( currentline == i)
{
for( offset = 0, i = 0; offset < strlen(text); offset++ ) {
if( currentline == i) {
break;
}
if( text[offset] =='\n')
{
if( text[offset] =='\n') {
i++;
}
}
// find last visible line in text and place \0
for( i = offset, cnt = 0; i < strlen(text); i++)
{
if(text[i]=='\n')
{
for( i = offset, cnt = 0; i < strlen(text); i++) {
if(text[i]=='\n') {
cnt++;
}
if ( cnt == visiblelines )
{
if ( cnt == visiblelines ) {
text[i]='\0';
break;
}
makeRoundedCorners( gui.infobox.pixmap);
// print the title if present
if( title )
{
if( title ) {
drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
}
// print the text
drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
// restore \n in text
if ( cnt == visiblelines )
{
if ( cnt == visiblelines ) {
text[i] = '\n';
}
position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
// draw prev indicator
if(offset)
{
if(offset) {
blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
}
// draw next indicator
if( lines > ( currentline + visiblelines ) )
{
if( lines > ( currentline + visiblelines ) ) {
pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
}
key = getchar();
if( key == KEY_UP )
{
if( currentline > 0 )
{
if( key == KEY_UP ) {
if( currentline > 0 ) {
currentline--;
}
}
if( key == KEY_DOWN )
{
if( lines > ( currentline + visiblelines ) )
{
if( key == KEY_DOWN ) {
if( lines > ( currentline + visiblelines ) ) {
currentline++;
}
}
if( key == KEY_ESC || key == 'q' || key == 'Q')
{
if( key == KEY_ESC || key == 'q' || key == 'Q') {
gui.infobox.draw = false;
gui.redraw = true;
updateVRAM();
break;
}
if(key == ' ') // spacebar = next page
{
if( lines > ( currentline + visiblelines ) )
{
if(key == ' ') { // spacebar = next page
if( lines > ( currentline + visiblelines ) ) {
currentline += visiblelines;
}
if(lines < (currentline + visiblelines))
{
if(lines < (currentline + visiblelines)) {
currentline = lines - visiblelines;
}
}
{
int y;
if( time18() > lasttime)
{
if( time18() > lasttime) {
lasttime = time18();
pixmap_t *buffBar = images[iProgressBar].image;
memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
for( y = buffBar->height - 1; y > 0; y--)
{
for( y = buffBar->height - 1; y > 0; y--) {
pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
}
pixel(buffBar, buffBar->width-1, 0).value = buff;
int x=0,x2=0,y=0;
for(y=0; y<buff->height; y++)
{
for(x=0; x<todraw; x++, x2++)
{
if(x2 == (buff->width-1))
{
for(y=0; y<buff->height; y++) {
for(x=0; x<todraw; x++, x2++) {
if(x2 == (buff->width-1)) {
x2=0;
}
pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
x2=0;
}
for(y=0; y<buff->height; y++)
{
for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
{
if(x2 == (buffBG->width -2 ))
{
for(y=0; y<buff->height; y++) {
for(x=todraw, x2 = 0; x < width - 1; x++, x2++) {
if(x2 == (buffBG->width -2 )) {
x2 = 0;
}
pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
}
if(progress < 100)
{
if(progress < 100) {
pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
}
if(progress == 0)
{
if(progress == 0) {
pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
}
position = pos(0,0);
for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
{
if (i == infoMenuSelection)
{
for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) {
if (i == infoMenuSelection) {
blend(selection, gui.menu.pixmap, position);
}
pbuff = images[n].image;
if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
{
if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) {
blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
}
else
{
} else {
blend( pbuff, gui.menu.pixmap,
pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
}
{
case KEY_UP:// up arrow
if (infoMenuSelection > 0)
{
if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
{
if (infoMenuSelection > 0) {
if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) {
infoMenuSelection -= 4;
}
else
{
} else {
infoMenuSelection--;
}
drawInfoMenuItems();
updateVRAM();
}
else
{
} else {
gui.menu.draw = false;
gui.redraw = true;
break;
case KEY_DOWN:// down arrow
if (infoMenuSelection < infoMenuItemsCount - 1)
{
if (infoMenuSelection < infoMenuItemsCount - 1) {
if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
{
infoMenuSelection += 4;
}
else
{
} else {
infoMenuSelection++;
}
drawInfoMenuItems();
case KEY_ENTER:
key = 0;
if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
{
if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) {
showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
}
else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
{
} else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) {
showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
}
else if( infoMenuSelection == MENU_SHOW_HELP )
{
} else if( infoMenuSelection == MENU_SHOW_HELP ) {
showHelp();
}
else
{
} else {
int buff = infoMenuSelection;
infoMenuSelection = 0;
return buff;
getGraphicModeParams(screen_params);
// Set graphics mode if the booter was in text mode or the screen resolution has changed.
if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
{
if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) {
setVideoMode(GRAPHICS_MODE, 0);
}
branches/ErmaC/Enoch/i386/boot2/lzss.c
4949
5050
5151
52
53
54
55
56
5257
58
59
60
61
62
63
64
65
66
67
5368
5469
5570
......
97112
98113
99114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#define THRESHOLD2/* Encode string into position and length if match_length is greater than this. */
#define NILN/* Index for root of binary search trees. */
struct encode_state {
/*
* left & right children & parent. These constitute binary search trees.
*/
int lchild[N + 1], rchild[N + 257], parent[N + 1];
/* ring buffer of size N, with extra F-1 bytes to aid string comparison */
u_int8_t text_buf[N + F - 1];
/*
* match_length of longest match.
* These are set by the insert_node() procedure.
*/
int match_position, match_length;
};
//==============================================================================
// Refactoring and bug fix Copyright (c) 2010 by DHP.
return dst - dststart;
}
/*
* initialize state, mostly the trees
*
* For i = 0 to N - 1, rchild[i] and lchild[i] will be the right and left
* children of node i. These nodes need not be initialized. Also, parent[i]
* is the parent of node i. These are initialized to NIL (= N), which stands
* for 'not used.' For i = 0 to 255, rchild[N + i + 1] is the root of the
* tree for strings that begin with character i. These are initialized to NIL.
* Note there are 256 trees. */
static void init_state(struct encode_state *sp)
{
int i;
bzero(sp, sizeof(*sp));
for (i = 0; i < N - F; i++)
sp->text_buf[i] = ' ';
for (i = N + 1; i <= N + 256; i++)
sp->rchild[i] = NIL;
for (i = 0; i < N; i++)
sp->parent[i] = NIL;
}
/*
* Inserts string of length F, text_buf[r..r+F-1], into one of the trees
* (text_buf[r]'th tree) and returns the longest-match position and length
* via the global variables match_position and match_length.
* If match_length = F, then removes the old node in favor of the new one,
* because the old one will be deleted sooner. Note r plays double role,
* as tree node and position in buffer.
*/
static void insert_node(struct encode_state *sp, int r)
{
int i, p, cmp;
u_int8_t *key;
cmp = 1;
key = &sp->text_buf[r];
p = N + 1 + key[0];
sp->rchild[r] = sp->lchild[r] = NIL;
sp->match_length = 0;
for ( ; ; ) {
if (cmp >= 0) {
if (sp->rchild[p] != NIL)
p = sp->rchild[p];
else {
sp->rchild[p] = r;
sp->parent[r] = p;
return;
}
} else {
if (sp->lchild[p] != NIL)
p = sp->lchild[p];
else {
sp->lchild[p] = r;
sp->parent[r] = p;
return;
}
}
for (i = 1; i < F; i++) {
if ((cmp = key[i] - sp->text_buf[p + i]) != 0)
break;
}
if (i > sp->match_length) {
sp->match_position = p;
if ((sp->match_length = i) >= F)
break;
}
}
sp->parent[r] = sp->parent[p];
sp->lchild[r] = sp->lchild[p];
sp->rchild[r] = sp->rchild[p];
sp->parent[sp->lchild[p]] = r;
sp->parent[sp->rchild[p]] = r;
if (sp->rchild[sp->parent[p]] == p)
sp->rchild[sp->parent[p]] = r;
else
sp->lchild[sp->parent[p]] = r;
sp->parent[p] = NIL; /* remove p */
}
/* deletes node p from tree */
static void delete_node(struct encode_state *sp, int p)
{
int q;
if (sp->parent[p] == NIL)
return; /* not in tree */
if (sp->rchild[p] == NIL)
q = sp->lchild[p];
else if (sp->lchild[p] == NIL)
q = sp->rchild[p];
else {
q = sp->lchild[p];
if (sp->rchild[q] != NIL) {
do {
q = sp->rchild[q];
} while (sp->rchild[q] != NIL);
sp->rchild[sp->parent[q]] = sp->lchild[q];
sp->parent[sp->lchild[q]] = sp->parent[q];
sp->lchild[q] = sp->lchild[p];
sp->parent[sp->lchild[p]] = q;
}
sp->rchild[q] = sp->rchild[p];
sp->parent[sp->rchild[p]] = q;
}
sp->parent[q] = sp->parent[p];
if (sp->rchild[sp->parent[p]] == p)
sp->rchild[sp->parent[p]] = q;
else
sp->lchild[sp->parent[p]] = q;
sp->parent[p] = NIL;
}
u_int8_t *compress_lzss(
u_int8_t * dst,
u_int32_t dstlen,
u_int8_t * src,
u_int32_t srclen)
{
u_int8_t * result = NULL;
/* Encoding state, mostly tree but some current match stuff */
struct encode_state *sp;
int i, c, len, r, s, last_match_length, code_buf_ptr;
u_int8_t code_buf[17], mask;
u_int8_t * srcend = src + srclen;
u_int8_t *dstend = dst + dstlen;
/* initialize trees */
sp = (struct encode_state *) malloc(sizeof(*sp));
if (!sp) goto finish;
init_state(sp);
/*
* code_buf[1..16] saves eight units of code, and code_buf[0] works
* as eight flags, "1" representing that the unit is an unencoded
* letter (1 byte), "0" a position-and-length pair (2 bytes).
* Thus, eight units require at most 16 bytes of code.
*/
code_buf[0] = 0;
code_buf_ptr = mask = 1;
/* Clear the buffer with any character that will appear often. */
s = 0; r = N - F;
/* Read F bytes into the last F bytes of the buffer */
for (len = 0; len < F && src < srcend; len++)
sp->text_buf[r + len] = *src++;
if (!len)
goto finish;
/*
* Insert the F strings, each of which begins with one or more
* 'space' characters. Note the order in which these strings are
* inserted. This way, degenerate trees will be less likely to occur.
*/
for (i = 1; i <= F; i++)
insert_node(sp, r - i);
/*
* Finally, insert the whole string just read.
* The global variables match_length and match_position are set.
*/
insert_node(sp, r);
do {
/* match_length may be spuriously long near the end of text. */
if (sp->match_length > len)
sp->match_length = len;
if (sp->match_length <= THRESHOLD) {
sp->match_length = 1; /* Not long enough match. Send one byte. */
code_buf[0] |= mask; /* 'send one byte' flag */
code_buf[code_buf_ptr++] = sp->text_buf[r]; /* Send uncoded. */
} else {
/* Send position and length pair. Note match_length > THRESHOLD. */
code_buf[code_buf_ptr++] = (u_int8_t) sp->match_position;
code_buf[code_buf_ptr++] = (u_int8_t)
( ((sp->match_position >> 4) & 0xF0)
| (sp->match_length - (THRESHOLD + 1)) );
}
if ((mask <<= 1) == 0) { /* Shift mask left one bit. */
/* Send at most 8 units of code together */
for (i = 0; i < code_buf_ptr; i++)
if (dst < dstend)
*dst++ = code_buf[i];
else
goto finish;
code_buf[0] = 0;
code_buf_ptr = mask = 1;
}
last_match_length = sp->match_length;
for (i = 0; i < last_match_length && src < srcend; i++) {
delete_node(sp, s); /* Delete old strings and */
c = *src++;
sp->text_buf[s] = c; /* read new bytes */
/*
* If the position is near the end of buffer, extend the buffer
* to make string comparison easier.
*/
if (s < F - 1)
sp->text_buf[s + N] = c;
/* Since this is a ring buffer, increment the position modulo N. */
s = (s + 1) & (N - 1);
r = (r + 1) & (N - 1);
/* Register the string in text_buf[r..r+F-1] */
insert_node(sp, r);
}
while (i++ < last_match_length) {
delete_node(sp, s);
/* After the end of text, no need to read, */
s = (s + 1) & (N - 1);
r = (r + 1) & (N - 1);
/* but buffer may not be empty. */
if (--len)
insert_node(sp, r);
}
} while (len > 0); /* until length of string to be processed is zero */
if (code_buf_ptr > 1) { /* Send remaining code. */
for (i = 0; i < code_buf_ptr; i++)
if (dst < dstend)
*dst++ = code_buf[i];
else
goto finish;
}
result = dst;
finish:
if (sp) free(sp);
return result;
}
branches/ErmaC/Enoch/i386/boot2/options.c
11251125
11261126
11271127
1128
1129
1130
1131
1132
1128
1129
1130
1131
11331132
1134
1135
1133
11361134
11371135
1138
1139
1140
1136
11411137
11421138
1143
1144
1145
1139
11461140
11471141
11481142
1149
1150
1143
11511144
11521145
11531146
......
11751168
11761169
11771170
1178
1179
1180
1181
1171
1172
11821173
11831174
11841175
11851176
1186
1177
11871178
11881179
11891180
......
11941185
11951186
11961187
1197
1198
1199
1200
1188
1189
1190
1191
1192
12011193
1202
1194
12031195
1204
1205
1206
1207
1196
1197
1198
1199
12081200
1209
1210
1201
1202
12111203
12121204
12131205
12141206
1215
1216
1217
1218
1219
1220
1207
1208
1209
1210
1211
1212
12211213
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
12321224
12331225
12341226
12351227
1236
1237
1228
1229
12381230
12391231
1240
1232
12411233
1242
1243
1244
1245
1246
1234
1235
1236
1237
1238
12471239
1248
1240
12491241
12501242
1251
1252
1253
1254
1255
1243
1244
1245
1246
12561247
1257
1258
1248
12591249
1260
1250
12611251
1252
12621253
1263
1254
12641255
1265
1266
1256
1257
12671258
1259
12681260
12691261
1270
1262
12711263
1264
12721265
12731266
1274
1267
12751268
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
12981291
1299
1300
1301
1302
1292
1293
1294
1295
13031296
1304
1305
1306
1307
1297
1298
1299
1300
13081301
1309
1302
13101303
1311
1312
1313
1314
1304
1305
1306
1307
13151308
1316
1309
13171310
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
13351328
1336
1337
1329
13381330
13391331
13401332
13411333
13421334
13431335
1344
1345
1346
1336
1337
1338
13471339
13481340
1349
1341
13501342
1351
1343
13521344
1345
13531346
1354
1355
1347
1348
13561349
1357
1350
13581351
13591352
13601353
int *cntRemainingP, // Output count
char *foundVal, // found value
int foundValSize // max found value size
)
{
const char *val;
int cnt;
bool found = false;
) {
const char *val;
int cnt;
bool found = false;
if (getValueForBootKey(userString, argName, &val, &cnt))
{
if (getValueForBootKey(userString, argName, &val, &cnt)) {
// Don't copy; these values will be copied at the end of argument processing.
found = true;
}
else if (getValueForBootKey(kernelFlags, argName, &val, &cnt))
{
} else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {
// Don't copy; these values will be copied at the end of argument processing.
found = true;
}
else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig))
{
} else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) {
copyArgument(argName, val, cnt, argP, cntRemainingP);
found = true;
}
if (found && foundVal)
{
if (found && foundVal) {
strlcpy(foundVal, val, foundValSize);
}
return found;
// Update the unit and partition number.
if ( gBootVolume )
{
if (!( gBootVolume->flags & kBVFlagNativeBoot ))
{
if ( gBootVolume ) {
if (!( gBootVolume->flags & kBVFlagNativeBoot )) {
readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 );
//
// Setup edx, and signal intention to chain load the
// foreign booter.
//
//
chainbootdev = gBootVolume->biosdev;
chainbootflag = 1;
setRootVolume(gBootVolume);
}
// If no boot volume fail immediately because we're just going to fail
// trying to load the config file anyway.
else
return -1;
// If no boot volume fail immediately because we're just going to fail
// trying to load the config file anyway.
else {
return -1;
}
// Load config table specified by the user, or use the default.
// Load config table specified by the user, or use the default.
if (!getValueForBootKey(cp, "config", &val, &cnt)) {
val = 0;
cnt = 0;
}
if (!getValueForBootKey(cp, "config", &val, &cnt)) {
val = 0;
cnt = 0;
}
// Load com.apple.Boot.plist from the selected volume
// and use its contents to override default bootConfig.
// Load com.apple.Boot.plist from the selected volume
// and use its contents to override default bootConfig.
loadSystemConfig(&bootInfo->bootConfig);
loadChameleonConfig(&bootInfo->chameleonConfig);
// Use the kernel name specified by the user, or fetch the name
// in the config table, or use the default if not specified.
// Specifying a kernel name on the command line, or specifying
// a non-default kernel name in the config file counts as
// overriding the kernel, which causes the kernelcache not
// to be used.
// Use the kernel name specified by the user, or fetch the name
// in the config table, or use the default if not specified.
// Specifying a kernel name on the command line, or specifying
// a non-default kernel name in the config file counts as
// overriding the kernel, which causes the kernelcache not
// to be used.
gOverrideKernel = false;
if (( kernel = extractKernelName((char **)&cp) )) {
strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );
} else {
if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {
strlcpy( bootInfo->bootFile, val, cnt+1 );
} else {
strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );
}
}
gOverrideKernel = false;
if (( kernel = extractKernelName((char **)&cp) )) {
strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );
} else {
if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {
strlcpy( bootInfo->bootFile, val, cnt+1 );
} else {
strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );
}
}
if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
gOverrideKernel = true;
}
cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space
argP = bootArgs->CommandLine;
cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space
argP = bootArgs->CommandLine;
// Get config kernel flags, if not ignored.
if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||
if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||
!getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {
val = "";
cnt = 0;
}
configKernelFlags = malloc(cnt + 1);
strlcpy(configKernelFlags, val, cnt + 1);
val = "";
cnt = 0;
}
configKernelFlags = malloc(cnt + 1);
strlcpy(configKernelFlags, val, cnt + 1);
// boot-uuid can be set either on the command-line or in the config file
// boot-uuid can be set either on the command-line or in the config file
if (!processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config,
&argP, &cntRemaining, gBootUUIDString, sizeof(gBootUUIDString))) {
//
// Try an alternate method for getting the root UUID on boot helper partitions.
//
if (gBootVolume->flags & kBVFlagBooter)
{
//
// Try an alternate method for getting the root UUID on boot helper partitions.
//
if (gBootVolume->flags & kBVFlagBooter) {
// Load the configuration store in the boot helper partition
if (loadHelperConfig(&bootInfo->helperConfig) == 0)
{
if (loadHelperConfig(&bootInfo->helperConfig) == 0) {
val = getStringForKey(kHelperRootUUIDKey, &bootInfo->helperConfig);
if (val != NULL)
if (val != NULL) {
strlcpy(gBootUUIDString, val, sizeof(gBootUUIDString));
}
}
}
}
// Try to get the volume uuid string
if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid)
// Try to get the volume uuid string
if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) {
gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);
}
// If we have the volume uuid add it to the commandline arguments
if (strlen(gBootUUIDString))
if (strlen(gBootUUIDString)) {
copyArgument(kBootUUIDKey, gBootUUIDString, strlen(gBootUUIDString), &argP, &cntRemaining);
}
}
if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config,
if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config,
&argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE)) {
cnt = 0;
if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) {
valueBuffer[0] = '*';
cnt++;
strlcpy(valueBuffer + 1, val, cnt);
val = valueBuffer;
} else {
if (strlen(gBootUUIDString)) {
val = "*uuid";
cnt = 5;
} else {
// Don't set "rd=.." if there is no boot device key
// and no UUID.
val = "";
cnt = 0;
}
}
if (cnt > 0) {
copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);
}
strlcpy( gRootDevice, val, (cnt + 1));
}
cnt = 0;
if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) {
valueBuffer[0] = '*';
cnt++;
strlcpy(valueBuffer + 1, val, cnt);
val = valueBuffer;
} else {
if (strlen(gBootUUIDString)) {
val = "*uuid";
cnt = 5;
} else {
// Don't set "rd=.." if there is no boot device key
// and no UUID.
val = "";
cnt = 0;
}
}
if (cnt > 0) {
copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);
}
strlcpy( gRootDevice, val, (cnt + 1));
}
/*
* Removed. We don't need this anymore.
*
if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config,
/*
* Removed. We don't need this anymore.
*
if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config,
&argP, &cntRemaining, gPlatformName, sizeof(gCacheNameAdler))) {
getPlatformName(gPlatformName);
copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);
}
*/
getPlatformName(gPlatformName);
copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);
}
*/
if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&
if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&
!getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) {
if (gBootMode & kBootModeSafe) {
copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);
}
}
if (gBootMode & kBootModeSafe) {
copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);
}
}
// Store the merged kernel flags and boot args.
// Store the merged kernel flags and boot args.
cnt = strlen(configKernelFlags);
if (cnt) {
if (cnt > cntRemaining) {
error("Warning: boot arguments too long, truncating\n");
cnt = cntRemaining;
}
strncpy(argP, configKernelFlags, cnt);
argP[cnt++] = ' ';
cntRemaining -= cnt;
}
userCnt = strlen(cp);
if (userCnt > cntRemaining) {
error("Warning: boot arguments too long, truncating\n");
userCnt = cntRemaining;
}
strncpy(&argP[cnt], cp, userCnt);
argP[cnt+userCnt] = '\0';
cnt = strlen(configKernelFlags);
if (cnt) {
if (cnt > cntRemaining) {
error("Warning: boot arguments too long, truncating\n");
cnt = cntRemaining;
}
strncpy(argP, configKernelFlags, cnt);
argP[cnt++] = ' ';
cntRemaining -= cnt;
}
userCnt = strlen(cp);
if (userCnt > cntRemaining) {
error("Warning: boot arguments too long, truncating\n");
userCnt = cntRemaining;
}
strncpy(&argP[cnt], cp, userCnt);
argP[cnt+userCnt] = '\0';
if(!shouldboot)
{
if(!shouldboot) {
gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ||
getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->chameleonConfig );
gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) ?
kBootModeSafe : kBootModeNormal;
if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) {
gBootMode = kBootModeSafe;
}
if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) {
gBootMode = kBootModeSafe;
}
}
if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )
if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) ) {
strlcpy(gMKextName, val, cnt + 1);
else
} else {
gMKextName[0]=0;
}
free(configKernelFlags);
free(valueBuffer);
free(configKernelFlags);
free(valueBuffer);
return 0;
return 0;
}
branches/ErmaC/Enoch/i386/config/nconf.h
2626
2727
2828
29
30
31
32
33
34
35
36
37
38
3929
4030
4131
#include "ncurses.h"
#define max(a, b) ({\
typeof(a) _a = a;\
typeof(b) _b = b;\
_a > _b ? _a : _b; })
#define min(a, b) ({\
typeof(a) _a = a;\
typeof(b) _b = b;\
_a < _b ? _a : _b; })
typedef enum {
NORMAL = 1,
MAIN_HEADING,
branches/ErmaC/Enoch/i386/config/confdata.c
1616
1717
1818
19
20
21
22
23
24
25
26
27
28
1929
2030
2131
......
7585
7686
7787
88
7889
7990
80
91
92
93
94
8195
82
83
96
97
98
99
100
101
102
84103
85
86
87
88
104
105
106
107
89108
90
91
92
93
109
110
111
112
113
114
115
94116
95117
96
118
119
120
121
122
123
124
97125
98126
99
100127
128
101129
102130
103131
......
110138
111139
112140
113
141
114142
115143
116144
......
570598
571599
572600
573
574
601
602
575603
576604
577
605
578606
579607
580
608
581609
582
610
583611
584
612
613
585614
586
615
616
587617
588
589
618
619
590620
591621
592
622
593623
594624
595625
596626
597627
598
628
599629
600
630
601631
602632
603
633
604634
635
605636
606637
607638
......
640671
641672
642673
643
674
644675
645
676
646677
647678
648679
......
655686
656687
657688
658
689
659690
691
660692
661693
662694
#define LKC_DIRECT_LINK
#include "lkc.h"
#define max(a, b) ({\
typeof(a) _a = a;\
typeof(b) _b = b;\
_a > _b ? _a : _b; })
#define min(a, b) ({\
typeof(a) _a = a;\
typeof(b) _b = b;\
_a < _b ? _a : _b; })
static void conf_warning(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
return name ? name : "auto.conf";
}
/* TODO: figure out if symbols are always null-terminated */
static char *conf_expand_value(const char *in)
{
struct symbol *sym;
static char res_value[SYMBOL_MAXLENGTH + 1];
char name[SYMBOL_MAXLENGTH];
size_t res_rem = SYMBOL_MAXLENGTH;
char *res_ptr = res_value;
const char *src;
static char res_value[SYMBOL_MAXLENGTH];
char *dst, name[SYMBOL_MAXLENGTH];
*res_ptr = 0;
res_ptr[SYMBOL_MAXLENGTH] = 0;
while ((src = strchr(in, '$'))) {
struct symbol *sym;
const char *symval;
char *name_ptr = name;
size_t n = min(res_rem, src - in);
res_value[0] = 0;
dst = name;
while ((src = strchr(in, '$'))) {
strncat(res_value, in, src - in);
res_ptr = stpncpy(res_ptr, in, n);
if (!(res_rem -= n)) {
return res_value; /* buffer full, quit now */
}
src++;
dst = name;
while (isalnum(*src) || *src == '_')
*dst++ = *src++;
*dst = 0;
*name_ptr = 0;
while (isalnum(*src) || *src == '_') {
*name_ptr++ = *src++;
}
*name_ptr = 0;
sym = sym_lookup(name, 0);
sym_calc_value(sym);
strcat(res_value, sym_get_string_value(sym));
symval = sym_get_string_value(sym);
n = min(res_rem, strlen(symval));
res_ptr = stpncpy(res_ptr, symval, n);
if (!(res_rem -= n)) {
return res_value; /* buffer full, quit now */
}
in = src;
}
strcat(res_value, in);
strncpy(res_ptr, in, res_rem + 1);
return res_value;
}
name = conf_expand_value(conf_defname);
env = getenv(SRCTREE);
if (env) {
sprintf(fullname, "%s/%s", env, name);
snprintf(fullname, PATH_MAX+1, "%s/%s", env, name);
if (!stat(fullname, &buf))
return fullname;
}
char *slash;
if (!stat(name, &st) && S_ISDIR(st.st_mode)) {
strcpy(dirname, name);
strcat(dirname, "/");
/* FIXME: add length check */
strcpy(stpcpy(dirname, name), "/");
basename = conf_get_configname();
} else if ((slash = strrchr(name, '/'))) {
int size = slash - name + 1;
size_t size = slash - name + 1;
memcpy(dirname, name, size);
dirname[size] = 0;
if (slash[1])
if (slash[1]) {
basename = slash + 1;
else
} else {
basename = conf_get_configname();
} else
}
} else {
basename = name;
} else
}
} else {
basename = conf_get_configname();
sprintf(newname, "%s%s", dirname, basename);
}
snprintf(newname, PATH_MAX+1, "%s%s", dirname, basename);
env = getenv("KCONFIG_OVERWRITECONFIG");
if (!env || !*env) {
sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid());
snprintf(tmpname, PATH_MAX+1, "%s.tmpconfig.%d", dirname, (int)getpid());
out = fopen(tmpname, "w");
} else {
*tmpname = 0;
out = fopen(newname, "w");
}
if (!out)
if (!out) {
return 1;
}
time(&now);
env = getenv("KCONFIG_NOTIMESTAMP");
if (env && *env)
if (env && *env) {
use_timestamp = 0;
}
fprintf(out, _("#\n"
"# Automatically generated make config: don't edit\n"
menu = menu->list;
continue;
}
if (menu->next)
if (menu->next) {
menu = menu->next;
else while ((menu = menu->parent)) {
} else while ((menu = menu->parent)) {
if (menu->next) {
menu = menu->next;
break;
strcat(dirname, basename);
strcat(dirname, ".old");
rename(newname, dirname);
if (rename(tmpname, newname))
if (rename(tmpname, newname)) {
return 1;
}
}
//conf_message(_("configuration written to %s"), newname);
branches/ErmaC/Enoch/i386/libsa/libsa.h
9595
9696
9797
98
9899
100
99101
100102
101103
extern int strcmp(const char * s1, const char * s2);
extern int strncmp(const char * s1, const char * s2, size_t n);
extern char * strcpy(char * s1, const char * s2);
extern char * stpcpy(char * s1, const char * s2);
extern char * strncpy(char * s1, const char * s2, size_t n);
extern char * strpcpy(char * s1, const char * s2, size_t n);
extern size_t strlcpy(char * s1, const char * s2, size_t n);
extern char * strstr(const char *in, const char *str);
extern int atoi(const char * str);
branches/ErmaC/Enoch/i386/libsa/zalloc.c
7878
7979
8080
81
82
81
8382
8483
8584
......
109108
110109
111110
112
113
114
115
111
112
116113
117114
118115
......
132129
133130
134131
135
136
137
138
132
133
139134
140135
141136
142137
143
144138
145139
146140
......
152146
153147
154148
155
156
149
157150
158151
159152
......
161154
162155
163156
164
165
166
167
157
158
168159
169160
170161
171162
172
173
163
174164
175165
176166
......
196186
197187
198188
199
200
189
201190
202191
203192
......
218207
219208
220209
221
222
223
224
210
211
225212
226
227
228
213
229214
230215
231216
......
233218
234219
235220
236
237
221
238222
239223
240224
......
243227
244228
245229
246
247
230
248231
249232
250233
251234
252235
253
254
255
256
257
258
236
237
238
259239
260240
261241
......
266246
267247
268248
269
270
271
272
249
250
273251
274252
275253
......
292270
293271
294272
295
296
297
298
273
274
299275
300276
301277
......
311287
312288
313289
314
315
290
316291
317292
318293
......
326301
327302
328303
329
330
304
331305
332306
333307
......
337311
338312
339313
340
341
342
343
314
315
344316
345317
346318
zavailable = (zmem *) zalloc_base + sizeof(zmem) * totalNodes;
zavailable[0].start = (char *)zavailable + sizeof(zmem) * totalNodes;
if (size == 0)
{
if (size == 0) {
size = ZALLOC_LEN;
}
size = ((size + 0xf) & ~0xf);
if (size == 0)
{
if (zerror)
{
if (size == 0) {
if (zerror) {
(*zerror)((char *)0xdeadbeef, 0, file, line);
}
}
goto done;
}
#if BEST_FIT
else
{
if ((zavailable[i].size > size) && ((smallestSize == 0) || (zavailable[i].size < smallestSize)))
{
else {
if ((zavailable[i].size > size) && ((smallestSize == 0) || (zavailable[i].size < smallestSize))) {
bestFit = i;
smallestSize = zavailable[i].size;
}
}
#else
else if (zavailable[i].size > size)
{
#endif
}
#if BEST_FIT
if (bestFit != -1)
{
if (bestFit != -1) {
zallocate(ret = zavailable[bestFit].start, size);
zavailable[bestFit].start += size;
zavailable[bestFit].size -= size;
#endif
done:
if ((ret == 0) || (ret + size >= zalloc_end))
{
if (zerror)
{
if ((ret == 0) || (ret + size >= zalloc_end)) {
if (zerror) {
(*zerror)(ret, size, file, line);
}
}
if (ret != 0)
{
if (ret != 0) {
bzero(ret, size);
}
#if ZDEBUG
rp = 0;
#endif
if (!start)
{
if (!start) {
return;
}
break;
}
}
if (!found)
{
if (zerror)
{
if (!found) {
if (zerror) {
(*zerror)(pointer, rp, "free", 0);
}
else
{
} else {
return;
}
}
zalloced_size -= tsize;
#endif
for (i = 0; i < availableNodes; i++)
{
for (i = 0; i < availableNodes; i++) {
if ((start + tsize) == zavailable[i].start) // merge it in
{
zavailable[i].start = start;
return;
}
if ((i > 0) && (zavailable[i-1].start + zavailable[i-1].size == start))
{
if ((i > 0) && (zavailable[i-1].start + zavailable[i-1].size == start)) {
zavailable[i-1].size += tsize;
zcoalesce();
return;
}
if ((start + tsize) < zavailable[i].start)
{
if (++availableNodes > totalNodes)
{
if (zerror)
{
if ((start + tsize) < zavailable[i].start) {
if (++availableNodes > totalNodes) {
if (zerror) {
(*zerror)((char *)0xf000f000, 0, "free", 0);
}
}
}
}
if (++availableNodes > totalNodes)
{
if (zerror)
{
if (++availableNodes > totalNodes) {
if (zerror) {
(*zerror)((char *)0xf000f000, 1, "free", 0);
}
}
zalloced[allocedNodes].start = start;
zalloced[allocedNodes].size = size;
if (++allocedNodes > totalNodes)
{
if (zerror)
{
if (++allocedNodes > totalNodes) {
if (zerror) {
(*zerror)((char *)0xf000f000, 2, "zallocate", 0);
}
};
z1 = zp + i;
z2 = z1 + 1;
for (; i >= ndx; i--, z1--, z2--)
{
for (; i >= ndx; i--, z1--, z2--) {
*z2 = *z1;
}
}
z1 = zp + ndx;
z2 = z1 + 1;
for (i = ndx; i < totalNodes - 1; i++, z1++, z2++)
{
for (i = ndx; i < totalNodes - 1; i++, z1++, z2++) {
*z1 = *z2;
}
}
{
int i;
for (i = 0; i < availableNodes-1; i++)
{
if ( zavailable[i].start + zavailable[i].size == zavailable[i + 1].start )
{
for (i = 0; i < availableNodes-1; i++) {
if ( zavailable[i].start + zavailable[i].size == zavailable[i + 1].start ) {
zavailable[i].size += zavailable[i + 1].size;
zdelete(zavailable, i + 1); availableNodes--;
return;
branches/ErmaC/Enoch/i386/libsa/string.c
131131
132132
133133
134
135
136
134
135
136
137137
138138
139139
......
159159
160160
161161
162
162
163
163164
164
165
166
167
168
165
166
167
168
169
170
171
172
173
169174
170175
171176
......
178183
179184
180185
186
187
188
189
190
191
192
193
181194
182195
183196
184197
185198
186
199
187200
188201
189202
......
191204
192205
193206
207
208
209
210
211
212
213
214
215
216
217
194218
195219
196220
......
245269
246270
247271
248
249
250
272
251273
252274
253275
254276
255277
256
278
279
280
281
282
283
257284
258285
259286
......
300327
301328
302329
303
330
304331
305332
306333
......
312339
313340
314341
315
342
316343
317
344
318345
319346
320
347
321348
322349
323350
size_t strlen(const char * s)
{
int n = 0;
while (*s++) n++;
return(n);
const char* save = s;
while (*s++);
return (--s) - save;
}
/*#endif*/
return (*s1 - *s2);
}
int strncmp(const char * s1, const char * s2, size_t len)
/* Derived from FreeBSD source */
int strncmp(const char * s1, const char * s2, size_t n)
{
register int n = len;
while (--n >= 0 && *s1 == *s2++)
if (*s1++ == '\0')
return(0);
return(n<0 ? 0 : *s1 - *--s2);
if (!n)
return 0;
do {
if (*s1 != *s2++)
return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1));
if (!*s1++)
break;
} while (--n);
return 0;
}
char *
}
char *
stpcpy(char * s1, const char * s2)
{
while ((*s1++ = *s2++))
continue;
return --s1;
}
char *
strncpy(char * s1, const char * s2, size_t n)
{
register char *ret = s1;
while (n && (*s1++ = *s2++))
--n;
/* while (n--) *s1++ = '\0'; */
if (n > 0) {
bzero(s1, n);
}
}
char *
stpncpy(char * s1, const char * s2, size_t n)
{
while (n && (*s1++ = *s2++))
--n;
if (n > 0) {
bzero(s1, n);
}
return s1;
}
char *
strstr(const char *in, const char *str)
{
char c;
register char *ret = s1;
while (*s1)
s1++;
while (n-- && *s2)
*s1++ = *s2++;
*s1 = '\0';
while (n-- && (*s1++ = *s2++));
return ret;
}
char *strcat(char *s1, const char *s2)
{
return(strncat(s1, s2, strlen(s2)));
register char *ret = s1;
while (*s1) {
s1++;
}
while ((*s1++ = *s2++));
return ret;
}
char *strdup(const char *s1)
if (*start == '"')
{
start++;
end = strchr(start, '"');
if(end)
quoted = true;
for ( end = start; *end && !isspace(*end); end++ )
{}
}
*len = end - start;
if(next)
*next = quoted ? end+1 : end;
return start;
}
branches/ErmaC/Enoch/i386/libsa/prf.c
104104
105105
106106
107
108
107
109108
110109
111
112
110
113111
114112
115113
......
154152
155153
156154
157
158
155
159156
160157
161158
162159
163160
164161
165
166
167
168
162
163
169164
170165
171166
......
173168
174169
175170
176
177
171
178172
179173
180174
181175
182176
183177
184
185
178
186179
187180
188181
loop:
while ((c = *fmt++) != '%') {
if(c == '\0')
{
if(c == '\0') {
return len;
}
if (putfn_p)
{
if (putfn_p) {
(*putfn_p)(c, putfn_arg);
}
len++;
case 'o': case 'O':
b = 8;
number:
if (putfn_p)
{
if (putfn_p) {
printn((u_long)*adx, b, flag, minwidth, putfn_p, putfn_arg);
}
len++;
break;
case 's':
s = (char *)*adx;
while ((c = *s++))
{
if (putfn_p)
{
while ((c = *s++)) {
if (putfn_p) {
(*putfn_p)(c, putfn_arg);
}
len++;
}
while (width++ < minwidth)
{
if (putfn_p)
{
if (putfn_p) {
(*putfn_p)(' ', putfn_arg);
}
len++;
}
break;
case 'c':
if (putfn_p)
{
if (putfn_p) {
(*putfn_p)((char)*adx, putfn_arg);
}
len++;
branches/ErmaC/Enoch/i386/libsa/strtol.c
103103
104104
105105
106
107
108
106
109107
110108
111109
112
113
110
114111
115112
116113
117
118
119
114
120115
121116
122117
123118
124
125
119
126120
127121
128122
......
147141
148142
149143
150
144
151145
152
146
153147
154
148
155149
156
150
151
157152
158
153
154
159155
160
156
161157
162158
163159
......
168164
169165
170166
171
167
172168
169
173170
174171
175172
......
201198
202199
203200
204
205
206
201
207202
208203
209
210
204
211205
212206
213207
214
215
216
208
217209
218210
219211
220212
221
222
213
223214
224215
225216
226217
227218
228
229
219
230220
231
232
233
221
234222
235
236
237
223
238224
239225
240
241
226
242227
243228
244
245
229
246230
247
248
249
231
250232
251233
252234
......
255237
256238
257239
258
259
260
240
261241
262242
263
264
243
265244
266245
267246
......
297276
298277
299278
300
301
279
302280
303281
304282
305
306
283
307284
308285
309286
310287
311
312
288
313289
314290
315291
316292
317293
318294
319
320
295
321296
322
323
324
297
325298
326
327
328
299
329300
330301
331
332
302
333303
334304
335
336
305
337306
338
339
340
307
341308
342309
343310
......
346313
347314
348315
349
350
351
316
352317
353318
354
355
319
356320
357321
358322
if (c == '-') {
neg = 1;
c = *s++;
}
else if (c == '+')
{
} else if (c == '+') {
c = *s++;
}
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X'))
{
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B'))
{
} else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B')) {
c = s[1];
s += 2;
base = 2;
}
if (base == 0)
{
if (base == 0) {
base = c == '0' ? 8 : 10;
}
cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c))
if (isdigit(c)) {
c -= '0';
else if (isalpha(c))
} else if (isalpha(c)) {
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
} else {
break;
if (c >= base)
}
if (c >= base) {
break;
if ((any < 0 || acc > cutoff) || (acc == cutoff && c > cutlim))
}
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
else {
} else {
any = 1;
acc *= base;
acc += c;
//errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != 0)
if (endptr != 0) {
*endptr = (char *)(any ? s - 1 : nptr);
}
return (acc);
}
if (c == '-') {
neg = 1;
c = *s++;
}
else if (c == '+')
{
} else if (c == '+') {
c = *s++;
}
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X'))
{
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')){
c = s[1];
s += 2;
base = 16;
}
else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B'))
{
} else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B')) {
c = s[1];
s += 2;
base = 2;
}
if (base == 0)
{
if (base == 0) {
base = c == '0' ? 8 : 10;
}
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c))
{
if (isdigit(c)) {
c -= '0';
}
else if (isalpha(c))
{
} else if (isalpha(c)) {
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
}
else
{
} else {
break;
}
if (c >= base)
{
if (c >= base) {
break;
}
if ((any < 0 || acc > cutoff) || (acc == cutoff && c > cutlim))
{
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
}
else
{
} else {
any = 1;
acc *= base;
acc += c;
if (any < 0) {
acc = ULONG_MAX;
//errno = ERANGE;
}
else if (neg)
{
} else if (neg) {
acc = -acc;
}
if (endptr != 0)
{
if (endptr != 0) {
*endptr = (char *)(any ? s - 1 : nptr);
}
return (acc);
c = *s++;
} else {
neg = 0;
if (c == '+')
{
if (c == '+') {
c = *s++;
}
}
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X'))
{
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
{
if (base == 0) {
base = c == '0' ? 8 : 10;
}
qbase = (unsigned)base;
cutoff = (unsigned long long)UQUAD_MAX / qbase;
cutlim = (unsigned long long)UQUAD_MAX % qbase;
for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c))
{
if (isdigit(c)) {
c -= '0';
}
else if (isalpha(c))
{
} else if (isalpha(c)) {
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
}
else
{
} else {
break;
}
if (c >= base)
{
if (c >= base) {
break;
}
if ((any < 0 || acc > cutoff) || (acc == cutoff && c > cutlim))
{
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
}
else
{
} else {
any = 1;
acc *= qbase;
acc += c;
if (any < 0) {
acc = UQUAD_MAX;
//errno = ERANGE;
}
else if (neg)
{
} else if (neg) {
acc = -acc;
}
if (endptr != 0)
{
if (endptr != 0) {
*endptr = (char *)(any ? s - 1 : nptr);
}
return (acc);
branches/ErmaC/Enoch/doc/BootHelp.txt
176176
177177
178178
179
179180
180181
181182
Rescan=Yes Enable CD-ROM rescan mode.
"Rescan Prompt"=Yes Prompts for enable CD-ROM rescan mode.
SystemId=<UUID> Set the system id manually to UUID.
Deprecated - Now SMsystemuuid in smbios.plist
SMUUID in smbios config (reserved field) isn't used then.
SystemType=<n> Set the system type to n, where n is between 0..6
(default=1 Desktop)
branches/ErmaC/Enoch/CHANGES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
128
229
330
- bitshoveler : Optimized basic string functions strlen, strncmp, strncat, strcat
- ErmaC : Replaced sprintf with snprintf in spd.c.
- bitshoveler : Fixed inadvertent text buffer overflow in getDDRSerial
- bitshoveler : optimize get_hda_controller_name()
- Bungo : One of the changes as of rev2284 is boot option SystemId has now been deprecated. Instead use key SMsystemuuid in smbios.plist.
- bitshoveler : Defend against buffer overruns
- bitshoveler : Fix memory leak, defend against buffer overruns, add a check for malloc() failure
- bitshoveler : getMemoryInfoString: defend against buffer overruns, change O(n^2) algorithm to O(n)
- bitshoveler : Add closedir() to match opendir() call; relocate a malloc() call to fix a memory leak on error; better defense against buffer overruns
- bitshoveler : Improve robustness against buffer overruns
- bitshoveler : Add closedir() for every opendir() call, make more robust against buffer overruns
- bitshoveler : Fix memory leak
- bitshoveler : Fix cppcheck detected memory leak and error, make more robust against buffer overrun
- bitshoveler : get_pci_dev_path: get rid of tmp buffer, use snprintf, improved O(n) algorithm instead of O(n^2) (whoopee); dump_pci_dt: hack fix for printf format string vs. args mismatch
- bitshoveler : Fix memory leak; use snprintf instead of sprintf to make more robust
- bitshoveler : Fix badly formed comment inside #ifdef
- bitshoveler : setup_gma_devprop: fix memory leak
- bitshoveler : setup_nhm: fix cppcheck error
- bitshoveler : Correct cppcheck detected errors, make more robust against errors
- bitshoveler : AllocateMemoryRange: fix cppcheck detected memory leak
- bitshoveler : search_and_get_acpi_fd: fix pointer-to-temporary return problem; use snprintf instead of sprintf to prevent buffer overflows
- bitshoveler : sym_expand_string_value(): fix cppcheck errors; more to be done here
- bitshoveler : append_string(): fix cppcheck errors
- bitshoveler : conf_write_autoconf(): fix cppcheck errors
- bitshoveler : Fix memory leak for new_layout in main()
- bitshoveler : Implement snprintf(); implement missing zero-fill in strncpy()
- bitshoveler : Use original *BSD source for strlcpy()
- ErmaC: Port from Enoch the support for IVY Bridge and Haswell Intel Graphics cards. http://www.insanelymac.com/forum/topic/288241-intel-hd4000-and-haswell-inject-aaplig-platform-id/
- 2255: ErmaC add Skip flag key for Intel/nVidia/ATi from Enoch
- 2252: revert define processors name to match with xnu kernel name

Archive Download the corresponding diff file

Revision: 2341