Index: branches/ErmaC/Trunk/i386/libsaio/hfs.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/hfs.c (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/hfs.c (revision 1996) @@ -265,7 +265,7 @@ { char entry[512]; char devStr[12]; - long dirID, result, flags; + long dirID, result, flags =0; if (HFSInitPartition(ih) == -1) return -1; @@ -312,7 +312,7 @@ FinderInfo * finderInfo, long * infoValid) { char entry[512]; - long dirID, dirFlags; + long dirID, dirFlags = 0; if (HFSInitPartition(ih) == -1) return -1; @@ -351,7 +351,7 @@ UInt32 firstLeafNode; long long dirIndex; char *name; - long flags, time; + long flags =0, time; if (HFSInitPartition(ih) == -1) { return; } @@ -376,7 +376,7 @@ 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; @@ -510,13 +510,15 @@ } 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) { @@ -644,7 +646,7 @@ char key[sizeof(HFSPlusCatalogKey)]; HFSCatalogKey *hfsKey = (HFSCatalogKey *)key; HFSPlusCatalogKey *hfsPlusKey = (HFSPlusCatalogKey *)key; - + // Make the catalog key. if ( gIsHFSPlus ) { @@ -693,7 +695,7 @@ 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) { @@ -737,7 +739,7 @@ // 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; @@ -759,12 +761,12 @@ 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); @@ -833,162 +835,177 @@ 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) { - 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) Index: branches/ErmaC/Trunk/i386/libsaio/acpi_patcher.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/acpi_patcher.c (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/acpi_patcher.c (revision 1996) @@ -687,10 +687,12 @@ 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; @@ -749,7 +751,7 @@ 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"); } Index: branches/ErmaC/Trunk/i386/libsaio/aml_generator.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/aml_generator.c (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/aml_generator.c (revision 1996) @@ -195,8 +195,8 @@ } unsigned int root = 0; - - if ((len % 4) == 1 && name[0] == '\\') + + if (((len % 4) == 1) && (name[0] == '\\')) root++; if (count == 1) @@ -204,6 +204,7 @@ node->Length = 4 + root; node->Buffer = malloc(node->Length); memcpy(node->Buffer, name, 4 + root); + return node->Length; } @@ -418,12 +419,12 @@ 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 Index: branches/ErmaC/Trunk/i386/libsaio/aml_generator.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/aml_generator.h (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/aml_generator.h (revision 1996) @@ -29,10 +29,10 @@ { unsigned char Type; unsigned int Length; - char* Buffer; - + char* Buffer; + unsigned int Size; - + struct aml_chunk* Next; struct aml_chunk* First; struct aml_chunk* Last; @@ -58,4 +58,4 @@ 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 */ \ No newline at end of file +#endif /* !__LIBSAIO_AML_GENERATOR_H */ Index: branches/ErmaC/Trunk/i386/libsaio/fdisk.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/fdisk.h (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/fdisk.h (revision 1996) @@ -35,27 +35,27 @@ #ifndef __LIBSAIO_FDISK_H #define __LIBSAIO_FDISK_H -#define DISK_BLK0 0 /* blkno of boot block */ -#define DISK_BLK0SZ 512 /* size of boot block */ -#define DISK_BOOTSZ 446 /* size of boot code in boot block */ +#define DISK_BLK0 0 /* blkno of boot block */ +#define DISK_BLK0SZ 512 /* size of boot block */ +#define DISK_BOOTSZ 446 /* size of boot code in boot block */ #define DISK_SIGNATURE 0xAA55 /* signature of the boot record */ -#define FDISK_NPART 4 /* number of entries in fdisk table */ +#define FDISK_NPART 4 /* number of entries in fdisk table */ #define FDISK_ACTIVE 0x80 /* indicator of active partition */ #define FDISK_NEXTNAME 0xA7 /* indicator of NeXT partition */ -#define FDISK_DOS12 0x01 /* 12-bit fat < 10MB dos partition */ +#define FDISK_DOS12 0x01 /* 12-bit fat < 10MB dos partition */ #define FDISK_DOS16S 0x04 /* 16-bit fat < 32MB dos partition */ #define FDISK_DOSEXT 0x05 /* extended dos partition */ #define FDISK_DOS16B 0x06 /* 16-bit fat >= 32MB dos partition */ -#define FDISK_NTFS 0x07 /* NTFS partition */ -#define FDISK_SMALLFAT32 0x0b /* FAT32 partition */ -#define FDISK_FAT32 0x0c /* FAT32 partition */ -#define FDISK_DOS16SLBA 0x0e -#define FDISK_LINUX 0x83 +#define FDISK_NTFS 0x07 /* NTFS partition */ +#define FDISK_SMALLFAT32 0x0b /* FAT32 partition */ +#define FDISK_FAT32 0x0c /* FAT32 partition */ +#define FDISK_DOS16SLBA 0x0e +#define FDISK_LINUX 0x83 #define FDISK_OPENBSD 0xa6 /* OpenBSD FFS partition */ #define FDISK_FREEBSD 0xa5 /* FreeBSD UFS2 partition */ #define FDISK_BEFS 0xeb /* Haiku BeFS partition */ -#define FDISK_UFS 0xa8 /* Apple UFS partition */ -#define FDISK_HFS 0xaf /* Apple HFS partition */ +#define FDISK_UFS 0xa8 /* Apple UFS partition */ +#define FDISK_HFS 0xaf /* Apple HFS partition */ #define FDISK_BOOTER 0xab /* Apple booter partition */ /* Index: branches/ErmaC/Trunk/i386/libsaio/nvidia.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/nvidia.c (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/nvidia.c (revision 1996) @@ -64,25 +64,13 @@ #define DBG(x...) #endif -#define NVIDIA_ROM_SIZE 0x10000 -#define PATCH_ROM_SUCCESS 1 -#define PATCH_ROM_SUCCESS_HAS_LVDS 2 -#define PATCH_ROM_FAILED 0 -#define MAX_NUM_DCB_ENTRIES 16 -#define TYPE_GROUPED 0xff -#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" }; @@ -94,14 +82,9 @@ 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, @@ -109,8 +92,6 @@ 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. @@ -257,7 +238,7 @@ { 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" }, @@ -339,8 +320,17 @@ { 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 @@ -371,31 +361,36 @@ // 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 @@ -405,6 +400,7 @@ { 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" }, @@ -413,6 +409,7 @@ { 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" }, @@ -425,6 +422,11 @@ { 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" }, @@ -434,9 +436,15 @@ { 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 @@ -444,13 +452,16 @@ // 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" }, @@ -539,15 +550,28 @@ // 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 @@ -575,7 +599,42 @@ { 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 @@ -692,6 +751,8 @@ // 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" }, @@ -733,6 +794,7 @@ { 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" }, @@ -772,8 +834,11 @@ { 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 @@ -838,11 +903,32 @@ // 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" }, @@ -872,6 +958,7 @@ { 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" }, @@ -889,11 +976,23 @@ // 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" }, @@ -1483,7 +1582,7 @@ { 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" }, @@ -1819,7 +1918,7 @@ { 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 @@ -2128,7 +2227,7 @@ 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)) { @@ -2189,7 +2288,7 @@ 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 @@ -2258,17 +2357,26 @@ // 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; @@ -2538,7 +2646,7 @@ //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 Index: branches/ErmaC/Trunk/i386/libsaio/ati.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/ati.c (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/ati.c (revision 1996) @@ -278,6 +278,7 @@ { 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 }, @@ -412,6 +413,7 @@ { 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 }, Index: branches/ErmaC/Trunk/i386/libsaio/nvidia.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/nvidia.h (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/nvidia.h (revision 1996) @@ -65,11 +65,29 @@ #define DCB_LOC_ON_CHIP 0 -struct bios { +struct bios +{ uint16_t signature; /* 0x55AA */ uint8_t size; /* Size in multiples of 512 */ }; +#define NVIDIA_ROM_SIZE 0x10000 +#define PATCH_ROM_SUCCESS 1 +#define PATCH_ROM_SUCCESS_HAS_LVDS 2 +#define PATCH_ROM_FAILED 0 +#define MAX_NUM_DCB_ENTRIES 16 +#define TYPE_GROUPED 0xff +#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_IDS 0x00000000 #define NV_PMC_OFFSET 0x000000 #define NV_PMC_SIZE 0x2ffff Index: branches/ErmaC/Trunk/i386/libsaio/disk.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/disk.c (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/disk.c (revision 1996) @@ -1022,113 +1022,130 @@ 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; idpme_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; } //========================================================================== @@ -1140,319 +1157,332 @@ */ 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) @@ -1473,9 +1503,9 @@ if (!loadConfigFile(dirSpec, &systemVersion)) { - bvr->OSisServer = true; + bvr->OSisServer = true; valid = true; - } + } } if (valid) @@ -1501,61 +1531,61 @@ 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) @@ -1569,220 +1599,245 @@ 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; } //========================================================================== @@ -1814,32 +1869,36 @@ 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. @@ -1849,102 +1908,120 @@ 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); } //========================================================================== @@ -1980,39 +2057,43 @@ /* * 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; } //========================================================================== @@ -2020,8 +2101,8 @@ 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; } //========================================================================== @@ -2029,50 +2110,54 @@ 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 ) @@ -2082,33 +2167,37 @@ 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) Index: branches/ErmaC/Trunk/i386/libsaio/saio_types.h =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/saio_types.h (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/saio_types.h (revision 1996) @@ -41,20 +41,25 @@ 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 +{ long type; char *string; long offset; @@ -63,17 +68,21 @@ }; typedef struct Tag Tag, *TagPtr; -typedef struct { + +typedef struct +{ char plist[16384]; // buffer for plist - TagPtr dictionary; // buffer for xml dictionary + TagPtr dictionary; // buffer for xml dictionary bool canOverride; // 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; @@ -94,12 +103,14 @@ 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; @@ -110,23 +121,27 @@ 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; +struct BootVolume; typedef struct BootVolume * BVRef; typedef struct BootVolume * CICell; @@ -142,14 +157,15 @@ // 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 */ @@ -161,41 +177,44 @@ 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, @@ -205,16 +224,18 @@ 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, @@ -228,10 +249,10 @@ //#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, @@ -252,16 +273,18 @@ #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))*/ +#define round2(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 }; Index: branches/ErmaC/Trunk/i386/libsaio/msdos.c =================================================================== --- branches/ErmaC/Trunk/i386/libsaio/msdos.c (revision 1995) +++ branches/ErmaC/Trunk/i386/libsaio/msdos.c (revision 1996) @@ -152,14 +152,20 @@ } 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; @@ -167,20 +173,24 @@ 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); @@ -193,7 +203,8 @@ 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)) @@ -234,6 +245,10 @@ 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); @@ -294,9 +309,10 @@ 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 @@ -382,14 +398,14 @@ 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; } } @@ -649,10 +665,19 @@ 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)) { @@ -685,6 +710,12 @@ 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 @@ -692,6 +723,12 @@ 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; @@ -739,7 +776,7 @@ int toread, wastoread; char *ptr = (char *)base; struct direntry *dirp; - int i; + uint64_t i; char devStr[12]; if (MSDOSInitPartition (ih)<0) @@ -747,6 +784,10 @@ if (filePath[0] == '/') filePath++; buf = malloc(msdosclustersize); + if (!buf) + { + return -1; + } dirp = getdirpfrompath (ih, filePath, buf); if (!dirp || (dirp->deAttributes & ATTR_DIRECTORY)) @@ -759,7 +800,10 @@ 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;isize-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)) @@ -777,7 +821,7 @@ 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); @@ -800,6 +844,10 @@ if (filePath[0] == '/') filePath++; buf = malloc(msdosclustersize); + if (!buf) + { + return -1; + } dirp = getdirpfrompath (ih, filePath, buf); if (!dirp || (dirp->deAttributes & ATTR_DIRECTORY)) { @@ -842,28 +890,28 @@ 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) { - int i, len; - uint16_t labelucs[13]; - //unsigned char labelUTF8[LABEL_LENGTH*3]; + int i, len; + uint16_t labelucs[13]; + //unsigned char labelUTF8[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) @@ -876,8 +924,8 @@ void MSDOSGetDescription(CICell ih, char *str, long strMaxLen) { - struct direntry *dirp; - uint8_t label[LABEL_LENGTH+1]; + struct direntry *dirp; + uint8_t label[LABEL_LENGTH+1]; uint16_t vfatlabel[WIN_MAXLEN+2*WIN_CHARS]; struct msdosdirstate st; int labelfound = 0; @@ -887,11 +935,15 @@ 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); @@ -910,33 +962,46 @@ 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); Index: branches/ErmaC/Trunk/i386/boot2/picopng.c =================================================================== --- branches/ErmaC/Trunk/i386/boot2/picopng.c (revision 1995) +++ branches/ErmaC/Trunk/i386/boot2/picopng.c (revision 1996) @@ -60,6 +60,10 @@ void png_alloc_remove_node(png_alloc_node_t *node) { + if (!node) + { + return; + } if (node->prev) node->prev->next = node->next; if (node->next) @@ -85,7 +89,7 @@ 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); @@ -96,10 +100,12 @@ 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); } @@ -157,9 +163,17 @@ 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; } @@ -211,9 +225,17 @@ 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; } @@ -221,6 +243,10 @@ { 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; @@ -229,13 +255,13 @@ /*************************************************************************************************/ 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 }; @@ -250,6 +276,10 @@ HuffmanTree *HuffmanTree_new() { HuffmanTree *tree = png_alloc_malloc(sizeof (HuffmanTree)); + if (!tree) + { + return NULL; + } tree->tree2d = NULL; return tree; } @@ -262,6 +292,10 @@ 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++) @@ -289,6 +323,23 @@ 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, @@ -887,6 +938,10 @@ 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; @@ -937,6 +992,12 @@ 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); @@ -1002,6 +1063,11 @@ 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 @@ -1068,7 +1134,15 @@ } 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; } Index: branches/ErmaC/Trunk/i386/boot2/graphic_utils.c =================================================================== --- branches/ErmaC/Trunk/i386/boot2/graphic_utils.c (revision 1995) +++ branches/ErmaC/Trunk/i386/boot2/graphic_utils.c (revision 1996) @@ -7,9 +7,9 @@ #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; @@ -17,52 +17,55 @@ 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; } @@ -72,10 +75,11 @@ //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; } } Index: branches/ErmaC/Trunk/i386/modules/Resolution/915resolution.c =================================================================== --- branches/ErmaC/Trunk/i386/modules/Resolution/915resolution.c (revision 1995) +++ branches/ErmaC/Trunk/i386/modules/Resolution/915resolution.c (revision 1996) @@ -253,6 +253,10 @@ { UInt32 z; vbios_map * map = malloc(sizeof(vbios_map)); + if (!map) + { + return 0; + } for(z=0; zb1); outb(CONFIG_MECH_ONE_DATA + 2, map->b2); break; + default: + break; } #if DEBUG @@ -863,9 +871,11 @@ { break; } + default: + break; } // } // } } -#endif // _RESOLUTION_H_ \ No newline at end of file +#endif // _RESOLUTION_H_ Index: branches/ErmaC/Trunk/i386/modules/Resolution/edid.c =================================================================== --- branches/ErmaC/Trunk/i386/modules/Resolution/edid.c (revision 1995) +++ branches/ErmaC/Trunk/i386/modules/Resolution/edid.c (revision 1996) @@ -334,9 +334,9 @@ 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) @@ -385,6 +385,10 @@ } while(blocks_left); char* ret = malloc(sizeof(edidInfo)); + if (!ret) + { + return 0; + } memcpy(ret, edidInfo, sizeof(edidInfo)); return ret; }