Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -urN xnu-1699.26.8.orig/bsd/kern/kern_mib.c xnu-1699.26.8.snadge/bsd/kern/kern_mib.c
- --- xnu-1699.26.8.orig/bsd/kern/kern_mib.c 2012-05-11 01:24:40.000000000 +1000
- +++ xnu-1699.26.8.snadge/bsd/kern/kern_mib.c 2012-05-22 23:09:23.000000000 +1000
- @@ -416,6 +416,7 @@
- int supplementalsse3_flag = -1;
- int aes_flag = -1;
- int avx1_0_flag = -1;
- +int sse4a_flag = -1;
- SYSCTL_INT(_hw_optional, OID_AUTO, mmx, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &mmx_flag, 0, "");
- SYSCTL_INT(_hw_optional, OID_AUTO, sse, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse_flag, 0, "");
- @@ -424,6 +425,7 @@
- SYSCTL_INT(_hw_optional, OID_AUTO, supplementalsse3, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &supplementalsse3_flag, 0, "");
- SYSCTL_INT(_hw_optional, OID_AUTO, sse4_1, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse4_1_flag, 0, "");
- SYSCTL_INT(_hw_optional, OID_AUTO, sse4_2, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse4_2_flag, 0, "");
- +SYSCTL_INT(_hw_optional, OID_AUTO, sse4a, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse4a_flag, 0, "");
- /* "x86_64" is actually a preprocessor symbol on the x86_64 kernel, so we have to hack this */
- #undef x86_64
- SYSCTL_INT(_hw_optional, OID_AUTO, x86_64, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &x86_64_flag, 0, "");
- @@ -499,6 +501,7 @@
- x86_64_flag = is_capability_set(k64Bit);
- aes_flag = is_capability_set(kHasAES);
- avx1_0_flag = is_capability_set(kHasAVX1_0);
- + sse4a_flag = is_capability_set(kHasSSE4A);
- /* hw.cpufamily */
- cpufamily = cpuid_cpufamily();
- diff -urN xnu-1699.26.8.orig/iokit/IOKit/IOCatalogue.h xnu-1699.26.8.snadge/iokit/IOKit/IOCatalogue.h
- --- xnu-1699.26.8.orig/iokit/IOKit/IOCatalogue.h 2010-07-31 10:14:51.000000000 +1000
- +++ xnu-1699.26.8.snadge/iokit/IOKit/IOCatalogue.h 2012-05-22 23:09:23.000000000 +1000
- @@ -279,4 +279,15 @@
- extern const OSSymbol * gIOProbeScoreKey;
- extern IOCatalogue * gIOCatalogue;
- +extern "C" {
- + /* kaitek: see ::addDrivers() and StartIOKit() for more information about the built-in kernel
- + * kext blacklist. */
- + typedef struct {
- + const char *name;
- + uint32_t hits;
- + } blacklist_mod_t;
- + extern boolean_t blacklistEnabled;
- + extern blacklist_mod_t blacklistMods[];
- +};
- +
- #endif /* ! _IOKIT_IOCATALOGUE_H */
- diff -urN xnu-1699.26.8.orig/iokit/Kernel/IOCatalogue.cpp xnu-1699.26.8.snadge/iokit/Kernel/IOCatalogue.cpp
- --- xnu-1699.26.8.orig/iokit/Kernel/IOCatalogue.cpp 2011-04-07 08:45:40.000000000 +1000
- +++ xnu-1699.26.8.snadge/iokit/Kernel/IOCatalogue.cpp 2012-05-22 23:09:23.000000000 +1000
- @@ -75,6 +75,31 @@
- #pragma mark Utility functions
- #endif
- /*********************************************************************
- + *********************************************************************/
- +static void
- +UniqueProperties(OSDictionary * dict)
- +{
- + OSString * data;
- +
- + data = OSDynamicCast(OSString, dict->getObject(gIOClassKey));
- + if (data) {
- + const OSSymbol *classSymbol = OSSymbol::withString(data);
- +
- + dict->setObject( gIOClassKey, (OSSymbol *) classSymbol);
- + classSymbol->release();
- + }
- +
- + data = OSDynamicCast(OSString, dict->getObject(gIOMatchCategoryKey));
- + if (data) {
- + const OSSymbol *classSymbol = OSSymbol::withString(data);
- +
- + dict->setObject(gIOMatchCategoryKey, (OSSymbol *) classSymbol);
- + classSymbol->release();
- + }
- + return;
- +}
- +
- +/*********************************************************************
- * Add a new personality to the set if it has a unique IOResourceMatchKey value.
- * XXX -- svail: This should be optimized.
- * esb - There doesn't seem like any reason to do this - it causes problems
- @@ -151,7 +176,11 @@
- kernelTables->reset();
- while( (dict = (OSDictionary *) kernelTables->getNextObject())) {
- +#if 0
- OSKext::uniquePersonalityProperties(dict);
- +#else
- + UniqueProperties(dict);
- +#endif
- if( 0 == dict->getObject( gIOClassKey ))
- IOLog("Missing or bad \"%s\" key\n",
- gIOClassKey->getCStringNoCopy());
- @@ -281,7 +310,11 @@
- OSDictionary * dict;
- OSOrderedSet * set;
- +#if 0
- OSKext::uniquePersonalityProperties(matching);
- +#else
- + UniqueProperties(matching);
- +#endif
- set = OSOrderedSet::withCapacity( 1, IOServiceOrdering,
- (void *)gIOProbeScoreKey );
- @@ -320,8 +353,16 @@
- bool result = false;
- OSCollectionIterator * iter = NULL; // must release
- OSOrderedSet * set = NULL; // must release
- +#if 0
- OSObject * object = NULL; // do not release
- +#else
- + OSDictionary * dict = NULL; // do not release
- +#endif
- OSArray * persons = NULL; // do not release
- +#if 1
- + OSString * moduleName;
- + bool ret;
- +#endif
- persons = OSDynamicCast(OSArray, drivers);
- if (!persons) {
- @@ -344,10 +385,14 @@
- result = true;
- IOLockLock(lock);
- +#if 0
- while ( (object = iter->getNextObject()) ) {
- +#else
- + while ( (dict = (OSDictionary *) iter->getNextObject()) ) {
- +#endif
- // xxx Deleted OSBundleModuleDemand check; will handle in other ways for SL
- -
- +#if 0
- OSDictionary * personality = OSDynamicCast(OSDictionary, object);
- SInt count;
- @@ -376,8 +421,30 @@
- */
- if (personality->isEqualTo(driver)) {
- break;
- +#else
- + /* kaitek / qoopz: if the kext blacklist is enabled (which it is by default), then check
- + * if any of the personalities we are preparing for matching should be skipped. */
- + if (blacklistEnabled) {
- + OSString *modName = OSDynamicCast(OSString, dict->getObject(gIOModuleIdentifierKey));
- + const char *modNameStr = NULL;
- + if (modName)
- + modNameStr = modName->getCStringNoCopy();
- + if (modNameStr) {
- + boolean_t shouldMatch = TRUE;
- + for (uint32_t n = 0; blacklistMods[n].name; n++) {
- + if (strcmp(blacklistMods[n].name, modNameStr))
- + continue;
- + if (!blacklistMods[n].hits++)
- + printf("warning: skipping personalities in blacklisted kext %s\n",
- + modNameStr);
- + shouldMatch = FALSE;
- + }
- + if (!shouldMatch)
- + continue;
- +#endif // 0
- }
- }
- +#if 0
- if (count >= 0) {
- // its a dup
- continue;
- @@ -389,9 +456,55 @@
- }
- AddNewImports(set, personality);
- +#else
- + if ((moduleName = OSDynamicCast(OSString, dict->getObject("OSBundleModuleDemand")))) {
- + IOLockUnlock( lock );
- + ret = OSKext::loadKextWithIdentifier(moduleName->getCStringNoCopy(), false);
- + IOLockLock( lock );
- + ret = true;
- + } else {
- + SInt count;
- +
- + UniqueProperties(dict);
- +
- + // Add driver personality to catalogue.
- + count = array->getCount();
- + while (count--) {
- + OSDictionary * driver;
- +
- + // Be sure not to double up on personalities.
- + driver = (OSDictionary *)array->getObject(count);
- +
- + /* Unlike in other functions, this comparison must be exact!
- + * The catalogue must be able to contain personalities that
- + * are proper supersets of others.
- + * Do not compare just the properties present in one driver
- + * pesonality or the other.
- + */
- + if (dict->isEqualTo(driver)) {
- + break;
- + }
- + }
- + if (count >= 0) {
- + // its a dup
- + continue;
- + }
- +
- + result = array->setObject(dict);
- + if (!result) {
- + break;
- + }
- +
- + AddNewImports(set, dict);
- + };
- +#endif
- }
- // Start device matching.
- +#if 0
- if (result && doNubMatching && (set->getCount() > 0)) {
- +#else
- + if (doNubMatching && (set->getCount() > 0)) {
- +#endif
- IOService::catalogNewDrivers(set);
- generation++;
- }
- @@ -440,7 +553,11 @@
- return false;
- }
- +#if 0
- OSKext::uniquePersonalityProperties( matching );
- +#else
- + UniqueProperties( matching );
- +#endif
- IOLockLock(lock);
- kernelTables->reset();
- @@ -538,7 +655,12 @@
- startMatching(dict);
- dict->release();
- +#if 1
- + (void) OSKext::setDeferredLoadSucceeded();
- + (void) OSKext::considerRebuildOfPrelinkedKernel();
- +#else
- (void) OSKext::considerRebuildOfPrelinkedKernel(moduleName);
- +#endif
- }
- void IOCatalogue::moduleHasLoaded(const char * moduleName)
- @@ -573,7 +695,11 @@
- if ( !iter )
- return kIOReturnNoMemory;
- +#if 0
- OSKext::uniquePersonalityProperties( matching );
- +#else
- + UniqueProperties( matching );
- +#endif
- // terminate instances.
- do {
- @@ -769,6 +895,7 @@
- void IOCatalogue::reset(void)
- {
- +#if 0
- IOCatalogue::resetAndAddDrivers(/* no drivers; true reset */ NULL,
- /* doMatching */ false);
- return;
- @@ -946,6 +1073,7 @@
- if (errorString) errorString->release();
- return result;
- +#endif // 0
- }
- bool IOCatalogue::serialize(OSSerialize * s) const
- diff -urN xnu-1699.26.8.orig/iokit/Kernel/IOStartIOKit.cpp xnu-1699.26.8.snadge/iokit/Kernel/IOStartIOKit.cpp
- --- xnu-1699.26.8.orig/iokit/Kernel/IOStartIOKit.cpp 2011-05-11 06:33:57.000000000 +1000
- +++ xnu-1699.26.8.snadge/iokit/Kernel/IOStartIOKit.cpp 2012-05-22 23:09:23.000000000 +1000
- @@ -91,6 +91,16 @@
- IORegistryEntry * root;
- OSObject * obj;
- + uint32_t bootArg;
- + /* kaitek: todo: implement some kind of mechanism whereby the user can specify a
- + * custom list of kexts to be blacklisted. perhaps categories with the current
- + * list designated "default" and additional categories like "gfx", etc. */
- +
- + if (PE_parse_boot_argn("blacklist", &bootArg, sizeof(&bootArg)) && !bootArg) {
- + blacklistEnabled = FALSE;
- + printf("warning: disabling kext blacklist\n");
- + }
- +
- root = IORegistryEntry::initialize();
- assert( root );
- IOService::initialize();
- @@ -120,6 +130,22 @@
- // From <osfmk/kern/debug.c>
- extern int debug_mode;
- + /* kaitek / qoopz: blacklist of common kexts that are known to be problematic or undesirable
- + * for virtually all non-apple hardware. see notes in StartIOKit(). */
- +
- + boolean_t blacklistEnabled = TRUE;
- + blacklist_mod_t blacklistMods[] = {
- + { "com.apple.driver.AppleIntelMeromProfile", 0 },
- + { "com.apple.driver.AppleIntelNehalemProfile", 0 },
- + { "com.apple.driver.AppleIntelPenrynProfile", 0 },
- + { "com.apple.driver.AppleIntelYonahProfile", 0 },
- + { "com.apple.driver.AppleIntelCPUPowerManagement", 0 }, // must be added to use in 10.6.1+
- + { "com.apple.iokit.CHUDKernLib", 0 },
- + { "com.apple.iokit.CHUDProf", 0 },
- + { "com.apple.iokit.CHUDUtils", 0 },
- + { NULL, 0 }
- + };
- +
- /*****
- * Pointer into bootstrap KLD segment for functions never used past startup.
- */
- diff -urN xnu-1699.26.8.orig/iokit/Kernel/IOUserClient.cpp xnu-1699.26.8.snadge/iokit/Kernel/IOUserClient.cpp
- --- xnu-1699.26.8.orig/iokit/Kernel/IOUserClient.cpp 2011-07-22 04:52:15.000000000 +1000
- +++ xnu-1699.26.8.snadge/iokit/Kernel/IOUserClient.cpp 2012-05-22 23:09:23.000000000 +1000
- @@ -3965,7 +3965,11 @@
- array = OSDynamicCast(OSArray, obj);
- if (array) {
- +#if 0
- if ( !gIOCatalogue->resetAndAddDrivers(array,
- +#else
- + if ( !gIOCatalogue->addDrivers(array,
- +#endif
- flag == kIOCatalogResetDrivers) ) {
- kr = kIOReturnError;
- diff -urN xnu-1699.26.8.orig/libkern/c++/OSKext.cpp xnu-1699.26.8.snadge/libkern/c++/OSKext.cpp
- --- xnu-1699.26.8.orig/libkern/c++/OSKext.cpp 2012-05-11 01:24:45.000000000 +1000
- +++ xnu-1699.26.8.snadge/libkern/c++/OSKext.cpp 2012-05-22 23:09:23.000000000 +1000
- @@ -1863,7 +1863,9 @@
- const char * versionCString = NULL; // do not free
- const char * compatibleVersionCString = NULL; // do not free
- OSBoolean * scratchBool = NULL; // do not release
- +#if 0
- OSDictionary * scratchDict = NULL; // do not release
- +#endif
- if (infoDict) {
- panic("Attempt to set info dictionary on a kext "
- @@ -2004,11 +2006,13 @@
- /* Make sure common string values in personalities are uniqued to OSSymbols.
- */
- +#if 0
- scratchDict = OSDynamicCast(OSDictionary,
- getPropertyForHostArch(kIOKitPersonalitiesKey));
- if (scratchDict) {
- uniquePersonalityProperties(scratchDict);
- }
- +#endif
- result = true;
- @@ -2068,6 +2072,7 @@
- /*********************************************************************
- *********************************************************************/
- +#if 0
- static void
- uniqueStringPlistProperty(OSDictionary * dict, const char * key)
- {
- @@ -2091,9 +2096,11 @@
- return;
- }
- +#endif // 0
- /*********************************************************************
- *********************************************************************/
- +#if 0
- static void
- uniqueStringPlistProperty(OSDictionary * dict, const OSString * key)
- {
- @@ -2117,12 +2124,14 @@
- return;
- }
- +#endif // 0
- /*********************************************************************
- * Replace common personality property values with uniqued instances
- * to save on wired memory.
- *********************************************************************/
- /* static */
- +#if 0
- void
- OSKext::uniquePersonalityProperties(OSDictionary * personalityDict)
- {
- @@ -2154,6 +2163,7 @@
- return;
- }
- +#endif
- /*********************************************************************
- *********************************************************************/
- @@ -6097,7 +6107,11 @@
- sConsiderUnloadsPending = false;
- sConsiderUnloadsExecuted = true;
- +#if 0
- (void) OSKext::considerRebuildOfPrelinkedKernel(NULL);
- +#else
- + (void) OSKext::considerRebuildOfPrelinkedKernel();
- +#endif
- IORecursiveLockUnlock(sKextInnerLock);
- IORecursiveLockUnlock(sKextLock);
- @@ -6198,7 +6212,11 @@
- *********************************************************************/
- /* static */
- void
- +#if 0
- OSKext::considerRebuildOfPrelinkedKernel(OSString * moduleName)
- +#else
- +OSKext::considerRebuildOfPrelinkedKernel(void)
- +#endif
- {
- OSReturn checkResult = kOSReturnError;
- static bool requestedPrelink = false;
- @@ -6210,6 +6228,7 @@
- * interested in rebuilding the kernel cache if the kext we are loading
- * is not already in the original kernel cache. 9055303
- */
- +#if 0
- if (moduleName) {
- int count = sUnloadedPrelinkedKexts->getCount();
- int i;
- @@ -6232,6 +6251,7 @@
- }
- (void) OSKext::setDeferredLoadSucceeded();
- }
- +#endif // 0
- if (!sDeferredLoadSucceeded || !sConsiderUnloadsExecuted ||
- sSafeBoot || requestedPrelink)
- diff -urN xnu-1699.26.8.orig/libkern/libkern/c++/OSKext.h xnu-1699.26.8.snadge/libkern/libkern/c++/OSKext.h
- --- xnu-1699.26.8.orig/libkern/libkern/c++/OSKext.h 2011-04-07 08:45:40.000000000 +1000
- +++ xnu-1699.26.8.snadge/libkern/libkern/c++/OSKext.h 2012-05-22 23:09:23.000000000 +1000
- @@ -573,7 +573,11 @@
- static void flushNonloadedKexts(Boolean flushPrelinkedKexts);
- static void setKextdActive(Boolean active = true);
- static void setDeferredLoadSucceeded(Boolean succeeded = true);
- +#if 0
- static void considerRebuildOfPrelinkedKernel(OSString * moduleName);
- +#else
- + static void considerRebuildOfPrelinkedKernel(void);
- +#endif
- virtual bool setAutounloadEnabled(bool flag);
- @@ -597,7 +601,9 @@
- /* Converts common string-valued properties to OSSymbols for lower memory consumption.
- */
- +#if 0
- static void uniquePersonalityProperties(OSDictionary * personalityDict);
- +#endif
- virtual bool declaresExecutable(void); // might be missing
- virtual bool isInterface(void);
- diff -urN xnu-1699.26.8.orig/osfmk/conf/MASTER.i386 xnu-1699.26.8.snadge/osfmk/conf/MASTER.i386
- --- xnu-1699.26.8.orig/osfmk/conf/MASTER.i386 2011-05-11 08:52:53.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/conf/MASTER.i386 2012-05-23 15:16:16.000000000 +1000
- @@ -58,7 +58,8 @@
- options X86_64
- options DISPATCH_COUNTS
- options PAL_I386
- -options CONFIG_YONAH # 32-bit Yonah support # <config_yonah>
- +#options CONFIG_YONAH # 32-bit Yonah support # <config_yonah>
- +options CONFIG_LEGACY # Enable 32-bit legacy support
- #
- # Note: MAC/AUDIT options must be set in all the bsd/conf, osfmk/conf, and
- diff -urN xnu-1699.26.8.orig/osfmk/i386/AT386/model_dep.c xnu-1699.26.8.snadge/osfmk/i386/AT386/model_dep.c
- --- xnu-1699.26.8.orig/osfmk/i386/AT386/model_dep.c 2012-01-12 04:17:21.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/AT386/model_dep.c 2012-05-22 23:09:23.000000000 +1000
- @@ -119,6 +119,8 @@
- #include <mach-o/loader.h>
- #include <mach-o/nlist.h>
- +#include <chud/chud_xnu.h> // qoopz: chud kexts have cpuids, must remove them for AMD
- +
- #include <libkern/kernel_mach_header.h>
- #include <libkern/OSKextLibPrivate.h>
- @@ -752,9 +754,17 @@
- void
- halt_all_cpus(boolean_t reboot)
- {
- + /* ovof / paulicat: Disable all cores on shutdown to prevent the system hanging */
- + uint32_t ncpus, i;
- + ncpus = chudxnu_logical_cpu_count();
- + for (i = 0; i < ncpus; i++)
- + chudxnu_enable_cpu(i, FALSE);
- if (reboot) {
- printf("MACH Reboot\n");
- PEHaltRestart( kPERestartCPU );
- + asm volatile ("movb $0xfe, %al\n"
- + "outb %al, $0x64\n"
- + "hlt\n");
- } else {
- printf("CPU halted\n");
- PEHaltRestart( kPEHaltCPU );
- diff -urN xnu-1699.26.8.orig/osfmk/i386/commpage/commpage.c xnu-1699.26.8.snadge/osfmk/i386/commpage/commpage.c
- --- xnu-1699.26.8.orig/osfmk/i386/commpage/commpage.c 2012-03-06 10:27:50.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/commpage/commpage.c 2012-05-22 23:09:23.000000000 +1000
- @@ -207,6 +207,10 @@
- ml_cpu_get_info(&cpu_info);
- switch (cpu_info.vector_unit) {
- +#if 1
- + case 10:
- + bits |= kHasSSE4A;
- +#endif
- case 9:
- bits |= kHasAVX1_0;
- /* fall thru */
- diff -urN xnu-1699.26.8.orig/osfmk/i386/cpu_capabilities.h xnu-1699.26.8.snadge/osfmk/i386/cpu_capabilities.h
- --- xnu-1699.26.8.orig/osfmk/i386/cpu_capabilities.h 2011-05-03 08:29:48.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/cpu_capabilities.h 2012-05-22 23:09:23.000000000 +1000
- @@ -62,6 +62,11 @@
- #define kHasF16C 0x04000000
- #define kHasENFSTRG 0x08000000
- #define kNumCPUsShift 16 /* see _NumCPUs() below */
- +#if 1
- +#define kHasSSE4A 0x00000040
- +#define kHas_A3DNOW 0x80000000
- +#define kHas_A3DNOWEXT 0x40000000
- +#endif
- #ifndef __ASSEMBLER__
- #include <sys/cdefs.h>
- diff -urN xnu-1699.26.8.orig/osfmk/i386/cpu_data.h xnu-1699.26.8.snadge/osfmk/i386/cpu_data.h
- --- xnu-1699.26.8.orig/osfmk/i386/cpu_data.h 2011-05-30 05:29:00.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/cpu_data.h 2012-05-23 15:18:12.000000000 +1000
- @@ -317,7 +317,7 @@
- {
- CPU_DATA_GET(cpu_is64bit, boolean_t)
- }
- -#if CONFIG_YONAH
- +#if defined(CONFIG_YONAH) || defined(CONFIG_LEGACY)
- #define cpu_mode_is64bit() get_is64bit()
- #else
- #define cpu_mode_is64bit() TRUE
- diff -urN xnu-1699.26.8.orig/osfmk/i386/cpuid.c xnu-1699.26.8.snadge/osfmk/i386/cpuid.c
- --- xnu-1699.26.8.orig/osfmk/i386/cpuid.c 2012-05-11 01:24:47.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/cpuid.c 2012-05-23 23:49:20.000000000 +1000
- @@ -28,10 +28,16 @@
- /*
- * @OSF_COPYRIGHT@
- */
- +
- +#ifndef CPUID_C
- +#define CPUID_C 1
- +#endif
- +
- #include <platforms.h>
- #include <mach_kdb.h>
- #include <vm/vm_page.h>
- #include <pexpert/pexpert.h>
- +#include <kern/voodoo_assert.h>
- #include <i386/cpuid.h>
- #if MACH_KDB
- @@ -450,7 +456,12 @@
- info_p->cache_linesize = linesizes[L2U];
- else if (linesizes[L1D])
- info_p->cache_linesize = linesizes[L1D];
- +#if 0
- else panic("no linesize");
- +#else
- + else kprintf("no linesize");
- +#endif
- +
- DBG(" cache_linesize : %d\n", info_p->cache_linesize);
- /*
- @@ -502,6 +513,241 @@
- }
- static void
- +get_amd_cache_info(
- + i386_cpu_info_t* info_p,
- + uint32_t linesizes[],
- + cache_type_t type,
- + uint32_t* geometry_colors,
- + uint32_t n_cores)
- +{
- + uint32_t reg[4] = {0, 0, 0, 0};
- + uint32_t cache_level;
- + uint32_t cache_sharing;
- + uint32_t cache_linesize;
- + uint32_t cache_associativity;
- + uint32_t cache_size;
- + uint32_t cache_sets;
- + uint32_t cache_partitions;
- + uint32_t reg_to_use;
- + uint32_t colors;
- + uint32_t ncores;
- +
- + switch (type) {
- + case L1D:
- + cache_level = 1;
- + do_cpuid(0x80000005, reg);
- + reg_to_use = ecx;
- + break;
- + case L1I:
- + cache_level = 1;
- + do_cpuid(0x80000005, reg);
- + reg_to_use = edx;
- + break;
- + case L2U:
- + cache_level = 2;
- + do_cpuid(0x80000006, reg);
- + reg_to_use = ecx;
- + break;
- + case L3U:
- + cache_level = 3;
- + do_cpuid(0x80000006, reg);
- + reg_to_use = edx;
- + break;
- + case Lnone:
- + default:
- + return;
- + };
- +
- + /* Avoid div0 errors if we couldn't get the # of cores */
- + if (n_cores == 0)
- + ncores = 1;
- + else
- + ncores = n_cores;
- +
- + cache_size = bitfield32(reg[reg_to_use], 31, 16);
- +
- + if (cache_size == 0) {
- + /* Cache doesn't exist, set it as zero */
- + info_p->cache_size[type] = 0;
- + info_p->cache_sharing[type] = 0;
- + info_p->cache_partitions[type] = 0;
- + return;
- + }
- +
- + switch (cache_level) {
- + case 1:
- + /* L1 uses only bits 31 to 24 so we should shift right 8 bits
- + * This is in KB units, and is reported per-core.
- + */
- + cache_size = (cache_size >> 8) * 1024;
- + cache_sharing = 1;
- + break;
- + case 2:
- + /* L2 cache is in KB units, reported per-core */
- + cache_size *= 1024;
- + cache_sharing = 1;
- + break;
- + case 3:
- + /* L3 is in 512 KB units. This is reported by CPU as total, and
- + * we export it as per-core. */
- + cache_size = cache_size * 512 * 1024 / ncores;
- + cache_sharing = ncores;
- + break;
- + default:
- + BUG("invalid cache level");
- + return; /* not reached, silences optimizer */
- + };
- +
- + cache_linesize = bitfield32(reg[reg_to_use], 7, 0);
- + cache_partitions = bitfield32(reg[reg_to_use], 15, 8); // Needs review
- + cache_associativity = bitfield32(reg[reg_to_use], 23, 16);
- +
- + /* For L2/L3 caches, AMD uses an encoding for associativity.
- + * The formula is 2 ^ (assoc / 2)
- + */
- + if (cache_level > 1) {
- + //cache_associativity = 1ul << (cache_associativity / 2);
- + cache_associativity = (uint32_t)1ul << (cache_associativity / 2);
- + }
- +
- + info_p->cache_size[type] = cache_size;
- + info_p->cache_sharing[type] = cache_sharing;
- + info_p->cache_partitions[type] = cache_partitions;
- +
- + if (type == L2U) {
- + info_p->cpuid_cache_L2_associativity = cache_associativity;
- + info_p->cpuid_cache_size = cache_size;
- + }
- +
- + linesizes[type] = cache_linesize;
- + cache_sets = cache_size / (cache_associativity * cache_linesize * cache_partitions);
- + colors = ( cache_linesize * cache_sets ) >> 12;
- +
- + if ( colors > *geometry_colors )
- + *geometry_colors = colors;
- +}
- +
- +static void
- +cpuid_set_amd_cache_info( i386_cpu_info_t * info_p )
- +{
- + uint32_t cpuid_result[4];
- +
- + uint32_t index;
- +
- + //unsigned int i;
- + // unsigned int j;
- + boolean_t cpuid_deterministic_supported = FALSE;
- +
- + uint32_t linesizes[LCACHE_MAX];
- + uint32_t reg[4] = {0, 0, 0, 0};
- +
- + bzero( linesizes, sizeof(linesizes) );
- +
- + /* It would make sense to fill in info_p->cache_info with complete information
- + * on the TLBs and data cache associativity, lines, etc, either by mapping
- + * to the Intel tags (if possible), or replacing cache_info with a generic
- + * mechanism. But right now, nothing makes use of that information (that I know
- + * of).
- + */
- +
- + /* L1 Cache and TLB Information */
- + do_cpuid(0x80000005, cpuid_result);
- +
- + /* EAX: TLB Information for 2-Mbyte and 4-MByte Pages */
- + /* (ignore) */
- +
- + /* EBX: TLB Information for 4-Kbyte Pages */
- + /* (ignore) */
- +
- + /* ECX: L1 Data Cache Information */
- + info_p->cache_size[L1D] = ((cpuid_result[ecx] >> 24) & 0xFF) * 1024;
- + info_p->cache_linesize = (cpuid_result[ecx] & 0xFF);
- +
- + /* EDX: L1 Instruction Cache Information */
- + info_p->cache_size[L1I] = ((cpuid_result[edx] >> 24) & 0xFF) * 1024;
- + /* L2 Cache Information */
- + do_cpuid(0x80000006, cpuid_result);
- +
- + /* EAX: L2 TLB Information for 2-Mbyte and 4-Mbyte Pages */
- + /* (ignore) */
- +
- + /* EBX: L2 TLB Information for 4-Kbyte Pages */
- + /* (ignore) */
- +
- + /* ECX: L2 Cache Information */
- + info_p->cache_size[L2U] = ((cpuid_result[ecx] >> 16) & 0xFFFF) * 1024;
- + if (info_p->cache_size[L2U] > 0)
- + info_p->cache_linesize = cpuid_result[ecx] & 0xFF;
- +
- + //do_cpuid(0x80000008, cpuid_result);
- +
- + //uint32_t reg[4];
- + //uint32_t index;
- +
- + //info_p->cpuid_cores_per_package =((unsigned)(cpuid_result[ecx] & 0xff)) + 1;
- + do_cpuid(0x80000008, cpuid_result);
- + info_p->cpuid_cores_per_package = bitfield32(cpuid_result[ecx], 7, 0)+1;
- +
- + get_amd_cache_info(info_p, linesizes, L1I, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
- + get_amd_cache_info(info_p, linesizes, L1D, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
- + get_amd_cache_info(info_p, linesizes, L2U, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
- + get_amd_cache_info(info_p, linesizes, L3U, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
- +
- + if ( linesizes[L2U] )
- + info_p->cache_linesize = linesizes[L2U];
- + else if (linesizes[L1D])
- + info_p->cache_linesize = linesizes[L1D];
- + else printf("no linesize"); /* AMD machines should always report a cacheline */
- +
- + do_cpuid(0x8000001D, cpuid_result);
- + if (cpuid_result[eax] >= 4) {
- + //uint32_t reg[4];
- + //uint32_t index;
- + cpuid_deterministic_supported = TRUE;
- +
- + for (index = 0; cpuid_deterministic_supported; index++) {
- + /*
- + * Scan making calls for cpuid with %eax = 4
- + * to get info about successive cache levels
- + * until a null type is returned.
- + */
- + cache_type_t type = Lnone;
- + uint32_t cache_type;
- + uint32_t cache_level;
- + uint32_t cache_sharing;
- +
- + reg[eax] = 4; /* cpuid request 4 */
- + reg[ecx] = index; /* index starting at 0 */
- + cpuid(reg);
- + //kprintf("cpuid(4) index=%d eax=%p\n", index, reg[eax]);
- + cache_type = bitfield32(reg[eax], 4, 0);
- + if (cache_type == 0)
- + break; /* done with cache info */
- + cache_level = bitfield32(reg[eax], 7, 5);
- + cache_sharing = bitfield32(reg[eax], 25, 14);
- + switch (cache_level) {
- + case 1:
- + type = cache_type == 1 ? L1D :
- + cache_type == 2 ? L1I :
- + Lnone;
- + break;
- + case 2:
- + type = cache_type == 3 ? L2U :
- + Lnone;
- + break;
- + case 3:
- + type = cache_type == 3 ? L3U :
- + Lnone;
- + }
- + if (type != Lnone)
- + info_p->cache_sharing[type] = cache_sharing + 1;
- + }
- + if (info_p->cpuid_cores_per_package == 0)
- + info_p->cpuid_cores_per_package = 1;
- + }
- +}
- +
- +static void
- cpuid_set_generic_info(i386_cpu_info_t *info_p)
- {
- uint32_t reg[4];
- @@ -569,7 +815,11 @@
- assoc = 16;
- else if (assoc == 0xF)
- assoc = 0xFFFF;
- +#if 0
- info_p->cpuid_cache_L2_associativity = assoc;
- +#else
- + info_p->cpuid_cache_L2_associativity = bitfield32(reg[ecx],15,12);
- +#endif
- info_p->cpuid_cache_size = bitfield32(reg[ecx],31,16);
- cpuid_fn(0x80000008, reg);
- info_p->cpuid_address_bits_physical =
- @@ -583,10 +833,14 @@
- * and bracket this with the approved procedure for reading the
- * the microcode version number a.k.a. signature a.k.a. BIOS ID
- */
- +#if 0
- wrmsr64(MSR_IA32_BIOS_SIGN_ID, 0);
- +#endif
- cpuid_fn(1, reg);
- +#if 0
- info_p->cpuid_microcode_version =
- (uint32_t) (rdmsr64(MSR_IA32_BIOS_SIGN_ID) >> 32);
- +#endif
- info_p->cpuid_signature = reg[eax];
- info_p->cpuid_stepping = bitfield32(reg[eax], 3, 0);
- info_p->cpuid_model = bitfield32(reg[eax], 7, 4);
- @@ -598,7 +852,9 @@
- info_p->cpuid_features = quad(reg[ecx], reg[edx]);
- /* Get "processor flag"; necessary for microcode update matching */
- +#if 0
- info_p->cpuid_processor_flag = (rdmsr64(MSR_IA32_PLATFORM_ID)>> 50) & 3;
- +#endif
- /* Fold extensions into family/model */
- if (info_p->cpuid_family == 0x0f)
- @@ -743,10 +999,19 @@
- static uint32_t
- cpuid_set_cpufamily(i386_cpu_info_t *info_p)
- {
- +#if 0
- uint32_t cpufamily = CPUFAMILY_UNKNOWN;
- +#else
- + uint32_t cpufamily = CPUID_FAMILY_AMDX2;
- +#endif
- switch (info_p->cpuid_family) {
- case 6:
- +#if 1
- + case 15:
- + case 16:
- + case 10:
- +#endif
- switch (info_p->cpuid_model) {
- #if CONFIG_YONAH
- case 14:
- @@ -774,6 +1039,15 @@
- case CPUID_MODEL_JAKETOWN:
- cpufamily = CPUFAMILY_INTEL_SANDYBRIDGE;
- break;
- + case CPUID_MODEL_ATHLON_TM_II:
- + case CPUID_MODEL_ATHLON_K8:
- + case CPUID_MODEL_ATHLON_PHENOM_II:
- + cpufamily = CPUID_FAMILY_AMDX2;
- + cpufamily = CPUID_FAMILY_AMDX2_15;
- + cpufamily = CPUID_FAMILY_AMDX4;
- +
- + // return "AMD Athlon(tm) II X2";
- + break;
- }
- break;
- }
- @@ -797,17 +1071,24 @@
- cpuid_set_generic_info(info_p);
- +#if 0
- /* verify we are running on a supported CPU */
- if ((strncmp(CPUID_VID_INTEL, info_p->cpuid_vendor,
- min(strlen(CPUID_STRING_UNKNOWN) + 1,
- sizeof(info_p->cpuid_vendor)))) ||
- (cpuid_set_cpufamily(info_p) == CPUFAMILY_UNKNOWN))
- panic("Unsupported CPU");
- +#else
- + cpuid_set_cpufamily(info_p);
- +#endif
- info_p->cpuid_cpu_type = CPU_TYPE_X86;
- info_p->cpuid_cpu_subtype = CPU_SUBTYPE_X86_ARCH1;
- /* Must be invoked after set_generic_info */
- cpuid_set_cache_info(&cpuid_cpu_info);
- +#if 1
- + cpuid_set_amd_cache_info(&cpuid_cpu_info);
- +#endif
- /*
- * Find the number of enabled cores and threads
- @@ -888,6 +1169,9 @@
- {CPUID_FEATURE_PDCM, "PDCM"},
- {CPUID_FEATURE_SSE4_1, "SSE4.1"},
- {CPUID_FEATURE_SSE4_2, "SSE4.2"},
- +#if 1
- + {CPUID_FEATURE_SSE4A, "SSE4A"},
- +#endif
- {CPUID_FEATURE_xAPIC, "xAPIC"},
- {CPUID_FEATURE_MOVBE, "MOVBE"},
- {CPUID_FEATURE_POPCNT, "POPCNT"},
- diff -urN xnu-1699.26.8.orig/osfmk/i386/cpuid.h xnu-1699.26.8.snadge/osfmk/i386/cpuid.h
- --- xnu-1699.26.8.orig/osfmk/i386/cpuid.h 2012-05-11 01:24:47.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/cpuid.h 2012-05-22 23:09:23.000000000 +1000
- @@ -132,7 +132,14 @@
- #define CPUID_EXTFEATURE_1GBPAGE _Bit(26) /* 1GB pages */
- #define CPUID_EXTFEATURE_RDTSCP _Bit(27) /* RDTSCP */
- +#if 0
- #define CPUID_EXTFEATURE_EM64T _Bit(29) /* Extended Mem 64 Technology */
- +#else
- +#define CPUID_EXTFEATURE_EM64T (0x80000001 << 29) /* Extended Mem 64 Technology */
- +#define CPUID_FEATURE_SSE4A (0x80000001 <<6)
- +#define CPUID_FEATURE_A3DNOW _Bit(31)
- +#define CPUID_FEATURE_A3DNOWEXT _Bit(30)
- +#endif
- #define CPUID_EXTFEATURE_LAHF _HBit(0) /* LAFH/SAHF instructions */
- @@ -159,6 +166,14 @@
- #define CPUID_MODEL_WESTMERE_EX 0x2F
- #define CPUID_MODEL_SANDYBRIDGE 0x2A
- #define CPUID_MODEL_JAKETOWN 0x2D
- +#if 1
- +#define CPUID_MODEL_ATHLON_TM_II 0x6
- +#define CPUID_MODEL_ATHLON_K8 0xb
- +#define CPUID_MODEL_ATHLON_PHENOM_II 0x4
- +#define CPUID_FAMILY_AMDX2_15 (0xf)
- +#define CPUID_FAMILY_AMDX2 (0x10)
- +#define CPUID_FAMILY_AMDX4 (0xa)
- +#endif
- #ifndef ASSEMBLER
- diff -urN xnu-1699.26.8.orig/osfmk/i386/fpu.c xnu-1699.26.8.snadge/osfmk/i386/fpu.c
- --- xnu-1699.26.8.orig/osfmk/i386/fpu.c 2012-03-09 08:37:33.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/fpu.c 2012-05-23 00:38:43.000000000 +1000
- @@ -258,7 +258,11 @@
- if (xsp->extended_state[0] & (uint32_t)XFEM_YMM) {
- assert(xsp->extended_state[0] & (uint32_t) XFEM_SSE);
- /* XSAVE container size for all features */
- +#if 0
- assert(xsp->extended_state[2] == sizeof(struct x86_avx_thread_state));
- +#else
- + kprintf("BUG: xsp->extended_state[2] = %u != sizeof(struct x86_zvx_thread_state = %lu", xsp->extended_state[2], sizeof(struct x86_avx_thread_state));
- +#endif
- fp_register_state_size = sizeof(struct x86_avx_thread_state);
- fpu_YMM_present = TRUE;
- set_cr4(get_cr4() | CR4_OSXSAVE);
- diff -urN xnu-1699.26.8.orig/osfmk/i386/i386_init.c xnu-1699.26.8.snadge/osfmk/i386/i386_init.c
- --- xnu-1699.26.8.orig/osfmk/i386/i386_init.c 2012-01-12 04:17:21.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/i386_init.c 2012-05-23 15:19:27.000000000 +1000
- @@ -497,7 +497,7 @@
- &urgency_notification_assert_abstime_threshold,
- sizeof(urgency_notification_assert_abstime_threshold));
- -#if CONFIG_YONAH
- +#if defined(CONFIG_YONAH) || defined(CONFIG_LEGACY)
- /*
- * At this point we check whether we are a 64-bit processor
- * and that we're not restricted to legacy mode, 32-bit operation.
- diff -urN xnu-1699.26.8.orig/osfmk/i386/idt.s xnu-1699.26.8.snadge/osfmk/i386/idt.s
- --- xnu-1699.26.8.orig/osfmk/i386/idt.s 2010-11-13 10:21:10.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/idt.s 2012-05-22 23:09:23.000000000 +1000
- @@ -474,8 +474,13 @@
- INTERRUPT(0xf8)
- INTERRUPT(0xf9)
- INTERRUPT(0xfa)
- +#if 0
- INTERRUPT(0xfb)
- INTERRUPT(0xfc)
- +#else
- +EXCEP_SPC_USR(0xfb, t_fake_cpuid)
- +EXCEP_SPC_USR(0xfc, t_fake_sysenter)
- +#endif
- INTERRUPT(0xfd)
- INTERRUPT(0xfe)
- EXCEPTION(0xff,t_preempt)
- @@ -488,6 +493,29 @@
- .text
- +#if 1
- +Entry(t_fake_cpuid)
- +pushf // Must not modify eflags!
- +testl %eax, %eax // If eax == 0, we are getting cpuid string, so compare and set ZF for later
- +cpuid // Get cpuid; we'll patch it later based on the above test
- +// Note that cpuid does not affect any flags, so it's ok to compare
- +// first, do cpuid, and then do the conditional jump
- +jnz 2f // eax was not zero: we are getting feature bits etc, so skip patching
- +1: // otherwise, eax was zero so patch the cpuid vendor string with GenuineIntel
- +movl $0x756e6547, %ebx // "Genu"
- +movl $0x49656e69, %edx // "ineI"
- +movl $0x6c65746e, %ecx // "ntel"
- +2:
- +popf // restore eflags
- +iret // Done. Return from interrupt
- +
- +Entry(t_fake_sysenter)
- +pushl %eax /* save system call number */
- +pushl $0 /* clear trap number slot */
- +pusha /* save the general registers */
- +movl $EXT(lo_sysenter32),%ebx
- +jmp enter_lohandler
- +#endif
- /*
- * Trap/interrupt entry points.
- diff -urN xnu-1699.26.8.orig/osfmk/i386/idt64.s xnu-1699.26.8.snadge/osfmk/i386/idt64.s
- --- xnu-1699.26.8.orig/osfmk/i386/idt64.s 2012-05-11 01:24:52.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/idt64.s 2012-05-22 23:09:23.000000000 +1000
- @@ -428,14 +428,41 @@
- INTERRUPT64(0xf8)
- INTERRUPT64(0xf9)
- INTERRUPT64(0xfa)
- +#if 0
- INTERRUPT64(0xfb)
- INTERRUPT64(0xfc)
- +#else
- +EXCEP64_SPC_USR(0xfb, t64_fake_cpuid)
- +EXCEP64_SPC_USR(0xfc, t64_fake_sysenter)
- +#endif
- INTERRUPT64(0xfd)
- INTERRUPT64(0xfe)
- EXCEPTION64(0xff,t64_preempt)
- .text
- +#if 1
- +Entry(t64_fake_cpuid)
- +pushf
- +testl %eax, %eax // cpuid only checks the lower dword of rax
- +cpuid
- +jnz 2f
- +1:
- +movq $0x756e6547, %rbx // results, however, are zero-extended to qword size
- +movq $0x49656e69, %rdx
- +movq $0x6c65746e, %rcx
- +2:
- +popf
- +iretq // operand size is *very* important here
- +
- +Entry(t64_fake_sysenter)
- +swapgs /* switch to kernel gs (cpu_data) */
- +push %rax /* save system call number */
- +push $(UNIX_INT) /* only used for statistics */
- +movl $EXT(lo_sysenter32),4(%rsp)
- +jmp L_32bit_enter_check
- +#endif
- +
- /*
- *
- * Trap/interrupt entry points.
- diff -urN xnu-1699.26.8.orig/osfmk/i386/lapic_native.c xnu-1699.26.8.snadge/osfmk/i386/lapic_native.c
- --- xnu-1699.26.8.orig/osfmk/i386/lapic_native.c 2011-01-26 11:35:13.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/lapic_native.c 2012-05-22 23:09:23.000000000 +1000
- @@ -216,7 +216,11 @@
- lapic_ops->init();
- +#if 0
- if ((LAPIC_READ(VERSION)&LAPIC_VERSION_MASK) < 0x14) {
- +#else
- + if ((LAPIC_READ(VERSION)&LAPIC_VERSION_MASK) < 0x10) {
- +#endif
- panic("Local APIC version 0x%x, 0x14 or more expected\n",
- (LAPIC_READ(VERSION)&LAPIC_VERSION_MASK));
- }
- diff -urN xnu-1699.26.8.orig/osfmk/i386/machine_routines.c xnu-1699.26.8.snadge/osfmk/i386/machine_routines.c
- --- xnu-1699.26.8.orig/osfmk/i386/machine_routines.c 2011-04-08 08:41:09.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/machine_routines.c 2012-05-22 23:09:23.000000000 +1000
- @@ -436,6 +436,10 @@
- os_supports_sse = !!(get_cr4() & CR4_OSXMM);
- if (ml_fpu_avx_enabled())
- +#if 0
- + cpu_infop->vector_unit = 10;
- + else if ((cpuid_features() & CPUID_FEATURE_SSE4A) && os_supports_sse)
- +#endif
- cpu_infop->vector_unit = 9;
- else if ((cpuid_features() & CPUID_FEATURE_SSE4_2) && os_supports_sse)
- cpu_infop->vector_unit = 8;
- diff -urN xnu-1699.26.8.orig/osfmk/i386/pmap.c xnu-1699.26.8.snadge/osfmk/i386/pmap.c
- --- xnu-1699.26.8.orig/osfmk/i386/pmap.c 2012-05-11 01:24:47.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/pmap.c 2012-05-23 15:20:53.000000000 +1000
- @@ -175,7 +175,7 @@
- #endif
- int allow_stack_exec = 0; /* No apps may execute from the stack by default */
- -#if CONFIG_YONAH
- +#if defined(CONFIG_YONAH) || defined(CONFIG_LEGACY)
- boolean_t cpu_64bit = FALSE;
- #else
- const boolean_t cpu_64bit = TRUE;
- @@ -779,7 +779,7 @@
- pmap_store_pte(pdpt, pa | INTEL_PTE_VALID);
- }
- -#if CONFIG_YONAH
- +#if defined(CONFIG_YONAH) || defined(CONFIG_LEGACY)
- /* 32-bit and legacy support depends on IA32e mode being disabled */
- cpu_64bit = IA32e;
- #endif
- diff -urN xnu-1699.26.8.orig/osfmk/i386/pmap_internal.h xnu-1699.26.8.snadge/osfmk/i386/pmap_internal.h
- --- xnu-1699.26.8.orig/osfmk/i386/pmap_internal.h 2012-05-11 01:24:47.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/pmap_internal.h 2012-05-23 14:55:44.000000000 +1000
- @@ -84,7 +84,7 @@
- void
- pmap_update_cache_attributes_locked(ppnum_t, unsigned);
- -#if CONFIG_YONAH
- +#ifdef __i386__
- extern boolean_t cpu_64bit;
- #else
- extern const boolean_t cpu_64bit;
- diff -urN xnu-1699.26.8.orig/osfmk/i386/tsc.c xnu-1699.26.8.snadge/osfmk/i386/tsc.c
- --- xnu-1699.26.8.orig/osfmk/i386/tsc.c 2012-03-06 10:27:50.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/tsc.c 2012-05-22 23:09:23.000000000 +1000
- @@ -92,6 +92,9 @@
- #define CPU_FAMILY_PENTIUM_M (0x6)
- static const char FSB_Frequency_prop[] = "FSBFrequency";
- +#if 1
- +static const char FSB_CPUFrequency_prop[] = "CPUFrequency";
- +#endif
- /*
- * This routine extracts the bus frequency in Hz from the device tree.
- */
- @@ -126,6 +129,59 @@
- return frequency;
- }
- +static uint64_t
- +EFI_CPU_Frequency(void)
- +{
- + uint64_t frequency = 0;
- + DTEntry entry;
- + void *value;
- + unsigned int size;
- +
- + if (DTLookupEntry(0, "/efi/platform", &entry) != kSuccess) {
- + kprintf("EFI_CPU_Frequency: didn't find /efi/platform\n");
- + return 0;
- + }
- + if (DTGetProperty(entry,FSB_CPUFrequency_prop,&value,&size) != kSuccess) {
- + kprintf("EFI_CPU_Frequency: property %s not found\n",
- + FSB_Frequency_prop);
- + return 0;
- + }
- + if (size == sizeof(uint64_t)) {
- + frequency = *(uint64_t *) value;
- + kprintf("EFI_CPU_Frequency: read %s value: %llu\n",
- + FSB_Frequency_prop, frequency);
- + if (!(10*Mega < frequency && frequency < 50*Giga)) {
- + kprintf("EFI_Fake_MSR: value out of range\n");
- + frequency = 0;
- + }
- + } else {
- + kprintf("EFI_CPU_Frequency: unexpected size %d\n", size);
- + }
- + return frequency;
- +}
- +
- +static uint64_t
- +getFakeMSR(uint64_t frequency, uint64_t bFreq) {
- + uint64_t fakeMSR = 0ull;
- + uint64_t multi = 0;
- +
- + if (frequency == 0 || bFreq == 0)
- + return 0;
- +
- + multi = frequency / (bFreq / 1000); // = multi*1000
- + // divide by 1000, rounding up if it was x.75 or more
- + // Example: 12900 will get rounded to 13150/1000 = 13
- + // but 12480 will be 12730/1000 = 12
- + fakeMSR = (multi + 250) / 1000;
- + fakeMSR <<= 40; // push multiplier into bits 44 to 40
- +
- + // If fractional part was within (0.25, 0.75), set N/2
- + if ((multi % 1000 > 250) && (multi % 1000 < 750))
- + fakeMSR |= (1ull << 46);
- +
- + return fakeMSR;
- +}
- +
- /*
- * Initialize the various conversion factors needed by code referencing
- * the TSC.
- @@ -135,11 +191,16 @@
- {
- uint64_t busFCvtInt = 0;
- boolean_t N_by_2_bus_ratio = FALSE;
- + uint64_t cpuFreq=0;
- /*
- * Get the FSB frequency and conversion factors from EFI.
- */
- busFreq = EFI_FSB_frequency();
- +#if 1
- + if (busFreq == 0)
- + busFreq = BASE_NHM_CLOCK_SOURCE;
- +#endif
- switch (cpuid_cpufamily()) {
- case CPUFAMILY_INTEL_SANDYBRIDGE:
- @@ -173,6 +234,23 @@
- break;
- }
- +#if 1
- + case CPUID_FAMILY_AMDX2:
- + case CPUID_FAMILY_AMDX2_15:
- + case CPUID_FAMILY_AMDX4:
- + if (busFreq == 0)
- + busFreq = BASE_NHM_CLOCK_SOURCE;
- +
- + uint64_t prfsts;
- +
- + prfsts = rdmsr64(AMD_COFVID_STS);
- + cpuFreq = EFI_CPU_Frequency();
- + //prfsts = rdmsr64(IA32_PERF_STS);
- + prfsts = getFakeMSR(cpuFreq, busFreq);
- + tscGranularity = (uint32_t)bitfield(prfsts, 44, 40);
- + N_by_2_bus_ratio = (prfsts & bit(46)) != 0;
- + break;
- +#else
- default: {
- uint64_t prfsts;
- @@ -180,6 +258,7 @@
- tscGranularity = (uint32_t)bitfield(prfsts, 44, 40);
- N_by_2_bus_ratio = (prfsts & bit(46)) != 0;
- }
- +#endif
- }
- if (busFreq != 0) {
- @@ -187,7 +266,13 @@
- busFCvtn2t = 0xFFFFFFFFFFFFFFFFULL / busFCvtt2n;
- busFCvtInt = tmrCvt(1 * Peta, 0xFFFFFFFFFFFFFFFFULL / busFreq);
- } else {
- +#if 0
- panic("tsc_init: EFI not supported!\n");
- +#else
- + /* Instead of panicking, set a default FSB frequency */
- + busFreq = 200*Mega;
- + printf("rtclock_init: Setting fsb to %u MHz\n", (uint32_t) (busFreq/Mega));
- +#endif
- }
- kprintf(" BUS: Frequency = %6d.%04dMHz, "
- diff -urN xnu-1699.26.8.orig/osfmk/i386/tsc.h xnu-1699.26.8.snadge/osfmk/i386/tsc.h
- --- xnu-1699.26.8.orig/osfmk/i386/tsc.h 2010-04-22 11:25:23.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/i386/tsc.h 2012-05-22 23:09:23.000000000 +1000
- @@ -40,7 +40,14 @@
- #ifndef _I386_TSC_H_
- #define _I386_TSC_H_
- +#if 0
- #define BASE_NHM_CLOCK_SOURCE 133333333ULL
- +#else
- +#define BASE_NHM_CLOCK_SOURCE 200000000ULL
- +#define AMD_PERF_STS 0xC0010042 /* AMD's version of the MSR */
- +#define AMD_PSTATE0_STS 0xC0010064 /* K10/phenom class AMD cpus */
- +#define AMD_COFVID_STS 0xC0010071 /* This might be a better MSR for K10? */
- +#endif
- #define IA32_PERF_STS 0x198
- #define SLOW_TSC_THRESHOLD 1000067800 /* TSC is too slow for regular nanotime() algorithm */
- diff -urN xnu-1699.26.8.orig/osfmk/kern/debug.c xnu-1699.26.8.snadge/osfmk/kern/debug.c
- --- xnu-1699.26.8.orig/osfmk/kern/debug.c 2011-10-06 05:56:50.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/kern/debug.c 2012-05-22 23:09:23.000000000 +1000
- @@ -97,7 +97,11 @@
- unsigned int disable_debug_output = TRUE;
- unsigned int systemLogDiags = FALSE;
- unsigned int panicDebugging = FALSE;
- +#if 0
- unsigned int logPanicDataToScreen = FALSE;
- +#else
- +unsigned int logPanicDataToScreen = TRUE;
- +#endif
- int mach_assert = 1;
- diff -urN xnu-1699.26.8.orig/osfmk/kern/voodoo_assert.h xnu-1699.26.8.snadge/osfmk/kern/voodoo_assert.h
- --- xnu-1699.26.8.orig/osfmk/kern/voodoo_assert.h 1970-01-01 10:00:00.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/kern/voodoo_assert.h 2012-05-22 23:09:23.000000000 +1000
- @@ -0,0 +1,11 @@
- +#ifndef _VOODOO_ASSERT_H
- +#define _VOODOO_ASSERT_H
- +
- +#include <kern/debug.h>
- +
- +#define ASSERT(expr) do { if (!(expr)) panic("%s: failed assertion '%s'", \
- + __FUNCTION__, #expr); } while (0)
- +
- +#define BUG(msg) panic("%s: %s\n", __FUNCTION__, #msg)
- +
- +#endif
- diff -urN xnu-1699.26.8.orig/osfmk/vm/vm_resident.c xnu-1699.26.8.snadge/osfmk/vm/vm_resident.c
- --- xnu-1699.26.8.orig/osfmk/vm/vm_resident.c 2012-02-22 09:10:31.000000000 +1000
- +++ xnu-1699.26.8.snadge/osfmk/vm/vm_resident.c 2012-05-24 00:37:16.000000000 +1000
- @@ -393,7 +393,11 @@
- /* the count must be a power of 2 */
- if ( ( n & (n - 1)) != 0 )
- +#if 0
- panic("vm_page_set_colors");
- +#else
- + kprintf("vm_page_set_colors: n not power of 2 (%u)\n", n);
- +#endif
- vm_colors = n;
- vm_color_mask = n - 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement