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
This commit is contained in:
Aidan MacDonald 2026-01-12 12:35:56 +00:00
parent af4ff3e270
commit e29780fe09

View file

@ -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