Skip to content

Commit ea8e208

Browse files
authored
Merge pull request #3306 from jonaszhou1/develop
Add cpu detection support for Zhaoxin processors
2 parents 44cc7cd + 0fca36c commit ea8e208

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

Diff for: cpuid.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#define VENDOR_TRANSMETA 9
5555
#define VENDOR_NSC 10
5656
#define VENDOR_HYGON 11
57+
#define VENDOR_ZHAOXIN 12
5758
#define VENDOR_UNKNOWN 99
5859

5960
#define BITMASK(a, b, c) ((((a) >> (b)) & (c)))

Diff for: cpuid_x86.c

+29-15
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ int get_vendor(void){
283283
if (!strcmp(vendor, "CyrixInstead")) return VENDOR_CYRIX;
284284
if (!strcmp(vendor, "NexGenDriven")) return VENDOR_NEXGEN;
285285
if (!strcmp(vendor, "CentaurHauls")) return VENDOR_CENTAUR;
286-
if (!strcmp(vendor, " Shanghai ")) return VENDOR_CENTAUR;
286+
if (!strcmp(vendor, " Shanghai ")) return VENDOR_ZHAOXIN;
287287
if (!strcmp(vendor, "RiseRiseRise")) return VENDOR_RISE;
288288
if (!strcmp(vendor, " SiS SiS SiS")) return VENDOR_SIS;
289289
if (!strcmp(vendor, "GenuineTMx86")) return VENDOR_TRANSMETA;
@@ -1067,7 +1067,8 @@ int get_cacheinfo(int type, cache_info_t *cacheinfo){
10671067

10681068
if ((get_vendor() == VENDOR_AMD) ||
10691069
(get_vendor() == VENDOR_HYGON) ||
1070-
(get_vendor() == VENDOR_CENTAUR)) {
1070+
(get_vendor() == VENDOR_CENTAUR) ||
1071+
(get_vendor() == VENDOR_ZHAOXIN)) {
10711072
cpuid(0x80000005, &eax, &ebx, &ecx, &edx);
10721073

10731074
LDTB.size = 4096;
@@ -1190,14 +1191,15 @@ int get_cacheinfo(int type, cache_info_t *cacheinfo){
11901191

11911192
int get_cpuname(void){
11921193

1193-
int family, exfamily, model, vendor, exmodel;
1194+
int family, exfamily, model, vendor, exmodel, stepping;
11941195

11951196
if (!have_cpuid()) return CPUTYPE_80386;
11961197

11971198
family = get_cputype(GET_FAMILY);
11981199
exfamily = get_cputype(GET_EXFAMILY);
11991200
model = get_cputype(GET_MODEL);
12001201
exmodel = get_cputype(GET_EXMODEL);
1202+
stepping = get_cputype(GET_STEPPING);
12011203

12021204
vendor = get_vendor();
12031205

@@ -1628,15 +1630,20 @@ int get_cpuname(void){
16281630
switch (family) {
16291631
case 0x5:
16301632
return CPUTYPE_CENTAURC6;
1631-
break;
16321633
case 0x6:
1633-
return CPUTYPE_NANO;
1634-
break;
1635-
case 0x7:
1634+
if (model == 0xf && stepping < 0xe)
1635+
return CPUTYPE_NANO;
16361636
return CPUTYPE_NEHALEM;
1637-
break;
1637+
default:
1638+
if (family >= 0x7)
1639+
return CPUTYPE_NEHALEM;
1640+
else
1641+
return CPUTYPE_VIAC3;
16381642
}
1639-
return CPUTYPE_VIAC3;
1643+
}
1644+
1645+
if (vendor == VENDOR_ZHAOXIN){
1646+
return CPUTYPE_NEHALEM;
16401647
}
16411648

16421649
if (vendor == VENDOR_RISE){
@@ -1869,14 +1876,15 @@ char *get_lower_cpunamechar(void){
18691876

18701877
int get_coretype(void){
18711878

1872-
int family, exfamily, model, exmodel, vendor;
1879+
int family, exfamily, model, exmodel, vendor, stepping;
18731880

18741881
if (!have_cpuid()) return CORE_80486;
18751882

18761883
family = get_cputype(GET_FAMILY);
18771884
exfamily = get_cputype(GET_EXFAMILY);
18781885
model = get_cputype(GET_MODEL);
18791886
exmodel = get_cputype(GET_EXMODEL);
1887+
stepping = get_cputype(GET_STEPPING);
18801888

18811889
vendor = get_vendor();
18821890

@@ -2286,13 +2294,19 @@ int get_coretype(void){
22862294
if (vendor == VENDOR_CENTAUR) {
22872295
switch (family) {
22882296
case 0x6:
2289-
return CORE_NANO;
2290-
break;
2291-
case 0x7:
2297+
if (model == 0xf && stepping < 0xe)
2298+
return CORE_NANO;
22922299
return CORE_NEHALEM;
2293-
break;
2300+
default:
2301+
if (family >= 0x7)
2302+
return CORE_NEHALEM;
2303+
else
2304+
return CORE_VIAC3;
22942305
}
2295-
return CORE_VIAC3;
2306+
}
2307+
2308+
if (vendor == VENDOR_ZHAOXIN) {
2309+
return CORE_NEHALEM;
22962310
}
22972311

22982312
return CORE_UNKNOWN;

Diff for: driver/others/dynamic.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ extern gotoblas_t gotoblas_COOPERLAKE;
292292
#define VENDOR_AMD 2
293293
#define VENDOR_CENTAUR 3
294294
#define VENDOR_HYGON 4
295+
#define VENDOR_ZHAOXIN 5
295296
#define VENDOR_UNKNOWN 99
296297

297298
#define BITMASK(a, b, c) ((((a) >> (b)) & (c)))
@@ -404,7 +405,7 @@ static int get_vendor(void){
404405
if (!strcmp(vendor.vchar, "GenuineIntel")) return VENDOR_INTEL;
405406
if (!strcmp(vendor.vchar, "AuthenticAMD")) return VENDOR_AMD;
406407
if (!strcmp(vendor.vchar, "CentaurHauls")) return VENDOR_CENTAUR;
407-
if (!strcmp(vendor.vchar, " Shanghai ")) return VENDOR_CENTAUR;
408+
if (!strcmp(vendor.vchar, " Shanghai ")) return VENDOR_ZHAOXIN;
408409
if (!strcmp(vendor.vchar, "HygonGenuine")) return VENDOR_HYGON;
409410

410411
if ((eax == 0) || ((eax & 0x500) != 0)) return VENDOR_INTEL;
@@ -415,14 +416,15 @@ static int get_vendor(void){
415416
static gotoblas_t *get_coretype(void){
416417

417418
int eax, ebx, ecx, edx;
418-
int family, exfamily, model, vendor, exmodel;
419+
int family, exfamily, model, vendor, exmodel, stepping;
419420

420421
cpuid(1, &eax, &ebx, &ecx, &edx);
421422

422423
family = BITMASK(eax, 8, 0x0f);
423424
exfamily = BITMASK(eax, 20, 0xff);
424425
model = BITMASK(eax, 4, 0x0f);
425426
exmodel = BITMASK(eax, 16, 0x0f);
427+
stepping = BITMASK(eax, 0, 0x0f);
426428

427429
vendor = get_vendor();
428430

@@ -824,13 +826,19 @@ static gotoblas_t *get_coretype(void){
824826
if (vendor == VENDOR_CENTAUR) {
825827
switch (family) {
826828
case 0x6:
827-
return &gotoblas_NANO;
828-
break;
829-
case 0x7:
829+
if (model == 0xf && stepping < 0xe)
830+
return &gotoblas_NANO;
830831
return &gotoblas_NEHALEM;
832+
default:
833+
if (family >= 0x7)
834+
return &gotoblas_NEHALEM;
831835
}
832836
}
833837

838+
if (vendor == VENDOR_ZHAOXIN) {
839+
return &gotoblas_NEHALEM;
840+
}
841+
834842
return NULL;
835843
}
836844

0 commit comments

Comments
 (0)