RTEMS CPU Kit with SuperCore  4.11.2
basedefs.h
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 1989-2007.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * Copyright (c) 2010 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 
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 
56  #define TRUE 1
57 #endif
58 
59 #ifndef FALSE
60 
63  #define FALSE 0
64 #endif
65 
66 #if TRUE == FALSE
67  #error "TRUE equals FALSE"
68 #endif
69 
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 
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 
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 
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 
132 #ifdef __GNUC__
133  #define RTEMS_INLINE_ROUTINE static __inline__
134 #else
135  #define RTEMS_INLINE_ROUTINE static inline
136 #endif
137 
143 #ifdef __GNUC__
144  #define RTEMS_COMPILER_MEMORY_BARRIER() __asm__ volatile("" ::: "memory")
145 #else
146  #define RTEMS_COMPILER_MEMORY_BARRIER()
147 #endif
148 
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 
171 #ifdef __GNUC__
172  #define RTEMS_COMPILER_PURE_ATTRIBUTE \
173  __attribute__ ((pure))
174 #else
175  #define RTEMS_COMPILER_PURE_ATTRIBUTE
176 #endif
177 
182 #ifdef __GNUC__
183  #define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE \
184  __attribute__ ((deprecated))
185 #else
186  #define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE
187 #endif
188 
194 #if defined(__GNUC__)
195  #define RTEMS_COMPILER_UNUSED_ATTRIBUTE __attribute__((unused))
196 #else
197  #define RTEMS_COMPILER_UNUSED_ATTRIBUTE
198 #endif
199 
204 #if defined(__GNUC__)
205  #define RTEMS_COMPILER_PACKED_ATTRIBUTE __attribute__((packed))
206 #else
207  #define RTEMS_COMPILER_PACKED_ATTRIBUTE
208 #endif
209 
210 #if __cplusplus >= 201103L
211  #define RTEMS_STATIC_ASSERT(cond, msg) \
212  static_assert(cond, # msg)
213 #elif __STDC_VERSION__ >= 201112L
214  #define RTEMS_STATIC_ASSERT(cond, msg) \
215  _Static_assert(cond, # msg)
216 #else
217  #define RTEMS_STATIC_ASSERT(cond, msg) \
218  typedef int rtems_static_assert_ ## msg [(cond) ? 1 : -1]
219 #endif
220 
221 #define RTEMS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
222 
223 /*
224  * Zero-length arrays are valid in C99 as flexible array members. C++11
225  * doesn't allow flexible array members. Use the GNU extension which is also
226  * supported by other compilers.
227  */
228 #define RTEMS_ZERO_LENGTH_ARRAY 0
229 
237 #define RTEMS_CONTAINER_OF( _m, _type, _member_name ) \
238  ( (_type *) ( (uintptr_t) ( _m ) - offsetof( _type, _member_name ) ) )
239 
240 #ifdef __cplusplus
241 #define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) \
242  (const_cast<_type>( _var ))
243 #else /* Standard C code */
244 
245 /* The reference type idea based on libHX by Jan Engelhardt */
246 #define RTEMS_TYPEOF_REFX(_ptr_level, _ptr_type) \
247  typeof(_ptr_level(union { int z; typeof(_ptr_type) x; }){0}.x)
248 
249 #if defined(__GNUC__) && !defined(ASM)
250 #if ((__GNUC__ * 1000 + __GNUC_MINOR__) >= 4004)
251 extern void* RTEMS_DEQUALIFY_types_not_compatible(void)
252  __attribute__((error ("RTEMS_DEQUALIFY types differ not only by volatile and const")));
253 #else
254 extern void RTEMS_DEQUALIFY_types_not_compatible(void);
255 #endif
256 #define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) ( \
257  __builtin_choose_expr( __builtin_types_compatible_p ( \
258  RTEMS_TYPEOF_REFX( _ptr_level, _var ), \
259  RTEMS_TYPEOF_REFX( _ptr_level, _type ) \
260  ) || __builtin_types_compatible_p ( _type, void * ), \
261  (_type)(_var), \
262  RTEMS_DEQUALIFY_types_not_compatible() \
263  ) \
264 )
265 #endif /*__GNUC__*/
266 #endif /*__cplusplus*/
267 
268 #ifndef RTEMS_DECONST
269 #ifdef RTEMS_DEQUALIFY_DEPTHX
270 #define RTEMS_DECONST( _type, _var ) \
271  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
272 #else /*RTEMS_DEQUALIFY_DEPTHX*/
273 
279 #define RTEMS_DECONST( _type, _var ) \
280  ((_type)(uintptr_t)(const void *) ( _var ))
281 
282 #endif /*RTEMS_DEQUALIFY_DEPTHX*/
283 #endif /*RTEMS_DECONST*/
284 
285 #ifndef RTEMS_DEVOLATILE
286 #ifdef RTEMS_DEQUALIFY_DEPTHX
287 #define RTEMS_DEVOLATILE( _type, _var ) \
288  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
289 #else /*RTEMS_DEQUALIFY_DEPTHX*/
290 
296 #define RTEMS_DEVOLATILE( _type, _var ) \
297  ((_type)(uintptr_t)(volatile void *) ( _var ))
298 
299 #endif /*RTEMS_DEQUALIFY_DEPTHX*/
300 #endif /*RTEMS_DEVOLATILE*/
301 
302 #ifndef RTEMS_DEQUALIFY
303 #ifdef RTEMS_DEQUALIFY_DEPTHX
304 #define RTEMS_DEQUALIFY( _type, _var ) \
305  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
306 #else /*RTEMS_DEQUALIFY_DEPTHX*/
307 
313 #define RTEMS_DEQUALIFY( _type, _var ) \
314  ((_type)(uintptr_t)(const volatile void *) ( _var ))
315 
316 #endif /*RTEMS_DEQUALIFY_DEPTHX*/
317 #endif /*RTEMS_DEQUALIFY*/
318 
319 #ifndef ASM
320  #ifdef RTEMS_DEPRECATED_TYPES
321  typedef bool boolean;
322  typedef float single_precision;
323  typedef double double_precision;
324  #endif
325 
329  typedef void * proc_ptr;
330 #endif
331 
334 #endif /* _RTEMS_BASEDEFS_H */
void * proc_ptr
XXX: Eventually proc_ptr needs to disappear!!!
Definition: basedefs.h:329