Skip to content

Commit

Permalink
Merge #441
Browse files Browse the repository at this point in the history
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 <adam@adamgreig.com>
Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
  • Loading branch information
bors[bot] and adamgreig committed May 31, 2022
2 parents b581ec7 + bba4f0f commit e0bfe3a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [v0.7.5] - 2022-05-15

### Deprecated
- the `ptr()` function on all peripherals register blocks in favor of
the associated constant `PTR` (#386).

### Changed

- The `inline-asm` feature no longer requires a nightly Rust compiler, but
does require Rust 1.59 or above.

### Fixed
- Fixed `singleton!()` statics sometimes ending up in `.data` instead of `.bss` (#364, #380).
(Backported from upcoming 0.8 release).

## [v0.7.4] - 2021-12-31

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

[Unreleased]: https://github.com/rust-embedded/cortex-m/compare/v0.7.4...HEAD
[Unreleased]: https://github.com/rust-embedded/cortex-m/compare/v0.7.5...HEAD
[v0.7.5]: https://github.com/rust-embedded/cortex-m/compare/v0.7.4...v0.7.5
[v0.7.4]: https://github.com/rust-embedded/cortex-m/compare/v0.7.3...v0.7.4
[v0.7.3]: https://github.com/rust-embedded/cortex-m/compare/v0.7.2...v0.7.3
[v0.7.2]: https://github.com/rust-embedded/cortex-m/compare/v0.7.1...v0.7.2
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0"
name = "cortex-m"
readme = "README.md"
repository = "https://github.com/rust-embedded/cortex-m"
version = "0.7.4"
version = "0.7.5"
edition = "2018"
links = "cortex-m" # prevent multiple versions of this crate to be linked together

Expand Down
6 changes: 2 additions & 4 deletions cortex-m-semihosting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@
//!
//! ## `inline-asm`
//!
//! When this feature is enabled semihosting is implemented using inline assembly (`llvm_asm!`) and
//! compiling this crate requires nightly.
//! When this feature is enabled semihosting is implemented using inline assembly (`asm!`).
//!
//! When this feature is disabled semihosting is implemented using FFI calls into an external
//! assembly file and compiling this crate works on stable and beta.
Expand All @@ -179,7 +178,6 @@
//!
//! [pdf]: http://infocenter.arm.com/help/topic/com.arm.doc.dui0471e/DUI0471E_developing_for_arm_processors.pdf

#![cfg_attr(feature = "inline-asm", feature(llvm_asm))]
#![deny(missing_docs)]
#![no_std]

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

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
//! - Some of the `register` API only becomes available only when `inline-asm` is enabled. Check the
//! API docs for details.
//!
//! The disadvantage is that `inline-asm` requires a nightly toolchain.
//! The disadvantage is that `inline-asm` requires a Rust version at least 1.59 to use the `asm!()`
//! macro. In the future 0.8 and above versions of `cortex-m`, this feature will always be enabled.
//!
//! ## `cm7-r0p1`
//!
Expand Down Expand Up @@ -55,7 +56,6 @@
//! This crate is guaranteed to compile on stable Rust 1.38 and up. It *might*
//! compile with older versions but that may change in any new patch release.

#![cfg_attr(feature = "inline-asm", feature(asm))]
#![deny(missing_docs)]
#![no_std]
#![allow(clippy::identity_op)]
Expand Down
32 changes: 22 additions & 10 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ macro_rules! iprintln {
/// `None` variant the caller must ensure that the macro is called from a function that's executed
/// at most once in the whole lifetime of the program.
///
/// # Note
/// # Notes
/// This macro is unsound on multi core systems.
///
/// For debuggability, you can set an explicit name for a singleton. This name only shows up the
/// the debugger and is not referencable from other code. See example below.
///
/// # Example
///
/// ``` no_run
Expand All @@ -50,32 +53,41 @@ macro_rules! iprintln {
/// fn alias() -> &'static mut bool {
/// singleton!(: bool = false).unwrap()
/// }
///
/// fn singleton_with_name() {
/// // A name only for debugging purposes
/// singleton!(FOO_BUFFER: [u8; 1024] = [0u8; 1024]);
/// }
/// ```
#[macro_export]
macro_rules! singleton {
(: $ty:ty = $expr:expr) => {
($name:ident: $ty:ty = $expr:expr) => {
$crate::interrupt::free(|_| {
static mut VAR: Option<$ty> = None;
// this is a tuple of a MaybeUninit and a bool because using an Option here is
// problematic: Due to niche-optimization, an Option could end up producing a non-zero
// initializer value which would move the entire static from `.bss` into `.data`...
static mut $name: (::core::mem::MaybeUninit<$ty>, bool) =
(::core::mem::MaybeUninit::uninit(), false);

#[allow(unsafe_code)]
let used = unsafe { VAR.is_some() };
let used = unsafe { $name.1 };
if used {
None
} else {
let expr = $expr;

#[allow(unsafe_code)]
unsafe {
VAR = Some(expr)
}

#[allow(unsafe_code)]
unsafe {
VAR.as_mut()
$name.1 = true;
$name.0 = ::core::mem::MaybeUninit::new(expr);
Some(&mut *$name.0.as_mut_ptr())
}
}
})
};
(: $ty:ty = $expr:expr) => {
$crate::singleton!(VAR: $ty = $expr)
};
}

/// ``` compile_fail
Expand Down

0 comments on commit e0bfe3a

Please sign in to comment.