diff --git a/asm.s b/asm.s index 1be4a02d..37dedbd6 100644 --- a/asm.s +++ b/asm.s @@ -40,3 +40,17 @@ FpuTrampoline: # Hand execution over to `main`. bl main # Note: `main` must not return. `bl` is used only because it has a wider range than `b`. + + # ARMv6-M leaves LR in an unknown state on Reset + # this trampoline sets LR before it's pushed onto the stack by Reset + .section .PreResetTrampoline, "ax" + .global PreResetTrampoline + # .type and .thumb_func are both required; otherwise its Thumb bit does not + # get set and an invalid vector table is generated + .type PreResetTrampoline,%function + .thumb_func +PreResetTrampoline: + # set LR to the initial value used by the ARMv7-M (0xFFFF_FFFF) + ldr r0,=0xffffffff + mov lr,r0 + b Reset diff --git a/bin/thumbv6m-none-eabi.a b/bin/thumbv6m-none-eabi.a index 99f1b1a5..65684dad 100644 Binary files a/bin/thumbv6m-none-eabi.a and b/bin/thumbv6m-none-eabi.a differ diff --git a/bin/thumbv7em-none-eabi.a b/bin/thumbv7em-none-eabi.a index 020b7964..c4e1f47a 100644 Binary files a/bin/thumbv7em-none-eabi.a and b/bin/thumbv7em-none-eabi.a differ diff --git a/bin/thumbv7em-none-eabihf.a b/bin/thumbv7em-none-eabihf.a index 020b7964..c4e1f47a 100644 Binary files a/bin/thumbv7em-none-eabihf.a and b/bin/thumbv7em-none-eabihf.a differ diff --git a/bin/thumbv7m-none-eabi.a b/bin/thumbv7m-none-eabi.a index 16ade100..ed96942a 100644 Binary files a/bin/thumbv7m-none-eabi.a and b/bin/thumbv7m-none-eabi.a differ diff --git a/bin/thumbv8m.base-none-eabi.a b/bin/thumbv8m.base-none-eabi.a index 264b029c..f1c7734a 100644 Binary files a/bin/thumbv8m.base-none-eabi.a and b/bin/thumbv8m.base-none-eabi.a differ diff --git a/bin/thumbv8m.main-none-eabi.a b/bin/thumbv8m.main-none-eabi.a index 01b343fc..cb216dcf 100644 Binary files a/bin/thumbv8m.main-none-eabi.a and b/bin/thumbv8m.main-none-eabi.a differ diff --git a/bin/thumbv8m.main-none-eabihf.a b/bin/thumbv8m.main-none-eabihf.a index 01b343fc..cb216dcf 100644 Binary files a/bin/thumbv8m.main-none-eabihf.a and b/bin/thumbv8m.main-none-eabihf.a differ diff --git a/link.x.in b/link.x.in index f5e582e5..f4f49590 100644 --- a/link.x.in +++ b/link.x.in @@ -85,6 +85,10 @@ SECTIONS /* ### .text */ .text _stext : { + /* place these 2 close to each other or the `b` instruction will fail to link */ + *(.PreResetTrampoline); + *(.Reset); + *(.text .text.*); *(.HardFaultTrampoline); *(.HardFault.*); diff --git a/src/lib.rs b/src/lib.rs index e2dd6673..ab4bc3f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -923,9 +923,17 @@ pub fn heap_start() -> *mut u32 { #[doc(hidden)] #[link_section = ".vector_table.reset_vector"] #[no_mangle] +#[cfg(not(armv6m))] pub static __RESET_VECTOR: unsafe extern "C" fn() -> ! = Reset; #[doc(hidden)] +#[link_section = ".vector_table.reset_vector"] +#[no_mangle] +#[cfg(armv6m)] +pub static __RESET_VECTOR: unsafe extern "C" fn() -> ! = PreResetTrampoline; + +#[doc(hidden)] +#[link_section = ".Reset"] #[no_mangle] pub unsafe extern "C" fn Reset() -> ! { extern "C" { @@ -1030,6 +1038,9 @@ pub enum Exception { pub use self::Exception as exception; extern "C" { + #[cfg(armv6m)] + fn PreResetTrampoline() -> !; + fn NonMaskableInt(); fn HardFaultTrampoline();