Skip to content
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

riscv-semihosting: bug fixes #171

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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