[rtems commit] score: Clarify CPU port alignment requirements

Sebastian Huber sebh at rtems.org
Mon Apr 7 14:42:12 UTC 2014


Module:    rtems
Branch:    master
Commit:    57740ce8a1e2370f7fc29c8bcf634e480f920e2b
Changeset: http://git.rtems.org/rtems/commit/?id=57740ce8a1e2370f7fc29c8bcf634e480f920e2b

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Apr  7 14:50:24 2014 +0200

score: Clarify CPU port alignment requirements

---

 cpukit/score/cpu/no_cpu/rtems/score/cpu.h |   16 +++++++-----
 cpukit/score/src/percpuasm.c              |   35 +++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/cpukit/score/cpu/no_cpu/rtems/score/cpu.h b/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
index 0b6c4da..c864164 100644
--- a/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
+++ b/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
@@ -733,7 +733,10 @@ SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
 
 /**
  * CPU's worst alignment requirement for data types on a byte boundary.  This
- * alignment does not take into account the requirements for the stack.
+ * alignment does not take into account the requirements for the stack.  It
+ * must be a power of two greater than or equal to two.  The power of two
+ * requirement makes it possible to align values easily using simple bit
+ * operations.
  *
  * Port Specific Information:
  *
@@ -749,12 +752,11 @@ SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
  * @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is strict enough for
  * the heap, then this should be set to @ref CPU_ALIGNMENT.
  *
- * NOTE:  This does not have to be a power of 2 although it should be
- *        a multiple of 2 greater than or equal to 2.  The requirement
- *        to be a multiple of 2 is because the heap uses the least
- *        significant field of the front and back flags to indicate
- *        that a block is in use or free.  So you do not want any odd
- *        length blocks really putting length data in that bit.
+ * NOTE:  It must be a power of two greater than or equal to two.  The
+ *        requirement to be a multiple of two is because the heap uses the
+ *        least significant field of the front and back flags to indicate that
+ *        a block is in use or free.  So you do not want any odd length blocks
+ *        really putting length data in that bit.
  *
  *        On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
  *        have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
diff --git a/cpukit/score/src/percpuasm.c b/cpukit/score/src/percpuasm.c
index d6bf756..d422a0d 100644
--- a/cpukit/score/src/percpuasm.c
+++ b/cpukit/score/src/percpuasm.c
@@ -1,8 +1,8 @@
 /*
- * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2012-2014 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
- *  Obere Lagerstr. 30
+ *  Dornierstr. 4
  *  82178 Puchheim
  *  Germany
  *  <rtems at embedded-brains.de>
@@ -21,6 +21,37 @@
 #define _RTEMS_PERCPU_DEFINE_OFFSETS
 #include <rtems/score/percpu.h>
 
+/*
+ * 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.
+ */
+RTEMS_STATIC_ASSERT(
+  CPU_ALIGNMENT == 2
+    || CPU_ALIGNMENT == 4
+    || CPU_ALIGNMENT == 8
+    || CPU_ALIGNMENT == 16
+    || CPU_ALIGNMENT == 32,
+  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_0
+);
+
+RTEMS_STATIC_ASSERT(
+  CPU_HEAP_ALIGNMENT >= CPU_ALIGNMENT,
+  CPU_HEAP_ALIGNMENT_1
+);
+
 RTEMS_STATIC_ASSERT(
   sizeof(void *) == CPU_SIZEOF_POINTER,
   CPU_SIZEOF_POINTER




More information about the vc mailing list