Skip to content

Commit 0b6a48b

Browse files
committed
arch: arm: protect r0 in z_arch_switch_to_main_thread() inline ASM
Adding r0 to the clobber list in the inline ASM block of z_arch_switch_to_main_thread(). This instructs assembler to not use r0 to store ASM expression operands, e.g. in the subsequent instruction, msr PSR %1. We also do a minor optimization with the clearing of R1 before jumping to main. Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent da5a595 commit 0b6a48b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/arm/core/thread.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -432,23 +432,23 @@ void z_arch_switch_to_main_thread(struct k_thread *main_thread,
432432
"msr PSP, %1\n\t" /* __set_PSP(start_of_main_stack) */
433433
#endif
434434

435+
"movs r1, #0\n\t"
435436
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE) \
436437
|| defined(CONFIG_ARMV7_R)
437438
"cpsie i\n\t" /* __enable_irq() */
438439
#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
439440
"cpsie if\n\t" /* __enable_irq(); __enable_fault_irq() */
440-
"mov r1, #0\n\t"
441441
"msr BASEPRI, r1\n\t" /* __set_BASEPRI(0) */
442442
#else
443443
#error Unknown ARM architecture
444444
#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */
445445
"isb\n\t"
446-
"movs r1, #0\n\t"
447446
"movs r2, #0\n\t"
448447
"movs r3, #0\n\t"
449448
"bl z_thread_entry\n\t" /* z_thread_entry(_main, 0, 0, 0); */
450449
:
451450
: "r" (_main), "r" (start_of_main_stack)
451+
: "r0" /* not to be overwritten by msr PSP, %1 */
452452
);
453453

454454
CODE_UNREACHABLE;

0 commit comments

Comments
 (0)