-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Add new Tier-3 target: riscv64im-unknown-none-elf #148790
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| use crate::spec::{ | ||
| Arch, Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetMetadata, | ||
| TargetOptions, | ||
| }; | ||
|
|
||
| pub(crate) fn target() -> Target { | ||
| Target { | ||
| data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(), | ||
| llvm_target: "riscv64".into(), | ||
| metadata: TargetMetadata { | ||
| description: Some("Bare RISC-V (RV64IM ISA)".into()), | ||
| tier: Some(3), | ||
| host_tools: Some(false), | ||
| std: Some(false), | ||
| }, | ||
| pointer_width: 64, | ||
| arch: Arch::RiscV64, | ||
|
|
||
| options: TargetOptions { | ||
| linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), | ||
| linker: Some("rust-lld".into()), | ||
| cpu: "generic-rv64".into(), | ||
| max_atomic_width: Some(64), | ||
| atomic_cas: false, | ||
| features: "+m,+forced-atomics".into(), | ||
| llvm_abiname: "lp64".into(), | ||
| panic_strategy: PanicStrategy::Abort, | ||
| relocation_model: RelocModel::Static, | ||
| code_model: Some(CodeModel::Medium), | ||
| emit_debug_gdb_scripts: false, | ||
| eh_frame_header: false, | ||
| ..Default::default() | ||
| }, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # `riscv64im-unknown-none-elf` | ||
|
|
||
| **Tier: 3** | ||
|
|
||
| Bare-metal target for RISC-V CPUs with the RV64IM ISA. | ||
|
|
||
| ## Target maintainers | ||
|
|
||
| * Rust Embedded Working Group, [RISC-V team](https://github.com/rust-embedded/wg#the-risc-v-team) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@almindor @dkhayes117 @romancardenas @MabezDev @jessebraham @rmsyn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok from my side! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any hardware implementing this spec outside of FPGA? This really looks like something an implementation would reach for Regardless, since it's a strict subset of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mentioned it a little in the PR body; the target is currently zkVMs -- do you mean rv32e(Tier 3) or was you referring to possibly adding rv64e as a target?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. M is needed for efficient multiplication: theres a little blurb on the proposal to standardize rv64im here: https://github.com/eth-act/zkvm-standards/blob/main/standards/riscv-target/target.md
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay from my side :). |
||
|
|
||
| ## Requirements | ||
|
|
||
| This target is cross-compiled and uses static linking. The target supports `core` and `alloc`, but not `std`. | ||
|
|
||
| The target does not support atomic compare-and-swap operations, as the RV64IM ISA lacks the "A" (Atomics) extension. Atomic operations are emulated using the `+forced-atomics` feature. | ||
|
|
||
| No external toolchain is required and the default `rust-lld` linker works, but you must specify a linker script. The [`riscv-rt`] crate provides suitable linker scripts. The [`riscv-rust-quickstart`] repository gives examples of RISC-V bare-metal projects. | ||
|
|
||
| [`riscv-rt`]: https://crates.io/crates/riscv-rt | ||
| [`riscv-rust-quickstart`]: https://github.com/riscv-rust/riscv-rust-quickstart | ||
|
|
||
| ## Building the target | ||
|
|
||
| This target is included in Rust and can be installed via `rustup`: | ||
|
|
||
| ```bash | ||
| rustup target add riscv64im-unknown-none-elf | ||
kevaundray marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Building Rust programs | ||
|
|
||
| Build using the standard Cargo workflow: | ||
|
|
||
| ```bash | ||
| cargo build --target riscv64im-unknown-none-elf | ||
kevaundray marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| You will need to provide a linker script. The [`riscv-rt`] crate handles this automatically when used as a dependency. | ||
|
|
||
| ## Testing | ||
|
|
||
| This is a cross-compiled `no-std` target, which must be run either in a simulator or by programming onto suitable hardware. It is not possible to run the Rust test-suite on this target. | ||
|
|
||
| You can test the target in QEMU with: | ||
|
|
||
| ```bash | ||
| qemu-system-riscv64 -machine virt -cpu rv64,a=false,c=false -nographic -semihosting -kernel your-binary | ||
| ``` | ||
|
|
||
| Note: You must explicitly disable the 'a' (atomics) and 'c' (compressed) extensions when using QEMU to accurately emulate an RV64IM-only CPU. | ||
|
|
||
| ## Cross-compilation toolchains and C code | ||
|
|
||
| This target supports C code. If interlinking with C or C++, you may need to use `riscv64-unknown-elf-gcc` with the appropriate `-march=rv64im -mabi=lp64` flags as a linker instead of `rust-lld`. | ||
Uh oh!
There was an error while loading. Please reload this page.