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 
39 #include <stdio.h>
40 #include <string.h>
41 #ifdef linux
42 #include <sys/sysinfo.h>
43 #endif
44 #include "cpuid.h"
45 
46 #ifdef __ECC
47 #include <ia64intrin.h>
48 #endif
49 
cpuid(unsigned long regnum)50 static inline unsigned long cpuid(unsigned long regnum){
51   unsigned long value;
52 
53 #ifdef __ECC
54   value = __getIndReg(_IA64_REG_INDR_CPUID, regnum);
55 #else
56   asm ("mov %0=cpuid[%r1]" : "=r"(value) : "rO"(regnum));
57 #endif
58 
59   return value;
60 }
61 
have_cpuid(void)62 int have_cpuid(void){ return 1;}
63 
get_vendor(void)64 int get_vendor(void){
65   unsigned long cpuid0, cpuid1;
66   char vendor[18];
67 
68   cpuid0 = cpuid(0);
69   cpuid1 = cpuid(1);
70 
71   *(unsigned long *)(&vendor[0]) = cpuid0;
72   *(unsigned long *)(&vendor[8]) = cpuid1;
73   vendor[17] = (char)0;
74 
75   if (!strcmp(vendor, "GenuineIntel")) return VENDOR_INTEL;
76 
77   return VENDOR_UNKNOWN;
78 }
79 
get_cputype(int gettype)80 int get_cputype(int gettype){
81   unsigned long cpuid3;
82 
83   cpuid3 = cpuid(3);
84 
85   switch (gettype) {
86   case GET_ARCHREV :
87     return BITMASK(cpuid3, 32, 0xff);
88   case GET_FAMILY :
89     return BITMASK(cpuid3, 24, 0xff);
90   case GET_MODEL :
91     return BITMASK(cpuid3, 16, 0xff);
92   case GET_REVISION :
93     return BITMASK(cpuid3,  8, 0xff);
94   case GET_NUMBER :
95     return BITMASK(cpuid3,  0, 0xff);
96   }
97 
98   return 0;
99 }
100 
get_cpunamechar(void)101 char *get_cpunamechar(void){
102   if (get_cputype(GET_FAMILY) == 0x07) return "ITANIUM";
103   if (get_cputype(GET_FAMILY) == 0x1f) return "ITANIUM2";
104   if (get_cputype(GET_FAMILY) == 0x20) return "ITANIUM2";
105 
106   return "UNKNOWN";
107 }
108 
get_libname(void)109 char *get_libname(void){
110   if (get_cputype(GET_FAMILY) == 0x07) { printf("itanium"); return NULL;}
111   if (get_cputype(GET_FAMILY) == 0x1f) { printf("itanium2"); return NULL;}
112   if (get_cputype(GET_FAMILY) == 0x20) { printf("itanium2"); return NULL;}
113 
114   printf("UNKNOWN");
115 
116   return NULL;
117 }
118 
get_architecture(void)119 void get_architecture(void){
120   printf("IA64");
121 }
122 
get_subarchitecture(void)123 void get_subarchitecture(void){
124     printf("%s", get_cpunamechar());
125 }
126 
get_subdirname(void)127 void get_subdirname(void){
128     printf("ia64");
129 }
130 
get_cpuconfig(void)131 void get_cpuconfig(void){
132   printf("#define %s\n", get_cpunamechar());
133   printf("#define L1_DATA_SIZE 262144\n");
134   printf("#define L1_DATA_LINESIZE 128\n");
135   printf("#define L2_SIZE 1572864\n");
136   printf("#define L2_LINESIZE 128\n");
137   printf("#define DTB_SIZE 16384\n");
138   printf("#define DTB_ENTRIES 128\n");
139 }
140 
141