aboutsummaryrefslogtreecommitdiff
path: root/core/sys/info/cpu_linux_riscv64.odin
diff options
context:
space:
mode:
authorLaytan <laytanlaats@hotmail.com>2024-08-15 20:39:35 +0200
committerLaytan Laats <laytanlaats@hotmail.com>2024-08-20 14:06:40 +0200
commitca6ef95b038f3eb443971240de73924a721485cc (patch)
treefb72aa52d41f114540dfcc3c5832dc88b2b5cbd5 /core/sys/info/cpu_linux_riscv64.odin
parent29838da782ad4ce77507665f6f6aa36142ceeac1 (diff)
add support for linux_riscv64 and freestanding_riscv64
Diffstat (limited to 'core/sys/info/cpu_linux_riscv64.odin')
-rw-r--r--core/sys/info/cpu_linux_riscv64.odin46
1 files changed, 46 insertions, 0 deletions
diff --git a/core/sys/info/cpu_linux_riscv64.odin b/core/sys/info/cpu_linux_riscv64.odin
new file mode 100644
index 000000000..0f109e7ba
--- /dev/null
+++ b/core/sys/info/cpu_linux_riscv64.odin
@@ -0,0 +1,46 @@
+//+build riscv64
+//+build linux
+package sysinfo
+
+import "base:intrinsics"
+
+import "core:sys/linux"
+
+@(init, private)
+init_cpu_features :: proc() {
+ fd, err := linux.open("/proc/self/auxv", {})
+ if err != .NONE { return }
+ defer linux.close(fd)
+
+ // This is probably enough right?
+ buf: [4096]byte
+ n, rerr := linux.read(fd, buf[:])
+ if rerr != .NONE || n == 0 { return }
+
+ ulong :: u64
+ AT_HWCAP :: 16
+
+ // TODO: using these we could get more information than just the basics.
+ // AT_HWCAP2 :: 26
+ // AT_HWCAP3 :: 29
+ // AT_HWCAP4 :: 30
+
+ auxv := buf[:n]
+ for len(auxv) >= size_of(ulong)*2 {
+ key := intrinsics.unaligned_load((^ulong)(&auxv[0]))
+ val := intrinsics.unaligned_load((^ulong)(&auxv[size_of(ulong)]))
+ auxv = auxv[2*size_of(ulong):]
+
+ if key != AT_HWCAP {
+ continue
+ }
+
+ cpu_features = transmute(CPU_Features)(val)
+ break
+ }
+}
+
+@(init, private)
+init_cpu_name :: proc() {
+ cpu_name = "RISCV64"
+}