1 | /* |
---|
2 | * Copyright (c) 2015, 2016 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifndef _RTEMS_LINKERSET_H |
---|
16 | #define _RTEMS_LINKERSET_H |
---|
17 | |
---|
18 | #include <rtems/score/basedefs.h> |
---|
19 | |
---|
20 | #ifdef __cplusplus |
---|
21 | extern "C" { |
---|
22 | #endif /* __cplusplus */ |
---|
23 | |
---|
24 | #define RTEMS_LINKER_SET_BEGIN( set ) \ |
---|
25 | _Linker_set_##set##_begin |
---|
26 | |
---|
27 | #define RTEMS_LINKER_SET_END( set ) \ |
---|
28 | _Linker_set_##set##_end |
---|
29 | |
---|
30 | #define RTEMS_LINKER_ROSET_DECLARE( set, type ) \ |
---|
31 | extern type const RTEMS_LINKER_SET_BEGIN( set )[0]; \ |
---|
32 | extern type const RTEMS_LINKER_SET_END( set )[0] |
---|
33 | |
---|
34 | #define RTEMS_LINKER_ROSET( set, type ) \ |
---|
35 | type const RTEMS_LINKER_SET_BEGIN( set )[0] \ |
---|
36 | RTEMS_SECTION( ".rtemsroset." #set ".begin" ) RTEMS_USED; \ |
---|
37 | type const RTEMS_LINKER_SET_END( set )[0] \ |
---|
38 | RTEMS_SECTION( ".rtemsroset." #set ".end" ) RTEMS_USED |
---|
39 | |
---|
40 | #define RTEMS_LINKER_ROSET_ITEM_DECLARE( set, type, item ) \ |
---|
41 | extern type const _Linker_set_##set##_##item |
---|
42 | |
---|
43 | #define RTEMS_LINKER_ROSET_ITEM_REFERENCE( set, type, item ) \ |
---|
44 | static type const * const _Set_reference_##set##_##item \ |
---|
45 | RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED = \ |
---|
46 | &_Linker_set_##set##_##item |
---|
47 | |
---|
48 | #define RTEMS_LINKER_ROSET_ITEM_ORDERED( set, type, item, order ) \ |
---|
49 | type const _Linker_set_##set##_##item \ |
---|
50 | RTEMS_SECTION( ".rtemsroset." #set ".content.0." RTEMS_XSTRING( order ) ) \ |
---|
51 | RTEMS_USED |
---|
52 | |
---|
53 | #define RTEMS_LINKER_ROSET_ITEM( set, type, item ) \ |
---|
54 | type const _Linker_set_##set##_##item \ |
---|
55 | RTEMS_SECTION( ".rtemsroset." #set ".content.1" ) RTEMS_USED |
---|
56 | |
---|
57 | #define RTEMS_LINKER_ROSET_CONTENT( set, decl ) \ |
---|
58 | decl \ |
---|
59 | RTEMS_SECTION( ".rtemsroset." #set ".content" ) |
---|
60 | |
---|
61 | #define RTEMS_LINKER_RWSET_DECLARE( set, type ) \ |
---|
62 | extern type RTEMS_LINKER_SET_BEGIN( set )[0]; \ |
---|
63 | extern type RTEMS_LINKER_SET_END( set )[0] |
---|
64 | |
---|
65 | #define RTEMS_LINKER_RWSET( set, type ) \ |
---|
66 | type RTEMS_LINKER_SET_BEGIN( set )[0] \ |
---|
67 | RTEMS_SECTION( ".rtemsrwset." #set ".begin" ) RTEMS_USED; \ |
---|
68 | type RTEMS_LINKER_SET_END( set )[0] \ |
---|
69 | RTEMS_SECTION( ".rtemsrwset." #set ".end" ) RTEMS_USED |
---|
70 | |
---|
71 | #define RTEMS_LINKER_RWSET_ITEM_DECLARE( set, type, item ) \ |
---|
72 | extern type _Linker_set_##set##_##item |
---|
73 | |
---|
74 | /* |
---|
75 | * The .rtemsroset is here not a typo. We must ensure that the references are |
---|
76 | * not a victim of the garbage collection of the linker. Thus, we place them |
---|
77 | * in a dedicated area of the RTEMS read-only linker set section. |
---|
78 | */ |
---|
79 | #define RTEMS_LINKER_RWSET_ITEM_REFERENCE( set, type, item ) \ |
---|
80 | static type * const _Set_reference_##set##_##item \ |
---|
81 | RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED = \ |
---|
82 | &_Linker_set_##set##_##item |
---|
83 | |
---|
84 | #define RTEMS_LINKER_RWSET_ITEM_ORDERED( set, type, item, order ) \ |
---|
85 | type _Linker_set_##set##_##item \ |
---|
86 | RTEMS_SECTION( ".rtemsrwset." #set ".content.0." RTEMS_XSTRING( order ) ) \ |
---|
87 | RTEMS_USED |
---|
88 | |
---|
89 | #define RTEMS_LINKER_RWSET_ITEM( set, type, item ) \ |
---|
90 | type _Linker_set_##set##_##item \ |
---|
91 | RTEMS_SECTION( ".rtemsrwset." #set ".content.1" ) RTEMS_USED |
---|
92 | |
---|
93 | #define RTEMS_LINKER_RWSET_CONTENT( set, decl ) \ |
---|
94 | decl \ |
---|
95 | RTEMS_SECTION( ".rtemsrwset." #set ".content" ) |
---|
96 | |
---|
97 | RTEMS_INLINE_ROUTINE uintptr_t _Linker_set_Obfuscate( const void *ptr ) |
---|
98 | { |
---|
99 | uintptr_t addr; |
---|
100 | |
---|
101 | addr = (uintptr_t) ptr; |
---|
102 | RTEMS_OBFUSCATE_VARIABLE( addr ); |
---|
103 | |
---|
104 | return addr; |
---|
105 | } |
---|
106 | |
---|
107 | #define RTEMS_LINKER_SET_SIZE( set ) \ |
---|
108 | ( _Linker_set_Obfuscate( RTEMS_LINKER_SET_END( set ) ) \ |
---|
109 | - _Linker_set_Obfuscate( RTEMS_LINKER_SET_BEGIN( set ) ) ) |
---|
110 | |
---|
111 | #define RTEMS_LINKER_SET_ITEM_COUNT( set ) \ |
---|
112 | ( RTEMS_LINKER_SET_SIZE( set ) \ |
---|
113 | / sizeof( RTEMS_LINKER_SET_BEGIN( set )[ 0 ] ) ) |
---|
114 | |
---|
115 | #define RTEMS_LINKER_SET_IS_EMPTY( set ) \ |
---|
116 | ( RTEMS_LINKER_SET_SIZE( set ) == 0 ) |
---|
117 | |
---|
118 | #define RTEMS_LINKER_SET_FOREACH( set, item ) \ |
---|
119 | for ( \ |
---|
120 | item = (void *) _Linker_set_Obfuscate( RTEMS_LINKER_SET_BEGIN( set ) ) ; \ |
---|
121 | item != RTEMS_LINKER_SET_END( set ) ; \ |
---|
122 | ++item \ |
---|
123 | ) |
---|
124 | |
---|
125 | #ifdef __cplusplus |
---|
126 | } |
---|
127 | #endif /* __cplusplus */ |
---|
128 | |
---|
129 | #endif /* _RTEMS_LINKERSET_H */ |
---|