source: rtems/cpukit/score/include/rtems/score/basedefs.h @ 2605a489

5
Last change on this file since 2605a489 was 58089ff, checked in by Sebastian Huber <sebastian.huber@…>, on 12/14/15 at 14:28:51

rtems: Delete empty _RTEMS_API_Initialize()

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