firmware: fix thread_exit handling on ARM Cortex-M
rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
| Newsgroups | gmane.comp.systems.archos.rockbox.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit e29780fe0901bb97bdb3a19339940d81a108366b Author: Aidan MacDonald <[email protected]> Date: Mon Jan 12 12:35:56 2026 +0000 firmware: fix thread_exit handling on ARM Cortex-M The "mov lr, pc" instruction doesn't link a proper return address in Thumb mode: bit 0 will be unset, leading to a UsageFault exception when returning from the thread's main function. Cortex-M has the "blx" instruction to automatically branch and link the correct return address, so use that. Change-Id: I4c0ca55b1b2204286343f906f0b53be0c0ddc392 diff --git a/firmware/asm/arm/thread-micro.c b/firmware/asm/arm/thread-micro.c index 9ad329b55d..95992c39c3 100644 --- a/firmware/asm/arm/thread-micro.c +++ b/firmware/asm/arm/thread-micro.c @@ -34,10 +34,9 @@ static void __attribute__((naked)) USED_ATTR start_thread(void) "ldr r4, [r0, #40] \n" /* start in r4 since it's non-volatile */ "mov r1, #0 \n" /* Mark thread as running */ "str r1, [r0, #40] \n" - "mov lr, pc \n" /* Call thread function */ - "bx r4 \n" + "blx r4 \n" /* Call thread function */ + "b thread_exit \n" ); /* No clobber list - new thread doesn't care */ - thread_exit(); } /* For startup, place context pointer in r4 slot, start_thread pointer in r5 -- rockbox-cvs mailing list [email protected] https://lists.haxx.se/mailman/listinfo/rockbox-cvs