1 /*****************************************************************************
2 Copyright (c) 2011, Lab of Parallel Software and Computational Science,ICSAS
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
16 3. Neither the name of the ISCAS nor the names of its contributors may
17 be used to endorse or promote products derived from this software
18 without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
29 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 **********************************************************************************/
34 /*********************************************************************/
35 /* Copyright 2009, 2010 The University of Texas at Austin. */
36 /* All rights reserved. */
38 /* Redistribution and use in source and binary forms, with or */
39 /* without modification, are permitted provided that the following */
40 /* conditions are met: */
42 /* 1. Redistributions of source code must retain the above */
43 /* copyright notice, this list of conditions and the following */
46 /* 2. Redistributions in binary form must reproduce the above */
47 /* copyright notice, this list of conditions and the following */
48 /* disclaimer in the documentation and/or other materials */
49 /* provided with the distribution. */
51 /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
52 /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
53 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
54 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
55 /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
56 /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
57 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
58 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
59 /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
60 /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
61 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
62 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
63 /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
64 /* POSSIBILITY OF SUCH DAMAGE. */
66 /* The views and conclusions contained in the software and */
67 /* documentation are those of the authors and should not be */
68 /* interpreted as representing official policies, either expressed */
69 /* or implied, of The University of Texas at Austin. */
70 /*********************************************************************/
73 #define CPU_SICORTEX 1
74 #define CPU_LOONGSON3A 2
75 #define CPU_LOONGSON3B 3
77 static char *cpuname[] = {
91 infile = fopen("/proc/cpuinfo", "r");
92 while (fgets(buffer, sizeof(buffer), infile)){
93 if (!strncmp("cpu", buffer, 3)){
94 p = strchr(buffer, ':') + 2;
96 fprintf(stderr, "%s\n", p);
104 if (strstr(p, "Loongson-3A")){
105 return CPU_LOONGSON3A;
106 }else if(strstr(p, "Loongson-3B")){
107 return CPU_LOONGSON3B;
108 }else if (strstr(p, "Loongson-3")){
109 infile = fopen("/proc/cpuinfo", "r");
110 while (fgets(buffer, sizeof(buffer), infile)){
111 if (!strncmp("system type", buffer, 11)){
112 p = strchr(buffer, ':') + 2;
117 if (strstr(p, "loongson3a"))
118 return CPU_LOONGSON3A;
126 char *get_corename(void){
127 return cpuname[detect()];
130 void get_architecture(void){
134 void get_subarchitecture(void){
135 if(detect()==CPU_LOONGSON3A) {
136 printf("LOONGSON3A");
137 }else if(detect()==CPU_LOONGSON3B){
138 printf("LOONGSON3B");
144 void get_subdirname(void){
148 void get_cpuconfig(void){
149 if(detect()==CPU_LOONGSON3A) {
150 printf("#define LOONGSON3A\n");
151 printf("#define L1_DATA_SIZE 65536\n");
152 printf("#define L1_DATA_LINESIZE 32\n");
153 printf("#define L2_SIZE 512488\n");
154 printf("#define L2_LINESIZE 32\n");
155 printf("#define DTB_DEFAULT_ENTRIES 64\n");
156 printf("#define DTB_SIZE 4096\n");
157 printf("#define L2_ASSOCIATIVE 4\n");
158 }else if(detect()==CPU_LOONGSON3B){
159 printf("#define LOONGSON3B\n");
160 printf("#define L1_DATA_SIZE 65536\n");
161 printf("#define L1_DATA_LINESIZE 32\n");
162 printf("#define L2_SIZE 512488\n");
163 printf("#define L2_LINESIZE 32\n");
164 printf("#define DTB_DEFAULT_ENTRIES 64\n");
165 printf("#define DTB_SIZE 4096\n");
166 printf("#define L2_ASSOCIATIVE 4\n");
168 printf("#define SICORTEX\n");
169 printf("#define L1_DATA_SIZE 32768\n");
170 printf("#define L1_DATA_LINESIZE 32\n");
171 printf("#define L2_SIZE 512488\n");
172 printf("#define L2_LINESIZE 32\n");
173 printf("#define DTB_DEFAULT_ENTRIES 32\n");
174 printf("#define DTB_SIZE 4096\n");
175 printf("#define L2_ASSOCIATIVE 8\n");
179 void get_libname(void){
180 if(detect()==CPU_LOONGSON3A) {
181 printf("loongson3a\n");
182 }else if(detect()==CPU_LOONGSON3B) {
183 printf("loongson3b\n");