Skip to content

Add RISC-V 32-bit support - #258

Merged
lalinsky merged 2 commits into
mainfrom
riscv-32bit
Jan 29, 2026
Merged

lalinsky merged 2 commits into
mainfrom
riscv-32bit

Conversation

@lalinsky

Copy link
Copy Markdown
Owner
  • Add riscv32 coroutine context switching and CI testing
  • Simplify ARM/Thumb context switching by removing explicit LR handling
  • Add Linux syscall compatibility for 32-bit architectures (time64, renameat2)
  • Remove sentinel frames from coroutine entry points

- Add riscv32 coroutine context switching and CI testing
- Simplify ARM/Thumb context switching by removing explicit LR handling
- Add Linux syscall compatibility for 32-bit architectures (time64, renameat2)
- Remove sentinel frames from coroutine entry points
@coderabbitai

coderabbitai Bot commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds riscv32 coroutine support and related assembly paths, centralizes libc linking in the build module, introduces syscall fallbacks on Linux, adds a CI matrix entry to run riscv32 tests under QEMU, and adds a release mode flag to the check script. (49 words)

Changes

Cohort / File(s) Summary
CI & Testing
\.github/workflows/test-coro.yml
Added QEMU-enabled matrix entry for riscv32-linux to run tests under emulation.
Build System
build.zig
Centralized libc linking via zio module .link_libc flag and removed per-executable linkLibC() calls from examples, benchmarks, and unit tests.
Coroutine Architecture Support
src/coro/coroutines.zig
Added .riscv32 Context variant (sp, fp, pc, stack_info, stack_alignment=16); updated setupContext and switchContext per-architecture paths (aarch64, arm/thumb, riscv32, riscv64, loongarch64), adjusted saved/unsaved register maps and entry/restore sequences, and added riscv32 assembly save/restore.
Linux Syscall Dispatch
src/os/system/linux.zig
Branch syscalls: use utimensat if available otherwise utimensat_time64; use renameat2 when available (with 0 flags) otherwise prior renameat path.
Developer scripts
check.sh
Added --release flag (RELEASE_MODE) to enable ReleaseFast optimization and emit build mode info.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🧭 New context frames for RISC-V take flight,
Build flags converge, CI boots in QEMU light,
Syscalls pick fallbacks when systems stray,
Release mode readies fast builds for the day,
Coroutines march in step — tiny wins, tight.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main objective of adding RISC-V 32-bit support, which is reflected across multiple files including coroutine context switching, CI configuration, and build setup.
Description check ✅ Passed The description covers the primary changes: riscv32 support, ARM/Thumb context switching adjustments, Linux syscall compatibility, and CI testing enhancements—all present in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch riscv-32bit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/os/system/linux.zig`:
- Around line 309-327: The renameat implementation should handle the case where
linux.syscall5(.renameat2, ...) returns ENOSYS (kernel doesn't implement
renameat2) by detecting the syscall failure and errno == linux.ENOSYS and then
falling back to calling linux.syscall4(.renameat, ...) with the same arguments;
modify the renameat function to invoke renameat2 via linux.syscall5, check the
error indicator and errno, and only call linux.syscall4 when the syscall failed
with ENOSYS so the no-flags case behaves like the traditional renameat.
🧹 Nitpick comments (1)
src/coro/coroutines.zig (1)

1148-1150: Consider dumping stack traces only on failure.

Unconditional stack traces will spam successful test runs; gating this behind the failure path keeps CI logs clean.

Comment thread src/os/system/linux.zig Resolved
The attempt to remove LR handling was causing stack unwinder crashes in
release mode. The compiler's clobber list (r14 = true) was not sufficient
to preserve LR across context switches, likely due to an LLVM bug with
register aliases (similar to the lr vs x30 issue on aarch64).

Also add --release flag to check.sh for testing with ReleaseFast optimization.
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.

1 participant