aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv
diff options
context:
space:
mode:
Diffstat (limited to 'arch/riscv')
-rw-r--r--arch/riscv/user/basics/README.md2
-rw-r--r--arch/riscv/user/hwprobe/Makefile2
-rw-r--r--arch/riscv/user/hwprobe/README.md36
-rw-r--r--arch/riscv/user/hwprobe/probe.c12
4 files changed, 46 insertions, 6 deletions
diff --git a/arch/riscv/user/basics/README.md b/arch/riscv/user/basics/README.md
new file mode 100644
index 0000000..e938133
--- /dev/null
+++ b/arch/riscv/user/basics/README.md
@@ -0,0 +1,2 @@
+Just random assembly messing with basic programming concepts from the RISC-V
+ISA.
diff --git a/arch/riscv/user/hwprobe/Makefile b/arch/riscv/user/hwprobe/Makefile
index 6c47002..67053a8 100644
--- a/arch/riscv/user/hwprobe/Makefile
+++ b/arch/riscv/user/hwprobe/Makefile
@@ -24,7 +24,7 @@ ISA ?= rv64imafdc_zicntr_zicsr_zifencei_zihpm_zca_zcd_zba_zbb
WARNINGS = -Werror -Wpedantic -Wall -Wextra -Wcast-align -Wcast-qual -Winit-self \
-Wmissing-include-dirs -Wredundant-decls -Wshadow -Wsign-conversion \
-Wswitch-default -Wundef -Wunreachable-code -Wmissing-noreturn
-CCFLAGS = $(WARNINGS) -march=$(ISA) -static
+CCFLAGS = $(WARNINGS) -march=$(ISA) -static -I$(LINUX_HEADERS)
LDFLAGS =
diff --git a/arch/riscv/user/hwprobe/README.md b/arch/riscv/user/hwprobe/README.md
new file mode 100644
index 0000000..58f09c1
--- /dev/null
+++ b/arch/riscv/user/hwprobe/README.md
@@ -0,0 +1,36 @@
+The RISC-V support for the Linux kernel has a new system call which is specific
+to it, called `hwprobe`. With this system call you can check which features,
+extensions, etc. are available on the current machine.
+
+In order to build this example you need Linux headers for the RISC-V
+architecture. You can achieve this in two ways:
+
+1. Simply install the Linux headers from your distribution if you are already
+ using a RISC-V machine.
+2. Build the Linux kernel and use the `LINUX_HEADERS` environment variable to
+ point to the headers directory (i.e. the directory produced by `make
+ headers_install`)
+
+After that, build it and run it. On a QEMU machine I got the following:
+
+```
+Supports base extensions I, M, A? yes
+
+We got back this bit map: 0000001110001101001010000001000100100000000000000000000011111011; which means:
+
+F, D: OK
+C: OK
+ZBA: OK
+ZBB: OK
+ZBS: OK
+ZICBOZ: OK
+ZBC: OK
+ZIHINTNTL: OK
+ZFA: OK
+ZIHINTPAUSE: OK
+ZCA: OK
+ZCD: OK
+ZAWRS: OK
+ZICNTR: OK
+ZIHPM: OK
+```
diff --git a/arch/riscv/user/hwprobe/probe.c b/arch/riscv/user/hwprobe/probe.c
index de2c209..70206f2 100644
--- a/arch/riscv/user/hwprobe/probe.c
+++ b/arch/riscv/user/hwprobe/probe.c
@@ -1,19 +1,21 @@
#define _GNU_SOURCE
-#include <sched.h>
-#include <asm/hwprobe.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdint.h>
-#define NR_RISCV_HWPROBE 258
+#include <sched.h>
+#include <asm/hwprobe.h>
+#include <asm/unistd.h>
+#ifndef RISCV_HWPROBE_EXT_ZICNTR
// Merged in Linux v6.15.
// See 4458b8f68dc7 ("riscv: hwprobe: export Zicntr and Zihpm extensions").
#define RISCV_HWPROBE_EXT_ZICNTR (1ULL << 50)
#define RISCV_HWPROBE_EXT_ZIHPM (1ULL << 51)
+#endif
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr)[0])
@@ -253,7 +255,7 @@ int main()
pairs = (struct riscv_hwprobe){
.key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR,
};
- rc = syscall(NR_RISCV_HWPROBE, &pairs, 1, 0, NULL, 0);
+ rc = syscall(__NR_riscv_hwprobe, &pairs, 1, 0, NULL, 0);
if (rc) {
perror("could not fetch the base behavior for the system");
exit(EXIT_FAILURE);
@@ -265,7 +267,7 @@ int main()
pairs = (struct riscv_hwprobe){
.key = RISCV_HWPROBE_KEY_IMA_EXT_0,
};
- rc = syscall(NR_RISCV_HWPROBE, &pairs, 1, 0, NULL, 0);
+ rc = syscall(__NR_riscv_hwprobe, &pairs, 1, 0, NULL, 0);
if (rc) {
perror("could not fetch extensions as given by hwprobe");
exit(EXIT_FAILURE);