Skip to content

Commit

Permalink
Merge pull request #171 from rust-embedded/semihosting
Browse files Browse the repository at this point in the history
`riscv-semihosting`: bug fixes
  • Loading branch information
romancardenas authored Jan 2, 2024
2 parents 1921b5e + f98f303 commit d9b9df3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions riscv-semihosting/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
15 changes: 13 additions & 2 deletions riscv-semihosting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion riscv-semihosting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit d9b9df3

Please sign in to comment.