1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup Score |
---|
5 | * |
---|
6 | * @brief Basic Definitions |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2007. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * Copyright (c) 2010-2015 embedded brains GmbH. |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #ifndef _RTEMS_BASEDEFS_H |
---|
21 | #define _RTEMS_BASEDEFS_H |
---|
22 | |
---|
23 | /** |
---|
24 | * @defgroup ScoreBaseDefs Basic Definitions |
---|
25 | * |
---|
26 | * @ingroup Score |
---|
27 | */ |
---|
28 | /**@{*/ |
---|
29 | |
---|
30 | #include <rtems/score/cpuopts.h> |
---|
31 | |
---|
32 | #ifndef ASM |
---|
33 | #include <stddef.h> |
---|
34 | #include <stdbool.h> |
---|
35 | #include <stdint.h> |
---|
36 | |
---|
37 | /* |
---|
38 | * FIXME: This include should not be present. In older RTEMS versions |
---|
39 | * <rtems.h> provided <limits.h> indirectly. This include is here to not |
---|
40 | * break application source files that relied on this accidentally. |
---|
41 | */ |
---|
42 | #include <limits.h> |
---|
43 | |
---|
44 | /* |
---|
45 | * FIXME: This include should not be present. In older RTEMS versions |
---|
46 | * <rtems.h> provided <string.h> indirectly. This include is here to not |
---|
47 | * break application source files that relied on this accidentally. |
---|
48 | */ |
---|
49 | #include <string.h> |
---|
50 | #endif |
---|
51 | |
---|
52 | #ifndef TRUE |
---|
53 | /** |
---|
54 | * This ensures that RTEMS has TRUE defined in all situations. |
---|
55 | */ |
---|
56 | #define TRUE 1 |
---|
57 | #endif |
---|
58 | |
---|
59 | #ifndef FALSE |
---|
60 | /** |
---|
61 | * This ensures that RTEMS has FALSE defined in all situations. |
---|
62 | */ |
---|
63 | #define FALSE 0 |
---|
64 | #endif |
---|
65 | |
---|
66 | #if TRUE == FALSE |
---|
67 | #error "TRUE equals FALSE" |
---|
68 | #endif |
---|
69 | |
---|
70 | /** |
---|
71 | * The following ensures that all data is declared in the space |
---|
72 | * of the initialization routine for either the Initialization Manager |
---|
73 | * or the initialization file for the appropriate API. It is |
---|
74 | * referenced as "external" in every other file. |
---|
75 | */ |
---|
76 | #ifdef SCORE_INIT |
---|
77 | #undef SCORE_EXTERN |
---|
78 | #define SCORE_EXTERN |
---|
79 | #else |
---|
80 | #undef SCORE_EXTERN |
---|
81 | #define SCORE_EXTERN extern |
---|
82 | #endif |
---|
83 | |
---|
84 | /** |
---|
85 | * The following ensures that all data is declared in the space |
---|
86 | * of the initialization routine for either the Initialization Manager |
---|
87 | * or the initialization file for the appropriate API. It is |
---|
88 | * referenced as "external" in every other file. |
---|
89 | */ |
---|
90 | #ifdef SAPI_INIT |
---|
91 | #undef SAPI_EXTERN |
---|
92 | #define SAPI_EXTERN |
---|
93 | #else |
---|
94 | #undef SAPI_EXTERN |
---|
95 | #define SAPI_EXTERN extern |
---|
96 | #endif |
---|
97 | |
---|
98 | /** |
---|
99 | * The following ensures that all data is declared in the space |
---|
100 | * of the initialization routine for either the Initialization Manager |
---|
101 | * or the initialization file for the appropriate API. It is |
---|
102 | * referenced as "external" in every other file. |
---|
103 | */ |
---|
104 | #ifdef RTEMS_API_INIT |
---|
105 | #undef RTEMS_EXTERN |
---|
106 | #define RTEMS_EXTERN |
---|
107 | #else |
---|
108 | #undef RTEMS_EXTERN |
---|
109 | #define RTEMS_EXTERN extern |
---|
110 | #endif |
---|
111 | |
---|
112 | /** |
---|
113 | * The following ensures that all data is declared in the space |
---|
114 | * of the initialization routine for either the Initialization Manager |
---|
115 | * or the initialization file for the appropriate API. It is |
---|
116 | * referenced as "external" in every other file. |
---|
117 | */ |
---|
118 | #ifdef POSIX_API_INIT |
---|
119 | #undef POSIX_EXTERN |
---|
120 | #define POSIX_EXTERN |
---|
121 | #else |
---|
122 | #undef POSIX_EXTERN |
---|
123 | #define POSIX_EXTERN extern |
---|
124 | #endif |
---|
125 | |
---|
126 | /** |
---|
127 | * The following (in conjunction with compiler arguments) are used |
---|
128 | * to choose between the use of static inline functions and macro |
---|
129 | * functions. The static inline implementation allows better |
---|
130 | * type checking with no cost in code size or execution speed. |
---|
131 | */ |
---|
132 | #ifdef __GNUC__ |
---|
133 | #define RTEMS_INLINE_ROUTINE static __inline__ |
---|
134 | #else |
---|
135 | #define RTEMS_INLINE_ROUTINE static inline |
---|
136 | #endif |
---|
137 | |
---|
138 | /** |
---|
139 | * The following macro is a compiler specific way to ensure that memory |
---|
140 | * writes are not reordered around certian points. This specifically can |
---|
141 | * impact interrupt disable and thread dispatching critical sections. |
---|
142 | */ |
---|
143 | #ifdef __GNUC__ |
---|
144 | #define RTEMS_COMPILER_MEMORY_BARRIER() __asm__ volatile("" ::: "memory") |
---|
145 | #else |
---|
146 | #define RTEMS_COMPILER_MEMORY_BARRIER() |
---|
147 | #endif |
---|
148 | |
---|
149 | /** |
---|
150 | * The following macro is a compiler specific way to indicate that |
---|
151 | * the method will NOT return to the caller. This can assist the |
---|
152 | * compiler in code generation and avoid unreachable paths. This |
---|
153 | * can impact the code generated following calls to |
---|
154 | * rtems_fatal_error_occurred and _Terminate. |
---|
155 | */ |
---|
156 | #if defined(RTEMS_SCHEDSIM) |
---|
157 | #define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE |
---|
158 | #elif defined(__GNUC__) |
---|
159 | #define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE \ |
---|
160 | __attribute__ ((noreturn)) |
---|
161 | #else |
---|
162 | #define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE |
---|
163 | #endif |
---|
164 | |
---|
165 | /** |
---|
166 | * The following defines a compiler specific attribute which informs |
---|
167 | * the compiler that the method has no effect except the return value |
---|
168 | * and that the return value depends only on parameters and/or global |
---|
169 | * variables. |
---|
170 | */ |
---|
171 | #ifdef __GNUC__ |
---|
172 | #define RTEMS_COMPILER_PURE_ATTRIBUTE \ |
---|
173 | __attribute__ ((pure)) |
---|
174 | #else |
---|
175 | #define RTEMS_COMPILER_PURE_ATTRIBUTE |
---|
176 | #endif |
---|
177 | |
---|
178 | /** |
---|
179 | * Instructs the compiler to issue a warning whenever a variable or function |
---|
180 | * with this attribute will be used. |
---|
181 | */ |
---|
182 | #ifdef __GNUC__ |
---|
183 | #define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE \ |
---|
184 | __attribute__ ((deprecated)) |
---|
185 | #else |
---|
186 | #define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE |
---|
187 | #endif |
---|
188 | |
---|
189 | /** |
---|
190 | * @brief Instructs the compiler to place a specific variable or function in |
---|
191 | * the specified section. |
---|
192 | */ |
---|
193 | #if defined(__GNUC__) |
---|
194 | #define RTEMS_SECTION( _section ) __attribute__((__section__(_section))) |
---|
195 | #else |
---|
196 | #define RTEMS_SECTION( _section ) |
---|
197 | #endif |
---|
198 | |
---|
199 | /** |
---|
200 | * @brief Instructs the compiler that a specific variable or function is used. |
---|
201 | */ |
---|
202 | #if defined(__GNUC__) |
---|
203 | #define RTEMS_USED __attribute__((__used__)) |
---|
204 | #else |
---|
205 | #define RTEMS_USED |
---|
206 | #endif |
---|
207 | |
---|
208 | /** |
---|
209 | * Instructs the compiler that a specific variable is deliberately unused. |
---|
210 | * This can occur when reading volatile device memory or skipping arguments |
---|
211 | * in a variable argument method. |
---|
212 | */ |
---|
213 | #if defined(__GNUC__) |
---|
214 | #define RTEMS_COMPILER_UNUSED_ATTRIBUTE __attribute__((unused)) |
---|
215 | #else |
---|
216 | #define RTEMS_COMPILER_UNUSED_ATTRIBUTE |
---|
217 | #endif |
---|
218 | |
---|
219 | /** |
---|
220 | * Instructs the compiler that a specific structure or union members will be |
---|
221 | * placed so that the least memory is used. |
---|
222 | */ |
---|
223 | #if defined(__GNUC__) |
---|
224 | #define RTEMS_COMPILER_PACKED_ATTRIBUTE __attribute__((packed)) |
---|
225 | #else |
---|
226 | #define RTEMS_COMPILER_PACKED_ATTRIBUTE |
---|
227 | #endif |
---|
228 | |
---|
229 | #if __cplusplus >= 201103L |
---|
230 | #define RTEMS_STATIC_ASSERT(cond, msg) \ |
---|
231 | static_assert(cond, # msg) |
---|
232 | #elif __STDC_VERSION__ >= 201112L |
---|
233 | #define RTEMS_STATIC_ASSERT(cond, msg) \ |
---|
234 | _Static_assert(cond, # msg) |
---|
235 | #else |
---|
236 | #define RTEMS_STATIC_ASSERT(cond, msg) \ |
---|
237 | typedef int rtems_static_assert_ ## msg [(cond) ? 1 : -1] |
---|
238 | #endif |
---|
239 | |
---|
240 | #define RTEMS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) |
---|
241 | |
---|
242 | /* |
---|
243 | * Zero-length arrays are valid in C99 as flexible array members. C++11 |
---|
244 | * doesn't allow flexible array members. Use the GNU extension which is also |
---|
245 | * supported by other compilers. |
---|
246 | */ |
---|
247 | #define RTEMS_ZERO_LENGTH_ARRAY 0 |
---|
248 | |
---|
249 | /** |
---|
250 | * @brief Returns a pointer to the container of a specified member pointer. |
---|
251 | * |
---|
252 | * @param[in] _m The pointer to a member of the container. |
---|
253 | * @param[in] _type The type of the container. |
---|
254 | * @param[in] _member_name The designator name of the container member. |
---|
255 | */ |
---|
256 | #define RTEMS_CONTAINER_OF( _m, _type, _member_name ) \ |
---|
257 | ( (_type *) ( (uintptr_t) ( _m ) - offsetof( _type, _member_name ) ) ) |
---|
258 | |
---|
259 | #ifdef __cplusplus |
---|
260 | #define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) \ |
---|
261 | (const_cast<_type>( _var )) |
---|
262 | #else /* Standard C code */ |
---|
263 | |
---|
264 | /* The reference type idea based on libHX by Jan Engelhardt */ |
---|
265 | #define RTEMS_TYPEOF_REFX(_ptr_level, _ptr_type) \ |
---|
266 | typeof(_ptr_level(union { int z; typeof(_ptr_type) x; }){0}.x) |
---|
267 | |
---|
268 | #if defined(__GNUC__) && !defined(ASM) |
---|
269 | #if ((__GNUC__ * 1000 + __GNUC_MINOR__) >= 4004) |
---|
270 | extern void* RTEMS_DEQUALIFY_types_not_compatible(void) |
---|
271 | __attribute__((error ("RTEMS_DEQUALIFY types differ not only by volatile and const"))); |
---|
272 | #else |
---|
273 | extern void RTEMS_DEQUALIFY_types_not_compatible(void); |
---|
274 | #endif |
---|
275 | #define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) ( \ |
---|
276 | __builtin_choose_expr( __builtin_types_compatible_p ( \ |
---|
277 | RTEMS_TYPEOF_REFX( _ptr_level, _var ), \ |
---|
278 | RTEMS_TYPEOF_REFX( _ptr_level, _type ) \ |
---|
279 | ) || __builtin_types_compatible_p ( _type, void * ), \ |
---|
280 | (_type)(_var), \ |
---|
281 | RTEMS_DEQUALIFY_types_not_compatible() \ |
---|
282 | ) \ |
---|
283 | ) |
---|
284 | #endif /*__GNUC__*/ |
---|
285 | #endif /*__cplusplus*/ |
---|
286 | |
---|
287 | #ifndef RTEMS_DECONST |
---|
288 | #ifdef RTEMS_DEQUALIFY_DEPTHX |
---|
289 | #define RTEMS_DECONST( _type, _var ) \ |
---|
290 | RTEMS_DEQUALIFY_DEPTHX( *, _type, _var ) |
---|
291 | #else /*RTEMS_DEQUALIFY_DEPTHX*/ |
---|
292 | /** |
---|
293 | * @brief Removes the const qualifier from a type of a variable. |
---|
294 | * |
---|
295 | * @param[in] _type The target type for the variable. |
---|
296 | * @param[in] _var The variable. |
---|
297 | */ |
---|
298 | #define RTEMS_DECONST( _type, _var ) \ |
---|
299 | ((_type)(uintptr_t)(const void *) ( _var )) |
---|
300 | |
---|
301 | #endif /*RTEMS_DEQUALIFY_DEPTHX*/ |
---|
302 | #endif /*RTEMS_DECONST*/ |
---|
303 | |
---|
304 | #ifndef RTEMS_DEVOLATILE |
---|
305 | #ifdef RTEMS_DEQUALIFY_DEPTHX |
---|
306 | #define RTEMS_DEVOLATILE( _type, _var ) \ |
---|
307 | RTEMS_DEQUALIFY_DEPTHX( *, _type, _var ) |
---|
308 | #else /*RTEMS_DEQUALIFY_DEPTHX*/ |
---|
309 | /** |
---|
310 | * @brief Removes the volatile qualifier from a type of a variable. |
---|
311 | * |
---|
312 | * @param[in] _type The target type for the variable. |
---|
313 | * @param[in] _var The variable. |
---|
314 | */ |
---|
315 | #define RTEMS_DEVOLATILE( _type, _var ) \ |
---|
316 | ((_type)(uintptr_t)(volatile void *) ( _var )) |
---|
317 | |
---|
318 | #endif /*RTEMS_DEQUALIFY_DEPTHX*/ |
---|
319 | #endif /*RTEMS_DEVOLATILE*/ |
---|
320 | |
---|
321 | #ifndef RTEMS_DEQUALIFY |
---|
322 | #ifdef RTEMS_DEQUALIFY_DEPTHX |
---|
323 | #define RTEMS_DEQUALIFY( _type, _var ) \ |
---|
324 | RTEMS_DEQUALIFY_DEPTHX( *, _type, _var ) |
---|
325 | #else /*RTEMS_DEQUALIFY_DEPTHX*/ |
---|
326 | /** |
---|
327 | * @brief Removes the all qualifiers from a type of a variable. |
---|
328 | * |
---|
329 | * @param[in] _type The target type for the variable. |
---|
330 | * @param[in] _var The variable. |
---|
331 | */ |
---|
332 | #define RTEMS_DEQUALIFY( _type, _var ) \ |
---|
333 | ((_type)(uintptr_t)(const volatile void *) ( _var )) |
---|
334 | |
---|
335 | #endif /*RTEMS_DEQUALIFY_DEPTHX*/ |
---|
336 | #endif /*RTEMS_DEQUALIFY*/ |
---|
337 | |
---|
338 | /** |
---|
339 | * @brief Concatenates _x and _y without expanding. |
---|
340 | */ |
---|
341 | #define RTEMS_CONCAT( _x, _y ) _x##_y |
---|
342 | |
---|
343 | /** |
---|
344 | * @brief Concatenates expansion of _x and expansion of _y. |
---|
345 | */ |
---|
346 | #define RTEMS_XCONCAT( _x, _y ) RTEMS_CONCAT( _x, _y ) |
---|
347 | |
---|
348 | /** |
---|
349 | * @brief Stringifies _x without expanding. |
---|
350 | */ |
---|
351 | #define RTEMS_STRING( _x ) #_x |
---|
352 | |
---|
353 | /** |
---|
354 | * @brief Stringifies expansion of _x. |
---|
355 | */ |
---|
356 | #define RTEMS_XSTRING( _x ) RTEMS_STRING( _x ) |
---|
357 | |
---|
358 | #ifndef ASM |
---|
359 | #ifdef RTEMS_DEPRECATED_TYPES |
---|
360 | typedef bool boolean; |
---|
361 | typedef float single_precision; |
---|
362 | typedef double double_precision; |
---|
363 | #endif |
---|
364 | |
---|
365 | /** |
---|
366 | * XXX: Eventually proc_ptr needs to disappear!!! |
---|
367 | */ |
---|
368 | typedef void * proc_ptr; |
---|
369 | #endif |
---|
370 | |
---|
371 | /**@}*/ |
---|
372 | |
---|
373 | #endif /* _RTEMS_BASEDEFS_H */ |
---|