aboutsummaryrefslogtreecommitdiff
path: root/platform/atm2/ATM22xx-x1x/include/armgcc/compiler.h
blob: 25f461012a77a5783d610dc33db55d7c7a3d9dd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
 *******************************************************************************
 *
 * @file compiler.h
 *
 * @brief Definitions of compiler specific directives.
 *
 * Copyright (C) RivieraWaves 2009-2015
 * Copyright (C) Atmosic 2017-2023
 *
 *******************************************************************************
 */

#pragma once

/**
 * @defgroup COMPILER Compiler
 * @ingroup ATMx2
 * @brief GNU gcc compiler interface
 * @{
 */

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef __GNUC__
#error "File only included with ARM GCC"
#endif // __GNUC__

/// define the static keyword for this compiler
#define __STATIC static

/// define the force inlining attribute for this compiler
#define __INLINE __attribute__((__always_inline__)) static inline

/// define the IRQ handler attribute for this compiler
#define __IRQ __attribute__((__interrupt__("IRQ")))

/// define the BLE IRQ handler attribute for this compiler
#define __BTIRQ

/// define the BLE IRQ handler attribute for this compiler
#ifndef CFG_ROM
#define __BLEIRQ __attribute__((section(".data_text")))
#else
#define __BLEIRQ
#endif

/// define the FIQ handler attribute for this compiler
#define __FIQ __attribute__((__interrupt__("FIQ")))

/// define size of an empty array (used to declare structure with an array size not defined)
#define __ARRAY_EMPTY

/// Function returns struct in registers (4 in rvds, var with gnuarm).
/// With Gnuarm, feature depends on command line options and
/// impacts ALL functions returning 2-words max structs
/// (check -freg-struct-return and -mabi=xxx)
#define __VIR

/// function has no side effect and return depends only on arguments
#define __PURE __attribute__((const))
#define __PUREISH __attribute__((pure))

/// Function never returns
#define __NORETURN __attribute__((noreturn))

/// Align instantiated lvalue or struct member on 4 bytes
#define __ALIGN4 __attribute__((aligned(4)))

/// __MODULE__ comes from the RVDS compiler that supports it
#ifndef __MODULE__
#define __MODULE__ __BASE_FILE__
#endif

/// Pack a structure field
#define __PACKED __attribute__ ((__packed__))

/// Put a variable in a memory maintained during deep sleep
#define __LOWPOWER_SAVED

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define AT __MODULE__ ":" TOSTRING(__LINE__)

/// Do not initialize variable at startup
/// Create unique section header @file+line
#define __UNINIT __attribute__((section(".uninit." AT)))
#ifndef CFG_ROM
#define __UNINIT_NAMED(__s) __UNINIT
#else
#define __UNINIT_NAMED(__s) __attribute__((section(".uninit" __s)))
#endif

/// Locate code in high performance memory
#ifndef CFG_ROM
/// Create unique section header @file+line
#define __FAST __attribute__((section(".data_text." AT)))
#else
#define __FAST
#endif

/// Export everything for ROM
#ifdef CFG_ROM
#define __NR_STATIC
#else
#define __NR_STATIC	static
#endif

/// Compile-time assertion
#define STATIC_ASSERT	_Static_assert

/// Unused variable
#define __UNUSED __attribute__((unused))

/// Convert context pointer from const to non-const
#define CONTEXT_VOID_P(__p) ({ \
    __typeof__(__p) __tmp = (__p); \
    __builtin_choose_expr( \
	__builtin_types_compatible_p(__typeof__(__tmp), void const *), \
	(void *)(uintptr_t)__tmp, __tmp); \
})

/// Printf-like function
#define __PRINTF(...) __attribute__((format(printf, ##__VA_ARGS__)))

/// Arguments not permitting NULL value
#define __NONNULL_ALL __attribute__((nonnull))
#define __NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))

/// Field position in compound object
#define __OFFSET(__s, __f) offsetof(__typeof__(__s), __f)

/// Constructor priority
#define __CONSTRUCTOR_PRIO(__p) __attribute__((constructor(__p)))

/// Convert structured struct with different type name
#define TYPE_CONVERT(src_type, var, dst_type) ({ \
    STATIC_ASSERT(__builtin_types_compatible_p(src_type, __typeof__(var)) && \
    (sizeof(src_type) == sizeof(dst_type)), "incompatible"); \
    *(dst_type const *)&var;})

#ifdef __cplusplus
}
#endif

/// @} COMPILER