Chameleon

Chameleon Commit Details

Date:2010-07-22 20:22:09 (9 years 30 days ago)
Author:Tamás Kosárszky
Commit:199
Parents: 198
Message:Synced trunk with mozodojo's changes between r196-r198: Added CPU family check. Fixed memory deallocation error while adding SSDTs into RSDT/XSDT. Fixed improper DSDT parsing algorithm in acpi_find_cpu_names. Improvements in memory detection algo, thank to Azimutz. Using my own algo for CPU type injections (need testing and testers, especially with newer i7, i5, i3 cpus, show me chameleon log).
Changes:
M/trunk/i386/boot2/drivers.c
M/trunk/i386/libsaio/acpi_patcher.c
M/trunk/i386/libsaio/smbios_patcher.c
M/trunk/i386/libsaio/spd.c
M/trunk/i386/libsa/libsa.h
M/trunk/i386/libsaio/aml_generator.c

File differences

trunk/i386/libsaio/acpi_patcher.c
195195
196196
197197
198
198
199199
200
201
202
200
201
202
203203
204204
205
205
206
207
206208
207
209
210
211
208212
209
210
211
212
213
214
215213
216214
217
218
219
215
216
217
218
219
220
221
222
223
220224
221225
222226
......
775779
776780
777781
778
779782
783
784
780785
781786
782787
......
841846
842847
843848
844
849
850
845851
846852
847853
......
872878
873879
874880
875
881
876882
877883
878884
......
899905
900906
901907
908
909
910
911
912
913
914
915
916
902917
903918
904919
905
906
920
907921
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
922
923
932924
933
934
925
935926
936
937
938
939
940927
941928
942929
......
967954
968955
969956
970
957
958
971959
972960
973961
......
998986
999987
1000988
1001
989
1002990
1003991
1004992
......
10301018
10311019
10321020
1021
1022
1023
1024
1025
1026
1027
1028
1029
10331030
10341031
10351032
1036
1037
1033
10381034
1039
1040
1041
1042
1043
1035
1036
10441037
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1038
10671039
1068
1069
1070
1071
10721040
10731041
10741042
for (i=0; i<length-7; i++)
{
if (dsdt[i] == 0x83 && dsdt[i+1] == 0x0B && dsdt[i+6] < 32)
if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP
{
acpi_cpu_name[acpi_cpu_count] = malloc(5);
int j;
uint8_t offset = i+2+(dsdt[i+2] >> 6) + 1, j;
bool add_name = TRUE;
for (j=0; j<4; j++)
{
if (aml_isvalidchar(dsdt[i+2+j]))
char c = dsdt[offset+j];
if (!aml_isvalidchar(c))
{
acpi_cpu_name[acpi_cpu_count][j] = dsdt[i+2+j];
add_name = FALSE;
verbose("Invalid characters found in ProcessorOP!\n");
break;
}
else
{
verbose("Invalid characters found in ProcessorOP!");
free(acpi_cpu_name[acpi_cpu_count]);
continue;
}
}
verbose("Found %c%c%c%c (from DSDT)\n", acpi_cpu_name[acpi_cpu_count][0], acpi_cpu_name[acpi_cpu_count][1], acpi_cpu_name[acpi_cpu_count][2], acpi_cpu_name[acpi_cpu_count][3]);
acpi_cpu_count++;
if (add_name && dsdt[offset+5] < 32 )
{
acpi_cpu_name[acpi_cpu_count] = malloc(5);
memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4);
verbose("Found %c%c%c%c (from DSDT)\n", acpi_cpu_name[acpi_cpu_count][0], acpi_cpu_name[acpi_cpu_count][1], acpi_cpu_name[acpi_cpu_count][2], acpi_cpu_name[acpi_cpu_count][3]);
if (++acpi_cpu_count == 32) return;
}
}
}
}
// Mozodojo: Load additional SSDTs
struct acpi_2_ssdt *new_ssdt[32]; // 30 + 2 additional tables for pss & cst
struct acpi_2_fadt *fadt; // will be used in CST generator
int ssdt_count=0;
// SSDT Options
bool drop_ssdt=false, generate_pstates=false, generate_cstates=false;
getBoolForKey(kDropSSDT, &drop_ssdt, &bootInfo->bootConfig);
int rsdt_entries_num;
int dropoffset=0, i;
rsdt_mod=(struct acpi_2_rsdt *)AllocateKernelMemory(rsdt->Length);
// mozo: using malloc cos I didn't found how to free already allocated kernel memory
rsdt_mod=(struct acpi_2_rsdt *)malloc(rsdt->Length);
memcpy (rsdt_mod, rsdt, rsdt->Length);
rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;
rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;
}
if (tableSign(table, "FACP"))
{
struct acpi_2_fadt *fadt_mod;
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)rsdt_entries[i];
DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);
}
DBG("\n");
// Allocate rsdt in Kernel memory area
rsdt_mod->Length += rsdt_mod->Length + 4*ssdt_count - 4*dropoffset;
struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);
memcpy (rsdt_copy, rsdt_mod, rsdt_mod->Length);
free(rsdt_mod); rsdt_mod = rsdt_copy;
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);
// Mozodojo: Insert additional SSDTs into RSDT
if(ssdt_count>0)
{
uint32_t j = rsdt_mod->Length;
bool add_new_ssdt = TRUE;
int j;
rsdt_mod->Length+=4*ssdt_count-4*dropoffset;
if (rsdt_mod->Length > j)
{
struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);
if (rsdt_copy)
{
memcpy (rsdt_copy, rsdt_mod, rsdt_mod->Length);
free(rsdt_mod); rsdt_mod = rsdt_copy;
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);
}
else
{
verbose("RSDT: Couldn't allocate memory for additional SSDT tables!\n");
add_new_ssdt = FALSE;
}
}
if (add_new_ssdt)
{
for (j=0; j<ssdt_count; j++)
rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
for (j=0; j<ssdt_count; j++)
rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
verbose("RSDT: Added %d SSDT table(s)\n", ssdt_count);
}
verbose("RSDT: Added %d SSDT table(s)\n", ssdt_count);
}
else
{
rsdt_mod->Length-=4*dropoffset;
}
// Correct the checksum of RSDT
DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);
int xsdt_entries_num, i;
int dropoffset=0;
xsdt_mod=(struct acpi_2_xsdt*)AllocateKernelMemory(xsdt->Length);
// mozo: using malloc cos I didn't found how to free already allocated kernel memory
xsdt_mod=(struct acpi_2_xsdt*)malloc(xsdt->Length);
memcpy(xsdt_mod, xsdt, xsdt->Length);
rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;
xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;
}
if (tableSign(table, "FACP"))
{
struct acpi_2_fadt *fadt_mod;
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];
DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt,
}
// Allocate xsdt in Kernel memory area
xsdt_mod->Length += 8*ssdt_count - 8*dropoffset;
struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);
memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);
free(xsdt_mod); xsdt_mod = xsdt_copy;
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);
// Mozodojo: Insert additional SSDTs into XSDT
if(ssdt_count>0)
{
int j = xsdt_mod->Length;
bool add_new_ssdt = TRUE;
int j;
xsdt_mod->Length+=8*ssdt_count-8*dropoffset;
if (xsdt_mod->Length > j)
{
struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);
for (j=0; j<ssdt_count; j++)
xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
if (xsdt_copy)
{
memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);
free(xsdt_mod); xsdt_mod = xsdt_copy;
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);
}
else
{
verbose("RSDT: Couldn't allocate memory for additional SSDT tables!\n");
add_new_ssdt = FALSE;
}
}
if (add_new_ssdt)
{
for (j=0; j<ssdt_count; j++)
xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);
}
verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);
}
else
{
xsdt_mod->Length-=8*dropoffset;
}
// Correct the checksum of XSDT
xsdt_mod->Checksum=0;
trunk/i386/libsaio/spd.c
175175
176176
177177
178
178
179179
180180
181181
......
197197
198198
199199
200
201
202
200
201
202
203
203204
204205
205206
206207
207208
208
209
209210
210211
211212
}
if (!ret) sprintf(asciiSerial, "10000000%d", serialnum++);
else sprintf(asciiSerial, "%d", ret);
else sprintf(asciiSerial, "%X", ret);
return strdup(asciiSerial);
}
if (sPart) { // Check that the spd part name is zero terminated and that it is ascii:
bzero(asciiPartNo, 32);
for (i=0; i<32; i++) {
if (isalpha(sPart[i]) || isdigit(sPart[i])) // It seems that System Profiler likes only letters and digits...
asciiPartNo[index++] = sPart[i];
else if (!isascii(sPart[i]))
char c = sPart[i];
if (isalpha(c) || isdigit(c) || ispunct(c)) // It seems that System Profiler likes only letters and digits...
asciiPartNo[index++] = c;
else if (!isascii(c))
break;
}
return strdup(asciiPartNo);
}
return "N/A";
return NULL;
}
int mapping []= {0,2,1,3,4,6,5,7,8,10,9,11};
trunk/i386/libsaio/smbios_patcher.c
142142
143143
144144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
145159
146160
147
148
149
161
162
163
150164
151
152
153
154
155
156
157
158
159
160
161
162
163
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
164181
165
166
167
168
169
170
171
182
183
184
172185
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
186
214187
215
216
217
218
219
220
221
222
223
224
225
226188
189
190
227191
228192
229193
return Platform.CPU.CPUFrequency/1000000;
}
static int sm_get_simplecputype()
{
if (Platform.CPU.NoCores >= 4)
{
return 0x0501; // Quad-Core Xeon
}
else if (Platform.CPU.NoCores == 1)
{
return 0x0201; // Core Solo
};
return 0x0301; // Core 2 Duo
}
static int sm_get_cputype (const char *name, int table_num)
{
if (Platform.CPU.Vendor == 0x756E6547) {
int cores = Platform.CPU.NoCores;
int intelPM = Platform.CPU.Model; //+ (Platform.CPU.ExtModel<< 4);//verify this
if (Platform.CPU.Vendor == 0x756E6547) // Intel
{
verbose("CPU is Intel, family 0x%x, model 0x%x, ext.model 0x%x\n", Platform.CPU.Family, Platform.CPU.Model, Platform.CPU.ExtModel);
switch (intelPM) {
case 13: // Pentium M model D
return 0x0101;
break;
case 14: // Core Solo/Duo, "Yonah", 65nm
return 0x0201;
break;
case 15: // Pentium 4, Core 2, Xeon, "Merom", "Conroe", 65nm
switch (cores) {
case 1: // Core Solo
return 0x0201;
break;
case 2: // Core 2, 65nm
switch (Platform.CPU.Family)
{
case 0x06:
{
switch (Platform.CPU.Model)
{
case 0x0F: // Intel Core (65nm)
case 0x17: // Intel Core (45nm)
case 0x1C: // Intel Atom (45nm)
return sm_get_simplecputype();
case 0x1A: // Intel Core i7 LGA1366 (45nm)
return 0x0701;
case 0x1E: // Intel Core i5, i7 LGA1156 (45nm)
case 0x1F: // Intel Core i5, i7 LGA1156 (45nm) ???
return 0x0601;
case 0x25: // Intel Core i3, i5, i7 LGA1156 (32nm)
return 0x0301;
break;
case 4: // Quad Core, Xeon
return 0x0501;
break;
default:
return 0x0301;
break;
case 0x2C: // Intel Core i7 LGA1366 (32nm) 6 Core
case 0x2E: // Intel Core i7 LGA1366 (45nm) 6 Core ???
return 0x0601;
}
/* if (cores == 1)
return 0x0201; // Core Solo
else if (cores == 2)
return 0x0301; // Core 2, 65nm
else if (cores == 4)
return 0x0501; // Quad-Core Xeon
else
return 0x0301;*/
break;
case 21: // EP80579 integrated processor
return 0x0301; // ???
break;
case 22: // Core 2 Solo, "Merom-L", "Conroe-L", 45nm
return 0x0201; // ???
break;
case 23: // Core 2 Extreme, Xeon, "Penryn", "Wolfdale", 45nm
return 0x0301;
break;
case 26: // Nehalem, Xeon 5500, "Bloomfield", 45nm
return 0x0701;
break;
case 29: // Six-Core Xeon 7400, "Dunnington", 45nm
return 0x0401;
break;
case 30: // Nehalem, Xeon, "Lynnfield", "Clarksfield", "Jasper", 45nm
return 0x0701;
break;
case 31: // Core i5, Xeon MP, "Havendale", "Auburndale", 45nm
return 0x0601;
break;
case 37: // Nehalem, "Clarkdale", 32nm
return 0x0301; // ???
break;
case 44: // Nehalem, "Gulftown", 32nm
return 0x0601;
break;
case 46: // "Nehalem-ex", "Beckton", 45nm
return 0x0301; // ???
break;
default:
goto core_ident;
}
}
} else {
core_ident:
if (Platform.CPU.NoCores == 1) {
return 0x0201; // Core Solo
} else if (Platform.CPU.NoCores == 2) {
return 0x0301; // Core 2 Duo
} else if (Platform.CPU.NoCores >= 4) {
return 0x0501; // Quad-Core Xeon
} else {
return 0x0301; // Core 2 Duo
}
}
return sm_get_simplecputype();
}
static int sm_get_memtype (const char *name, int table_num)
trunk/i386/libsaio/aml_generator.c
1515
1616
1717
18
18
1919
2020
2121
......
163163
164164
165165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189166
190167
168
169
170
191171
192172
193173
......
230210
231211
232212
233
213
234214
235215
236216
237217
218
219
238220
239221
240222
......
247229
248230
249231
250
251
252232
253233
254234
......
261241
262242
263243
264
244
265245
266
246
267247
268248
269249
return 2;
else if (length > 0x3FFF)
return 3;
return 1;
}
return 4;
}
int aml_get_names_count(const char* name)
{
int i, len = strlen(name), count = 0;
for (i = 0; i < len; i++)
{
if (name[i] == '.')
{
count++;
}
else if (!aml_isvalidchar(name[i]))
{
len = i;
break;
}
}
if (count == 0 && len > 0)
count++;
return count;
}
int aml_fill_name(struct aml_chunk* node, const char* name)
{
if (!node)
return -1;
int i, len = strlen(name), count = 0;
for (i = 0; i < len; i++)
node->Buffer[offset++] = 0x2f; // Multi name
node->Buffer[offset++] = count; // Names count
}
int j = 0;
for (i = 0; i < count; i++)
{
offset += aml_fill_simple_name(node->Buffer + offset, name + j);
while (name[j] != '.')
{
if (j < len)
return -1;
}
}
offset += aml_fill_simple_name(node->Buffer + offset, name + j);
}
return offset;
if (node)
{
node->Type = AML_CHUNK_NAME;
aml_fill_name(node, name);
return node->Length;
}
trunk/i386/boot2/drivers.c
262262
263263
264264
265
265
266266
267267
268268
{
long ret, flags, time, time2;
char altDirSpec[512];
sprintf (altDirSpec, "%s%s", dirSpec, extDirSpec);
ret = GetFileInfo(altDirSpec, "Extensions.mkext", &flags, &time);
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat))
trunk/i386/libsa/libsa.h
7070
7171
7272
73
74
75
76
77
7378
7479
7580
return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'));
}
//Azi: TODO - add more ponctuation characters as needed; at least these two, i need for PartNo.
static inline int ispunct(char c)
{
return (c == '.' || c == '-');
}
/*
* string.c

Archive Download the corresponding diff file

Revision: 199