source: rtems/cpukit/score/include/rtems/score/basedefs.h @ 74f9db8

5
Last change on this file since 74f9db8 was 74f9db8, checked in by Sebastian Huber <sebastian.huber@…>, on 06/29/17 at 10:08:27

score: Add RTEMS_NO_INLINE

Update #3056.

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