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