Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

[ARMv6-M] initialize the LR register #293

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions asm.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file modified bin/thumbv6m-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabihf.a
Binary file not shown.
Binary file modified bin/thumbv7m-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.base-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabihf.a
Binary file not shown.
4 changes: 4 additions & 0 deletions link.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.*);
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -1030,6 +1038,9 @@ pub enum Exception {
pub use self::Exception as exception;

extern "C" {
#[cfg(armv6m)]
fn PreResetTrampoline() -> !;

fn NonMaskableInt();

fn HardFaultTrampoline();
Expand Down