From 29bc6c5fe0ccbaa008c93382ff194d7724f61397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C3=A1n=20C=C3=A1rdenas?= Date: Tue, 2 Jan 2024 17:23:08 +0100 Subject: [PATCH 1/2] bug fixes --- riscv-semihosting/CHANGELOG.md | 2 ++ riscv-semihosting/README.md | 15 +++++++++++++-- riscv-semihosting/src/lib.rs | 5 ++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/riscv-semihosting/CHANGELOG.md b/riscv-semihosting/CHANGELOG.md index df76aa4f..64a1a597 100644 --- a/riscv-semihosting/CHANGELOG.md +++ b/riscv-semihosting/CHANGELOG.md @@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +- Add recommendation for `semihosting` in README.md. +- Bug fixes - Moved to the `riscv` Cargo workspace - Bring in API changes from [cortex-m-semihosting](https://github.com/rust-embedded/cortex-m/tree/master/cortex-m-semihosting), diff --git a/riscv-semihosting/README.md b/riscv-semihosting/README.md index 75da8aeb..0768aeba 100644 --- a/riscv-semihosting/README.md +++ b/riscv-semihosting/README.md @@ -3,10 +3,10 @@ # `riscv-semihosting` -> Semihosting for RISC-V processors +> Simple semihosting for RISC-V processors This is a fork of the -[cortex-m-semihosting](https://docs.rs/cortex-m-semihosting) crate with changes +[`cortex-m-semihosting`] crate with changes to support the RISC-V Semihosting Specification as documented [here](https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-semihosting-spec.adoc) @@ -23,6 +23,15 @@ to execute the semihosting operation in an interrupt-free context, while *user-mode (U-mode)* causes them to just execute the operation. By default, M-mode is used. You can activate the U-mode via the `u-mode` feature. +# About the [`semihosting`] crate + +`riscv-semihosting` provides a simple semihosting API that matches [`cortex-m-semihosting`]. +This allows a simple port from Cortex-M applications to RISC-V applications. +However, the [`semihosting`] crate presents a more advanced interface that is compatible +for RISC-V as well as other architectures (e.g., ARM or MIPS). +While `riscv-semihosting` is a good starting point for developing semihosted applications, +**we recommend using the [`semihosting`] crate.** + # Minimum Supported Rust Version (MSRV) @@ -59,3 +68,5 @@ to intervene to uphold that code of conduct. [CoC]: ../CODE_OF_CONDUCT.md [team]: https://github.com/rust-embedded/wg#the-risc-v-team +[`semihosting`]: https://crates.io/crates/semihosting +[`cortex-m-semihosting`]: https://docs.rs/cortex-m-semihosting \ No newline at end of file diff --git a/riscv-semihosting/src/lib.rs b/riscv-semihosting/src/lib.rs index 9c019e18..56fe6a24 100644 --- a/riscv-semihosting/src/lib.rs +++ b/riscv-semihosting/src/lib.rs @@ -216,11 +216,13 @@ pub unsafe fn syscall1(_nr: usize, _arg: usize) -> usize { #[cfg(all(riscv, not(feature = "no-semihosting")))] () => { let mut nr = _nr; + let mut arg = _arg; // The instructions below must always be uncompressed, otherwise // it will be treated as a regular break, hence the norvc option. // // See https://github.com/riscv/riscv-semihosting-spec for more details. asm!(" + .balign 16 .option push .option norvc slli x0, x0, 0x1f @@ -229,7 +231,8 @@ pub unsafe fn syscall1(_nr: usize, _arg: usize) -> usize { .option pop ", inout("a0") nr, - in("a1") _arg, + inout("a1") arg, + options(nostack, preserves_flags), ); nr } From f98f303ed30429e5ba764c973f32e72555ace48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C3=A1n=20C=C3=A1rdenas=20Rodr=C3=ADguez?= Date: Tue, 2 Jan 2024 18:22:24 +0100 Subject: [PATCH 2/2] Update riscv-semihosting/src/lib.rs Co-authored-by: Taiki Endo --- riscv-semihosting/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riscv-semihosting/src/lib.rs b/riscv-semihosting/src/lib.rs index 56fe6a24..7a22b89a 100644 --- a/riscv-semihosting/src/lib.rs +++ b/riscv-semihosting/src/lib.rs @@ -231,7 +231,7 @@ pub unsafe fn syscall1(_nr: usize, _arg: usize) -> usize { .option pop ", inout("a0") nr, - inout("a1") arg, + inout("a1") arg => _, options(nostack, preserves_flags), ); nr