Advertisement
snadge

xnu 1699.26.8 amd diff v1 - snadge

May 28th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 44.86 KB | None | 0 0
  1. diff -urN xnu-1699.26.8.orig/bsd/kern/kern_mib.c xnu-1699.26.8.snadge/bsd/kern/kern_mib.c
  2. --- xnu-1699.26.8.orig/bsd/kern/kern_mib.c  2012-05-11 01:24:40.000000000 +1000
  3. +++ xnu-1699.26.8.snadge/bsd/kern/kern_mib.c    2012-05-22 23:09:23.000000000 +1000
  4. @@ -416,6 +416,7 @@
  5.  int supplementalsse3_flag = -1;
  6.  int aes_flag = -1;
  7.  int avx1_0_flag = -1;
  8. +int sse4a_flag = -1;
  9.  
  10.  SYSCTL_INT(_hw_optional, OID_AUTO, mmx, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &mmx_flag, 0, "");
  11.  SYSCTL_INT(_hw_optional, OID_AUTO, sse, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse_flag, 0, "");
  12. @@ -424,6 +425,7 @@
  13.  SYSCTL_INT(_hw_optional, OID_AUTO, supplementalsse3, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &supplementalsse3_flag, 0, "");
  14.  SYSCTL_INT(_hw_optional, OID_AUTO, sse4_1, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse4_1_flag, 0, "");
  15.  SYSCTL_INT(_hw_optional, OID_AUTO, sse4_2, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse4_2_flag, 0, "");
  16. +SYSCTL_INT(_hw_optional, OID_AUTO, sse4a, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse4a_flag, 0, "");
  17.  /* "x86_64" is actually a preprocessor symbol on the x86_64 kernel, so we have to hack this */
  18.  #undef x86_64
  19.  SYSCTL_INT(_hw_optional, OID_AUTO, x86_64, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &x86_64_flag, 0, "");
  20. @@ -499,6 +501,7 @@
  21.     x86_64_flag     = is_capability_set(k64Bit);
  22.     aes_flag        = is_capability_set(kHasAES);
  23.     avx1_0_flag     = is_capability_set(kHasAVX1_0);
  24. +   sse4a_flag      = is_capability_set(kHasSSE4A);
  25.  
  26.     /* hw.cpufamily */
  27.     cpufamily = cpuid_cpufamily();
  28. diff -urN xnu-1699.26.8.orig/iokit/IOKit/IOCatalogue.h xnu-1699.26.8.snadge/iokit/IOKit/IOCatalogue.h
  29. --- xnu-1699.26.8.orig/iokit/IOKit/IOCatalogue.h    2010-07-31 10:14:51.000000000 +1000
  30. +++ xnu-1699.26.8.snadge/iokit/IOKit/IOCatalogue.h  2012-05-22 23:09:23.000000000 +1000
  31. @@ -279,4 +279,15 @@
  32.  extern const OSSymbol * gIOProbeScoreKey;
  33.  extern IOCatalogue    * gIOCatalogue;
  34.  
  35. +extern "C" {
  36. +    /* kaitek: see ::addDrivers() and StartIOKit() for more information about the built-in kernel
  37. +     * kext blacklist. */
  38. +    typedef struct {
  39. +        const char *name;
  40. +        uint32_t hits;
  41. +    } blacklist_mod_t;
  42. +    extern boolean_t blacklistEnabled;
  43. +    extern blacklist_mod_t blacklistMods[];
  44. +};
  45. +
  46.  #endif /* ! _IOKIT_IOCATALOGUE_H */
  47. diff -urN xnu-1699.26.8.orig/iokit/Kernel/IOCatalogue.cpp xnu-1699.26.8.snadge/iokit/Kernel/IOCatalogue.cpp
  48. --- xnu-1699.26.8.orig/iokit/Kernel/IOCatalogue.cpp 2011-04-07 08:45:40.000000000 +1000
  49. +++ xnu-1699.26.8.snadge/iokit/Kernel/IOCatalogue.cpp   2012-05-22 23:09:23.000000000 +1000
  50. @@ -75,6 +75,31 @@
  51.  #pragma mark Utility functions
  52.  #endif
  53.  /*********************************************************************
  54. + *********************************************************************/
  55. +static void
  56. +UniqueProperties(OSDictionary * dict)
  57. +{
  58. +    OSString * data;
  59. +  
  60. +    data = OSDynamicCast(OSString, dict->getObject(gIOClassKey));
  61. +    if (data) {
  62. +        const OSSymbol *classSymbol = OSSymbol::withString(data);
  63. +    
  64. +        dict->setObject( gIOClassKey, (OSSymbol *) classSymbol);
  65. +        classSymbol->release();
  66. +    }
  67. +  
  68. +    data = OSDynamicCast(OSString, dict->getObject(gIOMatchCategoryKey));
  69. +    if (data) {
  70. +        const OSSymbol *classSymbol = OSSymbol::withString(data);
  71. +
  72. +        dict->setObject(gIOMatchCategoryKey, (OSSymbol *) classSymbol);
  73. +        classSymbol->release();
  74. +    }
  75. +    return;
  76. +}
  77. +
  78. +/*********************************************************************
  79.  * Add a new personality to the set if it has a unique IOResourceMatchKey value.
  80.  * XXX -- svail: This should be optimized.
  81.  * esb - There doesn't seem like any reason to do this - it causes problems
  82. @@ -151,7 +176,11 @@
  83.  
  84.      kernelTables->reset();
  85.      while( (dict = (OSDictionary *) kernelTables->getNextObject())) {
  86. +#if 0
  87.          OSKext::uniquePersonalityProperties(dict);
  88. +#else
  89. +        UniqueProperties(dict);
  90. +#endif
  91.          if( 0 == dict->getObject( gIOClassKey ))
  92.              IOLog("Missing or bad \"%s\" key\n",
  93.                      gIOClassKey->getCStringNoCopy());
  94. @@ -281,7 +310,11 @@
  95.      OSDictionary         * dict;
  96.      OSOrderedSet         * set;
  97.  
  98. +#if 0
  99.      OSKext::uniquePersonalityProperties(matching);
  100. +#else
  101. +    UniqueProperties(matching);
  102. +#endif
  103.  
  104.      set = OSOrderedSet::withCapacity( 1, IOServiceOrdering,
  105.                                        (void *)gIOProbeScoreKey );
  106. @@ -320,8 +353,16 @@
  107.      bool                   result = false;
  108.      OSCollectionIterator * iter = NULL;       // must release
  109.      OSOrderedSet         * set = NULL;        // must release
  110. +#if 0
  111.      OSObject             * object = NULL;       // do not release
  112. +#else
  113. +    OSDictionary         * dict = NULL;       // do not release
  114. +#endif
  115.      OSArray              * persons = NULL;    // do not release
  116. +#if 1
  117. +    OSString             * moduleName;
  118. +    bool                   ret;
  119. +#endif
  120.  
  121.      persons = OSDynamicCast(OSArray, drivers);
  122.      if (!persons) {
  123. @@ -344,10 +385,14 @@
  124.      result = true;
  125.  
  126.      IOLockLock(lock);
  127. +#if 0
  128.      while ( (object = iter->getNextObject()) ) {
  129. +#else
  130. +    while ( (dict = (OSDictionary *) iter->getNextObject()) ) {
  131. +#endif
  132.      
  133.          // xxx Deleted OSBundleModuleDemand check; will handle in other ways for SL
  134. -
  135. +#if 0
  136.          OSDictionary * personality = OSDynamicCast(OSDictionary, object);
  137.  
  138.          SInt count;
  139. @@ -376,8 +421,30 @@
  140.              */
  141.              if (personality->isEqualTo(driver)) {
  142.                  break;
  143. +#else
  144. +        /* kaitek / qoopz: if the kext blacklist is enabled (which it is by default), then check
  145. +         * if any of the personalities we are preparing for matching should be skipped. */
  146. +        if (blacklistEnabled) {
  147. +            OSString *modName = OSDynamicCast(OSString, dict->getObject(gIOModuleIdentifierKey));
  148. +            const char *modNameStr = NULL;
  149. +            if (modName)
  150. +                modNameStr = modName->getCStringNoCopy();
  151. +            if (modNameStr) {
  152. +                boolean_t shouldMatch = TRUE;
  153. +                for (uint32_t n = 0; blacklistMods[n].name; n++) {
  154. +                    if (strcmp(blacklistMods[n].name, modNameStr))
  155. +                        continue;
  156. +                    if (!blacklistMods[n].hits++)
  157. +                        printf("warning: skipping personalities in blacklisted kext %s\n",
  158. +                               modNameStr);
  159. +                    shouldMatch = FALSE;
  160. +                }
  161. +                if (!shouldMatch)
  162. +                    continue;
  163. +#endif // 0
  164.              }
  165.          }
  166. +#if 0
  167.          if (count >= 0) {
  168.              // its a dup
  169.              continue;
  170. @@ -389,9 +456,55 @@
  171.          }
  172.          
  173.          AddNewImports(set, personality);
  174. +#else
  175. +        if ((moduleName = OSDynamicCast(OSString, dict->getObject("OSBundleModuleDemand")))) {
  176. +            IOLockUnlock( lock );
  177. +            ret = OSKext::loadKextWithIdentifier(moduleName->getCStringNoCopy(), false);
  178. +            IOLockLock( lock );
  179. +            ret = true;
  180. +        } else {
  181. +            SInt count;
  182. +    
  183. +            UniqueProperties(dict);
  184. +
  185. +            // Add driver personality to catalogue.
  186. +            count = array->getCount();
  187. +            while (count--) {
  188. +                OSDictionary * driver;
  189. +
  190. +                // Be sure not to double up on personalities.
  191. +                driver = (OSDictionary *)array->getObject(count);
  192. +
  193. +                /* Unlike in other functions, this comparison must be exact!
  194. +                 * The catalogue must be able to contain personalities that
  195. +                 * are proper supersets of others.
  196. +                 * Do not compare just the properties present in one driver
  197. +                 * pesonality or the other.
  198. +                 */
  199. +                if (dict->isEqualTo(driver)) {
  200. +                    break;
  201. +                }
  202. +            }
  203. +            if (count >= 0) {
  204. +                // its a dup
  205. +                continue;
  206. +            }
  207. +
  208. +            result = array->setObject(dict);
  209. +            if (!result) {
  210. +                break;
  211. +            }
  212. +
  213. +            AddNewImports(set, dict);
  214. +        };
  215. +#endif
  216.      }
  217.      // Start device matching.
  218. +#if 0
  219.      if (result && doNubMatching && (set->getCount() > 0)) {
  220. +#else
  221. +    if (doNubMatching && (set->getCount() > 0)) {
  222. +#endif
  223.          IOService::catalogNewDrivers(set);
  224.          generation++;
  225.      }
  226. @@ -440,7 +553,11 @@
  227.          return false;
  228.      }
  229.  
  230. +#if 0
  231.      OSKext::uniquePersonalityProperties( matching );
  232. +#else
  233. +    UniqueProperties( matching );
  234. +#endif
  235.  
  236.      IOLockLock(lock);
  237.      kernelTables->reset();
  238. @@ -538,7 +655,12 @@
  239.      startMatching(dict);
  240.      dict->release();
  241.  
  242. +#if 1
  243. +    (void) OSKext::setDeferredLoadSucceeded();
  244. +    (void) OSKext::considerRebuildOfPrelinkedKernel();
  245. +#else
  246.      (void) OSKext::considerRebuildOfPrelinkedKernel(moduleName);
  247. +#endif
  248.  }
  249.  
  250.  void IOCatalogue::moduleHasLoaded(const char * moduleName)
  251. @@ -573,7 +695,11 @@
  252.      if ( !iter )
  253.          return kIOReturnNoMemory;
  254.  
  255. +#if 0
  256.      OSKext::uniquePersonalityProperties( matching );
  257. +#else
  258. +    UniqueProperties( matching );
  259. +#endif
  260.  
  261.      // terminate instances.
  262.      do {
  263. @@ -769,6 +895,7 @@
  264.  
  265.  void IOCatalogue::reset(void)
  266.  {
  267. +#if 0
  268.      IOCatalogue::resetAndAddDrivers(/* no drivers; true reset */ NULL,
  269.          /* doMatching */ false);
  270.      return;
  271. @@ -946,6 +1073,7 @@
  272.      if (errorString) errorString->release();
  273.  
  274.      return result;
  275. +#endif // 0
  276.  }
  277.  
  278.  bool IOCatalogue::serialize(OSSerialize * s) const
  279. diff -urN xnu-1699.26.8.orig/iokit/Kernel/IOStartIOKit.cpp xnu-1699.26.8.snadge/iokit/Kernel/IOStartIOKit.cpp
  280. --- xnu-1699.26.8.orig/iokit/Kernel/IOStartIOKit.cpp    2011-05-11 06:33:57.000000000 +1000
  281. +++ xnu-1699.26.8.snadge/iokit/Kernel/IOStartIOKit.cpp  2012-05-22 23:09:23.000000000 +1000
  282. @@ -91,6 +91,16 @@
  283.      IORegistryEntry *      root;
  284.      OSObject *         obj;
  285.  
  286. +    uint32_t                    bootArg;
  287. +        /* kaitek: todo: implement some kind of mechanism whereby the user can specify a
  288. +     * custom list of kexts to be blacklisted. perhaps categories with the current
  289. +     * list designated "default" and additional categories like "gfx", etc. */
  290. +
  291. +        if (PE_parse_boot_argn("blacklist", &bootArg, sizeof(&bootArg)) && !bootArg) {
  292. +        blacklistEnabled = FALSE;
  293. +        printf("warning: disabling kext blacklist\n");
  294. +    }
  295. +
  296.      root = IORegistryEntry::initialize();
  297.      assert( root );
  298.      IOService::initialize();
  299. @@ -120,6 +130,22 @@
  300.  // From <osfmk/kern/debug.c>
  301.  extern int debug_mode;
  302.  
  303. +    /* kaitek / qoopz: blacklist of common kexts that are known to be problematic or undesirable
  304. +     * for virtually all non-apple hardware. see notes in StartIOKit(). */
  305. +
  306. +        boolean_t blacklistEnabled = TRUE;
  307. +        blacklist_mod_t blacklistMods[] = {
  308. +            { "com.apple.driver.AppleIntelMeromProfile",        0 },
  309. +            { "com.apple.driver.AppleIntelNehalemProfile",      0 },
  310. +            { "com.apple.driver.AppleIntelPenrynProfile",       0 },
  311. +            { "com.apple.driver.AppleIntelYonahProfile",        0 },
  312. +            { "com.apple.driver.AppleIntelCPUPowerManagement",  0 }, // must be added to use in 10.6.1+
  313. +            { "com.apple.iokit.CHUDKernLib",                    0 },
  314. +            { "com.apple.iokit.CHUDProf",                       0 },
  315. +            { "com.apple.iokit.CHUDUtils",                      0 },
  316. +            { NULL,                                             0 }
  317. +        };
  318. +
  319.  /*****
  320.   * Pointer into bootstrap KLD segment for functions never used past startup.
  321.   */
  322. diff -urN xnu-1699.26.8.orig/iokit/Kernel/IOUserClient.cpp xnu-1699.26.8.snadge/iokit/Kernel/IOUserClient.cpp
  323. --- xnu-1699.26.8.orig/iokit/Kernel/IOUserClient.cpp    2011-07-22 04:52:15.000000000 +1000
  324. +++ xnu-1699.26.8.snadge/iokit/Kernel/IOUserClient.cpp  2012-05-22 23:09:23.000000000 +1000
  325. @@ -3965,7 +3965,11 @@
  326.  
  327.                  array = OSDynamicCast(OSArray, obj);
  328.                  if (array) {
  329. +#if 0
  330.                      if ( !gIOCatalogue->resetAndAddDrivers(array,
  331. +#else
  332. +                    if ( !gIOCatalogue->addDrivers(array,
  333. +#endif
  334.                          flag == kIOCatalogResetDrivers) ) {
  335.  
  336.                          kr = kIOReturnError;
  337. diff -urN xnu-1699.26.8.orig/libkern/c++/OSKext.cpp xnu-1699.26.8.snadge/libkern/c++/OSKext.cpp
  338. --- xnu-1699.26.8.orig/libkern/c++/OSKext.cpp   2012-05-11 01:24:45.000000000 +1000
  339. +++ xnu-1699.26.8.snadge/libkern/c++/OSKext.cpp 2012-05-22 23:09:23.000000000 +1000
  340. @@ -1863,7 +1863,9 @@
  341.      const char   * versionCString           = NULL;  // do not free
  342.      const char   * compatibleVersionCString = NULL;  // do not free
  343.      OSBoolean    * scratchBool              = NULL;  // do not release
  344. +#if 0
  345.      OSDictionary * scratchDict              = NULL;  // do not release
  346. +#endif
  347.  
  348.      if (infoDict) {
  349.          panic("Attempt to set info dictionary on a kext "
  350. @@ -2004,11 +2006,13 @@
  351.  
  352.     /* Make sure common string values in personalities are uniqued to OSSymbols.
  353.      */
  354. +#if 0
  355.      scratchDict = OSDynamicCast(OSDictionary,
  356.          getPropertyForHostArch(kIOKitPersonalitiesKey));
  357.      if (scratchDict) {
  358.          uniquePersonalityProperties(scratchDict);
  359.      }
  360. +#endif
  361.  
  362.      result = true;
  363.  
  364. @@ -2068,6 +2072,7 @@
  365.  
  366.  /*********************************************************************
  367.  *********************************************************************/
  368. +#if 0
  369.  static void
  370.  uniqueStringPlistProperty(OSDictionary * dict, const char * key)
  371.  {
  372. @@ -2091,9 +2096,11 @@
  373.  
  374.      return;
  375.  }
  376. +#endif // 0
  377.  
  378.  /*********************************************************************
  379.  *********************************************************************/
  380. +#if 0
  381.  static void
  382.  uniqueStringPlistProperty(OSDictionary * dict, const OSString * key)
  383.  {
  384. @@ -2117,12 +2124,14 @@
  385.  
  386.      return;
  387.  }
  388. +#endif // 0
  389.  
  390.  /*********************************************************************
  391.  * Replace common personality property values with uniqued instances
  392.  * to save on wired memory.
  393.  *********************************************************************/
  394.  /* static */
  395. +#if 0
  396.  void
  397.  OSKext::uniquePersonalityProperties(OSDictionary * personalityDict)
  398.  {
  399. @@ -2154,6 +2163,7 @@
  400.  
  401.      return;
  402.  }
  403. +#endif
  404.  
  405.  /*********************************************************************
  406.  *********************************************************************/
  407. @@ -6097,7 +6107,11 @@
  408.      sConsiderUnloadsPending = false;
  409.      sConsiderUnloadsExecuted = true;
  410.  
  411. +#if 0
  412.      (void) OSKext::considerRebuildOfPrelinkedKernel(NULL);
  413. +#else
  414. +    (void) OSKext::considerRebuildOfPrelinkedKernel();
  415. +#endif
  416.      
  417.      IORecursiveLockUnlock(sKextInnerLock);
  418.      IORecursiveLockUnlock(sKextLock);
  419. @@ -6198,7 +6212,11 @@
  420.  *********************************************************************/
  421.  /* static */
  422.  void
  423. +#if 0
  424.  OSKext::considerRebuildOfPrelinkedKernel(OSString * moduleName)
  425. +#else
  426. +OSKext::considerRebuildOfPrelinkedKernel(void)
  427. +#endif
  428.  {
  429.      OSReturn       checkResult      = kOSReturnError;
  430.      static bool    requestedPrelink = false;
  431. @@ -6210,6 +6228,7 @@
  432.       * interested in rebuilding the kernel cache if the kext we are loading
  433.       * is not already in the original kernel cache.  9055303
  434.       */
  435. +#if 0
  436.      if (moduleName) {
  437.          int         count = sUnloadedPrelinkedKexts->getCount();
  438.          int         i;
  439. @@ -6232,6 +6251,7 @@
  440.          }
  441.          (void) OSKext::setDeferredLoadSucceeded();
  442.      }
  443. +#endif // 0
  444.  
  445.      if (!sDeferredLoadSucceeded || !sConsiderUnloadsExecuted ||
  446.          sSafeBoot || requestedPrelink)
  447. diff -urN xnu-1699.26.8.orig/libkern/libkern/c++/OSKext.h xnu-1699.26.8.snadge/libkern/libkern/c++/OSKext.h
  448. --- xnu-1699.26.8.orig/libkern/libkern/c++/OSKext.h 2011-04-07 08:45:40.000000000 +1000
  449. +++ xnu-1699.26.8.snadge/libkern/libkern/c++/OSKext.h   2012-05-22 23:09:23.000000000 +1000
  450. @@ -573,7 +573,11 @@
  451.      static void     flushNonloadedKexts(Boolean flushPrelinkedKexts);
  452.      static void     setKextdActive(Boolean active = true);
  453.      static void     setDeferredLoadSucceeded(Boolean succeeded = true);
  454. +#if 0
  455.      static void     considerRebuildOfPrelinkedKernel(OSString * moduleName);
  456. +#else
  457. +    static void     considerRebuildOfPrelinkedKernel(void);
  458. +#endif
  459.  
  460.      virtual bool    setAutounloadEnabled(bool flag);
  461.  
  462. @@ -597,7 +601,9 @@
  463.  
  464.     /* Converts common string-valued properties to OSSymbols for lower memory consumption.
  465.      */
  466. +#if 0
  467.      static void uniquePersonalityProperties(OSDictionary * personalityDict);
  468. +#endif
  469.  
  470.      virtual bool               declaresExecutable(void);     // might be missing
  471.      virtual bool               isInterface(void);
  472. diff -urN xnu-1699.26.8.orig/osfmk/conf/MASTER.i386 xnu-1699.26.8.snadge/osfmk/conf/MASTER.i386
  473. --- xnu-1699.26.8.orig/osfmk/conf/MASTER.i386   2011-05-11 08:52:53.000000000 +1000
  474. +++ xnu-1699.26.8.snadge/osfmk/conf/MASTER.i386 2012-05-23 15:16:16.000000000 +1000
  475. @@ -58,7 +58,8 @@
  476.  options        X86_64
  477.  options        DISPATCH_COUNTS
  478.  options        PAL_I386
  479. -options        CONFIG_YONAH    # 32-bit Yonah support      # <config_yonah>
  480. +#options   CONFIG_YONAH    # 32-bit Yonah support      # <config_yonah>
  481. +options        CONFIG_LEGACY   # Enable 32-bit legacy support
  482.  
  483.  #
  484.  # Note: MAC/AUDIT options must be set in all the bsd/conf, osfmk/conf, and
  485. diff -urN xnu-1699.26.8.orig/osfmk/i386/AT386/model_dep.c xnu-1699.26.8.snadge/osfmk/i386/AT386/model_dep.c
  486. --- xnu-1699.26.8.orig/osfmk/i386/AT386/model_dep.c 2012-01-12 04:17:21.000000000 +1000
  487. +++ xnu-1699.26.8.snadge/osfmk/i386/AT386/model_dep.c   2012-05-22 23:09:23.000000000 +1000
  488. @@ -119,6 +119,8 @@
  489.  #include <mach-o/loader.h>
  490.  #include <mach-o/nlist.h>
  491.  
  492. +#include <chud/chud_xnu.h> // qoopz: chud kexts have cpuids, must remove them for AMD
  493. +
  494.  #include <libkern/kernel_mach_header.h>
  495.  #include <libkern/OSKextLibPrivate.h>
  496.  
  497. @@ -752,9 +754,17 @@
  498.  void
  499.  halt_all_cpus(boolean_t reboot)
  500.  {
  501. +   /* ovof / paulicat: Disable all cores on shutdown to prevent the system hanging */
  502. +   uint32_t ncpus, i;
  503. +   ncpus = chudxnu_logical_cpu_count();
  504. +   for (i = 0; i < ncpus; i++)
  505. +       chudxnu_enable_cpu(i, FALSE);
  506.     if (reboot) {
  507.         printf("MACH Reboot\n");
  508.         PEHaltRestart( kPERestartCPU );
  509. +       asm volatile ("movb $0xfe, %al\n"
  510. +                     "outb %al, $0x64\n"
  511. +                     "hlt\n");
  512.     } else {
  513.         printf("CPU halted\n");
  514.         PEHaltRestart( kPEHaltCPU );
  515. diff -urN xnu-1699.26.8.orig/osfmk/i386/commpage/commpage.c xnu-1699.26.8.snadge/osfmk/i386/commpage/commpage.c
  516. --- xnu-1699.26.8.orig/osfmk/i386/commpage/commpage.c   2012-03-06 10:27:50.000000000 +1000
  517. +++ xnu-1699.26.8.snadge/osfmk/i386/commpage/commpage.c 2012-05-22 23:09:23.000000000 +1000
  518. @@ -207,6 +207,10 @@
  519.     ml_cpu_get_info(&cpu_info);
  520.    
  521.     switch (cpu_info.vector_unit) {
  522. +#if 1
  523. +       case 10:
  524. +           bits |= kHasSSE4A;
  525. +#endif
  526.         case 9:
  527.             bits |= kHasAVX1_0;
  528.             /* fall thru */
  529. diff -urN xnu-1699.26.8.orig/osfmk/i386/cpu_capabilities.h xnu-1699.26.8.snadge/osfmk/i386/cpu_capabilities.h
  530. --- xnu-1699.26.8.orig/osfmk/i386/cpu_capabilities.h    2011-05-03 08:29:48.000000000 +1000
  531. +++ xnu-1699.26.8.snadge/osfmk/i386/cpu_capabilities.h  2012-05-22 23:09:23.000000000 +1000
  532. @@ -62,6 +62,11 @@
  533.  #define    kHasF16C            0x04000000
  534.  #define    kHasENFSTRG         0x08000000
  535.  #define    kNumCPUsShift           16      /* see _NumCPUs() below */
  536. +#if 1
  537. +#define kHasSSE4A          0x00000040
  538. +#define kHas_A3DNOW            0x80000000
  539. +#define kHas_A3DNOWEXT         0x40000000
  540. +#endif
  541.  
  542.  #ifndef    __ASSEMBLER__
  543.  #include <sys/cdefs.h>
  544. diff -urN xnu-1699.26.8.orig/osfmk/i386/cpu_data.h xnu-1699.26.8.snadge/osfmk/i386/cpu_data.h
  545. --- xnu-1699.26.8.orig/osfmk/i386/cpu_data.h    2011-05-30 05:29:00.000000000 +1000
  546. +++ xnu-1699.26.8.snadge/osfmk/i386/cpu_data.h  2012-05-23 15:18:12.000000000 +1000
  547. @@ -317,7 +317,7 @@
  548.  {
  549.     CPU_DATA_GET(cpu_is64bit, boolean_t)
  550.  }
  551. -#if CONFIG_YONAH
  552. +#if defined(CONFIG_YONAH) || defined(CONFIG_LEGACY)
  553.  #define cpu_mode_is64bit()     get_is64bit()
  554.  #else
  555.  #define cpu_mode_is64bit()     TRUE
  556. diff -urN xnu-1699.26.8.orig/osfmk/i386/cpuid.c xnu-1699.26.8.snadge/osfmk/i386/cpuid.c
  557. --- xnu-1699.26.8.orig/osfmk/i386/cpuid.c   2012-05-11 01:24:47.000000000 +1000
  558. +++ xnu-1699.26.8.snadge/osfmk/i386/cpuid.c 2012-05-23 23:49:20.000000000 +1000
  559. @@ -28,10 +28,16 @@
  560.  /*
  561.   * @OSF_COPYRIGHT@
  562.   */
  563. +
  564. +#ifndef CPUID_C
  565. +#define CPUID_C 1
  566. +#endif
  567. +
  568.  #include <platforms.h>
  569.  #include <mach_kdb.h>
  570.  #include <vm/vm_page.h>
  571.  #include <pexpert/pexpert.h>
  572. +#include <kern/voodoo_assert.h>
  573.  
  574.  #include <i386/cpuid.h>
  575.  #if MACH_KDB
  576. @@ -450,7 +456,12 @@
  577.         info_p->cache_linesize = linesizes[L2U];
  578.     else if (linesizes[L1D])
  579.         info_p->cache_linesize = linesizes[L1D];
  580. +#if 0
  581.     else panic("no linesize");
  582. +#else
  583. +   else kprintf("no linesize");
  584. +#endif
  585. +
  586.     DBG(" cache_linesize    : %d\n", info_p->cache_linesize);
  587.  
  588.     /*
  589. @@ -502,6 +513,241 @@
  590.  }
  591.  
  592.  static void
  593. +get_amd_cache_info(
  594. +                  i386_cpu_info_t*     info_p,
  595. +                  uint32_t             linesizes[],
  596. +                  cache_type_t         type,
  597. +                  uint32_t*            geometry_colors,
  598. +                  uint32_t             n_cores)
  599. +{
  600. +   uint32_t    reg[4] = {0, 0, 0, 0};
  601. +   uint32_t    cache_level;
  602. +   uint32_t    cache_sharing;
  603. +   uint32_t    cache_linesize;
  604. +   uint32_t    cache_associativity;
  605. +   uint32_t    cache_size;
  606. +   uint32_t    cache_sets;
  607. +   uint32_t    cache_partitions;
  608. +   uint32_t    reg_to_use;
  609. +   uint32_t    colors;
  610. +   uint32_t    ncores;
  611. +
  612. +   switch (type) {
  613. +       case L1D:
  614. +           cache_level = 1;
  615. +           do_cpuid(0x80000005, reg);
  616. +           reg_to_use = ecx;
  617. +           break;
  618. +       case L1I:
  619. +           cache_level = 1;
  620. +           do_cpuid(0x80000005, reg);
  621. +           reg_to_use = edx;
  622. +           break;
  623. +       case L2U:
  624. +           cache_level = 2;
  625. +           do_cpuid(0x80000006, reg);
  626. +           reg_to_use = ecx;
  627. +           break;
  628. +       case L3U:
  629. +           cache_level = 3;
  630. +           do_cpuid(0x80000006, reg);
  631. +           reg_to_use = edx;
  632. +           break;
  633. +       case Lnone:
  634. +       default:
  635. +           return;
  636. +   };
  637. +
  638. +   /* Avoid div0 errors if we couldn't get the # of cores */
  639. +   if (n_cores == 0)
  640. +       ncores = 1;
  641. +   else
  642. +       ncores = n_cores;
  643. +
  644. +   cache_size = bitfield32(reg[reg_to_use], 31, 16);
  645. +
  646. +   if (cache_size == 0) {
  647. +       /* Cache doesn't exist, set it as zero */
  648. +       info_p->cache_size[type]        = 0;
  649. +       info_p->cache_sharing[type]     = 0;
  650. +       info_p->cache_partitions[type]  = 0;
  651. +       return;
  652. +   }
  653. +
  654. +   switch (cache_level) {
  655. +       case 1:
  656. +           /* L1 uses only bits 31 to 24 so we should shift right 8 bits
  657. +            * This is in KB units, and is reported per-core.
  658. +            */
  659. +           cache_size = (cache_size >> 8) * 1024;
  660. +           cache_sharing = 1;
  661. +           break;
  662. +       case 2:
  663. +           /* L2 cache is in KB units, reported per-core */
  664. +           cache_size *= 1024;
  665. +           cache_sharing = 1;
  666. +           break;
  667. +       case 3:
  668. +           /* L3 is in 512 KB units. This is reported by CPU as total, and
  669. +            * we export it as per-core. */
  670. +           cache_size = cache_size * 512 * 1024 / ncores;
  671. +           cache_sharing = ncores;
  672. +           break;
  673. +       default:
  674. +           BUG("invalid cache level");
  675. +           return; /* not reached, silences optimizer */
  676. +   };
  677. +
  678. +   cache_linesize          = bitfield32(reg[reg_to_use], 7,  0);
  679. +   cache_partitions        = bitfield32(reg[reg_to_use], 15, 8); // Needs review
  680. +   cache_associativity     = bitfield32(reg[reg_to_use], 23, 16);
  681. +
  682. +   /* For L2/L3 caches, AMD uses an encoding for associativity.
  683. +    * The formula is 2 ^ (assoc / 2)
  684. +    */
  685. +   if (cache_level > 1) {
  686. +       //cache_associativity = 1ul << (cache_associativity / 2);
  687. +       cache_associativity = (uint32_t)1ul << (cache_associativity / 2);
  688. +   }
  689. +
  690. +   info_p->cache_size[type]        = cache_size;
  691. +   info_p->cache_sharing[type]     = cache_sharing;
  692. +   info_p->cache_partitions[type]  = cache_partitions;
  693. +
  694. +   if (type == L2U) {
  695. +       info_p->cpuid_cache_L2_associativity = cache_associativity;
  696. +       info_p->cpuid_cache_size = cache_size;
  697. +   }
  698. +
  699. +   linesizes[type] = cache_linesize;
  700. +   cache_sets = cache_size / (cache_associativity * cache_linesize * cache_partitions);
  701. +   colors = ( cache_linesize * cache_sets ) >> 12;
  702. +
  703. +   if ( colors > *geometry_colors )
  704. +       *geometry_colors = colors;
  705. +}
  706. +
  707. +static void
  708. +cpuid_set_amd_cache_info( i386_cpu_info_t * info_p )
  709. +{
  710. +   uint32_t        cpuid_result[4];
  711. +
  712. +   uint32_t        index;
  713. +
  714. +   //unsigned int  i;
  715. +   //      unsigned int    j;
  716. +   boolean_t       cpuid_deterministic_supported = FALSE;
  717. +
  718. +   uint32_t        linesizes[LCACHE_MAX];
  719. +   uint32_t        reg[4] = {0, 0, 0, 0};
  720. +
  721. +   bzero( linesizes, sizeof(linesizes) );
  722. +
  723. +   /* It would make sense to fill in info_p->cache_info with complete information
  724. +    * on the TLBs and data cache associativity, lines, etc, either by mapping
  725. +    * to the Intel tags (if possible), or replacing cache_info with a generic
  726. +    * mechanism.  But right now, nothing makes use of that information (that I know
  727. +    * of).
  728. +    */
  729. +
  730. +   /* L1 Cache and TLB Information */
  731. +   do_cpuid(0x80000005, cpuid_result);
  732. +
  733. +   /* EAX: TLB Information for 2-Mbyte and 4-MByte Pages */
  734. +   /* (ignore) */
  735. +
  736. +   /* EBX: TLB Information for 4-Kbyte Pages */
  737. +   /* (ignore) */
  738. +
  739. +   /* ECX: L1 Data Cache Information */
  740. +   info_p->cache_size[L1D] = ((cpuid_result[ecx] >> 24) & 0xFF) * 1024;
  741. +   info_p->cache_linesize = (cpuid_result[ecx] & 0xFF);
  742. +
  743. +   /* EDX: L1 Instruction Cache Information */
  744. +   info_p->cache_size[L1I] = ((cpuid_result[edx] >> 24) & 0xFF) * 1024;
  745. +   /* L2 Cache Information */
  746. +   do_cpuid(0x80000006, cpuid_result);
  747. +
  748. +   /* EAX: L2 TLB Information for 2-Mbyte and 4-Mbyte Pages */
  749. +   /* (ignore) */
  750. +
  751. +   /* EBX: L2 TLB Information for 4-Kbyte Pages */
  752. +   /* (ignore) */
  753. +
  754. +   /* ECX: L2 Cache Information */
  755. +   info_p->cache_size[L2U] = ((cpuid_result[ecx] >> 16) & 0xFFFF) * 1024;
  756. +   if (info_p->cache_size[L2U] > 0)
  757. +       info_p->cache_linesize = cpuid_result[ecx] & 0xFF;
  758. +
  759. +   //do_cpuid(0x80000008, cpuid_result);
  760. +
  761. +   //uint32_t      reg[4];
  762. +   //uint32_t      index;
  763. +
  764. +   //info_p->cpuid_cores_per_package =((unsigned)(cpuid_result[ecx] & 0xff)) + 1;
  765. +   do_cpuid(0x80000008, cpuid_result);
  766. +   info_p->cpuid_cores_per_package = bitfield32(cpuid_result[ecx], 7, 0)+1;
  767. +
  768. +   get_amd_cache_info(info_p, linesizes, L1I, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
  769. +   get_amd_cache_info(info_p, linesizes, L1D, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
  770. +   get_amd_cache_info(info_p, linesizes, L2U, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
  771. +   get_amd_cache_info(info_p, linesizes, L3U, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
  772. +
  773. +   if ( linesizes[L2U] )
  774. +       info_p->cache_linesize = linesizes[L2U];
  775. +   else if (linesizes[L1D])
  776. +       info_p->cache_linesize = linesizes[L1D];
  777. +   else printf("no linesize"); /* AMD machines should always report a cacheline */
  778. +
  779. +   do_cpuid(0x8000001D, cpuid_result);
  780. +   if (cpuid_result[eax] >= 4) {
  781. +       //uint32_t      reg[4];
  782. +       //uint32_t      index;
  783. +       cpuid_deterministic_supported = TRUE;
  784. +
  785. +       for (index = 0; cpuid_deterministic_supported; index++) {
  786. +           /*
  787. +            * Scan making calls for cpuid with %eax = 4
  788. +            * to get info about successive cache levels
  789. +            * until a null type is returned.
  790. +            */
  791. +           cache_type_t    type = Lnone;
  792. +           uint32_t        cache_type;
  793. +           uint32_t        cache_level;
  794. +           uint32_t        cache_sharing;
  795. +
  796. +           reg[eax] = 4;           /* cpuid request 4 */
  797. +           reg[ecx] = index;       /* index starting at 0 */
  798. +           cpuid(reg);
  799. +           //kprintf("cpuid(4) index=%d eax=%p\n", index, reg[eax]);
  800. +           cache_type = bitfield32(reg[eax], 4, 0);
  801. +           if (cache_type == 0)
  802. +               break;          /* done with cache info */
  803. +           cache_level   = bitfield32(reg[eax],  7,  5);
  804. +           cache_sharing = bitfield32(reg[eax], 25, 14);            
  805. +           switch (cache_level) {
  806. +               case 1:
  807. +                   type = cache_type == 1 ? L1D :
  808. +                   cache_type == 2 ? L1I :
  809. +                   Lnone;
  810. +                   break;
  811. +               case 2:
  812. +                   type = cache_type == 3 ? L2U :
  813. +                   Lnone;
  814. +                   break;
  815. +               case 3:
  816. +                   type = cache_type == 3 ? L3U :
  817. +                   Lnone;
  818. +           }
  819. +           if (type != Lnone)
  820. +               info_p->cache_sharing[type] = cache_sharing + 1;
  821. +       }
  822. +       if (info_p->cpuid_cores_per_package == 0)
  823. +           info_p->cpuid_cores_per_package = 1;
  824. +   }
  825. +}
  826. +
  827. +static void
  828.  cpuid_set_generic_info(i386_cpu_info_t *info_p)
  829.  {
  830.     uint32_t    reg[4];
  831. @@ -569,7 +815,11 @@
  832.             assoc = 16;
  833.         else if (assoc == 0xF)
  834.             assoc = 0xFFFF;
  835. +#if 0
  836.         info_p->cpuid_cache_L2_associativity = assoc;
  837. +#else
  838. +       info_p->cpuid_cache_L2_associativity = bitfield32(reg[ecx],15,12);
  839. +#endif
  840.         info_p->cpuid_cache_size       = bitfield32(reg[ecx],31,16);
  841.         cpuid_fn(0x80000008, reg);
  842.         info_p->cpuid_address_bits_physical =
  843. @@ -583,10 +833,14 @@
  844.      * and bracket this with the approved procedure for reading the
  845.      * the microcode version number a.k.a. signature a.k.a. BIOS ID
  846.      */
  847. +#if 0
  848.     wrmsr64(MSR_IA32_BIOS_SIGN_ID, 0);
  849. +#endif
  850.     cpuid_fn(1, reg);
  851. +#if 0
  852.     info_p->cpuid_microcode_version =
  853.         (uint32_t) (rdmsr64(MSR_IA32_BIOS_SIGN_ID) >> 32);
  854. +#endif
  855.     info_p->cpuid_signature = reg[eax];
  856.     info_p->cpuid_stepping  = bitfield32(reg[eax],  3,  0);
  857.     info_p->cpuid_model     = bitfield32(reg[eax],  7,  4);
  858. @@ -598,7 +852,9 @@
  859.     info_p->cpuid_features  = quad(reg[ecx], reg[edx]);
  860.  
  861.     /* Get "processor flag"; necessary for microcode update matching */
  862. +#if 0
  863.     info_p->cpuid_processor_flag = (rdmsr64(MSR_IA32_PLATFORM_ID)>> 50) & 3;
  864. +#endif
  865.  
  866.     /* Fold extensions into family/model */
  867.     if (info_p->cpuid_family == 0x0f)
  868. @@ -743,10 +999,19 @@
  869.  static uint32_t
  870.  cpuid_set_cpufamily(i386_cpu_info_t *info_p)
  871.  {
  872. +#if 0
  873.     uint32_t cpufamily = CPUFAMILY_UNKNOWN;
  874. +#else
  875. +   uint32_t cpufamily = CPUID_FAMILY_AMDX2;
  876. +#endif
  877.  
  878.     switch (info_p->cpuid_family) {
  879.     case 6:
  880. +#if 1
  881. +   case 15:
  882. +   case 16:
  883. +   case 10:
  884. +#endif
  885.         switch (info_p->cpuid_model) {
  886.  #if CONFIG_YONAH
  887.         case 14:
  888. @@ -774,6 +1039,15 @@
  889.         case CPUID_MODEL_JAKETOWN:
  890.             cpufamily = CPUFAMILY_INTEL_SANDYBRIDGE;
  891.             break;
  892. +       case CPUID_MODEL_ATHLON_TM_II:
  893. +       case CPUID_MODEL_ATHLON_K8:
  894. +       case CPUID_MODEL_ATHLON_PHENOM_II:
  895. +           cpufamily = CPUID_FAMILY_AMDX2;
  896. +           cpufamily = CPUID_FAMILY_AMDX2_15;
  897. +           cpufamily = CPUID_FAMILY_AMDX4;
  898. +
  899. +           // return "AMD Athlon(tm) II X2";
  900. +           break;
  901.         }
  902.         break;
  903.     }
  904. @@ -797,17 +1071,24 @@
  905.  
  906.     cpuid_set_generic_info(info_p);
  907.  
  908. +#if 0
  909.     /* verify we are running on a supported CPU */
  910.     if ((strncmp(CPUID_VID_INTEL, info_p->cpuid_vendor,
  911.              min(strlen(CPUID_STRING_UNKNOWN) + 1,
  912.              sizeof(info_p->cpuid_vendor)))) ||
  913.        (cpuid_set_cpufamily(info_p) == CPUFAMILY_UNKNOWN))
  914.         panic("Unsupported CPU");
  915. +#else
  916. +   cpuid_set_cpufamily(info_p);
  917. +#endif
  918.  
  919.     info_p->cpuid_cpu_type = CPU_TYPE_X86;
  920.     info_p->cpuid_cpu_subtype = CPU_SUBTYPE_X86_ARCH1;
  921.     /* Must be invoked after set_generic_info */
  922.     cpuid_set_cache_info(&cpuid_cpu_info);
  923. +#if 1
  924. +   cpuid_set_amd_cache_info(&cpuid_cpu_info);
  925. +#endif
  926.  
  927.     /*
  928.      * Find the number of enabled cores and threads
  929. @@ -888,6 +1169,9 @@
  930.     {CPUID_FEATURE_PDCM,      "PDCM"},
  931.     {CPUID_FEATURE_SSE4_1,    "SSE4.1"},
  932.     {CPUID_FEATURE_SSE4_2,    "SSE4.2"},
  933. +#if 1
  934. +   {CPUID_FEATURE_SSE4A,     "SSE4A"},
  935. +#endif
  936.     {CPUID_FEATURE_xAPIC,     "xAPIC"},
  937.     {CPUID_FEATURE_MOVBE,     "MOVBE"},
  938.     {CPUID_FEATURE_POPCNT,    "POPCNT"},
  939. diff -urN xnu-1699.26.8.orig/osfmk/i386/cpuid.h xnu-1699.26.8.snadge/osfmk/i386/cpuid.h
  940. --- xnu-1699.26.8.orig/osfmk/i386/cpuid.h   2012-05-11 01:24:47.000000000 +1000
  941. +++ xnu-1699.26.8.snadge/osfmk/i386/cpuid.h 2012-05-22 23:09:23.000000000 +1000
  942. @@ -132,7 +132,14 @@
  943.  
  944.  #define CPUID_EXTFEATURE_1GBPAGE   _Bit(26)    /* 1GB pages */
  945.  #define CPUID_EXTFEATURE_RDTSCP       _Bit(27) /* RDTSCP */
  946. +#if 0
  947.  #define CPUID_EXTFEATURE_EM64T    _Bit(29) /* Extended Mem 64 Technology */
  948. +#else
  949. +#define CPUID_EXTFEATURE_EM64T     (0x80000001 << 29)   /* Extended Mem 64 Technology */
  950. +#define CPUID_FEATURE_SSE4A       (0x80000001 <<6)
  951. +#define CPUID_FEATURE_A3DNOW      _Bit(31)
  952. +#define CPUID_FEATURE_A3DNOWEXT   _Bit(30)
  953. +#endif
  954.  
  955.  #define CPUID_EXTFEATURE_LAHF     _HBit(0) /* LAFH/SAHF instructions */
  956.  
  957. @@ -159,6 +166,14 @@
  958.  #define CPUID_MODEL_WESTMERE_EX    0x2F
  959.  #define CPUID_MODEL_SANDYBRIDGE    0x2A
  960.  #define CPUID_MODEL_JAKETOWN   0x2D
  961. +#if 1
  962. +#define CPUID_MODEL_ATHLON_TM_II   0x6
  963. +#define CPUID_MODEL_ATHLON_K8      0xb
  964. +#define CPUID_MODEL_ATHLON_PHENOM_II   0x4
  965. +#define CPUID_FAMILY_AMDX2_15      (0xf)
  966. +#define CPUID_FAMILY_AMDX2     (0x10)
  967. +#define CPUID_FAMILY_AMDX4     (0xa)
  968. +#endif
  969.  
  970.  
  971.  #ifndef ASSEMBLER
  972. diff -urN xnu-1699.26.8.orig/osfmk/i386/fpu.c xnu-1699.26.8.snadge/osfmk/i386/fpu.c
  973. --- xnu-1699.26.8.orig/osfmk/i386/fpu.c 2012-03-09 08:37:33.000000000 +1000
  974. +++ xnu-1699.26.8.snadge/osfmk/i386/fpu.c   2012-05-23 00:38:43.000000000 +1000
  975. @@ -258,7 +258,11 @@
  976.         if (xsp->extended_state[0] & (uint32_t)XFEM_YMM) {
  977.             assert(xsp->extended_state[0] & (uint32_t) XFEM_SSE);
  978.             /* XSAVE container size for all features */
  979. +#if 0
  980.             assert(xsp->extended_state[2] == sizeof(struct x86_avx_thread_state));
  981. +#else
  982. +           kprintf("BUG: xsp->extended_state[2] = %u != sizeof(struct x86_zvx_thread_state = %lu", xsp->extended_state[2], sizeof(struct x86_avx_thread_state));
  983. +#endif
  984.             fp_register_state_size = sizeof(struct x86_avx_thread_state);
  985.             fpu_YMM_present = TRUE;
  986.             set_cr4(get_cr4() | CR4_OSXSAVE);
  987. diff -urN xnu-1699.26.8.orig/osfmk/i386/i386_init.c xnu-1699.26.8.snadge/osfmk/i386/i386_init.c
  988. --- xnu-1699.26.8.orig/osfmk/i386/i386_init.c   2012-01-12 04:17:21.000000000 +1000
  989. +++ xnu-1699.26.8.snadge/osfmk/i386/i386_init.c 2012-05-23 15:19:27.000000000 +1000
  990. @@ -497,7 +497,7 @@
  991.         &urgency_notification_assert_abstime_threshold,
  992.         sizeof(urgency_notification_assert_abstime_threshold));
  993.  
  994. -#if CONFIG_YONAH
  995. +#if defined(CONFIG_YONAH) || defined(CONFIG_LEGACY)
  996.     /*
  997.      * At this point we check whether we are a 64-bit processor
  998.      * and that we're not restricted to legacy mode, 32-bit operation.
  999. diff -urN xnu-1699.26.8.orig/osfmk/i386/idt.s xnu-1699.26.8.snadge/osfmk/i386/idt.s
  1000. --- xnu-1699.26.8.orig/osfmk/i386/idt.s 2010-11-13 10:21:10.000000000 +1000
  1001. +++ xnu-1699.26.8.snadge/osfmk/i386/idt.s   2012-05-22 23:09:23.000000000 +1000
  1002. @@ -474,8 +474,13 @@
  1003.  INTERRUPT(0xf8)
  1004.  INTERRUPT(0xf9)
  1005.  INTERRUPT(0xfa)
  1006. +#if 0
  1007.  INTERRUPT(0xfb)
  1008.  INTERRUPT(0xfc)
  1009. +#else
  1010. +EXCEP_SPC_USR(0xfb, t_fake_cpuid)
  1011. +EXCEP_SPC_USR(0xfc, t_fake_sysenter)
  1012. +#endif
  1013.  INTERRUPT(0xfd)
  1014.  INTERRUPT(0xfe)
  1015.  EXCEPTION(0xff,t_preempt)
  1016. @@ -488,6 +493,29 @@
  1017.    
  1018.          .text
  1019.  
  1020. +#if 1
  1021. +Entry(t_fake_cpuid)
  1022. +pushf                  // Must not modify eflags!
  1023. +testl %eax, %eax       // If eax == 0, we are getting cpuid string, so compare and set ZF for later
  1024. +cpuid                  // Get cpuid; we'll patch it later based on the above test
  1025. +// Note that cpuid does not affect any flags, so it's ok to compare
  1026. +// first, do cpuid, and then do the conditional jump
  1027. +jnz 2f                 // eax was not zero: we are getting feature bits etc, so skip patching
  1028. +1:     // otherwise, eax was zero so patch the cpuid vendor string with GenuineIntel
  1029. +movl $0x756e6547, %ebx // "Genu"
  1030. +movl $0x49656e69, %edx // "ineI"
  1031. +movl $0x6c65746e, %ecx // "ntel"
  1032. +2:
  1033. +popf                   // restore eflags
  1034. +iret                   // Done. Return from interrupt
  1035. +
  1036. +Entry(t_fake_sysenter)
  1037. +pushl   %eax                    /* save system call number */
  1038. +pushl   $0                      /* clear trap number slot */
  1039. +pusha                           /* save the general registers */
  1040. +movl   $EXT(lo_sysenter32),%ebx
  1041. +jmp    enter_lohandler
  1042. +#endif
  1043.    
  1044.  /*
  1045.   * Trap/interrupt entry points.
  1046. diff -urN xnu-1699.26.8.orig/osfmk/i386/idt64.s xnu-1699.26.8.snadge/osfmk/i386/idt64.s
  1047. --- xnu-1699.26.8.orig/osfmk/i386/idt64.s   2012-05-11 01:24:52.000000000 +1000
  1048. +++ xnu-1699.26.8.snadge/osfmk/i386/idt64.s 2012-05-22 23:09:23.000000000 +1000
  1049. @@ -428,14 +428,41 @@
  1050.  INTERRUPT64(0xf8)
  1051.  INTERRUPT64(0xf9)
  1052.  INTERRUPT64(0xfa)
  1053. +#if 0
  1054.  INTERRUPT64(0xfb)
  1055.  INTERRUPT64(0xfc)
  1056. +#else
  1057. +EXCEP64_SPC_USR(0xfb, t64_fake_cpuid)
  1058. +EXCEP64_SPC_USR(0xfc, t64_fake_sysenter)
  1059. +#endif
  1060.  INTERRUPT64(0xfd)
  1061.  INTERRUPT64(0xfe)
  1062.  EXCEPTION64(0xff,t64_preempt)
  1063.  
  1064.  
  1065.          .text
  1066. +#if 1
  1067. +Entry(t64_fake_cpuid)
  1068. +pushf
  1069. +testl %eax, %eax               // cpuid only checks the lower dword of rax
  1070. +cpuid
  1071. +jnz 2f
  1072. +1:
  1073. +movq $0x756e6547, %rbx         // results, however, are zero-extended to qword size
  1074. +movq $0x49656e69, %rdx
  1075. +movq $0x6c65746e, %rcx
  1076. +2:
  1077. +popf
  1078. +iretq                          // operand size is *very* important here
  1079. +
  1080. +Entry(t64_fake_sysenter)
  1081. +swapgs                         /* switch to kernel gs (cpu_data) */
  1082. +push   %rax                    /* save system call number */
  1083. +push   $(UNIX_INT)             /* only used for statistics */
  1084. +movl   $EXT(lo_sysenter32),4(%rsp)
  1085. +jmp    L_32bit_enter_check
  1086. +#endif
  1087. +
  1088.  /*
  1089.   *
  1090.   * Trap/interrupt entry points.
  1091. diff -urN xnu-1699.26.8.orig/osfmk/i386/lapic_native.c xnu-1699.26.8.snadge/osfmk/i386/lapic_native.c
  1092. --- xnu-1699.26.8.orig/osfmk/i386/lapic_native.c    2011-01-26 11:35:13.000000000 +1000
  1093. +++ xnu-1699.26.8.snadge/osfmk/i386/lapic_native.c  2012-05-22 23:09:23.000000000 +1000
  1094. @@ -216,7 +216,11 @@
  1095.  
  1096.     lapic_ops->init();
  1097.  
  1098. +#if 0
  1099.     if ((LAPIC_READ(VERSION)&LAPIC_VERSION_MASK) < 0x14) {
  1100. +#else
  1101. +   if ((LAPIC_READ(VERSION)&LAPIC_VERSION_MASK) < 0x10) {
  1102. +#endif
  1103.         panic("Local APIC version 0x%x, 0x14 or more expected\n",
  1104.             (LAPIC_READ(VERSION)&LAPIC_VERSION_MASK));
  1105.     }
  1106. diff -urN xnu-1699.26.8.orig/osfmk/i386/machine_routines.c xnu-1699.26.8.snadge/osfmk/i386/machine_routines.c
  1107. --- xnu-1699.26.8.orig/osfmk/i386/machine_routines.c    2011-04-08 08:41:09.000000000 +1000
  1108. +++ xnu-1699.26.8.snadge/osfmk/i386/machine_routines.c  2012-05-22 23:09:23.000000000 +1000
  1109. @@ -436,6 +436,10 @@
  1110.     os_supports_sse = !!(get_cr4() & CR4_OSXMM);
  1111.  
  1112.     if (ml_fpu_avx_enabled())
  1113. +#if 0
  1114. +       cpu_infop->vector_unit = 10;
  1115. +   else if  ((cpuid_features() & CPUID_FEATURE_SSE4A) && os_supports_sse)
  1116. +#endif
  1117.         cpu_infop->vector_unit = 9;
  1118.     else if ((cpuid_features() & CPUID_FEATURE_SSE4_2) && os_supports_sse)
  1119.         cpu_infop->vector_unit = 8;
  1120. diff -urN xnu-1699.26.8.orig/osfmk/i386/pmap.c xnu-1699.26.8.snadge/osfmk/i386/pmap.c
  1121. --- xnu-1699.26.8.orig/osfmk/i386/pmap.c    2012-05-11 01:24:47.000000000 +1000
  1122. +++ xnu-1699.26.8.snadge/osfmk/i386/pmap.c  2012-05-23 15:20:53.000000000 +1000
  1123. @@ -175,7 +175,7 @@
  1124.  #endif
  1125.  int allow_stack_exec = 0;      /* No apps may execute from the stack by default */
  1126.  
  1127. -#if CONFIG_YONAH
  1128. +#if defined(CONFIG_YONAH) || defined(CONFIG_LEGACY)
  1129.  boolean_t cpu_64bit  = FALSE;
  1130.  #else
  1131.  const boolean_t cpu_64bit  = TRUE;
  1132. @@ -779,7 +779,7 @@
  1133.       pmap_store_pte(pdpt, pa | INTEL_PTE_VALID);
  1134.     }
  1135.  
  1136. -#if CONFIG_YONAH
  1137. +#if defined(CONFIG_YONAH) || defined(CONFIG_LEGACY)
  1138.     /* 32-bit and legacy support depends on IA32e mode being disabled */
  1139.     cpu_64bit = IA32e;
  1140.  #endif
  1141. diff -urN xnu-1699.26.8.orig/osfmk/i386/pmap_internal.h xnu-1699.26.8.snadge/osfmk/i386/pmap_internal.h
  1142. --- xnu-1699.26.8.orig/osfmk/i386/pmap_internal.h   2012-05-11 01:24:47.000000000 +1000
  1143. +++ xnu-1699.26.8.snadge/osfmk/i386/pmap_internal.h 2012-05-23 14:55:44.000000000 +1000
  1144. @@ -84,7 +84,7 @@
  1145.  void
  1146.  pmap_update_cache_attributes_locked(ppnum_t, unsigned);
  1147.  
  1148. -#if CONFIG_YONAH
  1149. +#ifdef __i386__
  1150.  extern boolean_t cpu_64bit;
  1151.  #else
  1152.  extern const boolean_t cpu_64bit;
  1153. diff -urN xnu-1699.26.8.orig/osfmk/i386/tsc.c xnu-1699.26.8.snadge/osfmk/i386/tsc.c
  1154. --- xnu-1699.26.8.orig/osfmk/i386/tsc.c 2012-03-06 10:27:50.000000000 +1000
  1155. +++ xnu-1699.26.8.snadge/osfmk/i386/tsc.c   2012-05-22 23:09:23.000000000 +1000
  1156. @@ -92,6 +92,9 @@
  1157.  #define CPU_FAMILY_PENTIUM_M   (0x6)
  1158.  
  1159.  static const char  FSB_Frequency_prop[] = "FSBFrequency";
  1160. +#if 1
  1161. +static const char  FSB_CPUFrequency_prop[] = "CPUFrequency";
  1162. +#endif
  1163.  /*
  1164.   * This routine extracts the bus frequency in Hz from the device tree.
  1165.   */
  1166. @@ -126,6 +129,59 @@
  1167.     return frequency;
  1168.  }
  1169.  
  1170. +static uint64_t
  1171. +EFI_CPU_Frequency(void)
  1172. +{
  1173. +   uint64_t    frequency = 0;
  1174. +   DTEntry             entry;
  1175. +   void                *value;
  1176. +   unsigned int        size;
  1177. +
  1178. +   if (DTLookupEntry(0, "/efi/platform", &entry) != kSuccess) {
  1179. +       kprintf("EFI_CPU_Frequency: didn't find /efi/platform\n");
  1180. +       return 0;
  1181. +   }
  1182. +   if (DTGetProperty(entry,FSB_CPUFrequency_prop,&value,&size) != kSuccess) {
  1183. +       kprintf("EFI_CPU_Frequency: property %s not found\n",
  1184. +           FSB_Frequency_prop);
  1185. +       return 0;
  1186. +   }
  1187. +   if (size == sizeof(uint64_t)) {
  1188. +       frequency = *(uint64_t *) value;
  1189. +       kprintf("EFI_CPU_Frequency: read %s value: %llu\n",
  1190. +           FSB_Frequency_prop, frequency);
  1191. +       if (!(10*Mega < frequency && frequency < 50*Giga)) {
  1192. +           kprintf("EFI_Fake_MSR: value out of range\n");
  1193. +           frequency = 0;
  1194. +       }
  1195. +   } else {
  1196. +       kprintf("EFI_CPU_Frequency: unexpected size %d\n", size);
  1197. +   }
  1198. +   return frequency;
  1199. +}
  1200. +
  1201. +static uint64_t
  1202. +getFakeMSR(uint64_t frequency, uint64_t bFreq) {
  1203. +   uint64_t fakeMSR = 0ull;
  1204. +   uint64_t multi = 0;
  1205. +
  1206. +   if (frequency == 0 || bFreq == 0)
  1207. +       return 0;
  1208. +
  1209. +   multi = frequency / (bFreq / 1000); // = multi*1000
  1210. +   // divide by 1000, rounding up if it was x.75 or more
  1211. +   // Example: 12900 will get rounded to 13150/1000 = 13
  1212. +   //          but 12480 will be 12730/1000 = 12
  1213. +   fakeMSR = (multi + 250) / 1000;
  1214. +   fakeMSR <<= 40; // push multiplier into bits 44 to 40
  1215. +
  1216. +   // If fractional part was within (0.25, 0.75), set N/2
  1217. +   if ((multi % 1000 > 250) && (multi % 1000 < 750))
  1218. +       fakeMSR |= (1ull << 46);
  1219. +
  1220. +   return fakeMSR;
  1221. +}
  1222. +
  1223.  /*
  1224.   * Initialize the various conversion factors needed by code referencing
  1225.   * the TSC.
  1226. @@ -135,11 +191,16 @@
  1227.  {
  1228.     uint64_t    busFCvtInt = 0;
  1229.     boolean_t   N_by_2_bus_ratio = FALSE;
  1230. +   uint64_t    cpuFreq=0;
  1231.  
  1232.     /*
  1233.      * Get the FSB frequency and conversion factors from EFI.
  1234.      */
  1235.     busFreq = EFI_FSB_frequency();
  1236. +#if 1
  1237. +   if (busFreq == 0)
  1238. +       busFreq = BASE_NHM_CLOCK_SOURCE;
  1239. +#endif
  1240.  
  1241.     switch (cpuid_cpufamily()) {
  1242.     case CPUFAMILY_INTEL_SANDYBRIDGE:
  1243. @@ -173,6 +234,23 @@
  1244.  
  1245.         break;
  1246.              }
  1247. +#if 1
  1248. +   case CPUID_FAMILY_AMDX2:
  1249. +   case CPUID_FAMILY_AMDX2_15:
  1250. +   case CPUID_FAMILY_AMDX4:
  1251. +       if (busFreq == 0)
  1252. +       busFreq = BASE_NHM_CLOCK_SOURCE;
  1253. +
  1254. +       uint64_t    prfsts;
  1255. +
  1256. +       prfsts = rdmsr64(AMD_COFVID_STS);
  1257. +       cpuFreq = EFI_CPU_Frequency();
  1258. +       //prfsts = rdmsr64(IA32_PERF_STS);
  1259. +       prfsts  = getFakeMSR(cpuFreq, busFreq);
  1260. +       tscGranularity = (uint32_t)bitfield(prfsts, 44, 40);
  1261. +       N_by_2_bus_ratio = (prfsts & bit(46)) != 0;
  1262. +       break;
  1263. +#else
  1264.     default: {
  1265.         uint64_t    prfsts;
  1266.  
  1267. @@ -180,6 +258,7 @@
  1268.         tscGranularity = (uint32_t)bitfield(prfsts, 44, 40);
  1269.         N_by_2_bus_ratio = (prfsts & bit(46)) != 0;
  1270.         }
  1271. +#endif
  1272.     }
  1273.  
  1274.     if (busFreq != 0) {
  1275. @@ -187,7 +266,13 @@
  1276.         busFCvtn2t = 0xFFFFFFFFFFFFFFFFULL / busFCvtt2n;
  1277.         busFCvtInt = tmrCvt(1 * Peta, 0xFFFFFFFFFFFFFFFFULL / busFreq);
  1278.     } else {
  1279. +#if 0
  1280.         panic("tsc_init: EFI not supported!\n");
  1281. +#else
  1282. +       /* Instead of panicking, set a default FSB frequency */
  1283. +       busFreq = 200*Mega;
  1284. +       printf("rtclock_init: Setting fsb to %u MHz\n", (uint32_t) (busFreq/Mega));
  1285. +#endif
  1286.     }
  1287.  
  1288.     kprintf(" BUS: Frequency = %6d.%04dMHz, "
  1289. diff -urN xnu-1699.26.8.orig/osfmk/i386/tsc.h xnu-1699.26.8.snadge/osfmk/i386/tsc.h
  1290. --- xnu-1699.26.8.orig/osfmk/i386/tsc.h 2010-04-22 11:25:23.000000000 +1000
  1291. +++ xnu-1699.26.8.snadge/osfmk/i386/tsc.h   2012-05-22 23:09:23.000000000 +1000
  1292. @@ -40,7 +40,14 @@
  1293.  #ifndef _I386_TSC_H_
  1294.  #define _I386_TSC_H_
  1295.  
  1296. +#if 0
  1297.  #define BASE_NHM_CLOCK_SOURCE  133333333ULL
  1298. +#else
  1299. +#define BASE_NHM_CLOCK_SOURCE   200000000ULL
  1300. +#define AMD_PERF_STS    0xC0010042      /* AMD's version of the MSR */
  1301. +#define AMD_PSTATE0_STS 0xC0010064      /* K10/phenom class AMD cpus */
  1302. +#define AMD_COFVID_STS  0xC0010071      /* This might be a better MSR for K10? */
  1303. +#endif
  1304.  #define IA32_PERF_STS      0x198
  1305.  #define    SLOW_TSC_THRESHOLD  1000067800  /* TSC is too slow for regular nanotime() algorithm */
  1306.  
  1307. diff -urN xnu-1699.26.8.orig/osfmk/kern/debug.c xnu-1699.26.8.snadge/osfmk/kern/debug.c
  1308. --- xnu-1699.26.8.orig/osfmk/kern/debug.c   2011-10-06 05:56:50.000000000 +1000
  1309. +++ xnu-1699.26.8.snadge/osfmk/kern/debug.c 2012-05-22 23:09:23.000000000 +1000
  1310. @@ -97,7 +97,11 @@
  1311.  unsigned int   disable_debug_output = TRUE;
  1312.  unsigned int   systemLogDiags = FALSE;
  1313.  unsigned int   panicDebugging = FALSE;
  1314. +#if 0
  1315.  unsigned int   logPanicDataToScreen = FALSE;
  1316. +#else
  1317. +unsigned int   logPanicDataToScreen = TRUE;
  1318. +#endif
  1319.  
  1320.  int mach_assert = 1;
  1321.  
  1322. diff -urN xnu-1699.26.8.orig/osfmk/kern/voodoo_assert.h xnu-1699.26.8.snadge/osfmk/kern/voodoo_assert.h
  1323. --- xnu-1699.26.8.orig/osfmk/kern/voodoo_assert.h   1970-01-01 10:00:00.000000000 +1000
  1324. +++ xnu-1699.26.8.snadge/osfmk/kern/voodoo_assert.h 2012-05-22 23:09:23.000000000 +1000
  1325. @@ -0,0 +1,11 @@
  1326. +#ifndef _VOODOO_ASSERT_H
  1327. +#define _VOODOO_ASSERT_H
  1328. +
  1329. +#include <kern/debug.h>
  1330. +
  1331. +#define ASSERT(expr) do { if (!(expr)) panic("%s: failed assertion '%s'", \
  1332. +                                                      __FUNCTION__, #expr); } while (0)
  1333. +
  1334. +#define BUG(msg) panic("%s: %s\n", __FUNCTION__, #msg)
  1335. +
  1336. +#endif
  1337. diff -urN xnu-1699.26.8.orig/osfmk/vm/vm_resident.c xnu-1699.26.8.snadge/osfmk/vm/vm_resident.c
  1338. --- xnu-1699.26.8.orig/osfmk/vm/vm_resident.c   2012-02-22 09:10:31.000000000 +1000
  1339. +++ xnu-1699.26.8.snadge/osfmk/vm/vm_resident.c 2012-05-24 00:37:16.000000000 +1000
  1340. @@ -393,7 +393,11 @@
  1341.        
  1342.     /* the count must be a power of 2  */
  1343.     if ( ( n & (n - 1)) != 0  )
  1344. +#if 0
  1345.         panic("vm_page_set_colors");
  1346. +#else
  1347. +       kprintf("vm_page_set_colors: n not power of 2 (%u)\n", n);
  1348. +#endif
  1349.    
  1350.     vm_colors = n;
  1351.     vm_color_mask = n - 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement