This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a14f119ab0066a717c0c8fa0ca8cf7b8c41fddd4
Author: hujun5 <[email protected]>
AuthorDate: Wed Feb 4 16:08:56 2026 +0800

    arch: consolidate stack alignment macros into common irq.h
    
    Remove duplicate stack alignment macros (SMP_STACK_MASK, 
SMP_STACK_ALIGNMENT,
    STACK_ISALIGNED) from arch-specific files in arm, arm64, risc-v and sparc.
    Replace them with the common STACKFRAME_ALIGN_UP, STACKFRAME_ALIGN_DOWN
    and STACKFRAME_ISALIGNED macros defined in include/nuttx/irq.h, and add
    the missing STACK_ISALIGNED and STACKFRAME_ISALIGNED definitions there.
    
    Signed-off-by: hujun5 <[email protected]>
---
 arch/arm/include/irq.h                          | 12 ++++++------
 arch/arm/src/arm_a_r/arm_cpuidlestack.c         |  6 +-----
 arch/arm/src/arm_a_r/smp.h                      |  8 ++++----
 arch/arm64/src/common/arm64_cpuidlestack.c      |  6 +-----
 arch/risc-v/src/common/riscv_common_memorymap.h |  9 ++++++---
 arch/risc-v/src/common/riscv_cpuidlestack.c     |  4 +---
 arch/sparc/src/s698pm/s698pm.h                  |  6 ++----
 arch/sparc/src/s698pm/s698pm_cpuidlestack.c     |  6 +-----
 include/nuttx/irq.h                             |  2 ++
 9 files changed, 24 insertions(+), 35 deletions(-)

diff --git a/arch/arm/include/irq.h b/arch/arm/include/irq.h
index 08f35f7868c..d1accdbee62 100644
--- a/arch/arm/include/irq.h
+++ b/arch/arm/include/irq.h
@@ -77,6 +77,12 @@
 #  define __ARM_FEATURE_DSP 1
 #endif
 
+/* For use with EABI and floating point, the stack must be aligned to 8-byte
+ * addresses.
+ */
+
+#define STACKFRAME_ALIGN 8
+
 #ifndef __ASSEMBLY__
 
 #ifndef up_switch_context
@@ -90,12 +96,6 @@
   } while (0)
 #endif
 
