Zephyr Project API
4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
iccarm.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2025 IAR Systems AB
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef ZEPHYR_INCLUDE_TOOLCHAIN_ICCARM_H_
8
#define ZEPHYR_INCLUDE_TOOLCHAIN_ICCARM_H_
9
16
17
/* ICCARM supports its own #pragma diag_{warning,default,error,warning}. */
18
/* #define TOOLCHAIN_HAS_PRAGMA_DIAG 0 */
19
20
#define TOOLCHAIN_HAS_C_GENERIC 1
21
22
#define TOOLCHAIN_HAS_C_AUTO_TYPE 1
23
24
/* #define TOOLCHAIN_HAS_ZLA 1 */
25
26
/*
27
* IAR do not define __BYTE_ORDER__, so it must be manually
28
* detected and defined using arch-specific definitions.
29
*/
30
31
#ifndef _LINKER
32
33
#ifndef __ORDER_BIG_ENDIAN__
34
#define __ORDER_BIG_ENDIAN__ (1)
35
#endif
/* __ORDER_BIG_ENDIAN__ */
36
37
#ifndef __ORDER_LITTLE_ENDIAN__
38
#define __ORDER_LITTLE_ENDIAN__ (2)
39
#endif
/* __ORDER_LITTLE_ENDIAN__ */
40
41
#ifndef __ORDER_PDP_ENDIAN__
42
#define __ORDER_PDP_ENDIAN__ (3)
43
#endif
/* __ORDER_PDP_ENDIAN__ */
44
45
#ifndef __BYTE_ORDER__
46
47
#if __LITTLE_ENDIAN__ == 1
48
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
49
#else
50
#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
51
#endif
/* __LITTLE_ENDIAN__ == 1 */
52
53
#endif
/* __BYTE_ORDER__ */
54
55
56
#if defined(__cplusplus) && (__cplusplus >= 201103L)
57
#define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG)
58
#elif defined(__ICCARM__)
59
#define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)
60
#endif
61
62
/* Zephyr makes use of __ATOMIC_SEQ_CST */
63
#ifdef __STDC_NO_ATOMICS__
64
#ifndef __ATOMIC_SEQ_CST
65
#define __MEMORY_ORDER_SEQ_CST__ 5
66
#endif
67
#endif
68
#ifndef __ATOMIC_SEQ_CST
69
#define __ATOMIC_SEQ_CST __MEMORY_ORDER_SEQ_CST__
70
#endif
71
72
/* By default, restrict is recognized in Standard C
73
* __restrict is always recognized
74
*/
75
#define ZRESTRICT __restrict
76
77
#include <
zephyr/toolchain/common.h
>
78
#include <
stdbool.h
>
79
80
/* common.h defines ALWAYS_INLINE as inline __attribute__((always_inline)).
81
* IAR emits Go004 ("function cannot be inlined") for ALWAYS_INLINE functions
82
* when optimization is disabled (e.g. debug builds). This is expected and
83
* unavoidable. Override the macro here to silence Go004 at each call site
84
* via the C99 _Pragma operator, removing the need for per-function guard
85
* pairs throughout the codebase.
86
*/
87
#ifndef CONFIG_COVERAGE
88
#undef ALWAYS_INLINE
89
#define ALWAYS_INLINE \
90
_Pragma("diag_suppress=Go004") inline __attribute__((always_inline))
91
#endif
92
93
#define ALIAS_OF(of) __attribute__((alias(#of)))
94
95
#define FUNC_ALIAS(real_func, new_alias, return_type) \
96
return_type new_alias() ALIAS_OF(real_func)
97
98
#define CODE_UNREACHABLE __builtin_unreachable()
99
#define FUNC_NORETURN __attribute__((__noreturn__))
100
101
#define _NODATA_SECTION(segment) __attribute__((section(#segment)))
102
103
/* Unaligned access */
104
#define UNALIGNED_GET(p) \
105
__extension__ ({ \
106
struct __attribute__((__packed__)) { \
107
__typeof__(*(p)) __v; \
108
} *__p = (__typeof__(__p)) (p); \
109
__p->__v; \
110
})
111
112
#define UNALIGNED_PUT(v, p) \
113
do { \
114
struct __attribute__((__packed__)) { \
115
__typeof__(*p) __v; \
116
} *__p = (__typeof__(__p)) (p); \
117
__p->__v = (v); \
118
} while (false)
119
120
121
/* Double indirection to ensure section names are expanded before
122
* stringification
123
*/
124
#define __GENERIC_SECTION(segment) __attribute__((section(STRINGIFY(segment))))
125
#define Z_GENERIC_SECTION(segment) __GENERIC_SECTION(segment)
126
127
#define __GENERIC_DOT_SECTION(segment) \
128
__attribute__((section("." STRINGIFY(segment))))
129
#define Z_GENERIC_DOT_SECTION(segment) __GENERIC_DOT_SECTION(segment)
130
131
#define ___in_section(a, b, c) \
132
__attribute__((section("." Z_STRINGIFY(a) \
133
"." Z_STRINGIFY(b) \
134
"." Z_STRINGIFY(c))))
135
#define __in_section(a, b, c) ___in_section(a, b, c)
136
137
#define ___in_section_unique(a, b) \
138
__attribute__((section("." Z_STRINGIFY(a) \
139
"." __FILE__ \
140
"." Z_STRINGIFY(b))))
141
142
#define __in_section_unique(seg) ___in_section_unique(seg, __COUNTER__)
143
144
#define __in_section_unique_named(seg, name) ___in_section_unique(seg, name)
145
146
/* When using XIP, using '__ramfunc' places a function into RAM instead
147
* of FLASH. Make sure '__ramfunc' is defined only when
148
* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT is defined, so that the compiler can
149
* report an error if '__ramfunc' is used but the architecture does not
150
* support it.
151
*/
152
#if !defined(CONFIG_XIP)
153
#define __ramfunc
154
#elif defined(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT)
155
/* Use this instead of the IAR keyword __ramfunc to make sure it
156
* ends up in the correct section.
157
*/
158
#define __ramfunc __attribute__((noinline, section(".ramfunc")))
159
#endif
/* !CONFIG_XIP */
160
161
#ifndef __fallthrough
162
/* TG-WG: ICCARM does not support __fallthrough */
163
#define __fallthrough [[fallthrough]]
164
#endif
165
166
#ifndef __packed
167
#define __packed __attribute__((__packed__))
168
#endif
169
170
#ifndef __aligned
171
#define __aligned(x) __attribute__((__aligned__(x)))
172
#endif
173
174
#ifndef __noinline
175
#define __noinline __attribute__((noinline))
176
#endif
177
178
#if defined(__cplusplus)
179
#define __alignof(x) alignof(x)
180
#else
181
#define __alignof(x) _Alignof(x)
182
#endif
183
184
#define __may_alias __attribute__((__may_alias__))
185
186
#ifndef __printf_like
187
/*
188
* The Zephyr stdint convention enforces int32_t = int, int64_t = long long,
189
* and intptr_t = long so that short string format length modifiers can be
190
* used universally across ILP32 and LP64 architectures. Without that it
191
* is possible for ILP32 toolchains to have int32_t = long and intptr_t = int
192
* clashing with the Zephyr convention and generating pointless warnings
193
* as they're still the same size. Inhibit the format argument type
194
* validation in that case and let the other configs do it.
195
*/
196
#define __printf_like(f, a)
197
#endif
198
199
#define __used __attribute__((__used__))
200
#define __unused __attribute__((__unused__))
201
#define __maybe_unused __attribute__((__unused__))
202
203
#ifndef __deprecated
204
#define __deprecated __attribute__((deprecated))
205
#endif
206
207
#ifndef __deprecated_version
208
#define __deprecated_version(version) \
209
__attribute__((deprecated("planned removal in v" #version)))
210
#endif
211
212
#define FUNC_NO_STACK_PROTECTOR _Pragma("no_stack_protect")
213
214
#ifndef __attribute_const__
215
#if __VER__ > 0x09000000
216
#define __attribute_const__ __attribute__((const))
217
#else
218
#define __attribute_const__
219
#endif
220
#endif
221
222
#ifndef __must_check
223
/* #warning "The attribute __warn_unused_result is not supported in ICCARM". */
224
#define __must_check
225
/* #define __must_check __attribute__((warn_unused_result)) */
226
#endif
227
228
#define __PRAGMA(...) _Pragma(#__VA_ARGS__)
229
#define ARG_UNUSED(x) (void)(x)
230
231
#define likely(x) (__builtin_expect((bool)!!(x), true) != 0L)
232
#define unlikely(x) (__builtin_expect((bool)!!(x), false) != 0L)
233
#define POPCOUNT(x) __builtin_popcount(x)
234
235
#ifndef __no_optimization
236
#define __no_optimization __PRAGMA(optimize = none)
237
#endif
238
239
#ifndef __attribute_nonnull
240
#define __attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
241
#endif
242
243
/* __weak is an ICCARM built-in, but it doesn't work in all positions */
244
/* the Zephyr uses it so we replace it with an attribute((weak)) */
245
#define __weak __attribute__((__weak__))
246
247
/* Builtins */
248
249
#include <intrinsics.h>
250
251
/*
252
* Be *very* careful with these. You cannot filter out __DEPRECATED_MACRO with
253
* -wno-deprecated, which has implications for -Werror.
254
*/
255
256
257
/*
258
* Expands to nothing and generates a warning. Used like
259
*
260
* #define FOO __WARN("Please use BAR instead") ...
261
*
262
* The warning points to the location where the macro is expanded.
263
*/
264
#define __WARN(s) __PRAGMA(message = #s)
265
#define __WARN1(s) __PRAGMA(message = #s)
266
267
/* Generic message */
268
#if !(defined(CONFIG_DEPRECATION_TEST) || !defined(CONFIG_WARN_DEPRECATED))
269
#define __DEPRECATED_MACRO __WARN("Macro is deprecated")
270
#else
271
#define __DEPRECATED_MACRO
272
#endif
273
274
275
276
/* These macros allow having ARM asm functions callable from thumb */
277
278
#if defined(_ASMLANGUAGE)
279
280
#if defined(CONFIG_ASSEMBLER_ISA_THUMB2)
281
#define FUNC_CODE() .code 32
282
#define FUNC_INSTR(a)
283
/* '.syntax unified' is a gcc-ism used in thumb-2 asm files */
284
#define _ASM_FILE_PROLOGUE .text; .syntax unified; .thumb
285
#else
286
#define FUNC_CODE()
287
#define FUNC_INSTR(a)
288
#define _ASM_FILE_PROLOGUE .text; .code 32
289
#endif
/* CONFIG_ASSEMBLER_ISA_THUMB2 */
290
291
/*
292
* These macros are used to declare assembly language symbols that need
293
* to be typed properly(func or data) to be visible to the OMF tool.
294
* So that the build tool could mark them as an entry point to be linked
295
* correctly. This is an elfism. Use #if 0 for a.out.
296
*/
297
298
/* This is not implemented yet for IAR */
299
#define GTEXT(sym)
300
#define GDATA(sym)
301
#define WTEXT(sym)
302
#define WDATA(sym)
303
304
#define SECTION_VAR(sect, sym)
305
#define SECTION_FUNC(sect, sym)
306
#define SECTION_SUBSEC_FUNC(sect, subsec, sym)
307
308
#endif
/* _ASMLANGUAGE */
309
310
311
/*
312
* These macros generate absolute symbols for IAR
313
*/
314
315
/* create an extern reference to the absolute symbol */
316
317
#define GEN_OFFSET_EXTERN(name) extern const char name[]
318
319
#define GEN_ABS_SYM_BEGIN(name) \
320
EXTERN_C void name(void); \
321
void name(void) \
322
{
323
324
#define GEN_ABS_SYM_END }
325
326
/*
327
* Note that GEN_ABSOLUTE_SYM(), depending on the architecture
328
* and toolchain, may restrict the range of values permitted
329
* for assignment to the named symbol.
330
*/
331
#define GEN_ABSOLUTE_SYM(name, value) \
332
__PRAGMA(public_equ = #name, (unsigned int)value)
333
334
/*
335
* GEN_ABSOLUTE_SYM_KCONFIG() is outputted by the build system
336
* to generate named symbol/value pairs for kconfigs.
337
*/
338
#define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \
339
__PRAGMA(public_equ = #name, (unsigned int)value)
340
341
#define compiler_barrier() do { \
342
__asm volatile("" ::: "memory"); \
343
} while (false)
344
351
#define Z_POW2_CEIL(x) \
352
((x) <= 2UL ? (x) : (1UL << (8 * sizeof(long) - __builtin_clzl((x) - 1))))
353
360
#define Z_IS_POW2(x) (((x) != 0) && (((x) & ((x)-1)) == 0))
361
362
#ifndef __INT8_C
363
#define __INT8_C(x) x
364
#endif
365
366
#ifndef INT8_C
367
#define INT8_C(x) __INT8_C(x)
368
#endif
369
370
#ifndef __UINT8_C
371
#define __UINT8_C(x) x ## U
372
#endif
373
374
#ifndef UINT8_C
375
#define UINT8_C(x) __UINT8_C(x)
376
#endif
377
378
#ifndef __INT16_C
379
#define __INT16_C(x) x
380
#endif
381
382
#ifndef INT16_C
383
#define INT16_C(x) __INT16_C(x)
384
#endif
385
386
#ifndef __UINT16_C
387
#define __UINT16_C(x) x ## U
388
#endif
389
390
#ifndef UINT16_C
391
#define UINT16_C(x) __UINT16_C(x)
392
#endif
393
394
#ifndef __INT32_C
395
#define __INT32_C(x) x
396
#endif
397
398
#ifndef INT32_C
399
#define INT32_C(x) __INT32_C(x)
400
#endif
401
402
#ifndef __UINT32_C
403
#define __UINT32_C(x) x ## U
404
#endif
405
406
#ifndef UINT32_C
407
#define UINT32_C(x) __UINT32_C(x)
408
#endif
409
410
#ifndef __INT64_C
411
#define __INT64_C(x) x ## LL
412
#endif
413
414
#ifndef INT64_C
415
#define INT64_C(x) __INT64_C(x)
416
#endif
417
418
#ifndef __UINT64_C
419
#define __UINT64_C(x) x ## ULL
420
#endif
421
422
#ifndef UINT64_C
423
#define UINT64_C(x) __UINT64_C(x)
424
#endif
425
426
/* Convenience macros */
427
#undef _GLUE_B
428
#undef _GLUE
429
#define _GLUE_B(x, y) x##y
430
#define _GLUE(x, y) _GLUE_B(x, y)
431
432
#ifndef INTMAX_C
433
#define INTMAX_C(x) _GLUE(x, __INTMAX_C_SUFFIX__)
434
#endif
435
436
#ifndef UINTMAX_C
437
#define UINTMAX_C(x) _GLUE(x, __UINTMAX_C_SUFFIX__)
438
#endif
439
440
#endif
/* !_LINKER */
441
#endif
/* ZEPHYR_INCLUDE_TOOLCHAIN_ICCARM_H_ */
common.h
Common toolchain abstraction.
stdbool.h
include
zephyr
toolchain
iar
iccarm.h
Generated on
for Zephyr Project API by
1.16.1