[PATCH] linker set: Allow adding any variable into content
Christian Mauderer
christian.mauderer at embedded-brains.de
Mon Aug 1 10:53:20 UTC 2016
From: Christian Mauderer <Christian.Mauderer at embedded-brains.de>
The newly created macro allows to add any kind of variable into the
content of a linker set. This allows (for example) saving an execution
state of a function using the following method:
- put a group of different variables into one linker set
- save the memory area containing the group of variables before the
execution of a function
- restore the memory area after the function has been executed
---
cpukit/score/include/rtems/linkersets.h | 8 ++++++++
testsuites/sptests/splinkersets01/init.c | 22 ++++++++++++++++++++++
testsuites/sptests/splinkersets01/items.c | 8 ++++++++
testsuites/sptests/splinkersets01/sets.c | 4 ++++
testsuites/sptests/splinkersets01/splinkersets01.h | 12 ++++++++++++
5 files changed, 54 insertions(+)
diff --git a/cpukit/score/include/rtems/linkersets.h b/cpukit/score/include/rtems/linkersets.h
index e40be66..5ab8a75 100644
--- a/cpukit/score/include/rtems/linkersets.h
+++ b/cpukit/score/include/rtems/linkersets.h
@@ -57,6 +57,10 @@ extern "C" {
type volatile const _Linker_set_##set##_##item \
RTEMS_SECTION( ".rtemsroset." #set ".content.1" ) RTEMS_USED
+#define RTEMS_LINKER_ROSET_CONTENT( set, decl ) \
+ decl \
+ RTEMS_SECTION( ".rtemsroset." #set ".content.2" )
+
#define RTEMS_LINKER_RWSET_DECLARE( set, type ) \
extern type volatile RTEMS_LINKER_SET_BEGIN( set )[0]; \
extern type volatile RTEMS_LINKER_SET_END( set )[0]
@@ -89,6 +93,10 @@ extern "C" {
type volatile _Linker_set_##set##_##item \
RTEMS_SECTION( ".rtemsrwset." #set ".content.1" ) RTEMS_USED
+#define RTEMS_LINKER_RWSET_CONTENT( set, decl ) \
+ decl \
+ RTEMS_SECTION( ".rtemsrwset." #set ".content.2" )
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/testsuites/sptests/splinkersets01/init.c b/testsuites/sptests/splinkersets01/init.c
index 3d35a4e..b1f233d 100644
--- a/testsuites/sptests/splinkersets01/init.c
+++ b/testsuites/sptests/splinkersets01/init.c
@@ -130,11 +130,33 @@ static void test(void)
rtems_test_assert(&s2 == sb[2]);
}
+static void test_content(void)
+{
+ char volatile *b_rw = RTEMS_LINKER_SET_BEGIN(test_content_rw);
+ char volatile *e_rw = RTEMS_LINKER_SET_END(test_content_rw);
+
+ char volatile const *b_ro = RTEMS_LINKER_SET_BEGIN(test_content_ro);
+ char volatile const *e_ro = RTEMS_LINKER_SET_END(test_content_ro);
+
+ rtems_test_assert(&content_rw_1 == (void *)b_rw);
+ rtems_test_assert(&content_rw_2 == b_rw + sizeof(content_rw_1));
+ rtems_test_assert(&content_rw_3 == b_rw + sizeof(content_rw_1) +
+ sizeof(content_rw_2));
+ rtems_test_assert(&content_rw_3 <= e_rw);
+
+ rtems_test_assert(&content_ro_1 == (void *)b_ro);
+ rtems_test_assert(&content_ro_2 == b_ro + sizeof(content_ro_1));
+ rtems_test_assert(&content_ro_3 == b_ro + sizeof(content_ro_1) +
+ sizeof(content_ro_2));
+ rtems_test_assert(&content_ro_3 <= e_ro);
+}
+
static void Init(rtems_task_argument arg)
{
TEST_BEGIN();
test();
+ test_content();
TEST_END();
rtems_test_exit(0);
diff --git a/testsuites/sptests/splinkersets01/items.c b/testsuites/sptests/splinkersets01/items.c
index 7ca6f53..fde102a 100644
--- a/testsuites/sptests/splinkersets01/items.c
+++ b/testsuites/sptests/splinkersets01/items.c
@@ -21,3 +21,11 @@
RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw, const int *, a1, 1) = &a[1];
RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro, const int *, ca2, OC) = &ca[2];
+
+int content_rw_1;
+char content_rw_2;
+char content_rw_3;
+
+const int content_ro_1;
+const char content_ro_2;
+const char content_ro_3;
diff --git a/testsuites/sptests/splinkersets01/sets.c b/testsuites/sptests/splinkersets01/sets.c
index 0cc1993..1061379 100644
--- a/testsuites/sptests/splinkersets01/sets.c
+++ b/testsuites/sptests/splinkersets01/sets.c
@@ -21,3 +21,7 @@
RTEMS_LINKER_RWSET(test_rw, const int *);
RTEMS_LINKER_ROSET(test_ro, const int *);
+
+RTEMS_LINKER_RWSET(test_content_rw, char);
+
+RTEMS_LINKER_ROSET(test_content_ro, char);
diff --git a/testsuites/sptests/splinkersets01/splinkersets01.h b/testsuites/sptests/splinkersets01/splinkersets01.h
index 5da8ec6..0339154 100644
--- a/testsuites/sptests/splinkersets01/splinkersets01.h
+++ b/testsuites/sptests/splinkersets01/splinkersets01.h
@@ -29,10 +29,22 @@ RTEMS_LINKER_RWSET_DECLARE(test_rw, const int *);
RTEMS_LINKER_ROSET_DECLARE(test_ro, const int *);
+RTEMS_LINKER_RWSET_DECLARE(test_content_rw, char);
+
+RTEMS_LINKER_ROSET_DECLARE(test_content_ro, char);
+
RTEMS_LINKER_RWSET_ITEM_DECLARE(test_rw, const int *, a1);
RTEMS_LINKER_ROSET_ITEM_DECLARE(test_ro, const int *, ca2);
+RTEMS_LINKER_RWSET_CONTENT(test_content_rw, extern int content_rw_1);
+RTEMS_LINKER_RWSET_CONTENT(test_content_rw, extern char content_rw_2);
+RTEMS_LINKER_RWSET_CONTENT(test_content_rw, extern char content_rw_3);
+
+RTEMS_LINKER_ROSET_CONTENT(test_content_ro, extern const int content_ro_1);
+RTEMS_LINKER_ROSET_CONTENT(test_content_ro, extern const char content_ro_2);
+RTEMS_LINKER_ROSET_CONTENT(test_content_ro, extern const char content_ro_3);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
--
2.9.2
More information about the devel
mailing list