Skip to content

Commit bf037b3

Browse files
Restore LR after __pre_init call
1 parent 35dc34b commit bf037b3

8 files changed

+6
-2
lines changed

cortex-m-rt/asm.s

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@ FpuTrampoline:
6060
.cfi_startproc
6161
PreResetTrampoline:
6262
# set LR to the initial value used by the ARMv7-M (0xFFFF_FFFF)
63-
ldr r0,=0xffffffff
64-
mov lr,r0
63+
ldr r4,=0xffffffff
64+
mov lr,r4
6565

6666
# run the pre-init code
6767
bl __pre_init
6868

69+
# the call above clobbers LR, but tools may expect LR to be 0xFFFFFFFF when reaching the first
70+
# call frame, so we restore it to its previous value (r4 is preserved by subroutines)
71+
mov lr,r4
72+
6973
# initialize .data and .bss memory
7074
ldr r0,=__sbss
7175
ldr r1,=__ebss

cortex-m-rt/bin/thumbv6m-none-eabi.a

4 Bytes
Binary file not shown.

cortex-m-rt/bin/thumbv7em-none-eabi.a

4 Bytes
Binary file not shown.
4 Bytes
Binary file not shown.

cortex-m-rt/bin/thumbv7m-none-eabi.a

4 Bytes
Binary file not shown.
4 Bytes
Binary file not shown.
4 Bytes
Binary file not shown.
4 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)