Skip to content

Commit 3960e2d

Browse files
committed
RTX - fix ARMv6 in premain (restore lr) and bx to main
1 parent 61552db commit 3960e2d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libraries/rtos/rtx/TARGET_CORTEX_M/RTX_CM_lib.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,18 @@ __attribute__((naked)) void pre_main (void) {
560560
".syntax unified\n"
561561
".thumb\n"
562562
/* Save link register (keep 8 byte alignment with dummy r4) */
563-
"push {r4, lr}\n"
563+
"push {r4, r5}\n"
564+
"mov r4, lr\n"
564565
"ldr r0,= __libc_fini_array\n"
565566
"bl atexit\n"
566567
"bl __libc_init_array\n"
567568
/* Restore link register and branch so when main returns it
568569
* goes to the thread destroy function.
569570
*/
570-
"pop {r4, lr}\n"
571-
"b main\n"
571+
"mov lr, r4\n"
572+
"pop {r4, r5}\n"
573+
"ldr r0,=main\n"
574+
"bx r0\n"
572575
);
573576
}
574577

0 commit comments

Comments
 (0)