diff options
Diffstat (limited to 'gprofng/common/cpuid.c')
-rw-r--r-- | gprofng/common/cpuid.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/gprofng/common/cpuid.c b/gprofng/common/cpuid.c index af15439..f9f9046 100644 --- a/gprofng/common/cpuid.c +++ b/gprofng/common/cpuid.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2021-2024 Free Software Foundation, Inc. +/* Copyright (C) 2021-2025 Free Software Foundation, Inc. Contributed by Oracle. This file is part of GNU Binutils. @@ -18,10 +18,12 @@ Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -#if defined(__i386__) || defined(__x86_64) +#if defined(__i386__) || defined(__x86_64__) #include <cpuid.h> /* GCC-provided */ #elif defined(__aarch64__) +#if !defined(ATTRIBUTE_UNUSED) #define ATTRIBUTE_UNUSED __attribute__((unused)) +#endif static inline uint_t __attribute_const__ __get_cpuid (unsigned int op ATTRIBUTE_UNUSED, unsigned int *eax, @@ -42,6 +44,13 @@ __get_cpuid (unsigned int op ATTRIBUTE_UNUSED, unsigned int *eax, Tprintf (DBG_LT0, "cpuid.c:%d read_cpuid_id() MIDR_EL1=0x%016x\n", __LINE__, *eax); return res; } +#elif defined(__riscv) +#include <sched.h> +#include <sys/syscall.h> +#include <unistd.h> +#ifdef HAVE_ASM_HWPROBE_H +#include <asm/hwprobe.h> +#endif #endif /* @@ -84,7 +93,7 @@ typedef struct } cpuid_info_t; -#if defined(__i386__) || defined(__x86_64) +#if defined(__i386__) || defined(__x86_64__) static uint_t cpuid_vendorstr_to_vendorcode (char *vendorstr) { @@ -144,7 +153,7 @@ get_cpuid_info () Tprintf (DBG_LT0, "cpuid.c:%d read_cpuid_id() MIDR_EL1==0x%016x cpi_vendor=%d cpi_model=%d\n", __LINE__, (unsigned int) reg, cpi->cpi_vendor, cpi->cpi_model); -#elif defined(__i386__) || defined(__x86_64) +#elif defined(__i386__) || defined(__x86_64__) cpuid_regs_t regs; my_cpuid (0, ®s); cpi->cpi_maxeax = regs.eax; @@ -180,6 +189,28 @@ get_cpuid_info () cpi->cpi_model += CPI_MODEL_XTD (regs.eax) << 4; break; } +#elif defined(__riscv) + #if !defined(__riscv_hwprobe) || !defined(HAVE_ASM_HWPROBE_H) + cpi->cpi_vendor = 0; + cpi->cpi_family = 0; + cpi->cpi_model = 0; + #else + struct riscv_hwprobe res; + res.key = RISCV_HWPROBE_KEY_MVENDORID; + cpu_set_t cpu_set; + int __riscv_hwprobe (struct riscv_hwprobe *pairs, \ + long pair_count, long cpu_count, \ + unsigned long *cpus, unsigned long flags) \ + { + return syscall(__NR_riscv_hwprobe, pairs, pair_count, cpu_count, cpus, flags); + } + CPU_ZERO(&cpu_set); + CPU_SET(0, &cpu_set); + long ret = __riscv_hwprobe(&res, 1, 1, &cpu_set, 0); + cpi->cpi_vendor = res.value; + cpi->cpi_family = 0; + cpi->cpi_model = 0; + #endif #endif return cpi; } |