From de457014e31d6aaeb947275eb6aec48af195f32a Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 29 Oct 2024 16:33:13 +0000 Subject: [PATCH 1/2] arch: arm: cortex_m: move _main in input list Move the _main argument to the input list rather than the output one on the asm block and change the spec to "r". The ASM block does not return, so it does not make sense for it to expect any output. Signed-off-by: Wilfried Chauveau Signed-off-by: Fabio Baltieri --- arch/arm/core/cortex_m/thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/core/cortex_m/thread.c b/arch/arm/core/cortex_m/thread.c index fa500032d3cc0..4cadc4e72bf5d 100644 --- a/arch/arm/core/cortex_m/thread.c +++ b/arch/arm/core/cortex_m/thread.c @@ -586,8 +586,8 @@ void arch_switch_to_main_thread(struct k_thread *main_thread, char *stack_ptr, "mov r3, #0\n" "ldr r4, =z_thread_entry\n" "bx r4\n" /* We don’t intend to return, so there is no need to link. */ - : "+r" (_main) - : "r" (stack_ptr) + : + : "r" (_main), "r" (stack_ptr) : "r0", "r1", "r2", "r3", "r4", "ip", "lr"); CODE_UNREACHABLE; From 4f0b9c7b29486928e5370ebca0e1a1e64a6c578d Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 29 Oct 2024 16:35:08 +0000 Subject: [PATCH 2/2] arch: arm: cortex_m: add memory to the clobber list Add "memory" to the clobber list" From GCC 14 the compiler optimizes away memory accesses that do not impact the asm block. Adding the memory to the clobber list lets the compiler know that the memory state is to be preserved. Signed-off-by: Wilfried Chauveau Signed-off-by: Fabio Baltieri --- arch/arm/core/cortex_m/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/core/cortex_m/thread.c b/arch/arm/core/cortex_m/thread.c index 4cadc4e72bf5d..6cd7144e79d17 100644 --- a/arch/arm/core/cortex_m/thread.c +++ b/arch/arm/core/cortex_m/thread.c @@ -588,7 +588,7 @@ void arch_switch_to_main_thread(struct k_thread *main_thread, char *stack_ptr, "bx r4\n" /* We don’t intend to return, so there is no need to link. */ : : "r" (_main), "r" (stack_ptr) - : "r0", "r1", "r2", "r3", "r4", "ip", "lr"); + : "r0", "r1", "r2", "r3", "r4", "ip", "lr", "memory"); CODE_UNREACHABLE; }