From 2c24e5b430cf67e3fb6e28bbc3b8911d0fd2c7b0 Mon Sep 17 00:00:00 2001 From: wanggang26 Date: Mon, 29 Jul 2024 13:45:26 +0800 Subject: [PATCH] arch/arm-m: Clear lr before jump to __start to fix issue about https://github.com/apache/nuttx/issues/12687 Signed-off-by: wanggang26 --- arch/arm/src/armv6-m/arm_vectors.c | 18 ++++++++++++++++-- arch/arm/src/armv7-m/arm_vectors.c | 16 ++++++++++++++-- arch/arm/src/armv8-m/arm_vectors.c | 16 ++++++++++++++-- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/arch/arm/src/armv6-m/arm_vectors.c b/arch/arm/src/armv6-m/arm_vectors.c index eb4f27ebbd..8beb9443c1 100644 --- a/arch/arm/src/armv6-m/arm_vectors.c +++ b/arch/arm/src/armv6-m/arm_vectors.c @@ -57,13 +57,27 @@ #endif /**************************************************************************** - * Public Functions + * Private Functions ****************************************************************************/ /* Chip-specific entrypoint */ extern void __start(void); +static void start(void) +{ + /* Zero lr to mark the end of backtrace */ + + asm volatile ("mov lr, %0\n\t" + "bx %1\n\t" + : + : "r"(0), "r"(__start)); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + /* Common exception entrypoint */ extern void exception_common(void); @@ -89,7 +103,7 @@ const void * const _vectors[] locate_data(".vectors") = /* Reset exception handler */ - __start, + start, /* Vectors 2 - n point directly at the generic handler */ diff --git a/arch/arm/src/armv7-m/arm_vectors.c b/arch/arm/src/armv7-m/arm_vectors.c index b5459ebd1d..c4674ab20f 100644 --- a/arch/arm/src/armv7-m/arm_vectors.c +++ b/arch/arm/src/armv7-m/arm_vectors.c @@ -49,13 +49,25 @@ #define IDLE_STACK (_ebss + CONFIG_IDLETHREAD_STACKSIZE) /**************************************************************************** - * Public Functions + * Private Functions ****************************************************************************/ /* Chip-specific entrypoint */ extern void __start(void); +static void start(void) +{ + /* Zero lr to mark the end of backtrace */ + + asm volatile ("mov lr, #0\n\t" + "b __start\n\t"); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + /* Common exception entrypoint */ extern void exception_common(void); @@ -82,7 +94,7 @@ const void * const _vectors[] locate_data(".vectors") /* Reset exception handler */ - __start, + start, /* Vectors 2 - n point directly at the generic handler */ diff --git a/arch/arm/src/armv8-m/arm_vectors.c b/arch/arm/src/armv8-m/arm_vectors.c index 7427b23a43..75308996e1 100644 --- a/arch/arm/src/armv8-m/arm_vectors.c +++ b/arch/arm/src/armv8-m/arm_vectors.c @@ -52,13 +52,25 @@ #endif /**************************************************************************** - * Public Functions + * Private Functions ****************************************************************************/ /* Chip-specific entrypoint */ extern void __start(void); +static void start(void) +{ + /* Zero lr to mark the end of backtrace */ + + asm volatile ("mov lr, #0\n\t" + "b __start\n\t"); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + /* Common exception entrypoint */ extern void exception_common(void); @@ -84,7 +96,7 @@ const void * const _vectors[] locate_data(".vectors") = /* Reset exception handler */ - __start, + start, /* Vectors 2 - n point directly at the generic handler */