Index: branches/ErmaC/Enoch/i386/libsaio/smbios_getters.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/smbios_getters.h (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/smbios_getters.h (revision 2341) @@ -10,7 +10,7 @@ #define SMBIOS_RANGE_START 0x000F0000 #define SMBIOS_RANGE_END 0x000FFFFF -#define NOT_AVAILABLE "N/A" +#define NOT_AVAILABLE "N/A" typedef enum { Index: branches/ErmaC/Enoch/i386/libsaio/xml.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/xml.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/xml.c (revision 2341) @@ -27,6 +27,34 @@ #include "sl.h" #include "xml.h" +#define kXMLTagPList "plist " +#define kXMLTagPListLen (sizeof(kXMLTagPList) - 1) +#define kXMLTagDict "dict" +#define kXMLTagDictLen (sizeof(kXMLTagDict) - 1) +#define kXMLTagKey "key" +#define kXMLTagKeyLen (sizeof(kXMLTagKey) - 1) +#define kXMLTagString "string" +#define kXMLTagStringLen (sizeof(kXMLTagString) - 1) +#define kXMLTagInteger "integer" +#define kXMLTagIntegerLen (sizeof(kXMLTagInteger) - 1) +#define kXMLTagData "data" +#define kXMLTagDataLen (sizeof(kXMLTagData) - 1) +#define kXMLTagDate "date" +#define kXMLTagDateLen (sizeof(kXMLTagDate) - 1) +#define kXMLTagFalse "false/" +#define kXMLTagFalseLen (sizeof(kXMLTagFalse) - 1) +#define kXMLTagTrue "true/" +#define kXMLTagTrueLen (sizeof(kXMLTagTrue) - 1) +#define kXMLTagArray "array" +#define kXMLTagArrayLen (sizeof(kXMLTagArray) - 1) +// for back-references used by libkern serializer +#define kXMLTagReference "reference" +#define kXMLTagReferenceLen (sizeof(kXMLTagReference) - 1) +#define kXMLStringID "ID=" +#define kXMLStringIDLen (sizeof(kXMLStringID) - 1) +#define kXMLStringIDRef "IDREF=" +#define kXMLStringIDRefLen (sizeof(kXMLStringIDRef) - 1) + string_ref *ref_strings = NULL; /// TODO: remove below @@ -130,17 +158,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 +178,6 @@ return tag->tag; } } - return 0; } @@ -362,222 +390,194 @@ } pos = length; - if (!strncmp(tagName, kXMLTagPList, 6)) - { - length = 0; - // just a header; nothing to parse - // return-via-reference tag should be left alone - } - /***** dict ****/ - else if (!strcmp(tagName, kXMLTagDict)) - { - length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); - } - else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/') - { - length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1); - } - else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " "))) - { - length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); - } + + /* Check most common cases first, make them fast */ + /***** key ****/ - else if (!strcmp(tagName, kXMLTagKey)) - { + if (!strcmp(tagName, kXMLTagKey)) { length = ParseTagKey(buffer + pos, tag); } /***** string ****/ - else if (!strcmp(tagName, kXMLTagString)) - { - length = ParseTagString(buffer + pos, tag); - } - else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " "))) - { - // TODO: save tag if if found - if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID))) - { - // ID= - int id = 0; - int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1; - while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; - tagName[cnt] = 0; - char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\""); - while(*val) - { - if ((*val >= '0' && *val <= '9')) // 0 - 9 - { - id = (id * 10) + (*val++ - '0'); - } - else - { - printf("ParseStringID error (0x%x)\n", *val); - getchar(); - return -1; - } - } + else if (!strncmp(tagName, kXMLTagString, kXMLTagStringLen)) { + if (!tagName[kXMLTagStringLen]) { /* */ length = ParseTagString(buffer + pos, tag); - - SaveRefString(buffer + pos, id); - } - else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) - { - // IDREF= - int id = 0; - int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1; - while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; - tagName[cnt] = 0; - char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\""); - while(*val) - { - if ((*val >= '0' && *val <= '9')) // 0 - 9 - { - id = (id * 10) + (*val++ - '0'); + } else if (' ' == tagName[kXMLTagStringLen]) { /* */ + // TODO: save tag if if found + if(!strncmp(tagName + kXMLTagStringLen + 1, (kXMLStringID "\""), kXMLStringIDLen + 1)) { /* = '0' && *val <= '9')) { // 0 - 9 + id = (id * 10) + (*val++ - '0'); + } else { + printf("ParseStringID error (0x%x)\n", *val); + getchar(); + return -1; + } } - else - { - printf("ParseStringIDREF error (0x%x)\n", *val); - getchar(); - return -1; + length = ParseTagString(buffer + pos, tag); + + SaveRefString(buffer + pos, id); + } else if(!strncmp(tagName + kXMLTagStringLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) { /* */ + // IDREF= + int id = 0; + int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1; + while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; + tagName[cnt] = 0; + char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\""); + while(*val) { + if ((*val >= '0' && *val <= '9')) { // 0 - 9 + id = (id * 10) + (*val++ - '0'); + } else { + printf("ParseStringIDREF error (0x%x)\n", *val); + getchar(); + return -1; + } } - } - char* str = GetRefString(id); + char* str = GetRefString(id); - TagPtr tmpTag = NewTag(); - tmpTag->type = kTagTypeString; - tmpTag->string = str; - tmpTag->tag = 0; - tmpTag->tagNext = 0; - tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0; - *tag = tmpTag; - + TagPtr tmpTag = NewTag(); + tmpTag->type = kTagTypeString; + tmpTag->string = str; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0; + *tag = tmpTag; + + length = 0; + //printf("Located IDREF, id = %d, string = %s\n", id, str); + } + } else { /* unrecognized */ + *tag = 0; length = 0; - //printf("Located IDREF, id = %d, string = %s\n", id, str); } } /***** integer ****/ - else if (!strcmp(tagName, kXMLTagInteger)) - { - length = ParseTagInteger(buffer + pos, tag); - } - else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " "))) - { - if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID))) - { - // ID= - int id = 0; - int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1; - while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; - tagName[cnt] = 0; - char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\""); - while(*val) - { - if ((*val >= '0' && *val <= '9')) // 0 - 9 - { - id = (id * 10) + (*val++ - '0'); - } - else - { - printf("ParseIntegerID error (0x%x)\n", *val); - getchar(); - return -1; - } - } + else if (!strncmp(tagName, kXMLTagInteger, kXMLTagIntegerLen)) { + if (!tagName[kXMLTagIntegerLen]) { /* */ length = ParseTagInteger(buffer + pos, tag); - - SaveRefString((*tag)->string, id); - } - else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) - { - // IDREF= - int id = 0; - int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1; - while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; - tagName[cnt] = 0; - char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\""); - while(*val) - { - if ((*val >= '0' && *val <= '9')) // 0 - 9 - { - id = (id * 10) + (*val++ - '0'); + } else if (' ' == tagName[kXMLTagIntegerLen]) { /* */ + if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringID, kXMLStringIDLen)) { /* */ + // ID= + int id = 0; + int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1; + while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; + tagName[cnt] = 0; + char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\""); + while(*val) { + if ((*val >= '0' && *val <= '9')) { // 0 - 9 + id = (id * 10) + (*val++ - '0'); + } else { + printf("ParseIntegerID error (0x%x)\n", *val); + getchar(); + return -1; + } } - else - { - printf("ParseStringIDREF error (0x%x)\n", *val); - getchar(); - return -1; + length = ParseTagInteger(buffer + pos, tag); + + SaveRefString((*tag)->string, id); + } else if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) { /* */ + // IDREF= + int id = 0; + int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1; + while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; + tagName[cnt] = 0; + char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\""); + while(*val) { + if ((*val >= '0' && *val <= '9')) { // 0 - 9 + id = (id * 10) + (*val++ - '0'); + } else { + printf("ParseStringIDREF error (0x%x)\n", *val); + getchar(); + return -1; + } } + int integer = (int)GetRefString(id); + + TagPtr tmpTag = NewTag(); + tmpTag->type = kTagTypeInteger; + tmpTag->string = (char*) integer; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0; + + *tag = tmpTag; + + length = 0; + //printf("Located IDREF, id = %d, string = %s\n", id, str); + } else { + length = ParseTagInteger(buffer + pos, tag); } - int integer = (int)GetRefString(id); - - TagPtr tmpTag = NewTag(); - tmpTag->type = kTagTypeInteger; - tmpTag->string = (char*) integer; - tmpTag->tag = 0; - tmpTag->tagNext = 0; - tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0; - - *tag = tmpTag; - + } else { /* unrecognized */ + *tag = 0; length = 0; - //printf("Located IDREF, id = %d, string = %s\n", id, str); } - else - { - length = ParseTagInteger(buffer + pos, tag); - } } - - /***** data ****/ - else if (!strcmp(tagName, kXMLTagData)) - { - length = ParseTagData(buffer + pos, tag); - } - else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " "))) - { - length = ParseTagData(buffer + pos, tag); - } - else if (!strcmp(tagName, kXMLTagDate)) - { - length = ParseTagDate(buffer + pos, tag); - } - /***** date ****/ - else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " "))) - { - length = ParseTagDate(buffer + pos, tag); - } /***** false ****/ - else if (!strcmp(tagName, kXMLTagFalse)) - { + else if (!strcmp(tagName, kXMLTagFalse)) { length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse); } + /***** true ****/ - else if (!strcmp(tagName, kXMLTagTrue)) - { + else if (!strcmp(tagName, kXMLTagTrue)) { length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue); } - /***** array ****/ - else if (!strcmp(tagName, kXMLTagArray)) - { - length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); + /***** plist ****/ + else if (!strncmp(tagName, kXMLTagPList, kXMLTagPListLen)) { + length = 0; } - else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " "))) - { - length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); + + /***** dict ****/ + else if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen)) { + if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen) && tagName[strlen(tagName)-1] == '/') { /* */ + length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1); + } else if (!tagName[kXMLTagDictLen] || ' ' == tagName[kXMLTagDictLen]) { /* or */ + length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); + } else { /* unrecognized */ + *tag = 0; + length = 0; + } } - else if (!strcmp(tagName, kXMLTagArray "/")) - { - length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1); + + /***** data ****/ + else if ((!strncmp(tagName, kXMLTagData, kXMLTagDataLen)) + && (!tagName[kXMLTagDataLen] /* */ + || ' ' == tagName[kXMLTagDataLen])) { /* */ + length = ParseTagData(buffer + pos, tag); } + /***** date ****/ + else if ((!strncmp(tagName, kXMLTagDate, kXMLTagDateLen)) + && (!tagName[kXMLTagDateLen] /* */ + || ' ' == tagName[kXMLTagDateLen])) { /* */ + length = ParseTagDate(buffer + pos, tag); + } + + /***** array ****/ + else if (!strncmp(tagName, kXMLTagArray, kXMLTagArrayLen)) { /* */ + char c = tagName[kXMLTagArrayLen]; + if ('/' == c) { /* */ + length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1); + } + else if ('\0' == c || ' ' == c) { /* or */ + length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); + } else { /* unrecognized */ + *tag = 0; + length = 0; + } + } /***** unknown ****/ - else - { - // it wasn't parsed so we consumed no additional characters + else { *tag = 0; length = 0; } @@ -601,10 +601,8 @@ tagList = 0; pos = 0; - if (!empty) - { - while (1) - { + if (!empty) { + while (1) { length = XMLParseNextTag(buffer + pos, &tmpTag); if (length == -1) { break; @@ -620,16 +618,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 +731,7 @@ TagPtr tmpTag; char* val = buffer; int size; - + if(buffer[0] == '<') { printf("Warning integer is non existant\n"); @@ -753,65 +749,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; @@ -914,25 +901,49 @@ static long GetNextTag( char * buffer, char ** tag, long * start ) { - long cnt, cnt2; + char* tagStart = buffer; + char* tagEnd; + char c; - if (tag == 0) return -1; + if (!tag) { + return -1; + } -// Find the start of the tag. - cnt = 0; - while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++; - if (buffer[cnt] == '\0') return -1; - // Find the end of the tag. - cnt2 = cnt + 1; - while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++; - if (buffer[cnt2] == '\0') return -1; + /* Find the start of the tag. */ + do { + c = *tagStart++; + if (c == '<') { + break; + } + } while (c); + if (!c) { + return -1; + } + /* tagStart points just past the '<' */ + /* Find the end of the tag. */ + tagEnd = tagStart; + do { + c = *tagEnd++; + if (c == '>') { + break; + } + } while (c); + if (!c) { + return -1; + } - // Fix the tag data. - *tag = buffer + cnt + 1; - buffer[cnt2] = '\0'; - if (start) *start = cnt; + /* tagEnd points just past the '>' */ + /* Fix up tag data by nulling out the '>' */ + --tagEnd; + *tagEnd = '\0'; - return cnt2 + 1; + *tag = tagStart; /* first char after initial '<' */ + if (start) { + *start = (long) (tagStart - buffer) - 1; /* offset of the initial '<' itself */ + } + + /* Return offset to the char after '>' */ + return (long) (tagEnd - buffer) + 1; } //========================================================================== @@ -1006,13 +1017,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 +1068,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 +1086,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 +1105,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 +1139,8 @@ symbol = gSymbolsHead; prev = 0; - while (symbol != 0) - { - if (!strcmp(symbol->string, string)) - { + while (symbol != 0) { + if (!strcmp(symbol->string, string)) { break; } @@ -1149,8 +1148,7 @@ symbol = symbol->next; } - if ((symbol != 0) && (prevSymbol != 0)) - { + if ((symbol != 0) && (prevSymbol != 0)) { *prevSymbol = prev; } @@ -1159,8 +1157,7 @@ bool XMLIsType(TagPtr dict, enum xmltype type) { - if(!dict) - { + if(!dict) { return (type == kTagTypeNone); } return (dict->type == type); @@ -1174,17 +1171,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 +1193,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 +1210,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 +1223,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 +1238,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 +1252,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 +1268,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 +1288,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 +1305,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: branches/ErmaC/Enoch/i386/libsaio/xml.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/xml.h (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/xml.h (revision 2341) @@ -48,21 +48,6 @@ extern string_ref* ref_strings; -#define kXMLTagPList "plist " -#define kXMLTagDict "dict" -#define kXMLTagKey "key" -#define kXMLTagString "string" -#define kXMLTagInteger "integer" -#define kXMLTagData "data" -#define kXMLTagDate "date" -#define kXMLTagFalse "false/" -#define kXMLTagTrue "true/" -#define kXMLTagArray "array" -// for back-references used by libkern serializer -#define kXMLTagReference "reference" -#define kXMLStringID "ID=" -#define kXMLStringIDRef "IDREF=" - #define kPropCFBundleIdentifier ("CFBundleIdentifier") #define kPropCFBundleExecutable ("CFBundleExecutable") #define kPropOSBundleRequired ("OSBundleRequired") Index: branches/ErmaC/Enoch/i386/libsaio/ext2fs.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/ext2fs.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/ext2fs.c (revision 2341) @@ -18,20 +18,41 @@ return (OSReadLittleInt16(buf+0x438,0)==0xEF53); } +void EX2GetDescription(CICell ih, char *str, long strMaxLen) +{ + char * buf=malloc (EX2ProbeSize); + str[0]=0; + if (!buf) { + return; + } + Seek(ih, 0); + Read(ih, (long)buf, EX2ProbeSize); + if (!EX2Probe (buf)) { + free (buf); + return; + } + if (OSReadLittleInt32 (buf+0x44c,0)<1) { + free (buf); + return; + } + str[strMaxLen]=0; + strncpy (str, buf+0x478, MIN(strMaxLen, 16)); + free (buf); +} + long EX2GetUUID(CICell ih, char *uuidStr) { uint8_t *b, *buf=malloc (EX2ProbeSize); - if (!buf) + if (!buf) { return -1; + } Seek(ih, 0); Read(ih, (long)buf, EX2ProbeSize); - if (!EX2Probe (buf)) - { + if (!EX2Probe (buf)) { free (buf); return -1; } - if (OSReadLittleInt32 (buf+0x44c,0)<1) - { + if (OSReadLittleInt32 (buf+0x44c,0)<1) { free (buf); return -1; } @@ -46,26 +67,3 @@ free (buf); return 0; } - -void EX2GetDescription(CICell ih, char *str, long strMaxLen) -{ - char * buf=malloc (EX2ProbeSize); - str[0]=0; - if (!buf) - return; - Seek(ih, 0); - Read(ih, (long)buf, EX2ProbeSize); - if (!EX2Probe (buf)) - { - free (buf); - return; - } - if (OSReadLittleInt32 (buf+0x44c,0)<1) - { - free (buf); - return; - } - str[strMaxLen]=0; - strncpy (str, buf+0x478, MIN(strMaxLen, 16)); - free (buf); -} Index: branches/ErmaC/Enoch/i386/libsaio/device_tree.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/device_tree.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/device_tree.c (revision 2341) @@ -297,7 +297,7 @@ for (count = 0, prop = node->properties; prop != 0; count++, prop = prop->next) { flatProp = (DeviceTreeNodeProperty *)buffer; - strcpy(flatProp->name, prop->name); + strncpy(flatProp->name, prop->name, kPropNameLength); flatProp->length = prop->length; buffer += sizeof(DeviceTreeNodeProperty); bcopy(prop->value, buffer, prop->length); Index: branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c (revision 2341) @@ -516,44 +516,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; @@ -596,9 +592,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; } @@ -607,25 +601,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: @@ -636,8 +626,7 @@ } // Generating SSDT - if (p_states_count > 0) - { + if (p_states_count > 0) { int i; AML_CHUNK* root = aml_create_node(NULL); @@ -647,8 +636,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); @@ -660,8 +648,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]); @@ -687,9 +674,7 @@ return ssdt; } - } - else - { + } else { verbose ("ACPI CPUs not found: P-States not generated !!!\n"); } @@ -707,27 +692,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; } @@ -738,43 +716,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; } @@ -784,10 +750,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 @@ -796,9 +760,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 @@ -812,13 +774,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; } @@ -868,12 +828,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"); } @@ -882,84 +839,63 @@ new_dsdt = loadACPITable(dirSpec); /* Try using the file specified with the HPET option */ - if (getValueForKey(kHPET, &filename, &len, &bootInfo->chameleonConfig)) - { + if (getValueForKey(kHPET, &filename, &len, &bootInfo->chameleonConfig)) { snprintf(dirSpec, sizeof(dirSpec), filename); - } - else - { + } else { sprintf(dirSpec, "HPET.aml"); } // Load replacement HPET new_hpet = loadACPITable(dirSpec); /* Try using the file specified with the SBST option */ - if (getValueForKey(kSBST, &filename, &len, &bootInfo->chameleonConfig)) - { + if (getValueForKey(kSBST, &filename, &len, &bootInfo->chameleonConfig)) { snprintf(dirSpec, sizeof(dirSpec), filename); - } - else - { + } else { sprintf(dirSpec, "SBST.aml"); } // Load replacement SBST new_sbst = loadACPITable(dirSpec); /* Try using the file specified with the ECDT option */ - if (getValueForKey(kECDT, &filename, &len, &bootInfo->chameleonConfig)) - { + if (getValueForKey(kECDT, &filename, &len, &bootInfo->chameleonConfig)) { snprintf(dirSpec, sizeof(dirSpec), filename); - } - else - { + } else { sprintf(dirSpec, "ECDT.aml"); } // Load replacement ECDT new_ecdt = loadACPITable(dirSpec); /* Try using the file specified with the ASF! option */ - if (getValueForKey(kASFT, &filename, &len, &bootInfo->chameleonConfig)) - { + if (getValueForKey(kASFT, &filename, &len, &bootInfo->chameleonConfig)) { snprintf(dirSpec, sizeof(dirSpec), filename); - } - else - { + } else { sprintf(dirSpec, "ASFT.aml"); } // Load replacement ASF! new_asft = loadACPITable(dirSpec); /* Try using the file specified with the DMAR option */ - if (getValueForKey(kDMAR, &filename, &len, &bootInfo->chameleonConfig)) - { + if (getValueForKey(kDMAR, &filename, &len, &bootInfo->chameleonConfig)) { snprintf(dirSpec, sizeof(dirSpec), filename); - } - else - { + } else { sprintf(dirSpec, "DMAR.aml"); } // Load replacement DMAR new_dmar = loadACPITable(dirSpec); /* Try using the file specified with the APIC option */ - if (getValueForKey(kAPIC, &filename, &len, &bootInfo->chameleonConfig)) - { + if (getValueForKey(kAPIC, &filename, &len, &bootInfo->chameleonConfig)) { snprintf(dirSpec, sizeof(dirSpec), filename); - } - else - { + } else { sprintf(dirSpec, "APIC.aml"); } // Load replacement APIC new_apic = loadACPITable(dirSpec); // Try using the file specified with the MCFG option */ - if (getValueForKey(kMCFG, &filename, &len, &bootInfo->chameleonConfig)) - { + if (getValueForKey(kMCFG, &filename, &len, &bootInfo->chameleonConfig)) { snprintf(dirSpec, sizeof(dirSpec), filename); - } - else - { + } else { sprintf(dirSpec, "MCFG.aml"); } // Load replacement MCFG @@ -998,18 +934,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; } } @@ -1023,15 +955,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; @@ -1052,8 +980,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; @@ -1064,11 +991,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; } @@ -1231,16 +1131,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++; @@ -1261,12 +1159,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 @@ -1295,8 +1190,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; @@ -1308,70 +1202,59 @@ 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; } @@ -1498,15 +1365,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++; } @@ -1534,23 +1399,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"); @@ -1573,26 +1435,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: branches/ErmaC/Enoch/i386/libsaio/spd.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/spd.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/spd.c (revision 2341) @@ -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; @@ -452,18 +418,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: branches/ErmaC/Enoch/i386/libsaio/device_inject.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/device_inject.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/device_inject.c (revision 2341) @@ -159,8 +159,7 @@ int i; - for(i = 0; i < numpaths; i++) - { + for(i = 0; i < numpaths; i++) { device->pci_dev_path[i].length = 0x06; device->pci_dev_path[i].type = 0x01; device->pci_dev_path[i].subtype = 0x01; @@ -196,46 +195,39 @@ } uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2); uint8_t *data = (uint8_t*)malloc(length); - { - if(!data) - { - return 0; - } - memset(data, 0, length); - uint32_t off= 0; - data[off+1] = ((strlen(nm) * 2) + 6) >> 8; - data[off] = ((strlen(nm) * 2) + 6) & 0x00FF; - - off += 4; - uint32_t i=0, l = strlen(nm); - for(i = 0 ; i < l ; i++, off += 2) - { - data[off] = *nm++; - } + if(!data) { + return 0; + } - off += 2; - l = len; - uint32_t *datalength = (uint32_t*)&data[off]; - *datalength = (uint32_t)(l + 4); - off += 4; - for(i = 0 ; i < l ; i++, off++) - { - data[off] = *vl++; - } + memset(data, 0, length); + uint32_t off= 0; + data[off+1] = ((strlen(nm) * 2) + 6) >> 8; + data[off] = ((strlen(nm) * 2) + 6) & 0x00FF; + + off += 4; + uint32_t i=0, l = strlen(nm); + for(i = 0 ; i < l ; i++, off += 2) { + data[off] = *nm++; } + + off += 2; + l = len; + uint32_t *datalength = (uint32_t*)&data[off]; + *datalength = (uint32_t)(l + 4); + off += 4; + for(i = 0 ; i < l ; i++, off++) { + data[off] = *vl++; + } uint32_t offset = device->length - (24 + (6 * device->num_pci_devpaths)); uint8_t *newdata = (uint8_t*)malloc((length + offset)); - if(!newdata) - { + if(!newdata) { return 0; } - if(device->data) - { - if(offset > 1) - { + if(device->data) { + if(offset > 1) { memcpy(newdata, device->data, offset); } } @@ -246,12 +238,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); } @@ -318,18 +307,14 @@ void devprop_free_string(DevPropString *string) { - if(!string) - { + if(!string) { return; } int i; - for(i = 0; i < string->numentries; i++) - { - if(string->entries[i]) - { - if(string->entries[i]->data) - { + for(i = 0; i < string->numentries; i++) { + if(string->entries[i]) { + if(string->entries[i]->data) { free(string->entries[i]->data); string->entries[i]->data = NULL; } @@ -355,8 +340,7 @@ int i; char buf[3]; - if (hex == NULL || bin == NULL || len <= 0 || strlen(hex) != len * 2) - { + if (hex == NULL || bin == NULL || len <= 0 || strlen(hex) != len * 2) { printf("[ERROR] bin2hex input error\n"); return -1; } @@ -364,10 +348,8 @@ buf[2] = '\0'; p = (char *) hex; - for (i = 0; i < len; i++) - { - if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) - { + for (i = 0; i < len; i++) { + if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) { printf("[ERROR] bin2hex '%s' syntax error\n", hex); return -2; } Index: branches/ErmaC/Enoch/i386/libsaio/device_inject.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/device_inject.h (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/device_inject.h (revision 2341) @@ -80,4 +80,5 @@ 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: branches/ErmaC/Enoch/i386/libsaio/dram_controllers.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/dram_controllers.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/dram_controllers.c (revision 2341) @@ -37,11 +37,10 @@ static void setup_p35(pci_dt_t *dram_dev) { uint32_t dev0; - + // Activate MMR I/O dev0 = pci_config_read32(dram_dev->dev.addr, 0x48); - if (!(dev0 & 0x1)) - { + if (!(dev0 & 0x1)) { pci_config_write8(dram_dev->dev.addr, 0x48, (dev0 | 1)); } } @@ -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]; } } @@ -82,43 +79,39 @@ uint32_t dev0, mch_ratio, mch_cfg, mch_fsb; long *ptr; - + // Find Ratio dev0 = pci_config_read32(dram_dev->dev.addr, 0x48); dev0 &= 0xFFFFC000; ptr = (long*)(dev0 + 0xC00); mch_cfg = *ptr & 0xFFFF; - + mch_ratio = 100000; - - switch (mch_cfg & 7) - { + + switch (mch_cfg & 7) { case 0: mch_fsb = 1066; break; case 1: mch_fsb = 533; break; - default: + default: case 2: mch_fsb = 800; break; - case 3: mch_fsb = 667; break; + case 3: mch_fsb = 667; break; case 4: mch_fsb = 1333; break; - case 6: mch_fsb = 1600; break; + case 6: mch_fsb = 1600; break; } - + DBG("mch_fsb %d\n", mch_fsb); - - switch (mch_fsb) - { + + switch (mch_fsb) { case 533: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 1: mch_ratio = 200000; break; case 2: mch_ratio = 250000; break; case 3: mch_ratio = 300000; break; } break; - + default: case 800: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 0: mch_ratio = 100000; break; case 1: mch_ratio = 125000; break; case 2: mch_ratio = 166667; break; // 1.666666667 @@ -127,10 +120,9 @@ case 5: mch_ratio = 333333; break; // 3.333333333 } break; - + case 1066: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 1: mch_ratio = 100000; break; case 2: mch_ratio = 125000; break; case 3: mch_ratio = 150000; break; @@ -138,17 +130,16 @@ case 5: mch_ratio = 250000; break; } break; - + case 1333: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 2: mch_ratio = 100000; break; case 3: mch_ratio = 120000; break; case 4: mch_ratio = 160000; break; case 5: mch_ratio = 200000; break; } break; - + case 1600: switch ((mch_cfg >> 4) & 7) { @@ -159,12 +150,12 @@ } break; } - + DBG("mch_ratio %d\n", mch_ratio); // Compute RAM Frequency Platform.RAM.Frequency = (Platform.CPU.FSBFrequency * mch_ratio) / 100000; - + DBG("ram_fsb %d\n", Platform.RAM.Frequency); } @@ -175,38 +166,34 @@ uint32_t dev0, mch_ratio, mch_cfg, mch_fsb; long *ptr; - + // Find Ratio dev0 = pci_config_read32(dram_dev->dev.addr, 0x48); dev0 &= 0xFFFFC000; ptr = (long*)(dev0 + 0xC00); mch_cfg = *ptr & 0xFFFF; - + mch_ratio = 100000; - - switch (mch_cfg & 7) - { + + switch (mch_cfg & 7) { case 1: mch_fsb = 533; break; default: case 2: mch_fsb = 800; break; - case 3: mch_fsb = 667; break; - case 6: mch_fsb = 1066; break; + case 3: mch_fsb = 667; break; + case 6: mch_fsb = 1066; break; } - - switch (mch_fsb) - { + + switch (mch_fsb) { case 533: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 1: mch_ratio = 125000; break; case 2: mch_ratio = 150000; break; case 3: mch_ratio = 200000; break; } break; - + case 667: - switch ((mch_cfg >> 4)& 7) - { + switch ((mch_cfg >> 4)& 7) { case 1: mch_ratio = 100000; break; case 2: mch_ratio = 120000; break; case 3: mch_ratio = 160000; break; @@ -214,11 +201,10 @@ case 5: mch_ratio = 240000; break; } break; - + default: case 800: - switch ((mch_cfg >> 4) & 7) - { + switch ((mch_cfg >> 4) & 7) { case 1: mch_ratio = 83333; break; // 0.833333333 case 2: mch_ratio = 100000; break; case 3: mch_ratio = 133333; break; // 1.333333333 @@ -227,16 +213,17 @@ } break; case 1066: - switch ((mch_cfg >> 4)&7) - { + switch ((mch_cfg >> 4)&7) { case 5: mch_ratio = 150000; break; case 6: mch_ratio = 200000; break; } - + } - + // Compute RAM Frequency Platform.RAM.Frequency = (Platform.CPU.FSBFrequency * mch_ratio) / 100000; + + DBG("ram_fsb %d\n", Platform.RAM.Frequency); } @@ -244,13 +231,14 @@ static void get_fsb_nhm(pci_dt_t *dram_dev) { uint32_t mch_ratio, mc_dimm_clk_ratio; - + // Get the clock ratio mc_dimm_clk_ratio = pci_config_read16(PCIADDR(nhm_bus, 3, 4), 0x54 ); mch_ratio = (mc_dimm_clk_ratio & 0x1F); - + // Compute RAM Frequency Platform.RAM.Frequency = Platform.CPU.FSBFrequency * mch_ratio / 2; + DBG("ram_fsb %d\n", Platform.RAM.Frequency); } /* @@ -259,56 +247,56 @@ // Get i965 Memory Timings static void get_timings_i965(pci_dt_t *dram_dev) -{ +{ // Thanks for CDH optis uint32_t dev0, c0ckectrl, c1ckectrl, offset; uint32_t ODT_Control_Register, Precharge_Register, ACT_Register, Read_Register, Misc_Register; long *ptr; - + // Read MMR Base Address dev0 = pci_config_read32(dram_dev->dev.addr, 0x48); dev0 &= 0xFFFFC000; - + ptr = (long*)(dev0 + 0x260); c0ckectrl = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + 0x660); c1ckectrl = *ptr & 0xFFFFFFFF; - + // If DIMM 0 not populated, check DIMM 1 ((c0ckectrl) >> 20 & 0xF) ? (offset = 0) : (offset = 0x400); - + ptr = (long*)(dev0 + offset + 0x29C); ODT_Control_Register = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + offset + 0x250); Precharge_Register = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + offset + 0x252); ACT_Register = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + offset + 0x258); Read_Register = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + offset + 0x244); Misc_Register = *ptr & 0xFFFFFFFF; - + // 965 Series only support DDR2 Platform.RAM.Type = SMB_MEM_TYPE_DDR2; - + // CAS Latency (tCAS) Platform.RAM.CAS = ((ODT_Control_Register >> 17) & 7) + 3; - + // RAS-To-CAS (tRCD) Platform.RAM.TRC = (Read_Register >> 16) & 0xF; - + // RAS Precharge (tRP) Platform.RAM.TRP = (ACT_Register >> 13) & 0xF; - + // RAS Active to precharge (tRAS) Platform.RAM.RAS = (Precharge_Register >> 11) & 0x1F; - + if ((c0ckectrl >> 20 & 0xF) && (c1ckectrl >> 20 & 0xF)) { Platform.RAM.Channels = SMB_MEM_CHANNEL_DUAL; } else { @@ -322,41 +310,41 @@ // Thanks for CDH optis uint32_t dev0, c0ckectrl, c1ckectrl, offset, ODT_Control_Register, Precharge_Register; long *ptr; - + // Read MMR Base Address dev0 = pci_config_read32(dram_dev->dev.addr, 0x48); dev0 &= 0xFFFFC000; - + ptr = (long*)(dev0 + 0x1200); c0ckectrl = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + 0x1300); c1ckectrl = *ptr & 0xFFFFFFFF; - + // If DIMM 0 not populated, check DIMM 1 ((c0ckectrl) >> 20 & 0xF) ? (offset = 0) : (offset = 0x100); - + ptr = (long*)(dev0 + offset + 0x121C); ODT_Control_Register = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + offset + 0x1214); Precharge_Register = *ptr & 0xFFFFFFFF; - + // Series only support DDR2 Platform.RAM.Type = SMB_MEM_TYPE_DDR2; - + // CAS Latency (tCAS) Platform.RAM.CAS = ((ODT_Control_Register >> 23) & 7) + 3; - + // RAS-To-CAS (tRCD) Platform.RAM.TRC = ((Precharge_Register >> 5) & 7) + 2; - + // RAS Precharge (tRP) Platform.RAM.TRP= (Precharge_Register & 7) + 2; - + // RAS Active to precharge (tRAS) Platform.RAM.RAS = (Precharge_Register >> 21) & 0x1F; - + if ((c0ckectrl >> 20 & 0xF) && (c1ckectrl >> 20 & 0xF)) { Platform.RAM.Channels = SMB_MEM_CHANNEL_DUAL; } else { @@ -366,58 +354,58 @@ // Get P35 Memory Timings static void get_timings_p35(pci_dt_t *dram_dev) -{ +{ // Thanks for CDH optis unsigned long dev0, Memory_Check, c0ckectrl, c1ckectrl, offset; unsigned long ODT_Control_Register, Precharge_Register, ACT_Register, Read_Register, Misc_Register; long *ptr; - + //Device_ID = pci_config_read16(dram_dev->dev.addr, 0x02); //Device_ID &= 0xFFFF; - + // Now, read MMR Base Address dev0 = pci_config_read32(dram_dev->dev.addr, 0x48); dev0 &= 0xFFFFC000; - + ptr = (long*)(dev0 + 0x260); - c0ckectrl = *ptr & 0xFFFFFFFF; - + c0ckectrl = *ptr & 0xFFFFFFFF; + ptr = (long*)(dev0 + 0x660); c1ckectrl = *ptr & 0xFFFFFFFF; - + // If DIMM 0 not populated, check DIMM 1 ((c0ckectrl) >> 20 & 0xF) ? (offset = 0) : (offset = 0x400); - + ptr = (long*)(dev0 + offset + 0x265); ODT_Control_Register = *ptr & 0xFFFFFFFF; - - ptr = (long*)(dev0 + offset + 0x25D); + + ptr = (long*)(dev0 + offset + 0x25D); Precharge_Register = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + offset + 0x252); ACT_Register = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + offset + 0x258); Read_Register = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + offset + 0x244); Misc_Register = *ptr & 0xFFFFFFFF; - + ptr = (long*)(dev0 + offset + 0x1E8); - Memory_Check = *ptr & 0xFFFFFFFF; - + Memory_Check = *ptr & 0xFFFFFFFF; + // On P45, check 1A8 if(dram_dev->device_id > 0x2E00) { ptr = (long*)(dev0 + offset + 0x1A8); - Memory_Check = *ptr & 0xFFFFFFFF; + Memory_Check = *ptr & 0xFFFFFFFF; Memory_Check >>= 2; Memory_Check &= 1; Memory_Check = !Memory_Check; } else { ptr = (long*)(dev0 + offset + 0x1E8); - Memory_Check = *ptr & 0xFFFFFFFF; + Memory_Check = *ptr & 0xFFFFFFFF; } - + // Determine DDR-II or DDR-III if (Memory_Check & 1) { Platform.RAM.Type = SMB_MEM_TYPE_DDR2; @@ -434,13 +422,13 @@ // RAS-To-CAS (tRCD) Platform.RAM.TRC = (Read_Register >> 17) & 0xF; - + // RAS Precharge (tRP) Platform.RAM.TRP = (ACT_Register >> 13) & 0xF; - + // RAS Active to precharge (tRAS) Platform.RAM.RAS = Precharge_Register & 0x3F; - + // Channel configuration if (((c0ckectrl >> 20) & 0xF) && ((c1ckectrl >> 20) & 0xF)) { Platform.RAM.Channels = SMB_MEM_CHANNEL_DUAL; @@ -454,14 +442,14 @@ { unsigned long mc_channel_bank_timing, mc_control, mc_channel_mrs_value; int fvc_bn = 4; - + // Find which channels are populated mc_control = pci_config_read16(PCIADDR(nhm_bus, 3, 0), 0x48); mc_control = (mc_control >> 8) & 0x7; - + // DDR-III Platform.RAM.Type = SMB_MEM_TYPE_DDR3; - + // Get the first valid channel if(mc_control & 1) { fvc_bn = 4; @@ -474,19 +462,19 @@ // Now, detect timings mc_channel_bank_timing = pci_config_read32(PCIADDR(nhm_bus, fvc_bn, 0), 0x88); mc_channel_mrs_value = pci_config_read32(PCIADDR(nhm_bus, fvc_bn, 0), 0x70); - + // CAS Latency (tCAS) Platform.RAM.CAS = ((mc_channel_mrs_value >> 4) & 0xF ) + 4; - + // RAS-To-CAS (tRCD) Platform.RAM.TRC = (mc_channel_bank_timing >> 9) & 0xF; - + // RAS Active to precharge (tRAS) Platform.RAM.RAS = (mc_channel_bank_timing >> 4) & 0x1F; - + // RAS Precharge (tRP) Platform.RAM.TRP = mc_channel_bank_timing & 0xF; - + // Single , Dual or Triple Channels if (mc_control == 1 || mc_control == 2 || mc_control == 4 ) { Platform.RAM.Channels = SMB_MEM_CHANNEL_SINGLE; @@ -564,20 +552,18 @@ static const char *memory_channel_types[] = { "Unknown", "Single", "Dual", "Triple" -}; +}; void scan_dram_controller(pci_dt_t *dram_dev) { int i; - for(i = 1; i < sizeof(dram_controllers) / sizeof(dram_controllers[0]); i++) - { - if ((dram_controllers[i].vendor == dram_dev->vendor_id) && (dram_controllers[i].device == dram_dev->device_id)) - { + for(i = 1; i < sizeof(dram_controllers) / sizeof(dram_controllers[0]); i++) { + if ((dram_controllers[i].vendor == dram_dev->vendor_id) && (dram_controllers[i].device == dram_dev->device_id)) { verbose("%s%s DRAM Controller [%4x:%4x] at %02x:%02x.%x\n", (dram_dev->vendor_id == 0x8086) ? "Intel Corporation " : "" , dram_controllers[i].name, dram_dev->vendor_id, dram_dev->device_id, dram_dev->dev.bits.bus, dram_dev->dev.bits.dev, dram_dev->dev.bits.func); - + if (dram_controllers[i].initialise != NULL) { dram_controllers[i].initialise(dram_dev); } @@ -596,7 +582,7 @@ memory_channel_types[Platform.RAM.Channels] ,Platform.RAM.CAS, Platform.RAM.TRC, Platform.RAM.TRP, Platform.RAM.RAS ,Platform.RAM.CAS, Platform.RAM.TRC, Platform.RAM.TRP, Platform.RAM.RAS); -// getchar(); +// getchar(); } } } Index: branches/ErmaC/Enoch/i386/libsaio/nvidia.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/nvidia.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/nvidia.c (revision 2341) @@ -77,6 +77,7 @@ #define WRITE_LE_SHORT(data) (((data) << 8 & 0xff00) | ((data) >> 8 & 0x00ff )) #define WRITE_LE_INT(data) (WRITE_LE_SHORT(data) << 16 | WRITE_LE_SHORT(data >> 16)) +char generic_name[128]; extern uint32_t devices_number; const char *nvidia_compatible_0[] = { "@0,compatible", "NVDA,NVMac" }; @@ -1458,45 +1459,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 +1498,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 +1528,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 +1538,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 +1627,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; } } @@ -1678,44 +1640,40 @@ static char *get_nvidia_model(uint32_t device_id, uint32_t subsys_id) { int i, j; - static char name_model[128]; + bool showGeneric = false; // First check in the plist, (for e.g this can override any hardcoded devices) cardList_t * nvcard = FindCardWithIds(device_id, subsys_id); - if (nvcard) - { - if (nvcard->model) - { + if (nvcard) { + if (nvcard->model) { return nvcard->model; } } + //ErmaC added selector for Chameleon "old" style in System Profiler + if ((getBoolForKey(kNvidiaGeneric, &showGeneric, &bootInfo->chameleonConfig) && showGeneric) == true) { + DBG("- TEST - NOT YET IMPLEMENTED.\n"); + } + // Then check the exceptions table - if (subsys_id) - { - for (i = 0; i < (sizeof(nvidia_card_exceptions) / sizeof(nvidia_card_exceptions[0])); i++) - { - if ((nvidia_card_exceptions[i].device == device_id) && (nvidia_card_exceptions[i].subdev == subsys_id)) - { + if (subsys_id) { + for (i = 0; i < (sizeof(nvidia_card_exceptions) / sizeof(nvidia_card_exceptions[0])); i++) { + if ((nvidia_card_exceptions[i].device == device_id) && (nvidia_card_exceptions[i].subdev == subsys_id)) { return nvidia_card_exceptions[i].name; + break; } } } // At last try the generic names - for (i = 1; i < (sizeof(nvidia_card_generic) / sizeof(nvidia_card_generic[0])); i++) - { - if (nvidia_card_generic[i].device == device_id) - { - if (subsys_id) - { - for (j = 0; j < (sizeof(nvidia_card_vendors) / sizeof(nvidia_card_vendors[0])); j++) - { - if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000)) - { - snprintf(name_model, sizeof(name_model), "%s %s", + for (i = 1; i < (sizeof(nvidia_card_generic) / sizeof(nvidia_card_generic[0])); i++) { + if (nvidia_card_generic[i].device == device_id) { + if (subsys_id) { + for (j = 0; j < (sizeof(nvidia_card_vendors) / sizeof(nvidia_card_vendors[0])); j++) { + if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000)) { + snprintf(generic_name, 128, "%s %s", // sizeof(generic_name), "%s %s", nvidia_card_vendors[j].name, nvidia_card_generic[i].name); - return name_model; + return &generic_name[0]; } } } @@ -1730,15 +1688,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 +1722,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 +1807,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 +1864,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 +1890,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 +1901,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 +1954,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 +1973,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 +2000,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 +2023,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 +2056,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 +2068,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 +2077,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 +2086,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: branches/ErmaC/Enoch/i386/libsaio/sys.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/sys.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/sys.c (revision 2341) @@ -121,7 +121,7 @@ //static BVRef getBootVolumeRef( const char * path, const char ** outPath ); static BVRef newBootVolumeRef( int biosdev, int partno ); -//============================================================================== +//========================================================================== // LoadVolumeFile - LOW-LEVEL FILESYSTEM FUNCTION. // Load the specified file from the specified volume // to the load buffer at LOAD_ADDR. @@ -129,7 +129,7 @@ long LoadVolumeFile(BVRef bvr, const char *filePath) { - long fileSize; + long fileSize; // Read file into load buffer. The data in the load buffer will be // overwritten by the next LoadFile() call. @@ -143,7 +143,7 @@ return fileSize; } -//============================================================================== +//========================================================================== // LoadFile - LOW-LEVEL FILESYSTEM FUNCTION. // Load the specified file to the load buffer at LOAD_ADDR. // If the file is fat, load only the i386 portion. @@ -162,7 +162,7 @@ return LoadVolumeFile(bvr, filePath); } -//============================================================================== +//========================================================================== long ReadFileAtOffset(const char * fileSpec, void *buffer, uint64_t offset, uint64_t length) { @@ -180,11 +180,11 @@ return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length); } -//============================================================================== +//========================================================================== long LoadThinFatFile(const char *fileSpec, void **binary) { - const char * filePath; + const char *filePath; FSReadFile readFile; BVRef bvr; unsigned long length, length2; @@ -239,7 +239,7 @@ return length; } -//============================================================================== +//========================================================================== #if UNUSED long GetFSUUID(char *spec, char *uuidStr) @@ -324,11 +324,13 @@ return 0; } -//============================================================================== + +//========================================================================== // GetDirEntry - LOW-LEVEL FILESYSTEM FUNCTION. // Fetch the next directory entry for the given directory. -long GetDirEntry(const char * dirSpec, long long * dirIndex, const char ** name, long * flags, long * time) +long GetDirEntry(const char * dirSpec, long long * dirIndex, const char ** name, + long * flags, long * time) { const char * dirPath; BVRef bvr; @@ -347,13 +349,14 @@ /* dirEntry */ (char **)name, flags, time, 0, 0 ); } -//============================================================================== +//========================================================================== // GetFileInfo - LOW-LEVEL FILESYSTEM FUNCTION. // Get attributes for the specified file. static char* gMakeDirSpec; -long GetFileInfo(const char * dirSpec, const char * name, long * flags, long * time) +long GetFileInfo(const char * dirSpec, const char * name, + long * flags, long * time) { long long index = 0; const char * entryName; @@ -410,7 +413,7 @@ return bvr->fs_getfileblock(bvr, (char *)filePath, firstBlock); } -//============================================================================== +//========================================================================== // GetFreeFD() static int GetFreeFd(void) @@ -428,7 +431,7 @@ return -1; } -//============================================================================== +//========================================================================== // iob_from_fdesc() // // Return a pointer to an allocated 'iob' based on the file descriptor @@ -445,7 +448,7 @@ } } -//============================================================================== +//========================================================================== // openmem() int openmem(char * buf, int len) @@ -467,7 +470,7 @@ return fdesc; } -//============================================================================== +//========================================================================== // open() - Open the file specified by 'path' for reading. static int open_bvr(BVRef bvr, const char *filePath, int flags) @@ -487,11 +490,8 @@ // Mark the descriptor as taken. io->i_flgs = F_ALLOC; - // Find the next available memory block in the download buffer. - io->i_buf = (char *) LOAD_ADDR; - for (i = 0; i < NFILES; i++) { if ((iob[i].i_flgs != F_ALLOC) || (i == fdesc)) { continue; @@ -500,15 +500,12 @@ } // Load entire file into memory. Unnecessary open() calls must be avoided. - gFSLoadAddress = io->i_buf; io->i_filesize = bvr->fs_loadfile(bvr, (char *)filePath); - if (io->i_filesize < 0) { close(fdesc); return -1; } - return fdesc; } @@ -569,7 +566,7 @@ return -1; } -//============================================================================== +//========================================================================== // close() - Close a file descriptor. int close(int fdesc) @@ -585,8 +582,7 @@ return 0; } - -//============================================================================== +//========================================================================== // lseek() - Reposition the byte offset of the file descriptor from the // beginning of the file. Returns the relocated offset. @@ -603,8 +599,7 @@ return offset; } - -//============================================================================== +//========================================================================== // tell() - Returns the byte offset of the file descriptor. int tell(int fdesc) @@ -618,8 +613,7 @@ return io->i_offset; } - -//============================================================================== +//========================================================================== // read() - Read up to 'count' bytes of data from the file descriptor // into the buffer pointed to by buf. @@ -646,8 +640,7 @@ return count; } - -//============================================================================== +//========================================================================== // write() - Write up to 'count' bytes of data to the file descriptor // from the buffer pointed to by buf. @@ -703,7 +696,7 @@ return 4; } -//============================================================================== +//========================================================================== // file_size() - Returns the size of the file described by the file // descriptor. @@ -718,9 +711,8 @@ return io->i_filesize; } +//========================================================================== -//============================================================================== - struct dirstuff * vol_opendir(BVRef bvr, const char * path) { struct dirstuff * dirp = 0; @@ -744,9 +736,8 @@ return NULL; } +//========================================================================== -//============================================================================== - struct dirstuff * opendir(const char * path) { struct dirstuff * dirp = 0; @@ -773,9 +764,8 @@ return NULL; } +//========================================================================== -//============================================================================== - int closedir(struct dirstuff * dirp) { if (dirp) { @@ -789,9 +779,8 @@ return 0; } +//========================================================================== -//============================================================================== - int readdir(struct dirstuff * dirp, const char ** name, long * flags, long * time) { @@ -801,7 +790,7 @@ /* dirEntry */ (char **)name, flags, time, 0, 0); } -//============================================================================== +//========================================================================== int readdir_ext(struct dirstuff * dirp, const char ** name, long * flags, long * time, FinderInfo *finderInfo, long *infoValid) @@ -814,7 +803,7 @@ finderInfo, infoValid); } -//============================================================================== +//========================================================================== const char * systemConfigDir() { @@ -824,7 +813,7 @@ return "/Library/Preferences/SystemConfiguration"; } -//============================================================================== +//========================================================================== int gBootFileType; @@ -843,7 +832,7 @@ } } -//============================================================================== +//========================================================================== void scanDisks(int biosdev, int *count) { @@ -865,7 +854,7 @@ } } -//============================================================================== +//========================================================================== BVRef selectBootVolume( BVRef chain ) { @@ -955,7 +944,7 @@ return bvr; } -//============================================================================== +//========================================================================== #define LP '(' #define RP ')' @@ -999,11 +988,11 @@ is changed to the selected volume unless the volume selector is that of a ramdisk. */ -BVRef getBootVolumeRef(const char * path, const char ** outPath) +BVRef getBootVolumeRef( const char * path, const char ** outPath ) { const char * cp; BVRef bvr = gRootVolume; - int biosdev = gBIOSDev; + int biosdev = gBIOSDev; // Search for left parenthesis in the path specification. @@ -1091,10 +1080,8 @@ // Bad device specifier, skip past the right paren. for (cp++; *cp && *cp != RP; cp++) /* LOOP */; - { - if (*cp == RP) { - cp++; - } + if (*cp == RP) { + cp++; } // If gRootVolume was NULL, then bvr will be NULL as well which Index: branches/ErmaC/Enoch/i386/libsaio/load.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/load.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/load.c (revision 2341) @@ -32,15 +32,6 @@ #include -/* - * Backward compatibility fix for the SDK 10.7 version of loader.h - */ - -#ifndef LC_MAIN - #define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */ -#endif - - static long DecodeSegment(long cmdBase, unsigned int*load_addr, unsigned int *load_size); static long DecodeUnixThread(long cmdBase, unsigned int *entry); static long DecodeSymbolTable(long cmdBase); @@ -63,46 +54,35 @@ uint32_t fapoffset; uint32_t fapsize; - if (fhp->magic == FAT_MAGIC) - { + if (fhp->magic == FAT_MAGIC) { nfat = fhp->nfat_arch; swapped = 0; - } - else if (fhp->magic == FAT_CIGAM) - { + } else if (fhp->magic == FAT_CIGAM) { nfat = OSSwapInt32(fhp->nfat_arch); swapped = 1; - } - else - { + } else { return -1; } - for (; nfat > 0; nfat--, fap++) - { - if (swapped) - { + for (; nfat > 0; nfat--, fap++) { + if (swapped) { fapcputype = OSSwapInt32(fap->cputype); fapoffset = OSSwapInt32(fap->offset); fapsize = OSSwapInt32(fap->size); - } - else - { + } else { fapcputype = fap->cputype; fapoffset = fap->offset; fapsize = fap->size; } - if (fapcputype == archCpuType) - { + if (fapcputype == archCpuType) { *binary = (void *) ((unsigned long)*binary + fapoffset); size = fapsize; break; } } - if (length != 0) - { + if (length != 0) { *length = size; } @@ -124,6 +104,7 @@ unsigned int entry = 0; gBinaryAddress = (unsigned long)binary; + mH = (struct mach_header *)(gBinaryAddress); #if DEBUG @@ -141,8 +122,7 @@ { case CPU_TYPE_I386: - if (mH->magic != MH_MAGIC) - { + if (mH->magic != MH_MAGIC) { error("Mach-O file has bad magic number\n"); return -1; } @@ -152,13 +132,11 @@ case CPU_TYPE_X86_64: - if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC) - { + if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC) { return -1; } - if (mH->magic != MH_MAGIC_64) - { + if (mH->magic != MH_MAGIC_64) { error("Mach-O file has bad magic number\n"); return -1; } @@ -182,11 +160,9 @@ unsigned int load_addr; unsigned int load_size; - switch (cmd) - { - case LC_SEGMENT: + switch (cmd) { case LC_SEGMENT_64: - + case LC_SEGMENT: ret = DecodeSegment(cmdBase, &load_addr, &load_size); if (ret == 0 && load_size != 0 && load_addr >= KERNEL_ADDR) @@ -196,7 +172,6 @@ } break; - case LC_MAIN: /* Mountain Lion's replacement for LC_UNIXTHREAD */ case LC_UNIXTHREAD: ret = DecodeUnixThread(cmdBase, &entry); break; @@ -212,8 +187,7 @@ } - if (ret != 0) - { + if (ret != 0) { return -1; } @@ -226,15 +200,12 @@ cmdBase = cmdstart; - for (cnt = 0; cnt < ncmds; cnt++) -{ + for (cnt = 0; cnt < ncmds; cnt++) { cmd = ((long *)cmdBase)[0]; cmdsize = ((long *)cmdBase)[1]; - if (cmd == LC_SYMTAB) - { - if (DecodeSymbolTable(cmdBase) != 0) - { + if (cmd == LC_SYMTAB) { + if (DecodeSymbolTable(cmdBase) != 0) { return -1; } } @@ -256,8 +227,7 @@ long vmsize, filesize; unsigned long vmaddr, fileaddr; - if (((long *)cmdBase)[0] == LC_SEGMENT_64) - { + if (((long *)cmdBase)[0] == LC_SEGMENT_64) { struct segment_command_64 *segCmd; segCmd = (struct segment_command_64 *)cmdBase; vmaddr = (segCmd->vmaddr & 0x3fffffff); @@ -272,9 +242,7 @@ (unsigned) segCmd->nsects, (unsigned)segCmd->flags); getchar(); #endif - } - else - { + } else { struct segment_command *segCmd; segCmd = (struct segment_command *)cmdBase; @@ -292,33 +260,28 @@ #endif } - if (vmsize == 0 || filesize == 0) - { + if (vmsize == 0 || filesize == 0) { *load_addr = ~0; *load_size = 0; return 0; } if (! ((vmaddr >= KERNEL_ADDR && (vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) || - (vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) - { - stop("Kernel overflows available space"); + (vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) { + stop("Kernel overflows available space"); } - if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) - { + if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) { gHaveKernelCache = true; } // Copy from file load area. - if (vmsize>0 && filesize > 0) - { + if (vmsize>0 && filesize > 0) { bcopy((char *)fileaddr, (char *)vmaddr, vmsize > filesize ? filesize : vmsize); } // Zero space at the end of the segment. - if (vmsize > filesize) - { + if (vmsize > filesize) { bzero((char *)(vmaddr + filesize), vmsize - filesize); } @@ -328,13 +291,11 @@ return 0; } - //============================================================================== static long DecodeUnixThread(long cmdBase, unsigned int *entry) { - switch (archCpuType) - { + switch (archCpuType) { case CPU_TYPE_I386: { i386_thread_state_t *i386ThreadState; Index: branches/ErmaC/Enoch/i386/libsaio/cpu.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/cpu.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/cpu.c (revision 2341) @@ -266,21 +266,16 @@ do_cpuid(0x00000003, p->CPU.CPUID[CPUID_3]); do_cpuid2(0x00000004, 0, p->CPU.CPUID[CPUID_4]); do_cpuid(0x80000000, p->CPU.CPUID[CPUID_80]); - if (p->CPU.CPUID[CPUID_0][0] >= 0x5) - { + if (p->CPU.CPUID[CPUID_0][0] >= 0x5) { do_cpuid(5, p->CPU.CPUID[CPUID_5]); } - if (p->CPU.CPUID[CPUID_0][0] >= 6) - { + if (p->CPU.CPUID[CPUID_0][0] >= 6) { do_cpuid(6, p->CPU.CPUID[CPUID_6]); } - if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 8) - { + if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 8) { do_cpuid(0x80000008, p->CPU.CPUID[CPUID_88]); do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]); - } - else if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) - { + } else if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) { do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]); } @@ -288,8 +283,7 @@ { int i; printf("CPUID Raw Values:\n"); - for (i=0; iCPU.CPUID[i][0], p->CPU.CPUID[i][1], p->CPU.CPUID[i][2], p->CPU.CPUID[i][3]); @@ -313,11 +307,17 @@ p->CPU.Vendor = p->CPU.CPUID[CPUID_0][1]; p->CPU.Signature = p->CPU.CPUID[CPUID_1][0]; + // stepping = cpu_feat_eax & 0xF; p->CPU.Stepping = bitfield(p->CPU.CPUID[CPUID_1][0], 3, 0); + // model = (cpu_feat_eax >> 4) & 0xF; p->CPU.Model = bitfield(p->CPU.CPUID[CPUID_1][0], 7, 4); + // family = (cpu_feat_eax >> 8) & 0xF; p->CPU.Family = bitfield(p->CPU.CPUID[CPUID_1][0], 11, 8); - p->CPU.Type = bitfield(p->CPU.CPUID[CPUID_1][0], 13, 12); + // type = (cpu_feat_eax >> 12) & 0x3; + //p->CPU.Type = bitfield(p->CPU.CPUID[CPUID_1][0], 13, 12); + // ext_model = (cpu_feat_eax >> 16) & 0xF; p->CPU.ExtModel = bitfield(p->CPU.CPUID[CPUID_1][0], 19, 16); + // ext_family = (cpu_feat_eax >> 20) & 0xFF; p->CPU.ExtFamily = bitfield(p->CPU.CPUID[CPUID_1][0], 27, 20); p->CPU.Model += (p->CPU.ExtModel << 4); @@ -326,19 +326,14 @@ p->CPU.Family == 0x06 && p->CPU.Model >= CPU_MODEL_NEHALEM && p->CPU.Model != CPU_MODEL_ATOM // MSR is *NOT* available on the Intel Atom CPU - ) - { + ) { msr = rdmsr64(MSR_CORE_THREAD_COUNT); // Undocumented MSR in Nehalem and newer CPUs p->CPU.NoCores = bitfield((uint32_t)msr, 31, 16); // Using undocumented MSR to get actual values p->CPU.NoThreads = bitfield((uint32_t)msr, 15, 0); // Using undocumented MSR to get actual values - } - else if (p->CPU.Vendor == CPUID_VENDOR_AMD) - { + } else if (p->CPU.Vendor == CPUID_VENDOR_AMD) { p->CPU.NoThreads = bitfield(p->CPU.CPUID[CPUID_1][1], 23, 16); p->CPU.NoCores = bitfield(p->CPU.CPUID[CPUID_88][2], 7, 0) + 1; - } - else - { + } else { // Use previous method for Cores and Threads p->CPU.NoThreads = bitfield(p->CPU.CPUID[CPUID_1][1], 23, 16); p->CPU.NoCores = bitfield(p->CPU.CPUID[CPUID_4][0], 31, 26) + 1; @@ -346,8 +341,7 @@ /* get brand string (if supported) */ /* Copyright: from Apple's XNU cpuid.c */ - if (p->CPU.CPUID[CPUID_80][0] > 0x80000004) - { + if (p->CPU.CPUID[CPUID_80][0] > 0x80000004) { uint32_t reg[4]; char str[128], *s; /* @@ -360,18 +354,15 @@ bcopy((char *)reg, &str[16], 16); do_cpuid(0x80000004, reg); bcopy((char *)reg, &str[32], 16); - for (s = str; *s != '\0'; s++) - { - if (*s != ' ') - { + for (s = str; *s != '\0'; s++) { + if (*s != ' ') { break; } } strlcpy(p->CPU.BrandString, s, sizeof(p->CPU.BrandString)); - if (!strncmp(p->CPU.BrandString, CPU_STRING_UNKNOWN, MIN(sizeof(p->CPU.BrandString), strlen(CPU_STRING_UNKNOWN) + 1))) - { + if (!strncmp(p->CPU.BrandString, CPU_STRING_UNKNOWN, MIN(sizeof(p->CPU.BrandString), strlen(CPU_STRING_UNKNOWN) + 1))) { /* * This string means we have a firmware-programmable brand string, * and the firmware couldn't figure out what sort of CPU we have. @@ -381,54 +372,42 @@ } /* setup features */ - if ((bit(23) & p->CPU.CPUID[CPUID_1][3]) != 0) - { + if ((bit(23) & p->CPU.CPUID[CPUID_1][3]) != 0) { p->CPU.Features |= CPU_FEATURE_MMX; } - if ((bit(25) & p->CPU.CPUID[CPUID_1][3]) != 0) - { + if ((bit(25) & p->CPU.CPUID[CPUID_1][3]) != 0) { p->CPU.Features |= CPU_FEATURE_SSE; } - if ((bit(26) & p->CPU.CPUID[CPUID_1][3]) != 0) - { + if ((bit(26) & p->CPU.CPUID[CPUID_1][3]) != 0) { p->CPU.Features |= CPU_FEATURE_SSE2; } - if ((bit(0) & p->CPU.CPUID[CPUID_1][2]) != 0) - { + if ((bit(0) & p->CPU.CPUID[CPUID_1][2]) != 0) { p->CPU.Features |= CPU_FEATURE_SSE3; } - if ((bit(19) & p->CPU.CPUID[CPUID_1][2]) != 0) - { + if ((bit(19) & p->CPU.CPUID[CPUID_1][2]) != 0) { p->CPU.Features |= CPU_FEATURE_SSE41; } - if ((bit(20) & p->CPU.CPUID[CPUID_1][2]) != 0) - { + if ((bit(20) & p->CPU.CPUID[CPUID_1][2]) != 0) { p->CPU.Features |= CPU_FEATURE_SSE42; } - if ((bit(29) & p->CPU.CPUID[CPUID_81][3]) != 0) - { + if ((bit(29) & p->CPU.CPUID[CPUID_81][3]) != 0) { p->CPU.Features |= CPU_FEATURE_EM64T; } - if ((bit(5) & p->CPU.CPUID[CPUID_1][3]) != 0) - { + if ((bit(5) & p->CPU.CPUID[CPUID_1][3]) != 0) { p->CPU.Features |= CPU_FEATURE_MSR; } //if ((bit(28) & p->CPU.CPUID[CPUID_1][3]) != 0) { - if (p->CPU.NoThreads > p->CPU.NoCores) - { + if (p->CPU.NoThreads > p->CPU.NoCores) { p->CPU.Features |= CPU_FEATURE_HTT; } tscFrequency = measure_tsc_frequency(); DBG("cpu freq classic = 0x%016llx\n", tscFrequency); /* if usual method failed */ - if ( tscFrequency < 1000 )//TEST - { + if ( tscFrequency < 1000 ) { //TEST tscFrequency = timeRDTSC() * 20;//measure_tsc_frequency(); // DBG("cpu freq timeRDTSC = 0x%016llx\n", tscFrequency); - } - else - { + } else { // DBG("cpu freq timeRDTSC = 0x%016llxn", timeRDTSC() * 20); } fsbFrequency = 0; @@ -461,8 +440,7 @@ bus_ratio_min = bitfield(msr, 47, 40); //valv: not sure about this one (Remarq.1) msr = rdmsr64(MSR_FLEX_RATIO); DBG("msr(%d): flex_ratio %08x\n", __LINE__, bitfield(msr, 31, 0)); - if (bitfield(msr, 16, 16)) - { + if (bitfield(msr, 16, 16)) { flex_ratio = bitfield(msr, 15, 8); /* bcc9: at least on the gigabyte h67ma-ud2h, where the cpu multipler can't be changed to @@ -472,63 +450,47 @@ causing the system to crash since tscGranularity is inadvertently set to 0. */ - if (flex_ratio == 0) - { + if (flex_ratio == 0) { /* Clear bit 16 (evidently the presence bit) */ wrmsr64(MSR_FLEX_RATIO, (msr & 0xFFFFFFFFFFFEFFFFULL)); msr = rdmsr64(MSR_FLEX_RATIO); verbose("Unusable flex ratio detected. Patched MSR now %08x\n", bitfield(msr, 31, 0)); - } - else - { - if (bus_ratio_max > flex_ratio) - { + } else { + if (bus_ratio_max > flex_ratio) { bus_ratio_max = flex_ratio; } } } - if (bus_ratio_max) - { + if (bus_ratio_max) { fsbFrequency = (tscFrequency / bus_ratio_max); } //valv: Turbo Ratio Limit - if ((intelCPU != 0x2e) && (intelCPU != 0x2f)) - { + if ((intelCPU != 0x2e) && (intelCPU != 0x2f)) { msr = rdmsr64(MSR_TURBO_RATIO_LIMIT); cpuFrequency = bus_ratio_max * fsbFrequency; max_ratio = bus_ratio_max * 10; - } - else - { + } else { cpuFrequency = tscFrequency; } - if ((getValueForKey(kbusratio, &newratio, &len, &bootInfo->chameleonConfig)) && (len <= 4)) - { + if ((getValueForKey(kbusratio, &newratio, &len, &bootInfo->chameleonConfig)) && (len <= 4)) { max_ratio = atoi(newratio); max_ratio = (max_ratio * 10); - if (len >= 3) - { + if (len >= 3) { max_ratio = (max_ratio + 5); } verbose("Bus-Ratio: min=%d, max=%s\n", bus_ratio_min, newratio); // extreme overclockers may love 320 ;) - if ((max_ratio >= min_ratio) && (max_ratio <= 320)) - { + if ((max_ratio >= min_ratio) && (max_ratio <= 320)) { cpuFrequency = (fsbFrequency * max_ratio) / 10; - if (len >= 3) - { + if (len >= 3) { maxdiv = 1; - } - else - { + } else { maxdiv = 0; } - } - else - { + } else { max_ratio = (bus_ratio_max * 10); } } @@ -538,46 +500,36 @@ p->CPU.MinRatio = min_ratio; myfsb = fsbFrequency / 1000000; - verbose("Sticking with [BCLK: %dMhz, Bus-Ratio: %d]\n", myfsb, max_ratio/10); + verbose("Sticking with [BCLK: %dMhz, Bus-Ratio: %d]\n", myfsb, max_ratio/10); // Bungo: fixed wrong Bus-Ratio readout currcoef = bus_ratio_max; } else { msr = rdmsr64(MSR_IA32_PERF_STATUS); DBG("msr(%d): ia32_perf_stat 0x%08x\n", __LINE__, bitfield(msr, 31, 0)); - currcoef = bitfield(msr, 12, 8); + currcoef = bitfield(msr, 12, 8); // Bungo: reverted to 2263 state because of wrong old CPUs freq. calculating /* Non-integer bus ratio for the max-multi*/ maxdiv = bitfield(msr, 46, 46); /* Non-integer bus ratio for the current-multi (undocumented)*/ currdiv = bitfield(msr, 14, 14); // This will always be model >= 3 - if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f)) - { + if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f)) { /* On these models, maxcoef defines TSC freq */ maxcoef = bitfield(msr, 44, 40); - } - else - { + } else { /* On lower models, currcoef defines TSC freq */ /* XXX */ maxcoef = currcoef; } - if (maxcoef) - { - if (maxdiv) - { + if (maxcoef) { + if (maxdiv) { fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1)); - } - else - { + } else { fsbFrequency = (tscFrequency / maxcoef); } - if (currdiv) - { + if (currdiv) { cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2); - } - else - { + } else { cpuFrequency = (fsbFrequency * currcoef); } DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : ""); @@ -660,8 +612,7 @@ } #if 0 - if (!fsbFrequency) - { + if (!fsbFrequency) { fsbFrequency = (DEFAULT_FSB * 1000); cpuFrequency = tscFrequency; DBG("0 ! using the default value for FSB !\n"); @@ -688,8 +639,7 @@ DBG("Family: 0x%x\n", p->CPU.Family); // Family ex: 6 (06h) DBG("ExtFamily: 0x%x\n", p->CPU.ExtFamily); DBG("Signature: %x\n", p->CPU.Signature); // CPUID signature - switch (p->CPU.Type) - { + /*switch (p->CPU.CpuType) { case PT_OEM: DBG("Processor type: Intel Original OEM Processor\n"); break; @@ -704,7 +654,7 @@ break; default: break; - } + }*/ DBG("Model: 0x%x\n", p->CPU.Model); // Model ex: 37 (025h) DBG("ExtModel: 0x%x\n", p->CPU.ExtModel); DBG("Stepping: 0x%x\n", p->CPU.Stepping); // Stepping ex: 5 (05h) Index: branches/ErmaC/Enoch/i386/libsaio/platform.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/platform.h (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/platform.h (revision 2341) @@ -137,7 +137,7 @@ uint32_t Vendor; // Vendor uint32_t Signature; // Processor Signature uint32_t Stepping; // Stepping - uint32_t Type; // Type + //uint32_t Type; // Type uint32_t Model; // Model uint32_t ExtModel; // Extended Model uint32_t Family; // Family Index: branches/ErmaC/Enoch/i386/libsaio/disk.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/disk.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/disk.c (revision 2341) @@ -222,6 +222,9 @@ { 0x00, 0 } }; + +//============================================================================== + static const char * bios_error(int errnum) { static char errorstr[] = "Error 0x00"; @@ -1588,6 +1591,7 @@ valid = true; bvr->OSisInstaller = true; strcpy(bvr->OSVersion, "10.7"); // 10.7 + + close(fh); } else { close(fh); } Index: branches/ErmaC/Enoch/i386/libsaio/pci_setup.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/pci_setup.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/pci_setup.c (revision 2341) @@ -2,11 +2,7 @@ #include "boot.h" #include "bootstruct.h" #include "pci.h" -//#include "gma.h" -//#include "nvidia.h" -//#include "hda.h" #include "modules.h" -//#include "device_inject.h" extern bool setup_ati_devprop(pci_dt_t *ati_dev); extern bool setup_nvidia_devprop(pci_dt_t *nvda_dev); @@ -25,8 +21,6 @@ bool doit, do_eth_devprop, do_wifi_devprop, do_usb_devprop, do_gfx_devprop, do_enable_hpet, do_hda_devprop = false; pci_dt_t *current = pci_dt; - //do_eth_devprop = do_wifi_devprop = do_usb_devprop = do_gfx_devprop = do_enable_hpet = do_hda_devprop = false; - getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->chameleonConfig); getBoolForKey(kEnableWifi, &do_wifi_devprop, &bootInfo->chameleonConfig); getBoolForKey(kGraphicsEnabler, &do_gfx_devprop, &bootInfo->chameleonConfig); @@ -34,54 +28,6 @@ getBoolForKey(kHDAEnabler, &do_hda_devprop, &bootInfo->chameleonConfig); getBoolForKey(kForceHPET, &do_enable_hpet, &bootInfo->chameleonConfig); -/* tennisgeek http://forum.voodooprojects.org/index.php/topic,1333.0.html - // Get some PCI stuff - if (hasPciToEfiMapping == -1) { - hasPciToEfiMapping = (loadSystemConfig("", &bootInfo->pciConfig, "pci.plist", true) == 0 ? 1 : 0); - if (hasPciToEfiMapping) { - verbose("pci.plist is found.\n"); - } - } - - if (hasPciToEfiMapping) { - // Device ID override injection - memset(id_array, sizeof(id_array), 0); - sprintf(override_key, "pci%04x,%04x", current->vendor_id, current->device_id); - id_count = PciToEfiOverride(override_key, id_array, 4); - device = NULL; - for (i = 0; i < id_count; i++) { - uint8_t fourOctets[4]; - uint32_t id = id_array[i]; - if (id == 0) { - if (i == 0) { - id = current->vendor_id; - } else if (i == 1) { - id = current->device_id; - } else { - continue; - } - } - - fourOctets[0] = id; - fourOctets[1] = id >> 8; - fourOctets[2] = 0; - fourOctets[3] = 0; - if (id != 0) { - if (device == NULL) { - device = devprop_find_device(devicepath); - if (device == NULL) { - deviceString = devprop_create_string(); - device = devprop_add_device(deviceString, devicepath); - } - } - devprop_add_value(device, id_keys[i], fourOctets, sizeof(fourOctets)); - verbose("%s: %s 0x%02x\n", override_key, id_keys[i], id); - } - } - current = current->next; - } -*/ // tennisgeek http://forum.voodooprojects.org/index.php/topic,1333.0.html - while (current) { devicepath = get_pci_dev_path(current); Index: branches/ErmaC/Enoch/i386/libsaio/smbios.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/smbios.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/smbios.c (revision 2341) @@ -62,8 +62,10 @@ // Bungo #define kSMBBaseBoardVersionKey "SMboardversion" // MacPro3,1 #define kSMBBaseBoardSerialNumberKey "SMboardserial" // C02140302D5DMT31M -#define kSMBBaseBoardAssetTagNumberKey "SMboardassettag" // Base Board Asset Tag# +#define kSMBBaseBoardAssetTagKey "SMboardassettag" // Base Board Asset Tag# Bungo: renamed folowing convention #define kSMBBaseBoardLocationInChassisKey "SMboardlocation" // Part Component + +// ErmaC BoardType 0x0a(10) or 0x0b(11) MacPro Family #define kSMBBaseBoardTypeKey "SMboardtype" // 10 (Motherboard) all model, 11 (Processor+Memory Module) MacPro // Bungo @@ -74,7 +76,7 @@ #define kSMBSystemEnclosureTypeKey "SMchassistype" // 7 Desktop #define kSMBSystemEnclosureVersionKey "SMchassisversion" // Mac-F42C88C8 #define kSMBSystemEnclosureSerialNumberKey "SMchassisserial" // Serial number -#define kSMBSystemEnclosureAssetTagNumberKey "SMchassisassettag" // Pro-Enclosure +#define kSMBSystemEnclosureAssetTagKey "SMchassisassettag" // Pro-Enclosure Bungo: renamed folowing convention /* ============================ Processor Information (Type 4) @@ -90,7 +92,7 @@ #define kSMBProcessorInformationCurrentClockKey "SMcurrentclock" #define kSMBProcessorInformationUpgradeKey "SMcpuupgrade" #define kSMBProcessorInformationSerialNumberKey "SMcpuserial" -#define kSMBProcessorInformationAssetTagNumberKey "SMcpuassettag" +#define kSMBProcessorInformationAssetTagKey "SMcpuassettag" // Bungo: renamed folowing convention #define kSMBProcessorInformationPartNumberKey "SMcpupartnumber" /* ===================== @@ -165,7 +167,7 @@ char *product; char *version; // Bungo char *serialNumber; // ErmaC - char *assetTagNumber; // ErmaC + char *assetTag; // ErmaC Bungo: renamed folowing convention char *locationInChassis; // ErmaC uint8_t boardType; // ErmaC } defaultBaseBoard_t; @@ -174,11 +176,11 @@ // Bungo typedef struct { - char *manufacturer; - uint8_t chassisType; - char *version; - char *serialNumber; - char *assetTagNumber; + char *manufacturer; + uint8_t chassisType; + char *version; + char *serialNumber; + char *assetTag; // Bungo: renamed folowing convention } defaultChassis_t; defaultChassis_t defaultChassis; @@ -257,8 +259,8 @@ {kSMBTypeBaseBoard, kSMBString, getFieldOffset(SMBBaseBoard, serialNumber), kSMBBaseBoardSerialNumberKey, NULL, &defaultBaseBoard.serialNumber }, // SMboardserial - C02140302D5DMT31M - {kSMBTypeBaseBoard, kSMBString, getFieldOffset(SMBBaseBoard, assetTagNumber), - kSMBBaseBoardAssetTagNumberKey, NULL, &defaultBaseBoard.assetTagNumber }, // SMboardassetag - Base Board Asset Tag# + {kSMBTypeBaseBoard, kSMBString, getFieldOffset(SMBBaseBoard, assetTag), + kSMBBaseBoardAssetTagKey, NULL, &defaultBaseBoard.assetTag }, // SMboardassetag - Base Board Asset Tag# {kSMBTypeBaseBoard, kSMBString, getFieldOffset(SMBBaseBoard, locationInChassis), kSMBBaseBoardLocationInChassisKey, NULL, &defaultBaseBoard.locationInChassis }, // SMboardlocation - Part Component @@ -282,13 +284,13 @@ kSMBSystemEnclosureTypeKey, NULL, (char **)&defaultChassis.chassisType }, // SMchassistype - 7 {kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, version), - kSMBSystemEnclosureVersionKey, NULL, &defaultBaseBoard.product }, // SMchassisversion - Mac-F42C88C8 + kSMBSystemEnclosureVersionKey, NULL, &defaultChassis.version }, // SMchassisversion - Mac-F42C88C8 {kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, serialNumber), kSMBSystemEnclosureSerialNumberKey, NULL, &defaultChassis.serialNumber }, // SMchassisserial - {kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, assetTagNumber), - kSMBSystemEnclosureAssetTagNumberKey, NULL, &defaultChassis.assetTagNumber }, // SMchassisassettag - Pro Enclosure + {kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, assetTag), + kSMBSystemEnclosureAssetTagKey, NULL, &defaultChassis.assetTag }, // SMchassisassettag - Pro Enclosure /* ============================ Processor Information (Type 4) @@ -317,16 +319,16 @@ // {kSMBTypeProcessorInformation, kSMBString, getFieldOffset(SMBProcessorInformation, serialNumber), - NULL, NULL, NULL}, + kSMBProcessorInformationSerialNumberKey, NULL, NULL}, // Bungo {kSMBTypeProcessorInformation, kSMBString, getFieldOffset(SMBProcessorInformation, assetTag), - kSMBProcessorInformationAssetTagNumberKey, NULL, NULL}, // SMcpuassettag + kSMBProcessorInformationAssetTagKey, NULL, NULL}, // SMcpuassettag // {kSMBTypeProcessorInformation, kSMBString, getFieldOffset(SMBProcessorInformation, partNumber), - NULL, NULL, NULL}, + kSMBProcessorInformationPartNumberKey, NULL, NULL}, /* ===================== Memory Device (Type 17) @@ -393,11 +395,11 @@ // Bungo: suggest to not mixing data from different Mac models, use real Mac SMBIOS dumps #define kDefaultVendorManufacturer "Apple Inc." -//#define kDefaultBIOSReleaseDate "11/06/2009" +//#define kDefaultBIOSReleaseDate "11/06/2009" #define kDefaultSerialNumber "SOMESRLNMBR" //Bungo #define kDefaultSkuNumber "Default SKU#" -#define kDefaultAssetTagNumber "Default Asset Tag#" +#define kDefaultAssetTag "Default Asset Tag#" //#define kDefaultBoardType "10" // 0xA //#define kDefaultBoardProcessorType "11" // 0xB #define kDefaultSystemVersion "1.0" @@ -456,7 +458,7 @@ //#define kDefaultMacBookProBoardAssetTagNumber "MacBook-Aluminum" #define kDefaultMacBookPro "MacBookPro4,1" -#define kDefaultMacBookProBIOSVersion " MBP41.88Z.0073.B00.0903051113" +#define kDefaultMacBookProBIOSVersion " MBP41.88Z.00C1.B03.0802271651" #define kDefaultMacBookProBIOSReleaseDate "02/27/08" #define kDefaultMacBookProBoardProduct "Mac-F42C89C8" @@ -490,7 +492,7 @@ // iMac11,1 core i3/i5/i7 #define kDefaultiMacNehalem "iMac11,1" #define kDefaultiMacNehalemBIOSVersion " IM111.88Z.0034.B02.1003171314" -#define kDefaultiMacNehalemBIOSReleaseDate "10/30/09" +#define kDefaultiMacNehalemBIOSReleaseDate "03/30/10" #define kDefaultiMacNehalemBoardProduct "Mac-F2268DAE" // iMac11,2 // iMac11,3 @@ -503,7 +505,7 @@ // iMac12,2 Mac-942B59F58194171B //#define kDefaultiMacSandy "iMac12,2" //#define kDefaultiMacSandyBIOSVersion " IM121.88Z.0047.B1D.1110171110" -//#define kDefaultiMacSandyBIOSReleaseDate "10/17/2011" +//#define kDefaultiMacSandyBIOSReleaseDate "10/17/11" //#define kDefaultiMacSandyBoardProduct "Mac-942B59F58194171B" // iMac13,2 @@ -521,15 +523,15 @@ #define kDefaultMacProBIOSVersion " MP31.88Z.006C.B05.0903051113" #define kDefaultMacProBIOSReleaseDate "08/03/2010" //#define kDefaultMacProSystemVersion "1.3" -#define kDefaultMacProBoardProduct "Mac-F2268DC8" +#define kDefaultMacProBoardProduct "Mac-F42C88C8" //#define KDefaultMacProBoardSerialNumber "J593902RA4MFE" // Mac Pro 4,1 core i7/Xeon #define kDefaultMacProNehalem "MacPro4,1" -#define kDefaultMacProNehalemBIOSVersion " MP41.88Z.0081.B04.0903051113" -#define kDefaultMacProNehalemBIOSReleaseDate "11/06/2009" +#define kDefaultMacProNehalemBIOSVersion " MP41.88Z.0081.B07.0910130729" +#define kDefaultMacProNehalemBIOSReleaseDate "10/13/09" //#define kDefaultMacProNehalemSystemVersion "1.4" -#define kDefaultMacProNehalemBoardProduct "Mac-F4238CC8" +#define kDefaultMacProNehalemBoardProduct "Mac-F221BEC8" //#define KDefaultMacProNehalemBoardSerialNumber "J593004RB1LUE" // Mac Pro 5,1 core i7/Xeon @@ -542,8 +544,8 @@ // Mac Pro 6,1 #define kDefaultMacProHaswell "MacPro6,1" -#define kDefaultMacProHaswellBIOSVersion " MP61.88Z.0116.B00.1311020956" -#define kDefaultMacProHaswellBIOSReleaseDate "06/12/13" +#define kDefaultMacProHaswellBIOSVersion " MP61.88Z.0116.B04.1312061508" +#define kDefaultMacProHaswellBIOSReleaseDate "12/06/2013" //#define kDefaultMacProHaswellSystemVersion "1.?" #define kDefaultMacProHaswellBoardProduct "Mac-F60DEB81FF30ACF6" //#define KDefaultMacProHaswellBoardSerialNumber "?????????????" @@ -578,34 +580,34 @@ defaultBaseBoard.manufacturer = kDefaultVendorManufacturer; defaultBaseBoard.serialNumber = kDefaultSerialNumber; - defaultBaseBoard.assetTagNumber = kDefaultAssetTagNumber; + defaultBaseBoard.assetTag = kDefaultAssetTag; defaultChassis.manufacturer = kDefaultVendorManufacturer; defaultChassis.serialNumber = kDefaultSerialNumber; - defaultChassis.assetTagNumber = kDefaultAssetTagNumber; + defaultChassis.assetTag = kDefaultAssetTag; // if (platformCPUFeature(CPU_FEATURE_MOBILE)) Bungo: doesn't recognise correctly if (PlatformType == 2) // this method works { if (Platform.CPU.NoCores > 1) { - defaultSystemInfo.productName = kDefaultMacBookPro; - defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion; - defaultBIOSInfo.releaseDate = kDefaultMacBookProBIOSReleaseDate; - defaultSystemInfo.family = kDefaultMacBookProFamily; - defaultBaseBoard.product = kDefaultMacBookProBoardProduct; - defaultBaseBoard.boardType = kSMBBaseBoardMotherboard; - defaultChassis.chassisType = kSMBchassisUnknown; + defaultSystemInfo.productName = kDefaultMacBookPro; + defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion; + defaultBIOSInfo.releaseDate = kDefaultMacBookProBIOSReleaseDate; + defaultSystemInfo.family = kDefaultMacBookProFamily; + defaultBaseBoard.product = kDefaultMacBookProBoardProduct; + defaultBaseBoard.boardType = kSMBBaseBoardMotherboard; + defaultChassis.chassisType = kSMBchassisUnknown; } else { - defaultSystemInfo.productName = kDefaultMacBook; - defaultBIOSInfo.version = kDefaultMacBookBIOSVersion; - defaultBIOSInfo.releaseDate = kDefaultMacBookBIOSReleaseDate; - defaultSystemInfo.family = kDefaultMacBookFamily; - defaultBaseBoard.product = kDefaultMacBookBoardProduct; - defaultBaseBoard.boardType = kSMBBaseBoardMotherboard; - defaultChassis.chassisType = kSMBchassisUnknown; + defaultSystemInfo.productName = kDefaultMacBook; + defaultBIOSInfo.version = kDefaultMacBookBIOSVersion; + defaultBIOSInfo.releaseDate = kDefaultMacBookBIOSReleaseDate; + defaultSystemInfo.family = kDefaultMacBookFamily; + defaultBaseBoard.product = kDefaultMacBookBoardProduct; + defaultBaseBoard.boardType = kSMBBaseBoardMotherboard; + defaultChassis.chassisType = kSMBchassisUnknown; } } else @@ -613,20 +615,20 @@ switch (Platform.CPU.NoCores) { case 1: - defaultBIOSInfo.version = kDefaultMacMiniBIOSVersion; - defaultBIOSInfo.releaseDate = kDefaultMacMiniBIOSReleaseDate; - defaultSystemInfo.productName = kDefaultMacMini; - defaultSystemInfo.family = kDefaultMacMiniFamily; + defaultBIOSInfo.version = kDefaultMacMiniBIOSVersion; + defaultBIOSInfo.releaseDate = kDefaultMacMiniBIOSReleaseDate; + defaultSystemInfo.productName = kDefaultMacMini; + defaultSystemInfo.family = kDefaultMacMiniFamily; defaultBaseBoard.product = kDefaultMacMiniBoardProduct; defaultBaseBoard.boardType = kSMBBaseBoardUnknown; defaultChassis.chassisType = kSMBchassisLPDesktop; break; case 2: - defaultBIOSInfo.version = kDefaultiMacBIOSVersion; - defaultBIOSInfo.releaseDate = kDefaultiMacBIOSReleaseDate; - defaultSystemInfo.productName = kDefaultiMac; - defaultSystemInfo.family = kDefaultiMacFamily; + defaultBIOSInfo.version = kDefaultiMacBIOSVersion; + defaultBIOSInfo.releaseDate = kDefaultiMacBIOSReleaseDate; + defaultSystemInfo.productName = kDefaultiMac; + defaultSystemInfo.family = kDefaultiMacFamily; defaultBaseBoard.product = kDefaultiMacBoardProduct; defaultBaseBoard.boardType = kSMBBaseBoardMotherboard; defaultChassis.chassisType = kSMBchassisAllInOne; @@ -654,10 +656,10 @@ case CPU_MODEL_SANDYBRIDGE: // Intel Core i3, i5, i7 LGA1155 (32nm) case CPU_MODEL_IVYBRIDGE: // Intel Core i3, i5, i7 LGA1155 (22nm) case CPU_MODEL_IVYBRIDGE_XEON: - defaultBIOSInfo.version = kDefaultiMacSandyBIOSVersion; - defaultBIOSInfo.releaseDate = kDefaultiMacSandyBIOSReleaseDate; + defaultBIOSInfo.version = kDefaultiMacSandyBIOSVersion; + defaultBIOSInfo.releaseDate = kDefaultiMacSandyBIOSReleaseDate; defaultSystemInfo.productName = kDefaultiMacSandy; - defaultSystemInfo.family = kDefaultiMacFamily; + defaultSystemInfo.family = kDefaultiMacFamily; defaultBaseBoard.product = kDefaultiMacSandyBoardProduct; defaultBaseBoard.boardType = kSMBBaseBoardMotherboard; defaultChassis.chassisType = kSMBchassisAllInOne; @@ -722,25 +724,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 +747,7 @@ { uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length; - if (!field) - { + if (!field) { return NULL; } @@ -766,13 +761,11 @@ { int strSize; - if (!field) - { + if (!field) { return; } - if (!string) - { + if (!string) { *field = 0; return; } @@ -780,13 +773,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 +796,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 +821,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 && *(SMBSetters[idx].defaultValue)) { string = *(SMBSetters[idx].defaultValue); break; } @@ -852,20 +838,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,20 +863,17 @@ } } - if (SMBSetters[idx].getSMBValue) - { - if (SMBSetters[idx].getSMBValue(value)) - { + if (SMBSetters[idx].getSMBValue) { + if (SMBSetters[idx].getSMBValue(value)) { return true; } } // #if 0 Bungo: enables code below // if (*(SMBSetters[idx].defaultValue)) Bungo - if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue)) + if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) { // value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo - switch (SMBSetters[idx].valueType) - { + switch (SMBSetters[idx].valueType) { case kSMBByte: value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue); break; @@ -913,8 +892,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 +998,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 +1008,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 +1045,7 @@ tableLength += structSize; - if (structSize > maxStructSize) - { + if (structSize > maxStructSize) { maxStructSize = structSize; } @@ -1090,10 +1057,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 +1079,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; } @@ -1136,7 +1100,7 @@ uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress; SMBStructHeader *structHeader = (SMBStructHeader *)ptr; int i, isZero, isOnes; - uint8_t FixedUUID[UUID_LEN] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; + uint8_t FixedUUID[UUID_LEN] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist); uint8_t *ret = (uint8_t *)getUUIDFromString(sysId); @@ -1145,8 +1109,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 +1118,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 + ret = Platform.UUID; // ...try bios dmi system uuid extraction } for (i=0, isZero=1, isOnes=1; ichameleonConfig); Bungo getBoolForKey(kSMBIOSdefaults, &useSMBIOSdefaults, &bootInfo->chameleonConfig); - // if (setSMB) - setDefaultSMBData(); - // Bungo - + // if (setSMB) Bungo + setDefaultSMBData(); + setupNewSMBIOSTable(origeps, structPtr); neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint)); - if (!neweps) - { + if (!neweps) { free(buffer); free(structPtr); return; @@ -1236,7 +1190,7 @@ neweps->anchor[3] = '_'; neweps->entryPointLength = sizeof(SMBEntryPoint); neweps->majorVersion = 2; // Bungo: - neweps->minorVersion = 4; // We're using 2.4 SMBIOS rev. as real Macs + neweps->minorVersion = 4; // Here we're using 2.4 SMBIOS rev. as real Macs neweps->maxStructureSize = maxStructSize; neweps->entryPointRevision = 0; @@ -1248,10 +1202,9 @@ neweps->dmi.tableLength = tableLength; neweps->dmi.tableAddress = AllocateKernelMemory(tableLength); neweps->dmi.structureCount = structureCount; - neweps->dmi.bcdRevision = 0x24; + neweps->dmi.bcdRevision = 0x24; // ... and 2.4 DMI rev. as real Macs - if (!neweps->dmi.tableAddress) - { + if (!neweps->dmi.tableAddress) { free(buffer); free(structPtr); return; @@ -1259,7 +1212,6 @@ memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength); - // Bungo Platform.UUID = FixSystemUUID(); // Bungo: fix System UUID neweps->dmi.checksum = 0; @@ -1276,11 +1228,9 @@ void *getSmbios(int which) { - switch (which) - { + switch (which) { case SMBIOS_ORIGINAL: - if (!origeps) - { + if (!origeps) { origeps = getAddressOfSmbiosTable(); } return origeps; @@ -1306,11 +1256,10 @@ { switch (structHeader->type) { - /* Bungo: fixed in smbios now case kSMBTypeSystemInformation: - Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; + Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; // get factory system uuid break; - */ + case kSMBTypeSystemEnclosure: // Bungo: determine platform type switch (((SMBSystemEnclosure *)structHeader)->chassisType) { case kSMBchassisDesktop: @@ -1338,12 +1287,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 +1302,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: branches/ErmaC/Enoch/i386/libsaio/smbios_decode.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/smbios_decode.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/smbios_decode.c (revision 2341) @@ -7,6 +7,9 @@ #include "libsaio.h" #include "smbios.h" +// Bungo: +#include "boot.h" +#include "bootstruct.h" #ifndef DEBUG_SMBIOS #define DEBUG_SMBIOS 0 @@ -18,54 +21,56 @@ #define DBG(x...) msglog(x) #endif -static SMBWord minorVersion; +static SMBByte minorVersion; // SMBIOS rev. minor +// Bungo: +static SMBByte majorVersion; // SMBIOS rev. major +static SMBByte bcdRevisionLo; // DMI rev. minor +static SMBByte bcdRevisionHi; // DMI rev. major extern char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field); -// Bungo: fixes random string readout if null in smbios to "Not Specified" as dmidecode dispays -#define NotSpecifiedStr "Not Specified" +// Bungo: +#define NotSpecifiedStr "Not Specified" // no string +#define OutOfSpecStr "" // value out of smbios spec. range +#define PrivateStr "** PRIVATE **" // masking private data +#define alwaysMask true +#define neverMask false +static bool privateData = true; -char *SMBStringForField(SMBStructHeader *structHeader, uint8_t field) +char *SMBStringForField(SMBStructHeader *structHeader, uint8_t field, const bool mask) // Bungo: fixes random string readout if null in smbios to "Not Specified" as dmidecode displays { - char *str; - str = getSMBStringForField(structHeader, field); - if (str == 0) - str = NotSpecifiedStr; + char *str = NULL; + str = getSMBStringForField(structHeader, field); + if (!field) { + str = NotSpecifiedStr; + } else if (mask) { + str = PrivateStr; + } return str; }; -// -// http://www.on-time.com/rtos-32-docs/rttarget-32/reference-manual/smbios/rtsmbios-oem-string.htm -// http://cvs.savannah.gnu.org/viewvc/dmidecode/dmidecode/ - -#define out_of_spec "" - -/*=== -7.2.2 -===*/ -static const char *dmi_system_wake_up_type[] = +/*==== + 7.2.2 + ===*/ +static const char *SMBWakeUpTypes[] = // Bungo: strings for wake-up type (Table Type 1 - System Information) { - "Reserved", /* 00h */ - "Other", /* 01h */ - "Unknown", /* 02h */ - "APM Timer", /* 03h */ - "Modem Ring", /* 04h */ - "LAN Remote", /* 05h */ - "Power Switch", /* 06h */ - "PCI PME#", /* 07h */ - "AC Power Restored" /* 08h */ + "Reserved", /* 00h */ + "Other", /* 01h */ + "Unknown", /* 02h */ + "APM Timer", /* 03h */ + "Modem Ring", /* 04h */ + "LAN Remote", /* 05h */ + "Power Switch", /* 06h */ + "PCI PME#", /* 07h */ + "AC Power Restored" /* 08h */ }; -static const int kdmi_system_wake_up_typeCount = sizeof(dmi_system_wake_up_type) / -sizeof(dmi_system_wake_up_type[0]); - -/*=== +/*==== 7.3.2 ===*/ -static const char *dmi_base_board_type[] = +static const char *SMBBaseBoardTypes[] = // Bungo: strings for base board type (Table Type 2 - Base Board Information) { - "Reserved", /* 00h */ "Unknown", /* 01h */ "Other", /* 02h */ "Server Blade", /* 03h */ @@ -81,48 +86,92 @@ "Interconnect Board" /* 0Dh */ }; -static const int kdmi_base_board_type = sizeof(dmi_base_board_type) / -sizeof(dmi_base_board_type[0]); - /*=== 7.4.1 ===*/ -static const char *dmi_chassis_type[] = +static const char *SMBChassisTypes[] = // Bungo: strings for chassis type (Table Type 3 - Chassis Information) { - "Reserved", /* 00h */ - "Other", /* 01h */ - "Unknown", /* 02h */ - "Desktop", /* 03h */ - "Low Profile Desktop", /* 04h */ - "Pizza Box", /* 05h */ - "Mini Tower", /* 06h */ - "Tower", /* 07h */ - "Portable", /* 08h */ - "Laptop", /* 09h */ - "Notebook", /* 0Ah */ - "Hand Held", /* 0Bh */ - "Docking Station", /* 0Ch */ - "All in One", /* 0Dh */ - "Sub Notebook", /* 0Eh */ - "Space-saving", /* 0Fh */ - "Lunch Box", /* 10h */ - "Main Server Chassis", /* 11h */ - "Expansion Chassis", /* 12h */ - "SubChassis", /* 13h */ - "Bus Expansion Chassis",/* 14h */ - "Peripheral Chassis", /* 15h */ - "RAID Chassis", /* 16h */ - "Rack Mount Chassis", /* 17h */ - "Sealed-case PC", /* 18h */ - "Multi-system chassis", /* 19h */ - "Compact PCI", /* 1Ah */ - "Advanced TCA", /* 1Bh */ - "Blade", /* 1Ch */ // An SMBIOS implementation for a Blade would contain a Type 3 Chassis structure - "Blade Enclosing" /* 1Dh */ // A Blade Enclosure is a specialized chassis that contains a set of Blades. + "Other", /* 01h */ + "Unknown", /* 02h */ + "Desktop", /* 03h */ + "Low Profile Desktop", /* 04h */ + "Pizza Box", /* 05h */ + "Mini Tower", /* 06h */ + "Tower", /* 07h */ + "Portable", /* 08h */ + "Laptop", /* 09h */ + "Notebook", /* 0Ah */ + "Hand Held", /* 0Bh */ + "Docking Station", /* 0Ch */ + "All in One", /* 0Dh */ + "Sub Notebook", /* 0Eh */ + "Space-saving", /* 0Fh */ + "Lunch Box", /* 10h */ + "Main Server Chassis", /* 11h */ + "Expansion Chassis", /* 12h */ + "SubChassis", /* 13h */ + "Bus Expansion Chassis",/* 14h */ + "Peripheral Chassis", /* 15h */ + "RAID Chassis", /* 16h */ + "Rack Mount Chassis", /* 17h */ + "Sealed-case PC", /* 18h */ + "Multi-system Chassis", /* 19h */ + "Compact PCI", /* 1Ah */ + "Advanced TCA", /* 1Bh */ + "Blade", /* 1Ch */ // An SMBIOS implementation for a Blade would contain a Type 3 Chassis structure + "Blade Enclosing" /* 1Dh */ // A Blade Enclosure is a specialized chassis that contains a set of Blades. }; -static const int kdmi_chassis_typeCount = sizeof(dmi_chassis_type) / -sizeof(dmi_chassis_type[0]); +/*==== + 7.5.5 + ===*/ +/*static const char *SMBCpuSocket[] = // ErmaC: strings for (Table Type 4 - Processor Information ) +{ + "Other", // 01h + "Unknown", + "Daughter Board", + "ZIF Socket", + "Replaceable Piggy Back", + "None", + "LIF Socket", + "Slot 1", + "Slot 2", + "370-pin Socket", + "Slot A", + "Slot M", + "Socket 423", + "Socket A (Socket 462)", + "Socket 478", + "Socket 754", + "Socket 940", + "Socket 939", + "Socket mPGA604", + "Socket LGA771", + "Socket LGA775", + "Socket S1", + "Socket AM2", + "Socket F (1207)", + "Socket LGA1366", + "Socket G34", + "Socket AM3", + "Socket C32", + "Socket LGA1156", + "Socket LGA1567", + "Socket PGA988A", + "Socket BGA1288", + "Socket rPGA988B", + "Socket BGA1023", + "Socket BGA1224", + "Socket BGA1155", + "Socket LGA1356", + "Socket LGA2011", + "Socket FS1", + "Socket FS2", + "Socket FM1", + "Socket FM2", + "Socket LGA2011-3", + "Socket LGA1356-3" // 2Ch +};*/ /*===== 7.18.2 @@ -130,32 +179,32 @@ static const char * SMBMemoryDeviceTypes[] = { - "RAM", /* 00h Undefined */ - "RAM", /* 01h Other */ - "RAM", /* 02h Unknown */ - "DRAM", /* 03h DRAM */ - "EDRAM", /* 04h EDRAM */ - "VRAM", /* 05h VRAM */ - "SRAM", /* 06h SRAM */ - "RAM", /* 07h RAM */ - "ROM", /* 08h ROM */ - "FLASH", /* 09h FLASH */ - "EEPROM", /* 0Ah EEPROM */ - "FEPROM", /* 0Bh FEPROM */ - "EPROM", /* 0Ch EPROM */ - "CDRAM", /* 0Dh CDRAM */ - "3DRAM", /* 0Eh 3DRAM */ - "SDRAM", /* 0Fh SDRAM */ - "SGRAM", /* 10h SGRAM */ - "RDRAM", /* 11h RDRAM */ - "DDR SDRAM", /* 12h DDR */ - "DDR2 SDRAM", /* 13h DDR2 */ - "DDR2 FB-DIMM", /* 14h DDR2 FB-DIMM */ - "RAM", /* 15h unused */ - "RAM", /* 16h unused */ - "RAM", /* 17h unused */ - "DDR3", /* 18h DDR3, chosen in [5776134] */ - "FBD2" /* 19h FBD2 */ + "RAM", /* 00h Undefined */ + "RAM", /* 01h Other */ + "RAM", /* 02h Unknown */ + "DRAM", /* 03h DRAM */ + "EDRAM", /* 04h EDRAM */ + "VRAM", /* 05h VRAM */ + "SRAM", /* 06h SRAM */ + "RAM", /* 07h RAM */ + "ROM", /* 08h ROM */ + "FLASH", /* 09h FLASH */ + "EEPROM", /* 0Ah EEPROM */ + "FEPROM", /* 0Bh FEPROM */ + "EPROM", /* 0Ch EPROM */ + "CDRAM", /* 0Dh CDRAM */ + "3DRAM", /* 0Eh 3DRAM */ + "SDRAM", /* 0Fh SDRAM */ + "SGRAM", /* 10h SGRAM */ + "RDRAM", /* 11h RDRAM */ + "DDR SDRAM", /* 12h DDR */ + "DDR2 SDRAM", /* 13h DDR2 */ + "DDR2 FB-DIMM", /* 14h DDR2 FB-DIMM */ + "RAM", /* 15h unused */ + "RAM", /* 16h unused */ + "RAM", /* 17h unused */ + "DDR3", /* 18h DDR3, chosen in [5776134] */ + "FBD2" /* 19h FBD2 */ }; static const int kSMBMemoryDeviceTypeCount = sizeof(SMBMemoryDeviceTypes) / @@ -167,10 +216,11 @@ void decodeBIOSInformation(SMBBIOSInformation *structHeader) { DBG("BIOS Information:\n"); - DBG("\tVendor: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->vendor)); - DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); + DBG("\tVendor: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->vendor, neverMask)); + DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version, neverMask)); // Address Segment - DBG("\tRelease Date: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->releaseDate)); + DBG("\tRelease Date: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->releaseDate, neverMask)); + DBG("\tBIOS Revision: %d.%d\n", structHeader->releaseMajor, structHeader->releaseMinor); // ROM Size //DBG("\tSupported BIOS functions: (0x%llX) %s\n", structHeader->characteristics, SMBBIOSInfoChar0[structHeader->characteristics]); // Major Release @@ -188,25 +238,37 @@ void decodeSystemInformation(SMBSystemInformation *structHeader) { DBG("System Information:\n"); - DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); - DBG("\tProduct Name: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->productName)); - DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); - DBG("\tSerial Number: ** PRIVATE **\n"); //%s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); + DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer, neverMask)); + DBG("\tProduct Name: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->productName, neverMask)); + DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version, neverMask)); + DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber, privateData)); - if (minorVersion < 1 || structHeader->header.length < 25) + if (minorVersion < 1 || structHeader->header.length < 25) { return; + } + uint8_t *uuid = structHeader->uuid; if (uuid) { - DBG("\tuuid: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02x%02X-%02X%02X%02X%02X%02X%02X\n", - uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], - uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); + if (privateData) { + DBG("\tUUID: %s\n", PrivateStr); + } else { + DBG("\tUUID: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02x%02X-%02X%02X%02X%02X%02X%02X\n", + uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], + uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); + } } - DBG("\tWake-up Type: 0x%x\n", structHeader->wakeupReason); - if (minorVersion < 4 || structHeader->header.length < 27) + if (structHeader->wakeupReason > 8) { + DBG("\tWake-up Type: %s\n", OutOfSpecStr); + } else { + DBG("\tWake-up Type: %s\n", SMBWakeUpTypes[structHeader->wakeupReason]); + } + if (minorVersion < 4 || structHeader->header.length < 27) { return; - DBG("\tSKU Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->skuNumber)); // System SKU# - DBG("\tFamily: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->family)); + } + + DBG("\tSKU Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->skuNumber, neverMask)); // System SKU# + DBG("\tFamily: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->family, neverMask)); DBG("\n"); } @@ -216,15 +278,19 @@ void decodeBaseBoard(SMBBaseBoard *structHeader) { DBG("Base Board Information:\n"); - DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); - DBG("\tProduct Name: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->product)); - DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); - DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); - DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber)); + DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer, neverMask)); + DBG("\tProduct Name: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->product, neverMask)); + DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version, neverMask)); + DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber, privateData)); + DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag, neverMask)); // Feature Flags (BYTE) - DBG("\tLocation In Chassis: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->locationInChassis)); // Part Component + DBG("\tLocation In Chassis: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->locationInChassis, neverMask)); // Part Component // Chassis Handle (WORD) - DBG("\tType: 0x%X\n", structHeader->boardType); + if ((structHeader->boardType < kSMBBaseBoardUnknown) || (structHeader->boardType > kSMBBaseBoardInterconnect)) { + DBG("\tType: %s\n", OutOfSpecStr); + } else { + DBG("\tType: %s\n", SMBBaseBoardTypes[(structHeader->boardType - 1)]); + } // Number of Contained Object Handles (n) (BYTE) // Contained Object Handles n(WORDs) DBG("\n"); @@ -236,11 +302,16 @@ void decodeSystemEnclosure(SMBSystemEnclosure *structHeader) { DBG("Chassis Information:\n"); - DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); - DBG("\tType: 0x%X\n", structHeader->chassisType); - DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); - DBG("\tSerial Number: ** PRIVATE **\n"); //%s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); - DBG("\tAsset Tag Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber)); + DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer, neverMask)); + // DBG("\tType: 0x%X\n", structHeader->chassisType); + if ((structHeader->chassisType < kSMBchassisOther) || (structHeader->chassisType > kSMBchassisBladeEnclosing)) { + DBG("\tType: %s\n", OutOfSpecStr); + } else { + DBG("\tType: %s\n", SMBChassisTypes[(structHeader->chassisType - 1)]); + } + DBG("\tVersion: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->version, neverMask)); + DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber, privateData)); + DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag, neverMask)); // Boot-up State: // Power Supply State // Thermal State @@ -260,22 +331,24 @@ void decodeProcessorInformation(SMBProcessorInformation *structHeader) { DBG("Processor Information:\n"); - DBG("\tSocket Designation: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->socketDesignation)); + DBG("\tSocket Designation: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->socketDesignation, neverMask)); DBG("\tType: %d\n", structHeader->processorType); DBG("\tFamily: 0x%X\n", structHeader->processorFamily); - DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); + DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer, neverMask)); DBG("\tID: 0x%llX\n", structHeader->processorID); - DBG("\tProcessor Version: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->processorVersion)); + DBG("\tProcessor Version: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->processorVersion, neverMask)); // DBG("\tVoltage: 0.%xV\n", structHeader->voltage); DBG("\tExternal Clock: %dMHz\n", structHeader->externalClock); DBG("\tMaximum Clock: %dMHz\n", structHeader->maximumClock); DBG("\tCurrent Clock: %dMHz\n", structHeader->currentClock); - if (minorVersion < 3 || structHeader->header.length < 35) + if (minorVersion < 3 || structHeader->header.length < 35) { return; - DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); - DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag)); - DBG("\tPart Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber)); + } + + DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber, privateData)); + DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag, neverMask)); + DBG("\tPart Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber, neverMask)); // DBG("\tProcessor Family 2: %d\n", structHeader->processorFamily2); DBG("\n"); } @@ -314,18 +387,19 @@ void decodeMemoryDevice(SMBMemoryDevice *structHeader) { DBG("Memory Device:\n"); - DBG("\tDevice Locator: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->deviceLocator)); - DBG("\tBank Locator: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->bankLocator)); + DBG("\tDevice Locator: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->deviceLocator, neverMask)); + DBG("\tBank Locator: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->bankLocator, neverMask)); DBG("\tMemory Type: %s\n", SMBMemoryDeviceTypes[structHeader->memoryType]); - if (minorVersion < 3 || structHeader->header.length < 27) + if (minorVersion < 3 || structHeader->header.length < 27) { return; + } DBG("\tSpeed: %d MHz\n", structHeader->memorySpeed); DBG("\tError Handle: %x\n", structHeader->errorHandle); - DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); - DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); - DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag)); - DBG("\tPart Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber)); + DBG("\tManufacturer: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer, neverMask)); + DBG("\tSerial Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber, privateData)); + DBG("\tAsset Tag: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag, neverMask)); + DBG("\tPart Number: %s\n", SMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber, neverMask)); DBG("\n"); } @@ -334,15 +408,15 @@ //------------------------------------------------------------------------------------------------------------------------- void decodeOemProcessorType(SMBOemProcessorType *structHeader) { - DBG("AppleProcessorType:\n"); - DBG("\tProcessorType: 0x%x\n", ((SMBOemProcessorType *)structHeader)->ProcessorType); + DBG("Apple specific Processor Type:\n"); + DBG("\tCpu-type: 0x%x\n", ((SMBOemProcessorType *)structHeader)->ProcessorType); DBG("\n"); } void decodeOemProcessorBusSpeed(SMBOemProcessorBusSpeed *structHeader) { - DBG("AppleProcessorBusSpeed:\n"); - DBG("\tProcessorBusSpeed (QPI): %d.%dGT/s\n", + DBG("Apple specific Processor Interconnect Speed:\n"); + DBG("\tQPI = %d.%dGT/s\n", ((SMBOemProcessorBusSpeed *)structHeader)->ProcessorBusSpeed / 1000, (((SMBOemProcessorBusSpeed *)structHeader)->ProcessorBusSpeed / 100) % 10); DBG("\n"); @@ -356,11 +430,18 @@ SMBStructHeader *structHeader = (SMBStructHeader *)ptr; minorVersion = eps->minorVersion; + majorVersion = eps->majorVersion; + bcdRevisionHi = eps->dmi.bcdRevision >> 4; + bcdRevisionLo = eps->dmi.bcdRevision & 0x0F; + getBoolForKey(kPrivateData, &privateData, &bootInfo->chameleonConfig); // Bungo: chek if mask some data + DBG("\n"); + DBG("SMBIOS rev. %d.%d, DMI rev. %d.%d\n", majorVersion, minorVersion, bcdRevisionHi, bcdRevisionLo); + DBG("\n"); for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));) { - DBG("Type: %d, Length: %d, Handle: 0x%x\n", + DBG("Type: %d, Length: %d, Handle: 0x%04x\n", structHeader->type, structHeader->length, structHeader->handle); switch (structHeader->type) @@ -397,6 +478,8 @@ decodeMemoryDevice((SMBMemoryDevice *)structHeader); break; + //kSMBTypeMemoryArrayMappedAddress: // Type 19 + /* Skip all Apple Specific Structures */ case kSMBTypeFirmwareVolume: // Type 128 case kSMBTypeMemorySPD: // Type 130 @@ -410,6 +493,8 @@ decodeOemProcessorBusSpeed((SMBOemProcessorBusSpeed *)structHeader); break; + //kSMBTypeOemPlatformFeature: // Type 133 + case kSMBTypeEndOfTable: // Type 127 /* Skip, to be added at the end */ break; @@ -421,8 +506,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: branches/ErmaC/Enoch/i386/libsaio/hpet.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/hpet.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/hpet.c (revision 2341) @@ -130,31 +130,6 @@ { 0x1106, 0x3372, "VT8237S" }, }; - -void force_enable_hpet(pci_dt_t *lpc_dev) -{ - switch(lpc_dev->vendor_id) - { - case 0x8086: - force_enable_hpet_intel(lpc_dev); - break; - - case 0x10de: - force_enable_hpet_nvidia(lpc_dev); - break; - - case 0x1106: - force_enable_hpet_via(lpc_dev); - break; - } - -#if DEBUG_HPET - printf("Press [Enter] to continue...\n"); - getchar(); -#endif - -} - /* ErmaC add lpc for nVidia */ void force_enable_hpet_nvidia(pci_dt_t *lpc_dev) { @@ -162,32 +137,24 @@ int i; void *rcba; - for(i = 1; i < sizeof(lpc_controllers_nvidia) / sizeof(lpc_controllers_nvidia[0]); i++) - { - if ((lpc_controllers_nvidia[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_nvidia[i].device == lpc_dev->device_id)) - { + for(i = 1; i < sizeof(lpc_controllers_nvidia) / sizeof(lpc_controllers_nvidia[0]); i++) { + if ((lpc_controllers_nvidia[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_nvidia[i].device == lpc_dev->device_id)) { rcba = (void *)(pci_config_read32(lpc_dev->dev.addr, 0xF0) & 0xFFFFC000); DBG("nVidia(R) %s LPC Interface [%04x:%04x], MMIO @ 0x%lx\n", lpc_controllers_nvidia[i].name, lpc_dev->vendor_id, lpc_dev->device_id, rcba); - if (rcba == 0) - { + if (rcba == 0) { printf(" RCBA disabled; cannot force enable HPET\n"); - } - else - { + } else { val = REG32(rcba, 0x3404); - if (val & 0x80) - { + if (val & 0x80) { // HPET is enabled in HPTC. Just not reported by BIOS DBG(" HPET is enabled in HPTC, just not reported by BIOS\n"); hpet_address |= (val & 3) << 12 ; DBG(" HPET MMIO @ 0x%lx\n", hpet_address); - } - else - { + } else { // HPET disabled in HPTC. Trying to enable DBG(" HPET is disabled in HPTC, trying to enable\n"); REG32(rcba, 0x3404) = val | 0x80; @@ -197,8 +164,7 @@ // verify if the job is done val = REG32(rcba, 0x3404); - if (!(val & 0x80)) - { + if (!(val & 0x80)) { printf(" Failed to force enable HPET\n"); } } @@ -212,32 +178,24 @@ uint32_t val, hpet_address = 0xFED00000; int i; - for(i = 1; i < sizeof(lpc_controllers_via) / sizeof(lpc_controllers_via[0]); i++) - { - if ((lpc_controllers_via[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_via[i].device == lpc_dev->device_id)) - { + for(i = 1; i < sizeof(lpc_controllers_via) / sizeof(lpc_controllers_via[0]); i++) { + if ((lpc_controllers_via[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_via[i].device == lpc_dev->device_id)) { val = pci_config_read32(lpc_dev->dev.addr, 0x68); DBG("VIA %s LPC Interface [%04x:%04x], MMIO\n", lpc_controllers_via[i].name, lpc_dev->vendor_id, lpc_dev->device_id); - if (val & 0x80) - { + if (val & 0x80) { hpet_address = (val & ~0x3ff); DBG("HPET at 0x%lx\n", hpet_address); - } - else - { + } else { val = 0xfed00000 | 0x80; pci_config_write32(lpc_dev->dev.addr, 0x68, val); val = pci_config_read32(lpc_dev->dev.addr, 0x68); - if (val & 0x80) - { + if (val & 0x80) { hpet_address = (val & ~0x3ff); DBG("Force enabled HPET at 0x%lx\n", hpet_address); - } - else - { + } else { DBG("Unable to enable HPET"); } } @@ -252,32 +210,24 @@ void *rcba; /* LPC on Intel ICH is always (?) at 00:1f.0 */ - for(i = 1; i < sizeof(lpc_controllers_intel) / sizeof(lpc_controllers_intel[0]); i++) - { - if ((lpc_controllers_intel[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_intel[i].device == lpc_dev->device_id)) - { + for(i = 1; i < sizeof(lpc_controllers_intel) / sizeof(lpc_controllers_intel[0]); i++) { + if ((lpc_controllers_intel[i].vendor == lpc_dev->vendor_id) && (lpc_controllers_intel[i].device == lpc_dev->device_id)) { rcba = (void *)(pci_config_read32(lpc_dev->dev.addr, 0xF0) & 0xFFFFC000); DBG("Intel(R) %s LPC Interface [%04x:%04x], MMIO @ 0x%lx\n", lpc_controllers_intel[i].name, lpc_dev->vendor_id, lpc_dev->device_id, rcba); - if (rcba == 0) - { + if (rcba == 0) { printf(" RCBA disabled; cannot force enable HPET\n"); - } - else - { + } else { val = REG32(rcba, 0x3404); - if (val & 0x80) - { + if (val & 0x80) { // HPET is enabled in HPTC. Just not reported by BIOS DBG(" HPET is enabled in HPTC, just not reported by BIOS\n"); hpet_address |= (val & 3) << 12 ; DBG(" HPET MMIO @ 0x%lx\n", hpet_address); - } - else - { + } else { // HPET disabled in HPTC. Trying to enable DBG(" HPET is disabled in HPTC, trying to enable\n"); REG32(rcba, 0x3404) = val | 0x80; @@ -287,8 +237,7 @@ // verify if the job is done val = REG32(rcba, 0x3404); - if (!(val & 0x80)) - { + if (!(val & 0x80)) { printf(" Failed to force enable HPET\n"); } } @@ -297,3 +246,25 @@ } } +void force_enable_hpet(pci_dt_t *lpc_dev) +{ + switch(lpc_dev->vendor_id) { + case 0x8086: + force_enable_hpet_intel(lpc_dev); + break; + + case 0x10de: + force_enable_hpet_nvidia(lpc_dev); + break; + + case 0x1106: + force_enable_hpet_via(lpc_dev); + break; + } + +#if DEBUG_HPET + printf("Press [Enter] to continue...\n"); + getchar(); +#endif + +} Index: branches/ErmaC/Enoch/i386/libsaio/smbios.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/smbios.h (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/smbios.h (revision 2341) @@ -191,7 +191,7 @@ SMBString product; SMBString version; SMBString serialNumber; - SMBString assetTagNumber; + SMBString assetTag; // Bungo: renamed from assetTagNumber folowing convention SMBByte featureFlags; // Collection of flag that identify features of this baseboard SMBString locationInChassis; SMBWord chassisHandle; @@ -231,11 +231,10 @@ { SMB_STRUCT_HEADER // Type 3 SMBString manufacturer; -// SMBByte type; Bungo: renamed to chassisType - convention SMBByte chassisType; // System Enclosure Indicator SMBString version; // Board Number? SMBString serialNumber; - SMBString assetTagNumber; + SMBString assetTag; // Bungo: renamed from assetTagNumber folowing convention SMBByte bootupState; // State of enclosure when when it was last booted SMBByte powerSupplyState; // State of enclosure's power supply when last booted SMBByte thermalState; // Thermal state of the enclosure when last booted @@ -265,9 +264,10 @@ kSMBchassisDockingStation = 0x0C, kSMBchassisAllInOne = 0x0D, kSMBchassisSubNotebook = 0x0E, - // ... - kSMBchassisLunchBox = 0x10 - // fill up if needed ;-) + // ... fill up if needed ;-) + kSMBchassisLunchBox = 0x10, + // ... fill up if needed ;-) + kSMBchassisBladeEnclosing = 0x1D }; /* ============================ Index: branches/ErmaC/Enoch/i386/libsaio/biosfn.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/biosfn.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/biosfn.c (revision 2341) @@ -396,7 +396,6 @@ bb.eax.r.h = 0x00; bios(&bb); } - return bb.eax.r.h; } @@ -903,7 +902,6 @@ } checked = true; } - return (isEISA); } Index: branches/ErmaC/Enoch/i386/libsaio/convert.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/convert.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/convert.c (revision 2341) @@ -104,10 +104,11 @@ { binChar = 0; - for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) - { - if (hexNibbleIdx > 0) binChar = binChar << 4; - + for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) { + if (hexNibbleIdx > 0) { + binChar = binChar << 4; + } + if (hexByte[hexNibbleIdx] <= '9') binChar += hexByte[hexNibbleIdx] - '0'; else if (hexByte[hexNibbleIdx] <= 'F') binChar += hexByte[hexNibbleIdx] - ('A' - 10); else if (hexByte[hexNibbleIdx] <= 'f') binChar += hexByte[hexNibbleIdx] - ('a' - 10); Index: branches/ErmaC/Enoch/i386/libsaio/pci.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/pci.h (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/pci.h (revision 2341) @@ -30,7 +30,7 @@ } pci_dev_t; typedef struct pci_dt_t { - uint8_t* regs; + uint8_t* regs; pci_dev_t dev; uint16_t devfn; /* encoded device & function index */ @@ -71,15 +71,23 @@ 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 *); -//----------------------------------------------------------------------------- -// added by iNDi +/* Option ROM header */ +typedef struct { + uint16_t signature; // 0xAA55 + uint8_t rom_size; //in 512 bytes blocks + uint8_t jump; //0xE9 for ATI and Intel, 0xEB for NVidia + uint32_t entry_point; + uint8_t reserved[16]; + uint16_t pci_header_offset; //@0x18 + uint16_t expansion_header_offset; +} option_rom_header_t; /* Option ROM PCI Data Structure */ typedef struct { @@ -97,6 +105,8 @@ uint16_t reserved; } option_rom_pci_header_t; +//----------------------------------------------------------------------------- +// added by iNDi typedef struct { uint32_t signature; // 0x24506E50 '$PnP' @@ -116,18 +126,6 @@ uint16_t resource_vector; } option_rom_pnp_header_t; -/* Option ROM header */ -typedef struct { - uint16_t signature; // 0xAA55 - uint8_t rom_size; //in 512 bytes blocks - uint8_t jump; //0xE9 for ATI and Intel, 0xEB for NVidia - uint8_t entry_point[4]; //offset to - uint8_t reserved[16]; - uint16_t pci_header_offset; //@0x18 - uint16_t expansion_header_offset; -} option_rom_header_t; - - /* * Under PCI, each device has 256 bytes of configuration address space, * of which the first 64 bytes are standardized as follows: Index: branches/ErmaC/Enoch/i386/libsaio/msdos.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/msdos.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/msdos.c (revision 2341) @@ -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; } @@ -842,8 +838,7 @@ if (filePath[0] == '/') filePath++; buf = malloc(msdosclustersize); - if (!buf) - { + if (!buf) { return -1; } dirp = getdirpfrompath (ih, filePath, buf); @@ -938,8 +933,7 @@ initRoot (&st); st.buf = malloc(msdosclustersize); - if (!st.buf) - { + if (!st.buf) { return; } while ((dirp = getnextdirent (ih, vfatlabel, &st))) @@ -948,7 +942,7 @@ labelfound = 1; break; } - + free(st.buf); if (vfatlabel[0] && labelfound) @@ -971,9 +965,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) @@ -991,8 +983,7 @@ MSDOSGetUUID(CICell ih, char *uuidStr) { char *buf = malloc (512); - if (!buf) - { + if (!buf) { return -1; } union bootsector *bsp = (union bootsector *)buf; @@ -1013,5 +1004,5 @@ } free (buf); return 0; - + } Index: branches/ErmaC/Enoch/i386/libsaio/md5c.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/md5c.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/md5c.c (revision 2341) @@ -151,8 +151,7 @@ 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]++; } @@ -162,19 +161,18 @@ /* Transform as many times as possible. */ - if (inputLen >= partLen) - { + if (inputLen >= partLen) { memcpy((void *)&context->buffer[index], (const void *)input, partLen); MD5Transform (context->state, context->buffer); - for (i = partLen; i + 63 < inputLen; i += 64) + for (i = partLen; i + 63 < inputLen; i += 64) { MD5Transform (context->state, &((const unsigned char *)input)[i]); - + } index = 0; - } - else + } else { i = 0; + } /* Buffer remaining input */ memcpy ((void *)&context->buffer[index], (const void *)&((const unsigned char*)input)[i], Index: branches/ErmaC/Enoch/i386/libsaio/fake_efi.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/fake_efi.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/fake_efi.c (revision 2341) @@ -73,7 +73,7 @@ */ /* Identify ourselves as the EFI firmware vendor */ -static EFI_CHAR16 const FIRMWARE_VENDOR[] = { 'E', 'n', 'o', 'c', 'h', '\0' }; +static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'E','n','o','c','h', 0}; static EFI_UINT32 const FIRMWARE_REVISION = 132; /* FIXME: Find a constant for this. */ // Bungo @@ -628,14 +628,13 @@ // Bungo /* Export system-id. Can be disabled with SystemId=No in com.apple.Boot.plist - if ((ret=getSystemID())) - { + if ((ret=getSystemID())) { DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) ret); } */ - DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, Platform.UUID); - // + DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32 *)Platform.UUID); + // Export SystemSerialNumber if present if ((ret16=getSmbiosChar16("SMserial", &len))) { Index: branches/ErmaC/Enoch/i386/libsaio/smbios_getters.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/smbios_getters.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsaio/smbios_getters.c (revision 2341) @@ -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); } @@ -71,8 +67,7 @@ switch (Platform.CPU.Family) { case 0x06: { - switch (Platform.CPU.Model) - { + switch (Platform.CPU.Model) { case CPU_MODEL_PENTIUM_M: case CPU_MODEL_DOTHAN: // Intel Pentium M case CPU_MODEL_YONAH: // Intel Mobile Core Solo, Duo @@ -103,15 +98,15 @@ // Nehalem supports Scrubbing // First, locate the PCI bus where the MCH is located - for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) - { + for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) { vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00); did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02); vid &= 0xFFFF; did &= 0xFF00; - if(vid == 0x8086 && did >= 0x2C00) + if(vid == 0x8086 && did >= 0x2C00) { nhm_bus = possible_nhm_bus[i]; + } } unsigned long qpimult, qpibusspeed; @@ -120,8 +115,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); @@ -143,8 +137,7 @@ { if (Platform.CPU.NoCores >= 4) { return 0x0501; // Quad-Core Xeon - } - else if (Platform.CPU.NoCores == 1) { + } else if (Platform.CPU.NoCores == 1) { return 0x0201; // Core Solo }; @@ -157,10 +150,8 @@ value->word = simpleGetSMBOemProcessorType(); - if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel - { - if (!done) - { + if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel + if (!done) { verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, (uint32_t)Platform.CPU.Family, (uint32_t)Platform.CPU.Model); done = true; } @@ -168,8 +159,7 @@ switch (Platform.CPU.Family) { case 0x06: { - switch (Platform.CPU.Model) - { + switch (Platform.CPU.Model) { case CPU_MODEL_DOTHAN: // 0x0D - Intel Pentium M model D value->word = 0x101; @@ -186,8 +176,7 @@ case CPU_MODEL_MEROM: // 0x0F - Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx case CPU_MODEL_PENRYN: // 0x17 - Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx - if (strstr(Platform.CPU.BrandString, "Xeon(R)")) - { + if (strstr(Platform.CPU.BrandString, "Xeon(R)")) { value->word = 0x402; // Xeon } case CPU_MODEL_PENTIUM_M: // 0x09 - Banias @@ -197,129 +186,104 @@ case CPU_MODEL_NEHALEM_EX: // 0x2E - Nehalem-ex, "Beckton", 45nm case CPU_MODEL_NEHALEM: // 0x1A - Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm) - if (strstr(Platform.CPU.BrandString, "Xeon(R)")) - { + if (strstr(Platform.CPU.BrandString, "Xeon(R)")) { value->word = 0x501; // Xeon } - if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) { value->word = 0x701; // Core i7 } return true; case CPU_MODEL_FIELDS: // 0x1E - Intel Core i5, i7, Xeon X34xx LGA1156 (45nm) - if (strstr(Platform.CPU.BrandString, "Xeon(R)")) - { + if (strstr(Platform.CPU.BrandString, "Xeon(R)")) { value->word = 0x501; // Lynnfiled Quad-Core Xeon } - if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) { value->word = 0x701; // Core i7 } - if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) { value->word = 0x601; // Core i5 } return true; case CPU_MODEL_DALES: // 0x1F - Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale) - if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) { value->word = 0x901; // Core i3 } - if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) { value->word = 0x602; // Core i5 } - if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) { value->word = 0x702; // Core i7 } - if (Platform.CPU.NoCores <= 2) - { + if (Platform.CPU.NoCores <= 2) { value->word = 0x602; // Core i5 } return true; case CPU_MODEL_DALES_32NM: // 0x25 - Intel Core i3, i5 LGA1156 (32nm) (Clarkdale, Arrandale) - if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) { value->word = 0x901; // Core i3 } - if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) { value->word = 0x601; // Core i5 } - if(strstr(Platform.CPU.BrandString, "Core(TM) i5 CPU M 540")) - { + if(strstr(Platform.CPU.BrandString, "Core(TM) i5 CPU M 540")) { value->word = 0x602; // Core i5 } - if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) { value->word = 0x701; // Core i7 } - if (Platform.CPU.NoCores <= 2) - { + if (Platform.CPU.NoCores <= 2) { value->word = 0x602; // Core i5 } return true; case CPU_MODEL_WESTMERE: // 0x2C - Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core case CPU_MODEL_WESTMERE_EX: // 0x2F - Intel Xeon E7 - if (strstr(Platform.CPU.BrandString, "Xeon(R)")) - { + if (strstr(Platform.CPU.BrandString, "Xeon(R)")) { value->word = 0x501; // Xeon } - if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) { value->word = 0x701; // Core i7 } return true; case CPU_MODEL_JAKETOWN: // 0x2D - Intel Core i7, Xeon E5-xxxx LGA2011 (32nm) case CPU_MODEL_SANDYBRIDGE: // 0x2A - Intel Core i3, i5, i7 LGA1155 (32nm) - if (strstr(Platform.CPU.BrandString, "Xeon(R)")) - { + if (strstr(Platform.CPU.BrandString, "Xeon(R)")) { value->word = 0x501; // Xeon } - if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) { value->word = 0x903; // Core i3 } - if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) { value->word = 0x603; // Core i5 } - if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) { value->word = 0x703; // Core i7 } - if (Platform.CPU.NoCores <= 2) - { + if (Platform.CPU.NoCores <= 2) { value->word = 0x603; // Core i5 } return true; case CPU_MODEL_IVYBRIDGE: // 0x3A - Intel Core i3, i5, i7 LGA1155 (22nm) - if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) { value->word = 0x903; // Core i3 - Apple doesn't use it } - if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) { value->word = 0x604; // Core i5 } - if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) { value->word = 0x704; // Core i7 } - if (Platform.CPU.NoCores <= 2) - { + if (Platform.CPU.NoCores <= 2) { value->word = 0x604; // Core i5 } return true; - case CPU_MODEL_IVYBRIDGE_XEON: // 0x3E - + case CPU_MODEL_IVYBRIDGE_XEON: // 0x3E - Mac Pro 6,1 - shouldn't be Sandy Bridge EP refering to intel spec.? value->word = 0xA01; return true; @@ -327,20 +291,16 @@ case CPU_MODEL_HASWELL_MB: // 0x3F - case CPU_MODEL_HASWELL_ULT: // 0x45 - case CPU_MODEL_CRYSTALWELL: // 0x46 - if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) { value->word = 0x905; // Core i3 - Apple doesn't use it } - if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) { value->word = 0x605; // Core i5 } - if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) - { + if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) { value->word = 0x705; // Core i7 } - if (Platform.CPU.NoCores <= 2) - { + if (Platform.CPU.NoCores <= 2) { value->word = 0x605; // Core i5 } return true; @@ -371,17 +331,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 +357,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; @@ -421,19 +377,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].Vendor) > 0) - { + if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0) { DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor); value->string = Platform.RAM.DIMM[map].Vendor; return true; } } - if (!bootInfo->memDetect) - { + if (!bootInfo->memDetect) { return false; } value->string = NOT_AVAILABLE; @@ -449,19 +402,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 +424,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: branches/ErmaC/Enoch/i386/include/string.h =================================================================== --- branches/ErmaC/Enoch/i386/include/string.h (revision 2340) +++ branches/ErmaC/Enoch/i386/include/string.h (revision 2341) @@ -108,6 +108,7 @@ int strncmp(const char *, const char *, size_t); char *strncpy(char *, const char *, size_t); #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) +char *stpncpy(char *, const char *, size_t); char *strnstr(const char *, const char *, size_t); #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ char *strpbrk(const char *, const char *); Index: branches/ErmaC/Enoch/i386/boot2/graphics.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/graphics.c (revision 2340) +++ branches/ErmaC/Enoch/i386/boot2/graphics.c (revision 2341) @@ -107,25 +107,26 @@ void printVBEModeInfo() { - VBEInfoBlock vbeInfo; - unsigned short * modePtr; - VBEModeInfoBlock modeInfo; - int err; - int line; - char* vbeInfoString = NULL; + VBEInfoBlock vbeInfo; + unsigned short * modePtr; + VBEModeInfoBlock modeInfo; + int err; + int line; + char* vbeInfoString = NULL; bzero( &vbeInfo, sizeof(vbeInfo) ); - strcpy( (char*)&vbeInfo, "VBE2" ); - err = getVBEInfo( &vbeInfo ); - if ( err != errSuccess ) - return; + strcpy( (char*)&vbeInfo, "VBE2" ); + err = getVBEInfo( &vbeInfo ); + if ( err != errSuccess ) { + return; + } - line = 0; + line = 0; - // Activate and clear page 1 - setActiveDisplayPage(1); - clearScreenRows(0, 24); - setCursorPosition( 0, 0, 1 ); + // Activate and clear page 1 + setActiveDisplayPage(1); + clearScreenRows(0, 24); + setCursorPosition( 0, 0, 1 ); vbeInfoString = getVBEInfoString(); if (!vbeInfoString) { Index: branches/ErmaC/Enoch/i386/boot2/drivers.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/drivers.c (revision 2340) +++ branches/ErmaC/Enoch/i386/boot2/drivers.c (revision 2341) @@ -703,33 +703,25 @@ ModulePtr module, module2; long done; - do - { + do { done = 1; module = gModuleHead; - while (module != 0) - { - if (module->willLoad == 1) - { + while (module != 0) { + if (module->willLoad == 1) { prop = XMLGetProperty(module->dict, kPropOSBundleLibraries); - if (prop != 0) - { + if (prop != 0) { prop = prop->tag; - while (prop != 0) - { + while (prop != 0) { module2 = gModuleHead; - while (module2 != 0) - { + while (module2 != 0) { prop2 = XMLGetProperty(module2->dict, kPropCFBundleIdentifier); - if ((prop2 != 0) && (!strcmp(prop->string, prop2->string))) - { - if (module2->willLoad == 0) - { + if ((prop2 != 0) && (!strcmp(prop->string, prop2->string))) { + if (module2->willLoad == 0) { module2->willLoad = 1; } break; @@ -763,8 +755,7 @@ module = gModuleHead; - while (module != 0) - { + while (module != 0) { prop = GetProperty(module->dict, kPropCFBundleIdentifier); if ((prop != 0) && !strcmp(name, prop->string)) { @@ -814,8 +805,7 @@ required = XMLGetProperty(moduleDict, kPropOSBundleRequired); - if ( (required == 0) || (required->type != kTagTypeString) || !strcmp(required->string, "Safe Boot")) - { + if ( (required == 0) || (required->type != kTagTypeString) || !strcmp(required->string, "Safe Boot")) { XMLFreeTag(moduleDict); return -2; } @@ -863,20 +853,16 @@ getchar(); #endif - if (kernel_header->signature == OSSwapBigToHostConstInt32('comp')) - { - if (kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss')) - { + if (kernel_header->signature == OSSwapBigToHostConstInt32('comp')) { + if (kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss')) { error("kernel compression is bad\n"); return -1; } #if NOTDEF - if (kernel_header->platform_name[0] && strcmp(gPlatformName, kernel_header->platform_name)) - { + if (kernel_header->platform_name[0] && strcmp(gPlatformName, kernel_header->platform_name)) { return -1; } - if (kernel_header->root_path[0] && strcmp(gBootFile, kernel_header->root_path)) - { + if (kernel_header->root_path[0] && strcmp(gBootFile, kernel_header->root_path)) { return -1; } #endif @@ -892,16 +878,14 @@ } if (OSSwapBigToHostInt32(kernel_header->adler32) != - Adler32(binary, uncompressed_size)) - { + Adler32(binary, uncompressed_size)) { printf("adler mismatch\n"); return -1; } } ret = ThinFatFile(&binary, &len); - if (ret == 0 && len == 0 && archCpuType==CPU_TYPE_X86_64) - { + if (ret == 0 && len == 0 && archCpuType==CPU_TYPE_X86_64) { archCpuType=CPU_TYPE_I386; ret = ThinFatFile(&binary, &len); } @@ -910,8 +894,7 @@ execute_hook("DecodeKernel", (void*)binary, NULL, NULL, NULL); ret = DecodeMachO(binary, rentry, raddr, rsize); - if (ret<0 && archCpuType==CPU_TYPE_X86_64) - { + if (ret<0 && archCpuType==CPU_TYPE_X86_64) { archCpuType=CPU_TYPE_I386; ret = DecodeMachO(binary, rentry, raddr, rsize); } Index: branches/ErmaC/Enoch/i386/boot2/resume.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/resume.c (revision 2340) +++ branches/ErmaC/Enoch/i386/boot2/resume.c (revision 2341) @@ -28,10 +28,8 @@ // Activate and clear page 1 line = 1; - for (i = 0; i < bootInfo->memoryMapCount; i++) - { - if((mp->type == 1) && ((unsigned long)mp->base == 0x100000)) - { + for (i = 0; i < bootInfo->memoryMapCount; i++) { + if((mp->type == 1) && ((unsigned long)mp->base == 0x100000)) { return (unsigned long)(mp->base + mp->length); } mp++; @@ -69,8 +67,7 @@ lowHalf = 1; highHalf = 0; - for (cnt = 0; cnt < compressedSize; cnt += 0x20) - { + for (cnt = 0; cnt < compressedSize; cnt += 0x20) { dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; Index: branches/ErmaC/Enoch/i386/boot2/boot.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/boot.c (revision 2340) +++ branches/ErmaC/Enoch/i386/boot2/boot.c (revision 2341) @@ -271,19 +271,7 @@ snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32); } } -/* Issue: http://forge.voodooprojects.org/p/chameleon/issues/270/ - // kernelCacheFile must start with a / - if (kernelCacheFile[0] != '/') - { - char *str = strdup(kernelCacheFile); - if (str == NULL) - { - return -1; - } - sprintf(kernelCacheFile, "/%s", str); - free(str); - } -*/ + // Check if the kernel cache file exists ret = -1; Index: branches/ErmaC/Enoch/i386/boot2/boot.h =================================================================== --- branches/ErmaC/Enoch/i386/boot2/boot.h (revision 2340) +++ branches/ErmaC/Enoch/i386/boot2/boot.h (revision 2341) @@ -179,7 +179,6 @@ #define kHDAEnabler "HDAEnabler" /* pci_setup.c */ #define kHDEFLayoutID "HDEFLayoutID" /* hda.c */ #define kHDAULayoutID "HDAULayoutID" /* hda.c */ -//#define kHDAPinConf "HDEFPinConfiguration" /* hda.c */ #define kBGRT "BGRT" /* acpi_patcher.c */ #define kDropBGRT "DropBGRT" /* acpi_patcher.c */ #define kDropMCFG "DropMCFG" /* acpi_patcher.c */ @@ -188,6 +187,10 @@ /* Karas: added these keys */ #define kMemFullInfo "ForceFullMemInfo" /* smbios.c */ +/* Bungo: added these keys */ +// mask private data or no +#define kPrivateData "PrivateData" /* smbios_decode.c */ + /* * Flags to the booter or kernel */ Index: branches/ErmaC/Enoch/i386/boot2/modules.h =================================================================== --- branches/ErmaC/Enoch/i386/boot2/modules.h (revision 2340) +++ branches/ErmaC/Enoch/i386/boot2/modules.h (revision 2341) @@ -98,7 +98,6 @@ void bind_macho(void* base, UInt8* bind_stream, UInt32 size); - /********************************************************************************/ /* Module Interface */ /********************************************************************************/ Index: branches/ErmaC/Enoch/i386/boot2/gui.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/gui.c (revision 2340) +++ branches/ErmaC/Enoch/i386/boot2/gui.c (revision 2341) @@ -256,10 +256,8 @@ static int getImageIndexByName(const char *name) { int i; - for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) - { - if (strcmp(name, images[i].name) == 0) - { + for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) { + if (strcmp(name, images[i].name) == 0) { return i; // found the name } } @@ -279,26 +277,18 @@ // generated manualy, this *will* fail to work properly. while((result = strcmp(name, embeddedImages[compareIndex].name)) != 0) { - if (result > 0) // We need to search a HIGHER index - { - if (compareIndex != lowerLimit) - { + if (result > 0) { // We need to search a HIGHER index + if (compareIndex != lowerLimit) { lowerLimit = compareIndex; - } - else - { + } else { return -1; } compareIndex = (upperLimit + lowerLimit + 1) >> 1; // Midpoint, round up } - else // We Need to search a LOWER index - { - if (compareIndex != upperLimit) - { + else { // We Need to search a LOWER index + if (compareIndex != upperLimit) { upperLimit = compareIndex; - } - else - { + } else { return -1; } compareIndex = (upperLimit + lowerLimit) >> 1; // Midpoint, round down @@ -517,10 +507,8 @@ int destx = 0, desty = 0; int srcx = pos.x, srcy = pos.y; - for( ; desty < height; desty++, srcy++) - { - for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ ) - { + for( ; desty < height; desty++, srcy++) { + for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ ) { pixel( cropped, destx, desty ).value = pixel( from, srcx, srcy ).value; } } @@ -530,13 +518,11 @@ int createBackBuffer( window_t *window ) { gui.backbuffer = malloc(sizeof(pixmap_t)); - if(!gui.backbuffer) - { + if(!gui.backbuffer) { return 1; } gui.backbuffer->pixels = malloc( window->width * window->height * 4 ); - if(!gui.backbuffer->pixels) - { + if(!gui.backbuffer->pixels) { free(gui.backbuffer); gui.backbuffer = 0; return 1; @@ -551,14 +537,12 @@ int createWindowBuffer( window_t *window ) { window->pixmap = malloc(sizeof(pixmap_t)); - if(!window->pixmap) - { + if(!window->pixmap) { return 1; } window->pixmap->pixels = malloc( window->width * window->height * 4 ); - if(!window->pixmap->pixels) - { + if(!window->pixmap->pixels) { free(window->pixmap); window->pixmap = 0; return 1; @@ -1078,8 +1062,7 @@ makeRoundedCorners( gui.devicelist.pixmap); - switch (gui.layout) - { + switch (gui.layout) { case VerticalLayout: p.x = (gui.devicelist.width /2); @@ -1106,34 +1089,26 @@ } // draw visible device icons - for (i = 0; i < gui.maxdevices; i++) - { + for (i = 0; i < gui.maxdevices; i++) { BVRef param = menuItems[start + i].param; bool isSelected = ((start + i) == selection) ? true : false; - if (isSelected) - { - if (param->flags & kBVFlagNativeBoot) - { + if (isSelected) { + if (param->flags & kBVFlagNativeBoot) { infoMenuNativeBoot = true; - } - else - { + } else { infoMenuNativeBoot = false; - if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) - { + if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) { infoMenuSelection = 0; } } - if (gui.menu.draw) - { + if (gui.menu.draw) { drawInfoMenuItems(); } getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig); - if (shoWinfo && showBootBanner) - { + if (shoWinfo && showBootBanner) { gui.debug.cursor = pos( 10, 100); dprintf( &gui.screen, "label: %s\n", param->label ); dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev ); @@ -1156,24 +1131,20 @@ drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected); - if (gui.layout == HorizontalLayout) - { + if (gui.layout == HorizontalLayout) { p.x += images[iSelection].image->width + gui.devicelist.iconspacing; } - if (gui.layout == VerticalLayout) - { + if (gui.layout == VerticalLayout) { p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); } } // draw prev indicator - if (start) - { + if (start) { blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) ); } // draw next indicator - if ( end < gDeviceCount - 1 ) - { + if ( end < gDeviceCount - 1 ) { blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) ); } gui.redraw = true; @@ -1189,8 +1160,7 @@ //prompt_pos=0; - if( gui.bootprompt.draw == true ) - { + if( gui.bootprompt.draw == true ) { gui.bootprompt.draw = false; gui.redraw = true; // this causes extra frames to be drawn @@ -1228,23 +1198,17 @@ static inline void vramwrite (void *data, int width, int height) { - if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) - { + if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) { memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height)); - } - else - { + } else { uint32_t r, g, b; int i, j; - for (i = 0; i < VIDEO (height); i++) - { - for (j = 0; j < VIDEO (width); j++) - { + for (i = 0; i < VIDEO (height); i++) { + for (j = 0; j < VIDEO (width); j++) { b = ((uint8_t *) data)[4*i*width + 4*j]; g = ((uint8_t *) data)[4*i*width + 4*j + 1]; r = ((uint8_t *) data)[4*i*width + 4*j + 2]; - switch (VIDEO (depth)) - { + switch (VIDEO (depth)) { case 32: *(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16); break; @@ -1267,30 +1231,24 @@ void updateVRAM() { - if (gui.redraw) - { - if (gui.devicelist.draw) - { + if (gui.redraw) { + if (gui.devicelist.draw) { blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos ); } - if (gui.bootprompt.draw) - { + if (gui.bootprompt.draw) { blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos ); } - if (gui.menu.draw) - { + if (gui.menu.draw) { blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos ); } - if (gui.infobox.draw) - { + if (gui.infobox.draw) { blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos ); } } vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height ); - if (gui.redraw) - { + if (gui.redraw) { memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); gui.redraw = false; } @@ -1305,10 +1263,8 @@ static int sputc(int c, struct putc_info * pi) //Azi: same as above { - if (pi->last_str) - { - if (pi->str == pi->last_str) - { + if (pi->last_str) { + if (pi->str == pi->last_str) { *(pi->str) = '\0'; return 0; } @@ -1349,28 +1305,24 @@ font_t *font = &font_console; - for( i=0; i< strlen(formattedtext); i++ ) - { + for( i=0; i< strlen(formattedtext); i++ ) { character = formattedtext[i]; character -= 32; // newline ? - if( formattedtext[i] == '\n' ) - { + if( formattedtext[i] == '\n' ) { cursor.x = window->hborder; cursor.y += font->height; - if ( cursor.y > bounds.y ) - { + if ( cursor.y > bounds.y ) { cursor.y = origin.y; } continue; } // tab ? - if( formattedtext[i] == '\t' ) - { + if( formattedtext[i] == '\t' ) { cursor.x += ( font->chars[0]->width * 5 ); } @@ -1382,8 +1334,7 @@ cursor.x += font->chars[character]->width; // check x pos and do newline - if ( cursor.x > bounds.x ) - { + if ( cursor.x > bounds.x ) { cursor.x = origin.x; cursor.y += font->height; } @@ -1400,7 +1351,6 @@ free(formattedtext); return 0; - } return 1; } @@ -1439,47 +1389,40 @@ font_t *font = &font_console; - for( i=0; i< strlen(formattedtext); i++ ) - { + for( i=0; i< strlen(formattedtext); i++ ) { character = formattedtext[i]; character -= 32; // newline ? - if( formattedtext[i] == '\n' ) - { + if( formattedtext[i] == '\n' ) { cursor.x = window->hborder; cursor.y += font->height; - if ( cursor.y > bounds.y ) - { + if ( cursor.y > bounds.y ) { cursor.y = origin.y; } continue; } // tab ? - if( formattedtext[i] == '\t' ) - { + if( formattedtext[i] == '\t' ) { cursor.x += ( font->chars[0]->width * 5 ); } // draw the character - if( font->chars[character]) - { + if( font->chars[character]) { blend(font->chars[character], gui.backbuffer, cursor); } cursor.x += font->chars[character]->width; // check x pos and do newline - if ( cursor.x > bounds.x ) - { + if ( cursor.x > bounds.x ) { cursor.x = origin.x; cursor.y += font->height; } // check y pos and reset to origin.y - if ( cursor.y > bounds.y ) - { + if ( cursor.y > bounds.y ) { cursor.y = origin.y; } } @@ -1520,18 +1463,15 @@ bounds.y = ( window->height - ( window->vborder * 2 ) ); cursor = origin; - for( i=0; i< strlen(formattedtext); i++ ) - { + for( i=0; i< strlen(formattedtext); i++ ) { character = formattedtext[i]; character -= 32; // newline ? - if( formattedtext[i] == '\n' ) - { + if( formattedtext[i] == '\n' ) { cursor.x = window->hborder; cursor.y += font->height; - if ( cursor.y > bounds.y ) - { + if ( cursor.y > bounds.y ) { gui.redraw = true; updateVRAM(); cursor.y = window->vborder; @@ -1541,30 +1481,26 @@ } // tab ? - if( formattedtext[i] == '\t' ) - { + if( formattedtext[i] == '\t' ) { cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 ); continue; } cursor.x += font->chars[character]->width; // check x pos and do newline - if ( cursor.x > bounds.x ) - { + if ( cursor.x > bounds.x ) { cursor.x = origin.x; cursor.y += font->height; } // check y pos and reset to origin.y - if ( cursor.y > ( bounds.y + font->chars[0]->height) ) - { + if ( cursor.y > ( bounds.y + font->chars[0]->height) ) { gui.redraw = true; updateVRAM(); cursor.y = window->vborder; } // draw the character - if( font->chars[character]) - { + if( font->chars[character]) { blend(font->chars[character], gui.backbuffer, cursor); } } @@ -1579,8 +1515,7 @@ pixmap_t* charToPixmap(unsigned char ch, font_t *font) { unsigned int cha = (unsigned int)ch - 32; - if (cha >= font->count) - { + if (cha >= font->count) { // return ? if the font for the char doesn't exists cha = '?' - 32; } @@ -1589,13 +1524,10 @@ position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) { pixmap_t* pm = charToPixmap(ch, font); - if (pm && ((p.x + pm->width) < blendInto->width)) - { + if (pm && ((p.x + pm->width) < blendInto->width)) { blend(pm, blendInto, p); return pos(p.x + pm->width, p.y); - } - else - { + } else { return p; } } @@ -1605,19 +1537,16 @@ int i=0; position_t current_pos = pos(p.x, p.y); - for (i=0; i < strlen(ch); i++) - { + for (i=0; i < strlen(ch); i++) { // newline ? - if ( ch[i] == '\n' ) - { + if ( ch[i] == '\n' ) { current_pos.x = p.x; current_pos.y += font->height; continue; } // tab ? - if ( ch[i] == '\t' ) - { + if ( ch[i] == '\t' ) { current_pos.x += TAB_PIXELS_WIDTH; continue; } @@ -1635,25 +1564,18 @@ // calculate the width in pixels for (i=0; i < strlen(text); i++) { - if (text[i] == '\n') - { + if (text[i] == '\n') { width = 0; height += font->height; - } - else if (text[i] == '\t') - { + } else if (text[i] == '\t') { width += TAB_PIXELS_WIDTH; - } - else - { + } else { pixmap_t* pm = charToPixmap(text[i], font); - if (pm) - { + if (pm) { width += pm->width; } } - if (width > max_width) - { + if (width > max_width) { max_width = width; } } @@ -1667,12 +1589,9 @@ int destroyFont(font_t *font) { int i; - for (i = 0; i < CHARACTERS_COUNT; i++) - { - if (font->chars[i]) - { - if (font->chars[i]->pixels) - { + for (i = 0; i < CHARACTERS_COUNT; i++) { + if (font->chars[i]) { + if (font->chars[i]->pixels) { free (font->chars[i]->pixels); } free (font->chars[i]); @@ -1692,35 +1611,28 @@ font->height = data->image->height; - for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) - { + for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) { start = end; // if the pixel is red we've reached the end of the char - if( pixel( data->image, x, 0 ).value == 0xFFFF0000) - { + if( pixel( data->image, x, 0 ).value == 0xFFFF0000) { end = x + 1; - if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) - { + if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) { font->chars[count]->width = ( end - start) - 1; font->chars[count]->height = font->height; - if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) - { + if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) { space += ( font->chars[count]->width * data->image->height * 4 ); // we skip the first line because there are just the red pixels for the char width - for( y = 1; y< (font->height); y++) - { - for( x2 = start, x3 = 0; x2 < end; x2++, x3++) - { + for( y = 1; y< (font->height); y++) { + for( x2 = start, x3 = 0; x2 < end; x2++, x3++) { pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y ); } } // check if font is monospaced - if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) - { + if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) { monospaced = true; } @@ -1732,13 +1644,11 @@ } } - for (x = count; x < CHARACTERS_COUNT; x++) - { + for (x = count; x < CHARACTERS_COUNT; x++) { font->chars[x] = NULL; } - if(monospaced) - { + if(monospaced) { font->width = 0; } @@ -1749,8 +1659,7 @@ void colorFont(font_t *font, uint32_t color) { - if( !color ) - { + if( !color ) { return; } @@ -1758,17 +1667,13 @@ int count = 0; pixel_t *buff; - while( font->chars[count++] ) - { + while( font->chars[count++] ) { width = font->chars[count-1]->width; height = font->chars[count-1]->height; - for( y = 0; y < height; y++ ) - { - for( x = 0; x < width; x++ ) - { + for( y = 0; y < height; y++ ) { + for( x = 0; x < width; x++ ) { buff = &(pixel( font->chars[count-1], x, y )); - if( buff->ch.a ) - { + if( buff->ch.a ) { buff->ch.r = (color & 0xFFFF0000) >> 16; buff->ch.g = (color & 0xFF00FF00) >> 8; buff->ch.b = (color & 0xFF0000FF); @@ -1801,13 +1706,10 @@ uint8_t alpha=0; - for( y=0; y<10; y++) - { - for( x=0; x<10; x++) - { + for( y=0; y<10; y++) { + for( x=0; x<10; x++) { // skip if the pixel should be visible - if(roundedCorner[y][x] != 0xFF) - { + if(roundedCorner[y][x] != 0xFF) { alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 ); // Upper left corner pixel(p, x, y).ch.a = alpha; @@ -1845,10 +1747,8 @@ position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder ); // calculate number of lines in the title - for ( i = 0, lines = 1; iwidth - ( gui.infobox.vborder / 2) ), pos_text.y ); // draw prev indicator - if(offset) - { + if(offset) { blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator )); } // draw next indicator - if( lines > ( currentline + visiblelines ) ) - { + if( lines > ( currentline + visiblelines ) ) { pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) ); blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) ); } @@ -1937,38 +1826,30 @@ key = getchar(); - if( key == KEY_UP ) - { - if( currentline > 0 ) - { + if( key == KEY_UP ) { + if( currentline > 0 ) { currentline--; } } - if( key == KEY_DOWN ) - { - if( lines > ( currentline + visiblelines ) ) - { + if( key == KEY_DOWN ) { + if( lines > ( currentline + visiblelines ) ) { currentline++; } } - if( key == KEY_ESC || key == 'q' || key == 'Q') - { + if( key == KEY_ESC || key == 'q' || key == 'Q') { gui.infobox.draw = false; gui.redraw = true; updateVRAM(); break; } - if(key == ' ') // spacebar = next page - { - if( lines > ( currentline + visiblelines ) ) - { + if(key == ' ') { // spacebar = next page + if( lines > ( currentline + visiblelines ) ) { currentline += visiblelines; } - if(lines < (currentline + visiblelines)) - { + if(lines < (currentline + visiblelines)) { currentline = lines - visiblelines; } } @@ -1980,8 +1861,7 @@ { int y; - if( time18() > lasttime) - { + if( time18() > lasttime) { lasttime = time18(); pixmap_t *buffBar = images[iProgressBar].image; @@ -1990,8 +1870,7 @@ memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 ); - for( y = buffBar->height - 1; y > 0; y--) - { + for( y = buffBar->height - 1; y > 0; y--) { pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1); } pixel(buffBar, buffBar->width-1, 0).value = buff; @@ -2025,12 +1904,9 @@ int x=0,x2=0,y=0; - for(y=0; yheight; y++) - { - for(x=0; xwidth-1)) - { + for(y=0; yheight; y++) { + for(x=0; xwidth-1)) { x2=0; } pixel(&progressbar, x,y).value = pixel(buff, x2,y).value; @@ -2038,23 +1914,18 @@ x2=0; } - for(y=0; yheight; y++) - { - for(x=todraw, x2 = 0; x < width - 1; x++, x2++) - { - if(x2 == (buffBG->width -2 )) - { + for(y=0; yheight; y++) { + for(x=todraw, x2 = 0; x < width - 1; x++, x2++) { + if(x2 == (buffBG->width -2 )) { x2 = 0; } pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value; } - if(progress < 100) - { + if(progress < 100) { pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value; } - if(progress == 0) - { + if(progress == 0) { pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value; } @@ -2084,21 +1955,16 @@ position = pos(0,0); - for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) - { - if (i == infoMenuSelection) - { + for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) { + if (i == infoMenuSelection) { blend(selection, gui.menu.pixmap, position); } pbuff = images[n].image; - if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) - { + if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) { blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2))); - } - else - { + } else { blend( pbuff, gui.menu.pixmap, pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2))); } @@ -2130,22 +1996,16 @@ { case KEY_UP: // up arrow - if (infoMenuSelection > 0) - { - if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) - { + if (infoMenuSelection > 0) { + if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) { infoMenuSelection -= 4; - } - else - { + } else { infoMenuSelection--; } drawInfoMenuItems(); updateVRAM(); - } - else - { + } else { gui.menu.draw = false; gui.redraw = true; @@ -2157,14 +2017,11 @@ break; case KEY_DOWN: // down arrow - if (infoMenuSelection < infoMenuItemsCount - 1) - { + if (infoMenuSelection < infoMenuItemsCount - 1) { if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1) { infoMenuSelection += 4; - } - else - { + } else { infoMenuSelection++; } drawInfoMenuItems(); @@ -2174,20 +2031,13 @@ case KEY_ENTER: key = 0; - if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) - { + if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) { showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString()); - } - else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) - { + } else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) { showInfoBox( getVBEInfoString(), getVBEModeInfoString() ); - } - else if( infoMenuSelection == MENU_SHOW_HELP ) - { + } else if( infoMenuSelection == MENU_SHOW_HELP ) { showHelp(); - } - else - { + } else { int buff = infoMenuSelection; infoMenuSelection = 0; return buff; @@ -2265,8 +2115,7 @@ getGraphicModeParams(screen_params); // Set graphics mode if the booter was in text mode or the screen resolution has changed. - if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) - { + if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) { setVideoMode(GRAPHICS_MODE, 0); } Index: branches/ErmaC/Enoch/i386/boot2/lzss.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/lzss.c (revision 2340) +++ branches/ErmaC/Enoch/i386/boot2/lzss.c (revision 2341) @@ -49,7 +49,22 @@ #define THRESHOLD 2 /* Encode string into position and length if match_length is greater than this. */ #define NIL N /* Index for root of binary search trees. */ +struct encode_state { + /* + * left & right children & parent. These constitute binary search trees. + */ + int lchild[N + 1], rchild[N + 257], parent[N + 1]; + /* ring buffer of size N, with extra F-1 bytes to aid string comparison */ + u_int8_t text_buf[N + F - 1]; + + /* + * match_length of longest match. + * These are set by the insert_node() procedure. + */ + int match_position, match_length; +}; + //============================================================================== // Refactoring and bug fix Copyright (c) 2010 by DHP. @@ -97,3 +112,226 @@ return dst - dststart; } + +/* + * initialize state, mostly the trees + * + * For i = 0 to N - 1, rchild[i] and lchild[i] will be the right and left + * children of node i. These nodes need not be initialized. Also, parent[i] + * is the parent of node i. These are initialized to NIL (= N), which stands + * for 'not used.' For i = 0 to 255, rchild[N + i + 1] is the root of the + * tree for strings that begin with character i. These are initialized to NIL. + * Note there are 256 trees. */ +static void init_state(struct encode_state *sp) +{ + int i; + + bzero(sp, sizeof(*sp)); + + for (i = 0; i < N - F; i++) + sp->text_buf[i] = ' '; + for (i = N + 1; i <= N + 256; i++) + sp->rchild[i] = NIL; + for (i = 0; i < N; i++) + sp->parent[i] = NIL; +} + +/* + * Inserts string of length F, text_buf[r..r+F-1], into one of the trees + * (text_buf[r]'th tree) and returns the longest-match position and length + * via the global variables match_position and match_length. + * If match_length = F, then removes the old node in favor of the new one, + * because the old one will be deleted sooner. Note r plays double role, + * as tree node and position in buffer. + */ +static void insert_node(struct encode_state *sp, int r) +{ + int i, p, cmp; + u_int8_t *key; + + cmp = 1; + key = &sp->text_buf[r]; + p = N + 1 + key[0]; + sp->rchild[r] = sp->lchild[r] = NIL; + sp->match_length = 0; + for ( ; ; ) { + if (cmp >= 0) { + if (sp->rchild[p] != NIL) + p = sp->rchild[p]; + else { + sp->rchild[p] = r; + sp->parent[r] = p; + return; + } + } else { + if (sp->lchild[p] != NIL) + p = sp->lchild[p]; + else { + sp->lchild[p] = r; + sp->parent[r] = p; + return; + } + } + for (i = 1; i < F; i++) { + if ((cmp = key[i] - sp->text_buf[p + i]) != 0) + break; + } + if (i > sp->match_length) { + sp->match_position = p; + if ((sp->match_length = i) >= F) + break; + } + } + sp->parent[r] = sp->parent[p]; + sp->lchild[r] = sp->lchild[p]; + sp->rchild[r] = sp->rchild[p]; + sp->parent[sp->lchild[p]] = r; + sp->parent[sp->rchild[p]] = r; + if (sp->rchild[sp->parent[p]] == p) + sp->rchild[sp->parent[p]] = r; + else + sp->lchild[sp->parent[p]] = r; + sp->parent[p] = NIL; /* remove p */ +} + +/* deletes node p from tree */ +static void delete_node(struct encode_state *sp, int p) +{ + int q; + + if (sp->parent[p] == NIL) + return; /* not in tree */ + if (sp->rchild[p] == NIL) + q = sp->lchild[p]; + else if (sp->lchild[p] == NIL) + q = sp->rchild[p]; + else { + q = sp->lchild[p]; + if (sp->rchild[q] != NIL) { + do { + q = sp->rchild[q]; + } while (sp->rchild[q] != NIL); + sp->rchild[sp->parent[q]] = sp->lchild[q]; + sp->parent[sp->lchild[q]] = sp->parent[q]; + sp->lchild[q] = sp->lchild[p]; + sp->parent[sp->lchild[p]] = q; + } + sp->rchild[q] = sp->rchild[p]; + sp->parent[sp->rchild[p]] = q; + } + sp->parent[q] = sp->parent[p]; + if (sp->rchild[sp->parent[p]] == p) + sp->rchild[sp->parent[p]] = q; + else + sp->lchild[sp->parent[p]] = q; + sp->parent[p] = NIL; +} + +u_int8_t *compress_lzss( + u_int8_t * dst, + u_int32_t dstlen, + u_int8_t * src, + u_int32_t srclen) +{ + u_int8_t * result = NULL; + /* Encoding state, mostly tree but some current match stuff */ + struct encode_state *sp; + int i, c, len, r, s, last_match_length, code_buf_ptr; + u_int8_t code_buf[17], mask; + u_int8_t * srcend = src + srclen; + u_int8_t *dstend = dst + dstlen; + /* initialize trees */ + sp = (struct encode_state *) malloc(sizeof(*sp)); + if (!sp) goto finish; + init_state(sp); + /* + * code_buf[1..16] saves eight units of code, and code_buf[0] works + * as eight flags, "1" representing that the unit is an unencoded + * letter (1 byte), "0" a position-and-length pair (2 bytes). + * Thus, eight units require at most 16 bytes of code. + */ + code_buf[0] = 0; + code_buf_ptr = mask = 1; + /* Clear the buffer with any character that will appear often. */ + s = 0; r = N - F; + /* Read F bytes into the last F bytes of the buffer */ + for (len = 0; len < F && src < srcend; len++) + sp->text_buf[r + len] = *src++; + if (!len) + goto finish; + /* + * Insert the F strings, each of which begins with one or more + * 'space' characters. Note the order in which these strings are + * inserted. This way, degenerate trees will be less likely to occur. + */ + for (i = 1; i <= F; i++) + insert_node(sp, r - i); + /* + * Finally, insert the whole string just read. + * The global variables match_length and match_position are set. + */ + insert_node(sp, r); + do { + /* match_length may be spuriously long near the end of text. */ + if (sp->match_length > len) + sp->match_length = len; + if (sp->match_length <= THRESHOLD) { + sp->match_length = 1; /* Not long enough match. Send one byte. */ + code_buf[0] |= mask; /* 'send one byte' flag */ + code_buf[code_buf_ptr++] = sp->text_buf[r]; /* Send uncoded. */ + } else { + /* Send position and length pair. Note match_length > THRESHOLD. */ + code_buf[code_buf_ptr++] = (u_int8_t) sp->match_position; + code_buf[code_buf_ptr++] = (u_int8_t) + ( ((sp->match_position >> 4) & 0xF0) + | (sp->match_length - (THRESHOLD + 1)) ); + } + if ((mask <<= 1) == 0) { /* Shift mask left one bit. */ + /* Send at most 8 units of code together */ + for (i = 0; i < code_buf_ptr; i++) + if (dst < dstend) + *dst++ = code_buf[i]; + else + goto finish; + code_buf[0] = 0; + code_buf_ptr = mask = 1; + } + last_match_length = sp->match_length; + for (i = 0; i < last_match_length && src < srcend; i++) { + delete_node(sp, s); /* Delete old strings and */ + c = *src++; + sp->text_buf[s] = c; /* read new bytes */ + /* + * If the position is near the end of buffer, extend the buffer + * to make string comparison easier. + */ + if (s < F - 1) + sp->text_buf[s + N] = c; + /* Since this is a ring buffer, increment the position modulo N. */ + s = (s + 1) & (N - 1); + r = (r + 1) & (N - 1); + /* Register the string in text_buf[r..r+F-1] */ + insert_node(sp, r); + } + while (i++ < last_match_length) { + delete_node(sp, s); + /* After the end of text, no need to read, */ + s = (s + 1) & (N - 1); + r = (r + 1) & (N - 1); + /* but buffer may not be empty. */ + if (--len) + insert_node(sp, r); + } + } while (len > 0); /* until length of string to be processed is zero */ + if (code_buf_ptr > 1) { /* Send remaining code. */ + for (i = 0; i < code_buf_ptr; i++) + if (dst < dstend) + *dst++ = code_buf[i]; + else + goto finish; + } + result = dst; +finish: + if (sp) free(sp); + return result; +} Index: branches/ErmaC/Enoch/i386/boot2/options.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/options.c (revision 2340) +++ branches/ErmaC/Enoch/i386/boot2/options.c (revision 2341) @@ -1125,29 +1125,22 @@ int *cntRemainingP, // Output count char *foundVal, // found value int foundValSize // max found value size - ) -{ - const char *val; - int cnt; - bool found = false; + ) { + const char *val; + int cnt; + bool found = false; - if (getValueForBootKey(userString, argName, &val, &cnt)) - { + if (getValueForBootKey(userString, argName, &val, &cnt)) { // Don't copy; these values will be copied at the end of argument processing. found = true; - } - else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) - { + } else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) { // Don't copy; these values will be copied at the end of argument processing. found = true; - } - else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) - { + } else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) { copyArgument(argName, val, cnt, argP, cntRemainingP); found = true; } - if (found && foundVal) - { + if (found && foundVal) { strlcpy(foundVal, val, foundValSize); } return found; @@ -1175,15 +1168,13 @@ // Update the unit and partition number. - if ( gBootVolume ) - { - if (!( gBootVolume->flags & kBVFlagNativeBoot )) - { + if ( gBootVolume ) { + if (!( gBootVolume->flags & kBVFlagNativeBoot )) { readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 ); // // Setup edx, and signal intention to chain load the // foreign booter. - // + // chainbootdev = gBootVolume->biosdev; chainbootflag = 1; @@ -1194,167 +1185,169 @@ setRootVolume(gBootVolume); } - // If no boot volume fail immediately because we're just going to fail - // trying to load the config file anyway. - else - return -1; + // If no boot volume fail immediately because we're just going to fail + // trying to load the config file anyway. + else { + return -1; + } - // Load config table specified by the user, or use the default. + // Load config table specified by the user, or use the default. - if (!getValueForBootKey(cp, "config", &val, &cnt)) { - val = 0; - cnt = 0; - } + if (!getValueForBootKey(cp, "config", &val, &cnt)) { + val = 0; + cnt = 0; + } - // Load com.apple.Boot.plist from the selected volume - // and use its contents to override default bootConfig. + // Load com.apple.Boot.plist from the selected volume + // and use its contents to override default bootConfig. loadSystemConfig(&bootInfo->bootConfig); loadChameleonConfig(&bootInfo->chameleonConfig); - // Use the kernel name specified by the user, or fetch the name - // in the config table, or use the default if not specified. - // Specifying a kernel name on the command line, or specifying - // a non-default kernel name in the config file counts as - // overriding the kernel, which causes the kernelcache not - // to be used. + // Use the kernel name specified by the user, or fetch the name + // in the config table, or use the default if not specified. + // Specifying a kernel name on the command line, or specifying + // a non-default kernel name in the config file counts as + // overriding the kernel, which causes the kernelcache not + // to be used. - gOverrideKernel = false; - if (( kernel = extractKernelName((char **)&cp) )) { - strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) ); - } else { - if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) { - strlcpy( bootInfo->bootFile, val, cnt+1 ); - } else { - strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) ); - } - } + gOverrideKernel = false; + if (( kernel = extractKernelName((char **)&cp) )) { + strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) ); + } else { + if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) { + strlcpy( bootInfo->bootFile, val, cnt+1 ); + } else { + strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) ); + } + } if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) { gOverrideKernel = true; } - cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space - argP = bootArgs->CommandLine; + cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space + argP = bootArgs->CommandLine; // Get config kernel flags, if not ignored. - if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || + if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) { - val = ""; - cnt = 0; - } - configKernelFlags = malloc(cnt + 1); - strlcpy(configKernelFlags, val, cnt + 1); + val = ""; + cnt = 0; + } + configKernelFlags = malloc(cnt + 1); + strlcpy(configKernelFlags, val, cnt + 1); - // boot-uuid can be set either on the command-line or in the config file + // boot-uuid can be set either on the command-line or in the config file if (!processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gBootUUIDString, sizeof(gBootUUIDString))) { - // - // Try an alternate method for getting the root UUID on boot helper partitions. - // - if (gBootVolume->flags & kBVFlagBooter) - { + // + // Try an alternate method for getting the root UUID on boot helper partitions. + // + if (gBootVolume->flags & kBVFlagBooter) { // Load the configuration store in the boot helper partition - if (loadHelperConfig(&bootInfo->helperConfig) == 0) - { + if (loadHelperConfig(&bootInfo->helperConfig) == 0) { val = getStringForKey(kHelperRootUUIDKey, &bootInfo->helperConfig); - if (val != NULL) + if (val != NULL) { strlcpy(gBootUUIDString, val, sizeof(gBootUUIDString)); + } } - } + } - // Try to get the volume uuid string - if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) + // Try to get the volume uuid string + if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) { gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString); + } // If we have the volume uuid add it to the commandline arguments - if (strlen(gBootUUIDString)) + if (strlen(gBootUUIDString)) { copyArgument(kBootUUIDKey, gBootUUIDString, strlen(gBootUUIDString), &argP, &cntRemaining); + } } - if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, + if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE)) { - cnt = 0; - if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) { - valueBuffer[0] = '*'; - cnt++; - strlcpy(valueBuffer + 1, val, cnt); - val = valueBuffer; - } else { - if (strlen(gBootUUIDString)) { - val = "*uuid"; - cnt = 5; - } else { - // Don't set "rd=.." if there is no boot device key - // and no UUID. - val = ""; - cnt = 0; - } - } - if (cnt > 0) { - copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); - } - strlcpy( gRootDevice, val, (cnt + 1)); - } + cnt = 0; + if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) { + valueBuffer[0] = '*'; + cnt++; + strlcpy(valueBuffer + 1, val, cnt); + val = valueBuffer; + } else { + if (strlen(gBootUUIDString)) { + val = "*uuid"; + cnt = 5; + } else { + // Don't set "rd=.." if there is no boot device key + // and no UUID. + val = ""; + cnt = 0; + } + } + if (cnt > 0) { + copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); + } + strlcpy( gRootDevice, val, (cnt + 1)); + } - /* - * Removed. We don't need this anymore. - * - if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, + /* + * Removed. We don't need this anymore. + * + if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName, sizeof(gCacheNameAdler))) { - getPlatformName(gPlatformName); - copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining); - } - */ + getPlatformName(gPlatformName); + copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining); + } + */ - if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) && + if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) && !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) { - if (gBootMode & kBootModeSafe) { - copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining); - } - } + if (gBootMode & kBootModeSafe) { + copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining); + } + } - // Store the merged kernel flags and boot args. + // Store the merged kernel flags and boot args. - cnt = strlen(configKernelFlags); - if (cnt) { - if (cnt > cntRemaining) { - error("Warning: boot arguments too long, truncating\n"); - cnt = cntRemaining; - } - strncpy(argP, configKernelFlags, cnt); - argP[cnt++] = ' '; - cntRemaining -= cnt; - } - userCnt = strlen(cp); - if (userCnt > cntRemaining) { - error("Warning: boot arguments too long, truncating\n"); - userCnt = cntRemaining; - } - strncpy(&argP[cnt], cp, userCnt); - argP[cnt+userCnt] = '\0'; + cnt = strlen(configKernelFlags); + if (cnt) { + if (cnt > cntRemaining) { + error("Warning: boot arguments too long, truncating\n"); + cnt = cntRemaining; + } + strncpy(argP, configKernelFlags, cnt); + argP[cnt++] = ' '; + cntRemaining -= cnt; + } + userCnt = strlen(cp); + if (userCnt > cntRemaining) { + error("Warning: boot arguments too long, truncating\n"); + userCnt = cntRemaining; + } + strncpy(&argP[cnt], cp, userCnt); + argP[cnt+userCnt] = '\0'; - if(!shouldboot) - { + if(!shouldboot) { gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) || getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->chameleonConfig ); gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) ? kBootModeSafe : kBootModeNormal; - if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) { - gBootMode = kBootModeSafe; - } + if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) { + gBootMode = kBootModeSafe; + } } - if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) ) + if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) ) { strlcpy(gMKextName, val, cnt + 1); - else + } else { gMKextName[0]=0; + } - free(configKernelFlags); - free(valueBuffer); + free(configKernelFlags); + free(valueBuffer); - return 0; + return 0; } Index: branches/ErmaC/Enoch/i386/config/nconf.h =================================================================== --- branches/ErmaC/Enoch/i386/config/nconf.h (revision 2340) +++ branches/ErmaC/Enoch/i386/config/nconf.h (revision 2341) @@ -26,16 +26,6 @@ #include "ncurses.h" -#define max(a, b) ({\ - typeof(a) _a = a;\ - typeof(b) _b = b;\ - _a > _b ? _a : _b; }) - -#define min(a, b) ({\ - typeof(a) _a = a;\ - typeof(b) _b = b;\ - _a < _b ? _a : _b; }) - typedef enum { NORMAL = 1, MAIN_HEADING, Index: branches/ErmaC/Enoch/i386/config/confdata.c =================================================================== --- branches/ErmaC/Enoch/i386/config/confdata.c (revision 2340) +++ branches/ErmaC/Enoch/i386/config/confdata.c (revision 2341) @@ -16,6 +16,16 @@ #define LKC_DIRECT_LINK #include "lkc.h" +#define max(a, b) ({\ + typeof(a) _a = a;\ + typeof(b) _b = b;\ + _a > _b ? _a : _b; }) + +#define min(a, b) ({\ + typeof(a) _a = a;\ + typeof(b) _b = b;\ + _a < _b ? _a : _b; }) + static void conf_warning(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); @@ -75,29 +85,47 @@ return name ? name : "auto.conf"; } +/* TODO: figure out if symbols are always null-terminated */ static char *conf_expand_value(const char *in) { - struct symbol *sym; + static char res_value[SYMBOL_MAXLENGTH + 1]; + char name[SYMBOL_MAXLENGTH]; + size_t res_rem = SYMBOL_MAXLENGTH; + char *res_ptr = res_value; const char *src; - static char res_value[SYMBOL_MAXLENGTH]; - char *dst, name[SYMBOL_MAXLENGTH]; + *res_ptr = 0; + res_ptr[SYMBOL_MAXLENGTH] = 0; + while ((src = strchr(in, '$'))) { + struct symbol *sym; + const char *symval; + char *name_ptr = name; + size_t n = min(res_rem, src - in); - res_value[0] = 0; - dst = name; - while ((src = strchr(in, '$'))) { - strncat(res_value, in, src - in); + res_ptr = stpncpy(res_ptr, in, n); + if (!(res_rem -= n)) { + return res_value; /* buffer full, quit now */ + } src++; - dst = name; - while (isalnum(*src) || *src == '_') - *dst++ = *src++; - *dst = 0; + + *name_ptr = 0; + while (isalnum(*src) || *src == '_') { + *name_ptr++ = *src++; + } + *name_ptr = 0; + sym = sym_lookup(name, 0); sym_calc_value(sym); - strcat(res_value, sym_get_string_value(sym)); + symval = sym_get_string_value(sym); + n = min(res_rem, strlen(symval)); + + res_ptr = stpncpy(res_ptr, symval, n); + if (!(res_rem -= n)) { + return res_value; /* buffer full, quit now */ + } in = src; } - strcat(res_value, in); + strncpy(res_ptr, in, res_rem + 1); return res_value; } @@ -110,7 +138,7 @@ name = conf_expand_value(conf_defname); env = getenv(SRCTREE); if (env) { - sprintf(fullname, "%s/%s", env, name); + snprintf(fullname, PATH_MAX+1, "%s/%s", env, name); if (!stat(fullname, &buf)) return fullname; } @@ -570,38 +598,41 @@ char *slash; if (!stat(name, &st) && S_ISDIR(st.st_mode)) { - strcpy(dirname, name); - strcat(dirname, "/"); + /* FIXME: add length check */ + strcpy(stpcpy(dirname, name), "/"); basename = conf_get_configname(); } else if ((slash = strrchr(name, '/'))) { - int size = slash - name + 1; + size_t size = slash - name + 1; memcpy(dirname, name, size); dirname[size] = 0; - if (slash[1]) + if (slash[1]) { basename = slash + 1; - else + } else { basename = conf_get_configname(); - } else + } + } else { basename = name; - } else + } + } else { basename = conf_get_configname(); - - sprintf(newname, "%s%s", dirname, basename); + } + snprintf(newname, PATH_MAX+1, "%s%s", dirname, basename); env = getenv("KCONFIG_OVERWRITECONFIG"); if (!env || !*env) { - sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid()); + snprintf(tmpname, PATH_MAX+1, "%s.tmpconfig.%d", dirname, (int)getpid()); out = fopen(tmpname, "w"); } else { *tmpname = 0; out = fopen(newname, "w"); } - if (!out) + if (!out) { return 1; - + } time(&now); env = getenv("KCONFIG_NOTIMESTAMP"); - if (env && *env) + if (env && *env) { use_timestamp = 0; + } fprintf(out, _("#\n" "# Automatically generated make config: don't edit\n" @@ -640,9 +671,9 @@ menu = menu->list; continue; } - if (menu->next) + if (menu->next) { menu = menu->next; - else while ((menu = menu->parent)) { + } else while ((menu = menu->parent)) { if (menu->next) { menu = menu->next; break; @@ -655,8 +686,9 @@ strcat(dirname, basename); strcat(dirname, ".old"); rename(newname, dirname); - if (rename(tmpname, newname)) + if (rename(tmpname, newname)) { return 1; + } } // conf_message(_("configuration written to %s"), newname); Index: branches/ErmaC/Enoch/i386/libsa/libsa.h =================================================================== --- branches/ErmaC/Enoch/i386/libsa/libsa.h (revision 2340) +++ branches/ErmaC/Enoch/i386/libsa/libsa.h (revision 2341) @@ -95,7 +95,9 @@ extern int strcmp(const char * s1, const char * s2); extern int strncmp(const char * s1, const char * s2, size_t n); extern char * strcpy(char * s1, const char * s2); +extern char * stpcpy(char * s1, const char * s2); extern char * strncpy(char * s1, const char * s2, size_t n); +extern char * strpcpy(char * s1, const char * s2, size_t n); extern size_t strlcpy(char * s1, const char * s2, size_t n); extern char * strstr(const char *in, const char *str); extern int atoi(const char * str); Index: branches/ErmaC/Enoch/i386/libsa/zalloc.c =================================================================== --- branches/ErmaC/Enoch/i386/libsa/zalloc.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsa/zalloc.c (revision 2341) @@ -78,8 +78,7 @@ zavailable = (zmem *) zalloc_base + sizeof(zmem) * totalNodes; zavailable[0].start = (char *)zavailable + sizeof(zmem) * totalNodes; - if (size == 0) - { + if (size == 0) { size = ZALLOC_LEN; } @@ -109,10 +108,8 @@ size = ((size + 0xf) & ~0xf); - if (size == 0) - { - if (zerror) - { + if (size == 0) { + if (zerror) { (*zerror)((char *)0xdeadbeef, 0, file, line); } } @@ -132,15 +129,12 @@ goto done; } #if BEST_FIT - else - { - if ((zavailable[i].size > size) && ((smallestSize == 0) || (zavailable[i].size < smallestSize))) - { + else { + if ((zavailable[i].size > size) && ((smallestSize == 0) || (zavailable[i].size < smallestSize))) { bestFit = i; smallestSize = zavailable[i].size; } } - #else else if (zavailable[i].size > size) { @@ -152,8 +146,7 @@ #endif } #if BEST_FIT - if (bestFit != -1) - { + if (bestFit != -1) { zallocate(ret = zavailable[bestFit].start, size); zavailable[bestFit].start += size; zavailable[bestFit].size -= size; @@ -161,16 +154,13 @@ #endif done: - if ((ret == 0) || (ret + size >= zalloc_end)) - { - if (zerror) - { + if ((ret == 0) || (ret + size >= zalloc_end)) { + if (zerror) { (*zerror)(ret, size, file, line); } } - if (ret != 0) - { + if (ret != 0) { bzero(ret, size); } #if ZDEBUG @@ -196,8 +186,7 @@ rp = 0; #endif - if (!start) - { + if (!start) { return; } @@ -218,14 +207,10 @@ break; } } - if (!found) - { - if (zerror) - { + if (!found) { + if (zerror) { (*zerror)(pointer, rp, "free", 0); - } - else - { + } else { return; } } @@ -233,8 +218,7 @@ 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; @@ -243,19 +227,15 @@ return; } - if ((i > 0) && (zavailable[i-1].start + zavailable[i-1].size == start)) - { + if ((i > 0) && (zavailable[i-1].start + zavailable[i-1].size == start)) { zavailable[i-1].size += tsize; zcoalesce(); return; } - if ((start + tsize) < zavailable[i].start) - { - if (++availableNodes > totalNodes) - { - if (zerror) - { + if ((start + tsize) < zavailable[i].start) { + if (++availableNodes > totalNodes) { + if (zerror) { (*zerror)((char *)0xf000f000, 0, "free", 0); } } @@ -266,10 +246,8 @@ } } - if (++availableNodes > totalNodes) - { - if (zerror) - { + if (++availableNodes > totalNodes) { + if (zerror) { (*zerror)((char *)0xf000f000, 1, "free", 0); } } @@ -292,10 +270,8 @@ zalloced[allocedNodes].start = start; zalloced[allocedNodes].size = size; - if (++allocedNodes > totalNodes) - { - if (zerror) - { + if (++allocedNodes > totalNodes) { + if (zerror) { (*zerror)((char *)0xf000f000, 2, "zallocate", 0); } }; @@ -311,8 +287,7 @@ z1 = zp + i; z2 = z1 + 1; - for (; i >= ndx; i--, z1--, z2--) - { + for (; i >= ndx; i--, z1--, z2--) { *z2 = *z1; } } @@ -326,8 +301,7 @@ z1 = zp + ndx; z2 = z1 + 1; - for (i = ndx; i < totalNodes - 1; i++, z1++, z2++) - { + for (i = ndx; i < totalNodes - 1; i++, z1++, z2++) { *z1 = *z2; } } @@ -337,10 +311,8 @@ { int i; - for (i = 0; i < availableNodes-1; i++) - { - if ( zavailable[i].start + zavailable[i].size == zavailable[i + 1].start ) - { + for (i = 0; i < availableNodes-1; i++) { + if ( zavailable[i].start + zavailable[i].size == zavailable[i + 1].start ) { zavailable[i].size += zavailable[i + 1].size; zdelete(zavailable, i + 1); availableNodes--; return; Index: branches/ErmaC/Enoch/i386/libsa/string.c =================================================================== --- branches/ErmaC/Enoch/i386/libsa/string.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsa/string.c (revision 2341) @@ -131,9 +131,9 @@ size_t strlen(const char * s) { - int n = 0; - while (*s++) n++; - return(n); + const char* save = s; + while (*s++); + return (--s) - save; } /*#endif*/ @@ -159,13 +159,18 @@ return (*s1 - *s2); } -int strncmp(const char * s1, const char * s2, size_t len) +/* Derived from FreeBSD source */ +int strncmp(const char * s1, const char * s2, size_t n) { - register int n = len; - while (--n >= 0 && *s1 == *s2++) - if (*s1++ == '\0') - return(0); - return(n<0 ? 0 : *s1 - *--s2); + if (!n) + return 0; + do { + if (*s1 != *s2++) + return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1)); + if (!*s1++) + break; + } while (--n); + return 0; } char * @@ -178,12 +183,20 @@ } char * +stpcpy(char * s1, const char * s2) +{ + while ((*s1++ = *s2++)) + continue; + return --s1; +} + +char * strncpy(char * s1, const char * s2, size_t n) { register char *ret = s1; while (n && (*s1++ = *s2++)) --n; - /* while (n--) *s1++ = '\0'; */ + if (n > 0) { bzero(s1, n); } @@ -191,6 +204,17 @@ } char * +stpncpy(char * s1, const char * s2, size_t n) +{ + while (n && (*s1++ = *s2++)) + --n; + if (n > 0) { + bzero(s1, n); + } + return s1; +} + +char * strstr(const char *in, const char *str) { char c; @@ -245,15 +269,18 @@ register char *ret = s1; while (*s1) s1++; - while (n-- && *s2) - *s1++ = *s2++; - *s1 = '\0'; + while (n-- && (*s1++ = *s2++)); return ret; } char *strcat(char *s1, const char *s2) { - return(strncat(s1, s2, strlen(s2))); + register char *ret = s1; + while (*s1) { + s1++; + } + while ((*s1++ = *s2++)); + return ret; } char *strdup(const char *s1) @@ -300,7 +327,7 @@ if (*start == '"') { start++; - + end = strchr(start, '"'); if(end) quoted = true; @@ -312,12 +339,12 @@ for ( end = start; *end && !isspace(*end); end++ ) {} } - + *len = end - start; - + if(next) *next = quoted ? end+1 : end; - + return start; } Index: branches/ErmaC/Enoch/i386/libsa/prf.c =================================================================== --- branches/ErmaC/Enoch/i386/libsa/prf.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsa/prf.c (revision 2341) @@ -104,12 +104,10 @@ loop: while ((c = *fmt++) != '%') { - if(c == '\0') - { + if(c == '\0') { return len; } - if (putfn_p) - { + if (putfn_p) { (*putfn_p)(c, putfn_arg); } len++; @@ -154,18 +152,15 @@ case 'o': case 'O': b = 8; number: - if (putfn_p) - { + if (putfn_p) { printn((u_long)*adx, b, flag, minwidth, putfn_p, putfn_arg); } len++; break; case 's': s = (char *)*adx; - while ((c = *s++)) - { - if (putfn_p) - { + while ((c = *s++)) { + if (putfn_p) { (*putfn_p)(c, putfn_arg); } len++; @@ -173,16 +168,14 @@ } while (width++ < minwidth) { - if (putfn_p) - { + if (putfn_p) { (*putfn_p)(' ', putfn_arg); } len++; } break; case 'c': - if (putfn_p) - { + if (putfn_p) { (*putfn_p)((char)*adx, putfn_arg); } len++; Index: branches/ErmaC/Enoch/i386/libsa/strtol.c =================================================================== --- branches/ErmaC/Enoch/i386/libsa/strtol.c (revision 2340) +++ branches/ErmaC/Enoch/i386/libsa/strtol.c (revision 2341) @@ -103,26 +103,20 @@ if (c == '-') { neg = 1; c = *s++; - } - else if (c == '+') - { + } else if (c == '+') { c = *s++; } - if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) - { + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { c = s[1]; s += 2; base = 16; - } - else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B')) - { + } else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B')) { c = s[1]; s += 2; base = 2; } - if (base == 0) - { + if (base == 0) { base = c == '0' ? 8 : 10; } @@ -147,17 +141,19 @@ cutlim = cutoff % (unsigned long)base; cutoff /= (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) + if (isdigit(c)) { c -= '0'; - else if (isalpha(c)) + } else if (isalpha(c)) { c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else + } else { break; - if (c >= base) + } + if (c >= base) { break; - if ((any < 0 || acc > cutoff) || (acc == cutoff && c > cutlim)) + } + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) { any = -1; - else { + } else { any = 1; acc *= base; acc += c; @@ -168,8 +164,9 @@ // errno = ERANGE; } else if (neg) acc = -acc; - if (endptr != 0) + if (endptr != 0) { *endptr = (char *)(any ? s - 1 : nptr); + } return (acc); } @@ -201,52 +198,37 @@ if (c == '-') { neg = 1; c = *s++; - } - else if (c == '+') - { + } else if (c == '+') { c = *s++; } - if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) - { + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { c = s[1]; s += 2; base = 16; - } - else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B')) - { + } else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B')) { c = s[1]; s += 2; base = 2; } - if (base == 0) - { + if (base == 0) { base = c == '0' ? 8 : 10; } cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) - { + if (isdigit(c)) { c -= '0'; - } - else if (isalpha(c)) - { + } else if (isalpha(c)) { c -= isupper(c) ? 'A' - 10 : 'a' - 10; - } - else - { + } else { break; } - if (c >= base) - { + if (c >= base) { break; } - if ((any < 0 || acc > cutoff) || (acc == cutoff && c > cutlim)) - { + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) { any = -1; - } - else - { + } else { any = 1; acc *= base; acc += c; @@ -255,13 +237,10 @@ if (any < 0) { acc = ULONG_MAX; // errno = ERANGE; - } - else if (neg) - { + } else if (neg) { acc = -acc; } - if (endptr != 0) - { + if (endptr != 0) { *endptr = (char *)(any ? s - 1 : nptr); } return (acc); @@ -297,47 +276,35 @@ c = *s++; } else { neg = 0; - if (c == '+') - { + if (c == '+') { c = *s++; } } - if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) - { + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { c = s[1]; s += 2; base = 16; } - if (base == 0) - { + if (base == 0) { base = c == '0' ? 8 : 10; } qbase = (unsigned)base; cutoff = (unsigned long long)UQUAD_MAX / qbase; cutlim = (unsigned long long)UQUAD_MAX % qbase; for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) - { + if (isdigit(c)) { c -= '0'; - } - else if (isalpha(c)) - { + } else if (isalpha(c)) { c -= isupper(c) ? 'A' - 10 : 'a' - 10; - } - else - { + } else { break; } - if (c >= base) - { + if (c >= base) { break; } - if ((any < 0 || acc > cutoff) || (acc == cutoff && c > cutlim)) - { + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) { any = -1; - } - else - { + } else { any = 1; acc *= qbase; acc += c; @@ -346,13 +313,10 @@ if (any < 0) { acc = UQUAD_MAX; // errno = ERANGE; - } - else if (neg) - { + } else if (neg) { acc = -acc; } - if (endptr != 0) - { + if (endptr != 0) { *endptr = (char *)(any ? s - 1 : nptr); } return (acc); Index: branches/ErmaC/Enoch/doc/BootHelp.txt =================================================================== --- branches/ErmaC/Enoch/doc/BootHelp.txt (revision 2340) +++ branches/ErmaC/Enoch/doc/BootHelp.txt (revision 2341) @@ -176,6 +176,7 @@ Rescan=Yes Enable CD-ROM rescan mode. "Rescan Prompt"=Yes Prompts for enable CD-ROM rescan mode. SystemId= Set the system id manually to UUID. + Deprecated - Now SMsystemuuid in smbios.plist SMUUID in smbios config (reserved field) isn't used then. SystemType= Set the system type to n, where n is between 0..6 (default=1 Desktop) Index: branches/ErmaC/Enoch/CHANGES =================================================================== --- branches/ErmaC/Enoch/CHANGES (revision 2340) +++ branches/ErmaC/Enoch/CHANGES (revision 2341) @@ -1,3 +1,30 @@ +- bitshoveler : Optimized basic string functions strlen, strncmp, strncat, strcat +- ErmaC : Replaced sprintf with snprintf in spd.c. +- bitshoveler : Fixed inadvertent text buffer overflow in getDDRSerial +- bitshoveler : optimize get_hda_controller_name() +- Bungo : One of the changes as of rev2284 is boot option SystemId has now been deprecated. Instead use key SMsystemuuid in smbios.plist. +- bitshoveler : Defend against buffer overruns +- bitshoveler : Fix memory leak, defend against buffer overruns, add a check for malloc() failure +- bitshoveler : getMemoryInfoString: defend against buffer overruns, change O(n^2) algorithm to O(n) +- bitshoveler : Add closedir() to match opendir() call; relocate a malloc() call to fix a memory leak on error; better defense against buffer overruns +- bitshoveler : Improve robustness against buffer overruns +- bitshoveler : Add closedir() for every opendir() call, make more robust against buffer overruns +- bitshoveler : Fix memory leak +- bitshoveler : Fix cppcheck detected memory leak and error, make more robust against buffer overrun +- bitshoveler : get_pci_dev_path: get rid of tmp buffer, use snprintf, improved O(n) algorithm instead of O(n^2) (whoopee); dump_pci_dt: hack fix for printf format string vs. args mismatch +- bitshoveler : Fix memory leak; use snprintf instead of sprintf to make more robust +- bitshoveler : Fix badly formed comment inside #ifdef +- bitshoveler : setup_gma_devprop: fix memory leak +- bitshoveler : setup_nhm: fix cppcheck error +- bitshoveler : Correct cppcheck detected errors, make more robust against errors +- bitshoveler : AllocateMemoryRange: fix cppcheck detected memory leak +- bitshoveler : search_and_get_acpi_fd: fix pointer-to-temporary return problem; use snprintf instead of sprintf to prevent buffer overflows +- bitshoveler : sym_expand_string_value(): fix cppcheck errors; more to be done here +- bitshoveler : append_string(): fix cppcheck errors +- bitshoveler : conf_write_autoconf(): fix cppcheck errors +- bitshoveler : Fix memory leak for new_layout in main() +- bitshoveler : Implement snprintf(); implement missing zero-fill in strncpy() +- bitshoveler : Use original *BSD source for strlcpy() - ErmaC: Port from Enoch the support for IVY Bridge and Haswell Intel Graphics cards. http://www.insanelymac.com/forum/topic/288241-intel-hd4000-and-haswell-inject-aaplig-platform-id/ - 2255: ErmaC add Skip flag key for Intel/nVidia/ATi from Enoch - 2252: revert define processors name to match with xnu kernel name