Index: trunk/i386/libsaio/xml.c =================================================================== --- trunk/i386/libsaio/xml.c (revision 2330) +++ trunk/i386/libsaio/xml.c (revision 2331) @@ -130,17 +130,18 @@ TagPtr XMLGetProperty(TagPtr dict, const char * key) { - TagPtr tagList, tag; + TagPtr tagList, tag; - if (dict->type != kTagTypeDict) return 0; - - tag = 0; - tagList = dict->tag; - while (tagList) - { - tag = tagList; - tagList = tag->tagNext; - + if (dict->type != kTagTypeDict) { + return 0; + } + + tag = 0; + tagList = dict->tag; + while (tagList) { + tag = tagList; + tagList = tag->tagNext; + if ((tag->type != kTagTypeKey) || (tag->string == 0)) { continue; } @@ -149,7 +150,6 @@ return tag->tag; } } - return 0; } @@ -362,8 +362,7 @@ } pos = length; - if (!strncmp(tagName, kXMLTagPList, 6)) - { + if (!strncmp(tagName, kXMLTagPList, 6)) { length = 0; // just a header; nothing to parse // return-via-reference tag should be left alone @@ -372,45 +371,32 @@ else if (!strcmp(tagName, kXMLTagDict)) { length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); - } - else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/') - { + } else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/') { length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1); - } - else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " "))) - { + } else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " "))) { length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); } /***** key ****/ - else if (!strcmp(tagName, kXMLTagKey)) - { + else if (!strcmp(tagName, kXMLTagKey)) { length = ParseTagKey(buffer + pos, tag); } /***** string ****/ - else if (!strcmp(tagName, kXMLTagString)) - { + else if (!strcmp(tagName, kXMLTagString)) { length = ParseTagString(buffer + pos, tag); - } - else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " "))) - { + } else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " "))) { // TODO: save tag if if found - if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID))) - { + if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID))) { // ID= int id = 0; int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1; while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; tagName[cnt] = 0; char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\""); - while(*val) - { - if ((*val >= '0' && *val <= '9')) // 0 - 9 - { + while(*val) { + if ((*val >= '0' && *val <= '9')) { // 0 - 9 id = (id * 10) + (*val++ - '0'); - } - else - { + } else { printf("ParseStringID error (0x%x)\n", *val); getchar(); return -1; @@ -419,23 +405,17 @@ length = ParseTagString(buffer + pos, tag); SaveRefString(buffer + pos, id); - } - else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) - { + } else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) { // IDREF= int id = 0; int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1; while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; tagName[cnt] = 0; char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\""); - while(*val) - { - if ((*val >= '0' && *val <= '9')) // 0 - 9 - { + while(*val) { + if ((*val >= '0' && *val <= '9')) { // 0 - 9 id = (id * 10) + (*val++ - '0'); - } - else - { + } else { printf("ParseStringIDREF error (0x%x)\n", *val); getchar(); return -1; @@ -457,28 +437,20 @@ } /***** integer ****/ - else if (!strcmp(tagName, kXMLTagInteger)) - { + else if (!strcmp(tagName, kXMLTagInteger)) { length = ParseTagInteger(buffer + pos, tag); - } - else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " "))) - { - if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID))) - { + } else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " "))) { + if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID))) { // ID= int id = 0; int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1; while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; tagName[cnt] = 0; char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\""); - while(*val) - { - if ((*val >= '0' && *val <= '9')) // 0 - 9 - { + while(*val) { + if ((*val >= '0' && *val <= '9')) { // 0 - 9 id = (id * 10) + (*val++ - '0'); - } - else - { + } else { printf("ParseIntegerID error (0x%x)\n", *val); getchar(); return -1; @@ -487,23 +459,17 @@ length = ParseTagInteger(buffer + pos, tag); SaveRefString((*tag)->string, id); - } - else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) - { + } else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) { // IDREF= int id = 0; int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1; while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; tagName[cnt] = 0; char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\""); - while(*val) - { - if ((*val >= '0' && *val <= '9')) // 0 - 9 - { + while(*val) { + if ((*val >= '0' && *val <= '9')) { // 0 - 9 id = (id * 10) + (*val++ - '0'); - } - else - { + } else { printf("ParseStringIDREF error (0x%x)\n", *val); getchar(); return -1; @@ -517,66 +483,57 @@ tmpTag->tag = 0; tmpTag->tagNext = 0; tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0; - + *tag = tmpTag; length = 0; //printf("Located IDREF, id = %d, string = %s\n", id, str); - } - else - { + } else { length = ParseTagInteger(buffer + pos, tag); } } - - /***** data ****/ - else if (!strcmp(tagName, kXMLTagData)) - { - length = ParseTagData(buffer + pos, tag); - } - else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " "))) - { - length = ParseTagData(buffer + pos, tag); - } - else if (!strcmp(tagName, kXMLTagDate)) - { - length = ParseTagDate(buffer + pos, tag); - } - /***** date ****/ - else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " "))) - { - length = ParseTagDate(buffer + pos, tag); - } /***** false ****/ - else if (!strcmp(tagName, kXMLTagFalse)) - { + else if (!strcmp(tagName, kXMLTagFalse)) { length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse); } + /***** true ****/ - else if (!strcmp(tagName, kXMLTagTrue)) - { + else if (!strcmp(tagName, kXMLTagTrue)) { length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue); } - /***** array ****/ - else if (!strcmp(tagName, kXMLTagArray)) - { - length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); + /***** plist ****/ + + + /***** dict ****/ + + + /***** data ****/ + else if (!strcmp(tagName, kXMLTagData)) { + length = ParseTagData(buffer + pos, tag); + } else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " "))) { + length = ParseTagData(buffer + pos, tag); + } else if (!strcmp(tagName, kXMLTagDate)) { + length = ParseTagDate(buffer + pos, tag); } - else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " "))) - { + + /***** date ****/ + else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " "))) { + length = ParseTagDate(buffer + pos, tag); + } /***** array ****/ + else if (!strcmp(tagName, kXMLTagArray)) { length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); } - else if (!strcmp(tagName, kXMLTagArray "/")) - { + else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " "))) { + length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); + } else if (!strcmp(tagName, kXMLTagArray "/")) { length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1); } /***** unknown ****/ - else - { + else { // it wasn't parsed so we consumed no additional characters *tag = 0; length = 0; @@ -601,10 +558,8 @@ tagList = 0; pos = 0; - if (!empty) - { - while (1) - { + if (!empty) { + while (1) { length = XMLParseNextTag(buffer + pos, &tmpTag); if (length == -1) { break; @@ -620,16 +575,14 @@ tagList = tmpTag; } - if (length == -1) - { + if (length == -1) { XMLFreeTag(tagList); return -1; } } tmpTag = NewTag(); - if (tmpTag == 0) - { + if (tmpTag == 0) { XMLFreeTag(tagList); return -1; } @@ -735,7 +688,7 @@ TagPtr tmpTag; char* val = buffer; int size; - + if(buffer[0] == '<') { printf("Warning integer is non existant\n"); @@ -753,65 +706,56 @@ } size = length = FixDataMatchingTag(buffer, kXMLTagInteger); - if (length == -1) return -1; + if (length == -1) { + return -1; + } tmpTag = NewTag(); - if (tmpTag == 0) return -1; + if (tmpTag == 0) { + return -1; + } integer = 0; - if(size > 1 && (val[1] == 'x' || val[1] == 'X')) // Hex value - { + if(size > 1 && (val[1] == 'x' || val[1] == 'X')) { // Hex value val += 2; - while(*val) - { - if ((*val >= '0' && *val <= '9')) // 0 - 9 - { + while(*val) { + if ((*val >= '0' && *val <= '9')) { // 0 - 9 + integer = (integer * 16) + (*val++ - '0'); - } - else if ((*val >= 'a' && *val <= 'f')) // a - f - { + } else if ((*val >= 'a' && *val <= 'f')) { // a - f integer = (integer * 16) + (*val++ - 'a' + 10); - } - else if ((*val >= 'A' && *val <= 'F')) // A - F - { - integer = (integer * 16) + (*val++ - 'a' + 10); - } - else - { + } else if ((*val >= 'A' && *val <= 'F')) { // A - F + integer = (integer * 16) + (*val++ - 'A' + 10); + } else { printf("ParseTagInteger hex error (0x%x) in buffer %s\n", *val, buffer); getchar(); XMLFreeTag(tmpTag); return -1; } } - } - else if ( size ) // Decimal value - { - if (*val == '-') - { + } else if ( size ) { // Decimal value + if (*val == '-') { negative = true; val++; size--; } - for (integer = 0; size > 0; size--) - { - if(*val) // UGLY HACK, fix me. - { - if (*val < '0' || *val > '9') - { + for (integer = 0; size > 0; size--) { + if(*val) { // UGLY HACK, fix me. + if (*val < '0' || *val > '9') { printf("ParseTagInteger decimal error (0x%x) in buffer %s\n", *val, buffer); getchar(); return -1; } - + integer = (integer * 10) + (*val++ - '0'); } } - if (negative) + if (negative) { integer = -integer; + } } tmpTag->type = kTagTypeInteger; @@ -916,21 +860,29 @@ { long cnt, cnt2; - if (tag == 0) return -1; + if (tag == 0) { + return -1; + } -// Find the start of the tag. + // Find the start of the tag. cnt = 0; while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++; - if (buffer[cnt] == '\0') return -1; + if (buffer[cnt] == '\0') { + return -1; + } // Find the end of the tag. cnt2 = cnt + 1; while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++; - if (buffer[cnt2] == '\0') return -1; + if (buffer[cnt2] == '\0') { + return -1; + } // Fix the tag data. *tag = buffer + cnt + 1; buffer[cnt2] = '\0'; - if (start) *start = cnt; + if (start) { + *start = cnt; + } return cnt2 + 1; } @@ -1006,13 +958,11 @@ XMLFreeTag( TagPtr tag ) { #if DOFREE - if (tag == 0) - { + if (tag == 0) { return; } - if (!XMLIsInteger(tag) && tag->string) - { + if (!XMLIsInteger(tag) && tag->string) { FreeSymbol(tag->string); } @@ -1059,11 +1009,9 @@ symbol = FindSymbol(string, 0); // Add the new symbol. - if (symbol == 0) - { + if (symbol == 0) { symbol = (SymbolPtr)malloc(sizeof(Symbol) + 1 + strlen(string)); - if (symbol == 0) //return 0; - { + if (symbol == 0) { //return 0; stop("NULL symbol!"); } @@ -1079,8 +1027,7 @@ // Update the refCount and return the string. symbol->refCount++; - if (lastGuy && lastGuy->next != 0) - { + if (lastGuy && lastGuy->next != 0) { stop("last guy not last!"); } @@ -1099,26 +1046,21 @@ // Look for string in the list of symbols. symbol = FindSymbol(string, &prev); - if (symbol == 0) - { + if (symbol == 0) { return; } // Update the refCount. symbol->refCount--; - if (symbol->refCount != 0) - { + if (symbol->refCount != 0) { return; } // Remove the symbol from the list. - if (prev != 0) - { + if (prev != 0) { prev->next = symbol->next; - } - else - { + } else { gSymbolsHead = symbol->next; } @@ -1138,10 +1080,8 @@ symbol = gSymbolsHead; prev = 0; - while (symbol != 0) - { - if (!strcmp(symbol->string, string)) - { + while (symbol != 0) { + if (!strcmp(symbol->string, string)) { break; } @@ -1149,8 +1089,7 @@ symbol = symbol->next; } - if ((symbol != 0) && (prevSymbol != 0)) - { + if ((symbol != 0) && (prevSymbol != 0)) { *prevSymbol = prev; } @@ -1159,8 +1098,7 @@ bool XMLIsType(TagPtr dict, enum xmltype type) { - if(!dict) - { + if(!dict) { return (type == kTagTypeNone); } return (dict->type == type); @@ -1174,17 +1112,12 @@ TagPtr XMLCastArray(TagPtr dict) { - if(!dict) - { + if(!dict) { return NULL; } - - if(dict->type == kTagTypeArray) - { + if(dict->type == kTagTypeArray) { return dict; - } - else - { + } else { return NULL; } } @@ -1201,17 +1134,12 @@ TagPtr XMLCastDict(TagPtr dict) { - if(!dict) - { + if(!dict) { return NULL; } - - if(dict->type == kTagTypeDict) - { + if(dict->type == kTagTypeDict) { return dict; - } - else - { + } else { return NULL; } } @@ -1223,13 +1151,11 @@ char* XMLCastString(TagPtr dict) { - if(!dict) - { + if(!dict) { return NULL; } - if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)) - { + if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)) { return dict->string; } @@ -1238,13 +1164,11 @@ char* XMLCastData(TagPtr dict, int* length) { - if(!dict) - { + if(!dict) { return NULL; } - if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey)) - { + if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey)) { *length = dict->offset; return dict->string; } @@ -1255,12 +1179,9 @@ long XMLCastStringOffset(TagPtr dict) { - if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))) - { + if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))) { return dict->offset; - } - else - { + } else { return -1; } } @@ -1272,16 +1193,12 @@ bool XMLCastBoolean(TagPtr dict) { - if(!dict) - { + if(!dict) { return false; } - - if(dict->type == kTagTypeTrue) - { + if(dict->type == kTagTypeTrue) { return true; } - return false; } @@ -1292,23 +1209,19 @@ int XMLCastInteger(TagPtr dict) { - if(!dict) - { + if(!dict) { //printf("XMLCastInteger: null dict\n"); return 0; } - if(dict->type == kTagTypeInteger) - { + if(dict->type == kTagTypeInteger) { return (int)(dict->string); } - return 0; } bool XMLAddTagToDictionary(TagPtr dict, char* key, TagPtr value) { - if (!dict || dict->type != kTagTypeDict) - { + if (!dict || dict->type != kTagTypeDict) { return false; } @@ -1316,14 +1229,12 @@ char* string; tmpTag = NewTag(); - if (tmpTag == 0) - { + if (tmpTag == 0) { return false; } string = NewSymbol(key); - if (string == 0) - { + if (string == 0) { XMLFreeTag(tmpTag); return false; } @@ -1335,15 +1246,13 @@ tmpTag->tagNext = 0; TagPtr tagList = dict->tag; - if(!tagList) - { + if(!tagList) { // First tag dict->tag = tmpTag; return true; } while(tagList && tagList->tagNext) tagList = tagList->tagNext; - if(tagList) - { + if(tagList) { tagList->tagNext = tmpTag; return true; } Index: trunk/i386/libsaio/ext2fs.c =================================================================== --- trunk/i386/libsaio/ext2fs.c (revision 2330) +++ trunk/i386/libsaio/ext2fs.c (revision 2331) @@ -22,17 +22,16 @@ { char * buf=malloc (EX2ProbeSize); str[0]=0; - if (!buf) + if (!buf) { return; + } Seek(ih, 0); Read(ih, (long)buf, EX2ProbeSize); - if (!EX2Probe (buf)) - { + if (!EX2Probe (buf)) { free (buf); return; } - if (OSReadLittleInt32 (buf+0x44c,0)<1) - { + if (OSReadLittleInt32 (buf+0x44c,0)<1) { free (buf); return; } @@ -44,17 +43,16 @@ long EX2GetUUID(CICell ih, char *uuidStr) { uint8_t *b, *buf=malloc (EX2ProbeSize); - if (!buf) + if (!buf) { return -1; + } Seek(ih, 0); Read(ih, (long)buf, EX2ProbeSize); - if (!EX2Probe (buf)) - { + if (!EX2Probe (buf)) { free (buf); return -1; } - if (OSReadLittleInt32 (buf+0x44c,0)<1) - { + if (OSReadLittleInt32 (buf+0x44c,0)<1) { free (buf); return -1; } Index: trunk/i386/libsaio/bootstruct.h =================================================================== --- trunk/i386/libsaio/bootstruct.h (revision 2330) +++ trunk/i386/libsaio/bootstruct.h (revision 2331) @@ -30,8 +30,8 @@ #include "bios.h" #include "device_tree.h" -/*! - Kernel boot args global also used by booter for its own data. +/* + * Kernel boot args global also used by booter for its own data. */ extern boot_args *bootArgs; extern boot_args_pre_lion *bootArgsPreLion; @@ -57,20 +57,21 @@ * PCI bus information. */ typedef struct _PCI_bus_info_t { - union { - struct { - unsigned char configMethod1 :1; - unsigned char configMethod2 :1; - unsigned char :2; - unsigned char specialCycle1 :1; - unsigned char specialCycle2 :1; - } s; - unsigned char d; - } u_bus; - unsigned char maxBusNum; - unsigned char majorVersion; - unsigned char minorVersion; - unsigned char BIOSPresent; + union { + struct { + unsigned char configMethod1 :1; + unsigned char configMethod2 :1; + unsigned char :2; + unsigned char specialCycle1 :1; + unsigned char specialCycle2 :1; + } s; + unsigned char d; + } u_bus; + + unsigned char maxBusNum; + unsigned char majorVersion; + unsigned char minorVersion; + unsigned char BIOSPresent; } PCI_bus_info_t; typedef struct { Index: trunk/i386/libsaio/device_tree.c =================================================================== --- trunk/i386/libsaio/device_tree.c (revision 2330) +++ trunk/i386/libsaio/device_tree.c (revision 2331) @@ -218,8 +218,8 @@ void DT__FreeNode(Node *node) { - node->next = freeNodes; - freeNodes = node; + node->next = freeNodes; + freeNodes = node; } //============================================================================== Index: trunk/i386/libsaio/hfs.c =================================================================== --- trunk/i386/libsaio/hfs.c (revision 2330) +++ trunk/i386/libsaio/hfs.c (revision 2331) @@ -294,9 +294,9 @@ long HFSReadFile(CICell ih, char * filePath, void *base, uint64_t offset, uint64_t length) { - char entry[512]; - char devStr[12]; - long dirID, result, flags; + char entry[512]; + char devStr[12]; + long dirID, result, flags; if (HFSInitPartition(ih) == -1) { Index: trunk/i386/libsaio/vbe.h =================================================================== --- trunk/i386/libsaio/vbe.h (revision 2330) +++ trunk/i386/libsaio/vbe.h (revision 2331) @@ -57,18 +57,18 @@ * Functions */ enum { - funcGetControllerInfo = 0x4F00, - funcGetModeInfo = 0x4F01, - funcSetMode = 0x4F02, - funcGetCurrentMode = 0x4F03, - funcSaveRestoreState = 0x4F04, - funcWindowControl = 0x4F05, - funcGetSetScanLineLength = 0x4F06, - funcGetSetDisplayStart = 0x4F07, - funcGetSetPaletteFormat = 0x4F08, - funcGetSetPaletteData = 0x4F09, - funcGetProtModeInterdace = 0x4F0A, - funcGetSetPixelClock = 0x4F0B + funcGetControllerInfo = 0x4F00, + funcGetModeInfo = 0x4F01, + funcSetMode = 0x4F02, + funcGetCurrentMode = 0x4F03, + funcSaveRestoreState = 0x4F04, + funcWindowControl = 0x4F05, + funcGetSetScanLineLength = 0x4F06, + funcGetSetDisplayStart = 0x4F07, + funcGetSetPaletteFormat = 0x4F08, + funcGetSetPaletteData = 0x4F09, + funcGetProtModeInterdace = 0x4F0A, + funcGetSetPixelClock = 0x4F0B }; enum { Index: trunk/i386/libsaio/acpi_patcher.c =================================================================== --- trunk/i386/libsaio/acpi_patcher.c (revision 2330) +++ trunk/i386/libsaio/acpi_patcher.c (revision 2331) @@ -512,44 +512,40 @@ minimum.CID = ((minimum.FID & 0x1F) << 1) >> cpu_dynamic_fsb; // Sanity check - if (maximum.CID < minimum.CID) - { + if (maximum.CID < minimum.CID) { DBG("P-States: Insane FID values!"); p_states_count = 0; - } - else - { + } else { // Finalize P-States // Find how many P-States machine supports p_states_count = maximum.CID - minimum.CID + 1; - if (p_states_count > 32) + if (p_states_count > 32) { p_states_count = 32; + } uint8_t vidstep; uint8_t i = 0, u, invalid = 0; vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1); - for (u = 0; u < p_states_count; u++) - { + for (u = 0; u < p_states_count; u++) { i = u - invalid; p_states[i].CID = maximum.CID - u; p_states[i].FID = (p_states[i].CID >> 1); - if (p_states[i].FID < 0x6) - { - if (cpu_dynamic_fsb) + if (p_states[i].FID < 0x6) { + if (cpu_dynamic_fsb) { p_states[i].FID = (p_states[i].FID << 1) | 0x80; - } - else if (cpu_noninteger_bus_ratio) - { + } + } else if (cpu_noninteger_bus_ratio) { p_states[i].FID = p_states[i].FID | (0x40 * (p_states[i].CID & 0x1)); } - if (i && p_states[i].FID == p_states[i-1].FID) + if (i && p_states[i].FID == p_states[i-1].FID) { invalid++; + } p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2; @@ -592,9 +588,7 @@ (Platform.CPU.Model == CPU_MODEL_HASWELL_ULT) || (Platform.CPU.Model == CPU_MODEL_CRYSTALWELL)) { maximum.Control = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0xff; - } - else - { + } else { maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff; } @@ -603,25 +597,21 @@ verbose("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control); // Sanity check - if (maximum.Control < minimum.Control) - { + if (maximum.Control < minimum.Control) { DBG("Insane control values!"); p_states_count = 0; - } - else - { + } else { uint8_t i; p_states_count = 0; - for (i = maximum.Control; i >= minimum.Control; i--) - { + for (i = maximum.Control; i >= minimum.Control; i--) { p_states[p_states_count].Control = i; p_states[p_states_count].CID = p_states[p_states_count].Control << 1; p_states[p_states_count].Frequency = (Platform.CPU.FSBFrequency / 1000000) * i; p_states_count++; } } - + break; } default: @@ -632,8 +622,7 @@ } // Generating SSDT - if (p_states_count > 0) - { + if (p_states_count > 0) { int i; AML_CHUNK* root = aml_create_node(NULL); @@ -643,8 +632,7 @@ AML_CHUNK* name = aml_add_name(scop, "PSS_"); AML_CHUNK* pack = aml_add_package(name); - for (i = 0; i < p_states_count; i++) - { + for (i = 0; i < p_states_count; i++) { AML_CHUNK* pstt = aml_add_package(pack); aml_add_dword(pstt, p_states[i].Frequency); @@ -656,8 +644,7 @@ } // Add aliaces - for (i = 0; i < acpi_cpu_count; i++) - { + for (i = 0; i < acpi_cpu_count; i++) { char name[9]; sprintf(name, "_PR_%c%c%c%c", acpi_cpu_name[i][0], acpi_cpu_name[i][1], acpi_cpu_name[i][2], acpi_cpu_name[i][3]); @@ -683,9 +670,7 @@ return ssdt; } - } - else - { + } else { verbose ("ACPI CPUs not found: P-States not generated !!!\n"); } @@ -703,27 +688,20 @@ const char * value; // Restart Fix - if (Platform.CPU.Vendor == 0x756E6547) - { /* Intel */ + if (Platform.CPU.Vendor == 0x756E6547) { /* Intel */ fix_restart = true; fix_restart_ps2 = false; - if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2) - { + if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2) { fix_restart = true; - } - else - { + } else { getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig); } - } - else - { + } else { verbose ("Not an Intel platform: Restart Fix not applied !!!\n"); fix_restart = false; } - if (fix_restart) - { + if (fix_restart) { fadt_rev2_needed = true; } @@ -734,43 +712,31 @@ memcpy(fadt_mod, fadt, fadt->Length); fadt_mod->Length = 0x84; fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions) - } - else - { + } else { fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length); memcpy(fadt_mod, fadt, fadt->Length); } // Determine system type / PM_Model if ( (value=getStringForKey(kSystemType, &bootInfo->chameleonConfig))!=NULL) { - if (Platform.Type > 6) - { - if(fadt_mod->PM_Profile<=6) - { + if (Platform.Type > 6) { + if(fadt_mod->PM_Profile<=6) { Platform.Type = fadt_mod->PM_Profile; // get the fadt if correct - } - else - { + } else { Platform.Type = 1; /* Set a fixed value (Desktop) */ } verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type); - } - else - { + } else { Platform.Type = (unsigned char) strtoul(value, NULL, 10); } } // Set PM_Profile from System-type if only user wanted this value to be forced - if (fadt_mod->PM_Profile != Platform.Type) - { - if (value) - { + if (fadt_mod->PM_Profile != Platform.Type) { + if (value) { // user has overriden the SystemType so take care of it in FACP verbose("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform.Type); fadt_mod->PM_Profile = Platform.Type; - } - else - { + } else { // PM_Profile has a different value and no override has been set, so reflect the user value to ioregs Platform.Type = fadt_mod->PM_Profile <= 6 ? fadt_mod->PM_Profile : 1; } @@ -780,10 +746,8 @@ setupSystemType(); // Patch FADT to fix restart - if (fix_restart) - { - if (fix_restart_ps2) - { + if (fix_restart) { + if (fix_restart_ps2) { fadt_mod->Flags|= 0x400; fadt_mod->Reset_SpaceID = 0x01; // System I/O fadt_mod->Reset_BitWidth = 0x08; // 1 byte @@ -792,9 +756,7 @@ fadt_mod->Reset_Address = 0x64; // Address of the register fadt_mod->Reset_Value = 0xfe; // Value to write to reset the system msglog("FADT: PS2 Restart Fix applied!\n"); - } - else - { + } else { fadt_mod->Flags|= 0x400; fadt_mod->Reset_SpaceID = 0x01; // System I/O fadt_mod->Reset_BitWidth = 0x08; // 1 byte @@ -808,13 +770,11 @@ } // Patch DSDT Address if we have loaded DSDT.aml - if(new_dsdt) - { + if(new_dsdt) { DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT); fadt_mod->DSDT=(uint32_t)new_dsdt; - if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length) - { + if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length) { fadt_mod->X_DSDT=(uint32_t)new_dsdt; } @@ -858,12 +818,9 @@ acpi_cpu_count = 0; /* Try using the file specified with the DSDT option */ - if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig)) - { + if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig)) { snprintf(dirSpec, sizeof(dirSpec), filename); - } - else - { + } else { sprintf(dirSpec, "DSDT.aml"); //verbose("dirSpec, DSDT.aml"); } @@ -893,18 +850,14 @@ { int i; - for (i = 0; i < 30; i++) - { + for (i = 0; i < 30; i++) { char filename[512]; sprintf(filename, i > 0?"SSDT-%d.aml":"SSDT.aml", i); - if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) ) - { + if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) ) { ssdt_count++; - } - else - { + } else { break; } } @@ -918,15 +871,11 @@ // Find original rsdp rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable()); - if (!rsdp) - { + if (!rsdp) { DBG("No ACPI version %d found. Ignoring\n", version+1); - if (version) - { + if (version) { addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20"); - } - else - { + } else { addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI"); } continue; @@ -947,8 +896,7 @@ DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length); - if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000) - { + if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000) { uint32_t *rsdt_entries; int rsdt_entries_num; int dropoffset=0, i; @@ -959,11 +907,9 @@ rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod; rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4; rsdt_entries=(uint32_t *)(rsdt_mod+1); - for (i=0;iLength); - if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000) - { + if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000) { printf("FADT incorrect. Not modified\n"); continue; } @@ -1006,16 +947,14 @@ rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod; // Generate _CST SSDT - if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) - { + if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) { DBG("C-States generated\n"); generate_cstates = false; // Generate SSDT only once! ssdt_count++; } // Generating _PSS SSDT - if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) - { + if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) { DBG("P-States generated\n"); generate_pstates = false; // Generate SSDT only once! ssdt_count++; @@ -1036,12 +975,12 @@ rsdt_entries=(uint32_t *)(rsdt_mod+1); // Mozodojo: Insert additional SSDTs into RSDT - if(ssdt_count>0) - { + if(ssdt_count>0) { int j; - for (j=0; jChecksum=256-checksum8(rsdt_mod,rsdt_mod->Length); DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod); - } - else - { + } else { rsdp_mod->RsdtAddress=0; printf("RSDT not found or incorrect\n"); } - if (version) - { + if (version) { struct acpi_2_xsdt *xsdt, *xsdt_mod; // FIXME: handle 64-bit address correctly @@ -1070,8 +1006,7 @@ xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress); DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress, xsdt->Length); - if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000) - { + if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000) { uint64_t *xsdt_entries; int xsdt_entries_num, i; int dropoffset=0; @@ -1083,27 +1018,22 @@ rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod; xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8; xsdt_entries=(uint64_t *)(xsdt_mod+1); - for (i=0;i>32),fadt, fadt->Length); - if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000) - { + if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000) { verbose("FADT incorrect or after 4GB. Dropping XSDT\n"); goto drop_xsdt; } @@ -1131,15 +1059,13 @@ DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]); // Generate _CST SSDT - if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) - { + if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) { generate_cstates = false; // Generate SSDT only once! ssdt_count++; } // Generating _PSS SSDT - if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) - { + if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) { generate_pstates = false; // Generate SSDT only once! ssdt_count++; } @@ -1161,23 +1087,20 @@ xsdt_entries=(uint64_t *)(xsdt_mod+1); // Mozodojo: Insert additional SSDTs into XSDT - if(ssdt_count > 0) - { + if(ssdt_count > 0) { int j; - for (j=0; jChecksum=0; xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length); - } - else - { + } else { drop_xsdt: DBG("About to drop XSDT\n"); @@ -1200,26 +1123,21 @@ DBG("New checksum %d\n", rsdp_mod->Checksum); - if (version) - { + if (version) { DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum); rsdp_mod->ExtendedChecksum=0; rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length); DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum); - } //verbose("Patched ACPI version %d DSDT\n", version+1); - if (version) - { + if (version) { /* XXX aserebln why uint32 cast if pointer is uint64 ? */ acpi20_p = (uint32_t)rsdp_mod; addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20"); - } - else - { + } else { /* XXX aserebln why uint32 cast if pointer is uint64 ? */ acpi10_p = (uint32_t)rsdp_mod; addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI"); Index: trunk/i386/libsaio/hfs_compare.c =================================================================== --- trunk/i386/libsaio/hfs_compare.c (revision 2330) +++ trunk/i386/libsaio/hfs_compare.c (revision 2331) @@ -123,14 +123,14 @@ if (aSortWord < bSortWord) return -1; } - + /* * If characters match exactly, then go on to next character * immediately without doing any extra work. */ } - /* if you got to here, then return bestGuess */ + /* If you got to here, then return bestGuess */ return bestGuess; } Index: trunk/i386/libsaio/spd.c =================================================================== --- trunk/i386/libsaio/spd.c (revision 2330) +++ trunk/i386/libsaio/spd.c (revision 2331) @@ -30,14 +30,14 @@ "RAM", /* 00h Undefined */ "FPM", /* 01h FPM */ "EDO", /* 02h EDO */ - "", /* 03h PIPELINE NIBBLE */ + "", /* 03h PIPELINE NIBBLE */ "SDRAM", /* 04h SDRAM */ - "", /* 05h MULTIPLEXED ROM */ + "", /* 05h MULTIPLEXED ROM */ "DDR SGRAM", /* 06h SGRAM DDR */ "DDR SDRAM", /* 07h SDRAM DDR */ "DDR2 SDRAM", /* 08h SDRAM DDR 2 */ - "", /* 09h Undefined */ - "", /* 0Ah Undefined */ + "", /* 09h Undefined */ + "", /* 0Ah Undefined */ "DDR3 SDRAM" /* 0Bh SDRAM DDR 3 */ }; @@ -69,19 +69,6 @@ #define SMBHSTDAT 5 #define SBMBLKDAT 7 -int spd_indexes[] = { - SPD_MEMORY_TYPE, - SPD_DDR3_MEMORY_BANK, - SPD_DDR3_MEMORY_CODE, - SPD_NUM_ROWS, - SPD_NUM_COLUMNS, - SPD_NUM_DIMM_BANKS, - SPD_NUM_BANKS_PER_SDRAM, - 4,7,8,9,12,64, /* TODO: give names to these values */ - 95,96,97,98, 122,123,124,125 /* UIS */ -}; -#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int)) - /** Read one byte from the intel i2c, used for reading SPD on intel chipsets only. */ unsigned char smb_read_byte_intel(uint32_t base, uint8_t adr, uint8_t cmd) @@ -124,6 +111,18 @@ /* SPD i2c read optimization: prefetch only what we need, read non prefetcheable bytes on the fly */ #define READ_SPD(spd, base, slot, x) spd[x] = smb_read_byte_intel(base, 0x50 + slot, x) +int spd_indexes[] = { + SPD_MEMORY_TYPE, + SPD_DDR3_MEMORY_BANK, + SPD_DDR3_MEMORY_CODE, + SPD_NUM_ROWS, + SPD_NUM_COLUMNS, + SPD_NUM_DIMM_BANKS, + SPD_NUM_BANKS_PER_SDRAM, + 4,7,8,9,12,64, /* TODO: give names to these values */ + 95,96,97,98, 122,123,124,125 /* UIS */ +}; +#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int)) /** Read from spd *used* values only*/ static void init_spd(char * spd, uint32_t base, int slot) @@ -147,42 +146,31 @@ { // DDR3 bank = (spd[SPD_DDR3_MEMORY_BANK] & 0x07f); // constructors like Patriot use b7=1 code = spd[SPD_DDR3_MEMORY_CODE]; - for (i=0; i < VEN_MAP_SIZE; i++) - { - if (bank==vendorMap[i].bank && code==vendorMap[i].code) - { + for (i=0; i < VEN_MAP_SIZE; i++) { + if (bank==vendorMap[i].bank && code==vendorMap[i].code) { return vendorMap[i].name; } } - } - else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) - { - if(spd[64]==0x7f) - { - for (i=64; i<72 && spd[i]==0x7f;i++) - { + } else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) { + if(spd[64]==0x7f) { + for (i=64; i<72 && spd[i]==0x7f;i++) { bank++; READ_SPD(spd, base, slot_num, (uint8_t)(i+1)); // prefetch next spd byte to read for next loop } READ_SPD(spd, base, slot_num,(uint8_t)i); code = spd[i]; - } - else - { + } else { code = spd[64]; bank = 0; } - for (i=0; i < VEN_MAP_SIZE; i++) - { - if (bank==vendorMap[i].bank && code==vendorMap[i].code) - { + for (i=0; i < VEN_MAP_SIZE; i++) { + if (bank==vendorMap[i].bank && code==vendorMap[i].code) { return vendorMap[i].name; } } } /* OK there is no vendor id here lets try to match the partnum if it exists */ - if (strstr(slot->PartNo,"GU332") == slot->PartNo) // Unifosa fingerprint - { + if (strstr(slot->PartNo,"GU332") == slot->PartNo) { // Unifosa fingerprint return "Unifosa"; } return "NoName"; @@ -191,10 +179,8 @@ /* Get Default Memory Module Speed (no overclocking handled) */ int getDDRspeedMhz(const char * spd) { - if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) - { - switch(spd[12]) - { + if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) { + switch(spd[12]) { case 0x0f: return 1066; case 0x0c: @@ -205,11 +191,8 @@ default: return 800; } - } - else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) - { - switch(spd[9]) - { + } else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) { + switch(spd[9]) { case 0x50: return 400; case 0x3d: @@ -233,16 +216,16 @@ const char *getDDRSerial(const char* spd) { static char asciiSerial[16]; - + if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) // DDR3 { - sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125)); + snprintf(asciiSerial, sizeof(asciiSerial), "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125)); } else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) // DDR2 or DDR { - sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98)); + snprintf(asciiSerial, sizeof(asciiSerial), "%X%X%X%X%X%X%X%X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98)); } else { - sprintf(asciiSerial, "0000000000000000"); + sprintf(asciiSerial, "000000000000000"); } return strdup(asciiSerial); @@ -254,33 +237,26 @@ static char asciiPartNo[32]; int i, start=0, index = 0; - if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) - { + if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) { start = 128; - } - else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) - { + } else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) { start = 73; } // Check that the spd part name is zero terminated and that it is ascii: bzero(asciiPartNo, sizeof(asciiPartNo)); char c; - for (i=start; i < start + sizeof(asciiPartNo); i++) - { + for (i=start; i < start + sizeof(asciiPartNo); i++) { READ_SPD(spd, base, slot, i); // only read once the corresponding model part (ddr3 or ddr2) c = spd[i]; - if (isalpha(c) || isdigit(c) || ispunct(c)) - { + if (isalpha(c) || isdigit(c) || ispunct(c)) { // It seems that System Profiler likes only letters and digits... asciiPartNo[index++] = c; - } - else if (!isascii(c)) - { + } else if (!isascii(c)) { break; } } - + return strdup(asciiPartNo); } @@ -288,10 +264,9 @@ /* Read from smbus the SPD content and interpret it for detecting memory attributes */ -static void read_smb_intel(pci_dt_t *smbus_dev) -{ - uint16_t speed; - uint8_t i, spd_size, spd_type; +static void read_smb_intel(pci_dt_t *smbus_dev) { + int i, speed; + uint8_t spd_size, spd_type; uint32_t base, mmio, hostc; // bool dump = false; RamSlotInfo_t* slot; @@ -313,18 +288,14 @@ char spdbuf[MAX_SPD_SIZE]; // Search MAX_RAM_SLOTS slots - for (i = 0; i < MAX_RAM_SLOTS; i++) - { - // ---- + for (i = 0; i < MAX_RAM_SLOTS; i++) { slot = &Platform.RAM.DIMM[i]; spd_size = smb_read_byte_intel(base, 0x50 + i, 0); - DBG("SPD[0] (size): 0x%02x @0x%x\n", spd_size, 0x50 + i); + DBG("SPD[0] (size): %d @0x%x\n", spd_size, 0x50 + i); // Check spd is present - if (spd_size && (spd_size != 0xff)) - { + if (spd_size && (spd_size != 0xff)) { slot->spd = spdbuf; - // ----- slot->InUse = true; bzero(slot->spd, spd_size); @@ -334,10 +305,9 @@ //for (x = 0; x < spd_size; x++) slot->spd[x] = smb_read_byte_intel(base, 0x50 + i, x); init_spd(slot->spd, base, i); - switch (slot->spd[SPD_MEMORY_TYPE]) - { + switch (slot->spd[SPD_MEMORY_TYPE]) { case SPD_MEMORY_TYPE_SDRAM_DDR: - + slot->ModuleSize = (((1 << ((slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17)) * ((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * @@ -346,8 +316,8 @@ case SPD_MEMORY_TYPE_SDRAM_DDR2: - slot->ModuleSize = ((1 << ((slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17)) * - ((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * slot->spd[SPD_NUM_BANKS_PER_SDRAM]); + slot->ModuleSize = ((1 << ((slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17)) * + ((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * slot->spd[SPD_NUM_BANKS_PER_SDRAM]); break; case SPD_MEMORY_TYPE_SDRAM_DDR3: @@ -361,8 +331,7 @@ spd_type = (slot->spd[SPD_MEMORY_TYPE] < ((char) 12) ? slot->spd[SPD_MEMORY_TYPE] : 0); slot->Type = spd_mem_to_smbios[spd_type]; - if (slot->Type == UNKNOWN_MEM_TYPE) - { + if (slot->Type == UNKNOWN_MEM_TYPE) { continue; } slot->PartNo = getDDRPartNum(slot->spd, base, i); @@ -371,19 +340,16 @@ // determine spd speed speed = getDDRspeedMhz(slot->spd); - if (slot->FrequencyFrequency < speed) { slot->Frequency = speed; } - + // pci memory controller if available, is more reliable - if (Platform.RAM.Frequency > 0) - { + if (Platform.RAM.Frequency > 0) { uint32_t freq = (uint32_t)Platform.RAM.Frequency / 500000; // now round off special cases uint32_t fmod100 = freq %100; - switch(fmod100) - { + switch(fmod100) { case 1: freq--; break; case 32: freq++; break; case 65: freq++; break; @@ -394,7 +360,7 @@ } verbose("Slot: %d Type %d %dMB (%s) %dMHz Vendor=%s\n PartNo=%s SerialNo=%s\n", - i, + i, (int)slot->Type, slot->ModuleSize, spd_memory_types[spd_type], @@ -407,7 +373,7 @@ // laptops sometimes show slot 0 and 2 with slot 1 empty when only 2 slots are presents so: Platform.DMI.DIMM[i]= - (uint32_t)((i>0 && Platform.RAM.DIMM[1].InUse==false && !fullBanks && Platform.DMI.CntMemorySlots == 2) ? + (uint32_t)((i>0 && Platform.RAM.DIMM[1].InUse==false && fullBanks && Platform.DMI.CntMemorySlots == 2) ? mapping[i] : i); // for laptops case, mapping setup would need to be more generic than this slot->spd = NULL; @@ -415,7 +381,6 @@ } static struct smbus_controllers_t smbus_controllers[] = { -// Info from here: http://cateee.net/lkddb/web-lkddb/I2C_I801.html {0x8086, 0x1C22, "6 Series", read_smb_intel }, {0x8086, 0x1D22, "C600/X79 Series", read_smb_intel }, @@ -452,18 +417,15 @@ pci_dt_t *current = pci_dt; int i; - while (current) - { + while (current) { #if 0 printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n", current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func, current->class_id, current->vendor_id, current->device_id, get_pci_dev_path(current)); #endif - for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) - { - if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device) - { + for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) { + if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device) { smbus_controllers[i].read_smb(current); // read smb return true; } Index: trunk/i386/libsaio/pci_root.c =================================================================== --- trunk/i386/libsaio/pci_root.c (revision 2330) +++ trunk/i386/libsaio/pci_root.c (revision 2331) @@ -50,7 +50,7 @@ void *new_dsdt; const char *val; int len,fsize; - const char * dsdt_filename=NULL; + const char * dsdt_filename = NULL; extern int search_and_get_acpi_fd(const char *, const char **); if (rootuid < 10) return rootuid; @@ -75,7 +75,6 @@ goto out; } - // Try using the file specified with the DSDT option if (getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->chameleonConfig)) { Index: trunk/i386/libsaio/aml_generator.c =================================================================== --- trunk/i386/libsaio/aml_generator.c (revision 2330) +++ trunk/i386/libsaio/aml_generator.c (revision 2331) @@ -34,7 +34,7 @@ default: break; } - + if (!parent->First) { parent->First = node; } @@ -42,19 +42,19 @@ parent->Last->Next = node; } parent->Last = node; - + return true; } - + return false; } AML_CHUNK* aml_create_node(AML_CHUNK* parent) { AML_CHUNK* node = (AML_CHUNK*)malloc(sizeof(AML_CHUNK)); - + aml_add_to_parent(parent, node); - + return node; } @@ -62,11 +62,11 @@ { // Delete child nodes AML_CHUNK* child = node->First; - + while (child) { AML_CHUNK* next = child->Next; - + if (child->Buffer) { free(child->Buffer); } @@ -74,7 +74,7 @@ child = next; } - + // Free node if (node->Buffer) { free(node->Buffer); @@ -86,21 +86,21 @@ AML_CHUNK* aml_add_buffer(AML_CHUNK* parent, char* buffer, uint32_t size) { AML_CHUNK* node = aml_create_node(parent); - + if (node) { node->Type = AML_CHUNK_NONE; node->Length = (uint16_t)size; node->Buffer = malloc(node->Length); memcpy(node->Buffer, buffer, node->Length); } - + return node; } AML_CHUNK* aml_add_byte(AML_CHUNK* parent, uint8_t value) { AML_CHUNK* node = aml_create_node(parent); - + if (node) { node->Type = AML_CHUNK_BYTE; node->Length = 1; @@ -113,7 +113,7 @@ AML_CHUNK* aml_add_word(AML_CHUNK* parent, uint16_t value) { AML_CHUNK* node = aml_create_node(parent); - + if (node) { node->Type = AML_CHUNK_WORD; node->Length = 2; @@ -127,7 +127,7 @@ AML_CHUNK* aml_add_dword(AML_CHUNK* parent, uint32_t value) { AML_CHUNK* node = aml_create_node(parent); - + if (node) { node->Type = AML_CHUNK_DWORD; node->Length = 4; @@ -143,7 +143,7 @@ AML_CHUNK* aml_add_qword(AML_CHUNK* parent, uint64_t value) { AML_CHUNK* node = aml_create_node(parent); - + if (node) { node->Type = AML_CHUNK_QWORD; node->Length = 8; @@ -199,7 +199,7 @@ offset += 4 + root; return (uint32_t)offset; } - + if (count == 2) { node->Length = 2 + 8; node->Buffer = malloc(node->Length+4); @@ -209,7 +209,7 @@ offset += 8; return (uint32_t)offset; } - + node->Length = (uint16_t)(3 + (count << 2)); node->Buffer = malloc(node->Length+4); node->Buffer[offset++] = 0x5c; // Root Char @@ -223,7 +223,7 @@ AML_CHUNK* aml_add_scope(AML_CHUNK* parent, char* name) { AML_CHUNK* node = aml_create_node(parent); - + if (node) { node->Type = AML_CHUNK_SCOPE; @@ -235,7 +235,7 @@ AML_CHUNK* aml_add_name(AML_CHUNK* parent, char* name) { AML_CHUNK* node = aml_create_node(parent); - + if (node) { node->Type = AML_CHUNK_NAME; @@ -420,7 +420,7 @@ return 2; else if (size + 3 <= 0xfffff) /* Encode in 4 bits and 2 bytes */ return 3; - + return 4; /* Encode 0xfffffff in 4 bits and 2 bytes */ } @@ -430,7 +430,7 @@ // Calculate child nodes size AML_CHUNK* child = node->First; uint8_t child_count = 0; - + node->Size = 0; while (child) { child_count++; @@ -439,7 +439,7 @@ child = child->Next; } - + switch (node->Type) { case AML_CHUNK_NONE: case AML_STORE_OP: @@ -618,13 +618,13 @@ child = child->Next; } - + if (offset - old != node->Size) { verbose("Node size incorrect: type=0x%x size=%x offset=%x\n", node->Type, node->Size, (offset - old)); } } - + return offset; } @@ -652,9 +652,9 @@ uint32_t get_size(uint8_t* Buffer, uint32_t adr) { uint32_t temp; - + temp = Buffer[adr] & 0xF0; //keep bits 0x30 to check if this is valid size field - + if(temp <= 0x30) { // 0 temp = Buffer[adr]; } else if(temp == 0x40) { // 4 Index: trunk/i386/libsaio/device_inject.c =================================================================== --- trunk/i386/libsaio/device_inject.c (revision 2330) +++ trunk/i386/libsaio/device_inject.c (revision 2331) @@ -25,7 +25,7 @@ uint32_t devices_number = 1; uint32_t builtin_set = 0; -struct DevPropString *string = 0; +DevPropString *string = 0; uint8_t *stringdata = 0; uint32_t stringlength = 0; @@ -68,7 +68,7 @@ } } -struct DevPropString *devprop_create_string(void) +DevPropString *devprop_create_string(void) { string = (struct DevPropString*)malloc(sizeof(struct DevPropString)); @@ -82,11 +82,11 @@ return string; } -struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path) +DevPropDevice *devprop_add_device(DevPropString *string, char *path) { - struct DevPropDevice *device = NULL; - static const char pciroot_string[] = "PciRoot(0x"; - static const char pci_device_string[] = "Pci(0x"; + DevPropDevice *device = NULL; + const char pciroot_string[] = "PciRoot(0x"; + const char pci_device_string[] = "Pci(0x"; if (string == NULL || path == NULL) { printf("ERROR null device path\n"); @@ -97,13 +97,12 @@ printf("ERROR parsing device path\n"); return NULL; } - - if (!(device = malloc(sizeof(struct DevPropDevice)))) { + if (!(device = malloc(sizeof(DevPropDevice)))) { printf("ERROR malloc failed\n"); return NULL; } - memset(device, 0, sizeof(struct DevPropDevice)); + memset(device, 0, sizeof(DevPropDevice)); device->acpi_dev_path._UID = getPciRootUID(); int numpaths = 0; @@ -184,13 +183,13 @@ /* FIXME: probably needs bounds checking, as well as error handling in event of malloc failure */ string->length += device->length; - string->entries[string->numentries++] = (struct DevPropDevice*)malloc(sizeof(device)); + string->entries[string->numentries++] = (DevPropDevice*)malloc(sizeof(device)); string->entries[string->numentries-1] = device; return device; } -int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len) +int devprop_add_value(DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len) { if(!nm || !vl || !len) { @@ -199,8 +198,7 @@ uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2); uint8_t *data = (uint8_t*)malloc(length); { - if(!data) - { + if(!data) { return 0; } @@ -211,8 +209,7 @@ off += 4; uint32_t i=0, l = strlen(nm); - for(i = 0 ; i < l ; i++, off += 2) - { + for(i = 0 ; i < l ; i++, off += 2) { data[off] = *nm++; } @@ -230,14 +227,11 @@ uint32_t offset = device->length - (24 + (6 * device->num_pci_devpaths)); uint8_t *newdata = (uint8_t*)malloc((length + offset)); - if(!newdata) - { + if(!newdata) { return 0; } - if(device->data) - { - if(offset > 1) - { + if(device->data) { + if(offset > 1) { memcpy(newdata, device->data, offset); } } @@ -248,12 +242,9 @@ device->string->length += length; device->numentries++; - if(!device->data) - { + if(!device->data) { device->data = (uint8_t*)malloc(sizeof(uint8_t)); - } - else - { + } else { free(device->data); } @@ -263,7 +254,7 @@ return 1; } -char *devprop_generate_string(struct DevPropString *string) +char *devprop_generate_string(DevPropString *string) { char *buffer = (char*)malloc(string->length * 2); char *ptr = buffer; @@ -317,11 +308,10 @@ return ptr; } -void devprop_free_string(struct DevPropString *string) +void devprop_free_string(DevPropString *string) { - if(!string) - { + if(!string) { return; } @@ -384,7 +374,7 @@ /* a fine place for this code */ -int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id) +int devprop_add_network_template(DevPropDevice *device, uint16_t vendor_id) { if(!device) return 0; @@ -403,7 +393,7 @@ void set_eth_builtin(pci_dt_t *eth_dev) { char *devicepath = get_pci_dev_path(eth_dev); - struct DevPropDevice *device = NULL; + DevPropDevice *device = NULL; verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath); Index: trunk/i386/libsaio/device_inject.h =================================================================== --- trunk/i386/libsaio/device_inject.h (revision 2330) +++ trunk/i386/libsaio/device_inject.h (revision 2331) @@ -53,6 +53,8 @@ // ------------------------ }; +typedef struct DevPropDevice DevPropDevice; + struct DevPropString { uint32_t length; uint32_t WHAT2; // 0x01000000 ? @@ -61,16 +63,20 @@ struct DevPropDevice **entries; }; -extern struct DevPropString *string; +typedef struct DevPropString DevPropString; + +extern DevPropString *string; extern uint8_t *stringdata; extern uint32_t stringlength; -struct DevPropString *devprop_create_string(void); -struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path); + +DevPropString *devprop_create_string(void); +DevPropDevice *devprop_add_device(DevPropString *string, char *path); char *efi_inject_get_devprop_string(uint32_t *len); -int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len); -char *devprop_generate_string(struct DevPropString *string); -void devprop_free_string(struct DevPropString *string); +int devprop_add_value(DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len); +char *devprop_generate_string(DevPropString *string); +void devprop_free_string(DevPropString *string); -int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id); +int devprop_add_network_template(DevPropDevice *device, uint16_t vendor_id); int hex2bin(const char *hex, uint8_t *bin, int len); + #endif /* !__LIBSAIO_DEVICE_INJECT_H */ Index: trunk/i386/libsaio/dram_controllers.c =================================================================== --- trunk/i386/libsaio/dram_controllers.c (revision 2330) +++ trunk/i386/libsaio/dram_controllers.c (revision 2331) @@ -40,8 +40,7 @@ // Activate MMR I/O dev0 = pci_config_read32(dram_dev->dev.addr, 0x48); - if (!(dev0 & 0x1)) - { + if (!(dev0 & 0x1)) { pci_config_write8(dram_dev->dev.addr, 0x48, (dev0 | 1)); } } @@ -57,15 +56,13 @@ // Nehalem supports Scrubbing // First, locate the PCI bus where the MCH is located - for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) - { + for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) { vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), PCI_VENDOR_ID); did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), PCI_DEVICE_ID); vid &= 0xFFFF; did &= 0xFF00; - if(vid == 0x8086 && did >= 0x2C00) - { + if(vid == 0x8086 && did >= 0x2C00) { nhm_bus = possible_nhm_bus[i]; } } @@ -91,8 +88,7 @@ mch_ratio = 100000; - switch (mch_cfg & 7) - { + switch (mch_cfg & 7) { case 0: mch_fsb = 1066; break; case 1: mch_fsb = 533; break; default: @@ -104,11 +100,9 @@ DBG("mch_fsb %d\n", mch_fsb); - switch (mch_fsb) - { + switch (mch_fsb) { case 533: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 1: mch_ratio = 200000; break; case 2: mch_ratio = 250000; break; case 3: mch_ratio = 300000; break; @@ -117,8 +111,7 @@ default: case 800: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 0: mch_ratio = 100000; break; case 1: mch_ratio = 125000; break; case 2: mch_ratio = 166667; break; // 1.666666667 @@ -129,8 +122,7 @@ break; case 1066: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 1: mch_ratio = 100000; break; case 2: mch_ratio = 125000; break; case 3: mch_ratio = 150000; break; @@ -140,8 +132,7 @@ break; case 1333: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 2: mch_ratio = 100000; break; case 3: mch_ratio = 120000; break; case 4: mch_ratio = 160000; break; @@ -184,8 +175,7 @@ mch_ratio = 100000; - switch (mch_cfg & 7) - { + switch (mch_cfg & 7) { case 1: mch_fsb = 533; break; default: case 2: mch_fsb = 800; break; @@ -193,11 +183,9 @@ case 6: mch_fsb = 1066; break; } - switch (mch_fsb) - { + switch (mch_fsb) { case 533: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 1: mch_ratio = 125000; break; case 2: mch_ratio = 150000; break; case 3: mch_ratio = 200000; break; @@ -205,8 +193,7 @@ break; case 667: - switch ((mch_cfg >> 4)& 7) - { + switch ((mch_cfg >> 4)& 7) { case 1: mch_ratio = 100000; break; case 2: mch_ratio = 120000; break; case 3: mch_ratio = 160000; break; @@ -217,8 +204,7 @@ default: case 800: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 1: mch_ratio = 83333; break; // 0.833333333 case 2: mch_ratio = 100000; break; case 3: mch_ratio = 133333; break; // 1.333333333 @@ -227,8 +213,7 @@ } break; case 1066: - switch ((mch_cfg >> 4)&7) - { + switch ((mch_cfg >> 4)&7) { case 5: mch_ratio = 150000; break; case 6: mch_ratio = 200000; break; } @@ -569,10 +554,8 @@ void scan_dram_controller(pci_dt_t *dram_dev) { int i; - for(i = 1; i < sizeof(dram_controllers) / sizeof(dram_controllers[0]); i++) - { - if ((dram_controllers[i].vendor == dram_dev->vendor_id) && (dram_controllers[i].device == dram_dev->device_id)) - { + for(i = 1; i < sizeof(dram_controllers) / sizeof(dram_controllers[0]); i++) { + if ((dram_controllers[i].vendor == dram_dev->vendor_id) && (dram_controllers[i].device == dram_dev->device_id)) { verbose("%s%s DRAM Controller [%4x:%4x] at %02x:%02x.%x\n", (dram_dev->vendor_id == 0x8086) ? "Intel Corporation " : "" , dram_controllers[i].name, dram_dev->vendor_id, dram_dev->device_id, Index: trunk/i386/libsaio/nvidia.c =================================================================== --- trunk/i386/libsaio/nvidia.c (revision 2330) +++ trunk/i386/libsaio/nvidia.c (revision 2331) @@ -1458,45 +1458,35 @@ uint8_t numentries = 0; uint8_t recordlength = 0; - if (dcbtable_version >= 0x20) - { + if (dcbtable_version >= 0x20) { uint32_t sig; - if (dcbtable_version >= 0x30) - { + if (dcbtable_version >= 0x30) { headerlength = dcbtable[1]; numentries = dcbtable[2]; recordlength = dcbtable[3]; sig = READ_LE_INT(dcbtable, 6); - } - else - { + } else { sig = READ_LE_INT(dcbtable, 4); headerlength = 8; } - if (sig != 0x4edcbdcb) - { + if (sig != 0x4edcbdcb) { printf("Bad display config block signature (0x%8x)\n", sig); //Azi: issue #48 return PATCH_ROM_FAILED; } - } - else if (dcbtable_version >= 0x14) /* some NV15/16, and NV11+ */ - { + } else if (dcbtable_version >= 0x14) { /* some NV15/16, and NV11+ */ char sig[8] = { 0 }; strncpy(sig, (char *)&dcbtable[-7], 7); recordlength = 10; - if (strcmp(sig, "DEV_REC")) - { + if (strcmp(sig, "DEV_REC")) { printf("Bad Display Configuration Block signature (%s)\n", sig); return PATCH_ROM_FAILED; } - } - else - { + } else { printf("ERROR: dcbtable_version is 0x%X\n", dcbtable_version); return PATCH_ROM_FAILED; } @@ -1507,29 +1497,24 @@ uint8_t num_outputs = 0, i = 0; - struct dcbentry - { + struct dcbentry { uint8_t type; uint8_t index; uint8_t *heads; } entries[numentries]; - for (i = 0; i < numentries; i++) - { + for (i = 0; i < numentries; i++) { uint32_t connection; connection = READ_LE_INT(dcbtable,headerlength + recordlength * i); /* Should we allow discontinuous DCBs? Certainly DCB I2C tables can be discontinuous */ - if ((connection & 0x0000000f) == 0x0000000f) /* end of records */ - { + if ((connection & 0x0000000f) == 0x0000000f) { /* end of records */ continue; } - if (connection == 0x00000000) /* seen on an NV11 with DCB v1.5 */ - { + if (connection == 0x00000000) { /* seen on an NV11 with DCB v1.5 */ continue; } - if ((connection & 0xf) == 0x6) /* we skip type 6 as it doesnt appear on macbook nvcaps */ - { + if ((connection & 0xf) == 0x6) { /* we skip type 6 as it doesnt appear on macbook nvcaps */ continue; } @@ -1542,10 +1527,8 @@ int has_lvds = false; uint8_t channel1 = 0, channel2 = 0; - for (i = 0; i < num_outputs; i++) - { - if (entries[i].type == 3) - { + for (i = 0; i < num_outputs; i++) { + if (entries[i].type == 3) { has_lvds = true; //printf("found LVDS\n"); channel1 |= ( 0x1 << entries[i].index); @@ -1554,51 +1537,39 @@ } // if we have a LVDS output, we group the rest to the second channel - if (has_lvds) - { - for (i = 0; i < num_outputs; i++) - { - if (entries[i].type == TYPE_GROUPED) - { + if (has_lvds) { + for (i = 0; i < num_outputs; i++) { + if (entries[i].type == TYPE_GROUPED) { continue; } channel2 |= ( 0x1 << entries[i].index); entries[i].type = TYPE_GROUPED; } - } - else - { + } else { int x; // we loop twice as we need to generate two channels - for (x = 0; x <= 1; x++) - { - for (i=0; i channel2) - { + if (channel1 > channel2) { uint8_t buff = channel1; channel1 = channel2; channel2 = buff; @@ -1661,14 +1626,10 @@ default_NVCAP[8] = channel2; // patching HEADS - for (i = 0; i < num_outputs; i++) - { - if (channel1 & (1 << i)) - { + for (i = 0; i < num_outputs; i++) { + if (channel1 & (1 << i)) { *entries[i].heads = 1; - } - else if(channel2 & (1 << i)) - { + } else if(channel2 & (1 << i)) { *entries[i].heads = 2; } } @@ -1682,19 +1643,15 @@ // First check in the plist, (for e.g this can override any hardcoded devices) cardList_t * nvcard = FindCardWithIds(device_id, subsys_id); - if (nvcard) - { - if (nvcard->model) - { + if (nvcard) { + if (nvcard->model) { return nvcard->model; } } // Then check the exceptions table - if (subsys_id) - { - for (i = 0; i < (sizeof(nvidia_card_exceptions) / sizeof(nvidia_card_exceptions[0])); i++) - { + if (subsys_id) { + for (i = 0; i < (sizeof(nvidia_card_exceptions) / sizeof(nvidia_card_exceptions[0])); i++) { if ((nvidia_card_exceptions[i].device == device_id) && (nvidia_card_exceptions[i].subdev == subsys_id)) { return nvidia_card_exceptions[i].name; @@ -1703,16 +1660,11 @@ } // At last try the generic names - for (i = 1; i < (sizeof(nvidia_card_generic) / sizeof(nvidia_card_generic[0])); i++) - { - if (nvidia_card_generic[i].device == device_id) - { - if (subsys_id) - { - for (j = 0; j < (sizeof(nvidia_card_vendors) / sizeof(nvidia_card_vendors[0])); j++) - { - if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000)) - { + for (i = 1; i < (sizeof(nvidia_card_generic) / sizeof(nvidia_card_generic[0])); i++) { + if (nvidia_card_generic[i].device == device_id) { + if (subsys_id) { + for (j = 0; j < (sizeof(nvidia_card_vendors) / sizeof(nvidia_card_vendors[0])); j++) { + if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000)) { snprintf(name_model, sizeof(name_model), "%s %s", nvidia_card_vendors[j].name, nvidia_card_generic[i].name); return name_model; @@ -1730,15 +1682,13 @@ int fd; int size; - if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) - { + if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) { return 0; } size = file_size(fd); - if (size) - { + if (size) { *buf = malloc(size); size = read(fd, (char *)buf, size); } @@ -1766,20 +1716,17 @@ return 0; if (!DP_ADD_TEMP_VAL(device, nvidia_name_1)) return 0; - if (devices_number == 1) - { + if (devices_number == 1) { if (!DP_ADD_TEMP_VAL(device, nvidia_device_type_parent)) return 0; - } - else - { + } else { if (!DP_ADD_TEMP_VAL(device, nvidia_device_type_child)) return 0; } // Rek : Dont use sprintf return, it does not WORK !! our custom sprintf() always return 0! // len = sprintf(tmp, "Slot-%x", devices_number); - sprintf(tmp, "Slot-%x",devices_number); + snprintf(tmp, sizeof(tmp), "Slot-%x",devices_number); devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp)); devices_number++; @@ -1854,21 +1801,15 @@ break; } - if (!vram_size) - { // Finally, if vram_size still not set do the calculation with our own method - if (nvCardType < NV_ARCH_50) - { + if (!vram_size) { // Finally, if vram_size still not set do the calculation with our own method + if (nvCardType < NV_ARCH_50) { vram_size = REG32(NV04_PFB_FIFO_DATA); vram_size &= NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK; - } - else if (nvCardType < NV_ARCH_C0) - { + } else if (nvCardType < NV_ARCH_C0) { vram_size = REG32(NV04_PFB_FIFO_DATA); vram_size |= (vram_size & 0xff) << 32; vram_size &= 0xffffffff00ll; - } - else // >= NV_ARCH_C0 - { + } else { // >= NV_ARCH_C0 vram_size = REG32(NVC0_MEM_CTRLR_RAM_AMOUNT) << 20; vram_size *= REG32(NVC0_MEM_CTRLR_COUNT); } @@ -1917,27 +1858,22 @@ // Amount of VRAM in kilobytes videoRam = mem_detect(regs, nvCardType, nvda_dev,((nvda_dev->vendor_id << 16) | nvda_dev->device_id),((nvda_dev->subsys_id.subsys.vendor_id << 16) | nvda_dev->subsys_id.subsys.device_id) ); - sprintf(nvFilename, "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id); + snprintf(nvFilename, sizeof(nvFilename), "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id); if (getBoolForKey(kUseNvidiaROM, &doit, &bootInfo->chameleonConfig) && doit) { verbose("Looking for nvidia video bios file %s\n", nvFilename); nvBiosOveride = load_nvidia_bios_file(nvFilename, &rom); - if (nvBiosOveride > 0) - { + if (nvBiosOveride > 0) { verbose("Using nVidia Video BIOS File %s (%d Bytes)\n", nvFilename, nvBiosOveride); DBG("%s Signature 0x%02x%02x %d bytes\n", nvFilename, rom[0], rom[1], nvBiosOveride); - } - else - { + } else { printf("ERROR: unable to open nVidia Video BIOS File %s\n", nvFilename); free(rom); return false; } - } - else - { + } else { rom = malloc(NVIDIA_ROM_SIZE); // Otherwise read bios from card nvBiosOveride = 0; @@ -1948,13 +1884,10 @@ nvRom = (uint8_t*)®s[NV_PROM_OFFSET]; // Valid Signature ? - if (checkNvRomSig(nvRom)) - { + if (checkNvRomSig(nvRom)) { bcopy((uint8_t *)nvRom, rom, NVIDIA_ROM_SIZE); DBG("PROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]); - } - else - { + } else { // disable PROM access (REG32(NV_PBUS_PCI_NV_20)) = NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED; @@ -1962,52 +1895,42 @@ //PRAM next nvRom = (uint8_t*)®s[NV_PRAMIN_OFFSET]; - if(checkNvRomSig(nvRom)) - { + if(checkNvRomSig(nvRom)) { bcopy((uint32_t *)nvRom, rom, NVIDIA_ROM_SIZE); DBG("PRAM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]); - } - else - { + } else { // 0xC0000 last bcopy((char *)0xc0000, rom, NVIDIA_ROM_SIZE); // Valid Signature ? - if (!checkNvRomSig(rom)) - { + if (!checkNvRomSig(rom)) { printf("ERROR: Unable to locate nVidia Video BIOS\n"); return false; - } - else - { + } else { DBG("ROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]); } }//end PRAM check }//end PROM check }//end load rom from bios - if ((nvPatch = patch_nvidia_rom(rom)) == PATCH_ROM_FAILED) - { + if ((nvPatch = patch_nvidia_rom(rom)) == PATCH_ROM_FAILED) { printf("ERROR: nVidia ROM Patching Failed!\n"); + free(rom); //return false; } rom_pci_header = (option_rom_pci_header_t*)(rom + *(uint16_t *)&rom[24]); // check for 'PCIR' sig - if (rom_pci_header->signature == 0x50434952) - { - if (rom_pci_header->device_id != nvda_dev->device_id) - { + if (rom_pci_header->signature == 0x50434952) { + if (rom_pci_header->device_id != nvda_dev->device_id) { // Get Model from the OpROM model = get_nvidia_model(((rom_pci_header->vendor_id << 16) | rom_pci_header->device_id), 0); // Get VRAM again videoRam = mem_detect(regs, nvCardType, nvda_dev, ((rom_pci_header->vendor_id << 16) | rom_pci_header->device_id), 0); - } - else - { + } else { printf("nVidia incorrect PCI ROM signature: 0x%x\n", rom_pci_header->signature); } } @@ -2025,8 +1948,7 @@ /* FIXME: for primary graphics card only */ boot_display = 1; - if (devices_number == 1) - { + if (devices_number == 1) { devprop_add_value(device, "@0,AAPL,boot-display", (uint8_t*)&boot_display, 4); } @@ -2045,26 +1967,20 @@ int crlf_count = 0; // only search the first 384 bytes - for (i = 0; i < 0x180; i++) - { - if (rom[i] == 0x0D && rom[i+1] == 0x0A) - { + for (i = 0; i < 0x180; i++) { + if (rom[i] == 0x0D && rom[i+1] == 0x0A) { crlf_count++; // second 0x0D0A was found, extract bios version - if (crlf_count == 2) - { + if (crlf_count == 2) { if (rom[i-1] == 0x20) i--; // strip last " " - for (version_start = i; version_start > (i-MAX_BIOS_VERSION_LENGTH); version_start--) - { + for (version_start = i; version_start > (i-MAX_BIOS_VERSION_LENGTH); version_start--) { // find start - if (rom[version_start] == 0x00) - { + if (rom[version_start] == 0x00) { version_start++; // strip "Version " - if (strncmp((const char*)rom+version_start, "Version ", 8) == 0) - { + if (strncmp((const char*)rom+version_start, "Version ", 8) == 0) { version_start += 8; } @@ -2078,25 +1994,21 @@ } snprintf(biosVersion, sizeof(biosVersion), "%s", (nvBiosOveride > 0) ? nvFilename : version_str); - sprintf(kNVCAP, "NVCAP_%04x", nvda_dev->device_id); + snprintf(kNVCAP, sizeof(kNVCAP), "NVCAP_%04x", nvda_dev->device_id); - if (getValueForKey(kNVCAP, &value, &len, &bootInfo->chameleonConfig) && len == NVCAP_LEN * 2) - { + if (getValueForKey(kNVCAP, &value, &len, &bootInfo->chameleonConfig) && len == NVCAP_LEN * 2) { uint8_t new_NVCAP[NVCAP_LEN]; - if (hex2bin(value, new_NVCAP, NVCAP_LEN) == 0) - { + if (hex2bin(value, new_NVCAP, NVCAP_LEN) == 0) { verbose("Using user supplied NVCAP for %s :: %s\n", model, devicepath); memcpy(default_NVCAP, new_NVCAP, NVCAP_LEN); } } - if (getValueForKey(kDcfg0, &value, &len, &bootInfo->chameleonConfig) && len == DCFG0_LEN * 2) - { + if (getValueForKey(kDcfg0, &value, &len, &bootInfo->chameleonConfig) && len == DCFG0_LEN * 2) { uint8_t new_dcfg0[DCFG0_LEN]; - if (hex2bin(value, new_dcfg0, DCFG0_LEN) == 0) - { + if (hex2bin(value, new_dcfg0, DCFG0_LEN) == 0) { memcpy(default_dcfg_0, new_dcfg0, DCFG0_LEN); verbose("Using user supplied @0,display-cfg\n"); @@ -2105,12 +2017,10 @@ } } - if (getValueForKey(kDcfg1, &value, &len, &bootInfo->chameleonConfig) && len == DCFG1_LEN * 2) - { + if (getValueForKey(kDcfg1, &value, &len, &bootInfo->chameleonConfig) && len == DCFG1_LEN * 2) { uint8_t new_dcfg1[DCFG1_LEN]; - if (hex2bin(value, new_dcfg1, DCFG1_LEN) == 0) - { + if (hex2bin(value, new_dcfg1, DCFG1_LEN) == 0) { memcpy(default_dcfg_1, new_dcfg1, DCFG1_LEN); verbose("Using user supplied @1,display-cfg\n"); @@ -2140,8 +2050,7 @@ /******************** Added Marchrius.**********************/ // For the AppleBacklightDisplay // /***********************************************************/ - if (getBoolForKey(kEnableBacklight, &doit, &bootInfo->chameleonConfig) && doit) - { + if (getBoolForKey(kEnableBacklight, &doit, &bootInfo->chameleonConfig) && doit) { uint8_t AAPL_value[] = {0x01, 0x00, 0x00, 0x00}; //Is the same for all devprop_add_value(device, "AAPL,HasPanel", AAPL_value, 4); devprop_add_value(device, "AAPL,Haslid", AAPL_value, 4); @@ -2153,8 +2062,7 @@ /***********************************************************/ // For the DualLink // /***********************************************************/ - if (getBoolForKey(kEnableDualLink, &doit, &bootInfo->chameleonConfig) && doit) - { + if (getBoolForKey(kEnableDualLink, &doit, &bootInfo->chameleonConfig) && doit) { uint8_t AAPL00_value[] = {0x01, 0x00, 0x00, 0x00}; devprop_add_value(device, "AAPL00,DualLink", AAPL00_value, 4); } @@ -2163,8 +2071,7 @@ /************************ HDMI Audio ***********************/ doit = false; //http://forge.voodooprojects.org/p/chameleon/issues/67/ - if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit) - { + if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit) { static uint8_t connector_type_1[]= {0x00, 0x08, 0x00, 0x00}; devprop_add_value(device, "@0,connector-type",connector_type_1, 4); devprop_add_value(device, "@1,connector-type",connector_type_1, 4); @@ -2173,8 +2080,7 @@ } /************************ End Audio *************************/ - if (getBoolForKey(kVBIOS, &doit, &bootInfo->chameleonConfig) && doit) - { + if (getBoolForKey(kVBIOS, &doit, &bootInfo->chameleonConfig) && doit) { devprop_add_value(device, "vbios", rom, (nvBiosOveride > 0) ? nvBiosOveride : (rom[2] * 512)); } Index: trunk/i386/libsaio/ntfs.c =================================================================== --- trunk/i386/libsaio/ntfs.c (revision 2330) +++ trunk/i386/libsaio/ntfs.c (revision 2331) @@ -271,13 +271,12 @@ goto error; } if (read(fd, buf, mftRecordSize) != mftRecordSize) { - //verbose("NTFS: error reading MFT $Volume record: %s\n", strerror(errno)); + //verbose("NTFS: error reading MFT $Volume record: %s\n", strerror(errno)); goto error; } #endif - if (ntfs_fixup(buf, mftRecordSize, NTFS_FILEMAGIC, bytesPerSector) != 0) - { + if (ntfs_fixup(buf, mftRecordSize, NTFS_FILEMAGIC, bytesPerSector) != 0) { //verbose("NTFS: block fixup failed\n"); goto error; } @@ -331,8 +330,9 @@ } // 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, @@ -344,7 +344,7 @@ bool NTFSProbe(const void * buffer) { bool result = false; - + const struct bootfile * part_bootfile = buffer; // NTFS boot sector structure // Looking for NTFS signature. Index: trunk/i386/libsaio/ati.c =================================================================== --- trunk/i386/libsaio/ati.c (revision 2330) +++ trunk/i386/libsaio/ati.c (revision 2331) @@ -1359,7 +1359,9 @@ { 0x95C4, 0x00000000, CHIP_FAMILY_RV620, "ATI Radeon HD 3470 Series", kIago }, { 0x95C5, 0x00000000, CHIP_FAMILY_RV620, "ATI Radeon HD 3450 Series", kIago }, + { 0x95C6, 0x00000000, CHIP_FAMILY_RV620, "ATI Radeon HD 3450 AGP", kIago }, + /* IGP */ { 0x9610, 0x00000000, CHIP_FAMILY_RS780, "ATI Radeon HD 3200 Graphics", kNull }, { 0x9611, 0x00000000, CHIP_FAMILY_RS780, "ATI Radeon HD 3100 Graphics", kNull }, @@ -1559,7 +1561,7 @@ { 0x6808, 0x00000000, CHIP_FAMILY_TAHITI, "AMD Radeon HD 7600 Series", kFutomaki }, // ATI7000Controller.kext // { 0x6809, 0x00000000, CHIP_FAMILY_PITCAIRN, "AMD Radeon HD ??? Series", kNull }, -// { 0x6810, 0x00000000, CHIP_FAMILY_PITCAIRN, "AMD Radeon HD ??? Series", kNull }, + { 0x6810, 0x00000000, CHIP_FAMILY_PITCAIRN, "AMD Radeon R9 270X", kNull }, { 0x6818, 0x00000000, CHIP_FAMILY_TAHITI, "AMD Radeon HD 7870 Series", kFutomaki }, // CHIP_FAMILY_PITCAIRN ??// ATI7000Controller.kext { 0x6819, 0x00000000, CHIP_FAMILY_TAHITI, "AMD Radeon HD 7850 Series", kFutomaki },// CHIP_FAMILY_PITCAIRN ?? @@ -1584,7 +1586,7 @@ { 0x6831, 0x00000000, CHIP_FAMILY_VERDE, "AMD Radeon HD 7700 Series", kBuri }, { 0x6837, 0x00000000, CHIP_FAMILY_VERDE, "AMD Radeon HD 7700 Series", kBuri }, -// { 0x6838, 0x00000000, CHIP_FAMILY_VERDE, "AMD Radeon HD ??? Series", kBuri }, + { 0x6838, 0x00000000, CHIP_FAMILY_VERDE, "AMD Radeon HD 7700 Series", kBuri }, { 0x6839, 0x00000000, CHIP_FAMILY_VERDE, "AMD Radeon HD 7700 Series", kBuri }, // ATI7000Controller.kext { 0x683B, 0x00000000, CHIP_FAMILY_VERDE, "AMD Radeon HD 7700 Series", kBuri }, // ATI7000Controller.kext Index: trunk/i386/libsaio/sys.c =================================================================== --- trunk/i386/libsaio/sys.c (revision 2330) +++ trunk/i386/libsaio/sys.c (revision 2331) @@ -82,20 +82,20 @@ extern int multiboot_skip_partition_set; struct devsw { - const char * name; - // size increased from char to short to handle non-BIOS internal devices - unsigned short biosdev; - int type; + const char * name; + // size increased from char to short to handle non-BIOS internal devices + unsigned short biosdev; + int type; }; // Device entries must be ordered by bios device numbers. static struct devsw devsw[] = { - { "hd", 0x80, kBIOSDevTypeHardDrive }, /* DEV_HD */ - { "en", 0xE0, kBIOSDevTypeNetwork }, /* DEV_EN */ - { "rd", 0x100, kBIOSDevTypeHardDrive }, - { "bt", 0x101, kBIOSDevTypeHardDrive }, // turbo - type for booter partition - { 0, 0 } + { "hd", 0x80, kBIOSDevTypeHardDrive }, /* DEV_HD */ + { "en", 0xE0, kBIOSDevTypeNetwork }, /* DEV_EN */ + { "rd", 0x100, kBIOSDevTypeHardDrive }, + { "bt", 0x101, kBIOSDevTypeHardDrive }, // turbo - type for booter partition + { 0, 0 } }; // Pseudo BIOS devices @@ -149,98 +149,118 @@ long LoadFile(const char * fileSpec) { - const char * filePath; - BVRef bvr; + const char * filePath; + BVRef bvr; - // Resolve the boot volume from the file spec. + // Resolve the boot volume from the file spec. - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) - return -1; + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) { + return -1; + } - return LoadVolumeFile(bvr, filePath); + return LoadVolumeFile(bvr, filePath); } +//========================================================================== + long ReadFileAtOffset(const char * fileSpec, void *buffer, uint64_t offset, uint64_t length) { - const char *filePath; - BVRef bvr; + const char *filePath; + BVRef bvr; - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) - return -1; + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) { + return -1; + } - if (bvr->fs_readfile == NULL) - return -1; + if (bvr->fs_readfile == NULL) { + return -1; + } - return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length); + return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length); } +//========================================================================== + long LoadThinFatFile(const char *fileSpec, void **binary) { - const char *filePath; - FSReadFile readFile; - BVRef bvr; - unsigned long length, length2; - - // Resolve the boot volume from the file spec. + const char *filePath; + FSReadFile readFile; + BVRef bvr; + unsigned long length, length2; - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) - return -1; + // Resolve the boot volume from the file spec. + + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) { + return -1; + } + + *binary = (void *)kLoadAddr; - *binary = (void *)kLoadAddr; - - // Read file into load buffer. The data in the load buffer will be - // overwritten by the next LoadFile() call. + // Read file into load buffer. The data in the load buffer will be + // overwritten by the next LoadFile() call. - gFSLoadAddress = (void *) LOAD_ADDR; + gFSLoadAddress = (void *) LOAD_ADDR; - readFile = bvr->fs_readfile; + readFile = bvr->fs_readfile; - if (readFile != NULL) { - // Read the first 4096 bytes (fat header) - length = readFile(bvr, (char *)filePath, *binary, 0, 0x1000); - if (length > 0) { - if (ThinFatFile(binary, &length) == 0) { - if (length == 0) + if (readFile != NULL) { + // Read the first 4096 bytes (fat header) + length = readFile(bvr, (char *)filePath, *binary, 0, 0x1000); + + if (length > 0) { + if (ThinFatFile(binary, &length) == 0) { + if (length == 0) { return 0; - // We found a fat binary; read only the thin part - length = readFile(bvr, (char *)filePath, - (void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length); - *binary = (void *)kLoadAddr; - } else { - // Not a fat binary; read the rest of the file - length2 = readFile(bvr, (char *)filePath, (void *)(kLoadAddr + length), length, 0); - if (length2 == -1) return -1; - length += length2; - } - } - } else { - length = bvr->fs_loadfile(bvr, (char *)filePath); - if (length > 0) { - ThinFatFile(binary, &length); - } - } + } + + // We found a fat binary; read only the thin part + length = readFile(bvr, (char *)filePath, (void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length); + *binary = (void *)kLoadAddr; + } else { + // Not a fat binary; read the rest of the file + length2 = readFile(bvr, (char *)filePath, (void *)(kLoadAddr + length), length, 0); + + if (length2 == -1) { + return -1; + } + + length += length2; + } + } + } else { + length = bvr->fs_loadfile(bvr, (char *)filePath); + + if (length > 0) { + ThinFatFile(binary, &length); + } + } - return length; + return length; } +//========================================================================== + #if UNUSED long GetFSUUID(char *spec, char *uuidStr) { - BVRef bvr; - long rval = -1; - const char *devSpec; + BVRef bvr; + long rval = -1; + const char *devSpec; - if ((bvr = getBootVolumeRef(spec, &devSpec)) == NULL) - return -1; + if ((bvr = getBootVolumeRef(spec, &devSpec)) == NULL) { + return -1; + } - if(bvr->fs_getuuid) - rval = bvr->fs_getuuid(bvr, uuidStr); + if(bvr->fs_getuuid) { + rval = bvr->fs_getuuid(bvr, uuidStr); + } - return rval; + return rval; } #endif // filesystem-specific getUUID functions call this shared string generator + long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr) { unsigned fmtbase, fmtidx, i; @@ -264,31 +284,43 @@ // generate the text: e.g. 5EB1869F-C4FA-3502-BDEB-3B8ED5D87292 - i = 0; fmtbase = 0; - for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) { - for(i=0; i < uuidfmt[fmtidx]; i++) { - uint8_t byte = mdresult[fmtbase+i]; - char nib; + i = 0; + fmtbase = 0; - nib = byte >> 4; - *p = nib + '0'; // 0x4 -> '4' - if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' - p++; + for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) { + for (i = 0; i < uuidfmt[fmtidx]; i++) { + uint8_t byte = mdresult[fmtbase + i]; + char nib = byte >> 4; + *p = nib + '0'; // 0x4 -> '4' - nib = byte & 0xf; - *p = nib + '0'; // 0x4 -> '4' - if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' - p++; + if (*p > '9') { + *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' + } - } - fmtbase += i; - if(fmtidx < sizeof(uuidfmt)-1) - *(p++) = '-'; - else - *p = '\0'; - } + p++; - return 0; + nib = byte & 0xf; + *p = nib + '0'; // 0x4 -> '4' + + if (*p > '9') { + *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' + } + + p++; + } + + fmtbase += i; + + if (fmtidx < sizeof(uuidfmt) - 1) { + *(p++) = '-'; + } + else + { + *p = '\0'; + } + } + + return 0; } @@ -299,15 +331,16 @@ long GetDirEntry(const char * dirSpec, long long * dirIndex, const char ** name, long * flags, long * time) { - const char * dirPath; - BVRef bvr; + const char * dirPath; + BVRef bvr; - // Resolve the boot volume from the dir spec. + // Resolve the boot volume from the dir spec. - if ((bvr = getBootVolumeRef(dirSpec, &dirPath)) == NULL) - return -1; + if ((bvr = getBootVolumeRef(dirSpec, &dirPath)) == NULL) { + return -1; + } - // Return 0 on success, or -1 if there are no additional entries. + // Returns 0 on success or -1 when there are no additional entries. return bvr->fs_getdirentry( bvr, /* dirPath */ (char *)dirPath, @@ -324,52 +357,59 @@ long GetFileInfo(const char * dirSpec, const char * name, long * flags, long * time) { - long long index = 0; - const char * entryName; + long long index = 0; + const char * entryName; - if (gMakeDirSpec == 0) - gMakeDirSpec = (char *)malloc(1024); + if (gMakeDirSpec == 0) { + gMakeDirSpec = (char *)malloc(1024); + } - if (!dirSpec) { - long idx, len; + if (!dirSpec) { + long idx, len; - len = strlen(name); + len = strlen(name); - for (idx = len; idx && (name[idx] != '/' && name[idx] != '\\'); idx--) {} - if (idx == 0) { - if(name[idx] == '/' || name[idx] == '\\') ++name; // todo: ensure other functions handel \ properly - gMakeDirSpec[0] = '/'; - gMakeDirSpec[1] = '\0'; - } else { - idx++; - strncpy(gMakeDirSpec, name, idx); - gMakeDirSpec[idx] = '\0'; - name += idx; - } - dirSpec = gMakeDirSpec; - } + for (idx = len; idx && (name[idx] != '/' && name[idx] != '\\'); idx--) {} + if (idx == 0) { + if(name[idx] == '/' || name[idx] == '\\') ++name; // todo: ensure other functions handel \ properly + gMakeDirSpec[0] = '/'; + gMakeDirSpec[1] = '\0'; + gMakeDirSpec[idx] = '\0'; + } else { + idx++; + strncpy(gMakeDirSpec, name, idx); + gMakeDirSpec[idx] = '\0'; // ISSUE: http://forge.voodooprojects.org/p/chameleon/issues/270/ + name += idx; + } - while (GetDirEntry(dirSpec, &index, &entryName, flags, time) == 0) - { - if (strcmp(entryName, name) == 0) - return 0; // success - } - return -1; // file not found + dirSpec = gMakeDirSpec; + } + + while (GetDirEntry(dirSpec, &index, &entryName, flags, time) == 0) + { + if (strcmp(entryName, name) == 0) { + return 0; // success + } + } + + return -1; // file not found } +//============================================================================== + long GetFileBlock(const char *fileSpec, unsigned long long *firstBlock) { - const char * filePath; - BVRef bvr; + const char * filePath; + BVRef bvr; - // Resolve the boot volume from the file spec. + // Resolve the boot volume from the file spec. - if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) { - printf("Boot volume for '%s' is bogus\n", fileSpec); - return -1; - } + if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) { + // printf("Boot volume for '%s' is bogus\n", fileSpec); + return -1; + } - return bvr->fs_getfileblock(bvr, (char *)filePath, firstBlock); + return bvr->fs_getfileblock(bvr, (char *)filePath, firstBlock); } //========================================================================== @@ -398,13 +438,13 @@ static struct iob * iob_from_fdesc(int fdesc) { - register struct iob * io; + register struct iob * io; - if (fdesc < 0 || fdesc >= NFILES || - ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) - return NULL; - else - return io; + if (fdesc < 0 || fdesc >= NFILES || ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) { + return NULL; + } else { + return io; + } } //========================================================================== @@ -530,14 +570,15 @@ int close(int fdesc) { - struct iob * io; + struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == NULL) - return (-1); + if ((io = iob_from_fdesc(fdesc)) == NULL) { + return (-1); + } - io->i_flgs = 0; + io->i_flgs = 0; - return 0; + return 0; } //========================================================================== @@ -546,14 +587,15 @@ int b_lseek(int fdesc, int offset, int ptr) { - struct iob * io; + struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == NULL) - return (-1); + if ((io = iob_from_fdesc(fdesc)) == NULL) { + return (-1); + } - io->i_offset = offset; + io->i_offset = offset; - return offset; + return offset; } //========================================================================== @@ -561,12 +603,13 @@ int tell(int fdesc) { - struct iob * io; + struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == NULL) - return 0; + if ((io = iob_from_fdesc(fdesc)) == NULL) { + return 0; + } - return io->i_offset; + return io->i_offset; } //========================================================================== @@ -575,22 +618,25 @@ int read(int fdesc, char * buf, int count) { - struct iob * io; - - if ((io = iob_from_fdesc(fdesc)) == NULL) - return (-1); + struct iob * io; - if ((io->i_offset + count) > (unsigned int)io->i_filesize) - count = io->i_filesize - io->i_offset; + if ((io = iob_from_fdesc(fdesc)) == NULL) { + return (-1); + } - if (count <= 0) - return 0; // end of file + if ((io->i_offset + count) > (unsigned int)io->i_filesize) { + count = io->i_filesize - io->i_offset; + } - bcopy(io->i_buf + io->i_offset, buf, count); + if (count <= 0) { + return 0; // end of file + } - io->i_offset += count; + bcopy(io->i_buf + io->i_offset, buf, count); - return count; + io->i_offset += count; + + return count; } //========================================================================== @@ -655,44 +701,47 @@ int file_size(int fdesc) { - struct iob * io; + struct iob * io; - if ((io = iob_from_fdesc(fdesc)) == 0) - return 0; + if ((io = iob_from_fdesc(fdesc)) == 0) { + return 0; + } - return io->i_filesize; + return io->i_filesize; } //========================================================================== struct dirstuff * vol_opendir(BVRef bvr, const char * path) { - struct dirstuff * dirp = 0; + struct dirstuff * dirp = 0; - dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff)); - if (dirp == NULL) - goto error; + dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff)); - dirp->dir_path = newString(path); - if (dirp->dir_path == NULL) - goto error; + if (dirp == NULL) + goto error; - dirp->dir_bvr = bvr; + dirp->dir_path = newString(path); + if (dirp->dir_path == NULL) + goto error; - return dirp; + dirp->dir_bvr = bvr; + return dirp; + error: - closedir(dirp); - return NULL; + closedir(dirp); + + return NULL; } //========================================================================== struct dirstuff * opendir(const char * path) { - struct dirstuff * dirp = 0; - const char * dirPath; - BVRef bvr; + struct dirstuff * dirp = 0; + const char * dirPath; + BVRef bvr; if ((bvr = getBootVolumeRef(path, &dirPath)) == NULL) goto error; @@ -718,91 +767,89 @@ int closedir(struct dirstuff * dirp) { - if (dirp) { - if (dirp->dir_path) free(dirp->dir_path); - free(dirp); - } + if (dirp) { + if (dirp->dir_path) { + free(dirp->dir_path); + } + + free(dirp); + } + return 0; } //========================================================================== int readdir(struct dirstuff * dirp, const char ** name, long * flags, - long * time) + long * time) { - return dirp->dir_bvr->fs_getdirentry( dirp->dir_bvr, - /* dirPath */ dirp->dir_path, - /* dirIndex */ &dirp->dir_index, - /* dirEntry */ (char **)name, flags, time, - 0, 0); + return dirp->dir_bvr->fs_getdirentry(dirp->dir_bvr, + /* dirPath */ dirp->dir_path, + /* dirIndex */ &dirp->dir_index, + /* dirEntry */ (char **)name, flags, time, 0, 0); } //========================================================================== int readdir_ext(struct dirstuff * dirp, const char ** name, long * flags, - long * time, FinderInfo *finderInfo, long *infoValid) + long * time, FinderInfo *finderInfo, long *infoValid) { - return dirp->dir_bvr->fs_getdirentry( dirp->dir_bvr, - /* dirPath */ dirp->dir_path, - /* dirIndex */ &dirp->dir_index, - /* dirEntry */ (char **)name, - flags, time, - finderInfo, infoValid); + return dirp->dir_bvr->fs_getdirentry( dirp->dir_bvr, + /* dirPath */ dirp->dir_path, + /* dirIndex */ &dirp->dir_index, + /* dirEntry */ (char **)name, + flags, time, + finderInfo, infoValid); } //========================================================================== const char * systemConfigDir() { - if (gBootFileType == kNetworkDeviceType) - return ""; - return "/Library/Preferences/SystemConfiguration"; + if (gBootFileType == kNetworkDeviceType) { + return ""; + } + return "/Library/Preferences/SystemConfiguration"; } //========================================================================== int gBootFileType; -void scanBootVolumes( int biosdev, int * count ) +void scanBootVolumes(int biosdev, int * count) { - BVRef bvr = 0; + BVRef bvr = 0; - bvr = diskScanBootVolumes(biosdev, count); - if (bvr == NULL) - { - bvr = nbpScanBootVolumes(biosdev, count); - if (bvr != NULL) - { - gBootFileType = kNetworkDeviceType; - } - } - else - { - gBootFileType = kBlockDeviceType; - } + bvr = diskScanBootVolumes(biosdev, count); + if (bvr == NULL) { + bvr = nbpScanBootVolumes(biosdev, count); + if (bvr != NULL) { + gBootFileType = kNetworkDeviceType; + } + } else { + gBootFileType = kBlockDeviceType; + } } //========================================================================== void scanDisks(int biosdev, int *count) { - #define MAX_HDD_COUNT 32 - int bvCount; - int hd = 0; + #define MAX_HDD_COUNT 32 + int bvCount; + int hd = 0; - // Testing up to MAX_HDD_COUNT hard drives. - while(!testBiosread(0x80 + hd, 0) && hd < MAX_HDD_COUNT) - { - bvCount = 0; - scanBootVolumes(0x80 + hd, &bvCount); - hd++; + // Testing up to MAX_HDD_COUNT hard drives. + while(!testBiosread(0x80 + hd, 0) && hd < MAX_HDD_COUNT) { + bvCount = 0; + scanBootVolumes(0x80 + hd, &bvCount); + hd++; } - // Also scanning CD/DVD drive. - if (biosDevIsCDROM(gBIOSDev)) - { - bvCount = 0; - scanBootVolumes(gBIOSDev, &bvCount); + // Also scanning CD/DVD drive. + if (biosDevIsCDROM(gBIOSDev)) { + bvCount = 0; + scanBootVolumes(gBIOSDev, &bvCount); } } @@ -814,57 +861,66 @@ bool foundPrimary = false; BVRef bvr, bvr1 = 0, bvr2 = 0; - if (chain->filtered) filteredChain = true; + if (chain->filtered) { + filteredChain = true; + } - if (multiboot_partition_set) - for ( bvr = chain; bvr; bvr = bvr->next ) - if ( bvr->part_no == multiboot_partition && bvr->biosdev == gBIOSDev ) + if (multiboot_partition_set) { + for ( bvr = chain; bvr; bvr = bvr->next ) { + if ( bvr->part_no == multiboot_partition && bvr->biosdev == gBIOSDev ) { return bvr; - + } + } + } + /* * Checking "Default Partition" key in system configuration - use format: hd(x,y), the volume UUID or label - * to override the default selection. * We accept only kBVFlagSystemVolume or kBVFlagForeignBoot volumes. */ char *val = XMLDecode(getStringForKey(kDefaultPartition, &bootInfo->chameleonConfig)); - if (val) { - for ( bvr = chain; bvr; bvr = bvr->next ) { - if (matchVolumeToString(bvr, val, false)) { - free(val); - return bvr; - } - } - free(val); - } - + if (val) { + for ( bvr = chain; bvr; bvr = bvr->next ) { + if (matchVolumeToString(bvr, val, false)) { + free(val); + return bvr; + } + } + free(val); + } + /* * Scannig the volume chain backwards and trying to find * a HFS+ volume with valid boot record signature. * If not found any active partition then we will * select this volume as the boot volume. */ - for ( bvr = chain; bvr; bvr = bvr->next ) - { - if (multiboot_skip_partition_set) { - if (bvr->part_no == multiboot_skip_partition) continue; - } - if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) foundPrimary = true; + for ( bvr = chain; bvr; bvr = bvr->next ) { + if (multiboot_skip_partition_set) { + if (bvr->part_no == multiboot_skip_partition) continue; + } + if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) { + foundPrimary = true; + } + // zhell -- Undo a regression that was introduced from r491 to 492. // if gBIOSBootVolume is set already, no change is required if ( bvr->flags & (kBVFlagBootable|kBVFlagSystemVolume) && gBIOSBootVolume && (!filteredChain || (filteredChain && bvr->visible)) - && bvr->biosdev == gBIOSDev ) + && bvr->biosdev == gBIOSDev ) { bvr2 = bvr; + } + // zhell -- if gBIOSBootVolume is NOT set, we use the "if" statement // from r491, if ( bvr->flags & kBVFlagBootable && ! gBIOSBootVolume - && bvr->biosdev == gBIOSDev ) + && bvr->biosdev == gBIOSDev ) { bvr2 = bvr; - } - - + } + } + /* * Use the standrad method for selecting the boot volume. */ @@ -872,8 +928,12 @@ { for ( bvr = chain; bvr; bvr = bvr->next ) { - if ( bvr->flags & kBVFlagNativeBoot && bvr->biosdev == gBIOSDev ) bvr1 = bvr; - if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) bvr2 = bvr; + if ( bvr->flags & kBVFlagNativeBoot && bvr->biosdev == gBIOSDev ) { + bvr1 = bvr; + } + if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) { + bvr2 = bvr; + } } } @@ -898,22 +958,25 @@ void setRootVolume(BVRef volume) { - 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)) - gRootVolume = NULL; + 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)) { + gRootVolume = NULL; + } } void setBootGlobals(BVRef chain) { - // Record default boot device. - gBootVolume = selectBootVolume(chain); + // Record default boot device. + gBootVolume = selectBootVolume(chain); - // turbo - Save the ORIGINAL boot volume too for loading our mkext - if (!gBIOSBootVolume) gBIOSBootVolume = gBootVolume; - - setRootVolume(gBootVolume); + // turbo - Save the ORIGINAL boot volume too for loading our mkext + if (!gBIOSBootVolume) { + gBIOSBootVolume = gBootVolume; + } + + setRootVolume(gBootVolume); } /*! @@ -932,95 +995,106 @@ // Search for left parenthesis in the path specification. - for (cp = path; *cp; cp++) { - if (*cp == LP || *cp == '/') break; - } + for (cp = path; *cp; cp++) { + if (*cp == LP || *cp == '/') { + break; + } + } - if (*cp != LP) // no left paren found - { - // Path is using the implicit current device so if there is - // no current device, then we must fail. - cp = path; - if ( gRootVolume == NULL ) - return NULL; - } - else if ((cp - path) == 2) // found "xx(" - { - const struct devsw * dp; - const char * xp = path; - int i; - int unit = -1; - int part = -1; + if (*cp != LP) { // no left paren found + cp = path; + // Path is using the implicit current device so if there is + // no current device, then we must fail. + if (gRootVolume == NULL) { + return NULL; + } + } else if ((cp - path) == 2) { // found "xx(" + const struct devsw * dp; + const char * xp = path; - cp++; + int i; + int unit = -1; + int part = -1; - // Check the 2 character device name pointed by 'xp'. + cp++; - 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) - { - error("Unknown device '%c%c'\n", xp[0], xp[1]); - return NULL; - } + // 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])) { + break; // Found matching entry. + } + } + + if (dp->name == NULL) { + error("Unknown device '%c%c'\n", xp[0], xp[1]); + return NULL; + } - // Extract the optional unit number from the specification. - // hd(unit) or hd(unit, part). + // Extract the optional unit number from the specification. + // hd(unit) or hd(unit, part). - i = 0; - while (*cp >= '0' && *cp <= '9') - { - i = i * 10 + *cp++ - '0'; - unit = i; - } + i = 0; + 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) - return NULL; + if (unit == -1) { + return NULL; + } - // Extract the optional partition number from the specification. + // Extract the optional partition number from the specification. - if (*cp == ',') - part = atoi(++cp); + if (*cp == ',') { + part = atoi(++cp); + } - // If part is not specified part will be -1 whereas before it would have been - // whatever the last partition was which makes about zero sense if the device - // has been switched. + // If part is not specified part will be -1 whereas before it would have been + // whatever the last partition was which makes about zero sense if the device + // has been switched. - // Skip past the right paren. + // Skip past the right paren. - for ( ; *cp && *cp != RP; cp++) /* LOOP */; - if (*cp == RP) cp++; + for ( ; *cp && *cp != RP; cp++) /* LOOP */; + + if (*cp == RP) { + cp++; + } - biosdev = dp->biosdev + unit; - bvr = newBootVolumeRef(biosdev, part); + biosdev = dp->biosdev + unit; - if(bvr == NULL) - return NULL; - } - else - { - // Bad device specifier, skip past the right paren. + bvr = newBootVolumeRef(biosdev, part); - for ( cp++; *cp && *cp != RP; cp++) /* LOOP */; - if (*cp == RP) cp++; - // If gRootVolume was NULL, then bvr will be NULL as well which - // should be caught by the caller. - } + if (bvr == NULL) { + return NULL; + } + } else { + // Bad device specifier, skip past the right paren. - // Returns the file path following the device spec. - // e.g. 'hd(1,b)mach_kernel' is reduced to 'mach_kernel'. + for (cp++; *cp && *cp != RP; cp++) /* LOOP */; + { + if (*cp == RP) { + cp++; + } + } - *outPath = cp; + // If gRootVolume was NULL, then bvr will be NULL as well which + // should be caught by the caller. + } - return bvr; + // Returns the file path following the device spec. + // e.g. 'hd(1,b)mach_kernel' is reduced to 'mach_kernel'. + + *outPath = cp; + + return bvr; } //========================================================================== @@ -1032,21 +1106,18 @@ bvr = bvr1 = NULL; - // Try resolving "rd" and "bt" devices first. - if (biosdev == kPseudoBIOSDevRAMDisk) - { - if (gRAMDiskVolume) - bvr1 = gRAMDiskVolume; - } - else if (biosdev == kPseudoBIOSDevBooter) - { - if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) + // Try resolving "rd" and "bt" devices first. + if (biosdev == kPseudoBIOSDevRAMDisk) { + if (gRAMDiskVolume) { bvr1 = gRAMDiskVolume; - else + } + } else if (biosdev == kPseudoBIOSDevBooter) { + if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) { + bvr1 = gRAMDiskVolume; + } else { bvr1 = gBIOSBootVolume; - } - else - { + } + } else { // Fetch the volume list from the device. scanBootVolumes( biosdev, NULL ); @@ -1054,12 +1125,15 @@ // 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 ) continue; + for ( bvr1 = NULL, bvr = bvrChain; bvr; bvr = bvr->next ) { + if ( ( bvr->flags & kBVFlagNativeBoot ) == 0 ) { + continue; + } bvr1 = bvr; - if ( bvr->part_no == partno ) break; + if ( bvr->part_no == partno ) { + break; + } } } @@ -1072,20 +1146,21 @@ // Returns length of the out string int getDeviceDescription(BVRef bvr, char *str) { - if(!str) - return 0; + if(!str) { + return 0; + } *str = '\0'; - if (bvr) - { - const struct devsw *dp = devsw; - while(dp->name && bvr->biosdev >= dp->biosdev) - dp++; - + if (bvr) { + const struct devsw *dp = devsw; + while(dp->name && bvr->biosdev >= dp->biosdev) { + dp++; + } dp--; - if (dp->name) - return sprintf(str, "%s(%d,%d)", dp->name, bvr->biosdev - dp->biosdev, bvr->part_no); + if (dp->name) { + return sprintf(str, "%s(%d,%d)", dp->name, bvr->biosdev - dp->biosdev, bvr->part_no); + } } return 0; Index: trunk/i386/libsaio/load.c =================================================================== --- trunk/i386/libsaio/load.c (revision 2330) +++ trunk/i386/libsaio/load.c (revision 2331) @@ -41,249 +41,266 @@ bool gHaveKernelCache; /* XXX aserebln: uninitialized? and only set to true, never to false */ cpu_type_t archCpuType=CPU_TYPE_I386; -// Public Functions +//============================================================================== +// Public function. + long ThinFatFile(void **binary, unsigned long *length) { - unsigned long nfat, swapped, size = 0; - struct fat_header *fhp = (struct fat_header *)*binary; - struct fat_arch *fap = - (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header)); - cpu_type_t fapcputype; - uint32_t fapoffset; - uint32_t fapsize; + unsigned long nfat, swapped, size = 0; + struct fat_header *fhp = (struct fat_header *)*binary; + struct fat_arch *fap = (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header)); + cpu_type_t fapcputype; + uint32_t fapoffset; + uint32_t fapsize; - if (fhp->magic == FAT_MAGIC) { - nfat = fhp->nfat_arch; - swapped = 0; - } else if (fhp->magic == FAT_CIGAM) { - nfat = OSSwapInt32(fhp->nfat_arch); - swapped = 1; - } else { - return -1; - } - - for (; nfat > 0; nfat--, fap++) { - if (swapped) { - fapcputype = OSSwapInt32(fap->cputype); - fapoffset = OSSwapInt32(fap->offset); - fapsize = OSSwapInt32(fap->size); - } - else - { - fapcputype = fap->cputype; - fapoffset = fap->offset; - fapsize = fap->size; + if (fhp->magic == FAT_MAGIC) { + nfat = fhp->nfat_arch; + swapped = 0; + } else if (fhp->magic == FAT_CIGAM) { + nfat = OSSwapInt32(fhp->nfat_arch); + swapped = 1; + } else { + return -1; } - - if (fapcputype == archCpuType) { - *binary = (void *) ((unsigned long)*binary + fapoffset); - size = fapsize; - break; - } - } - - if (length != 0) *length = size; - - return 0; + + for (; nfat > 0; nfat--, fap++) { + if (swapped) { + fapcputype = OSSwapInt32(fap->cputype); + fapoffset = OSSwapInt32(fap->offset); + fapsize = OSSwapInt32(fap->size); + } else { + fapcputype = fap->cputype; + fapoffset = fap->offset; + fapsize = fap->size; + } + + if (fapcputype == archCpuType) { + *binary = (void *) ((unsigned long)*binary + fapoffset); + size = fapsize; + break; + } + } + + if (length != 0) { + *length = size; + } + + return 0; } + +//============================================================================== + long DecodeMachO(void *binary, entry_t *rentry, char **raddr, int *rsize) { - struct mach_header *mH; - unsigned long ncmds, cmdBase, cmd, cmdsize, cmdstart; - // long headerBase, headerAddr, headerSize; - unsigned int vmaddr = ~0; - unsigned int vmend = 0; - unsigned long cnt; - long ret = -1; - unsigned int entry = 0; - - gBinaryAddress = (unsigned long)binary; - - mH = (struct mach_header *)(gBinaryAddress); - switch (archCpuType) + struct mach_header *mH; + unsigned long ncmds, cmdBase, cmd, cmdsize, cmdstart; + // long headerBase, headerAddr, headerSize; + unsigned int vmaddr = ~0; + unsigned int vmend = 0; + unsigned long cnt; + long ret = -1; + unsigned int entry = 0; + + gBinaryAddress = (unsigned long)binary; + + mH = (struct mach_header *)(gBinaryAddress); + +#if DEBUG + printf("magic: %x\n", (unsigned)mH->magic); + printf("cputype: %x\n", (unsigned)mH->cputype); + printf("cpusubtype: %x\n", (unsigned)mH->cpusubtype); + printf("filetype: %x\n", (unsigned)mH->filetype); + printf("ncmds: %x\n", (unsigned)mH->ncmds); + printf("sizeofcmds: %x\n", (unsigned)mH->sizeofcmds); + printf("flags: %x\n", (unsigned)mH->flags); + getchar(); +#endif + + switch (archCpuType) { case CPU_TYPE_I386: + if (mH->magic != MH_MAGIC) { error("Mach-O file has bad magic number\n"); return -1; } + cmdstart = (unsigned long)gBinaryAddress + sizeof(struct mach_header); break; + case CPU_TYPE_X86_64: - if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC) + + if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC) { return -1; + } + if (mH->magic != MH_MAGIC_64) { error("Mach-O file has bad magic number\n"); return -1; } + cmdstart = (unsigned long)gBinaryAddress + sizeof(struct mach_header_64); break; + default: + error("Unknown CPU type\n"); return -1; } - - cmdBase = cmdstart; -#if DEBUG - printf("magic: %x\n", (unsigned)mH->magic); - printf("cputype: %x\n", (unsigned)mH->cputype); - printf("cpusubtype: %x\n", (unsigned)mH->cpusubtype); - printf("filetype: %x\n", (unsigned)mH->filetype); - printf("ncmds: %x\n", (unsigned)mH->ncmds); - printf("sizeofcmds: %x\n", (unsigned)mH->sizeofcmds); - printf("flags: %x\n", (unsigned)mH->flags); - getchar(); -#endif - - ncmds = mH->ncmds; - - for (cnt = 0; cnt < ncmds; cnt++) { - cmd = ((long *)cmdBase)[0]; - cmdsize = ((long *)cmdBase)[1]; - unsigned int load_addr; - unsigned int load_size; - - switch (cmd) { - case LC_SEGMENT_64: - case LC_SEGMENT: - ret = DecodeSegment(cmdBase, &load_addr, &load_size); - if (ret == 0 && load_size != 0 && load_addr >= KERNEL_ADDR) { - vmaddr = MIN(vmaddr, load_addr); - vmend = MAX(vmend, load_addr + load_size); - } - break; - - case LC_UNIXTHREAD: - ret = DecodeUnixThread(cmdBase, &entry); - break; + cmdBase = cmdstart; + ncmds = mH->ncmds; - case LC_SYMTAB: - break; - - default: + for (cnt = 0; cnt < ncmds; cnt++) + { + cmd = ((long *)cmdBase)[0]; + cmdsize = ((long *)cmdBase)[1]; + unsigned int load_addr; + unsigned int load_size; + + switch (cmd) { + case LC_SEGMENT_64: + case LC_SEGMENT: + ret = DecodeSegment(cmdBase, &load_addr, &load_size); + + if (ret == 0 && load_size != 0 && load_addr >= KERNEL_ADDR) + { + vmaddr = MIN(vmaddr, load_addr); + vmend = MAX(vmend, load_addr + load_size); + } + break; + + case LC_UNIXTHREAD: + ret = DecodeUnixThread(cmdBase, &entry); + break; + + case LC_SYMTAB: + break; + + default: #if NOTDEF - printf("Ignoring cmd type %d.\n", (unsigned)cmd); + printf("Ignoring cmd type %d.\n", (unsigned)cmd); #endif - break; - } - - if (ret != 0) return -1; - - cmdBase += cmdsize; - } - - *rentry = (entry_t)( (unsigned long) entry & 0x3fffffff ); - *rsize = vmend - vmaddr; - *raddr = (char *)vmaddr; - - cmdBase = cmdstart; - for (cnt = 0; cnt < ncmds; cnt++) { + break; + } + + + if (ret != 0) { + return -1; + } + + cmdBase += cmdsize; + } + + *rentry = (entry_t)( (unsigned long) entry & 0x3fffffff ); + *rsize = vmend - vmaddr; + *raddr = (char *)vmaddr; + + cmdBase = cmdstart; + + for (cnt = 0; cnt < ncmds; cnt++) { cmd = ((long *)cmdBase)[0]; cmdsize = ((long *)cmdBase)[1]; - if(cmd==LC_SYMTAB) - if (DecodeSymbolTable(cmdBase)!=0) - return -1; - - cmdBase += cmdsize; - } + if (cmd == LC_SYMTAB) { + if (DecodeSymbolTable(cmdBase) != 0) { + return -1; + } + } + + cmdBase += cmdsize; + } - return ret; + return ret; } -// Private Functions +//============================================================================== +// Private function. + + static long DecodeSegment(long cmdBase, unsigned int *load_addr, unsigned int *load_size) { - unsigned long vmaddr, fileaddr; - long vmsize, filesize; - char *segname; - - if (((long *)cmdBase)[0]==LC_SEGMENT_64) - { - struct segment_command_64 *segCmd; - - segCmd = (struct segment_command_64 *)cmdBase; - - vmaddr = (segCmd->vmaddr & 0x3fffffff); - vmsize = segCmd->vmsize; - fileaddr = (gBinaryAddress + segCmd->fileoff); - filesize = segCmd->filesize; + char *segname; + long vmsize, filesize; + unsigned long vmaddr, fileaddr; - segname=segCmd->segname; + if (((long *)cmdBase)[0] == LC_SEGMENT_64) { + struct segment_command_64 *segCmd; + segCmd = (struct segment_command_64 *)cmdBase; + vmaddr = (segCmd->vmaddr & 0x3fffffff); + vmsize = segCmd->vmsize; + fileaddr = (gBinaryAddress + segCmd->fileoff); + filesize = segCmd->filesize; + segname = segCmd->segname; #ifdef DEBUG printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags); getchar(); -#endif - } - else - { - struct segment_command *segCmd; +#endif + } else { + struct segment_command *segCmd; - segCmd = (struct segment_command *)cmdBase; - - vmaddr = (segCmd->vmaddr & 0x3fffffff); - vmsize = segCmd->vmsize; - fileaddr = (gBinaryAddress + segCmd->fileoff); - filesize = segCmd->filesize; - - segname=segCmd->segname; + segCmd = (struct segment_command *)cmdBase; + vmaddr = (segCmd->vmaddr & 0x3fffffff); + vmsize = segCmd->vmsize; + fileaddr = (gBinaryAddress + segCmd->fileoff); + filesize = segCmd->filesize; + segname = segCmd->segname; + #ifdef DEBUG - printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", - segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, - (unsigned) segCmd->nsects, (unsigned)segCmd->flags); - getchar(); -#endif - } + printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", + segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags); + getchar(); +#endif + } - if (vmsize == 0 || filesize == 0) { - *load_addr = ~0; - *load_size = 0; - return 0; - } - - if (! ((vmaddr >= KERNEL_ADDR && - (vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) || - (vmaddr >= HIB_ADDR && - (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) { - stop("Kernel overflows available space"); - } - - if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) - gHaveKernelCache = true; - - // Copy from file load area. - if (vmsize>0 && filesize>0) - bcopy((char *)fileaddr, (char *)vmaddr, vmsize>filesize?filesize:vmsize); - - // Zero space at the end of the segment. - if (vmsize > filesize) - bzero((char *)(vmaddr + filesize), vmsize - filesize); + if (vmsize == 0 || filesize == 0) { + *load_addr = ~0; + *load_size = 0; + return 0; + } - *load_addr = vmaddr; - *load_size = vmsize; + if (! ((vmaddr >= KERNEL_ADDR && (vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) || + (vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) { + stop("Kernel overflows available space"); + } - return 0; + if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) { + gHaveKernelCache = true; + } + + // Copy from file load area. + if (vmsize>0 && filesize > 0) { + bcopy((char *)fileaddr, (char *)vmaddr, vmsize > filesize ? filesize : vmsize); + } + + // Zero space at the end of the segment. + if (vmsize > filesize) { + bzero((char *)(vmaddr + filesize), vmsize - filesize); + } + + *load_addr = vmaddr; + *load_size = vmsize; + + return 0; } +//============================================================================== + static long DecodeUnixThread(long cmdBase, unsigned int *entry) { - switch (archCpuType) - { + switch (archCpuType) { case CPU_TYPE_I386: { i386_thread_state_t *i386ThreadState; - - i386ThreadState = (i386_thread_state_t *) - (cmdBase + sizeof(struct thread_command) + 8); - + i386ThreadState = (i386_thread_state_t *) (cmdBase + sizeof(struct thread_command) + 8); + *entry = i386ThreadState->eip; return 0; } @@ -291,10 +308,7 @@ case CPU_TYPE_X86_64: { x86_thread_state64_t *x86_64ThreadState; - - x86_64ThreadState = (x86_thread_state64_t *) - (cmdBase + sizeof(struct thread_command) + 8); - + x86_64ThreadState = (x86_thread_state64_t *) (cmdBase + sizeof(struct thread_command) + 8); *entry = x86_64ThreadState->rip; return 0; } @@ -305,38 +319,42 @@ } } + +//============================================================================== + static long DecodeSymbolTable(long cmdBase) { - struct symtab_command *symTab, *symTableSave; - long tmpAddr, symsSize, totalSize; - long gSymbolTableAddr; - long gSymbolTableSize; + long tmpAddr, symsSize, totalSize; + long gSymbolTableAddr; + long gSymbolTableSize; - symTab = (struct symtab_command *)cmdBase; - + struct symtab_command *symTab, *symTableSave; + + symTab = (struct symtab_command *)cmdBase; + #if DEBUG - printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n", - symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize); - getchar(); + + printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n", symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize); + getchar(); #endif - - symsSize = symTab->stroff - symTab->symoff; - totalSize = symsSize + symTab->strsize; - - gSymbolTableSize = totalSize + sizeof(struct symtab_command); - gSymbolTableAddr = AllocateKernelMemory(gSymbolTableSize); - // Add the SymTab to the memory-map. - AllocateMemoryRange("Kernel-__SYMTAB", gSymbolTableAddr, gSymbolTableSize, -1); - - symTableSave = (struct symtab_command *)gSymbolTableAddr; - tmpAddr = gSymbolTableAddr + sizeof(struct symtab_command); - - symTableSave->symoff = tmpAddr; - symTableSave->nsyms = symTab->nsyms; - symTableSave->stroff = tmpAddr + symsSize; - symTableSave->strsize = symTab->strsize; + + symsSize = symTab->stroff - symTab->symoff; + totalSize = symsSize + symTab->strsize; + + gSymbolTableSize = totalSize + sizeof(struct symtab_command); + gSymbolTableAddr = AllocateKernelMemory(gSymbolTableSize); + // Add the SymTab to the memory-map. + AllocateMemoryRange("Kernel-__SYMTAB", gSymbolTableAddr, gSymbolTableSize, -1); + + symTableSave = (struct symtab_command *)gSymbolTableAddr; + tmpAddr = gSymbolTableAddr + sizeof(struct symtab_command); + + symTableSave->symoff = tmpAddr; + symTableSave->nsyms = symTab->nsyms; + symTableSave->stroff = tmpAddr + symsSize; + symTableSave->strsize = symTab->strsize; - bcopy((char *)(gBinaryAddress + symTab->symoff), - (char *)tmpAddr, totalSize); - return 0; + bcopy((char *)(gBinaryAddress + symTab->symoff), (char *)tmpAddr, totalSize); + + return 0; } Index: trunk/i386/libsaio/nvidia.h =================================================================== --- trunk/i386/libsaio/nvidia.h (revision 2330) +++ trunk/i386/libsaio/nvidia.h (revision 2331) @@ -77,13 +77,13 @@ uint8_t size; /* Size in multiples of 512 */ }; -#define NV_PMC_OFFSET 0x000000 -#define NV_PMC_SIZE 0x2ffff +#define NV_PMC_OFFSET 0x00000000 +#define NV_PMC_SIZE 0x00001000 // 0x2ffff #define NV_PDISPLAY_OFFSET 0x610000 #define NV_PDISPLAY_SIZE 0x10000 -#define NV_PROM_OFFSET 0x300000 -#define NV_PROM_SIZE 0x0000ffff +#define NV_PROM_OFFSET 0x00300000 +#define NV_PROM_SIZE 0x00010000 #define NV_PRAMIN_OFFSET 0x00700000 #define NV_PRAMIN_SIZE 0x00100000 #define NV04_PFB_FIFO_DATA 0x0010020c Index: trunk/i386/libsaio/sl.h =================================================================== --- trunk/i386/libsaio/sl.h (revision 2330) +++ trunk/i386/libsaio/sl.h (revision 2331) @@ -39,22 +39,22 @@ // File Permissions and Types enum { - kPermOtherExecute = 1 << 0, - kPermOtherWrite = 1 << 1, - kPermOtherRead = 1 << 2, - kPermGroupExecute = 1 << 3, - kPermGroupWrite = 1 << 4, - kPermGroupRead = 1 << 5, - kPermOwnerExecute = 1 << 6, - kPermOwnerWrite = 1 << 7, - kPermOwnerRead = 1 << 8, - kPermMask = 0x1FF, - kOwnerNotRoot = 1 << 9, - kFileTypeUnknown = 0x0 << 16, - kFileTypeFlat = 0x1 << 16, - kFileTypeDirectory = 0x2 << 16, - kFileTypeLink = 0x3 << 16, - kFileTypeMask = 0x3 << 16 + kPermOtherExecute = 1 << 0, + kPermOtherWrite = 1 << 1, + kPermOtherRead = 1 << 2, + kPermGroupExecute = 1 << 3, + kPermGroupWrite = 1 << 4, + kPermGroupRead = 1 << 5, + kPermOwnerExecute = 1 << 6, + kPermOwnerWrite = 1 << 7, + kPermOwnerRead = 1 << 8, + kPermMask = 0x1FF, + kOwnerNotRoot = 1 << 9, + kFileTypeUnknown = 0x0 << 16, + kFileTypeFlat = 0x1 << 16, + kFileTypeDirectory = 0x2 << 16, + kFileTypeLink = 0x3 << 16, + kFileTypeMask = 0x3 << 16 }; #define Seek(c, p) diskSeek(c, p); Index: trunk/i386/libsaio/cpu.c =================================================================== --- trunk/i386/libsaio/cpu.c (revision 2330) +++ trunk/i386/libsaio/cpu.c (revision 2331) @@ -415,8 +415,7 @@ tscFrequency = measure_tsc_frequency(); /* if usual method failed */ - if ( tscFrequency < 1000 )//TEST - { + if ( tscFrequency < 1000 ) { //TEST tscFrequency = timeRDTSC() * 20; } fsbFrequency = 0; @@ -648,8 +647,7 @@ } #if 0 - if (!fsbFrequency) - { + if (!fsbFrequency) { fsbFrequency = (DEFAULT_FSB * 1000); cpuFrequency = tscFrequency; DBG("0 ! using the default value for FSB !\n"); Index: trunk/i386/libsaio/platform.h =================================================================== --- trunk/i386/libsaio/platform.h (revision 2330) +++ trunk/i386/libsaio/platform.h (revision 2331) @@ -177,7 +177,7 @@ int DIMM[MAX_RAM_SLOTS]; // Information and SPD mapping for each slot } DMI; - uint8_t Type; // System Type: 1=Desktop, 2=Portable... according ACPI2.0 (FACP: PM_Profile) + uint8_t Type; // System Type: 1=Desktop, 2=Portable... according ACPI2.0 (FACP: PM_Profile) uint8_t *UUID; } PlatformInfo_t; Index: trunk/i386/libsaio/disk.c =================================================================== --- trunk/i386/libsaio/disk.c (revision 2330) +++ trunk/i386/libsaio/disk.c (revision 2331) @@ -222,6 +222,9 @@ { 0x00, 0 } }; + +//============================================================================== + static const char * bios_error(int errnum) { static char errorstr[] = "Error 0x00"; Index: trunk/i386/libsaio/openbsd.c =================================================================== --- trunk/i386/libsaio/openbsd.c (revision 2330) +++ trunk/i386/libsaio/openbsd.c (revision 2331) @@ -3,10 +3,11 @@ #include "openbsd.h" #define OpenBSDProbeSize 2048 +#define DISKMAGIC ((uint32_t)0x82564557) /* The disk magic number */ bool OpenBSDProbe (const void *buf) { - return (OSReadLittleInt32(buf+0x200,0)==0x82564557); + return (OSReadLittleInt32(buf+0x200,0) == DISKMAGIC); } void OpenBSDGetDescription(CICell ih, char *str, long strMaxLen) { Index: trunk/i386/libsaio/smbios.c =================================================================== --- trunk/i386/libsaio/smbios.c (revision 2330) +++ trunk/i386/libsaio/smbios.c (revision 2331) @@ -722,25 +722,19 @@ int len; char key[24]; - if (current != structHeader->handle) - { + if (current != structHeader->handle) { idx++; current = structHeader->handle; } sprintf(key, "%s%d", keyString, idx); - if (value) - { - if (getIntForKey(key, (int *)&(value->dword), SMBPlist)) - { + if (value) { + if (getIntForKey(key, (int *)&(value->dword), SMBPlist)) { return true; } - } - else - { - if (getValueForKey(key, string, &len, SMBPlist)) - { + } else { + if (getValueForKey(key, string, &len, SMBPlist)) { return true; } } @@ -751,8 +745,7 @@ { uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length; - if (!field) - { + if (!field) { return NULL; } @@ -766,13 +759,11 @@ { int strSize; - if (!field) - { + if (!field) { return; } - if (!string) - { + if (!string) { *field = 0; return; } @@ -780,13 +771,11 @@ strSize = strlen(string); // remove any spaces found at the end - while ((strSize != 0) && (string[strSize - 1] == ' ')) - { + while ((strSize != 0) && (string[strSize - 1] == ' ')) { strSize--; } - if (strSize == 0) - { + if (strSize == 0) { *field = 0; return; } @@ -805,13 +794,11 @@ bool parsed; int val; - if (numOfSetters <= idx) - { + if (numOfSetters <= idx) { return false; } - switch (SMBSetters[idx].valueType) - { + switch (SMBSetters[idx].valueType) { case kSMBString: { if (SMBSetters[idx].keyString) @@ -832,16 +819,13 @@ } } - if (SMBSetters[idx].getSMBValue) - { - if (SMBSetters[idx].getSMBValue((returnType *)&string)) - { + if (SMBSetters[idx].getSMBValue) { + if (SMBSetters[idx].getSMBValue((returnType *)&string)) { break; } } // if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) Bungo - if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue)) - { + if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue)) { string = *(SMBSetters[idx].defaultValue); break; } @@ -852,20 +836,16 @@ case kSMBWord: case kSMBDWord: //case kSMBQWord: - if (SMBSetters[idx].keyString) - { + if (SMBSetters[idx].keyString) { parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist); if (!parsed) { - if (structPtr->orig->type == kSMBTypeMemoryDevice) // MemoryDevice only - { + if (structPtr->orig->type == kSMBTypeMemoryDevice) { // MemoryDevice only parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val); } } - if (parsed) - { - switch (SMBSetters[idx].valueType) - { + if (parsed) { + switch (SMBSetters[idx].valueType) { case kSMBByte: value->byte = (uint8_t)val; break; @@ -881,10 +861,8 @@ } } - if (SMBSetters[idx].getSMBValue) - { - if (SMBSetters[idx].getSMBValue(value)) - { + if (SMBSetters[idx].getSMBValue) { + if (SMBSetters[idx].getSMBValue(value)) { return true; } } @@ -893,8 +871,7 @@ if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue)) { // value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo - switch (SMBSetters[idx].valueType) - { + switch (SMBSetters[idx].valueType) { case kSMBByte: value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue); break; @@ -913,8 +890,7 @@ } // if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified" - if ((SMBSetters[idx].valueType == kSMBString) && string) - { + if ((SMBSetters[idx].valueType == kSMBString) && string) { setSMBStringForField(structPtr->new, string, &value->byte); } return true; @@ -1020,11 +996,9 @@ /* http://forge.voodooprojects.org/p/chameleon/issues/361/ */ bool forceFullMemInfo = false; - if (structPtr->orig->type == kSMBTypeMemoryDevice) - { + if (structPtr->orig->type == kSMBTypeMemoryDevice) { getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig); - if (forceFullMemInfo) - { + if (forceFullMemInfo) { structPtr->orig->length = 27; } } @@ -1032,40 +1006,32 @@ stringIndex = 1; stringsSize = 0; - if (handle < structPtr->orig->handle) - { + if (handle < structPtr->orig->handle) { handle = structPtr->orig->handle; } memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length); - for (i = 0; i < numOfSetters; i++) - { - if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length)) - { + for (i = 0; i < numOfSetters; i++) { + if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length)) { setterFound = true; setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset)); } } - if (setterFound) - { + if (setterFound) { ptr = (uint8_t *)structPtr->new + structPtr->orig->length; for (; ((uint16_t *)ptr)[0] != 0; ptr++); - if (((uint16_t *)ptr)[0] == 0) - { + if (((uint16_t *)ptr)[0] == 0) { ptr += 2; } structSize = ptr - (uint8_t *)structPtr->new; - } - else - { + } else { ptr = (uint8_t *)structPtr->orig + structPtr->orig->length; for (; ((uint16_t *)ptr)[0] != 0; ptr++); - if (((uint16_t *)ptr)[0] == 0) - { + if (((uint16_t *)ptr)[0] == 0) { ptr += 2; } @@ -1077,8 +1043,7 @@ tableLength += structSize; - if (structSize > maxStructSize) - { + if (structSize > maxStructSize) { maxStructSize = structSize; } @@ -1090,10 +1055,8 @@ uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress; structPtr->orig = (SMBStructHeader *)ptr; - for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));) - { - switch (structPtr->orig->type) - { + for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));) { + switch (structPtr->orig->type) { /* Skip all Apple Specific Structures */ case kSMBTypeFirmwareVolume: case kSMBTypeMemorySPD: @@ -1114,8 +1077,7 @@ ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length); for (; ((uint16_t *)ptr)[0] != 0; ptr++); - if (((uint16_t *)ptr)[0] == 0) - { + if (((uint16_t *)ptr)[0] == 0) { ptr += 2; } @@ -1145,8 +1107,7 @@ 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; } @@ -1155,27 +1116,23 @@ ptr = ((SMBSystemInformation *)structHeader)->uuid; - if (!sysId || !ret) // no or bad custom UUID,... - { + if (!sysId || !ret) { // no or bad custom UUID,... sysId = 0; ret = ((SMBSystemInformation *)structHeader)->uuid; // ...try bios dmi info UUID extraction } for (i=0, isZero=1, isOnes=1; idmi.structureCount = structureCount; neweps->dmi.bcdRevision = 0x24; - if (!neweps->dmi.tableAddress) - { + if (!neweps->dmi.tableAddress) { free(buffer); free(structPtr); return; @@ -1276,11 +1228,9 @@ void *getSmbios(int which) { - switch (which) - { + switch (which) { case SMBIOS_ORIGINAL: - if (!origeps) - { + if (!origeps) { origeps = getAddressOfSmbiosTable(); } return origeps; @@ -1338,12 +1288,10 @@ case kSMBTypeMemoryDevice: Platform.DMI.CntMemorySlots++; - if (((SMBMemoryDevice *)structHeader)->memorySize != 0) - { + if (((SMBMemoryDevice *)structHeader)->memorySize != 0) { Platform.DMI.MemoryModules++; } - if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0) - { + if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0) { Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed; } dimmnbr++; @@ -1355,8 +1303,7 @@ structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length); for (; ((uint16_t *)structPtr)[0] != 0; structPtr++); - if (((uint16_t *)structPtr)[0] == 0) - { + if (((uint16_t *)structPtr)[0] == 0) { structPtr += 2; } Index: trunk/i386/libsaio/openbsd.h =================================================================== --- trunk/i386/libsaio/openbsd.h (revision 2330) +++ trunk/i386/libsaio/openbsd.h (revision 2331) @@ -1,2 +1,7 @@ +#ifndef __LIBSAIO_OPENBSD_H +#define __LIBSAIO_OPENBSD_H + extern bool OpenBSDProbe (const void *buf); -extern void OpenBSDGetDescription(CICell ih, char *str, long strMaxLen); \ No newline at end of file +extern void OpenBSDGetDescription(CICell ih, char *str, long strMaxLen); + +#endif /* !__LIBSAIO_OPENBSD_H */ Index: trunk/i386/libsaio/smbios_decode.c =================================================================== --- trunk/i386/libsaio/smbios_decode.c (revision 2330) +++ trunk/i386/libsaio/smbios_decode.c (revision 2331) @@ -329,8 +329,7 @@ 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/nvidia_helper.c =================================================================== --- trunk/i386/libsaio/nvidia_helper.c (revision 2330) +++ trunk/i386/libsaio/nvidia_helper.c (revision 2331) @@ -15,35 +15,35 @@ NVIDIA card injection usage e.g (to be placed in the boot.plist): NVIDIA - - - Chipset Name - Quadro FX 380 - IOPCIPrimaryMatch - 0x10DE0658 - VRam Size - 256 - - - Chipset Name - YOUR_CARD_NAME - IOPCIPrimaryMatch - YOUR_CARD_ID - IOPCISubDevId - YOUR_CARD_SUB_ID(if necessary) - VRam Size - YOUR_CARD_VRAM_SIZE - - - Chipset Name - YOUR_SECOND_CARD_NAME - IOPCIPrimaryMatch - YOUR_SECOND_CARD_ID - IOPCISubDevId - YOUR_SECOND_CARD_SUB_ID(if necessary) - VRam Size - YOUR_SECOND_CARD_VRAM_SIZE - + + + Chipset Name + Quadro FX 380 + IOPCIPrimaryMatch + 0x10DE0658 + VRam Size + 256 + + + Chipset Name + YOUR_CARD_NAME + IOPCIPrimaryMatch + YOUR_CARD_ID + IOPCISubDevId + YOUR_CARD_SUB_ID(if necessary) + VRam Size + YOUR_CARD_VRAM_SIZE + + + Chipset Name + YOUR_SECOND_CARD_NAME + IOPCIPrimaryMatch + YOUR_SECOND_CARD_ID + IOPCISubDevId + YOUR_SECOND_CARD_SUB_ID(if necessary) + VRam Size + YOUR_SECOND_CARD_VRAM_SIZE + . . . @@ -110,7 +110,7 @@ unsigned int i, count; TagPtr NVDIATag; char *model_name = NULL, *match_id = NULL, *sub_id = NULL, *vram_size = NULL; - uint32_t dev_id = 0, subdev_id = 0; + uint32_t dev_id = 0, subdev_id = 0; uint64_t VramSize = 0; if ((NVDIATag = XMLCastArray(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"NVIDIA")))) Index: trunk/i386/libsaio/freebsd.h =================================================================== --- trunk/i386/libsaio/freebsd.h (revision 2330) +++ trunk/i386/libsaio/freebsd.h (revision 2331) @@ -1,2 +1,7 @@ +#ifndef __LIBSAIO_FREEBSD_H +#define __LIBSAIO_FREEBSD_H + extern bool FreeBSDProbe (const void *buf); -extern void FreeBSDGetDescription(CICell ih, char *str, long strMaxLen); \ No newline at end of file +extern void FreeBSDGetDescription(CICell ih, char *str, long strMaxLen); + +#endif /* !__LIBSAIO_FREEBSD_H */ Index: trunk/i386/libsaio/convert.c =================================================================== --- trunk/i386/libsaio/convert.c (revision 2330) +++ trunk/i386/libsaio/convert.c (revision 2331) @@ -93,11 +93,10 @@ { hexNibble = hexStr[hexStrIdx]; - // ignore all chars except valid hex numbers - if ( (hexNibble >= '0' && hexNibble <= '9') || - (hexNibble >= 'A' && hexNibble <= 'F') || - (hexNibble >= 'a' && hexNibble <= 'f') ) - { + // 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 Index: trunk/i386/libsaio/pci.h =================================================================== --- trunk/i386/libsaio/pci.h (revision 2330) +++ trunk/i386/libsaio/pci.h (revision 2331) @@ -30,8 +30,10 @@ } pci_dev_t; typedef struct pci_dt_t { + uint8_t* regs; pci_dev_t dev; + uint16_t devfn; /* encoded device & function index */ uint16_t vendor_id; /* Specifies a vendor ID. The PCI bus configuration code obtains this vendor ID from the vendor ID device register. */ uint16_t device_id; /* Specifies a device ID that identifies the specific device. The PCI @@ -52,11 +54,15 @@ uint16_t class_id; /* Specifies a class code. This member is a data structure that stores information related to the device's class code device register. */ + //uint16_t subclass_id; /* A read-only register that specifies the specific function the device performs. */ + struct pci_dt_t *parent; struct pci_dt_t *children; struct pci_dt_t *next; -} pci_dt_t; +} pci_dt_t; // Info +/* Have pci_addr in the same format as the values written to 0xcf8 + * so register accesses can be made easy. */ #define PCIADDR(bus, dev, func) ((1 << 31) | (bus << 16) | (dev << 11) | (func << 8)) #define PCI_ADDR_REG 0xcf8 #define PCI_DATA_REG 0xcfc @@ -65,12 +71,12 @@ extern uint8_t pci_config_read8(uint32_t, uint8_t); extern uint16_t pci_config_read16(uint32_t, uint8_t); extern uint32_t pci_config_read32(uint32_t, uint8_t); -extern void pci_config_write8(uint32_t, uint8_t, uint8_t); -extern void pci_config_write16(uint32_t, uint8_t, uint16_t); -extern void pci_config_write32(uint32_t, uint8_t, uint32_t); -extern char *get_pci_dev_path(pci_dt_t *); -extern void build_pci_dt(void); -extern void dump_pci_dt(pci_dt_t *); +extern void pci_config_write8(uint32_t, uint8_t, uint8_t); +extern void pci_config_write16(uint32_t, uint8_t, uint16_t); +extern void pci_config_write32(uint32_t, uint8_t, uint32_t); +extern char *get_pci_dev_path(pci_dt_t *); +extern void build_pci_dt(void); +extern void dump_pci_dt(pci_dt_t *); /* Option ROM header */ typedef struct { Index: trunk/i386/libsaio/msdos.c =================================================================== --- trunk/i386/libsaio/msdos.c (revision 2330) +++ trunk/i386/libsaio/msdos.c (revision 2331) @@ -130,7 +130,7 @@ if (!memcmp((char *)((struct extboot *)bsp->bs50.bsExt)->exFileSysType, "FAT12 ", 8)) return 12; } - + return 0; } @@ -188,9 +188,7 @@ 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); @@ -775,15 +773,14 @@ char *ptr = (char *)base; struct direntry *dirp; uint64_t i; - char devStr[12]; + char devStr[12]; if (MSDOSInitPartition (ih)<0) return -1; if (filePath[0] == '/') filePath++; buf = malloc(msdosclustersize); - if (!buf) - { + if (!buf) { return -1; } dirp = getdirpfrompath (ih, filePath, buf); @@ -797,8 +794,7 @@ 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; } @@ -840,8 +836,7 @@ if (filePath[0] == '/') filePath++; buf = malloc(msdosclustersize); - if (!buf) - { + if (!buf) { return -1; } dirp = getdirpfrompath (ih, filePath, buf); @@ -936,8 +931,7 @@ initRoot (&st); st.buf = malloc(msdosclustersize); - if (!st.buf) - { + if (!st.buf) { return; } while ((dirp = getnextdirent (ih, vfatlabel, &st))) @@ -946,7 +940,7 @@ labelfound = 1; break; } - + free(st.buf); if (vfatlabel[0] && labelfound) @@ -969,9 +963,7 @@ 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) @@ -989,12 +981,11 @@ 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/md5c.c =================================================================== --- trunk/i386/libsaio/md5c.c (revision 2330) +++ trunk/i386/libsaio/md5c.c (revision 2331) @@ -1,6 +1,34 @@ /* - * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm + * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. * + * @APPLE_OSREFERENCE_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. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * 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, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * 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_OSREFERENCE_LICENSE_HEADER_END@ + */ + +/* + * MD5.C - RSA Data Security, Inc., MD5 message-digest algorithm + * * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All * rights reserved. * @@ -35,40 +63,50 @@ #define Encode memcpy #define Decode memcpy +//------------------------------------------------------------------------------ + static unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -/* F, G, H and I are basic MD5 functions. */ + +//------------------------------------------------------------------------------ +// F, G, H and I are basic MD5 functions. + #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) #define H(x, y, z) ((x) ^ (y) ^ (z)) #define I(x, y, z) ((y) ^ ((x) | (~z))) -/* ROTATE_LEFT rotates x left n bits. */ +//------------------------------------------------------------------------------ +// ROTATE_LEFT rotates x left n bits. + #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) -/* - * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. - * Rotation is separate from addition to prevent recomputation. - */ +//------------------------------------------------------------------------------ +// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. +// Rotation is separate from addition to prevent recomputation. + #define FF(a, b, c, d, x, s, ac) { \ (a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } + #define GG(a, b, c, d, x, s, ac) { \ (a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } + #define HH(a, b, c, d, x, s, ac) { \ (a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } + #define II(a, b, c, d, x, s, ac) { \ (a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ @@ -79,14 +117,12 @@ /* MD5 initialization. Begins an MD5 operation, writing a new context. */ -void -MD5Init (context) +void MD5Init (context) MD5_CTX *context; { - context->count[0] = context->count[1] = 0; - /* Load magic initialization constants. */ + // Load magic initialization constants. context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; @@ -115,26 +151,28 @@ index = (unsigned int)((context->count[0] >> 3) & 0x3F); /* Update number of bits */ - if ((context->count[0] += ((u_int32_t)inputLen << 3)) - < ((u_int32_t)inputLen << 3)) + if ((context->count[0] += ((u_int32_t)inputLen << 3)) < ((u_int32_t)inputLen << 3)) { context->count[1]++; + } + context->count[1] += ((u_int32_t)inputLen >> 29); partLen = 64 - index; /* Transform as many times as possible. */ + if (inputLen >= partLen) { memcpy((void *)&context->buffer[index], (const void *)input, partLen); MD5Transform (context->state, context->buffer); - for (i = partLen; i + 63 < inputLen; i += 64) + for (i = partLen; i + 63 < inputLen; i += 64) { MD5Transform (context->state, &((const unsigned char *)input)[i]); - + } index = 0; + } else { + i = 0; } - else - i = 0; /* Buffer remaining input */ memcpy ((void *)&context->buffer[index], (const void *)&((const unsigned char*)input)[i], @@ -227,7 +265,7 @@ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ - GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG (d, a, b, c, x[10], S22, 0x02441453); /* 22 */ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ @@ -255,7 +293,7 @@ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ - HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ + HH (b, c, d, a, x[ 6], S34, 0x04881d05); /* 44 */ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ Index: trunk/i386/libsaio/smbios_getters.c =================================================================== --- trunk/i386/libsaio/smbios_getters.c (revision 2330) +++ trunk/i386/libsaio/smbios_getters.c (revision 2331) @@ -21,10 +21,8 @@ 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) @@ -50,9 +48,7 @@ default: value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000); } - } - else - { + } else { value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000); } @@ -120,8 +116,7 @@ DBG("qpimult %d\n", qpimult); qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000)); // Rek: rounding decimals to match original mac profile info - if (qpibusspeed%100 != 0) - { + if (qpibusspeed%100 != 0) { qpibusspeed = ((qpibusspeed+50)/100)*100; } DBG("qpibusspeed %d\n", qpibusspeed); @@ -371,17 +366,15 @@ int map; idx++; - if (idx < MAX_RAM_SLOTS) - { + if (idx < MAX_RAM_SLOTS) { map = Platform.DMI.DIMM[idx]; - if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) - { + if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) { DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type); value->byte = Platform.RAM.DIMM[map].Type; return true; } } - + return false; // value->byte = SMB_MEM_TYPE_DDR2; // return true; @@ -399,11 +392,9 @@ int map; idx++; - if (idx < MAX_RAM_SLOTS) - { + if (idx < MAX_RAM_SLOTS) { map = Platform.DMI.DIMM[idx]; - if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0) - { + if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0) { DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency); value->dword = Platform.RAM.DIMM[map].Frequency; return true; @@ -432,8 +423,7 @@ } } - if (!bootInfo->memDetect) - { + if (!bootInfo->memDetect) { return false; } value->string = NOT_AVAILABLE; @@ -449,19 +439,16 @@ DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS); - if (idx < MAX_RAM_SLOTS) - { + if (idx < MAX_RAM_SLOTS) { map = Platform.DMI.DIMM[idx]; - if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) - { + if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) { DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo); value->string = Platform.RAM.DIMM[map].SerialNo; return true; } } - if (!bootInfo->memDetect) - { + if (!bootInfo->memDetect) { return false; } value->string = NOT_AVAILABLE; @@ -474,19 +461,16 @@ int map; idx++; - if (idx < MAX_RAM_SLOTS) - { + if (idx < MAX_RAM_SLOTS) { map = Platform.DMI.DIMM[idx]; - if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) - { + if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) { DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo); value->string = Platform.RAM.DIMM[map].PartNo; return true; } } - if (!bootInfo->memDetect) - { + if (!bootInfo->memDetect) { return false; } value->string = NOT_AVAILABLE; Index: trunk/i386/boot2/picopng.c =================================================================== --- trunk/i386/boot2/picopng.c (revision 2330) +++ trunk/i386/boot2/picopng.c (revision 2331) @@ -60,14 +60,21 @@ void png_alloc_remove_node(png_alloc_node_t *node) { - if (node->prev) + if (!node) { + return; + } + if (node->prev) { node->prev->next = node->next; - if (node->next) + } + if (node->next) { node->next->prev = node->prev; - if (node == png_alloc_head) + } + if (node == png_alloc_head) { png_alloc_head = node->next; - if (node == png_alloc_tail) + } + if (node == png_alloc_tail) { png_alloc_tail = node->prev; + } node->prev = node->next = node->addr = NULL; free(node); } @@ -81,25 +88,37 @@ void *png_alloc_realloc(void *addr, size_t size) { - void *new_addr; - if (!addr) + void *new_addr = NULL; + if (!addr) { return png_alloc_malloc(size); - new_addr = realloc(addr, size); - if (new_addr != addr) { - png_alloc_node_t *old_node; - old_node = png_alloc_find_node(addr); - png_alloc_remove_node(old_node); - png_alloc_add_node(new_addr, size); } + + png_alloc_node_t *old_node; + old_node = png_alloc_find_node(addr); + + if (old_node) + { + new_addr = realloc(addr, size); + if (new_addr && (new_addr != addr)) + { + png_alloc_remove_node(old_node); + png_alloc_add_node(new_addr, size); + } + } + return new_addr; } void png_alloc_free(void *addr) { + if (!addr) { + return; + } + png_alloc_node_t *node = png_alloc_find_node(addr); - if (!node) - return; - png_alloc_remove_node(node); + if (node) { + png_alloc_remove_node(node); + } free(addr); } @@ -157,9 +176,15 @@ vector32_t *vector32_new(size_t size, uint32_t value) { vector32_t *p = png_alloc_malloc(sizeof (vector32_t)); + if (!p) { + return NULL; + } vector32_init(p); - if (size && !vector32_resizev(p, size, value)) + if (size && !vector32_resizev(p, size, value)) { + vector32_cleanup(p); + png_alloc_free(p); return NULL; + } return p; } @@ -211,9 +236,17 @@ vector8_t *vector8_new(size_t size, uint8_t value) { vector8_t *p = png_alloc_malloc(sizeof (vector8_t)); + if(!p) + { + return NULL; + } vector8_init(p); if (size && !vector8_resizev(p, size, value)) + { + vector8_cleanup(p); + png_alloc_free(p); return NULL; + } return p; } @@ -221,6 +254,10 @@ { vector8_t *q = vector8_new(p->size, 0); uint32_t n; + if (!q) + { + return NULL; + } for (n = 0; n < q->size; n++) q->data[n] = p->data[n]; return q; @@ -229,13 +266,13 @@ /*************************************************************************************************/ const uint32_t LENBASE[29] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, - 59, 67, 83, 99, 115, 131, 163, 195, 227, 258 }; + 59, 67, 83, 99, 115, 131, 163, 195, 227, 258 }; const uint32_t LENEXTRA[29] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, - 4, 5, 5, 5, 5, 0 }; + 4, 5, 5, 5, 5, 0 }; const uint32_t DISTBASE[30] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, - 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 }; + 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 }; const uint32_t DISTEXTRA[30] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, - 10, 10, 11, 11, 12, 12, 13, 13 }; + 10, 10, 11, 11, 12, 12, 13, 13 }; // code length code lengths const uint32_t CLCL[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; @@ -250,6 +287,10 @@ HuffmanTree *HuffmanTree_new() { HuffmanTree *tree = png_alloc_malloc(sizeof (HuffmanTree)); + if (!tree) + { + return NULL; + } tree->tree2d = NULL; return tree; } @@ -262,6 +303,10 @@ tree1d = vector32_new(numcodes, 0); blcount = vector32_new(maxbitlen + 1, 0); nextcode = vector32_new(maxbitlen + 1, 0); + if (!tree1d || !blcount || !nextcode || !nextcode->data) + { + goto error; + } for (bits = 0; bits < numcodes; bits++) blcount->data[bitlen->data[bits]]++; // count number of instances of each code length for (bits = 1; bits <= maxbitlen; bits++) @@ -289,6 +334,23 @@ treepos = tree2d->data[2 * treepos + bit] - numcodes; } return 0; +error: + if (tree1d) + { + vector32_cleanup(tree1d); + png_alloc_free(tree1d); + } + if (blcount) + { + vector32_cleanup(blcount); + png_alloc_free(blcount); + } + if (nextcode) + { + vector32_cleanup(nextcode); + png_alloc_free(nextcode); + } + return 1; } int HuffmanTree_decode(const HuffmanTree *tree, bool *decoded, uint32_t *result, size_t *treepos, @@ -362,6 +424,11 @@ { // get the tree of a deflated block with dynamic tree, the tree itself is also Huffman // compressed with a known tree size_t i, n; + size_t HLIT; + size_t HDIST; + size_t HCLEN; + size_t replength; + vector32_t *codelengthcode; HuffmanTree *codelengthcodetree = HuffmanTree_new(); // the code tree for code length codes vector32_t *bitlen, *bitlenD; bitlen = vector32_new(288, 0); @@ -370,46 +437,53 @@ Inflator_error = 49; // the bit pointer is or will go past the memory return; } - size_t HLIT = Zlib_readBitsFromStream(bp, in, 5) + 257; // number of literal/length codes + 257 - size_t HDIST = Zlib_readBitsFromStream(bp, in, 5) + 1; // number of dist codes + 1 - size_t HCLEN = Zlib_readBitsFromStream(bp, in, 4) + 4; // number of code length codes + 4 - vector32_t *codelengthcode; // lengths of tree to decode the lengths of the dynamic tree + HLIT = Zlib_readBitsFromStream(bp, in, 5) + 257; // number of literal/length codes + 257 + HDIST = Zlib_readBitsFromStream(bp, in, 5) + 1; // number of dist codes + 1 + HCLEN = Zlib_readBitsFromStream(bp, in, 4) + 4; // number of code length codes + 4 + // lengths of tree to decode the lengths of the dynamic tree codelengthcode = vector32_new(19, 0); for (i = 0; i < 19; i++) codelengthcode->data[CLCL[i]] = (i < HCLEN) ? Zlib_readBitsFromStream(bp, in, 3) : 0; Inflator_error = HuffmanTree_makeFromLengths(codelengthcodetree, codelengthcode, 7); if (Inflator_error) return; - size_t replength; + for (i = 0; i < HLIT + HDIST; ) { uint32_t code = Inflator_huffmanDecodeSymbol(in, bp, codelengthcodetree, inlength); - if (Inflator_error) + if (Inflator_error) { return; + } if (code <= 15) { // a length code - if (i < HLIT) + if (i < HLIT) { bitlen->data[i++] = code; - else + } else { bitlenD->data[i++ - HLIT] = code; - } else if (code == 16) { // repeat previous - if (*bp >> 3 >= inlength) { + } + } else if (code == 16) + { // repeat previous + uint32_t value; // set value to the previous code + if (*bp >> 3 >= inlength) + { Inflator_error = 50; // error, bit pointer jumps past memory return; } replength = 3 + Zlib_readBitsFromStream(bp, in, 2); - uint32_t value; // set value to the previous code - if ((i - 1) < HLIT) + + if ((i - 1) < HLIT) { value = bitlen->data[i - 1]; - else + } else { value = bitlenD->data[i - HLIT - 1]; + } for (n = 0; n < replength; n++) { // repeat this value in the next lengths if (i >= HLIT + HDIST) { Inflator_error = 13; // error: i is larger than the amount of codes return; } - if (i < HLIT) + if (i < HLIT) { bitlen->data[i++] = value; - else + } else { bitlenD->data[i++ - HLIT] = value; + } } } else if (code == 17) { // repeat "0" 3-10 times if (*bp >> 3 >= inlength) { @@ -423,9 +497,13 @@ return; } if (i < HLIT) + { bitlen->data[i++] = 0; + } else + { bitlenD->data[i++ - HLIT] = 0; + } } } else if (code == 18) { // repeat "0" 11-138 times if (*bp >> 3 >= inlength) { @@ -439,9 +517,13 @@ return; } if (i < HLIT) + { bitlen->data[i++] = 0; + } else + { bitlenD->data[i++ - HLIT] = 0; + } } } else { Inflator_error = 16; // error: an nonexitent code appeared. This can never happen. @@ -479,14 +561,20 @@ if (Inflator_error) return; if (code == 256) // end code + { return; + } else if (code <= 255) { // literal symbol if (*pos >= out->size) + { vector8_resize(out, (*pos + 1) * 2); // reserve more room + } out->data[(*pos)++] = (uint8_t) code; - } else if (code >= 257 && code <= 285) { // length code + } else if (code >= 257 && code <= 285) + { // length code size_t length = LENBASE[code - 257], numextrabits = LENEXTRA[code - 257]; - if ((*bp >> 3) >= inlength) { + if ((*bp >> 3) >= inlength) + { Inflator_error = 51; // error, bit pointer will jump past memory return; } @@ -582,14 +670,17 @@ // supposed to be made that way return 24; uint32_t CM = in->data[0] & 15, CINFO = (in->data[0] >> 4) & 15, FDICT = (in->data[1] >> 5) & 1; - if (CM != 8 || CINFO > 7) + if (CM != 8 || CINFO > 7){ // error: only compression method 8: inflate with sliding window of 32k is supported by // the PNG spec + return 25; - if (FDICT != 0) + } + if (FDICT != 0) { // error: the specification of PNG says about the zlib stream: "The additional flags shall // not specify a preset dictionary." return 26; + } Inflator_inflate(out, in, 2); return Inflator_error; // note: adler32 checksum was skipped and ignored } @@ -659,11 +750,17 @@ bitDepth = info->bitDepth; colorType = info->colorType; if (colorType == 2) + { return (3 * bitDepth); + } else if (colorType >= 4) + { return (colorType - 2) * bitDepth; + } else + { return bitDepth; + } } void PNG_readPngHeader(PNG_info_t *info, const uint8_t *in, size_t inlength) @@ -887,6 +984,10 @@ PNG_info_t *PNG_info_new() { PNG_info_t *info = png_alloc_malloc(sizeof (PNG_info_t)); + if (!info) + { + return NULL; + } uint32_t i; for (i = 0; i < sizeof (PNG_info_t); i++) ((uint8_t *) info)[i] = 0; @@ -937,6 +1038,12 @@ vector8_resize(idat, offset + chunkLength); } else idat = vector8_new(chunkLength, 0); + + if (!idat) + { + PNG_error = 1; + return NULL; + } for (i = 0; i < chunkLength; i++) idat->data[offset + i] = in[pos + 4 + i]; pos += (4 + chunkLength); @@ -1002,6 +1109,10 @@ uint32_t bpp = PNG_getBpp(info); vector8_t *scanlines; // now the out buffer will be filled scanlines = vector8_new(((info->width * (info->height * bpp + 7)) / 8) + info->height, 0); + if (!scanlines) { + PNG_error = 1; + return NULL; + } PNG_error = Zlib_decompress(scanlines, idat); if (PNG_error) return NULL; // stop if the zlib decompressor returned an error @@ -1068,7 +1179,13 @@ } if (info->colorType != 6 || info->bitDepth != 8) { // conversion needed vector8_t *copy = vector8_copy(info->image); // xxx: is this copy necessary? + if (!copy) { + return NULL; + } PNG_error = PNG_convert(info, info->image, copy->data); + if (PNG_error) { + return NULL; + } } return info; } Index: trunk/i386/boot2/modules.c =================================================================== --- trunk/i386/boot2/modules.c (revision 2330) +++ trunk/i386/boot2/modules.c (revision 2331) @@ -105,8 +105,7 @@ long flags; long time; struct dirstuff* moduleDir = opendir("/Extra/modules/"); - while (readdir(moduleDir, (const char**)&name, &flags, &time) >= 0) - { + while (readdir(moduleDir, (const char**)&name, &flags, &time) >= 0) { if(strcmp(&name[strlen(name) - sizeof("dylib")], ".dylib") == 0) { char* tmp = malloc(strlen(name) + 1); strcpy(tmp, name); @@ -120,6 +119,7 @@ { DBG("Ignoring %s\n", name); } + } closedir(moduleDir); } @@ -605,21 +605,18 @@ unsigned int binIndex = 0; index = 0; - do - { + do { segCommand = base + sizeof(struct mach_header) + binIndex; binIndex += segCommand->cmdsize; index++; - } - while(index <= immediate); + } while(index <= immediate); segmentAddress = segCommand->fileoff; tmp = 0; bits = 0; - do - { + do { tmp |= (rebase_stream[++i] & 0x7f) << bits; bits += 7; } @@ -628,18 +625,15 @@ segmentAddress += tmp; break; - case REBASE_OPCODE_ADD_ADDR_ULEB: // Add value to rebase address tmp = 0; bits = 0; - do - { + do { tmp <<= bits; tmp |= rebase_stream[++i] & 0x7f; bits += 7; - } - while(rebase_stream[i] & 0x80); + } while(rebase_stream[i] & 0x80); segmentAddress += tmp; break; @@ -647,8 +641,8 @@ case REBASE_OPCODE_ADD_ADDR_IMM_SCALED: segmentAddress += immediate * sizeof(void*); break; - - + + case REBASE_OPCODE_DO_REBASE_IMM_TIMES: index = 0; for (index = 0; index < immediate; ++index) { @@ -660,13 +654,11 @@ case REBASE_OPCODE_DO_REBASE_ULEB_TIMES: tmp = 0; bits = 0; - do - { + do { tmp |= (rebase_stream[++i] & 0x7f) << bits; bits += 7; - } - while(rebase_stream[i] & 0x80); - + } while(rebase_stream[i] & 0x80); + index = 0; for (index = 0; index < tmp; ++index) { //DBG("\tRebasing 0x%X\n", segmentAddress); @@ -678,12 +670,10 @@ case REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB: tmp = 0; bits = 0; - do - { + do { tmp |= (rebase_stream[++i] & 0x7f) << bits; bits += 7; - } - while(rebase_stream[i] & 0x80); + } while(rebase_stream[i] & 0x80); rebase_location(base + segmentAddress, (char*)base, type); @@ -693,23 +683,19 @@ case REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB: tmp = 0; bits = 0; - do - { + do { tmp |= (rebase_stream[++i] & 0x7f) << bits; bits += 7; - } - while(rebase_stream[i] & 0x80); + } while(rebase_stream[i] & 0x80); tmp2 = 0; bits = 0; - do - { + do { tmp2 |= (rebase_stream[++i] & 0x7f) << bits; bits += 7; - } - while(rebase_stream[i] & 0x80); - + } while(rebase_stream[i] & 0x80); + index = 0; for (index = 0; index < tmp; ++index) { @@ -728,23 +714,18 @@ UInt32 read_uleb(UInt8* bind_stream, unsigned int* i) { - // Read in offset - UInt32 tmp = 0; - UInt8 bits = 0; - do - { - if(bits < sizeof(UInt32)*8) // hack - { - tmp |= (bind_stream[++(*i)] & 0x7f) << bits; - bits += 7; - } - else - { - ++(*i); - } - } - while(bind_stream[*i] & 0x80); - return tmp; + // Read in offset + UInt32 tmp = 0; + UInt8 bits = 0; + do { + if(bits < sizeof(UInt32)*8) { // hack + tmp |= (bind_stream[++(*i)] & 0x7f) << bits; + bits += 7; + } else { + ++(*i); + } + } while(bind_stream[*i] & 0x80); + return tmp; } @@ -830,7 +811,7 @@ // Locate address struct segment_command* segCommand = NULL; // NOTE: 32bit only - + unsigned int binIndex = 0; index = 0; do @@ -984,11 +965,12 @@ if(addr != 0xFFFFFFFF) { //DBG("Replacing %s to point to 0x%x\n", symbol, newAddress); - UInt32* jumpPointer = malloc(sizeof(UInt32*)); + UInt32* jumpPointer = malloc(sizeof(UInt32*)); char* binary = (char*)addr; *binary++ = 0xFF; // Jump *binary++ = 0x25; // Long Jump *((UInt32*)binary) = (UInt32)jumpPointer; + *jumpPointer = (UInt32)newAddress; return 1; } Index: trunk/i386/boot2/modules.h =================================================================== --- trunk/i386/boot2/modules.h (revision 2330) +++ trunk/i386/boot2/modules.h (revision 2331) @@ -94,6 +94,7 @@ long long(*symbol_handler)(char*, long long, char), char is64); void rebase_macho(void* base, char* rebase_stream, UInt32 size); + void bind_macho(void* base, UInt8* bind_stream, UInt32 size); Index: trunk/i386/libsa/libsa.h =================================================================== --- trunk/i386/libsa/libsa.h (revision 2330) +++ trunk/i386/libsa/libsa.h (revision 2331) @@ -37,53 +37,53 @@ */ static inline int isupper(int c) { - return (c >= 'A' && c <= 'Z'); + return (c >= 'A' && c <= 'Z'); } static inline int islower(int c) { - return (c >= 'a' && c <= 'z'); + return (c >= 'a' && c <= 'z'); } static inline int isalpha(int c) { - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); } static inline int isascii(int c) { - return ( (c >= 0x20) && (c < 0x7f) ); + return ( (c >= 0x20) && (c < 0x7f) ); } static inline int isspace(int c) { - return (c == ' ' || c == '\t' || c == '\n' || c == '\12'); + return (c == ' ' || c == '\t' || c == '\n' || c == '\12'); } static inline int isdigit(int c) { - return (c >= '0' && c <= '9'); + return (c >= '0' && c <= '9'); } static inline int isxdigit(int c) { - return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); + return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); } static inline int ispunct(int c) { - return (c == '.' || c == '-'); + return (c == '.' || c == '-'); } /* * string.c */ #ifndef bcopy -extern void bcopy(const void * src, void * dst, size_t len); +extern void bcopy(const void * src, void * dst, size_t len); #endif #ifndef bzero -extern void bzero(void * dst, size_t len); +extern void bzero(void * dst, size_t len); #else #error bzero is defined. #endif @@ -105,7 +105,7 @@ extern char * strdup(const char *s1); #if STRNCASECMP -extern int strncasecmp(const char * s1, const char * s2, size_t n); +extern int strncasecmp(const char *s1, const char *s2, size_t n); #endif extern char * strchr(const char *str, int c); @@ -129,8 +129,7 @@ /* * prf.c */ -extern void prf(const char * fmt, va_list ap, int (*putfn_p)(), - void * putfn_arg); +extern void prf(const char * fmt, va_list ap, int (*putfn_p)(), void * putfn_arg); /* * printf.c @@ -142,7 +141,7 @@ /* * zalloc.c */ -#define malloc(size) safe_malloc(size, __FILE__, __LINE__) +#define malloc(size) safe_malloc(size, __FILE__, __LINE__) extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int)); extern void * safe_malloc(size_t size,const char *file, int line); extern void free(void * start); @@ -151,7 +150,6 @@ /* * getsegbyname.c */ -extern struct segment_command * - getsegbynamefromheader(struct mach_header * mhp, char * segname); +extern struct segment_command * getsegbynamefromheader(struct mach_header * mhp, char * segname); #endif /* !__BOOT_LIBSA_H */ Index: trunk/i386/libsa/printf.c =================================================================== --- trunk/i386/libsa/printf.c (revision 2330) +++ trunk/i386/libsa/printf.c (revision 2331) @@ -30,36 +30,39 @@ struct putc_info //Azi: exists on console.c & gui.c { - char * str; - char * last_str; + char * str; + char * last_str; }; static int sputc(int c, struct putc_info * pi) //Azi: same as above { - if (pi->last_str) - if (pi->str == pi->last_str) { - *(pi->str) = '\0'; - return 0; - } - *(pi->str)++ = c; - return c; + if (pi->last_str) + { + if (pi->str == pi->last_str) + { + *(pi->str) = '\0'; + return 0; + } + } + *(pi->str)++ = c; + return c; } /*VARARGS1*/ /* now slprintf() return the length of the string as in man sprintf()*/ int sprintf(char * str, const char * fmt, ...) { - va_list ap; - struct putc_info pi; + va_list ap; + struct putc_info pi; - va_start(ap, fmt); - pi.str = str; - pi.last_str = 0; - prf(fmt, ap, sputc, &pi); - *pi.str = '\0'; - va_end(ap); - return (pi.str - str); + va_start(ap, fmt); + pi.str = str; + pi.last_str = 0; + prf(fmt, ap, sputc, &pi); + *pi.str = '\0'; + va_end(ap); + return (pi.str - str); } /*VARARGS1*/ @@ -80,10 +83,10 @@ /*VARARGS1*/ int slvprintf(char * str, int len, const char * fmt, va_list ap) { - struct putc_info pi; - pi.str = str; - pi.last_str = str + len - 1; - prf(fmt, ap, sputc, &pi); - *pi.str = '\0'; - return (pi.str - str); + struct putc_info pi; + pi.str = str; + pi.last_str = str + len - 1; + prf(fmt, ap, sputc, &pi); + *pi.str = '\0'; + return (pi.str - str); } Index: trunk/i386/libsa/zalloc.c =================================================================== --- trunk/i386/libsa/zalloc.c (revision 2330) +++ trunk/i386/libsa/zalloc.c (revision 2331) @@ -49,7 +49,7 @@ static short availableNodes, allocedNodes, totalNodes; static char * zalloc_base; static char * zalloc_end; -static void (*zerror)(char *, size_t, const char *, int); +static void (*zerror)(char *, size_t, const char *, int); static void zallocate(char * start,int size); static void zinsert(zmem * zp, int ndx); @@ -65,7 +65,7 @@ static void malloc_error(char *addr, size_t size, const char *file, int line) { #ifdef i386 - asm volatile ("hlt"); + asm volatile ("hlt"); #endif } @@ -77,12 +77,16 @@ zalloced = (zmem *) zalloc_base; zavailable = (zmem *) zalloc_base + sizeof(zmem) * totalNodes; zavailable[0].start = (char *)zavailable + sizeof(zmem) * totalNodes; - if (size == 0) size = ZALLOC_LEN; + + if (size == 0) { + size = ZALLOC_LEN; + } + zavailable[0].size = size - (zavailable[0].start - zalloc_base); - zalloc_end = zalloc_base + size; + zalloc_end = zalloc_base + size; availableNodes = 1; allocedNodes = 0; - zerror = malloc_err_fn ? malloc_err_fn : malloc_error; + zerror = malloc_err_fn ? malloc_err_fn : malloc_error; } #define BEST_FIT 1 @@ -91,8 +95,8 @@ { int i; #if BEST_FIT - int bestFit; - size_t smallestSize; + int bestFit; + size_t smallestSize; #endif char * ret = 0; @@ -105,37 +109,34 @@ size = ((size + 0xf) & ~0xf); if (size == 0) { - if (zerror) (*zerror)((char *)0xdeadbeef, 0, file, line); + if (zerror) { + (*zerror)((char *)0xdeadbeef, 0, file, line); + } } #if BEST_FIT - smallestSize = 0; - bestFit = -1; + smallestSize = 0; + bestFit = -1; #endif - + for (i = 0; i < availableNodes; i++) { // find node with equal size, or if not found, // then smallest node that fits. - if ( zavailable[i].size == size ) + if (zavailable[i].size == size) { zallocate(ret = zavailable[i].start, size); zdelete(zavailable, i); availableNodes--; goto done; } #if BEST_FIT - else - { - if ((zavailable[i].size > size) && - ((smallestSize == 0) || - (zavailable[i].size < smallestSize))) - { - bestFit = i; - smallestSize = zavailable[i].size; - } - } - + else { + if ((zavailable[i].size > size) && ((smallestSize == 0) || (zavailable[i].size < smallestSize))) { + bestFit = i; + smallestSize = zavailable[i].size; + } + } #else - else if ( zavailable[i].size > size ) + else if (zavailable[i].size > size) { zallocate(ret = zavailable[i].start, size); zavailable[i].start += size; @@ -143,77 +144,81 @@ goto done; } #endif - } + } #if BEST_FIT - if (bestFit != -1) - { - zallocate(ret = zavailable[bestFit].start, size); - zavailable[bestFit].start += size; - zavailable[bestFit].size -= size; - } + if (bestFit != -1) { + zallocate(ret = zavailable[bestFit].start, size); + zavailable[bestFit].start += size; + zavailable[bestFit].size -= size; + } #endif done: - if ((ret == 0) || (ret + size >= zalloc_end)) - { - if (zerror) (*zerror)(ret, size, file, line); - } - if (ret != 0) - { + if ((ret == 0) || (ret + size >= zalloc_end)) { + if (zerror) { + (*zerror)(ret, size, file, line); + } + } + + if (ret != 0) { bzero(ret, size); - } + } #if ZDEBUG - zalloced_size += size; + zalloced_size += size; #endif return (void *) ret; } void free(void * pointer) { - unsigned long rp; + unsigned long rp; int i, found = 0; - size_t tsize = 0; + size_t tsize = 0; char * start = pointer; #if i386 - // Get return address of our caller, - // in case we have to report an error below. - asm volatile ("movl %%esp, %%eax\n\t" + // Get return address of our caller, + // in case we have to report an error below. + asm volatile ("movl %%esp, %%eax\n\t" "subl $4, %%eax\n\t" - "movl 0(%%eax), %%eax" : "=a" (rp) ); + "movl 0(%%eax), %%eax" : "=a" (rp)); #else rp = 0; #endif - if ( !start ) return; + if (!start) { + return; + } for (i = 0; i < allocedNodes; i++) { - if ( zalloced[i].start == start ) + if (zalloced[i].start == start) { tsize = zalloced[i].size; #if ZDEBUG zout -= tsize; - printf(" zz out %d\n",zout); + printf(" zz out %d\n", zout); #endif zdelete(zalloced, i); allocedNodes--; found = 1; #if ZDEBUG - memset(pointer, 0x5A, tsize); + memset(pointer, 0x5A, tsize); #endif break; } } - if ( !found ) { - if (zerror) (*zerror)(pointer, rp, "free", 0); - else return; - } + if (!found) { + if (zerror) { + (*zerror)(pointer, rp, "free", 0); + } else { + return; + } + } #if ZDEBUG zalloced_size -= tsize; #endif - for (i = 0; i < availableNodes; i++) - { + for (i = 0; i < availableNodes; i++) { if ((start + tsize) == zavailable[i].start) // merge it in { zavailable[i].start = start; @@ -222,19 +227,18 @@ return; } - if ((i > 0) && - (zavailable[i-1].start + zavailable[i-1].size == start)) - { + if ((i > 0) && (zavailable[i-1].start + zavailable[i-1].size == start)) { zavailable[i-1].size += tsize; zcoalesce(); return; } - if ((start + tsize) < zavailable[i].start) - { + if ((start + tsize) < zavailable[i].start) { if (++availableNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 0, "free", 0); - } + if (zerror) { + (*zerror)((char *)0xf000f000, 0, "free", 0); + } + } zinsert(zavailable, i); zavailable[i].start = start; zavailable[i].size = tsize; @@ -242,27 +246,35 @@ } } - if (++availableNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 1, "free", 0); - } + if (++availableNodes > totalNodes) { + if (zerror) { + (*zerror)((char *)0xf000f000, 1, "free", 0); + } + } zavailable[i].start = start; zavailable[i].size = tsize; zcoalesce(); + return; } static void zallocate(char * start,int size) { + #if ZDEBUG zout += size; printf(" alloc %d, total 0x%x\n",size,zout); #endif + zalloced[allocedNodes].start = start; zalloced[allocedNodes].size = size; + if (++allocedNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 2, "zallocate", 0); - }; + if (zerror) { + (*zerror)((char *)0xf000f000, 2, "zallocate", 0); + } + }; } static void @@ -275,9 +287,8 @@ z1 = zp + i; z2 = z1 + 1; - for (; i >= ndx; i--, z1--, z2--) - { - *z2 = *z1; + for (; i >= ndx; i--, z1--, z2--) { + *z2 = *z1; } } @@ -290,9 +301,8 @@ z1 = zp + ndx; z2 = z1 + 1; - for (i = ndx; i < totalNodes-1; i++, z1++, z2++) - { - *z1 = *z2; + for (i = ndx; i < totalNodes - 1; i++, z1++, z2++) { + *z1 = *z2; } } @@ -301,13 +311,10 @@ { int i; - for (i = 0; i < availableNodes-1; i++) - { - if ( zavailable[i].start + zavailable[i].size == - zavailable[i+1].start ) - { - zavailable[i].size += zavailable[i+1].size; - zdelete(zavailable, i+1); availableNodes--; + for (i = 0; i < availableNodes-1; i++) { + if ( zavailable[i].start + zavailable[i].size == zavailable[i + 1].start ) { + zavailable[i].size += zavailable[i + 1].size; + zdelete(zavailable, i + 1); availableNodes--; return; } } Index: trunk/i386/libsa/string.c =================================================================== --- trunk/i386/libsa/string.c (revision 2330) +++ trunk/i386/libsa/string.c (revision 2331) @@ -307,9 +307,9 @@ uint8_t * cp = (uint8_t *) start; unsigned int i; - for ( i = 0; i < length; i++) - csum += *cp++; - - return csum; + for ( i = 0; i < length; i++) { + csum += *cp++; + } + return csum; } Index: trunk/i386/libsa/prf.c =================================================================== --- trunk/i386/libsa/prf.c (revision 2330) +++ trunk/i386/libsa/prf.c (revision 2331) @@ -73,7 +73,7 @@ } cp = prbuf; do { - *cp++ = "0123456789abcdef0123456789ABCDEF"[(flag & UCASE) + n%b]; + *cp++ = "0123456789abcdef0123456789ABCDEF"[(flag & UCASE) + n%b]; n /= b; width++; } while (n); @@ -84,7 +84,7 @@ } while (width++ < minwidth) (*putfn_p)( (flag & ZERO) ? '0' : ' ', putfn_arg); - + do (*putfn_p)(*--cp, putfn_arg); while (cp > prbuf); @@ -100,7 +100,7 @@ int b, c; char *s; int flag = 0, width = 0; - int minwidth; + int minwidth; loop: while ((c = *fmt++) != '%') { Index: trunk/i386/libsa/efi_tables.c =================================================================== --- trunk/i386/libsa/efi_tables.c (revision 2330) +++ trunk/i386/libsa/efi_tables.c (revision 2331) @@ -129,17 +129,21 @@ bool efi_guid_is_null(EFI_GUID const *pGuid) { - if(pGuid->Data1 == 0 && pGuid->Data2 == 0 && pGuid->Data3 == 0) - { - int i; - for(i=0; i<8; ++i) - { - if(pGuid->Data4[i] != 0) - return false; - } - return true; - } - return false; + if (pGuid->Data1 == 0 && pGuid->Data2 == 0 && pGuid->Data3 == 0) + { + int i; + + for (i = 0; i < 8; ++i) + { + if (pGuid->Data4[i] != 0) + { + return false; + } + } + return true; + } + + return false; } #define COMPARE_MEMBER_AND_RETURN_IF_NE(a,b,mem) \ @@ -154,7 +158,8 @@ COMPARE_MEMBER_AND_RETURN_IF_NE(pG1, pG2, Data2); COMPARE_MEMBER_AND_RETURN_IF_NE(pG1, pG2, Data3); int i; - for(i=0; i<8; ++i) + + for(i = 0; i < 8; ++i) { COMPARE_MEMBER_AND_RETURN_IF_NE(pG1, pG2, Data4[i]); } Index: trunk/i386/libsa/memory.h =================================================================== --- trunk/i386/libsa/memory.h (revision 2330) +++ trunk/i386/libsa/memory.h (revision 2331) @@ -57,7 +57,7 @@ #define BOOT2_SEG 0x2000 #define BOOT2_OFS 0x0200 // 512 byte disk sector offset -#define BOOT2_MAX_LENGTH 0x6FE00 // Maximum size for boot2 is currentl 447kb +#define BOOT2_MAX_LENGTH 0x6FE00 // Maximum size for boot2 is currentl 447kb #define BIOS_ADDR 0x8000 // BIOS disk I/O buffer #define BIOS_LEN 0x8000 // 32K - divisible by 512 and 2048 @@ -118,9 +118,10 @@ #define OFFSET(addr) ((addr) & 0xFFFF) #define SEGMENT(addr) (((addr) & 0xF0000) >> 4) -/* Extract segment/offset in normalized form so that the resulting far pointer - will point to something that is very unlikely to straddle a segment. - This is sometimes known as a "huge" pointer. +/* + * Extract segment/offset in normalized form so that the resulting far pointer + * will point to something that is very unlikely to straddle a segment. + * This is sometimes known as a "huge" pointer. */ #define NORMALIZED_OFFSET(addr) ((addr) & 0x000F) #define NORMALIZED_SEGMENT(addr) (((addr) & 0xFFFF0) >> 4) @@ -131,7 +132,7 @@ #define MIN_SYS_MEM_KB (32 * 1024) /* - * The number of descriptor entries in the GDT. + * The number of descriptor entries in the GDT (Global Descriptor Table). */ #define NGDTENT 7 @@ -139,6 +140,6 @@ * The total size of the GDT in bytes. * Each descriptor entry require 8 bytes. */ -#define GDTLIMIT ( NGDTENT * 8 ) +#define GDTLIMIT (NGDTENT * 8) #endif /* !__BOOT_MEMORY_H */