RTEMS  5.1
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, 2019 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 
31 #include <rtems/score/cpuopts.h>
32 
33 #ifndef ASM
34  #include <stddef.h>
35  #include <stdbool.h>
36  #include <stdint.h>
37 #endif
38 
39 #ifndef TRUE
40 
43  #define TRUE 1
44 #endif
45 
46 #ifndef FALSE
47 
50  #define FALSE 0
51 #endif
52 
53 #if TRUE == FALSE
54  #error "TRUE equals FALSE"
55 #endif
56 
63 #ifdef __GNUC__
64  #define RTEMS_INLINE_ROUTINE static __inline__
65 #else
66  #define RTEMS_INLINE_ROUTINE static inline
67 #endif
68 
74 #ifdef __GNUC__
75  #define RTEMS_COMPILER_MEMORY_BARRIER() __asm__ volatile("" ::: "memory")
76 #else
77  #define RTEMS_COMPILER_MEMORY_BARRIER()
78 #endif
79 
84 #ifdef __GNUC__
85  #define RTEMS_NO_INLINE __attribute__((__noinline__))
86 #else
87  #define RTEMS_NO_INLINE
88 #endif
89 
97 #if defined(RTEMS_SCHEDSIM)
98  #define RTEMS_NO_RETURN
99 #elif defined(__GNUC__) && !defined(RTEMS_DEBUG)
100  #define RTEMS_NO_RETURN __attribute__((__noreturn__))
101 #else
102  #define RTEMS_NO_RETURN
103 #endif
104 
105 /* Provided for backward compatibility */
106 #define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE RTEMS_NO_RETURN
107 
113 #ifdef __GNUC__
114  #define RTEMS_CONST __attribute__((__const__))
115 #else
116  #define RTEMS_CONST
117 #endif
118 
125 #ifdef __GNUC__
126  #define RTEMS_PURE __attribute__((__pure__))
127 #else
128  #define RTEMS_PURE
129 #endif
130 
131 /* Provided for backward compatibility */
132 #define RTEMS_COMPILER_PURE_ATTRIBUTE RTEMS_PURE
133 
138 #ifdef __GNUC__
139  #define RTEMS_DEPRECATED __attribute__((__deprecated__))
140 #else
141  #define RTEMS_DEPRECATED
142 #endif
143 
144 /* Provided for backward compatibility */
145 #define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE RTEMS_DEPRECATED
146 
151 #if defined(__GNUC__)
152  #define RTEMS_SECTION( _section ) __attribute__((__section__(_section)))
153 #else
154  #define RTEMS_SECTION( _section )
155 #endif
156 
160 #if defined(__GNUC__)
161  #define RTEMS_USED __attribute__((__used__))
162 #else
163  #define RTEMS_USED
164 #endif
165 
171 #if defined(__GNUC__)
172  #define RTEMS_UNUSED __attribute__((__unused__))
173 #else
174  #define RTEMS_UNUSED
175 #endif
176 
177 /* Provided for backward compatibility */
178 #define RTEMS_COMPILER_UNUSED_ATTRIBUTE RTEMS_UNUSED
179 
184 #if defined(__GNUC__)
185  #define RTEMS_PACKED __attribute__((__packed__))
186 #else
187  #define RTEMS_PACKED
188 #endif
189 
194 #if defined(__GNUC__)
195  #define RTEMS_ALIAS( _target ) __attribute__((__alias__(#_target)))
196 #else
197  #define RTEMS_ALIAS( _target )
198 #endif
199 
204 #if defined(__GNUC__)
205  #define RTEMS_WEAK_ALIAS( _target ) __attribute__((__weak__, __alias__(#_target)))
206 #else
207  #define RTEMS_WEAK_ALIAS( _target )
208 #endif
209 
213 #if defined(__GNUC__)
214  #define RTEMS_ALIGNED( _alignment ) __attribute__((__aligned__(_alignment)))
215 #else
216  #define RTEMS_ALIGNED( _alignment )
217 #endif
218 
219 /* Provided for backward compatibility */
220 #define RTEMS_COMPILER_PACKED_ATTRIBUTE RTEMS_PACKED
221 
222 #if defined(RTEMS_DEBUG) && !defined(RTEMS_SCHEDSIM)
223  #define _Assert_Unreachable() _Assert( 0 )
224 #else
225  #define _Assert_Unreachable() do { } while ( 0 )
226 #endif
227 
231 #if defined(__GNUC__) && !defined(RTEMS_SCHEDSIM)
232  #define RTEMS_UNREACHABLE() \
233  do { \
234  __builtin_unreachable(); \
235  _Assert_Unreachable(); \
236  } while ( 0 )
237 #else
238  #define RTEMS_UNREACHABLE() _Assert_Unreachable()
239 #endif
240 
245 #if defined(__GNUC__)
246  #define RTEMS_PRINTFLIKE( _format_pos, _ap_pos ) \
247  __attribute__((__format__(__printf__, _format_pos, _ap_pos)))
248 #else
249  #define RTEMS_PRINTFLIKE( _format_pos, _ap_pos )
250 #endif
251 
256 #if defined(__GNUC__)
257  #define RTEMS_MALLOCLIKE __attribute__((__malloc__))
258 #else
259  #define RTEMS_MALLOCLIKE
260 #endif
261 
266 #if defined(__GNUC__)
267  #define RTEMS_ALLOC_SIZE( _index ) __attribute__((__alloc_size__(_index)))
268 #else
269  #define RTEMS_ALLOC_SIZE( _index )
270 #endif
271 
276 #if defined(__GNUC__)
277  #define RTEMS_ALLOC_SIZE_2( _count_index, _size_index ) \
278  __attribute__((__alloc_size__(_count_index, _size_index)))
279 #else
280  #define RTEMS_ALLOC_SIZE_2( _count_index, _size_index )
281 #endif
282 
287 #if defined(__GNUC__)
288  #define RTEMS_ALLOC_ALIGN( _index ) __attribute__((__alloc_align__(_index)))
289 #else
290  #define RTEMS_ALLOC_ALIGN( _index )
291 #endif
292 
296 #if defined(__GNUC__)
297  #define RTEMS_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
298 #else
299  #define RTEMS_WARN_UNUSED_RESULT
300 #endif
301 
308 #if defined(__GNUC__)
309  #define RTEMS_OBFUSCATE_VARIABLE( _var ) __asm__("" : "+r" (_var))
310 #else
311  #define RTEMS_OBFUSCATE_VARIABLE( _var ) (void) (_var)
312 #endif
313 
321 #define RTEMS_DECLARE_GLOBAL_SYMBOL( _name ) \
322  extern char _name[]
323 
330 #if defined(__USER_LABEL_PREFIX__)
331  #define RTEMS_SYMBOL_NAME( _name ) \
332  RTEMS_XCONCAT( __USER_LABEL_PREFIX__, _name )
333 #else
334  /* Helper to perform the macro expansion */
335  #define _RTEMS_SYMBOL_NAME( _name ) _name
336 
337  #define RTEMS_SYMBOL_NAME( _name ) _RTEMS_SYMBOL_NAME( _name )
338 #endif
339 
352 #if defined(__GNUC__)
353  #define RTEMS_DEFINE_GLOBAL_SYMBOL( _name, _value ) \
354  __asm__( \
355  "\t.globl " RTEMS_XSTRING( RTEMS_SYMBOL_NAME( _name ) ) \
356  "\n\t.set " RTEMS_XSTRING( RTEMS_SYMBOL_NAME( _name ) ) \
357  ", " RTEMS_STRING( _value ) "\n" \
358  )
359 #else
360  #define RTEMS_DEFINE_GLOBAL_SYMBOL( _name, _value )
361 #endif
362 
371 #if defined(__GNUC__)
372  #define RTEMS_PREDICT_TRUE( _exp ) __builtin_expect( ( _exp ), 1 )
373 #else
374  #define RTEMS_PREDICT_TRUE( _exp ) ( _exp )
375 #endif
376 
385 #if defined(__GNUC__)
386  #define RTEMS_PREDICT_FALSE( _exp ) __builtin_expect( ( _exp ), 0 )
387 #else
388  #define RTEMS_PREDICT_FALSE( _exp ) ( _exp )
389 #endif
390 
396 #if defined(__GNUC__)
397  #define RTEMS_RETURN_ADDRESS() __builtin_return_address( 0 )
398 #else
399  #define RTEMS_RETURN_ADDRESS() NULL
400 #endif
401 
402 #if __cplusplus >= 201103L
403  #define RTEMS_STATIC_ASSERT(cond, msg) \
404  static_assert(cond, # msg)
405 #elif __STDC_VERSION__ >= 201112L
406  #define RTEMS_STATIC_ASSERT(cond, msg) \
407  _Static_assert(cond, # msg)
408 #else
409  #define RTEMS_STATIC_ASSERT(cond, msg) \
410  struct rtems_static_assert_ ## msg \
411  { int rtems_static_assert_ ## msg : (cond) ? 1 : -1; }
412 #endif
413 
414 #define RTEMS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
415 
416 /*
417  * Zero-length arrays are valid in C99 as flexible array members. C++11
418  * doesn't allow flexible array members. Use the GNU extension which is also
419  * supported by other compilers.
420  */
421 #define RTEMS_ZERO_LENGTH_ARRAY 0
422 
430 #define RTEMS_CONTAINER_OF( _m, _type, _member_name ) \
431  ( (_type *) ( (uintptr_t) ( _m ) - offsetof( _type, _member_name ) ) )
432 
433 #ifdef __cplusplus
434 #define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) \
435  (const_cast<_type>( _var ))
436 #else /* Standard C code */
437 
438 /* The reference type idea based on libHX by Jan Engelhardt */
439 #define RTEMS_TYPEOF_REFX(_ptr_level, _ptr_type) \
440  __typeof__(_ptr_level(union { int z; __typeof__(_ptr_type) x; }){0}.x)
441 
442 #if defined(__GNUC__) && !defined(ASM)
443 #if ((__GNUC__ * 1000 + __GNUC_MINOR__) >= 4004)
444 extern void* RTEMS_DEQUALIFY_types_not_compatible(void)
445  __attribute__((error ("RTEMS_DEQUALIFY types differ not only by volatile and const")));
446 #else
447 extern void RTEMS_DEQUALIFY_types_not_compatible(void);
448 #endif
449 #define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) ( \
450  __builtin_choose_expr( __builtin_types_compatible_p ( \
451  RTEMS_TYPEOF_REFX( _ptr_level, _var ), \
452  RTEMS_TYPEOF_REFX( _ptr_level, _type ) \
453  ) || __builtin_types_compatible_p ( _type, void * ), \
454  (_type)(_var), \
455  RTEMS_DEQUALIFY_types_not_compatible() \
456  ) \
457 )
458 #endif /*__GNUC__*/
459 #endif /*__cplusplus*/
460 
461 #ifndef RTEMS_DECONST
462 #ifdef RTEMS_DEQUALIFY_DEPTHX
463 #define RTEMS_DECONST( _type, _var ) \
464  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
465 #else /*RTEMS_DEQUALIFY_DEPTHX*/
466 
472 #define RTEMS_DECONST( _type, _var ) \
473  ((_type)(uintptr_t)(const void *) ( _var ))
474 
475 #endif /*RTEMS_DEQUALIFY_DEPTHX*/
476 #endif /*RTEMS_DECONST*/
477 
478 #ifndef RTEMS_DEVOLATILE
479 #ifdef RTEMS_DEQUALIFY_DEPTHX
480 #define RTEMS_DEVOLATILE( _type, _var ) \
481  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
482 #else /*RTEMS_DEQUALIFY_DEPTHX*/
483 
489 #define RTEMS_DEVOLATILE( _type, _var ) \
490  ((_type)(uintptr_t)(volatile void *) ( _var ))
491 
492 #endif /*RTEMS_DEQUALIFY_DEPTHX*/
493 #endif /*RTEMS_DEVOLATILE*/
494 
495 #ifndef RTEMS_DEQUALIFY
496 #ifdef RTEMS_DEQUALIFY_DEPTHX
497 #define RTEMS_DEQUALIFY( _type, _var ) \
498  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
499 #else /*RTEMS_DEQUALIFY_DEPTHX*/
500 
506 #define RTEMS_DEQUALIFY( _type, _var ) \
507  ((_type)(uintptr_t)(const volatile void *) ( _var ))
508 
509 #endif /*RTEMS_DEQUALIFY_DEPTHX*/
510 #endif /*RTEMS_DEQUALIFY*/
511 
520 #ifdef __GNUC__
521  #define RTEMS_HAVE_MEMBER_SAME_TYPE( _t_lhs, _m_lhs, _t_rhs, _m_rhs ) \
522  __builtin_types_compatible_p( \
523  __typeof__( ( (_t_lhs *) 0 )->_m_lhs ), \
524  __typeof__( ( (_t_rhs *) 0 )->_m_rhs ) \
525  )
526 #else
527  #define RTEMS_HAVE_MEMBER_SAME_TYPE( _t_lhs, _m_lhs, _t_rhs, _m_rhs ) \
528  true
529 #endif
530 
534 #define RTEMS_CONCAT( _x, _y ) _x##_y
535 
539 #define RTEMS_XCONCAT( _x, _y ) RTEMS_CONCAT( _x, _y )
540 
544 #define RTEMS_STRING( _x ) #_x
545 
549 #define RTEMS_XSTRING( _x ) RTEMS_STRING( _x )
550 
551 #ifndef ASM
552  #ifdef RTEMS_DEPRECATED_TYPES
553  typedef bool boolean RTEMS_DEPRECATED;
554  typedef float single_precision RTEMS_DEPRECATED;
555  typedef double double_precision RTEMS_DEPRECATED;
556  #endif
557 
561  typedef void * proc_ptr RTEMS_DEPRECATED;
562 #endif
563 
566 #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:141