Chameleon

Chameleon Commit Details

Date:2013-10-16 02:32:57 (5 years 7 months ago)
Author:ErmaC
Commit:2266
Parents: 2265
Message:XCode 5 compatibility credits to bltz, zenith432 and meklort.
Changes:
M/trunk/i386/modules/Makefile
M/trunk/i386/libsaio/gma.c
M/trunk/i386/modules/KernelPatcher/Cconfig
M/trunk/i386/libsaio/spd.c
M/trunk/i386/libsaio/cpu.c
M/trunk/i386/modules/HDAEnabler/Makefile
M/trunk/i386/libsaio/nvidia.c
M/trunk/i386/boot2/modules.c
M/trunk/i386/libsaio/cpu.h
M/trunk/i386/modules/Cconfig
M/trunk/i386/boot2/modules.h

File differences

trunk/i386/libsaio/spd.c
296296
297297
298298
299
299
300300
301301
302302
switch (slot->spd[SPD_MEMORY_TYPE]) {
case SPD_MEMORY_TYPE_SDRAM_DDR2:
slot->ModuleSize = ((1 << (slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17) *
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;
trunk/i386/libsaio/gma.c
111111
112112
113113
114
114115
115116
116117
{ 0x00,0x00,0x26,0x0d }, // 8 "AAPL,ig-platform-id" //FB: 64MB, Pipes: 3, Ports: 3, FBMem: 3 - CRW mobile GT3
{ 0x02,0x00,0x16,0x04 },// 9 "AAPL,ig-platform-id" //FB: 64MB, Pipes: 1, Ports: 1, FBMem: 1 - mobile GT2
{ 0x03,0x00,0x22,0x0d }, // 10 "AAPL,ig-platform-id" //FB: 0MB, Pipes: 0, Ports: 0, FBMem: 0 - CRW Desktop GT3
//{ 0x04,0x00,0x12,0x04 },// ?? "AAPL,ig-platform-id" //FB: 32MB, Pipes: 3, Ports: 3, FBMem: 3 - ULT mobile GT3
{ 0x05,0x00,0x26,0x0a },// 11 "AAPL,ig-platform-id" //FB: 32MB, Pipes: 3, Ports: 3, FBMem: 3 - ULT mobile GT3
{ 0x06,0x00,0x26,0x0a },// 12 "AAPL,ig-platform-id" //FB: 32MB, Pipes: 3, Ports: 3, FBMem: 3 - ULT mobile GT3
{ 0x07,0x00,0x26,0x0d }, // 13 "AAPL,ig-platform-id" //FB: 64MB, Pipes: 3, Ports: 4, FBMem: 3 - CRW mobile GT3
trunk/i386/libsaio/nvidia.c
13961396
13971397
13981398
1399
13991400
14001401
14011402
......
21462147
21472148
21482149
2150
21492151
2152
2153
21502154
21512155
21522156
{ 0x10DE11A1,0x15587102,"Clevo N13E-GR" },
{ 0x10DE11C0,0x10DE0995,"Inno3D GeForce GTX660" },
{ 0x10DE11C0,0x1458354E,"GV-N660OC-2GD" },
{ 0x10DE11C6,0x1043842A,"GTX650TI-1GD5" },
// 1200 - 12FF
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);
devprop_add_value(device, "@2,connector-type",connector_type_1, 4);
devprop_add_value(device, "@3,connector-type",connector_type_1, 4);
}
/************************ End Audio *************************/
trunk/i386/libsaio/cpu.c
5757
5858
5959
60
61
62
63
64
65
66
67
68
69
60
61
62
63
64
65
66
67
68
69
7070
71
71
72
7273
7374
7475
7576
7677
7778
78
79
80
81
79
80
81
82
8283
83
84
85
86
84
85
86
87
8788
88
89
89
90
9091
91
92
9293
9394
9495
......
121122
122123
123124
125
124126
127
125128
126129
127130
128131
129132
133
130134
135
131136
132137
138
133139
140
134141
135142
136143
......
146153
147154
148155
156
149157
158
150159
151160
152161
......
187196
188197
189198
199
190200
201
191202
192203
193204
194205
195206
207
196208
209
197210
198211
212
199213
214
200215
201216
202217
203218
204219
205220
221
206222
223
207224
208225
209226
......
240257
241258
242259
243
260
261
244262
245263
246
264
265
247266
248267
249
268
269
250270
251271
252272
253
273
274
254275
255276
256277
......
258279
259280
260281
261
282
283
262284
263285
264286
......
300322
301323
302324
303
325
326
304327
305328
306329
......
313336
314337
315338
316
317
339
340
341
342
343
344
318345
319346
320347
321348
322
349
350
323351
324352
325353
......
329357
330358
331359
332
360
361
333362
334363
335
364
365
336366
337367
338
368
369
339370
340371
341
372
373
342374
343375
344
376
377
345378
346379
347
380
381
348382
349383
350
384
385
351386
352387
353
388
389
354390
355391
356392
357
393
394
358395
359396
360397
......
367404
368405
369406
370
407
408
371409
372
410
411
373412
374413
375414
......
394433
395434
396435
397
436
437
398438
399439
400440
......
404444
405445
406446
407
447
448
408449
409450
410451
411452
412
413
453
454
455
456
457
414458
415459
416460
417461
418462
419
463
464
420465
421466
422467
423
468
469
424470
425471
426472
427
473
474
475
428476
429477
430
478
479
431480
432481
433
482
483
484
485
434486
435487
436488
437489
438
490
491
439492
440
441
442
493
494
495
496
497
498
499
500
501
502
503
443504
444505
445506
......
451512
452513
453514
454
515
516
517
455518
456519
457
520
458521
459522
460523
......
465528
466529
467530
468
531
532
533
469534
470535
471536
472537
473538
474
475
539
540
541
542
476543
477
544
545
546
478547
479548
480
549
550
481551
482
552
553
554
483555
484556
485557
......
487559
488560
489561
490
562
563
491564
492565
493566
......
536609
537610
538611
539
612
613
614
615
616
540617
618
541619
620
542621
622
543623
544
624
545625
546
626
627
628
547629
630
548631
632
549633
634
550635
636
551637
552638
553639
......
557643
558644
559645
560
646
647
648
561649
562650
563651
......
566654
567655
568656
569
657
658
570659
571660
572661
// This will flash-reboot. TODO: Use tscPanic instead.
printf("Timestamp counter calibation failed with %d attempts\n", attempts);
}
attempts++;
enable_PIT2();// turn on PIT2
set_PIT2(0);// reset timer 2 to be zero
latchTime = rdtsc64();// get the time stamp to time
latchTime = get_PIT2(&timerValue) - latchTime; // time how long this takes
set_PIT2(SAMPLE_CLKS_INT);// set up the timer for (almost) 1/20th a second
saveTime = rdtsc64();// now time how long a 20th a second is...
get_PIT2(&lastValue);
get_PIT2(&lastValue);// read twice, first value may be unreliable
do {
attempts++;
enable_PIT2();// turn on PIT2
set_PIT2(0);// reset timer 2 to be zero
latchTime = rdtsc64();// get the time stamp to time
latchTime = get_PIT2(&timerValue) - latchTime; // time how long this takes
set_PIT2(SAMPLE_CLKS_INT);// set up the timer for (almost) 1/20th a second
saveTime = rdtsc64();// now time how long a 20th a second is...
get_PIT2(&lastValue);
get_PIT2(&lastValue);// read twice, first value may be unreliable
do {
intermediate = get_PIT2(&timerValue);
if (timerValue > lastValue) {
if (timerValue > lastValue)
{
// Timer wrapped
set_PIT2(0);
disable_PIT2();
goto restart;
}
lastValue = timerValue;
} while (timerValue > 5);
printf("timerValue %d\n",timerValue);
printf("intermediate 0x%016llx\n",intermediate);
printf("saveTime 0x%016llx\n",saveTime);
} while (timerValue > 5);
printf("timerValue %d\n",timerValue);
printf("intermediate 0x%016llx\n",intermediate);
printf("saveTime 0x%016llx\n",saveTime);
intermediate -= saveTime;// raw count for about 1/20 second
intermediate *= scale[timerValue];// rescale measured time spent
intermediate /= SAMPLE_NSECS;// so its exactly 1/20 a second
intermediate += latchTime;// add on our save fudge
intermediate -= saveTime;// raw count for about 1/20 second
intermediate *= scale[timerValue];// rescale measured time spent
intermediate /= SAMPLE_NSECS;// so its exactly 1/20 a second
intermediate += latchTime;// add on our save fudge
set_PIT2(0);// reset timer 2 to be zero
disable_PIT2();// turn off PIT 2
set_PIT2(0);// reset timer 2 to be zero
disable_PIT2();// turn off PIT 2
return intermediate;
return intermediate;
}
/*
tscEnd = rdtsc64();
/* The poll loop must have run at least a few times for accuracy */
if (pollCount <= 1)
{
continue;
}
/* The TSC must increment at LEAST once every millisecond.
* We should have waited exactly 30 msec so the TSC delta should
* be >= 30. Anything less and the processor is way too slow.
*/
if ((tscEnd - tscStart) <= CALIBRATE_TIME_MSEC)
{
continue;
}
// tscDelta = MIN(tscDelta, (tscEnd - tscStart))
if ( (tscEnd - tscStart) < tscDelta )
{
tscDelta = tscEnd - tscStart;
}
}
/* tscDelta is now the least number of TSC ticks the processor made in
* a timespan of 0.03 s (e.g. 30 milliseconds)
* Also unlike Linux, our compiler can do 64-bit integer arithmetic.
*/
if (tscDelta > (1ULL<<32))
{
retval = 0;
}
else
{
retval = tscDelta * 1000 / 30;
aperfEnd = rdmsr64(MSR_AMD_APERF);
/* The poll loop must have run at least a few times for accuracy */
if (pollCount <= 1)
{
continue;
}
/* The TSC must increment at LEAST once every millisecond.
* We should have waited exactly 30 msec so the APERF delta should
* be >= 30. Anything less and the processor is way too slow.
*/
if ((aperfEnd - aperfStart) <= CALIBRATE_TIME_MSEC)
{
continue;
}
// tscDelta = MIN(tscDelta, (tscEnd - tscStart))
if ( (aperfEnd - aperfStart) < aperfDelta )
{
aperfDelta = aperfEnd - aperfStart;
}
}
/* mperfDelta is now the least number of MPERF ticks the processor made in
* a timespan of 0.03 s (e.g. 30 milliseconds)
*/
if (aperfDelta > (1ULL<<32))
{
retval = 0;
}
else
{
retval = aperfDelta * 1000 / 30;
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]);
}
{
inti;
printf("CPUID Raw Values:\n");
for (i=0; i<CPUID_MAX; i++) {
for (i=0; i<CPUID_MAX; i++)
{
printf("%02d: %08x-%08x-%08x-%08x\n", i,
p->CPU.CPUID[i][0], p->CPU.CPUID[i][1],
p->CPU.CPUID[i][2], p->CPU.CPUID[i][3]);
/* 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_treg[4];
charstr[128], *s;
/*
bcopy((char *)reg, &str[16], 16);
do_cpuid(0x80000004, reg);
bcopy((char *)reg, &str[32], 16);
for (s = str; *s != '\0'; s++) {
if (*s != ' ') break;
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.
}
/* 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;
}
fsbFrequency = 0;
cpuFrequency = 0;
if ((p->CPU.Vendor == CPUID_VENDOR_INTEL) && ((p->CPU.Family == 0x06) || (p->CPU.Family == 0x0f))) {
if ((p->CPU.Vendor == CPUID_VENDOR_INTEL) && ((p->CPU.Family == 0x06) || (p->CPU.Family == 0x0f)))
{
int intelCPU = p->CPU.Model;
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0c) || (p->CPU.Family == 0x0f && p->CPU.Model >= 0x03)) {
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0c) || (p->CPU.Family == 0x0f && p->CPU.Model >= 0x03))
{
/* Nehalem CPU model */
if (p->CPU.Family == 0x06 && (p->CPU.Model == CPU_MODEL_NEHALEM||
p->CPU.Model == CPU_MODEL_FIELDS||
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
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) max_ratio = (max_ratio + 5);
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) maxdiv = 1;
else maxdiv = 0;
} else {
if (len >= 3)
{
maxdiv = 1;
}
else
{
maxdiv = 0;
}
}
else
{
max_ratio = (bus_ratio_max * 10);
}
}
myfsb = fsbFrequency / 1000000;
verbose("Sticking with [BCLK: %dMhz, Bus-Ratio: %d]\n", myfsb, max_ratio);
currcoef = bus_ratio_max;
} else {
}
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, 15, 8);
/* Non-integer bus ratio for the max-multi*/
maxdiv = bitfield(msr, 46, 46);
/* Non-integer bus ratio for the current-multi (undocumented)*/
{
/* 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" : "");
}
}
/* Mobile CPU */
if (rdmsr64(MSR_IA32_PLATFORM_ID) & (1<<28)) {
if (rdmsr64(MSR_IA32_PLATFORM_ID) & (1<<28))
{
p->CPU.Features |= CPU_FEATURE_MOBILE;
}
}
{
if (currdiv)
{
if (!currcoef) currcoef = maxcoef;
if (!currcoef)
{
currcoef = maxcoef;
}
if (!cpuFrequency)
{
fsbFrequency = ((tscFrequency * currdiv) / currcoef);
}
else
{
fsbFrequency = ((cpuFrequency * currdiv) / currcoef);
}
DBG("%d.%d\n", currcoef / currdiv, ((currcoef % currdiv) * 100) / currdiv);
} else {
}
else
{
if (!cpuFrequency)
{
fsbFrequency = (tscFrequency / maxcoef);
}
else
{
fsbFrequency = (cpuFrequency / maxcoef);
}
DBG("%d\n", currcoef);
}
}
{
fsbFrequency = ((tscFrequency * currdiv) / currcoef);
DBG("%d.%d\n", currcoef / currdiv, ((currcoef % currdiv) * 100) / currdiv);
} else {
}
else
{
fsbFrequency = (tscFrequency / currcoef);
DBG("%d\n", currcoef);
}
}
#if 0
if (!fsbFrequency) {
if (!fsbFrequency)
{
fsbFrequency = (DEFAULT_FSB * 1000);
cpuFrequency = tscFrequency;
DBG("0 ! using the default value for FSB !\n");
trunk/i386/libsaio/cpu.h
179179
180180
181181
182
182
183183
184184
185185
++count;
__asm__ volatile(
"inb$0x61,%0"
: "=q"(nmi_sc_val) /*:*/ /* no input */ /*:*/ /* no clobber */);
: "=a"(nmi_sc_val) /*:*/ /* no input */ /*:*/ /* no clobber */);
} while( (nmi_sc_val & 0x20) == 0);
return count;
}
trunk/i386/boot2/modules.c
2222
2323
2424
25
26
27
2528
2629
2730
......
4245
4346
4447
45
46
48
49
4750
4851
49
52
5053
5154
52
55
5356
5457
5558
5659
5760
58
61
5962
6063
6164
......
7073
7174
7275
73
76
7477
7578
7679
......
108111
109112
110113
111
114
112115
113116
114117
115118
116119
117120
118
121
119122
120123
121124
......
147150
148151
149152
150
151153
152154
153155
......
155157
156158
157159
160
158161
159162
160163
......
204207
205208
206209
207
210
208211
209212
210
213
211214
212215
213216
......
232235
233236
234237
235
238
236239
237
238
240
241
239242
240
241
242
243
244
245
243
244
245
246
247
248
246249
247250
248251
......
291294
292295
293296
294
297
295298
296299
297300
......
304307
305308
306309
307
310
308311
309312
310313
......
332335
333336
334337
335
338
336339
337340
338341
339342
340343
341344
342
345
343346
344347
345348
......
357360
358361
359362
360
361
362
363
363364
364365
365366
......
384385
385386
386387
387
388
388389
389
390
390391
391
392
392393
393
394
394395
395396
396397
397
398
398399
399
400
400401
401
402
402
403
403404
404405
405406
......
410411
411412
412413
413
414
414415
415
416
416417
417
418
418419
419
420
420421
421422
422423
423
424
424425
425
426
426427
427428
428429
......
431432
432433
433434
434
435
435
436
436437
437438
438
439
439440
440441
441442
......
455456
456457
457458
458
459
459460
460
461
461462
462463
463464
......
465466
466467
467468
468
469
469470
470471
471472
......
474475
475476
476477
478
479
477480
478481
479482
......
488491
489492
490493
491
494
492495
493496
494497
......
500503
501504
502505
503
506
504507
505508
506509
......
510513
511514
512515
513
516
514517
515518
516519
......
527530
528531
529532
530
533
531534
532535
533536
......
538541
539542
540543
541
542
544
545
543546
544547
545548
546549
547
550
548551
549552
550553
551
554
552555
553556
554557
......
564567
565568
566569
570
567571
568572
569573
......
587591
588592
589593
590
591594
592595
593596
......
597600
598601
599602
603
600604
601605
602606
603
607
604608
605609
606610
607611
608612
609
610
613
611614
612615
613616
614617
615
616
618
617619
618620
619621
......
627629
628630
629631
630
631
632
633
632634
633635
634636
......
657659
658660
659661
660
661662
662663
663664
......
671672
672673
673674
674
675
675676
676677
677678
......
719720
720721
721722
723
724
722725
723726
724727
725728
726729
727
728
729
730
731
732
733
734
735
736
737
738
739
740730
741
742731
743732
744733
......
787776
788777
789778
779
790780
791781
792782
......
806796
807797
808798
809
810799
811800
812801
......
828817
829818
830819
831
820
832821
833822
834823
835824
836825
837
826
838827
839828
840829
841830
842831
843
832
844833
845834
846835
......
853842
854843
855844
856
845
857846
858
847
859848
860849
861850
......
867856
868857
869858
870
859
871860
872861
873862
......
914903
915904
916905
917
906
918907
919908
920909
921
910
922911
923912
924
913
925914
926915
927916
......
938927
939928
940929
930
931
932
941933
942934
943935
944936
945
946937
947
938
948939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
949955
950956
951957
......
10051011
10061012
10071013
1008
1014
10091015
10101016
10111017
......
10381044
10391045
10401046
1041
1047
10421048
10431049
10441050
......
10541060
10551061
10561062
1057
1063
10581064
10591065
10601066
10611067
1062
1068
10631069
10641070
1065
1071
10661072
1067
1073
10681074
10691075
10701076
10711077
1072
1078
10731079
10741080
10751081
10761082
10771083
10781084
1079
1085
10801086
10811087
10821088
......
10901096
10911097
10921098
1093
1099
10941100
10951101
10961102
#define DBGPAUSE()
#endif
static inline voidrebase_location(UInt32* location, char* base, int type);
static inline voidbind_location(UInt32* location, char* value, UInt32 addend, int type);
// NOTE: Global so that modules can link with this
static UInt64 textAddress = 0;
static UInt64 textSection = 0;
{
// Start any modules that were compiled in first.
start_built_in_modules();
int retVal = 0;
void (*module_start)(void) = NULL;
extern char symbols_start __asm("section$start$__DATA$__Symbols");
char* module_data = &symbols_start;
// Intialize module system
if(module_data)
{
// Module system was compiled in (Symbols.dylib addr known)
module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);
if(module_start && module_start != (void*)0xFFFFFFFF)
{
// Notify the system that it was laoded
{
// The module does not have a valid start function
printf("Unable to start %s at 0x%x\n", SYMBOLS_MODULE, module_data); pause();
}
}
}
return retVal;
}
{
char* tmp = malloc(strlen(name) + 1);
strcpy(tmp, name);
if(!load_module(tmp))
{
// failed to load
// free(tmp);
}
}
else
else
{
DBG("Ignoring %s\n", name);
}
DBG("WARNING: Unable to locate module %s\n", modString); DBGPAUSE();
return 0;
}
unsigned int moduleSize = file_size(fh);
if(moduleSize == 0)
DBG("WARNING: The module %s has a file size of %d, the module will not be loaded.\n", modString, moduleSize);
return 0;
}
char* module_base = (char*) malloc(moduleSize);
if (moduleSize && read(fh, module_base, moduleSize) == moduleSize)
{
entry = malloc(sizeof(symbolList_t));
entry->next = moduleSymbols;
moduleSymbols = entry;
entry->addr = (UInt32)addr;
entry->symbol = symbol;
if(!is64 && strcmp(symbol, "start") == 0)
{
return addr;
if(!name) name = "Unknown";
if(!author) author = "Unknown";
if(!description) description = "";
new_entry->name = name;
new_entry->author = author;
new_entry->description = description;
new_entry->author = author;
new_entry->description = description;
new_entry->version = version;
new_entry->compat = compat;
msglog("Module '%s' by '%s' Loaded.\n", name, author);
msglog("\tDescription: %s\n", description);
msglog("\tVersion: %d\n", version); // todo: sperate to major.minor.bugfix
msglog("\tCompat: %d\n", compat); // todo: ^^^ major.minor.bugfix
new_entry->compat = compat;
msglog("Module '%s' by '%s' Loaded.\n", name, author);
msglog("\tDescription: %s\n", description);
msglog("\tVersion: %d\n", version); // todo: sperate to major.minor.bugfix
msglog("\tCompat: %d\n", compat); // todo: ^^^ major.minor.bugfix
}
int is_module_loaded(const char* name)
printf("Unable to locate symbol %s\n", name);
getchar();
#endif
if(strcmp(name, VOID_SYMBOL) == 0) return 0xFFFFFFFF;
// In the event that a symbol does not exist
// Return a pointer to a void function.
/*
* Parse through a macho module. The module will be rebased and binded
* as specified in the macho header. If the module is sucessfuly laoded
* as specified in the macho header. If the module is successfully loaded
* the module iinit address will be returned.
* NOTE; all dependecies will be loaded before this module is started
* NOTE: If the module is unable to load ot completeion, the modules
struct symtab_command* symtabCommand = NULL;
struct segment_command *segCommand = NULL;
struct segment_command_64 *segCommand64 = NULL;
//struct dysymtab_command* dysymtabCommand = NULL;
UInt32 binaryIndex = 0;
UInt16 cmd = 0;
textSection = 0;
textAddress = 0;// reinitialize text location in case it doesn't exist;
// Parse through the load commands
if(((struct mach_header*)binary)->magic == MH_MAGIC)
{
verbose("Invalid mach magic 0x%X\n", ((struct mach_header*)binary)->magic);
return NULL;
}
/*if(((struct mach_header*)binary)->filetype != MH_DYLIB)
{
printf("Module is not a dylib. Unable to load.\n");
case LC_SEGMENT: // 32bit macho
{
segCommand = binary + binaryIndex;
UInt32 sectionIndex;
sectionIndex = sizeof(struct segment_command);
struct section *sect;
while(sectionIndex < segCommand->cmdsize)
{
sect = binary + binaryIndex + sectionIndex;
sectionIndex += sizeof(struct section);
if(section_handler) section_handler(sect->sectname, segCommand->segname, (void*)sect, sect->offset, sect->addr);
if((strcmp("__TEXT", segCommand->segname) == 0) && (strcmp("__text", sect->sectname) == 0))
if((strcmp("__TEXT", segCommand->segname) == 0) && (strcmp("__text", sect->sectname) == 0))
{
// __TEXT,__text found, save the offset and address for when looking for the calls.
textSection = sect->offset;
break;
case LC_SEGMENT_64:// 64bit macho's
{
segCommand64 = binary + binaryIndex;
segCommand64 = binary + binaryIndex;
UInt32 sectionIndex;
sectionIndex = sizeof(struct segment_command_64);
struct section_64 *sect;
while(sectionIndex < segCommand64->cmdsize)
{
sect = binary + binaryIndex + sectionIndex;
sectionIndex += sizeof(struct section_64);
if(section_handler) section_handler(sect->sectname, segCommand64->segname, (void*)sect, sect->offset, sect->addr);
if((strcmp("__TEXT", segCommand64->segname) == 0) && (strcmp("__text", sect->sectname) == 0))
textSection = sect->offset;
textAddress = sect->addr;
}
}
}
}
}
break;
case LC_LOAD_DYLIB:
case LC_LOAD_WEAK_DYLIB ^ LC_REQ_DYLD:
// Required modules
free(name);
}
}
break;
case LC_ID_DYLIB:
//dylibCommand = binary + binaryIndex;
/*moduleName =binary + binaryIndex + ((UInt32)*((UInt32*)&dylibCommand->dylib.name));
moduleCompat =dylibCommand->dylib.compatibility_version;
*/
break;
case LC_DYLD_INFO:
//case LC_DYLD_INFO_ONLY:// compressed info, 10.6+ macho files, already handeled
// Bind and rebase info is stored here
case LC_DYSYMTAB:
case LC_UUID:
break;
case LC_UNIXTHREAD:
break;
// bind_macho uses the symbols, if the textAdd does not exist (Symbols.dylib, no code), addresses are static and not relative
module_start = (void*)handle_symtable((UInt32)binary, symtabCommand, symbol_handler, is64);
if(dyldInfoCommand)
{
// Rebase the module before binding it.
}
return module_start;
}
/*
unsigned int handle_symtable(UInt32 base, struct symtab_command* symtabCommand, long long(*symbol_handler)(char*, long long, char), char is64)
{
unsigned int module_start= 0xFFFFFFFF;
unsigned int module_start= 0xFFFFFFFF;
UInt32 symbolIndex= 0;
char* symbolString= base + (char*)symtabCommand->stroff;
// Module start located. Start is an alias so don't register it
module_start = textAddress ? base + symbolEntry->n_value : symbolEntry->n_value;
}
symbolEntry++;
symbolIndex++;// TODO remove
}
// NOTE First entry is *not* correct, but we can ignore it (i'm getting radar:// right now, verify later)
while(symbolIndex < symtabCommand->nsyms)
{
// If the symbol is exported by this module
if(symbolEntry->n_value &&
symbol_handler(symbolString + symbolEntry->n_un.n_strx, textAddress ? (long long)base + symbolEntry->n_value : symbolEntry->n_value, is64) != 0xFFFFFFFF)
{
// Module start located. Start is an alias so don't register it
module_start = textAddress ? base + symbolEntry->n_value : symbolEntry->n_value;
}
symbolEntry++;
symbolIndex++;// TODO remove
}
UInt8 immediate = 0;
UInt8 opcode = 0;
UInt8 type = 0;
UInt32 segmentAddress = 0;
opcode = 0;
type = 0;
segmentAddress = 0;
default:
break;
case REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
// Locate address to begin rebasing
segmentAddress = 0;
struct segment_command* segCommand = NULL; // NOTE: 32bit only
unsigned int binIndex = 0;
index = 0;
do
{
segCommand = base + sizeof(struct mach_header) + binIndex;
binIndex += segCommand->cmdsize;
index++;
}
while(index <= immediate);
segmentAddress = segCommand->fileoff;
tmp = 0;
segmentAddress += tmp;
break;
case REBASE_OPCODE_ADD_ADDR_ULEB:
// Add value to rebase address
tmp = 0;
}
break;
case REBASE_OPCODE_DO_REBASE_ULEB_TIMES:
tmp = 0;
bits = 0;
index = 0;
for (index = 0; index < tmp; ++index) {
//DBG("\tRebasing 0x%X\n", segmentAddress);
rebase_location(base + segmentAddress, (char*)base, type);
rebase_location(base + segmentAddress, (char*)base, type);
segmentAddress += sizeof(void*);
}
break;
segmentAddress += tmp2 + sizeof(void*);
}
break;
default:
break;
}
i++;
}
}
inline void rebase_location(UInt32* location, char* base, int type)
{
switch(type)
{
case REBASE_TYPE_POINTER:
case REBASE_TYPE_TEXT_ABSOLUTE32:
*location += (UInt32)base;
break;
default:
break;
}
}
UInt32 read_uleb(UInt8* bind_stream, unsigned int* i)
{
// Read in offset
// Temperary variables
UInt32 tmp = 0;
UInt32 tmp2 = 0;
UInt32 index = 0;
unsigned int i = 0;
addend = 0;
libraryOrdinal = 0;
symbolAddr = 0xFFFFFFFF;
default:
break;
case BIND_OPCODE_SET_DYLIB_ORDINAL_IMM:
symbolAddr = lookup_all_symbols(symbolName);
break;
case BIND_OPCODE_SET_TYPE_IMM:
type = immediate;
break;
case BIND_OPCODE_SET_ADDEND_SLEB:
addend = read_uleb(bind_stream, &i);
addend = read_uleb(bind_stream, &i);
if(!(bind_stream[i-1] & 0x40)) addend *= -1;
break;
case BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
segmentAddress = 0;
// Locate address
struct segment_command* segCommand = NULL;// NOTE: 32bit only
index++;
}
while(index <= immediate);
segmentAddress = segCommand->fileoff;
segmentAddress += read_uleb(bind_stream, &i);
break;
if(symbolAddr != 0xFFFFFFFF)
{
address = segmentAddress + (UInt32)base;
bind_location((UInt32*)address, (char*)symbolAddr, addend, type);
}
else
}
segmentAddress += (immediate * sizeof(void*)) + sizeof(void*);
break;
case BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB:
tmp = read_uleb(bind_stream, &i);
tmp = read_uleb(bind_stream, &i);
tmp2 = read_uleb(bind_stream, &i);
if(symbolAddr != 0xFFFFFFFF)
{
for(index = 0; index < tmp; index++)
getchar();
}
break;
default:
break;
}
i++;
}
}
inline void bind_location(UInt32* location, char* value, UInt32 addend, int type)
static inline void rebase_location(UInt32* location, char* base, int type)
{
switch(type)
{
case REBASE_TYPE_POINTER:
case REBASE_TYPE_TEXT_ABSOLUTE32:
*location += (UInt32)base;
break;
default:
break;
}
}
static inline void bind_location(UInt32* location, char* value, UInt32 addend, int type)
{
// do actual update
char* newValue = value + addend;
{
DBG("Attempting to execute hook '%s'\n", name); DBGPAUSE();
moduleHook_t* hook = hook_exists(name);
if(hook)
{
// Loop through all callbacks for this module
*NOTE: the hooks take four void* arguments.
*/
void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*))
{
{
DBG("Adding callback for '%s' hook.\n", name); DBGPAUSE();
moduleHook_t* hook = hook_exists(name);
else
{
// create new hook
moduleHook_t* newHook = malloc(sizeof(moduleHook_t));
moduleHook_t* newHook = malloc(sizeof(moduleHook_t));
newHook->name = name;
newHook->callbacks = malloc(sizeof(callbackList_t));
newHook->callbacks->callback = callback;
newHook->callbacks->next = NULL;
newHook->next = moduleCallbacks;
moduleCallbacks = newHook;
}
#if CONFIG_MODULE_DEBUG
//print_hook_list();
//getchar();
#endif
}
moduleHook_t* hook_exists(const char* name)
{
moduleHook_t* hooks = moduleCallbacks;
// look for a hook. If it exists, return the moduleHook_t*,
// If not, return NULL.
while(hooks)
}
//DBG("Hook %s does not exist\n", name);
return NULL;
}
#if CONFIG_MODULE_DEBUG
trunk/i386/boot2/modules.h
3131
3232
3333
34
3534
3635
3736
......
4847
4948
5049
51
52
50
51
5352
5453
5554
......
9594
9695
9796
98
9997
100
10198
10299
103
104
105100
106101
107102
......
119114
120115
121116
122
117
struct symbolList_t* next;
} symbolList_t;
typedef struct callbackList_t
{
void(*callback)(void*, void*, void*, void*);
typedef struct modulesList_t
{
const char*name;
const char* author;
const char* description;
const char* author;
const char* description;
UInt32version;
UInt32compat;
struct modulesList_t* next;
long long(*symbol_handler)(char*, long long, char),
char is64);
voidrebase_macho(void* base, char* rebase_stream, UInt32 size);
inline voidrebase_location(UInt32* location, char* base, int type);
voidbind_macho(void* base, UInt8* bind_stream, UInt32 size);
inline voidbind_location(UInt32* location, char* value, UInt32 addend, int type);
/********************************************************************************/
/*Module Interface*/
/********************************************************************************/
/********************************************************************************/
void dyld_stub_binder();
#endif /* __BOOT_MODULES_H */
#endif /* __BOOT_MODULES_H */
trunk/i386/modules/HDAEnabler/Makefile
11
2
2
33
44
55
MODULE_NAME = HDAEnabler
MODULE_AUTHOR = "ErmaC"
MODULE_AUTHOR = ErmaC
MODULE_DESCRIPTION = This module provides a remplacement for the DSDT edits like HDEF/HDAU
MODULE_VERSION = "1.0.0"
MODULE_COMPAT_VERSION = "1.0.0"
trunk/i386/modules/KernelPatcher/Cconfig
33
44
55
6
7
6
7
88
9
9
1010
#
config KERNELPATCHER_MODULE
bool "KernelPatcher Module"
default y
bool "Kernel Patcher Module"
default y
---help---
Say Y here if you want to enable to use of this module.
Say Y here if you want to enable the use of this module.
trunk/i386/modules/Cconfig
1111
1212
1313
14
1415
1516
1617
source "i386/modules/Keylayout/Cconfig"
source "i386/modules/ACPIcodec/Cconfig"
source "i386/modules/KernelPatcher/Cconfig"
#source "i386/modules/KextPatcher/Cconfig"
source "i386/modules/FileNVRAM/Cconfig"
#source "i386/modules/HDAEnabler/Cconfig"
endmenu
trunk/i386/modules/Makefile
4545
4646
4747
48
49
50
51
4852
4953
5054
SUBDIRS += FileNVRAM
endif
#ifdef CONFIG_KEXTPATCHER_MODULE
#SUBDIRS += KextPatcher
#endif
#ifdef CONFIG_HDAENABLER_MODULE
#SUBDIRS += HDAEnabler
#endif

Archive Download the corresponding diff file

Revision: 2266