cpu_linux_riscv64.odin 921 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //+build riscv64
  2. //+build linux
  3. package sysinfo
  4. import "base:intrinsics"
  5. import "core:sys/linux"
  6. @(init, private)
  7. init_cpu_features :: proc() {
  8. fd, err := linux.open("/proc/self/auxv", {})
  9. if err != .NONE { return }
  10. defer linux.close(fd)
  11. // This is probably enough right?
  12. buf: [4096]byte
  13. n, rerr := linux.read(fd, buf[:])
  14. if rerr != .NONE || n == 0 { return }
  15. ulong :: u64
  16. AT_HWCAP :: 16
  17. // TODO: using these we could get more information than just the basics.
  18. // AT_HWCAP2 :: 26
  19. // AT_HWCAP3 :: 29
  20. // AT_HWCAP4 :: 30
  21. auxv := buf[:n]
  22. for len(auxv) >= size_of(ulong)*2 {
  23. key := intrinsics.unaligned_load((^ulong)(&auxv[0]))
  24. val := intrinsics.unaligned_load((^ulong)(&auxv[size_of(ulong)]))
  25. auxv = auxv[2*size_of(ulong):]
  26. if key != AT_HWCAP {
  27. continue
  28. }
  29. cpu_features = transmute(CPU_Features)(val)
  30. break
  31. }
  32. }
  33. @(init, private)
  34. init_cpu_name :: proc() {
  35. cpu_name = "RISCV64"
  36. }