[9f9a82b] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @ingroup Score |
---|
| 5 | * |
---|
[319cb20] | 6 | * @brief Basic Definitions |
---|
[9f9a82b] | 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | * COPYRIGHT (c) 1989-2007. |
---|
| 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
[2423857] | 13 | * Copyright (c) 2010-2015 embedded brains GmbH. |
---|
[9f9a82b] | 14 | * |
---|
| 15 | * The license and distribution terms for this file may be |
---|
| 16 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 17 | * http://www.rtems.org/license/LICENSE. |
---|
[9f9a82b] | 18 | */ |
---|
| 19 | |
---|
| 20 | #ifndef _RTEMS_BASEDEFS_H |
---|
| 21 | #define _RTEMS_BASEDEFS_H |
---|
| 22 | |
---|
[319cb20] | 23 | /** |
---|
| 24 | * @defgroup ScoreBaseDefs Basic Definitions |
---|
| 25 | * |
---|
| 26 | * @ingroup Score |
---|
| 27 | */ |
---|
| 28 | /**@{*/ |
---|
| 29 | |
---|
[9f9a82b] | 30 | #include <rtems/score/cpuopts.h> |
---|
| 31 | |
---|
| 32 | #ifndef ASM |
---|
| 33 | #include <stddef.h> |
---|
| 34 | #include <stdbool.h> |
---|
| 35 | #include <stdint.h> |
---|
[e64f164] | 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> |
---|
[d19c5352] | 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> |
---|
[9f9a82b] | 50 | #endif |
---|
| 51 | |
---|
| 52 | #ifndef TRUE |
---|
[27a1a6a] | 53 | /** |
---|
| 54 | * This ensures that RTEMS has TRUE defined in all situations. |
---|
| 55 | */ |
---|
[9f9a82b] | 56 | #define TRUE 1 |
---|
| 57 | #endif |
---|
| 58 | |
---|
| 59 | #ifndef FALSE |
---|
[27a1a6a] | 60 | /** |
---|
| 61 | * This ensures that RTEMS has FALSE defined in all situations. |
---|
| 62 | */ |
---|
[9f9a82b] | 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__ |
---|
[27a1a6a] | 77 | #define RTEMS_INLINE_ROUTINE static __inline__ |
---|
[9f9a82b] | 78 | #else |
---|
[27a1a6a] | 79 | #define RTEMS_INLINE_ROUTINE static inline |
---|
[9f9a82b] | 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__ |
---|
[f7e5fb5] | 88 | #define RTEMS_COMPILER_MEMORY_BARRIER() __asm__ volatile("" ::: "memory") |
---|
[9f9a82b] | 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 |
---|
[83bf105] | 98 | * rtems_fatal_error_occurred and _Terminate. |
---|
[9f9a82b] | 99 | */ |
---|
[8e7db68c] | 100 | #if defined(RTEMS_SCHEDSIM) |
---|
[143696a] | 101 | #define RTEMS_NO_RETURN |
---|
[8e7db68c] | 102 | #elif defined(__GNUC__) |
---|
[143696a] | 103 | #define RTEMS_NO_RETURN __attribute__((__noreturn__)) |
---|
[9f9a82b] | 104 | #else |
---|
[143696a] | 105 | #define RTEMS_NO_RETURN |
---|
[9f9a82b] | 106 | #endif |
---|
| 107 | |
---|
[143696a] | 108 | /* Provided for backward compatibility */ |
---|
| 109 | #define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE RTEMS_NO_RETURN |
---|
| 110 | |
---|
[06dcaf0] | 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__ |
---|
[a3ba5b37] | 118 | #define RTEMS_PURE __attribute__((__pure__)) |
---|
[06dcaf0] | 119 | #else |
---|
[a3ba5b37] | 120 | #define RTEMS_PURE |
---|
[06dcaf0] | 121 | #endif |
---|
| 122 | |
---|
[a3ba5b37] | 123 | /* Provided for backward compatibility */ |
---|
| 124 | #define RTEMS_COMPILER_PURE_ATTRIBUTE RTEMS_PURE |
---|
| 125 | |
---|
[9f9a82b] | 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__ |
---|
[c52568d] | 131 | #define RTEMS_DEPRECATED __attribute__((__deprecated__)) |
---|
[9f9a82b] | 132 | #else |
---|
[c52568d] | 133 | #define RTEMS_DEPRECATED |
---|
[9f9a82b] | 134 | #endif |
---|
| 135 | |
---|
[c52568d] | 136 | /* Provided for backward compatibility */ |
---|
| 137 | #define RTEMS_COMPILER_DEPRECATED_ATTRIBUTE RTEMS_DEPRECATED |
---|
| 138 | |
---|
[2423857] | 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 | |
---|
[ecd82b6d] | 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 | */ |
---|
[80ad7090] | 163 | #if defined(__GNUC__) |
---|
[f97536d] | 164 | #define RTEMS_UNUSED __attribute__((__unused__)) |
---|
[ecd82b6d] | 165 | #else |
---|
[f97536d] | 166 | #define RTEMS_UNUSED |
---|
[ecd82b6d] | 167 | #endif |
---|
| 168 | |
---|
[f97536d] | 169 | /* Provided for backward compatibility */ |
---|
| 170 | #define RTEMS_COMPILER_UNUSED_ATTRIBUTE RTEMS_UNUSED |
---|
| 171 | |
---|
[b2db1f5c] | 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__) |
---|
[bc792bb] | 177 | #define RTEMS_PACKED __attribute__((__packed__)) |
---|
[b2db1f5c] | 178 | #else |
---|
[bc792bb] | 179 | #define RTEMS_PACKED |
---|
[b2db1f5c] | 180 | #endif |
---|
| 181 | |
---|
[cd9ef185] | 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 | |
---|
[bc792bb] | 191 | /* Provided for backward compatibility */ |
---|
| 192 | #define RTEMS_COMPILER_PACKED_ATTRIBUTE RTEMS_PACKED |
---|
| 193 | |
---|
[e8d9b26] | 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 | |
---|
[e8020d1] | 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 | |
---|
[e278f8b7] | 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 |
---|
[51ab73b] | 234 | |
---|
[9ed2bef] | 235 | #define RTEMS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) |
---|
| 236 | |
---|
[dc18190] | 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 | |
---|
[40dcafa] | 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 | |
---|
[80ad7090] | 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) |
---|
| 265 | extern void* RTEMS_DEQUALIFY_types_not_compatible(void) |
---|
| 266 | __attribute__((error ("RTEMS_DEQUALIFY types differ not only by volatile and const"))); |
---|
| 267 | #else |
---|
| 268 | extern 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*/ |
---|
[a72f16e] | 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 | |
---|
[80ad7090] | 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*/ |
---|
[a72f16e] | 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 | |
---|
[80ad7090] | 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*/ |
---|
[a72f16e] | 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 | |
---|
[80ad7090] | 330 | #endif /*RTEMS_DEQUALIFY_DEPTHX*/ |
---|
| 331 | #endif /*RTEMS_DEQUALIFY*/ |
---|
| 332 | |
---|
[2423857] | 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 | |
---|
[9f9a82b] | 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 | |
---|
[319cb20] | 366 | /**@}*/ |
---|
| 367 | |
---|
[b10825c] | 368 | #endif /* _RTEMS_BASEDEFS_H */ |
---|