Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions cpuid_riscv64.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ static char *cpuname_lower[] = {
int detect(void){
#ifdef __linux
FILE *infile;
char buffer[512],isa_buffer[512],model_buffer[512];
char buffer[512],isa_buffer[512],model_buffer[512], uarch_buffer[512];
const char* check_c910_str = "T-HEAD C910";
char *pmodel = NULL, *pisa = NULL;
const char* check_u74_str = "sifive,u74";
char *pmodel = NULL, *pisa = NULL, *puarch = NULL;

infile = fopen("/proc/cpuinfo", "r");
if (!infile)
Expand All @@ -113,6 +114,13 @@ int detect(void){
pmodel++;
}

if(!strncmp(buffer, "uarch", 5)){
strcpy(uarch_buffer, buffer);
puarch = strchr(uarch_buffer, ':');
if (puarch)
puarch++;
}

if(!strncmp(buffer, "isa", 3)){
strcpy(isa_buffer, buffer);
pisa = strchr(isa_buffer, '4');
Expand All @@ -123,12 +131,16 @@ int detect(void){

fclose(infile);

if (!pmodel || !pisa)
if ((!pmodel && !puarch) || !pisa)
return(CPU_GENERIC);

if (strstr(pmodel, check_c910_str) && strchr(pisa, 'v'))
return CPU_C910V;

if (pmodel) {
if (strstr(pmodel, check_c910_str) && strchr(pisa, 'v'))
return CPU_C910V;
} else if (puarch) {
if (strstr(puarch, check_u74_str) && !strchr(pisa, 'v'))
return CPU_U74;
}
return CPU_GENERIC;
#endif

Expand Down
Loading