ZackehSoul

Mac Lion AMD Kernel Source Diff

Apr 8th, 2012
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 123.15 KB | None | 0 0
  1. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/.DS_Store differ
  2. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/bsd/conf/MASTER.i386 /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/bsd/conf/MASTER.i386
  3. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/bsd/conf/MASTER.i386   2011-02-11 03:21:19.000000000 +0300
  4. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/bsd/conf/MASTER.i386    2012-03-28 01:24:49.000000000 +0400
  5. @@ -64,7 +64,7 @@
  6.  machine        "i386"                      # <intel>
  7.  cpu        "i386"                      # <intel>
  8.  
  9. -makeoptions    CCONFIGFLAGS = "-g -O3 -fno-omit-frame-pointer" # <gdb>
  10. +makeoptions    CCONFIGFLAGS = "-g -O3 -fno-omit-frame-pointer -msse4a" # <gdb>
  11.  makeoptions    CCONFIGFLAGS = "-O3"                # <!gdb>
  12.  makeoptions    RELOC = "00100000"              # <intel>
  13.  makeoptions    SYMADDR = "00780000"                # <intel>
  14. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/bsd/kern/kern_mib.c /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/bsd/kern/kern_mib.c
  15. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/bsd/kern/kern_mib.c    2012-02-02 19:16:31.000000000 +0300
  16. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/bsd/kern/kern_mib.c 2012-03-28 04:07:34.000000000 +0400
  17. @@ -131,23 +131,23 @@
  18.  static int packages;
  19.  
  20.  SYSCTL_NODE(, 0,     sysctl, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
  21. -   "Sysctl internal magic");
  22. +            "Sysctl internal magic");
  23.  SYSCTL_NODE(, CTL_KERN,      kern,   CTLFLAG_RW|CTLFLAG_LOCKED, 0,
  24. -   "High kernel, proc, limits &c");
  25. +            "High kernel, proc, limits &c");
  26.  SYSCTL_NODE(, CTL_VM,    vm,     CTLFLAG_RW|CTLFLAG_LOCKED, 0,
  27. -   "Virtual memory");
  28. +            "Virtual memory");
  29.  SYSCTL_NODE(, CTL_VFS,   vfs,     CTLFLAG_RW|CTLFLAG_LOCKED, 0,
  30. -   "File system");
  31. +            "File system");
  32.  SYSCTL_NODE(, CTL_NET,   net,    CTLFLAG_RW|CTLFLAG_LOCKED, 0,
  33. -   "Network, (see socket.h)");
  34. +            "Network, (see socket.h)");
  35.  SYSCTL_NODE(, CTL_DEBUG,  debug,  CTLFLAG_RW|CTLFLAG_LOCKED, 0,
  36. -   "Debugging");
  37. +            "Debugging");
  38.  SYSCTL_NODE(, CTL_HW,    hw,     CTLFLAG_RW|CTLFLAG_LOCKED, 0,
  39. -   "hardware");
  40. +            "hardware");
  41.  SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
  42. -   "machine dependent");
  43. +            "machine dependent");
  44.  SYSCTL_NODE(, CTL_USER,      user,   CTLFLAG_RW|CTLFLAG_LOCKED, 0,
  45. -   "user-level");
  46. +            "user-level");
  47.  
  48.  #define SYSCTL_RETURN(r, x)    SYSCTL_OUT(r, &x, sizeof(x))
  49.  
  50. @@ -171,7 +171,7 @@
  51.   */
  52.  static int
  53.  sysctl_hw_generic(__unused struct sysctl_oid *oidp, __unused void *arg1,
  54. -   int arg2, struct sysctl_req *req)
  55. +                  int arg2, struct sysctl_req *req)
  56.  {
  57.     char dummy[65];
  58.     int  epochTemp;
  59. @@ -181,19 +181,19 @@
  60.     host_basic_info_data_t hinfo;
  61.     kern_return_t kret;
  62.     mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
  63. -
  64. +    
  65.     /*
  66.      * Test and mask off the 'return quad' flag.
  67.      * Note that only some things here support it.
  68.      */
  69.     doquad = arg2 & CTLHW_RETQUAD;
  70.     arg2 &= ~CTLHW_RETQUAD;
  71. -
  72. +    
  73.     ml_cpu_get_info(&cpu_info);
  74. -
  75. +    
  76.  #define BSD_HOST 1
  77.     kret = host_info((host_t)BSD_HOST, HOST_BASIC_INFO, (host_info_t)&hinfo, &count);
  78. -
  79. +    
  80.     /*
  81.      * Handle various OIDs.
  82.      *
  83. @@ -201,108 +201,108 @@
  84.      * Errors and int-only values return inline.
  85.      */
  86.     switch (arg2) {
  87. -   case HW_NCPU:
  88. -       if (kret == KERN_SUCCESS) {
  89. -           return(SYSCTL_RETURN(req, hinfo.max_cpus));
  90. -       } else {
  91. -           return(EINVAL);
  92. -       }
  93. -   case HW_AVAILCPU:
  94. -       if (kret == KERN_SUCCESS) {
  95. -           return(SYSCTL_RETURN(req, hinfo.avail_cpus));
  96. -       } else {
  97. -           return(EINVAL);
  98. -       }
  99. -   case HW_LOCAL_PHYSICALCPU:
  100. -       if (kret == KERN_SUCCESS) {
  101. -           return(SYSCTL_RETURN(req, hinfo.physical_cpu));
  102. -       } else {
  103. -           return(EINVAL);
  104. -       }
  105. -   case HW_LOCAL_PHYSICALCPUMAX:
  106. -       if (kret == KERN_SUCCESS) {
  107. -           return(SYSCTL_RETURN(req, hinfo.physical_cpu_max));
  108. -       } else {
  109. -           return(EINVAL);
  110. -       }
  111. -   case HW_LOCAL_LOGICALCPU:
  112. -       if (kret == KERN_SUCCESS) {
  113. -           return(SYSCTL_RETURN(req, hinfo.logical_cpu));
  114. -       } else {
  115. -           return(EINVAL);
  116. -       }
  117. -   case HW_LOCAL_LOGICALCPUMAX:
  118. -       if (kret == KERN_SUCCESS) {
  119. -           return(SYSCTL_RETURN(req, hinfo.logical_cpu_max));
  120. -       } else {
  121. -           return(EINVAL);
  122. -       }
  123. -   case HW_CACHELINE:
  124. -       val = cpu_info.cache_line_size;
  125. -       qval = (long long)val;
  126. -       break;
  127. -   case HW_L1ICACHESIZE:
  128. -       val = cpu_info.l1_icache_size;
  129. -       qval = (long long)val;
  130. -       break;
  131. -   case HW_L1DCACHESIZE:
  132. -       val = cpu_info.l1_dcache_size;
  133. -       qval = (long long)val;
  134. -       break;
  135. -   case HW_L2CACHESIZE:
  136. -       if (cpu_info.l2_cache_size == 0xFFFFFFFF)
  137. -           return(EINVAL);
  138. -       val = cpu_info.l2_cache_size;
  139. -       qval = (long long)val;
  140. -       break;
  141. -   case HW_L3CACHESIZE:
  142. -       if (cpu_info.l3_cache_size == 0xFFFFFFFF)
  143. -           return(EINVAL);
  144. -       val = cpu_info.l3_cache_size;
  145. -       qval = (long long)val;
  146. -       break;
  147. -
  148. -       /*
  149. -        * Deprecated variables.  We still support these for
  150. -        * backwards compatibility purposes only.
  151. -        */
  152. -   case HW_MACHINE:
  153. -       bzero(dummy, sizeof(dummy));
  154. -       if(!PEGetMachineName(dummy,64))
  155. -           return(EINVAL);
  156. -       dummy[64] = 0;
  157. -       return(SYSCTL_OUT(req, dummy, strlen(dummy) + 1));
  158. -   case HW_MODEL:
  159. -       bzero(dummy, sizeof(dummy));
  160. -       if(!PEGetModelName(dummy,64))
  161. -           return(EINVAL);
  162. -       dummy[64] = 0;
  163. -       return(SYSCTL_OUT(req, dummy, strlen(dummy) + 1));
  164. -   case HW_USERMEM:
  165. +        case HW_NCPU:
  166. +            if (kret == KERN_SUCCESS) {
  167. +                return(SYSCTL_RETURN(req, hinfo.max_cpus));
  168. +            } else {
  169. +                return(EINVAL);
  170. +            }
  171. +        case HW_AVAILCPU:
  172. +            if (kret == KERN_SUCCESS) {
  173. +                return(SYSCTL_RETURN(req, hinfo.avail_cpus));
  174. +            } else {
  175. +                return(EINVAL);
  176. +            }
  177. +        case HW_LOCAL_PHYSICALCPU:
  178. +            if (kret == KERN_SUCCESS) {
  179. +                return(SYSCTL_RETURN(req, hinfo.physical_cpu));
  180. +            } else {
  181. +                return(EINVAL);
  182. +            }
  183. +        case HW_LOCAL_PHYSICALCPUMAX:
  184. +            if (kret == KERN_SUCCESS) {
  185. +                return(SYSCTL_RETURN(req, hinfo.physical_cpu_max));
  186. +            } else {
  187. +                return(EINVAL);
  188. +            }
  189. +        case HW_LOCAL_LOGICALCPU:
  190. +            if (kret == KERN_SUCCESS) {
  191. +                return(SYSCTL_RETURN(req, hinfo.logical_cpu));
  192. +            } else {
  193. +                return(EINVAL);
  194. +            }
  195. +        case HW_LOCAL_LOGICALCPUMAX:
  196. +            if (kret == KERN_SUCCESS) {
  197. +                return(SYSCTL_RETURN(req, hinfo.logical_cpu_max));
  198. +            } else {
  199. +                return(EINVAL);
  200. +            }
  201. +        case HW_CACHELINE:
  202. +            val = cpu_info.cache_line_size;
  203. +            qval = (long long)val;
  204. +            break;
  205. +        case HW_L1ICACHESIZE:
  206. +            val = cpu_info.l1_icache_size;
  207. +            qval = (long long)val;
  208. +            break;
  209. +        case HW_L1DCACHESIZE:
  210. +            val = cpu_info.l1_dcache_size;
  211. +            qval = (long long)val;
  212. +            break;
  213. +        case HW_L2CACHESIZE:
  214. +            if (cpu_info.l2_cache_size == 0xFFFFFFFF)
  215. +                return(EINVAL);
  216. +            val = cpu_info.l2_cache_size;
  217. +            qval = (long long)val;
  218. +            break;
  219. +        case HW_L3CACHESIZE:
  220. +            if (cpu_info.l3_cache_size == 0xFFFFFFFF)
  221. +                return(EINVAL);
  222. +            val = cpu_info.l3_cache_size;
  223. +            qval = (long long)val;
  224. +            break;
  225. +            
  226. +            /*
  227. +             * Deprecated variables.  We still support these for
  228. +             * backwards compatibility purposes only.
  229. +             */
  230. +        case HW_MACHINE:
  231. +            bzero(dummy, sizeof(dummy));
  232. +            if(!PEGetMachineName(dummy,64))
  233. +                return(EINVAL);
  234. +            dummy[64] = 0;
  235. +            return(SYSCTL_OUT(req, dummy, strlen(dummy) + 1));
  236. +        case HW_MODEL:
  237. +            bzero(dummy, sizeof(dummy));
  238. +            if(!PEGetModelName(dummy,64))
  239. +                return(EINVAL);
  240. +            dummy[64] = 0;
  241. +            return(SYSCTL_OUT(req, dummy, strlen(dummy) + 1));
  242. +        case HW_USERMEM:
  243.         {
  244. -       int usermem = mem_size - vm_page_wire_count * page_size;
  245. -
  246. +            int usermem = mem_size - vm_page_wire_count * page_size;
  247. +            
  248.             return(SYSCTL_RETURN(req, usermem));
  249.         }
  250. -   case HW_EPOCH:
  251. +        case HW_EPOCH:
  252.             epochTemp = PEGetPlatformEpoch();
  253. -       if (epochTemp == -1)
  254. -           return(EINVAL);
  255. -       return(SYSCTL_RETURN(req, epochTemp));
  256. -   case HW_VECTORUNIT: {
  257. -       int vector = cpu_info.vector_unit == 0? 0 : 1;
  258. -       return(SYSCTL_RETURN(req, vector));
  259. -   }
  260. -   case HW_L2SETTINGS:
  261. -       if (cpu_info.l2_cache_size == 0xFFFFFFFF)
  262. -           return(EINVAL);
  263. -       return(SYSCTL_RETURN(req, cpu_info.l2_settings));
  264. -   case HW_L3SETTINGS:
  265. -       if (cpu_info.l3_cache_size == 0xFFFFFFFF)
  266. -           return(EINVAL);
  267. -       return(SYSCTL_RETURN(req, cpu_info.l3_settings));
  268. -   default:
  269. -       return(ENOTSUP);
  270. +            if (epochTemp == -1)
  271. +                return(EINVAL);
  272. +            return(SYSCTL_RETURN(req, epochTemp));
  273. +        case HW_VECTORUNIT: {
  274. +            int vector = cpu_info.vector_unit == 0? 0 : 1;
  275. +            return(SYSCTL_RETURN(req, vector));
  276. +        }
  277. +        case HW_L2SETTINGS:
  278. +            if (cpu_info.l2_cache_size == 0xFFFFFFFF)
  279. +                return(EINVAL);
  280. +            return(SYSCTL_RETURN(req, cpu_info.l2_settings));
  281. +        case HW_L3SETTINGS:
  282. +            if (cpu_info.l3_cache_size == 0xFFFFFFFF)
  283. +                return(EINVAL);
  284. +            return(SYSCTL_RETURN(req, cpu_info.l3_settings));
  285. +        default:
  286. +            return(ENOTSUP);
  287.     }
  288.     /*
  289.      * Callers may come to us with either int or quad buffers.
  290. @@ -416,6 +416,7 @@
  291.  int supplementalsse3_flag = -1;
  292.  int aes_flag = -1;
  293.  int avx1_0_flag = -1;
  294. +int sse4a_flag = -1;
  295.  
  296.  SYSCTL_INT(_hw_optional, OID_AUTO, mmx, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &mmx_flag, 0, "");
  297.  SYSCTL_INT(_hw_optional, OID_AUTO, sse, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse_flag, 0, "");
  298. @@ -424,6 +425,7 @@
  299.  SYSCTL_INT(_hw_optional, OID_AUTO, supplementalsse3, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &supplementalsse3_flag, 0, "");
  300.  SYSCTL_INT(_hw_optional, OID_AUTO, sse4_1, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse4_1_flag, 0, "");
  301.  SYSCTL_INT(_hw_optional, OID_AUTO, sse4_2, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse4_2_flag, 0, "");
  302. +SYSCTL_INT(_hw_optional, OID_AUTO, sse4a, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &sse4a_flag, 0, "");
  303.  /* "x86_64" is actually a preprocessor symbol on the x86_64 kernel, so we have to hack this */
  304.  #undef x86_64
  305.  SYSCTL_INT(_hw_optional, OID_AUTO, x86_64, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &x86_64_flag, 0, "");
  306. @@ -439,19 +441,19 @@
  307.   */
  308.  static int
  309.  pmsSysctl(__unused struct sysctl_oid *oidp, __unused void *arg1,
  310. -     __unused int arg2, struct sysctl_req *req)
  311. +          __unused int arg2, struct sysctl_req *req)
  312.  {
  313.     pmsctl_t    ctl;
  314.     int     error;
  315.     boolean_t   intr;
  316. -
  317. +    
  318.     if ((error = SYSCTL_IN(req, &ctl, sizeof(ctl))))
  319.         return(error);
  320. -
  321. +    
  322.     intr = ml_set_interrupts_enabled(FALSE);        /* No interruptions in here */
  323.     error = pmsControl(ctl.request, (user_addr_t)(uintptr_t)ctl.reqaddr, ctl.reqsize);
  324.     (void)ml_set_interrupts_enabled(intr);          /* Restore interruptions */
  325. -
  326. +    
  327.     return(error);
  328.  }
  329.  
  330. @@ -474,7 +476,7 @@
  331.  #if defined(__i386__) || defined (__x86_64__)
  332.      cpu64bit = (_get_cpu_capabilities() & k64Bit) == k64Bit;
  333.  #endif
  334. -
  335. +    
  336.     /*
  337.      * Populate the optional portion of the hw.* MIB.
  338.      *
  339. @@ -482,11 +484,11 @@
  340.      *     that actually directly relate to the functions in
  341.      *     question.
  342.      */
  343. -
  344. +    
  345.     if (cputhreadtype != CPU_THREADTYPE_NONE) {
  346.         sysctl_register_oid(&sysctl__hw_cputhreadtype);
  347.     }
  348. -
  349. +    
  350.  #if defined (__i386__) || defined (__x86_64__)
  351.  #define is_capability_set(k) (((_get_cpu_capabilities() & (k)) == (k)) ? 1 : 0)
  352.     mmx_flag        = is_capability_set(kHasMMX);
  353. @@ -499,30 +501,31 @@
  354.     x86_64_flag     = is_capability_set(k64Bit);
  355.     aes_flag        = is_capability_set(kHasAES);
  356.     avx1_0_flag     = is_capability_set(kHasAVX1_0);
  357. -
  358. +    sse4a_flag     = is_capability_set(kHasSSE4A);
  359. +    
  360.     /* hw.cpufamily */
  361.     cpufamily = cpuid_cpufamily();
  362. -
  363. +    
  364.     /* hw.cacheconfig */
  365.     cacheconfig[0] = ml_cpu_cache_sharing(0);
  366.     cacheconfig[1] = ml_cpu_cache_sharing(1);
  367.     cacheconfig[2] = ml_cpu_cache_sharing(2);
  368.     cacheconfig[3] = ml_cpu_cache_sharing(3);
  369.     cacheconfig[4] = 0;
  370. -
  371. +    
  372.     /* hw.cachesize */
  373.     cachesize[0] = ml_cpu_cache_size(0);
  374.     cachesize[1] = ml_cpu_cache_size(1);
  375.     cachesize[2] = ml_cpu_cache_size(2);
  376.     cachesize[3] = ml_cpu_cache_size(3);
  377.     cachesize[4] = 0;
  378. -
  379. +    
  380.     /* hw.packages */
  381.     packages = roundup(ml_cpu_cache_sharing(0), cpuid_info()->thread_count)
  382. -           / cpuid_info()->thread_count;
  383. -
  384. +    / cpuid_info()->thread_count;
  385. +    
  386.  #else /* end __arm__ */
  387.  # error unknown architecture
  388.  #endif /* !__i386__ && !__x86_64 && !__arm__ */
  389. -
  390. +    
  391.  }
  392. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/.DS_Store differ
  393. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/Drivers/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/Drivers/.DS_Store differ
  394. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/Drivers/platform/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/Drivers/platform/.DS_Store differ
  395. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/IOKit/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/IOKit/.DS_Store differ
  396. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/IOKit/IOCatalogue.h /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/IOKit/IOCatalogue.h
  397. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/IOKit/IOCatalogue.h  2010-07-31 04:14:51.000000000 +0400
  398. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/IOKit/IOCatalogue.h   2012-03-23 14:27:04.000000000 +0300
  399. @@ -279,4 +279,16 @@
  400.  extern const OSSymbol * gIOProbeScoreKey;
  401.  extern IOCatalogue    * gIOCatalogue;
  402.  
  403. +
  404. +extern "C" {
  405. +    /* kaitek: see ::addDrivers() and StartIOKit() for more information about the built-in kernel
  406. +     * kext blacklist. */
  407. +    typedef struct {
  408. +        const char *name;
  409. +        uint32_t hits;
  410. +    } blacklist_mod_t;
  411. +    extern boolean_t blacklistEnabled;
  412. +    extern blacklist_mod_t blacklistMods[];
  413. +};
  414. +
  415.  #endif /* ! _IOKIT_IOCATALOGUE_H */
  416. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/Kernel/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/Kernel/.DS_Store differ
  417. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/Kernel/IOCatalogue.cpp /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/Kernel/IOCatalogue.cpp
  418. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/Kernel/IOCatalogue.cpp   2011-04-07 02:45:40.000000000 +0400
  419. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/Kernel/IOCatalogue.cpp    2012-03-23 23:28:52.000000000 +0300
  420. @@ -61,7 +61,7 @@
  421.  #pragma mark Internal Declarations
  422.  #endif
  423.  /*********************************************************************
  424. -*********************************************************************/
  425. + *********************************************************************/
  426.  
  427.  #define CATALOGTEST 0
  428.  
  429. @@ -75,11 +75,36 @@
  430.  #pragma mark Utility functions
  431.  #endif
  432.  /*********************************************************************
  433. -* Add a new personality to the set if it has a unique IOResourceMatchKey value.
  434. -* XXX -- svail: This should be optimized.
  435. -* esb - There doesn't seem like any reason to do this - it causes problems
  436. -* esb - when there are more than one loadable driver matching on the same provider class
  437. -*********************************************************************/
  438. + *********************************************************************/
  439. +static void
  440. +UniqueProperties(OSDictionary * dict)
  441. +{
  442. +    OSString * data;
  443. +    
  444. +    data = OSDynamicCast(OSString, dict->getObject(gIOClassKey));
  445. +    if (data) {
  446. +        const OSSymbol *classSymbol = OSSymbol::withString(data);
  447. +        
  448. +        dict->setObject( gIOClassKey, (OSSymbol *) classSymbol);
  449. +        classSymbol->release();
  450. +    }
  451. +    
  452. +    data = OSDynamicCast(OSString, dict->getObject(gIOMatchCategoryKey));
  453. +    if (data) {
  454. +        const OSSymbol *classSymbol = OSSymbol::withString(data);
  455. +        
  456. +        dict->setObject(gIOMatchCategoryKey, (OSSymbol *) classSymbol);
  457. +        classSymbol->release();
  458. +    }
  459. +    return;
  460. +}
  461. +
  462. +/*********************************************************************
  463. + * Add a new personality to the set if it has a unique IOResourceMatchKey value.
  464. + * XXX -- svail: This should be optimized.
  465. + * esb - There doesn't seem like any reason to do this - it causes problems
  466. + * esb - when there are more than one loadable driver matching on the same provider class
  467. + *********************************************************************/
  468.  static void
  469.  AddNewImports(OSOrderedSet * set, OSDictionary * dict)
  470.  {
  471. @@ -90,35 +115,35 @@
  472.  #pragma mark IOCatalogue class implementation
  473.  #endif
  474.  /*********************************************************************
  475. -*********************************************************************/
  476. + *********************************************************************/
  477.  
  478.  #define super OSObject
  479.  OSDefineMetaClassAndStructors(IOCatalogue, OSObject)
  480.  
  481.  /*********************************************************************
  482. -*********************************************************************/
  483. + *********************************************************************/
  484.  void IOCatalogue::initialize(void)
  485.  {
  486.      OSArray              * array;
  487.      OSString             * errorString;
  488.      bool          rc;
  489. -
  490. +    
  491.      extern const char * gIOKernelConfigTables;
  492. -
  493. +    
  494.      array = OSDynamicCast(OSArray, OSUnserialize(gIOKernelConfigTables, &errorString));
  495.      if (!array && errorString) {
  496.          IOLog("KernelConfigTables syntax error: %s\n",
  497. -            errorString->getCStringNoCopy());
  498. +              errorString->getCStringNoCopy());
  499.          errorString->release();
  500.      }
  501. -
  502. +    
  503.      gIOClassKey              = OSSymbol::withCStringNoCopy( kIOClassKey );
  504.      gIOProbeScoreKey        = OSSymbol::withCStringNoCopy( kIOProbeScoreKey );
  505.      gIOModuleIdentifierKey   = OSSymbol::withCStringNoCopy( kCFBundleIdentifierKey );
  506. -
  507. +    
  508.      assert( array && gIOClassKey && gIOProbeScoreKey
  509. -       && gIOModuleIdentifierKey);
  510. -
  511. +           && gIOModuleIdentifierKey);
  512. +    
  513.      gIOCatalogue = new IOCatalogue;
  514.      assert(gIOCatalogue);
  515.      rc = gIOCatalogue->init(array);
  516. @@ -127,54 +152,54 @@
  517.  }
  518.  
  519.  /*********************************************************************
  520. -* Initialize the IOCatalog object.
  521. -*********************************************************************/
  522. + * Initialize the IOCatalog object.
  523. + *********************************************************************/
  524.  bool IOCatalogue::init(OSArray * initArray)
  525.  {
  526.      OSDictionary         * dict;
  527.      
  528.      if ( !super::init() )
  529.          return false;
  530. -
  531. +    
  532.      generation = 1;
  533.      
  534.      array = initArray;
  535.      array->retain();
  536.      kernelTables = OSCollectionIterator::withCollection( array );
  537. -
  538. +    
  539.      gIOCatalogLock = IOLockAlloc();
  540. -
  541. +    
  542.      lock     = gIOCatalogLock;
  543. -#if __i386__
  544. +#if __ppc__ || __i386__
  545.      kld_lock = NULL;
  546. -#endif /* __i386__ */
  547. -
  548. +#endif /* __ppc__ || __i386__ */
  549. +    
  550.      kernelTables->reset();
  551.      while( (dict = (OSDictionary *) kernelTables->getNextObject())) {
  552. -        OSKext::uniquePersonalityProperties(dict);
  553. +        UniqueProperties(dict);
  554.          if( 0 == dict->getObject( gIOClassKey ))
  555.              IOLog("Missing or bad \"%s\" key\n",
  556. -                    gIOClassKey->getCStringNoCopy());
  557. +                  gIOClassKey->getCStringNoCopy());
  558.      }
  559. -
  560. +    
  561.  #if CATALOGTEST
  562.      AbsoluteTime deadline;
  563.      clock_interval_to_deadline( 1000, kMillisecondScale );
  564.      thread_call_func_delayed( ping, this, deadline );
  565.  #endif
  566. -
  567. +    
  568.      return true;
  569.  }
  570.  
  571.  /*********************************************************************
  572. -* Release all resources used by IOCatalogue and deallocate.
  573. -* This will probably never be called.
  574. -*********************************************************************/
  575. + * Release all resources used by IOCatalogue and deallocate.
  576. + * This will probably never be called.
  577. + *********************************************************************/
  578.  void IOCatalogue::free( void )
  579.  {
  580.      if ( array )
  581.          array->release();
  582. -
  583. +    
  584.      if ( kernelTables )
  585.          kernelTables->release();
  586.      
  587. @@ -182,7 +207,7 @@
  588.  }
  589.  
  590.  /*********************************************************************
  591. -*********************************************************************/
  592. + *********************************************************************/
  593.  #if CATALOGTEST
  594.  
  595.  static int hackLimit;
  596. @@ -195,33 +220,33 @@
  597.      OSOrderedSet         * set;
  598.      OSDictionary         * table;
  599.      int                       newLimit;
  600. -
  601. +    
  602.      set = OSOrderedSet::withCapacity( 1 );
  603. -
  604. +    
  605.      IOLockLock( &self->lock );
  606. -
  607. +    
  608.      for( newLimit = 0; newLimit < kDriversPerIter; newLimit++) {
  609. -   table = (OSDictionary *) self->array->getObject(
  610. -                   hackLimit + newLimit );
  611. -   if( table) {
  612. -       set->setLastObject( table );
  613. -
  614. -       OSSymbol * sym = (OSSymbol *) table->getObject(gIOClassKey);
  615. -       kprintf("enabling %s\n", sym->getCStringNoCopy());
  616. -
  617. -   } else {
  618. -       newLimit--;
  619. -       break;
  620. -   }
  621. +        table = (OSDictionary *) self->array->getObject(
  622. +                                                        hackLimit + newLimit );
  623. +        if( table) {
  624. +            set->setLastObject( table );
  625. +            
  626. +            OSSymbol * sym = (OSSymbol *) table->getObject(gIOClassKey);
  627. +            kprintf("enabling %s\n", sym->getCStringNoCopy());
  628. +            
  629. +        } else {
  630. +            newLimit--;
  631. +            break;
  632. +        }
  633.      }
  634. -
  635. +    
  636.      IOService::catalogNewDrivers( set );
  637. -
  638. +    
  639.      hackLimit += newLimit;
  640.      self->generation++;
  641. -
  642. +    
  643.      IOLockUnlock( &self->lock );
  644. -
  645. +    
  646.      if( kDriversPerIter == newLimit) {
  647.          AbsoluteTime deadline;
  648.          clock_interval_to_deadline(500, kMillisecondScale);
  649. @@ -231,202 +256,229 @@
  650.  #endif
  651.  
  652.  /*********************************************************************
  653. -*********************************************************************/
  654. + *********************************************************************/
  655.  OSOrderedSet *
  656.  IOCatalogue::findDrivers(
  657. -    IOService * service,
  658. -    SInt32 * generationCount)
  659. +                         IOService * service,
  660. +                         SInt32 * generationCount)
  661.  {
  662.      OSDictionary         * nextTable;
  663.      OSOrderedSet         * set;
  664.      OSString             * imports;
  665. -
  666. +    
  667.      set = OSOrderedSet::withCapacity( 1, IOServiceOrdering,
  668. -                                      (void *)gIOProbeScoreKey );
  669. +                                     (void *)gIOProbeScoreKey );
  670.      if( !set )
  671. -   return( 0 );
  672. -
  673. +        return( 0 );
  674. +    
  675.      IOLockLock(lock);
  676.      kernelTables->reset();
  677. -
  678. +    
  679.  #if CATALOGTEST
  680.      int hackIndex = 0;
  681.  #endif
  682.      while( (nextTable = (OSDictionary *) kernelTables->getNextObject())) {
  683.  #if CATALOGTEST
  684. -   if( hackIndex++ > hackLimit)
  685. -       break;
  686. +        if( hackIndex++ > hackLimit)
  687. +            break;
  688.  #endif
  689.          imports = OSDynamicCast( OSString,
  690. -           nextTable->getObject( gIOProviderClassKey ));
  691. -   if( imports && service->metaCast( imports ))
  692. +                                nextTable->getObject( gIOProviderClassKey ));
  693. +        if( imports && service->metaCast( imports ))
  694.              set->setObject( nextTable );
  695.      }
  696. -
  697. +    
  698.      *generationCount = getGenerationCount();
  699. -
  700. +    
  701.      IOLockUnlock(lock);
  702. -
  703. +    
  704.      return( set );
  705.  }
  706.  
  707.  /*********************************************************************
  708. -* Is personality already in the catalog?
  709. -*********************************************************************/
  710. + * Is personality already in the catalog?
  711. + *********************************************************************/
  712.  OSOrderedSet *
  713.  IOCatalogue::findDrivers(
  714. -    OSDictionary * matching,
  715. -    SInt32 * generationCount)
  716. +                         OSDictionary * matching,
  717. +                         SInt32 * generationCount)
  718.  {
  719.      OSDictionary         * dict;
  720.      OSOrderedSet         * set;
  721. -
  722. -    OSKext::uniquePersonalityProperties(matching);
  723. -
  724. +    
  725. +    UniqueProperties(matching);
  726. +    
  727.      set = OSOrderedSet::withCapacity( 1, IOServiceOrdering,
  728. -                                      (void *)gIOProbeScoreKey );
  729. -
  730. +                                     (void *)gIOProbeScoreKey );
  731. +    
  732.      IOLockLock(lock);
  733.      kernelTables->reset();
  734.      while ( (dict = (OSDictionary *) kernelTables->getNextObject()) ) {
  735. -
  736. -       /* This comparison must be done with only the keys in the
  737. -        * "matching" dict to enable general searches.
  738. -        */
  739. +        
  740. +        /* This comparison must be done with only the keys in the
  741. +         * "matching" dict to enable general searches.
  742. +         */
  743.          if ( dict->isEqualTo(matching, matching) )
  744.              set->setObject(dict);
  745.      }
  746.      *generationCount = getGenerationCount();
  747.      IOLockUnlock(lock);
  748. -
  749. +    
  750.      return set;
  751.  }
  752.  
  753.  /*********************************************************************
  754. -* Add driver config tables to catalog and start matching process.
  755. -*
  756. -* Important that existing personalities are kept (not replaced)
  757. -* if duplicates found. Personalities can come from OSKext objects
  758. -* or from userland kext library. We want to minimize distinct
  759. -* copies between OSKext & IOCatalogue.
  760. -*
  761. -* xxx - userlib used to refuse to send personalities with IOKitDebug
  762. -* xxx - during safe boot. That would be better implemented here.
  763. -*********************************************************************/
  764. + * Add driver config tables to catalog and start matching process.
  765. + *
  766. + * Important that existing personalities are kept (not replaced)
  767. + * if duplicates found. Personalities can come from OSKext objects
  768. + * or from userland kext library. We want to minimize distinct
  769. + * copies between OSKext & IOCatalogue.
  770. + *
  771. + * xxx - userlib used to refuse to send personalities with IOKitDebug
  772. + * xxx - during safe boot. That would be better implemented here.
  773. + *********************************************************************/
  774.  bool IOCatalogue::addDrivers(
  775. -    OSArray * drivers,
  776. -    bool doNubMatching)
  777. +                             OSArray * drivers,
  778. +                             bool doNubMatching)
  779.  {
  780.      bool                   result = false;
  781.      OSCollectionIterator * iter = NULL;       // must release
  782.      OSOrderedSet         * set = NULL;        // must release
  783. -    OSObject             * object = NULL;       // do not release
  784. +    OSDictionary         * dict = NULL;       // do not release
  785.      OSArray              * persons = NULL;    // do not release
  786. -
  787. +   OSString             * moduleName;
  788. +   bool                   ret;
  789. +  
  790. +  
  791.      persons = OSDynamicCast(OSArray, drivers);
  792.      if (!persons) {
  793.          goto finish;
  794.      }
  795.      
  796.      set = OSOrderedSet::withCapacity( 10, IOServiceOrdering,
  797. -        (void *)gIOProbeScoreKey );
  798. +                                     (void *)gIOProbeScoreKey );
  799.      if (!set) {
  800.          goto finish;
  801.      }
  802. -
  803. +    
  804.      iter = OSCollectionIterator::withCollection(persons);
  805.      if (!iter) {
  806.          goto finish;
  807.      }
  808. -
  809. -   /* Start with success; clear it on an error.
  810. -    */
  811. +    
  812.      result = true;
  813. -
  814. -    IOLockLock(lock);
  815. -    while ( (object = iter->getNextObject()) ) {
  816.      
  817. +    IOLockLock(lock);
  818. +    while ( (dict = (OSDictionary *) iter->getNextObject()) ) {
  819. +        
  820.          // xxx Deleted OSBundleModuleDemand check; will handle in other ways for SL
  821. -
  822. -        OSDictionary * personality = OSDynamicCast(OSDictionary, object);
  823. -
  824. -        SInt count;
  825. -
  826. -        if (!personality) {
  827. -            IOLog("IOCatalogue::addDrivers() encountered non-dictionary; bailing.\n");
  828. -            result = false;
  829. -            break;
  830. -        }
  831. -
  832. -        OSKext::uniquePersonalityProperties(personality);
  833.          
  834. -        // Add driver personality to catalogue.
  835. -        count = array->getCount();
  836. -        while (count--) {
  837. -            OSDictionary * driver;
  838. -            
  839. -            // Be sure not to double up on personalities.
  840. -            driver = (OSDictionary *)array->getObject(count);
  841. -            
  842. -           /* Unlike in other functions, this comparison must be exact!
  843. -            * The catalogue must be able to contain personalities that
  844. -            * are proper supersets of others.
  845. -            * Do not compare just the properties present in one driver
  846. -            * pesonality or the other.
  847. -            */
  848. -            if (personality->isEqualTo(driver)) {
  849. -                break;
  850. +       /* kaitek / qoopz: if the kext blacklist is enabled (which it is by default), then check
  851. +         * if any of the personalities we are preparing for matching should be skipped. */
  852. +        if (blacklistEnabled) {
  853. +            OSString *modName = OSDynamicCast(OSString, dict->getObject(gIOModuleIdentifierKey));
  854. +            const char *modNameStr = NULL;
  855. +            if (modName)
  856. +                modNameStr = modName->getCStringNoCopy();
  857. +            if (modNameStr) {
  858. +                boolean_t shouldMatch = TRUE;
  859. +                for (uint32_t n = 0; blacklistMods[n].name; n++) {
  860. +                    if (strcmp(blacklistMods[n].name, modNameStr))
  861. +                        continue;
  862. +                    if (!blacklistMods[n].hits++)
  863. +                        printf("warning: skipping personalities in blacklisted kext %s\n",
  864. +                               modNameStr);
  865. +                    shouldMatch = FALSE;
  866. +                }
  867. +                if (!shouldMatch)
  868. +                    continue;
  869.              }
  870.          }
  871. -        if (count >= 0) {
  872. -            // its a dup
  873. -            continue;
  874. -        }
  875. -        
  876. -        result = array->setObject(personality);
  877. -        if (!result) {
  878. -            break;
  879. -        }
  880. -        
  881. -        AddNewImports(set, personality);
  882. +      
  883. +        if ((moduleName = OSDynamicCast(OSString, dict->getObject("OSBundleModuleDemand"))))
  884. +        {
  885. +            IOLockUnlock( lock );    
  886. +            ret = OSKext::loadKextWithIdentifier(moduleName->getCStringNoCopy(), false);
  887. +            IOLockLock( lock );
  888. +            ret = true;
  889. +        }
  890. +      
  891. +       else
  892. +        {
  893. +            
  894. +            SInt count;
  895. +            
  896. +            UniqueProperties(dict);
  897. +            
  898. +            // Add driver personality to catalogue.
  899. +            count = array->getCount();
  900. +            while (count--) {
  901. +                OSDictionary * driver;
  902. +                
  903. +                // Be sure not to double up on personalities.
  904. +                driver = (OSDictionary *)array->getObject(count);
  905. +                
  906. +                /* Unlike in other functions, this comparison must be exact!
  907. +                 * The catalogue must be able to contain personalities that
  908. +                 * are proper supersets of others.
  909. +                 * Do not compare just the properties present in one driver
  910. +                 * pesonality or the other.
  911. +                 */
  912. +                if (dict->isEqualTo(driver)) {
  913. +                    break;
  914. +                }
  915. +            }
  916. +            if (count >= 0) {
  917. +                // its a dup
  918. +                continue;
  919. +            }
  920. +            
  921. +            result = array->setObject(dict);
  922. +            if (!result) {
  923. +                break;
  924. +            }
  925. +            
  926. +            AddNewImports(set, dict);
  927. +        };
  928.      }
  929.      // Start device matching.
  930. -    if (result && doNubMatching && (set->getCount() > 0)) {
  931. +    if (doNubMatching && (set->getCount() > 0)) {
  932.          IOService::catalogNewDrivers(set);
  933.          generation++;
  934.      }
  935.      IOLockUnlock(lock);
  936. -
  937. +    
  938.  finish:
  939.      if (set)  set->release();
  940.      if (iter) iter->release();
  941. -
  942. +    
  943.      return result;
  944.  }
  945.  
  946.  /*********************************************************************
  947. -* Remove drivers from the catalog which match the
  948. -* properties in the matching dictionary.
  949. -*********************************************************************/
  950. + * Remove drivers from the catalog which match the
  951. + * properties in the matching dictionary.
  952. + *********************************************************************/
  953.  bool
  954.  IOCatalogue::removeDrivers(
  955. -    OSDictionary * matching,
  956. -    bool doNubMatching)
  957. +                           OSDictionary * matching,
  958. +                           bool doNubMatching)
  959.  {
  960.      OSCollectionIterator * tables;
  961.      OSDictionary         * dict;
  962.      OSOrderedSet         * set;
  963.      OSArray              * arrayCopy;
  964. -
  965. +    
  966.      if ( !matching )
  967.          return false;
  968. -
  969. +    
  970.      set = OSOrderedSet::withCapacity(10,
  971.                                       IOServiceOrdering,
  972.                                       (void *)gIOProbeScoreKey);
  973.      if ( !set )
  974.          return false;
  975. -
  976. +    
  977.      arrayCopy = OSArray::withCapacity(100);
  978.      if ( !arrayCopy ) {
  979.          set->release();
  980. @@ -439,24 +491,24 @@
  981.          set->release();
  982.          return false;
  983.      }
  984. -
  985. -    OSKext::uniquePersonalityProperties( matching );
  986. -
  987. +    
  988. +    UniqueProperties( matching );
  989. +    
  990.      IOLockLock(lock);
  991.      kernelTables->reset();
  992.      arrayCopy->merge(array);
  993.      array->flushCollection();
  994.      tables->reset();
  995.      while ( (dict = (OSDictionary *)tables->getNextObject()) ) {
  996. -
  997. -       /* This comparison must be done with only the keys in the
  998. -        * "matching" dict to enable general searches.
  999. -        */
  1000. +        
  1001. +        /* This comparison must be done with only the keys in the
  1002. +         * "matching" dict to enable general searches.
  1003. +         */
  1004.          if ( dict->isEqualTo(matching, matching) ) {
  1005.              AddNewImports( set, dict );
  1006.              continue;
  1007.          }
  1008. -
  1009. +        
  1010.          array->setObject(dict);
  1011.      }
  1012.      // Start device matching.
  1013. @@ -501,10 +553,10 @@
  1014.  {
  1015.      OSString             * moduleName = NULL;
  1016.      OSString             * publisherName = NULL;
  1017. -
  1018. +    
  1019.      if ( !driver )
  1020.          return false;
  1021. -
  1022. +    
  1023.      /* The personalities of codeless kexts often contain the bundle ID of the
  1024.       * kext they reference, and not the bundle ID of the codeless kext itself.
  1025.       * The prelinked kernel needs to know the bundle ID of the codeless kext
  1026. @@ -512,16 +564,16 @@
  1027.       * in the IOPersonalityPublisher key, and we record it as requested here.
  1028.       */
  1029.      publisherName = OSDynamicCast(OSString,
  1030. -        driver->getObject(kIOPersonalityPublisherKey));
  1031. +                                  driver->getObject(kIOPersonalityPublisherKey));
  1032.      OSKext::recordIdentifierRequest(publisherName);
  1033. -
  1034. +    
  1035.      moduleName = OSDynamicCast(OSString, driver->getObject(gIOModuleIdentifierKey));
  1036.      if ( moduleName )
  1037.          return isModuleLoaded(moduleName);
  1038. -
  1039. -   /* If a personality doesn't hold the "CFBundleIdentifier" key
  1040. -    * it is assumed to be an "in-kernel" driver.
  1041. -    */
  1042. +    
  1043. +    /* If a personality doesn't hold the "CFBundleIdentifier" key
  1044. +     * it is assumed to be an "in-kernel" driver.
  1045. +     */
  1046.      return true;
  1047.  }
  1048.  
  1049. @@ -532,19 +584,20 @@
  1050.  void IOCatalogue::moduleHasLoaded(OSString * moduleName)
  1051.  {
  1052.      OSDictionary * dict;
  1053. -
  1054. +    
  1055.      dict = OSDictionary::withCapacity(2);
  1056.      dict->setObject(gIOModuleIdentifierKey, moduleName);
  1057.      startMatching(dict);
  1058.      dict->release();
  1059. -
  1060. -    (void) OSKext::considerRebuildOfPrelinkedKernel(moduleName);
  1061. +    
  1062. +    (void) OSKext::setDeferredLoadSucceeded();
  1063. +    (void) OSKext::considerRebuildOfPrelinkedKernel();
  1064.  }
  1065.  
  1066.  void IOCatalogue::moduleHasLoaded(const char * moduleName)
  1067.  {
  1068.      OSString * name;
  1069. -
  1070. +    
  1071.      name = OSString::withCString(moduleName);
  1072.      moduleHasLoaded(name);
  1073.      name->release();
  1074. @@ -562,19 +615,19 @@
  1075.      OSIterator           * iter;
  1076.      IOService            * service;
  1077.      IOReturn               ret;
  1078. -
  1079. +    
  1080.      if ( !matching )
  1081.          return kIOReturnBadArgument;
  1082. -
  1083. +    
  1084.      ret = kIOReturnSuccess;
  1085.      dict = 0;
  1086.      iter = IORegistryIterator::iterateOver(gIOServicePlane,
  1087. -                                kIORegistryIterateRecursively);
  1088. +                                           kIORegistryIterateRecursively);
  1089.      if ( !iter )
  1090.          return kIOReturnNoMemory;
  1091. -
  1092. -    OSKext::uniquePersonalityProperties( matching );
  1093. -
  1094. +    
  1095. +    UniqueProperties( matching );
  1096. +    
  1097.      // terminate instances.
  1098.      do {
  1099.          iter->reset();
  1100. @@ -582,14 +635,14 @@
  1101.              dict = service->getPropertyTable();
  1102.              if ( !dict )
  1103.                  continue;
  1104. -
  1105. -           /* Terminate only for personalities that match the matching dictionary.
  1106. -            * This comparison must be done with only the keys in the
  1107. -            * "matching" dict to enable general matching.
  1108. -            */
  1109. +            
  1110. +            /* Terminate only for personalities that match the matching dictionary.
  1111. +             * This comparison must be done with only the keys in the
  1112. +             * "matching" dict to enable general matching.
  1113. +             */
  1114.              if ( !dict->isEqualTo(matching, matching) )
  1115. -                 continue;
  1116. -
  1117. +                continue;
  1118. +            
  1119.              if ( !service->terminate(kIOServiceRequired|kIOServiceSynchronous) ) {
  1120.                  ret = kIOReturnUnsupported;
  1121.                  break;
  1122. @@ -597,7 +650,7 @@
  1123.          }
  1124.      } while( !service && !iter->isValid());
  1125.      iter->release();
  1126. -
  1127. +    
  1128.      return ret;
  1129.  }
  1130.  
  1131. @@ -607,77 +660,77 @@
  1132.      OSDictionary         * dict;
  1133.      OSArray              * arrayCopy;
  1134.      IOReturn               ret = kIOReturnSuccess;
  1135. -
  1136. +    
  1137.      // remove configs from catalog.
  1138. -
  1139. +    
  1140.      arrayCopy = OSArray::withCapacity(100);
  1141.      if ( !arrayCopy )
  1142.          return kIOReturnNoMemory;
  1143. -
  1144. +    
  1145.      tables = OSCollectionIterator::withCollection(arrayCopy);
  1146.      arrayCopy->release();
  1147.      if ( !tables )
  1148.          return kIOReturnNoMemory;
  1149. -
  1150. +    
  1151.      arrayCopy->merge(array);
  1152.      array->flushCollection();
  1153.      tables->reset();
  1154.      while ( (dict = (OSDictionary *)tables->getNextObject()) ) {
  1155. -
  1156. -       /* Remove from the catalogue's array any personalities
  1157. -        * that match the matching dictionary.
  1158. -        * This comparison must be done with only the keys in the
  1159. -        * "matching" dict to enable general matching.
  1160. -        */
  1161. +        
  1162. +        /* Remove from the catalogue's array any personalities
  1163. +         * that match the matching dictionary.
  1164. +         * This comparison must be done with only the keys in the
  1165. +         * "matching" dict to enable general matching.
  1166. +         */
  1167.          if ( dict->isEqualTo(matching, matching) )
  1168.              continue;
  1169. -
  1170. +        
  1171.          array->setObject(dict);
  1172.      }
  1173. -
  1174. +    
  1175.      tables->release();
  1176. -
  1177. +    
  1178.      return ret;
  1179.  }
  1180.  
  1181.  IOReturn IOCatalogue::terminateDrivers(OSDictionary * matching)
  1182.  {
  1183.      IOReturn ret;
  1184. -
  1185. +    
  1186.      ret = _terminateDrivers(matching);
  1187.      IOLockLock(lock);
  1188.      if (kIOReturnSuccess == ret)
  1189. -   ret = _removeDrivers(array, matching);
  1190. +        ret = _removeDrivers(array, matching);
  1191.      kernelTables->reset();
  1192.      IOLockUnlock(lock);
  1193. -
  1194. +    
  1195.      return ret;
  1196.  }
  1197.  
  1198.  IOReturn IOCatalogue::terminateDriversForModule(
  1199. -    OSString * moduleName,
  1200. -    bool unload)
  1201. +                                                OSString * moduleName,
  1202. +                                                bool unload)
  1203.  {
  1204.      IOReturn ret;
  1205.      OSDictionary * dict;
  1206.      bool isLoaded = false;
  1207. -
  1208. -   /* Check first if the kext currently has any linkage dependents;
  1209. -    * in such a case the unload would fail so let's not terminate any
  1210. -    * IOServices (since doing so typically results in a panic when there
  1211. -    * are loaded dependencies). Note that we aren't locking the kext here
  1212. -    * so it might lose or gain dependents by the time we call unloadModule();
  1213. -    * I think that's ok, our unload can fail if a kext comes in on top of
  1214. -    * this one even after we've torn down IOService objects. Conversely,
  1215. -    * if we fail the unload here and then lose a library, the autounload
  1216. -    * thread will get us in short order.
  1217. -    */
  1218. -    if (OSKext::isKextWithIdentifierLoaded(moduleName->getCStringNoCopy())) {
  1219.      
  1220. +    /* Check first if the kext currently has any linkage dependents;
  1221. +     * in such a case the unload would fail so let's not terminate any
  1222. +     * IOServices (since doing so typically results in a panic when there
  1223. +     * are loaded dependencies). Note that we aren't locking the kext here
  1224. +     * so it might lose or gain dependents by the time we call unloadModule();
  1225. +     * I think that's ok, our unload can fail if a kext comes in on top of
  1226. +     * this one even after we've torn down IOService objects. Conversely,
  1227. +     * if we fail the unload here and then lose a library, the autounload
  1228. +     * thread will get us in short order.
  1229. +     */
  1230. +    if (OSKext::isKextWithIdentifierLoaded(moduleName->getCStringNoCopy())) {
  1231. +        
  1232.          isLoaded = true;
  1233. -
  1234. +        
  1235.          if (!OSKext::canUnloadKextWithIdentifier(moduleName,
  1236. -            /* checkClasses */ false)) {
  1237. +                                                 /* checkClasses */ false)) {
  1238.              ret = kOSKextReturnInUse;
  1239.              goto finish;
  1240.          }
  1241. @@ -687,46 +740,46 @@
  1242.          ret = kIOReturnNoMemory;
  1243.          goto finish;
  1244.      }
  1245. -
  1246. +    
  1247.      dict->setObject(gIOModuleIdentifierKey, moduleName);
  1248. -
  1249. +    
  1250.      ret = _terminateDrivers(dict);
  1251.      
  1252. -   /* No goto between IOLock calls!
  1253. -    */
  1254. +    /* No goto between IOLock calls!
  1255. +     */
  1256.      IOLockLock(lock);
  1257.      if (kIOReturnSuccess == ret) {
  1258.          ret = _removeDrivers(array, dict);
  1259.      }
  1260.      kernelTables->reset();
  1261. -
  1262. +    
  1263.      // Unload the module itself.
  1264.      if (unload && isLoaded && ret == kIOReturnSuccess) {
  1265.          ret = unloadModule(moduleName);
  1266.      }
  1267. -
  1268. +    
  1269.      IOLockUnlock(lock);
  1270. -
  1271. +    
  1272.      dict->release();
  1273. -
  1274. +    
  1275.  finish:
  1276.      return ret;
  1277.  }
  1278.  
  1279.  IOReturn IOCatalogue::terminateDriversForModule(
  1280. -    const char * moduleName,
  1281. -    bool unload)
  1282. +                                                const char * moduleName,
  1283. +                                                bool unload)
  1284.  {
  1285.      OSString * name;
  1286.      IOReturn ret;
  1287. -
  1288. +    
  1289.      name = OSString::withCString(moduleName);
  1290.      if ( !name )
  1291.          return kIOReturnNoMemory;
  1292. -
  1293. +    
  1294.      ret = terminateDriversForModule(name, unload);
  1295.      name->release();
  1296. -
  1297. +    
  1298.      return ret;
  1299.  }
  1300.  
  1301. @@ -737,20 +790,20 @@
  1302.      
  1303.      if ( !matching )
  1304.          return false;
  1305. -
  1306. +    
  1307.      set = OSOrderedSet::withCapacity(10, IOServiceOrdering,
  1308.                                       (void *)gIOProbeScoreKey);
  1309.      if ( !set )
  1310.          return false;
  1311. -
  1312. +    
  1313.      IOLockLock(lock);
  1314.      kernelTables->reset();
  1315. -
  1316. +    
  1317.      while ( (dict = (OSDictionary *)kernelTables->getNextObject()) ) {
  1318. -
  1319. -       /* This comparison must be done with only the keys in the
  1320. -        * "matching" dict to enable general matching.
  1321. -        */
  1322. +        
  1323. +        /* This comparison must be done with only the keys in the
  1324. +         * "matching" dict to enable general matching.
  1325. +         */
  1326.          if ( dict->isEqualTo(matching, matching) )
  1327.              AddNewImports(set, dict);
  1328.      }
  1329. @@ -759,231 +812,55 @@
  1330.          IOService::catalogNewDrivers(set);
  1331.          generation++;
  1332.      }
  1333. -
  1334. +    
  1335.      IOLockUnlock(lock);
  1336. -
  1337. +    
  1338.      set->release();
  1339. -
  1340. +    
  1341.      return true;
  1342.  }
  1343.  
  1344.  void IOCatalogue::reset(void)
  1345.  {
  1346. -    IOCatalogue::resetAndAddDrivers(/* no drivers; true reset */ NULL,
  1347. -        /* doMatching */ false);
  1348. -    return;
  1349. -}
  1350. -
  1351. -bool IOCatalogue::resetAndAddDrivers(OSArray * drivers, bool doNubMatching)
  1352. -{
  1353. -    bool                   result              = false;
  1354. -    OSArray              * newPersonalities    = NULL;  // do not release
  1355. -    OSCollectionIterator * newPIterator        = NULL;  // must release
  1356. -    OSOrderedSet         * matchSet            = NULL;  // must release
  1357. -    OSArray              * oldPersonalities    = NULL;  // must release
  1358. -    OSArray              * kernelPersonalities = NULL;  // must release
  1359. -    OSString             * errorString         = NULL;  // must release
  1360. -    OSObject             * object              = NULL;  // do not release
  1361. -    OSDictionary         * thisNewPersonality  = NULL;  // do not release
  1362. -    signed int             count, i;
  1363. -
  1364. -    extern const char    * gIOKernelConfigTables;
  1365. -
  1366. -    if (drivers) {
  1367. -        newPersonalities = OSDynamicCast(OSArray, drivers);
  1368. -        if (!newPersonalities) {
  1369. -            goto finish;
  1370. -        }
  1371. -
  1372. -        newPIterator = OSCollectionIterator::withCollection(newPersonalities);
  1373. -        if (!newPIterator) {
  1374. -            goto finish;
  1375. -        }
  1376. -        
  1377. -        matchSet = OSOrderedSet::withCapacity(10, IOServiceOrdering,
  1378. -            (void *)gIOProbeScoreKey);
  1379. -        if (!matchSet) {
  1380. -            goto finish;
  1381. -        }
  1382. -    }
  1383. -
  1384. -   /* Read personalities for the built-in kernel driver classes.
  1385. -    * We don't have many any more.
  1386. -    */
  1387. -    kernelPersonalities = OSDynamicCast(OSArray,
  1388. -        OSUnserialize(gIOKernelConfigTables, &errorString));
  1389. -    if (!kernelPersonalities && errorString) {
  1390. -        IOLog("KernelConfigTables syntax error: %s\n",
  1391. -            errorString->getCStringNoCopy());
  1392. -        goto finish;
  1393. -    }
  1394. -    
  1395. -   /* Now copy the current array of personalities so we can reuse them
  1396. -    * if the new list contains any duplicates. This saves on memory
  1397. -    * consumption.
  1398. -    */
  1399. -    oldPersonalities = OSDynamicCast(OSArray, array->copyCollection());
  1400. -    if (!oldPersonalities) {
  1401. -        goto finish;
  1402. -    }
  1403. -
  1404. -    result = true;
  1405. -
  1406.      IOLog("Resetting IOCatalogue.\n");
  1407. -    
  1408. -   /* No goto finish from here to unlock.
  1409. -    */
  1410. -    IOLockLock(lock);
  1411. -    
  1412. -    array->flushCollection();
  1413. -
  1414. -   /* Add back the kernel personalities and remove them from the old
  1415. -    * array so we don't try to match on them again. Go forward through
  1416. -    * the arrays as this causes the least iteration since kernel personalities
  1417. -    * should always be first.
  1418. -    */
  1419. -    count = kernelPersonalities->getCount();
  1420. -    for (i = 0; i < count; i++) {
  1421. -    
  1422. -       /* Static cast here, as the data is coming from within the kernel image.
  1423. -        */
  1424. -        OSDictionary * thisNewPersonality = (OSDictionary *)
  1425. -            kernelPersonalities->getObject(i);
  1426. -        array->setObject(thisNewPersonality);
  1427. -
  1428. -        signed int oldPCount = oldPersonalities->getCount();
  1429. -        for (signed int oldPIndex = 0; oldPIndex < oldPCount; oldPIndex++) {
  1430. -            if (thisNewPersonality->isEqualTo(oldPersonalities->getObject(oldPIndex))) {
  1431. -                oldPersonalities->removeObject(oldPIndex);
  1432. -                break;
  1433. -            }
  1434. -        }
  1435. -    }
  1436. -
  1437. -   /* Now add the new set of personalities passed in, using existing
  1438. -    * copies if we had them in kernel memory already.
  1439. -    */
  1440. -    if (newPIterator) {
  1441. -        OSDictionary * thisOldPersonality = NULL;  // do not release
  1442. -        
  1443. -        while ( (object = newPIterator->getNextObject()) ) {
  1444. -
  1445. -            thisNewPersonality = OSDynamicCast(OSDictionary, object);
  1446. -            if (!thisNewPersonality) {
  1447. -                IOLog("IOCatalogue::resetAndAddDrivers() encountered non-dictionary; bailing.\n");
  1448. -            result = false;
  1449. -            break;
  1450. -            }
  1451. -
  1452. -           /* Convert common OSString property values to OSSymbols.
  1453. -            */
  1454. -            OSKext::uniquePersonalityProperties(thisNewPersonality);
  1455. -            
  1456. -           /* Add driver personality to catalogue, but if we had a copy already
  1457. -            * use that instead so we don't have multiple copies from OSKext instances.
  1458. -            */
  1459. -            count = oldPersonalities->getCount();
  1460. -            thisOldPersonality = NULL;
  1461. -            while (count--) {
  1462. -                
  1463. -                thisOldPersonality = (OSDictionary *)oldPersonalities->getObject(count);
  1464. -                
  1465. -               /* Unlike in other functions, this comparison must be exact!
  1466. -                * The catalogue must be able to contain personalities that
  1467. -                * are proper supersets of others.
  1468. -                * Do not compare just the properties present in one driver
  1469. -                * pesonality or the other.
  1470. -                */
  1471. -                if (thisNewPersonality->isEqualTo(thisOldPersonality)) {
  1472. -                    break;
  1473. -                }
  1474. -            }
  1475. -
  1476. -           /* If we found a dup, add the *original* back to the catalogue,
  1477. -            * remove it from our bookkeeping list, and continue.
  1478. -            * Don't worry about matching on personalities we already had.
  1479. -            */
  1480. -            if (count >= 0) {
  1481. -                array->setObject(thisOldPersonality);
  1482. -                oldPersonalities->removeObject(count);
  1483. -                continue;
  1484. -            }
  1485. -
  1486. -           /* Otherwise add the new personality and mark it for matching.
  1487. -            */
  1488. -            array->setObject(thisNewPersonality);
  1489. -            AddNewImports(matchSet, thisNewPersonality);                
  1490. -        }
  1491. -
  1492. -       /*****
  1493. -        * Now, go through remaining old personalities, which have effectively
  1494. -        * been removed, and add them to the match set as necessary.
  1495. -        */
  1496. -        count = oldPersonalities->getCount();
  1497. -        while (count--) {
  1498. -        
  1499. -           /* Static cast here is ok as these dictionaries were already in the catalogue.
  1500. -            */
  1501. -            thisOldPersonality = (OSDictionary *)oldPersonalities->getObject(count);
  1502. -            AddNewImports(matchSet, thisOldPersonality);
  1503. -        }
  1504. -
  1505. -       /* Finally, start device matching on all new & removed personalities.
  1506. -        */
  1507. -        if (result && doNubMatching && (matchSet->getCount() > 0)) {
  1508. -            IOService::catalogNewDrivers(matchSet);
  1509. -            generation++;
  1510. -        }
  1511. -    }
  1512. -
  1513. -    IOLockUnlock(lock);
  1514. -
  1515. -finish:
  1516. -    if (newPIterator) newPIterator->release();
  1517. -    if (matchSet) matchSet->release();
  1518. -    if (oldPersonalities) oldPersonalities->release();
  1519. -    if (kernelPersonalities) kernelPersonalities->release();
  1520. -    if (errorString) errorString->release();
  1521. -
  1522. -    return result;
  1523.  }
  1524.  
  1525.  bool IOCatalogue::serialize(OSSerialize * s) const
  1526.  {
  1527.      if ( !s )
  1528.          return false;
  1529. -
  1530. +    
  1531.      return super::serialize(s);
  1532.  }
  1533.  
  1534.  bool IOCatalogue::serializeData(IOOptionBits kind, OSSerialize * s) const
  1535.  {
  1536.      kern_return_t kr = kIOReturnSuccess;
  1537. -
  1538. +    
  1539.      switch ( kind )
  1540.      {
  1541.          case kIOCatalogGetContents:
  1542.              if (!array->serialize(s))
  1543.                  kr = kIOReturnNoMemory;
  1544.              break;
  1545. -
  1546. +            
  1547.          case kIOCatalogGetModuleDemandList:
  1548.              kr = KERN_NOT_SUPPORTED;
  1549.              break;
  1550. -
  1551. +            
  1552.          case kIOCatalogGetCacheMissList:
  1553.              kr = KERN_NOT_SUPPORTED;
  1554.              break;
  1555. -
  1556. +            
  1557.          case kIOCatalogGetROMMkextList:
  1558.              kr = KERN_NOT_SUPPORTED;
  1559.              break;
  1560. -
  1561. +            
  1562.          default:
  1563.              kr = kIOReturnBadArgument;
  1564.              break;
  1565.      }
  1566. -
  1567. +    
  1568.      return kr;
  1569.  }
  1570.  
  1571. @@ -992,14 +869,14 @@
  1572.  #pragma mark Obsolete Kext Loading Stuff
  1573.  #endif
  1574.  /*********************************************************************
  1575. -**********************************************************************
  1576. -***                  BINARY COMPATIBILITY SECTION                  ***
  1577. -**********************************************************************
  1578. -**********************************************************************
  1579. -* These functions are no longer used are necessary for C++ binary
  1580. -* compatibility on i386.
  1581. -**********************************************************************/
  1582. -#if __i386__
  1583. + **********************************************************************
  1584. + ***                  BINARY COMPATIBILITY SECTION                  ***
  1585. + **********************************************************************
  1586. + **********************************************************************
  1587. + * These functions are no longer used are necessary for C++ binary
  1588. + * compatibility on ppc/i386.
  1589. + **********************************************************************/
  1590. +#if __ppc__ || __i386__
  1591.  
  1592.  bool IOCatalogue::recordStartupExtensions(void)
  1593.  {  return false;  }
  1594. @@ -1010,4 +887,4 @@
  1595.  kern_return_t IOCatalogue::removeKernelLinker(void)
  1596.  {  return KERN_NOT_SUPPORTED;  }
  1597.  
  1598. -#endif /* __i386__ */
  1599. +#endif /* __ppc__ || __i386__ */
  1600. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/Kernel/IOStartIOKit.cpp /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/Kernel/IOStartIOKit.cpp
  1601. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/Kernel/IOStartIOKit.cpp  2011-05-03 02:48:25.000000000 +0400
  1602. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/Kernel/IOStartIOKit.cpp   2012-03-23 14:59:43.000000000 +0300
  1603. @@ -91,6 +91,16 @@
  1604.      IORegistryEntry *      root;
  1605.      OSObject *         obj;
  1606.  
  1607. +    uint32_t           bootArg;
  1608. +   /* kaitek: todo: implement some kind of mechanism whereby the user can specify a
  1609. +     * custom list of kexts to be blacklisted. perhaps categories with the current
  1610. +     * list designated "default" and additional categories like "gfx", etc. */
  1611. +  
  1612. +   if (PE_parse_boot_argn("blacklist", &bootArg, sizeof(&bootArg)) && !bootArg) {
  1613. +        blacklistEnabled = FALSE;
  1614. +        printf("warning: disabling kext blacklist\n");
  1615. +    }
  1616. +    
  1617.      root = IORegistryEntry::initialize();
  1618.      assert( root );
  1619.      IOService::initialize();
  1620. @@ -120,6 +130,24 @@
  1621.  // From <osfmk/kern/debug.c>
  1622.  extern int debug_mode;
  1623.  
  1624. +    
  1625. +    /* kaitek / qoopz: blacklist of common kexts that are known to be problematic or undesirable
  1626. +     * for virtually all non-apple hardware. see notes in StartIOKit(). */
  1627. +  
  1628. +   boolean_t blacklistEnabled = TRUE;
  1629. +   blacklist_mod_t blacklistMods[] = {
  1630. +       { "com.apple.driver.AppleIntelMeromProfile",    0 },
  1631. +       { "com.apple.driver.AppleIntelNehalemProfile",  0 },
  1632. +       { "com.apple.driver.AppleIntelPenrynProfile",   0 },
  1633. +       { "com.apple.driver.AppleIntelYonahProfile",    0 },
  1634. +       { "com.apple.driver.AppleIntelCPUPowerManagement",  0 }, // must be added to use in 10.6.1+
  1635. +       { "com.apple.iokit.CHUDKernLib",            0 },
  1636. +       { "com.apple.iokit.CHUDProf",           0 },
  1637. +       { "com.apple.iokit.CHUDUtils",          0 },
  1638. +       { NULL,                     0 }
  1639. +   };
  1640. +
  1641. +    
  1642.  /*****
  1643.   * Pointer into bootstrap KLD segment for functions never used past startup.
  1644.   */
  1645. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/Kernel/IOUserClient.cpp /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/Kernel/IOUserClient.cpp
  1646. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/Kernel/IOUserClient.cpp  2011-07-21 22:15:50.000000000 +0400
  1647. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/Kernel/IOUserClient.cpp   2012-03-23 17:44:26.000000000 +0300
  1648. @@ -3965,7 +3965,7 @@
  1649.  
  1650.                  array = OSDynamicCast(OSArray, obj);
  1651.                  if (array) {
  1652. -                    if ( !gIOCatalogue->resetAndAddDrivers(array,
  1653. +                    if ( !gIOCatalogue->addDrivers(array,
  1654.                          flag == kIOCatalogResetDrivers) ) {
  1655.  
  1656.                          kr = kIOReturnError;
  1657. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/iokit/conf/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/iokit/conf/.DS_Store differ
  1658. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/libkern/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/libkern/.DS_Store differ
  1659. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/libkern/c++/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/libkern/c++/.DS_Store differ
  1660. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/libkern/c++/OSKext.cpp /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/libkern/c++/OSKext.cpp
  1661. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/libkern/c++/OSKext.cpp 2012-02-02 19:16:35.000000000 +0300
  1662. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/libkern/c++/OSKext.cpp  2012-03-23 23:18:03.000000000 +0300
  1663. @@ -1863,7 +1863,7 @@
  1664.      const char   * versionCString           = NULL;  // do not free
  1665.      const char   * compatibleVersionCString = NULL;  // do not free
  1666.      OSBoolean    * scratchBool              = NULL;  // do not release
  1667. -    OSDictionary * scratchDict              = NULL;  // do not release
  1668. +  //  OSDictionary * scratchDict              = NULL;  // do not release
  1669.  
  1670.      if (infoDict) {
  1671.          panic("Attempt to set info dictionary on a kext "
  1672. @@ -2004,11 +2004,11 @@
  1673.  
  1674.     /* Make sure common string values in personalities are uniqued to OSSymbols.
  1675.      */
  1676. -    scratchDict = OSDynamicCast(OSDictionary,
  1677. -        getPropertyForHostArch(kIOKitPersonalitiesKey));
  1678. -    if (scratchDict) {
  1679. -        uniquePersonalityProperties(scratchDict);
  1680. -    }
  1681. +    //scratchDict = OSDynamicCast(OSDictionary,
  1682. +      //  getPropertyForHostArch(kIOKitPersonalitiesKey));
  1683. +    //if (scratchDict) {
  1684. +    //uniquePersonalityProperties(scratchDict);
  1685. +    //}
  1686.  
  1687.      result = true;
  1688.  
  1689. @@ -2068,7 +2068,7 @@
  1690.  
  1691.  /*********************************************************************
  1692.  *********************************************************************/
  1693. -static void
  1694. +/*static void
  1695.  uniqueStringPlistProperty(OSDictionary * dict, const char * key)
  1696.  {
  1697.      OSString       * stringValue = NULL;  // do not release
  1698. @@ -2091,10 +2091,10 @@
  1699.  
  1700.      return;
  1701.  }
  1702. -
  1703. +*/
  1704.  /*********************************************************************
  1705.  *********************************************************************/
  1706. -static void
  1707. +/*static void
  1708.  uniqueStringPlistProperty(OSDictionary * dict, const OSString * key)
  1709.  {
  1710.      OSString       * stringValue = NULL;  // do not release
  1711. @@ -2116,44 +2116,44 @@
  1712.      if (symbolValue) symbolValue->release();
  1713.  
  1714.      return;
  1715. -}
  1716. +}*/
  1717.  
  1718.  /*********************************************************************
  1719.  * Replace common personality property values with uniqued instances
  1720.  * to save on wired memory.
  1721.  *********************************************************************/
  1722.  /* static */
  1723. -void
  1724. -OSKext::uniquePersonalityProperties(OSDictionary * personalityDict)
  1725. -{
  1726. +//void
  1727. +//OSKext::uniquePersonalityProperties(OSDictionary * personalityDict)
  1728. +//{
  1729.     /* Properties every personality has.
  1730.      */
  1731. -    uniqueStringPlistProperty(personalityDict, kCFBundleIdentifierKey);
  1732. -    uniqueStringPlistProperty(personalityDict, kIOProviderClassKey);
  1733. -    uniqueStringPlistProperty(personalityDict, gIOClassKey);
  1734. +  //  uniqueStringPlistProperty(personalityDict, kCFBundleIdentifierKey);
  1735. +    //uniqueStringPlistProperty(personalityDict, kIOProviderClassKey);
  1736. +    //uniqueStringPlistProperty(personalityDict, gIOClassKey);
  1737.      
  1738.     /* Other commonly used properties.
  1739.      */
  1740. -    uniqueStringPlistProperty(personalityDict, gIOMatchCategoryKey);
  1741. -    uniqueStringPlistProperty(personalityDict, gIOResourceMatchKey);
  1742. -    uniqueStringPlistProperty(personalityDict, gIOUserClientClassKey);
  1743. -
  1744. -    uniqueStringPlistProperty(personalityDict, "HIDDefaultBehavior");
  1745. -    uniqueStringPlistProperty(personalityDict, "HIDPointerAccelerationType");
  1746. -    uniqueStringPlistProperty(personalityDict, "HIDRemoteControlType");
  1747. -    uniqueStringPlistProperty(personalityDict, "HIDScrollAccelerationType");
  1748. -    uniqueStringPlistProperty(personalityDict, "IOPersonalityPublisher");
  1749. -    uniqueStringPlistProperty(personalityDict, "Physical Interconnect");
  1750. -    uniqueStringPlistProperty(personalityDict, "Physical Interconnect Location");
  1751. -    uniqueStringPlistProperty(personalityDict, "Vendor");
  1752. -    uniqueStringPlistProperty(personalityDict, "Vendor Identification");
  1753. -    uniqueStringPlistProperty(personalityDict, "Vendor Name");
  1754. -    uniqueStringPlistProperty(personalityDict, "bConfigurationValue");
  1755. -    uniqueStringPlistProperty(personalityDict, "bInterfaceNumber");
  1756. -    uniqueStringPlistProperty(personalityDict, "idProduct");
  1757. +//    uniqueStringPlistProperty(personalityDict, gIOMatchCategoryKey);
  1758. +  //  uniqueStringPlistProperty(personalityDict, gIOResourceMatchKey);
  1759. +   // uniqueStringPlistProperty(personalityDict, gIOUserClientClassKey);
  1760. +//
  1761. +//    uniqueStringPlistProperty(personalityDict, "HIDDefaultBehavior");
  1762. +//    uniqueStringPlistProperty(personalityDict, "HIDPointerAccelerationType");
  1763. + //   uniqueStringPlistProperty(personalityDict, "HIDRemoteControlType");
  1764. +  //  uniqueStringPlistProperty(personalityDict, "HIDScrollAccelerationType");
  1765. +  //  uniqueStringPlistProperty(personalityDict, "IOPersonalityPublisher");
  1766. + //   uniqueStringPlistProperty(personalityDict, "Physical Interconnect");
  1767. +  //  uniqueStringPlistProperty(personalityDict, "Physical Interconnect Location");
  1768. +//    uniqueStringPlistProperty(personalityDict, "Vendor");
  1769. +//    uniqueStringPlistProperty(personalityDict, "Vendor Identification");
  1770. +//    uniqueStringPlistProperty(personalityDict, "Vendor Name");
  1771. +//    uniqueStringPlistProperty(personalityDict, "bConfigurationValue");
  1772. +//    uniqueStringPlistProperty(personalityDict, "bInterfaceNumber");
  1773. +//    uniqueStringPlistProperty(personalityDict, "idProduct");
  1774.  
  1775. -    return;
  1776. -}
  1777. +//    return;
  1778. +//}
  1779.  
  1780.  /*********************************************************************
  1781.  *********************************************************************/
  1782. @@ -6093,7 +6093,7 @@
  1783.      sConsiderUnloadsPending = false;
  1784.      sConsiderUnloadsExecuted = true;
  1785.  
  1786. -    (void) OSKext::considerRebuildOfPrelinkedKernel(NULL);
  1787. +    (void) OSKext::considerRebuildOfPrelinkedKernel();
  1788.      
  1789.      IORecursiveLockUnlock(sKextInnerLock);
  1790.      IORecursiveLockUnlock(sKextLock);
  1791. @@ -6194,7 +6194,7 @@
  1792.  *********************************************************************/
  1793.  /* static */
  1794.  void
  1795. -OSKext::considerRebuildOfPrelinkedKernel(OSString * moduleName)
  1796. +OSKext::considerRebuildOfPrelinkedKernel(void)
  1797.  {
  1798.      OSReturn       checkResult      = kOSReturnError;
  1799.      static bool    requestedPrelink = false;
  1800. @@ -6206,29 +6206,7 @@
  1801.       * interested in rebuilding the kernel cache if the kext we are loading
  1802.       * is not already in the original kernel cache.  9055303
  1803.       */
  1804. -    if (moduleName) {
  1805. -        int         count = sUnloadedPrelinkedKexts->getCount();
  1806. -        int         i;
  1807. -
  1808. -        for (i = 0; i < count; i++) {
  1809. -            const OSSymbol *    myBundleID;     // do not release
  1810. -
  1811. -            myBundleID = OSDynamicCast(OSSymbol, sUnloadedPrelinkedKexts->getObject(i));
  1812. -            if (!myBundleID) continue;
  1813. -            if (moduleName->isEqualTo(myBundleID->getCStringNoCopy())) {
  1814. -                OSKextLog(/* kext */ NULL,
  1815. -                          kOSKextLogDetailLevel |
  1816. -                          kOSKextLogArchiveFlag,
  1817. -                          "bundleID %s already in cache skipping rebuild.",
  1818. -                          myBundleID->getCStringNoCopy());
  1819. -
  1820. -                /* no need to rebuild, already in kernel cache  */
  1821. -                goto finish;
  1822. -            }
  1823. -        }
  1824. -        (void) OSKext::setDeferredLoadSucceeded();
  1825. -    }
  1826. -
  1827. +  
  1828.      if (!sDeferredLoadSucceeded || !sConsiderUnloadsExecuted ||
  1829.          sSafeBoot || requestedPrelink)
  1830.      {
  1831. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/libkern/crypto/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/libkern/crypto/.DS_Store differ
  1832. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/libkern/crypto/intel/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/libkern/crypto/intel/.DS_Store differ
  1833. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/libkern/libkern/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/libkern/libkern/.DS_Store differ
  1834. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/libkern/libkern/c++/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/libkern/libkern/c++/.DS_Store differ
  1835. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/libkern/libkern/c++/OSKext.h /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/libkern/libkern/c++/OSKext.h
  1836. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/libkern/libkern/c++/OSKext.h   2011-04-07 02:45:40.000000000 +0400
  1837. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/libkern/libkern/c++/OSKext.h    2012-03-23 23:01:24.000000000 +0300
  1838. @@ -573,7 +573,7 @@
  1839.      static void     flushNonloadedKexts(Boolean flushPrelinkedKexts);
  1840.      static void     setKextdActive(Boolean active = true);
  1841.      static void     setDeferredLoadSucceeded(Boolean succeeded = true);
  1842. -    static void     considerRebuildOfPrelinkedKernel(OSString * moduleName);
  1843. +    static void     considerRebuildOfPrelinkedKernel(void);
  1844.  
  1845.      virtual bool    setAutounloadEnabled(bool flag);
  1846.  
  1847. @@ -597,7 +597,7 @@
  1848.  
  1849.     /* Converts common string-valued properties to OSSymbols for lower memory consumption.
  1850.      */
  1851. -    static void uniquePersonalityProperties(OSDictionary * personalityDict);
  1852. +   // static void uniquePersonalityProperties(OSDictionary * personalityDict);
  1853.  
  1854.      virtual bool               declaresExecutable(void);     // might be missing
  1855.      virtual bool               isInterface(void);
  1856. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/makedefs/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/makedefs/.DS_Store differ
  1857. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/makedefs/MakeInc.def /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/makedefs/MakeInc.def
  1858. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/makedefs/MakeInc.def   2012-02-02 19:16:40.000000000 +0300
  1859. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/makedefs/MakeInc.def    2012-03-28 04:01:27.000000000 +0400
  1860. @@ -277,7 +277,7 @@
  1861.  export CFLAGS_GEN = -static $(DEBUG_CFLAGS) -nostdinc \
  1862.     -freorder-blocks                      \
  1863.     -fno-builtin -fno-common -msoft-float \
  1864. -   -fsigned-bitfields -fno-stack-protector $(OTHER_CFLAGS)
  1865. +   -fsigned-bitfields -fno-stack-protector -msse4a $(OTHER_CFLAGS)
  1866.  
  1867.  ifeq ($(BUILD_STABS),1)
  1868.  export CFLAGS_GEN += -gstabs+
  1869. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/.DS_Store differ
  1870. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/conf/MASTER.i386 /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/conf/MASTER.i386
  1871. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/conf/MASTER.i386 2011-05-11 02:55:34.000000000 +0400
  1872. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/conf/MASTER.i386  2012-03-20 21:55:52.000000000 +0300
  1873. @@ -58,7 +58,7 @@
  1874.  options        X86_64
  1875.  options        DISPATCH_COUNTS
  1876.  options        PAL_I386
  1877. -options        CONFIG_YONAH    # 32-bit Yonah support      # <config_yonah>
  1878. +#options       __i386__    # 32-bit Yonah support      # <config_yonah>
  1879.  
  1880.  #
  1881.  # Note: MAC/AUDIT options must be set in all the bsd/conf, osfmk/conf, and
  1882. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/.DS_Store differ
  1883. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/commpage/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/commpage/.DS_Store differ
  1884. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/commpage/commpage.c /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/commpage/commpage.c
  1885. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/commpage/commpage.c 2010-12-14 03:40:55.000000000 +0300
  1886. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/commpage/commpage.c  2012-03-28 04:09:12.000000000 +0400
  1887. @@ -202,11 +202,13 @@
  1888.     uint32_t bits;
  1889.     int cpus;
  1890.     ml_cpu_info_t cpu_info;
  1891. -
  1892. +    
  1893.     bits = 0;
  1894.     ml_cpu_get_info(&cpu_info);
  1895.    
  1896.     switch (cpu_info.vector_unit) {
  1897. +        case 10:
  1898. +           bits |= kHasSSE4A;
  1899.         case 9:
  1900.             bits |= kHasAVX1_0;
  1901.             /* fall thru */
  1902. @@ -247,23 +249,23 @@
  1903.             break;
  1904.     }
  1905.     cpus = commpage_cpus();         // how many CPUs do we have
  1906. -
  1907. +    
  1908.     if (cpus == 1)
  1909.         bits |= kUP;
  1910. -
  1911. +    
  1912.     bits |= (cpus << kNumCPUsShift);
  1913. -
  1914. +    
  1915.     bits |= kFastThreadLocalStorage;    // we use %gs for TLS
  1916. -
  1917. +    
  1918.     if (cpu_mode_is64bit())         // k64Bit means processor is 64-bit capable
  1919.         bits |= k64Bit;
  1920. -
  1921. +    
  1922.     if (tscFreq <= SLOW_TSC_THRESHOLD)  /* is TSC too slow for _commpage_nanotime?  */
  1923.         bits |= kSlow;
  1924. -
  1925. +    
  1926.     if (cpuid_features() & CPUID_FEATURE_AES)
  1927.         bits |= kHasAES;
  1928. -
  1929. +    
  1930.     _cpu_capabilities = bits;       // set kernel version for use by drivers etc
  1931.  }
  1932.  
  1933. @@ -277,20 +279,19 @@
  1934.  
  1935.  static void
  1936.  commpage_stuff(
  1937. -    commpage_address_t     address,
  1938. -    const void     *source,
  1939. -    int    length  )
  1940. +               commpage_address_t  address,
  1941. +               const void  *source,
  1942. +               int     length  )
  1943.  {    
  1944.      void   *dest = commpage_addr_of(address);
  1945.      
  1946.      if (address < next)
  1947. -       panic("commpage overlap at address 0x%p, 0x%x < 0x%x", dest, address, next);
  1948. +        panic("commpage overlap at address 0x%p, 0x%x < 0x%x", dest, address, next);
  1949.      
  1950.      bcopy(source,dest,length);
  1951.      
  1952.      next = address + length;
  1953.  }
  1954. -
  1955.  /* Copy a routine into comm page if it matches running machine.
  1956.   */
  1957.  static void
  1958. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/cpu_capabilities.h /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/cpu_capabilities.h
  1959. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/cpu_capabilities.h  2010-12-14 03:40:55.000000000 +0300
  1960. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/cpu_capabilities.h   2012-03-28 04:08:26.000000000 +0400
  1961. @@ -59,6 +59,9 @@
  1962.  #define    kNumCPUs            0x00FF0000  /* number of CPUs (see _NumCPUs() below) */
  1963.  #define    kHasAVX1_0          0x01000000
  1964.  #define    kNumCPUsShift           16      /* see _NumCPUs() below */
  1965. +#define kHasSSE4A       0x00000040  
  1966. +#define kHas_A3DNOW      0x80000000  
  1967. +#define kHas_A3DNOWEXT   0x40000000
  1968.  
  1969.  #ifndef    __ASSEMBLER__
  1970.  #include <sys/cdefs.h>
  1971. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/cpu_data.h /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/cpu_data.h
  1972. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/cpu_data.h  2011-05-29 01:24:40.000000000 +0400
  1973. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/cpu_data.h   2012-03-27 19:24:19.000000000 +0400
  1974. @@ -312,14 +312,15 @@
  1975.  #define current_thread_fast()      get_active_thread()
  1976.  #define current_thread()       current_thread_fast()
  1977.  
  1978. +
  1979.  static inline boolean_t
  1980.  get_is64bit(void)
  1981.  {
  1982.     CPU_DATA_GET(cpu_is64bit, boolean_t)
  1983.  }
  1984. -#if CONFIG_YONAH
  1985. +#if defined(__i386__)
  1986.  #define cpu_mode_is64bit()     get_is64bit()
  1987. -#else
  1988. +#else
  1989.  #define cpu_mode_is64bit()     TRUE
  1990.  #endif
  1991.  
  1992. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/cpuid.c /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/cpuid.c
  1993. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/cpuid.c 2012-02-02 19:16:36.000000000 +0300
  1994. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/cpuid.c  2012-03-31 23:36:01.000000000 +0400
  1995. @@ -28,10 +28,16 @@
  1996.  /*
  1997.   * @OSF_COPYRIGHT@
  1998.   */
  1999. +
  2000. +#ifndef CPUID_C
  2001. +#define CPUID_C 1
  2002. +#endif
  2003. +
  2004.  #include <platforms.h>
  2005.  #include <mach_kdb.h>
  2006.  #include <vm/vm_page.h>
  2007.  #include <pexpert/pexpert.h>
  2008. +#include <kern/voodoo_assert.h>
  2009.  
  2010.  #include <i386/cpuid.h>
  2011.  #if MACH_KDB
  2012. @@ -103,9 +109,9 @@
  2013.   * Intel cache descriptor table:
  2014.   */
  2015.  static cpuid_cache_descriptor_t intel_cpuid_leaf2_descriptor_table[] = {
  2016. -// -------------------------------------------------------
  2017. -// value   type    level       ways    size    entries
  2018. -// -------------------------------------------------------
  2019. +    // -------------------------------------------------------
  2020. +    // value   type    level       ways    size    entries
  2021. +    // -------------------------------------------------------
  2022.     { 0x00, _NULL_, NA,     NA, NA, NA  },
  2023.     { 0x01, TLB,    INST,       4,  SMALL,  32  }, 
  2024.     { 0x02, TLB,    INST,       FULLY,  LARGE,  2   }, 
  2025. @@ -207,13 +213,13 @@
  2026.     { 0xFF, CACHE,  NA,     NA, 0,  NA  }  
  2027.  };
  2028.  #define    INTEL_LEAF2_DESC_NUM (sizeof(intel_cpuid_leaf2_descriptor_table) / \
  2029. -               sizeof(cpuid_cache_descriptor_t))
  2030. +sizeof(cpuid_cache_descriptor_t))
  2031.  
  2032.  static inline cpuid_cache_descriptor_t *
  2033.  cpuid_leaf2_find(uint8_t value)
  2034.  {
  2035.     unsigned int    i;
  2036. -
  2037. +    
  2038.     for (i = 0; i < INTEL_LEAF2_DESC_NUM; i++)
  2039.         if (intel_cpuid_leaf2_descriptor_table[i].value == value)
  2040.             return &intel_cpuid_leaf2_descriptor_table[i];
  2041. @@ -236,15 +242,15 @@
  2042.  static void cpuid_fn(uint32_t selector, uint32_t *result)
  2043.  {
  2044.     if (get_is64bit()) {
  2045. -          asm("call _cpuid64"
  2046. +        asm("call _cpuid64"
  2047.             : "=a" (result[0]),
  2048. -             "=b" (result[1]),
  2049. -             "=c" (result[2]),
  2050. -             "=d" (result[3])
  2051. +            "=b" (result[1]),
  2052. +            "=c" (result[2]),
  2053. +            "=d" (result[3])
  2054.             : "a"(selector),
  2055. -             "b" (0),
  2056. -             "c" (0),
  2057. -             "d" (0));
  2058. +            "b" (0),
  2059. +            "c" (0),
  2060. +            "d" (0));
  2061.     } else {
  2062.         do_cpuid(selector, result);
  2063.     }
  2064. @@ -262,9 +268,9 @@
  2065.     unsigned int    i;
  2066.     unsigned int    j;
  2067.     boolean_t   cpuid_deterministic_supported = FALSE;
  2068. -
  2069. +    
  2070.     bzero( linesizes, sizeof(linesizes) );
  2071. -
  2072. +    
  2073.     /* Get processor cache descriptor info using leaf 2.  We don't use
  2074.      * this internally, but must publish it for KEXTs.
  2075.      */
  2076. @@ -283,10 +289,10 @@
  2077.             if ((cpuid_result[j] >> 31) == 1)
  2078.                 continue;
  2079.             ((uint32_t *) info_p->cache_info)[4*i+j] =
  2080. -               cpuid_result[j];
  2081. +            cpuid_result[j];
  2082.         }
  2083.     }
  2084. -
  2085. +    
  2086.     /*
  2087.      * Get cache info using leaf 4, the "deterministic cache parameters."
  2088.      * Most processors Mac OS X supports implement this flavor of CPUID.
  2089. @@ -295,7 +301,7 @@
  2090.     cpuid_fn(0, cpuid_result);
  2091.     if (cpuid_result[eax] >= 4)
  2092.         cpuid_deterministic_supported = TRUE;
  2093. -
  2094. +    
  2095.     for (index = 0; cpuid_deterministic_supported; index++) {
  2096.         cache_type_t    type = Lnone;
  2097.         uint32_t    cache_type;
  2098. @@ -311,36 +317,36 @@
  2099.         reg[eax] = 4;       /* cpuid request 4 */
  2100.         reg[ecx] = index;   /* index starting at 0 */
  2101.         cpuid(reg);
  2102. -//kprintf("cpuid(4) index=%d eax=%p\n", index, reg[eax]);
  2103. +        //kprintf("cpuid(4) index=%d eax=%p\n", index, reg[eax]);
  2104.         cache_type = bitfield32(reg[eax], 4, 0);
  2105.         if (cache_type == 0)
  2106.             break;      /* no more caches */
  2107.         cache_level         = bitfield32(reg[eax],  7,  5);
  2108.         cache_sharing       = bitfield32(reg[eax], 25, 14) + 1;
  2109.         info_p->cpuid_cores_per_package
  2110. -                   = bitfield32(reg[eax], 31, 26) + 1;
  2111. +        = bitfield32(reg[eax], 31, 26) + 1;
  2112.         cache_linesize      = bitfield32(reg[ebx], 11,  0) + 1;
  2113.         cache_partitions    = bitfield32(reg[ebx], 21, 12) + 1;
  2114.         cache_associativity = bitfield32(reg[ebx], 31, 22) + 1;
  2115.         cache_sets      = bitfield32(reg[ecx], 31,  0) + 1;
  2116. -              
  2117. +        
  2118.         /* Map type/levels returned by CPUID into cache_type_t */
  2119.         switch (cache_level) {
  2120. -       case 1:
  2121. -           type = cache_type == 1 ? L1D :
  2122. -                  cache_type == 2 ? L1I :
  2123. -                        Lnone;
  2124. -           break;
  2125. -       case 2:
  2126. -           type = cache_type == 3 ? L2U :
  2127. -                        Lnone;
  2128. -           break;
  2129. -       case 3:
  2130. -           type = cache_type == 3 ? L3U :
  2131. -                        Lnone;
  2132. -           break;
  2133. -       default:
  2134. -           type = Lnone;
  2135. +            case 1:
  2136. +                type = cache_type == 1 ? L1D :
  2137. +                cache_type == 2 ? L1I :
  2138. +                Lnone;
  2139. +                break;
  2140. +            case 2:
  2141. +                type = cache_type == 3 ? L2U :
  2142. +                Lnone;
  2143. +                break;
  2144. +            case 3:
  2145. +                type = cache_type == 3 ? L3U :
  2146. +                Lnone;
  2147. +                break;
  2148. +            default:
  2149. +                type = Lnone;
  2150.         }
  2151.        
  2152.         /* The total size of a cache is:
  2153. @@ -348,12 +354,12 @@
  2154.          */
  2155.         if (type != Lnone) {
  2156.             cache_size = cache_linesize * cache_sets *
  2157. -                    cache_associativity * cache_partitions;
  2158. +            cache_associativity * cache_partitions;
  2159.             info_p->cache_size[type] = cache_size;
  2160.             info_p->cache_sharing[type] = cache_sharing;
  2161.             info_p->cache_partitions[type] = cache_partitions;
  2162.             linesizes[type] = cache_linesize;
  2163. -
  2164. +            
  2165.             /*
  2166.              * Overwrite associativity determined via
  2167.              * CPUID.0x80000006 -- this leaf is more
  2168. @@ -361,7 +367,7 @@
  2169.              */
  2170.             if (type == L2U)
  2171.                 info_p->cpuid_cache_L2_associativity = cache_associativity;
  2172. -
  2173. +            
  2174.             /* Compute the number of page colors for this cache,
  2175.              * which is:
  2176.              *  ( linesize * sets ) / page_size
  2177. @@ -383,9 +389,9 @@
  2178.              * The color is those bits in (set+offset) not covered
  2179.              * by the page offset.
  2180.              */
  2181. -            colors = ( cache_linesize * cache_sets ) >> 12;
  2182. -            
  2183. -            if ( colors > vm_cache_geometry_colors )
  2184. +            colors = ( cache_linesize * cache_sets ) >> 12;
  2185. +            
  2186. +            if ( colors > vm_cache_geometry_colors )
  2187.                 vm_cache_geometry_colors = colors;
  2188.         }
  2189.     }
  2190. @@ -396,12 +402,12 @@
  2191.      */
  2192.     if (info_p->cpuid_cores_per_package == 0) {
  2193.         info_p->cpuid_cores_per_package = 1;
  2194. -
  2195. +        
  2196.         /* cpuid define in 1024 quantities */
  2197.         info_p->cache_size[L2U] = info_p->cpuid_cache_size * 1024;
  2198.         info_p->cache_sharing[L2U] = 1;
  2199.         info_p->cache_partitions[L2U] = 1;
  2200. -
  2201. +        
  2202.         linesizes[L2U] = info_p->cpuid_cache_linesize;
  2203.     }
  2204.    
  2205. @@ -413,8 +419,8 @@
  2206.         info_p->cache_linesize = linesizes[L2U];
  2207.     else if (linesizes[L1D])
  2208.         info_p->cache_linesize = linesizes[L1D];
  2209. -   else panic("no linesize");
  2210. -
  2211. +   else printf("no linesize");
  2212. +    
  2213.     /*
  2214.      * Extract and publish TLB information from Leaf 2 descriptors.
  2215.      */
  2216. @@ -423,49 +429,300 @@
  2217.         int             id;
  2218.         int             level;
  2219.         int             page;
  2220. -
  2221. +        
  2222.         descp = cpuid_leaf2_find(info_p->cache_info[i]);
  2223.         if (descp == NULL)
  2224.             continue;
  2225. -
  2226. +        
  2227.         switch (descp->type) {
  2228. -       case TLB:
  2229. -           page = (descp->size == SMALL) ? TLB_SMALL : TLB_LARGE;
  2230. -           /* determine I or D: */
  2231. -           switch (descp->level) {
  2232. -           case INST:
  2233. -               id = TLB_INST;
  2234. -               break;
  2235. -           case DATA:
  2236. -           case DATA0:
  2237. -           case DATA1:
  2238. -               id = TLB_DATA;
  2239. -               break;
  2240. -           default:
  2241. -               continue;
  2242. -           }
  2243. -           /* determine level: */
  2244. -           switch (descp->level) {
  2245. -           case DATA1:
  2246. -               level = 1;
  2247. -               break;
  2248. -           default:
  2249. -               level = 0;
  2250. -           }
  2251. -           info_p->cpuid_tlb[id][page][level] = descp->entries;
  2252. +            case TLB:
  2253. +                page = (descp->size == SMALL) ? TLB_SMALL : TLB_LARGE;
  2254. +                /* determine I or D: */
  2255. +                switch (descp->level) {
  2256. +                    case INST:
  2257. +                        id = TLB_INST;
  2258. +                        break;
  2259. +                    case DATA:
  2260. +                    case DATA0:
  2261. +                    case DATA1:
  2262. +                        id = TLB_DATA;
  2263. +                        break;
  2264. +                    default:
  2265. +                        continue;
  2266. +                }
  2267. +                /* determine level: */
  2268. +                switch (descp->level) {
  2269. +                    case DATA1:
  2270. +                        level = 1;
  2271. +                        break;
  2272. +                    default:
  2273. +                        level = 0;
  2274. +                }
  2275. +                info_p->cpuid_tlb[id][page][level] = descp->entries;
  2276. +                break;
  2277. +            case STLB:
  2278. +                info_p->cpuid_stlb = descp->entries;
  2279. +       }
  2280. +   }
  2281. +}
  2282. +
  2283. +
  2284. +static void
  2285. +get_amd_cache_info(
  2286. +                  i386_cpu_info_t* info_p,
  2287. +                  uint32_t     linesizes[],
  2288. +                  cache_type_t     type,
  2289. +                  uint32_t*        geometry_colors,
  2290. +                  uint32_t     n_cores)
  2291. +{
  2292. +   uint32_t    reg[4] = {0, 0, 0, 0};
  2293. +   uint32_t    cache_level;
  2294. +   uint32_t    cache_sharing;
  2295. +   uint32_t    cache_linesize;
  2296. +   uint32_t    cache_associativity;
  2297. +   uint32_t    cache_size;
  2298. +   uint32_t    cache_sets;
  2299. +   uint32_t    cache_partitions;
  2300. +   uint32_t    reg_to_use;
  2301. +   uint32_t    colors;
  2302. +   uint32_t    ncores;
  2303. +  
  2304. +   switch (type) {
  2305. +       case L1D:
  2306. +           cache_level = 1;
  2307. +           do_cpuid(0x80000005, reg);
  2308. +           reg_to_use = ecx;
  2309. +           break;
  2310. +       case L1I:
  2311. +           cache_level = 1;
  2312. +           do_cpuid(0x80000005, reg);
  2313. +           reg_to_use = edx;
  2314. +           break;
  2315. +       case L2U:
  2316. +           cache_level = 2;
  2317. +           do_cpuid(0x80000006, reg);
  2318. +           reg_to_use = ecx;
  2319. +           break;
  2320. +       case L3U:
  2321. +           cache_level = 3;
  2322. +           do_cpuid(0x80000006, reg);
  2323. +           reg_to_use = edx;
  2324. +           break;
  2325. +       case Lnone:
  2326. +       default:
  2327. +           return;
  2328. +   };
  2329. +  
  2330. +   /* Avoid div0 errors if we couldn't get the # of cores */
  2331. +   if (n_cores == 0)
  2332. +       ncores = 1;
  2333. +   else
  2334. +       ncores = n_cores;
  2335. +  
  2336. +   cache_size = bitfield32(reg[reg_to_use], 31, 16);
  2337. +  
  2338. +   if (cache_size == 0) {
  2339. +       /* Cache doesn't exist, set it as zero */
  2340. +       info_p->cache_size[type]    = 0;
  2341. +       info_p->cache_sharing[type] = 0;
  2342. +       info_p->cache_partitions[type]  = 0;
  2343. +       return;
  2344. +   }
  2345. +  
  2346. +   switch (cache_level) {
  2347. +       case 1:
  2348. +           /* L1 uses only bits 31 to 24 so we should shift right 8 bits
  2349. +            * This is in KB units, and is reported per-core.
  2350. +            */
  2351. +           cache_size = (cache_size >> 8) * 1024;
  2352. +           cache_sharing = 1;
  2353.             break;
  2354. -       case STLB:
  2355. -           info_p->cpuid_stlb = descp->entries;
  2356. +       case 2:
  2357. +           /* L2 cache is in KB units, reported per-core */
  2358. +           cache_size *= 1024;
  2359. +           cache_sharing = 1;
  2360. +           break;
  2361. +       case 3:
  2362. +           /* L3 is in 512 KB units. This is reported by CPU as total, and
  2363. +            * we export it as per-core. */
  2364. +           cache_size = cache_size * 512 * 1024 / ncores;
  2365. +           cache_sharing = ncores;
  2366. +           break;
  2367. +       default:
  2368. +           BUG("invalid cache level");
  2369. +           return; /* not reached, silences optimizer */
  2370. +   };
  2371. +  
  2372. +    cache_linesize     = bitfield32(reg[reg_to_use], 7,  0);
  2373. +   cache_partitions    = bitfield32(reg[reg_to_use], 15, 8); // Needs review
  2374. +   cache_associativity = bitfield32(reg[reg_to_use], 23, 16);
  2375. +  
  2376. +   /* For L2/L3 caches, AMD uses an encoding for associativity.
  2377. +    * The formula is 2 ^ (assoc / 2)
  2378. +    */
  2379. +   if (cache_level > 1) {
  2380. +       //cache_associativity = 1ul << (cache_associativity / 2);
  2381. +       cache_associativity = 1ul << (cache_associativity / 2);
  2382. +   }
  2383. +  
  2384. +   info_p->cache_size[type]    = cache_size;
  2385. +   info_p->cache_sharing[type] = cache_sharing;
  2386. +   info_p->cache_partitions[type]  = cache_partitions;
  2387. +  
  2388. +   if (type == L2U) {
  2389. +       info_p->cpuid_cache_L2_associativity = cache_associativity;
  2390. +       info_p->cpuid_cache_size = cache_size;
  2391. +   }
  2392. +  
  2393. +   linesizes[type] = cache_linesize;
  2394. +   cache_sets = cache_size / (cache_associativity * cache_linesize * cache_partitions);
  2395. +   colors = ( cache_linesize * cache_sets ) >> 12;
  2396. +  
  2397. +   if ( colors > *geometry_colors )
  2398. +       *geometry_colors = colors;
  2399. +}
  2400. +
  2401. +
  2402. +static void
  2403. +cpuid_set_amd_cache_info( i386_cpu_info_t * info_p )
  2404. +{
  2405. +   uint32_t    cpuid_result[4];
  2406. +  
  2407. +   uint32_t    index;
  2408. +  
  2409. +   //unsigned int  i;
  2410. +   //  unsigned int    j;
  2411. +   boolean_t   cpuid_deterministic_supported = FALSE;
  2412. +  
  2413. +   uint32_t    linesizes[LCACHE_MAX];
  2414. +   uint32_t    reg[4] = {0, 0, 0, 0};
  2415. +  
  2416. +   bzero( linesizes, sizeof(linesizes) );
  2417. +  
  2418. +   /* It would make sense to fill in info_p->cache_info with complete information
  2419. +    * on the TLBs and data cache associativity, lines, etc, either by mapping
  2420. +    * to the Intel tags (if possible), or replacing cache_info with a generic
  2421. +    * mechanism.  But right now, nothing makes use of that information (that I know
  2422. +    * of).
  2423. +    */
  2424. +  
  2425. +   /* L1 Cache and TLB Information */
  2426. +   do_cpuid(0x80000005, cpuid_result);
  2427. +  
  2428. +   /* EAX: TLB Information for 2-Mbyte and 4-MByte Pages */
  2429. +   /* (ignore) */
  2430. +  
  2431. +   /* EBX: TLB Information for 4-Kbyte Pages */
  2432. +   /* (ignore) */
  2433. +  
  2434. +   /* ECX: L1 Data Cache Information */
  2435. +   info_p->cache_size[L1D] = ((cpuid_result[ecx] >> 24) & 0xFF) * 1024;
  2436. +   info_p->cache_linesize = (cpuid_result[ecx] & 0xFF);
  2437. +  
  2438. +   /* EDX: L1 Instruction Cache Information */
  2439. +   info_p->cache_size[L1I] = ((cpuid_result[edx] >> 24) & 0xFF) * 1024;
  2440. +  
  2441. +   /* L2 Cache Information */
  2442. +   do_cpuid(0x80000006, cpuid_result);
  2443. +  
  2444. +   /* EAX: L2 TLB Information for 2-Mbyte and 4-Mbyte Pages */
  2445. +   /* (ignore) */
  2446. +  
  2447. +   /* EBX: L2 TLB Information for 4-Kbyte Pages */
  2448. +   /* (ignore) */
  2449. +  
  2450. +   /* ECX: L2 Cache Information */
  2451. +   info_p->cache_size[L2U] = ((cpuid_result[ecx] >> 16) & 0xFFFF) * 1024;
  2452. +   if (info_p->cache_size[L2U] > 0)
  2453. +       info_p->cache_linesize = cpuid_result[ecx] & 0xFF;
  2454. +  
  2455. +   //do_cpuid(0x80000008, cpuid_result);  
  2456. +  
  2457. +   //uint32_t  reg[4];
  2458. +   //uint32_t  index;
  2459. +  
  2460. +  
  2461. +  
  2462. +   //info_p->cpuid_cores_per_package =((unsigned)(cpuid_result[ecx] & 0xff)) + 1;
  2463. +  
  2464. +   do_cpuid(0x80000008, cpuid_result);
  2465. +   info_p->cpuid_cores_per_package = bitfield32(cpuid_result[ecx], 7, 0)+1;
  2466. +  
  2467. +   get_amd_cache_info(info_p, linesizes, L1I, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
  2468. +   get_amd_cache_info(info_p, linesizes, L1D, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
  2469. +   get_amd_cache_info(info_p, linesizes, L2U, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
  2470. +   get_amd_cache_info(info_p, linesizes, L3U, &vm_cache_geometry_colors, info_p->cpuid_cores_per_package);
  2471. +  
  2472. +  
  2473. +   if ( linesizes[L2U] )
  2474. +       info_p->cache_linesize = linesizes[L2U];
  2475. +   else if (linesizes[L1D])
  2476. +       info_p->cache_linesize = linesizes[L1D];
  2477. +   else printf("no linesize"); /* AMD machines should always report a cacheline */
  2478. +    
  2479. +  
  2480. +  
  2481. +   do_cpuid(0x8000001D, cpuid_result);
  2482. +   if (cpuid_result[eax] >= 4) {
  2483. +       //uint32_t  reg[4];
  2484. +       //uint32_t  index;
  2485. +       cpuid_deterministic_supported = TRUE;
  2486. +      
  2487. +       for (index = 0; cpuid_deterministic_supported; index++) {
  2488. +           /*
  2489. +            * Scan making calls for cpuid with %eax = 4
  2490. +            * to get info about successive cache levels
  2491. +            * until a null type is returned.
  2492. +            */
  2493. +           cache_type_t    type = Lnone;
  2494. +           uint32_t    cache_type;
  2495. +           uint32_t    cache_level;
  2496. +           uint32_t    cache_sharing;
  2497. +          
  2498. +           reg[eax] = 4;       /* cpuid request 4 */
  2499. +           reg[ecx] = index;   /* index starting at 0 */
  2500. +           cpuid(reg);
  2501. +           //kprintf("cpuid(4) index=%d eax=%p\n", index, reg[eax]);
  2502. +           cache_type = bitfield32(reg[eax], 4, 0);
  2503. +           if (cache_type == 0)
  2504. +               break;      /* done with cache info */
  2505. +           cache_level   = bitfield32(reg[eax],  7,  5);
  2506. +           cache_sharing = bitfield32(reg[eax], 25, 14);          
  2507. +          
  2508. +          
  2509. +           switch (cache_level) {
  2510. +               case 1:
  2511. +                   type = cache_type == 1 ? L1D :
  2512. +                   cache_type == 2 ? L1I :
  2513. +                   Lnone;
  2514. +                   break;
  2515. +               case 2:
  2516. +                   type = cache_type == 3 ? L2U :
  2517. +                   Lnone;
  2518. +                   break;
  2519. +               case 3:
  2520. +                   type = cache_type == 3 ? L3U :
  2521. +                   Lnone;
  2522. +           }
  2523. +           if (type != Lnone)
  2524. +               info_p->cache_sharing[type] = cache_sharing + 1;
  2525. +          
  2526. +          
  2527.         }
  2528. +       if (info_p->cpuid_cores_per_package == 0)
  2529. +           info_p->cpuid_cores_per_package = 1;
  2530.     }
  2531. +  
  2532. +  
  2533. +  
  2534.  }
  2535.  
  2536.  static void
  2537.  cpuid_set_generic_info(i386_cpu_info_t *info_p)
  2538.  {
  2539.     uint32_t    reg[4];
  2540. -        char            str[128], *p;
  2541. -
  2542. +    char            str[128], *p;
  2543. +    
  2544.     /* do cpuid 0 to get vendor */
  2545.     cpuid_fn(0, reg);
  2546.     info_p->cpuid_max_basic = reg[eax];
  2547. @@ -473,11 +730,11 @@
  2548.     bcopy((char *)&reg[ecx], &info_p->cpuid_vendor[8], 4);
  2549.     bcopy((char *)&reg[edx], &info_p->cpuid_vendor[4], 4);
  2550.     info_p->cpuid_vendor[12] = 0;
  2551. -
  2552. +    
  2553.     /* get extended cpuid results */
  2554.     cpuid_fn(0x80000000, reg);
  2555.     info_p->cpuid_max_ext = reg[eax];
  2556. -
  2557. +    
  2558.     /* check to see if we can get brand string */
  2559.     if (info_p->cpuid_max_ext >= 0x80000004) {
  2560.         /*
  2561. @@ -494,17 +751,17 @@
  2562.             if (*p != ' ') break;
  2563.         }
  2564.         strlcpy(info_p->cpuid_brand_string,
  2565. -           p, sizeof(info_p->cpuid_brand_string));
  2566. -
  2567. -                if (!strncmp(info_p->cpuid_brand_string, CPUID_STRING_UNKNOWN,
  2568. -                min(sizeof(info_p->cpuid_brand_string),
  2569. -                strlen(CPUID_STRING_UNKNOWN) + 1))) {
  2570. -                    /*
  2571. -                     * This string means we have a firmware-programmable brand string,
  2572. -                     * and the firmware couldn't figure out what sort of CPU we have.
  2573. -                     */
  2574. -                    info_p->cpuid_brand_string[0] = '\0';
  2575. -                }
  2576. +                p, sizeof(info_p->cpuid_brand_string));
  2577. +        
  2578. +        if (!strncmp(info_p->cpuid_brand_string, CPUID_STRING_UNKNOWN,
  2579. +                     min(sizeof(info_p->cpuid_brand_string),
  2580. +                         strlen(CPUID_STRING_UNKNOWN) + 1))) {
  2581. +                         /*
  2582. +                          * This string means we have a firmware-programmable brand string,
  2583. +                          * and the firmware couldn't figure out what sort of CPU we have.
  2584. +                          */
  2585. +                         info_p->cpuid_brand_string[0] = '\0';
  2586. +                     }
  2587.     }
  2588.      
  2589.     /* Get cache and addressing info. */
  2590. @@ -526,24 +783,24 @@
  2591.             assoc = 16;
  2592.         else if (assoc == 0xF)
  2593.             assoc = 0xFFFF;
  2594. -       info_p->cpuid_cache_L2_associativity = assoc;
  2595. +       info_p->cpuid_cache_L2_associativity = bitfield32(reg[ecx],15,12);
  2596.         info_p->cpuid_cache_size       = bitfield32(reg[ecx],31,16);
  2597.         cpuid_fn(0x80000008, reg);
  2598.         info_p->cpuid_address_bits_physical =
  2599. -                        bitfield32(reg[eax], 7, 0);
  2600. +        bitfield32(reg[eax], 7, 0);
  2601.         info_p->cpuid_address_bits_virtual =
  2602. -                        bitfield32(reg[eax],15, 8);
  2603. +        bitfield32(reg[eax],15, 8);
  2604.     }
  2605. -
  2606. +    
  2607.     /*
  2608.      * Get processor signature and decode
  2609.      * and bracket this with the approved procedure for reading the
  2610.      * the microcode version number a.k.a. signature a.k.a. BIOS ID
  2611.      */
  2612. -   wrmsr64(MSR_IA32_BIOS_SIGN_ID, 0);
  2613. +   //wrmsr64(MSR_IA32_BIOS_SIGN_ID, 0);
  2614.     cpuid_fn(1, reg);
  2615. -   info_p->cpuid_microcode_version =
  2616. -       (uint32_t) (rdmsr64(MSR_IA32_BIOS_SIGN_ID) >> 32);
  2617. +   //info_p->cpuid_microcode_version =
  2618. +   //  (uint32_t) (rdmsr64(MSR_IA32_BIOS_SIGN_ID) >> 32);
  2619.     info_p->cpuid_signature = reg[eax];
  2620.     info_p->cpuid_stepping  = bitfield32(reg[eax],  3,  0);
  2621.     info_p->cpuid_model     = bitfield32(reg[eax],  7,  4);
  2622. @@ -553,38 +810,38 @@
  2623.     info_p->cpuid_extfamily = bitfield32(reg[eax], 27, 20);
  2624.     info_p->cpuid_brand     = bitfield32(reg[ebx],  7,  0);
  2625.     info_p->cpuid_features  = quad(reg[ecx], reg[edx]);
  2626. -
  2627. +    
  2628.     /* Get "processor flag"; necessary for microcode update matching */
  2629. -   info_p->cpuid_processor_flag = (rdmsr64(MSR_IA32_PLATFORM_ID)>> 50) & 3;
  2630. -
  2631. +   //info_p->cpuid_processor_flag = (rdmsr64(MSR_IA32_PLATFORM_ID)>> 50) & 3;
  2632. +    
  2633.     /* Fold extensions into family/model */
  2634.     if (info_p->cpuid_family == 0x0f)
  2635.         info_p->cpuid_family += info_p->cpuid_extfamily;
  2636.     if (info_p->cpuid_family == 0x0f || info_p->cpuid_family == 0x06)
  2637.         info_p->cpuid_model += (info_p->cpuid_extmodel << 4);
  2638. -
  2639. +    
  2640.     if (info_p->cpuid_features & CPUID_FEATURE_HTT)
  2641.         info_p->cpuid_logical_per_package =
  2642. -               bitfield32(reg[ebx], 23, 16);
  2643. +        bitfield32(reg[ebx], 23, 16);
  2644.     else
  2645.         info_p->cpuid_logical_per_package = 1;
  2646. -
  2647. +    
  2648.     if (info_p->cpuid_max_ext >= 0x80000001) {
  2649.         cpuid_fn(0x80000001, reg);
  2650.         info_p->cpuid_extfeatures =
  2651. -               quad(reg[ecx], reg[edx]);
  2652. +        quad(reg[ecx], reg[edx]);
  2653.     }
  2654. -
  2655. +    
  2656.     /* Fold in the Invariant TSC feature bit, if present */
  2657.     if (info_p->cpuid_max_ext >= 0x80000007) {
  2658.         cpuid_fn(0x80000007, reg);  
  2659.         info_p->cpuid_extfeatures |=
  2660. -               reg[edx] & (uint32_t)CPUID_EXTFEATURE_TSCI;
  2661. +        reg[edx] & (uint32_t)CPUID_EXTFEATURE_TSCI;
  2662.     }
  2663. -
  2664. +    
  2665.     if (info_p->cpuid_max_basic >= 0x5) {
  2666.         cpuid_mwait_leaf_t  *cmp = &info_p->cpuid_mwait_leaf;
  2667. -
  2668. +        
  2669.         /*
  2670.          * Extract the Monitor/Mwait Leaf info:
  2671.          */
  2672. @@ -595,10 +852,10 @@
  2673.         cmp->sub_Cstates  = reg[edx];
  2674.         info_p->cpuid_mwait_leafp = cmp;
  2675.     }
  2676. -
  2677. +    
  2678.     if (info_p->cpuid_max_basic >= 0x6) {
  2679.         cpuid_thermal_leaf_t    *ctp = &info_p->cpuid_thermal_leaf;
  2680. -
  2681. +        
  2682.         /*
  2683.          * The thermal and Power Leaf:
  2684.          */
  2685. @@ -615,10 +872,10 @@
  2686.         ctp->energy_policy    = bitfield32(reg[ecx], 2, 2);
  2687.         info_p->cpuid_thermal_leafp = ctp;
  2688.     }
  2689. -
  2690. +    
  2691.     if (info_p->cpuid_max_basic >= 0xa) {
  2692.         cpuid_arch_perf_leaf_t  *capp = &info_p->cpuid_arch_perf_leaf;
  2693. -
  2694. +        
  2695.         /*
  2696.          * Architectural Performance Monitoring Leaf:
  2697.          */
  2698. @@ -632,7 +889,7 @@
  2699.         capp->fixed_width   = bitfield32(reg[edx], 12,  5);
  2700.         info_p->cpuid_arch_perf_leafp = capp;
  2701.     }
  2702. -
  2703. +    
  2704.     if (info_p->cpuid_max_basic >= 0xd) {
  2705.         cpuid_xsave_leaf_t  *xsp = &info_p->cpuid_xsave_leaf;
  2706.         /*
  2707. @@ -641,48 +898,66 @@
  2708.         cpuid_fn(0xd, info_p->cpuid_xsave_leaf.extended_state);
  2709.         info_p->cpuid_xsave_leafp = xsp;
  2710.     }
  2711. -
  2712. +    
  2713.     return;
  2714.  }
  2715.  
  2716.  static uint32_t
  2717.  cpuid_set_cpufamily(i386_cpu_info_t *info_p)
  2718.  {
  2719. -   uint32_t cpufamily = CPUFAMILY_UNKNOWN;
  2720. -
  2721. +    
  2722. +    
  2723. +    // uint32_t cpufamily = CPUFAMILY_UNKNOWN;
  2724. +    
  2725. +  
  2726. +    uint32_t cpufamily = CPUID_FAMILY_AMDX2;
  2727. +    
  2728. +    
  2729.     switch (info_p->cpuid_family) {
  2730. -   case 6:
  2731. -       switch (info_p->cpuid_model) {
  2732. +        case 6:
  2733. +        case 15:
  2734. +        case 16:
  2735. +        case 10:
  2736. +            switch (info_p->cpuid_model) {
  2737.  #if CONFIG_YONAH
  2738. -       case 14:
  2739. -           cpufamily = CPUFAMILY_INTEL_YONAH;
  2740. -           break;
  2741. +                case 14:
  2742. +                    cpufamily = CPUFAMILY_INTEL_YONAH;
  2743. +                    break;
  2744.  #endif
  2745. -       case 15:
  2746. -           cpufamily = CPUFAMILY_INTEL_MEROM;
  2747. -           break;
  2748. -       case 23:
  2749. -           cpufamily = CPUFAMILY_INTEL_PENRYN;
  2750. -           break;
  2751. -       case CPUID_MODEL_NEHALEM:
  2752. -       case CPUID_MODEL_FIELDS:
  2753. -       case CPUID_MODEL_DALES:
  2754. -       case CPUID_MODEL_NEHALEM_EX:
  2755. -           cpufamily = CPUFAMILY_INTEL_NEHALEM;
  2756. -           break;
  2757. -       case CPUID_MODEL_DALES_32NM:
  2758. -       case CPUID_MODEL_WESTMERE:
  2759. -       case CPUID_MODEL_WESTMERE_EX:
  2760. -           cpufamily = CPUFAMILY_INTEL_WESTMERE;
  2761. -           break;
  2762. -       case CPUID_MODEL_SANDYBRIDGE:
  2763. -       case CPUID_MODEL_JAKETOWN:
  2764. -           cpufamily = CPUFAMILY_INTEL_SANDYBRIDGE;
  2765. -           break;
  2766. -       }
  2767. -       break;
  2768. +                case 15:
  2769. +                    cpufamily = CPUFAMILY_INTEL_MEROM;
  2770. +                    break;
  2771. +                case 23:
  2772. +                    cpufamily = CPUFAMILY_INTEL_PENRYN;
  2773. +                    break;
  2774. +                case CPUID_MODEL_NEHALEM:
  2775. +                case CPUID_MODEL_FIELDS:
  2776. +                case CPUID_MODEL_DALES:
  2777. +                case CPUID_MODEL_NEHALEM_EX:
  2778. +                    cpufamily = CPUFAMILY_INTEL_NEHALEM;
  2779. +                    break;
  2780. +                case CPUID_MODEL_DALES_32NM:
  2781. +                case CPUID_MODEL_WESTMERE:
  2782. +                case CPUID_MODEL_WESTMERE_EX:
  2783. +                    cpufamily = CPUFAMILY_INTEL_WESTMERE;
  2784. +                    break;
  2785. +                case CPUID_MODEL_SANDYBRIDGE:
  2786. +                case CPUID_MODEL_JAKETOWN:
  2787. +                    cpufamily = CPUFAMILY_INTEL_SANDYBRIDGE;
  2788. +                    break;
  2789. +                case CPUID_MODEL_ATHLON_TM_II:
  2790. +                case CPUID_MODEL_ATHLON_K8:
  2791. +                case CPUID_MODEL_ATHLON_PHENOM_II:
  2792. +                    cpufamily = CPUID_FAMILY_AMDX2;
  2793. +                    cpufamily = CPUID_FAMILY_AMDX2_15;
  2794. +                    cpufamily = CPUID_FAMILY_AMDX4;
  2795. +                    
  2796. +                    //                     return "AMD Athlon(tm) II X2";
  2797. +                    break;
  2798. +            }
  2799. +            break;
  2800.     }
  2801. -
  2802. +    
  2803.     info_p->cpuid_cpufamily = cpufamily;
  2804.     return cpufamily;
  2805.  }
  2806. @@ -696,45 +971,48 @@
  2807.     i386_cpu_info_t     *info_p = &cpuid_cpu_info;
  2808.    
  2809.     bzero((void *)info_p, sizeof(cpuid_cpu_info));
  2810. -
  2811. +    
  2812.     cpuid_set_generic_info(info_p);
  2813. -
  2814. +    
  2815.     /* verify we are running on a supported CPU */
  2816. -   if ((strncmp(CPUID_VID_INTEL, info_p->cpuid_vendor,
  2817. +   if ((strncmp(CPUID_VID_AMD, info_p->cpuid_vendor,
  2818.              min(strlen(CPUID_STRING_UNKNOWN) + 1,
  2819.              sizeof(info_p->cpuid_vendor)))) ||
  2820. -      (cpuid_set_cpufamily(info_p) == CPUFAMILY_UNKNOWN))
  2821. -       panic("Unsupported CPU");
  2822. -
  2823. +     (cpuid_set_cpufamily(info_p) == CPUFAMILY_UNKNOWN))
  2824. +       printf("Unsupported CPU");
  2825. +    
  2826. +    cpuid_set_cpufamily(info_p);
  2827. +    
  2828.     info_p->cpuid_cpu_type = CPU_TYPE_X86;
  2829.     info_p->cpuid_cpu_subtype = CPU_SUBTYPE_X86_ARCH1;
  2830.     /* Must be invoked after set_generic_info */
  2831.     cpuid_set_cache_info(&cpuid_cpu_info);
  2832. -
  2833. +    
  2834. +    cpuid_set_amd_cache_info(&cpuid_cpu_info);
  2835.     /*
  2836.      * Find the number of enabled cores and threads
  2837.      * (which determines whether SMT/Hyperthreading is active).
  2838.      */
  2839.     switch (info_p->cpuid_cpufamily) {
  2840. -   case CPUFAMILY_INTEL_WESTMERE: {
  2841. -       uint64_t msr = rdmsr64(MSR_CORE_THREAD_COUNT);
  2842. -       info_p->core_count   = bitfield32((uint32_t)msr, 19, 16);
  2843. -       info_p->thread_count = bitfield32((uint32_t)msr, 15,  0);
  2844. -       break;
  2845. +        case CPUFAMILY_INTEL_WESTMERE: {
  2846. +            uint64_t msr = rdmsr64(MSR_CORE_THREAD_COUNT);
  2847. +            info_p->core_count   = bitfield32((uint32_t)msr, 19, 16);
  2848. +            info_p->thread_count = bitfield32((uint32_t)msr, 15,  0);
  2849. +            break;
  2850.         }
  2851. -   case CPUFAMILY_INTEL_SANDYBRIDGE:
  2852. -   case CPUFAMILY_INTEL_NEHALEM: {
  2853. -       uint64_t msr = rdmsr64(MSR_CORE_THREAD_COUNT);
  2854. -       info_p->core_count   = bitfield32((uint32_t)msr, 31, 16);
  2855. -       info_p->thread_count = bitfield32((uint32_t)msr, 15,  0);
  2856. -       break;
  2857. +        case CPUFAMILY_INTEL_SANDYBRIDGE:
  2858. +        case CPUFAMILY_INTEL_NEHALEM: {
  2859. +            uint64_t msr = rdmsr64(MSR_CORE_THREAD_COUNT);
  2860. +            info_p->core_count   = bitfield32((uint32_t)msr, 31, 16);
  2861. +            info_p->thread_count = bitfield32((uint32_t)msr, 15,  0);
  2862. +            break;
  2863.         }
  2864.     }
  2865.     if (info_p->core_count == 0) {
  2866.         info_p->core_count   = info_p->cpuid_cores_per_package;
  2867.         info_p->thread_count = info_p->cpuid_logical_per_package;
  2868.     }
  2869. -
  2870. +    
  2871.     cpuid_cpu_info.cpuid_model_string = ""; /* deprecated */
  2872.  }
  2873.  
  2874. @@ -787,6 +1065,7 @@
  2875.     {CPUID_FEATURE_PDCM,      "PDCM"},
  2876.     {CPUID_FEATURE_SSE4_1,    "SSE4.1"},
  2877.     {CPUID_FEATURE_SSE4_2,    "SSE4.2"},
  2878. +    {CPUID_FEATURE_SSE4A,    "SSE4A"},
  2879.     {CPUID_FEATURE_xAPIC,     "xAPIC"},
  2880.     {CPUID_FEATURE_MOVBE,     "MOVBE"},
  2881.     {CPUID_FEATURE_POPCNT,    "POPCNT"},
  2882. @@ -828,13 +1107,13 @@
  2883.     size_t  len = 0;
  2884.     char    *p = buf;
  2885.     int i;
  2886. -
  2887. +    
  2888.     for (i = 0; feature_map[i].mask != 0; i++) {
  2889.         if ((features & feature_map[i].mask) == 0)
  2890.             continue;
  2891.         if (len && ((size_t)(p - buf) < (buf_len - 1)))
  2892.             *p++ = ' ';
  2893. -
  2894. +        
  2895.         len = min(strlen(feature_map[i].name), (size_t) ((buf_len-1) - (p-buf)));
  2896.         if (len == 0)
  2897.             break;
  2898. @@ -851,7 +1130,7 @@
  2899.     size_t  len = 0;
  2900.     char    *p = buf;
  2901.     int i;
  2902. -
  2903. +    
  2904.     for (i = 0; extfeature_map[i].mask != 0; i++) {
  2905.         if ((extfeatures & extfeature_map[i].mask) == 0)
  2906.             continue;
  2907. @@ -870,41 +1149,41 @@
  2908.  
  2909.  void
  2910.  cpuid_feature_display(
  2911. -   const char  *header)
  2912. +                      const char   *header)
  2913.  {
  2914.     char    buf[256];
  2915. -
  2916. +    
  2917.     kprintf("%s: %s\n", header,
  2918. -         cpuid_get_feature_names(cpuid_features(),
  2919. -                       buf, sizeof(buf)));
  2920. +            cpuid_get_feature_names(cpuid_features(),
  2921. +                                    buf, sizeof(buf)));
  2922.     if (cpuid_features() & CPUID_FEATURE_HTT) {
  2923.  #define s_if_plural(n) ((n > 1) ? "s" : "")
  2924.         kprintf("  HTT: %d core%s per package;"
  2925. -                " %d logical cpu%s per package\n",
  2926. -           cpuid_cpu_info.cpuid_cores_per_package,
  2927. -           s_if_plural(cpuid_cpu_info.cpuid_cores_per_package),
  2928. -           cpuid_cpu_info.cpuid_logical_per_package,
  2929. -           s_if_plural(cpuid_cpu_info.cpuid_logical_per_package));
  2930. +                " %d logical cpu%s per package\n",
  2931. +                cpuid_cpu_info.cpuid_cores_per_package,
  2932. +                s_if_plural(cpuid_cpu_info.cpuid_cores_per_package),
  2933. +                cpuid_cpu_info.cpuid_logical_per_package,
  2934. +                s_if_plural(cpuid_cpu_info.cpuid_logical_per_package));
  2935.     }
  2936.  }
  2937.  
  2938.  void
  2939.  cpuid_extfeature_display(
  2940. -   const char  *header)
  2941. +                         const char    *header)
  2942.  {
  2943.     char    buf[256];
  2944. -
  2945. +    
  2946.     kprintf("%s: %s\n", header,
  2947. -         cpuid_get_extfeature_names(cpuid_extfeatures(),
  2948. -                       buf, sizeof(buf)));
  2949. +            cpuid_get_extfeature_names(cpuid_extfeatures(),
  2950. +                                       buf, sizeof(buf)));
  2951.  }
  2952.  
  2953.  void
  2954.  cpuid_cpu_display(
  2955. -   const char  *header)
  2956. +                  const char   *header)
  2957.  {
  2958.      if (cpuid_cpu_info.cpuid_brand_string[0] != '\0') {
  2959. -   kprintf("%s: %s\n", header, cpuid_cpu_info.cpuid_brand_string);
  2960. +        kprintf("%s: %s\n", header, cpuid_cpu_info.cpuid_brand_string);
  2961.      }
  2962.  }
  2963.  
  2964. @@ -937,21 +1216,21 @@
  2965.  {
  2966.     static int checked = 0;
  2967.     char    fpu_arg[20] = { 0 };
  2968. -
  2969. +    
  2970.     (void) cpuid_info();
  2971.     if (!checked) {
  2972. -           /* check for boot-time fpu limitations */
  2973. -           if (PE_parse_boot_argn("_fpu", &fpu_arg[0], sizeof (fpu_arg))) {
  2974. -               printf("limiting fpu features to: %s\n", fpu_arg);
  2975. -               if (!strncmp("387", fpu_arg, sizeof("387")) || !strncmp("mmx", fpu_arg, sizeof("mmx"))) {
  2976. -                   printf("no sse or sse2\n");
  2977. -                   cpuid_cpu_info.cpuid_features &= ~(CPUID_FEATURE_SSE | CPUID_FEATURE_SSE2 | CPUID_FEATURE_FXSR);
  2978. -               } else if (!strncmp("sse", fpu_arg, sizeof("sse"))) {
  2979. -                   printf("no sse2\n");
  2980. -                   cpuid_cpu_info.cpuid_features &= ~(CPUID_FEATURE_SSE2);
  2981. -               }
  2982. -           }
  2983. -           checked = 1;
  2984. +        /* check for boot-time fpu limitations */
  2985. +        if (PE_parse_boot_argn("_fpu", &fpu_arg[0], sizeof (fpu_arg))) {
  2986. +            printf("limiting fpu features to: %s\n", fpu_arg);
  2987. +            if (!strncmp("387", fpu_arg, sizeof("387")) || !strncmp("mmx", fpu_arg, sizeof("mmx"))) {
  2988. +                printf("no sse or sse2\n");
  2989. +                cpuid_cpu_info.cpuid_features &= ~(CPUID_FEATURE_SSE | CPUID_FEATURE_SSE2 | CPUID_FEATURE_FXSR);
  2990. +            } else if (!strncmp("sse", fpu_arg, sizeof("sse"))) {
  2991. +                printf("no sse2\n");
  2992. +                cpuid_cpu_info.cpuid_features &= ~(CPUID_FEATURE_SSE2);
  2993. +            }
  2994. +        }
  2995. +        checked = 1;
  2996.     }
  2997.     return cpuid_cpu_info.cpuid_features;
  2998.  }
  2999. @@ -961,7 +1240,7 @@
  3000.  {
  3001.     return cpuid_info()->cpuid_extfeatures;
  3002.  }
  3003. -
  3004. +
  3005.  
  3006.  #if MACH_KDB
  3007.  
  3008. @@ -972,37 +1251,37 @@
  3009.   */
  3010.  void
  3011.  db_cpuid(__unused db_expr_t addr,
  3012. -    __unused int have_addr,
  3013. -    __unused db_expr_t count,
  3014. -    __unused char *modif)
  3015. +         __unused int have_addr,
  3016. +         __unused db_expr_t count,
  3017. +         __unused char *modif)
  3018.  {
  3019. -
  3020. +    
  3021.     uint32_t        i, mid;
  3022.     uint32_t        cpid[4];
  3023. -
  3024. +    
  3025.     do_cpuid(0, cpid);  /* Get the first cpuid which is the number of
  3026. -                * basic ids */
  3027. +                         * basic ids */
  3028.     db_printf("%08X - %08X %08X %08X %08X\n",
  3029. -       0, cpid[eax], cpid[ebx], cpid[ecx], cpid[edx]);
  3030. -
  3031. +              0, cpid[eax], cpid[ebx], cpid[ecx], cpid[edx]);
  3032. +    
  3033.     mid = cpid[eax];    /* Set the number */
  3034.     for (i = 1; i <= mid; i++) {    /* Dump 'em out */
  3035.         do_cpuid(i, cpid);  /* Get the next */
  3036.         db_printf("%08X - %08X %08X %08X %08X\n",
  3037. -           i, cpid[eax], cpid[ebx], cpid[ecx], cpid[edx]);
  3038. +                  i, cpid[eax], cpid[ebx], cpid[ecx], cpid[edx]);
  3039.     }
  3040.     db_printf("\n");
  3041. -
  3042. +    
  3043.     do_cpuid(0x80000000, cpid); /* Get the first extended cpuid which
  3044. -                    * is the number of extended ids */
  3045. +                                 * is the number of extended ids */
  3046.     db_printf("%08X - %08X %08X %08X %08X\n",
  3047. -       0x80000000, cpid[eax], cpid[ebx], cpid[ecx], cpid[edx]);
  3048. -
  3049. +              0x80000000, cpid[eax], cpid[ebx], cpid[ecx], cpid[edx]);
  3050. +    
  3051.     mid = cpid[eax];    /* Set the number */
  3052.     for (i = 0x80000001; i <= mid; i++) {   /* Dump 'em out */
  3053.         do_cpuid(i, cpid);  /* Get the next */
  3054.         db_printf("%08X - %08X %08X %08X %08X\n",
  3055. -           i, cpid[eax], cpid[ebx], cpid[ecx], cpid[edx]);
  3056. +                  i, cpid[eax], cpid[ebx], cpid[ecx], cpid[edx]);
  3057.     }
  3058.  }
  3059.  
  3060. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/cpuid.h /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/cpuid.h
  3061. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/cpuid.h 2012-02-02 19:16:36.000000000 +0300
  3062. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/cpuid.h  2012-03-31 21:42:27.000000000 +0400
  3063. @@ -113,6 +113,7 @@
  3064.  #define CPUID_FEATURE_TSCTMR    _HBit(24) /* TSC deadline timer */
  3065.  #define CPUID_FEATURE_AVX1_0   _HBit(28) /* AVX 1.0 instructions */
  3066.  
  3067. +
  3068.  /*
  3069.   * The CPUID_EXTFEATURE_XXX values define 64-bit values
  3070.   * returned in %ecx:%edx to a CPUID request with %eax of 0x80000001:
  3071. @@ -122,7 +123,10 @@
  3072.  
  3073.  #define CPUID_EXTFEATURE_1GBPAGE   _Bit(26)    /* 1GB pages */
  3074.  #define CPUID_EXTFEATURE_RDTSCP       _Bit(27) /* RDTSCP */
  3075. -#define CPUID_EXTFEATURE_EM64T    _Bit(29) /* Extended Mem 64 Technology */
  3076. +#define CPUID_EXTFEATURE_EM64T    (0x80000001 << 29)   /* Extended Mem 64 Technology */
  3077. +#define CPUID_FEATURE_SSE4A       (0x80000001 <<6)  
  3078. +#define CPUID_FEATURE_A3DNOW      _Bit(31)  
  3079. +#define CPUID_FEATURE_A3DNOWEXT   _Bit(30)
  3080.  
  3081.  #define CPUID_EXTFEATURE_LAHF     _HBit(0) /* LAFH/SAHF instructions */
  3082.  
  3083. @@ -149,6 +153,13 @@
  3084.  #define CPUID_MODEL_WESTMERE_EX    0x2F
  3085.  #define CPUID_MODEL_SANDYBRIDGE    0x2A
  3086.  #define CPUID_MODEL_JAKETOWN   0x2D
  3087. +#define CPUID_MODEL_ATHLON_TM_II   0x6
  3088. +#define CPUID_MODEL_ATHLON_K8  0xb
  3089. +#define CPUID_MODEL_ATHLON_PHENOM_II   0x4
  3090. +#define CPUID_FAMILY_AMDX2_15      (0xf)
  3091. +#define CPUID_FAMILY_AMDX2 (0x10)
  3092. +#define CPUID_FAMILY_AMDX4 (0xa)
  3093. +
  3094.  
  3095.  #ifndef ASSEMBLER
  3096.  #include <stdint.h>
  3097. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/i386_init.c /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/i386_init.c
  3098. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/i386_init.c 2011-04-30 01:44:49.000000000 +0400
  3099. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/i386_init.c  2012-03-20 21:53:39.000000000 +0300
  3100. @@ -494,7 +494,7 @@
  3101.         &urgency_notification_assert_abstime_threshold,
  3102.         sizeof(urgency_notification_assert_abstime_threshold));
  3103.  
  3104. -#if CONFIG_YONAH
  3105. +#ifdef __i386__
  3106.     /*
  3107.      * At this point we check whether we are a 64-bit processor
  3108.      * and that we're not restricted to legacy mode, 32-bit operation.
  3109. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/idt.s /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/idt.s
  3110. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/idt.s   2010-11-13 03:21:10.000000000 +0300
  3111. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/idt.s    2012-03-23 14:19:28.000000000 +0300
  3112. @@ -474,19 +474,41 @@
  3113.  INTERRUPT(0xf8)
  3114.  INTERRUPT(0xf9)
  3115.  INTERRUPT(0xfa)
  3116. -INTERRUPT(0xfb)
  3117. -INTERRUPT(0xfc)
  3118. +EXCEP_SPC_USR(0xfb, t_fake_cpuid)
  3119. +EXCEP_SPC_USR(0xfc, t_fake_sysenter)
  3120.  INTERRUPT(0xfd)
  3121.  INTERRUPT(0xfe)
  3122.  EXCEPTION(0xff,t_preempt)
  3123.  
  3124.  
  3125. -   .data
  3126. +.data
  3127.  Entry(lo_kernel_cr3)
  3128. -   .long 0
  3129. -   .long 0
  3130. -  
  3131. -        .text
  3132. +.long 0
  3133. +.long 0
  3134. +
  3135. +.text
  3136. +
  3137. +Entry(t_fake_cpuid)
  3138. +pushf          // Must not modify eflags!
  3139. +testl %eax, %eax   // If eax == 0, we are getting cpuid string, so compare and set ZF for later
  3140. +cpuid          // Get cpuid; we'll patch it later based on the above test
  3141. +// Note that cpuid does not affect any flags, so it's ok to compare
  3142. +// first, do cpuid, and then do the conditional jump
  3143. +jnz 2f         // eax was not zero: we are getting feature bits etc, so skip patching
  3144. +1: // otherwise, eax was zero so patch the cpuid vendor string with GenuineIntel
  3145. +movl $0x756e6547, %ebx // "Genu"
  3146. +movl $0x49656e69, %edx // "ineI"
  3147. +movl $0x6c65746e, %ecx // "ntel"
  3148. +2:
  3149. +popf           // restore eflags
  3150. +iret           // Done. Return from interrupt
  3151. +
  3152. +Entry(t_fake_sysenter)
  3153. +pushl   %eax                    /* save system call number */
  3154. +pushl   $0                      /* clear trap number slot */
  3155. +pusha                           /* save the general registers */
  3156. +movl   $EXT(lo_sysenter32),%ebx
  3157. +jmp    enter_lohandler
  3158.  
  3159.    
  3160.  /*
  3161. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/idt64.s /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/idt64.s
  3162. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/idt64.s 2012-02-02 19:16:40.000000000 +0300
  3163. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/idt64.s  2012-03-23 14:20:03.000000000 +0300
  3164. @@ -428,14 +428,33 @@
  3165.  INTERRUPT64(0xf8)
  3166.  INTERRUPT64(0xf9)
  3167.  INTERRUPT64(0xfa)
  3168. -INTERRUPT64(0xfb)
  3169. -INTERRUPT64(0xfc)
  3170. +EXCEP64_SPC_USR(0xfb, t64_fake_cpuid)
  3171. +EXCEP64_SPC_USR(0xfc, t64_fake_sysenter)
  3172.  INTERRUPT64(0xfd)
  3173.  INTERRUPT64(0xfe)
  3174.  EXCEPTION64(0xff,t64_preempt)
  3175.  
  3176.  
  3177. -        .text
  3178. +.text
  3179. +Entry(t64_fake_cpuid)
  3180. +pushf
  3181. +testl %eax, %eax       // cpuid only checks the lower dword of rax
  3182. +cpuid
  3183. +jnz 2f
  3184. +1:
  3185. +movq $0x756e6547, %rbx     // results, however, are zero-extended to qword size
  3186. +movq $0x49656e69, %rdx
  3187. +movq $0x6c65746e, %rcx
  3188. +2:
  3189. +popf
  3190. +iretq              // operand size is *very* important here
  3191. +
  3192. +Entry(t64_fake_sysenter)
  3193. +swapgs             /* switch to kernel gs (cpu_data) */
  3194. +push   %rax            /* save system call number */
  3195. +push   $(UNIX_INT)     /* only used for statistics */
  3196. +movl   $EXT(lo_sysenter32),4(%rsp)
  3197. +jmp    L_32bit_enter_check
  3198.  /*
  3199.   *
  3200.   * Trap/interrupt entry points.
  3201. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/lapic_native.c /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/lapic_native.c
  3202. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/lapic_native.c  2011-01-26 04:35:13.000000000 +0300
  3203. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/lapic_native.c   2012-03-20 23:22:59.000000000 +0300
  3204. @@ -216,7 +216,7 @@
  3205.  
  3206.     lapic_ops->init();
  3207.  
  3208. -   if ((LAPIC_READ(VERSION)&LAPIC_VERSION_MASK) < 0x14) {
  3209. +   if ((LAPIC_READ(VERSION)&LAPIC_VERSION_MASK) < 0x10) {
  3210.         panic("Local APIC version 0x%x, 0x14 or more expected\n",
  3211.             (LAPIC_READ(VERSION)&LAPIC_VERSION_MASK));
  3212.     }
  3213. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/machine_routines.c /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/machine_routines.c
  3214. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/machine_routines.c  2011-04-08 02:41:09.000000000 +0400
  3215. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/machine_routines.c   2012-03-28 03:56:08.000000000 +0400
  3216. @@ -436,6 +436,8 @@
  3217.     os_supports_sse = !!(get_cr4() & CR4_OSXMM);
  3218.  
  3219.     if (ml_fpu_avx_enabled())
  3220. +      //  cpu_infop->vector_unit = 10;
  3221. +   //else if ((cpuid_features() & CPUID_FEATURE_SSE4A) && os_supports_sse)
  3222.         cpu_infop->vector_unit = 9;
  3223.     else if ((cpuid_features() & CPUID_FEATURE_SSE4_2) && os_supports_sse)
  3224.         cpu_infop->vector_unit = 8;
  3225. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/pmap.c /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/pmap.c
  3226. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/pmap.c  2012-02-02 19:16:37.000000000 +0300
  3227. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/pmap.c   2012-03-25 00:09:35.000000000 +0300
  3228. @@ -175,11 +175,12 @@
  3229.  #endif
  3230.  int allow_stack_exec = 0;      /* No apps may execute from the stack by default */
  3231.  
  3232. -#if CONFIG_YONAH
  3233. +#ifdef __i386__
  3234.  boolean_t cpu_64bit  = FALSE;
  3235.  #else
  3236.  const boolean_t cpu_64bit  = TRUE;
  3237.  #endif
  3238. +
  3239.  boolean_t pmap_trace = FALSE;
  3240.  
  3241.  uint64_t max_preemption_latency_tsc = 0;
  3242. @@ -829,10 +830,11 @@
  3243.       pmap_store_pte(pdpt, pa | INTEL_PTE_VALID);
  3244.     }
  3245.  
  3246. -#if CONFIG_YONAH
  3247. +
  3248.     /* 32-bit and legacy support depends on IA32e mode being disabled */
  3249.     cpu_64bit = IA32e;
  3250. -#endif
  3251. +
  3252. +
  3253.    
  3254.     lo_kernel_cr3 = kernel_pmap->pm_cr3;
  3255.     current_cpu_datap()->cpu_kernel_cr3 = (addr64_t) kernel_pmap->pm_cr3;
  3256. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/pmap_internal.h /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/pmap_internal.h
  3257. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/pmap_internal.h 2012-02-02 19:16:37.000000000 +0300
  3258. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/pmap_internal.h  2012-03-25 00:10:15.000000000 +0300
  3259. @@ -84,7 +84,7 @@
  3260.  void
  3261.  pmap_update_cache_attributes_locked(ppnum_t, unsigned);
  3262.  
  3263. -#if CONFIG_YONAH
  3264. +#if    defined(__i386__)
  3265.  extern boolean_t cpu_64bit;
  3266.  #else
  3267.  extern const boolean_t cpu_64bit;
  3268. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/tsc.c /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/tsc.c
  3269. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/tsc.c   2010-09-24 03:28:27.000000000 +0400
  3270. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/tsc.c    2012-03-31 21:40:44.000000000 +0400
  3271. @@ -65,6 +65,7 @@
  3272.  #include <sys/kdebug.h>
  3273.  #include <pexpert/device_tree.h>
  3274.  
  3275. +
  3276.  uint64_t   busFCvtt2n = 0;
  3277.  uint64_t   busFCvtn2t = 0;
  3278.  uint64_t   tscFreq = 0;
  3279. @@ -92,6 +93,7 @@
  3280.  #define CPU_FAMILY_PENTIUM_M   (0x6)
  3281.  
  3282.  static const char  FSB_Frequency_prop[] = "FSBFrequency";
  3283. +static const char  FSB_CPUFrequency_prop[] = "CPUFrequency";
  3284.  /*
  3285.   * This routine extracts the bus frequency in Hz from the device tree.
  3286.   */
  3287. @@ -102,20 +104,20 @@
  3288.     DTEntry     entry;
  3289.     void        *value;
  3290.     unsigned int    size;
  3291. -
  3292. +  
  3293.     if (DTLookupEntry(0, "/efi/platform", &entry) != kSuccess) {
  3294.         kprintf("EFI_FSB_frequency: didn't find /efi/platform\n");
  3295.         return 0;
  3296.     }
  3297.     if (DTGetProperty(entry,FSB_Frequency_prop,&value,&size) != kSuccess) {
  3298.         kprintf("EFI_FSB_frequency: property %s not found\n",
  3299. -           FSB_Frequency_prop);
  3300. +               FSB_Frequency_prop);
  3301.         return 0;
  3302.     }
  3303.     if (size == sizeof(uint64_t)) {
  3304.         frequency = *(uint64_t *) value;
  3305.         kprintf("EFI_FSB_frequency: read %s value: %llu\n",
  3306. -           FSB_Frequency_prop, frequency);
  3307. +               FSB_Frequency_prop, frequency);
  3308.         if (!(90*Mega < frequency && frequency < 10*Giga)) {
  3309.             kprintf("EFI_FSB_frequency: value out of range\n");
  3310.             frequency = 0;
  3311. @@ -126,6 +128,59 @@
  3312.     return frequency;
  3313.  }
  3314.  
  3315. +
  3316. +static uint64_t
  3317. +EFI_CPU_Frequency(void)
  3318. +{
  3319. +    uint64_t   frequency = 0;
  3320. +    DTEntry        entry;
  3321. +    void       *value;
  3322. +    unsigned int   size;
  3323. +    
  3324. +    if (DTLookupEntry(0, "/efi/platform", &entry) != kSuccess) {
  3325. +        kprintf("EFI_CPU_Frequency: didn't find /efi/platform\n");
  3326. +        return 0;
  3327. +    }
  3328. +    if (DTGetProperty(entry,FSB_CPUFrequency_prop,&value,&size) != kSuccess) {
  3329. +        kprintf("EFI_CPU_Frequency: property %s not found\n",
  3330. +                FSB_Frequency_prop);
  3331. +        return 0;
  3332. +    }
  3333. +    if (size == sizeof(uint64_t)) {
  3334. +        frequency = *(uint64_t *) value;
  3335. +        kprintf("EFI_CPU_Frequency: read %s value: %llu\n",
  3336. +                FSB_Frequency_prop, frequency);
  3337. +        if (!(10*Mega < frequency && frequency < 50*Giga)) {
  3338. +            kprintf("EFI_Fake_MSR: value out of range\n");
  3339. +            frequency = 0;
  3340. +        }
  3341. +    } else {
  3342. +        kprintf("EFI_CPU_Frequency: unexpected size %d\n", size);
  3343. +    }
  3344. +    return frequency;
  3345. +}
  3346. +
  3347. +static uint64_t
  3348. +getFakeMSR(uint64_t frequency, uint64_t bFreq) {
  3349. +    uint64_t fakeMSR = 0ull;
  3350. +    uint64_t multi = 0;
  3351. +    
  3352. +    if (frequency == 0 || bFreq == 0)
  3353. +        return 0;
  3354. +    
  3355. +    multi = frequency / (bFreq / 1000); // = multi*1000
  3356. +    // divide by 1000, rounding up if it was x.75 or more
  3357. +    // Example: 12900 will get rounded to 13150/1000 = 13
  3358. +    //          but 12480 will be 12730/1000 = 12
  3359. +    fakeMSR = (multi + 250) / 1000;
  3360. +    fakeMSR <<= 40; // push multiplier into bits 44 to 40
  3361. +    
  3362. +    // If fractional part was within (0.25, 0.75), set N/2
  3363. +    if ((multi % 1000 > 250) && (multi % 1000 < 750))
  3364. +        fakeMSR |= (1ull << 46);
  3365. +    
  3366. +    return fakeMSR;
  3367. +}
  3368.  /*
  3369.   * Initialize the various conversion factors needed by code referencing
  3370.   * the TSC.
  3371. @@ -135,70 +190,127 @@
  3372.  {
  3373.     uint64_t    busFCvtInt = 0;
  3374.     boolean_t   N_by_2_bus_ratio = FALSE;
  3375. -
  3376. +   uint64_t cpuFreq=0;
  3377.     /*
  3378.      * Get the FSB frequency and conversion factors from EFI.
  3379.      */
  3380.     busFreq = EFI_FSB_frequency();
  3381. -
  3382. +  
  3383. +   if (busFreq == 0)
  3384. +        busFreq = BASE_NHM_CLOCK_SOURCE;
  3385. +  
  3386. +  
  3387.     switch (cpuid_cpufamily()) {
  3388. -   case CPUFAMILY_INTEL_SANDYBRIDGE:
  3389. -   case CPUFAMILY_INTEL_WESTMERE:
  3390. -   case CPUFAMILY_INTEL_NEHALEM: {
  3391. -       uint64_t cpu_mhz;
  3392. -       uint64_t msr_flex_ratio;
  3393. -       uint64_t msr_platform_info;
  3394. -
  3395. -       /* See if FLEX_RATIO is being used */
  3396. -       msr_flex_ratio = rdmsr64(MSR_FLEX_RATIO);
  3397. -       msr_platform_info = rdmsr64(MSR_PLATFORM_INFO);
  3398. -       flex_ratio_min = (uint32_t)bitfield(msr_platform_info, 47, 40);
  3399. -       flex_ratio_max = (uint32_t)bitfield(msr_platform_info, 15, 8);
  3400. -       /* No BIOS-programed flex ratio. Use hardware max as default */
  3401. -       tscGranularity = flex_ratio_max;
  3402. -       if (msr_flex_ratio & bit(16)) {
  3403. -           /* Flex Enabled: Use this MSR if less than max */
  3404. -           flex_ratio = (uint32_t)bitfield(msr_flex_ratio, 15, 8);
  3405. -           if (flex_ratio < flex_ratio_max)
  3406. -               tscGranularity = flex_ratio;
  3407. +       case CPUFAMILY_INTEL_SANDYBRIDGE:
  3408. +       case CPUFAMILY_INTEL_WESTMERE:
  3409. +       case CPUFAMILY_INTEL_NEHALEM: {
  3410. +           uint64_t cpu_mhz;
  3411. +           uint64_t msr_flex_ratio;
  3412. +           uint64_t msr_platform_info;
  3413. +          
  3414. +           /* See if FLEX_RATIO is being used */
  3415. +           msr_flex_ratio = rdmsr64(MSR_FLEX_RATIO);
  3416. +           msr_platform_info = rdmsr64(MSR_PLATFORM_INFO);
  3417. +           flex_ratio_min = (uint32_t)bitfield(msr_platform_info, 47, 40);
  3418. +           flex_ratio_max = (uint32_t)bitfield(msr_platform_info, 15, 8);
  3419. +           /* No BIOS-programed flex ratio. Use hardware max as default */
  3420. +           tscGranularity = flex_ratio_max;
  3421. +           if (msr_flex_ratio & bit(16)) {
  3422. +               /* Flex Enabled: Use this MSR if less than max */
  3423. +               flex_ratio = (uint32_t)bitfield(msr_flex_ratio, 15, 8);
  3424. +               if (flex_ratio < flex_ratio_max)
  3425. +                   tscGranularity = flex_ratio;
  3426. +           }
  3427. +          
  3428. +           /* If EFI isn't configured correctly, use a constant
  3429. +            * value. See 6036811.
  3430. +            */
  3431. +           if (busFreq == 0)
  3432. +               busFreq = BASE_NHM_CLOCK_SOURCE;
  3433. +          
  3434. +           cpu_mhz = tscGranularity * BASE_NHM_CLOCK_SOURCE;
  3435. +          
  3436. +          
  3437.         }
  3438. -
  3439. -       /* If EFI isn't configured correctly, use a constant
  3440. -        * value. See 6036811.
  3441. -        */
  3442. -       if (busFreq == 0)
  3443. -           busFreq = BASE_NHM_CLOCK_SOURCE;
  3444. -
  3445. -       cpu_mhz = tscGranularity * BASE_NHM_CLOCK_SOURCE;
  3446. -
  3447. -       break;
  3448. -            }
  3449. -   default: {
  3450. -       uint64_t    prfsts;
  3451. -
  3452. -       prfsts = rdmsr64(IA32_PERF_STS);
  3453. -       tscGranularity = (uint32_t)bitfield(prfsts, 44, 40);
  3454. -       N_by_2_bus_ratio = (prfsts & bit(46)) != 0;
  3455. -       }
  3456. +           break;
  3457. +          
  3458. +            //case CPUID_FAMILY_AMDX2:
  3459. +           //case CPUID_FAMILY_AMDX2_15:
  3460. +            //{
  3461. +            // if (busFreq == 0)
  3462. +            //     busFreq = BASE_NHM_CLOCK_SOURCE;
  3463. +            //
  3464. +            // uint64_t    prfsts;
  3465. +           //      cpuFreq = EFI_CPU_Frequency;
  3466. +            // prfsts = rdmsr64(AMD_COFVID_STS);
  3467. +            // prfsts =    rdmsr64(AMD_PSTATE0_STS + (uint32_t)bitfield(prfsts, 34, 32));
  3468. +            // tscGranularity = (uint32_t)bitfield(prfsts, 34, 32);
  3469. +           //N_by_2_bus_ratio = (prfsts & bit(46)) != 0;
  3470. +          
  3471. +            //}       
  3472. +            // break;
  3473. +           /* If EFI isn't configured correctly, use a constant
  3474. +            * value. See 6036811.
  3475. +            */
  3476. +           //if (busFreq == 0)
  3477. +           //  busFreq = BASE_NHM_CLOCK_SOURCE_200;
  3478. +          
  3479. +          
  3480. +           //cpu_mhz = tscGranularity * BASE_NHM_CLOCK_SOURCE_200;
  3481. +          
  3482. +          
  3483. +          
  3484. +           //default: {
  3485. +           //  uint64_t    prfsts;
  3486. +          
  3487. +           //  prfsts = rdmsr64(AMD_COFVID_STS);
  3488. +           //  prfsts =    rdmsr64(AMD_PSTATE0_STS + (uint32_t)bitfield(prfsts, 34, 32));
  3489. +           //  tscGranularity = (uint32_t)bitfield(prfsts, 34, 32);
  3490. +           //N_by_2_bus_ratio = (prfsts & bit(46)) != 0;
  3491. +           //  }
  3492. +          
  3493. +        case CPUID_FAMILY_AMDX2:
  3494. +        case CPUID_FAMILY_AMDX2_15:
  3495. +        case CPUID_FAMILY_AMDX4:
  3496. +            
  3497. +        {
  3498. +            if (busFreq == 0)
  3499. +                busFreq = BASE_NHM_CLOCK_SOURCE;
  3500. +          
  3501. +            
  3502. +            uint64_t   prfsts;
  3503. +          
  3504. +            prfsts = rdmsr64(AMD_COFVID_STS);
  3505. +            cpuFreq = EFI_CPU_Frequency();
  3506. +            //prfsts = rdmsr64(IA32_PERF_STS);
  3507. +            prfsts  = getFakeMSR(cpuFreq, busFreq);
  3508. +            tscGranularity = (uint32_t)bitfield(prfsts, 44, 40);
  3509. +            N_by_2_bus_ratio = (prfsts & bit(46)) != 0;
  3510. +        }
  3511. +            break;
  3512.     }
  3513. -
  3514. +   //busFreq = BASE_NHM_CLOCK_SOURCE;
  3515. +  
  3516.     if (busFreq != 0) {
  3517.         busFCvtt2n = ((1 * Giga) << 32) / busFreq;
  3518.         busFCvtn2t = 0xFFFFFFFFFFFFFFFFULL / busFCvtt2n;
  3519.         busFCvtInt = tmrCvt(1 * Peta, 0xFFFFFFFFFFFFFFFFULL / busFreq);
  3520.     } else {
  3521. -       panic("tsc_init: EFI not supported!\n");
  3522. +       /* Instead of panicking, set a default FSB frequency */
  3523. +       busFreq = 200*Mega;
  3524. +       printf("rtclock_init: Setting fsb to %u MHz\n", (uint32_t) (busFreq/Mega));
  3525. +      
  3526.     }
  3527. -
  3528. -   kprintf(" BUS: Frequency = %6d.%04dMHz, "
  3529. -       "cvtt2n = %08X.%08X, cvtn2t = %08X.%08X, "
  3530. -       "cvtInt = %08X.%08X\n",
  3531. -       (uint32_t)(busFreq / Mega),
  3532. -       (uint32_t)(busFreq % Mega),
  3533. -       (uint32_t)(busFCvtt2n >> 32), (uint32_t)busFCvtt2n,
  3534. -       (uint32_t)(busFCvtn2t >> 32), (uint32_t)busFCvtn2t,
  3535. -       (uint32_t)(busFCvtInt >> 32), (uint32_t)busFCvtInt);
  3536. -
  3537. +  
  3538. +   printf(" BUS: Frequency = %6d.%04dMHz, "
  3539. +          "cvtt2n = %08X.%08X, cvtn2t = %08X.%08X, "
  3540. +          "cvtInt = %08X.%08X\n",
  3541. +          (uint32_t)(busFreq / Mega),
  3542. +          (uint32_t)(busFreq % Mega),
  3543. +          (uint32_t)(busFCvtt2n >> 32), (uint32_t)busFCvtt2n,
  3544. +          (uint32_t)(busFCvtn2t >> 32), (uint32_t)busFCvtn2t,
  3545. +          (uint32_t)(busFCvtInt >> 32), (uint32_t)busFCvtInt);
  3546. +  
  3547.     /*
  3548.      * Get the TSC increment.  The TSC is incremented by this
  3549.      * on every bus tick.  Calculate the TSC conversion factors
  3550. @@ -211,18 +323,18 @@
  3551.         tscFCvtt2n = busFCvtt2n * 2 / (1 + 2*tscGranularity);
  3552.     else
  3553.         tscFCvtt2n = busFCvtt2n / tscGranularity;
  3554. -
  3555. +  
  3556.     tscFreq = ((1 * Giga)  << 32) / tscFCvtt2n;
  3557.     tscFCvtn2t = 0xFFFFFFFFFFFFFFFFULL / tscFCvtt2n;
  3558. -
  3559. -   kprintf(" TSC: Frequency = %6d.%04dMHz, "
  3560. -       "cvtt2n = %08X.%08X, cvtn2t = %08X.%08X, gran = %lld%s\n",
  3561. -       (uint32_t)(tscFreq / Mega),
  3562. -       (uint32_t)(tscFreq % Mega),
  3563. -       (uint32_t)(tscFCvtt2n >> 32), (uint32_t)tscFCvtt2n,
  3564. -       (uint32_t)(tscFCvtn2t >> 32), (uint32_t)tscFCvtn2t,
  3565. -       tscGranularity, N_by_2_bus_ratio ? " (N/2)" : "");
  3566. -
  3567. +  
  3568. +   printf(" TSC: Frequency = %6d.%04dMHz, "
  3569. +          "cvtt2n = %08X.%08X, cvtn2t = %08X.%08X, gran = %lld%s\n",
  3570. +          (uint32_t)(tscFreq / Mega),
  3571. +          (uint32_t)(tscFreq % Mega),
  3572. +          (uint32_t)(tscFCvtt2n >> 32), (uint32_t)tscFCvtt2n,
  3573. +          (uint32_t)(tscFCvtn2t >> 32), (uint32_t)tscFCvtn2t,
  3574. +          tscGranularity, N_by_2_bus_ratio ? " (N/2)" : "");
  3575. +  
  3576.     /*
  3577.      * Calculate conversion from BUS to TSC
  3578.      */
  3579. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/tsc.h /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/tsc.h
  3580. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/i386/tsc.h   2010-04-22 05:25:23.000000000 +0400
  3581. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/i386/tsc.h    2012-03-23 17:14:42.000000000 +0300
  3582. @@ -40,10 +40,15 @@
  3583.  #ifndef _I386_TSC_H_
  3584.  #define _I386_TSC_H_
  3585.  
  3586. -#define BASE_NHM_CLOCK_SOURCE  133333333ULL
  3587. -#define IA32_PERF_STS      0x198
  3588.  #define    SLOW_TSC_THRESHOLD  1000067800  /* TSC is too slow for regular nanotime() algorithm */
  3589.  
  3590. +#define BASE_NHM_CLOCK_SOURCE  200000000ULL
  3591. +//#define BASE_NHM_CLOCK_SOURCE_200    100000000ULL
  3592. +#define AMD_PERF_STS   0xC0010042  /* AMD's version of the MSR */
  3593. +#define AMD_PSTATE0_STS    0xC0010064  /* K10/phenom class AMD cpus */
  3594. +#define AMD_COFVID_STS 0xC0010071  /* This might be a better MSR for K10? */
  3595. +#define IA32_PERF_STS      0x198
  3596. +
  3597.  #ifndef ASSEMBLER
  3598.  extern uint64_t    busFCvtt2n;
  3599.  extern uint64_t    busFCvtn2t;
  3600. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/kern/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/kern/.DS_Store differ
  3601. diff -Nur /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/kern/voodoo_assert.h /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/kern/voodoo_assert.h
  3602. --- /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/osfmk/kern/voodoo_assert.h 1970-01-01 03:00:00.000000000 +0300
  3603. +++ /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/osfmk/kern/voodoo_assert.h  2011-08-25 23:38:39.000000000 +0400
  3604. @@ -0,0 +1,11 @@
  3605. +#ifndef _VOODOO_ASSERT_H
  3606. +#define _VOODOO_ASSERT_H
  3607. +
  3608. +#include <kern/debug.h>
  3609. +
  3610. +#define ASSERT(expr) do { if (!(expr)) panic("%s: failed assertion '%s'", \
  3611. +                                                      __FUNCTION__, #expr); } while (0)
  3612. +
  3613. +#define BUG(msg) panic("%s: %s\n", __FUNCTION__, #msg)
  3614. +
  3615. +#endif
  3616. \ No newline at end of file
  3617. Binary files /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_original/security/.DS_Store and /Users/osx/Desktop/src_1068/10.7/xnu-1699.24.23_amd/security/.DS_Store differ
Advertisement
Add Comment
Please, Sign In to add comment