Zephyr API Documentation
4.3.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
#define ALIAS_OF(of) __attribute__((alias(#of)))
81
82
#define FUNC_ALIAS(real_func, new_alias, return_type) \
83
return_type new_alias() ALIAS_OF(real_func)
84
85
#define CODE_UNREACHABLE __builtin_unreachable()
86
#define FUNC_NORETURN __attribute__((__noreturn__))
87
88
#define _NODATA_SECTION(segment) __attribute__((section(#segment)))
89
90
/* Unaligned access */
91
#define UNALIGNED_GET(p) \
92
__extension__ ({ \
93
struct __attribute__((__packed__)) { \
94
__typeof__(*(p)) __v; \
95
} *__p = (__typeof__(__p)) (p); \
96
__p->__v; \
97
})
98
99
#define UNALIGNED_PUT(v, p) \
100
do { \
101
struct __attribute__((__packed__)) { \
102
__typeof__(*p) __v; \
103
} *__p = (__typeof__(__p)) (p); \
104
__p->__v = (v); \
105
} while (false)
106
107
108
/* Double indirection to ensure section names are expanded before
109
* stringification
110
*/
111
#define __GENERIC_SECTION(segment) __attribute__((section(STRINGIFY(segment))))
112
#define Z_GENERIC_SECTION(segment) __GENERIC_SECTION(segment)
113
114
#define __GENERIC_DOT_SECTION(segment) \
115
__attribute__((section("." STRINGIFY(segment))))
116
#define Z_GENERIC_DOT_SECTION(segment) __GENERIC_DOT_SECTION(segment)
117
118
#define ___in_section(a, b, c) \
119
__attribute__((section("." Z_STRINGIFY(a) \
120
"." Z_STRINGIFY(b) \
121
"." Z_STRINGIFY(c))))
122
#define __in_section(a, b, c) ___in_section(a, b, c)
123
124
#define ___in_section_unique(a, b) \
125
__attribute__((section("." Z_STRINGIFY(a) \
126
"." __FILE__ \
127
"." Z_STRINGIFY(b))))
128
129
#define __in_section_unique(seg) ___in_section_unique(seg, __COUNTER__)
130
131
#define __in_section_unique_named(seg, name) ___in_section_unique(seg, name)
132
133
/* When using XIP, using '__ramfunc' places a function into RAM instead
134
* of FLASH. Make sure '__ramfunc' is defined only when
135
* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT is defined, so that the compiler can
136
* report an error if '__ramfunc' is used but the architecture does not
137
* support it.
138
*/
139
#if !defined(CONFIG_XIP)
140
#define __ramfunc
141
#elif defined(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT)
142
/* Use this instead of the IAR keyword __ramfunc to make sure it
143
* ends up in the correct section.
144
*/
145
#define __ramfunc __attribute__((noinline, section(".ramfunc")))
146
#endif
/* !CONFIG_XIP */
147
148
#ifndef __fallthrough
149
/* TG-WG: ICCARM does not support __fallthrough */
150
#define __fallthrough [[fallthrough]]
151
#endif
152
153
#ifndef __packed
154
#define __packed __attribute__((__packed__))
155
#endif
156
157
#ifndef __aligned
158
#define __aligned(x) __attribute__((__aligned__(x)))
159
#endif
160
161
#ifndef __noinline
162
#define __noinline __attribute__((noinline))
163
#endif
164
165
#if defined(__cplusplus)
166
#define __alignof(x) alignof(x)
167
#else
168
#define __alignof(x) _Alignof(x)
169
#endif
170
171
#define __may_alias __attribute__((__may_alias__))
172
173
#ifndef __printf_like
174
/*
175
* The Zephyr stdint convention enforces int32_t = int, int64_t = long long,
176
* and intptr_t = long so that short string format length modifiers can be
177
* used universally across ILP32 and LP64 architectures. Without that it
178
* is possible for ILP32 toolchains to have int32_t = long and intptr_t = int
179
* clashing with the Zephyr convention and generating pointless warnings
180
* as they're still the same size. Inhibit the format argument type
181
* validation in that case and let the other configs do it.
182
*/
183
#define __printf_like(f, a)
184
#endif
185
186
#define __used __attribute__((__used__))
187
#define __unused __attribute__((__unused__))
188
#define __maybe_unused __attribute__((__unused__))
189
190
#ifndef __deprecated
191
#define __deprecated __attribute__((deprecated))
192
#endif
193
194
#ifndef __deprecated_version
195
#define __deprecated_version(version) \
196
__attribute__((deprecated("planned removal in v" #version)))
197
#endif
198
199
#define FUNC_NO_STACK_PROTECTOR _Pragma("no_stack_protect")
200
201
#ifndef __attribute_const__
202
#if __VER__ > 0x09000000
203
#define __attribute_const__ __attribute__((const))
204
#else
205
#define __attribute_const__
206
#endif
207
#endif
208
209
#ifndef __must_check
210
/* #warning "The attribute __warn_unused_result is not supported in ICCARM". */
211
#define __must_check
212
/* #define __must_check __attribute__((warn_unused_result)) */
213
#endif
214
215
#define __PRAGMA(...) _Pragma(#__VA_ARGS__)
216
#define ARG_UNUSED(x) (void)(x)
217
218
#define likely(x) (__builtin_expect((bool)!!(x), true) != 0L)
219
#define unlikely(x) (__builtin_expect((bool)!!(x), false) != 0L)
220
#define POPCOUNT(x) __builtin_popcount(x)
221
222
#ifndef __no_optimization
223
#define __no_optimization __PRAGMA(optimize = none)
224
#endif
225
226
#ifndef __attribute_nonnull
227
#define __attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
228
#endif
229
230
/* __weak is an ICCARM built-in, but it doesn't work in all positions */
231
/* the Zephyr uses it so we replace it with an attribute((weak)) */
232
#define __weak __attribute__((__weak__))
233
234
/* Builtins */
235
236
#include <intrinsics.h>
237
238
/*
239
* Be *very* careful with these. You cannot filter out __DEPRECATED_MACRO with
240
* -wno-deprecated, which has implications for -Werror.
241
*/
242
243
244
/*
245
* Expands to nothing and generates a warning. Used like
246
*
247
* #define FOO __WARN("Please use BAR instead") ...
248
*
249
* The warning points to the location where the macro is expanded.
250
*/
251
#define __WARN(s) __PRAGMA(message = #s)
252
#define __WARN1(s) __PRAGMA(message = #s)
253
254
/* Generic message */
255
#if !(defined(CONFIG_DEPRECATION_TEST) || !defined(CONFIG_WARN_DEPRECATED))
256
#define __DEPRECATED_MACRO __WARN("Macro is deprecated")
257
#else
258
#define __DEPRECATED_MACRO
259
#endif
260
261
262
263
/* These macros allow having ARM asm functions callable from thumb */
264
265
#if defined(_ASMLANGUAGE)
266
267
#if defined(CONFIG_ASSEMBLER_ISA_THUMB2)
268
#define FUNC_CODE() .code 32
269
#define FUNC_INSTR(a)
270
/* '.syntax unified' is a gcc-ism used in thumb-2 asm files */
271
#define _ASM_FILE_PROLOGUE .text; .syntax unified; .thumb
272
#else
273
#define FUNC_CODE()
274
#define FUNC_INSTR(a)
275
#define _ASM_FILE_PROLOGUE .text; .code 32
276
#endif
/* CONFIG_ASSEMBLER_ISA_THUMB2 */
277
278
/*
279
* These macros are used to declare assembly language symbols that need
280
* to be typed properly(func or data) to be visible to the OMF tool.
281
* So that the build tool could mark them as an entry point to be linked
282
* correctly. This is an elfism. Use #if 0 for a.out.
283
*/
284
285
/* This is not implemented yet for IAR */
286
#define GTEXT(sym)
287
#define GDATA(sym)
288
#define WTEXT(sym)
289
#define WDATA(sym)
290
291
#define SECTION_VAR(sect, sym)
292
#define SECTION_FUNC(sect, sym)
293
#define SECTION_SUBSEC_FUNC(sect, subsec, sym)
294
295
#endif
/* _ASMLANGUAGE */
296
297
298
/*
299
* These macros generate absolute symbols for IAR
300
*/
301
302
/* create an extern reference to the absolute symbol */
303
304
#define GEN_OFFSET_EXTERN(name) extern const char name[]
305
306
#define GEN_ABS_SYM_BEGIN(name) \
307
EXTERN_C void name(void); \
308
void name(void) \
309
{
310
311
#define GEN_ABS_SYM_END }
312
313
/*
314
* Note that GEN_ABSOLUTE_SYM(), depending on the architecture
315
* and toolchain, may restrict the range of values permitted
316
* for assignment to the named symbol.
317
*/
318
#define GEN_ABSOLUTE_SYM(name, value) \
319
__PRAGMA(public_equ = #name, (unsigned int)value)
320
321
/*
322
* GEN_ABSOLUTE_SYM_KCONFIG() is outputted by the build system
323
* to generate named symbol/value pairs for kconfigs.
324
*/
325
#define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \
326
__PRAGMA(public_equ = #name, (unsigned int)value)
327
328
#define compiler_barrier() do { \
329
__asm volatile("" ::: "memory"); \
330
} while (false)
331
338
#define Z_POW2_CEIL(x) \
339
((x) <= 2UL ? (x) : (1UL << (8 * sizeof(long) - __builtin_clzl((x) - 1))))
340
347
#define Z_IS_POW2(x) (((x) != 0) && (((x) & ((x)-1)) == 0))
348
349
#ifndef __INT8_C
350
#define __INT8_C(x) x
351
#endif
352
353
#ifndef INT8_C
354
#define INT8_C(x) __INT8_C(x)
355
#endif
356
357
#ifndef __UINT8_C
358
#define __UINT8_C(x) x ## U
359
#endif
360
361
#ifndef UINT8_C
362
#define UINT8_C(x) __UINT8_C(x)
363
#endif
364
365
#ifndef __INT16_C
366
#define __INT16_C(x) x
367
#endif
368
369
#ifndef INT16_C
370
#define INT16_C(x) __INT16_C(x)
371
#endif
372
373
#ifndef __UINT16_C
374
#define __UINT16_C(x) x ## U
375
#endif
376
377
#ifndef UINT16_C
378
#define UINT16_C(x) __UINT16_C(x)
379
#endif
380
381
#ifndef __INT32_C
382
#define __INT32_C(x) x
383
#endif
384
385
#ifndef INT32_C
386
#define INT32_C(x) __INT32_C(x)
387
#endif
388
389
#ifndef __UINT32_C
390
#define __UINT32_C(x) x ## U
391
#endif
392
393
#ifndef UINT32_C
394
#define UINT32_C(x) __UINT32_C(x)
395
#endif
396
397
#ifndef __INT64_C
398
#define __INT64_C(x) x ## LL
399
#endif
400
401
#ifndef INT64_C
402
#define INT64_C(x) __INT64_C(x)
403
#endif
404
405
#ifndef __UINT64_C
406
#define __UINT64_C(x) x ## ULL
407
#endif
408
409
#ifndef UINT64_C
410
#define UINT64_C(x) __UINT64_C(x)
411
#endif
412
413
/* Convenience macros */
414
#undef _GLUE_B
415
#undef _GLUE
416
#define _GLUE_B(x, y) x##y
417
#define _GLUE(x, y) _GLUE_B(x, y)
418
419
#ifndef INTMAX_C
420
#define INTMAX_C(x) _GLUE(x, __INTMAX_C_SUFFIX__)
421
#endif
422
423
#ifndef UINTMAX_C
424
#define UINTMAX_C(x) _GLUE(x, __UINTMAX_C_SUFFIX__)
425
#endif
426
427
#endif
/* !_LINKER */
428
#endif
/* ZEPHYR_INCLUDE_TOOLCHAIN_ICCARM_H_ */
common.h
Common toolchain abstraction.
stdbool.h
zephyr
toolchain
iar
iccarm.h
Generated on
for Zephyr API Documentation by
1.15.0