add support for linux_riscv64 and freestanding_riscv64

This commit is contained in:
Laytan
2024-08-20 14:06:40 +02:00
committed by Laytan Laats
parent 29838da782
commit ca6ef95b03
28 changed files with 1395 additions and 116 deletions
+46
View File
@@ -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"
}
+16
View File
@@ -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)
+1 -1
View File
@@ -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.")
}