mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
add support for linux_riscv64 and freestanding_riscv64
This commit is contained in:
@@ -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"
|
||||
}
|
||||
@@ -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,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.")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user