aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Greig <adam@adamgreig.com> 2023-02-17 21:22:49 +0000
committerGravatar Adam Greig <adam@adamgreig.com> 2023-02-17 21:22:49 +0000
commit9b51b40a96f94a144b6f2006729ac01c52896c67 (patch)
treee0c1e8db21c879e833f8e132ecde65043f8063d7
parente50149446c6af5919f928317840716c442a342fe (diff)
downloadcortex-m-9b51b40a96f94a144b6f2006729ac01c52896c67.tar.gz
cortex-m-9b51b40a96f94a144b6f2006729ac01c52896c67.tar.zst
cortex-m-9b51b40a96f94a144b6f2006729ac01c52896c67.zip
Move zero-init-ram to just before bss initialisation, so that pre_init occurs before
-rw-r--r--cortex-m-rt/CHANGELOG.md7
-rw-r--r--cortex-m-rt/src/lib.rs26
2 files changed, 18 insertions, 15 deletions
diff --git a/cortex-m-rt/CHANGELOG.md b/cortex-m-rt/CHANGELOG.md
index 7f1226a..fd45a1a 100644
--- a/cortex-m-rt/CHANGELOG.md
+++ b/cortex-m-rt/CHANGELOG.md
@@ -7,14 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+- Add `zero-init-ram` feature to initialize RAM with zeros on startup. This can be necessary on
+ safety-critical hardware to properly initialize memory integrity measures.
+
+## [v0.7.3]
+
- Fixed a potential miscompilation caused by the initial stack pointer
not being 8-byte aligned. This issue affected 0.7.1 and 0.7.2; for
more details please see [the advisory] ([#467]).
- A linker error is generated if the initial stack pointer is not 8-byte aligned ([#464]).
- The initial stack pointer is now forced to be 8-byte aligned in the linker script,
to defend against it being overridden outside of the cortex-m-rt linker script ([#465]).
-- Add `zero-init-ram` feature to initialize RAM with zeros on startup. This can be necessary on
- safety-critical hardware to properly initialize memory integrity measures.
[the advisory]: https://github.com/rust-embedded/cortex-m/discussions/469
[#464]: https://github.com/rust-embedded/cortex-m/issues/464
diff --git a/cortex-m-rt/src/lib.rs b/cortex-m-rt/src/lib.rs
index 30fe37e..a6d946c 100644
--- a/cortex-m-rt/src/lib.rs
+++ b/cortex-m-rt/src/lib.rs
@@ -521,19 +521,6 @@ cfg_global_asm! {
"ldr r0, =_stack_start
msr msp, r0",
- // If enabled, initialize RAM with zeros. This is not usually required, but might be necessary
- // to properly initialize checksum-based memory integrity measures on safety-critical hardware.
- #[cfg(feature = "zero-init-ram")]
- "ldr r0, =_ram_start
- ldr r1, =_ram_end
- movs r2, #0
- 0:
- cmp r1, r0
- beq 1f
- stm r0!, {{r2}}
- b 0b
- 1:",
-
// If enabled, initialise VTOR to the start of the vector table. This is normally initialised
// by a bootloader when the non-reset value is required, but some bootloaders do not set it,
// leading to frustrating issues where everything seems to work but interrupts are never
@@ -549,6 +536,19 @@ cfg_global_asm! {
// Example use cases include disabling default watchdogs or enabling RAM.
"bl __pre_init",
+ // If enabled, initialize RAM with zeros. This is not usually required, but might be necessary
+ // to properly initialize checksum-based memory integrity measures on safety-critical hardware.
+ #[cfg(feature = "zero-init-ram")]
+ "ldr r0, =_ram_start
+ ldr r1, =_ram_end
+ movs r2, #0
+ 0:
+ cmp r1, r0
+ beq 1f
+ stm r0!, {{r2}}
+ b 0b
+ 1:",
+
// Initialise .bss memory. `__sbss` and `__ebss` come from the linker script.
#[cfg(not(feature = "zero-init-ram"))]
"ldr r0, =__sbss