Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
- Loading branch information
Showing
3 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <assert.h> | ||
|
|
||
| #define BUFFER_SIZE 1024 | ||
|
|
||
| int main(void) | ||
| { | ||
| char buffer[BUFFER_SIZE]; | ||
| FILE *fp = fopen("/proc/cpuinfo", "r"); | ||
| assert(fp != NULL); | ||
|
|
||
| while (fgets(buffer, BUFFER_SIZE, fp) != NULL) { | ||
| if (strstr(buffer, "processor") != NULL) { | ||
| assert(strstr(buffer, "processor\t: ") == buffer); | ||
| } else if (strstr(buffer, "hart") != NULL) { | ||
| assert(strstr(buffer, "hart\t\t: ") == buffer); | ||
| } else if (strstr(buffer, "isa") != NULL) { | ||
| assert(strcmp(buffer, "isa\t\t: rv64imafdc_zicsr_zifencei\n") == 0); | ||
| } else if (strstr(buffer, "mmu") != NULL) { | ||
| assert(strcmp(buffer, "mmu\t\t: sv48\n") == 0); | ||
| } else if (strstr(buffer, "uarch") != NULL) { | ||
| assert(strcmp(buffer, "uarch\t\t: qemu\n") == 0); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| fclose(fp); | ||
| return 0; | ||
| } |