Chameleon

Chameleon Commit Details

Date:2012-06-11 11:35:00 (7 years 2 months ago)
Author:ErmaC
Commit:1996
Parents: 1995
Message:General code cleaned up Nvidia: - Migrate define to header - added new DeviceID - added more SubDevID
Changes:
M/branches/ErmaC/Trunk/i386/libsaio/fdisk.h
M/branches/ErmaC/Trunk/i386/libsaio/msdos.c
M/branches/ErmaC/Trunk/i386/libsaio/disk.c
M/branches/ErmaC/Trunk/i386/libsaio/nvidia.c
M/branches/ErmaC/Trunk/i386/modules/Resolution/915resolution.c
M/branches/ErmaC/Trunk/i386/libsaio/ati.c
M/branches/ErmaC/Trunk/i386/modules/Resolution/edid.c
M/branches/ErmaC/Trunk/i386/libsaio/aml_generator.c
M/branches/ErmaC/Trunk/i386/libsaio/nvidia.h
M/branches/ErmaC/Trunk/i386/boot2/graphic_utils.c
M/branches/ErmaC/Trunk/i386/libsaio/hfs.c
M/branches/ErmaC/Trunk/i386/boot2/picopng.c
M/branches/ErmaC/Trunk/i386/libsaio/acpi_patcher.c
M/branches/ErmaC/Trunk/i386/libsaio/aml_generator.h
M/branches/ErmaC/Trunk/i386/libsaio/saio_types.h

File differences

