[rtems commit] score: Macros to declare and define global symbols

Sebastian Huber sebh at rtems.org
Fri Jun 22 04:31:14 UTC 2018


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Jun 15 16:53:27 2018 +0200

score: Macros to declare and define global symbols

Add RTEMS_DEFINE_GLOBAL_SYMBOL() and add RTEMS_DECLARE_GLOBAL_SYMBOL().

Update #3459.

---

 cpukit/include/rtems/score/basedefs.h    | 34 +++++++++++++++++++++-
 testsuites/sptests/Makefile.am           |  9 ++++++
 testsuites/sptests/configure.ac          |  1 +
 testsuites/sptests/spmisc01/init.c       | 49 ++++++++++++++++++++++++++++++++
 testsuites/sptests/spmisc01/spmisc01.doc | 13 +++++++++
 testsuites/sptests/spmisc01/spmisc01.scn |  2 ++
 6 files changed, 107 insertions(+), 1 deletion(-)

diff --git a/cpukit/include/rtems/score/basedefs.h b/cpukit/include/rtems/score/basedefs.h
index 4e48d22..8169f6d 100644
--- a/cpukit/include/rtems/score/basedefs.h
+++ b/cpukit/include/rtems/score/basedefs.h
@@ -10,7 +10,7 @@
  *  COPYRIGHT (c) 1989-2007.
  *  On-Line Applications Research Corporation (OAR).
  *
- *  Copyright (c) 2010, 2017 embedded brains GmbH.
+ *  Copyright (c) 2010, 2018 embedded brains GmbH.
  *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
@@ -249,6 +249,38 @@
   #define RTEMS_OBFUSCATE_VARIABLE( _var ) (void) (_var)
 #endif
 
+/**
+ * @brief Declares a global symbol with the specified name.
+ *
+ * This macro must be placed at file scope.
+ *
+ * The name must be a valid designator.
+ */
+#define RTEMS_DECLARE_GLOBAL_SYMBOL( _name ) \
+  extern char _name[];
+
+/**
+ * @brief Defines a global symbol with the specified name and value.
+ *
+ * This macro must be placed at file scope.
+ *
+ * The name must be a valid designator.
+ *
+ * On the value parameters macro expansion is performed and afterwards it is
+ * stringified.  It must expand to an integer literal understood by the
+ * assembler.
+ */
+#if defined(__GNUC__)
+  #define RTEMS_DEFINE_GLOBAL_SYMBOL( _name, _value ) \
+    __asm__( \
+      "\t.globl " RTEMS_XSTRING( __USER_LABEL_PREFIX__ ) #_name \
+      "\n\t.set " RTEMS_XSTRING( __USER_LABEL_PREFIX__ ) #_name \
+      ", " RTEMS_STRING( _value ) "\n" \
+    )
+#else
+  #define RTEMS_DEFINE_GLOBAL_SYMBOL( _name, _value )
+#endif
+
 #if __cplusplus >= 201103L
   #define RTEMS_STATIC_ASSERT(cond, msg) \
     static_assert(cond, # msg)
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index 8519702..d3a2e10 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -1493,6 +1493,15 @@ spmkdir_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spmkdir) \
 	$(support_includes)
 endif
 
+if TEST_spmisc01
+sp_tests += spmisc01
+sp_screens += spmisc01/spmisc01.scn
+sp_docs += spmisc01/spmisc01.doc
+spmisc01_SOURCES = spmisc01/init.c
+spmisc01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spmisc01) \
+	$(support_includes)
+endif
+
 if TEST_spmountmgr01
 sp_tests += spmountmgr01
 sp_screens += spmountmgr01/spmountmgr01.scn
diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac
index db213b9..ffbd733 100644
--- a/testsuites/sptests/configure.ac
+++ b/testsuites/sptests/configure.ac
@@ -194,6 +194,7 @@ RTEMS_TEST_CHECK([spintrcritical23])
 RTEMS_TEST_CHECK([spintrcritical24])
 RTEMS_TEST_CHECK([splinkersets01])
 RTEMS_TEST_CHECK([spmkdir])
+RTEMS_TEST_CHECK([spmisc01])
 RTEMS_TEST_CHECK([spmountmgr01])
 RTEMS_TEST_CHECK([spmrsp01])
 RTEMS_TEST_CHECK([spmsgq_err01])
diff --git a/testsuites/sptests/spmisc01/init.c b/testsuites/sptests/spmisc01/init.c
new file mode 100644
index 0000000..4ff6365
--- /dev/null
+++ b/testsuites/sptests/spmisc01/init.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  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.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+#include <tmacros.h>
+
+const char rtems_test_name[] = "SPMISC 1";
+
+RTEMS_DECLARE_GLOBAL_SYMBOL(a_global_symbol);
+
+RTEMS_DEFINE_GLOBAL_SYMBOL(a_global_symbol, 0xabc);
+
+static void Init(rtems_task_argument arg)
+{
+  TEST_BEGIN();
+  rtems_test_assert((uintptr_t)a_global_symbol == 0xabc);
+  TEST_END();
+  rtems_test_exit(0);
+}
+
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/sptests/spmisc01/spmisc01.doc b/testsuites/sptests/spmisc01/spmisc01.doc
new file mode 100644
index 0000000..2654788
--- /dev/null
+++ b/testsuites/sptests/spmisc01/spmisc01.doc
@@ -0,0 +1,13 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: spbasedefs01
+
+directives:
+
+  - RTEMS_DECLARE_GLOBAL_SYMBOL()
+  - RTEMS_DEFINE_GLOBAL_SYMBOL()
+
+concepts:
+
+  - Ensure that RTEMS_* defines and macros defined by <rtems/score/basedefs.h>
+    available via <rtems.h> work as expected.
diff --git a/testsuites/sptests/spmisc01/spmisc01.scn b/testsuites/sptests/spmisc01/spmisc01.scn
new file mode 100644
index 0000000..6e692da
--- /dev/null
+++ b/testsuites/sptests/spmisc01/spmisc01.scn
@@ -0,0 +1,2 @@
+*** BEGIN OF TEST SPMISC 1 ***
+*** END OF TEST SPMISC 1 ***




More information about the vc mailing list