-/* For use with EABI and floating point, the stack must be aligned to 8-byte
- * addresses.
- */
-
-#define STACKFRAME_ALIGN 8
-
 #ifdef __cplusplus
 extern "C"
 {
diff --git a/arch/arm/src/arm_a_r/arm_cpuidlestack.c 
b/arch/arm/src/arm_a_r/arm_cpuidlestack.c
index eb4aa942bf8..bf7fcced895 100644
--- a/arch/arm/src/arm_a_r/arm_cpuidlestack.c
+++ b/arch/arm/src/arm_a_r/arm_cpuidlestack.c
@@ -41,10 +41,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* Stack alignment macros */
-
-#define STACK_ISALIGNED(a) ((uintptr_t)(a) & ~SMP_STACK_MASK)
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -121,7 +117,7 @@ int up_cpu_idlestack(int cpu, struct tcb_s *tcb, size_t 
stack_size)
   /* Get the top of the stack */
 
   stack_alloc          = (uintptr_t)g_cpu_stackalloc[cpu];
-  DEBUGASSERT(stack_alloc != 0 && STACK_ISALIGNED(stack_alloc));
+  DEBUGASSERT(stack_alloc != 0 && STACKFRAME_IS_ALIGNED(stack_alloc));
 
   tcb->adj_stack_size  = SMP_STACK_SIZE;
   tcb->stack_alloc_ptr = (void *)stack_alloc;
diff --git a/arch/arm/src/arm_a_r/smp.h b/arch/arm/src/arm_a_r/smp.h
index c8057b770db..f60f4314cbd 100644
--- a/arch/arm/src/arm_a_r/smp.h
+++ b/arch/arm/src/arm_a_r/smp.h
@@ -29,6 +29,8 @@
 
 #include <nuttx/config.h>
 
+#include <nuttx/irq.h>
+
 #ifdef CONFIG_SMP
 
 /****************************************************************************
@@ -40,10 +42,8 @@
  * always use the EABI stack alignment
  */
 
-#define SMP_STACK_ALIGNMENT  8
-#define SMP_STACK_MASK       7
-#define SMP_STACK_SIZE       ((CONFIG_IDLETHREAD_STACKSIZE + 7) & ~7)
-#define SMP_STACK_WORDS      (SMP_STACK_SIZE >> 2)
+#define SMP_STACK_SIZE  STACKFRAME_ALIGN_UP(CONFIG_IDLETHREAD_STACKSIZE)
+#define SMP_STACK_WORDS (SMP_STACK_SIZE >> 2)
 
 /****************************************************************************
  * Public Data
diff --git a/arch/arm64/src/common/arm64_cpuidlestack.c 
b/arch/arm64/src/common/arm64_cpuidlestack.c
index 01ad53946a4..0bd165dd0da 100644
--- a/arch/arm64/src/common/arm64_cpuidlestack.c
+++ b/arch/arm64/src/common/arm64_cpuidlestack.c
@@ -37,10 +37,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* Stack alignment macros */
-
-#define STACK_ISALIGNED(a) ((uintptr_t)(a) & ~STACK_ALIGN_MASK)
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -103,7 +99,7 @@ int up_cpu_idlestack(int cpu, struct tcb_s *tcb, size_t 
stack_size)
   /* Get the top of the stack */
 
   stack_alloc          = (uintptr_t)g_cpu_idlestackalloc[cpu];
-  DEBUGASSERT(stack_alloc != 0 && STACK_ISALIGNED(stack_alloc));
+  DEBUGASSERT(stack_alloc != 0 && STACKFRAME_IS_ALIGNED(stack_alloc));
 
   tcb->adj_stack_size  = SMP_STACK_SIZE;
   tcb->stack_alloc_ptr = (void *)stack_alloc;
diff --git a/arch/risc-v/src/common/riscv_common_memorymap.h 
b/arch/risc-v/src/common/riscv_common_memorymap.h
index be39f1d25dd..0dcddb6b677 100644
--- a/arch/risc-v/src/common/riscv_common_memorymap.h
+++ b/arch/risc-v/src/common/riscv_common_memorymap.h
@@ -47,9 +47,12 @@
 #define _START_TBSS  _stbss
 #define _END_TBSS    _etbss
 
-#define SMP_STACK_MASK (15)
-#define SMP_STACK_SIZE \
-   ((CONFIG_IDLETHREAD_STACKSIZE + SMP_STACK_MASK) & ~SMP_STACK_MASK)
+/**
+ * SMP_STACK_SIZE: Total per-CPU idle stack size (aligned to 16 bytes),
+ * including both the normal and shadow stacks.
+ */
+
+#define SMP_STACK_SIZE STACKFRAME_ALIGN_UP(CONFIG_IDLETHREAD_STACKSIZE)
 
 /****************************************************************************
  * Public Types
diff --git a/arch/risc-v/src/common/riscv_cpuidlestack.c 
b/arch/risc-v/src/common/riscv_cpuidlestack.c
index 781abe897c7..5d995503440 100644
--- a/arch/risc-v/src/common/riscv_cpuidlestack.c
+++ b/arch/risc-v/src/common/riscv_cpuidlestack.c
@@ -39,8 +39,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define STACK_ISALIGNED(a)   ((uintptr_t)(a) & ~SMP_STACK_MASK)
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -110,7 +108,7 @@ int up_cpu_idlestack(int cpu, struct tcb_s *tcb, size_t 
stack_size)
   /* Get the top of the stack */
 
   stack_alloc = (uintptr_t)g_cpux_idlestack(cpu);
-  DEBUGASSERT(stack_alloc != 0 && STACK_ISALIGNED(stack_alloc));
+  DEBUGASSERT(stack_alloc != 0 && STACKFRAME_IS_ALIGNED(stack_alloc));
 
   tcb->adj_stack_size  = SMP_STACK_SIZE;
   tcb->stack_alloc_ptr = (void *)stack_alloc;
diff --git a/arch/sparc/src/s698pm/s698pm.h b/arch/sparc/src/s698pm/s698pm.h
index b520a92765b..5c67f5472d3 100644
--- a/arch/sparc/src/s698pm/s698pm.h
+++ b/arch/sparc/src/s698pm/s698pm.h
@@ -105,10 +105,8 @@
 #ifdef CONFIG_SMP
 /* SPARC requires at least a 8-byte stack alignment  */
 
-#define SMP_STACK_ALIGNMENT  8
-#define SMP_STACK_MASK       7
-#define SMP_STACK_SIZE       ((CONFIG_IDLETHREAD_STACKSIZE + 7) & ~7)
-#define SMP_STACK_WORDS      (SMP_STACK_SIZE >> 2)
+#define SMP_STACK_SIZE  STACKFRAME_ALIGN_UP(CONFIG_IDLETHREAD_STACKSIZE)
+#define SMP_STACK_WORDS (SMP_STACK_SIZE >> 2)
 
 /****************************************************************************
  * Public Data
diff --git a/arch/sparc/src/s698pm/s698pm_cpuidlestack.c 
b/arch/sparc/src/s698pm/s698pm_cpuidlestack.c
index 0b7297d58e4..ea55b92df15 100644
--- a/arch/sparc/src/s698pm/s698pm_cpuidlestack.c
+++ b/arch/sparc/src/s698pm/s698pm_cpuidlestack.c
@@ -41,10 +41,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* Stack alignment macros */
-
-#define STACK_ISALIGNED(a) ((uintptr_t)(a) & ~SMP_STACK_MASK)
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -121,7 +117,7 @@ int up_cpu_idlestack(int cpu, struct tcb_s *tcb, size_t 
stack_size)
   /* Get the top of the stack */
 
   stack_alloc          = (uintptr_t)g_cpu_stackalloc[cpu];
-  DEBUGASSERT(stack_alloc != 0 && STACK_ISALIGNED(stack_alloc));
+  DEBUGASSERT(stack_alloc != 0 && STACKFRAME_IS_ALIGNED(stack_alloc));
 
   tcb->adj_stack_size  = SMP_STACK_SIZE;
   tcb->stack_alloc_ptr = (void *)stack_alloc;
diff --git a/include/nuttx/irq.h b/include/nuttx/irq.h
index 28495e1f1a8..da5142a4571 100644
--- a/include/nuttx/irq.h
+++ b/include/nuttx/irq.h
@@ -117,10 +117,12 @@
 #define STACK_ALIGN_MASK         (STACK_ALIGNMENT - 1)
 #define STACK_ALIGN_DOWN(a)      ((a) & ~STACK_ALIGN_MASK)
 #define STACK_ALIGN_UP(a)        (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK)
+#define STACK_IS_ALIGNED(a)      (((uintptr_t)(a) & STACK_ALIGN_MASK) == 0)
 
 #define STACKFRAME_ALIGN_MASK    (STACKFRAME_ALIGN - 1)
 #define STACKFRAME_ALIGN_DOWN(a) ((a) & ~STACKFRAME_ALIGN_MASK)
 #define STACKFRAME_ALIGN_UP(a)   (((a) + STACKFRAME_ALIGN_MASK) & 
~STACKFRAME_ALIGN_MASK)
+#define STACKFRAME_IS_ALIGNED(a) (((uintptr_t)(a) & STACKFRAME_ALIGN_MASK) == 
0)
 
 /* Aligned size of the kernel stack */
 

Reply via email to