mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
linux-user: Emulate /proc/cpuinfo output for riscv
RISC-V does not expose all extensions via hwcaps, thus some userspace applications may want to query these via /proc/cpuinfo. Currently when querying this file the host's file is shown instead which is slightly confusing. Emulate a basic /proc/cpuinfo file with mmu info and an ISA string. Signed-off-by: Afonso Bordado <afonsobordado@gmail.com> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> Message-Id: <167873059442.9885.15152085316575248452-0@git.sr.ht> [lv: removed the test that fails in CI for unknown reason] Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
parent
7c18f2d663
commit
8ddc171b7b
1 changed files with 32 additions and 2 deletions
|
@ -8231,7 +8231,8 @@ void target_exception_dump(CPUArchState *env, const char *fmt, int code)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \
|
#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \
|
||||||
defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA)
|
defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) || \
|
||||||
|
defined(TARGET_RISCV)
|
||||||
static int is_proc(const char *filename, const char *entry)
|
static int is_proc(const char *filename, const char *entry)
|
||||||
{
|
{
|
||||||
return strcmp(filename, entry) == 0;
|
return strcmp(filename, entry) == 0;
|
||||||
|
@ -8309,6 +8310,35 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(TARGET_RISCV)
|
||||||
|
static int open_cpuinfo(CPUArchState *cpu_env, int fd)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
RISCVCPU *cpu = env_archcpu(cpu_env);
|
||||||
|
const RISCVCPUConfig *cfg = riscv_cpu_cfg((CPURISCVState *) cpu_env);
|
||||||
|
char *isa_string = riscv_isa_string(cpu);
|
||||||
|
const char *mmu;
|
||||||
|
|
||||||
|
if (cfg->mmu) {
|
||||||
|
mmu = (cpu_env->xl == MXL_RV32) ? "sv32" : "sv48";
|
||||||
|
} else {
|
||||||
|
mmu = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < num_cpus; i++) {
|
||||||
|
dprintf(fd, "processor\t: %d\n", i);
|
||||||
|
dprintf(fd, "hart\t\t: %d\n", i);
|
||||||
|
dprintf(fd, "isa\t\t: %s\n", isa_string);
|
||||||
|
dprintf(fd, "mmu\t\t: %s\n", mmu);
|
||||||
|
dprintf(fd, "uarch\t\t: qemu\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free(isa_string);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(TARGET_M68K)
|
#if defined(TARGET_M68K)
|
||||||
static int open_hardware(CPUArchState *cpu_env, int fd)
|
static int open_hardware(CPUArchState *cpu_env, int fd)
|
||||||
{
|
{
|
||||||
|
@ -8333,7 +8363,7 @@ static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int
|
||||||
#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
|
#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
|
||||||
{ "/proc/net/route", open_net_route, is_proc },
|
{ "/proc/net/route", open_net_route, is_proc },
|
||||||
#endif
|
#endif
|
||||||
#if defined(TARGET_SPARC) || defined(TARGET_HPPA)
|
#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || defined(TARGET_RISCV)
|
||||||
{ "/proc/cpuinfo", open_cpuinfo, is_proc },
|
{ "/proc/cpuinfo", open_cpuinfo, is_proc },
|
||||||
#endif
|
#endif
|
||||||
#if defined(TARGET_M68K)
|
#if defined(TARGET_M68K)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue