RTEMS  5.0.0
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, 2018 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 #endif
37 
38 #ifndef TRUE
39 
42  #define TRUE 1
43 #endif
44 
45 #ifndef FALSE
46 
49  #define FALSE 0
50 #endif
51 
52 #if TRUE == FALSE
53  #error "TRUE equals FALSE"
54 #endif
55 
62 #ifdef __GNUC__
63  #define RTEMS_INLINE_ROUTINE static __inline__
64 #else
65  #define RTEMS_INLINE_ROUTINE static inline
66 #endif
67 
73 #ifdef __GNUC__
74  #define RTEMS_COMPILER_MEMORY_BARRIER() __asm__ volatile("" ::: "memory")
75 #else
76  #define RTEMS_COMPILER_MEMORY_BARRIER()
77 #endif
78 
83 #ifdef __GNUC__
84  #define RTEMS_NO_INLINE __attribute__((__noinline__))
85 #else
86  #define RTEMS_NO_INLINE
87 #endif
88 
96 #if defined(RTEMS_SCHEDSIM)
97  #define RTEMS_NO_RETURN
98 #elif defined(__GNUC__) && !defined(RTEMS_DEBUG)
99  #define RTEMS_NO_RETURN __attribute__((__noreturn__))
100 #else
101  #define RTEMS_NO_RETURN
102 #endif
103 
104 /* Provided for backward compatibility */
105 #define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE RTEMS_NO_RETURN
106 
113 #ifdef __GNUC__
114  #define RTEMS_PURE __attribute__((__pure__))
115 #else
116  #define RTEMS_PURE
117 #endif
118 
119 /* Provided for backward compatibility */
120 #define RTEMS_COMPILER_PURE_ATTRIBUTE RTEMS_PURE
121 
126 #ifdef __GNUC__
127  #define RTEMS_DEPRECATED __attribute__((__deprecated__))
128 #else
129  #define RTEMS_DEPRECATED
130 #endif
131 
132 /* Provided for backward compatibility */
133 #define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE RTEMS_DEPRECATED
134 
139 #if defined(__GNUC__)
140  #define RTEMS_SECTION( _section ) __attribute__((__section__(_section)))
141 #else
142  #define RTEMS_SECTION( _section )
143 #endif
144 
148 #if defined(__GNUC__)
149  #define RTEMS_USED __attribute__((__used__))
150 #else
151  #define RTEMS_USED
152 #endif
153 
159 #if defined(__GNUC__)
160  #define RTEMS_UNUSED __attribute__((__unused__))
161 #else
162  #define RTEMS_UNUSED
163 #endif
164 
165 /* Provided for backward compatibility */
166 #define RTEMS_COMPILER_UNUSED_ATTRIBUTE RTEMS_UNUSED
167 
172 #if defined(__GNUC__)
173  #define RTEMS_PACKED __attribute__((__packed__))
174 #else
175  #define RTEMS_PACKED
176 #endif
177 
182 #if defined(__GNUC__)
183  #define RTEMS_ALIAS( _target ) __attribute__((__alias__(#_target)))
184 #else
185  #define RTEMS_ALIAS( _target )
186 #endif
187 
192 #if defined(__GNUC__)
193  #define RTEMS_WEAK_ALIAS( _target ) __attribute__((__weak__, __alias__(#_target)))
194 #else
195  #define RTEMS_WEAK_ALIAS( _target )
196 #endif
197 
201 #if defined(__GNUC__)
202  #define RTEMS_ALIGNED( _alignment ) __attribute__((__aligned__(_alignment)))
203 #else
204  #define RTEMS_ALIGNED( _alignment )
205 #endif
206 
207 /* Provided for backward compatibility */
208 #define RTEMS_COMPILER_PACKED_ATTRIBUTE RTEMS_PACKED
209 
210 #if defined(RTEMS_DEBUG) && !defined(RTEMS_SCHEDSIM)
211  #define _Assert_Unreachable() _Assert( 0 )
212 #else
213  #define _Assert_Unreachable() do { } while ( 0 )
214 #endif
215 
219 #if defined(__GNUC__) && !defined(RTEMS_SCHEDSIM)
220  #define RTEMS_UNREACHABLE() \
221  do { \
222  __builtin_unreachable(); \
223  _Assert_Unreachable(); \
224  } while ( 0 )
225 #else
226  #define RTEMS_UNREACHABLE() _Assert_Unreachable()
227 #endif
228 
233 #if defined(__GNUC__)
234  #define RTEMS_PRINTFLIKE( _format_pos, _ap_pos ) \
235  __attribute__((__format__(__printf__, _format_pos, _ap_pos)))
236 #else
237  #define RTEMS_PRINTFLIKE( _format_pos, _ap_pos )
238 #endif
239 
244 #if defined(__GNUC__)
245  #define RTEMS_MALLOCLIKE __attribute__((__malloc__))
246 #else
247  #define RTEMS_MALLOCLIKE
248 #endif
249 
254 #if defined(__GNUC__)
255  #define RTEMS_ALLOC_SIZE( _index ) __attribute__((__alloc_size__(_index)))
256 #else
257  #define RTEMS_ALLOC_SIZE( _index )
258 #endif
259 
264 #if defined(__GNUC__)
265  #define RTEMS_ALLOC_SIZE_2( _count_index, _size_index ) \
266  __attribute__((__alloc_size__(_count_index, _size_index)))
267 #else
268  #define RTEMS_ALLOC_SIZE_2( _count_index, _size_index )
269 #endif
270 
275 #if defined(__GNUC__)
276  #define RTEMS_ALLOC_ALIGN( _index ) __attribute__((__alloc_align__(_index)))
277 #else
278  #define RTEMS_ALLOC_ALIGN( _index )
279 #endif
280 
284 #if defined(__GNUC__)
285  #define RTEMS_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
286 #else
287  #define RTEMS_WARN_UNUSED_RESULT
288 #endif
289 
296 #if defined(__GNUC__)
297  #define RTEMS_OBFUSCATE_VARIABLE( _var ) __asm__("" : "+r" (_var))
298 #else
299  #define RTEMS_OBFUSCATE_VARIABLE( _var ) (void) (_var)
300 #endif
301 
309 #define RTEMS_DECLARE_GLOBAL_SYMBOL( _name ) \
310  extern char _name[]
311 
323 #if defined(__GNUC__)
324  #define RTEMS_DEFINE_GLOBAL_SYMBOL( _name, _value ) \
325  __asm__( \
326  "\t.globl " RTEMS_XSTRING( __USER_LABEL_PREFIX__ ) #_name \
327  "\n\t.set " RTEMS_XSTRING( __USER_LABEL_PREFIX__ ) #_name \
328  ", " RTEMS_STRING( _value ) "\n" \
329  )
330 #else
331  #define RTEMS_DEFINE_GLOBAL_SYMBOL( _name, _value )
332 #endif
333 
342 #if defined(__GNUC__)
343  #define RTEMS_PREDICT_TRUE( _exp ) __builtin_expect( ( _exp ), 1 )
344 #else
345  #define RTEMS_PREDICT_TRUE( _exp ) ( _exp )
346 #endif
347 
356 #if defined(__GNUC__)
357  #define RTEMS_PREDICT_FALSE( _exp ) __builtin_expect( ( _exp ), 0 )
358 #else
359  #define RTEMS_PREDICT_FALSE( _exp ) ( _exp )
360 #endif
361 
362 #if __cplusplus >= 201103L
363  #define RTEMS_STATIC_ASSERT(cond, msg) \
364  static_assert(cond, # msg)
365 #elif __STDC_VERSION__ >= 201112L
366  #define RTEMS_STATIC_ASSERT(cond, msg) \
367  _Static_assert(cond, # msg)
368 #else
369  #define RTEMS_STATIC_ASSERT(cond, msg) \
370  struct rtems_static_assert_ ## msg \
371  { int rtems_static_assert_ ## msg : (cond) ? 1 : -1; }
372 #endif
373 
374 #define RTEMS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
375 
376 /*
377  * Zero-length arrays are valid in C99 as flexible array members. C++11
378  * doesn't allow flexible array members. Use the GNU extension which is also
379  * supported by other compilers.
380  */
381 #define RTEMS_ZERO_LENGTH_ARRAY 0
382 
390 #define RTEMS_CONTAINER_OF( _m, _type, _member_name ) \
391  ( (_type *) ( (uintptr_t) ( _m ) - offsetof( _type, _member_name ) ) )
392 
393 #ifdef __cplusplus
394 #define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) \
395  (const_cast<_type>( _var ))
396 #else /* Standard C code */
397 
398 /* The reference type idea based on libHX by Jan Engelhardt */
399 #define RTEMS_TYPEOF_REFX(_ptr_level, _ptr_type) \
400  __typeof__(_ptr_level(union { int z; __typeof__(_ptr_type) x; }){0}.x)
401 
402 #if defined(__GNUC__) && !defined(ASM)
403 #if ((__GNUC__ * 1000 + __GNUC_MINOR__) >= 4004)
404 extern void* RTEMS_DEQUALIFY_types_not_compatible(void)
405  __attribute__((error ("RTEMS_DEQUALIFY types differ not only by volatile and const")));
406 #else
407 extern void RTEMS_DEQUALIFY_types_not_compatible(void);
408 #endif
409 #define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) ( \
410  __builtin_choose_expr( __builtin_types_compatible_p ( \
411  RTEMS_TYPEOF_REFX( _ptr_level, _var ), \
412  RTEMS_TYPEOF_REFX( _ptr_level, _type ) \
413  ) || __builtin_types_compatible_p ( _type, void * ), \
414  (_type)(_var), \
415  RTEMS_DEQUALIFY_types_not_compatible() \
416  ) \
417 )
418 #endif /*__GNUC__*/
419 #endif /*__cplusplus*/
420 
421 #ifndef RTEMS_DECONST
422 #ifdef RTEMS_DEQUALIFY_DEPTHX
423 #define RTEMS_DECONST( _type, _var ) \
424  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
425 #else /*RTEMS_DEQUALIFY_DEPTHX*/
426 
432 #define RTEMS_DECONST( _type, _var ) \
433  ((_type)(uintptr_t)(const void *) ( _var ))
434 
435 #endif /*RTEMS_DEQUALIFY_DEPTHX*/
436 #endif /*RTEMS_DECONST*/
437 
438 #ifndef RTEMS_DEVOLATILE
439 #ifdef RTEMS_DEQUALIFY_DEPTHX
440 #define RTEMS_DEVOLATILE( _type, _var ) \
441  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
442 #else /*RTEMS_DEQUALIFY_DEPTHX*/
443 
449 #define RTEMS_DEVOLATILE( _type, _var ) \
450  ((_type)(uintptr_t)(volatile void *) ( _var ))
451 
452 #endif /*RTEMS_DEQUALIFY_DEPTHX*/
453 #endif /*RTEMS_DEVOLATILE*/
454 
455 #ifndef RTEMS_DEQUALIFY
456 #ifdef RTEMS_DEQUALIFY_DEPTHX
457 #define RTEMS_DEQUALIFY( _type, _var ) \
458  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
459 #else /*RTEMS_DEQUALIFY_DEPTHX*/
460 
466 #define RTEMS_DEQUALIFY( _type, _var ) \
467  ((_type)(uintptr_t)(const volatile void *) ( _var ))
468 
469 #endif /*RTEMS_DEQUALIFY_DEPTHX*/
470 #endif /*RTEMS_DEQUALIFY*/
471 
480 #ifdef __GNUC__
481  #define RTEMS_HAVE_MEMBER_SAME_TYPE( _t_lhs, _m_lhs, _t_rhs, _m_rhs ) \
482  __builtin_types_compatible_p( \
483  __typeof__( ( (_t_lhs *) 0 )->_m_lhs ), \
484  __typeof__( ( (_t_rhs *) 0 )->_m_rhs ) \
485  )
486 #else
487  #define RTEMS_HAVE_MEMBER_SAME_TYPE( _t_lhs, _m_lhs, _t_rhs, _m_rhs ) \
488  true
489 #endif
490 
494 #define RTEMS_CONCAT( _x, _y ) _x##_y
495 
499 #define RTEMS_XCONCAT( _x, _y ) RTEMS_CONCAT( _x, _y )
500 
504 #define RTEMS_STRING( _x ) #_x
505 
509 #define RTEMS_XSTRING( _x ) RTEMS_STRING( _x )
510 
511 #ifndef ASM
512  #ifdef RTEMS_DEPRECATED_TYPES
513  typedef bool boolean RTEMS_DEPRECATED;
514  typedef float single_precision RTEMS_DEPRECATED;
515  typedef double double_precision RTEMS_DEPRECATED;
516  #endif
517 
521  typedef void * proc_ptr RTEMS_DEPRECATED;
522 #endif
523 
526 #endif /* _RTEMS_BASEDEFS_H */
typedef __attribute__
Disable IRQ Interrupts.
Definition: cmsis_gcc.h:69
#define RTEMS_DEPRECATED
Public name for task floating point context area.
Definition: basedefs.h:129