Skip to content

feat: riscv64-linux runtime (_start + syscall stubs)#307

Merged
octalide merged 3 commits into
devfrom
feat/306-riscv64-linux-runtime
Jun 27, 2026
Merged

feat: riscv64-linux runtime (_start + syscall stubs)#307
octalide merged 3 commits into
devfrom
feat/306-riscv64-linux-runtime

Conversation

@octalide

@octalide octalide commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

Closes #306

Adds the riscv64-linux runtime so riscv64-linux is 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, the syscall0..6 inline-asm bodies (ecall), and the clone / spawn / trap asm.
  • src/system/os/linux/riscv64.mach: arch-specific page_size + thread_spawn (+ thread_trampoline) and the fwd re-exports.
  • src/runtime/linux/riscv64.mach: the ELF _start entry (_rt_init, argc/argv/envp, main, exit_group).
  • dispatch wiring in src/runtime/linux.mach and src/system/os/linux.mach.
  • src/system/panic.mach: riscv64 write/trap (panic is a structural transitive dependency of the os/types layer via types.result).
  • test/riscv64 + a cross-riscv64 CI lane: cross-compiles a std consumer for linux-riscv64 and runs it under qemu-riscv64, asserting the exit code (mirrors mach's cross 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, so rename uses renameat2 (276) instead of renameat (38) - confirmed under qemu.

Verification

  • x86_64: mach test . -> 563/563 pass.
  • aarch64: builds clean.
  • riscv64: the cross-riscv64 lane cross-compiles the runtime smoke test and runs it under qemu-riscv64 (reaches main via _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.

octalide added 2 commits June 26, 2026 22:02
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
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.
@octalide octalide marked this pull request as ready for review June 27, 2026 05:00
@octalide octalide merged commit 8f6bb5b into dev Jun 27, 2026
2 checks passed
@octalide octalide deleted the feat/306-riscv64-linux-runtime branch June 27, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runtime: riscv64-linux _start + syscall stubs

1 participant