Index: trunk/i386/libsaio/spd.c =================================================================== --- trunk/i386/libsaio/spd.c (revision 2265) +++ trunk/i386/libsaio/spd.c (revision 2266) @@ -296,7 +296,7 @@ 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; Index: trunk/i386/libsaio/gma.c =================================================================== --- trunk/i386/libsaio/gma.c (revision 2265) +++ trunk/i386/libsaio/gma.c (revision 2266) @@ -111,6 +111,7 @@ { 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 Index: trunk/i386/libsaio/nvidia.c =================================================================== --- trunk/i386/libsaio/nvidia.c (revision 2265) +++ trunk/i386/libsaio/nvidia.c (revision 2266) @@ -1396,6 +1396,7 @@ { 0x10DE11A1, 0x15587102, "Clevo N13E-GR" }, { 0x10DE11C0, 0x10DE0995, "Inno3D GeForce GTX660" }, + { 0x10DE11C0, 0x1458354E, "GV-N660OC-2GD" }, { 0x10DE11C6, 0x1043842A, "GTX650TI-1GD5" }, // 1200 - 12FF @@ -2146,7 +2147,10 @@ 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 *************************/ Index: trunk/i386/libsaio/cpu.c =================================================================== --- trunk/i386/libsaio/cpu.c (revision 2265) +++ trunk/i386/libsaio/cpu.c (revision 2266) @@ -57,38 +57,39 @@ // 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; } /* @@ -121,16 +122,22 @@ 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) @@ -146,7 +153,9 @@ * Also unlike Linux, our compiler can do 64-bit integer arithmetic. */ if (tscDelta > (1ULL<<32)) + { retval = 0; + } else { retval = tscDelta * 1000 / 30; @@ -187,23 +196,31 @@ 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; @@ -240,17 +257,21 @@ 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]); } @@ -258,7 +279,8 @@ { 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]); @@ -300,7 +322,8 @@ /* 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; /* @@ -313,13 +336,18 @@ 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. @@ -329,32 +357,41 @@ } /* 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; } @@ -367,9 +404,11 @@ 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 || @@ -394,7 +433,8 @@ 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 @@ -404,42 +444,63 @@ 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); } } @@ -451,10 +512,12 @@ 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)*/ @@ -465,21 +528,30 @@ { /* 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" : ""); @@ -487,7 +559,8 @@ } } /* Mobile CPU */ - if (rdmsr64(MSR_IA32_PLATFORM_ID) & (1<<28)) { + if (rdmsr64(MSR_IA32_PLATFORM_ID) & (1<<28)) + { p->CPU.Features |= CPU_FEATURE_MOBILE; } } @@ -536,18 +609,31 @@ { 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); } } @@ -557,7 +643,9 @@ { fsbFrequency = ((tscFrequency * currdiv) / currcoef); DBG("%d.%d\n", currcoef / currdiv, ((currcoef % currdiv) * 100) / currdiv); - } else { + } + else + { fsbFrequency = (tscFrequency / currcoef); DBG("%d\n", currcoef); } @@ -566,7 +654,8 @@ } #if 0 - if (!fsbFrequency) { + if (!fsbFrequency) + { fsbFrequency = (DEFAULT_FSB * 1000); cpuFrequency = tscFrequency; DBG("0 ! using the default value for FSB !\n"); Index: trunk/i386/libsaio/cpu.h =================================================================== --- trunk/i386/libsaio/cpu.h (revision 2265) +++ trunk/i386/libsaio/cpu.h (revision 2266) @@ -179,7 +179,7 @@ ++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; } Index: trunk/i386/boot2/modules.c =================================================================== --- trunk/i386/boot2/modules.c (revision 2265) +++ trunk/i386/boot2/modules.c (revision 2266) @@ -22,6 +22,9 @@ #define DBGPAUSE() #endif +static inline void rebase_location(UInt32* location, char* base, int type); +static inline void bind_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; @@ -42,20 +45,20 @@ { // 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 @@ -70,7 +73,7 @@ { // 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; } @@ -108,14 +111,14 @@ { 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); } @@ -147,7 +150,6 @@ DBG("WARNING: Unable to locate module %s\n", modString); DBGPAUSE(); return 0; } - unsigned int moduleSize = file_size(fh); if(moduleSize == 0) @@ -155,6 +157,7 @@ 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) { @@ -204,10 +207,10 @@ 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; @@ -232,17 +235,17 @@ 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) @@ -291,7 +294,7 @@ 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. @@ -304,7 +307,7 @@ /* * 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 @@ -332,14 +335,14 @@ 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) { @@ -357,9 +360,7 @@ 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"); @@ -384,22 +385,22 @@ 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; @@ -410,19 +411,19 @@ 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)) @@ -431,11 +432,11 @@ textSection = sect->offset; textAddress = sect->addr; } - } - } + } + } break; - + case LC_LOAD_DYLIB: case LC_LOAD_WEAK_DYLIB ^ LC_REQ_DYLD: // Required modules @@ -455,9 +456,9 @@ free(name); } } - + break; - + case LC_ID_DYLIB: //dylibCommand = binary + binaryIndex; /*moduleName = binary + binaryIndex + ((UInt32)*((UInt32*)&dylibCommand->dylib.name)); @@ -465,7 +466,7 @@ 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 @@ -474,6 +475,8 @@ case LC_DYSYMTAB: case LC_UUID: + break; + case LC_UNIXTHREAD: break; @@ -488,7 +491,7 @@ // 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. @@ -500,7 +503,7 @@ } return module_start; - + } /* @@ -510,7 +513,7 @@ 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; @@ -527,7 +530,7 @@ // 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 } @@ -538,17 +541,17 @@ // 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 } @@ -564,6 +567,7 @@ UInt8 immediate = 0; UInt8 opcode = 0; UInt8 type = 0; + UInt32 segmentAddress = 0; @@ -587,7 +591,6 @@ opcode = 0; type = 0; segmentAddress = 0; - default: break; @@ -597,23 +600,22 @@ 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; @@ -627,8 +629,8 @@ segmentAddress += tmp; break; - - + + case REBASE_OPCODE_ADD_ADDR_ULEB: // Add value to rebase address tmp = 0; @@ -657,7 +659,6 @@ } break; - case REBASE_OPCODE_DO_REBASE_ULEB_TIMES: tmp = 0; bits = 0; @@ -671,7 +672,7 @@ 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; @@ -719,26 +720,14 @@ 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 @@ -787,6 +776,7 @@ // Temperary variables UInt32 tmp = 0; UInt32 tmp2 = 0; + UInt32 index = 0; unsigned int i = 0; @@ -806,7 +796,6 @@ addend = 0; libraryOrdinal = 0; symbolAddr = 0xFFFFFFFF; - default: break; case BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: @@ -828,19 +817,19 @@ 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 @@ -853,9 +842,9 @@ index++; } while(index <= immediate); - + segmentAddress = segCommand->fileoff; - + segmentAddress += read_uleb(bind_stream, &i); break; @@ -867,7 +856,7 @@ if(symbolAddr != 0xFFFFFFFF) { address = segmentAddress + (UInt32)base; - + bind_location((UInt32*)address, (char*)symbolAddr, addend, type); } else @@ -914,14 +903,14 @@ } 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++) @@ -938,14 +927,31 @@ 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; @@ -1005,7 +1011,7 @@ { DBG("Attempting to execute hook '%s'\n", name); DBGPAUSE(); moduleHook_t* hook = hook_exists(name); - + if(hook) { // Loop through all callbacks for this module @@ -1038,7 +1044,7 @@ * 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); @@ -1054,29 +1060,29 @@ 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) @@ -1090,7 +1096,7 @@ } //DBG("Hook %s does not exist\n", name); return NULL; - + } #if CONFIG_MODULE_DEBUG Index: trunk/i386/boot2/modules.h =================================================================== --- trunk/i386/boot2/modules.h (revision 2265) +++ trunk/i386/boot2/modules.h (revision 2266) @@ -31,7 +31,6 @@ struct symbolList_t* next; } symbolList_t; - typedef struct callbackList_t { void(*callback)(void*, void*, void*, void*); @@ -48,8 +47,8 @@ typedef struct modulesList_t { const char* name; - const char* author; - const char* description; + const char* author; + const char* description; UInt32 version; UInt32 compat; struct modulesList_t* next; @@ -95,13 +94,9 @@ long long(*symbol_handler)(char*, long long, char), char is64); void rebase_macho(void* base, char* rebase_stream, UInt32 size); -inline void rebase_location(UInt32* location, char* base, int type); void bind_macho(void* base, UInt8* bind_stream, UInt32 size); -inline void bind_location(UInt32* location, char* value, UInt32 addend, int type); - - /********************************************************************************/ /* Module Interface */ /********************************************************************************/ @@ -119,4 +114,4 @@ /********************************************************************************/ void dyld_stub_binder(); -#endif /* __BOOT_MODULES_H */ \ No newline at end of file +#endif /* __BOOT_MODULES_H */ Index: trunk/i386/modules/HDAEnabler/Makefile =================================================================== --- trunk/i386/modules/HDAEnabler/Makefile (revision 2265) +++ trunk/i386/modules/HDAEnabler/Makefile (revision 2266) @@ -1,5 +1,5 @@ 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" Index: trunk/i386/modules/KernelPatcher/Cconfig =================================================================== --- trunk/i386/modules/KernelPatcher/Cconfig (revision 2265) +++ trunk/i386/modules/KernelPatcher/Cconfig (revision 2266) @@ -3,8 +3,8 @@ # 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. Index: trunk/i386/modules/Cconfig =================================================================== --- trunk/i386/modules/Cconfig (revision 2265) +++ trunk/i386/modules/Cconfig (revision 2266) @@ -11,6 +11,7 @@ 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 Index: trunk/i386/modules/Makefile =================================================================== --- trunk/i386/modules/Makefile (revision 2265) +++ trunk/i386/modules/Makefile (revision 2266) @@ -45,6 +45,10 @@ SUBDIRS += FileNVRAM endif +#ifdef CONFIG_KEXTPATCHER_MODULE +#SUBDIRS += KextPatcher +#endif + #ifdef CONFIG_HDAENABLER_MODULE #SUBDIRS += HDAEnabler #endif