Chameleon

Chameleon Commit Details

Date:2010-02-12 11:34:47 (14 years 2 months ago)
Author:JrCs
Commit:72
Parents: 71
Message:New convert file
Changes:
A/branches/JrCs/i386/libsaio/convert.c
A/branches/JrCs/i386/libsaio/convert.h
M/branches/JrCs/i386/libsaio/device_tree.c
M/branches/JrCs/i386/libsaio/stringTable.c
M/branches/JrCs/i386/libsa/strtol.c
M/branches/JrCs/i386/libsaio/device_tree.h
M/branches/JrCs/i386/libsa/libsa.h
M/branches/JrCs/i386/libsaio/device_inject.c
M/branches/JrCs/i386/libsaio/Makefile

File differences

branches/JrCs/i386/libsaio/device_tree.c
6262
6363
6464
65
65
6666
6767
6868
......
9292
9393
9494
95
95
9696
9797
9898
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;
prop->name = name;
prop->length = length;
prop->value = value;
prop->value = (void *) value;
// Always add to end of list
if (node->properties == 0) {
branches/JrCs/i386/libsaio/device_tree.h
99
1010
1111
12
13
14
12
13
14
1515
1616
1717
......
2727
2828
2929
30
30
3131
3232
3333
#include <stdint.h>
typedef struct _Property {
char * name;
uint32_t length;
void * value;
const char * name;
uint32_t length;
void * value;
struct _Property * next;
} Property;
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);
branches/JrCs/i386/libsaio/Makefile
4141
4242
4343
44
44
45
4546
46
4747
4848
4949
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 =
branches/JrCs/i386/libsaio/device_inject.c
99
1010
1111
12
1213
13
1414
1515
1616
......
3838
3939
4040
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
11641
11742
11843
......
14267
14368
14469
145
146
147
148
149
150
151
152
153
154
155
156
157
15870
15971
16072
#include "bootstruct.h"
#include "pci.h"
#include "device_inject.h"
#include "convert.h"
#ifndef DEBUG_INJECT
#define DEBUG_INJECT 0
#endif
return NULL;
}
uint32_t ascii_hex_to_int(char *buff)
{
uint32_tvalue = 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;
}
returnvalue;
}
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;
}
}
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));
branches/JrCs/i386/libsaio/stringTable.c
3737
3838
3939
40
41
42
43
44
4540
4641
4742
//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
*/
branches/JrCs/i386/libsaio/convert.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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_tvalue = 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;
}
returnvalue;
}
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)<UUID_LEN) return (EFI_CHAR8*) 0;
while(*szInUUID) if (*szInUUID!='-') *p++=*szInUUID++; else szInUUID++;
*p='\0';
ret = convertHexStr2Binary(szUUID, &size);
if (!ret || size!=UUID_LEN)
{
verbose("UUID: cannot convert string <%s> to valid UUID.\n", szUUID);
return (EFI_CHAR8*) 0;
}
return (EFI_CHAR8*) ret; // new allocated buffer containing the converted string to bin
}
*/
branches/JrCs/i386/libsaio/convert.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
branches/JrCs/i386/libsa/libsa.h
3030
3131
3232
33
3334
3435
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
3569
3670
3771
#include <mach-o/loader.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>
/*
* 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
branches/JrCs/i386/libsa/strtol.c
7474
7575
7676
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
10877
10978
11079
#include "libsa.h"
#include <limits.h>
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.
*

Archive Download the corresponding diff file

Revision: 72