From 41aad1107a06bbb872e06fc42722b623ea5e9054 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Tue, 14 Jul 2026 07:30:47 +0200 Subject: [PATCH] Add Sifive U74 --- cpuid_riscv64.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/cpuid_riscv64.c b/cpuid_riscv64.c index 69adff7180..859da986eb 100644 --- a/cpuid_riscv64.c +++ b/cpuid_riscv64.c @@ -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) @@ -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'); @@ -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