Index: trunk/i386/libsaio/vbe.c =================================================================== --- trunk/i386/libsaio/vbe.c (revision 2475) +++ trunk/i386/libsaio/vbe.c (revision 2476) @@ -33,8 +33,6 @@ static biosBuf_t bb; -#if UNUSED - //============================================================================== #if UNUSED static inline void @@ -71,8 +69,6 @@ #endif /* UNUSED */ //============================================================================== -#endif /* UNUSED */ - int getVBEInfo( void * infoBlock ) { bb.intno = 0x10; Index: trunk/i386/libsaio/hfs.c =================================================================== --- trunk/i386/libsaio/hfs.c (revision 2475) +++ trunk/i386/libsaio/hfs.c (revision 2476) @@ -2,7 +2,7 @@ * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ - * + * * The contents of this file constitute Original Code as defined in and * are subject to the Apple Public Source License Version 2.0 (the * "License"). You may not use this file except in compliance with the @@ -16,10 +16,10 @@ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. - * + * * @APPLE_LICENSE_HEADER_END@ - */ -/* + * + * * hfs.c - File System Module for HFS and HFS+. * * Copyright (c) 1999-2002 Apple Computer, Inc. @@ -119,18 +119,17 @@ // Don't bother with location } - //============================================================================== void HFSFree(CICell ih) { - if(gCurrentIH == ih) { + if(gCurrentIH == ih) + { gCurrentIH = 0; } free(ih); } - //============================================================================== bool HFSProbe (const void *buf) @@ -150,7 +149,6 @@ return true; } - //============================================================================== long HFSInitPartition(CICell ih) @@ -284,7 +282,6 @@ return 0; } - //============================================================================== long HFSLoadFile(CICell ih, char * filePath) @@ -352,9 +349,9 @@ } getDeviceDescription(ih, devStr); - verbose("Read HFS%s file: [%s/%s] %d bytes.\n", - (gIsHFSPlus ? "+" : ""), devStr, filePath, (uint32_t)length); + verbose("Read HFS%s file: [%s/%s] %d bytes.\n", (gIsHFSPlus ? "+" : ""), devStr, filePath, (uint32_t)length); + return length; } @@ -365,37 +362,76 @@ char entry[512]; long dirID, dirFlags; - if (HFSInitPartition(ih) == -1) return -1; + if (HFSInitPartition(ih) == -1) + { + return -1; + } - if (*dirIndex == -1) return -1; + if (*dirIndex == -1) + { + return -1; + } - dirID = kHFSRootFolderID; - // Skip a lead '/'. Start in the system folder if there are two. - if (dirPath[0] == '/') { - if (dirPath[1] == '/') { - if (gIsHFSPlus) dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]); - else dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]); - if (dirID == 0) return -1; - dirPath++; - } - dirPath++; - } + dirID = kHFSRootFolderID; - if (*dirIndex == 0) { - ResolvePathToCatalogEntry(dirPath, &dirFlags, entry, dirID, dirIndex); - if (*dirIndex == 0) *dirIndex = -1; - if ((dirFlags & kFileTypeMask) != kFileTypeUnknown) return -1; - } + // Skip a lead '/'. Start in the system folder if there are two. + if (dirPath[0] == '/') + { + if (dirPath[1] == '/') + { + if (gIsHFSPlus) + { + dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]); + } + else + { + dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]); + } - GetCatalogEntry(dirIndex, name, flags, time, finderInfo, infoValid); - if (*dirIndex == 0) *dirIndex = -1; - if ((*flags & kFileTypeMask) == kFileTypeUnknown) return -1; + if (dirID == 0) + { + return -1; + } - return 0; + dirPath++; + } + + dirPath++; + } + + if (*dirIndex == 0) + { + ResolvePathToCatalogEntry(dirPath, &dirFlags, entry, dirID, dirIndex); + + if (*dirIndex == 0) + { + *dirIndex = -1; + } + + if ((dirFlags & kFileTypeMask) != kFileTypeUnknown) + { + return -1; + } + } + + GetCatalogEntry(dirIndex, name, flags, time, finderInfo, infoValid); + + if (*dirIndex == 0) + { + *dirIndex = -1; + } + + if ((*flags & kFileTypeMask) == kFileTypeUnknown) + { + return -1; + } + + return 0; } -void -HFSGetDescription(CICell ih, char *str, long strMaxLen) +//============================================================================== + +void HFSGetDescription(CICell ih, char *str, long strMaxLen) { UInt16 nodeSize; @@ -404,24 +440,28 @@ char *name; long flags, time; - if (HFSInitPartition(ih) == -1) { return; } + if (HFSInitPartition(ih) == -1) + { + return; + } /* Fill some crucial data structures by side effect. */ dirIndex = 0; HFSGetDirEntry(ih, "/", &dirIndex, &name, &flags, &time, 0, 0); - /* Now we can loook up the volume name node. */ - nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize); - firstLeafNode = SWAP_BE32(gBTHeaders[kBTreeCatalog]->firstLeafNode); + /* Now we can loook up the volume name node. */ + nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize); + firstLeafNode = SWAP_BE32(gBTHeaders[kBTreeCatalog]->firstLeafNode); - dirIndex = (long long) firstLeafNode * nodeSize; + dirIndex = (long long) firstLeafNode * nodeSize; - GetCatalogEntry(&dirIndex, &name, &flags, &time, 0, 0); + GetCatalogEntry(&dirIndex, &name, &flags, &time, 0, 0); - strncpy(str, name, strMaxLen); - str[strMaxLen] = '\0'; + strncpy(str, name, strMaxLen); + str[strMaxLen] = '\0'; } +//============================================================================== long HFSGetFileBlock(CICell ih, char *filePath, unsigned long long *firstBlock) { @@ -431,34 +471,49 @@ HFSCatalogFile *hfsFile = (void *)entry; HFSPlusCatalogFile *hfsPlusFile = (void *)entry; - if (HFSInitPartition(ih) == -1) return -1; + if (HFSInitPartition(ih) == -1) + { + return -1; + } - dirID = kHFSRootFolderID; - // Skip a lead '/'. Start in the system folder if there are two. - if (filePath[0] == '/') { - if (filePath[1] == '/') { - if (gIsHFSPlus) dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]); - else dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]); - if (dirID == 0) { + dirID = kHFSRootFolderID; + // Skip a lead '/'. Start in the system folder if there are two. + if (filePath[0] == '/') + { + if (filePath[1] == '/') + { + if (gIsHFSPlus) + { + dirID = SWAP_BE32(((long *) gHFSPlus->finderInfo)[5]); + } + else + { + dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]); + } + + if (dirID == 0) + { + return -1; + } + filePath++; + } + filePath++; + } + + result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0); + + if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) + { + printf("HFS: Resolve path %s failed\n", filePath); return -1; - } - filePath++; - } - filePath++; - } + } - result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0); - if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) { - printf("HFS: Resolve path %s failed\n", filePath); - return -1; - } + if (gIsHFSPlus) { + extents = &hfsPlusFile->dataFork.extents; + } else { + extents = &hfsFile->dataExtents; + } - if (gIsHFSPlus) { - extents = &hfsPlusFile->dataFork.extents; - } else { - extents = &hfsFile->dataExtents; - } - #if DEBUG printf("extent start 0x%x\n", (unsigned long)GetExtentStart(extents, 0)); printf("block size 0x%x\n", (unsigned long)gBlockSize); @@ -468,14 +523,25 @@ return 0; } + +//============================================================================== + long HFSGetUUID(CICell ih, char *uuidStr) { - if (HFSInitPartition(ih) == -1) return -1; - if (gVolID == 0LL) return -1; + if (HFSInitPartition(ih) == -1) + { + return -1; + } - return CreateUUIDString((uint8_t*)(&gVolID), sizeof(gVolID), uuidStr); + if (gVolID == 0LL) + { + return -1; + } + + return CreateUUIDString((uint8_t*)(&gVolID), sizeof(gVolID), uuidStr); } +//============================================================================== // Private Functions static long ReadFile(void * file, uint64_t * length, void * base, uint64_t offset) @@ -486,34 +552,42 @@ HFSCatalogFile *hfsFile = file; HFSPlusCatalogFile *hfsPlusFile = file; - if (gIsHFSPlus) { - fileID = SWAP_BE32(hfsPlusFile->fileID); - fileLength = (uint64_t)SWAP_BE64(hfsPlusFile->dataFork.logicalSize); - extents = &hfsPlusFile->dataFork.extents; - } else { - fileID = SWAP_BE32(hfsFile->fileID); - fileLength = SWAP_BE32(hfsFile->dataLogicalSize); - extents = &hfsFile->dataExtents; - } + if (gIsHFSPlus) + { + fileID = SWAP_BE32(hfsPlusFile->fileID); + fileLength = (uint64_t)SWAP_BE64(hfsPlusFile->dataFork.logicalSize); + extents = &hfsPlusFile->dataFork.extents; + } + else + { + fileID = SWAP_BE32(hfsFile->fileID); + fileLength = SWAP_BE32(hfsFile->dataLogicalSize); + extents = &hfsFile->dataExtents; + } - if (offset > fileLength) { - printf("Offset is too large.\n"); - return -1; - } + if (offset > fileLength) + { + printf("Offset is too large.\n"); - if ((*length == 0) || ((offset + *length) > fileLength)) { - *length = fileLength - offset; - } + return -1; + } -/* if (*length > kLoadSize) { - printf("File is too large.\n"); - return -1; - }*/ + if ((*length == 0) || ((offset + *length) > fileLength)) + { + *length = fileLength - offset; + } - *length = ReadExtent((char *)extents, fileLength, fileID, - offset, *length, (char *)base, 0); +/* + if (*length > kLoadSize) + { + printf("File is too large.\n"); + return -1; + } +*/ - return 0; + *length = ReadExtent((char *)extents, fileLength, fileID, offset, *length, (char *)base, 0); + + return 0; } static long GetCatalogEntryInfo(void * entry, long * flags, long * time, @@ -522,60 +596,69 @@ long tmpTime = 0; long valid = 0; - // Get information about the file. + // Get information about the file. - switch ( SWAP_BE16(*(short *)entry) ) - { - case kHFSFolderRecord : - *flags = kFileTypeDirectory; - tmpTime = SWAP_BE32(((HFSCatalogFolder *)entry)->modifyDate); - break; + switch ( SWAP_BE16(*(short *)entry) ) + { + case kHFSFolderRecord : + *flags = kFileTypeDirectory; + tmpTime = SWAP_BE32(((HFSCatalogFolder *)entry)->modifyDate); + break; - case kHFSPlusFolderRecord : - *flags = kFileTypeDirectory | - (SWAP_BE16(((HFSPlusCatalogFolder *)entry)->bsdInfo.fileMode) & kPermMask); - if (SWAP_BE32(((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID) != 0) - *flags |= kOwnerNotRoot; - tmpTime = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->contentModDate); - break; + case kHFSPlusFolderRecord : + *flags = kFileTypeDirectory | (SWAP_BE16(((HFSPlusCatalogFolder *)entry)->bsdInfo.fileMode) & kPermMask); + if (SWAP_BE32(((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID) != 0) + { + *flags |= kOwnerNotRoot; + } + tmpTime = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->contentModDate); + break; - case kHFSFileRecord : - *flags = kFileTypeFlat; - tmpTime = SWAP_BE32(((HFSCatalogFile *)entry)->modifyDate); - if (finderInfo) { - SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSCatalogFile *)entry)->userInfo); - valid = 1; - } - break; + case kHFSFileRecord : + *flags = kFileTypeFlat; + tmpTime = SWAP_BE32(((HFSCatalogFile *)entry)->modifyDate); + if (finderInfo) + { + SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSCatalogFile *)entry)->userInfo); + valid = 1; + } + break; - case kHFSPlusFileRecord : - *flags = kFileTypeFlat | - (SWAP_BE16(((HFSPlusCatalogFile *)entry)->bsdInfo.fileMode) & kPermMask); - if (SWAP_BE32(((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID) != 0) - *flags |= kOwnerNotRoot; - tmpTime = SWAP_BE32(((HFSPlusCatalogFile *)entry)->contentModDate); - if (finderInfo) { - SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSPlusCatalogFile *)entry)->userInfo); - valid = 1; - } - break; + case kHFSPlusFileRecord : + *flags = kFileTypeFlat | (SWAP_BE16(((HFSPlusCatalogFile *)entry)->bsdInfo.fileMode) & kPermMask); + if (SWAP_BE32(((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID) != 0) + { + *flags |= kOwnerNotRoot; + } + tmpTime = SWAP_BE32(((HFSPlusCatalogFile *)entry)->contentModDate); + if (finderInfo) + { + SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSPlusCatalogFile *)entry)->userInfo); + valid = 1; + } + 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; + } - if (time != 0) { - // Convert base time from 1904 to 1970. - *time = tmpTime - 2082844800; - } - if (infoValid) *infoValid = valid; + if (time != 0) + { + // Convert base time from 1904 to 1970. + *time = tmpTime - 2082844800; + } - return 0; + if (infoValid) + { + *infoValid = valid; + } + + return 0; } static long ResolvePathToCatalogEntry(char * filePath, long * flags, @@ -586,48 +669,64 @@ long long tmpDirIndex; HFSPlusCatalogFile *hfsPlusFile; - // Copy the file name to gTempStr - cnt = 0; - while ((filePath[cnt] != '/') && (filePath[cnt] != '\0')) cnt++; - strlcpy(gTempStr, filePath, cnt+1); + // Copy the file name to gTempStr + cnt = 0; + while ((filePath[cnt] != '/') && (filePath[cnt] != '\0')) + { + cnt++; + } - // Move restPath to the right place. - if (filePath[cnt] != '\0') cnt++; - restPath = filePath + cnt; + strlcpy(gTempStr, filePath, cnt+1); - // gTempStr is a name in the current Dir. - // restPath is the rest of the path if any. + // Move restPath to the right place. + if (filePath[cnt] != '\0') + { + cnt++; + } - result = ReadCatalogEntry(gTempStr, dirID, entry, dirIndex); - if (result == -1) { - return -1; - } + restPath = filePath + cnt; - GetCatalogEntryInfo(entry, flags, 0, 0, 0); + // gTempStr is a name in the current Dir. + // restPath is the rest of the path if any. - if ((*flags & kFileTypeMask) == kFileTypeDirectory) { - if (gIsHFSPlus) - subFolderID = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->folderID); - else - subFolderID = SWAP_BE32(((HFSCatalogFolder *)entry)->folderID); - } + result = ReadCatalogEntry(gTempStr, dirID, entry, dirIndex); - if ((*flags & kFileTypeMask) == kFileTypeDirectory) - result = ResolvePathToCatalogEntry(restPath, flags, entry, - subFolderID, dirIndex); + if (result == -1) + { + return -1; + } - if (gIsHFSPlus && ((*flags & kFileTypeMask) == kFileTypeFlat)) { - hfsPlusFile = (HFSPlusCatalogFile *)entry; - if ((SWAP_BE32(hfsPlusFile->userInfo.fdType) == kHardLinkFileType) && - (SWAP_BE32(hfsPlusFile->userInfo.fdCreator) == kHFSPlusCreator)) { - sprintf(gLinkTemp, "%s/%s%ld", HFSPLUSMETADATAFOLDER, - HFS_INODE_PREFIX, SWAP_BE32(hfsPlusFile->bsdInfo.special.iNodeNum)); - result = ResolvePathToCatalogEntry(gLinkTemp, flags, entry, - kHFSRootFolderID, &tmpDirIndex); - } - } + GetCatalogEntryInfo(entry, flags, 0, 0, 0); - return result; + if ((*flags & kFileTypeMask) == kFileTypeDirectory) + { + if (gIsHFSPlus) + { + subFolderID = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->folderID); + } + else + { + subFolderID = SWAP_BE32(((HFSCatalogFolder *)entry)->folderID); + } + } + + if ((*flags & kFileTypeMask) == kFileTypeDirectory) + { + result = ResolvePathToCatalogEntry(restPath, flags, entry, subFolderID, dirIndex); + } + + if (gIsHFSPlus && ((*flags & kFileTypeMask) == kFileTypeFlat)) + { + hfsPlusFile = (HFSPlusCatalogFile *)entry; + + if ((SWAP_BE32(hfsPlusFile->userInfo.fdType) == kHardLinkFileType) && (SWAP_BE32(hfsPlusFile->userInfo.fdCreator) == kHFSPlusCreator)) + { + sprintf(gLinkTemp, "%s/%s%ld", HFSPLUSMETADATAFOLDER, HFS_INODE_PREFIX, SWAP_BE32(hfsPlusFile->bsdInfo.special.iNodeNum)); + result = ResolvePathToCatalogEntry(gLinkTemp, flags, entry, kHFSRootFolderID, &tmpDirIndex); + } + } + + return result; } static long GetCatalogEntry(long long * dirIndex, char ** name, @@ -639,52 +738,59 @@ char *nodeBuf, *testKey, *entry; BTNodeDescriptor *node; - if (gIsHFSPlus) { - extent = &gHFSPlus->catalogFile.extents; - extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize); - } else { - extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec; - extentSize = SWAP_BE32(gHFSMDB->drCTFlSize); - } + if (gIsHFSPlus) + { + extent = &gHFSPlus->catalogFile.extents; + extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize); + } + else + { + extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec; + extentSize = SWAP_BE32(gHFSMDB->drCTFlSize); + } - nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize); - nodeBuf = (char *)malloc(nodeSize); - node = (BTNodeDescriptor *)nodeBuf; + nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize); + nodeBuf = (char *)malloc(nodeSize); + node = (BTNodeDescriptor *)nodeBuf; index = (long) (*dirIndex % nodeSize); curNode = (long) (*dirIndex / nodeSize); - // Read the BTree node and get the record for index. - ReadExtent(extent, extentSize, kHFSCatalogFileID, - (long long) curNode * nodeSize, nodeSize, nodeBuf, 1); - GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &entry); + // Read the BTree node and get the record for index. + ReadExtent(extent, extentSize, kHFSCatalogFileID, (long long) curNode * nodeSize, nodeSize, nodeBuf, 1); - GetCatalogEntryInfo(entry, flags, time, finderInfo, infoValid); + GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &entry); - // Get the file name. - if (gIsHFSPlus) { - utf_encodestr(((HFSPlusCatalogKey *)testKey)->nodeName.unicode, + GetCatalogEntryInfo(entry, flags, time, finderInfo, infoValid); + + // Get the file name. + if (gIsHFSPlus) + { + utf_encodestr(((HFSPlusCatalogKey *)testKey)->nodeName.unicode, SWAP_BE16(((HFSPlusCatalogKey *)testKey)->nodeName.length), (u_int8_t *)gTempStr, 256, OSBigEndian); - } else { - strncpy(gTempStr, - (const char *)&((HFSCatalogKey *)testKey)->nodeName[1], - ((HFSCatalogKey *)testKey)->nodeName[0]); - gTempStr[((HFSCatalogKey *)testKey)->nodeName[0]] = '\0'; - } - *name = gTempStr; + } + else + { + strncpy(gTempStr, (const char *)&((HFSCatalogKey *)testKey)->nodeName[1], ((HFSCatalogKey *)testKey)->nodeName[0]); - // Update dirIndex. - index++; - if (index == SWAP_BE16(node->numRecords)) { - index = 0; - curNode = SWAP_BE32(node->fLink); - } - *dirIndex = (long long) curNode * nodeSize + index; + gTempStr[((HFSCatalogKey *)testKey)->nodeName[0]] = '\0'; + } + *name = gTempStr; - free(nodeBuf); + // Update dirIndex. + index++; - return 0; + if (index == SWAP_BE16(node->numRecords)) + { + index = 0; + curNode = SWAP_BE32(node->fLink); + } + *dirIndex = (long long) curNode * nodeSize + index; + + free(nodeBuf); + + return 0; } static long ReadCatalogEntry(char * fileName, long dirID, @@ -711,29 +817,34 @@ strncpy((char *)(hfsKey->nodeName + 1), fileName, length); } - return ReadBTreeEntry(kBTreeCatalog, &key, entry, dirIndex); + return ReadBTreeEntry(kBTreeCatalog, &key, entry, dirIndex); } static long ReadExtentsEntry(long fileID, long startBlock, void * entry) { - char key[sizeof(HFSPlusExtentKey)]; - HFSExtentKey *hfsKey = (HFSExtentKey *)key; - HFSPlusExtentKey *hfsPlusKey = (HFSPlusExtentKey *)key; + char key[sizeof(HFSPlusExtentKey)]; + HFSExtentKey *hfsKey = (HFSExtentKey *)key; + HFSPlusExtentKey *hfsPlusKey = (HFSPlusExtentKey *)key; - // Make the extents key. - if (gIsHFSPlus) { - hfsPlusKey->forkType = 0; - hfsPlusKey->fileID = SWAP_BE32(fileID); - hfsPlusKey->startBlock = SWAP_BE32(startBlock); - } else { - hfsKey->forkType = 0; - hfsKey->fileID = SWAP_BE32(fileID); - hfsKey->startBlock = SWAP_BE16(startBlock); - } + // Make the extents key. + if (gIsHFSPlus) + { + hfsPlusKey->forkType = 0; + hfsPlusKey->fileID = SWAP_BE32(fileID); + hfsPlusKey->startBlock = SWAP_BE32(startBlock); + } + else + { + hfsKey->forkType = 0; + hfsKey->fileID = SWAP_BE32(fileID); + hfsKey->startBlock = SWAP_BE16(startBlock); + } - return ReadBTreeEntry(kBTreeExtents, &key, entry, 0); + return ReadBTreeEntry(kBTreeExtents, &key, entry, 0); } +//============================================================================== + static long ReadBTreeEntry(long btree, void * key, char * entry, long long * dirIndex) { long extentSize; @@ -745,121 +856,180 @@ long curNode, index = 0, lowerBound, upperBound; char *testKey, *recordData; - // Figure out which tree is being looked at. - if (btree == kBTreeCatalog) { - if (gIsHFSPlus) { - extent = &gHFSPlus->catalogFile.extents; - extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize); - } else { - extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec; - extentSize = SWAP_BE32(gHFSMDB->drCTFlSize); - } - extentFile = kHFSCatalogFileID; - } else { - if (gIsHFSPlus) { - extent = &gHFSPlus->extentsFile.extents; - extentSize = SWAP_BE64(gHFSPlus->extentsFile.logicalSize); - } else { - extent = (HFSExtentDescriptor *)&gHFSMDB->drXTExtRec; - extentSize = SWAP_BE32(gHFSMDB->drXTFlSize); - } - extentFile = kHFSExtentsFileID; - } + // Figure out which tree is being looked at. + if (btree == kBTreeCatalog) + { + if (gIsHFSPlus) + { + extent = &gHFSPlus->catalogFile.extents; + extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize); + } + else + { + extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec; + extentSize = SWAP_BE32(gHFSMDB->drCTFlSize); + } + extentFile = kHFSCatalogFileID; + } + else + { + if (gIsHFSPlus) + { + extent = &gHFSPlus->extentsFile.extents; + extentSize = SWAP_BE64(gHFSPlus->extentsFile.logicalSize); + } + else + { + extent = (HFSExtentDescriptor *)&gHFSMDB->drXTExtRec; + extentSize = SWAP_BE32(gHFSMDB->drXTFlSize); + } + extentFile = kHFSExtentsFileID; + } - // Read the BTree Header if needed. - if (gBTHeaders[btree] == 0) { - ReadExtent(extent, extentSize, extentFile, 0, 256, - gBTreeHeaderBuffer + btree * 256, 0); - gBTHeaders[btree] = (BTHeaderRec *)(gBTreeHeaderBuffer + btree * 256 + - sizeof(BTNodeDescriptor)); - if ((gIsHFSPlus && btree == kBTreeCatalog) && - (gBTHeaders[btree]->keyCompareType == kHFSBinaryCompare)) { - gCaseSensitive = 1; - } - } + // Read the BTree Header if needed. + if (gBTHeaders[btree] == 0) + { + ReadExtent(extent, extentSize, extentFile, 0, 256, gBTreeHeaderBuffer + btree * 256, 0); + gBTHeaders[btree] = (BTHeaderRec *)(gBTreeHeaderBuffer + btree * 256 + sizeof(BTNodeDescriptor)); - curNode = SWAP_BE32(gBTHeaders[btree]->rootNode); - nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize); - nodeBuf = (char *)malloc(nodeSize); - node = (BTNodeDescriptor *)nodeBuf; + if ((gIsHFSPlus && btree == kBTreeCatalog) && (gBTHeaders[btree]->keyCompareType == kHFSBinaryCompare)) + { + gCaseSensitive = 1; + } + } - while (1) { - // 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; - while (lowerBound <= upperBound) { - index = (lowerBound + upperBound) / 2; + curNode = SWAP_BE32(gBTHeaders[btree]->rootNode); + nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize); + nodeBuf = (char *)malloc(nodeSize); + node = (BTNodeDescriptor *)nodeBuf; - GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData); + while (1) + { + // Read the current node. + ReadExtent(extent, extentSize, extentFile, (long long) curNode * nodeSize, nodeSize, nodeBuf, 1); - if (gIsHFSPlus) { - if (btree == kBTreeCatalog) { - result = CompareHFSPlusCatalogKeys(key, testKey); - } else { - result = CompareHFSPlusExtentsKeys(key, testKey); - } - } else { - if (btree == kBTreeCatalog) { - result = CompareHFSCatalogKeys(key, testKey); - } else { - 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 - } + // Find the matching key. + lowerBound = 0; + upperBound = SWAP_BE16(node->numRecords) - 1; + + while (lowerBound <= upperBound) + { + index = (lowerBound + upperBound) / 2; + + GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData); + + if (gIsHFSPlus) + { + if (btree == kBTreeCatalog) + { + result = CompareHFSPlusCatalogKeys(key, testKey); + } + else + { + result = CompareHFSPlusExtentsKeys(key, testKey); + } + } + else + { + if (btree == kBTreeCatalog) + { + result = CompareHFSCatalogKeys(key, testKey); + } + else + { + 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); + } - if (result < 0) { - index = upperBound; - GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData); - } - - // Found the closest key... Recurse on it if this is an index node. - if (node->kind == kBTIndexNode) { - curNode = SWAP_BE32( *((long *)recordData) ); - } else break; - } - - // Return error if the file was not found. - if (result != 0) { free(nodeBuf); return -1; } + // Found the closest key... Recurse on it if this is an index node. + if (node->kind == kBTIndexNode) + { + curNode = SWAP_BE32( *((long *)recordData) ); + } + else + { + break; + } + } - if (btree == kBTreeCatalog) { - switch (SWAP_BE16(*(short *)recordData)) { - case kHFSFolderRecord : entrySize = 70; break; - case kHFSFileRecord : entrySize = 102; break; - case kHFSFolderThreadRecord : entrySize = 46; break; - case kHFSFileThreadRecord : entrySize = 46; break; - case kHFSPlusFolderRecord : entrySize = 88; break; - case kHFSPlusFileRecord : entrySize = 248; break; - case kHFSPlusFolderThreadRecord : entrySize = 264; break; - case kHFSPlusFileThreadRecord : entrySize = 264; break; - } - } else { - if (gIsHFSPlus) entrySize = sizeof(HFSPlusExtentRecord); - else entrySize = sizeof(HFSExtentRecord); - } - - bcopy(recordData, entry, entrySize); + // Return error if the file was not found. + if (result != 0) + { + free(nodeBuf); + return -1; + } - // Update dirIndex. - if (dirIndex != 0) { - index++; - if (index == SWAP_BE16(node->numRecords)) { - index = 0; - curNode = SWAP_BE32(node->fLink); - } - *dirIndex = (long long) curNode * nodeSize + index; - } - - free(nodeBuf); - - return 0; + if (btree == kBTreeCatalog) + { + switch (SWAP_BE16(*(short *)recordData)) + { + case kHFSFolderRecord : entrySize = 70; + break; + case kHFSFileRecord : entrySize = 102; + break; + case kHFSFolderThreadRecord : entrySize = 46; + break; + case kHFSFileThreadRecord : entrySize = 46; + break; + case kHFSPlusFolderRecord : entrySize = 88; + break; + case kHFSPlusFileRecord : entrySize = 248; + break; + case kHFSPlusFolderThreadRecord : entrySize = 264; + break; + case kHFSPlusFileThreadRecord : entrySize = 264; + break; + } + } + else + { + if (gIsHFSPlus) + { + entrySize = sizeof(HFSPlusExtentRecord); + } + else + { + entrySize = sizeof(HFSExtentRecord); + } + } + + bcopy(recordData, entry, entrySize); + + // Update dirIndex. + if (dirIndex != 0) + { + index++; + if (index == SWAP_BE16(node->numRecords)) + { + index = 0; + curNode = SWAP_BE32(node->fLink); + } + *dirIndex = (long long) curNode * nodeSize + index; + } + + free(nodeBuf); + + return 0; } static void GetBTreeRecord(long index, char * nodeBuffer, long nodeSize, @@ -891,73 +1061,97 @@ 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; - // Find the extent for the offset. - for (; ; nextExtent++) { - if (nextExtent < extentDensity) { - if ((countedBlocks + GetExtentSize(extent, nextExtent) - 1) < blockNumber) { - countedBlocks += GetExtentSize(extent, nextExtent); - continue; - } + while (offset < lastOffset) + { + blockNumber = offset / gBlockSize; - currentExtent = extent + nextExtent * sizeofExtent; - break; - } + // Find the extent for the offset. + for (; ; nextExtent++) + { + if (nextExtent < extentDensity) + { + if ((countedBlocks + GetExtentSize(extent, nextExtent) -1) < blockNumber) + { + countedBlocks += GetExtentSize(extent, nextExtent); + continue; + } - if (extentBuffer == 0) { - extentBuffer = malloc(sizeofExtent * extentDensity); - if (extentBuffer == 0) return -1; - } + currentExtent = extent + nextExtent * sizeofExtent; + break; + } - nextExtentBlock = nextExtent / extentDensity; - if (currentExtentBlock != nextExtentBlock) { - ReadExtentsEntry(extentFile, countedBlocks, extentBuffer); - currentExtentBlock = nextExtentBlock; - } + if (extentBuffer == 0) + { + extentBuffer = malloc(sizeofExtent * extentDensity); - currentExtentSize = GetExtentSize(extentBuffer, nextExtent % extentDensity); + if (extentBuffer == 0) + { + return -1; + } + } - if ((countedBlocks + currentExtentSize - 1) >= blockNumber) { - currentExtent = extentBuffer + sizeofExtent * (nextExtent % extentDensity); - break; - } - - countedBlocks += currentExtentSize; - } + nextExtentBlock = nextExtent / extentDensity; - readOffset = ((blockNumber - countedBlocks) * gBlockSize) + - (offset % gBlockSize); - + if (currentExtentBlock != nextExtentBlock) + { + ReadExtentsEntry(extentFile, countedBlocks, extentBuffer); + currentExtentBlock = nextExtentBlock; + } + + currentExtentSize = GetExtentSize(extentBuffer, nextExtent % extentDensity); + + if ((countedBlocks + currentExtentSize - 1) >= blockNumber) + { + currentExtent = extentBuffer + sizeofExtent * (nextExtent % extentDensity); + break; + } + + countedBlocks += currentExtentSize; + } + + 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; - readOffset += (long long)GetExtentStart(currentExtent, 0) * gBlockSize; - - CacheRead(gCurrentIH, bufferPos, gAllocationOffset + readOffset, - readSize, cache); + if (readSize > (size - sizeRead)) + { + readSize = size - sizeRead; + } - sizeRead += readSize; - offset += readSize; - bufferPos += readSize; - } + readOffset += (long long)GetExtentStart(currentExtent, 0) * gBlockSize; - if (extentBuffer) free(extentBuffer); + CacheRead(gCurrentIH, bufferPos, gAllocationOffset + readOffset, readSize, cache); - return sizeRead; + sizeRead += readSize; + offset += readSize; + bufferPos += readSize; + } + + if (extentBuffer) + { + free(extentBuffer); + } + + return sizeRead; } static long GetExtentStart(void * extents, long index) @@ -966,10 +1160,16 @@ 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) @@ -984,132 +1184,192 @@ 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; - - searchKey = key; - trialKey = testKey; - - searchParentID = SWAP_BE32(searchKey->parentID); - trialParentID = SWAP_BE32(trialKey->parentID); + HFSPlusCatalogKey *searchKey, *trialKey; + long result, searchParentID, trialParentID; - // 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], + searchKey = key; + trialKey = testKey; + + 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], 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) { - HFSExtentKey *searchKey, *trialKey; - long result; - - searchKey = key; - trialKey = testKey; - - // assume searchKey < trialKey - result = -1; + HFSExtentKey *searchKey, *trialKey; + long result; - if (searchKey->fileID == trialKey->fileID) { - // FileNum's are equal; compare fork types - if (searchKey->forkType == trialKey->forkType) { - // Fork types are equal; compare allocation block number - if (searchKey->startBlock == trialKey->startBlock) { - // Everything is equal - result = 0; - } else { - // Allocation block numbers differ; determine sign - if (SWAP_BE16(searchKey->startBlock) > SWAP_BE16(trialKey->startBlock)) - result = 1; - } - } else { - // Fork types differ; determine sign - if (searchKey->forkType > trialKey->forkType) result = 1; - } - } else { - // FileNums differ; determine sign - if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID)) - result = 1; - } + searchKey = key; + trialKey = testKey; - return result; + // assume searchKey < trialKey + result = -1; + + if (searchKey->fileID == trialKey->fileID) + { + // FileNum's are equal; compare fork types + if (searchKey->forkType == trialKey->forkType) + { + // Fork types are equal; compare allocation block number + if (searchKey->startBlock == trialKey->startBlock) + { + // Everything is equal + result = 0; + } + else + { + // Allocation block numbers differ; determine sign + if (SWAP_BE16(searchKey->startBlock) > SWAP_BE16(trialKey->startBlock)) + { + result = 1; + } + } + } + else + { + // Fork types differ; determine sign + if (searchKey->forkType > trialKey->forkType) + { + result = 1; + } + } + } + else + { + // FileNums differ; determine sign + if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID)) + { + result = 1; + } + } + + return result; } + +//============================================================================== + static long CompareHFSPlusExtentsKeys(void * key, void * testKey) { - HFSPlusExtentKey *searchKey, *trialKey; - long result; + HFSPlusExtentKey *searchKey, *trialKey; - searchKey = key; - trialKey = testKey; + long result; - // assume searchKey < trialKey - result = -1; + searchKey = key; + trialKey = testKey; - if (searchKey->fileID == trialKey->fileID) { - // FileNum's are equal; compare fork types - if (searchKey->forkType == trialKey->forkType) { - // Fork types are equal; compare allocation block number - if (searchKey->startBlock == trialKey->startBlock) { - // Everything is equal - result = 0; - } else { - // Allocation block numbers differ; determine sign - if (SWAP_BE32(searchKey->startBlock) > SWAP_BE32(trialKey->startBlock)) - result = 1; - } - } else { - // Fork types differ; determine sign - if (searchKey->forkType > trialKey->forkType) result = 1; - } - } else { - // FileNums differ; determine sign - if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID)) - result = 1; - } + // assume searchKey < trialKey + result = -1; + if (searchKey->fileID == trialKey->fileID) + { + // FileNum's are equal; compare fork types + if (searchKey->forkType == trialKey->forkType) + { + // Fork types are equal; compare allocation block number + if (searchKey->startBlock == trialKey->startBlock) + { + // Everything is equal + result = 0; + } + else + { + // Allocation block numbers differ; determine sign + if (SWAP_BE32(searchKey->startBlock) > SWAP_BE32(trialKey->startBlock)) + { + result = 1; + } + } + } + else + { + // Fork types differ; determine sign + if (searchKey->forkType > trialKey->forkType) + { + result = 1; + } + } + } + else + { + // FileNums differ; determine sign + if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID)) + { + result = 1; + } + } + return result; } Index: trunk/i386/libsaio/allocate.c =================================================================== --- trunk/i386/libsaio/allocate.c (revision 2475) +++ trunk/i386/libsaio/allocate.c (revision 2476) @@ -49,7 +49,8 @@ buffer = malloc(2 * sizeof(uint32_t)); - if (buffer == 0) { + if (buffer == 0) + { free(nameBuf); return -1; } @@ -71,13 +72,15 @@ { long addr; - if (gImageLastKernelAddr == 0) { + if (gImageLastKernelAddr == 0) + { gImageLastKernelAddr = RoundPage(bootArgs->kaddr + bootArgs->ksize); } addr = gImageLastKernelAddr; gImageLastKernelAddr += RoundPage(inSize); - if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) ) { + if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) ) + { stop ("AllocateKernelMemory error"); } Index: trunk/i386/libsaio/bootargs.h =================================================================== --- trunk/i386/libsaio/bootargs.h (revision 2475) +++ trunk/i386/libsaio/bootargs.h (revision 2476) @@ -131,14 +131,20 @@ #define kBootArgsFlagRebootOnPanic (1 << 0) #define kBootArgsFlagHiDPI (1 << 1) #define kBootArgsFlagBlack (1 << 2) +#define kBootArgsFlagCSRActiveConfig (1 << 3) +#define kBootArgsFlagCSRPendingConfig (1 << 4) +#define kBootArgsFlagCSRBoot (1 << 5) +#define kBootArgsFlagBlackBg (1 << 6) +#define kBootArgsFlagLoginUI (1 << 7) -typedef struct boot_args { +typedef struct boot_args +{ uint16_t Revision; /* Revision of boot_args structure */ uint16_t Version; /* Version of boot_args structure */ uint8_t efiMode; /* 32 means 32-bit mode, 64 means 64-bit mode */ uint8_t debugMode; /* Bit field with behavior changes */ - uint16_t flags; // uint8_t __reserved1[2]; + uint16_t flags; char CommandLine[BOOT_LINE_LENGTH]; /* Passed in command line */ @@ -159,29 +165,30 @@ uint32_t efiRuntimeServicesPageCount; uint64_t efiRuntimeServicesVirtualPageStart; /* virtual address of defragmented runtime pages */ - uint32_t efiSystemTable; /* physical address of system table in runtime area */ - uint32_t kslide; // uint32_t __reserved2; + uint32_t efiSystemTable; /* physical address of system table in runtime area */ + uint32_t kslide; - uint32_t performanceDataStart; /* physical address of log */ + uint32_t performanceDataStart; /* physical address of log */ uint32_t performanceDataSize; - uint32_t keyStoreDataStart; /* physical address of key store data */ + uint32_t keyStoreDataStart; /* physical address of key store data */ uint32_t keyStoreDataSize; - uint64_t bootMemStart; /* physical address of interpreter boot memory */ + uint64_t bootMemStart; uint64_t bootMemSize; uint64_t PhysicalMemorySize; uint64_t FSBFrequency; - // + uint64_t pciConfigSpaceBaseAddress; uint32_t pciConfigSpaceStartBusNumber; uint32_t pciConfigSpaceEndBusNumber; - uint32_t __reserved4[730]; - // -// uint32_t __reserved4[734]; + uint32_t csrActiveConfig; + uint32_t csrPendingConfig; + uint32_t __reserved4[728]; } boot_args; -typedef struct boot_args_pre_lion { +typedef struct boot_args_pre_lion +{ uint16_t Revision; /* Revision of boot_args structure */ uint16_t Version; /* Version of boot_args structure */ @@ -202,6 +209,7 @@ uint32_t efiRuntimeServicesPageStart; /* physical address of defragmented runtime pages */ uint32_t efiRuntimeServicesPageCount; + uint32_t efiSystemTable; /* physical address of system table in runtime area */ uint8_t efiMode; /* 32 means 32-bit mode, 64 means 64-bit mode */ Index: trunk/i386/libsaio/dram_controllers.c =================================================================== --- trunk/i386/libsaio/dram_controllers.c (revision 2475) +++ trunk/i386/libsaio/dram_controllers.c (revision 2476) @@ -222,6 +222,7 @@ // Compute RAM Frequency Platform.RAM.Frequency = (Platform.CPU.FSBFrequency * mch_ratio) / 100000; + // DBG("ram_fsb %d\n", Platform.RAM.Frequency); } @@ -236,6 +237,7 @@ // Compute RAM Frequency Platform.RAM.Frequency = Platform.CPU.FSBFrequency * mch_ratio / 2; + // DBG("ram_fsb %d\n", Platform.RAM.Frequency); } /* Index: trunk/i386/libsaio/ntfs.c =================================================================== --- trunk/i386/libsaio/ntfs.c (revision 2475) +++ trunk/i386/libsaio/ntfs.c (revision 2476) @@ -106,8 +106,7 @@ * Find a resident attribute of a given type. Returns a pointer to the * attribute data, and its size in bytes. */ -static int -ntfs_find_attr( +static int ntfs_find_attr( char *buf, u_int32_t attrType, void **attrData, @@ -148,79 +147,78 @@ /* * Examine a volume to see if we recognize it as a mountable. */ -void -NTFSGetDescription(CICell ih, char *str, long strMaxLen) +void NTFSGetDescription(CICell ih, char *str, long strMaxLen) { - struct bootfile *boot; - unsigned bytesPerSector; - unsigned sectorsPerCluster; - int mftRecordSize; - u_int64_t totalClusters; - u_int64_t cluster, mftCluster; - size_t mftOffset; - void *nameAttr; - size_t nameSize; - char *buf; + struct bootfile *boot; + unsigned bytesPerSector; + unsigned sectorsPerCluster; + int mftRecordSize; + u_int64_t totalClusters; + u_int64_t cluster, mftCluster; + size_t mftOffset; + void *nameAttr; + size_t nameSize; + char *buf; - buf = (char *)malloc(MAX_CLUSTER_SIZE); - if (buf == 0) { - goto error; - } + buf = (char *)malloc(MAX_CLUSTER_SIZE); + if (buf == 0) + { + goto error; + } - /* - * Read the boot sector, check signatures, and do some minimal - * sanity checking. NOTE: the size of the read below is intended - * to be a multiple of all supported block sizes, so we don't - * have to determine or change the device's block size. - */ - Seek(ih, 0); - Read(ih, (long)buf, MAX_BLOCK_SIZE); + /* + * Read the boot sector, check signatures, and do some minimal + * sanity checking. NOTE: the size of the read below is intended + * to be a multiple of all supported block sizes, so we don't + * have to determine or change the device's block size. + */ + Seek(ih, 0); + Read(ih, (long)buf, MAX_BLOCK_SIZE); - boot = (struct bootfile *) buf; - - /* - * The first three bytes are an Intel x86 jump instruction. I assume it - * can be the same forms as DOS FAT: - * 0xE9 0x?? 0x?? - * 0xEC 0x?? 0x90 - * where 0x?? means any byte value is OK. - */ - if (boot->reserved1[0] != 0xE9 - && (boot->reserved1[0] != 0xEB || boot->reserved1[2] != 0x90)) - { - goto error; - } + boot = (struct bootfile *) buf; - /* - * Check the "NTFS " signature. - */ - if (memcmp((const char *)boot->bf_sysid, "NTFS ", 8) != 0) - { - /* - * Check for EXFAT. Finish by jumping to error to free buf, - * although if it is EXFAT then it's no an error. - */ - EXFATGetDescription(ih, str, strMaxLen); - goto error; - } + /* + * The first three bytes are an Intel x86 jump instruction. I assume it + * can be the same forms as DOS FAT: + * 0xE9 0x?? 0x?? + * 0xEC 0x?? 0x90 + * where 0x?? means any byte value is OK. + */ + if (boot->reserved1[0] != 0xE9 && (boot->reserved1[0] != 0xEB || boot->reserved1[2] != 0x90)) + { + goto error; + } - /* - * Make sure the bytes per sector and sectors per cluster are - * powers of two, and within reasonable ranges. - */ - bytesPerSector = OSReadLittleInt16(&boot->bf_bps,0); - if ((bytesPerSector & (bytesPerSector-1)) || bytesPerSector < 512 || bytesPerSector > 32768) - { - //verbose("NTFS: invalid bytes per sector (%d)\n", bytesPerSector); - goto error; - } + /* + * Check the "NTFS " signature. + */ + if (memcmp((const char *)boot->bf_sysid, "NTFS ", 8) != 0) + { + /* + * Check for EXFAT. Finish by jumping to error to free buf, + * although if it is EXFAT then it's no an error. + */ + EXFATGetDescription(ih, str, strMaxLen); + goto error; + } - sectorsPerCluster = boot->bf_spc; /* Just one byte; no swapping needed */ - if ((sectorsPerCluster & (sectorsPerCluster-1)) || sectorsPerCluster > 128) - { - //verbose("NTFS: invalid sectors per cluster (%d)\n", bytesPerSector); - goto error; - } + /* + * Make sure the bytes per sector and sectors per cluster are + * powers of two, and within reasonable ranges. + */ + bytesPerSector = OSReadLittleInt16(&boot->bf_bps,0); + if ((bytesPerSector & (bytesPerSector-1)) || bytesPerSector < 512 || bytesPerSector > 32768) + { + //verbose("NTFS: invalid bytes per sector (%d)\n", bytesPerSector); + goto error; + } + + sectorsPerCluster = boot->bf_spc; /* Just one byte; no swapping needed */ + if ((sectorsPerCluster & (sectorsPerCluster-1)) || sectorsPerCluster > 128) + { + //verbose("NTFS: invalid sectors per cluster (%d)\n", bytesPerSector); + goto error; + } /* * Calculate the number of clusters from the number of sectors. @@ -284,22 +282,25 @@ /* * Loop over the attributes, looking for $VOLUME_NAME (0x60). */ - if(ntfs_find_attr(buf, NTFS_A_VOLUMENAME, &nameAttr, &nameSize) != 0) - { - //verbose("NTFS: $VOLUME_NAME attribute not found\n"); - goto error; - } - - str[0] = '\0'; + if(ntfs_find_attr(buf, NTFS_A_VOLUMENAME, &nameAttr, &nameSize) != 0) + { + //verbose("NTFS: $VOLUME_NAME attribute not found\n"); + goto error; + } - utf_encodestr( nameAttr, nameSize / 2, (u_int8_t *)str, strMaxLen, OSLittleEndian ); + str[0] = '\0'; - free(buf); - return; + utf_encodestr( nameAttr, nameSize / 2, (u_int8_t *)str, strMaxLen, OSLittleEndian ); + free(buf); + return; + error: - if (buf) free(buf); - return; + if (buf) + { + free(buf); + } + return; } long NTFSGetUUID(CICell ih, char *uuidStr) @@ -308,7 +309,8 @@ struct bootfile *boot; void *buf = malloc(MAX_BLOCK_SIZE); - if ( !buf ) { + if ( !buf ) + { return -1; } @@ -324,19 +326,20 @@ boot = (struct bootfile *) buf; // Check for NTFS signature - if ( memcmp((void*)boot->bf_sysid, NTFS_BBID, NTFS_BBIDLEN) != 0 ) { + if ( memcmp((void*)boot->bf_sysid, NTFS_BBID, NTFS_BBIDLEN) != 0 ) + { // If not NTFS, maybe it is EXFAT return EXFATGetUUID(ih, uuidStr); } // Check for non-null volume serial number - if( !boot->bf_volsn ) { + if( !boot->bf_volsn ) + { return -1; } // Use UUID like the one you get on Windows - sprintf(uuidStr, "%04X-%04X", (unsigned short)(boot->bf_volsn >> 16) & 0xFFFF, - (unsigned short)boot->bf_volsn & 0xFFFF); + sprintf(uuidStr, "%04X-%04X", (unsigned short)(boot->bf_volsn >> 16) & 0xFFFF, (unsigned short)boot->bf_volsn & 0xFFFF); return 0; } @@ -349,11 +352,15 @@ // Looking for NTFS signature. if (strncmp((const char *)part_bootfile->bf_sysid, NTFS_BBID, NTFS_BBIDLEN) == 0) + { result = true; + } // If not NTFS, maybe it is EXFAT if (!result) + { result = EXFATProbe(buffer); + } return result; } Index: trunk/i386/libsaio/sys.c =================================================================== --- trunk/i386/libsaio/sys.c (revision 2475) +++ trunk/i386/libsaio/sys.c (revision 2476) @@ -161,7 +161,8 @@ // Resolve the boot volume from the file spec. - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) { + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) + { return -1; } @@ -175,11 +176,13 @@ const char *filePath; BVRef bvr; - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) { + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) + { return -1; } - if (bvr->fs_readfile == NULL) { + if (bvr->fs_readfile == NULL) + { return -1; } @@ -197,7 +200,8 @@ // Resolve the boot volume from the file spec. - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) { + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) + { return -1; } @@ -228,19 +232,24 @@ DBG("Fat Binary found. Reading thin part only...\n"); length = readFile(bvr, (char *)filePath, (void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length); *binary = (void *)kLoadAddr; - } else { + } + else + { // Not a fat binary; read the rest of the file DBG("Thin Binary found. Reading rest of the file...\n"); length2 = readFile(bvr, (char *)filePath, (void *)(kLoadAddr + length), length, 0); - if (length2 == -1) { + if (length2 == -1) + { return -1; } length += length2; } } - } else { + } + else + { length = bvr->fs_loadfile(bvr, (char *)filePath); if (length > 0) @@ -248,7 +257,7 @@ ThinFatFile(binary, &length); } } - + return length; } @@ -301,13 +310,16 @@ i = 0; fmtbase = 0; - for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) { - for (i = 0; i < uuidfmt[fmtidx]; i++) { + for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) + { + for (i = 0; i < uuidfmt[fmtidx]; i++) + { uint8_t byte = mdresult[fmtbase + i]; char nib = byte >> 4; *p = nib + '0'; // 0x4 -> '4' - if (*p > '9') { + if (*p > '9') + { *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' } @@ -316,7 +328,8 @@ nib = byte & 0xf; *p = nib + '0'; // 0x4 -> '4' - if (*p > '9') { + if (*p > '9') + { *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' } @@ -325,7 +338,8 @@ fmtbase += i; - if (fmtidx < sizeof(uuidfmt) - 1) { + if (fmtidx < sizeof(uuidfmt) - 1) + { *(p++) = '-'; } else @@ -350,13 +364,14 @@ // Resolve the boot volume from the dir spec. - if ((bvr = getBootVolumeRef(dirSpec, &dirPath)) == NULL) { + if ((bvr = getBootVolumeRef(dirSpec, &dirPath)) == NULL) + { return -1; } - // Returns 0 on success or -1 when there are no additional entries. + // Return 0 on success, or -1 if there are no additional entries. - return bvr->fs_getdirentry( bvr, + return bvr->fs_getdirentry( bvr, /* dirPath */ (char *)dirPath, /* dirIndex */ dirIndex, /* dirEntry */ (char **)name, flags, time, 0, 0 ); @@ -374,7 +389,8 @@ long long index = 0; const char * entryName; - if (gMakeDirSpec == 0) { + if (gMakeDirSpec == 0) + { gMakeDirSpec = (char *)malloc(1024); } @@ -401,7 +417,8 @@ while (GetDirEntry(dirSpec, &index, &entryName, flags, time) == 0) { - if (strcmp(entryName, name) == 0) { + if (strcmp(entryName, name) == 0) + { return 0; // success } } @@ -434,10 +451,12 @@ int fd; // Locate a free descriptor slot. - for (fd = 0; fd < NFILES; fd++) { - if (iob[fd].i_flgs == 0) { + for (fd = 0; fd < NFILES; fd++) + { + if (iob[fd].i_flgs == 0) + { return fd; - } + } } stop("Out of file descriptors"); // not reached @@ -454,9 +473,12 @@ { register struct iob * io; - if (fdesc < 0 || fdesc >= NFILES || ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) { + if (fdesc < 0 || fdesc >= NFILES || ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) + { return NULL; - } else { + } + else + { return io; } } @@ -466,21 +488,21 @@ int openmem(char * buf, int len) { - int fdesc; - struct iob * io; + int fdesc; + struct iob * io; - fdesc = GetFreeFd(); - io = &iob[fdesc]; - bzero(io, sizeof(*io)); + fdesc = GetFreeFd(); + io = &iob[fdesc]; + bzero(io, sizeof(*io)); - // Mark the descriptor as taken. Set the F_MEM flag to indicate - // that the file buffer is provided by the caller. + // Mark the descriptor as taken. Set the F_MEM flag to indicate + // that the file buffer is provided by the caller. - io->i_flgs = F_ALLOC | F_MEM; - io->i_buf = buf; - io->i_filesize = len; + io->i_flgs = F_ALLOC | F_MEM; + io->i_buf = buf; + io->i_filesize = len; - return fdesc; + return fdesc; } //========================================================================== @@ -528,7 +550,8 @@ BVRef bvr; // Resolve the boot volume from the file spec. - if ((bvr = getBootVolumeRef(path, &filepath)) != NULL) { + if ((bvr = getBootVolumeRef(path, &filepath)) != NULL) + { return open_bvr(bvr, filepath, flags); } return -1; @@ -536,7 +559,7 @@ int open_bvdev(const char *bvd, const char *path, int flags) { - const struct devsw *dp; + const struct devsw *dp; const char *cp; BVRef bvr; int i; @@ -544,38 +567,46 @@ int unit; int partition; - if ((i = open(path, flags)) >= 0) { + if ((i = open(path, flags)) >= 0) + { return i; } - if (bvd == NULL || (len = strlen(bvd)) < 2) { + if (bvd == NULL || (len = strlen(bvd)) < 2) + { return -1; } - for (dp=devsw; dp->name; dp++) { - if (bvd[0] == dp->name[0] && bvd[1] == dp->name[1]) { + for (dp=devsw; dp->name; dp++) + { + if (bvd[0] == dp->name[0] && bvd[1] == dp->name[1]) + { unit = 0; partition = 0; /* get optional unit and partition */ if (len >= 5 && bvd[2] == '(') { /* min must be present xx(0) */ cp = &bvd[3]; i = 0; - while ((cp - path) < len && isdigit(*cp)) { + while ((cp - path) < len && isdigit(*cp)) + { i = i * 10 + *cp++ - '0'; unit = i; } - if (*cp++ == ',') { + if (*cp++ == ',') + { i = 0; - while ((cp - path) < len && isdigit(*cp)) { + while ((cp - path) < len && isdigit(*cp)) + { i = i * 10 + *cp++ - '0'; partition = i; } } } bvr = newBootVolumeRef(dp->biosdev + unit, partition); + return open_bvr(bvr, path, flags); } - } + } return -1; } @@ -586,7 +617,8 @@ { struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == NULL) { + if ((io = iob_from_fdesc(fdesc)) == NULL) + { return (-1); } @@ -603,7 +635,8 @@ { struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == NULL) { + if ((io = iob_from_fdesc(fdesc)) == NULL) + { return (-1); } @@ -619,7 +652,8 @@ { struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == NULL) { + if ((io = iob_from_fdesc(fdesc)) == NULL) + { return 0; } @@ -820,7 +854,8 @@ const char * systemConfigDir() { - if (gBootFileType == kNetworkDeviceType) { + if (gBootFileType == kNetworkDeviceType) + { return ""; } return "/Library/Preferences/SystemConfiguration"; @@ -835,12 +870,16 @@ BVRef bvr = 0; bvr = diskScanBootVolumes(biosdev, count); - if (bvr == NULL) { + if (bvr == NULL) + { bvr = nbpScanBootVolumes(biosdev, count); - if (bvr != NULL) { + if (bvr != NULL) + { gBootFileType = kNetworkDeviceType; } - } else { + } + else + { gBootFileType = kBlockDeviceType; } } @@ -854,14 +893,16 @@ int hd = 0; // Testing up to MAX_HDD_COUNT hard drives. - while(!testBiosread(0x80 + hd, 0) && hd < MAX_HDD_COUNT) { + while(!testBiosread(0x80 + hd, 0) && hd < MAX_HDD_COUNT) + { bvCount = 0; scanBootVolumes(0x80 + hd, &bvCount); hd++; } // Also scanning CD/DVD drive. - if (biosDevIsCDROM(gBIOSDev)) { + if (biosDevIsCDROM(gBIOSDev)) + { bvCount = 0; scanBootVolumes(gBIOSDev, &bvCount); } @@ -875,13 +916,17 @@ bool foundPrimary = false; BVRef bvr, bvr1 = 0, bvr2 = 0; - if (chain->filtered) { + if (chain->filtered) + { filteredChain = true; } - if (multiboot_partition_set) { - for ( bvr = chain; bvr; bvr = bvr->next ) { - if ( bvr->part_no == multiboot_partition && bvr->biosdev == gBIOSDev ) { + if (multiboot_partition_set) + { + for ( bvr = chain; bvr; bvr = bvr->next ) + { + if ( bvr->part_no == multiboot_partition && bvr->biosdev == gBIOSDev ) + { return bvr; } } @@ -893,9 +938,12 @@ * We accept only kBVFlagSystemVolume or kBVFlagForeignBoot volumes. */ char *val = XMLDecode(getStringForKey(kDefaultPartition, &bootInfo->chameleonConfig)); - if (val) { - for ( bvr = chain; bvr; bvr = bvr->next ) { - if (matchVolumeToString(bvr, val, false)) { + if (val) + { + for ( bvr = chain; bvr; bvr = bvr->next ) + { + if (matchVolumeToString(bvr, val, false)) + { free(val); return bvr; } @@ -909,11 +957,14 @@ * If not found any active partition then we will * select this volume as the boot volume. */ - for ( bvr = chain; bvr; bvr = bvr->next ) { - if (multiboot_skip_partition_set) { + for ( bvr = chain; bvr; bvr = bvr->next ) + { + if (multiboot_skip_partition_set) + { if (bvr->part_no == multiboot_skip_partition) continue; } - if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) { + if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) + { foundPrimary = true; } @@ -922,7 +973,8 @@ if ( bvr->flags & (kBVFlagBootable|kBVFlagSystemVolume) && gBIOSBootVolume && (!filteredChain || (filteredChain && bvr->visible)) - && bvr->biosdev == gBIOSDev ) { + && bvr->biosdev == gBIOSDev ) + { bvr2 = bvr; } @@ -930,7 +982,8 @@ // from r491, if ( bvr->flags & kBVFlagBootable && ! gBIOSBootVolume - && bvr->biosdev == gBIOSDev ) { + && bvr->biosdev == gBIOSDev ) + { bvr2 = bvr; } } @@ -942,10 +995,12 @@ { for ( bvr = chain; bvr; bvr = bvr->next ) { - if ( bvr->flags & kBVFlagNativeBoot && bvr->biosdev == gBIOSDev ) { + if ( bvr->flags & kBVFlagNativeBoot && bvr->biosdev == gBIOSDev ) + { bvr1 = bvr; } - if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) { + if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) + { bvr2 = bvr; } } @@ -975,7 +1030,8 @@ gRootVolume = volume; // Veto non-native FS. Basically that means don't allow the root volume to // be set to a volume we can't read files from. - if(gRootVolume != NULL && ((gRootVolume->flags & kBVFlagNativeBoot) == 0)) { + if(gRootVolume != NULL && ((gRootVolume->flags & kBVFlagNativeBoot) == 0)) + { gRootVolume = NULL; } } @@ -984,9 +1040,10 @@ { // Record default boot device. gBootVolume = selectBootVolume(chain); - + // turbo - Save the ORIGINAL boot volume too for loading our mkext - if (!gBIOSBootVolume) { + if (!gBIOSBootVolume) + { gBIOSBootVolume = gBootVolume; } @@ -1010,7 +1067,8 @@ // Search for left parenthesis in the path specification. for (cp = path; *cp; cp++) { - if (*cp == LP || *cp == '/') { + if (*cp == LP || *cp == '/') + { break; } } @@ -1019,7 +1077,8 @@ cp = path; // Path is using the implicit current device so if there is // no current device, then we must fail. - if (gRootVolume == NULL) { + if (gRootVolume == NULL) + { return NULL; } } else if ((cp - path) == 2) { // found "xx(" @@ -1034,13 +1093,16 @@ // Check the 2 character device name pointed by 'xp'. - for (dp = devsw; dp->name; dp++) { - if ((xp[0] == dp->name[0]) && (xp[1] == dp->name[1])) { + for (dp = devsw; dp->name; dp++) + { + if ((xp[0] == dp->name[0]) && (xp[1] == dp->name[1])) + { break; // Found matching entry. } } - if (dp->name == NULL) { + if (dp->name == NULL) + { error("Unknown device '%c%c'\n", xp[0], xp[1]); return NULL; } @@ -1050,23 +1112,26 @@ i = 0; - while (*cp >= '0' && *cp <= '9') { + while (*cp >= '0' && *cp <= '9') + { i = i * 10 + *cp++ - '0'; unit = i; } - // Unit is no longer optional and never really was. - // If the user failed to specify it then the unit number from the previous kernDev - // would have been used which makes little sense anyway. - // For example, if the user did fd()/foobar and the current root device was the - // second hard disk (i.e. unit 1) then fd() would select the second floppy drive! - if (unit == -1) { + // Unit is no longer optional and never really was. + // If the user failed to specify it then the unit number from the previous kernDev + // would have been used which makes little sense anyway. + // For example, if the user did fd()/foobar and the current root device was the + // second hard disk (i.e. unit 1) then fd() would select the second floppy drive! + if (unit == -1) + { return NULL; } // Extract the optional partition number from the specification. - if (*cp == ',') { + if (*cp == ',') + { part = atoi(++cp); } @@ -1078,22 +1143,27 @@ for ( ; *cp && *cp != RP; cp++) /* LOOP */; - if (*cp == RP) { + if (*cp == RP) + { cp++; } - + biosdev = dp->biosdev + unit; bvr = newBootVolumeRef(biosdev, part); - if (bvr == NULL) { + if (bvr == NULL) + { return NULL; } - } else { + } + else + { // Bad device specifier, skip past the right paren. for (cp++; *cp && *cp != RP; cp++) /* LOOP */; - if (*cp == RP) { + if (*cp == RP) + { cp++; } @@ -1119,17 +1189,26 @@ bvr = bvr1 = NULL; // Try resolving "rd" and "bt" devices first. - if (biosdev == kPseudoBIOSDevRAMDisk) { - if (gRAMDiskVolume) { + if (biosdev == kPseudoBIOSDevRAMDisk) + { + if (gRAMDiskVolume) + { bvr1 = gRAMDiskVolume; } - } else if (biosdev == kPseudoBIOSDevBooter) { - if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) { + } + else if (biosdev == kPseudoBIOSDevBooter) + { + if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) + { bvr1 = gRAMDiskVolume; - } else { + } + else + { bvr1 = gBIOSBootVolume; } - } else { + } + else + { // Fetch the volume list from the device. scanBootVolumes( biosdev, NULL ); @@ -1137,13 +1216,16 @@ // Look for a perfect match based on device and partition number. - for ( bvr1 = NULL, bvr = bvrChain; bvr; bvr = bvr->next ) { - if ( ( bvr->flags & kBVFlagNativeBoot ) == 0 ) { + for ( bvr1 = NULL, bvr = bvrChain; bvr; bvr = bvr->next ) + { + if ( ( bvr->flags & kBVFlagNativeBoot ) == 0 ) + { continue; } bvr1 = bvr; - if ( bvr->part_no == partno ) { + if ( bvr->part_no == partno ) + { break; } } @@ -1158,19 +1240,23 @@ // Returns length of the out string int getDeviceDescription(BVRef bvr, char *str) { - if(!str) { + if(!str) + { return 0; } *str = '\0'; - if (bvr) { + if (bvr) + { const struct devsw *dp = devsw; - while(dp->name && bvr->biosdev >= dp->biosdev) { + while(dp->name && bvr->biosdev >= dp->biosdev) + { dp++; } dp--; - if (dp->name) { + if (dp->name) + { return sprintf(str, "%s(%d,%d)", dp->name, bvr->biosdev - dp->biosdev, bvr->part_no); } } Index: trunk/i386/libsaio/cpu.c =================================================================== --- trunk/i386/libsaio/cpu.c (revision 2475) +++ trunk/i386/libsaio/cpu.c (revision 2476) @@ -192,18 +192,21 @@ pollCount = poll_PIT2_gate(); aperfEnd = rdmsr64(MSR_AMD_APERF); /* The poll loop must have run at least a few times for accuracy */ - if (pollCount <= 1) { + if (pollCount <= 1) + { continue; } /* The TSC must increment at LEAST once every millisecond. * We should have waited exactly 30 msec so the APERF delta should * be >= 30. Anything less and the processor is way too slow. */ - if ((aperfEnd - aperfStart) <= CALIBRATE_TIME_MSEC) { + if ((aperfEnd - aperfStart) <= CALIBRATE_TIME_MSEC) + { continue; } // tscDelta = MIN(tscDelta, (tscEnd - tscStart)) - if ( (aperfEnd - aperfStart) < aperfDelta ) { + if ( (aperfEnd - aperfStart) < aperfDelta ) + { aperfDelta = aperfEnd - aperfStart; } } @@ -211,9 +214,12 @@ * a timespan of 0.03 s (e.g. 30 milliseconds) */ - if (aperfDelta > (1ULL<<32)) { + if (aperfDelta > (1ULL<<32)) + { retval = 0; - } else { + } + else + { retval = aperfDelta * 1000 / 30; } disable_PIT2(); @@ -258,16 +264,21 @@ do_cpuid2(0x00000004, 0, p->CPU.CPUID[CPUID_4]); do_cpuid(0x80000000, p->CPU.CPUID[CPUID_80]); - if (p->CPU.CPUID[CPUID_0][0] >= 0x5) { + if (p->CPU.CPUID[CPUID_0][0] >= 0x5) + { do_cpuid(5, p->CPU.CPUID[CPUID_5]); } - if (p->CPU.CPUID[CPUID_0][0] >= 6) { + if (p->CPU.CPUID[CPUID_0][0] >= 6) + { do_cpuid(6, p->CPU.CPUID[CPUID_6]); } - if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 8) { + if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 8) + { do_cpuid(0x80000008, p->CPU.CPUID[CPUID_88]); do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]); - } else if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) { + } + else if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) + { do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]); } @@ -601,6 +612,11 @@ maxcoef = currcoef; } + if (!currcoef) + { + currcoef = maxcoef; + } + if (maxcoef) { if (maxdiv) @@ -745,24 +761,24 @@ DBG("\n---------------------------------------------\n"); DBG("------------------ CPU INFO -----------------\n"); DBG("---------------------------------------------\n"); - DBG("Brand String: %s\n", p->CPU.BrandString); // Processor name (BIOS) - DBG("Vendor: 0x%x\n", p->CPU.Vendor); // Vendor ex: GenuineIntel - DBG("Family: 0x%x\n", p->CPU.Family); // Family ex: 6 (06h) - DBG("ExtFamily: 0x%x\n", p->CPU.ExtFamily); - DBG("Signature: %x\n", p->CPU.Signature); // CPUID signature - DBG("Model: 0x%x\n", p->CPU.Model); // Model ex: 37 (025h) - DBG("ExtModel: 0x%x\n", p->CPU.ExtModel); - DBG("Stepping: 0x%x\n", p->CPU.Stepping); // Stepping ex: 5 (05h) - DBG("MaxCoef: 0x%x\n", p->CPU.MaxCoef); - DBG("CurrCoef: 0x%x\n", p->CPU.CurrCoef); - DBG("MaxDiv: 0x%x\n", p->CPU.MaxDiv); - DBG("CurrDiv: 0x%x\n", p->CPU.CurrDiv); - DBG("TSCFreq: %dMHz\n", p->CPU.TSCFrequency / 1000000); - DBG("FSBFreq: %dMHz\n", p->CPU.FSBFrequency / 1000000); - DBG("CPUFreq: %dMHz\n", p->CPU.CPUFrequency / 1000000); - DBG("Cores: %d\n", p->CPU.NoCores); // Cores - DBG("Logical processor: %d\n", p->CPU.NoThreads); // Logical procesor - DBG("Features: 0x%08x\n", p->CPU.Features); + DBG("Brand String: %s\n", p->CPU.BrandString); // Processor name (BIOS) + DBG("Vendor: 0x%x\n", p->CPU.Vendor); // Vendor ex: GenuineIntel + DBG("Family: 0x%x\n", p->CPU.Family); // Family ex: 6 (06h) + DBG("ExtFamily: 0x%x\n", p->CPU.ExtFamily); + DBG("Signature: %x\n", p->CPU.Signature); // CPUID signature + DBG("Model: 0x%x\n", p->CPU.Model); // Model ex: 37 (025h) + DBG("ExtModel: 0x%x\n", p->CPU.ExtModel); + DBG("Stepping: 0x%x\n", p->CPU.Stepping); // Stepping ex: 5 (05h) + DBG("MaxCoef: 0x%x\n", p->CPU.MaxCoef); + DBG("CurrCoef: 0x%x\n", p->CPU.CurrCoef); + DBG("MaxDiv: 0x%x\n", p->CPU.MaxDiv); + DBG("CurrDiv: 0x%x\n", p->CPU.CurrDiv); + DBG("TSCFreq: %dMHz\n", p->CPU.TSCFrequency / 1000000); + DBG("FSBFreq: %dMHz\n", p->CPU.FSBFrequency / 1000000); + DBG("CPUFreq: %dMHz\n", p->CPU.CPUFrequency / 1000000); + DBG("Cores: %d\n", p->CPU.NoCores); // Cores + DBG("Logical processor: %d\n", p->CPU.NoThreads); // Logical procesor + DBG("Features: 0x%08x\n", p->CPU.Features); DBG("\n---------------------------------------------\n"); #if DEBUG_CPU Index: trunk/i386/libsaio/disk.c =================================================================== --- trunk/i386/libsaio/disk.c (revision 2475) +++ trunk/i386/libsaio/disk.c (revision 2476) @@ -717,7 +717,8 @@ int probe, int type, unsigned int bvrFlags ) { BVRef bvr = (BVRef) malloc( sizeof(*bvr) ); - if ( bvr ) { + if ( bvr ) + { bzero(bvr, sizeof(*bvr)); bvr->biosdev = biosdev; @@ -733,14 +734,18 @@ bvr->bv_free = bvFreeFunc; // FIXME: UCS-2 -> UTF-8 the name strlcpy(bvr->name, "----", DPISTRLEN); - if ( (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)part->ent_type) == 0) || (efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)part->ent_type) == 0) ) { + if ( (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)part->ent_type) == 0) || (efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)part->ent_type) == 0) ) + { strlcpy(bvr->type_name, "GPT HFS+", DPISTRLEN); - } else { + } + else + { strlcpy(bvr->type_name, "GPT Unknown", DPISTRLEN); } /* - if ( part->bootid & FDISK_ACTIVE ) { + if ( part->bootid & FDISK_ACTIVE ) + { bvr->flags |= kBVFlagPrimary; } */ @@ -820,45 +825,45 @@ spc = 1; } - do { - // Create a new mapping. + do { + // Create a new mapping. - map = (struct DiskBVMap *) malloc( sizeof(*map) ); - if ( map ) + map = (struct DiskBVMap *) malloc( sizeof(*map) ); + if ( map ) { - 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; - // Create a record for each partition found on the disk. + // Create a record for each partition found on the disk. - while ( getNextFDiskPartition( biosdev, &partno, &part ) ) - { - DEBUG_DISK(("%s: part %d [%x]\n", __FUNCTION__, - partno, part->systid)); - bvr = 0; + while ( getNextFDiskPartition( biosdev, &partno, &part ) ) + { + DEBUG_DISK(("%s: part %d [%x]\n", __FUNCTION__, + partno, part->systid)); + bvr = 0; - switch ( part->systid ) - { + switch ( part->systid ) + { #if UFS_SUPPORT - case FDISK_UFS: - bvr = newFDiskBVRef( - biosdev, partno, - part->relsect + UFS_FRONT_PORCH/BPS, - part, - UFSInitPartition, - UFSLoadFile, - UFSReadFile, - UFSGetDirEntry, - UFSGetFileBlock, - UFSGetUUID, - UFSGetDescription, - UFSFree, - 0, - kBIOSDevTypeHardDrive, 0); - break; + case FDISK_UFS: + bvr = newFDiskBVRef( + biosdev, partno, + part->relsect + UFS_FRONT_PORCH/BPS, + part, + UFSInitPartition, + UFSLoadFile, + UFSReadFile, + UFSGetDirEntry, + UFSGetFileBlock, + UFSGetUUID, + UFSGetDescription, + UFSFree, + 0, + kBIOSDevTypeHardDrive, 0); + break; #endif case FDISK_HFS: @@ -898,8 +903,8 @@ break; #if UFS_SUPPORT - case FDISK_BOOTER: - booterUFS = newFDiskBVRef( + case FDISK_BOOTER: + booterUFS = newFDiskBVRef( biosdev, partno, ((part->relsect + spc - 1) / spc) * spc, part, @@ -913,7 +918,7 @@ UFSFree, 0, kBIOSDevTypeHardDrive, 0); - break; + break; #endif case FDISK_FAT32: @@ -1650,25 +1655,32 @@ long flags, time; int fh, fileSize, error; - for (bvr = chain; bvr; bvr = bvr->next) { + for (bvr = chain; bvr; bvr = bvr->next) + { ret = -1; error = 0; // // Check for alternate volume label on boot helper partitions. // - if (bvr->flags & kBVFlagBooter) { + 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) { + if (!ret) + { fh = open(strcat(dirSpec, fileSpec), 0); fileSize = file_size(fh); - if (fileSize > 0 && fileSize < BVSTRLEN) { - if (read(fh, label, fileSize) != fileSize) { + if (fileSize > 0 && fileSize < BVSTRLEN) + { + if (read(fh, label, fileSize) != fileSize) + { error = -1; } - } else { + } + else + { error = -1; } @@ -1691,6 +1703,7 @@ bvr->flags |= kBVFlagSystemVolume; } } + } } @@ -1721,11 +1734,16 @@ verbose("Resetting BIOS device %xh\n", biosdev); // Reset the biosbuf cache cache_valid = false; - if(map == gDiskBVMap) { + if(map == gDiskBVMap) + { gDiskBVMap = map->next; - } else if(prevMap != NULL) { + } + else if(prevMap != NULL) + { prevMap->next = map->next; - } else { + } + else + { stop(""); } } @@ -1873,7 +1891,8 @@ if ( (!allowFlags || newBVR->flags & allowFlags) && (!denyFlags || !(newBVR->flags & denyFlags) ) && (newBVR->biosdev >= minBIOSDev && newBVR->biosdev <= maxBIOSDev) - ) { + ) + { newBVR->visible = true; } @@ -1882,7 +1901,8 @@ * to be able to hide foreign partitions from the boot menu. * */ - if ( (newBVR->flags & kBVFlagForeignBoot) ) { + if ( (newBVR->flags & kBVFlagForeignBoot) ) + { char *start, *next = val; long len = 0; do @@ -1899,18 +1919,21 @@ /* * Use the first bvr entry as the starting chain pointer. */ - if (!chain) { + if (!chain) + { chain = newBVR; } /* * Update the previous bvr's link pointer to use the new memory area. */ - if (prevBVR) { + if (prevBVR) + { prevBVR->next = newBVR; } - if (newBVR->visible) { + if (newBVR->visible) + { bvCount++; } } Index: trunk/i386/libsaio/smbios.c =================================================================== --- trunk/i386/libsaio/smbios.c (revision 2475) +++ trunk/i386/libsaio/smbios.c (revision 2476) @@ -652,7 +652,9 @@ defaultBaseBoard.product = kDefaultMacBookProBoardProduct; defaultBaseBoard.boardType = kSMBBaseBoardMotherboard; defaultChassis.chassisType = kSMBchassisUnknown; - } else { + } + else + { defaultSystemInfo.productName = kDefaultMacBook; defaultBIOSInfo.version = kDefaultMacBookBIOSVersion; defaultBIOSInfo.releaseDate = kDefaultMacBookBIOSReleaseDate; @@ -661,7 +663,9 @@ defaultBaseBoard.boardType = kSMBBaseBoardMotherboard; defaultChassis.chassisType = kSMBchassisUnknown; } - } else { + } + else + { switch (Platform.CPU.NoCores) { case 1: Index: trunk/i386/libsaio/smbios_decode.c =================================================================== --- trunk/i386/libsaio/smbios_decode.c (revision 2475) +++ trunk/i386/libsaio/smbios_decode.c (revision 2476) @@ -471,38 +471,48 @@ printHeader(structHeader); DBG("Memory Device\n"); // Aray Handle - if (((SMBMemoryDevice *)structHeader)->errorHandle == 0xFFFF) { + if (((SMBMemoryDevice *)structHeader)->errorHandle == 0xFFFF) + { DBG("\tError Information Handle: No Error\n"); - } else { + } + else + { DBG("\tError Information Handle: 0x%x\n", ((SMBMemoryDevice *)structHeader)->errorHandle); } // Total Width: // Data Width: - switch (((SMBMemoryDevice *)structHeader)->memorySize) { - case 0: - DBG("\tSize: No Module Installed\n"); - break; - case 0x7FFF: - DBG("\tSize: 32GB or more\n"); - break; - case 0xFFFF: - DBG("\tSize: Unknown\n"); - break; - default: - DBG("\tSize: %d %s\n", ((SMBMemoryDevice *)structHeader)->memorySize & 0x7FFF, ((((SMBMemoryDevice *)structHeader)->memorySize & 0x8000) == 0x8000) ? "kB" : "MB"); - break; - } - if ((((SMBMemoryDevice *)structHeader)->formFactor < 0x01) || (((SMBMemoryDevice *)structHeader)->formFactor > 0x0F)) { + switch (((SMBMemoryDevice *)structHeader)->memorySize) + { + case 0: + DBG("\tSize: No Module Installed\n"); + break; + case 0x7FFF: + DBG("\tSize: 32GB or more\n"); + break; + case 0xFFFF: + DBG("\tSize: Unknown\n"); + break; + default: + DBG("\tSize: %d %s\n", ((SMBMemoryDevice *)structHeader)->memorySize & 0x7FFF, ((((SMBMemoryDevice *)structHeader)->memorySize & 0x8000) == 0x8000) ? "kB" : "MB"); + break; + } + if ((((SMBMemoryDevice *)structHeader)->formFactor < 0x01) || (((SMBMemoryDevice *)structHeader)->formFactor > 0x0F)) + { DBG("\tForm Factor: %s\n", OutOfSpecStr); - } else { - DBG("\tForm Factor: %s\n", SMBMemoryDeviceFormFactors[((SMBMemoryDevice *)structHeader)->formFactor - 1]); - } + } + else + { + DBG("\tForm Factor: %s\n", SMBMemoryDeviceFormFactors[((SMBMemoryDevice *)structHeader)->formFactor - 1]); + } // Set: DBG("\tLocator: %s\n", SMBStringForField(structHeader, ((SMBMemoryDevice *)structHeader)->deviceLocator, neverMask)); DBG("\tBank Locator: %s\n", SMBStringForField(structHeader, ((SMBMemoryDevice *)structHeader)->bankLocator, neverMask)); - if (((SMBMemoryDevice *)structHeader)->memoryType > kSMBMemoryDeviceTypeCount) { + if (((SMBMemoryDevice *)structHeader)->memoryType > kSMBMemoryDeviceTypeCount) + { DBG("\tMemory Type: %s\n", OutOfSpecStr); - } else { + } + else + { DBG("\tMemory Type: %s\n", SMBMemoryDeviceTypes[((SMBMemoryDevice *)structHeader)->memoryType]); } // Type Detail: @@ -651,7 +661,8 @@ ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length); for (; ((uint16_t *)ptr)[0] != 0; ptr++); - if (((uint16_t *)ptr)[0] == 0) { + if (((uint16_t *)ptr)[0] == 0) + { ptr += 2; } Index: trunk/i386/libsaio/convert.c =================================================================== --- trunk/i386/libsaio/convert.c (revision 2475) +++ trunk/i386/libsaio/convert.c (revision 2476) @@ -10,21 +10,21 @@ /** Transform a 16 bytes hexadecimal value UUID to a string */ const char * getStringFromUUID(const EFI_CHAR8* eUUID) { - static char msg[UUID_LEN*2 + 8] = ""; - if (!eUUID) return ""; - const unsigned char * uuid = (unsigned char*) eUUID; - sprintf(msg, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + static char msg[UUID_LEN*2 + 8] = ""; + if (!eUUID) return ""; + const unsigned char * uuid = (unsigned char*) eUUID; + sprintf(msg, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10],uuid[11], uuid[12],uuid[13],uuid[14],uuid[15]); - return msg ; + return msg ; } /** Parse an UUID string into an (EFI_CHAR8*) buffer */ EFI_CHAR8* getUUIDFromString(const char *source) { - if (!source) return 0; + if (!source) return 0; char *p = (char *)source; int i; @@ -32,21 +32,25 @@ static EFI_CHAR8 uuid[UUID_LEN+1]=""; buf[2] = '\0'; - for (i=0; i= 48 && buff[i] <= 57) // '0' through '9' - digit = buff[i] - 48; + if (buff[i] >= 48 && buff[i] <= 57) // '0' through '9' + digit = buff[i] - 48; else if (buff[i] >= 65 && buff[i] <= 70) // 'A' through 'F' digit = buff[i] - 55; else if (buff[i] >= 97 && buff[i] <= 102) // 'a' through 'f' digit = buff[i] - 87; else return value; - + value = digit + 16 * value; } return value; @@ -75,58 +79,62 @@ void *convertHexStr2Binary(const char *hexStr, int *outLength) { - int len; - char hexNibble; - char hexByte[2]; - uint8_t binChar; - uint8_t *binStr; - int hexStrIdx, binStrIdx, hexNibbleIdx; + int len; + char hexNibble; + char hexByte[2]; + uint8_t binChar; + uint8_t *binStr; + int hexStrIdx, binStrIdx, hexNibbleIdx; - len = strlen(hexStr); - if (len > 1) - { - // the resulting binary will be the half size of the input hex string - binStr = malloc(len / 2); - binStrIdx = 0; - hexNibbleIdx = 0; - for (hexStrIdx = 0; hexStrIdx < len; hexStrIdx++) - { - hexNibble = hexStr[hexStrIdx]; - - // ignore all chars except valid hex numbers - if ( (hexNibble >= '0' && hexNibble <= '9') || - (hexNibble >= 'A' && hexNibble <= 'F') || - (hexNibble >= 'a' && hexNibble <= 'f') ) { - hexByte[hexNibbleIdx++] = hexNibble; - - // found both two nibbles, convert to binary - if (hexNibbleIdx == 2) - { - binChar = 0; + len = strlen(hexStr); + if (len > 1) + { + // the resulting binary will be the half size of the input hex string + binStr = malloc(len / 2); + + binStrIdx = 0; + hexNibbleIdx = 0; + for (hexStrIdx = 0; hexStrIdx < len; hexStrIdx++) + { + hexNibble = hexStr[hexStrIdx]; + + // ignore all chars except valid hex numbers + if ( (hexNibble >= '0' && hexNibble <= '9') || + (hexNibble >= 'A' && hexNibble <= 'F') || + (hexNibble >= 'a' && hexNibble <= 'f') ) + { + hexByte[hexNibbleIdx++] = hexNibble; + + // found both two nibbles, convert to binary + if (hexNibbleIdx == 2) + { + binChar = 0; + + for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) + { + if (hexNibbleIdx > 0) + { + binChar = binChar << 4; + } + + if (hexByte[hexNibbleIdx] <= '9') binChar += hexByte[hexNibbleIdx] - '0'; + else if (hexByte[hexNibbleIdx] <= 'F') binChar += hexByte[hexNibbleIdx] - ('A' - 10); + else if (hexByte[hexNibbleIdx] <= 'f') binChar += hexByte[hexNibbleIdx] - ('a' - 10); + } - for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) { - if (hexNibbleIdx > 0) { - binChar = binChar << 4; + binStr[binStrIdx++] = binChar; + hexNibbleIdx = 0; + } + } } - - if (hexByte[hexNibbleIdx] <= '9') binChar += hexByte[hexNibbleIdx] - '0'; - else if (hexByte[hexNibbleIdx] <= 'F') binChar += hexByte[hexNibbleIdx] - ('A' - 10); - else if (hexByte[hexNibbleIdx] <= 'f') binChar += hexByte[hexNibbleIdx] - ('a' - 10); - } - - binStr[binStrIdx++] = binChar; - hexNibbleIdx = 0; - } - } - } - *outLength = binStrIdx; - return binStr; - } - else - { - *outLength = 0; - return NULL; - } + *outLength = binStrIdx; + return binStr; + } + else + { + *outLength = 0; + return NULL; + } } // FIXME: can't use my original code here, Index: trunk/i386/libsaio/msdos.c =================================================================== --- trunk/i386/libsaio/msdos.c (revision 2475) +++ trunk/i386/libsaio/msdos.c (revision 2476) @@ -71,21 +71,35 @@ static int msdosrootcluster = 0; static int msdosfatbits = 0; +struct msdosdirstate +{ + struct direntry *buf; + uint8_t vfatchecksum; + int root16; + off_t cluster; + int nument; + int vfatnumber; +}; + #if UNUSED /* * Check a volume label. */ -static int -oklabel(const char *src) +static int oklabel(const char *src); + +static int oklabel(const char *src) { int c, i; - for (i = 0, c = 0; i <= 11; i++) { - c = (u_char)*src++; - if (c < ' ' + !i || strchr("\"*+,./:;<=>?[\\]|", c)) - break; - } - return i && !c; + for (i = 0, c = 0; i <= 11; i++) + { + c = (u_char)*src++; + if (c < ' ' + !i || strchr("\"*+,./:;<=>?[\\]|", c)) + { + break; + } + } + return i && !c; } #endif /* UNUSED */ @@ -167,10 +181,10 @@ Seek(ih, 0); Read(ih, (long)buf, 512); - bsp = (union bootsector *)buf; - b33 = (struct bpb33 *)bsp->bs33.bsBPB; - b50 = (struct bpb50 *)bsp->bs50.bsBPB; - b710 = (struct bpb710 *)bsp->bs710.bsBPB; + bsp = (union bootsector *)buf; + b33 = (struct bpb33 *)bsp->bs33.bsBPB; + b50 = (struct bpb50 *)bsp->bs50.bsBPB; + b710 = (struct bpb710 *)bsp->bs710.bsBPB; /* We only work with 512, 1024, and 2048 byte sectors */ @@ -188,7 +202,9 @@ 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); @@ -201,11 +217,16 @@ 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)) + { msdosfatbits = 12; + } else { free (buf); @@ -325,16 +346,6 @@ } } -struct msdosdirstate -{ - struct direntry *buf; - uint8_t vfatchecksum; - int root16; - off_t cluster; - int nument; - int vfatnumber; -}; - static struct direntry * getnextdirent (CICell ih, uint16_t *longname, struct msdosdirstate *st) { @@ -427,134 +438,134 @@ /* First comes lowercase, then uppercase*/ static uint16_t cp850[128][2]= { -{0x00E7,0x00C7}, -{0x00FC,0x00DC}, -{0x00E9,0x00C9}, -{0x00E2,0x00C2}, -{0x00E4,0x00C4}, -{0x00E0,0x00C0}, -{0x00E5,0x00C5}, -{0x00E7,0x00C7}, -{0x00EA,0x00CA}, -{0x00EB,0x00CB}, -{0x00E8,0x00C8}, -{0x00EF,0x00CF}, -{0x00EE,0x00CE}, -{0x00EC,0x00CC}, -{0x00E4,0x00C4}, -{0x00E5,0x00C5}, -{0x00E9,0x00C9}, -{0x00E6,0x00C6}, -{0x00E6,0x00C6}, -{0x00F4,0x00D4}, -{0x00F6,0x00D6}, -{0x00F2,0x00D2}, -{0x00FB,0x00DB}, -{0x00F9,0x00D9}, -{0x00FF,0x0178}, -{0x00F6,0x00D6}, -{0x00FC,0x00DC}, -{0x00F8,0x00D8}, -{0x00A3,0x00A3}, -{0x00F8,0x00D8}, -{0x00D7,0x00D7}, -{0x0192,0x0191}, -{0x00E1,0x00C1}, -{0x00ED,0x00CD}, -{0x00F3,0x00D3}, -{0x00FA,0x00DA}, -{0x00F1,0x00D1}, -{0x00F1,0x00D1}, -{0x00AA,0x00AA}, -{0x00BA,0x00BA}, -{0x00BF,0x00BF}, -{0x00AE,0x00AE}, -{0x00AC,0x00AC}, -{0x00BD,0x00BD}, -{0x00BC,0x00BC}, -{0x00A1,0x00A1}, -{0x00AB,0x00AB}, -{0x00BB,0x00BB}, -{0x2591,0x2591}, -{0x2592,0x2592}, -{0x2593,0x2593}, -{0x2502,0x2502}, -{0x2524,0x2524}, -{0x00E1,0x00C1}, -{0x00E2,0x00C2}, -{0x00E0,0x00C0}, -{0x00A9,0x00A9}, -{0x2563,0x2563}, -{0x2551,0x2551}, -{0x2557,0x2557}, -{0x255D,0x255D}, -{0x00A2,0x00A2}, -{0x00A5,0x00A5}, -{0x2510,0x2510}, -{0x2514,0x2514}, -{0x2534,0x2534}, -{0x252C,0x252C}, -{0x251C,0x251C}, -{0x2500,0x2500}, -{0x253C,0x253C}, -{0x00E3,0x00C3}, -{0x00E3,0x00C3}, -{0x255A,0x255A}, -{0x2554,0x2554}, -{0x2569,0x2569}, -{0x2566,0x2566}, -{0x2560,0x2560}, -{0x2550,0x2550}, -{0x256C,0x256C}, -{0x00A4,0x00A4}, -{0x00F0,0x00D0}, -{0x00F0,0x00D0}, -{0x00EA,0x00CA}, -{0x00EB,0x00CB}, -{0x00E8,0x00C8}, -{0x0131,0x0049}, -{0x00ED,0x00CD}, -{0x00EE,0x00CE}, -{0x00EF,0x00CF}, -{0x2518,0x2518}, -{0x250C,0x250C}, -{0x2588,0x2588}, -{0x2584,0x2584}, -{0x00A6,0x00A6}, -{0x00EC,0x00CC}, -{0x2580,0x2580}, -{0x00F3,0x00D3}, -{0x00DF,0x00DF}, -{0x00F4,0x00D4}, -{0x00F2,0x00D2}, -{0x00F5,0x00D5}, -{0x00F5,0x00D5}, -{0x00B5,0x00B5}, -{0x00FE,0x00DE}, -{0x00FE,0x00DE}, -{0x00FA,0x00DA}, -{0x00FB,0x00DB}, -{0x00F9,0x00D9}, -{0x00FD,0x00DD}, -{0x00FD,0x00DD}, -{0x00AF,0x00AF}, -{0x00B4,0x00B4}, -{0x00AD,0x00AD}, -{0x00B1,0x00B1}, -{0x2017,0x2017}, -{0x00BE,0x00BE}, -{0x00B6,0x00B6}, -{0x00A7,0x00A7}, -{0x00F7,0x00F7}, -{0x00B8,0x00B8}, -{0x00B0,0x00B0}, -{0x00A8,0x00A8}, -{0x00B7,0x00B7}, -{0x00B9,0x00B9}, -{0x00B3,0x00B3}, -{0x00B2,0x00B2}, -{0x25A0,0x25A0}, -{0x00A0,0x00A0} + {0x00E7,0x00C7}, + {0x00FC,0x00DC}, + {0x00E9,0x00C9}, + {0x00E2,0x00C2}, + {0x00E4,0x00C4}, + {0x00E0,0x00C0}, + {0x00E5,0x00C5}, + {0x00E7,0x00C7}, + {0x00EA,0x00CA}, + {0x00EB,0x00CB}, + {0x00E8,0x00C8}, + {0x00EF,0x00CF}, + {0x00EE,0x00CE}, + {0x00EC,0x00CC}, + {0x00E4,0x00C4}, + {0x00E5,0x00C5}, + {0x00E9,0x00C9}, + {0x00E6,0x00C6}, + {0x00E6,0x00C6}, + {0x00F4,0x00D4}, + {0x00F6,0x00D6}, + {0x00F2,0x00D2}, + {0x00FB,0x00DB}, + {0x00F9,0x00D9}, + {0x00FF,0x0178}, + {0x00F6,0x00D6}, + {0x00FC,0x00DC}, + {0x00F8,0x00D8}, + {0x00A3,0x00A3}, + {0x00F8,0x00D8}, + {0x00D7,0x00D7}, + {0x0192,0x0191}, + {0x00E1,0x00C1}, + {0x00ED,0x00CD}, + {0x00F3,0x00D3}, + {0x00FA,0x00DA}, + {0x00F1,0x00D1}, + {0x00F1,0x00D1}, + {0x00AA,0x00AA}, + {0x00BA,0x00BA}, + {0x00BF,0x00BF}, + {0x00AE,0x00AE}, + {0x00AC,0x00AC}, + {0x00BD,0x00BD}, + {0x00BC,0x00BC}, + {0x00A1,0x00A1}, + {0x00AB,0x00AB}, + {0x00BB,0x00BB}, + {0x2591,0x2591}, + {0x2592,0x2592}, + {0x2593,0x2593}, + {0x2502,0x2502}, + {0x2524,0x2524}, + {0x00E1,0x00C1}, + {0x00E2,0x00C2}, + {0x00E0,0x00C0}, + {0x00A9,0x00A9}, + {0x2563,0x2563}, + {0x2551,0x2551}, + {0x2557,0x2557}, + {0x255D,0x255D}, + {0x00A2,0x00A2}, + {0x00A5,0x00A5}, + {0x2510,0x2510}, + {0x2514,0x2514}, + {0x2534,0x2534}, + {0x252C,0x252C}, + {0x251C,0x251C}, + {0x2500,0x2500}, + {0x253C,0x253C}, + {0x00E3,0x00C3}, + {0x00E3,0x00C3}, + {0x255A,0x255A}, + {0x2554,0x2554}, + {0x2569,0x2569}, + {0x2566,0x2566}, + {0x2560,0x2560}, + {0x2550,0x2550}, + {0x256C,0x256C}, + {0x00A4,0x00A4}, + {0x00F0,0x00D0}, + {0x00F0,0x00D0}, + {0x00EA,0x00CA}, + {0x00EB,0x00CB}, + {0x00E8,0x00C8}, + {0x0131,0x0049}, + {0x00ED,0x00CD}, + {0x00EE,0x00CE}, + {0x00EF,0x00CF}, + {0x2518,0x2518}, + {0x250C,0x250C}, + {0x2588,0x2588}, + {0x2584,0x2584}, + {0x00A6,0x00A6}, + {0x00EC,0x00CC}, + {0x2580,0x2580}, + {0x00F3,0x00D3}, + {0x00DF,0x00DF}, + {0x00F4,0x00D4}, + {0x00F2,0x00D2}, + {0x00F5,0x00D5}, + {0x00F5,0x00D5}, + {0x00B5,0x00B5}, + {0x00FE,0x00DE}, + {0x00FE,0x00DE}, + {0x00FA,0x00DA}, + {0x00FB,0x00DB}, + {0x00F9,0x00D9}, + {0x00FD,0x00DD}, + {0x00FD,0x00DD}, + {0x00AF,0x00AF}, + {0x00B4,0x00B4}, + {0x00AD,0x00AD}, + {0x00B1,0x00B1}, + {0x2017,0x2017}, + {0x00BE,0x00BE}, + {0x00B6,0x00B6}, + {0x00A7,0x00A7}, + {0x00F7,0x00F7}, + {0x00B8,0x00B8}, + {0x00B0,0x00B0}, + {0x00A8,0x00A8}, + {0x00B7,0x00B7}, + {0x00B9,0x00B9}, + {0x00B3,0x00B3}, + {0x00B2,0x00B2}, + {0x25A0,0x25A0}, + {0x00A0,0x00A0} }; static int @@ -780,7 +791,8 @@ if (filePath[0] == '/') filePath++; buf = malloc(msdosclustersize); - if (!buf) { + if (!buf) + { return -1; } dirp = getdirpfrompath (ih, filePath, buf); @@ -794,7 +806,8 @@ if (msdosfatbits == 32) cluster |= ((uint32_t)OSReadLittleInt16 ((dirp->deHighClust),0)) <<16; size = (uint32_t)OSReadLittleInt32 ((dirp->deFileSize),0); - if (size<=offset) { + if (size<=offset) + { free (buf); return -1; } @@ -816,8 +829,7 @@ } getDeviceDescription(ih, devStr); - verbose("Read FAT%d file: [%s/%s] %d bytes.\n", - msdosfatbits, devStr, filePath, (uint32_t)( toread<0 ) ? wastoread : wastoread-toread); + verbose("Read FAT%d file: [%s/%s] %d bytes.\n", msdosfatbits, devStr, filePath, (uint32_t)( toread<0 ) ? wastoread : wastoread-toread); free (buf); if (toread<0) return wastoread; @@ -836,7 +848,8 @@ if (filePath[0] == '/') filePath++; buf = malloc(msdosclustersize); - if (!buf) { + if (!buf) + { return -1; } dirp = getdirpfrompath (ih, filePath, buf); @@ -931,7 +944,8 @@ initRoot (&st); st.buf = malloc(msdosclustersize); - if (!st.buf) { + if (!st.buf) + { return; } while ((dirp = getnextdirent (ih, vfatlabel, &st))) @@ -963,7 +977,9 @@ union bootsector *bsp = (union bootsector *)buf; Seek(ih, 0); Read(ih, (long)buf, 512); - if (msdosfatbits == 32) { /* It's FAT32 */ + if (msdosfatbits == 32) + { + /* It's FAT32 */ strncpy((char *)label, (char *)((struct extboot *)bsp->bs710.bsExt)->exVolumeLabel, LABEL_LENGTH); } else if (msdosfatbits == 16) @@ -981,11 +997,12 @@ MSDOSGetUUID(CICell ih, char *uuidStr) { char *buf = malloc (512); - if (!buf) { + if (!buf) + { return -1; } union bootsector *bsp = (union bootsector *)buf; - + if (MSDOSInitPartition (ih)<0) { free (buf); Index: trunk/i386/libsaio/fake_efi.c =================================================================== --- trunk/i386/libsaio/fake_efi.c (revision 2475) +++ trunk/i386/libsaio/fake_efi.c (revision 2476) @@ -717,7 +717,6 @@ DT__AddProperty(chosenNode, "machine-signature", sizeof(EFI_UINT32), (EFI_UINT32 *)&MachineSig); - if(YOSEMITE) { // @@ -772,6 +771,7 @@ } cpuTick = getCPUTick(); // callq 0x121a7 +// printf("value: 0x%llx\n", getCPUTick()); rcx = (cpuTick >> 8); // mov %rax, %rcx // shr $0x8, %rcx rdx = (cpuTick >> 10); // mov %rax, %rdx Index: trunk/i386/libsaio/smbios_getters.c =================================================================== --- trunk/i386/libsaio/smbios_getters.c (revision 2475) +++ trunk/i386/libsaio/smbios_getters.c (revision 2476) @@ -21,8 +21,10 @@ bool getProcessorInformationExternalClock(returnType *value) { - if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel - switch (Platform.CPU.Family) { + if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel + { + switch (Platform.CPU.Family) + { case 0x06: { switch (Platform.CPU.Model) @@ -49,7 +51,9 @@ default: value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL); } - } else { + } + else + { value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL); } @@ -70,7 +74,8 @@ { case 0x06: { - switch (Platform.CPU.Model) { + switch (Platform.CPU.Model) + { case CPU_MODEL_PENTIUM_M: case CPU_MODEL_DOTHAN: // Intel Pentium M case CPU_MODEL_YONAH: // Intel Mobile Core Solo, Duo @@ -101,13 +106,15 @@ // Nehalem supports Scrubbing // First, locate the PCI bus where the MCH is located - for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) { + for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) + { vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00); did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02); vid &= 0xFFFF; did &= 0xFF00; - if(vid == 0x8086 && did >= 0x2C00) { + if(vid == 0x8086 && did >= 0x2C00) + { nhm_bus = possible_nhm_bus[i]; } } @@ -118,7 +125,8 @@ DBG("qpimult %d\n", qpimult); qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000LL)); // Rek: rounding decimals to match original mac profile info - if (qpibusspeed%100 != 0) { + if (qpibusspeed%100 != 0) + { qpibusspeed = ((qpibusspeed+50)/100)*100; } DBG("qpibusspeed %d\n", qpibusspeed); @@ -138,9 +146,12 @@ uint16_t simpleGetSMBOemProcessorType(void) { - if (Platform.CPU.NoCores >= 4) { + if (Platform.CPU.NoCores >= 4) + { return 0x501; // 1281 - Quad-Core Xeon - } else if (Platform.CPU.NoCores == 1) { + } + else if (Platform.CPU.NoCores == 1) + { return 0x201; // 513 - Core Duo }; @@ -153,22 +164,27 @@ value->word = simpleGetSMBOemProcessorType(); - if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel - if (!done) { + if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel + { + if (!done) + { verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, (uint32_t)Platform.CPU.Family, (uint32_t)Platform.CPU.Model); done = true; } // Bungo: fixes Oem Processor Type - better matching IMHO, needs testing - switch (Platform.CPU.Family) { + switch (Platform.CPU.Family) + { case 0x0F: case 0x06: { - switch (Platform.CPU.Model) { + switch (Platform.CPU.Model) + { case CPU_MODEL_PENTIUM_M: case CPU_MODEL_DOTHAN: // 0x0D - Intel Pentium M model D case CPU_MODEL_PRESCOTT: case CPU_MODEL_NOCONA: - if (strstr(Platform.CPU.BrandString, "Xeon")) { + if (strstr(Platform.CPU.BrandString, "Xeon")) + { value->word = 0x402; // 1026 - Xeon } return true; @@ -182,11 +198,13 @@ case CPU_MODEL_MEROM: // 0x0F - Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx case CPU_MODEL_XEON_MP: // 0x1D - Six-Core Xeon 7400, "Dunnington", 45nm case CPU_MODEL_PENRYN: // 0x17 - Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx - if (strstr(Platform.CPU.BrandString, "Xeon")) { + if (strstr(Platform.CPU.BrandString, "Xeon")) + { value->word = 0x402; // 1026 - Xeon return true; } - if (Platform.CPU.NoCores <= 2) { + if (Platform.CPU.NoCores <= 2) + { value->word = 0x301; // 769 - Core 2 Duo } else { value->word = 0x402; // 1026 - Core 2 Quad as Xeon @@ -345,14 +363,17 @@ static int idx = -1; int map; - if (!bootInfo->memDetect) { + if (!bootInfo->memDetect) + { return false; } idx++; - if (idx < MAX_RAM_SLOTS) { + if (idx < MAX_RAM_SLOTS) + { map = Platform.DMI.DIMM[idx]; - if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) { + if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) + { DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type); value->byte = Platform.RAM.DIMM[map].Type; return true; @@ -406,9 +427,11 @@ } idx++; - if (idx < MAX_RAM_SLOTS) { + if (idx < MAX_RAM_SLOTS) + { map = Platform.DMI.DIMM[idx]; - if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0) { + if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0) + { DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor); value->string = Platform.RAM.DIMM[map].Vendor; return true; @@ -432,9 +455,11 @@ //DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS); - if (idx < MAX_RAM_SLOTS) { + if (idx < MAX_RAM_SLOTS) + { map = Platform.DMI.DIMM[idx]; - if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) { + if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) + { DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo); value->string = Platform.RAM.DIMM[map].SerialNo; return true; @@ -455,9 +480,11 @@ } idx++; - if (idx < MAX_RAM_SLOTS) { + if (idx < MAX_RAM_SLOTS) + { map = Platform.DMI.DIMM[idx]; - if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) { + if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) + { DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo); value->string = Platform.RAM.DIMM[map].PartNo; return true; @@ -482,11 +509,13 @@ * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_"). */ smbios = (SMBEntryPoint*)SMBIOS_RANGE_START; - while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) { + while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) + { if (COMPARE_DWORD(smbios->anchor, SMTAG) && COMPARE_DWORD(smbios->dmi.anchor, DMITAG) && smbios->dmi.anchor[4] == DMITAG[4] && - checksum8(smbios, sizeof(SMBEntryPoint)) == 0) { + checksum8(smbios, sizeof(SMBEntryPoint)) == 0) + { return smbios; } smbios = (SMBEntryPoint*)(((char*)smbios) + 16); Index: trunk/i386/libsaio/saio_internal.h =================================================================== --- trunk/i386/libsaio/saio_internal.h (revision 2475) +++ trunk/i386/libsaio/saio_internal.h (revision 2476) @@ -2,7 +2,7 @@ * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ - * + * * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public @@ -10,7 +10,7 @@ * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. - * + * * The Original Code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -18,7 +18,7 @@ * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. - * + * * @APPLE_LICENSE_HEADER_END@ */ Index: trunk/i386/boot0/boot0.s =================================================================== --- trunk/i386/boot0/boot0.s (revision 2475) +++ trunk/i386/boot0/boot0.s (revision 2476) @@ -328,7 +328,7 @@ ; equipped with boot1h in its boot record ; regardless if it's active or not. jne .continue - mov dh, 1 ; Argument for loadBootSector to check HFS+ partition signature. + mov dh, 1 ; Argument for loadBootSector to check HFS+ partition signature. DebugChar('*') @@ -350,7 +350,7 @@ ; Scanned all partitions but not found any with active flag enabled ; Anyway if we found a protective MBR before we still have a chance ; for a possible GPT Header at LBA 1 - ; + ; dec bl jnz .switchPass2 ; didn't find Protective MBR before call checkGPT @@ -372,7 +372,7 @@ ; Jump to partition booter. The drive number is already in register DL. ; SI is pointing to the modified partition entry. ; -initBootLoader: +initBootLoader: DebugChar('J') @@ -382,7 +382,6 @@ jmp kBoot0LoadAddr - ; ; Found Protective MBR Partition Type: 0xEE ; Check for 'EFI PART' string at the beginning @@ -463,16 +462,16 @@ ; mov eax, [si + gpta.StartingLBA] ; load boot sector from StartingLBA - mov [my_lba], eax - mov dh, 1 ; Argument for loadBootSector to check HFS+ partition signature. + mov [my_lba], eax + mov dh, 1 ; Argument for loadBootSector to check HFS+ partition signature. call loadBootSector - jne .gpt_continue ; no boot loader signature + jne .gpt_continue ; no boot loader signature - mov si, kMBRPartTable ; fake the current GUID Partition - mov [si + part.lba], eax ; as MBR style partition for boot1h + mov si, kMBRPartTable ; fake the current GUID Partition + mov [si + part.lba], eax ; as MBR style partition for boot1h mov BYTE [si + part.type], kPartTypeHFS ; with HFS+ filesystem type (0xAF) - jmp SHORT initBootLoader - + jmp SHORT initBootLoader + .gpt_continue: add si, bx ; advance SI to next partition entry @@ -506,7 +505,7 @@ or dh, dh jz .checkBootSignature - + .checkHFSSignature: %if VERBOSE @@ -611,7 +610,7 @@ mov eax, ecx call print_hex %endif - + ; ; INT13 Func 42 - Extended Read Sectors ; @@ -621,7 +620,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; @@ -782,7 +781,7 @@ ; that the 'times' argument is negative. ; -; According to EFI specification, maximum boot code size is 440 bytes +; According to EFI specification, maximum boot code size is 440 bytes ; ; Index: trunk/i386/boot0/boot0hfs.s =================================================================== --- trunk/i386/boot0/boot0hfs.s (revision 2475) +++ trunk/i386/boot0/boot0hfs.s (revision 2476) @@ -620,7 +620,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: trunk/i386/include/mach-o/loader.h =================================================================== --- trunk/i386/include/mach-o/loader.h (revision 2475) +++ trunk/i386/include/mach-o/loader.h (revision 2476) @@ -2,14 +2,14 @@ * Copyright (c) 1999-2010 Apple Inc. All Rights Reserved. * * @APPLE_LICENSE_HEADER_START@ - * + * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. - * + * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -17,7 +17,7 @@ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. - * + * * @APPLE_LICENSE_HEADER_END@ */ #ifndef _MACHO_LOADER_H_ @@ -35,7 +35,7 @@ #include /* - * is needed here for the vm_prot_t type and contains the + * is needed here for the vm_prot_t type and contains the * constants that are or'ed together for the possible values of this type. */ #include @@ -90,10 +90,10 @@ * boundary for efficient demand pageing. The MH_EXECUTE, MH_FVMLIB, MH_DYLIB, * MH_DYLINKER and MH_BUNDLE file types also have the headers included as part * of their first segment. - * + * * The file type MH_OBJECT is a compact format intended as output of the * assembler and input (and possibly output) of the link editor (the .o - * format). All sections are in one unnamed segment with no segment padding. + * format). All sections are in one unnamed segment with no segment padding. * This format is used as an executable format when the file is so small the * segment padding greatly increases its size. * @@ -159,7 +159,7 @@ all two-level namespace modules of its dependent libraries. only used when MH_PREBINDABLE and MH_TWOLEVEL - are both set. */ + are both set. */ #define MH_SUBSECTIONS_VIA_SYMBOLS 0x2000/* safe to divide up the sections into sub-sections via symbols for dead code stripping */ @@ -170,19 +170,19 @@ #define MH_BINDS_TO_WEAK 0x10000 /* the final linked image uses weak symbols */ -#define MH_ALLOW_STACK_EXECUTION 0x20000/* When this bit is set, all stacks +#define MH_ALLOW_STACK_EXECUTION 0x20000/* When this bit is set, all stacks in the task will be given stack execution privilege. Only used in MH_EXECUTE filetypes. */ -#define MH_ROOT_SAFE 0x40000 /* When this bit is set, the binary +#define MH_ROOT_SAFE 0x40000 /* When this bit is set, the binary declares it is safe for use in processes with uid zero */ - -#define MH_SETUID_SAFE 0x80000 /* When this bit is set, the binary + +#define MH_SETUID_SAFE 0x80000 /* When this bit is set, the binary declares it is safe for use in processes when issetugid() is true */ -#define MH_NO_REEXPORTED_DYLIBS 0x100000 /* When this bit is set on a dylib, +#define MH_NO_REEXPORTED_DYLIBS 0x100000 /* When this bit is set on a dylib, the static linker does not need to examine dependent dylibs to see if any are re-exported */ @@ -197,7 +197,7 @@ LC_LOAD_DYLIB load command to the dylib if no symbols are being referenced from the dylib. */ -#define MH_HAS_TLV_DESCRIPTORS 0x800000 /* Contains a section of type +#define MH_HAS_TLV_DESCRIPTORS 0x800000 /* Contains a section of type S_THREAD_LOCAL_VARIABLES */ #define MH_NO_HEAP_EXECUTION 0x1000000 /* When this bit is set, the OS will @@ -303,7 +303,7 @@ uint32_t offset; /* offset to the string */ #ifndef __LP64__ char *ptr; /* pointer to the string */ -#endif +#endif }; /* @@ -474,7 +474,7 @@ interposing */ #define S_16BYTE_LITERALS 0xe /* section with only 16 byte literals */ -#define S_DTRACE_DOF 0xf /* section contains +#define S_DTRACE_DOF 0xf /* section contains DTrace Object Format */ #define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10 /* section with only lazy symbol pointers to lazy @@ -482,12 +482,12 @@ /* * Section types to support thread local variables */ -#define S_THREAD_LOCAL_REGULAR 0x11 /* template of initial +#define S_THREAD_LOCAL_REGULAR 0x11 /* template of initial values for TLVs */ -#define S_THREAD_LOCAL_ZEROFILL 0x12 /* template of initial +#define S_THREAD_LOCAL_ZEROFILL 0x12 /* template of initial values for TLVs */ #define S_THREAD_LOCAL_VARIABLES 0x13 /* TLV descriptors */ -#define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14 /* pointers to TLV +#define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14 /* pointers to TLV descriptors */ #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15 /* functions to call to initialize TLV @@ -520,7 +520,7 @@ * a section type S_REGULAR. The static linker will not copy section contents * from sections with this attribute into its output file. These sections * generally contain DWARF debugging info. - */ + */ #define S_ATTR_DEBUG 0x02000000 /* a debug section */ #define SECTION_ATTRIBUTES_SYS 0x00ffff00 /* system setable attributes */ #define S_ATTR_SOME_INSTRUCTIONS 0x00000400 /* section contains some @@ -681,7 +681,7 @@ * A dynamically linked shared library may be a sub_umbrella of an umbrella * framework. If so it will be linked with "-sub_umbrella umbrella_name" where * Where "umbrella_name" is the name of the sub_umbrella framework. When - * staticly linking when -twolevel_namespace is in effect a twolevel namespace + * staticly linking when -twolevel_namespace is in effect a twolevel namespace * umbrella framework will only cause its subframeworks and those frameworks * listed as sub_umbrella frameworks to be implicited linked in. Any other * dependent dynamic libraries will not be linked it when -twolevel_namespace @@ -700,7 +700,7 @@ * A dynamically linked shared library may be a sub_library of another shared * library. If so it will be linked with "-sub_library library_name" where * Where "library_name" is the name of the sub_library shared library. When - * staticly linking when -twolevel_namespace is in effect a twolevel namespace + * staticly linking when -twolevel_namespace is in effect a twolevel namespace * shared library will only cause its subframeworks and those frameworks * listed as sub_umbrella frameworks and libraries listed as sub_libraries to * be implicited linked in. Any other dependent dynamic libraries will not be @@ -780,7 +780,7 @@ }; /* - * The routines command contains the address of the dynamic shared library + * The routines command contains the address of the dynamic shared library * initialization routine and an index into the module table for the module * that defines the routine. Before any modules are used from the library the * dynamic linker fully binds the module that defines the initialization routine @@ -986,12 +986,12 @@ uint32_t locreloff; /* offset to local relocation entries */ uint32_t nlocrel; /* number of local relocation entries */ -}; +}; /* - * An indirect symbol table entry is simply a 32bit index into the symbol table + * An indirect symbol table entry is simply a 32bit index into the symbol table * to the symbol that the pointer or stub is refering to. Unless it is for a - * non-lazy symbol pointer section for a defined symbol which strip(1) as + * non-lazy symbol pointer section for a defined symbol which strip(1) as * removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the * symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that. */ @@ -1005,7 +1005,7 @@ (index into the symbol table) */ uint32_t module_index; /* index into the module table this symbol is defined in */ -}; +}; /* a module table entry */ struct dylib_module { @@ -1032,7 +1032,7 @@ objc_module_info_addr; /* the (__OBJC,__module_info) section */ uint32_t /* for this module size of */ objc_module_info_size; /* the (__OBJC,__module_info) section */ -}; +}; /* a 64-bit module table entry */ struct dylib_module_64 { @@ -1061,7 +1061,7 @@ objc_module_info_addr; /* the (__OBJC,__module_info) section */ }; -/* +/* * The entries in the reference symbol table are used when loading the module * (both by the static and dynamic link editors) and if the module is unloaded * or replaced. Therefore all external symbols (defined and undefined) are @@ -1102,7 +1102,7 @@ * binary search or a directed linear search. */ struct twolevel_hint { - uint32_t + uint32_t isub_image:8, /* index into the sub images */ itoc:24; /* index into the table of contents */ }; @@ -1145,7 +1145,7 @@ /* * The linkedit_data_command contains the offsets and sizes of a blob - * of data in the __LINKEDIT segment. + * of data in the __LINKEDIT segment. */ struct linkedit_data_command { uint32_t cmd; /* LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, @@ -1181,12 +1181,12 @@ }; /* - * The dyld_info_command contains the file offsets and sizes of - * the new compressed form of the information dyld needs to + * The dyld_info_command contains the file offsets and sizes of + * the new compressed form of the information dyld needs to * load the image. This information is used by dyld on Mac OS X * 10.6 and later. All information pointed to by this command * is encoded using byte streams, so no endian swapping is needed - * to interpret it. + * to interpret it. */ struct dyld_info_command { uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */ @@ -1205,28 +1205,28 @@ */ uint32_t rebase_off; /* file offset to rebase info */ uint32_t rebase_size; /* size of rebase info */ - + /* * Dyld binds an image during the loading process, if the image - * requires any pointers to be initialized to symbols in other images. - * The bind information is a stream of byte sized + * requires any pointers to be initialized to symbols in other images. + * The bind information is a stream of byte sized * opcodes whose symbolic names start with BIND_OPCODE_. * Conceptually the bind information is a table of tuples: * * The opcodes are a compressed way to encode the table by only * encoding when a column changes. In addition simple patterns - * like for runs of pointers initialzed to the same value can be + * like for runs of pointers initialzed to the same value can be * encoded in a few bytes. */ uint32_t bind_off; /* file offset to binding info */ uint32_t bind_size; /* size of binding info */ - + /* * Some C++ programs require dyld to unique symbols so that all * images in the process use the same copy of some code/data. * This step is done after binding. The content of the weak_bind * info is an opcode stream like the bind_info. But it is sorted - * alphabetically by symbol name. This enable dyld to walk + * alphabetically by symbol name. This enable dyld to walk * all images with weak binding information in order and look * for collisions. If there are no collisions, dyld does * no updating. That means that some fixups are also encoded @@ -1238,36 +1238,37 @@ */ uint32_t weak_bind_off; /* file offset to weak binding info */ uint32_t weak_bind_size; /* size of weak binding info */ - + /* * Some uses of external symbols do not need to be bound immediately. * Instead they can be lazily bound on first use. The lazy_bind * are contains a stream of BIND opcodes to bind all lazy symbols. * Normal use is that dyld ignores the lazy_bind section when * loading an image. Instead the static linker arranged for the - * lazy pointer to initially point to a helper function which + * lazy pointer to initially point to a helper function which * pushes the offset into the lazy_bind area for the symbol * needing to be bound, then jumps to dyld which simply adds - * the offset to lazy_bind_off to get the information on what - * to bind. + * the offset to lazy_bind_off to get the information on what + * to bind. */ uint32_t lazy_bind_off; /* file offset to lazy binding info */ uint32_t lazy_bind_size; /* size of lazy binding infs */ - + /* * The symbols exported by a dylib are encoded in a trie. This * is a compact representation that factors out common prefixes. - * It also reduces LINKEDIT pages in RAM because it encodes all + * It also reduces LINKEDIT pages in RAM because it encodes all * information (name, address, flags) in one small, contiguous range. * The export area is a stream of nodes. The first node sequentially - * is the start node for the trie. + * is the start node for the trie. * * Nodes for a symbol start with a uleb128 that is the length of * the exported symbol information for the string so far. - * If there is no exported symbol, the node starts with a zero byte. - * If there is exported info, it follows the length. First is - * a uleb128 containing flags. Normally, it is followed by a - * uleb128 encoded offset which is location of the content named + * If there is no exported symbol, the node starts with a zero byte. + * If there is exported info, it follows the length. + * + * First is a uleb128 containing flags. Normally, it is followed by + * a uleb128 encoded offset which is location of the content named * by the symbol from the mach_header for the image. If the flags * is EXPORT_SYMBOL_FLAGS_REEXPORT, then following the flags is * a uleb128 encoded library ordinal, then a zero terminated @@ -1275,12 +1276,12 @@ * is re-export from the specified dylib with the same name. * * After the optional exported symbol information is a byte of - * how many edges (0-255) that this node has leaving it, + * how many edges (0-255) that this node has leaving it, * followed by each edge. * Each edge is a zero terminated UTF8 of the addition chars * in the symbol, followed by a uleb128 offset for the node that * edge points to. - * + * */ uint32_t export_off; /* file offset to lazy binding info */ uint32_t export_size; /* size of lazy binding infs */ @@ -1389,7 +1390,7 @@ }; /* - * Sections of type S_THREAD_LOCAL_VARIABLES contain an array + * Sections of type S_THREAD_LOCAL_VARIABLES contain an array * of tlv_descriptor structures. */ struct tlv_descriptor Index: trunk/i386/boot2/graphics.c =================================================================== --- trunk/i386/boot2/graphics.c (revision 2475) +++ trunk/i386/boot2/graphics.c (revision 2476) @@ -41,7 +41,7 @@ uint8_t *previewSaveunder = 0; #define VIDEO(x) (bootArgs->Video.v_ ## x) - + //========================================================================== // getVBEVideoRam @@ -77,13 +77,18 @@ strcpy( (char*)&vbeInfo, "VBE2" ); err = getVBEInfo( &vbeInfo ); if (err != errSuccess) + { return 0; + } if ( strncmp( (char *)vbeInfo.VESASignature, "VESA", 4 ) ) + { return 0; + } buff = malloc(sizeof(char) * 256); - if (!buff) { + if (!buff) + { return 0; } @@ -157,16 +162,20 @@ modeInfo.BitsPerPixel, modeInfo.MemoryModel, modeInfo.ModeAttributes); - if (line++ >= 20) { + if (line++ >= 20) + { pause(); line = 0; clearScreenRows(0, 24); setCursorPosition( 0, 0, 1 ); } } - if (line != 0) { + + if (line != 0) + { pause(); } + setActiveDisplayPage(0); } @@ -182,9 +191,11 @@ bzero( &vbeInfo, sizeof(vbeInfo) ); strcpy( (char*)&vbeInfo, "VBE2" ); err = getVBEInfo( &vbeInfo ); - if ( err != errSuccess ) { + if ( err != errSuccess ) + { return 0; } + char *buff=malloc(sizeof(char)*3072); if(!buff) { @@ -202,7 +213,8 @@ bzero( &modeInfo, sizeof(modeInfo) ); err = getVBEModeInfo( *modePtr, &modeInfo ); - if ( err != errSuccess ) { + if ( err != errSuccess ) + { continue; } @@ -816,24 +828,27 @@ unsigned short height, unsigned char colorIndex ) { - long pixelBytes; - long color = lookUpCLUTIndex( colorIndex, VIDEO(depth) ); - char * vram; + long pixelBytes; + long color = lookUpCLUTIndex( colorIndex, VIDEO(depth) ); + char * vram; - pixelBytes = VIDEO(depth) / 8; - vram = (char *) VIDEO(baseAddr) + - VIDEO(rowBytes) * y + pixelBytes * x; + pixelBytes = VIDEO(depth) / 8; + vram = (char *) VIDEO(baseAddr) + VIDEO(rowBytes) * y + pixelBytes * x; - width = MIN(width, VIDEO(width) - x); - height = MIN(height, VIDEO(height) - y); + width = MIN(width, VIDEO(width) - x); + height = MIN(height, VIDEO(height) - y); - while ( height-- ) - { - int rem = ( pixelBytes * width ) % 4; - if ( rem ) bcopy( &color, vram, rem ); - stosl( vram + rem, color, pixelBytes * width / 4 ); - vram += VIDEO(rowBytes); - } + while ( height-- ) + { + int rem = ( pixelBytes * width ) % 4; + if ( rem ) + { + bcopy( &color, vram, rem ); + } + + stosl( vram + rem, color, pixelBytes * width / 4 ); + vram += VIDEO(rowBytes); + } } //========================================================================== @@ -845,18 +860,18 @@ unsigned short height, unsigned char * data ) { - unsigned short drawWidth; - long pixelBytes = VIDEO(depth) / 8; - unsigned char * vram = (unsigned char *) VIDEO(baseAddr) + - VIDEO(rowBytes) * y + pixelBytes * x; + unsigned short drawWidth; + long pixelBytes = VIDEO(depth) / 8; + unsigned char * vram = (unsigned char *) VIDEO(baseAddr) + VIDEO(rowBytes) * y + pixelBytes * x; - drawWidth = MIN(width, VIDEO(width) - x); - height = MIN(height, VIDEO(height) - y); - while ( height-- ) { - bcopy( data, vram, drawWidth * pixelBytes ); - vram += VIDEO(rowBytes); - data += width * pixelBytes; - } + drawWidth = MIN(width, VIDEO(width) - x); + height = MIN(height, VIDEO(height) - y); + while ( height-- ) + { + bcopy( data, vram, drawWidth * pixelBytes ); + vram += VIDEO(rowBytes); + data += width * pixelBytes; + } } //============================================================================== @@ -925,7 +940,10 @@ { if (!setVESAGraphicsMode(origwidth, origheight, origbpx, 0)) if (initGraphicsMode () != errSuccess) + { return; + } + screen = (uint8_t *) VIDEO (baseAddr); rowBytes = VIDEO (rowBytes); loadImageScale (uncomp, origwidth, origheight, origbpx, screen, VIDEO(width), VIDEO(height), VIDEO(depth), VIDEO (rowBytes)); @@ -933,16 +951,21 @@ else { if (initGraphicsMode () != errSuccess) + { return; + } + screen = (uint8_t *) VIDEO (baseAddr); rowBytes = VIDEO (rowBytes); // Set the screen to 75% grey. - drawColorRectangle(0, 0, VIDEO(width), VIDEO(height), 0x01 /* color index */); + drawColorRectangle(0, 0, VIDEO(width), VIDEO(height), 0x01 /* color index */); } - pixelShift = VIDEO (depth) >> 4; - if (pixelShift < 1) return; + if (pixelShift < 1) + { + return; + } screen += ((VIDEO (width) - kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1)) @@ -968,7 +991,10 @@ in = (in << 3) | (in >> 2); } else + { in = *((uint32_t *)out) & 0xff; // 32 + } + saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++] = in; result = ((255 - alpha) * in + alpha * result + 0xff) >> 8; } @@ -978,7 +1004,10 @@ *((uint16_t *)out) = (result << 10) | (result << 5) | result; // 16 } else + { *((uint32_t *)out) = (result << 16) | (result << 8) | result; // 32 + } + } out += (1 << pixelShift); } @@ -1029,13 +1058,16 @@ in = saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++]; result = ((255 - alpha) * in + alpha * result + 0xff) / 255; } + if (1 == pixelShift) { result >>= 3; *((uint16_t *)out) = (result << 10) | (result << 5) | result; // 16 } else + { *((uint32_t *)out) = (result << 16) | (result << 8) | result; // 32 + } } out += (1 << pixelShift); } @@ -1044,42 +1076,41 @@ } } - //========================================================================== // setVESATextMode static int setVESATextMode( unsigned short cols, unsigned short rows, unsigned char bitsPerPixel ) { - VBEModeInfoBlock minfo; - unsigned short mode = modeEndOfList; + VBEModeInfoBlock minfo; + unsigned short mode = modeEndOfList; - if ( (cols != 80) || (rows != 25) ) // not 80x25 mode - { - mode = getVESAModeWithProperties( cols, rows, bitsPerPixel, + if ( (cols != 80) || (rows != 25) ) // not 80x25 mode + { + mode = getVESAModeWithProperties( cols, rows, bitsPerPixel, maColorModeBit | maModeIsSupportedBit, maGraphicsModeBit, &minfo, NULL ); - } + } - if ( ( mode == modeEndOfList ) || ( setVBEMode(mode, NULL) != errSuccess ) ) - { - video_mode( 2 ); // VGA BIOS, 80x25 text mode. - minfo.XResolution = 80; - minfo.YResolution = 25; - } + if ( ( mode == modeEndOfList ) || ( setVBEMode(mode, NULL) != errSuccess ) ) + { + video_mode( 2 ); // VGA BIOS, 80x25 text mode. + minfo.XResolution = 80; + minfo.YResolution = 25; + } - // Update KernBootStruct using info provided by the selected - // VESA mode. + // Update KernBootStruct using info provided by the selected + // VESA mode. - bootArgs->Video.v_display = VGA_TEXT_MODE; - bootArgs->Video.v_baseAddr = 0xb8000; - bootArgs->Video.v_width = minfo.XResolution; - bootArgs->Video.v_height = minfo.YResolution; - bootArgs->Video.v_depth = 8; - bootArgs->Video.v_rowBytes = 0x8000; + bootArgs->Video.v_display = VGA_TEXT_MODE; + bootArgs->Video.v_baseAddr = 0xb8000; + bootArgs->Video.v_width = minfo.XResolution; + bootArgs->Video.v_height = minfo.YResolution; + bootArgs->Video.v_depth = 8; + bootArgs->Video.v_rowBytes = 0x8000; - return errSuccess; // always return success + return errSuccess; // always return success } //========================================================================== @@ -1089,64 +1120,69 @@ unsigned long numbers[], unsigned long maxArrayCount ) { - char * propStr; - unsigned long count = 0; + char * propStr; + unsigned long count = 0; - propStr = newStringForKey( (char *) propKey , &bootInfo->chameleonConfig ); - if ( propStr ) - { - char * delimiter = propStr; - char * p = propStr; + propStr = newStringForKey( (char *) propKey , &bootInfo->chameleonConfig ); + if ( propStr ) + { + char * delimiter = propStr; + char * p = propStr; - while ( count < maxArrayCount && *p != '\0' ) - { - unsigned long val = strtoul( p, &delimiter, 10 ); - if ( p != delimiter ) - { - numbers[count++] = val; - p = delimiter; - } - while ( ( *p != '\0' ) && !isdigit(*p) ) - p++; - } + while ( count < maxArrayCount && *p != '\0' ) + { + unsigned long val = strtoul( p, &delimiter, 10 ); + if ( p != delimiter ) + { + numbers[count++] = val; + p = delimiter; + } + while ( ( *p != '\0' ) && !isdigit(*p) ) + p++; + } - free( propStr ); - } + free( propStr ); + } - return count; + return count; } //============================================================================== int initGraphicsMode () { - unsigned long params[4]; - int count; + unsigned long params[4]; + int count; - params[3] = 0; - count = getNumberArrayFromProperty( kGraphicsModeKey, params, 4 ); + params[3] = 0; + count = getNumberArrayFromProperty( kGraphicsModeKey, params, 4 ); - // Try to find a resolution if "Graphics Mode" setting is not available. - if ( count < 3 ) - { - // Use the default resolution if we don't have an initialized GUI. - if (gui.screen.width == 0 || gui.screen.height == 0) - { - gui.screen.width = DEFAULT_SCREEN_WIDTH; - gui.screen.height = DEFAULT_SCREEN_HEIGHT; - } + // Try to find a resolution if "Graphics Mode" setting is not available. + if ( count < 3 ) + { + // Use the default resolution if we don't have an initialized GUI. + if (gui.screen.width == 0 || gui.screen.height == 0) + { + gui.screen.width = DEFAULT_SCREEN_WIDTH; + gui.screen.height = DEFAULT_SCREEN_HEIGHT; + } - params[0] = gui.screen.width; - params[1] = gui.screen.height; - params[2] = 32; - } + params[0] = gui.screen.width; + params[1] = gui.screen.height; + params[2] = 32; + } - // Map from pixel format to bits per pixel. + // Map from pixel format to bits per pixel. - if ( params[2] == 256 ) params[2] = 8; - if ( params[2] == 555 ) params[2] = 16; - if ( params[2] == 888 ) params[2] = 32; + if ( params[2] == 256 ) + params[2] = 8; + if ( params[2] == 555 ) + params[2] = 16; + + if ( params[2] == 888 ) + params[2] = 32; + return setVESAGraphicsMode( params[0], params[1], params[2], params[3] ); } @@ -1157,47 +1193,51 @@ void setVideoMode( int mode, int drawgraphics) { - unsigned long params[4]; - int count; - int err = errSuccess; + unsigned long params[4]; + int count; + int err = errSuccess; - if ( mode == GRAPHICS_MODE ) - { - if ( (err=initGraphicsMode ()) == errSuccess ) { - if (gVerboseMode) { - // Tell the kernel to use text mode on a linear frame buffer display - bootArgs->Video.v_display = FB_TEXT_MODE; - } else { - bootArgs->Video.v_display = GRAPHICS_MODE; - } - } - } + if ( mode == GRAPHICS_MODE ) + { + if ( (err=initGraphicsMode ()) == errSuccess ) + { + if (gVerboseMode) + { + // Tell the kernel to use text mode on a linear frame buffer display + bootArgs->Video.v_display = FB_TEXT_MODE; + } + else + { + bootArgs->Video.v_display = GRAPHICS_MODE; + } + } + } - if ( (mode == VGA_TEXT_MODE) || (err != errSuccess) ) - { - count = getNumberArrayFromProperty( kTextModeKey, params, 2 ); - if ( count < 2 ) - { - params[0] = 80; // Default text mode is 80x25. - params[1] = 25; - } + if ( (mode == VGA_TEXT_MODE) || (err != errSuccess) ) + { + count = getNumberArrayFromProperty( kTextModeKey, params, 2 ); + if ( count < 2 ) + { + params[0] = 80; // Default text mode is 80x25. + params[1] = 25; + } - setVESATextMode( params[0], params[1], 4 ); - bootArgs->Video.v_display = VGA_TEXT_MODE; - } + setVESATextMode( params[0], params[1], 4 ); + bootArgs->Video.v_display = VGA_TEXT_MODE; + } - currentIndicator = 0; + currentIndicator = 0; } //============================================================================== -void getGraphicModeParams(unsigned long params[]) { - +void getGraphicModeParams(unsigned long params[]) +{ params[3] = 0; VBEModeInfoBlock minfo; - unsigned short vesaVersion; - unsigned short mode = modeEndOfList; + unsigned short vesaVersion; + unsigned short mode = modeEndOfList; getNumberArrayFromProperty( kGraphicsModeKey, params, 4); @@ -1225,6 +1265,7 @@ //========================================================================== // Display and clear the activity indicator. +// BASIC Indicator static char indicator[] = {'-', '\\', '|', '/', '-', '\\', '|', '/', '\0'}; // To prevent a ridiculously fast-spinning indicator, Index: trunk/i386/boot2/Makefile =================================================================== --- trunk/i386/boot2/Makefile (revision 2475) +++ trunk/i386/boot2/Makefile (revision 2476) @@ -36,7 +36,7 @@ INC = -I. -I$(SRCROOT) -I$(SYMDIR) -I$(LIBSADIR) -I$(LIBSAIODIR) -I${SRCROOT}/i386/include LIBS= -L$(SYMDIR) -lsaio -lsa -lklibc -LIBDEP= libsaio.a libsa.a libklibc.a +LIBDEP= libsaio.a libsa.a libklibc.a OTHER_FILES = @@ -80,7 +80,7 @@ endif @${MKDIRS} $(OBJROOT)/../boot2_modules/ - + @### First pass, don't worry abount segment alignment. @echo " [LD] boot.sys" @$(CC) -Wl,-preload -Wl,-alias,boot2,start \ Index: trunk/i386/boot2/boot.c =================================================================== --- trunk/i386/boot2/boot.c (revision 2475) +++ trunk/i386/boot2/boot.c (revision 2476) @@ -28,24 +28,19 @@ * Copyright (c) 1989 Carnegie-Mellon University * All rights reserved. The CMU software License Agreement specifies * the terms and conditions for use and redistribution. - */ - -/* - * INTEL CORPORATION PROPRIETARY INFORMATION * - * This software is supplied under the terms of a license agreement or - * nondisclosure agreement with Intel Corporation and may not be copied - * nor disclosed except in accordance with the terms of that agreement. + * INTEL CORPORATION PROPRIETARY INFORMATION * + * This software is supplied under the terms of a license agreement or + * nondisclosure agreement with Intel Corporation and may not be copied + * nor disclosed except in accordance with the terms of that agreement. + * * Copyright 1988, 1989 by Intel Corporation - */ - -/* + * + * * Copyright 1993 NeXT Computer, Inc. * All rights reserved. - */ - -/* + * * Completely reworked by Sam Streeper (sam_s@NeXT.com) * Reworked again by Curtis Galloway (galloway@NeXT.com) */ @@ -536,7 +531,7 @@ long flags, sleeptime, time; void *binary = (void *)kLoadAddr; - char bootFile[sizeof(bootInfo->bootFile)]; + char bootFile[sizeof(bootInfo->bootFile)]; char bootFilePath[512]; char kernelCacheFile[512]; @@ -719,7 +714,7 @@ // bootFile must start with a / if it not start with a device name if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/') { - if (!YOSEMITE) + if ( !YOSEMITE ) { //printf(HEADER " (%s).\n", bootInfo->bootFile); snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading / Index: trunk/i386/boot2/modules.c =================================================================== --- trunk/i386/boot2/modules.c (revision 2475) +++ trunk/i386/boot2/modules.c (revision 2476) @@ -78,8 +78,8 @@ return retVal; } -void start_built_in_module(const char* name, - const char* author, +void start_built_in_module(const char* name, + const char* author, const char* description, UInt32 version, UInt32 compat, @@ -95,7 +95,7 @@ * Module depencdies will be loaded first * Modules will only be loaded once. When loaded a module must * setup apropriete function calls and hooks as required. - * NOTE: To ensure a module loads after another you may + * NOTE: To ensure a module loads after another you may * link one module with the other. For dyld to allow this, you must * reference at least one symbol within the module. */ @@ -107,7 +107,7 @@ struct dirstuff* moduleDir = opendir("/Extra/modules/"); if(!moduleDir) { - verbose("Warning: Unable to open modules folder at '/Extra/modules/'. Ingoring modules.\n"); + verbose("Warning: Unable to open modules folder at '/Extra/modules/'. Ignoring modules.\n"); return; } while (readdir(moduleDir, (const char**)&name, &flags, &time) >= 0) { @@ -146,7 +146,7 @@ { return 1; } - + snprintf(modString, sizeof(modString), MODULE_PATH "%s", module); fh = open(modString, 0); if(fh < 0) @@ -197,17 +197,17 @@ /* * add_symbol - * This function adds a symbol from a module to the list of known symbols + * This function adds a symbol from a module to the list of known symbols * possibly change to a pointer and add this to the Symbol module so that it can * adjust it's internal symbol list (sort) to optimize locating new symbols * NOTE: returns the address if the symbol is "start", else returns 0xFFFFFFFF */ long long add_symbol(char* symbol, long long addr, char is64) { - // This only can handle 32bit symbols + // This only can handle 32bit symbols symbolList_t* entry; //DBG("Adding symbol %s at 0x%X\n", symbol, addr); - + entry = malloc(sizeof(symbolList_t)); entry->next = moduleSymbols; moduleSymbols = entry; @@ -235,7 +235,7 @@ new_entry->next = loadedModules; loadedModules = new_entry; - + if(!name) name = "Unknown"; if(!author) author = "Unknown"; if(!description) description = ""; @@ -269,7 +269,7 @@ } } - + DBG("Module %s not loaded\n", name); DBGPAUSE(); return 0; } @@ -298,7 +298,7 @@ entry = entry->next; } } - + #if CONFIG_MODULE_DEBUG printf("Unable to locate symbol %s\n", name); getchar(); @@ -307,7 +307,7 @@ if(strcmp(name, VOID_SYMBOL) == 0) return 0xFFFFFFFF; // In the event that a symbol does not exist // Return a pointer to a void function. - else return lookup_all_symbols(VOID_SYMBOL); + else return lookup_all_symbols(VOID_SYMBOL); } /********************************************************************************/ @@ -322,15 +322,15 @@ * NOTE: If the module is unable to load ot completeion, the modules * symbols will still be available. */ -void* parse_mach(void* binary, - int(*dylib_loader)(char*), +void* parse_mach(void* binary, + int(*dylib_loader)(char*), long long(*symbol_handler)(char*, long long, char), void (*section_handler)(char* section, char* segment, void* cmd, UInt64 offset, UInt64 address) ) -{ +{ char is64 = false; void (*module_start)(void) = NULL; - + // Module info /*char* moduleName = NULL; UInt32 moduleVersion = 0; @@ -340,7 +340,7 @@ struct load_command *loadCommand = NULL; struct dylib_command* dylibCommand = NULL; struct dyld_info_command* dyldInfoCommand = NULL; - + struct symtab_command* symtabCommand = NULL; struct segment_command *segCommand = NULL; struct segment_command_64 *segCommand64 = NULL; @@ -348,7 +348,7 @@ //struct dysymtab_command* dysymtabCommand = NULL; UInt32 binaryIndex = 0; UInt16 cmd = 0; - + textSection = 0; textAddress = 0; // reinitialize text location in case it doesn't exist; @@ -376,21 +376,21 @@ getchar(); return NULL; // Module is in the incorrect format }*/ - + while(cmd < ((struct mach_header*)binary)->ncmds) { cmd++; - + loadCommand = binary + binaryIndex; UInt32 cmdSize = loadCommand->cmdsize; - - + + switch ((loadCommand->cmd & 0x7FFFFFFF)) { case LC_SYMTAB: symtabCommand = binary + binaryIndex; break; - + case LC_SEGMENT: // 32bit macho { segCommand = binary + binaryIndex; @@ -414,7 +414,7 @@ // __TEXT,__text found, save the offset and address for when looking for the calls. textSection = sect->offset; textAddress = sect->addr; - } + } } } break; @@ -440,12 +440,12 @@ // __TEXT,__text found, save the offset and address for when looking for the calls. textSection = sect->offset; textAddress = sect->addr; - } + } } } break; - + case LC_LOAD_DYLIB: case LC_LOAD_WEAK_DYLIB ^ LC_REQ_DYLD: // Required modules @@ -458,7 +458,7 @@ { char* name = malloc(strlen(module) + strlen(".dylib") + 1); sprintf(name, "%s.dylib", module); - + if (!dylib_loader(name)) { // NOTE: any symbols exported by dep will be replace with the void function @@ -481,20 +481,20 @@ // Bind and rebase info is stored here dyldInfoCommand = binary + binaryIndex; break; - + case LC_DYSYMTAB: case LC_UUID: break; case LC_UNIXTHREAD: break; - + default: DBG("Unhandled loadcommand 0x%X\n", loadCommand->cmd & 0x7FFFFFFF); break; - + } - + binaryIndex += cmdSize; } @@ -505,12 +505,12 @@ { // Rebase the module before binding it. if(dyldInfoCommand->rebase_off) rebase_macho(binary, (char*)dyldInfoCommand->rebase_off, dyldInfoCommand->rebase_size); - // Bind all symbols. + // Bind all symbols. if(dyldInfoCommand->bind_off) bind_macho(binary, (UInt8*)dyldInfoCommand->bind_off, dyldInfoCommand->bind_size); if(dyldInfoCommand->weak_bind_off) bind_macho(binary, (UInt8*)dyldInfoCommand->weak_bind_off, dyldInfoCommand->weak_bind_size); if(dyldInfoCommand->lazy_bind_off) bind_macho(binary, (UInt8*)dyldInfoCommand->lazy_bind_off, dyldInfoCommand->lazy_bind_size); } - + return module_start; } @@ -535,7 +535,7 @@ if(symbolEntry->n_value && symbol_handler(symbolString + symbolEntry->n_un.n_strx, textAddress ? (long long)base + symbolEntry->n_value : symbolEntry->n_value, is64) != 0xFFFFFFFF) { - + // Module start located. Start is an alias so don't register it module_start = textAddress ? base + symbolEntry->n_value : symbolEntry->n_value; } @@ -547,7 +547,7 @@ else { struct nlist_64* symbolEntry = (void*)base + symtabCommand->symoff; - // NOTE First entry is *not* correct, but we can ignore it (i'm getting radar:// right now, verify later) + // NOTE First entry is *not* correct, but we can ignore it (i'm getting radar:// right now, verify later) while(symbolIndex < symtabCommand->nsyms) { @@ -572,26 +572,26 @@ void rebase_macho(void* base, char* rebase_stream, UInt32 size) { rebase_stream += (UInt32)base; - + UInt8 immediate = 0; UInt8 opcode = 0; UInt8 type = 0; UInt32 segmentAddress = 0; - - + + UInt32 tmp = 0; UInt32 tmp2 = 0; UInt8 bits = 0; int index = 0; unsigned int i = 0; - + while(i < size) { immediate = rebase_stream[i] & REBASE_IMMEDIATE_MASK; opcode = rebase_stream[i] & REBASE_OPCODE_MASK; - - + + switch(opcode) { case REBASE_OPCODE_DONE: @@ -601,13 +601,13 @@ type = 0; segmentAddress = 0; break; - - + + case REBASE_OPCODE_SET_TYPE_IMM: type = immediate; break; - - + + case REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: // Locate address to begin rebasing @@ -624,7 +624,7 @@ } while(index <= immediate); segmentAddress = segCommand->fileoff; - + tmp = 0; bits = 0; do { @@ -632,7 +632,7 @@ bits += 7; } while(rebase_stream[i] & 0x80); - + segmentAddress += tmp; break; @@ -645,10 +645,10 @@ tmp |= rebase_stream[++i] & 0x7f; bits += 7; } while(rebase_stream[i] & 0x80); - - segmentAddress += tmp; + + segmentAddress += tmp; break; - + case REBASE_OPCODE_ADD_ADDR_IMM_SCALED: segmentAddress += immediate * sizeof(void*); break; @@ -661,7 +661,7 @@ segmentAddress += sizeof(void*); } break; - + case REBASE_OPCODE_DO_REBASE_ULEB_TIMES: tmp = 0; bits = 0; @@ -677,7 +677,7 @@ segmentAddress += sizeof(void*); } break; - + case REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB: tmp = 0; bits = 0; @@ -685,12 +685,12 @@ tmp |= (rebase_stream[++i] & 0x7f) << bits; bits += 7; } while(rebase_stream[i] & 0x80); - + rebase_location(base + segmentAddress, (char*)base, type); - + segmentAddress += tmp + sizeof(void*); break; - + case REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB: tmp = 0; bits = 0; @@ -698,8 +698,8 @@ tmp |= (rebase_stream[++i] & 0x7f) << bits; bits += 7; } while(rebase_stream[i] & 0x80); - - + + tmp2 = 0; bits = 0; do { @@ -709,9 +709,9 @@ index = 0; for (index = 0; index < tmp; ++index) { - + rebase_location(base + segmentAddress, (char*)base, type); - + segmentAddress += tmp2 + sizeof(void*); } break; @@ -741,41 +741,41 @@ // Based on code from dylibinfo.cpp and ImageLoaderMachOCompressed.cpp -// NOTE: this uses 32bit values, and not 64bit values. +// NOTE: this uses 32bit values, and not 64bit values. // There is a possibility that this could cause issues, // however the modules are 32 bits, so it shouldn't matter too much void bind_macho(void* base, UInt8* bind_stream, UInt32 size) -{ +{ bind_stream += (UInt32)base; - + UInt8 immediate = 0; UInt8 opcode = 0; UInt8 type = BIND_TYPE_POINTER; - + UInt32 segmentAddress = 0; - + UInt32 address = 0; - + SInt32 addend = 0; SInt32 libraryOrdinal = 0; - + const char* symbolName = NULL; UInt8 symboFlags = 0; UInt32 symbolAddr = 0xFFFFFFFF; - + // Temperary variables UInt32 tmp = 0; UInt32 tmp2 = 0; UInt32 index = 0; unsigned int i = 0; - + while(i < size) { immediate = bind_stream[i] & BIND_IMMEDIATE_MASK; opcode = bind_stream[i] & BIND_OPCODE_MASK; - - + + switch(opcode) { case BIND_OPCODE_DONE: @@ -787,19 +787,19 @@ libraryOrdinal = 0; symbolAddr = 0xFFFFFFFF; break; - + case BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: libraryOrdinal = immediate; break; - + case BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: libraryOrdinal = read_uleb(bind_stream, &i); break; - + case BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: - libraryOrdinal = immediate ? (SInt8)(BIND_OPCODE_MASK | immediate) : immediate; + libraryOrdinal = immediate ? (SInt8)(BIND_OPCODE_MASK | immediate) : immediate; break; - + case BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: symboFlags = immediate; symbolName = (char*)&bind_stream[++i]; @@ -811,12 +811,12 @@ case BIND_OPCODE_SET_TYPE_IMM: type = immediate; break; - + case BIND_OPCODE_SET_ADDEND_SLEB: addend = read_uleb(bind_stream, &i); if(!(bind_stream[i-1] & 0x40)) addend *= -1; break; - + case BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: segmentAddress = 0; @@ -837,11 +837,11 @@ segmentAddress += read_uleb(bind_stream, &i); break; - + case BIND_OPCODE_ADD_ADDR_ULEB: segmentAddress += read_uleb(bind_stream, &i); break; - + case BIND_OPCODE_DO_BIND: if(symbolAddr != 0xFFFFFFFF) { @@ -854,10 +854,10 @@ printf("Unable to bind symbol %s\n", symbolName); getchar(); } - + segmentAddress += sizeof(void*); break; - + case BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: // Read in offset tmp = read_uleb(bind_stream, &i); @@ -865,7 +865,7 @@ if(symbolAddr != 0xFFFFFFFF) { address = segmentAddress + (UInt32)base; - + bind_location((UInt32*)address, (char*)symbolAddr, addend, type); } else @@ -875,15 +875,15 @@ } segmentAddress += tmp + sizeof(void*); - - + + break; - + case BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED: if(symbolAddr != 0xFFFFFFFF) { address = segmentAddress + (UInt32)base; - + bind_location((UInt32*)address, (char*)symbolAddr, addend, type); } else @@ -892,20 +892,20 @@ getchar(); } segmentAddress += (immediate * sizeof(void*)) + sizeof(void*); - + break; - + case BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: tmp = read_uleb(bind_stream, &i); - - tmp2 = read_uleb(bind_stream, &i); + tmp2 = read_uleb(bind_stream, &i); + if(symbolAddr != 0xFFFFFFFF) { for(index = 0; index < tmp; index++) { - + address = segmentAddress + (UInt32)base; bind_location((UInt32*)address, (char*)symbolAddr, addend, type); segmentAddress += tmp2 + sizeof(void*); @@ -926,14 +926,14 @@ } static inline void rebase_location(UInt32* location, char* base, int type) -{ +{ switch(type) { case REBASE_TYPE_POINTER: case REBASE_TYPE_TEXT_ABSOLUTE32: *location += (UInt32)base; break; - + default: break; } @@ -941,18 +941,18 @@ static inline void bind_location(UInt32* location, char* value, UInt32 addend, int type) -{ +{ // do actual update char* newValue = value + addend; - + switch (type) { case BIND_TYPE_POINTER: case BIND_TYPE_TEXT_ABSOLUTE32: break; - + case BIND_TYPE_TEXT_PCREL32: newValue -= ((UInt32)location + 4); - + break; default: return; @@ -981,7 +981,7 @@ *binary++ = 0xFF; // Jump *binary++ = 0x25; // Long Jump *((UInt32*)binary) = (UInt32)jumpPointer; - + *jumpPointer = (UInt32)newAddress; return 1; } @@ -1035,9 +1035,9 @@ void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*)) { DBG("Adding callback for '%s' hook.\n", name); DBGPAUSE(); - + moduleHook_t* hook = hook_exists(name); - + if(hook) { // append @@ -1092,7 +1092,7 @@ void print_hook_list() { printf("---Hook Table---\n"); - + moduleHook_t* hooks = moduleCallbacks; while(hooks) { @@ -1122,7 +1122,7 @@ void load_all_modules() { - + } int execute_hook(const char* name, void* arg1, void* arg2, void* arg3, void* arg4) @@ -1143,8 +1143,8 @@ return 0; } -void start_built_in_module(const char* name, - const char* author, +void start_built_in_module(const char* name, + const char* author, const char* description, UInt32 version, UInt32 compat, Index: trunk/i386/boot2/bmdecompress.c =================================================================== --- trunk/i386/boot2/bmdecompress.c (revision 2475) +++ trunk/i386/boot2/bmdecompress.c (revision 2476) @@ -22,229 +22,257 @@ #include "libsa.h" -static void -PreviewDecompress16(uint32_t * compressBuffer, +static void PreviewDecompress16(uint32_t * compressBuffer, + uint32_t width, uint32_t height, uint32_t row, + uint16_t * output); + +static void PreviewDecompress32(uint32_t * compressBuffer, uint32_t width, uint32_t height, uint32_t row, - uint16_t * output) + uint32_t * output); + +static void PreviewDecompress16(uint32_t * compressBuffer, + uint32_t width, uint32_t height, uint32_t row, + uint16_t * output) { - int i, j; - uint32_t * input; - - uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t)); - uint32_t sr0, sr1, sr2, sr3; + int i, j; + uint32_t * input; - bzero(sc0, (width+2) * sizeof(uint16_t)); - bzero(sc1, (width+2) * sizeof(uint16_t)); - bzero(sc2, (width+2) * sizeof(uint16_t)); - bzero(sc3, (width+2) * sizeof(uint16_t)); + uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t)); + uint32_t sr0, sr1, sr2, sr3; - uint32_t tmp1, tmp2, out; - for (j = 0; j < (height + 2); j++) - { - input = compressBuffer; - if (j < height) - input += j; - else - input += height - 1; - input = (uint32_t *)(input[3] + ((uint8_t *)compressBuffer)); + bzero(sc0, (width+2) * sizeof(uint16_t)); + bzero(sc1, (width+2) * sizeof(uint16_t)); + bzero(sc2, (width+2) * sizeof(uint16_t)); + bzero(sc3, (width+2) * sizeof(uint16_t)); - uint32_t data = 0, repeat = 0, fetch = 0, count = 0; - sr0 = sr1 = sr2 = sr3 = 0; + uint32_t tmp1, tmp2, out; + for (j = 0; j < (height + 2); j++) + { + input = compressBuffer; - for (i = 0; i < (width + 2); i++) - { - if (i < width) - { - if (!count) - { - count = *input++; - repeat = (count & 0xff000000); - count ^= repeat; - fetch = true; - } - else - fetch = (0 == repeat); + if (j < height) + { + input += j; + } + else + { + input += height - 1; + } + + input = (uint32_t *)(input[3] + ((uint8_t *)compressBuffer)); + + uint32_t data = 0, repeat = 0, fetch = 0, count = 0; + sr0 = sr1 = sr2 = sr3 = 0; + + for (i = 0; i < (width + 2); i++) + { + if (i < width) + { + if (!count) + { + count = *input++; + repeat = (count & 0xff000000); + count ^= repeat; + fetch = true; + } + else + { + fetch = (0 == repeat); + } - count--; + count--; - if (fetch) - { + if (fetch) + { data = *((uint16_t *)input); - (*((uint16_t *)input))++; + (*((uint16_t *)input))++; - // grayscale - // srgb 13933, 46871, 4732 - // ntsc 19595, 38470, 7471 - data = 13933 * (0x1f & (data >> 10)) - + 46871 * (0x1f & (data >> 5)) - + 4732 * (0x1f & data); - data >>= 13; - - // 70% white, 30 % black - data *= 19661; - data += (103 << 16); - data >>= 16; - } - } + // grayscale + // srgb 13933, 46871, 4732 + // ntsc 19595, 38470, 7471 + data = 13933 * (0x1f & (data >> 10)) + + 46871 * (0x1f & (data >> 5)) + + 4732 * (0x1f & data); + data >>= 13; - // gauss blur - tmp2 = sr0 + data; - sr0 = data; - tmp1 = sr1 + tmp2; - sr1 = tmp2; - tmp2 = sr2 + tmp1; - sr2 = tmp1; - tmp1 = sr3 + tmp2; - sr3 = tmp2; - - tmp2 = sc0[i] + tmp1; - sc0[i] = tmp1; - tmp1 = sc1[i] + tmp2; - sc1[i] = tmp2; - tmp2 = sc2[i] + tmp1; - sc2[i] = tmp1; - out = (128 + sc3[i] + tmp2) >> 11; - sc3[i] = tmp2; + // 70% white, 30 % black + data *= 19661; + data += (103 << 16); + data >>= 16; + } + } - out &= 0x1f; - if ((i > 1) && (j > 1)) - output[i-2] = out | (out << 5) | (out << 10); - } + // gauss blur + tmp2 = sr0 + data; + sr0 = data; + tmp1 = sr1 + tmp2; + sr1 = tmp2; + tmp2 = sr2 + tmp1; + sr2 = tmp1; + tmp1 = sr3 + tmp2; + sr3 = tmp2; + + tmp2 = sc0[i] + tmp1; + sc0[i] = tmp1; + tmp1 = sc1[i] + tmp2; + sc1[i] = tmp2; + tmp2 = sc2[i] + tmp1; + sc2[i] = tmp1; + out = (128 + sc3[i] + tmp2) >> 11; + sc3[i] = tmp2; - if (j > 1) - output += row; - } - free(sc3); - free(sc2); - free(sc1); - free(sc0); + out &= 0x1f; + if ((i > 1) && (j > 1)) + { + output[i-2] = out | (out << 5) | (out << 10); + } + } + + if (j > 1) + { + output += row; + } + } + free(sc3); + free(sc2); + free(sc1); + free(sc0); } -static void -PreviewDecompress32(uint32_t * compressBuffer, - uint32_t width, uint32_t height, uint32_t row, - uint32_t * output) +static void PreviewDecompress32(uint32_t * compressBuffer, + uint32_t width, uint32_t height, uint32_t row, + uint32_t * output) { - int i, j; - uint32_t * input; + int i, j; + uint32_t * input; - uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t)); - uint32_t sr0, sr1, sr2, sr3; + uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t)); + uint32_t sr0, sr1, sr2, sr3; - bzero(sc0, (width+2) * sizeof(uint16_t)); - bzero(sc1, (width+2) * sizeof(uint16_t)); - bzero(sc2, (width+2) * sizeof(uint16_t)); - bzero(sc3, (width+2) * sizeof(uint16_t)); + bzero(sc0, (width+2) * sizeof(uint16_t)); + bzero(sc1, (width+2) * sizeof(uint16_t)); + bzero(sc2, (width+2) * sizeof(uint16_t)); + bzero(sc3, (width+2) * sizeof(uint16_t)); - uint32_t tmp1, tmp2, out; - for (j = 0; j < (height + 2); j++) - { - input = compressBuffer; - if (j < height) - input += j; - else - input += height - 1; - input = (uint32_t *)(input[3] + ((uint8_t *)compressBuffer)); + uint32_t tmp1, tmp2, out; + for (j = 0; j < (height + 2); j++) + { + input = compressBuffer; + if (j < height) + { + input += j; + } + else + { + input += height - 1; + } + input = (uint32_t *)(input[3] + ((uint8_t *)compressBuffer)); - uint32_t data = 0, repeat = 0, fetch = 0, count = 0; - sr0 = sr1 = sr2 = sr3 = 0; + uint32_t data = 0, repeat = 0, fetch = 0, count = 0; + sr0 = sr1 = sr2 = sr3 = 0; - for (i = 0; i < (width + 2); i++) - { - if (i < width) - { - if (!count) - { - count = *input++; - repeat = (count & 0xff000000); - count ^= repeat; - fetch = true; - } - else - fetch = (0 == repeat); - - count--; - - if (fetch) - { - data = *input++; - - // grayscale - // srgb 13933, 46871, 4732 - // ntsc 19595, 38470, 7471 - data = 13933 * (0xff & (data >> 24)) - + 46871 * (0xff & (data >> 16)) - + 4732 * (0xff & data); - data >>= 16; - - // 70% white, 30 % black - data *= 19661; - data += (103 << 16); - data >>= 16; - } - } + for (i = 0; i < (width + 2); i++) + { + if (i < width) + { + if (!count) + { + count = *input++; + repeat = (count & 0xff000000); + count ^= repeat; + fetch = true; + } + else + { + fetch = (0 == repeat); + } - // gauss blur - tmp2 = sr0 + data; - sr0 = data; - tmp1 = sr1 + tmp2; - sr1 = tmp2; - tmp2 = sr2 + tmp1; - sr2 = tmp1; - tmp1 = sr3 + tmp2; - sr3 = tmp2; - - tmp2 = sc0[i] + tmp1; - sc0[i] = tmp1; - tmp1 = sc1[i] + tmp2; - sc1[i] = tmp2; - tmp2 = sc2[i] + tmp1; - sc2[i] = tmp1; - out = (128 + sc3[i] + tmp2) >> 8; - sc3[i] = tmp2; + count--; - out &= 0xff; - if ((i > 1) && (j > 1)) - output[i-2] = out | (out << 8) | (out << 16); - } + if (fetch) + { + data = *input++; - if (j > 1) - output += row; - } + // grayscale + // srgb 13933, 46871, 4732 + // ntsc 19595, 38470, 7471 + data = 13933 * (0xff & (data >> 24)) + + 46871 * (0xff & (data >> 16)) + + 4732 * (0xff & data); + data >>= 16; - free(sc3); - free(sc2); - free(sc1); - free(sc0); + // 70% white, 30 % black + data *= 19661; + data += (103 << 16); + data >>= 16; + } + } + + // gauss blur + tmp2 = sr0 + data; + sr0 = data; + tmp1 = sr1 + tmp2; + sr1 = tmp2; + tmp2 = sr2 + tmp1; + sr2 = tmp1; + tmp1 = sr3 + tmp2; + sr3 = tmp2; + + tmp2 = sc0[i] + tmp1; + sc0[i] = tmp1; + tmp1 = sc1[i] + tmp2; + sc1[i] = tmp2; + tmp2 = sc2[i] + tmp1; + sc2[i] = tmp1; + out = (128 + sc3[i] + tmp2) >> 8; + sc3[i] = tmp2; + + out &= 0xff; + if ((i > 1) && (j > 1)) + { + output[i-2] = out | (out << 8) | (out << 16); + } + } + + if (j > 1) + { + output += row; + } + } + + free(sc3); + free(sc2); + free(sc1); + free(sc0); } void * DecompressData(void *srcbase, int *dw, int *dh, int *bitsPerPixel) { - uint32_t * src = (uint32_t *) srcbase; + uint32_t * src = (uint32_t *) srcbase; void * ret; - *bitsPerPixel = 8 * ((int) src[0]); + *bitsPerPixel = 8 * ((int) src[0]); *dw = (int) src[1]; *dh = (int) src[2]; ret = malloc ((*dw * *dh * *bitsPerPixel)/ 8); - switch(*bitsPerPixel) - { - case 32: - PreviewDecompress32((uint32_t *)srcbase, *dw, *dh, *dw, ret); - return ret; - case 16: - PreviewDecompress16((uint32_t *)srcbase, *dw, *dh, *dw, ret); - return ret; - default: - return 0; - } + switch(*bitsPerPixel) + { + case 32: + PreviewDecompress32((uint32_t *)srcbase, *dw, *dh, *dw, ret); + return ret; + case 16: + PreviewDecompress16((uint32_t *)srcbase, *dw, *dh, *dw, ret); + return ret; + default: + return 0; + } } Index: trunk/i386/boot2/gui.c =================================================================== --- trunk/i386/boot2/gui.c (revision 2475) +++ trunk/i386/boot2/gui.c (revision 2476) @@ -988,9 +988,7 @@ { case kPartitionTypeHFS: { - // ErmaC : TODO test needed for recovery icon - // Use HFSRECOVERY icon. // if (device->flags & kBVFlagBooter) // { Index: trunk/i386/boot2/appleboot.h =================================================================== --- trunk/i386/boot2/appleboot.h (revision 2475) +++ trunk/i386/boot2/appleboot.h (revision 2476) @@ -38,7 +38,7 @@ // The original data was 16K in size (128x128) and would make the booter // cross a 64K segment boundary. boot0 cannot load more than 127 sectors -// without changes. To eiminate that complexity, the data was run length +// without changes. To eliminate that complexity, the data was run length // encoded to save space. The reduced size is 1372 bytes. const unsigned char gAppleBootPictRLE[] = Index: trunk/i386/boot2/options.c =================================================================== --- trunk/i386/boot2/options.c (revision 2475) +++ trunk/i386/boot2/options.c (revision 2476) @@ -611,8 +611,7 @@ //========================================================================== -static void -printMemoryInfo(void) +static void printMemoryInfo(void) { int line; int i; @@ -1240,7 +1239,6 @@ { if( YOSEMITE ) // is 10.10 { - strlcpy( bootInfo->bootFile, kOSXKernel, sizeof(bootInfo->bootFile) ); //printf(HEADER "/System/Library/Kernels/%s\n", bootInfo->bootFile); } Index: trunk/i386/boot2/graphic_utils.c =================================================================== --- trunk/i386/boot2/graphic_utils.c (revision 2475) +++ trunk/i386/boot2/graphic_utils.c (revision 2476) @@ -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,57 @@ 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 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 pos(const uint16_t x, const uint16_t y) { position_t p; p.x = x; p.y = y; return p; } @@ -72,10 +77,10 @@ //if(testForQemu()) return; uint32_t x; - register uint8_t tempB; + 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: trunk/i386/config/confdata.c =================================================================== --- trunk/i386/config/confdata.c (revision 2475) +++ trunk/i386/config/confdata.c (revision 2476) @@ -107,14 +107,16 @@ const char *src; *res_ptr = 0; res_ptr[SYMBOL_MAXLENGTH] = 0; - while ((src = strchr(in, '$'))) { + while ((src = strchr(in, '$'))) + { struct symbol *sym; const char *symval; char *name_ptr = name; size_t n = min(res_rem, src - in); res_ptr = int_stpncpy(res_ptr, in, n); - if (!(res_rem -= n)) { + if (!(res_rem -= n)) + { return res_value; /* buffer full, quit now */ } src++; @@ -131,7 +133,8 @@ n = min(res_rem, strlen(symval)); res_ptr = int_stpncpy(res_ptr, symval, n); - if (!(res_rem -= n)) { + if (!(res_rem -= n)) + { return res_value; /* buffer full, quit now */ } in = src; Index: trunk/i386/modules/FileNVRAM/Cconfig =================================================================== --- trunk/i386/modules/FileNVRAM/Cconfig (revision 2475) +++ trunk/i386/modules/FileNVRAM/Cconfig (revision 2476) @@ -4,7 +4,7 @@ config FILENVRAM_MODULE bool "FileNVRAM Module" - default y + default y ---help--- Say Y here if you want to enable to use of this module. Index: trunk/i386/modules/MakeInc.dir =================================================================== --- trunk/i386/modules/MakeInc.dir (revision 2475) +++ trunk/i386/modules/MakeInc.dir (revision 2476) @@ -41,10 +41,10 @@ endif -UTILDIR = ../../util -LIBSADIR = ../../libsa -LIBSAIODIR = ../../libsaio -BOOT2DIR = ../../boot2 +UTILDIR = ${SRCROOT}/i386/util +LIBSADIR = ${SRCROOT}/i386/libsa +LIBSAIODIR = ${SRCROOT}/i386/libsaio +BOOT2DIR = ${SRCROOT}/i386/boot2 MODULE_INCLUDES := $(foreach x,$(MODULE_DEPENDENCIES),-I$(SRCROOT)/i386/modules/$(x)/include/) Index: trunk/i386/modules/KernelPatcher/Makefile =================================================================== --- trunk/i386/modules/KernelPatcher/Makefile (revision 2475) +++ trunk/i386/modules/KernelPatcher/Makefile (revision 2476) @@ -4,7 +4,7 @@ MODULE_VERSION = "1.1.3" MODULE_COMPAT_VERSION = "1.0.0" MODULE_START = $(MODULE_NAME)_start -MODULE_DEPENDENCIES = +MODULE_DEPENDENCIES = DIR = KernelPatcher Index: trunk/i386/modules/Sata/Sata.c =================================================================== --- trunk/i386/modules/Sata/Sata.c (revision 2475) +++ trunk/i386/modules/Sata/Sata.c (revision 2476) @@ -20,13 +20,12 @@ #define DBG(x...) #endif -void SATA_hook(void* arg1, void* arg2, void* arg3, void* arg4); - uint8_t default_SATA_ID[]= { 0x81, 0x26, 0x00, 0x00 }; #define SATA_ID_LEN ( sizeof(default_SATA_ID) / sizeof(uint8_t) ) +void SATA_hook(void* arg1, void* arg2, void* arg3, void* arg4); void SATA_hook(void* arg1, void* arg2, void* arg3, void* arg4) { pci_dt_t* current = arg1; Index: trunk/i386/modules/AcpiCodec/acpi_codec.c =================================================================== --- trunk/i386/modules/AcpiCodec/acpi_codec.c (revision 2475) +++ trunk/i386/modules/AcpiCodec/acpi_codec.c (revision 2476) @@ -4752,33 +4752,33 @@ bool acpidir_found = false; ret = GetFileInfo("rd(0,0)/Extra/", "Acpi", &flags, &time); - if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) + if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) { - sprintf(dirspec, "rd(0,0)/Extra/Acpi/"); - acpidir_found = true; + sprintf(dirspec, "rd(0,0)/Extra/Acpi/"); + acpidir_found = true; - } + } else { - ret = GetFileInfo("/Extra/", "Acpi", &flags, &time); - if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) + ret = GetFileInfo("/Extra/", "Acpi", &flags, &time); + if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) { - sprintf(dirspec, "/Extra/Acpi/"); - acpidir_found = true; + sprintf(dirspec, "/Extra/Acpi/"); + acpidir_found = true; - } + } else { - ret = GetFileInfo("bt(0,0)/Extra/", "Acpi", &flags, &time); - if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) + ret = GetFileInfo("bt(0,0)/Extra/", "Acpi", &flags, &time); + if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) { - sprintf(dirspec, "bt(0,0)/Extra/Acpi/"); - acpidir_found = true; + sprintf(dirspec, "bt(0,0)/Extra/Acpi/"); + acpidir_found = true; - } - } - } + } + } + } if (acpidir_found == true) { @@ -5058,60 +5058,63 @@ getBoolForKey(kSTRIPAPIC, &strip_madt, &bootInfo->chameleonConfig); - if ((strip_madt == false) || (!buildMADT(new_table_list, DsdtPtr, &madt_info ))) + if ((strip_madt == false) || (!buildMADT(new_table_list, DsdtPtr, &madt_info ))) { - ACPI_TABLE_MADT * madt_file = (void*)0ul; - ACPI_TABLE_MADT * MadtPointer = (void*)0ul; - bool oem_apic=false; + ACPI_TABLE_MADT * madt_file = (void*)0ul; + ACPI_TABLE_MADT * MadtPointer = (void*)0ul; + bool oem_apic=false; - { - bool tmpval; - oem_apic=getBoolForKey(kOEMAPIC, &tmpval, &bootInfo->chameleonConfig)&&tmpval; - } + { + bool tmpval; + oem_apic=getBoolForKey(kOEMAPIC, &tmpval, &bootInfo->chameleonConfig)&&tmpval; + } - if ((madt_file = (ACPI_TABLE_MADT *)get_new_table_in_list(new_table_list, NAMESEG("APIC"), &new_table_index)) != (void *)0ul) - { - if (oem_apic == false) - { - MadtPointer = (ACPI_TABLE_MADT *)madt_file; - } - - } else - MadtPointer = (acpi_tables.MadtPointer64 != (void*)0ul) ? (ACPI_TABLE_MADT *)acpi_tables.MadtPointer64 : (ACPI_TABLE_MADT *)acpi_tables.MadtPointer; + if ((madt_file = (ACPI_TABLE_MADT *)get_new_table_in_list(new_table_list, NAMESEG("APIC"), &new_table_index)) != (void *)0ul) + { + if (oem_apic == false) + { + MadtPointer = (ACPI_TABLE_MADT *)madt_file; + } + + } + else + { + MadtPointer = (acpi_tables.MadtPointer64 != (void*)0ul) ? (ACPI_TABLE_MADT *)acpi_tables.MadtPointer64 : (ACPI_TABLE_MADT *)acpi_tables.MadtPointer; + } + + ProcessMadtInfo(MadtPointer, &madt_info); - ProcessMadtInfo(MadtPointer, &madt_info); - - } + } - if (gen_ssdt || gen_csta || gen_psta || gen_tsta) - { - ProcessSsdt(new_table_list, DsdtPtr, &madt_info, gen_csta, gen_psta, gen_tsta ); - } - } + if (gen_ssdt || gen_csta || gen_psta || gen_tsta) + { + ProcessSsdt(new_table_list, DsdtPtr, &madt_info, gen_csta, gen_psta, gen_tsta ); + } + } if (rsdp_mod == (void *)0ul) - { + { printf("Error: rsdp_mod == null \n"); return EFI_ABORTED; } - - if (!(rsdp_mod->Length >= ACPI_RSDP_REV0_SIZE)) + + if (!(rsdp_mod->Length >= ACPI_RSDP_REV0_SIZE)) { printf("Error: rsdp_mod size is incorrect \n"); return EFI_ABORTED; - + } - + do { - + if ((rsdp_mod->Revision == 0) || (gen_xsdt == true)) { if (process_rsdt(rsdp_mod, gen_xsdt, new_table_list)) break; printf("Error : ACPI RSD PTR Revision 1 is incorrect, \n"); } - + if ((GetChecksum(rsdp_mod, sizeof(ACPI_TABLE_RSDP)) == 0) && (Revision == 2) && (rsdplength == sizeof(ACPI_TABLE_RSDP))) @@ -5119,40 +5122,40 @@ if (process_xsdt(rsdp_mod, new_table_list)) break; printf("Error : ACPI RSD PTR Revision 2 is incorrect \n"); - } - + } + Revision = 0; // fallback to Revision 0 - + if (process_rsdt(rsdp_mod, false, new_table_list)) - break; - + break; + printf("Error: Incorect ACPI RSD PTR or not found \n"); return EFI_ABORTED; - + } while (0); - - + + // Correct the checksum of RSDP - + DBG("RSDP: Original checksum %d\n", rsdp_mod->Checksum); - + setRsdpchecksum(rsdp_mod); - + DBG("New checksum %d\n", rsdp_mod->Checksum); - + if (Revision == 2) { - DBG("RSDP: Original extended checksum %d\n", rsdp_mod->ExtendedChecksum); - + DBG("RSDP: Original extended checksum %d\n", rsdp_mod->ExtendedChecksum); + setRsdpXchecksum(rsdp_mod); - + DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum); - + } - + verbose("ACPI Revision %d successfully patched\n", Revision); - - if (Revision == 2) + + if (Revision == 2) { /* XXX aserebln why uint32 cast if pointer is uint64 ? */ rsd_p = (U32)rsdp_mod; @@ -5164,8 +5167,8 @@ rsd_p = (U32)rsdp_mod; addConfigurationTable(&gEfiAcpiTableGuid, &rsd_p, "ACPI"); } - - + + #if DEBUG_ACPI==2 printf("Press a key to continue... (DEBUG_ACPI)\n"); getc(); @@ -5176,6 +5179,6 @@ int AcpiSetup(void) { EFI_STATUS status = setup_Acpi(); - + return (status == EFI_SUCCESS); } Index: trunk/i386/libsa/zalloc.c =================================================================== --- trunk/i386/libsa/zalloc.c (revision 2475) +++ trunk/i386/libsa/zalloc.c (revision 2476) @@ -157,7 +157,8 @@ #endif done: - if ((ret == 0) || (ret + size >= zalloc_end)) { + if ((ret == 0) || (ret + size >= zalloc_end)) + { if (zerror) { (*zerror)(ret, size, file, line); Index: trunk/i386/libsa/string.c =================================================================== --- trunk/i386/libsa/string.c (revision 2475) +++ trunk/i386/libsa/string.c (revision 2476) @@ -110,9 +110,9 @@ size_t strlen(const char * s) { - const char* save = s; - while (*s++); - return (--s) - save; + const char* save = s; + while (*s++); + return (--s) - save; } /*#endif*/ @@ -141,16 +141,20 @@ /* Derived from FreeBSD source */ int strncmp(const char * s1, const char * s2, size_t n) { - if (!n) - return 0; - do { - if (*s1 != *s2++) - return (*(const unsigned char *)s1 - - *(const unsigned char *)(s2 - 1)); - if (!*s1++) - break; - } while (--n); - return 0; + if (!n) + return 0; + do { + if (*s1 != *s2++) + { + return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1)); + } + + if (!*s1++) + { + break; + } + } while (--n); + return 0; } char * @@ -165,7 +169,8 @@ char * stpcpy(char * s1, const char * s2) { - while ((*s1++ = *s2++)) { + while ((*s1++ = *s2++)) + { continue; } return --s1; @@ -176,7 +181,8 @@ { register char *ret = s1; while (n && (*s1++ = *s2++)) - --n; + --n; + if (n > 0) { bzero(s1, n); } @@ -187,10 +193,12 @@ stpncpy(char * s1, const char * s2, size_t n) { while (n && (*s1++ = *s2++)) - --n; + --n; if (n > 0) - bzero(s1, n); - return s1; + { + bzero(s1, n); + } + return s1; } char * @@ -256,7 +264,9 @@ { register char *ret = s1; while (*s1) + { s1++; + } while ((*s1++ = *s2++)); return ret; } Index: trunk/i386/libsa/prf.c =================================================================== --- trunk/i386/libsa/prf.c (revision 2475) +++ trunk/i386/libsa/prf.c (revision 2476) @@ -118,10 +118,11 @@ flag |= SPACE; goto again; case '0': - if (minwidth == 0) { - /* this is a flag */ - flag |= ZERO; - goto again; + if (minwidth == 0) + { + /* this is a flag */ + flag |= ZERO; + goto again; } /* fall through */ case '1': case '2': Index: trunk/i386/util/machOconv.c =================================================================== --- trunk/i386/util/machOconv.c (revision 2475) +++ trunk/i386/util/machOconv.c (revision 2476) @@ -40,8 +40,10 @@ static unsigned long swap(unsigned long x) { - if (swap_ends) return OSSwapInt32(x); - else return x; + if (swap_ends) + return OSSwapInt32(x); + else + return x; } int @@ -52,75 +54,84 @@ int nc, ncmds; char * cp; - if (argc == 2) + if (argc == 2) { infile = open(argv[1], O_RDONLY); - if (infile < 0) goto usage; + if (infile < 0) + { + goto usage; + } outfile = fileno(stdout); - } - else if (argc == 3) + } + else if (argc == 3) { - infile = open(argv[1], O_RDONLY); - if (infile < 0) goto usage; + infile = open(argv[1], O_RDONLY); + if (infile < 0){ + goto usage; + } outfile = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (outfile < 0) goto usage; - } - else - { - usage: - fprintf(stderr, "usage: machOconv inputfile [outputfile]\n"); + if (outfile < 0) + { + goto usage; + } + } else { +usage: + fprintf(stderr, "usage: machOconv inputfile [outputfile]\n"); exit(1); - } + } - nc = read(infile, &mh, sizeof (mh)); - if (nc < 0) + nc = read(infile, &mh, sizeof (mh)); + if (nc < 0) { perror("read mach header"); exit(1); - } - - if (nc < (int)sizeof (mh)) + } + + if (nc < (int)sizeof (mh)) { fprintf(stderr, "read mach header: premature EOF %d\n", nc); exit(1); - } - - - if (mh.magic == MH_MAGIC) swap_ends = false; - else if (mh.magic == MH_CIGAM) swap_ends = true; - else + } + + if (mh.magic == MH_MAGIC) { - fprintf(stderr, "bad magic number %lx\n", (unsigned long)mh.magic); + swap_ends = false; + } + else if (mh.magic == MH_CIGAM) + { + swap_ends = true; + } else { + fprintf(stderr, "bad magic number %lx\n", (unsigned long)mh.magic); exit(1); - } - - cmds = calloc(swap(mh.sizeofcmds), sizeof (char)); - if (cmds == 0) + } + + cmds = calloc(swap(mh.sizeofcmds), sizeof (char)); + if (cmds == 0) { fprintf(stderr, "alloc load commands: no memory\n"); exit(1); - } - nc = read(infile, cmds, swap(mh.sizeofcmds)); - if (nc < 0) + } + + nc = read(infile, cmds, swap(mh.sizeofcmds)); + if (nc < 0) { perror("read load commands"); exit(1); - } - if (nc < (int)swap(mh.sizeofcmds)) + } + if (nc < (int)swap(mh.sizeofcmds)) { fprintf(stderr, "read load commands: premature EOF %d\n", nc); exit(1); - } + } unsigned long vmstart = (unsigned long)-1; // First pass: determine actual load address - for (ncmds = swap(mh.ncmds), cp = cmds; - ncmds > 0; ncmds--) + for (ncmds = swap(mh.ncmds), cp = cmds; ncmds > 0; ncmds--) { -#define lcp ((struct load_command *)cp) +#define lcp ((struct load_command *)cp) #define scp ((struct segment_command *)cp) - + switch(swap(lcp->cmd)) { case LC_SEGMENT: @@ -132,17 +143,16 @@ cp += swap(lcp->cmdsize); } - + // Second pass: output to file. - for (ncmds = swap(mh.ncmds), cp = cmds; - ncmds > 0; ncmds--) + for (ncmds = swap(mh.ncmds), cp = cmds; ncmds > 0; ncmds--) { -#define lcp ((struct load_command *)cp) +#define lcp ((struct load_command *)cp) #define scp ((struct segment_command *)cp) - bool isDATA; - unsigned vmsize; - + bool isDATA; + unsigned vmsize; + switch(swap(lcp->cmd)) { case LC_SEGMENT: @@ -150,42 +160,43 @@ if (isDATA) { vmsize = swap(scp->filesize); - } - else - { + } else { vmsize = swap(scp->vmsize); } - + result = vm_allocate(mach_task_self(), &data, vmsize, true); - if (result != KERN_SUCCESS) { + if (result != KERN_SUCCESS) + { mach_error("vm_allocate segment data", result); exit(1); } - + lseek(infile, swap(scp->fileoff), L_SET); nc = read(infile, (void *)data, swap(scp->filesize)); if (nc < 0) { perror("read segment data"); exit(1); } - if (nc < (int)swap(scp->filesize)) { + if (nc < (int)swap(scp->filesize)) + { fprintf(stderr, "read segment data: premature EOF %d\n", nc); exit(1); } - + lseek(outfile, swap(scp->vmaddr) - vmstart, L_SET); nc = write(outfile, (void *)data, vmsize); - if (nc < (int)vmsize) { + if (nc < (int)vmsize) + { perror("write segment data"); exit(1); } - + vm_deallocate(mach_task_self(), data, vmsize); break; } - + cp += swap(lcp->cmdsize); - } + } - exit(0); + exit(0); }