feat: riscv64-linux runtime (_start + syscall stubs)#307
Merged
Conversation
Add the riscv64-linux OS layer mirroring the aarch64 one: - riscv64 arms in shared.mach for the syscall numbers, stat_t, O_DIRECTORY, the syscall0..6 inline-asm bodies (ecall), and the clone/spawn/trap asm. - src/system/os/linux/riscv64.mach: page_size + thread_spawn + the fwd re-exports. - riscv64 dispatch in os/linux.mach and the riscv64 panic write/trap. riscv64 and aarch64 share the asm-generic syscall table; only the inline-asm dialect changes. The one divergence: riscv lacks __ARCH_WANT_RENAMEAT, so rename uses renameat2 (276) instead of renameat (38), confirmed under qemu. Refs #306
Add src/runtime/linux/riscv64.mach (_start, _rt_init, the argc/argv/envp globals) and the riscv64 dispatch in runtime/linux.mach. _start is a naked inline-asm entry that reads the kernel-supplied sp, publishes argc/argv/envp, calls _rt_init then main, and exits via exit_group. Refs #306
This was referenced Jun 27, 2026
Closed
Add a test/riscv64 fixture (a tiny std consumer that reaches main through _start and exercises a write syscall) plus verify.sh, and a cross-riscv64 CI job that cross-compiles it for linux-riscv64 with the released mach and runs it under qemu-riscv64 asserting the exit code. Mirrors mach's cross riscv64-linux lane and exercises the riscv64 runtime end to end.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #306
Adds the riscv64-linux runtime so
riscv64-linuxis self-hostable, mirroring the x86_64 / aarch64 layers.Changes
src/system/os/linux/shared.mach: riscv64 arms for the syscall numbers,stat_t,O_DIRECTORY, thesyscall0..6inline-asm bodies (ecall), and the clone / spawn / trap asm.src/system/os/linux/riscv64.mach: arch-specificpage_size+thread_spawn(+thread_trampoline) and thefwdre-exports.src/runtime/linux/riscv64.mach: the ELF_startentry (_rt_init, argc/argv/envp,main,exit_group).src/runtime/linux.machandsrc/system/os/linux.mach.src/system/panic.mach: riscv64 write/trap (panic is a structural transitive dependency of the os/types layer viatypes.result).test/riscv64+ across-riscv64CI lane: cross-compiles a std consumer for linux-riscv64 and runs it underqemu-riscv64, asserting the exit code (mirrors mach'scross riscv64-linux).riscv64 and aarch64 share the Linux asm-generic syscall table; only the inline-asm dialect changes. One divergence handled: riscv lacks
__ARCH_WANT_RENAMEAT, sorenameusesrenameat2(276) instead ofrenameat(38) - confirmed under qemu.Verification
mach test .-> 563/563 pass.cross-riscv64lane cross-compiles the runtime smoke test and runs it under qemu-riscv64 (reachesmainvia_start, does a write syscall, exits 42). Every inline-asm pattern in the runtime was also unit-verified standalone under qemu.Requires mach >= v2.9.0 (full riscv64 backend: RV64A, branch relaxation, frame-slot fix). CI seeds from the latest mach release, so all lanes are green on v2.9.0.