1 /* 2 * Copyright (c) 2017 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_XCC_H_ 8 #define ZEPHYR_INCLUDE_TOOLCHAIN_XCC_H_ 9 10 #ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_ 11 #error Please do not include toolchain-specific headers directly, use <zephyr/toolchain.h> instead 12 #endif 13 14 /* toolchain/gcc.h errors out if __BYTE_ORDER__ cannot be determined 15 * there. However, __BYTE_ORDER__ is actually being defined later in 16 * this file. So define __BYTE_ORDER__ to skip the check in gcc.h 17 * and undefine after including gcc.h. 18 * 19 * Clang has it defined so there is no need to work around. 20 */ 21 #ifndef __clang__ 22 #define __BYTE_ORDER__ 23 #endif 24 25 #ifdef __clang__ 26 #include <zephyr/toolchain/llvm.h> 27 #else 28 #include <zephyr/toolchain/gcc.h> 29 #endif 30 31 #ifndef __clang__ 32 #undef __BYTE_ORDER__ 33 #endif 34 35 #include <stdbool.h> 36 37 #ifndef __INT8_C 38 #define __INT8_C(x) x 39 #endif 40 41 #ifndef INT8_C 42 #define INT8_C(x) __INT8_C(x) 43 #endif 44 45 #ifndef __UINT8_C 46 #define __UINT8_C(x) x ## U 47 #endif 48 49 #ifndef UINT8_C 50 #define UINT8_C(x) __UINT8_C(x) 51 #endif 52 53 #ifndef __INT16_C 54 #define __INT16_C(x) x 55 #endif 56 57 #ifndef INT16_C 58 #define INT16_C(x) __INT16_C(x) 59 #endif 60 61 #ifndef __UINT16_C 62 #define __UINT16_C(x) x ## U 63 #endif 64 65 #ifndef UINT16_C 66 #define UINT16_C(x) __UINT16_C(x) 67 #endif 68 69 #ifndef __INT32_C 70 #define __INT32_C(x) x 71 #endif 72 73 #ifndef INT32_C 74 #define INT32_C(x) __INT32_C(x) 75 #endif 76 77 #ifndef __UINT32_C 78 #define __UINT32_C(x) x ## U 79 #endif 80 81 #ifndef UINT32_C 82 #define UINT32_C(x) __UINT32_C(x) 83 #endif 84 85 #ifndef __INT64_C 86 #define __INT64_C(x) x 87 #endif 88 89 #ifndef INT64_C 90 #define INT64_C(x) __INT64_C(x) 91 #endif 92 93 #ifndef __UINT64_C 94 #define __UINT64_C(x) x ## ULL 95 #endif 96 97 #ifndef UINT64_C 98 #define UINT64_C(x) __UINT64_C(x) 99 #endif 100 101 #ifndef __INTMAX_C 102 #define __INTMAX_C(x) x 103 #endif 104 105 #ifndef INTMAX_C 106 #define INTMAX_C(x) __INTMAX_C(x) 107 #endif 108 109 #ifndef __UINTMAX_C 110 #define __UINTMAX_C(x) x ## ULL 111 #endif 112 113 #ifndef UINTMAX_C 114 #define UINTMAX_C(x) __UINTMAX_C(x) 115 #endif 116 117 #ifndef __COUNTER__ 118 /* XCC (GCC-based compiler) doesn't support __COUNTER__ 119 * but this should be good enough 120 */ 121 #define __COUNTER__ __LINE__ 122 #endif 123 124 #undef __in_section_unique 125 #define __in_section_unique(seg) \ 126 __attribute__((section("." STRINGIFY(seg) "." STRINGIFY(__COUNTER__)))) 127 128 #undef __in_section_unique_named 129 #define __in_section_unique_named(seg, name) \ 130 __attribute__((section("." STRINGIFY(seg) \ 131 "." STRINGIFY(__COUNTER__) \ 132 "." STRINGIFY(name)))) 133 134 #ifndef __GCC_LINKER_CMD__ 135 #include <xtensa/config/core.h> 136 137 /* 138 * XCC does not define the following macros with the expected names, but the 139 * HAL defines similar ones. Thus we include it and define the missing macros 140 * ourselves. 141 */ 142 #if XCHAL_MEMORY_ORDER == XTHAL_BIGENDIAN 143 #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ 144 #elif XCHAL_MEMORY_ORDER == XTHAL_LITTLEENDIAN 145 #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ 146 #else 147 #error "Cannot determine __BYTE_ORDER__" 148 #endif 149 150 #endif /* __GCC_LINKER_CMD__ */ 151 152 #define __builtin_unreachable() __builtin_trap() 153 154 /* Not a full barrier, just a SW barrier */ 155 #define __sync_synchronize() do { __asm__ __volatile__ ("" ::: "memory"); } \ 156 while (false) 157 158 #ifdef __deprecated 159 /* 160 * XCC does not support using deprecated attribute in enum, 161 * so just nullify it here to avoid compilation errors. 162 */ 163 #undef __deprecated 164 #define __deprecated 165 #endif 166 167 #endif 168