1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*!
8  @addtogroup cc_pal_compiler
9  @{
10  */
11 
12 /*!
13  @file
14  @brief This file contains CryptoCell PAL platform-dependent compiler-related
15  definitions.
16  */
17 
18 
19 #ifndef __CC_PAL_COMPILER_H__
20 #define __CC_PAL_COMPILER_H__
21 
22 #ifdef __GNUC__
23 
24 /* *********************** Defines ******************************/
25 
26 /*! Associate a symbol with a link section. */
27 #define CC_PAL_COMPILER_SECTION(sectionName)  __attribute__((section(sectionName)))
28 
29 /*! Mark symbol as used, that is, prevent the garbage collector from
30 dropping it. */
31 #define CC_PAL_COMPILER_KEEP_SYMBOL __attribute__((used))
32 
33 /*! Align a given data item in bytes. */
34 #define CC_PAL_COMPILER_ALIGN(alignement)  __attribute__((aligned(alignement)))
35 
36 /*! Mark a function that never returns. */
37 #define CC_PAL_COMPILER_FUNC_NEVER_RETURNS __attribute__((noreturn))
38 
39 /*! Prevent a function from being inlined. */
40 #define CC_PAL_COMPILER_FUNC_DONT_INLINE __attribute__((noinline))
41 
42 /*! Given data type might serve as an alias for another data-type pointer. */
43 /* (this is used for "superclass" struct casting)             */
44 #define CC_PAL_COMPILER_TYPE_MAY_ALIAS __attribute__((__may_alias__))
45 
46 /*! Get the size of a structure-type member. */
47 #define CC_PAL_COMPILER_SIZEOF_STRUCT_MEMBER(type_name, member_name) \
48     sizeof(((type_name *)0)->member_name)
49 
50 /*! Definition of assertion. */
51 #define CC_ASSERT_CONCAT_(a, b) a##b
52 /*! Definition of assertion. */
53 #define CC_ASSERT_CONCAT(a, b) CC_ASSERT_CONCAT_(a, b)
54 /*! Definition of assertion. */
55 #define CC_PAL_COMPILER_ASSERT(cond, message) \
56     enum { CC_ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(cond)) }
57 
58 #elif defined(__ARM_DSM__)
59 #define inline
60 
61 /*! Associate a symbol with a link section. */
62 #define CC_PAL_COMPILER_SECTION(sectionName)  __attribute__((section(sectionName)))
63 
64 /*! Mark a symbol as used, that is, prevent garbage collector from
65 dropping it. */
66 #define CC_PAL_COMPILER_KEEP_SYMBOL __attribute__((used))
67 
68 /*! Align a given data item in bytes. */
69 #define CC_PAL_COMPILER_ALIGN(alignement)  __attribute__((aligned(alignement)))
70 
71 /*! Mark a function that never returns. */
72 #define CC_PAL_COMPILER_FUNC_NEVER_RETURNS __attribute__((noreturn))
73 
74 /*! Prevent a function from being inlined. */
75 #define CC_PAL_COMPILER_FUNC_DONT_INLINE __attribute__((noinline))
76 
77 /*! Given data type might serve as an alias for another data-type pointer. */
78 /* (this is used for "superclass" struct casting)             */
79 #define CC_PAL_COMPILER_TYPE_MAY_ALIAS __attribute__((__may_alias__))
80 
81 /*! Get the size of a structure-type member. */
82 #define CC_PAL_COMPILER_SIZEOF_STRUCT_MEMBER(type_name, member_name) \
83     sizeof(((type_name *)0)->member_name)
84 
85 /*! Definition of assertion. */
86 #define CC_ASSERT_CONCAT_(a, b) a##b
87 /*! Definition of assertion. */
88 #define CC_ASSERT_CONCAT(a, b) CC_ASSERT_CONCAT_(a, b)
89 /*! Definition of assertion. */
90 #define CC_PAL_COMPILER_ASSERT(cond, message) \
91     enum { CC_ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(cond)) }
92 
93 
94 #elif defined(__ARM_DS__)
95 #define inline
96 
97 /*! Associate a symbol with a link section. */
98 #define CC_PAL_COMPILER_SECTION(sectionName)  __attribute__((section(sectionName)))
99 
100 /*! Mark a symbol as used, that is, prevent garbage collector from
101 dropping it. */
102 #define CC_PAL_COMPILER_KEEP_SYMBOL __attribute__((used))
103 
104 /*! Align a given data item in bytes. */
105 #define CC_PAL_COMPILER_ALIGN(alignement)  __attribute__((aligned(alignement)))
106 
107 /*! Mark a function that never returns. */
108 #define CC_PAL_COMPILER_FUNC_NEVER_RETURNS __attribute__((noreturn))
109 
110 /*! Prevent a function from being inlined. */
111 #define CC_PAL_COMPILER_FUNC_DONT_INLINE __attribute__((noinline))
112 
113 /*! Given data type might serve as an alias for another data-type pointer. */
114 /* (this is used for "superclass" struct casting)             */
115 #define CC_PAL_COMPILER_TYPE_MAY_ALIAS
116 
117 /*! Get the size of a structure-type member. */
118 #define CC_PAL_COMPILER_SIZEOF_STRUCT_MEMBER(type_name, member_name) \
119     sizeof(((type_name *)0)->member_name)
120 
121 /*! Definition of assertion. */
122 #define CC_ASSERT_CONCAT_(a, b) a##b
123 /*! Definition of assertion. */
124 #define CC_ASSERT_CONCAT(a, b) CC_ASSERT_CONCAT_(a, b)
125 /*! Definition of assertion. */
126 #define CC_PAL_COMPILER_ASSERT(cond, message) \
127     enum { CC_ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(cond)) }
128 
129 
130 #elif defined(__ARM_DS5__)
131 #define inline __inline
132 
133 
134 /*! Associate a symbol with a link section. */
135 #define CC_PAL_COMPILER_SECTION(sectionName)  __attribute__((section(sectionName)))
136 
137 /*! Mark a symbol as used, that is, prevent garbage collector from
138 dropping it. */
139 #define CC_PAL_COMPILER_KEEP_SYMBOL __attribute__((used))
140 
141 /*! Align a given data item in bytes. */
142 #define CC_PAL_COMPILER_ALIGN(alignement)  __attribute__((aligned(alignement)))
143 
144 /*! Mark a function that never returns. */
145 #define CC_PAL_COMPILER_FUNC_NEVER_RETURNS __attribute__((noreturn))
146 
147 /*! Prevent a function from being inlined. */
148 #define CC_PAL_COMPILER_FUNC_DONT_INLINE __attribute__((noinline))
149 
150 /*! Given data type might serve as an alias for another data-type pointer. */
151 /* (this is used for "superclass" struct casting)             */
152 #define CC_PAL_COMPILER_TYPE_MAY_ALIAS
153 
154 /*! Get the size of a structure-type member. */
155 #define CC_PAL_COMPILER_SIZEOF_STRUCT_MEMBER(type_name, member_name) \
156     sizeof(((type_name *)0)->member_name)
157 
158 /*! Definition of assertion. */
159 #define CC_ASSERT_CONCAT_(a, b) a##b
160 /*! Definition of assertion. */
161 #define CC_ASSERT_CONCAT(a, b) CC_ASSERT_CONCAT_(a, b)
162 /*! Definition of assertion. */
163 #define CC_PAL_COMPILER_ASSERT(cond, message) \
164     enum { CC_ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(cond)) }
165 
166 #elif defined(__ICCARM__)
167 #define inline __inline
168 
169 
170 /*! Associate a symbol with a link section. */
171 #define CC_PAL_COMPILER_SECTION(sectionName)  __attribute__((section(sectionName)))
172 
173 /*! Mark a symbol as used, that is, prevent garbage collector from
174 dropping it. */
175 #define CC_PAL_COMPILER_KEEP_SYMBOL __attribute__((used))
176 
177 /*! Align a given data item in bytes. */
178 #define CC_PAL_COMPILER_ALIGN(alignement)  __attribute__((aligned(alignement)))
179 
180 /*! Mark a function that never returns. */
181 #define CC_PAL_COMPILER_FUNC_NEVER_RETURNS __attribute__((noreturn))
182 
183 /*! Prevent a function from being inlined. */
184 #define CC_PAL_COMPILER_FUNC_DONT_INLINE __attribute__((noinline))
185 
186 /*! Given data type might serve as an alias for another data-type pointer. */
187 /* (this is used for "superclass" struct casting)             */
188 #define CC_PAL_COMPILER_TYPE_MAY_ALIAS
189 
190 /*! Get the size of a structure-type member. */
191 #define CC_PAL_COMPILER_SIZEOF_STRUCT_MEMBER(type_name, member_name) \
192     sizeof(((type_name *)0)->member_name)
193 
194 /*! Definition of assertion. */
195 #define CC_ASSERT_CONCAT_(a, b) a##b
196 /*! Definition of assertion. */
197 #define CC_ASSERT_CONCAT(a, b) CC_ASSERT_CONCAT_(a, b)
198 /*! Definition of assertion. */
199 #define CC_PAL_COMPILER_ASSERT(cond, message) \
200     enum { CC_ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(cond)) }
201 
202 #else
203 #error Unsupported compiler.
204 #endif
205 
206 /*!
207  @}
208  */
209 
210 #endif /*__CC_PAL_COMPILER_H__*/
211