branches/ErmaC/Trunk/i386/libsaio/hfs.c
265265
266266
267267
268
268
269269
270270
271271
......
312312
313313
314314
315
315
316316
317317
318318
......
351351
352352
353353
354
354
355355
356356
357357
......
376376
377377
378378
379
379
380380
381381
382382
......
510510
511511
512512
513
514
515
516
517
518
519
513
514
515
516
517
518
519
520
521
520522
521523
522524
......
644646
645647
646648
647
649
648650
649651
650652
......
693695
694696
695697
696
698
697699
698700
699701
......
737739
738740
739741
740
742
741743
742744
743745
......
759761
760762
761763
762
764
763765
764766
765767
766768
767
769
768770
769771
770772
......
833835
834836
835837
836
838
837839
838
839
840
841
842
840
841
842
843
844
843845
844
846
845847
846
847
848
849
850
851
852
848
849
850
851
852
853
854
855
856
857
853858
854
855
856
859
860
861
862
857863
858
859
860
861
862
863
864
864
865
866
867
868
869
870
871
872
873
865874
866
867
868
875
876
877
869878
870
871
872
873
879
880
881
882
883
874884
875
876
877
878
879
885
886
887
888
889
890
880891
881
892
882893
883
884
885
886
894
895
896
897
898
887899
888
889
900
901
890902
891
903
892904
893905
894906
895
896
907
908
897909
898
910
899911
900
912
901913
902914
903
904
905
906
915
916
917
918
907919
908
920
909921
910
922
911923
912924
913925
914926
915
916
917
927
928
929
918930
919
920
931
932
921933
922
934
923935
924936
925937
926938
927
928
929
939
940
941
930942
931
932
943
944
933945
934
946
935947
936948
937949
938950
939
940
951
952
941953
942
943
954
955
944956
945
946
957
958
947959
948
949
950
951
952
953
954
960
961
962
963
964
965
966
967
955968
956
969
957970
958971
959972
960973
961
962
974
975
963976
964
965
977
978
966979
967
968
980
981
969982
970
971
972
973
974
975
976
977
978
979
983
984
985
986
987
988
989
990
991
992
993
994
980995
981996
982997
983
984
998
999
1000
1001
9851002
9861003
9871004
988
989
1005
1006
9901007
991
1008
9921009
9931010
9941011
{
char entry[512];
char devStr[12];
long dirID, result, flags;
long dirID, result, flags =0;
if (HFSInitPartition(ih) == -1) return -1;
FinderInfo * finderInfo, long * infoValid)
{
char entry[512];
long dirID, dirFlags;
long dirID, dirFlags = 0;
if (HFSInitPartition(ih) == -1) return -1;
UInt32 firstLeafNode;
long long dirIndex;
char *name;
long flags, time;
long flags =0, time;
if (HFSInitPartition(ih) == -1) { return; }
HFSGetFileBlock(CICell ih, char *filePath, unsigned long long *firstBlock)
{
char entry[512];
long dirID, result, flags;
long dirID, result, flags =0;
void *extents;
HFSCatalogFile *hfsFile = (void *)entry;
HFSPlusCatalogFile *hfsPlusFile = (void *)entry;
}
break;
case kHFSFileThreadRecord :
case kHFSPlusFileThreadRecord :
case kHFSFolderThreadRecord :
case kHFSPlusFolderThreadRecord :
*flags = kFileTypeUnknown;
tmpTime = 0;
break;
case kHFSFileThreadRecord :
case kHFSPlusFileThreadRecord :
case kHFSFolderThreadRecord :
case kHFSPlusFolderThreadRecord :
*flags = kFileTypeUnknown;
tmpTime = 0;
break;
default:
break;
}
if (time != 0) {
char key[sizeof(HFSPlusCatalogKey)];
HFSCatalogKey *hfsKey = (HFSCatalogKey *)key;
HFSPlusCatalogKey *hfsPlusKey = (HFSPlusCatalogKey *)key;
// Make the catalog key.
if ( gIsHFSPlus )
{
BTNodeDescriptor *node;
long nodeSize, result = 0, entrySize = 0;
long curNode, index = 0, lowerBound, upperBound;
char *testKey, *recordData;
char *testKey, *recordData =0;
// Figure out which tree is being looked at.
if (btree == kBTreeCatalog) {
// Read the current node.
ReadExtent(extent, extentSize, extentFile,
(long long) curNode * nodeSize, nodeSize, nodeBuf, 1);
// Find the matching key.
lowerBound = 0;
upperBound = SWAP_BE16(node->numRecords) - 1;
result = CompareHFSExtentsKeys(key, testKey);
}
}
if (result < 0) upperBound = index - 1; // search < trial
else if (result > 0) lowerBound = index + 1; // search > trial
else break; // search = trial
}
if (result < 0) {
index = upperBound;
GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData);
long extentFile, uint64_t offset, uint64_t size,
void * buffer, long cache)
{
uint64_t lastOffset;
uint64_t lastOffset;
long long blockNumber, countedBlocks = 0;
long long nextExtent = 0, sizeRead = 0, readSize;
long long nextExtentBlock, currentExtentBlock = 0;
long long readOffset;
long long extentDensity, sizeofExtent, currentExtentSize;
char *currentExtent, *extentBuffer = 0, *bufferPos = buffer;
long long nextExtent = 0, sizeRead = 0, readSize;
long long nextExtentBlock, currentExtentBlock = 0;
long long readOffset;
long long extentDensity, sizeofExtent, currentExtentSize;
char *currentExtent, *extentBuffer = 0, *bufferPos = buffer;
if (offset >= extentSize) return 0;
if (offset >= extentSize) return 0;
if (gIsHFSPlus) {
extentDensity = kHFSPlusExtentDensity;
sizeofExtent = sizeof(HFSPlusExtentDescriptor);
} else {
extentDensity = kHFSExtentDensity;
sizeofExtent = sizeof(HFSExtentDescriptor);
}
if (gIsHFSPlus)
{
extentDensity = kHFSPlusExtentDensity;
sizeofExtent = sizeof(HFSPlusExtentDescriptor);
}
else
{
extentDensity = kHFSExtentDensity;
sizeofExtent = sizeof(HFSExtentDescriptor);
}
lastOffset = offset + size;
while (offset < lastOffset) {
blockNumber = offset / gBlockSize;
lastOffset = offset + size;
while (offset < lastOffset)
{
blockNumber = offset / gBlockSize;
// Find the extent for the offset.
for (; ; nextExtent++) {
if (nextExtent < extentDensity) {
if ((countedBlocks+GetExtentSize(extent, nextExtent)-1)<blockNumber) {
countedBlocks += GetExtentSize(extent, nextExtent);
continue;
}
// Find the extent for the offset.
for (; ; nextExtent++)
{
if (nextExtent < extentDensity)
{
if ((countedBlocks+GetExtentSize(extent, nextExtent)-1)<blockNumber)
{
countedBlocks += GetExtentSize(extent, nextExtent);
continue;
}
currentExtent = extent + nextExtent * sizeofExtent;
break;
}
currentExtent = extent + nextExtent * sizeofExtent;
break;
}
if (extentBuffer == 0) {
extentBuffer = malloc(sizeofExtent * extentDensity);
if (extentBuffer == 0) return -1;
}
if (extentBuffer == 0)
{
extentBuffer = malloc(sizeofExtent * extentDensity);
if (extentBuffer == 0) return -1;
}
nextExtentBlock = nextExtent / extentDensity;
if (currentExtentBlock != nextExtentBlock) {
ReadExtentsEntry(extentFile, countedBlocks, extentBuffer);
currentExtentBlock = nextExtentBlock;
}
nextExtentBlock = nextExtent / extentDensity;
if (currentExtentBlock != nextExtentBlock)
{
ReadExtentsEntry(extentFile, countedBlocks, extentBuffer);
currentExtentBlock = nextExtentBlock;
}
currentExtentSize = GetExtentSize(extentBuffer, nextExtent % extentDensity);
currentExtentSize = GetExtentSize(extentBuffer, nextExtent % extentDensity);
if ((countedBlocks + currentExtentSize - 1) >= blockNumber) {
currentExtent = extentBuffer + sizeofExtent * (nextExtent % extentDensity);
break;
}
if ((countedBlocks + currentExtentSize - 1) >= blockNumber)
{
currentExtent = extentBuffer + sizeofExtent * (nextExtent % extentDensity);
break;
}
countedBlocks += currentExtentSize;
}
countedBlocks += currentExtentSize;
}
readOffset = ((blockNumber - countedBlocks) * gBlockSize) +
readOffset = ((blockNumber - countedBlocks) * gBlockSize) +
(offset % gBlockSize);
// MacWen: fix overflow in multiplication by forcing 64bit multiplication
readSize = (long long)GetExtentSize(currentExtent, 0) * gBlockSize - readOffset;
if (readSize > (size - sizeRead)) readSize = size - sizeRead;
readSize = (long long)GetExtentSize(currentExtent, 0) * gBlockSize - readOffset;
if (readSize > (size - sizeRead)) readSize = size - sizeRead;
readOffset += (long long)GetExtentStart(currentExtent, 0) * gBlockSize;
readOffset += (long long)GetExtentStart(currentExtent, 0) * gBlockSize;
CacheRead(gCurrentIH, bufferPos, gAllocationOffset + readOffset,
CacheRead(gCurrentIH, bufferPos, gAllocationOffset + readOffset,
readSize, cache);
sizeRead += readSize;
offset += readSize;
bufferPos += readSize;
}
sizeRead += readSize;
offset += readSize;
bufferPos += readSize;
}
if (extentBuffer) free(extentBuffer);
if (extentBuffer) free(extentBuffer);
return sizeRead;
return sizeRead;
}
static long GetExtentStart(void * extents, long index)
{
long start;
HFSExtentDescriptor *hfsExtents = extents;
HFSPlusExtentDescriptor *hfsPlusExtents = extents;
long start;
HFSExtentDescriptor *hfsExtents = extents;
HFSPlusExtentDescriptor *hfsPlusExtents = extents;
if (gIsHFSPlus) start = SWAP_BE32(hfsPlusExtents[index].startBlock);
else start = SWAP_BE16(hfsExtents[index].startBlock);
if (gIsHFSPlus) start = SWAP_BE32(hfsPlusExtents[index].startBlock);
else start = SWAP_BE16(hfsExtents[index].startBlock);
return start;
return start;
}
static long GetExtentSize(void * extents, long index)
{
long size;
HFSExtentDescriptor *hfsExtents = extents;
HFSPlusExtentDescriptor *hfsPlusExtents = extents;
long size;
HFSExtentDescriptor *hfsExtents = extents;
HFSPlusExtentDescriptor *hfsPlusExtents = extents;
if (gIsHFSPlus) size = SWAP_BE32(hfsPlusExtents[index].blockCount);
else size = SWAP_BE16(hfsExtents[index].blockCount);
if (gIsHFSPlus) size = SWAP_BE32(hfsPlusExtents[index].blockCount);
else size = SWAP_BE16(hfsExtents[index].blockCount);
return size;
return size;
}
static long CompareHFSCatalogKeys(void * key, void * testKey)
{
HFSCatalogKey *searchKey, *trialKey;
long result, searchParentID, trialParentID;
HFSCatalogKey *searchKey, *trialKey;
long result, searchParentID, trialParentID;
searchKey = key;
trialKey = testKey;
searchKey = key;
trialKey = testKey;
searchParentID = SWAP_BE32(searchKey->parentID);
trialParentID = SWAP_BE32(trialKey->parentID);
searchParentID = SWAP_BE32(searchKey->parentID);
trialParentID = SWAP_BE32(trialKey->parentID);
// parent dirID is unsigned
if (searchParentID > trialParentID) result = 1;
else if (searchParentID < trialParentID) result = -1;
else {
// parent dirID's are equal, compare names
result = FastRelString(searchKey->nodeName, trialKey->nodeName);
}
// parent dirID is unsigned
if (searchParentID > trialParentID) result = 1;
else if (searchParentID < trialParentID) result = -1;
else
{
// parent dirID's are equal, compare names
result = FastRelString(searchKey->nodeName, trialKey->nodeName);
}
return result;
return result;
}
static long CompareHFSPlusCatalogKeys(void * key, void * testKey)
{
HFSPlusCatalogKey *searchKey, *trialKey;
long result, searchParentID, trialParentID;
HFSPlusCatalogKey *searchKey, *trialKey;
long result, searchParentID, trialParentID;
searchKey = key;
trialKey = testKey;
searchKey = key;
trialKey = testKey;
searchParentID = SWAP_BE32(searchKey->parentID);
trialParentID = SWAP_BE32(trialKey->parentID);
searchParentID = SWAP_BE32(searchKey->parentID);
trialParentID = SWAP_BE32(trialKey->parentID);
// parent dirID is unsigned
if (searchParentID > trialParentID) result = 1;
else if (searchParentID < trialParentID) result = -1;
else {
// parent dirID's are equal, compare names
if ((searchKey->nodeName.length == 0) || (trialKey->nodeName.length == 0))
result = searchKey->nodeName.length - trialKey->nodeName.length;
else
if (gCaseSensitive) {
result = BinaryUnicodeCompare(&searchKey->nodeName.unicode[0],
// parent dirID is unsigned
if (searchParentID > trialParentID) result = 1;
else if (searchParentID < trialParentID) result = -1;
else
{
// parent dirID's are equal, compare names
if ((searchKey->nodeName.length == 0) || (trialKey->nodeName.length == 0))
result = searchKey->nodeName.length - trialKey->nodeName.length;
else
if (gCaseSensitive)
{
result = BinaryUnicodeCompare(&searchKey->nodeName.unicode[0],
SWAP_BE16(searchKey->nodeName.length),
&trialKey->nodeName.unicode[0],
SWAP_BE16(trialKey->nodeName.length));
} else {
result = FastUnicodeCompare(&searchKey->nodeName.unicode[0],
}
else
{
result = FastUnicodeCompare(&searchKey->nodeName.unicode[0],
SWAP_BE16(searchKey->nodeName.length),
&trialKey->nodeName.unicode[0],
SWAP_BE16(trialKey->nodeName.length), OSBigEndian);
}
}
}
}
return result;
return result;
}
static long CompareHFSExtentsKeys(void * key, void * testKey)
branches/ErmaC/Trunk/i386/libsaio/acpi_patcher.c
687687
688688
689689
690
691
692
693
690
691
692
693
694
695
694696
695697
696698
......
749751
750752
751753
752
754
753755
754756
755757
if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2)
fix_restart = true;
else
getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig);
} else {
verbose ("Not an Intel platform: Restart Fix not applied !!!\n");
fix_restart = false;
getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig);
}
else
{
verbose ("Not an Intel platform: Restart Fix not applied !!!\n");
fix_restart = false;
}
if (fix_restart) fadt_rev2_needed = true;
fadt_mod->Reset_BitWidth= 0x08; // 1 byte
fadt_mod->Reset_BitOffset= 0x00; // Offset 0
fadt_mod->Reset_AccessWidth= 0x01; // Byte access
fadt_mod->Reset_Address= 0x64; // Address of the register
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");
}
branches/ErmaC/Trunk/i386/libsaio/aml_generator.c
195195
196196
197197
198
199
198
199
200200
201201
202202
......
204204
205205
206206
207
207208
208209
209210
......
418419
419420
420421
421
422
422423
423424
424425
425426
426
427
427428
428429
429430
}
unsigned int root = 0;
if ((len % 4) == 1 && name[0] == '\\')
if (((len % 4) == 1) && (name[0] == '\\'))
root++;
if (count == 1)
node->Length = 4 + root;
node->Buffer = malloc(node->Length);
memcpy(node->Buffer, name, 4 + root);
return node->Length;
}
else if (size <= 0xfff)
{
buffer[offset++] = 0x40 | (size & 0xf); /* 0x40 is type, 0x0X is first nibble of length */
buffer[offset++] = (size >> 4) & 0xff; /* +1 bytes for rest length */
buffer[offset++] = (size >> 4) & 0xff; /* +1 bytes for rest length */
}
else if (size <= 0xfffff)
{
buffer[offset++] = 0x80 | (size & 0xf); /* 0x80 is type, 0x0X is first nibble of length */
buffer[offset++] = (size >> 4) & 0xff; /* +2 bytes for rest length */
buffer[offset++] = (size >> 4) & 0xff; /* +2 bytes for rest length */
buffer[offset++] = (size >> 12) & 0xff;
}
else
branches/ErmaC/Trunk/i386/libsaio/aml_generator.h
2929
3030
3131
32
33
32
33
3434
35
35
3636
3737
3838
......
5858
5959
6060
61
61
{
unsigned charType;
unsigned intLength;
char*Buffer;
char*Buffer;
unsigned intSize;
struct aml_chunk*Next;
struct aml_chunk*First;
struct aml_chunk*Last;
unsigned int aml_calculate_size(struct aml_chunk* node);
unsigned int aml_write_node(struct aml_chunk* node, char* buffer, unsigned int offset);
#endif /* !__LIBSAIO_AML_GENERATOR_H */
#endif /* !__LIBSAIO_AML_GENERATOR_H */
branches/ErmaC/Trunk/i386/libsaio/fdisk.h
3535
3636
3737
38
39
40
38
39
40
4141
42
42
4343
4444
45
45
4646
4747
4848
49
50
51
52
53
49
50
51
52
53
5454
5555
5656
57
58
57
58
5959
6060
6161
#ifndef __LIBSAIO_FDISK_H
#define __LIBSAIO_FDISK_H
#define DISK_BLK00/* blkno of boot block */
#define DISK_BLK0SZ512/* size of boot block */
#define DISK_BOOTSZ446/* size of boot code in boot block */
#define DISK_BLK00/* blkno of boot block */
#define DISK_BLK0SZ512/* size of boot block */
#define DISK_BOOTSZ446/* size of boot code in boot block */
#define DISK_SIGNATURE0xAA55/* signature of the boot record */
#define FDISK_NPART4/* number of entries in fdisk table */
#define FDISK_NPART4/* number of entries in fdisk table */
#define FDISK_ACTIVE0x80/* indicator of active partition */
#define FDISK_NEXTNAME0xA7/* indicator of NeXT partition */
#define FDISK_DOS120x01/* 12-bit fat < 10MB dos partition */
#define FDISK_DOS120x01/* 12-bit fat < 10MB dos partition */
#define FDISK_DOS16S0x04/* 16-bit fat < 32MB dos partition */
#define FDISK_DOSEXT0x05/* extended dos partition */
#define FDISK_DOS16B0x06/* 16-bit fat >= 32MB dos partition */
#define FDISK_NTFS0x07/* NTFS partition */
#define FDISK_SMALLFAT320x0b /* FAT32 partition */
#define FDISK_FAT320x0c/* FAT32 partition */
#define FDISK_DOS16SLBA 0x0e
#define FDISK_LINUX0x83
#define FDISK_NTFS0x07/* NTFS partition */
#define FDISK_SMALLFAT320x0b/* FAT32 partition */
#define FDISK_FAT320x0c/* FAT32 partition */
#define FDISK_DOS16SLBA0x0e
#define FDISK_LINUX0x83
#define FDISK_OPENBSD0xa6 /* OpenBSD FFS partition */
#define FDISK_FREEBSD0xa5 /* FreeBSD UFS2 partition */
#define FDISK_BEFS0xeb /* Haiku BeFS partition */
#define FDISK_UFS0xa8/* Apple UFS partition */
#define FDISK_HFS0xaf/* Apple HFS partition */
#define FDISK_UFS0xa8/* Apple UFS partition */
#define FDISK_HFS0xaf/* Apple HFS partition */
#define FDISK_BOOTER0xab/* Apple booter partition */
/*
branches/ErmaC/Trunk/i386/libsaio/nvidia.c
6464
6565
6666
67
68
69
70
71
72
73
74
75
76
77
78
7967
8068
8169
8270
8371
8472
85
73
8674
8775
8876
......
9482
9583
9684
97
98
9985
10086
10187
102
103
104
10588
10689
10790
......
10992
11093
11194
112
113
11495
11596
11697
......
257238
258239
259240
260
241
261242
262243
263244
......
339320
340321
341322
323
342324
343325
326
327
328
329
330
331
332
333
344334
345335
346336
......
371361
372362
373363
374
375
376
377
378
364
365
366
367
368
379369
380
381
382
383
384
385
386
387
370
371
372
373
374
375
376
377
378
379
388380
389381
390382
391383
392384
385
386
393387
394388
395389
396390
397391
398392
393
399394
400395
401396
......
405400
406401
407402
403
408404
409405
410406
......
413409
414410
415411
412
416413
417414
418415
......
425422
426423
427424
425
426
427
428
429
428430
429431
430432
......
434436
435437
436438
439
437440
438441
439442
443
444
445
446
447
440448
441449
442450
......
444452
445453
446454
455
447456
448
457
449458
450459
451460
461
452462
453463
464
454465
455466
456467
......
539550
540551
541552
553
554
555
556
542557
543558
544559
545560
546561
562
547563
564
565
566
548567
549568
550569
570
571
572
573
574
551575
552576
553577
......
575599
576600
577601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
578629
630
631
632
633
634
635
636
637
579638
580639
581640
......
692751
693752
694753
754
755
695756
696757
697758
......
733794
734795
735796
797
736798
737799
738800
......
772834
773835
774836
775
776
837
838
839
840
841
777842
778843
779844
......
838903
839904
840905
906
907
908
909
910
911
912
841913
914
915
916
917
918
842919
920
843921
922
923
924
925
926
927
928
844929
845930
931
846932
847933
848934
......
872958
873959
874960
961
875962
876963
877964
......
889976
890977
891978
979
980
981
982
983
984
985
892986
893987
894988
895989
896990
991
992
993
994
995
897996
898997
899998
......
14831582
14841583
14851584
1486
1585
14871586
14881587
14891588
......
18191918
18201919
18211920
1822
1921
18231922
18241923
18251924
......
21282227
21292228
21302229
2131
2230
21322231
21332232
21342233
......
21892288
21902289
21912290
2192
2291
21932292
21942293
21952294
......
22582357
22592358
22602359
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
22722380
22732381
22742382
......
25382646
25392647
25402648
2541
2649
25422650
25432651
25442652
#define DBG(x...)
#endif
#define NVIDIA_ROM_SIZE0x10000
#define PATCH_ROM_SUCCESS1
#define PATCH_ROM_SUCCESS_HAS_LVDS2
#define PATCH_ROM_FAILED0
#define MAX_NUM_DCB_ENTRIES16
#define TYPE_GROUPED0xff
#define READ_BYTE(rom, offset) (*(u_char *)(rom + offset))
#define READ_LE_SHORT(rom, offset) (READ_BYTE(rom, offset+1) << 8 | READ_BYTE(rom, offset))
#define READ_LE_INT(rom, offset) (READ_LE_SHORT(rom, offset+2) << 16 | READ_LE_SHORT(rom, offset))
#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))
extern uint32_t devices_number;
const char *nvidia_compatible_0[] ={ "@0,compatible","NVDA,NVMac" };
const char *nvidia_compatible_1[] ={ "@1,compatible","NVDA,NVMac" };
const char *nvidia_device_type_0[] ={ "@0,device_type","display" };
const char *nvidia_device_type_1[] ={ "@1,device_type","display" };
const char *nvidia_device_type[] ={ "device_type","NVDA,Parent" };
const char *nvidia_device_type_parent[] ={ "device_type","NVDA,Parent" };
const char *nvidia_device_type_child[]={ "device_type","NVDA,Child" };
const char *nvidia_name_0[] ={ "@0,name","NVDA,Display-A" };
const char *nvidia_name_1[] ={ "@1,name","NVDA,Display-B" };
0x00, 0x00, 0x00, 0x00
};
#define NVCAP_LEN ( sizeof(default_NVCAP) / sizeof(uint8_t) )
static uint8_t default_dcfg_0[]={0x03, 0x01, 0x03, 0x00};
static uint8_t default_dcfg_1[]={0xff, 0xff, 0x00, 0x01};
#define DCFG0_LEN ( sizeof(default_dcfg_0) / sizeof(uint8_t) )
#define DCFG1_LEN ( sizeof(default_dcfg_1) / sizeof(uint8_t) )
static uint8_t default_NVPM[]= {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
#define NVPM_LEN ( sizeof(default_NVPM) / sizeof(uint8_t) )
static nvidia_card_info_t nvidia_cards[] = {
/* ========================================================================================
* Layout is device(VendorId + DeviceId), subdev (SubvendorId + SubdeviceId), display name.
{ 0x10DE01D8,0x1864007A,"LG GeForce Go 7400" },
{ 0x10DE01D8,0x19614605,"ESS GeForce Go 7400" },
{ 0x10DE01D8,0x19615607,"ESS GeForce Go 7400" },
{ 0x10DE01D8,0x19915532,"GeForce Go 7400" }, // Topstar Digital Technologies Co., Ltd.
{ 0x10DE01D8,0x19915532,"Topstar GeForce Go 7400" },
{ 0x10DE01D8,0x19DB2174,"GeForce Go 7400" }, // ??
{ 0x10DE01D8,0xC0181631,"GeForce Go 7400" }, // ??
{ 0x10DE01DA,0x1028017D,"Dell Quadro NVS 110M" },
{ 0x10DE0407,0x106B00A3,"Apple GeForce 8600M GT" },
{ 0x10DE0407,0x106B00A4,"Apple GeForce 8600M GT" },
// 0410 - 041F
{ 0x10DE0410,0x174B3058,"PC Partner GeForce GT 330" },
// 0420 - 042F
{ 0x10DE0426,0x10338897,"NEC GeForce 8400M GT" },
{ 0x10DE0426,0x104381F7,"Asus GeForce 8400M GT" },
{ 0x10DE0426,0x104D9005,"Sony GeForce 8400M GT" },
{ 0x10DE0426,0x104D9016,"Sony GeForce 8400M GT" },
{ 0x10DE0426,0x104D9017,"Sony GeForce 8400M GT" },
{ 0x10DE0426,0x104D9018,"Sony GeForce 8400M GT" },
{ 0x10DE0426,0x104D902D,"Sony GeForce 8400M GT" },
{ 0x10DE0426,0x104D9030,"Sony GeForce 8400M GT" },
{ 0x10DE0426,0x19915584,"Topstar GeForce 8400M GT" },
// 0430 - 043F
// 0440 - 044F
// 0450 - 045F
// 05E0 - 05EF
{ 0x10DE05E0,0x10DE064E,"nVidia GeForce GTX 295" },
{ 0x10DE05E0,0x38421291,"EVGA GeForce GTX 295" },
{ 0x10DE05E2,0x10438291,"Asus GTX 260" },
{ 0x10DE05E2,0x10438298,"Asus GTX 260" },
{ 0x10DE05E2,0x104382C4,"Asus GTX 260" },
{ 0x10DE05E2,0x104382CF,"Asus GTX 260" },
{ 0x10DE05E2,0x104382E3,"Asus GTX 260" },
{ 0x10DE05E2,0x10438291,"Asus GeForce GTX 260" },
{ 0x10DE05E2,0x10438298,"Asus GeForce GTX 260" },
{ 0x10DE05E2,0x104382C4,"Asus GeForce GTX 260" },
{ 0x10DE05E2,0x104382CF,"Asus GeForce GTX 260" },
{ 0x10DE05E2,0x104382E3,"Asus GeForce GTX 260" },
{ 0x10DE05E2,0x104382EB,"ASUS ENGTX260" },
{ 0x10DE05E2,0x10B00801,"Gainward GTX 260" },
{ 0x10DE05E2,0x10DE0585,"nVidia GTX 260" },
{ 0x10DE05E2,0x10DE0617,"nVidia GTX 260" },
{ 0x10DE05E2,0x16822390,"HFX GTX 260" },
{ 0x10DE05E2,0x17870000,"HIS GTX 260" },
{ 0x10DE05E2,0x34421260,"Bihl GTX 260" },
{ 0x10DE05E2,0x34421262,"Bihl GTX 260" },
{ 0x10DE05E2,0x73770000,"Colorful GTX 260" },
{ 0x10DE05E2,0x10B00801,"Gainward GeForce GTX 260" },
{ 0x10DE05E2,0x10DE0585,"nVidia GeForce GTX 260" },
{ 0x10DE05E2,0x10DE0617,"nVidia GeForce GTX 260" },
{ 0x10DE05E2,0x16822390,"HFX GeForce GTX 260" },
{ 0x10DE05E2,0x17870000,"HIS GeForce GTX 260" },
{ 0x10DE05E2,0x196E064B,"PNY GeForce GTX 260" },
{ 0x10DE05E2,0x19F10FA9,"BFG GeForce GTX 260" },
{ 0x10DE05E2,0x34421260,"Bihl GeForce GTX 260" },
{ 0x10DE05E2,0x34421262,"Bihl GeForce GTX 260" },
{ 0x10DE05E2,0x73770000,"Colorful GeForce GTX 260" },
{ 0x10DE05E3,0x10438320,"Asus GeForce GTX 285" }, // mauriziopasotti
{ 0x10DE05E3,0x106B0000,"Apple GeForce GTX 285" },
{ 0x10DE05E3,0x10DE065B,"nVidia GeForce GTX 285" },
{ 0x10DE05E3,0x38421080,"EVGA GeForce GTX 285" },
{ 0x10DE05E3,0x38421187,"EVGA GeForce GTX 285" },
{ 0x10DE05E6,0x10B00401,"Gainward GeForce GTX 285" },
{ 0x10DE05E6,0x38421171,"EVGA GeForce GTX 275" },
{ 0x10DE05E7,0x10DE0595,"nVidia Tesla T10 Processor" },
{ 0x10DE05E7,0x10DE066A,"nVidia Tesla C1060" },
{ 0x10DE05E7,0x10DE068F,"nVidia Tesla T10 Processor" },
{ 0x10DE05E7,0x10DE0697,"nVidia Tesla M1060" },
{ 0x10DE05E7,0x10DE0714,"nVidia Tesla M1060" },
{ 0x10DE05E7,0x10DE0743,"nVidia Tesla M1060" },
{ 0x10DE05EA,0x10DE0738,"nVidia GeForce GTX 260" },
{ 0x10DE05EB,0x10DE0705,"nVidia GeForce GTX 295" },
{ 0x10DE05EB,0x19F110C2,"BFG GeForce GTX 295" },
// 05F0 - 05FF
{ 0x10DE0600,0x10DE0000,"Abit GeForce 8800 GTS" },
{ 0x10DE0600,0x10DE0502,"nVidia GeForce 8800 GTS" },
{ 0x10DE0600,0x19F10719,"BFG GeForce 8800 GTS" },
{ 0x10DE0603,0x1B0A9044,"Pegatron GeForce GT 230" },
// 0610 - 061F
{ 0x10DE0611,0x104381F7,"Asus GeForce 8800 GT" },
{ 0x10DE0611,0x10DE053C,"nVidia GeForce 8800 GT" },
{ 0x10DE0611,0x174B9210,"PC Partner GeForce 8800 GT" },
{ 0x10DE0611,0x1ACC8582,"Point of View GeForce 8800 GT" }, // Alex//3oo1
{ 0x10DE0611,0x3842C802,"EVGA GeForce 8800 GT" },
{ 0x10DE0612,0x3842C875,"EVGA GeForce 9800 GTX+" },
{ 0x10DE0618,0x1025028E,"Acer GeForce GTX 260M" },
{ 0x10DE0618,0x102802A1,"Dell GeForce GTX 260M" },
{ 0x10DE0618,0x102802A2,"Dell GeForce GTX 260M" },
{ 0x10DE0618,0x15580860,"Clevo/Kapok GeForce GTX 260M" },
// 0620 - 062F
{ 0x10DE0622,0x104382AC,"Asus EN9600GT Magic" }, // Fabio71
{ 0x10DE0622,0x10DE0545,"nVidia GeForce 9600GT" },
{ 0x10DE0622,0x10621272,"MSi GeForce 9600GT" },
{ 0x10DE0622,0x10621278,"MSi GeForce 9600GT" },
{ 0x10DE0622,0x10621279,"MSi GeForce 9600GT" },
{ 0x10DE0622,0x10621432,"MSi GeForce 9600GT" },
// 0630 - 063F
// 0640 - 064F
{ 0x10DE0640,0x106B00AD,"Apple GeForge 9500 GT" },
{ 0x10DE0640,0x14621290,"MSi GeForge 9500 GT" },
{ 0x10DE0640,0x14621291,"MSi GeForge 9500 GT" },
{ 0x10DE0640,0x16423796,"Bitland GeForge 9500 GT" },
{ 0x10DE0647,0x106B00BC,"Apple GeForge 9600M GT" },
{ 0x10DE0648,0x1043900F,"Asus GeForge 9600M GS" },
{ 0x10DE0649,0x10439013,"Asus GeForge 9600M GT" },
// 0650 - 065F
{ 0x10DE065C,0x10280250,"Dell Quadro FX 770M" },
{ 0x10DE065C,0x103C30E7,"HP Quadro FX 770M" },
{ 0x10DE065C,0x10DE058B,"nVidia Quadro FX 770M" },
{ 0x10DE065C,0x10DE0734,"nVidia Quadro FX 770M" }, // 512MB
{ 0x10DE065C,0x17341147,"Fujitsu Quadro FX 770M" },
// 0660 - 066F
// 0670 - 067F
// 0680 - 068F
// 06A0 - 06AF
// 06B0 - 06BF
// 06C0 - 06CF
{ 0x10DE06C0,0x10438359,"Asus GeForce GTX 480" },
{ 0x10DE06C0,0x10DE075F,"nVidia GeForce GTX 480" },
// { 0x10DE06C0,0x19DA0010,"Zotac GTX 480 AMP" },
{ 0x10DE06C0,0x38421480,"EVGA GTX 480" },
{ 0x10DE06C0,0x38421482,"EVGA GTX 480" },
{ 0x10DE06CD,0x10DE079F,"Point of View GeForce GTX 470" }, // Alex//3oo1
{ 0x10DE06CD,0x10DE979F,"nVidia GeForce GTX 470" },
{ 0x10DE06CD,0x145834F5,"GigaByte GeForce GTX 470" },
{ 0x10DE06CD,0x19DA0010,"Zotac GTX 470" },
{ 0x10DE06CD,0x19DA1153,"Zotac GeForce GTX 470" }, // magnifico10 and Fabio71 TODO: AMP???
{ 0x10DE06CD,0x38421472,"EVGA GeForce GTX 470" },
// 06D0 - 06DF
{ 0x10DE06D1,0x10DE0771,"nVidia Tesla C2050" },
{ 0x10DE06D1,0x10DE0772,"nVidia Tesla C2070" },
// 0820 - 082F
// 0830 - 083F
// 0840 - 084F
{ 0x10DE084B,0x10250227,"Acer GeForce 9200" },
{ 0x10DE084B,0x10250228,"Acer GeForce 9200" },
{ 0x10DE084B,0x103C2A6E,"HP GeForce 9200" },
{ 0x10DE084B,0x1631E03B,"NEC GeForce 9200" },
// 0850 - 085F
// 0860 - 086F
// 0870 - 087F
{ 0x10DE0876,0x103C3651,"HP ION" },
{ 0x10DE0876,0x10438402,"Asus ION" },
{ 0x10DE0876,0x144DC056,"Samsung ION" },
{ 0x10DE087D,0x17AA301D,"Lenovo ION" },
{ 0x10DE0876,0x18491202,"ASRock ION" },
{ 0x10DE0876,0x18540148,"LG ION" },
{ 0x10DE0876,0x18540149,"LG ION" },
// 0880 - 088F
// 0890 - 089F
// 08A0 - 08AF
{ 0x10DE08A0,0x106B00C0,"Apple GeForce 320M" },
{ 0x10DE08A0,0x106B00C2,"Apple GeForce 320M" },
{ 0x10DE08A0,0x106B00C5,"Apple GeForce 320M" },
{ 0x10DE08A0,0x106B00C9,"Apple GeForce 320M" },
{ 0x10DE08A0,0x106B00CE,"Apple GeForce 320M" },
// 08B0 - 08BF
// 08C0 - 08CF
// 08D0 - 08DF
{ 0x10DE0A20,0x10438311,"Asus GeForce GT 220" },
{ 0x10DE0A28,0x1B0A903B,"Pegatron GeForce GT 230" },
// 0A30 - 0A3F
{ 0x10DE0A34,0x10250200,"Acer GeForce GT 240M" },
{ 0x10DE0A34,0x10250201,"Acer GeForce GT 240M" },
{ 0x10DE0A34,0x1025020E,"Acer GeForce GT 240M" },
{ 0x10DE0A34,0x10250219,"Acer GeForce GT 240M" },
{ 0x10DE0A34,0x1025021E,"Acer GeForce GT 240M" },
{ 0x10DE0A34,0x10250252,"Acer GeForce GT 240M" },
{ 0x10DE0A34,0x10250259,"Acer GeForce GT 240M" },
{ 0x10DE0A34,0x1025026B,"Acer GeForce GT 240M" },
{ 0x10DE0A34,0x10250273,"Acer GeForce GT 240M" },
{ 0x10DE0A34,0x10250299,"Acer GeForce GT 240M" },
{ 0x10DE0A34,0x102802A2,"Dell GeForce GT 240M" },
{ 0x10DE0A34,0x10431AE2,"Asus GeForce GT 240M" },
{ 0x10DE0A34,0x1043202A,"Asus GeForce GT 240M" },
{ 0x10DE0A34,0x10432031,"Asus GeForce GT 240M" },
{ 0x10DE0A34,0x10432034,"Asus GeForce GT 240M" },
{ 0x10DE0A34,0x10432036,"Asus GeForce GT 240M" },
{ 0x10DE0A34,0x1043203A,"Asus GeForce GT 240M" },
{ 0x10DE0A34,0x10432040,"Asus GeForce GT 240M" },
{ 0x10DE0A34,0x104D905E,"Sony GeForce GT 240M" },
{ 0x10DE0A34,0x104D9060,"Sony GeForce GT 240M" },
{ 0x10DE0A34,0x10719072,"Mitac GeForce GT 240M" },
{ 0x10DE0A34,0x14621013,"MSi GeForce GT 240M" },
{ 0x10DE0A34,0x1462102E,"MSi GeForce GT 240M" },
{ 0x10DE0A34,0x14621031,"MSi GeForce GT 240M" },
{ 0x10DE0A34,0x14624570,"MSi GeForce GT 240M" },
{ 0x10DE0A34,0x14C00042,"Compal GeForce GT 240M" },
{ 0x10DE0A34,0x152D0828,"Quanta GeForce GT 240M" },
{ 0x10DE0A34,0x16423928,"Bitland GeForce GT 240M" },
{ 0x10DE0A34,0x1734118D,"Fujitsu GeForce GT 240M" },
{ 0x10DE0A34,0x1734118E,"Fujitsu GeForce GT 240M" },
{ 0x10DE0A34,0x17AA2144,"Lenovo GeForce GT 240M" },
{ 0x10DE0A34,0x17AA38CD,"Lenovo GeForce GT 240M" },
{ 0x10DE0A34,0x17AA38FD,"Lenovo GeForce GT 240M" },
{ 0x10DE0A34,0x17AA38FF,"Lenovo GeForce GT 240M" },
{ 0x10DE0A34,0x17C010D0,"Wistron GeForce GT 240M" },
{ 0x10DE0A34,0x17C0208D,"Wistron GeForce GT 240M" },
// 0A40 - 0A4F
// 0A50 - 0A5F
// 0A60 - 0A6F
// 0DB0 - 0DBF
// 0DC0 - 0DCF
{ 0x10DE0DC0,0x174B1178,"PC Partner GeForce GT 440" },
{ 0x10DE0DC4,0x10438365,"Asus GeForce GTS 450" },
{ 0x10DE0DCD,0x102804B7,"Dell GeForce GT 555M" },
{ 0x10DE0DD1,0x102802A2,"Dell GeForce GTX 460M" },
{ 0x10DE0DD1,0x1028048F,"Dell GeForce GTX 460M" },
{ 0x10DE0DD1,0x10280490,"Dell GeForce GTX 460M" },
{ 0x10DE0DD8,0x10DE084A,"nVidia Quadro 2000" }, // mauriziopasotti
{ 0x10DE0DD8,0x10DE0914,"nVidia Quadro 2000 D" },
// 0DE0 - 0DEF
{ 0x10DE0DE0,0x10DE0828,"nVidia GeForce GT 440" },
{ 0x10DE0DE1,0x38421430,"EVGA GeForce GT 430" },
{ 0x10DE0DE9,0x10250487,"Acer GeForce GT 630M" },
{ 0x10DE0DE9,0x10250488,"Acer GeForce GT 630M" },
{ 0x10DE0E22,0x14622381,"MSi GeForce GTX 460" },
{ 0x10DE0E22,0x19DA1166,"Zotac GeForce GTX 460" },
{ 0x10DE0E22,0x19DA2166,"Zotac GeForce GTX 460" }, // Fabio71
{ 0x10DE0E22,0x38421370,"GeForce GTX 460" },
{ 0x10DE0E22,0x38421373,"GeForce GTX 460" },
{ 0x10DE0E22,0x38421362,"EVGA GeForce GTX 460" },
{ 0x10DE0E22,0x38421370,"EVGA GeForce GTX 460" },
{ 0x10DE0E22,0x38421372,"EVGA GeForce GTX 460" },
{ 0x10DE0E22,0x38421373,"EVGA GeForce GTX 460" },
{ 0x10DE0E22,0x38421380,"EVGA GeForce GTX 460" },
{ 0x10DE0E23,0x10B00401,"Gainward GeForce GTX 460" },
// 0E30 - 0E3F
// 0E40 - 0E4F
// 1060 - 106F
// 1070 - 107F
// 1080 - 108F
{ 0x10DE1080,0x104383BB,"Asus GeForce GTX 580" },
{ 0x10DE1080,0x14622550,"MSi GeForce GTX 580" },
{ 0x10DE1080,0x196E086A,"PNY GeForce GTX 580" },
{ 0x10DE1080,0x19DA2203,"Zotac GeForce GTX 580" },
{ 0x10DE1080,0x38421582,"EVGA GeForce GTX 580" },
{ 0x10DE1080,0x38421584,"EVGA GeForce GTX 580" },
{ 0x10DE1081,0x10438383,"Asus GeForce GTX 570" },
{ 0x10DE1081,0x10DE087E,"nVidia GeForce GTX 570" },
{ 0x10DE1081,0x14583513,"GigaByte GeForce GTX 570" },
{ 0x10DE1081,0x14622551,"MSi GeForce GTX 570" },
{ 0x10DE1081,0x38421570,"EVGA GeForce GTX 570" },
{ 0x10DE1081,0x38421572,"EVGA GeForce GTX 570" },
{ 0x10DE1082,0x10DE0873,"nVidia GeForce GTX 560 Ti" },
{ 0x10DE1084,0x16423A96,"Bitland GeForce GTX 560" },
{ 0x10DE1086,0x10438387,"Asus GeForce GTX 570" },
{ 0x10DE1086,0x10DE0871,"Inno3D GeForce GTX 570" },
{ 0x10DE1086,0x14583513,"GigaByte GeForce GTX 570" },
{ 0x10DE1086,0x14622224,"MSi GeForce GTX 570" },
{ 0x10DE1086,0x174B1207,"PC Partner GeForce GTX 570" },
{ 0x10DE1086,0x196E0871,"PNY GeForce GTX 570" },
{ 0x10DE1086,0x19DA1207,"Zotac GeForce GTX 570" },
{ 0x10DE1086,0x38421571,"EVGA GeForce GTX 570" },
{ 0x10DE1086,0x38421573,"EVGA GeForce GTX 570" },
{ 0x10DE1087,0x104383D6,"Asus ENGTX560Ti448 DCII" },
{ 0x10DE1087,0x19DA2207,"Zotac GeForce GTX 560 Ti-448" },
{ 0x10DE1087,0x38422066,"EVGA GeForce GTX 560 Ti-448" },
// 1090 - 109F
{ 0x10DE1091,0x10DE0887,"nVidia Tesla M2090" },
{ 0x10DE1091,0x10DE088E,"nVidia Tesla X2090" },
{ 0x10DE1180,0x1458353C,"GV-N680OC-2GD WindForce GTX 680 OC" },
{ 0x10DE1180,0x15691180,"Palit GTX 680 JetStream" },
{ 0x10DE1180,0x19DA1255,"Zotac GTX 680" },
{ 0x10DE1180,0x38421582,"EVGA GTX 680" },
{ 0x10DE1180,0x38422680,"EVGA GTX 680" },
{ 0x10DE1180,0x38422682,"EVGA GTX 680 SC" },
{ 0x10DE1180,0x10DE097A,"nVidia GeForce GTX 680" },
// 11E0 - 11EF
// 11F0 - 11FF
// 1200 - 120F
{ 0x10DE1200,0x1043838B,"Asus GeForce GTX 560 Ti" },
{ 0x10DE1200,0x14622601,"MSi GeForce GTX 560 Ti" },
{ 0x10DE1200,0x196E0898,"PNY GeForce GTX 560 Ti" },
{ 0x10DE1200,0x38421568,"EVGA GeForce GTX 560 Ti" },
{ 0x10DE1201,0x104383B4,"Asus GeForce GTX 560" },
{ 0x10DE1201,0x10DE0895,"nVidia GeForce GTX 560" },
{ 0x10DE1201,0x14622383,"MSi GeForce GTX 560" },
{ 0x10DE1206,0x10DE0958,"nVidia GeForce GTX 555" },
{ 0x10DE1210,0x10431487,"Asus GeForce GTX 570M" },
{ 0x10DE1210,0x10432104,"Asus GeForce GTX 570M" },
{ 0x10DE1210,0x146210BD,"MSi GeForce GTX 570M" },
{ 0x10DE1211,0x10280490,"Dell GeForce GTX 580M" },
{ 0x10DE1241,0x10DE091D,"nVidia GeForce GT 545" },
{ 0x10DE1244,0x104383BC,"Asus GeForce GTX 550 Ti" },
{ 0x10DE1244,0x1458351A,"GigaByte GeForce GTX 550 Ti" },
{ 0x10DE1244,0x19DA5194,"Zotac GeForce GTX 550 Ti" },
{ 0x10DE1244,0x38421556,"EVGA GeForce GTX 550 Ti" },
{ 0x10DE1247,0x10431407,"Asus GeForce GT 555M" },
{ 0x10DE1247,0x10431752,"Asus GeForce GT 635M" },
{ 0x10DE1247,0x10432050,"Asus GeForce GT 555M" },
{ 0x10DE0848,NV_SUB_IDS,"GeForce 8300" },
{ 0x10DE0849,NV_SUB_IDS,"GeForce 8200" },
{ 0x10DE084A,NV_SUB_IDS,"nForce 730a" },
{ 0x10DE084B,NV_SUB_IDS,"GeForce 9200" },
{ 0x10DE084B,NV_SUB_IDS,"GeForce 9200" }, // nVidia GeForce 8200 ??
{ 0x10DE084C,NV_SUB_IDS,"nForce 980a/780a SLI" },
{ 0x10DE084D,NV_SUB_IDS,"nForce 750a SLI" },
{ 0x10DE084F,NV_SUB_IDS,"GeForce 8100 / nForce 720a" },
{ 0x10DE1091,NV_SUB_IDS,"nVidia Tesla M2090" },
{ 0x10DE1094,NV_SUB_IDS,"Tesla M2075 Dual-Slot Computing Processor Module" },
{ 0x10DE1096,NV_SUB_IDS,"Tesla C2075" },
// { 0x10DE1098,NV_SUB_IDS,"D13U" },
{ 0x10DE1098,NV_SUB_IDS,"D13U" },
{ 0x10DE109A,NV_SUB_IDS,"Quadro 5010M" },
{ 0x10DE109B,NV_SUB_IDS,"Quadro 7000" },
// 10A0 - 10AF
static char *get_nvidia_model(uint32_t device_id, uint32_t subsys_id)
{
int i;
for (i = 1; i < (sizeof(nvidia_cards) / sizeof(nvidia_cards[0])); i++) // size of NVKnowChipsets array for-loop
for (i = 1; i < (sizeof(nvidia_cards) / sizeof(nvidia_cards[0])); i++) // size of nvidia_cards array for-loop
{
if ((nvidia_cards[i].device == device_id) && (nvidia_cards[i].subdev == subsys_id))
{
return 0;
if (devices_number == 1)
{
if (!DP_ADD_TEMP_VAL(device, nvidia_device_type))
if (!DP_ADD_TEMP_VAL(device, nvidia_device_type_parent))
return 0;
}
else
// Workaround for 9600M GT, GT 210/420/430/440/525M/540M & GTX 560M
switch (nvda_dev->device_id)
{
case 0x0647: vram_size = 512*1024*1024; break;// 9600M GT 0647
//case 0x0649: vram_size = 1024*1024*1024; break;// 9600M GT 0649
case 0x0A65: vram_size = 1024*1024*1024; break; // GT 210
case 0x0DE0: vram_size = 1024*1024*1024; break; // GT 440
case 0x0DE1: vram_size = 1024*1024*1024; break; // GT 430
case 0x0DE2: vram_size = 1024*1024*1024; break; // GT 420
case 0x0DEC: vram_size = 1024*1024*1024; break; // GT 525M 0DEC
case 0x0DF4: vram_size = 1024*1024*1024; break; // GT 540M
case 0x0DF5: vram_size = 1024*1024*1024; break; // GT 525M 0DF5
case 0x1251: vram_size = 1536*1024*1024; break; // GTX 560M
default: break;
case 0x0647: // 9600M GT 0647
vram_size = 512*1024*1024;
break;
/*case 0x0649:// 9600M GT 0649
vram_size = 1024*1024*1024;
break;*/
case 0x0A65: // GT 210
case 0x0DE0: // GT 440
case 0x0DE1: // GT 430
case 0x0DE2: // GT 420
case 0x0DEC: // GT 525M 0DEC
case 0x0DF4: // GT 540M
case 0x0DF5: // GT 525M 0DF5
vram_size = 1024*1024*1024;
break;
case 0x1251: // GTX 560M
vram_size = 1536*1024*1024;
break;
default:
break;
}
return vram_size;
//http://forge.voodooprojects.org/p/chameleon/issues/67/
if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit)
{
static uint8_t connector_type_1[]= {0x00, 0x08, 0x00, 0x00};
static uint8_t connector_type_1[]= {0x00, 0x08, 0x00, 0x00};
devprop_add_value(device, "@1,connector-type",connector_type_1, 4);
}
//end Nvidia HDMI Audio
branches/ErmaC/Trunk/i386/libsaio/ati.c
278278
279279
280280
281
281282
282283
283284
......
412413
413414
414415
416
415417
416418
417419
{ 0x9505,0x3010174B, CHIP_FAMILY_RV670,"ATI Radeon HD 4750", kNull},
{ 0x9505,0x301017AF, CHIP_FAMILY_RV670,"ATI Radeon HD 4750", kNull},
{ 0x9505,0x4730174B, CHIP_FAMILY_RV670,"ATI Radeon HD 4730", kNull},
{ 0x9505,0xE630174B, CHIP_FAMILY_RV670,"ATI Radeon HD 3800 Series", kNull},
{ 0x9540,0x30501787, CHIP_FAMILY_RV710,"ATI Radeon HD 4590", kNull},
{ 0x9540,0x4590174B, CHIP_FAMILY_RV710,"ATI Radeon HD 4590", kNull},
{ 0x689C,0x034A1043, CHIP_FAMILY_HEMLOCK,"ATI Radeon HD 5970", kUakari},
{ 0x689C,0x03521043, CHIP_FAMILY_HEMLOCK,"ASUS ARES", kUakari},
{ 0x689C,0x039E1043, CHIP_FAMILY_HEMLOCK,"ASUS EAH5870", kUakari},
{ 0x689C,0x25421002, CHIP_FAMILY_HEMLOCK,"ATI Radeon HD 5970", kUakari},
{ 0x689C,0x30201682, CHIP_FAMILY_HEMLOCK,"ATI Radeon HD 5970", kUakari},
{ 0x68A0,0x03081025, CHIP_FAMILY_CYPRESS,"ATI Mobility Radeon HD 5830",kNomascus},
branches/ErmaC/Trunk/i386/libsaio/nvidia.h
6565
6666
6767
68
68
69
6970
7071
7172
7273
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
7391
7492
7593
#define DCB_LOC_ON_CHIP 0
struct bios {
struct bios
{
uint16_tsignature;/* 0x55AA */
uint8_tsize;/* Size in multiples of 512 */
};
#define NVIDIA_ROM_SIZE0x10000
#define PATCH_ROM_SUCCESS1
#define PATCH_ROM_SUCCESS_HAS_LVDS2
#define PATCH_ROM_FAILED0
#define MAX_NUM_DCB_ENTRIES16
#define TYPE_GROUPED0xff
#define READ_BYTE(rom, offset) (*(u_char *)(rom + offset))
#define READ_LE_SHORT(rom, offset) (READ_BYTE(rom, offset+1) << 8 | READ_BYTE(rom, offset))
#define READ_LE_INT(rom, offset) (READ_LE_SHORT(rom, offset+2) << 16 | READ_LE_SHORT(rom, offset))
#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))
#define NVCAP_LEN ( sizeof(default_NVCAP) / sizeof(uint8_t) )
#define NVPM_LEN ( sizeof(default_NVPM) / sizeof(uint8_t) )
#define DCFG0_LEN ( sizeof(default_dcfg_0) / sizeof(uint8_t) )
#define DCFG1_LEN ( sizeof(default_dcfg_1) / sizeof(uint8_t) )
#define NV_SUB_IDS0x00000000
#define NV_PMC_OFFSET0x000000
#define NV_PMC_SIZE0x2ffff
branches/ErmaC/Trunk/i386/libsaio/disk.c
10221022
10231023
10241024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
10361036
1037
1037
10381038
1039
1039
10401040
10411041
10421042
10431043
10441044
10451045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
10681080
1069
1070
1081
1082
1083
10711084
1072
1073
1074
1075
1076
1077
1078
1085
1086
1087
1088
1089
1090
1091
10791092
1080
1081
1082
1083
1084
1093
1094
1095
1096
1097
10851098
1086
1087
1099
1100
1101
10881102
1089
1090
1091
1103
1104
1105
1106
10921107
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
11031119
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
11261143
1127
1144
11281145
1129
1146
11301147
1131
1148
11321149
11331150
11341151
......
11401157
11411158
11421159
1143
1144
1145
1160
1161
1162
11461163
1147
1148
1149
1150
1164
1165
1166
1167
11511168
1152
1153
1154
1155
1169
1170
11561171
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
11891213
1190
1191
1214
1215
11921216
11931217
11941218
11951219
1196
1197
1198
1220
1221
1222
11991223
1200
1224
12011225
12021226
12031227
12041228
12051229
12061230
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
12201245
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
12321257
1233
1234
1235
1236
1258
1259
1260
1261
12371262
1238
1239
1263
1264
12401265
1241
1242
1266
1267
12431268
1244
1269
12451270
1246
1271
12471272
1248
1249
1250
1251
1273
1274
1275
1276
12521277
1253
1278
12541279
1255
1256
1280
1281
12571282
1258
1259
1260
1261
1283
1284
1285
1286
12621287
1263
1264
1265
1266
1288
1289
1290
1291
12671292
1268
1293
12691294
1270
1295
12711296
1272
1273
1274
1275
1297
1298
1299
1300
12761301
1277
1302
12781303
1279
1280
1281
1282
1283
1284
1304
1305
1306
1307
1308
1309
12851310
1286
1287
1288
1289
1311
1312
1313
1314
12901315
1291
1292
1293
1294
1316
1317
1318
1319
12951320
1296
1297
1298
1321
1322
1323
12991324
1300
1301
1302
1303
1325
1326
1327
1328
13041329
1305
1306
1330
1331
13071332
1308
1333
13091334
1310
1311
1312
1313
1314
1315
1316
1335
1336
1337
1338
1339
1340
1341
13171342
1318
1319
1343
1344
13201345
1321
1322
1323
1324
1325
1326
1327
1346
1347
1348
1349
13281350
1329
1330
1351
1352
13311353
1332
1333
1334
1335
1336
1354
1355
13371356
1338
1339
1357
1358
1359
1360
1361
13401362
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1363
1364
13601365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
13611386
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
13771397
1378
1379
1380
1381
1382
1383
1384
1385
1398
1399
1400
1401
1402
13861403
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1404
1405
1406
1407
1408
1409
14081410
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1411
14241412
1425
1426
1427
1428
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
14291434
1430
1431
1432
1433
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
14341450
1435
1436
1437
1438
1451
14391452
1440
1441
1453
14421454
1443
1444
1455
1456
14451457
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
14561486
14571487
14581488
......
14731503
14741504
14751505
1476
1506
14771507
1478
1508
14791509
14801510
14811511
......
15011531
15021532
15031533
1504
1505
1506
1507
1508
1509
1534
1535
1536
1537
1538
1539
15101540
1511
1512
1513
1514
1541
1542
1543
1544
15151545
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
15351565
1536
1566
15371567
1538
1539
1540
1541
1542
1543
1544
1568
1569
1570
1571
1572
1573
1574
15451575
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
15571587
1558
1588
15591589
15601590
15611591
......
15691599
15701600
15711601
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
15931626
15941627
15951628
15961629
15971630
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
16081642
16091643
16101644
16111645
1612
1613
1614
1646
1647
1648
16151649
1616
1650
16171651
1618
1619
1620
1621
1622
1623
1652
1653
1654
1655
1656
1657
1658
1659
16241660
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
16421683
16431684
16441685
16451686
1646
1647
1687
1688
16481689
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
16591700
16601701
16611702
16621703
1663
1664
1665
1666
1704
1705
1706
1707
16671708
1668
1669
1709
1710
16701711
1671
1672
1673
1712
1713
1714
16741715
1675
1676
1677
1678
1679
1716
1717
1718
1719
1720
16801721
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
16931734
1694
1695
1696
1697
1698
1735
1736
1737
1738
1739
1740
1741
1742
1743
16991744
1700
1701
1702
1703
1704
1745
1746
1747
1748
1749
17051750
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1751
1752
1753
1754
1755
1756
1757
17291758
1730
1731
1732
1733
1734
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
17351778
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1779
1780
1781
1782
1783
1784
1785
17461786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
17471802
1748
1749
1750
1751
1752
1753
1803
1804
1805
1806
1807
1808
17541809
17551810
1756
1757
1758
1759
1811
1812
1813
1814
17601815
17611816
17621817
17631818
1764
1765
1766
1819
1820
1821
17671822
1768
1769
1770
1823
1824
1825
17711826
1772
1773
1774
1775
1776
1777
1778
1779
1780
1827
1828
1829
1830
1831
1832
1833
1834
1835
17811836
1782
1783
1784
1785
1837
1838
1839
1840
17861841
17871842
17881843
......
18141869
18151870
18161871
1872
18171873
1818
1874
1875
18191876
1877
18201878
1879
1880
1881
1882
1883
1884
18211885
1822
1823
1824
1825
1886
1887
1888
1889
1890
1891
18261892
1827
1828
1829
1830
1831
1832
1893
1894
1895
1896
1897
1898
1899
18331900
1834
1835
1836
1837
1838
1839
1840
1841
1842
1901
18431902
18441903
18451904
......
18491908
18501909
18511910
1852
1911
18531912
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
18671930
1868
1869
1870
1871
1872
1873
1874
1931
1932
1933
1934
1935
1936
1937
18751938
1876
1877
1878
1939
1940
1941
1942
1943
18791944
1880
1881
1882
1945
1946
1947
1948
1949
18831950
1884
1885
1886
1887
1888
1889
1890
1891
1951
1952
1953
1954
1955
1956
1957
1958
18921959
1893
1894
1960
1961
18951962
18961963
18971964
18981965
1899
1900
1966
1967
19011968
1902
1903
1904
1905
1969
1970
1971
1972
19061973
1907
1908
1909
1910
1911
1974
19121975
1913
1914
1915
1916
1917
1976
1977
1978
1979
1980
19181981
1919
1920
1921
1922
1923
1982
1983
1984
1985
1986
19241987
1925
1926
1927
1928
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
19291999
1930
2000
19312001
1932
2002
19332003
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
2004
2005
2006
19452007
1946
1947
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
19482025
19492026
19502027
......
19802057
19812058
19822059
1983
2060
19842061
19852062
19862063
19872064
1988
1989
1990
1991
1992
2065
2066
2067
2068
2069
19932070
19942071
19952072
19962073
1997
1998
2074
2075
19992076
2000
2001
2002
2003
2004
2005
2006
2007
2008
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
20092089
2010
2011
2012
2013
2014
2015
2090
2091
2092
2093
2094
2095
2096
20162097
20172098
20182099
......
20202101
20212102
20222103
2023
2024
2104
2105
20252106
20262107
20272108
......
20292110
20302111
20312112
2032
2033
2034
2035
2036
2113
2114
2115
2116
2117
20372118
20382119
20392120
20402121
2041
2042
2043
2044
2122
2123
2124
2125
20452126
2046
2047
2048
2049
2050
2127
2128
2129
2130
2131
2132
20512133
2052
2134
20532135
2054
2055
2056
2057
2136
2137
2138
2139
2140
20582141
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
20742159
2075
2160
20762161
20772162
20782163
......
20822167
20832168
20842169
2085
2086
2087
2088
2089
2170
2171
2172
2173
2174
2175
20902176
2091
2177
20922178
2093
2094
2095
2096
2179
2180
2181
2182
2183
20972184
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2185
2186
2187
2188
2189
2190
2191
2192
21102193
2111
2194
2195
2196
2197
2198
2199
2200
21122201
21132202
21142203
map->bvrcnt++;
}
#endif
// Actually this should always be true given the above code
if(map == gDiskBVMap)
{
// Don't leave a null map in the chain
if(map->bvrcnt == 0 && map->bvr == NULL)
{
gDiskBVMap = map->next;
free(map);
map = NULL;
}
}
// Actually this should always be true given the above code
if(map == gDiskBVMap)
{
// Don't leave a null map in the chain
if(map->bvrcnt == 0 && map->bvr == NULL)
{
gDiskBVMap = map->next;
free(map);
map = NULL;
}
}
if (countPtr) *countPtr = map ? map->bvrcnt : 0;
if (countPtr) *countPtr = map ? map->bvrcnt : 0;
return map ? map->bvr : NULL;
return map ? map->bvr : NULL;
}
//==========================================================================
static BVRef diskScanAPMBootVolumes( int biosdev, int * countPtr )
{
struct DiskBVMap * map;
struct Block0 *block0_p;
unsigned int blksize;
unsigned int factor;
void *buffer = malloc(BPS);
/* Check for alternate block size */
if (readBytes( biosdev, 0, 0, BPS, buffer ) != 0) {
return NULL;
}
block0_p = buffer;
if (OSSwapBigToHostInt16(block0_p->sbSig) == BLOCK0_SIGNATURE) {
blksize = OSSwapBigToHostInt16(block0_p->sbBlkSize);
if (blksize != BPS) {
free(buffer);
buffer = malloc(blksize);
}
factor = blksize / BPS;
} else {
blksize = BPS;
factor = 1;
}
struct DiskBVMap * map;
struct Block0 *block0_p;
unsigned int blksize;
unsigned int factor;
void *buffer = malloc(BPS);
if (!buffer)
{
return NULL;
}
/* Check for alternate block size */
if (readBytes( biosdev, 0, 0, BPS, buffer ) != 0)
{
return NULL;
}
block0_p = buffer;
if (OSSwapBigToHostInt16(block0_p->sbSig) == BLOCK0_SIGNATURE)
{
blksize = OSSwapBigToHostInt16(block0_p->sbBlkSize);
if (blksize != BPS)
{
free(buffer);
buffer = malloc(blksize);
if (!buffer)
{
return NULL;
}
}
factor = blksize / BPS;
}
else
{
blksize = BPS;
factor = 1;
}
do {
// Create a new mapping.
do
{
// Create a new mapping.
map = (struct DiskBVMap *) malloc( sizeof(*map) );
if ( map )
{
int error;
DPME *dpme_p = (DPME *)buffer;
UInt32 i, npart = UINT_MAX;
BVRef bvr;
map = (struct DiskBVMap *) malloc( sizeof(*map) );
if ( map )
{
int error;
DPME *dpme_p = (DPME *)buffer;
UInt32 i, npart = UINT_MAX;
BVRef bvr;
map->biosdev = biosdev;
map->bvr = NULL;
map->bvrcnt = 0;
map->next = gDiskBVMap;
gDiskBVMap = map;
map->biosdev = biosdev;
map->bvr = NULL;
map->bvrcnt = 0;
map->next = gDiskBVMap;
gDiskBVMap = map;
for (i=0; i<npart; i++) {
error = readBytes( biosdev, (kAPMSector + i) * factor, 0, blksize, buffer );
for (i=0; i<npart; i++)
{
error = readBytes( biosdev, (kAPMSector + i) * factor, 0, blksize, buffer );
if (error || OSSwapBigToHostInt16(dpme_p->dpme_signature) != DPME_SIGNATURE) {
break;
}
if (error || OSSwapBigToHostInt16(dpme_p->dpme_signature) != DPME_SIGNATURE)
{
break;
}
if (i==0) {
npart = OSSwapBigToHostInt32(dpme_p->dpme_map_entries);
}
/*
printf("name = %s, %s%s %d -> %d [%d -> %d] {%d}\n",
dpme.dpme_name, dpme.dpme_type, (dpme.dpme_flags & DPME_FLAGS_BOOTABLE) ? "(bootable)" : "",
dpme.dpme_pblock_start, dpme.dpme_pblocks,
dpme.dpme_lblock_start, dpme.dpme_lblocks,
dpme.dpme_boot_block);
*/
if (i==0)
{
npart = OSSwapBigToHostInt32(dpme_p->dpme_map_entries);
}
/*
printf("name = %s, %s%s %d -> %d [%d -> %d] {%d}\n",
dpme.dpme_name, dpme.dpme_type, (dpme.dpme_flags & DPME_FLAGS_BOOTABLE) ? "(bootable)" : "",
dpme.dpme_pblock_start, dpme.dpme_pblocks,
dpme.dpme_lblock_start, dpme.dpme_lblocks,
dpme.dpme_boot_block);
*/
if (strcmp(dpme_p->dpme_type, "Apple_HFS") == 0) {
bvr = newAPMBVRef(biosdev,
i,
OSSwapBigToHostInt32(dpme_p->dpme_pblock_start) * factor,
dpme_p,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
bvr->next = map->bvr;
map->bvr = bvr;
map->bvrcnt++;
}
}
}
} while (0);
if (strcmp(dpme_p->dpme_type, "Apple_HFS") == 0)
{
bvr = newAPMBVRef(biosdev,
i,
OSSwapBigToHostInt32(dpme_p->dpme_pblock_start) * factor,
dpme_p,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
bvr->next = map->bvr;
map->bvr = bvr;
map->bvrcnt++;
}
}
}
} while (0);
free(buffer);
free(buffer);
if (countPtr) *countPtr = map ? map->bvrcnt : 0;
if (countPtr) *countPtr = map ? map->bvrcnt : 0;
return map ? map->bvr : NULL;
return map ? map->bvr : NULL;
}
//==========================================================================
*/
static int probeFileSystem(int biosdev, unsigned int blkoff)
{
// detected filesystem type;
int result = -1;
int fatbits;
// detected filesystem type;
int result = -1;
int fatbits;
// Allocating buffer for 4 sectors.
const void * probeBuffer = malloc(PROBEFS_SIZE);
if (probeBuffer == NULL)
goto exit;
// Allocating buffer for 4 sectors.
const void * probeBuffer = malloc(PROBEFS_SIZE);
if (probeBuffer == NULL)
goto exit;
// Reading first 4 sectors of current partition
int error = readBytes(biosdev, blkoff, 0, PROBEFS_SIZE, (void *)probeBuffer);
if (error)
goto exit;
// Reading first 4 sectors of current partition
int error = readBytes(biosdev, blkoff, 0, PROBEFS_SIZE, (void *)probeBuffer);
if (HFSProbe(probeBuffer))
result = FDISK_HFS;
else if (EX2Probe(probeBuffer))
result = FDISK_LINUX;
else if (FreeBSDProbe(probeBuffer))
result = FDISK_FREEBSD;
else if (OpenBSDProbe(probeBuffer))
result = FDISK_OPENBSD;
else if (NTFSProbe(probeBuffer))
result = FDISK_NTFS;
else if (BeFSProbe(probeBuffer))
result = FDISK_BEFS;
else if ( (fatbits = MSDOSProbe(probeBuffer)) )
{
switch (fatbits)
{
case 32:
default:
result = FDISK_FAT32;
break;
case 16:
result = FDISK_DOS16B;
break;
case 12:
result = FDISK_DOS12;
break;
}
}
else
// Couldn't detect filesystem type
result = 0;
if (error)
goto exit;
if (HFSProbe(probeBuffer))
result = FDISK_HFS;
else if (EX2Probe(probeBuffer))
result = FDISK_LINUX;
else if (FreeBSDProbe(probeBuffer))
result = FDISK_FREEBSD;
else if (OpenBSDProbe(probeBuffer))
result = FDISK_OPENBSD;
else if (NTFSProbe(probeBuffer))
result = FDISK_NTFS;
else if (BeFSProbe(probeBuffer))
result = FDISK_BEFS;
else if ( (fatbits = MSDOSProbe(probeBuffer)) )
{
switch (fatbits)
{
case 32:
default:
result = FDISK_FAT32;
break;
case 16:
result = FDISK_DOS16B;
break;
case 12:
result = FDISK_DOS12;
break;
}
}
else
// Couldn't detect filesystem type
result = 0;
exit:
if (probeBuffer != NULL) free((void *)probeBuffer);
return result;
if (probeBuffer != NULL) free((void *)probeBuffer);
return result;
}
static bool isPartitionUsed(gpt_ent * partition)
{
//
// Ask whether the given partition is used.
//
//
// Ask whether the given partition is used.
//
return efi_guid_is_null((EFI_GUID const*)partition->ent_type) ? false : true;
return efi_guid_is_null((EFI_GUID const*)partition->ent_type) ? false : true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static BVRef diskScanGPTBootVolumes( int biosdev, int * countPtr )
{
struct DiskBVMap * map = NULL;
void *buffer = malloc(BPS);
int error;
if ( (error = readBytes( biosdev, /*secno*/0, 0, BPS, buffer )) != 0) {
verbose("Failed to read boot sector from BIOS device %02xh. Error=%d\n", biosdev, error);
goto scanErr;
}
struct REAL_disk_blk0 *fdiskMap = buffer;
if ( OSSwapLittleToHostInt16(fdiskMap->signature) != DISK_SIGNATURE )
{
verbose("Failed to find boot signature on BIOS device %02xh\n", biosdev);
goto scanErr;
}
struct DiskBVMap * map = NULL;
void *buffer = malloc(BPS);
int error;
if ( (error = readBytes( biosdev, /*secno*/0, 0, BPS, buffer )) != 0)
{
verbose("Failed to read boot sector from BIOS device %02xh. Error=%d\n", biosdev, error);
goto scanErr;
}
struct REAL_disk_blk0 *fdiskMap = buffer;
if ( OSSwapLittleToHostInt16(fdiskMap->signature) != DISK_SIGNATURE )
{
verbose("Failed to find boot signature on BIOS device %02xh\n", biosdev);
goto scanErr;
}
int fdiskID = 0;
unsigned index;
for ( index = 0; index < FDISK_NPART; index++ )
{
if ( fdiskMap->parts[index].systid )
{
if ( fdiskMap->parts[index].systid == 0xEE )
{
// Fail if two 0xEE partitions are present which
// means the FDISK code will wind up parsing it.
if ( fdiskID ) goto scanErr;
int fdiskID = 0;
unsigned index;
for ( index = 0; index < FDISK_NPART; index++ )
{
if ( fdiskMap->parts[index].systid )
{
if ( fdiskMap->parts[index].systid == 0xEE )
{
// Fail if two 0xEE partitions are present which
// means the FDISK code will wind up parsing it.
if ( fdiskID ) goto scanErr;
fdiskID = index + 1;
}
}
}
fdiskID = index + 1;
}
}
}
if ( fdiskID == 0 ) goto scanErr;
verbose("Attempting to read GPT\n");
if ( fdiskID == 0 ) goto scanErr;
verbose("Attempting to read GPT\n");
if(readBytes(biosdev, 1, 0, BPS, buffer) != 0)
goto scanErr;
if(readBytes(biosdev, 1, 0, BPS, buffer) != 0)
goto scanErr;
gpt_hdr *headerMap = buffer;
gpt_hdr *headerMap = buffer;
// Determine whether the partition header signature is present.
// Determine whether the partition header signature is present.
if ( memcmp(headerMap->hdr_sig, GPT_HDR_SIG, strlen(GPT_HDR_SIG)) )
{
goto scanErr;
}
if ( memcmp(headerMap->hdr_sig, GPT_HDR_SIG, strlen(GPT_HDR_SIG)) )
{
goto scanErr;
}
// Determine whether the partition header size is valid.
// Determine whether the partition header size is valid.
UInt32 headerCheck = OSSwapLittleToHostInt32(headerMap->hdr_crc_self);
UInt32 headerSize = OSSwapLittleToHostInt32(headerMap->hdr_size);
UInt32 headerCheck = OSSwapLittleToHostInt32(headerMap->hdr_crc_self);
UInt32 headerSize = OSSwapLittleToHostInt32(headerMap->hdr_size);
if ( headerSize < offsetof(gpt_hdr, padding) )
{
goto scanErr;
}
if ( headerSize < offsetof(gpt_hdr, padding) )
{
goto scanErr;
}
if ( headerSize > BPS )
{
goto scanErr;
}
if ( headerSize > BPS )
{
goto scanErr;
}
// Determine whether the partition header checksum is valid.
// Determine whether the partition header checksum is valid.
headerMap->hdr_crc_self = 0;
headerMap->hdr_crc_self = 0;
if ( crc32(0, headerMap, headerSize) != headerCheck )
{
goto scanErr;
}
if ( crc32(0, headerMap, headerSize) != headerCheck )
{
goto scanErr;
}
// Determine whether the partition entry size is valid.
// Determine whether the partition entry size is valid.
UInt64 gptBlock = 0;
UInt32 gptCheck = 0;
UInt32 gptCount = 0;
UInt32 gptID = 0;
gpt_ent * gptMap = 0;
UInt32 gptSize = 0;
UInt64 gptBlock = 0;
UInt32 gptCheck = 0;
UInt32 gptCount = 0;
UInt32 gptID = 0;
gpt_ent * gptMap = 0;
UInt32 gptSize = 0;
gptBlock = OSSwapLittleToHostInt64(headerMap->hdr_lba_table);
gptCheck = OSSwapLittleToHostInt32(headerMap->hdr_crc_table);
gptCount = OSSwapLittleToHostInt32(headerMap->hdr_entries);
gptSize = OSSwapLittleToHostInt32(headerMap->hdr_entsz);
gptBlock = OSSwapLittleToHostInt64(headerMap->hdr_lba_table);
gptCheck = OSSwapLittleToHostInt32(headerMap->hdr_crc_table);
gptCount = OSSwapLittleToHostInt32(headerMap->hdr_entries);
gptSize = OSSwapLittleToHostInt32(headerMap->hdr_entsz);
if ( gptSize < sizeof(gpt_ent) )
{
goto scanErr;
}
if ( gptSize < sizeof(gpt_ent) )
{
goto scanErr;
}
// Allocate a buffer large enough to hold one map, rounded to a media block.
free(buffer);
buffer = NULL;
// Allocate a buffer large enough to hold one map, rounded to a media block.
free(buffer);
buffer = NULL;
UInt32 bufferSize = IORound(gptCount * gptSize, BPS);
if(bufferSize == 0)
goto scanErr;
buffer = malloc(bufferSize);
UInt32 bufferSize = IORound(gptCount * gptSize, BPS);
if (bufferSize == 0)
goto scanErr;
buffer = malloc(bufferSize);
if(readBytes(biosdev, gptBlock, 0, bufferSize, buffer) != 0)
goto scanErr;
if (readBytes(biosdev, gptBlock, 0, bufferSize, buffer) != 0)
goto scanErr;
verbose("Read GPT\n");
verbose("Read GPT\n");
// Allocate a new map for this BIOS device and insert it into the chain
map = malloc(sizeof(*map));
map->biosdev = biosdev;
map->bvr = NULL;
map->bvrcnt = 0;
map->next = gDiskBVMap;
gDiskBVMap = map;
// Allocate a new map for this BIOS device and insert it into the chain
map = malloc(sizeof(*map));
map->biosdev = biosdev;
map->bvr = NULL;
map->bvrcnt = 0;
map->next = gDiskBVMap;
gDiskBVMap = map;
// fdisk like partition type id.
int fsType = 0;
// fdisk like partition type id.
int fsType = 0;
for(gptID = 1; gptID <= gptCount; ++gptID)
{
BVRef bvr = NULL;
unsigned int bvrFlags = 0;
// size on disk can be larger than sizeof(gpt_ent)
gptMap = (gpt_ent *) ( buffer + ( (gptID - 1) * gptSize) );
for(gptID = 1; gptID <= gptCount; ++gptID)
{
BVRef bvr = NULL;
unsigned int bvrFlags = 0;
// NOTE: EFI_GUID's are in LE and we know we're on an x86.
// The IOGUIDPartitionScheme.cpp code uses byte-based UUIDs, we don't.
// size on disk can be larger than sizeof(gpt_ent)
gptMap = (gpt_ent *) ( buffer + ( (gptID - 1) * gptSize) );
if (isPartitionUsed(gptMap))
{
char stringuuid[100];
efi_guid_unparse_upper((EFI_GUID*)gptMap->ent_type, stringuuid);
verbose("Reading GPT partition %d, type %s\n", gptID, stringuuid);
// NOTE: EFI_GUID's are in LE and we know we're on an x86.
// The IOGUIDPartitionScheme.cpp code uses byte-based UUIDs, we don't.
// Getting fdisk like partition type.
fsType = probeFileSystem(biosdev, gptMap->ent_lba_start);
if (isPartitionUsed(gptMap))
{
char stringuuid[100];
efi_guid_unparse_upper((EFI_GUID*)gptMap->ent_type, stringuuid);
verbose("Reading GPT partition %d, type %s\n", gptID, stringuuid);
if ( (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ||
(efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
{
bvrFlags = (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ? kBVFlagBooter : 0;
bvr = newGPTBVRef(biosdev,
gptID,
gptMap->ent_lba_start,
gptMap,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, bvrFlags);
}
// Getting fdisk like partition type.
fsType = probeFileSystem(biosdev, gptMap->ent_lba_start);
if ( (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ||
(efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
{
bvrFlags = (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ? kBVFlagBooter : 0;
bvr = newGPTBVRef(biosdev,
gptID,
gptMap->ent_lba_start,
gptMap,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, bvrFlags);
}
// zef - foreign OS support
if ( (efi_guid_compare(&GPT_BASICDATA_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ||
(efi_guid_compare(&GPT_BASICDATA2_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
{
switch (fsType)
{
case FDISK_NTFS:
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
0, 0, 0, 0, 0, 0, NTFSGetDescription,
(BVFree)free, 0, kBIOSDevTypeHardDrive, 0);
break;
case FDISK_LINUX:
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
0, 0, 0, 0, 0, 0, EX2GetDescription,
(BVFree)free, 0, kBIOSDevTypeHardDrive, 0);
break;
if ( (efi_guid_compare(&GPT_BASICDATA_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ||
(efi_guid_compare(&GPT_BASICDATA2_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
{
switch (fsType)
{
case FDISK_NTFS:
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
0, 0, 0, 0, 0, 0, NTFSGetDescription,
(BVFree)free, 0, kBIOSDevTypeHardDrive, 0);
break;
default:
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
0, 0, 0, 0, 0, 0, 0,
(BVFree)free, 0, kBIOSDevTypeHardDrive, 0);
break;
}
}
case FDISK_LINUX:
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
0, 0, 0, 0, 0, 0, EX2GetDescription,
(BVFree)free, 0, kBIOSDevTypeHardDrive, 0);
break;
// turbo - save our booter partition
// zef - only on original boot device
if ( (efi_guid_compare(&GPT_EFISYS_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
{
switch (fsType)
{
case FDISK_HFS:
if (readBootSector( biosdev, gptMap->ent_lba_start, (void *)0x7e00 ) == 0)
{
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0, kBIOSDevTypeHardDrive, kBVFlagEFISystem);
}
break;
default:
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
0, 0, 0, 0, 0, 0, 0,
(BVFree)free, 0, kBIOSDevTypeHardDrive, 0);
break;
}
case FDISK_FAT32:
if (testFAT32EFIBootSector( biosdev, gptMap->ent_lba_start, (void *)0x7e00 ) == 0)
{
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
MSDOSInitPartition,
MSDOSLoadFile,
MSDOSReadFile,
MSDOSGetDirEntry,
MSDOSGetFileBlock,
MSDOSGetUUID,
MSDOSGetDescription,
MSDOSFree,
0, kBIOSDevTypeHardDrive, kBVFlagEFISystem);
}
break;
}
if (biosdev == gBIOSDev)
gBIOSBootVolume = bvr;
}
}
// turbo - save our booter partition
// zef - only on original boot device
if ( (efi_guid_compare(&GPT_EFISYS_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
{
switch (fsType)
{
case FDISK_HFS:
if (readBootSector( biosdev, gptMap->ent_lba_start, (void *)0x7e00 ) == 0)
{
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0, kBIOSDevTypeHardDrive, kBVFlagEFISystem);
}
break;
if (bvr)
{
// Fixup bvr with the fake fdisk partition type.
if (fsType > 0) bvr->part_type = fsType;
case FDISK_FAT32:
if (testFAT32EFIBootSector( biosdev, gptMap->ent_lba_start, (void *)0x7e00 ) == 0)
{
bvr = newGPTBVRef(biosdev, gptID, gptMap->ent_lba_start, gptMap,
MSDOSInitPartition,
MSDOSLoadFile,
MSDOSReadFile,
MSDOSGetDirEntry,
MSDOSGetFileBlock,
MSDOSGetUUID,
MSDOSGetDescription,
MSDOSFree,
0, kBIOSDevTypeHardDrive, kBVFlagEFISystem);
}
break;
bvr->next = map->bvr;
map->bvr = bvr;
++map->bvrcnt;
}
if (biosdev == gBIOSDev)
}
}
gBIOSBootVolume = bvr;
scanErr:
free(buffer);
}
}
if(map)
{
if(countPtr) *countPtr = map->bvrcnt;
return map->bvr;
}
else
{
if(countPtr) *countPtr = 0;
return NULL;
}
if (bvr)
{
// Fixup bvr with the fake fdisk partition type.
if (fsType > 0) bvr->part_type = fsType;
bvr->next = map->bvr;
map->bvr = bvr;
++map->bvrcnt;
}
}
}
scanErr:
free(buffer);
if(map)
{
if(countPtr) *countPtr = map->bvrcnt;
return map->bvr;
}
else
{
if(countPtr) *countPtr = 0;
return NULL;
}
}
static bool getOSVersion(BVRef bvr, char *str)
if (!loadConfigFile(dirSpec, &systemVersion))
{
bvr->OSisServer = true;
bvr->OSisServer = true;
valid = true;
}
}
}
if (valid)
static void scanFSLevelBVRSettings(BVRef chain)
{
BVRef bvr;
char dirSpec[512], fileSpec[512];
char label[BVSTRLEN];
int ret;
long flags, time;
int fh, fileSize, error;
BVRef bvr;
char dirSpec[512], fileSpec[512];
char label[BVSTRLEN];
int ret;
long flags, time;
int fh, fileSize, error;
for (bvr = chain; bvr; bvr = bvr->next)
{
ret = -1;
error = 0;
for (bvr = chain; bvr; bvr = bvr->next)
{
ret = -1;
error = 0;
//
// Check for alternate volume label on boot helper partitions.
//
if (bvr->flags & kBVFlagBooter)
{
sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/", BIOS_DEV_UNIT(bvr), bvr->part_no);
strcpy(fileSpec, ".disk_label.contentDetails");
ret = GetFileInfo(dirSpec, fileSpec, &flags, &time);
if (!ret)
{
fh = open(strcat(dirSpec, fileSpec), 0);
fileSize = file_size(fh);
if (fileSize > 0 && fileSize < BVSTRLEN)
{
if (read(fh, label, fileSize) != fileSize)
error = -1;
}
else
error = -1;
//
// Check for alternate volume label on boot helper partitions.
//
if (bvr->flags & kBVFlagBooter)
{
sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/", BIOS_DEV_UNIT(bvr), bvr->part_no);
strcpy(fileSpec, ".disk_label.contentDetails");
ret = GetFileInfo(dirSpec, fileSpec, &flags, &time);
if (!ret)
{
fh = open(strcat(dirSpec, fileSpec), 0);
fileSize = file_size(fh);
if (fileSize > 0 && fileSize < BVSTRLEN)
{
if (read(fh, label, fileSize) != fileSize)
error = -1;
}
else
error = -1;
close(fh);
close(fh);
if (!error)
{
label[fileSize] = '\0';
strcpy(bvr->altlabel, label);
}
}
}
if (!error)
{
label[fileSize] = '\0';
strcpy(bvr->altlabel, label);
}
}
}
//
// Check for SystemVersion.plist or ServerVersion.plist
// to determine if a volume hosts an installed system.
//
if (bvr->flags & kBVFlagNativeBoot)
{
if (getOSVersion(bvr,bvr->OSVersion) == true)
{
bvr->flags |= kBVFlagSystemVolume;
}
}
//
// Check for SystemVersion.plist or ServerVersion.plist
// to determine if a volume hosts an installed system.
//
if (bvr->flags & kBVFlagNativeBoot)
{
if (getOSVersion(bvr,bvr->OSVersion) == true)
{
bvr->flags |= kBVFlagSystemVolume;
}
}
}
}
}
void rescanBIOSDevice(int biosdev)
struct DiskBVMap* diskResetBootVolumes(int biosdev)
{
struct DiskBVMap * map;
struct DiskBVMap *prevMap = NULL;
for ( map = gDiskBVMap; map; prevMap = map, map = map->next ) {
if ( biosdev == map->biosdev ) {
break;
}
}
if(map != NULL)
{
verbose("Resetting BIOS device %xh\n", biosdev);
// Reset the biosbuf cache
cache_valid = false;
if(map == gDiskBVMap)
gDiskBVMap = map->next;
else if(prevMap != NULL)
prevMap->next = map->next;
else
stop("");
}
// Return the old map, either to be freed, or reinserted later
return map;
struct DiskBVMap * map;
struct DiskBVMap *prevMap = NULL;
for ( map = gDiskBVMap; map; prevMap = map, map = map->next )
{
if ( biosdev == map->biosdev )
{
break;
}
}
if(map != NULL)
{
verbose("Resetting BIOS device %xh\n", biosdev);
// Reset the biosbuf cache
cache_valid = false;
if(map == gDiskBVMap)
gDiskBVMap = map->next;
else if(prevMap != NULL)
prevMap->next = map->next;
else
stop("");
}
// Return the old map, either to be freed, or reinserted later
return map;
}
// Frees a DiskBVMap and all of its BootVolume's
void diskFreeMap(struct DiskBVMap *map)
{
if(map != NULL)
{
while(map->bvr != NULL)
{
BVRef bvr = map->bvr;
map->bvr = bvr->next;
(*bvr->bv_free)(bvr);
}
free(map);
}
if(map != NULL)
{
while(map->bvr != NULL)
{
BVRef bvr = map->bvr;
map->bvr = bvr->next;
(*bvr->bv_free)(bvr);
}
free(map);
}
}
BVRef diskScanBootVolumes( int biosdev, int * countPtr )
{
struct DiskBVMap * map = NULL;
BVRef bvr;
int count = 0;
struct DiskBVMap * map = NULL;
BVRef bvr;
int count = 0;
// Find an existing mapping for this device.
// Find an existing mapping for this device.
for ( map = gDiskBVMap; map; map = map->next ) {
if ( biosdev == map->biosdev ) {
count = map->bvrcnt;
break;
}
}
for ( map = gDiskBVMap; map; map = map->next )
{
if ( biosdev == map->biosdev )
{
count = map->bvrcnt;
break;
}
}
if (map == NULL) {
bvr = diskScanGPTBootVolumes(biosdev, &count);
if (bvr == NULL) {
bvr = diskScanFDiskBootVolumes(biosdev, &count);
}
if (bvr == NULL) {
bvr = diskScanAPMBootVolumes(biosdev, &count);
}
if (bvr)
{
scanFSLevelBVRSettings(bvr);
}
} else {
bvr = map->bvr;
}
if (countPtr) *countPtr += count;
return bvr;
if (map == NULL)
{
bvr = diskScanGPTBootVolumes(biosdev, &count);
if (bvr == NULL)
{
bvr = diskScanFDiskBootVolumes(biosdev, &count);
}
if (bvr == NULL)
{
bvr = diskScanAPMBootVolumes(biosdev, &count);
}
if (bvr)
{
scanFSLevelBVRSettings(bvr);
}
}
else
{
bvr = map->bvr;
}
if (countPtr) *countPtr += count;
return bvr;
}
BVRef getBVChainForBIOSDev(int biosdev)
{
BVRef chain = NULL;
struct DiskBVMap * map = NULL;
BVRef chain = NULL;
struct DiskBVMap * map = NULL;
for (map = gDiskBVMap; map; map = map->next)
{
if (map->biosdev == biosdev)
{
chain = map->bvr;
break;
}
}
return chain;
for (map = gDiskBVMap; map; map = map->next)
{
if (map->biosdev == biosdev)
{
chain = map->bvr;
break;
}
}
return chain;
}
BVRef newFilteredBVChain(int minBIOSDev, int maxBIOSDev, unsigned int allowFlags, unsigned int denyFlags, int *count)
{
BVRef chain = NULL;
BVRef bvr = NULL;
BVRef newBVR = NULL;
BVRef prevBVR = NULL;
BVRef chain = NULL;
BVRef bvr = NULL;
BVRef newBVR = NULL;
BVRef prevBVR = NULL;
struct DiskBVMap * map = NULL;
int bvCount = 0;
struct DiskBVMap * map = NULL;
int bvCount = 0;
const char *raw = 0;
char* val = 0;
int len;
const char *raw = 0;
char* val = 0;
int len;
getValueForKey(kHidePartition, &raw, &len, &bootInfo->chameleonConfig);
if(raw)
{
val = XMLDecode(raw);
}
getValueForKey(kHidePartition, &raw, &len, &bootInfo->chameleonConfig);
if(raw)
{
val = XMLDecode(raw);
}
/*
* Traverse gDISKBVmap to get references for
* individual bvr chains of each drive.
*/
for (map = gDiskBVMap; map; map = map->next)
{
for (bvr = map->bvr; bvr; bvr = bvr->next)
{
/*
* Save the last bvr.
*/
if (newBVR) prevBVR = newBVR;
/*
* Traverse gDISKBVmap to get references for
* individual bvr chains of each drive.
*/
for (map = gDiskBVMap; map; map = map->next)
{
for (bvr = map->bvr; bvr; bvr = bvr->next)
{
/*
* Save the last bvr.
*/
if (newBVR) prevBVR = newBVR;
/*
* Allocate and copy the matched bvr entry into a new one.
*/
newBVR = (BVRef) malloc(sizeof(*newBVR));
bcopy(bvr, newBVR, sizeof(*newBVR));
/*
* Allocate and copy the matched bvr entry into a new one.
*/
newBVR = (BVRef) malloc(sizeof(*newBVR));
if (!newBVR)
{
continue;
}
bcopy(bvr, newBVR, sizeof(*newBVR));
/*
* Adjust the new bvr's fields.
*/
newBVR->next = NULL;
newBVR->filtered = true;
/*
* Adjust the new bvr's fields.
*/
newBVR->next = NULL;
newBVR->filtered = true;
if ( (!allowFlags || newBVR->flags & allowFlags)
&& (!denyFlags || !(newBVR->flags & denyFlags) )
&& (newBVR->biosdev >= minBIOSDev && newBVR->biosdev <= maxBIOSDev)
)
newBVR->visible = true;
/*
* Looking for "Hide Partition" entries in 'hd(x,y)|uuid|"label" hd(m,n)|uuid|"label"' format,
* to be able to hide foreign partitions from the boot menu.
*
*/
if ( (newBVR->flags & kBVFlagForeignBoot) )
{
char *start, *next = val;
long len = 0;
do
{
start = strbreak(next, &next, &len);
if(len && matchVolumeToString(newBVR, start, len) )
newBVR->visible = false;
}
while ( next && *next );
}
if ( (!allowFlags || newBVR->flags & allowFlags)
&& (!denyFlags || !(newBVR->flags & denyFlags) )
&& (newBVR->biosdev >= minBIOSDev && newBVR->biosdev <= maxBIOSDev)
)
{
newBVR->visible = true;
}
/*
* Use the first bvr entry as the starting chain pointer.
*/
if (!chain)
chain = newBVR;
/*
* Looking for "Hide Partition" entries in 'hd(x,y)|uuid|"label" hd(m,n)|uuid|"label"' format,
* to be able to hide foreign partitions from the boot menu.
*
*/
if ( (newBVR->flags & kBVFlagForeignBoot) )
{
char *start, *next = val;
long len = 0;
do
{
start = strbreak(next, &next, &len);
if(len && matchVolumeToString(newBVR, start, len) )
{
newBVR->visible = false;
}
}
while ( next && *next );
}
/*
* Update the previous bvr's link pointer to use the new memory area.
*/
if (prevBVR)
prevBVR->next = newBVR;
if (newBVR->visible)
bvCount++;
}
}
/*
* Use the first bvr entry as the starting chain pointer.
*/
if (!chain)
{
chain = newBVR;
}
/*
* Update the previous bvr's link pointer to use the new memory area.
*/
if (prevBVR)
{
prevBVR->next = newBVR;
}
if (newBVR->visible)
{
bvCount++;
}
}
}
#if DEBUG //Azi: warning - too big for boot-log.. far too big.. i mean HUGE!! :P
for (bvr = chain; bvr; bvr = bvr->next)
{
printf(" bvr: %d, dev: %d, part: %d, flags: %d, vis: %d\n", bvr, bvr->biosdev, bvr->part_no, bvr->flags, bvr->visible);
}
printf("count: %d\n", bvCount);
getchar();
for (bvr = chain; bvr; bvr = bvr->next)
{
printf(" bvr: %d, dev: %d, part: %d, flags: %d, vis: %d\n", bvr, bvr->biosdev, bvr->part_no, bvr->flags, bvr->visible);
}
printf("count: %d\n", bvCount);
getchar();
#endif
*count = bvCount;
free(val);
return chain;
*count = bvCount;
free(val);
return chain;
}
int freeFilteredBVChain(const BVRef chain)
{
int ret = 1;
BVRef bvr = chain;
BVRef nextBVR = NULL;
int ret = 1;
BVRef bvr = chain;
BVRef nextBVR = NULL;
while (bvr)
{
nextBVR = bvr->next;
while (bvr)
{
nextBVR = bvr->next;
if (bvr->filtered)
{
free(bvr);
}
else
{
ret = 0;
break;
}
if (bvr->filtered)
{
free(bvr);
}
else
{
ret = 0;
break;
}
bvr = nextBVR;
}
return ret;
bvr = nextBVR;
}
return ret;
}
//==========================================================================
char testStr[128];
if ( !bvr || !match || !*match)
{
return 0;
}
if ( bvr->biosdev < 0x80 || bvr->biosdev >= 0x100 )
{
return 0;
}
// Try to match hd(x,y) first.
sprintf(testStr, "hd(%d,%d)", BIOS_DEV_UNIT(bvr), bvr->part_no);
if ( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) )
return true;
// Try to match hd(x,y) first.
sprintf(testStr, "hd(%d,%d)", BIOS_DEV_UNIT(bvr), bvr->part_no);
if ( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) )
return true;
// Try to match volume UUID.
if ( bvr->fs_getuuid && bvr->fs_getuuid(bvr, testStr) == 0)
{
if ( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) )
return true;
}
// Try to match volume UUID.
if ( bvr->fs_getuuid && bvr->fs_getuuid(bvr, testStr) == 0)
{
if( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) )
return true;
}
// Try to match volume label (always quoted).
if ( bvr->description )
{
bvr->description(bvr, testStr, sizeof(testStr)-1);
if ( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) )
return true;
}
// Try to match volume label (always quoted).
if ( bvr->description )
{
bvr->description(bvr, testStr, sizeof(testStr)-1);
if( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) )
return true;
}
return false;
return false;
}
/* If Rename Partition has defined an alias, then extract it for description purpose.
bool getVolumeLabelAlias(BVRef bvr, char* str, long strMaxLen)
{
char *aliasList, *entryStart, *entryNext;
char *aliasList, *entryStart, *entryNext;
if ( !str || strMaxLen <= 0)
return false;
aliasList = XMLDecode(getStringForKey(kRenamePartition, &bootInfo->chameleonConfig));
if ( !aliasList )
return false;
for ( entryStart = entryNext = aliasList;
entryNext && *entryNext;
entryStart = entryNext )
{
char *volStart, *volEnd, *aliasStart;
long volLen, aliasLen;
if ( !str || strMaxLen <= 0)
{
return false;
}
aliasList = XMLDecode(getStringForKey(kRenamePartition, &bootInfo->chameleonConfig));
if ( !aliasList )
{
return false;
}
for ( entryStart = entryNext = aliasList;
entryNext && *entryNext;
entryStart = entryNext )
{
char *volStart, *volEnd, *aliasStart;
long volLen, aliasLen;
// Delimit current entry
entryNext = strchr(entryStart, ';');
if ( entryNext )
{
*entryNext = '\0';
entryNext++;
}
// Delimit current entry
entryNext = strchr(entryStart, ';');
if ( entryNext )
{
*entryNext = '\0';
entryNext++;
}
volStart = strbreak(entryStart, &volEnd, &volLen);
if(!volLen)
continue;
volStart = strbreak(entryStart, &volEnd, &volLen);
if(!volLen)
{
continue;
}
aliasStart = strbreak(volEnd, 0, &aliasLen);
if(!aliasLen)
continue;
aliasStart = strbreak(volEnd, 0, &aliasLen);
if(!aliasLen)
{
continue;
}
if ( matchVolumeToString(bvr, volStart, volLen) )
{
strncat(str, aliasStart, MIN(strMaxLen, aliasLen));
free(aliasList);
return true;
}
}
if ( matchVolumeToString(bvr, volStart, volLen) )
{
strncat(str, aliasStart, MIN(strMaxLen, aliasLen));
free(aliasList);
return true;
}
}
free(aliasList);
return false;
free(aliasList);
return false;
}
void getBootVolumeDescription( BVRef bvr, char * str, long strMaxLen, bool useDeviceDescription )
{
unsigned char type;
char *p = str;
unsigned char type;
char *p = str;
if(!bvr || !p || strMaxLen <= 0)
return;
type = (unsigned char) bvr->part_type;
if(!bvr || !p || strMaxLen <= 0)
{
return;
}
if (useDeviceDescription)
{
int len = getDeviceDescription(bvr, str);
if(len >= strMaxLen)
return;
type = (unsigned char) bvr->part_type;
strcpy(str + len, " ");
len++;
strMaxLen -= len;
p += len;
}
if (useDeviceDescription)
{
int len = getDeviceDescription(bvr, str);
if(len >= strMaxLen)
return;
/* See if a partition rename is preferred */
if(getVolumeLabelAlias(bvr, p, strMaxLen)) {
strncpy(bvr->label, p, strMaxLen);
return; // we're done here no need to seek for real name
}
strcpy(str + len, " ");
len++;
strMaxLen -= len;
p += len;
}
//
// Get the volume label using filesystem specific functions
// or use the alternate volume label if available.
//
/* See if a partition rename is preferred */
if (getVolumeLabelAlias(bvr, p, strMaxLen))
{
strncpy(bvr->label, p, strMaxLen);
return; // we're done here no need to seek for real name
}
//
// Get the volume label using filesystem specific functions
// or use the alternate volume label if available.
//
if (*bvr->altlabel != '\0')
strncpy(p, bvr->altlabel, strMaxLen);
strncpy(p, bvr->altlabel, strMaxLen);
else if (bvr->description)
bvr->description(bvr, p, strMaxLen);
bvr->description(bvr, p, strMaxLen);
if (*p == '\0') {
const char * name = getNameForValue( fdiskTypes, type );
if (name == NULL) {
name = bvr->type_name;
}
if (name == NULL) {
sprintf(p, "TYPE %02x", type);
} else {
strncpy(p, name, strMaxLen);
}
}
if (*p == '\0')
{
const char * name = getNameForValue( fdiskTypes, type );
// Set the devices label
sprintf(bvr->label, p);
if (name == NULL)
{
name = bvr->type_name;
}
if (name == NULL)
{
sprintf(p, "TYPE %02x", type);
}
else
{
strncpy(p, name, strMaxLen);
}
}
// Set the devices label
sprintf(bvr->label, p);
}
//==========================================================================
/*
* Format of boot1f32 block.
*/
#define BOOT1F32_MAGIC "BOOT "
#define BOOT1F32_MAGICLEN 11
struct disk_boot1f32_blk {
unsigned char init[3];
unsigned char fsheader[87];
unsigned char magic[BOOT1F32_MAGICLEN];
unsigned char bootcode[409];
unsigned short signature;
unsigned char init[3];
unsigned char fsheader[87];
unsigned char magic[BOOT1F32_MAGICLEN];
unsigned char bootcode[409];
unsigned short signature;
};
int testFAT32EFIBootSector( int biosdev, unsigned int secno, void * buffer )
{
struct disk_boot1f32_blk * bootSector = (struct disk_boot1f32_blk *) buffer;
int error;
struct disk_boot1f32_blk * bootSector = (struct disk_boot1f32_blk *) buffer;
int error;
if ( bootSector == NULL )
{
if ( gBootSector == NULL )
{
gBootSector = (struct disk_blk0 *) malloc(sizeof(*gBootSector));
if ( gBootSector == NULL ) return -1;
}
bootSector = (struct disk_boot1f32_blk *) gBootSector;
}
if ( bootSector == NULL )
{
if ( gBootSector == NULL )
{
gBootSector = (struct disk_blk0 *) malloc(sizeof(*gBootSector));
if ( gBootSector == NULL )
{
return -1;
}
}
bootSector = (struct disk_boot1f32_blk *) gBootSector;
}
error = readBytes( biosdev, secno, 0, BPS, bootSector );
if ( error || bootSector->signature != DISK_SIGNATURE
|| strncmp((const char *)bootSector->magic, BOOT1F32_MAGIC, BOOT1F32_MAGICLEN) )
return -1;
return 0;
error = readBytes( biosdev, secno, 0, BPS, bootSector );
if ( error || bootSector->signature != DISK_SIGNATURE
|| strncmp((const char *)bootSector->magic, BOOT1F32_MAGIC, BOOT1F32_MAGICLEN) )
{
return -1;
}
return 0;
}
//==========================================================================
void diskSeek(BVRef bvr, long long position)
{
bvr->fs_boff = position / BPS;
bvr->fs_byteoff = position % BPS;
bvr->fs_boff = position / BPS;
bvr->fs_byteoff = position % BPS;
}
//==========================================================================
int diskRead( BVRef bvr, long addr, long length )
{
return readBytes( bvr->biosdev,
bvr->fs_boff + bvr->part_boff,
bvr->fs_byteoff,
length,
(void *) addr );
return readBytes( bvr->biosdev,
bvr->fs_boff + bvr->part_boff,
bvr->fs_byteoff,
length,
(void *) addr );
}
int rawDiskRead( BVRef bvr, unsigned int secno, void *buffer, unsigned int len )
{
int secs;
unsigned char *cbuf = (unsigned char *)buffer;
unsigned int copy_len;
int rc;
int secs;
unsigned char *cbuf = (unsigned char *)buffer;
unsigned int copy_len;
int rc;
if ((len & (BPS-1)) != 0) {
error("raw disk read not sector aligned");
return -1;
}
secno += bvr->part_boff;
if ((len & (BPS-1)) != 0)
{
error("raw disk read not sector aligned");
return -1;
}
secno += bvr->part_boff;
cache_valid = false;
cache_valid = false;
while (len > 0) {
secs = len / BPS;
if (secs > N_CACHE_SECS) secs = N_CACHE_SECS;
copy_len = secs * BPS;
while (len > 0)
{
secs = len / BPS;
if (secs > N_CACHE_SECS) secs = N_CACHE_SECS;
copy_len = secs * BPS;
//printf("rdr: ebiosread(%d, %d, %d)\n", bvr->biosdev, secno, secs);
if ((rc = ebiosread(bvr->biosdev, secno, secs)) != 0) {
/* Ignore corrected ECC errors */
if (rc != ECC_CORRECTED_ERR) {
error(" EBIOS read error: %s\n", bios_error(rc), rc);
error(" Block %d Sectors %d\n", secno, secs);
return rc;
}
}
bcopy( trackbuf, cbuf, copy_len );
len -= copy_len;
cbuf += copy_len;
secno += secs;
spinActivityIndicator(secs);
}
//printf("rdr: ebiosread(%d, %d, %d)\n", bvr->biosdev, secno, secs);
if ((rc = ebiosread(bvr->biosdev, secno, secs)) != 0)
{
/* Ignore corrected ECC errors */
if (rc != ECC_CORRECTED_ERR)
{
error(" EBIOS read error: %s\n", bios_error(rc), rc);
error(" Block %d Sectors %d\n", secno, secs);
return rc;
}
}
bcopy( trackbuf, cbuf, copy_len );
len -= copy_len;
cbuf += copy_len;
secno += secs;
spinActivityIndicator(secs);
}
return 0;
return 0;
}
int rawDiskWrite( BVRef bvr, unsigned int secno, void *buffer, unsigned int len )
unsigned int copy_len;
int rc;
if ((len & (BPS-1)) != 0) {
error("raw disk write not sector aligned");
return -1;
}
secno += bvr->part_boff;
if ((len & (BPS-1)) != 0)
{
error("raw disk write not sector aligned");
return -1;
}
secno += bvr->part_boff;
cache_valid = false;
cache_valid = false;
while (len > 0) {
secs = len / BPS;
if (secs > N_CACHE_SECS) secs = N_CACHE_SECS;
copy_len = secs * BPS;
while (len > 0)
{
secs = len / BPS;
if (secs > N_CACHE_SECS) secs = N_CACHE_SECS;
copy_len = secs * BPS;
bcopy( cbuf, trackbuf, copy_len );
//printf("rdr: ebioswrite(%d, %d, %d)\n", bvr->biosdev, secno, secs);
if ((rc = ebioswrite(bvr->biosdev, secno, secs)) != 0) {
error(" EBIOS write error: %s\n", bios_error(rc), rc);
error(" Block %d Sectors %d\n", secno, secs);
return rc;
}
len -= copy_len;
cbuf += copy_len;
secno += secs;
spinActivityIndicator(secs);
}
bcopy( cbuf, trackbuf, copy_len );
//printf("rdr: ebioswrite(%d, %d, %d)\n", bvr->biosdev, secno, secs);
if ((rc = ebioswrite(bvr->biosdev, secno, secs)) != 0)
{
error(" EBIOS write error: %s\n", bios_error(rc), rc);
error(" Block %d Sectors %d\n", secno, secs);
return rc;
}
return 0;
len -= copy_len;
cbuf += copy_len;
secno += secs;
spinActivityIndicator(secs);
}
return 0;
}
int diskIsCDROM(BVRef bvr)
branches/ErmaC/Trunk/i386/libsaio/saio_types.h
4141
4242
4343
44
44
45
4546
4647
4748
4849
4950
50
51
52
53
5154
5255
5356
5457
5558
5659
57
60
61
62
5863
5964
6065
......
6368
6469
6570
66
71
72
73
6774
68
75
6976
7077
7178
7279
7380
7481
75
76
82
83
84
85
7786
7887
7988
......
94103
95104
96105
97
106
107
108
98109
99110
100111
101112
102
113
103114
104115
105116
......
110121
111122
112123
113
124
114125
115126
116127
117
128
129
130
118131
132
119133
120134
121135
122136
123137
124138
125
139
140
126141
127142
128143
129
144
130145
131146
132147
......
142157
143158
144159
145
146
147
148
149
160
161
162
163
164
165
150166
151167
152
168
153169
154170
155171
......
161177
162178
163179
164
180
165181
166182
167183
168184
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
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
196213
197214
198
215
216
217
199218
200219
201220
......
205224
206225
207226
208
227
228
209229
210
230
211231
212232
213233
214234
215235
216236
217
237
238
218239
219240
220241
......
228249
229250
230251
231
232
233
234
252
253
254
255
235256
236257
237258
......
252273
253274
254275
255
256
276
277
257278
258
279
280
259281
260282
261283
262284
263
264
285
286
287
265288
266289
267290
typedef unsigned long entry_t;
typedef struct {
typedef struct
{
unsigned int sectors:8;
unsigned int heads:8;
unsigned int cylinders:16;
} compact_diskinfo_t;
struct driveParameters {
struct driveParameters
{
int cylinders;
int sectors;
int heads;
int totalDrives;
};
struct Tag {
struct Tag
{
longtype;
char *string;
longoffset;
};
typedef struct Tag Tag, *TagPtr;
typedef struct {
typedef struct
{
charplist[16384];// buffer for plist
TagPtrdictionary;// buffer for xml dictionary
TagPtrdictionary;// buffer for xml dictionary
boolcanOverride;// flag to mark a dictionary can be overriden
} config_file_t;
/*
* BIOS drive information.
*/
struct boot_drive_info {
struct drive_params {
struct boot_drive_info
{
struct drive_params
{
unsigned short buf_size;
unsigned short info_flags;
unsigned long phys_cyls;
unsigned char reserved3;
unsigned char checksum;
} params;
struct drive_dpte {
struct drive_dpte
{
unsigned short io_port_base;
unsigned short control_port_base;
unsigned char head_flags;
unsigned char vendor_info;
unsigned char irq : 4;
unsigned char irq : 4;
unsigned char irq_unused : 4;
unsigned char block_count;
unsigned char dma_channel : 4;
unsigned short reserved;
unsigned char revision;
unsigned char checksum;
} dpte;
} dpte;
} __attribute__((packed));
typedef struct boot_drive_info boot_drive_info_t;
struct driveInfo {
struct driveInfo
{
boot_drive_info_t di;
int uses_ebios;
int no_emulation;
int biosdev;
int valid;
};
typedef struct FinderInfo {
typedef struct FinderInfo
{
unsigned char data[16];
} FinderInfo;
struct BootVolume;
structBootVolume;
typedef struct BootVolume * BVRef;
typedef struct BootVolume * CICell;
// Can be just pointed to free or a special free function
typedef void (*BVFree)(CICell ih);
struct iob {
unsigned int i_flgs;/* see F_* below */
unsigned int i_offset;/* seek byte offset in file */
int i_filesize;/* size of file */
char * i_buf;/* file load address */
struct iob
{
unsigned int i_flgs; /* see F_* below */
unsigned int i_offset; /* seek byte offset in file */
int i_filesize; /* size of file */
char * i_buf; /* file load address */
};
#define BPS 512/* sector size of the device */
#define BPS 512/* sector size of the device */
#define F_READ 0x1/* file opened for reading */
#define F_WRITE 0x2/* file opened for writing */
#define F_ALLOC 0x4/* buffer allocated */
struct dirstuff {
char * dir_path;/* directory path */
long long dir_index;/* directory entry index */
BVRef dir_bvr;/* volume reference */
BVRef dir_bvr;/* volume reference */
};
#define BVSTRLEN 32
struct BootVolume {
BVRef next; /* list linkage pointer */
int biosdev; /* BIOS device number */
int type; /* device type (floppy, hd, network) */
unsigned int flags; /* attribute flags */
BVGetDescription description; /* BVGetDescription function */
int part_no; /* partition number (1 based) */
unsigned int part_boff; /* partition block offset */
unsigned int part_type; /* partition type */
unsigned int fs_boff; /* 1st block # of next read */
unsigned int fs_byteoff; /* Byte offset for read within block */
FSLoadFile fs_loadfile; /* FSLoadFile function */
FSReadFile fs_readfile; /* FSReadFile function */
FSGetDirEntry fs_getdirentry; /* FSGetDirEntry function */
FSGetFileBlock fs_getfileblock; /* FSGetFileBlock function */
FSGetUUID fs_getuuid; /* FSGetUUID function */
unsigned int bps; /* bytes per sector for this device */
char name[BVSTRLEN]; /* (name of partition) */
char type_name[BVSTRLEN]; /* (type of partition, eg. Apple_HFS) */
BVFree bv_free; /* BVFree function */
uint32_t modTime;
char label[BVSTRLEN]; /* partition volume label */
char altlabel[BVSTRLEN]; /* partition volume label */
bool filtered; /* newFilteredBVChain() will set to TRUE */
bool visible; /* will shown in the device list */
char OSVersion[8];
bool OSisServer; /* 1 = OS X server , 0 = OS X client */
struct BootVolume
{
BVRef next; /* list linkage pointer */
int biosdev; /* BIOS device number */
int type; /* device type (floppy, hd, network) */
unsigned int flags; /* attribute flags */
BVGetDescription description; /* BVGetDescription function */
int part_no; /* partition number (1 based) */
unsigned int part_boff; /* partition block offset */
unsigned int part_type; /* partition type */
unsigned int fs_boff; /* 1st block # of next read */
unsigned int fs_byteoff; /* Byte offset for read within block */
FSLoadFile fs_loadfile; /* FSLoadFile function */
FSReadFile fs_readfile; /* FSReadFile function */
FSGetDirEntry fs_getdirentry; /* FSGetDirEntry function */
FSGetFileBlock fs_getfileblock; /* FSGetFileBlock function */
FSGetUUID fs_getuuid; /* FSGetUUID function */
unsigned int bps; /* bytes per sector for this device */
char name[BVSTRLEN]; /* (name of partition) */
char type_name[BVSTRLEN]; /* (type of partition, eg. Apple_HFS) */
BVFree bv_free; /* BVFree function */
uint32_t modTime;
char label[BVSTRLEN]; /* partition volume label */
char altlabel[BVSTRLEN]; /* partition volume label */
bool filtered; /* newFilteredBVChain() will set to TRUE */
bool visible; /* will shown in the device list */
char OSVersion[8];
bool OSisServer; /* 1 = OS X server , 0 = OS X client */
};
enum {
enum
{
kBVFlagPrimary= 0x01,
kBVFlagNativeBoot= 0x02,
kBVFlagForeignBoot= 0x04,
kBVFlagSystemVolume= 0x40
};
enum {
enum
{
kBIOSDevTypeFloppy= 0x00,
kBIOSDevTypeHardDrive= 0x80,
kBIOSDevTypeHardDrive= 0x80,
kBIOSDevTypeNetwork= 0xE0,
kBIOSDevUnitMask= 0x0F,
kBIOSDevTypeMask= 0xF0,
kBIOSDevMask= 0xFF
};
enum {
enum
{
kPartitionTypeHFS= 0xAF,
kPartitionTypeHPFS= 0x07,
kPartitionTypeFAT16= 0x06,
//#define BIOS_DEV_TYPE(d)((d) & kBIOSDevTypeMask)
#define BIOS_DEV_UNIT(bvr)((bvr)->biosdev - (bvr)->type)
/*
* KernBootStruct device types.
*/
enum {
// KernBootStruct device types.
enum
{
DEV_SD = 0,
DEV_HD = 1,
DEV_FD = 2,
#define MAX(a,b) ( ((a) > (b)) ? (a) : (b) )
#endif
#define round2(x, m)(((x) + (m / 2)) & ~(m - 1))
#define roundup2(x, m)(((x) + m - 1) & ~(m - 1))*/
#defineround2(x, m)(((x) + (m / 2)) & ~(m - 1))
#define roundup2(x, m) (((x) + m - 1) & ~(m - 1))*/
enum {
enum
{
kNetworkDeviceType = kBIOSDevTypeNetwork,
kBlockDeviceType = kBIOSDevTypeHardDrive
}; //gBootFileType_t;
enum {
kCursorTypeHidden = 0x0100,
enum
{
kCursorTypeHidden = 0x0100,
kCursorTypeUnderline = 0x0607
};
branches/ErmaC/Trunk/i386/libsaio/msdos.c
152152
153153
154154
155
156
157
158
159
155160
156
157
158
159
160
161
162
161
162
163
164
165
166
167
168
163169
164170
165171
......
167173
168174
169175
170
171
172
176
177
178
173179
174180
175181
176182
177183
178
179
180
184
185
186
187
188
181189
182
183
190
191
192
193
184194
185195
186196
......
193203
194204
195205
196
206
207
197208
198209
199210
......
234245
235246
236247
248
249
250
251
237252
238253
239254
......
294309
295310
296311
297
312
298313
299
314
315
300316
301317
302318
......
382398
383399
384400
385
386
401
402
387403
388404
389405
390406
391
392
407
408
393409
394410
395411
......
649665
650666
651667
652
668
669
670
671
672
653673
654674
655675
676
677
678
679
680
656681
657682
658683
......
685710
686711
687712
713
714
715
716
717
718
688719
689720
690721
......
692723
693724
694725
726
727
728
729
730
731
695732
696733
697734
......
739776
740777
741778
742
779
743780
744781
745782
......
747784
748785
749786
787
788
789
790
750791
751792
752793
......
759800
760801
761802
803
804
762805
806
763807
764808
765809
......
768812
769813
770814
771
815
772816
773817
774818
......
777821
778822
779823
780
824
781825
782826
783827
......
800844
801845
802846
847
848
849
850
803851
804852
805853
......
842890
843891
844892
845
893
846894
847895
848896
849897
850898
851899
852
853
854
900
901
902
855903
856
857
858
904
905
906
859907
860
861
862
908
909
910
863911
864
865
866
912
913
914
867915
868916
869917
......
876924
877925
878926
879
880
927
928
881929
882930
883931
......
887935
888936
889937
890
938
891939
892940
893941
894942
943
944
945
946
895947
896948
897949
......
910962
911963
912964
913
914
965
966
967
915968
969
970
971
972
916973
917974
918975
919
920
921
922
923
924
976
977
978
979
980
981
982
983
984
925985
926986
927
987
928988
929
989
930990
931991
932992
933993
934994
935995
996
997
998
999
9361000
9371001
9381002
9391003
1004
9401005
9411006
9421007
}
buf=malloc (512);
if (!buf)
{
return -1;
}
/*
* Read the boot sector of the filesystem, and then check the
* boot signature. If not a dos boot sector then error out.
*
* NOTE: 2048 is a maximum sector size in current...
*/
Seek(ih, 0);
Read(ih, (long)buf, 512);
* Read the boot sector of the filesystem, and then check the
* boot signature. If not a dos boot sector then error out.
*
* NOTE: 2048 is a maximum sector size in current...
*/
Seek(ih, 0);
Read(ih, (long)buf, 512);
bsp = (union bootsector *)buf;
b33 = (struct bpb33 *)bsp->bs33.bsBPB;
b710 = (struct bpb710 *)bsp->bs710.bsBPB;
/* We only work with 512, 1024, and 2048 byte sectors */
msdosbps = OSSwapLittleToHostInt16(b33->bpbBytesPerSec);
if ((msdosbps < 0x200) || (msdosbps & (msdosbps - 1)) || (msdosbps > 0x800))
/* We only work with 512, 1024, and 2048 byte sectors */
msdosbps = OSSwapLittleToHostInt16(b33->bpbBytesPerSec);
if ((msdosbps < 0x200) || (msdosbps & (msdosbps - 1)) || (msdosbps > 0x800))
{
free (buf);
return -1;
}
/* Check to make sure valid sectors per cluster */
spc = b33->bpbSecPerClust;
if ((spc == 0 ) || (spc & (spc - 1)))
/* Check to make sure valid sectors per cluster */
spc = b33->bpbSecPerClust;
if ((spc == 0 ) || (spc & (spc - 1)))
{
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);
msdosrootDirSectors = 0;
msdosfatbits = 32;
}
else if (((struct extboot *)bsp->bs50.bsExt)->exBootSignature == EXBOOTSIG) {
else if (((struct extboot *)bsp->bs50.bsExt)->exBootSignature == EXBOOTSIG)
{
if (!memcmp((char *)((struct extboot *)bsp->bs50.bsExt)->exFileSysType, "FAT16 ", 8))
msdosfatbits = 16;
else if (!memcmp((char *)((struct extboot *)bsp->bs50.bsExt)->exFileSysType, "FAT12 ", 8))
char *cacheBuffer;
cacheBuffer = malloc(MSDOS_CACHE_BLOCKSIZE);
if (!cacheBuffer)
{
return -1;
}
CacheRead(ih, cacheBuffer, sectorOffset, MSDOS_CACHE_BLOCKSIZE, true);
bcopy(cacheBuffer + relOffset, buf, size);
free(cacheBuffer);
readOffset += ((uint64_t)*cluster * (uint64_t)msdosfatbits) / 8;
/* Read one sector of the FAT */
readSector(ih, readOffset, tmpbuf, 4);
if (readSector(ih, readOffset, tmpbuf, 4) != 0) return 0;
switch (msdosfatbits) {
switch (msdosfatbits)
{
case 32:
*cluster = OSReadLittleInt32(tmpbuf, 0);
*cluster &= 0x0FFFFFFF;// ignore reserved upper bits
st->vfatchecksum = 0;
st->vfatnumber = 0;
st->nument++;
if ((!st->root16 &&st->nument * sizeof (struct direntry)>=msdosclustersize)
|| (st->root16 &&st->nument * sizeof (struct direntry)>=msdosbps))
if (((int)(!st->root16 &&st->nument * sizeof (struct direntry))>=msdosclustersize)
|| ((int)(st->root16 &&st->nument * sizeof (struct direntry))>=msdosbps))
st->nument = 0;
return dirp;
}
st->nument++;
if ((!st->root16 &&st->nument * sizeof (struct direntry)>=msdosclustersize)
|| (st->root16 &&st->nument * sizeof (struct direntry)>=msdosbps))
if (((int)(!st->root16 &&st->nument * sizeof (struct direntry))>=msdosclustersize)
|| ((int)(st->root16 &&st->nument * sizeof (struct direntry))>=msdosbps))
st->nument = 0;
}
}
st = (struct msdosdirstate *)(long) *dirIndex;
if (!st)
{
st=malloc (sizeof (*st));
st=malloc (sizeof (struct msdosdirstate));
if (!st)
{
return -1;
}
if (dirPath[0])
{
uint8_t *buf=malloc(msdosclustersize);
if (!buf)
{
free (st);
return -1;
}
dirp = getdirpfrompath (ih, dirPath, buf);
if (!dirp || !(dirp->deAttributes & ATTR_DIRECTORY))
{
int i;
for (i=0;vfatname[i];i++);
*name = malloc (256);
if (!*name)
{
free (st->buf);
free (st);
return -1;
}
utf_encodestr(vfatname, i, (u_int8_t *)*name, 255, OSLittleEndian );
}
else
int i, j, k;
uint16_t tmp[13];
*name = malloc (26);
if (!*name)
{
free (st->buf);
free (st);
return -1;
}
for (i=7;i>=0;i--)
if (dirp->deName[i]!=' ')
break;
int toread, wastoread;
char *ptr = (char *)base;
struct direntry *dirp;
int i;
uint64_t i;
char devStr[12];
if (MSDOSInitPartition (ih)<0)
if (filePath[0] == '/')
filePath++;
buf = malloc(msdosclustersize);
if (!buf)
{
return -1;
}
dirp = getdirpfrompath (ih, filePath, buf);
if (!dirp || (dirp->deAttributes & ATTR_DIRECTORY))
cluster |= ((uint32_t)OSReadLittleInt16 ((dirp->deHighClust),0)) <<16;
size = (uint32_t)OSReadLittleInt32 ((dirp->deFileSize),0);
if (size<=offset)
{
free (buf);
return -1;
}
nskip=offset/msdosclustersize;
for (i=0;i<nskip;i++)
msdosreadcluster (ih, 0, 0, &cluster);
if (length==0 || length>size-offset)
toread=size-offset;
wastoread=toread;
bcopy (buf+(offset%msdosclustersize),ptr,MIN(msdosclustersize-(offset%msdosclustersize), toread));
bcopy (buf+(offset%msdosclustersize),ptr,MIN((msdosclustersize-(offset%msdosclustersize)),(unsigned)toread));
ptr+=msdosclustersize-(offset%msdosclustersize);
toread-=msdosclustersize-(offset%msdosclustersize);
while (toread>0 && msdosreadcluster (ih, (uint8_t *)ptr, MIN(msdosclustersize,toread), &cluster))
toread-=msdosclustersize;
}
getDeviceDescription(ih, devStr);
getDeviceDescription(ih, devStr);
/*
verbose("Read FAT%d file: [%s/%s] %d bytes.\n",
msdosfatbits, devStr, filePath, (uint32_t)( toread<0 ) ? wastoread : wastoread-toread);
if (filePath[0] == '/')
filePath++;
buf = malloc(msdosclustersize);
if (!buf)
{
return -1;
}
dirp = getdirpfrompath (ih, filePath, buf);
if (!dirp || (dirp->deAttributes & ATTR_DIRECTORY))
{
long MSDOSLoadFile(CICell ih, char * filePath)
{
return MSDOSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
return MSDOSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
}
/* Fix up volume label. */
static void
fixLabel(uint8_t *label, char *str, long strMaxLen)
{
inti, len;
uint16_tlabelucs[13];
//unsigned charlabelUTF8[LABEL_LENGTH*3];
inti, len;
uint16_tlabelucs[13];
//unsigned charlabelUTF8[LABEL_LENGTH*3];
/* Convert leading 0x05 to 0xE5 for multibyte languages like Japanese */
if (label[0] == 0x05)
label[0] = 0xE5;
/* Convert leading 0x05 to 0xE5 for multibyte languages like Japanese */
if (label[0] == 0x05)
label[0] = 0xE5;
/* Remove any trailing spaces */
for (i=LABEL_LENGTH-1; i>=0; --i) {
if (label[i] == ' ')
/* Remove any trailing spaces */
for (i=LABEL_LENGTH-1; i>=0; --i) {
if (label[i] == ' ')
label[i] = 0;
else
break;
}
else
break;
}
labelucs[i++]=0;
len=i;
for (;i>=0;--i)
void
MSDOSGetDescription(CICell ih, char *str, long strMaxLen)
{
struct direntry *dirp;
uint8_t label[LABEL_LENGTH+1];
struct direntry*dirp;
uint8_tlabel[LABEL_LENGTH+1];
uint16_tvfatlabel[WIN_MAXLEN+2*WIN_CHARS];
struct msdosdirstate st;
int labelfound = 0;
str[0]=0;
return;
}
label[0] = '\0';
initRoot (&st);
st.buf = malloc(msdosclustersize);
if (!st.buf)
{
return;
}
while ((dirp = getnextdirent (ih, vfatlabel, &st)))
if (dirp->deAttributes & ATTR_VOLUME) {
strncpy((char *)label, (char *)dirp->deName, LABEL_LENGTH);
else if (labelfound)
fixLabel(label, str, strMaxLen);
/* else look in the boot blocks */
if (!labelfound || str[0] == '\0') {
/* else look in the boot blocks */
if (!labelfound || str[0] == '\0')
{
char *buf = malloc (512);
if (!buf)
{
return;
}
union bootsector *bsp = (union bootsector *)buf;
Seek(ih, 0);
Read(ih, (long)buf, 512);
if (msdosfatbits == 32) { /* It's FAT32 */
strncpy((char *)label, (char *)((struct extboot *)bsp->bs710.bsExt)->exVolumeLabel, LABEL_LENGTH);
}
else if (msdosfatbits == 16) {
strncpy((char *)label, (char *)((struct extboot *)bsp->bs50.bsExt)->exVolumeLabel, LABEL_LENGTH);
}
if (msdosfatbits == 32)
{
/* It's FAT32 */
strncpy((char *)label, (char *)((struct extboot *)bsp->bs710.bsExt)->exVolumeLabel, LABEL_LENGTH);
}
else if (msdosfatbits == 16)
{
strncpy((char *)label, (char *)((struct extboot *)bsp->bs50.bsExt)->exVolumeLabel, LABEL_LENGTH);
}
free (buf);
fixLabel(label, str, strMaxLen);
}
}
return;
return;
}
long
MSDOSGetUUID(CICell ih, char *uuidStr)
{
char *buf = malloc (512);
if (!buf)
{
return -1;
}
union bootsector *bsp = (union bootsector *)buf;
if (MSDOSInitPartition (ih)<0)
{
free (buf);
return -1;
}
bzero (uuidStr, 16);
branches/ErmaC/Trunk/i386/boot2/picopng.c
6060
6161
6262
63
64
65
66
6367
6468
6569
......
8589
8690
8791
88
92
8993
9094
9195
......
96100
97101
98102
103
104
99105
100
101
102
106
107
108
103109
104110
105111
......
157163
158164
159165
166
167
168
169
160170
161171
172
173
174
162175
176
163177
164178
165179
......
211225
212226
213227
228
229
230
231
214232
215233
234
235
236
216237
238
217239
218240
219241
......
221243
222244
223245
246
247
248
249
224250
225251
226252
......
229255
230256
231257
232
258
233259
234
260
235261
236
262
237263
238
264
239265
240266
241267
......
250276
251277
252278
279
280
281
282
253283
254284
255285
......
262292
263293
264294
295
296
297
298
265299
266300
267301
......
289323
290324
291325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
292343
293344
294345
......
887938
888939
889940
941
942
943
944
890945
891946
892947
......
937992
938993
939994
995
996
997
998
999
1000
9401001
9411002
9421003
......
10021063
10031064
10041065
1066
1067
1068
1069
1070
10051071
10061072
10071073
......
10681134
10691135
10701136
1137
1138
1139
1140
10711141
1142
1143
1144
1145
10721146
10731147
10741148
void png_alloc_remove_node(png_alloc_node_t *node)
{
if (!node)
{
return;
}
if (node->prev)
node->prev->next = node->next;
if (node->next)
if (!addr)
return png_alloc_malloc(size);
new_addr = realloc(addr, size);
if (new_addr != addr) {
if (new_addr && (new_addr != addr)) {
png_alloc_node_t *old_node;
old_node = png_alloc_find_node(addr);
png_alloc_remove_node(old_node);
void png_alloc_free(void *addr)
{
if (!addr) return;
png_alloc_node_t *node = png_alloc_find_node(addr);
if (!node)
return;
png_alloc_remove_node(node);
if (node)
png_alloc_remove_node(node);
free(addr);
}
vector32_t *vector32_new(size_t size, uint32_t value)
{
vector32_t *p = png_alloc_malloc(sizeof (vector32_t));
if (!p)
{
return NULL;
}
vector32_init(p);
if (size && !vector32_resizev(p, size, value))
{
vector32_cleanup(p);
png_alloc_free(p);
return NULL;
}
return p;
}
vector8_t *vector8_new(size_t size, uint8_t value)
{
vector8_t *p = png_alloc_malloc(sizeof (vector8_t));
if(!p)
{
return NULL;
}
vector8_init(p);
if (size && !vector8_resizev(p, size, value))
{
vector8_cleanup(p);
png_alloc_free(p);
return NULL;
}
return p;
}
{
vector8_t *q = vector8_new(p->size, 0);
uint32_t n;
if (!q)
{
return NULL;
}
for (n = 0; n < q->size; n++)
q->data[n] = p->data[n];
return q;
/*************************************************************************************************/
const uint32_t LENBASE[29] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51,
59, 67, 83, 99, 115, 131, 163, 195, 227, 258 };
59, 67, 83, 99, 115, 131, 163, 195, 227, 258 };
const uint32_t LENEXTRA[29] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
4, 5, 5, 5, 5, 0 };
4, 5, 5, 5, 5, 0 };
const uint32_t DISTBASE[30] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385,
513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 };
513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 };
const uint32_t DISTEXTRA[30] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
10, 10, 11, 11, 12, 12, 13, 13 };
10, 10, 11, 11, 12, 12, 13, 13 };
// code length code lengths
const uint32_t CLCL[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
HuffmanTree *HuffmanTree_new()
{
HuffmanTree *tree = png_alloc_malloc(sizeof (HuffmanTree));
if (!tree)
{
return NULL;
}
tree->tree2d = NULL;
return tree;
}
tree1d = vector32_new(numcodes, 0);
blcount = vector32_new(maxbitlen + 1, 0);
nextcode = vector32_new(maxbitlen + 1, 0);
if (!tree1d || !blcount || !nextcode || !nextcode->data)
{
goto error;
}
for (bits = 0; bits < numcodes; bits++)
blcount->data[bitlen->data[bits]]++; // count number of instances of each code length
for (bits = 1; bits <= maxbitlen; bits++)
treepos = tree2d->data[2 * treepos + bit] - numcodes;
}
return 0;
error:
if (tree1d)
{
vector32_cleanup(tree1d);
png_alloc_free(tree1d);
}
if (blcount)
{
vector32_cleanup(blcount);
png_alloc_free(blcount);
}
if (nextcode)
{
vector32_cleanup(nextcode);
png_alloc_free(nextcode);
}
return 1;
}
int HuffmanTree_decode(const HuffmanTree *tree, bool *decoded, uint32_t *result, size_t *treepos,
PNG_info_t *PNG_info_new()
{
PNG_info_t *info = png_alloc_malloc(sizeof (PNG_info_t));
if (!info)
{
return NULL;
}
uint32_t i;
for (i = 0; i < sizeof (PNG_info_t); i++)
((uint8_t *) info)[i] = 0;
vector8_resize(idat, offset + chunkLength);
} else
idat = vector8_new(chunkLength, 0);
if (!idat)
{
PNG_error = 1;
return NULL;
}
for (i = 0; i < chunkLength; i++)
idat->data[offset + i] = in[pos + 4 + i];
pos += (4 + chunkLength);
uint32_t bpp = PNG_getBpp(info);
vector8_t *scanlines; // now the out buffer will be filled
scanlines = vector8_new(((info->width * (info->height * bpp + 7)) / 8) + info->height, 0);
if (!scanlines)
{
PNG_error = 1;
return NULL;
}
PNG_error = Zlib_decompress(scanlines, idat);
if (PNG_error)
return NULL; // stop if the zlib decompressor returned an error
}
if (info->colorType != 6 || info->bitDepth != 8) { // conversion needed
vector8_t *copy = vector8_copy(info->image); // xxx: is this copy necessary?
if (!copy)
{
return NULL;
}
PNG_error = PNG_convert(info, info->image, copy->data);
if (PNG_error)
{
return NULL;
}
}
return info;
}
branches/ErmaC/Trunk/i386/boot2/graphic_utils.c
77
88
99
10
11
12
10
11
12
1313
1414
1515
......
1717
1818
1919
20
21
22
20
21
22
23
24
2325
24
25
26
27
2628
27
28
29
30
31
29
30
31
32
33
34
3235
33
34
35
36
37
38
3639
37
38
39
40
41
42
43
44
45
46
47
48
49
40
41
42
43
44
45
46
47
48
49
50
51
52
5053
5154
5255
5356
54
55
56
57
57
58
59
60
5861
5962
6063
6164
62
63
64
65
65
66
67
68
6669
6770
6871
......
7275
7376
7477
75
76
78
79
80
7781
78
79
82
83
8084
8185
#include "graphic_utils.h"
#include "gui.h"
void blend( const pixmap_t *blendThis, // Source image
pixmap_t *blendInto, // Dest image
const position_t position) // Where to place the source image
void blend( const pixmap_t *blendThis,// Source image
pixmap_t *blendInto,// Dest image
const position_t position)// Where to place the source image
{
uint16_t sx, sy, dx, dy;
uint32_t dstrb, dstag, srcrb, srcag, drb, dag, rb, ag, alpha;
uint16_t width = (blendThis->width + position.x < blendInto->width) ? blendThis->width: blendInto->width-position.x;
uint16_t height = (blendThis->height + position.y < blendInto->height) ? blendThis->height: blendInto->height-position.y;
for (dy = position.y, sy = 0; sy < height; dy++, sy++) {
for (dx = position.x, sx = 0; sx < width; dx++, sx++) {
alpha = (pixel(blendThis, sx, sy).ch.a);
for (dy = position.y, sy = 0; sy < height; dy++, sy++)
{
for (dx = position.x, sx = 0; sx < width; dx++, sx++)
{
alpha = (pixel(blendThis, sx, sy).ch.a);
/* Skip blending for fully transparent pixel */
if (alpha == 0) continue;
/* Skip blending for fully transparent pixel */
if (alpha == 0) continue;
/* For fully opaque pixel, there is no need to interpolate */
if (alpha == 255) {
pixel(blendInto, dx, dy).value = pixel(blendThis, sx, sy).value;
continue;
}
/* For fully opaque pixel, there is no need to interpolate */
if (alpha == 255)
{
pixel(blendInto, dx, dy).value = pixel(blendThis, sx, sy).value;
continue;
}
/* For semi-transparent pixels, do a full blend */
//alpha++
/* This is needed to spread the alpha over [0..256] instead of [0..255]
/* For semi-transparent pixels, do a full blend */
//alpha++
/* This is needed to spread the alpha over [0..256] instead of [0..255]
Boundary conditions were handled above */
dstrb = pixel(blendInto, dx, dy).value & 0xFF00FF;
dstag = (pixel(blendInto, dx, dy).value >> 8) & 0xFF00FF;
srcrb = pixel(blendThis, sx, sy).value & 0xFF00FF;
srcag = (pixel(blendThis, sx, sy).value >> 8) & 0xFF00FF;
drb = srcrb - dstrb;
dag = srcag - dstag;
drb *= alpha; dag *= alpha;
drb >>= 8; dag >>= 8;
rb = (drb + dstrb) & 0x00FF00FF;
ag = ((dag + dstag) << 8) & 0xFF00FF00;
pixel(blendInto, dx, dy).value = (rb | ag);
}
}
dstrb = pixel(blendInto, dx, dy).value & 0xFF00FF;
dstag = (pixel(blendInto, dx, dy).value >> 8) & 0xFF00FF;
srcrb = pixel(blendThis, sx, sy).value & 0xFF00FF;
srcag = (pixel(blendThis, sx, sy).value >> 8) & 0xFF00FF;
drb = srcrb - dstrb;
dag = srcag - dstag;
drb *= alpha; dag *= alpha;
drb >>= 8; dag >>= 8;
rb = (drb + dstrb) & 0x00FF00FF;
ag = ((dag + dstag) << 8) & 0xFF00FF00;
pixel(blendInto, dx, dy).value = (rb | ag);
}
}
}
position_t centeredIn( const pixmap_t *background, const pixmap_t *toCenter )
{
position_t centered;
centered.x = ( background->width - toCenter->width ) / 2;
centered.y = ( background->height - toCenter->height ) / 2;
return centered;
position_t centered;
centered.x = ( background->width - toCenter->width ) / 2;
centered.y = ( background->height - toCenter->height ) / 2;
return centered;
}
position_t centeredAt( const pixmap_t *pixmap, const position_t center )
{
position_t topleft;
topleft.x = center.x - (pixmap->width / 2);
topleft.y = center.y - (pixmap->height / 2);
return topleft;
position_t topleft;
topleft.x = center.x - (pixmap->width / 2);
topleft.y = center.y - (pixmap->height / 2);
return topleft;
}
position_t pos(const uint16_t x, const uint16_t y) { position_t p; p.x = x; p.y = y; return p; }
//if(testForQemu()) return;
uint32_t x;
register uint8_t tempB;
for (x = 0; x < (p->height) * (p->width) ; x++) {
register uint8_t tempB;
for (x = 0; x < (p->height) * (p->width) ; x++)
{
tempB = (p->pixels[x]).ch.b;
(p->pixels[x]).ch.b = (p->pixels[x]).ch.r;
(p->pixels[x]).ch.r = tempB;
(p->pixels[x]).ch.b = (p->pixels[x]).ch.r;
(p->pixels[x]).ch.r = tempB;
}
}
branches/ErmaC/Trunk/i386/modules/Resolution/915resolution.c
253253
254254
255255
256
257
258
259
256260
257261
258262
......
512516
513517
514518
519
520
515521
516522
517523
......
565571
566572
567573
574
575
568576
569577
570578
......
863871
864872
865873
874
875
866876
867877
868878
869879
870880
871
881
{
UInt32 z;
vbios_map * map = malloc(sizeof(vbios_map));
if (!map)
{
return 0;
}
for(z=0; z<sizeof(vbios_map); z++) ((char*)map)[z]=0;
/*
* Determine chipset
outb(CONFIG_MECH_ONE_DATA + 1, 0x33);
outb(CONFIG_MECH_ONE_DATA + 2, 0x33);
break;
default:
break;
}
#if DEBUG
outb(CONFIG_MECH_ONE_DATA + 1, map->b1);
outb(CONFIG_MECH_ONE_DATA + 2, map->b2);
break;
default:
break;
}
#if DEBUG
{
break;
}
default:
break;
}
//}
//}
}
#endif // _RESOLUTION_H_
#endif // _RESOLUTION_H_
branches/ErmaC/Trunk/i386/modules/Resolution/edid.c
334334
335335
336336
337
337338
338339
339
340340
341341
342342
......
385385
386386
387387
388
389
390
391
388392
389393
390394
for(i = 0; i < 16; i++) msglog("0x%02X ", edidInfo[((i+1) * (j + 1)) - 1]);
msglog("\n");
}
if(status == 0)
{
//if( edidInfo[0] == 0x00 || edidInfo[0] == 0xFF)
} while(blocks_left);
char* ret = malloc(sizeof(edidInfo));
if (!ret)
{
return 0;
}
memcpy(ret, edidInfo, sizeof(edidInfo));
return ret;
}

Archive Download the corresponding diff file

Revision: 1996