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

5
Last change on this file since e8d9b26 was e8d9b26, checked in by Sebastian Huber <sebastian.huber@…>, on 03/22/16 at 06:24:14

score: Add and use RTEMS_UNREACHABLE

  • Property mode set to 100644
File size: 9.4 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#if __cplusplus >= 201103L
214  #define RTEMS_STATIC_ASSERT(cond, msg) \
215    static_assert(cond, # msg)
216#elif __STDC_VERSION__ >= 201112L
217  #define RTEMS_STATIC_ASSERT(cond, msg) \
218    _Static_assert(cond, # msg)
219#else
220  #define RTEMS_STATIC_ASSERT(cond, msg) \
221    typedef int rtems_static_assert_ ## msg [(cond) ? 1 : -1]
222#endif
223
224#define RTEMS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
225
226/*
227 * Zero-length arrays are valid in C99 as flexible array members.  C++11
228 * doesn't allow flexible array members.  Use the GNU extension which is also
229 * supported by other compilers.
230 */
231#define RTEMS_ZERO_LENGTH_ARRAY 0
232
233/**
234 * @brief Returns a pointer to the container of a specified member pointer.
235 *
236 * @param[in] _m The pointer to a member of the container.
237 * @param[in] _type The type of the container.
238 * @param[in] _member_name The designator name of the container member.
239 */
240#define RTEMS_CONTAINER_OF( _m, _type, _member_name ) \
241  ( (_type *) ( (uintptr_t) ( _m ) - offsetof( _type, _member_name ) ) )
242
243#ifdef __cplusplus
244#define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) \
245            (const_cast<_type>( _var ))
246#else /* Standard C code */
247
248/* The reference type idea based on libHX by Jan Engelhardt */
249#define RTEMS_TYPEOF_REFX(_ptr_level, _ptr_type) \
250  typeof(_ptr_level(union { int z; typeof(_ptr_type) x; }){0}.x)
251
252#if defined(__GNUC__) && !defined(ASM)
253#if  ((__GNUC__ * 1000 + __GNUC_MINOR__) >= 4004)
254extern void* RTEMS_DEQUALIFY_types_not_compatible(void)
255  __attribute__((error ("RTEMS_DEQUALIFY types differ not only by volatile and const")));
256#else
257extern void RTEMS_DEQUALIFY_types_not_compatible(void);
258#endif
259#define RTEMS_DEQUALIFY_DEPTHX( _ptr_level, _type, _var ) ( \
260    __builtin_choose_expr( __builtin_types_compatible_p ( \
261        RTEMS_TYPEOF_REFX( _ptr_level, _var ), \
262        RTEMS_TYPEOF_REFX( _ptr_level, _type ) \
263      ) || __builtin_types_compatible_p ( _type, void * ), \
264    (_type)(_var), \
265    RTEMS_DEQUALIFY_types_not_compatible() \
266  ) \
267)
268#endif /*__GNUC__*/
269#endif /*__cplusplus*/
270
271#ifndef RTEMS_DECONST
272#ifdef RTEMS_DEQUALIFY_DEPTHX
273#define RTEMS_DECONST( _type, _var ) \
274  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
275#else /*RTEMS_DEQUALIFY_DEPTHX*/
276/**
277 * @brief Removes the const qualifier from a type of a variable.
278 *
279 * @param[in] _type The target type for the variable.
280 * @param[in] _var The variable.
281 */
282#define RTEMS_DECONST( _type, _var ) \
283  ((_type)(uintptr_t)(const void *) ( _var ))
284
285#endif /*RTEMS_DEQUALIFY_DEPTHX*/
286#endif /*RTEMS_DECONST*/
287
288#ifndef RTEMS_DEVOLATILE
289#ifdef RTEMS_DEQUALIFY_DEPTHX
290#define RTEMS_DEVOLATILE( _type, _var ) \
291  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
292#else /*RTEMS_DEQUALIFY_DEPTHX*/
293/**
294 * @brief Removes the volatile qualifier from a type of a variable.
295 *
296 * @param[in] _type The target type for the variable.
297 * @param[in] _var The variable.
298 */
299#define RTEMS_DEVOLATILE( _type, _var ) \
300  ((_type)(uintptr_t)(volatile void *) ( _var ))
301
302#endif /*RTEMS_DEQUALIFY_DEPTHX*/
303#endif /*RTEMS_DEVOLATILE*/
304
305#ifndef RTEMS_DEQUALIFY
306#ifdef RTEMS_DEQUALIFY_DEPTHX
307#define RTEMS_DEQUALIFY( _type, _var ) \
308  RTEMS_DEQUALIFY_DEPTHX( *, _type, _var )
309#else /*RTEMS_DEQUALIFY_DEPTHX*/
310/**
311 * @brief Removes the all qualifiers from a type of a variable.
312 *
313 * @param[in] _type The target type for the variable.
314 * @param[in] _var The variable.
315 */
316#define RTEMS_DEQUALIFY( _type, _var ) \
317  ((_type)(uintptr_t)(const volatile void *) ( _var ))
318
319#endif /*RTEMS_DEQUALIFY_DEPTHX*/
320#endif /*RTEMS_DEQUALIFY*/
321
322/**
323 * @brief Concatenates _x and _y without expanding.
324 */
325#define RTEMS_CONCAT( _x, _y ) _x##_y
326
327/**
328 * @brief Concatenates expansion of _x and expansion of _y.
329 */
330#define RTEMS_XCONCAT( _x, _y ) RTEMS_CONCAT( _x, _y )
331
332/**
333 * @brief Stringifies _x  without expanding.
334 */
335#define RTEMS_STRING( _x ) #_x
336
337/**
338 * @brief Stringifies expansion of _x.
339 */
340#define RTEMS_XSTRING( _x ) RTEMS_STRING( _x )
341
342#ifndef ASM
343  #ifdef RTEMS_DEPRECATED_TYPES
344    typedef bool boolean;
345    typedef float single_precision;
346    typedef double double_precision;
347  #endif
348
349  /**
350   * XXX: Eventually proc_ptr needs to disappear!!!
351   */
352  typedef void * proc_ptr;
353#endif
354
355/**@}*/
356
357#endif /* _RTEMS_BASEDEFS_H */
Note: See TracBrowser for help on using the repository browser.