Merge pull request #3629 from Rabenda/riscv-c910

riscv: Fix machine recognition for c910v
This commit is contained in:
Zhang Xianyi 2022-05-19 17:57:19 +08:00 committed by GitHub
commit a720e2ca8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 10 deletions

View File

@ -81,23 +81,27 @@ static char *cpuname[] = {
int detect(void){ int detect(void){
#ifdef __linux #ifdef __linux
FILE *infile; FILE *infile;
char buffer[512], *p; char buffer[512],isa_buffer[512],model_buffer[512];
const char* check_c910_str = "T-HEAD C910";
char *pmodel = NULL, *pisa = NULL;
p = (char *)NULL;
infile = fopen("/proc/cpuinfo", "r"); infile = fopen("/proc/cpuinfo", "r");
while (fgets(buffer, sizeof(buffer), infile)){ while (fgets(buffer, sizeof(buffer), infile)){
if (!strncmp("isa", buffer, 3)){ if(!strncmp(buffer, "model name", 10)){
p = strchr(buffer, '4') + 1; /* the 4 in rv64ima... */ strcpy(model_buffer, buffer)
#if 0 pmodel = strchr(isa_buffer, ':') + 1;
fprintf(stderr, "%s\n", p); }
#endif
break; if(!strncmp(buffer, "isa", 3)){
} strcpy(isa_buffer, buffer)
pisa = strchr(isa_buffer, '4') + 1;
}
} }
fclose(infile); fclose(infile);
if (strchr(p, 'v')) return CPU_C910V; if (strstr(pmodel, check_c910_str) && strchr(p, 'v'))
return CPU_C910V;
return CPU_GENERIC; return CPU_GENERIC;
#endif #endif