Initial attempt at proper cpu detection on RISCV

This commit is contained in:
Martin Kroeker 2022-05-04 08:58:56 +02:00 committed by Owen Rafferty
parent d5e9de115d
commit a7b248631b
No known key found for this signature in database
GPG Key ID: A68B10E2554DEBCB
1 changed files with 28 additions and 4 deletions

View File

@ -79,7 +79,30 @@ static char *cpuname[] = {
}; };
int detect(void){ int detect(void){
return CPU_UNKNOWN; #ifdef __linux
FILE *infile;
char buffer[512], *p;
p = (char *)NULL;
infile = fopen("/proc/cpuinfo", "r");
while (fgets(buffer, sizeof(buffer), infile)){
if (!strncmp("isa", buffer, 3)){
p = strchr(buffer, '4') + 1; /* the 4 in rv64ima... */
#if 0
fprintf(stderr, "%s\n", p);
#endif
break;
}
}
fclose(infile);
if (strchr(p, 'v')) return CPU_C910V;
return CPU_GENERIC;
#endif
return CPU_GENERIC;
} }
char *get_corename(void){ char *get_corename(void){
@ -91,6 +114,7 @@ void get_architecture(void){
} }
void get_subarchitecture(void){ void get_subarchitecture(void){
printf("%s",cpuname[detect()]);
} }
void get_subdirname(void){ void get_subdirname(void){