PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/source/cpuid.cpp

https://code.google.com/p/crisscross/
C++ | 986 lines | 774 code | 128 blank | 84 comment | 60 complexity | 988b224ed403c401b159f3539012518a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*
  2. * CrissCross
  3. * A multi-purpose cross-platform library.
  4. *
  5. * A product of Uplink Laboratories.
  6. *
  7. * (c) 2006-2008 Steven Noonan.
  8. * Licensed under the New BSD License.
  9. *
  10. */
  11. /*
  12. * Last updated 1/9/2008
  13. * using Intel CPUID documentation (AP-485) updated 12/2007
  14. */
  15. #include <crisscross/universal_include.h>
  16. #ifdef ENABLE_CPUID
  17. /* The following definition enables some rather suspicious cache descriptors */
  18. /* from sandpile.org which haven't been verified with Intel's docs. */
  19. /* # define ENABLE_SANDPILE */
  20. #include <crisscross/cpuid.h>
  21. #include <crisscross/core_io.h>
  22. namespace CrissCross
  23. {
  24. namespace System
  25. {
  26. #define FPU_FLAG 0x0001
  27. #define LAHF_FLAG 0x0001
  28. #define SSE3_FLAG 0x0001
  29. #define VME_FLAG 0x0002
  30. #define DE_FLAG 0x0004
  31. #define DTES64_FLAG 0x0004
  32. #define MONITOR_FLAG 0x0008
  33. #define PSE_FLAG 0x0008
  34. #define DS_CPL_FLAG 0x0010
  35. #define TSC_FLAG 0x0010
  36. #define MSR_FLAG 0x0020
  37. #define VMX_FLAG 0x0020
  38. #define PAE_FLAG 0x0040
  39. #define SMX_FLAG 0x0040
  40. #define EIST_FLAG 0x0080
  41. #define MCE_FLAG 0x0080
  42. #define CX8_FLAG 0x0100
  43. #define TM2_FLAG 0x0100
  44. #define APIC_FLAG 0x0200
  45. #define SSSE3_FLAG 0x0200
  46. #define CNXTID_FLAG 0x0400
  47. #define SEP_FLAG 0x0800
  48. #define SYSCALL_FLAG 0x0800
  49. #define MTRR_FLAG 0x1000
  50. #define CX16_FLAG 0x2000
  51. #define PGE_FLAG 0x2000
  52. #define MCA_FLAG 0x4000
  53. #define XTPR_FLAG 0x4000
  54. #define PDCM_FLAG 0x8000
  55. #define CMOV_FLAG 0x8000
  56. #define PAT_FLAG 0x10000
  57. #define PSE36_FLAG 0x20000
  58. #define DCA_FLAG 0x40000
  59. #define PSNUM_FLAG 0x40000
  60. #define CLFLUSH_FLAG 0x80000
  61. #define SSE4_1_FLAG 0x80000
  62. #define SSE4_2_FLAG 0x100000
  63. #define XD_FLAG 0x100000
  64. #define DTS_FLAG 0x200000
  65. #define ACPI_FLAG 0x400000
  66. #define MMX_FLAG 0x800000
  67. #define FXSR_FLAG 0x1000000
  68. #define SSE_FLAG 0x2000000
  69. #define SSE2_FLAG 0x4000000
  70. #define SS_FLAG 0x8000000
  71. #define HTT_FLAG 0x10000000
  72. #define EM64T_FLAG 0x20000000
  73. #define TM1_FLAG 0x20000000
  74. #define IA64_FLAG 0x40000000
  75. #define PBE_FLAG 0x80000000
  76. /* AMD 8000_0001 EDX flags */
  77. #define _3DNOW_FLAG 0x80000000
  78. #define _3DNOWEXT_FLAG 0x40000000
  79. #define LM_FLAG 0x20000000
  80. #define RDTSCP_FLAG 0x8000000
  81. #define FFXSR_FLAG 0x2000000
  82. #define FXSR_FLAG 0x1000000
  83. #define MMXEXT_FLAG 0x800000
  84. #define NX_FLAG 0x100000
  85. /* AMD 8000_0001 ECX flags */
  86. #define WDT_FLAG 0x2000
  87. #define SKINIT_FLAG 0x1000
  88. #define OSVW_FLAG 0x200
  89. #define _3DNP_FLAG 0x100
  90. #define MAS_FLAG 0x80
  91. #define SSE4A_FLAG 0x40
  92. #define ABM_FLAG 0x20
  93. #define AMC8_FLAG 0x10
  94. #define EAS_FLAG 0x8
  95. #define SVM_FLAG 0x4
  96. #define CL_FLAG 0x2
  97. #define LS_FLAG 0x1
  98. struct Registers
  99. {
  100. unsigned int eax;
  101. unsigned int ebx;
  102. unsigned int ecx;
  103. unsigned int edx;
  104. };
  105. struct Registers *Std;
  106. unsigned int StdMax;
  107. struct Registers *Ext;
  108. unsigned int ExtMax;
  109. /* If the current processor supports the CPUID instruction, execute
  110. * one, with REQUEST in %eax, and set *EAX, *EBX, *ECX, and *EDX to
  111. * the values the 'cpuid' stored in those registers. Return true if
  112. * the current processor supports CPUID, false otherwise. */
  113. static bool call_cpuid(unsigned int request, unsigned int *_eax,
  114. unsigned int *_ebx, unsigned int *_ecx, unsigned int *_edx)
  115. {
  116. #ifndef TARGET_CPU_X64
  117. unsigned int pre_change, post_change;
  118. const unsigned int id_flag = 0x200000;
  119. #endif
  120. /* This is pretty much the standard way to detect whether the CPUID
  121. * instruction is supported: try to change the ID bit in the EFLAGS
  122. * register. If we can change it, then the CPUID instruction is
  123. * implemented. */
  124. #ifndef TARGET_CPU_X64
  125. #if defined (TARGET_COMPILER_GCC)
  126. asm ("pushfl\n\t" /* Save %eflags to restore later. */
  127. "pushfl\n\t" /* Push second copy, for manipulation. */
  128. "popl %1\n\t" /* Pop it into post_change. */
  129. "movl %1,%0\n\t" /* Save copy in pre_change. */
  130. "xorl %2,%1\n\t" /* Tweak bit in post_change. */
  131. "pushl %1\n\t" /* Push tweaked copy... */
  132. "popfl\n\t" /* ... and pop it into %eflags. */
  133. "pushfl\n\t" /* Did it change? Push new %eflags... */
  134. "popl %1\n\t" /* ... and pop it into post_change. */
  135. "popfl" /* Restore original value. */
  136. : "=&r" (pre_change), "=&r" (post_change)
  137. : "ir" (id_flag));
  138. #else
  139. __asm {
  140. mov edx, id_flag;
  141. pushfd; /* Save %eflags to restore later. */
  142. pushfd; /* Push second copy, for manipulation. */
  143. pop ebx; /* Pop it into post_change. */
  144. mov eax, ebx; /* Save copy in pre_change. */
  145. xor ebx, edx; /* Tweak bit in post_change. */
  146. push ebx; /* Push tweaked copy... */
  147. popfd; /* ... and pop it into eflags. */
  148. pushfd; /* Did it change? Push new %eflags... */
  149. pop ebx; /* ... and pop it into post_change. */
  150. popfd; /* Restore original value. */
  151. mov pre_change, eax;
  152. mov post_change, ebx;
  153. }
  154. #endif
  155. #endif
  156. /* If the bit changed, then we support the CPUID instruction. */
  157. #ifndef TARGET_CPU_X64
  158. if ((pre_change ^ post_change) & id_flag) {
  159. #endif
  160. #if defined (TARGET_COMPILER_GCC)
  161. asm volatile ("mov %%ebx, %%esi\n\t" /* Save %ebx. */
  162. "xorl %%ecx, %%ecx\n\t"
  163. "cpuid\n\t"
  164. "xchgl %%ebx, %%esi" /* Restore %ebx. */
  165. : "=a" (*_eax), "=S" (*_ebx), "=c" (*_ecx), "=d" (*_edx)
  166. : "0" (request)
  167. : "memory");
  168. #else
  169. __asm {
  170. push esi;
  171. push edi;
  172. xor ecx, ecx;
  173. mov eax, request;
  174. cpuid;
  175. mov edi, [_eax];
  176. mov esi, [_ebx];
  177. mov[edi], eax;
  178. mov[esi], ebx;
  179. mov edi, [_ecx];
  180. mov esi, [_edx];
  181. mov[edi], ecx;
  182. mov[esi], edx;
  183. pop edi;
  184. pop esi;
  185. }
  186. #endif
  187. return true;
  188. #ifndef TARGET_CPU_X64
  189. } else
  190. return false;
  191. #endif
  192. }
  193. CPUID::CPUID()
  194. {
  195. unsigned int i = 0;
  196. for (i = 0; i < MAX_PROCESSORS; i++) {
  197. proc[i] = new Processor();
  198. CoreAssert(proc[i]);
  199. proc[i]->Manufacturer = NULL;
  200. proc[i]->ProcessorName = NULL;
  201. }
  202. Std = new Registers[32];
  203. Ext = new Registers[32];
  204. memset(Std, 0, sizeof(Registers) * 32);
  205. memset(Ext, 0, sizeof(Registers) * 32);
  206. StdMax = 0;
  207. ExtMax = 0;
  208. /* Basic initializations complete */
  209. call_cpuid(0, &Std[0].eax, &Std[0].ebx, &Std[0].ecx, &Std[0].edx);
  210. StdMax = Std[0].eax;
  211. if (StdMax > 31) {
  212. #ifdef CPUID_DEBUG
  213. g_console->WriteLine("CPUID.0.EAX has an invalid value: %d",
  214. StdMax);
  215. #endif
  216. StdMax = 31;
  217. } else {
  218. #ifdef CPUID_DEBUG
  219. g_console->WriteLine("Standard CPUID maximum input is %d.",
  220. StdMax);
  221. #endif
  222. }
  223. for (i = 1; i <= StdMax; i++) {
  224. call_cpuid(i, &Std[i].eax, &Std[i].ebx, &Std[i].ecx, &Std[i].edx);
  225. }
  226. call_cpuid(0x80000000, &Ext[0].eax, &Ext[0].ebx, &Ext[0].ecx, &Ext[0].edx);
  227. if (Ext[0].eax < 0x80000004) {
  228. return;
  229. } else {
  230. ExtMax = Ext[0].eax - 0x80000000;
  231. }
  232. for (i = 0; i <= ExtMax; i++) {
  233. call_cpuid(0x80000000 + i, &Ext[i].eax, &Ext[i].ebx, &Ext[i].ecx, &Ext[i].edx);
  234. }
  235. }
  236. CPUID::~CPUID()
  237. {
  238. /* Time to deallocate all the memory we allocated. */
  239. size_t i = 0, j = 0;
  240. delete [] Std;
  241. delete [] Ext;
  242. for (i = 0; i < MAX_PROCESSORS; i++) {
  243. for (j = 0; j < proc[i]->caches.size(); j++) {
  244. if (proc[i]->caches.valid(j))
  245. delete [] proc[i]->caches.get(j);
  246. }
  247. delete [] (char *)proc[i]->Manufacturer;
  248. delete [] (char *)proc[i]->ProcessorName;
  249. delete proc[i];
  250. }
  251. }
  252. int CPUID::VirtualCount()
  253. {
  254. int count = 0, i;
  255. for (i = 0; i < MAX_PROCESSORS; i++) {
  256. if (proc[i]->Manufacturer)
  257. count++;
  258. }
  259. return count;
  260. }
  261. int CPUID::CoresPerPackage()
  262. {
  263. return proc[0]->CoresPerPackage;
  264. }
  265. int CPUID::LogicalPerPackage()
  266. {
  267. return proc[0]->LogicalPerPackage;
  268. }
  269. #ifdef TARGET_OS_WINDOWS
  270. DWORD WINAPI CPUID::GoThread(LPVOID * params)
  271. #else
  272. long int CPUID::GoThread(int processor)
  273. #endif
  274. {
  275. #ifdef TARGET_OS_WINDOWS
  276. int processor;
  277. memcpy(&processor, params, sizeof(int));
  278. #endif
  279. if (processor < 0 || processor > MAX_PROCESSORS) {
  280. return 1;
  281. }
  282. DetectManufacturer(processor);
  283. DetectProcessorName(processor);
  284. DetectFeatures(processor);
  285. DetectCacheInfo(processor);
  286. DetectFMS(processor);
  287. DetectBrandID(processor);
  288. DetectCount(processor);
  289. DetectAPIC(processor);
  290. return 0;
  291. }
  292. void CPUID::Go()
  293. {
  294. CoreAssert(this);
  295. #ifdef TARGET_OS_WINDOWS
  296. DWORD dThread = NULL;
  297. SYSTEM_INFO siSystem;
  298. int iCount = 0;
  299. struct GoThreadProc_Params params;
  300. params.cpuid_class = this;
  301. GetSystemInfo(&siSystem);
  302. iCount = siSystem.dwNumberOfProcessors;
  303. if (iCount > MAX_PROCESSORS) {
  304. iCount = MAX_PROCESSORS;
  305. }
  306. for (params.processor = 0; params.processor < iCount;
  307. params.processor++) {
  308. HANDLE hThread =
  309. CreateThread(NULL, 0, ( LPTHREAD_START_ROUTINE )s_GoThreadProc,
  310. &params, CREATE_SUSPENDED, &dThread);
  311. SetThreadAffinityMask(hThread,
  312. ( DWORD )pow(( double )2,
  313. ( double )params.
  314. processor));
  315. Sleep(0); /* Wait for affinity switch. */
  316. SetThreadPriority(hThread, THREAD_PRIORITY_ABOVE_NORMAL);
  317. ResumeThread(hThread);
  318. WaitForSingleObject(hThread, INFINITE);
  319. }
  320. #elif defined (TARGET_OS_LINUX) || defined (TARGET_OS_MACOSX)
  321. int NUM_PROCS = sysconf(_SC_NPROCESSORS_CONF), i;
  322. cpu_set_t mask;
  323. cpu_set_t originalmask;
  324. sched_getaffinity(0, sizeof(originalmask), &originalmask);
  325. for (i = 0; i < NUM_PROCS; i++) {
  326. CPU_ZERO(&mask);
  327. CPU_SET(( int )pow(2, i), &mask);
  328. sched_setaffinity(0, sizeof(mask), &mask);
  329. GoThread(i);
  330. }
  331. sched_setaffinity(0, sizeof(originalmask), &originalmask);
  332. #endif
  333. }
  334. void CPUID::DetectManufacturer(int processor)
  335. {
  336. char *manufacturer = new char[(4 * 3) + 1];
  337. char *_man = &manufacturer[0];
  338. memcpy(_man, &Std[0].ebx, 4);
  339. _man += 4;
  340. memcpy(_man, &Std[0].edx, 4);
  341. _man += 4;
  342. memcpy(_man, &Std[0].ecx, 4);
  343. _man += 4;
  344. *_man = '\x0';
  345. proc[processor]->Manufacturer = manufacturer;
  346. }
  347. void CPUID::DetectProcessorName(int processor)
  348. {
  349. char *processorname = new char[(4 * 12) + 1];
  350. char *_proc = &processorname[0];
  351. memcpy(_proc, &Ext[2].eax, 4);
  352. _proc += 4;
  353. memcpy(_proc, &Ext[2].ebx, 4);
  354. _proc += 4;
  355. memcpy(_proc, &Ext[2].ecx, 4);
  356. _proc += 4;
  357. memcpy(_proc, &Ext[2].edx, 4);
  358. _proc += 4;
  359. memcpy(_proc, &Ext[3].eax, 4);
  360. _proc += 4;
  361. memcpy(_proc, &Ext[3].ebx, 4);
  362. _proc += 4;
  363. memcpy(_proc, &Ext[3].ecx, 4);
  364. _proc += 4;
  365. memcpy(_proc, &Ext[3].edx, 4);
  366. _proc += 4;
  367. memcpy(_proc, &Ext[4].eax, 4);
  368. _proc += 4;
  369. memcpy(_proc, &Ext[4].ebx, 4);
  370. _proc += 4;
  371. memcpy(_proc, &Ext[4].ecx, 4);
  372. _proc += 4;
  373. memcpy(_proc, &Ext[4].edx, 4);
  374. _proc += 4;
  375. *_proc = '\x0';
  376. proc[processor]->ProcessorName = processorname;
  377. }
  378. void CPUID::DetectCacheInfo(int processor)
  379. {
  380. if (proc[processor]->Manufacturer) {
  381. if (strcmp(proc[processor]->Manufacturer, "GenuineIntel") == 0) {
  382. int ntlb = 255, i;
  383. for (i = 0; i < ntlb; i++) {
  384. ntlb = Std[2].eax & 0xff;
  385. AddIntelCacheData(processor, Std[2].eax >> 8);
  386. AddIntelCacheData(processor, Std[2].eax >> 16);
  387. AddIntelCacheData(processor, Std[2].eax >> 24);
  388. if ((Std[2].ebx & 0x80000000) == 0) {
  389. AddIntelCacheData(processor, Std[2].ebx);
  390. AddIntelCacheData(processor, Std[2].ebx >> 8);
  391. AddIntelCacheData(processor, Std[2].ebx >> 16);
  392. AddIntelCacheData(processor, Std[2].ebx >> 24);
  393. }
  394. if ((Std[2].ecx & 0x80000000) == 0) {
  395. AddIntelCacheData(processor, Std[2].ecx);
  396. AddIntelCacheData(processor, Std[2].ecx >> 8);
  397. AddIntelCacheData(processor, Std[2].ecx >> 16);
  398. AddIntelCacheData(processor, Std[2].ecx >> 24);
  399. }
  400. if ((Std[2].edx & 0x80000000) == 0) {
  401. AddIntelCacheData(processor, Std[2].edx);
  402. AddIntelCacheData(processor, Std[2].edx >> 8);
  403. AddIntelCacheData(processor, Std[2].edx >> 16);
  404. AddIntelCacheData(processor, Std[2].edx >> 24);
  405. }
  406. }
  407. } else if (strcmp(proc[processor]->Manufacturer, "AuthenticAMD") == 0) {
  408. DecodeAMDCacheIdentifiers(processor);
  409. }
  410. }
  411. CrissCross::Data::HeapSort<char *> sorter;
  412. proc[processor]->caches.sort(sorter);
  413. }
  414. const char *CPUID::CreateCacheDescription(cacheType _type, const char *_pages, unsigned int _size, unsigned int _assoc, unsigned int _entries, unsigned int _linesize, bool _sectored)
  415. {
  416. static char description[512];
  417. char assoc[64], prefix[64], size[32], sectored[32], linesz[32], entries[32];
  418. /* No associativity? Invalid cache entry. Abort, abort! */
  419. if (_assoc == 0)
  420. return NULL;
  421. memset(prefix, 0, sizeof(prefix));
  422. /* Get the prefix worked out. */
  423. switch (_type)
  424. {
  425. case CACHE_TYPE_TRACE:
  426. sprintf(prefix, "Trace cache: ");
  427. break;
  428. case CACHE_TYPE_L0DATA_TLB:
  429. sprintf(prefix, "L0 Data TLB: %s pages, ", _pages);
  430. break;
  431. case CACHE_TYPE_L1DATA_TLB:
  432. sprintf(prefix, "L1 Data TLB: %s pages, ", _pages);
  433. break;
  434. case CACHE_TYPE_L2DATA_TLB:
  435. sprintf(prefix, "L2 Data TLB: %s pages, ", _pages);
  436. break;
  437. case CACHE_TYPE_L0CODE_TLB:
  438. sprintf(prefix, "L0 Code TLB: %s pages, ", _pages);
  439. break;
  440. case CACHE_TYPE_L1CODE_TLB:
  441. sprintf(prefix, "L1 Code TLB: %s pages, ", _pages);
  442. break;
  443. case CACHE_TYPE_L2CODE_TLB:
  444. sprintf(prefix, "L2 Code TLB: %s pages, ", _pages);
  445. break;
  446. case CACHE_TYPE_DATA_TLB:
  447. sprintf(prefix, "Data TLB: %s pages, ", _pages);
  448. break;
  449. case CACHE_TYPE_CODE_TLB:
  450. sprintf(prefix, "Code TLB: %s pages, ", _pages);
  451. break;
  452. case CACHE_TYPE_L1CODE:
  453. sprintf(prefix, "1st-level code cache: ");
  454. break;
  455. case CACHE_TYPE_L1DATA:
  456. sprintf(prefix, "1st-level data cache: ");
  457. break;
  458. case CACHE_TYPE_L2:
  459. sprintf(prefix, "2nd-level cache: ");
  460. break;
  461. case CACHE_TYPE_L3:
  462. sprintf(prefix, "3rd-level cache: ");
  463. break;
  464. }
  465. /* Figure out the appropriate size descriptor. */
  466. memset(size, 0, sizeof(size));
  467. switch (_type)
  468. {
  469. case CACHE_TYPE_L0DATA_TLB:
  470. case CACHE_TYPE_L1DATA_TLB:
  471. case CACHE_TYPE_L2DATA_TLB:
  472. case CACHE_TYPE_L0CODE_TLB:
  473. case CACHE_TYPE_L1CODE_TLB:
  474. case CACHE_TYPE_L2CODE_TLB:
  475. case CACHE_TYPE_DATA_TLB:
  476. case CACHE_TYPE_CODE_TLB:
  477. break;
  478. case CACHE_TYPE_TRACE:
  479. sprintf(size, "%dK-uops, ", _size);
  480. break;
  481. default:
  482. if (_size >= 1024)
  483. sprintf(size, "%dMB, ", _size / 1024);
  484. else
  485. sprintf(size, "%dKB, ", _size);
  486. }
  487. /* Get the associativity part set up */
  488. switch (_assoc)
  489. {
  490. case 0x01: sprintf(assoc, "direct mapped"); break;
  491. case 0xFF: sprintf(assoc, "fully associative"); break;
  492. default: sprintf(assoc, "%d-way set associative", _assoc); break;
  493. }
  494. /* If this is a TLB, we have entries */
  495. if (_entries)
  496. sprintf(entries, ", %d entries", _entries);
  497. else
  498. memset(entries, 0, sizeof(entries));
  499. /* Is it a sectored cache? */
  500. sprintf(sectored, _sectored ? ", sectored cache" : "");
  501. /* If there's a line size, we append it. */
  502. if (_linesize)
  503. sprintf(linesz, ", %d byte line size", _linesize);
  504. else
  505. memset(linesz, 0, sizeof(linesz));
  506. sprintf(description, "%s%s%s%s%s%s\n", prefix, size, assoc, entries, sectored, linesz);
  507. return description;
  508. }
  509. void CPUID::DecodeAMDCacheIdentifiers(int processor)
  510. {
  511. /* L1 Cache Information */
  512. unsigned int L1DTlb2and4MAssoc, L1DTlb2and4MSize, L1ITlb2and4MAssoc, L1ITlb2and4MSize;
  513. unsigned int L1DTlb4KAssoc, L1DTlb4KSize, L1ITlb4KAssoc, L1ITlb4KSize;
  514. unsigned int L1DcSize, L1DcAssoc, L1DcLinesPerTag, L1DcLineSize;
  515. unsigned int L1IcSize, L1IcAssoc, L1IcLinesPerTag, L1IcLineSize;
  516. /* */
  517. /* L1 Data 2MB/4MB TLB */
  518. L1DTlb2and4MAssoc = (Ext[5].eax & 0xFF000000) >> 24;
  519. L1DTlb2and4MSize = (Ext[5].eax & 0x00FF0000) >> 16;
  520. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_DATA_TLB, "2MB or 4MB", 0, L1DTlb2and4MAssoc, L1DTlb2and4MSize, 0, false));
  521. /* */
  522. /* L1 Code 2MB/4MB TLB */
  523. L1ITlb2and4MAssoc = (Ext[5].eax & 0x0000FF00) >> 8;
  524. L1ITlb2and4MSize = (Ext[5].eax & 0x000000FF);
  525. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "2MB or 4MB", 0, L1ITlb2and4MAssoc, L1ITlb2and4MSize, 0, false));
  526. /* */
  527. /* L1 Data 4KB TLB */
  528. L1DTlb4KAssoc = (Ext[5].ebx & 0xFF000000) >> 24;
  529. L1DTlb4KSize = (Ext[5].ebx & 0x00FF0000) >> 16;
  530. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_DATA_TLB, "4KB", 0, L1DTlb4KAssoc, L1DTlb4KSize, 0, false));
  531. /* */
  532. /* L1 Code 4KB TLB */
  533. L1ITlb4KAssoc = (Ext[5].ebx & 0x0000FF00) >> 8;
  534. L1ITlb4KSize = (Ext[5].ebx & 0x000000FF);
  535. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "4KB", 0, L1ITlb4KAssoc, L1ITlb4KSize, 0, false));
  536. /* */
  537. /* L1 Data Cache */
  538. L1DcSize = (Ext[5].ecx & 0xFF000000) >> 24;
  539. L1DcAssoc = (Ext[5].ecx & 0x00FF0000) >> 16;
  540. L1DcLinesPerTag = (Ext[5].ecx & 0x0000FF00) >> 8;
  541. L1DcLineSize = (Ext[5].ecx & 0x000000FF);
  542. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA, NULL, L1DcSize, L1DcAssoc, 0, L1DcLineSize, false));
  543. /* */
  544. /* L1 Code Cache */
  545. L1IcSize = (Ext[5].edx & 0xFF000000) >> 24;
  546. L1IcAssoc = (Ext[5].edx & 0x00FF0000) >> 16;
  547. L1IcLinesPerTag = (Ext[5].edx & 0x0000FF00) >> 8;
  548. L1IcLineSize = (Ext[5].edx & 0x000000FF);
  549. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1CODE, NULL, L1IcSize, L1IcAssoc, 0, L1IcLineSize, false));
  550. /* L2 Cache Information */
  551. unsigned int L2DTlb2and4MAssoc, L2DTlb2and4MSize, L2ITlb2and4MAssoc, L2ITlb2and4MSize;
  552. unsigned int L2DTlb4KAssoc, L2DTlb4KSize, L2ITlb4KAssoc, L2ITlb4KSize;
  553. unsigned int L2Size, L2Assoc, L2LinesPerTag, L2LineSize;
  554. /* */
  555. /* L2 Data 2MB/4MB TLB */
  556. L2DTlb2and4MAssoc = (Ext[6].eax & 0xF0000000) >> 28;
  557. L2DTlb2and4MSize = (Ext[6].eax & 0x0FFF0000) >> 16;
  558. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2DATA_TLB, "2MB or 4MB", 0, L2DTlb2and4MAssoc, L2DTlb2and4MSize, 0, false));
  559. /* */
  560. /* L2 Code 2MB/4MB TLB */
  561. L2ITlb2and4MAssoc = (Ext[6].eax & 0x0000F000) >> 12;
  562. L2ITlb2and4MSize = (Ext[6].eax & 0x00000FFF);
  563. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2CODE_TLB, "2MB or 4MB", 0, L2ITlb2and4MAssoc, L2ITlb2and4MSize, 0, false));
  564. /* */
  565. /* L2 Data 4KB TLB */
  566. L2DTlb4KAssoc = (Ext[6].ebx & 0xF0000000) >> 28;
  567. L2DTlb4KSize = (Ext[6].ebx & 0x0FFF0000) >> 16;
  568. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2DATA_TLB, "4KB", 0, L2DTlb4KAssoc, L2DTlb4KSize, 0, false));
  569. /* */
  570. /* L2 Code 4KB TLB */
  571. L2ITlb4KAssoc = (Ext[6].ebx & 0x0000F000) >> 12;
  572. L2ITlb4KSize = (Ext[6].ebx & 0x00000FFF);
  573. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2CODE_TLB, "4KB", 0, L2ITlb4KAssoc, L2ITlb4KSize, 0, false));
  574. /* */
  575. /* L2 Cache */
  576. L2Size = (Ext[6].ecx & 0xFFFF0000) >> 16;
  577. L2Assoc = (Ext[6].ecx & 0x0000F000) >> 12;
  578. L2LinesPerTag = (Ext[6].ecx & 0x00000F00) >> 8;
  579. L2LineSize = (Ext[6].ecx & 0x000000FF);
  580. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, L2Size, L2Assoc, 0, L2LineSize, false));
  581. /* L3 Cache Information */
  582. unsigned int L3Size, L3Assoc, L3LinesPerTag, L3LineSize;
  583. /* */
  584. /* L3 Cache */
  585. L3Size = (Ext[6].edx & 0xFFFC0000) >> 18;
  586. L3Assoc = (Ext[6].edx & 0x0000F000) >> 12;
  587. L3LinesPerTag = (Ext[6].edx & 0x00000F00) >> 8;
  588. L3LineSize = (Ext[6].edx & 0x000000FF);
  589. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, L3Size * 512, L3Assoc, 0, L3LineSize, false));
  590. }
  591. void CPUID::AddCacheDescription(int processor, const char *description)
  592. {
  593. if (!description) return;
  594. char *temp = new char[strlen(description) + 1];
  595. CoreAssert(temp);
  596. strcpy(temp, description);
  597. proc[processor]->caches.insert(temp);
  598. temp = NULL;
  599. }
  600. void CPUID::AddIntelCacheData(int processor, int x)
  601. {
  602. /* Compliant with Intel document #241618, save for the ENABLE_SANDPILE sections. */
  603. x &= 0xff;
  604. switch (x)
  605. {
  606. case 0: break;
  607. case 0x1: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "4KB", 0, 4, 32, 0, false)); break;
  608. case 0x2: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "4MB", 0, 255, 2, 0, false)); break;
  609. case 0x3: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_DATA_TLB, "4KB", 0, 4, 64, 0, false)); break;
  610. case 0x4: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_DATA_TLB, "4MB", 0, 4, 8, 0, false)); break;
  611. case 0x5: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_DATA_TLB, "4MB", 0, 4, 32, 0, false)); break;
  612. case 0x6: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1CODE, NULL, 8, 4, 0, 32, false)); break;
  613. case 0x8: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1CODE, NULL, 16, 4, 0, 32, false)); break;
  614. case 0xa: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA, NULL, 8, 2, 0, 32, false)); break;
  615. #if defined (ENABLE_SANDPILE)
  616. case 0xb: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "4MB", 0, 4, 4, 0, false)); break;
  617. #endif
  618. case 0xc: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA, NULL, 16, 4, 0, 32, false)); break;
  619. #if defined (ENABLE_SANDPILE)
  620. case 0x10: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA, NULL, 16, 4, 0, 32, false)); break;
  621. case 0x15: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1CODE, NULL, 16, 4, 0, 32, false)); break;
  622. case 0x1A: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 96, 6, 0, 64, false)); break;
  623. #endif
  624. case 0x22: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 512, 4, 0, 64, true)); break;
  625. case 0x23: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 1024, 8, 0, 64, true)); break;
  626. case 0x25: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 2048, 8, 0, 64, true)); break;
  627. case 0x29: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 4096, 8, 0, 64, true)); break;
  628. case 0x2C: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA, NULL, 32, 8, 0, 64, false)); break;
  629. case 0x30: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1CODE, NULL, 32, 8, 0, 64, false)); break;
  630. case 0x39: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 128, 4, 0, 64, true)); break;
  631. case 0x3A: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 192, 6, 0, 64, true)); break;
  632. case 0x3B: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 128, 2, 0, 64, true)); break;
  633. case 0x3C: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 256, 4, 0, 64, true)); break;
  634. case 0x3D: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 384, 6, 0, 64, true)); break;
  635. case 0x3E: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 512, 4, 0, 64, true)); break;
  636. case 0x40: AddCacheDescription(processor, "No 2nd-level cache, or if 2nd-level cache exists, no 3rd-level cache\n"); break;
  637. case 0x41: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 128, 4, 0, 32, false)); break;
  638. case 0x42: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 256, 4, 0, 32, false)); break;
  639. case 0x43: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 512, 4, 0, 32, false)); break;
  640. case 0x44: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 1024, 4, 0, 32, false)); break;
  641. case 0x45: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 2048, 4, 0, 32, false)); break;
  642. case 0x46: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 4096, 4, 0, 64, false)); break;
  643. case 0x47: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 8192, 8, 0, 64, false)); break;
  644. #if defined (ENABLE_SANDPILE)
  645. case 0x48: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 3072, 12, 0, 64, false)); break;
  646. #endif
  647. case 0x49: AddCacheDescription(processor, CreateCacheDescription(
  648. /* This is an L3 on the P4 and an L2 on the Core 2 */
  649. proc[processor]->features.exists("SSSE3") ? CACHE_TYPE_L2 : CACHE_TYPE_L3, NULL, 4096, 16, 0, 64, false)); break;
  650. case 0x4A: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 6144, 12, 0, 64, false)); break;
  651. case 0x4B: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 8192, 16, 0, 64, false)); break;
  652. case 0x4C: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 12288, 12, 0, 64, false)); break;
  653. case 0x4D: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 16384, 16, 0, 64, false)); break;
  654. case 0x4E: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 6144, 24, 0, 64, false)); break;
  655. case 0x50: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "4KB, 2MB or 4MB", 0, 255, 64, 0, false)); break;
  656. case 0x51: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "4KB, 2MB or 4MB", 0, 255, 128, 0, false)); break;
  657. case 0x52: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "4KB, 2MB or 4MB", 0, 255, 256, 0, false)); break;
  658. case 0x56: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA_TLB, "4MB", 0, 4, 16, 0, false)); break;
  659. case 0x57: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA_TLB, "4KB", 0, 4, 16, 0, false)); break;
  660. case 0x5b: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_DATA_TLB, "4KB or 4MB", 0, 255, 64, 0, false)); break;
  661. case 0x5c: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_DATA_TLB, "4KB or 4MB", 0, 255, 128, 0, false)); break;
  662. case 0x5d: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_DATA_TLB, "4KB or 4MB", 0, 255, 256, 0, false)); break;
  663. case 0x60: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA, NULL, 16, 8, 0, 64, true)); break;
  664. case 0x66: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA, NULL, 8, 4, 0, 64, true)); break;
  665. case 0x67: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA, NULL, 16, 4, 0, 64, true)); break;
  666. case 0x68: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA, NULL, 32, 4, 0, 64, true)); break;
  667. case 0x70: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_TRACE, NULL, 12, 8, 0, 0, false)); break;
  668. case 0x71: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_TRACE, NULL, 16, 8, 0, 0, false)); break;
  669. case 0x72: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_TRACE, NULL, 32, 8, 0, 0, false)); break;
  670. case 0x73: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_TRACE, NULL, 64, 8, 0, 0, false)); break;
  671. #if defined (ENABLE_SANDPILE)
  672. case 0x77: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1CODE, NULL, 16, 4, 0, 64, true)); break;
  673. #endif
  674. case 0x78: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 1024, 4, 0, 64, false)); break;
  675. case 0x79: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 128, 8, 0, 64, true)); break;
  676. case 0x7A: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 256, 8, 0, 64, true)); break;
  677. case 0x7B: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 512, 8, 0, 64, true)); break;
  678. case 0x7C: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 1024, 8, 0, 64, true)); break;
  679. case 0x7D: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 2048, 8, 0, 64, false)); break;
  680. #if defined (ENABLE_SANDPILE)
  681. case 0x7E: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 256, 8, 0, 128, true)); break;
  682. #endif
  683. case 0x7F: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 512, 2, 0, 64, false)); break;
  684. #if defined (ENABLE_SANDPILE)
  685. case 0x81: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 128, 8, 0, 128, true)); break;
  686. #endif
  687. case 0x82: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 256, 8, 0, 32, false)); break;
  688. case 0x83: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 512, 8, 0, 32, false)); break;
  689. case 0x84: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 1024, 8, 0, 32, false)); break;
  690. case 0x85: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 2048, 8, 0, 32, false)); break;
  691. case 0x86: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 512, 4, 0, 64, false)); break;
  692. case 0x87: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2, NULL, 1024, 8, 0, 64, false)); break;
  693. #if defined (ENABLE_SANDPILE)
  694. case 0x88: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 2048, 4, 0, 64, false)); break;
  695. case 0x89: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 4096, 4, 0, 64, false)); break;
  696. case 0x8A: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 8192, 4, 0, 64, false)); break;
  697. case 0x8D: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L3, NULL, 3072, 12, 0, 128, false)); break;
  698. case 0x90: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "4KB or 256MB", 0, 255, 64, 0, false)); break;
  699. case 0x96: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L1DATA_TLB, "4KB or 256MB", 0, 255, 32, 0, false)); break;
  700. case 0x9B: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_L2DATA_TLB, "4KB or 256MB", 0, 255, 96, 0, false)); break;
  701. #endif
  702. case 0xB0: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "4KB", 0, 4, 128, 0, false)); break;
  703. case 0xB1: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "4MB", 0, 4, 4, 0, false));
  704. AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_CODE_TLB, "2MB", 0, 4, 8, 0, false)); break;
  705. case 0xB3: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_DATA_TLB, "4KB", 0, 4, 128, 0, false)); break;
  706. case 0xB4: AddCacheDescription(processor, CreateCacheDescription(CACHE_TYPE_DATA_TLB, "4KB", 0, 4, 256, 0, false)); break;
  707. case 0xF0: AddCacheDescription(processor, "64 byte prefetching\n"); break;
  708. case 0xF1: AddCacheDescription(processor, "128 byte prefetching\n"); break;
  709. default:
  710. {
  711. char temp[256];
  712. sprintf(temp, "Unknown cache descriptor 0x%02x\n", x);
  713. AddCacheDescription(processor, temp);
  714. }
  715. break;
  716. }
  717. }
  718. void CPUID::DetectFMS(int processor)
  719. {
  720. /* Compliant with Intel document #241618. */
  721. proc[processor]->Family = (char)(((Std[1].eax >> 8) + (Std[1].eax >> 20)) & 0xff);
  722. proc[processor]->Model = (char)(((((Std[1].eax >> 16) & 0xf) << 4) + ((Std[1].eax >> 4) & 0xf)) & 0xff);
  723. proc[processor]->Stepping = (char)(Std[1].eax & 0xf);
  724. }
  725. void CPUID::DetectBrandID(int processor)
  726. {
  727. /* Compliant with Intel document #241618. */
  728. proc[processor]->BrandID = (char)(Std[1].ebx & 0xff);
  729. }
  730. void CPUID::DetectCount(int processor)
  731. {
  732. /* Compliant with Intel document #241618. */
  733. /* Do we have HTT flag set? */
  734. if (proc[processor]->features.exists("HTT")) {
  735. /* AMD and Intel documentations state that if HTT is supported */
  736. /* then this the EBX:16 will reflect the logical processor count */
  737. /* otherwise the flag is reserved. */
  738. proc[processor]->features.insert("CMP", NULL);
  739. proc[processor]->CoresPerPackage = (char)((Std[4].eax & 0xFC000000) >> 26) + 1;
  740. proc[processor]->LogicalPerPackage = (char)((Std[1].ebx & 0x00FF0000) >> 16);
  741. if (proc[processor]->CoresPerPackage < 1)
  742. proc[processor]->CoresPerPackage = 1;
  743. if (proc[processor]->LogicalPerPackage < 1)
  744. proc[processor]->LogicalPerPackage = 1;
  745. if (proc[processor]->CoresPerPackage > 1 &&
  746. proc[processor]->LogicalPerPackage > proc[processor]->CoresPerPackage) {
  747. /* Hyperthreaded dual core. */
  748. } else if (proc[processor]->CoresPerPackage > 1 &&
  749. proc[processor]->LogicalPerPackage == proc[processor]->CoresPerPackage) {
  750. /* Dual core. */
  751. proc[processor]->features.erase("HTT");
  752. } else if (proc[processor]->CoresPerPackage == 1 &&
  753. proc[processor]->LogicalPerPackage > proc[processor]->CoresPerPackage) {
  754. /* Hyperthreaded. */
  755. proc[processor]->features.erase("CMP");
  756. }
  757. } else {
  758. /* HTT not supported. Report logical processor count as 1. */
  759. proc[processor]->LogicalPerPackage = 1;
  760. }
  761. }
  762. void CPUID::DetectAPIC(int processor)
  763. {
  764. /* Found at http://www.intel.com/cd/ids/developer/asmo-na/eng/211924.htm */
  765. proc[processor]->APICID = (char)((Std[1].ebx & 0xFF000000) >> 24);
  766. }
  767. void CPUID::DetectFeature(const unsigned int *_register, long _flag, int _processor, const char *_name)
  768. {
  769. /* Compliant with Intel document #241618. */
  770. bool supported = (*_register & _flag) > 0;
  771. if (supported)
  772. proc[_processor]->features.insert(_name, NULL);
  773. }
  774. void CPUID::DetectFeatures(int processor)
  775. {
  776. /* Compliant with Intel document #241618. */
  777. DetectFeature(&Std[1].edx, FPU_FLAG, processor, "FPU");
  778. DetectFeature(&Std[1].edx, VME_FLAG, processor, "VME");
  779. DetectFeature(&Std[1].edx, DE_FLAG, processor, "DE");
  780. DetectFeature(&Std[1].edx, PSE_FLAG, processor, "PSE");
  781. DetectFeature(&Std[1].edx, TSC_FLAG, processor, "TSC");
  782. DetectFeature(&Std[1].edx, MSR_FLAG, processor, "MSR");
  783. DetectFeature(&Std[1].edx, PAE_FLAG, processor, "PAE");
  784. DetectFeature(&Std[1].edx, MCE_FLAG, processor, "MCE");
  785. DetectFeature(&Std[1].edx, CX8_FLAG, processor, "CX8");
  786. DetectFeature(&Std[1].edx, APIC_FLAG, processor, "APIC");
  787. DetectFeature(&Std[1].edx, SEP_FLAG, processor, "SEP");
  788. DetectFeature(&Std[1].edx, MTRR_FLAG, processor, "MTRR");
  789. DetectFeature(&Std[1].edx, PGE_FLAG, processor, "PGE");
  790. DetectFeature(&Std[1].edx, MCA_FLAG, processor, "MCA");
  791. DetectFeature(&Std[1].edx, CMOV_FLAG, processor, "CMOV");
  792. DetectFeature(&Std[1].edx, PAT_FLAG, processor, "PAT");
  793. DetectFeature(&Std[1].edx, PSE36_FLAG, processor, "PSE36");
  794. DetectFeature(&Std[1].edx, PSNUM_FLAG, processor, "PSNUM");
  795. DetectFeature(&Std[1].edx, CLFLUSH_FLAG, processor, "CLFLUSH");
  796. DetectFeature(&Std[1].edx, DTS_FLAG, processor, "DTS");
  797. DetectFeature(&Std[1].edx, ACPI_FLAG, processor, "ACPI");
  798. DetectFeature(&Std[1].edx, MMX_FLAG, processor, "MMX");
  799. DetectFeature(&Std[1].edx, FXSR_FLAG, processor, "FXSR");
  800. DetectFeature(&Std[1].edx, SSE_FLAG, processor, "SSE");
  801. DetectFeature(&Std[1].edx, SSE2_FLAG, processor, "SSE2");
  802. DetectFeature(&Std[1].edx, SS_FLAG, processor, "SS");
  803. DetectFeature(&Std[1].edx, HTT_FLAG, processor, "HTT");
  804. DetectFeature(&Std[1].edx, TM1_FLAG, processor, "TM1");
  805. DetectFeature(&Std[1].ecx, SSE3_FLAG, processor, "SSE3");
  806. DetectFeature(&Std[1].ecx, CX16_FLAG, processor, "CX16");
  807. if (proc[processor]->Manufacturer) {
  808. if (strcmp(proc[processor]->Manufacturer, "GenuineIntel") == 0) {
  809. /* IA64 and PBE are on Intel where the 3DNow! flags are on AMD */
  810. DetectFeature(&Std[1].edx, IA64_FLAG, processor, "IA64");
  811. DetectFeature(&Std[1].edx, PBE_FLAG, processor, "PBE");
  812. /* Intel-only flags */
  813. DetectFeature(&Ext[1].ecx, LAHF_FLAG, processor, "LAHF");
  814. DetectFeature(&Std[1].ecx, DS_CPL_FLAG, processor, "DS_CPL");
  815. DetectFeature(&Std[1].ecx, MONITOR_FLAG, processor, "MONITOR");
  816. DetectFeature(&Std[1].ecx, DTES64_FLAG, processor, "DTES64");
  817. DetectFeature(&Std[1].ecx, EIST_FLAG, processor, "EIST");
  818. DetectFeature(&Std[1].ecx, TM2_FLAG, processor, "TM2");
  819. DetectFeature(&Std[1].ecx, SSSE3_FLAG, processor, "SSSE3");
  820. DetectFeature(&Std[1].ecx, CNXTID_FLAG, processor, "CNXTID");
  821. DetectFeature(&Ext[1].edx, SYSCALL_FLAG, processor, "SYSCALL");
  822. DetectFeature(&Std[1].ecx, XTPR_FLAG, processor, "XTPR");
  823. DetectFeature(&Ext[1].edx, XD_FLAG, processor, "XD");
  824. DetectFeature(&Std[1].ecx, DCA_FLAG, processor, "DCA");
  825. DetectFeature(&Ext[1].edx, EM64T_FLAG, processor, "EM64T");
  826. DetectFeature(&Std[1].ecx, SSE4_1_FLAG, processor, "SSE4.1");
  827. DetectFeature(&Std[1].ecx, SSE4_2_FLAG, processor, "SSE4.2");
  828. DetectFeature(&Std[1].ecx, VMX_FLAG, processor, "VMX");
  829. DetectFeature(&Std[1].ecx, SMX_FLAG, processor, "SMX");
  830. DetectFeature(&Std[1].ecx, PDCM_FLAG, processor, "PDCM");
  831. } else if (strcmp(proc[processor]->Manufacturer, "AuthenticAMD") == 0) {
  832. /* AMD-only flags, EDX 8000_0001 */
  833. DetectFeature(&Ext[1].edx, NX_FLAG, processor, "NX");
  834. DetectFeature(&Ext[1].edx, MMXEXT_FLAG, processor, "MMXEXT");
  835. DetectFeature(&Ext[1].edx, FFXSR_FLAG, processor, "FFXSR");
  836. DetectFeature(&Ext[1].edx, RDTSCP_FLAG, processor, "RDTSCP");
  837. DetectFeature(&Ext[1].edx, LM_FLAG, processor, "LM");
  838. DetectFeature(&Ext[1].edx, _3DNOWEXT_FLAG, processor, "3DNOWEXT");
  839. DetectFeature(&Ext[1].edx, _3DNOW_FLAG, processor, "3DNOW");
  840. /* AMD-only flags, ECX 8000_0001 */
  841. DetectFeature(&Ext[1].ecx, LS_FLAG, processor, "LS");
  842. DetectFeature(&Ext[1].ecx, CL_FLAG, processor, "CL");
  843. DetectFeature(&Ext[1].ecx, SVM_FLAG, processor, "SVM");
  844. DetectFeature(&Ext[1].ecx, EAS_FLAG, processor, "EAS");
  845. DetectFeature(&Ext[1].ecx, AMC8_FLAG, processor, "AMC8");
  846. DetectFeature(&Ext[1].ecx, ABM_FLAG, processor, "ABM");
  847. DetectFeature(&Ext[1].ecx, SSE4A_FLAG, processor, "SSE4A");
  848. DetectFeature(&Ext[1].ecx, MAS_FLAG, processor, "MAS");
  849. DetectFeature(&Ext[1].ecx, _3DNP_FLAG, processor, "3DNP");
  850. DetectFeature(&Ext[1].ecx, OSVW_FLAG, processor, "OSVW");
  851. DetectFeature(&Ext[1].ecx, SKINIT_FLAG, processor, "SKINIT");
  852. DetectFeature(&Ext[1].ecx, WDT_FLAG, processor, "WDT");
  853. }
  854. }
  855. }
  856. }
  857. }
  858. #endif