[PATCH 1/4] score: Enforce CPU_STACK_ALIGNMENT requirements

Kinsey Moore kinsey.moore at oarcorp.com
Wed Mar 3 19:53:15 UTC 2021


Looks good.

Kinsey

-----Original Message-----
From: devel <devel-bounces at rtems.org> On Behalf Of Sebastian Huber
Sent: Wednesday, March 3, 2021 02:40
To: devel at rtems.org
Subject: [PATCH 1/4] score: Enforce CPU_STACK_ALIGNMENT requirements

Clarify CPU_STACK_ALIGNMENT requirements in no_cpu port.  Add static
assertion to enforce CPU_STACK_ALIGNMENT requirements.
---
 .../score/cpu/bfin/include/rtems/score/cpu.h  | 13 --------
 .../score/cpu/lm32/include/rtems/score/cpu.h  | 10 -------
 .../score/cpu/m68k/include/rtems/score/cpu.h  |  2 +-
 .../score/cpu/mips/include/rtems/score/cpu.h  |  9 ------
 .../score/cpu/moxie/include/rtems/score/cpu.h | 14 +--------
 .../cpu/no_cpu/include/rtems/score/cpu.h      |  9 +++---
 .../score/cpu/or1k/include/rtems/score/cpu.h  | 12 +-------
 .../cpu/powerpc/include/rtems/score/cpu.h     |  9 ------
 cpukit/score/cpu/sh/include/rtems/score/cpu.h |  9 ------
 .../cpu/sparc64/include/rtems/score/cpu.h     |  7 -----
 .../score/cpu/v850/include/rtems/score/cpu.h  | 12 +-------
 cpukit/score/src/percpuasm.c                  | 30 +++++++++----------
 12 files changed, 22 insertions(+), 114 deletions(-)

