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 36 kB

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