Skip to content

Commit e0bfe3a

Browse files
bors[bot]adamgreig
andauthored
Merge #441
441: Prepare for v0.7.5 r=newAM a=adamgreig Currently with cortex-m 0.7.4 it's not possible for stable Rust users to enable the inline-asm feature, even though their compiler might support it, because of the `![cfg_attr(feature = "inline-asm", feature(asm))]` line. I propose a new 0.7.5 release that removes this line, which means users on stable Rust >=1.59 could enable the previously nightly-only feature to get stable inline asm. I wouldn't enable the feature by default, because that would be a significant MSRV bump, but at least this way more users could enable it before we release 0.8 with the revamped and inline-only asm. I've also backported the bugfix from #380 which I don't believe is a breaking change. I haven't had a chance to test this yet so it would be great if someone could try it out and just make sure the inline-asm feature does work before merging. Any thoughts on anything else worth backporting from 0.8? Co-authored-by: Adam Greig <[email protected]> Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
2 parents b581ec7 + bba4f0f commit e0bfe3a

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

CHANGELOG.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.7.5] - 2022-05-15
11+
1012
### Deprecated
1113
- the `ptr()` function on all peripherals register blocks in favor of
1214
the associated constant `PTR` (#386).
1315

16+
### Changed
17+
18+
- The `inline-asm` feature no longer requires a nightly Rust compiler, but
19+
does require Rust 1.59 or above.
20+
21+
### Fixed
22+
- Fixed `singleton!()` statics sometimes ending up in `.data` instead of `.bss` (#364, #380).
23+
(Backported from upcoming 0.8 release).
24+
1425
## [v0.7.4] - 2021-12-31
1526

1627
### Added
@@ -735,7 +746,8 @@ fn main() {
735746
- Functions to get the vector table
736747
- Wrappers over miscellaneous instructions like `bkpt`
737748

738-
[Unreleased]: https://github.com/rust-embedded/cortex-m/compare/v0.7.4...HEAD
749+
[Unreleased]: https://github.com/rust-embedded/cortex-m/compare/v0.7.5...HEAD
750+
[v0.7.5]: https://github.com/rust-embedded/cortex-m/compare/v0.7.4...v0.7.5
739751
[v0.7.4]: https://github.com/rust-embedded/cortex-m/compare/v0.7.3...v0.7.4
740752
[v0.7.3]: https://github.com/rust-embedded/cortex-m/compare/v0.7.2...v0.7.3
741753
[v0.7.2]: https://github.com/rust-embedded/cortex-m/compare/v0.7.1...v0.7.2

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0"
1111
name = "cortex-m"
1212
readme = "README.md"
1313
repository = "https://github.com/rust-embedded/cortex-m"
14-
version = "0.7.4"
14+
version = "0.7.5"
1515
edition = "2018"
1616
links = "cortex-m" # prevent multiple versions of this crate to be linked together
1717

cortex-m-semihosting/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@
153153
//!
154154
//! ## `inline-asm`
155155
//!
156-
//! When this feature is enabled semihosting is implemented using inline assembly (`llvm_asm!`) and
157-
//! compiling this crate requires nightly.
156+
//! When this feature is enabled semihosting is implemented using inline assembly (`asm!`).
158157
//!
159158
//! When this feature is disabled semihosting is implemented using FFI calls into an external
160159
//! assembly file and compiling this crate works on stable and beta.
@@ -179,7 +178,6 @@
179178
//!
180179
//! [pdf]: http://infocenter.arm.com/help/topic/com.arm.doc.dui0471e/DUI0471E_developing_for_arm_processors.pdf
181180
182-
#![cfg_attr(feature = "inline-asm", feature(llvm_asm))]
183181
#![deny(missing_docs)]
184182
#![no_std]
185183

@@ -213,7 +211,7 @@ pub unsafe fn syscall1(_nr: usize, _arg: usize) -> usize {
213211
#[cfg(all(thumb, feature = "inline-asm", not(feature = "no-semihosting")))]
214212
() => {
215213
let mut nr = _nr;
216-
llvm_asm!("bkpt 0xAB" : "+{r0}"(nr) : "{r1}"(_arg) :: "volatile");
214+
core::arch::asm!("bkpt #0xab", inout("r0") nr, in("r1") _arg, options(nostack, preserves_flags));
217215
nr
218216
}
219217

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
//! - Some of the `register` API only becomes available only when `inline-asm` is enabled. Check the
2323
//! API docs for details.
2424
//!
25-
//! The disadvantage is that `inline-asm` requires a nightly toolchain.
25+
//! The disadvantage is that `inline-asm` requires a Rust version at least 1.59 to use the `asm!()`
26+
//! macro. In the future 0.8 and above versions of `cortex-m`, this feature will always be enabled.
2627
//!
2728
//! ## `cm7-r0p1`
2829
//!
@@ -55,7 +56,6 @@
5556
//! This crate is guaranteed to compile on stable Rust 1.38 and up. It *might*
5657
//! compile with older versions but that may change in any new patch release.
5758
58-
#![cfg_attr(feature = "inline-asm", feature(asm))]
5959
#![deny(missing_docs)]
6060
#![no_std]
6161
#![allow(clippy::identity_op)]

src/macros.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ macro_rules! iprintln {
3030
/// `None` variant the caller must ensure that the macro is called from a function that's executed
3131
/// at most once in the whole lifetime of the program.
3232
///
33-
/// # Note
33+
/// # Notes
3434
/// This macro is unsound on multi core systems.
3535
///
36+
/// For debuggability, you can set an explicit name for a singleton. This name only shows up the
37+
/// the debugger and is not referencable from other code. See example below.
38+
///
3639
/// # Example
3740
///
3841
/// ``` no_run
@@ -50,32 +53,41 @@ macro_rules! iprintln {
5053
/// fn alias() -> &'static mut bool {
5154
/// singleton!(: bool = false).unwrap()
5255
/// }
56+
///
57+
/// fn singleton_with_name() {
58+
/// // A name only for debugging purposes
59+
/// singleton!(FOO_BUFFER: [u8; 1024] = [0u8; 1024]);
60+
/// }
5361
/// ```
5462
#[macro_export]
5563
macro_rules! singleton {
56-
(: $ty:ty = $expr:expr) => {
64+
($name:ident: $ty:ty = $expr:expr) => {
5765
$crate::interrupt::free(|_| {
58-
static mut VAR: Option<$ty> = None;
66+
// this is a tuple of a MaybeUninit and a bool because using an Option here is
67+
// problematic: Due to niche-optimization, an Option could end up producing a non-zero
68+
// initializer value which would move the entire static from `.bss` into `.data`...
69+
static mut $name: (::core::mem::MaybeUninit<$ty>, bool) =
70+
(::core::mem::MaybeUninit::uninit(), false);
5971

6072
#[allow(unsafe_code)]
61-
let used = unsafe { VAR.is_some() };
73+
let used = unsafe { $name.1 };
6274
if used {
6375
None
6476
} else {
6577
let expr = $expr;
6678

6779
#[allow(unsafe_code)]
6880
unsafe {
69-
VAR = Some(expr)
70-
}
71-
72-
#[allow(unsafe_code)]
73-
unsafe {
74-
VAR.as_mut()
81+
$name.1 = true;
82+
$name.0 = ::core::mem::MaybeUninit::new(expr);
83+
Some(&mut *$name.0.as_mut_ptr())
7584
}
7685
}
7786
})
7887
};
88+
(: $ty:ty = $expr:expr) => {
89+
$crate::singleton!(VAR: $ty = $expr)
90+
};
7991
}
8092

8193
/// ``` compile_fail

0 commit comments

Comments
 (0)