-
-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4089 from laytan/riscv64
add support for linux_riscv64 and freestanding_riscv64
- Loading branch information
Showing
28 changed files
with
1,370 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.text | ||
|
||
.globl _start | ||
|
||
_start: | ||
ld a0, 0(sp) | ||
addi a1, sp, 8 | ||
addi sp, sp, ~15 | ||
call _start_odin | ||
ebreak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.