Index: branches/JrCs/i386/libsaio/device_tree.c =================================================================== --- branches/JrCs/i386/libsaio/device_tree.c (revision 71) +++ branches/JrCs/i386/libsaio/device_tree.c (revision 72) @@ -62,7 +62,7 @@ static Property *freeProperties, *allocedProperties; Property * -DT__AddProperty(Node *node, char *name, uint32_t length, void *value) +DT__AddProperty(Node *node, const char *name, uint32_t length, const void *value) { Property *prop; @@ -92,7 +92,7 @@ prop->name = name; prop->length = length; - prop->value = value; + prop->value = (void *) value; // Always add to end of list if (node->properties == 0) { Index: branches/JrCs/i386/libsaio/device_tree.h =================================================================== --- branches/JrCs/i386/libsaio/device_tree.h (revision 71) +++ branches/JrCs/i386/libsaio/device_tree.h (revision 72) @@ -9,9 +9,9 @@ #include typedef struct _Property { - char * name; - uint32_t length; - void * value; + const char * name; + uint32_t length; + void * value; struct _Property * next; } Property; @@ -27,7 +27,7 @@ extern Property * -DT__AddProperty(Node *node, char *name, uint32_t length, void *value); +DT__AddProperty(Node *node, const char *name, uint32_t length, const void *value); extern Node * DT__AddChild(Node *parent, char *name); Index: branches/JrCs/i386/libsaio/Makefile =================================================================== --- branches/JrCs/i386/libsaio/Makefile (revision 71) +++ branches/JrCs/i386/libsaio/Makefile (revision 72) @@ -41,9 +41,9 @@ cpu.o platform.o dsdt_patcher.o \ smbios_patcher.o fake_efi.o ext2fs.o \ hpet.o spd.o usb.o pci_setup.o \ - device_inject.o nvidia.o ati.o mem.o + device_inject.o nvidia.o ati.o \ + convert.o mem.o - SAIO_EXTERN_OBJS = console.o SFILES = Index: branches/JrCs/i386/libsaio/device_inject.c =================================================================== --- branches/JrCs/i386/libsaio/device_inject.c (revision 71) +++ branches/JrCs/i386/libsaio/device_inject.c (revision 72) @@ -9,8 +9,8 @@ #include "bootstruct.h" #include "pci.h" #include "device_inject.h" +#include "convert.h" - #ifndef DEBUG_INJECT #define DEBUG_INJECT 0 #endif @@ -38,81 +38,6 @@ return NULL; } -uint32_t ascii_hex_to_int(char *buff) -{ - uint32_t value = 0, i, digit; - for(i = 0; i < strlen(buff); i++) - { - if (buff[i] >= 48 && buff[i] <= 57) // '0' through '9' - digit = buff[i] - 48; - else if (buff[i] >= 65 && buff[i] <= 70) // 'A' through 'F' - digit = buff[i] - 55; - else if (buff[i] >= 97 && buff[i] <= 102) // 'a' through 'f' - digit = buff[i] - 87; - else - return value; - - value = digit + 16 * value; - } - return value; -} - -void *convertHexStr2Binary(const char *hexStr, int *outLength) -{ - int len; - char hexNibble; - char hexByte[2]; - uint8_t binChar; - uint8_t *binStr; - int hexStrIdx, binStrIdx, hexNibbleIdx; - - len = strlen(hexStr); - if (len > 1) - { - // the resulting binary will be the half size of the input hex string - binStr = malloc(len / 2); - binStrIdx = 0; - hexNibbleIdx = 0; - for (hexStrIdx = 0; hexStrIdx < len; hexStrIdx++) - { - hexNibble = hexStr[hexStrIdx]; - - // ignore all chars except valid hex numbers - if (hexNibble >= '0' && hexNibble <= '9' - || hexNibble >= 'A' && hexNibble <= 'F' - || hexNibble >= 'a' && hexNibble <= 'f') - { - hexByte[hexNibbleIdx++] = hexNibble; - - // found both two nibbles, convert to binary - if (hexNibbleIdx == 2) - { - binChar = 0; - - 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); - } - - binStr[binStrIdx++] = binChar; - hexNibbleIdx = 0; - } - } - } - *outLength = binStrIdx; - return binStr; - } - else - { - *outLength = 0; - return NULL; - } -} - void setupDeviceProperties(Node *node) { const char *val; @@ -142,19 +67,6 @@ } } -uint16_t dp_swap16(uint16_t toswap) -{ - return (((toswap & 0x00FF) << 8) | ((toswap & 0xFF00) >> 8)); -} - -uint32_t dp_swap32(uint32_t toswap) -{ - return ((toswap & 0x000000FF) << 24) | - ((toswap & 0x0000FF00) << 8 ) | - ((toswap & 0x00FF0000) >> 8 ) | - ((toswap & 0xFF000000) >> 24); -} - struct DevPropString *devprop_create_string(void) { string = (struct DevPropString*)malloc(sizeof(struct DevPropString)); Index: branches/JrCs/i386/libsaio/stringTable.c =================================================================== --- branches/JrCs/i386/libsaio/stringTable.c (revision 71) +++ branches/JrCs/i386/libsaio/stringTable.c (revision 72) @@ -37,11 +37,6 @@ //static void eatThru(char val, const char **table_p); -static inline int isspace(char c) -{ - return (c == ' ' || c == '\t'); -} - /* * Compare a string to a key with quoted characters */ Index: branches/JrCs/i386/libsaio/convert.c =================================================================== --- branches/JrCs/i386/libsaio/convert.c (revision 0) +++ branches/JrCs/i386/libsaio/convert.c (revision 72) @@ -0,0 +1,151 @@ +/* + * Convert.c + * Implement conversion utility functions + * Create UUID parsing functions and gather other conversion routines + * --Rek + */ + +#include "convert.h" + +/** Transform a 16 bytes hexadecimal value UUID to a string */ +const char* getStringFromUUID(const EFI_CHAR8* eUUID) +{ + static char msg[UUID_LEN*2 + 8] = ""; + if (!eUUID) return NULL; + const unsigned char * uuid = (unsigned char*) eUUID; + sprintf(msg, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], uuid[6], uuid[7], + uuid[8], uuid[9], uuid[10],uuid[11], + uuid[12],uuid[13],uuid[14],uuid[15]); + return msg; +} + +/** Parse an UUID string into an (EFI_CHAR8*) buffer */ +EFI_CHAR8* getUUIDFromString(const char *source) +{ + if (! source) return NULL; + + char* p = (char*) source; + int i; + char buf[3]; + static EFI_CHAR8 uuid[UUID_LEN+1]=""; + + buf[2] = '\0'; + for (i=0; i < UUID_LEN; i++) { + if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) { + return NULL; + } + buf[0] = *p++; + buf[1] = *p++; + uuid[i] = (unsigned char) strtoul(buf, NULL, 16); + if (*p == '-' && (i % 2) == 1 && i < UUID_LEN - 1) { + p++; + } + } + uuid[UUID_LEN]='\0'; + + if (*p != '\0') { + return NULL; + } + return uuid; +} + +/** XXX AsereBLN replace by strtoul */ +uint32_t ascii_hex_to_int(char *buff) +{ + uint32_t value = 0, i, digit; + for(i = 0; i < strlen(buff); i++) + { + if (buff[i] >= 48 && buff[i] <= 57) // '0' through '9' + digit = buff[i] - 48; + else if (buff[i] >= 65 && buff[i] <= 70) // 'A' through 'F' + digit = buff[i] - 55; + else if (buff[i] >= 97 && buff[i] <= 102) // 'a' through 'f' + digit = buff[i] - 87; + else + return value; + + value = digit + 16 * value; + } + return value; +} + +void *convertHexStr2Binary(const char *hexStr, int *outLength) +{ + int len; + char hexNibble; + char hexByte[2]; + uint8_t binChar; + uint8_t *binStr; + int hexStrIdx, binStrIdx, hexNibbleIdx; + + len = strlen(hexStr); + if (len > 1) + { + // the resulting binary will be the half size of the input hex string + binStr = malloc(len / 2); + binStrIdx = 0; + hexNibbleIdx = 0; + for (hexStrIdx = 0; hexStrIdx < len; hexStrIdx++) + { + hexNibble = hexStr[hexStrIdx]; + + // ignore all chars except valid hex numbers + if (hexNibble >= '0' && hexNibble <= '9' + || hexNibble >= 'A' && hexNibble <= 'F' + || hexNibble >= 'a' && hexNibble <= 'f') + { + hexByte[hexNibbleIdx++] = hexNibble; + + // found both two nibbles, convert to binary + if (hexNibbleIdx == 2) + { + binChar = 0; + + 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); + } + + binStr[binStrIdx++] = binChar; + hexNibbleIdx = 0; + } + } + } + *outLength = binStrIdx; + return binStr; + } + else + { + *outLength = 0; + return NULL; + } +} + +// FIXME: can't use my original code here, +// Ironically, trying to reuse convertHexStr2Binary() would RESET the system! +/* +static EFI_CHAR8* getUUIDFromString2(const char * szInUUID) +{ + char szUUID[UUID_LEN+1], *p=szUUID; + int size=0; + void* ret; + + if (!szInUUID || strlen(szInUUID) to valid UUID.\n", szUUID); + return (EFI_CHAR8*) 0; + } + return (EFI_CHAR8*) ret; // new allocated buffer containing the converted string to bin +} +*/ Index: branches/JrCs/i386/libsaio/convert.h =================================================================== --- branches/JrCs/i386/libsaio/convert.h (revision 0) +++ branches/JrCs/i386/libsaio/convert.h (revision 72) @@ -0,0 +1,33 @@ +/* + * Convert.h + * Declare conversion utility functions + * --Rek + */ + +#ifndef __CONVERT_H +#define __CONVERT_H +#include "libsaio.h" +#include "efi.h" + +#define UUID_LEN 16 + +const char * getStringFromUUID(const EFI_CHAR8* uuid); +EFI_CHAR8* getUUIDFromString(const char *source); +void *convertHexStr2Binary(const char *hexStr, int *outLength); +uint32_t ascii_hex_to_int(char *buff); + +static inline uint16_t dp_swap16(uint16_t toswap) +{ + return (((toswap & 0x00FF) << 8) | ((toswap & 0xFF00) >> 8)); +} + +static inline uint32_t dp_swap32(uint32_t toswap) +{ + return ((toswap & 0x000000FF) << 24) | + ((toswap & 0x0000FF00) << 8 ) | + ((toswap & 0x00FF0000) >> 8 ) | + ((toswap & 0xFF000000) >> 24); +} + + +#endif Index: branches/JrCs/i386/libsa/libsa.h =================================================================== --- branches/JrCs/i386/libsa/libsa.h (revision 71) +++ branches/JrCs/i386/libsa/libsa.h (revision 72) @@ -30,8 +30,42 @@ #include #include #include +#include /* + * ctype stuff (aserebln) + */ +static inline int isupper(char c) +{ + return (c >= 'A' && c <= 'Z'); +} + +static inline int islower(char c) +{ + return (c >= 'a' && c <= 'z'); +} + +static inline int isalpha(char c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); +} + +static inline int isspace(char c) +{ + return (c == ' ' || c == '\t' || c == '\n' || c == '\12'); +} + +static inline int isdigit(char c) +{ + return (c >= '0' && c <= '9'); +} + +static inline int isxdigit(char c) +{ + return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); +} + +/* * string.c */ #ifndef bcopy Index: branches/JrCs/i386/libsa/strtol.c =================================================================== --- branches/JrCs/i386/libsa/strtol.c (revision 71) +++ branches/JrCs/i386/libsa/strtol.c (revision 72) @@ -74,37 +74,6 @@ #include "libsa.h" #include -static inline int -isupper(char c) -{ - return (c >= 'A' && c <= 'Z'); -} - -static inline int -islower(char c) -{ - return (c >= 'a' && c <= 'z'); -} - -static inline int -isalpha(char c) -{ - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); -} - -static inline int -isspace(char c) -{ - return (c == ' ' || c == '\t' || c == '\n' || c == '\12'); -} - -static inline int -isdigit(char c) -{ - return (c >= '0' && c <= '9'); -} - - /* * Convert a string to a long integer. *