source: rtems/cpukit/score/include/rtems/score/basedefs.h @ 529b08a7

Last change on this file since 529b08a7 was 529b08a7, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 15, 2015 at 8:38:31 AM

posix: Delete empty _POSIX_API_Initialize()

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