aboutsummaryrefslogtreecommitdiff
path: root/core/sys/info
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
parent29838da782ad4ce77507665f6f6aa36142ceeac1 (diff)
add support for linux_riscv64 and freestanding_riscv64
Diffstat (limited to 'core/sys/info')
-rw-r--r--core/sys/info/cpu_linux_riscv64.odin46
-rw-r--r--core/sys/info/cpu_riscv64.odin16
-rw-r--r--core/sys/info/sysinfo.odin2
3 files changed, 63 insertions, 1 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"
+}
diff --git a/core/sys/info/cpu_riscv64.odin b/core/sys/info/cpu_riscv64.odin
new file mode 100644
index 000000000..754110911
--- /dev/null
+++ b/core/sys/info/cpu_riscv64.odin
@@ -0,0 +1,16 @@
+package sysinfo
+
+CPU_Feature :: enum u64 {
+ I = 'I' - 'A', // Base features, don't think this is ever not here.
+ M = 'M' - 'A', // Integer multiplication and division, currently required by Odin.
+ A = 'A' - 'A', // Atomics.
+ F = 'F' - 'A', // Single precision floating point, currently required by Odin.
+ D = 'D' - 'A', // Double precision floating point, currently required by Odin.
+ C = 'C' - 'A', // Compressed instructions.
+ V = 'V' - 'A', // Vector operations.
+}
+
+CPU_Features :: distinct bit_set[CPU_Feature; u64]
+
+cpu_features: Maybe(CPU_Features)
+cpu_name: Maybe(string)
diff --git a/core/sys/info/sysinfo.odin b/core/sys/info/sysinfo.odin
index f0262f317..f624a1718 100644
--- a/core/sys/info/sysinfo.odin
+++ b/core/sys/info/sysinfo.odin
@@ -1,6 +1,6 @@
package sysinfo
-when !(ODIN_ARCH == .amd64 || ODIN_ARCH == .i386 || ODIN_ARCH == .arm32 || ODIN_ARCH == .arm64) {
+when !(ODIN_ARCH == .amd64 || ODIN_ARCH == .i386 || ODIN_ARCH == .arm32 || ODIN_ARCH == .arm64 || ODIN_ARCH == .riscv64) {
#assert(false, "This package is unsupported on this architecture.")
}