[PATCH] score: PR1607: Add and use CPU_SIZEOF_POINTER

Joel Sherrill joel.sherrill at OARcorp.com
Sun Nov 4 20:41:59 UTC 2012


I am pretty sure the h8300 pointer size varies by mulitilib variant. I am not at home to run checks.

Sebastian Huber <sebastian.huber at embedded-brains.de> wrote:

>Add and use new CPU port define CPU_SIZEOF_POINTER.  It must be an
>integer literal that can be used by the assembler.  This value will be
>used to calculate offsets of structure members.  These offsets will be
>used in assembler code.
>---
> cpukit/configure.ac                        |    9 ---
> cpukit/score/Makefile.am                   |    1 +
> cpukit/score/cpu/arm/rtems/score/cpu.h     |    3 +
> cpukit/score/cpu/avr/rtems/score/cpu.h     |    2 +
> cpukit/score/cpu/bfin/rtems/score/cpu.h    |    2 +
> cpukit/score/cpu/h8300/rtems/score/cpu.h   |    2 +
> cpukit/score/cpu/i386/rtems/score/cpu.h    |    2 +
> cpukit/score/cpu/lm32/rtems/score/cpu.h    |    2 +
> cpukit/score/cpu/m32c/rtems/score/cpu.h    |    2 +
> cpukit/score/cpu/m32r/rtems/score/cpu.h    |    2 +
> cpukit/score/cpu/m68k/rtems/score/cpu.h    |    2 +
> cpukit/score/cpu/mips/rtems/score/cpu.h    |    2 +
> cpukit/score/cpu/nios2/rtems/score/cpu.h   |    2 +
> cpukit/score/cpu/no_cpu/rtems/score/cpu.h  |    9 +++
> cpukit/score/cpu/powerpc/rtems/score/cpu.h |    2 +
> cpukit/score/cpu/sh/rtems/score/cpu.h      |    2 +
> cpukit/score/cpu/sparc/rtems/score/cpu.h   |    2 +
> cpukit/score/cpu/sparc64/rtems/score/cpu.h |    2 +
> cpukit/score/cpu/v850/rtems/score/cpu.h    |    2 +
> cpukit/score/include/rtems/score/percpu.h  |   23 ++++----
> cpukit/score/src/percpuasm.c               |   84 ++++++++++++++++++++++++++++
> 21 files changed, 139 insertions(+), 20 deletions(-)
> create mode 100644 cpukit/score/src/percpuasm.c
>
>diff --git a/cpukit/configure.ac b/cpukit/configure.ac
>index d0d957d..e3c4dd4 100644
>--- a/cpukit/configure.ac
>+++ b/cpukit/configure.ac
>@@ -154,10 +154,6 @@ rtems_major=`echo _RTEMS_VERSION | sed "s/\..*//"`
> rtems_minor=`echo _RTEMS_VERSION | sed "s/[[0-9]][[0-9]]*\.//;s/\..*//"`
> rtems_revision=`echo _RTEMS_VERSION | sed "s/[[0-9]][[0-9]]*\.//;s/[[0-9]][[0-9]]*\.//;s/\..*//"`
>
>-## This is needed to generate the field offsets of the per CPU
>-## data structure so they can be accessed from assembly code.
>-AC_CHECK_SIZEOF([void *])
>-
> _RTEMS_CPUOPT_INIT
>
> RTEMS_CPUOPT([RTEMS_DEBUG],
>@@ -233,11 +229,6 @@ RTEMS_CPUOPT([__RTEMS_ADA__],
> ## Then we propagate a private copy of the value into cpuopts.h
> ## so it is always available to the RTEMS header files.
>
>-RTEMS_CPUOPT([__RTEMS_SIZEOF_VOID_P__],
>-  [true],
>-  [$ac_cv_sizeof_void_p],
>-  [Size of a void * pointer])
>-
> RTEMS_CPUOPT([__RTEMS_MAJOR__],
>   [true],
>   [$rtems_major],
>diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
>index d259acb..ac82895 100644
>--- a/cpukit/score/Makefile.am
>+++ b/cpukit/score/Makefile.am
>@@ -157,6 +157,7 @@ libscore_a_SOURCES += src/coremutex.c src/coremutexflush.c \
>
> ## CORE_PERCPU_C_FILES
> libscore_a_SOURCES += src/percpu.c
>+libscore_a_SOURCES += src/percpuasm.c
>
> ## CORE_RWLOCK_C_FILES
> if HAS_PTHREADS
>diff --git a/cpukit/score/cpu/arm/rtems/score/cpu.h b/cpukit/score/cpu/arm/rtems/score/cpu.h
>index b12133f0..813295f 100644
>--- a/cpukit/score/cpu/arm/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/arm/rtems/score/cpu.h
>@@ -185,6 +185,9 @@
> #define CPU_STACK_MINIMUM_SIZE (1024 * 4)
>
> /* AAPCS, section 4.1, Fundamental Data Types */
>+#define CPU_SIZEOF_POINTER 4
>+
>+/* AAPCS, section 4.1, Fundamental Data Types */
> #define CPU_ALIGNMENT 8
>
> #define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
>diff --git a/cpukit/score/cpu/avr/rtems/score/cpu.h b/cpukit/score/cpu/avr/rtems/score/cpu.h
>index f085cf4..5436c21 100644
>--- a/cpukit/score/cpu/avr/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/avr/rtems/score/cpu.h
>@@ -527,6 +527,8 @@ SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
>  */
> #define CPU_PRIORITY_MAXIMUM             15
>
>+#define CPU_SIZEOF_POINTER 2
>+
> /*
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/bfin/rtems/score/cpu.h b/cpukit/score/cpu/bfin/rtems/score/cpu.h
>index 479311d..a8cfc17 100644
>--- a/cpukit/score/cpu/bfin/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/bfin/rtems/score/cpu.h
>@@ -615,6 +615,8 @@ SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
>  */
> #define CPU_STACK_MINIMUM_SIZE          (1024*8)
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /**
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/h8300/rtems/score/cpu.h b/cpukit/score/cpu/h8300/rtems/score/cpu.h
>index ea9d443..b191319 100644
>--- a/cpukit/score/cpu/h8300/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/h8300/rtems/score/cpu.h
>@@ -497,6 +497,8 @@ SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
>
> #define CPU_STACK_MINIMUM_SIZE          (1536)
>
>+#define CPU_SIZEOF_POINTER 2
>+
> /*
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/i386/rtems/score/cpu.h b/cpukit/score/cpu/i386/rtems/score/cpu.h
>index a8d23f9..2a48711 100644
>--- a/cpukit/score/cpu/i386/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/i386/rtems/score/cpu.h
>@@ -323,6 +323,8 @@ SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
>
> #define CPU_STACK_MINIMUM_SIZE          4096
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /*
>  *  i386 is pretty tolerant of alignment.  Just put things on 4 byte boundaries.
>  */
>diff --git a/cpukit/score/cpu/lm32/rtems/score/cpu.h b/cpukit/score/cpu/lm32/rtems/score/cpu.h
>index 19f3017..9f0876a 100644
>--- a/cpukit/score/cpu/lm32/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/lm32/rtems/score/cpu.h
>@@ -615,6 +615,8 @@ SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
>  */
> #define CPU_STACK_MINIMUM_SIZE          (1024*4)
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /**
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/m32c/rtems/score/cpu.h b/cpukit/score/cpu/m32c/rtems/score/cpu.h
>index c1d1db8..081e9a1 100644
>--- a/cpukit/score/cpu/m32c/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/m32c/rtems/score/cpu.h
>@@ -575,6 +575,8 @@ typedef struct {
>  */
> #define CPU_STACK_MINIMUM_SIZE          (2048L)
>
>+#define CPU_SIZEOF_POINTER 2
>+
> /**
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/m32r/rtems/score/cpu.h b/cpukit/score/cpu/m32r/rtems/score/cpu.h
>index 4e4c01f..02bc928 100644
>--- a/cpukit/score/cpu/m32r/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/m32r/rtems/score/cpu.h
>@@ -622,6 +622,8 @@ SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
>  */
> #define CPU_STACK_MINIMUM_SIZE          (1024)
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /**
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/m68k/rtems/score/cpu.h b/cpukit/score/cpu/m68k/rtems/score/cpu.h
>index 013f1b5..89b0295 100644
>--- a/cpukit/score/cpu/m68k/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/m68k/rtems/score/cpu.h
>@@ -380,6 +380,8 @@ SCORE_EXTERN _CPU_ISR_handler_entry _CPU_ISR_jump_table[256];
>  */
> #define CPU_PRIORITY_MAXIMUM             M68K_CPU_PRIORITY_MAXIMUM
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /*
>  *  m68k is pretty tolerant of alignment.  Just put things on 4 byte boundaries.
>  */
>diff --git a/cpukit/score/cpu/mips/rtems/score/cpu.h b/cpukit/score/cpu/mips/rtems/score/cpu.h
>index d0f7c05..3d6b540 100644
>--- a/cpukit/score/cpu/mips/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/mips/rtems/score/cpu.h
>@@ -655,6 +655,8 @@ extern unsigned int mips_interrupt_number_of_vectors;
>
> #define CPU_STACK_MINIMUM_SIZE          (8 * 1024)
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /*
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/nios2/rtems/score/cpu.h b/cpukit/score/cpu/nios2/rtems/score/cpu.h
>index 0632aa9..4d61c42 100644
>--- a/cpukit/score/cpu/nios2/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/nios2/rtems/score/cpu.h
>@@ -73,6 +73,8 @@ extern "C" {
>
> #define CPU_STACK_MINIMUM_SIZE (4 * 1024)
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /*
>  * Alignment value according to "Nios II Processor Reference" chapter 7
>  * "Application Binary Interface" section "Memory Alignment".
>diff --git a/cpukit/score/cpu/no_cpu/rtems/score/cpu.h b/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
>index 8a00c19..9ab1f26 100644
>--- a/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/no_cpu/rtems/score/cpu.h
>@@ -684,6 +684,15 @@ SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
> #define CPU_STACK_MINIMUM_SIZE          (1024*4)
>
> /**
>+ *  Size of a pointer.
>+ *
>+ *  This must be an integer literal that can be used by the assembler.  This
>+ *  value will be used to calculate offsets of structure members.  These
>+ *  offsets will be used in assembler code.
>+ */
>+#define CPU_SIZEOF_POINTER         4
>+
>+/**
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>  *
>diff --git a/cpukit/score/cpu/powerpc/rtems/score/cpu.h b/cpukit/score/cpu/powerpc/rtems/score/cpu.h
>index 840df7a..a38f9a4 100644
>--- a/cpukit/score/cpu/powerpc/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/powerpc/rtems/score/cpu.h
>@@ -668,6 +668,8 @@ void _BSP_Fatal_error(unsigned int);
>
> #define CPU_STACK_MINIMUM_SIZE          (1024*8)
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /*
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/sh/rtems/score/cpu.h b/cpukit/score/cpu/sh/rtems/score/cpu.h
>index 29319da..789024e 100644
>--- a/cpukit/score/cpu/sh/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/sh/rtems/score/cpu.h
>@@ -456,6 +456,8 @@ SCORE_EXTERN void CPU_delay( uint32_t   microseconds );
>
> #define CPU_STACK_MINIMUM_SIZE          4096
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /*
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/sparc/rtems/score/cpu.h b/cpukit/score/cpu/sparc/rtems/score/cpu.h
>index 06bb26e..d92b63c 100644
>--- a/cpukit/score/cpu/sparc/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/sparc/rtems/score/cpu.h
>@@ -874,6 +874,8 @@ extern const CPU_Trap_table_entry _CPU_Trap_slot_template;
>  */
> #define CPU_STACK_MINIMUM_SIZE  (1024*4)
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /**
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/sparc64/rtems/score/cpu.h b/cpukit/score/cpu/sparc64/rtems/score/cpu.h
>index 0f69c6d..f821e96 100644
>--- a/cpukit/score/cpu/sparc64/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/sparc64/rtems/score/cpu.h
>@@ -696,6 +696,8 @@ extern const CPU_Trap_table_entry _CPU_Trap_slot_template;
>
> #define CPU_STACK_MINIMUM_SIZE  (1024*8)
>
>+#define CPU_SIZEOF_POINTER 8
>+
> /*
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/cpu/v850/rtems/score/cpu.h b/cpukit/score/cpu/v850/rtems/score/cpu.h
>index 875f160..371bc32 100644
>--- a/cpukit/score/cpu/v850/rtems/score/cpu.h
>+++ b/cpukit/score/cpu/v850/rtems/score/cpu.h
>@@ -581,6 +581,8 @@ typedef struct {
>  */
> #define CPU_STACK_MINIMUM_SIZE          (1024*4)
>
>+#define CPU_SIZEOF_POINTER 4
>+
> /**
>  *  CPU's worst alignment requirement for data types on a byte boundary.  This
>  *  alignment does not take into account the requirements for the stack.
>diff --git a/cpukit/score/include/rtems/score/percpu.h b/cpukit/score/include/rtems/score/percpu.h
>index 50dd2e6..ed08f8a 100644
>--- a/cpukit/score/include/rtems/score/percpu.h
>+++ b/cpukit/score/include/rtems/score/percpu.h
>@@ -150,12 +150,13 @@ typedef struct {
> } Per_CPU_Control;
> #endif
>
>-#ifdef ASM
>+#if defined(ASM) || defined(_RTEMS_PERCPU_DEFINE_OFFSETS)
>+
> #if defined(RTEMS_SMP)
>   #define PER_CPU_LOCK     0
>-  #define PER_CPU_STATE    (1 * __RTEMS_SIZEOF_VOID_P__)
>-  #define PER_CPU_MESSAGE  (2 * __RTEMS_SIZEOF_VOID_P__)
>-  #define PER_CPU_END_SMP  (3 * __RTEMS_SIZEOF_VOID_P__)
>+  #define PER_CPU_STATE    (1 * CPU_SIZEOF_POINTER)
>+  #define PER_CPU_MESSAGE  (2 * CPU_SIZEOF_POINTER)
>+  #define PER_CPU_END_SMP  (3 * CPU_SIZEOF_POINTER)
> #else
>   #define PER_CPU_END_SMP  0
> #endif
>@@ -168,9 +169,9 @@ typedef struct {
>    */
>   #define PER_CPU_INTERRUPT_STACK_LOW   PER_CPU_END_SMP
>   #define PER_CPU_INTERRUPT_STACK_HIGH  \
>-          PER_CPU_INTERRUPT_STACK_LOW + (1 * __RTEMS_SIZEOF_VOID_P__)
>+          PER_CPU_INTERRUPT_STACK_LOW + (1 * CPU_SIZEOF_POINTER)
>   #define PER_CPU_END_STACK             \
>-          PER_CPU_INTERRUPT_STACK_HIGH + (1 * __RTEMS_SIZEOF_VOID_P__)
>+          PER_CPU_INTERRUPT_STACK_HIGH + (1 * CPU_SIZEOF_POINTER)
> #else
>   #define PER_CPU_END_STACK             PER_CPU_END_SMP
> #endif
>@@ -181,13 +182,13 @@ typedef struct {
> #define PER_CPU_ISR_NEST_LEVEL \
>           PER_CPU_END_STACK + 0
> #define PER_CPU_EXECUTING \
>-          PER_CPU_END_STACK + (1 * __RTEMS_SIZEOF_VOID_P__)
>+          PER_CPU_END_STACK + (1 * CPU_SIZEOF_POINTER)
> #define PER_CPU_HEIR \
>-          PER_CPU_END_STACK + (2 * __RTEMS_SIZEOF_VOID_P__)
>+          PER_CPU_END_STACK + (2 * CPU_SIZEOF_POINTER)
> #define PER_CPU_IDLE \
>-          PER_CPU_END_STACK + (3 * __RTEMS_SIZEOF_VOID_P__)
>+          PER_CPU_END_STACK + (3 * CPU_SIZEOF_POINTER)
> #define PER_CPU_DISPATCH_NEEDED \
>-         PER_CPU_END_STACK + (4 * __RTEMS_SIZEOF_VOID_P__)
>+         PER_CPU_END_STACK + (4 * CPU_SIZEOF_POINTER)
>
> #define ISR_NEST_LEVEL \
>          (SYM(_Per_CPU_Information) + PER_CPU_ISR_NEST_LEVEL)
>@@ -205,7 +206,7 @@ typedef struct {
>       (SYM(_Per_CPU_Information) + PER_CPU_INTERRUPT_STACK_HIGH)
> #endif
>
>-#endif
>+#endif /* defined(ASM) || defined(_RTEMS_PERCPU_DEFINE_OFFSETS) */
>
> #ifndef ASM
>
>diff --git a/cpukit/score/src/percpuasm.c b/cpukit/score/src/percpuasm.c
>new file mode 100644
>index 0000000..336921d
>--- /dev/null
>+++ b/cpukit/score/src/percpuasm.c
>@@ -0,0 +1,84 @@
>+/*
>+ * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
>+ *
>+ *  embedded brains GmbH
>+ *  Obere Lagerstr. 30
>+ *  82178 Puchheim
>+ *  Germany
>+ *  <rtems at embedded-brains.de>
>+ *
>+ * The license and distribution terms for this file may be
>+ * found in the file LICENSE in this distribution or at
>+ * http://www.rtems.com/license/LICENSE.
>+ */
>+
>+#if HAVE_CONFIG_H
>+  #include "config.h"
>+#endif
>+
>+#include <rtems/score/cpu.h>
>+
>+#define _RTEMS_PERCPU_DEFINE_OFFSETS
>+#include <rtems/score/percpu.h>
>+
>+RTEMS_STATIC_ASSERT(
>+  sizeof(void *) == CPU_SIZEOF_POINTER,
>+  CPU_SIZEOF_POINTER
>+);
>+
>+RTEMS_STATIC_ASSERT(
>+  offsetof(Per_CPU_Control, isr_nest_level) == PER_CPU_ISR_NEST_LEVEL,
>+  PER_CPU_ISR_NEST_LEVEL
>+);
>+
>+RTEMS_STATIC_ASSERT(
>+  offsetof(Per_CPU_Control, executing) == PER_CPU_EXECUTING,
>+  PER_CPU_EXECUTING
>+);
>+
>+RTEMS_STATIC_ASSERT(
>+  offsetof(Per_CPU_Control, heir) == PER_CPU_HEIR,
>+  PER_CPU_HEIR
>+);
>+
>+RTEMS_STATIC_ASSERT(
>+  offsetof(Per_CPU_Control, idle) == PER_CPU_IDLE,
>+  PER_CPU_IDLE
>+);
>+
>+RTEMS_STATIC_ASSERT(
>+  offsetof(Per_CPU_Control, dispatch_necessary) == PER_CPU_DISPATCH_NEEDED,
>+  PER_CPU_DISPATCH_NEEDED
>+);
>+
>+#if CPU_ALLOCATE_INTERRUPT_STACK == TRUE \
>+  || CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE
>+  RTEMS_STATIC_ASSERT(
>+    offsetof(Per_CPU_Control, interrupt_stack_low)
>+      == PER_CPU_INTERRUPT_STACK_LOW,
>+    PER_CPU_INTERRUPT_STACK_LOW
>+  );
>+
>+  RTEMS_STATIC_ASSERT(
>+    offsetof(Per_CPU_Control, interrupt_stack_high)
>+      == PER_CPU_INTERRUPT_STACK_HIGH,
>+    PER_CPU_INTERRUPT_STACK_HIGH
>+  );
>+#endif
>+
>+#ifdef RTEMS_SMP
>+  RTEMS_STATIC_ASSERT(
>+    offsetof(Per_CPU_Control, lock) == PER_CPU_LOCK,
>+    PER_CPU_LOCK
>+  );
>+
>+  RTEMS_STATIC_ASSERT(
>+    offsetof(Per_CPU_Control, state) == PER_CPU_STATE,
>+    PER_CPU_STATE
>+  );
>+
>+  RTEMS_STATIC_ASSERT(
>+    offsetof(Per_CPU_Control, message) == PER_CPU_MESSAGE,
>+    PER_CPU_MESSAGE
>+  );
>+#endif
>--
>1.7.10.4
>
>_______________________________________________
>rtems-devel mailing list
>rtems-devel at rtems.org
>http://www.rtems.org/mailman/listinfo/rtems-devel




More information about the devel mailing list