You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cpuid_x86.c 38 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include "cpuid.h"
  41. #ifdef NO_AVX
  42. #define CPUTYPE_SANDYBRIDGE CPUTYPE_NEHALEM
  43. #define CORE_SANDYBRIDGE CORE_NEHALEM
  44. #define CPUTYPE_BULLDOZER CPUTYPE_BARCELONA
  45. #define CORE_BULLDOZER CORE_BARCELONA
  46. #endif
  47. #ifndef CPUIDEMU
  48. #if defined(__APPLE__) && defined(__i386__)
  49. void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx);
  50. #else
  51. static inline void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx){
  52. __asm__ __volatile__
  53. ("cpuid": "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (op) : "cc");
  54. }
  55. #endif
  56. #else
  57. typedef struct {
  58. unsigned int id, a, b, c, d;
  59. } idlist_t;
  60. typedef struct {
  61. char *vendor;
  62. char *name;
  63. int start, stop;
  64. } vendor_t;
  65. extern idlist_t idlist[];
  66. extern vendor_t vendor[];
  67. static int cv = VENDOR;
  68. void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx){
  69. static int current = 0;
  70. int start = vendor[cv].start;
  71. int stop = vendor[cv].stop;
  72. int count = stop - start;
  73. if ((current < start) || (current > stop)) current = start;
  74. while ((count > 0) && (idlist[current].id != op)) {
  75. current ++;
  76. if (current > stop) current = start;
  77. count --;
  78. }
  79. *eax = idlist[current].a;
  80. *ebx = idlist[current].b;
  81. *ecx = idlist[current].c;
  82. *edx = idlist[current].d;
  83. }
  84. #endif
  85. static inline int have_cpuid(void){
  86. int eax, ebx, ecx, edx;
  87. cpuid(0, &eax, &ebx, &ecx, &edx);
  88. return eax;
  89. }
  90. static inline int have_excpuid(void){
  91. int eax, ebx, ecx, edx;
  92. cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
  93. return eax & 0xffff;
  94. }
  95. #ifndef NO_AVX
  96. static inline void xgetbv(int op, int * eax, int * edx){
  97. __asm__ __volatile__
  98. ("xgetbv": "=a" (*eax), "=d" (*edx) : "c" (op) : "cc");
  99. }
  100. #endif
  101. int support_avx(){
  102. #ifndef NO_AVX
  103. int eax, ebx, ecx, edx;
  104. int ret=0;
  105. cpuid(1, &eax, &ebx, &ecx, &edx);
  106. if ((ecx & (1 << 28)) != 0 && (ecx & (1 << 27)) != 0){
  107. xgetbv(0, &eax, &edx);
  108. if((eax & 6) == 6){
  109. ret=1; //OS support AVX
  110. }
  111. }
  112. return ret;
  113. #else
  114. return 0;
  115. #endif
  116. }
  117. int get_vendor(void){
  118. int eax, ebx, ecx, edx;
  119. char vendor[13];
  120. cpuid(0, &eax, &ebx, &ecx, &edx);
  121. *(int *)(&vendor[0]) = ebx;
  122. *(int *)(&vendor[4]) = edx;
  123. *(int *)(&vendor[8]) = ecx;
  124. vendor[12] = (char)0;
  125. if (!strcmp(vendor, "GenuineIntel")) return VENDOR_INTEL;
  126. if (!strcmp(vendor, " UMC UMC UMC")) return VENDOR_UMC;
  127. if (!strcmp(vendor, "AuthenticAMD")) return VENDOR_AMD;
  128. if (!strcmp(vendor, "CyrixInstead")) return VENDOR_CYRIX;
  129. if (!strcmp(vendor, "NexGenDriven")) return VENDOR_NEXGEN;
  130. if (!strcmp(vendor, "CentaurHauls")) return VENDOR_CENTAUR;
  131. if (!strcmp(vendor, "RiseRiseRise")) return VENDOR_RISE;
  132. if (!strcmp(vendor, " SiS SiS SiS")) return VENDOR_SIS;
  133. if (!strcmp(vendor, "GenuineTMx86")) return VENDOR_TRANSMETA;
  134. if (!strcmp(vendor, "Geode by NSC")) return VENDOR_NSC;
  135. if ((eax == 0) || ((eax & 0x500) != 0)) return VENDOR_INTEL;
  136. return VENDOR_UNKNOWN;
  137. }
  138. int get_cputype(int gettype){
  139. int eax, ebx, ecx, edx;
  140. int extend_family, family;
  141. int extend_model, model;
  142. int type, stepping;
  143. int feature = 0;
  144. cpuid(1, &eax, &ebx, &ecx, &edx);
  145. switch (gettype) {
  146. case GET_EXFAMILY :
  147. return BITMASK(eax, 20, 0xff);
  148. case GET_EXMODEL :
  149. return BITMASK(eax, 16, 0x0f);
  150. case GET_TYPE :
  151. return BITMASK(eax, 12, 0x03);
  152. case GET_FAMILY :
  153. return BITMASK(eax, 8, 0x0f);
  154. case GET_MODEL :
  155. return BITMASK(eax, 4, 0x0f);
  156. case GET_APICID :
  157. return BITMASK(ebx, 24, 0x0f);
  158. case GET_LCOUNT :
  159. return BITMASK(ebx, 16, 0x0f);
  160. case GET_CHUNKS :
  161. return BITMASK(ebx, 8, 0x0f);
  162. case GET_STEPPING :
  163. return BITMASK(eax, 0, 0x0f);
  164. case GET_BLANDID :
  165. return BITMASK(ebx, 0, 0xff);
  166. case GET_NUMSHARE :
  167. if (have_cpuid() < 4) return 0;
  168. cpuid(4, &eax, &ebx, &ecx, &edx);
  169. return BITMASK(eax, 14, 0xfff);
  170. case GET_NUMCORES :
  171. if (have_cpuid() < 4) return 0;
  172. cpuid(4, &eax, &ebx, &ecx, &edx);
  173. return BITMASK(eax, 26, 0x3f);
  174. case GET_FEATURE :
  175. if ((edx & (1 << 3)) != 0) feature |= HAVE_PSE;
  176. if ((edx & (1 << 15)) != 0) feature |= HAVE_CMOV;
  177. if ((edx & (1 << 19)) != 0) feature |= HAVE_CFLUSH;
  178. if ((edx & (1 << 23)) != 0) feature |= HAVE_MMX;
  179. if ((edx & (1 << 25)) != 0) feature |= HAVE_SSE;
  180. if ((edx & (1 << 26)) != 0) feature |= HAVE_SSE2;
  181. if ((edx & (1 << 27)) != 0) {
  182. if (BITMASK(ebx, 16, 0x0f) > 0) feature |= HAVE_HIT;
  183. }
  184. if ((ecx & (1 << 0)) != 0) feature |= HAVE_SSE3;
  185. if ((ecx & (1 << 9)) != 0) feature |= HAVE_SSSE3;
  186. if ((ecx & (1 << 19)) != 0) feature |= HAVE_SSE4_1;
  187. if ((ecx & (1 << 20)) != 0) feature |= HAVE_SSE4_2;
  188. #ifndef NO_AVX
  189. if (support_avx()) feature |= HAVE_AVX;
  190. #endif
  191. if (have_excpuid() >= 0x01) {
  192. cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
  193. if ((ecx & (1 << 6)) != 0) feature |= HAVE_SSE4A;
  194. if ((ecx & (1 << 7)) != 0) feature |= HAVE_MISALIGNSSE;
  195. #ifndef NO_AVX
  196. if ((ecx & (1 << 16)) != 0) feature |= HAVE_FMA4;
  197. #endif
  198. if ((edx & (1 << 30)) != 0) feature |= HAVE_3DNOWEX;
  199. if ((edx & (1 << 31)) != 0) feature |= HAVE_3DNOW;
  200. }
  201. if (have_excpuid() >= 0x1a) {
  202. cpuid(0x8000001a, &eax, &ebx, &ecx, &edx);
  203. if ((eax & (1 << 0)) != 0) feature |= HAVE_128BITFPU;
  204. if ((eax & (1 << 1)) != 0) feature |= HAVE_FASTMOVU;
  205. }
  206. }
  207. return feature;
  208. }
  209. int get_cacheinfo(int type, cache_info_t *cacheinfo){
  210. int eax, ebx, ecx, edx, cpuid_level;
  211. int info[15];
  212. int i;
  213. cache_info_t LC1, LD1, L2, L3,
  214. ITB, DTB, LITB, LDTB,
  215. L2ITB, L2DTB, L2LITB, L2LDTB;
  216. LC1.size = 0; LC1.associative = 0; LC1.linesize = 0; LC1.shared = 0;
  217. LD1.size = 0; LD1.associative = 0; LD1.linesize = 0; LD1.shared = 0;
  218. L2.size = 0; L2.associative = 0; L2.linesize = 0; L2.shared = 0;
  219. L3.size = 0; L3.associative = 0; L3.linesize = 0; L3.shared = 0;
  220. ITB.size = 0; ITB.associative = 0; ITB.linesize = 0; ITB.shared = 0;
  221. DTB.size = 0; DTB.associative = 0; DTB.linesize = 0; DTB.shared = 0;
  222. LITB.size = 0; LITB.associative = 0; LITB.linesize = 0; LITB.shared = 0;
  223. LDTB.size = 0; LDTB.associative = 0; LDTB.linesize = 0; LDTB.shared = 0;
  224. L2ITB.size = 0; L2ITB.associative = 0; L2ITB.linesize = 0; L2ITB.shared = 0;
  225. L2DTB.size = 0; L2DTB.associative = 0; L2DTB.linesize = 0; L2DTB.shared = 0;
  226. L2LITB.size = 0; L2LITB.associative = 0; L2LITB.linesize = 0; L2LITB.shared = 0;
  227. L2LDTB.size = 0; L2LDTB.associative = 0; L2LDTB.linesize = 0; L2LDTB.shared = 0;
  228. cpuid(0, &cpuid_level, &ebx, &ecx, &edx);
  229. if (cpuid_level > 1) {
  230. cpuid(2, &eax, &ebx, &ecx, &edx);
  231. info[ 0] = BITMASK(eax, 8, 0xff);
  232. info[ 1] = BITMASK(eax, 16, 0xff);
  233. info[ 2] = BITMASK(eax, 24, 0xff);
  234. info[ 3] = BITMASK(ebx, 0, 0xff);
  235. info[ 4] = BITMASK(ebx, 8, 0xff);
  236. info[ 5] = BITMASK(ebx, 16, 0xff);
  237. info[ 6] = BITMASK(ebx, 24, 0xff);
  238. info[ 7] = BITMASK(ecx, 0, 0xff);
  239. info[ 8] = BITMASK(ecx, 8, 0xff);
  240. info[ 9] = BITMASK(ecx, 16, 0xff);
  241. info[10] = BITMASK(ecx, 24, 0xff);
  242. info[11] = BITMASK(edx, 0, 0xff);
  243. info[12] = BITMASK(edx, 8, 0xff);
  244. info[13] = BITMASK(edx, 16, 0xff);
  245. info[14] = BITMASK(edx, 24, 0xff);
  246. for (i = 0; i < 15; i++){
  247. switch (info[i]){
  248. /* This table is from http://www.sandpile.org/ia32/cpuid.htm */
  249. case 0x01 :
  250. ITB.size = 4;
  251. ITB.associative = 4;
  252. ITB.linesize = 32;
  253. break;
  254. case 0x02 :
  255. LITB.size = 4096;
  256. LITB.associative = 0;
  257. LITB.linesize = 2;
  258. break;
  259. case 0x03 :
  260. DTB.size = 4;
  261. DTB.associative = 4;
  262. DTB.linesize = 64;
  263. break;
  264. case 0x04 :
  265. LDTB.size = 4096;
  266. LDTB.associative = 4;
  267. LDTB.linesize = 8;
  268. break;
  269. case 0x05 :
  270. LDTB.size = 4096;
  271. LDTB.associative = 4;
  272. LDTB.linesize = 32;
  273. break;
  274. case 0x06 :
  275. LC1.size = 8;
  276. LC1.associative = 4;
  277. LC1.linesize = 32;
  278. break;
  279. case 0x08 :
  280. LC1.size = 16;
  281. LC1.associative = 4;
  282. LC1.linesize = 32;
  283. break;
  284. case 0x09 :
  285. LC1.size = 32;
  286. LC1.associative = 4;
  287. LC1.linesize = 64;
  288. break;
  289. case 0x0a :
  290. LD1.size = 8;
  291. LD1.associative = 2;
  292. LD1.linesize = 32;
  293. break;
  294. case 0x0c :
  295. LD1.size = 16;
  296. LD1.associative = 4;
  297. LD1.linesize = 32;
  298. break;
  299. case 0x0d :
  300. LD1.size = 16;
  301. LD1.associative = 4;
  302. LD1.linesize = 64;
  303. break;
  304. case 0x0e :
  305. LD1.size = 24;
  306. LD1.associative = 6;
  307. LD1.linesize = 64;
  308. break;
  309. case 0x10 :
  310. LD1.size = 16;
  311. LD1.associative = 4;
  312. LD1.linesize = 32;
  313. break;
  314. case 0x15 :
  315. LC1.size = 16;
  316. LC1.associative = 4;
  317. LC1.linesize = 32;
  318. break;
  319. case 0x1a :
  320. L2.size = 96;
  321. L2.associative = 6;
  322. L2.linesize = 64;
  323. break;
  324. case 0x21 :
  325. L2.size = 256;
  326. L2.associative = 8;
  327. L2.linesize = 64;
  328. break;
  329. case 0x22 :
  330. L3.size = 512;
  331. L3.associative = 4;
  332. L3.linesize = 64;
  333. break;
  334. case 0x23 :
  335. L3.size = 1024;
  336. L3.associative = 8;
  337. L3.linesize = 64;
  338. break;
  339. case 0x25 :
  340. L3.size = 2048;
  341. L3.associative = 8;
  342. L3.linesize = 64;
  343. break;
  344. case 0x29 :
  345. L3.size = 4096;
  346. L3.associative = 8;
  347. L3.linesize = 64;
  348. break;
  349. case 0x2c :
  350. LD1.size = 32;
  351. LD1.associative = 8;
  352. LD1.linesize = 64;
  353. break;
  354. case 0x30 :
  355. LC1.size = 32;
  356. LC1.associative = 8;
  357. LC1.linesize = 64;
  358. break;
  359. case 0x39 :
  360. L2.size = 128;
  361. L2.associative = 4;
  362. L2.linesize = 64;
  363. break;
  364. case 0x3a :
  365. L2.size = 192;
  366. L2.associative = 6;
  367. L2.linesize = 64;
  368. break;
  369. case 0x3b :
  370. L2.size = 128;
  371. L2.associative = 2;
  372. L2.linesize = 64;
  373. break;
  374. case 0x3c :
  375. L2.size = 256;
  376. L2.associative = 4;
  377. L2.linesize = 64;
  378. break;
  379. case 0x3d :
  380. L2.size = 384;
  381. L2.associative = 6;
  382. L2.linesize = 64;
  383. break;
  384. case 0x3e :
  385. L2.size = 512;
  386. L2.associative = 4;
  387. L2.linesize = 64;
  388. break;
  389. case 0x41 :
  390. L2.size = 128;
  391. L2.associative = 4;
  392. L2.linesize = 32;
  393. break;
  394. case 0x42 :
  395. L2.size = 256;
  396. L2.associative = 4;
  397. L2.linesize = 32;
  398. break;
  399. case 0x43 :
  400. L2.size = 512;
  401. L2.associative = 4;
  402. L2.linesize = 32;
  403. break;
  404. case 0x44 :
  405. L2.size = 1024;
  406. L2.associative = 4;
  407. L2.linesize = 32;
  408. break;
  409. case 0x45 :
  410. L2.size = 2048;
  411. L2.associative = 4;
  412. L2.linesize = 32;
  413. break;
  414. case 0x46 :
  415. L3.size = 4096;
  416. L3.associative = 4;
  417. L3.linesize = 64;
  418. break;
  419. case 0x47 :
  420. L3.size = 8192;
  421. L3.associative = 8;
  422. L3.linesize = 64;
  423. break;
  424. case 0x48 :
  425. L2.size = 3184;
  426. L2.associative = 12;
  427. L2.linesize = 64;
  428. break;
  429. case 0x49 :
  430. if ((get_cputype(GET_FAMILY) == 0x0f) && (get_cputype(GET_MODEL) == 0x06)) {
  431. L3.size = 4096;
  432. L3.associative = 16;
  433. L3.linesize = 64;
  434. } else {
  435. L2.size = 4096;
  436. L2.associative = 16;
  437. L2.linesize = 64;
  438. }
  439. break;
  440. case 0x4a :
  441. L3.size = 6144;
  442. L3.associative = 12;
  443. L3.linesize = 64;
  444. break;
  445. case 0x4b :
  446. L3.size = 8192;
  447. L3.associative = 16;
  448. L3.linesize = 64;
  449. break;
  450. case 0x4c :
  451. L3.size = 12280;
  452. L3.associative = 12;
  453. L3.linesize = 64;
  454. break;
  455. case 0x4d :
  456. L3.size = 16384;
  457. L3.associative = 16;
  458. L3.linesize = 64;
  459. break;
  460. case 0x4e :
  461. L2.size = 6144;
  462. L2.associative = 24;
  463. L2.linesize = 64;
  464. break;
  465. case 0x4f :
  466. ITB.size = 4;
  467. ITB.associative = 0;
  468. ITB.linesize = 32;
  469. break;
  470. case 0x50 :
  471. ITB.size = 4;
  472. ITB.associative = 0;
  473. ITB.linesize = 64;
  474. LITB.size = 4096;
  475. LITB.associative = 0;
  476. LITB.linesize = 64;
  477. LITB.shared = 1;
  478. break;
  479. case 0x51 :
  480. ITB.size = 4;
  481. ITB.associative = 0;
  482. ITB.linesize = 128;
  483. LITB.size = 4096;
  484. LITB.associative = 0;
  485. LITB.linesize = 128;
  486. LITB.shared = 1;
  487. break;
  488. case 0x52 :
  489. ITB.size = 4;
  490. ITB.associative = 0;
  491. ITB.linesize = 256;
  492. LITB.size = 4096;
  493. LITB.associative = 0;
  494. LITB.linesize = 256;
  495. LITB.shared = 1;
  496. break;
  497. case 0x55 :
  498. LITB.size = 4096;
  499. LITB.associative = 0;
  500. LITB.linesize = 7;
  501. LITB.shared = 1;
  502. break;
  503. case 0x56 :
  504. LDTB.size = 4096;
  505. LDTB.associative = 4;
  506. LDTB.linesize = 16;
  507. break;
  508. case 0x57 :
  509. LDTB.size = 4096;
  510. LDTB.associative = 4;
  511. LDTB.linesize = 16;
  512. break;
  513. case 0x5b :
  514. DTB.size = 4;
  515. DTB.associative = 0;
  516. DTB.linesize = 64;
  517. LDTB.size = 4096;
  518. LDTB.associative = 0;
  519. LDTB.linesize = 64;
  520. LDTB.shared = 1;
  521. break;
  522. case 0x5c :
  523. DTB.size = 4;
  524. DTB.associative = 0;
  525. DTB.linesize = 128;
  526. LDTB.size = 4096;
  527. LDTB.associative = 0;
  528. LDTB.linesize = 128;
  529. LDTB.shared = 1;
  530. break;
  531. case 0x5d :
  532. DTB.size = 4;
  533. DTB.associative = 0;
  534. DTB.linesize = 256;
  535. LDTB.size = 4096;
  536. LDTB.associative = 0;
  537. LDTB.linesize = 256;
  538. LDTB.shared = 1;
  539. break;
  540. case 0x60 :
  541. LD1.size = 16;
  542. LD1.associative = 8;
  543. LD1.linesize = 64;
  544. break;
  545. case 0x66 :
  546. LD1.size = 8;
  547. LD1.associative = 4;
  548. LD1.linesize = 64;
  549. break;
  550. case 0x67 :
  551. LD1.size = 16;
  552. LD1.associative = 4;
  553. LD1.linesize = 64;
  554. break;
  555. case 0x68 :
  556. LD1.size = 32;
  557. LD1.associative = 4;
  558. LD1.linesize = 64;
  559. break;
  560. case 0x70 :
  561. LC1.size = 12;
  562. LC1.associative = 8;
  563. break;
  564. case 0x71 :
  565. LC1.size = 16;
  566. LC1.associative = 8;
  567. break;
  568. case 0x72 :
  569. LC1.size = 32;
  570. LC1.associative = 8;
  571. break;
  572. case 0x73 :
  573. LC1.size = 64;
  574. LC1.associative = 8;
  575. break;
  576. case 0x77 :
  577. LC1.size = 16;
  578. LC1.associative = 4;
  579. LC1.linesize = 64;
  580. break;
  581. case 0x78 :
  582. L2.size = 1024;
  583. L2.associative = 4;
  584. L2.linesize = 64;
  585. break;
  586. case 0x79 :
  587. L2.size = 128;
  588. L2.associative = 8;
  589. L2.linesize = 64;
  590. break;
  591. case 0x7a :
  592. L2.size = 256;
  593. L2.associative = 8;
  594. L2.linesize = 64;
  595. break;
  596. case 0x7b :
  597. L2.size = 512;
  598. L2.associative = 8;
  599. L2.linesize = 64;
  600. break;
  601. case 0x7c :
  602. L2.size = 1024;
  603. L2.associative = 8;
  604. L2.linesize = 64;
  605. break;
  606. case 0x7d :
  607. L2.size = 2048;
  608. L2.associative = 8;
  609. L2.linesize = 64;
  610. break;
  611. case 0x7e :
  612. L2.size = 256;
  613. L2.associative = 8;
  614. L2.linesize = 128;
  615. break;
  616. case 0x7f :
  617. L2.size = 512;
  618. L2.associative = 2;
  619. L2.linesize = 64;
  620. break;
  621. case 0x81 :
  622. L2.size = 128;
  623. L2.associative = 8;
  624. L2.linesize = 32;
  625. break;
  626. case 0x82 :
  627. L2.size = 256;
  628. L2.associative = 8;
  629. L2.linesize = 32;
  630. break;
  631. case 0x83 :
  632. L2.size = 512;
  633. L2.associative = 8;
  634. L2.linesize = 32;
  635. break;
  636. case 0x84 :
  637. L2.size = 1024;
  638. L2.associative = 8;
  639. L2.linesize = 32;
  640. break;
  641. case 0x85 :
  642. L2.size = 2048;
  643. L2.associative = 8;
  644. L2.linesize = 32;
  645. break;
  646. case 0x86 :
  647. L2.size = 512;
  648. L2.associative = 4;
  649. L2.linesize = 64;
  650. break;
  651. case 0x87 :
  652. L2.size = 1024;
  653. L2.associative = 8;
  654. L2.linesize = 64;
  655. break;
  656. case 0x88 :
  657. L3.size = 2048;
  658. L3.associative = 4;
  659. L3.linesize = 64;
  660. break;
  661. case 0x89 :
  662. L3.size = 4096;
  663. L3.associative = 4;
  664. L3.linesize = 64;
  665. break;
  666. case 0x8a :
  667. L3.size = 8192;
  668. L3.associative = 4;
  669. L3.linesize = 64;
  670. break;
  671. case 0x8d :
  672. L3.size = 3096;
  673. L3.associative = 12;
  674. L3.linesize = 128;
  675. break;
  676. case 0x90 :
  677. ITB.size = 4;
  678. ITB.associative = 0;
  679. ITB.linesize = 64;
  680. break;
  681. case 0x96 :
  682. DTB.size = 4;
  683. DTB.associative = 0;
  684. DTB.linesize = 32;
  685. break;
  686. case 0x9b :
  687. L2DTB.size = 4;
  688. L2DTB.associative = 0;
  689. L2DTB.linesize = 96;
  690. break;
  691. case 0xb0 :
  692. ITB.size = 4;
  693. ITB.associative = 4;
  694. ITB.linesize = 128;
  695. break;
  696. case 0xb1 :
  697. LITB.size = 4096;
  698. LITB.associative = 4;
  699. LITB.linesize = 4;
  700. break;
  701. case 0xb2 :
  702. ITB.size = 4;
  703. ITB.associative = 4;
  704. ITB.linesize = 64;
  705. break;
  706. case 0xb3 :
  707. DTB.size = 4;
  708. DTB.associative = 4;
  709. DTB.linesize = 128;
  710. break;
  711. case 0xb4 :
  712. DTB.size = 4;
  713. DTB.associative = 4;
  714. DTB.linesize = 256;
  715. break;
  716. case 0xba :
  717. DTB.size = 4;
  718. DTB.associative = 4;
  719. DTB.linesize = 64;
  720. break;
  721. case 0xd0 :
  722. L3.size = 512;
  723. L3.associative = 4;
  724. L3.linesize = 64;
  725. break;
  726. case 0xd1 :
  727. L3.size = 1024;
  728. L3.associative = 4;
  729. L3.linesize = 64;
  730. break;
  731. case 0xd2 :
  732. L3.size = 2048;
  733. L3.associative = 4;
  734. L3.linesize = 64;
  735. break;
  736. case 0xd6 :
  737. L3.size = 1024;
  738. L3.associative = 8;
  739. L3.linesize = 64;
  740. break;
  741. case 0xd7 :
  742. L3.size = 2048;
  743. L3.associative = 8;
  744. L3.linesize = 64;
  745. break;
  746. case 0xd8 :
  747. L3.size = 4096;
  748. L3.associative = 8;
  749. L3.linesize = 64;
  750. break;
  751. case 0xdc :
  752. L3.size = 2048;
  753. L3.associative = 12;
  754. L3.linesize = 64;
  755. break;
  756. case 0xdd :
  757. L3.size = 4096;
  758. L3.associative = 12;
  759. L3.linesize = 64;
  760. break;
  761. case 0xde :
  762. L3.size = 8192;
  763. L3.associative = 12;
  764. L3.linesize = 64;
  765. break;
  766. case 0xe2 :
  767. L3.size = 2048;
  768. L3.associative = 16;
  769. L3.linesize = 64;
  770. break;
  771. case 0xe3 :
  772. L3.size = 4096;
  773. L3.associative = 16;
  774. L3.linesize = 64;
  775. break;
  776. case 0xe4 :
  777. L3.size = 8192;
  778. L3.associative = 16;
  779. L3.linesize = 64;
  780. break;
  781. }
  782. }
  783. }
  784. if (get_vendor() == VENDOR_INTEL) {
  785. cpuid(0x80000000, &cpuid_level, &ebx, &ecx, &edx);
  786. if (cpuid_level >= 0x80000006) {
  787. cpuid(0x80000006, &eax, &ebx, &ecx, &edx);
  788. L2.size = BITMASK(ecx, 16, 0xffff);
  789. L2.associative = BITMASK(ecx, 12, 0x0f);
  790. L2.linesize = BITMASK(ecx, 0, 0xff);
  791. }
  792. }
  793. if ((get_vendor() == VENDOR_AMD) || (get_vendor() == VENDOR_CENTAUR)) {
  794. cpuid(0x80000005, &eax, &ebx, &ecx, &edx);
  795. LDTB.size = 4096;
  796. LDTB.associative = BITMASK(eax, 24, 0xff);
  797. if (LDTB.associative == 0xff) LDTB.associative = 0;
  798. LDTB.linesize = BITMASK(eax, 16, 0xff);
  799. LITB.size = 4096;
  800. LITB.associative = BITMASK(eax, 8, 0xff);
  801. if (LITB.associative == 0xff) LITB.associative = 0;
  802. LITB.linesize = BITMASK(eax, 0, 0xff);
  803. DTB.size = 4;
  804. DTB.associative = BITMASK(ebx, 24, 0xff);
  805. if (DTB.associative == 0xff) DTB.associative = 0;
  806. DTB.linesize = BITMASK(ebx, 16, 0xff);
  807. ITB.size = 4;
  808. ITB.associative = BITMASK(ebx, 8, 0xff);
  809. if (ITB.associative == 0xff) ITB.associative = 0;
  810. ITB.linesize = BITMASK(ebx, 0, 0xff);
  811. LD1.size = BITMASK(ecx, 24, 0xff);
  812. LD1.associative = BITMASK(ecx, 16, 0xff);
  813. if (LD1.associative == 0xff) LD1.associative = 0;
  814. LD1.linesize = BITMASK(ecx, 0, 0xff);
  815. LC1.size = BITMASK(ecx, 24, 0xff);
  816. LC1.associative = BITMASK(ecx, 16, 0xff);
  817. if (LC1.associative == 0xff) LC1.associative = 0;
  818. LC1.linesize = BITMASK(ecx, 0, 0xff);
  819. cpuid(0x80000006, &eax, &ebx, &ecx, &edx);
  820. L2LDTB.size = 4096;
  821. L2LDTB.associative = BITMASK(eax, 24, 0xff);
  822. if (L2LDTB.associative == 0xff) L2LDTB.associative = 0;
  823. L2LDTB.linesize = BITMASK(eax, 16, 0xff);
  824. L2LITB.size = 4096;
  825. L2LITB.associative = BITMASK(eax, 8, 0xff);
  826. if (L2LITB.associative == 0xff) L2LITB.associative = 0;
  827. L2LITB.linesize = BITMASK(eax, 0, 0xff);
  828. L2DTB.size = 4;
  829. L2DTB.associative = BITMASK(ebx, 24, 0xff);
  830. if (L2DTB.associative == 0xff) L2DTB.associative = 0;
  831. L2DTB.linesize = BITMASK(ebx, 16, 0xff);
  832. L2ITB.size = 4;
  833. L2ITB.associative = BITMASK(ebx, 8, 0xff);
  834. if (L2ITB.associative == 0xff) L2ITB.associative = 0;
  835. L2ITB.linesize = BITMASK(ebx, 0, 0xff);
  836. L2.size = BITMASK(ecx, 16, 0xffff);
  837. L2.associative = BITMASK(ecx, 12, 0xf);
  838. if (L2.associative == 0xff) L2.associative = 0;
  839. L2.linesize = BITMASK(ecx, 0, 0xff);
  840. L3.size = BITMASK(edx, 18, 0x3fff) * 512;
  841. L3.associative = BITMASK(edx, 12, 0xf);
  842. if (L3.associative == 0xff) L2.associative = 0;
  843. L3.linesize = BITMASK(edx, 0, 0xff);
  844. }
  845. switch (type) {
  846. case CACHE_INFO_L1_I :
  847. *cacheinfo = LC1;
  848. break;
  849. case CACHE_INFO_L1_D :
  850. *cacheinfo = LD1;
  851. break;
  852. case CACHE_INFO_L2 :
  853. *cacheinfo = L2;
  854. break;
  855. case CACHE_INFO_L3 :
  856. *cacheinfo = L3;
  857. break;
  858. case CACHE_INFO_L1_DTB :
  859. *cacheinfo = DTB;
  860. break;
  861. case CACHE_INFO_L1_ITB :
  862. *cacheinfo = ITB;
  863. break;
  864. case CACHE_INFO_L1_LDTB :
  865. *cacheinfo = LDTB;
  866. break;
  867. case CACHE_INFO_L1_LITB :
  868. *cacheinfo = LITB;
  869. break;
  870. case CACHE_INFO_L2_DTB :
  871. *cacheinfo = L2DTB;
  872. break;
  873. case CACHE_INFO_L2_ITB :
  874. *cacheinfo = L2ITB;
  875. break;
  876. case CACHE_INFO_L2_LDTB :
  877. *cacheinfo = L2LDTB;
  878. break;
  879. case CACHE_INFO_L2_LITB :
  880. *cacheinfo = L2LITB;
  881. break;
  882. }
  883. return 0;
  884. }
  885. int get_cpuname(void){
  886. int family, exfamily, model, vendor, exmodel;
  887. if (!have_cpuid()) return CPUTYPE_80386;
  888. family = get_cputype(GET_FAMILY);
  889. exfamily = get_cputype(GET_EXFAMILY);
  890. model = get_cputype(GET_MODEL);
  891. exmodel = get_cputype(GET_EXMODEL);
  892. vendor = get_vendor();
  893. if (vendor == VENDOR_INTEL){
  894. switch (family) {
  895. case 0x4:
  896. return CPUTYPE_80486;
  897. case 0x5:
  898. return CPUTYPE_PENTIUM;
  899. case 0x6:
  900. switch (exmodel) {
  901. case 0:
  902. switch (model) {
  903. case 1:
  904. case 3:
  905. case 5:
  906. case 6:
  907. return CPUTYPE_PENTIUM2;
  908. case 7:
  909. case 8:
  910. case 10:
  911. case 11:
  912. return CPUTYPE_PENTIUM3;
  913. case 9:
  914. case 13:
  915. case 14:
  916. return CPUTYPE_PENTIUMM;
  917. case 15:
  918. return CPUTYPE_CORE2;
  919. }
  920. break;
  921. case 1:
  922. switch (model) {
  923. case 6:
  924. return CPUTYPE_CORE2;
  925. case 7:
  926. return CPUTYPE_PENRYN;
  927. case 10:
  928. case 11:
  929. case 14:
  930. case 15:
  931. return CPUTYPE_NEHALEM;
  932. case 12:
  933. return CPUTYPE_ATOM;
  934. case 13:
  935. return CPUTYPE_DUNNINGTON;
  936. }
  937. break;
  938. case 2:
  939. switch (model) {
  940. case 5:
  941. //Intel Core (Clarkdale) / Core (Arrandale)
  942. // Pentium (Clarkdale) / Pentium Mobile (Arrandale)
  943. // Xeon (Clarkdale), 32nm
  944. return CPUTYPE_NEHALEM;
  945. case 10:
  946. //Intel Core i5-2000 /i7-2000 (Sandy Bridge)
  947. if(support_avx())
  948. return CPUTYPE_SANDYBRIDGE;
  949. else
  950. return CPUTYPE_NEHALEM; //OS doesn't support AVX
  951. case 12:
  952. //Xeon Processor 5600 (Westmere-EP)
  953. return CPUTYPE_NEHALEM;
  954. case 13:
  955. //Intel Core i7-3000 / Xeon E5 (Sandy Bridge)
  956. if(support_avx())
  957. return CPUTYPE_SANDYBRIDGE;
  958. else
  959. return CPUTYPE_NEHALEM;
  960. case 15:
  961. //Xeon Processor E7 (Westmere-EX)
  962. return CPUTYPE_NEHALEM;
  963. }
  964. break;
  965. case 3:
  966. switch (model) {
  967. case 10:
  968. if(support_avx())
  969. return CPUTYPE_SANDYBRIDGE;
  970. else
  971. return CPUTYPE_NEHALEM;
  972. }
  973. break;
  974. }
  975. break;
  976. case 0x7:
  977. return CPUTYPE_ITANIUM;
  978. case 0xf:
  979. switch (exfamily) {
  980. case 0 :
  981. return CPUTYPE_PENTIUM4;
  982. case 1 :
  983. return CPUTYPE_ITANIUM;
  984. }
  985. break;
  986. }
  987. return CPUTYPE_INTEL_UNKNOWN;
  988. }
  989. if (vendor == VENDOR_AMD){
  990. switch (family) {
  991. case 0x4:
  992. return CPUTYPE_AMD5X86;
  993. case 0x5:
  994. return CPUTYPE_AMDK6;
  995. case 0x6:
  996. return CPUTYPE_ATHLON;
  997. case 0xf:
  998. switch (exfamily) {
  999. case 0:
  1000. case 2:
  1001. return CPUTYPE_OPTERON;
  1002. case 1:
  1003. case 10:
  1004. return CPUTYPE_BARCELONA;
  1005. case 6: //AMD Bulldozer Opteron 6200 / Opteron 4200 / AMD FX-Series
  1006. if(support_avx())
  1007. return CPUTYPE_BULLDOZER;
  1008. else
  1009. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1010. case 5:
  1011. return CPUTYPE_BOBCAT;
  1012. }
  1013. break;
  1014. }
  1015. return CPUTYPE_AMD_UNKNOWN;
  1016. }
  1017. if (vendor == VENDOR_CYRIX){
  1018. switch (family) {
  1019. case 0x4:
  1020. return CPUTYPE_CYRIX5X86;
  1021. case 0x5:
  1022. return CPUTYPE_CYRIXM1;
  1023. case 0x6:
  1024. return CPUTYPE_CYRIXM2;
  1025. }
  1026. return CPUTYPE_CYRIX_UNKNOWN;
  1027. }
  1028. if (vendor == VENDOR_NEXGEN){
  1029. switch (family) {
  1030. case 0x5:
  1031. return CPUTYPE_NEXGENNX586;
  1032. }
  1033. return CPUTYPE_NEXGEN_UNKNOWN;
  1034. }
  1035. if (vendor == VENDOR_CENTAUR){
  1036. switch (family) {
  1037. case 0x5:
  1038. return CPUTYPE_CENTAURC6;
  1039. break;
  1040. case 0x6:
  1041. return CPUTYPE_NANO;
  1042. break;
  1043. }
  1044. return CPUTYPE_VIAC3;
  1045. }
  1046. if (vendor == VENDOR_RISE){
  1047. switch (family) {
  1048. case 0x5:
  1049. return CPUTYPE_RISEMP6;
  1050. }
  1051. return CPUTYPE_RISE_UNKNOWN;
  1052. }
  1053. if (vendor == VENDOR_SIS){
  1054. switch (family) {
  1055. case 0x5:
  1056. return CPUTYPE_SYS55X;
  1057. }
  1058. return CPUTYPE_SIS_UNKNOWN;
  1059. }
  1060. if (vendor == VENDOR_TRANSMETA){
  1061. switch (family) {
  1062. case 0x5:
  1063. return CPUTYPE_CRUSOETM3X;
  1064. }
  1065. return CPUTYPE_TRANSMETA_UNKNOWN;
  1066. }
  1067. if (vendor == VENDOR_NSC){
  1068. switch (family) {
  1069. case 0x5:
  1070. return CPUTYPE_NSGEODE;
  1071. }
  1072. return CPUTYPE_NSC_UNKNOWN;
  1073. }
  1074. return CPUTYPE_UNKNOWN;
  1075. }
  1076. static char *cpuname[] = {
  1077. "UNKNOWN",
  1078. "INTEL_UNKNOWN",
  1079. "UMC_UNKNOWN",
  1080. "AMD_UNKNOWN",
  1081. "CYRIX_UNKNOWN",
  1082. "NEXGEN_UNKNOWN",
  1083. "CENTAUR_UNKNOWN",
  1084. "RISE_UNKNOWN",
  1085. "SIS_UNKNOWN",
  1086. "TRANSMETA_UNKNOWN",
  1087. "NSC_UNKNOWN",
  1088. "80386",
  1089. "80486",
  1090. "PENTIUM",
  1091. "PENTIUM2",
  1092. "PENTIUM3",
  1093. "PENTIUMM",
  1094. "PENTIUM4",
  1095. "CORE2",
  1096. "PENRYN",
  1097. "DUNNINGTON",
  1098. "NEHALEM",
  1099. "ATOM",
  1100. "ITANIUM",
  1101. "ITANIUM2",
  1102. "5X86",
  1103. "K6",
  1104. "ATHLON",
  1105. "DURON",
  1106. "OPTERON",
  1107. "BARCELONA",
  1108. "SHANGHAI",
  1109. "ISTANBUL",
  1110. "CYRIX5X86",
  1111. "CYRIXM1",
  1112. "CYRIXM2",
  1113. "NEXGENNX586",
  1114. "CENTAURC6",
  1115. "RISEMP6",
  1116. "SYS55X",
  1117. "TM3X00",
  1118. "NSGEODE",
  1119. "VIAC3",
  1120. "NANO",
  1121. "SANDYBRIDGE",
  1122. "BOBCAT",
  1123. "BULLDOZER",
  1124. };
  1125. static char *lowercpuname[] = {
  1126. "unknown",
  1127. "intel_unknown",
  1128. "umc_unknown",
  1129. "amd_unknown",
  1130. "cyrix_unknown",
  1131. "nexgen_unknown",
  1132. "centaur_unknown",
  1133. "rise_unknown",
  1134. "sis_unknown",
  1135. "transmeta_unknown",
  1136. "nsc_unknown",
  1137. "80386",
  1138. "80486",
  1139. "pentium",
  1140. "pentium2",
  1141. "pentium3",
  1142. "pentiumm",
  1143. "pentium4",
  1144. "core2",
  1145. "penryn",
  1146. "dunnington",
  1147. "nehalem",
  1148. "atom",
  1149. "itanium",
  1150. "itanium2",
  1151. "5x86",
  1152. "k6",
  1153. "athlon",
  1154. "duron",
  1155. "opteron",
  1156. "barcelona",
  1157. "shanghai",
  1158. "istanbul",
  1159. "cyrix5x86",
  1160. "cyrixm1",
  1161. "cyrixm2",
  1162. "nexgennx586",
  1163. "centaurc6",
  1164. "risemp6",
  1165. "sys55x",
  1166. "tms3x00",
  1167. "nsgeode",
  1168. "nano",
  1169. "sandybridge",
  1170. "bobcat",
  1171. "bulldozer",
  1172. };
  1173. static char *corename[] = {
  1174. "UNKOWN",
  1175. "80486",
  1176. "P5",
  1177. "P6",
  1178. "KATMAI",
  1179. "COPPERMINE",
  1180. "NORTHWOOD",
  1181. "PRESCOTT",
  1182. "BANIAS",
  1183. "ATHLON",
  1184. "OPTERON",
  1185. "BARCELONA",
  1186. "VIAC3",
  1187. "YONAH",
  1188. "CORE2",
  1189. "PENRYN",
  1190. "DUNNINGTON",
  1191. "NEHALEM",
  1192. "ATOM",
  1193. "NANO",
  1194. "SANDYBRIDGE",
  1195. "BOBCAT",
  1196. "BULLDOZER",
  1197. };
  1198. static char *corename_lower[] = {
  1199. "unknown",
  1200. "80486",
  1201. "p5",
  1202. "p6",
  1203. "katmai",
  1204. "coppermine",
  1205. "northwood",
  1206. "prescott",
  1207. "banias",
  1208. "athlon",
  1209. "opteron",
  1210. "barcelona",
  1211. "viac3",
  1212. "yonah",
  1213. "core2",
  1214. "penryn",
  1215. "dunnington",
  1216. "nehalem",
  1217. "atom",
  1218. "nano",
  1219. "sandybridge",
  1220. "bobcat",
  1221. "bulldozer",
  1222. };
  1223. char *get_cpunamechar(void){
  1224. return cpuname[get_cpuname()];
  1225. }
  1226. char *get_lower_cpunamechar(void){
  1227. return lowercpuname[get_cpuname()];
  1228. }
  1229. int get_coretype(void){
  1230. int family, exfamily, model, exmodel, vendor;
  1231. if (!have_cpuid()) return CORE_80486;
  1232. family = get_cputype(GET_FAMILY);
  1233. exfamily = get_cputype(GET_EXFAMILY);
  1234. model = get_cputype(GET_MODEL);
  1235. exmodel = get_cputype(GET_EXMODEL);
  1236. vendor = get_vendor();
  1237. if (vendor == VENDOR_INTEL){
  1238. switch (family) {
  1239. case 4:
  1240. return CORE_80486;
  1241. case 5:
  1242. return CORE_P5;
  1243. case 6:
  1244. switch (exmodel) {
  1245. case 0:
  1246. switch (model) {
  1247. case 0:
  1248. case 1:
  1249. case 2:
  1250. case 3:
  1251. case 4:
  1252. case 5:
  1253. case 6:
  1254. return CORE_P6;
  1255. case 7:
  1256. return CORE_KATMAI;
  1257. case 8:
  1258. case 10:
  1259. case 11:
  1260. return CORE_COPPERMINE;
  1261. case 9:
  1262. case 13:
  1263. case 14:
  1264. return CORE_BANIAS;
  1265. case 15:
  1266. return CORE_CORE2;
  1267. }
  1268. break;
  1269. case 1:
  1270. switch (model) {
  1271. case 6:
  1272. return CORE_CORE2;
  1273. case 7:
  1274. return CORE_PENRYN;
  1275. case 10:
  1276. case 11:
  1277. case 14:
  1278. case 15:
  1279. return CORE_NEHALEM;
  1280. case 12:
  1281. return CORE_ATOM;
  1282. case 13:
  1283. return CORE_DUNNINGTON;
  1284. }
  1285. break;
  1286. case 2:
  1287. switch (model) {
  1288. case 5:
  1289. //Intel Core (Clarkdale) / Core (Arrandale)
  1290. // Pentium (Clarkdale) / Pentium Mobile (Arrandale)
  1291. // Xeon (Clarkdale), 32nm
  1292. return CORE_NEHALEM;
  1293. case 10:
  1294. //Intel Core i5-2000 /i7-2000 (Sandy Bridge)
  1295. if(support_avx())
  1296. return CORE_SANDYBRIDGE;
  1297. else
  1298. return CORE_NEHALEM; //OS doesn't support AVX
  1299. case 12:
  1300. //Xeon Processor 5600 (Westmere-EP)
  1301. return CORE_NEHALEM;
  1302. case 13:
  1303. //Intel Core i7-3000 / Xeon E5 (Sandy Bridge)
  1304. if(support_avx())
  1305. return CORE_SANDYBRIDGE;
  1306. else
  1307. return CORE_NEHALEM; //OS doesn't support AVX
  1308. case 15:
  1309. //Xeon Processor E7 (Westmere-EX)
  1310. return CORE_NEHALEM;
  1311. }
  1312. break;
  1313. case 3:
  1314. switch (model) {
  1315. case 10:
  1316. if(support_avx())
  1317. return CORE_SANDYBRIDGE;
  1318. else
  1319. return CORE_NEHALEM; //OS doesn't support AVX
  1320. }
  1321. break;
  1322. }
  1323. break;
  1324. case 15:
  1325. if (model <= 0x2) return CORE_NORTHWOOD;
  1326. else return CORE_PRESCOTT;
  1327. }
  1328. }
  1329. if (vendor == VENDOR_AMD){
  1330. if (family <= 0x5) return CORE_80486;
  1331. if (family <= 0xe) return CORE_ATHLON;
  1332. if (family == 0xf){
  1333. if ((exfamily == 0) || (exfamily == 2)) return CORE_OPTERON;
  1334. else if (exfamily == 5) return CORE_BOBCAT;
  1335. else if (exfamily == 6) {
  1336. //AMD Bulldozer Opteron 6200 / Opteron 4200 / AMD FX-Series
  1337. if(support_avx())
  1338. return CORE_BULLDOZER;
  1339. else
  1340. return CORE_BARCELONA; //OS don't support AVX. Use old kernels.
  1341. }else return CORE_BARCELONA;
  1342. }
  1343. }
  1344. if (vendor == VENDOR_CENTAUR) {
  1345. switch (family) {
  1346. case 0x6:
  1347. return CORE_NANO;
  1348. break;
  1349. }
  1350. return CORE_VIAC3;
  1351. }
  1352. return CORE_UNKNOWN;
  1353. }
  1354. void get_cpuconfig(void){
  1355. cache_info_t info;
  1356. int features;
  1357. printf("#define %s\n", cpuname[get_cpuname()]);
  1358. if (get_coretype() != CORE_P5) {
  1359. get_cacheinfo(CACHE_INFO_L1_I, &info);
  1360. if (info.size > 0) {
  1361. printf("#define L1_CODE_SIZE %d\n", info.size * 1024);
  1362. printf("#define L1_CODE_ASSOCIATIVE %d\n", info.associative);
  1363. printf("#define L1_CODE_LINESIZE %d\n", info.linesize);
  1364. }
  1365. get_cacheinfo(CACHE_INFO_L1_D, &info);
  1366. if (info.size > 0) {
  1367. printf("#define L1_DATA_SIZE %d\n", info.size * 1024);
  1368. printf("#define L1_DATA_ASSOCIATIVE %d\n", info.associative);
  1369. printf("#define L1_DATA_LINESIZE %d\n", info.linesize);
  1370. }
  1371. get_cacheinfo(CACHE_INFO_L2, &info);
  1372. if (info.size > 0) {
  1373. printf("#define L2_SIZE %d\n", info.size * 1024);
  1374. printf("#define L2_ASSOCIATIVE %d\n", info.associative);
  1375. printf("#define L2_LINESIZE %d\n", info.linesize);
  1376. }
  1377. get_cacheinfo(CACHE_INFO_L3, &info);
  1378. if (info.size > 0) {
  1379. printf("#define L3_SIZE %d\n", info.size * 1024);
  1380. printf("#define L3_ASSOCIATIVE %d\n", info.associative);
  1381. printf("#define L3_LINESIZE %d\n", info.linesize);
  1382. }
  1383. get_cacheinfo(CACHE_INFO_L1_ITB, &info);
  1384. if (info.size > 0) {
  1385. printf("#define ITB_SIZE %d\n", info.size * 1024);
  1386. printf("#define ITB_ASSOCIATIVE %d\n", info.associative);
  1387. printf("#define ITB_ENTRIES %d\n", info.linesize);
  1388. }
  1389. get_cacheinfo(CACHE_INFO_L1_DTB, &info);
  1390. if (info.size > 0) {
  1391. printf("#define DTB_SIZE %d\n", info.size * 1024);
  1392. printf("#define DTB_ASSOCIATIVE %d\n", info.associative);
  1393. printf("#define DTB_DEFAULT_ENTRIES %d\n", info.linesize);
  1394. }
  1395. features = get_cputype(GET_FEATURE);
  1396. if (features & HAVE_CMOV ) printf("#define HAVE_CMOV\n");
  1397. if (features & HAVE_MMX ) printf("#define HAVE_MMX\n");
  1398. if (features & HAVE_SSE ) printf("#define HAVE_SSE\n");
  1399. if (features & HAVE_SSE2 ) printf("#define HAVE_SSE2\n");
  1400. if (features & HAVE_SSE3 ) printf("#define HAVE_SSE3\n");
  1401. if (features & HAVE_SSSE3) printf("#define HAVE_SSSE3\n");
  1402. if (features & HAVE_SSE4_1) printf("#define HAVE_SSE4_1\n");
  1403. if (features & HAVE_SSE4_2) printf("#define HAVE_SSE4_2\n");
  1404. if (features & HAVE_SSE4A) printf("#define HAVE_SSE4A\n");
  1405. if (features & HAVE_SSE5 ) printf("#define HAVE_SSSE5\n");
  1406. if (features & HAVE_AVX ) printf("#define HAVE_AVX\n");
  1407. if (features & HAVE_3DNOWEX) printf("#define HAVE_3DNOWEX\n");
  1408. if (features & HAVE_3DNOW) printf("#define HAVE_3DNOW\n");
  1409. if (features & HAVE_FMA4 ) printf("#define HAVE_FMA4\n");
  1410. if (features & HAVE_CFLUSH) printf("#define HAVE_CFLUSH\n");
  1411. if (features & HAVE_HIT) printf("#define HAVE_HIT 1\n");
  1412. if (features & HAVE_MISALIGNSSE) printf("#define HAVE_MISALIGNSSE\n");
  1413. if (features & HAVE_128BITFPU) printf("#define HAVE_128BITFPU\n");
  1414. if (features & HAVE_FASTMOVU) printf("#define HAVE_FASTMOVU\n");
  1415. printf("#define NUM_SHAREDCACHE %d\n", get_cputype(GET_NUMSHARE) + 1);
  1416. printf("#define NUM_CORES %d\n", get_cputype(GET_NUMCORES) + 1);
  1417. features = get_coretype();
  1418. if (features > 0) printf("#define CORE_%s\n", corename[features]);
  1419. } else {
  1420. printf("#define DTB_DEFAULT_ENTRIES 16\n");
  1421. printf("#define L1_CODE_SIZE 8192\n");
  1422. printf("#define L1_DATA_SIZE 8192\n");
  1423. printf("#define L2_SIZE 0\n");
  1424. }
  1425. }
  1426. void get_architecture(void){
  1427. #ifndef __64BIT__
  1428. printf("X86");
  1429. #else
  1430. printf("X86_64");
  1431. #endif
  1432. }
  1433. void get_subarchitecture(void){
  1434. printf("%s", get_cpunamechar());
  1435. }
  1436. void get_subdirname(void){
  1437. #ifndef __64BIT__
  1438. printf("x86");
  1439. #else
  1440. printf("x86_64");
  1441. #endif
  1442. }
  1443. char *get_corename(void){
  1444. return corename[get_coretype()];
  1445. }
  1446. void get_libname(void){
  1447. printf("%s", corename_lower[get_coretype()]);
  1448. }
  1449. /* This if for Makefile */
  1450. void get_sse(void){
  1451. int features;
  1452. features = get_cputype(GET_FEATURE);
  1453. if (features & HAVE_MMX ) printf("HAVE_MMX=1\n");
  1454. if (features & HAVE_SSE ) printf("HAVE_SSE=1\n");
  1455. if (features & HAVE_SSE2 ) printf("HAVE_SSE2=1\n");
  1456. if (features & HAVE_SSE3 ) printf("HAVE_SSE3=1\n");
  1457. if (features & HAVE_SSSE3) printf("HAVE_SSSE3=1\n");
  1458. if (features & HAVE_SSE4_1) printf("HAVE_SSE4_1=1\n");
  1459. if (features & HAVE_SSE4_2) printf("HAVE_SSE4_2=1\n");
  1460. if (features & HAVE_SSE4A) printf("HAVE_SSE4A=1\n");
  1461. if (features & HAVE_SSE5 ) printf("HAVE_SSSE5=1\n");
  1462. if (features & HAVE_AVX ) printf("HAVE_AVX=1\n");
  1463. if (features & HAVE_3DNOWEX) printf("HAVE_3DNOWEX=1\n");
  1464. if (features & HAVE_3DNOW) printf("HAVE_3DNOW=1\n");
  1465. if (features & HAVE_FMA4 ) printf("HAVE_FMA4=1\n");
  1466. }