diff --git a/cpukit/score/cpu/bfin/include/rtems/score/cpu.h b/cpukit/score/cpu/bfin/include/rtems/score/cpu.h
index 44be6d7d54..d17dfbd30a 100644
--- a/cpukit/score/cpu/bfin/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/bfin/include/rtems/score/cpu.h
@@ -292,19 +292,6 @@ typedef struct {
  */
 #define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
 
-/**
- * This number corresponds to the byte alignment requirement for the
- * stack.  This alignment requirement may be stricter than that for the
- * data types alignment specified by @ref CPU_ALIGNMENT.  If the
- * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
- * set to 0.
- *
- * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
- *
- * Port Specific Information:
- *
- * XXX document implementation including references if appropriate
- */
 #define CPU_STACK_ALIGNMENT        8
 
 #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
diff --git a/cpukit/score/cpu/lm32/include/rtems/score/cpu.h b/cpukit/score/cpu/lm32/include/rtems/score/cpu.h
index 7cf6359419..5c890de53e 100644
--- a/cpukit/score/cpu/lm32/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/lm32/include/rtems/score/cpu.h
@@ -401,16 +401,6 @@ extern Context_Control_fp _CPU_Null_fp_context;
  */
 #define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
 
-/**
- * This number corresponds to the byte alignment requirement for the
- * stack.  This alignment requirement may be stricter than that for the
- * data types alignment specified by @ref CPU_ALIGNMENT.
- *
- *
- * Port Specific Information:
- *
- * Stack is software-managed
- */
 #define CPU_STACK_ALIGNMENT        CPU_ALIGNMENT
 
 #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
diff --git a/cpukit/score/cpu/m68k/include/rtems/score/cpu.h b/cpukit/score/cpu/m68k/include/rtems/score/cpu.h
index 5c1df94fc5..de7f8215bb 100644
--- a/cpukit/score/cpu/m68k/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/m68k/include/rtems/score/cpu.h
@@ -338,7 +338,7 @@ extern void*                     _VBR;
  *  from the Workspace.
  */
 
-#define CPU_STACK_ALIGNMENT        0
+#define CPU_STACK_ALIGNMENT              CPU_ALIGNMENT
 
 #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
 
diff --git a/cpukit/score/cpu/mips/include/rtems/score/cpu.h b/cpukit/score/cpu/mips/include/rtems/score/cpu.h
index 04d33f5658..cdb0e64013 100644
--- a/cpukit/score/cpu/mips/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/mips/include/rtems/score/cpu.h
@@ -525,15 +525,6 @@ extern Context_Control_fp _CPU_Null_fp_context;
 
 #define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
 
-/*
- *  This number corresponds to the byte alignment requirement for the
- *  stack.  This alignment requirement may be stricter than that for the
- *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
- *  is strict enough for the stack, then this should be set to 0.
- *
- *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
- */
-
 #define CPU_STACK_ALIGNMENT        CPU_ALIGNMENT
 
 #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
diff --git a/cpukit/score/cpu/moxie/include/rtems/score/cpu.h b/cpukit/score/cpu/moxie/include/rtems/score/cpu.h
index c0a41c9db6..c857734a2e 100644
--- a/cpukit/score/cpu/moxie/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/moxie/include/rtems/score/cpu.h
@@ -247,19 +247,7 @@ typedef struct {
  */
 #define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
 
-/*
- *  This number corresponds to the byte alignment requirement for the
- *  stack.  This alignment requirement may be stricter than that for the
- *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
- *  is strict enough for the stack, then this should be set to 0.
- *
- *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
- *
- *  MOXIE Specific Information:
- *
- *  XXX
- */
-#define CPU_STACK_ALIGNMENT        0
+#define CPU_STACK_ALIGNMENT        CPU_ALIGNMENT
 
 #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
 
diff --git a/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h b/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
index ea69a5b972..c067501502 100644
--- a/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
@@ -592,17 +592,16 @@ extern Context_Control_fp _CPU_Null_fp_context;
 /**
  * This number corresponds to the byte alignment requirement for the
  * stack.  This alignment requirement may be stricter than that for the
- * data types alignment specified by @ref CPU_ALIGNMENT.  If the
- * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
- * set to 0.
+ * data types alignment specified by @ref CPU_ALIGNMENT.
  *
- * NOTE: This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
+ * NOTE: This must be a power of two and greater than or equal to
+ * @ref CPU_HEAP_ALIGNMENT.
  *
  * Port Specific Information:
  *
  * XXX document implementation including references if appropriate
  */
-#define CPU_STACK_ALIGNMENT        0
+#define CPU_STACK_ALIGNMENT        CPU_HEAP_ALIGNMENT
 
 /**
  * The alignment of the interrupt stack in bytes.
diff --git a/cpukit/score/cpu/or1k/include/rtems/score/cpu.h b/cpukit/score/cpu/or1k/include/rtems/score/cpu.h
index c1f94a71af..22acfd590e 100644
--- a/cpukit/score/cpu/or1k/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/or1k/include/rtems/score/cpu.h
@@ -237,17 +237,7 @@ typedef Context_Control CPU_Interrupt_frame;
 
 #define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
 
-/*
- *  This number corresponds to the byte alignment requirement for the
- *  stack.  This alignment requirement may be stricter than that for the
- *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
- *  is strict enough for the stack, then this should be set to 0.
- *
- *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
- *
- */
-
-#define CPU_STACK_ALIGNMENT        0
+#define CPU_STACK_ALIGNMENT        CPU_ALIGNMENT
 
 #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
 
diff --git a/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h b/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
index a40b378b6d..996b6f8e60 100644
--- a/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
@@ -661,15 +661,6 @@ void ppc_set_interrupt_level( uint32_t level );
 
 #define CPU_HEAP_ALIGNMENT         (PPC_ALIGNMENT)
 
-/*
- *  This number corresponds to the byte alignment requirement for the
- *  stack.  This alignment requirement may be stricter than that for the
- *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
- *  is strict enough for the stack, then this should be set to 0.
- *
- *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
- */
-
 #define CPU_STACK_ALIGNMENT        (PPC_STACK_ALIGNMENT)
 
 #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
diff --git a/cpukit/score/cpu/sh/include/rtems/score/cpu.h b/cpukit/score/cpu/sh/include/rtems/score/cpu.h
index 0782021b2f..0df6aa3f83 100644
--- a/cpukit/score/cpu/sh/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sh/include/rtems/score/cpu.h
@@ -358,15 +358,6 @@ void CPU_delay( uint32_t   microseconds );
 
 #define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
 
-/*
- *  This number corresponds to the byte alignment requirement for the
- *  stack.  This alignment requirement may be stricter than that for the
- *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
- *  is strict enough for the stack, then this should be set to 0.
- *
- *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
- */
-
 #define CPU_STACK_ALIGNMENT        CPU_ALIGNMENT
 
 #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
diff --git a/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h b/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h
index 2701298733..e0f56b8e89 100644
--- a/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h
@@ -635,13 +635,6 @@ extern const CPU_Trap_table_entry _CPU_Trap_slot_template;
 #define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
 
 /*
- *  This number corresponds to the byte alignment requirement for the
- *  stack.  This alignment requirement may be stricter than that for the
- *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
- *  is strict enough for the stack, then this should be set to 0.
- *
- *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
- *
  *  The alignment restrictions for the SPARC are not that strict but this
  *  should unsure that the stack is always sufficiently alignment that the
  *  window overflow, underflow, and flush routines can use double word loads
diff --git a/cpukit/score/cpu/v850/include/rtems/score/cpu.h b/cpukit/score/cpu/v850/include/rtems/score/cpu.h
index a648931fb9..1921216e2d 100644
--- a/cpukit/score/cpu/v850/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/v850/include/rtems/score/cpu.h
@@ -255,20 +255,10 @@ typedef struct {
 #define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
 
 /**
- * This number corresponds to the byte alignment requirement for the
- * stack.  This alignment requirement may be stricter than that for the
- * data types alignment specified by @ref CPU_ALIGNMENT.  If the
- * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
- * set to 0.
- *
- * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
- *
- * Port Specific Information:
- *
  * The v850 has enough RAM where alignment to 16 may be desirable depending
  * on the cache properties. But this remains to be demonstrated.
  */
-#define CPU_STACK_ALIGNMENT        4
+#define CPU_STACK_ALIGNMENT        8
 
 #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
 
diff --git a/cpukit/score/src/percpuasm.c b/cpukit/score/src/percpuasm.c
index 9b0ce86c26..8414d3a7b4 100644
--- a/cpukit/score/src/percpuasm.c
+++ b/cpukit/score/src/percpuasm.c
@@ -30,29 +30,21 @@
 #define _RTEMS_PERCPU_DEFINE_OFFSETS
 #include <rtems/score/percpu.h>
 
+#define PER_CPU_IS_POWER_OF_TWO( value ) \
+  ( ( ( ( value ) - 1 ) & ( value ) ) == 0 )
+
 /*
- * In case a CPU port needs another alignment, then add this here and make sure
- * it is a power of two greater than or equal to two.
+ * The minimum alignment of two is due to the Heap Handler which uses the
+ * HEAP_PREV_BLOCK_USED flag to indicate that the previous block is used.
  */
+
 RTEMS_STATIC_ASSERT(
-  CPU_ALIGNMENT == 2
-    || CPU_ALIGNMENT == 4
-    || CPU_ALIGNMENT == 8
-    || CPU_ALIGNMENT == 16
-    || CPU_ALIGNMENT == 32,
+  CPU_ALIGNMENT >= 2 && PER_CPU_IS_POWER_OF_TWO( CPU_ALIGNMENT ),
   CPU_ALIGNMENT
 );
 
-/*
- * In case a CPU port needs another heap alignment, then add this here and make
- * sure it is a power of two greater than or equal to two.
- */
 RTEMS_STATIC_ASSERT(
-  CPU_HEAP_ALIGNMENT == 2
-    || CPU_HEAP_ALIGNMENT == 4
-    || CPU_HEAP_ALIGNMENT == 8
-    || CPU_HEAP_ALIGNMENT == 16
-    || CPU_HEAP_ALIGNMENT == 32,
+  CPU_HEAP_ALIGNMENT >= 2 && PER_CPU_IS_POWER_OF_TWO( CPU_HEAP_ALIGNMENT ),
   CPU_HEAP_ALIGNMENT_0
 );
 
@@ -61,6 +53,12 @@ RTEMS_STATIC_ASSERT(
   CPU_HEAP_ALIGNMENT_1
 );
 
+RTEMS_STATIC_ASSERT(
+  CPU_STACK_ALIGNMENT >= CPU_HEAP_ALIGNMENT &&
+    PER_CPU_IS_POWER_OF_TWO( CPU_STACK_ALIGNMENT ),
+  CPU_STACK_ALIGNMENT
+);
+
 RTEMS_STATIC_ASSERT(
   sizeof(void *) == CPU_SIZEOF_POINTER,
   CPU_SIZEOF_POINTER
-- 
2.26.2

_______________________________________________
devel mailing list
devel at rtems.org
http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list