source: rtems/cpukit/score/include/rtems/score/basedefs.h @ e8020d1

Last change on this file since e8020d1 was e8020d1, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 21, 2016 at 11:28:01 AM

Rename and move RTEMS_PRINTF_ATTRIBUTE()

Rename RTEMS_PRINTF_ATTRIBUTE() into RTEMS_PRINTFLIKE() (similar to
<sys/cdefs.h> printflike()) and move it to <rtems/score/basedefs.h>.

  • Property mode set to 100644
File size: 9.7 KB
Line 
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 (in conjunction with compiler arguments) are used
72 *  to choose between the use of static inline functions and macro
73 *  functions.   The static inline implementation allows better
74 *  type checking with no cost in code size or execution speed.
75 */
76#ifdef __GNUC__
77  #define RTEMS_INLINE_ROUTINE static __inline__
78#else
79  #define RTEMS_INLINE_ROUTINE static inline
80#endif
81
82/**
83 *  The following macro is a compiler specific way to ensure that memory
84 *  writes are not reordered around certian points.  This specifically can
85 *  impact interrupt disable and thread dispatching critical sections.
86 */
87#ifdef __GNUC__
88  #define RTEMS_COMPILER_MEMORY_BARRIER() __asm__ volatile("" ::: "memory")
89#else
90  #define RTEMS_COMPILER_MEMORY_BARRIER()
91#endif
92
93/**
94 *  The following macro is a compiler specific way to indicate that
95 *  the method will NOT return to the caller.  This can assist the
96 *  compiler in code generation and avoid unreachable paths.  This
97 *  can impact the code generated following calls to
98 *  rtems_fatal_error_occurred and _Terminate.
99 */
100#if defined(RTEMS_SCHEDSIM)
101  #define RTEMS_NO_RETURN
102#elif defined(__GNUC__)
103  #define RTEMS_NO_RETURN __attribute__((__noreturn__))
104#else
105  #define RTEMS_NO_RETURN
106#endif
107
108/* Provided for backward compatibility */
109#define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE RTEMS_NO_RETURN
110
111/**
112 *  The following defines a compiler specific attribute which informs
113 *  the compiler that the method has no effect except the return value
114 *  and that the return value depends only on parameters and/or global
115 *  variables.
116 */
117#ifdef __GNUC__
118  #define RTEMS_PURE __attribute__((__pure__))
119#else
120  #define RTEMS_PURE
121#endif
122
123/* Provided for backward compatibility */
124#define RTEMS_COMPILER_PURE_ATTRIBUTE RTEMS_PURE
125
126/**
127 *  Instructs the compiler to issue a warning whenever a variable or function
128 *  with this attribute will be used.
129 */
130#ifdef __GNUC__
131  #define RTEMS_DEPRECATED __attribute__((__deprecated__))
132#else
133  #define RTEMS_DEPRECATED
134#endif
135
136/* Provided for backward compatibility */
137#define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE RTEMS_DEPRECATED
138
139/**
140 * @brief Instructs the compiler to place a specific variable or function in
141 * the specified section.
142 */
143#if defined(__GNUC__)
144  #define RTEMS_SECTION( _section ) __attribute__((__section__(_section)))
145#else
146  #define RTEMS_SECTION( _section )
147#endif
148
149/**
150 * @brief Instructs the compiler that a specific variable or function is used.
151 */
152#if defined(__GNUC__)
153  #define RTEMS_USED __attribute__((__used__))
154#else
155  #define RTEMS_USED
156#endif
157
158/**
159 *  Instructs the compiler that a specific variable is deliberately unused.
160 *  This can occur when reading volatile device memory or skipping arguments
161 *  in a variable argument method.
162 */
163#if defined(__GNUC__)
164  #define RTEMS_UNUSED __attribute__((__unused__))
165#else
166  #define RTEMS_UNUSED
167#endif
168
169/* Provided for backward compatibility */
170#define RTEMS_COMPILER_UNUSED_ATTRIBUTE RTEMS_UNUSED
171
172/**
173 *  Instructs the compiler that a specific structure or union members will be
174 *  placed so that the least memory is used.
175 */
176#if defined(__GNUC__)
177  #define RTEMS_PACKED __attribute__((__packed__))
178#else
179  #define RTEMS_PACKED
180#endif
181
182/**
183 * @brief Instructs the compiler to enforce the specified alignment.
184 */
185#if defined(__GNUC__)
186  #define RTEMS_ALIGNED( _alignment ) __attribute__((__aligned__(_alignment)))
187#else
188  #define RTEMS_ALIGNED( _alignment )
189#endif
190
191/* Provided for backward compatibility */
192#define RTEMS_COMPILER_PACKED_ATTRIBUTE RTEMS_PACKED
193
194#if defined(RTEMS_DEBUG) && !defined(RTEMS_SCHEDSIM)
195  #define _Assert_Unreachable() _Assert( 0 )
196#else
197  #define _Assert_Unreachable() do { } while ( 0 )
198#endif
199
200/**
201 * @brief Tells the compiler that this program point is unreachable.
202 */
203#if defined(__GNUC__) && !defined(RTEMS_SCHEDSIM)
204  #define RTEMS_UNREACHABLE() \
205    do { \
206      __builtin_unreachable(); \
207      _Assert_Unreachable(); \
208    } while ( 0 )
209#else
210  #define RTEMS_UNREACHABLE() _Assert_Unreachable()
211#endif
212
213/**
214 * @brief Tells the compiler that this function expects printf()-like
215 * arguments.
216 */
217#if defined(__GNUC__)
218  #define RTEMS_PRINTFLIKE( _format_pos, _ap_pos ) \
219    __attribute__((__format__(__printf__, _format_pos, _ap_pos)))
220#else
221  #define RTEMS_PRINTFLIKE( _format_pos, _ap_pos )
222#endif
223
224#if __cplusplus >= 201103L
225  #define RTEMS_STATIC_ASSERT(cond, msg) \
226    static_assert(cond, # msg)
227#elif __STDC_VERSION__ >= 201112L
228  #define RTEMS_STATIC_ASSERT(cond, msg) \
229    _Static_assert(cond, # msg)
230#else
231  #define RTEMS_STATIC_ASSERT(cond, msg) \
232    typedef int rtems_static_assert_ ## msg [(cond) ? 1 : -1]
233#endif
234
235#define RTEMS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
236
237/*
238 * Zero-length arrays are valid in C99 as flexible array members.  C++11
239 * doesn't allow flexible array members.  Use the GNU extension which is also
240 * supported by other compilers.
241 */
242#define RTEMS_ZERO_LENGTH_ARRAY 0
243
244/**
245 * @brief Returns a pointer to the container of a specified member pointer.
246 *
247 * @param[in] _m The pointer to a member of the container.
248 * @param[in] _type The type of the container.
249 * @param[in] _member_name The designator name of the container member.
250 */
251#define RTEMS_CONTAINER_OF( _m, _type, _member_name ) \
252  ( (_type *) ( (uintptr_t) ( _m ) - offsetof( _type, _member_name ) ) )
253
254#ifdef __cplusplus
255#define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) \
256            (const_cast<_type>( _var ))
257#else /* Standard C code */
258
259/* The reference type idea based on libHX by Jan Engelhardt */
260#define RTEMS_TYPEOF_REFX(_ptr_level, _ptr_type) \
261  typeof(_ptr_level(union { int z; typeof(_ptr_type) x; }){0}.x)
262
263#if defined(__GNUC__) && !defined(ASM)
264#if  ((__GNUC__ * 1000 + __GNUC_MINOR__) >= 4004)
265extern void* RTEMS_DEQUALIFY_types_not_compatible(void)
266  __attribute__((error ("RTEMS_DEQUALIFY types differ not only by volatile and const")));
267#else
268extern void RTEMS_DEQUALIFY_types_not_compatible(void);
269#endif
270#define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) ( \
271    __builtin_choose_expr( __builtin_types_compatible_p ( \
272        RTEMS_TYPEOF_REFX( _ptr_level, _var ), \
273        RTEMS_TYPEOF_REFX( _ptr_level, _type ) \
274      ) || __builtin_types_compatible_p ( _type, void * ), \
275    (_type)(_var), \
276    RTEMS_DEQUALIFY_types_not_compatible() \
277  ) \
278)
279#endif /*__GNUC__*/
280#endif /*__cplusplus*/
281
282#ifndef RTEMS_DECONST
283#ifdef RTEMS_DEQUALIFY_DEPTHX
284#define RTEMS_DECONST( _type, _var ) \
285  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
286#else /*RTEMS_DEQUALIFY_DEPTHX*/
287/**
288 * @brief Removes the const qualifier from a type of a variable.
289 *
290 * @param[in] _type The target type for the variable.
291 * @param[in] _var The variable.
292 */
293#define RTEMS_DECONST( _type, _var ) \
294  ((_type)(uintptr_t)(const void *) ( _var ))
295
296#endif /*RTEMS_DEQUALIFY_DEPTHX*/
297#endif /*RTEMS_DECONST*/
298
299#ifndef RTEMS_DEVOLATILE
300#ifdef RTEMS_DEQUALIFY_DEPTHX
301#define RTEMS_DEVOLATILE( _type, _var ) \
302  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
303#else /*RTEMS_DEQUALIFY_DEPTHX*/
304/**
305 * @brief Removes the volatile qualifier from a type of a variable.
306 *
307 * @param[in] _type The target type for the variable.
308 * @param[in] _var The variable.
309 */
310#define RTEMS_DEVOLATILE( _type, _var ) \
311  ((_type)(uintptr_t)(volatile void *) ( _var ))
312
313#endif /*RTEMS_DEQUALIFY_DEPTHX*/
314#endif /*RTEMS_DEVOLATILE*/
315
316#ifndef RTEMS_DEQUALIFY
317#ifdef RTEMS_DEQUALIFY_DEPTHX
318#define RTEMS_DEQUALIFY( _type, _var ) \
319  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
320#else /*RTEMS_DEQUALIFY_DEPTHX*/
321/**
322 * @brief Removes the all qualifiers from a type of a variable.
323 *
324 * @param[in] _type The target type for the variable.
325 * @param[in] _var The variable.
326 */
327#define RTEMS_DEQUALIFY( _type, _var ) \
328  ((_type)(uintptr_t)(const volatile void *) ( _var ))
329
330#endif /*RTEMS_DEQUALIFY_DEPTHX*/
331#endif /*RTEMS_DEQUALIFY*/
332
333/**
334 * @brief Concatenates _x and _y without expanding.
335 */
336#define RTEMS_CONCAT( _x, _y ) _x##_y
337
338/**
339 * @brief Concatenates expansion of _x and expansion of _y.
340 */
341#define RTEMS_XCONCAT( _x, _y ) RTEMS_CONCAT( _x, _y )
342
343/**
344 * @brief Stringifies _x  without expanding.
345 */
346#define RTEMS_STRING( _x ) #_x
347
348/**
349 * @brief Stringifies expansion of _x.
350 */
351#define RTEMS_XSTRING( _x ) RTEMS_STRING( _x )
352
353#ifndef ASM
354  #ifdef RTEMS_DEPRECATED_TYPES
355    typedef bool boolean;
356    typedef float single_precision;
357    typedef double double_precision;
358  #endif
359
360  /**
361   * XXX: Eventually proc_ptr needs to disappear!!!
362   */
363  typedef void * proc_ptr;
364#endif
365
366/**@}*/
367
368#endif /* _RTEMS_BASEDEFS_H */
Note: See TracBrowser for help on using the repository browser.