Skip to content

Commit e07d797

Browse files
authored
Merge pull request #2 from FawazTirmizi/cortex-feature-parity
Merge upstream cortex-m-semihosting
2 parents cb1afe4 + bf2940f commit e07d797

File tree

8 files changed

+431
-129
lines changed

8 files changed

+431
-129
lines changed

CHANGELOG.md

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

66
## [Unreleased]
77

8+
## [v0.4.1] - 2020-10-20
9+
10+
0.4.1 was yanked because the pre-built binaries contain conflicting symbols
11+
with a supported version of cortex-m.
12+
13+
- Fix missing prebuilt binaries (#271)
14+
15+
## [v0.4.0] - 2020-10-14
16+
17+
v0.4.0 was yanked because it did not include the required pre-built binaries
18+
in the final crate.
19+
20+
- Moved into cortex-m repository
21+
- Merge `HStdout` and `HStderr` into one type: `HostStream`
22+
- Support cortex-m v0.7
23+
- Semihosting macros no longer return a Result, instead errors are ignored.
24+
25+
## [v0.3.7] - 2020-12-02
26+
27+
- Replaces the yanked v0.3.6 by reverting #48, so the semihosting macros
28+
continue to return a Result.
29+
30+
## [v0.3.6] - 2020-12-01
31+
32+
v0.3.6 was yanked because it incorrectly included #48, which was a breaking
33+
change.
34+
35+
### Added
36+
37+
- Update cortex-m dependency to support version 0.7.
38+
- Add `no-semihosting` feature to disable all semihosting calls.
39+
40+
## [v0.3.5] - 2019-08-29
41+
42+
### Added
43+
44+
- Adds a feature to work around JLink quirks
45+
- Adds a dbg! macro using heprintln
46+
- Added thumbv8m.main support on stable
47+
48+
### Fixed
49+
50+
- Now Rust 2018 edition
51+
52+
## [v0.3.4] - 2019-08-13
53+
54+
### Fixed
55+
56+
- Support for thumbv8 mainline hf target
57+
58+
## [v0.3.3] - 2019-04-22
59+
60+
### Added
61+
62+
- Adds support for thumbv8 and cortex-m v0.6.0
63+
64+
## [v0.3.2] - 2018-11-04
65+
66+
### Added
67+
68+
- Added a family of `hprint` macros for printing to the host standard output /
69+
error via globally shared `HStdout` / `HStderr` handles .
70+
71+
## [v0.3.1] - 2018-08-27
72+
73+
### Changed
74+
75+
- This crate no longer depends on `arm-none-eabi-gcc`.
76+
77+
## [v0.3.0] - 2018-05-10
78+
79+
### Changed
80+
81+
- [breaking-change] `inline-asm` is no longer a default feature (i.e. a feature that's enabled by
82+
default). The consequence is that this crate now compiles on 1.27 (beta) by default, and opting
83+
into `inline-asm` requires nightly.
84+
85+
## [v0.2.1] - 2018-04-25
86+
87+
### Added
88+
89+
- An opt-out "inline-asm" Cargo feature. When this feature is disabled semihosting is implemented
90+
using an external assembly file instead of using the unstable inline assembly (`asm!`) feature
91+
meaning that this crate can be compiled on stable.
92+
893
## [v0.2.0] - 2017-07-07
994

1095
### Added
@@ -56,8 +141,19 @@ This project adheres to [Semantic Versioning](http://semver.org/).
56141

57142
- Initial release
58143

59-
[Unreleased]: https://github.com/japaric/cortex-m-semihosting/compare/v0.2.0...HEAD
60-
[v0.2.0]: https://github.com/japaric/cortex-m-semihosting/compare/v0.1.3...v0.2.0
61-
[v0.1.3]: https://github.com/japaric/cortex-m-semihosting/compare/v0.1.2...v0.1.3
62-
[v0.1.2]: https://github.com/japaric/cortex-m-semihosting/compare/v0.1.1...v0.1.2
63-
[v0.1.1]: https://github.com/japaric/cortex-m-semihosting/compare/v0.1.0...v0.1.1
144+
[Unreleased]: https://github.com/rust-embedded/cortex-m/compare/c-m-sh-v0.4.1...HEAD
145+
[v0.4.1]: https://github.com/rust-embedded/cortex-m/compare/c-m-sh-v0.4.0...c-m-sh-v0.4.1
146+
[v0.4.0]: https://github.com/rust-embedded/cortex-m/compare/c-m-sh-v0.3.5...c-m-sh-v0.4.0
147+
[v0.3.7]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.3.6...v0.3.7
148+
[v0.3.6]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.3.5...v0.3.6
149+
[v0.3.5]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.3.4...v0.3.5
150+
[v0.3.4]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.3.3...v0.3.4
151+
[v0.3.3]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.3.2...v0.3.3
152+
[v0.3.2]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.3.1...v0.3.2
153+
[v0.3.1]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.3.0...v0.3.1
154+
[v0.3.0]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.2.1...v0.3.0
155+
[v0.2.1]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.2.0...v0.2.1
156+
[v0.2.0]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.1.3...v0.2.0
157+
[v0.1.3]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.1.2...v0.1.3
158+
[v0.1.2]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.1.1...v0.1.2
159+
[v0.1.1]: https://github.com/rust-embedded/cortex-m-semihosting/compare/v0.1.0...v0.1.1

Cargo.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
[package]
2-
authors = ["Jorge Aparicio <[email protected]>"]
2+
authors = [
3+
"The Cortex-M Team <[email protected]>",
4+
"Jorge Aparicio <[email protected]>",
5+
]
36
description = "Semihosting for RISCV processors"
47
documentation = "https://docs.rs/riscv-semihosting"
58
keywords = ["semihosting", "riscv"]
9+
categories = ["no-std", "embedded"]
610
license = "MIT OR Apache-2.0"
711
name = "riscv-semihosting"
12+
readme = "README.md"
813
repository = "https://github.com/riscv-rust/riscv-semihosting"
914
version = "0.0.1"
15+
edition = "2018"
16+
17+
[features]
18+
default = ["jlink-quirks"]
19+
jlink-quirks = []
20+
no-semihosting = []
1021

1122
[dependencies]
23+
riscv = "0.8.0"

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55

66
> Semihosting for ARM Cortex-M processors
77
8+
This project is developed and maintained by the [Cortex-M team][team].
9+
810
## [Documentation](https://docs.rs/cortex-m-semihosting)
911

12+
# Minimum Supported Rust Version (MSRV)
13+
14+
This crate is guaranteed to compile on stable Rust 1.59.0 and up. It **won't**
15+
compile with older versions.
16+
1017
## License
1118

1219
Licensed under either of
1320

14-
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
21+
- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or
1522
http://www.apache.org/licenses/LICENSE-2.0)
16-
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
23+
- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT)
1724

1825
at your option.
1926

@@ -22,3 +29,12 @@ at your option.
2229
Unless you explicitly state otherwise, any contribution intentionally submitted
2330
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
2431
dual licensed as above, without any additional terms or conditions.
32+
33+
## Code of Conduct
34+
35+
Contribution to this crate is organized under the terms of the [Rust Code of
36+
Conduct][CoC], the maintainer of this crate, the [Cortex-M team][team], promises
37+
to intervene to uphold that code of conduct.
38+
39+
[CoC]: ../CODE_OF_CONDUCT.md
40+
[team]: https://github.com/rust-embedded/wg#the-cortex-m-team

src/debug.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
//!
99
//! Target program:
1010
//!
11-
//! ```
12-
//! #[macro_use]
13-
//! extern crate cortex_m_semihosting;
14-
//! use cortex_m_semihosting::debug::{self, EXIT_SUCCESS, EXIT_FAILURE};
11+
//! ```no_run
12+
//! use riscv_semihosting::debug::{self, EXIT_SUCCESS, EXIT_FAILURE};
1513
//!
1614
//! fn main() {
1715
//! if 2 == 2 {

src/export.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//! IMPLEMENTATION DETAILS USED BY MACROS
2+
3+
use core::fmt::{self, Write};
4+
5+
use riscv::interrupt;
6+
7+
use crate::hio::{self, HostStream};
8+
9+
static mut HSTDOUT: Option<HostStream> = None;
10+
11+
pub fn hstdout_str(s: &str) {
12+
let _result = interrupt::free(|_| unsafe {
13+
if HSTDOUT.is_none() {
14+
HSTDOUT = Some(hio::hstdout()?);
15+
}
16+
17+
HSTDOUT.as_mut().unwrap().write_str(s).map_err(drop)
18+
});
19+
}
20+
21+
pub fn hstdout_fmt(args: fmt::Arguments) {
22+
let _result = interrupt::free(|_| unsafe {
23+
if HSTDOUT.is_none() {
24+
HSTDOUT = Some(hio::hstdout()?);
25+
}
26+
27+
HSTDOUT.as_mut().unwrap().write_fmt(args).map_err(drop)
28+
});
29+
}
30+
31+
static mut HSTDERR: Option<HostStream> = None;
32+
33+
pub fn hstderr_str(s: &str) {
34+
let _result = interrupt::free(|_| unsafe {
35+
if HSTDERR.is_none() {
36+
HSTDERR = Some(hio::hstderr()?);
37+
}
38+
39+
HSTDERR.as_mut().unwrap().write_str(s).map_err(drop)
40+
});
41+
}
42+
43+
pub fn hstderr_fmt(args: fmt::Arguments) {
44+
let _result = interrupt::free(|_| unsafe {
45+
if HSTDERR.is_none() {
46+
HSTDERR = Some(hio::hstderr()?);
47+
}
48+
49+
HSTDERR.as_mut().unwrap().write_fmt(args).map_err(drop)
50+
});
51+
}

src/hio.rs

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,46 @@
11
//! Host I/O
22
3+
use crate::nr;
34
use core::{fmt, slice};
4-
use nr;
55

6-
/// Host's standard error
7-
pub struct HStderr {
6+
/// A byte stream to the host (e.g., host's stdout or stderr).
7+
#[derive(Clone, Copy)]
8+
pub struct HostStream {
89
fd: usize,
910
}
1011

11-
impl HStderr {
12+
impl HostStream {
1213
/// Attempts to write an entire `buffer` into this sink
1314
pub fn write_all(&mut self, buffer: &[u8]) -> Result<(), ()> {
1415
write_all(self.fd, buffer)
1516
}
1617
}
1718

18-
impl fmt::Write for HStderr {
19-
fn write_str(&mut self, s: &str) -> fmt::Result {
20-
self.write_all(s.as_bytes()).map_err(|_| fmt::Error)
21-
}
22-
}
23-
24-
/// Host's standard output
25-
pub struct HStdout {
26-
fd: usize,
27-
}
28-
29-
impl HStdout {
30-
/// Attempts to write an entire `buffer` into this sink
31-
pub fn write_all(&mut self, buffer: &[u8]) -> Result<(), ()> {
32-
write_all(self.fd, buffer)
33-
}
34-
}
35-
36-
impl fmt::Write for HStdout {
19+
impl fmt::Write for HostStream {
3720
fn write_str(&mut self, s: &str) -> fmt::Result {
3821
self.write_all(s.as_bytes()).map_err(|_| fmt::Error)
3922
}
4023
}
4124

4225
/// Construct a new handle to the host's standard error.
43-
pub fn hstderr() -> Result<HStderr, ()> {
26+
pub fn hstderr() -> Result<HostStream, ()> {
4427
// There is actually no stderr access in ARM Semihosting documentation. Use
4528
// convention used in libgloss.
4629
// See: libgloss/arm/syscalls.c, line 139.
4730
// https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/arm/syscalls.c#l139
48-
open(":tt\0", nr::open::W_APPEND).map(|fd| HStderr { fd })
31+
open(":tt\0", nr::open::W_APPEND)
4932
}
5033

5134
/// Construct a new handle to the host's standard output.
52-
pub fn hstdout() -> Result<HStdout, ()> {
53-
open(":tt\0", nr::open::W_TRUNC).map(|fd| HStdout { fd })
35+
pub fn hstdout() -> Result<HostStream, ()> {
36+
open(":tt\0", nr::open::W_TRUNC)
5437
}
5538

56-
fn open(name: &str, mode: usize) -> Result<usize, ()> {
39+
fn open(name: &str, mode: usize) -> Result<HostStream, ()> {
5740
let name = name.as_bytes();
58-
match unsafe { syscall!(OPEN, name.as_ptr(), mode, name.len() - 1) } as
59-
isize {
41+
match unsafe { syscall!(OPEN, name.as_ptr(), mode, name.len() - 1) } as isize {
6042
-1 => Err(()),
61-
fd => Ok(fd as usize),
43+
fd => Ok(HostStream { fd: fd as usize }),
6244
}
6345
}
6446

@@ -70,10 +52,12 @@ fn write_all(fd: usize, mut buffer: &[u8]) -> Result<(), ()> {
7052
// `n` bytes were not written
7153
n if n <= buffer.len() => {
7254
let offset = (buffer.len() - n) as isize;
73-
buffer = unsafe {
74-
slice::from_raw_parts(buffer.as_ptr().offset(offset), n)
75-
}
55+
buffer = unsafe { slice::from_raw_parts(buffer.as_ptr().offset(offset), n) }
7656
}
57+
#[cfg(feature = "jlink-quirks")]
58+
// Error (-1) - should be an error but JLink can return -1, -2, -3,...
59+
// For good measure, we allow up to negative 15.
60+
n if n > 0xfffffff0 => return Ok(()),
7761
// Error
7862
_ => return Err(()),
7963
}

0 commit comments

Comments
 (0)