Skip to content

Commit d9b9df3

Browse files
Merge pull request #171 from rust-embedded/semihosting
`riscv-semihosting`: bug fixes
2 parents 1921b5e + f98f303 commit d9b9df3

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

riscv-semihosting/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
- Add recommendation for `semihosting` in README.md.
9+
- Bug fixes
810
- Moved to the `riscv` Cargo workspace
911
- Bring in API changes from
1012
[cortex-m-semihosting](https://github.com/rust-embedded/cortex-m/tree/master/cortex-m-semihosting),

riscv-semihosting/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
# `riscv-semihosting`
55

6-
> Semihosting for RISC-V processors
6+
> Simple semihosting for RISC-V processors
77
88
This is a fork of the
9-
[cortex-m-semihosting](https://docs.rs/cortex-m-semihosting) crate with changes
9+
[`cortex-m-semihosting`] crate with changes
1010
to support the RISC-V Semihosting Specification as documented
1111
[here](https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-semihosting-spec.adoc)
1212

@@ -23,6 +23,15 @@ to execute the semihosting operation in an interrupt-free context, while
2323
*user-mode (U-mode)* causes them to just execute the operation.
2424
By default, M-mode is used. You can activate the U-mode via the `u-mode` feature.
2525

26+
# About the [`semihosting`] crate
27+
28+
`riscv-semihosting` provides a simple semihosting API that matches [`cortex-m-semihosting`].
29+
This allows a simple port from Cortex-M applications to RISC-V applications.
30+
However, the [`semihosting`] crate presents a more advanced interface that is compatible
31+
for RISC-V as well as other architectures (e.g., ARM or MIPS).
32+
While `riscv-semihosting` is a good starting point for developing semihosted applications,
33+
**we recommend using the [`semihosting`] crate.**
34+
2635

2736
# Minimum Supported Rust Version (MSRV)
2837

@@ -59,3 +68,5 @@ to intervene to uphold that code of conduct.
5968

6069
[CoC]: ../CODE_OF_CONDUCT.md
6170
[team]: https://github.com/rust-embedded/wg#the-risc-v-team
71+
[`semihosting`]: https://crates.io/crates/semihosting
72+
[`cortex-m-semihosting`]: https://docs.rs/cortex-m-semihosting

riscv-semihosting/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,13 @@ pub unsafe fn syscall1(_nr: usize, _arg: usize) -> usize {
216216
#[cfg(all(riscv, not(feature = "no-semihosting")))]
217217
() => {
218218
let mut nr = _nr;
219+
let mut arg = _arg;
219220
// The instructions below must always be uncompressed, otherwise
220221
// it will be treated as a regular break, hence the norvc option.
221222
//
222223
// See https://github.com/riscv/riscv-semihosting-spec for more details.
223224
asm!("
225+
.balign 16
224226
.option push
225227
.option norvc
226228
slli x0, x0, 0x1f
@@ -229,7 +231,8 @@ pub unsafe fn syscall1(_nr: usize, _arg: usize) -> usize {
229231
.option pop
230232
",
231233
inout("a0") nr,
232-
in("a1") _arg,
234+
inout("a1") arg => _,
235+
options(nostack, preserves_flags),
233236
);
234237
nr
235238
}

0 commit comments

Comments
 (0)