From c7fa03ef65f4b8b387da770c5e6452e47bfc9f3e Mon Sep 17 00:00:00 2001 From: "Cliff L. Biffle" Date: Sun, 24 May 2020 17:19:57 -0700 Subject: [PATCH 1/8] ITM: don't test reserved bits in is_fifo_ready On ARMv7-M, bits 31:1 of the value read from STIMx are reserved, so comparing them against zero is a bad idea. On ARMv8-M, bit 1 has been repurposed to indicate DISABLED. This means that the is_fifo_ready impl hangs forever when ITM is disabled on a Cortex-M33 (for example). Changed to test only the FIFOREADY bit. --- src/peripheral/itm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peripheral/itm.rs b/src/peripheral/itm.rs index 30c7e47f..f5057c1a 100644 --- a/src/peripheral/itm.rs +++ b/src/peripheral/itm.rs @@ -55,6 +55,6 @@ impl Stim { /// Returns `true` if the stimulus port is ready to accept more data #[inline] pub fn is_fifo_ready(&self) -> bool { - unsafe { ptr::read_volatile(self.register.get()) == 1 } + unsafe { ptr::read_volatile(self.register.get()) & 1 == 1 } } } From f58e5e13740d254738646d144f4c24470ba940ad Mon Sep 17 00:00:00 2001 From: "Cliff L. Biffle" Date: Tue, 9 Jun 2020 18:49:00 -0700 Subject: [PATCH 2/8] ITM: don't test reserved bits in is_fifo_ready On ARMv7-M, bits 31:1 of the value read from STIMx are reserved, so comparing them against zero is a bad idea. On ARMv8-M, bit 1 has been repurposed to indicate DISABLED. This means that the is_fifo_ready impl hangs forever when ITM is disabled on a Cortex-M33 (for example). Changed to test only the FIFOREADY bit on ARMv7-M, and to test either FIFOREADY or DISABLED on ARMv8-M. --- src/peripheral/itm.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/peripheral/itm.rs b/src/peripheral/itm.rs index f5057c1a..9fe963d8 100644 --- a/src/peripheral/itm.rs +++ b/src/peripheral/itm.rs @@ -53,8 +53,19 @@ impl Stim { } /// Returns `true` if the stimulus port is ready to accept more data + #[cfg(not(armv8m))] #[inline] pub fn is_fifo_ready(&self) -> bool { - unsafe { ptr::read_volatile(self.register.get()) & 1 == 1 } + unsafe { ptr::read_volatile(self.register.get()) & 0b1 == 1 } + } + + /// Returns `true` if the stimulus port is ready to accept more data + #[cfg(armv8m)] + #[inline] + pub fn is_fifo_ready(&self) -> bool { + // ARMv8-M adds a disabled bit; we indicate that we are ready to + // proceed with a stimulus write if the port is either ready (bit 0) or + // disabled (bit 1). + unsafe { ptr::read_volatile(self.register.get()) & 0b11 != 0 } } } From 33f031868df877a4f54720938ab48fc434485f49 Mon Sep 17 00:00:00 2001 From: Peter Taylor Date: Fri, 19 Jun 2020 12:55:48 -0600 Subject: [PATCH 3/8] Correct the documentation for the `SCB::set_pendst` function --- src/peripheral/scb.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peripheral/scb.rs b/src/peripheral/scb.rs index 55ecdee8..f829c6b2 100644 --- a/src/peripheral/scb.rs +++ b/src/peripheral/scb.rs @@ -706,7 +706,7 @@ impl SCB { } } - /// Set the PENDSTCLR bit in the ICSR register which will clear a pending SysTick interrupt + /// Set the PENDSTSET bit in the ICSR register which will pend a SysTick interrupt #[inline] pub fn set_pendst() { unsafe { From b607b35faf9ba21c0f6718c1e717e59e5166b98f Mon Sep 17 00:00:00 2001 From: "Cliff L. Biffle" Date: Sat, 4 Jul 2020 10:27:51 -0700 Subject: [PATCH 4/8] Use assembly sequences to enable caches. See #232, which this partially fixes -- there's still the question of taking an interrupt in the midst of these sequences. --- asm-v7.s | 37 ++++++++++++++++++++++++++++++++ bin/thumbv6m-none-eabi.a | Bin 5806 -> 5822 bytes bin/thumbv7em-none-eabi.a | Bin 10570 -> 11258 bytes bin/thumbv7em-none-eabihf.a | Bin 10570 -> 11258 bytes bin/thumbv7m-none-eabi.a | Bin 8328 -> 9008 bytes bin/thumbv8m.base-none-eabi.a | Bin 8254 -> 8286 bytes bin/thumbv8m.main-none-eabi.a | Bin 13372 -> 14084 bytes bin/thumbv8m.main-none-eabihf.a | Bin 13372 -> 14084 bytes src/peripheral/scb.rs | 26 +++++++++++++++------- 9 files changed, 55 insertions(+), 8 deletions(-) diff --git a/asm-v7.s b/asm-v7.s index fad6f4c0..17d7110e 100644 --- a/asm-v7.s +++ b/asm-v7.s @@ -1,3 +1,4 @@ + .syntax unified .cfi_sections .debug_frame .section .text.__basepri_max @@ -39,3 +40,39 @@ __faultmask: bx lr .cfi_endproc .size __faultmask, . - __faultmask + + .section .text.__enable_icache + .global __enable_icache + .thumb_func + .cfi_startproc +__enable_icache: + ldr r0, =0xE000ED14 @ CCR + mrs r2, PRIMASK @ save critical nesting info + cpsid i @ mask interrupts + ldr r1, [r0] @ read CCR + orr.w r1, r1, #(1 << 17) @ Set bit 17, IC + str r1, [r0] @ write it back + dsb @ ensure store completes + isb @ synchronize pipeline + msr PRIMASK, r2 @ unnest critical section + bx lr + .cfi_endproc + .size __enable_icache, . - __enable_icache + + .section .text.__enable_dcache + .global __enable_dcache + .thumb_func + .cfi_startproc +__enable_dcache: + ldr r0, =0xE000ED14 @ CCR + mrs r2, PRIMASK @ save critical nesting info + cpsid i @ mask interrupts + ldr r1, [r0] @ read CCR + orr.w r1, r1, #(1 << 16) @ Set bit 16, DC + str r1, [r0] @ write it back + dsb @ ensure store completes + isb @ synchronize pipeline + msr PRIMASK, r2 @ unnest critical section + bx lr + .cfi_endproc + .size __enable_dcache, . - __enable_dcache diff --git a/bin/thumbv6m-none-eabi.a b/bin/thumbv6m-none-eabi.a index 001436833a97754ec85a3c730644ac1623b2bfb1..91563ff4593b29a1a50da79d8ef0680f0bf47c3f 100644 GIT binary patch delta 176 zcmZ3dyH9sR1S6A~#pEbP4MvyE&5R!y84V|wFyAsxOi9eu4=BpdN=+^))-Nh8F40ZR zO-fBkNlnpD&MzuSt}%FDgl` z(9LCV_X|~U3|27GGd9`W$nuq+@y_IO5r4*#$;U;?8JA497u9Aon4B%D%qTFqUsRpZ xW%70)xnuHuAXze*T}++v#$Jlxy3=HcS8Q=iM1OWUqEBXKc diff --git a/bin/thumbv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dx5c5st7VU%vH>M_9H3 zOqh6zB{iBE6F$x^j^%E=+OZE`^dG#NUT-nF(-6!C5pA3`+r-!QE9Ip8#C8j%3y@{HPQ285wk0;^s*iRklX#C$dn({k+X{+#~MV%J+;1P9M zJdIzdd&LyqQbTfz(o?u1j#bK}{)38mD5A1-)D@p$e=#}AgDz> delta 1348 zcmb_cUr1A76hGhH?kfMx>HfP-uWs(nE!)_ZsE`;=w2_OJ{tStnQy!?qBM;6DgF|I%W9AHO}!^sA4$`KZvVYKQR#5xuh7&@KRewotP zG%E*_q1T`@x{P&3v!cN31w}&-fXjLr=bYyKG=}TWDB27XwpPaRVdZypyG^+5GGVvh zgo|X|#AgW)yGNW@V*g_!mxA3bv$#rRG92UJ^FBcCg&>pqdw z$Xw=@4;0cWq%;crby5|+l22`ns|srjCA+_LlZ2+pY!tWPlaNcyP*x)@hrEUy)ouai zyb1c^PYCrai)P<5)_`w)eZhTv<%O&AXX-BNnFaIpJ@gNu3r?`}csm$k%{U+QihLFl zpGEmo%GY*s1%Cx)agxp>ywmc%vzo>BkSr`HeX!SvA(?I9%aH8guhAE^PeM{q)?eZ> B)xrP( diff --git a/bin/thumbv7m-none-eabi.a b/bin/thumbv7m-none-eabi.a index f1f686d00bb2d5ec30f2d57adc65bb1a99c991d3..ce4710dc185956e0e9c49412468e281bf76069e5 100644 GIT binary patch delta 1818 zcmb_cU1(HS5T0{)ubbEych}ASC1h_%a6@bMCcCk$_+Yk(QK-?@Qw95=pjDbeTd>t{?%tdI(Y}-pch1ar zX3orVv`L30JyI3erSui@dWMkf|hP9Wod|LIZ%?sbFM@kLx<4BaRc^0#UQeoQMIXAP< zDwgNXxew;c1J?AURVrB}vp6$Xwmuq|rqQuCjNI!+I+e+!hKQbk__pVZg}3xqSF8Jc zKD0v}=D$Mw)n$Ia<0Z9;&vf)EgTL)as&T%D@dplslknMq@h%s_NzJSCC*id)U&PcY zz7-zzW(L!PQskO%d^k-aeb^TL6sH*HBe8A1tq+&{hvu%Rs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!3MpT)>1ePQzIAOUEg`s95b_D7%N*m`>->XiCR9_KVM6pggYA6^xpa#k+0F=IIp~ z!X|`|V@^gngI%$P@qnS|Mi|NrcAAv%j;HLYlV$5bV?cL2VYm3tKKzX9j(Lt2=Z;~N zb6>5ENte({{&0X|>U@2}VrM;vHr8TxE?4 Date: Wed, 15 Apr 2020 09:52:01 +0100 Subject: [PATCH 5/8] Add a function to get SHCSR enable bit positions This removes the duplication of the look-up table and enforces some safety checks with the match statement. Signed-off-by: Hugues de Valon --- src/peripheral/scb.rs | 75 ++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/src/peripheral/scb.rs b/src/peripheral/scb.rs index b300d7af..d710272d 100644 --- a/src/peripheral/scb.rs +++ b/src/peripheral/scb.rs @@ -1,8 +1,6 @@ //! System Control Block use core::ptr; -#[cfg(not(any(armv6m, armv8m_base)))] -use crate::interrupt; use volatile_register::RW; @@ -852,6 +850,20 @@ impl SCB { } } + /// Return the bit position of the exception enable bit in the SHCSR register + #[inline] + #[cfg(not(any(armv6m, armv8m_base)))] + fn shcsr_enable_shift(exception: Exception) -> Option { + match exception { + Exception::MemoryManagement => Some(16), + Exception::BusFault => Some(17), + Exception::UsageFault => Some(18), + #[cfg(armv8m_main)] + Exception::SecureFault => Some(19), + _ => None, + } + } + /// Enable the exception /// /// If the exception is enabled, when the exception is triggered, the exception handler will be executed instead of the @@ -866,24 +878,11 @@ impl SCB { #[inline] #[cfg(not(any(armv6m, armv8m_base)))] pub fn enable(&mut self, exception: Exception) { - if self.is_enabled(exception) { - return; - } - - // Make sure that the read-modify-write sequence happens during a critical section to avoid - // modifying pending and active interrupts. - interrupt::free(|_| { - let shift = match exception { - Exception::MemoryManagement => 16, - Exception::BusFault => 17, - Exception::UsageFault => 18, - #[cfg(armv8m_main)] - Exception::SecureFault => 19, - _ => return, - }; - + if let Some(shift) = SCB::shcsr_enable_shift(exception) { + // The mutable reference to SCB makes sure that only this code is currently modifying + // the register. unsafe { self.shcsr.modify(|value| value | (1 << shift)) } - }) + } } /// Disable the exception @@ -900,24 +899,11 @@ impl SCB { #[inline] #[cfg(not(any(armv6m, armv8m_base)))] pub fn disable(&mut self, exception: Exception) { - if !self.is_enabled(exception) { - return; - } - - // Make sure that the read-modify-write sequence happens during a critical section to avoid - // modifying pending and active interrupts. - interrupt::free(|_| { - let shift = match exception { - Exception::MemoryManagement => 16, - Exception::BusFault => 17, - Exception::UsageFault => 18, - #[cfg(armv8m_main)] - Exception::SecureFault => 19, - _ => return, - }; - + if let Some(shift) = SCB::shcsr_enable_shift(exception) { + // The mutable reference to SCB makes sure that only this code is currently modifying + // the register. unsafe { self.shcsr.modify(|value| value & !(1 << shift)) } - }) + } } /// Check if an exception is enabled @@ -931,16 +917,11 @@ impl SCB { /// Calling this function with any other exception will read `false`. #[inline] #[cfg(not(any(armv6m, armv8m_base)))] - pub fn is_enabled(&mut self, exception: Exception) -> bool { - let shift = match exception { - Exception::MemoryManagement => 16, - Exception::BusFault => 17, - Exception::UsageFault => 18, - #[cfg(armv8m_main)] - Exception::SecureFault => 19, - _ => return false, - }; - - (self.shcsr.read() & (1 << shift)) > 0 + pub fn is_enabled(&self, exception: Exception) -> bool { + if let Some(shift) = SCB::shcsr_enable_shift(exception) { + (self.shcsr.read() & (1 << shift)) > 0 + } else { + false + } } } From b7ff5f7fe431776f9f8883b0f9dcba53c5b60620 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 12 Jul 2020 02:43:14 +0200 Subject: [PATCH 6/8] Allow the taken flag to be optimized out --- src/peripheral/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/peripheral/mod.rs b/src/peripheral/mod.rs index 8854830a..84f6b384 100644 --- a/src/peripheral/mod.rs +++ b/src/peripheral/mod.rs @@ -143,14 +143,17 @@ pub struct Peripherals { // NOTE `no_mangle` is used here to prevent linking different minor versions of this crate as that // would let you `take` the core peripherals more than once (one per minor version) #[no_mangle] -static mut CORE_PERIPHERALS: bool = false; +static CORE_PERIPHERALS: () = (); + +/// Set to `true` when `take` or `steal` was called to make `Peripherals` a singleton. +static mut TAKEN: bool = false; impl Peripherals { /// Returns all the core peripherals *once* #[inline] pub fn take() -> Option { interrupt::free(|_| { - if unsafe { CORE_PERIPHERALS } { + if unsafe { TAKEN } { None } else { Some(unsafe { Peripherals::steal() }) @@ -161,7 +164,7 @@ impl Peripherals { /// Unchecked version of `Peripherals::take` #[inline] pub unsafe fn steal() -> Self { - CORE_PERIPHERALS = true; + TAKEN = true; Peripherals { CBP: CBP { From 202cb2d885c6fe1fa6b8ebfcb81fc1308d378521 Mon Sep 17 00:00:00 2001 From: Adam Greig Date: Thu, 16 Jul 2020 12:42:30 +0100 Subject: [PATCH 7/8] Always link pre-built asm, required for new cache management functions --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index eb0cd114..d53dea5c 100644 --- a/build.rs +++ b/build.rs @@ -6,7 +6,7 @@ fn main() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); let name = env::var("CARGO_PKG_NAME").unwrap(); - if target.starts_with("thumb") && env::var_os("CARGO_FEATURE_INLINE_ASM").is_none() { + if target.starts_with("thumb") { fs::copy( format!("bin/{}.a", target), out_dir.join(format!("lib{}.a", name)), From 6717d4bc77d6f1d64183db17a7b473cff723371b Mon Sep 17 00:00:00 2001 From: Adam Greig Date: Mon, 20 Jul 2020 02:29:43 +0100 Subject: [PATCH 8/8] Update CHANGELOG with 0.6.3 backports --- CHANGELOG.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 274eb801..65027c3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [v0.6.3] - 2020-07-20 + +### Added + +- Initial Cortex-M Security Extension support for armv8m +- `UDF` intrinsic +- Methods to enable/disable exceptions in SCB + +### Fixed + +- Fix bug in `asm::delay` not updating status clobber flags +- Swapped to `llvm_asm!` to support inline assembly on new nightlies +- Our precompiled assembly routines have additional debug information +- ITM `is_fifo_ready` improved to support armv8 +- Cache enabling moved to pre-built assembly routines to prevent possible + undefined behaviour + ## [v0.6.2] - 2020-01-12 ### Added @@ -572,7 +589,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.6.2...HEAD +[Unreleased]: https://github.com/rust-embedded/cortex-m/compare/v0.6.3...HEAD +[v0.6.3]: https://github.com/rust-embedded/cortex-m/compare/v0.6.2...v0.6.3 [v0.6.2]: https://github.com/rust-embedded/cortex-m/compare/v0.6.1...v0.6.2 [v0.6.1]: https://github.com/rust-embedded/cortex-m/compare/v0.6.0...v0.6.1 [v0.6.0]: https://github.com/rust-embedded/cortex-m/compare/v0.5.8...v0.6.0