-
Notifications
You must be signed in to change notification settings - Fork 4
Add RISC-V RV64 platform support (v1.2.0) #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kristjanvalur
merged 15 commits into
stackless-dev:master
from
kristjanvalur:riscv-support
Nov 16, 2025
Merged
Add RISC-V RV64 platform support (v1.2.0) #13
kristjanvalur
merged 15 commits into
stackless-dev:master
from
kristjanvalur:riscv-support
Nov 16, 2025
Conversation
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
- Added platform detection for RISC-V 64-bit (__riscv && __riscv_xlen == 64) - Created skeleton assembly implementation (switch_riscv64_gcc.S) - Added RISC-V header file (switch_riscv64_gcc.h) - Updated CI workflow to build and test riscv64 with QEMU - Added riscv64 to release archives - Uses LP64D ABI (64-bit pointers, hardware floating point) TODO: Implement actual stack switching logic in assembly file
- Triggers on push to riscv-support branch - Installs RISC-V toolchain and QEMU - Builds and tests riscv64 platform only - Fast feedback for RISC-V development
The Makefile adds the dash automatically, so PLATFORM_PREFIX should be 'riscv64-linux-gnu' not 'riscv64-linux-gnu-'
- Implement stackman_switch with full register save/restore - Implement stackman_call with minimal frame - Save/restore callee-saved registers: s0-s11, fs0-fs11, ra - Follow RISC-V LP64D calling convention - Based on ARM64 implementation pattern
Critical bug fix: Save old stack pointer in s2 before switching stacks, then restore it after callback returns. Previously tried to restore registers from the new stack where they were never saved.
No need to preserve callback and context in callee-saved registers since they're used immediately. Only need to save old sp and ra. Reduced frame from 32 to 16 bytes.
CRITICAL FIX: Must save old stack pointer in s0 (callee-saved register), not on the stack. After switching to new stack, can't access old stack memory. The callback won't clobber s0, so it's safe across the call.
Added __ASSEMBLER__ check and proper assembly source inclusion, following the pattern used in ARM64. This ensures the assembly file is actually compiled into the object file.
Should only use STACKMAN_STACK_ALIGN like all other platforms.
Should be .LFE1 (function end) not .LFB1 (function begin).
- Move STACKMAN_ASSEMBLY_SRC definition outside STACKMAN_SWITCH_IMPL so it's always defined (prevents inline asm fallback) - Add #undef before redefining STACKMAN_STACK_ALIGN to avoid warning
Callback signature is: callback(context, opcode, sp) Was incorrectly calling: callback(context, sp, opcode) Fixed for both stackman_switch (two calls) and stackman_call.
- Bump version to 1.2.0 - Add riscv64 to supported platforms list in README - Add v1.2.0 changelog entry with RISC-V details
RISC-V is now part of the main buildcommit.yml workflow.
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.
Summary
Adds RISC-V 64-bit (LP64D ABI) platform support to stackman.
Changes
platforms/switch_riscv64_gcc.Splatforms/platform.hTesting
All tests pass under QEMU emulation:
This brings the total platform count to 10 ABIs (was 9).
Platforms Supported