VSF Documented
arm_compiler.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __USE_ARM_COMPILER_H_PART_1__
19#define __USE_ARM_COMPILER_H_PART_1__
20
21/*============================ INCLUDES ======================================*/
22
24
25#endif /* end of __USE_ARM_COMPILER_H_PART_1__ */
26
27/*========================== Multiple-Entry Start ============================*/
28
29#if defined(__IS_COMPILER_IAR__) && __IS_COMPILER_IAR__
30# include <intrinsics.h>
31#endif
32
33#ifndef __VSF_HEADER_ONLY_SHOW_COMPILER_INFO__
34# include "./type.h"
35#endif
36#include "../__common/__compiler.h"
37
38/*----------------------------------------------------------------------------*
39 * Overwrite MAX_CONSTRUCTOR_PRIORITY if necessary *
40 *----------------------------------------------------------------------------*/
41#if __IS_COMPILER_ARM_COMPILER_5__ \
42 || __IS_COMPILER_ARM_COMPILER_6__
43// TODO: what is the real MAX_CONSTRUCTOR_PRIORITY for arm-compiler 5/6?
44# ifndef MAX_CONSTRUCTOR_PRIORITY
45# define MAX_CONSTRUCTOR_PRIORITY 65535
46# endif
47#elif __IS_COMPILER_GCC__
48// TODO: as test, priority of 65535 is lower than 0, 65534 is the max priority
49# undef MAX_CONSTRUCTOR_PRIORITY
50# define MAX_CONSTRUCTOR_PRIORITY 65534
51#endif
52
53#ifndef VSF_UTILITIES_REQ___CMSIS_HEADER_FILE__FROM_USR
54#include "cmsis_compiler.h"
55#else
56#include VSF_UTILITIES_REQ___CMSIS_HEADER_FILE__FROM_USR
57#endif
58
59/*========================== Multiple-Entry End ==============================*/
60
61
62#ifndef __USE_ARM_COMPILER_H_PART_2__
63#define __USE_ARM_COMPILER_H_PART_2__
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* ----------------- Start of section using anonymous unions -------------- */
70#if __IS_COMPILER_ARM_COMPILER_5__
71 //#pragma push
72 #pragma anon_unions
73#elif __IS_COMPILER_ARM_COMPILER_6__
74#elif __IS_COMPILER_IAR__
75 #pragma language=extended
76// in new iar, FILE must be derived from __FILE struct
77 #define __VSF_STDIO_INTERNAL_FILE_NAME __FILE
78#elif __IS_COMPILER_GCC__
79/* anonymous unions are enabled by default */
80 #if __GNUC__ <= 7
81 #define __COMPILER_HAS_NO_NEXTTOWARDF_IN_MATH__
82 #endif
83#elif __IS_COMPILER_LLVM__
84/* anonymous unions are enabled by default */
85#elif defined(__TMS470__)
86/* anonymous unions are enabled by default */
87#elif defined(__TASKING__)
88 #pragma warning 586
89#else
90 #warning Not supported compiler type
91#endif
92
93/*----------------------------------------------------------------------------*
94 * Warning Mitigation *
95 *----------------------------------------------------------------------------*/
96
97#if __IS_COMPILER_ARM_COMPILER_6__
98# pragma clang diagnostic ignored "-Wdollar-in-identifier-extension"
99#endif
100
101
102
103/*============================ MACROS ========================================*/
104
106#ifndef NOP
107 #define NOP() __asm__ __volatile__ ("nop");
108#endif
109
110
112
113#if __IS_COMPILER_GCC__
114# undef __VSF_CAL_AT_ADDR
115# define __VSF_CAL_AT_ADDR(__ADDR) __attribute__((section(".ARM.__at_" #__ADDR)))
116#elif __IS_COMPILER_IAR__
117# define LOW_LEVEL_INIT_RET_T int
118# define VSF_CAL_NO_INIT __no_init
119# define VSF_CAL_NO_RETURN __attribute__((noreturn))
120# define VSF_CAL_ROOT __root
121# define VSF_CAL_INLINE inline
122# define VSF_CAL_NO_INLINE __attribute__((noinline))
123# define VSF_CAL_ALWAYS_INLINE inline __attribute__((always_inline))
124# define VSF_CAL_WEAK(...) __weak
125# define VSF_CAL_RAMFUNC __ramfunc
126# define __asm__ __asm
127# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
128# define __VSF_CAL_AT_ADDR(__ADDR) @ __ADDR
129# define __VSF_CAL_SECTION(__SEC_STR) __attribute__((section (__SEC_STR)))
130# define VSF_CAL_SECTION_DECLARE(__SEC)
131# define VSF_CAL_SECTION_START(__SEC) __section_begin(#__SEC)
132# define VSF_CAL_SECTION_END(__SEC) __section_end(#__SEC)
133# define VSF_CAL_SECTION_SIZE(__SEC) __section_size(#__SEC)
134# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
135 _Pragma(__VSF_STR(weak __ORIGIN=__ALIAS))
136# define VSF_CAL_PACKED __attribute__((packed))
137# define VSF_CAL_UNALIGNED __packed
138# define VSF_CAL_NAKED __naked
139# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
140# define __VSF_CAL_ALIGN_OF(...) __ALIGNOF__(__VA_ARGS__)
141
142# define __IAR_STARTUP_DATA_INIT __iar_data_init3
143
144# define __VSF_CAL_ISR(__VEC) void __VEC(void)
145
146#elif __IS_COMPILER_ARM_COMPILER_5__
147# define VSF_CAL_NO_INIT __attribute__( ( section( ".bss.noinit"),zero_init) )
148# define VSF_CAL_NO_RETURN __attribute__((noreturn))
149# define VSF_CAL_ROOT __attribute__((used))
150# define VSF_CAL_INLINE __inline
151# define VSF_CAL_NO_INLINE __attribute__((noinline))
152# define VSF_CAL_ALWAYS_INLINE __inline __attribute__((always_inline))
153# define VSF_CAL_WEAK(...) __attribute__((weak))
154# define VSF_CAL_RAMFUNC __attribute__((section (".textrw")))
155# define __asm__ __asm
156# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
157# define __VSF_CAL_AT_ADDR(__ADDR) __attribute__((at(__ADDR)))
158# define __VSF_CAL_SECTION(__SEC_STR) __attribute__((section (__SEC_STR)))
159# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
160 __attribute__((weakref(__VSF_STR(__ALIAS))))
161
162# define VSF_CAL_PACKED __attribute__((packed))
163# define VSF_CAL_UNALIGNED __packed
164# define VSF_CAL_NAKED does AC5 support this?
165# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
166# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
167
168# define __VSF_CAL_ISR(__VEC) void __VEC(void)
169
170#elif __IS_COMPILER_ARM_COMPILER_6__
171# define VSF_CAL_NO_INIT __attribute__( ( section( ".bss.noinit")) )
172# define VSF_CAL_NO_RETURN __attribute__((noreturn))
173# define VSF_CAL_ROOT __attribute__((used))
174# define VSF_CAL_INLINE __inline
175# define VSF_CAL_NO_INLINE __attribute__((noinline))
176# define VSF_CAL_ALWAYS_INLINE __inline __attribute__((always_inline))
177# define VSF_CAL_WEAK(...) __attribute__((weak))
178# define VSF_CAL_RAMFUNC __attribute__((section (".textrw")))
179# define __asm__ __asm
180# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
181# define __VSF_CAL_AT_ADDR(__ADDR) __attribute__((section (".ARM.__at_" #__ADDR)))
182# define __VSF_CAL_SECTION(__SEC_STR) __attribute__((section (__SEC_STR)))
183# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
184 __attribute__((weakref(__VSF_STR(__ALIAS))))
185
186# define VSF_CAL_PACKED __attribute__((packed))
187# define VSF_CAL_UNALIGNED __unaligned
188# define VSF_CAL_NAKED __attribute__((naked))
189# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
190# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
191
192# define __VSF_CAL_ISR(__VEC) void __VEC(void)
193#endif
194
195/*----------------------------------------------------------------------------*
196 * Signal & Interrupt Definition *
197 *----------------------------------------------------------------------------*/
198
200#if __IS_COMPILER_IAR__
201# define ENABLE_GLOBAL_INTERRUPT() __enable_interrupt()
202#else
203# define ENABLE_GLOBAL_INTERRUPT() __enable_irq()
204#endif
205
207#if __IS_COMPILER_IAR__
208# define DISABLE_GLOBAL_INTERRUPT() ____disable_irq()
210static VSF_CAL_ALWAYS_INLINE uint32_t ____disable_irq(void)
211{
212 uint32_t wPRIMASK = __get_interrupt_state();
213 __disable_interrupt();
214 return wPRIMASK;
215}
216
217#elif __IS_COMPILER_ARM_COMPILER_5__
218# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
219#elif __IS_COMPILER_ARM_COMPILER_6__ && !defined(__CMSIS_ARMCC_V6_H)
220# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
221#elif __IS_COMPILER_GCC_
222# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
223#else /* for other compilers, using gcc assembly syntax to implement */
224
225# define DISABLE_GLOBAL_INTERRUPT() ____disable_irq()
226
227static VSF_CAL_ALWAYS_INLINE uint32_t ____disable_irq(void)
229 uint32_t cpsr;
230
231 __asm__ __volatile__("mrs %[cpsr], primask\n"
232 "cpsid i\n"
233 : [cpsr] "=r"(cpsr));
234 return cpsr & 0x1;
235}
236#endif
237
238#if __IS_COMPILER_IAR__
239# define GET_GLOBAL_INTERRUPT_STATE() __get_interrupt_state()
240# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_interrupt_state(__STATE)
241typedef __istate_t vsf_gint_state_t;
242#elif __IS_COMPILER_ARM_COMPILER_5__ || __IS_COMPILER_ARM_COMPILER_6__
243# define GET_GLOBAL_INTERRUPT_STATE() __get_PRIMASK()
244# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_PRIMASK(__STATE)
246#elif __IS_COMPILER_GCC__
247# define GET_GLOBAL_INTERRUPT_STATE() __get_PRIMASK()
248# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_PRIMASK(__STATE)
250#else
252# define GET_GLOBAL_INTERRUPT_STATE() ____get_PRIMASK()
253
259VSF_CAL_ALWAYS_INLINE static inline uint32_t ____get_PRIMASK(void)
260{
261 unsigned int result;
262
263 __asm__ volatile ("MRS %0, primask" : "=r" (result) );
264 return(result);
265}
266
267# define SET_GLOBAL_INTERRUPT_STATE(__STATE) ____set_PRIMASK(__STATE)
268
274VSF_CAL_ALWAYS_INLINE static inline void ____set_PRIMASK(uint32_t priMask)
275{
276 __asm__ volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
277}
278#endif
279
280/*----------------------------------------------------------------------------*
281 * Startup Source Code *
282 *----------------------------------------------------------------------------*/
283#if __IS_COMPILER_IAR__
284
285#ifndef __VECTOR_TABLE
286# define __VECTOR_TABLE __vector_table
287#endif
288#ifndef __VECTOR_TABLE_ATTRIBUTE
289# define __VECTOR_TABLE_ATTRIBUTE @".intvec"
290#endif
291#ifndef __PROGRAM_START
292# define __PROGRAM_START __iar_program_start
293#endif
294#ifndef __INITIAL_SP
295# define __INITIAL_SP CSTACK$$Limit
296#endif
297
298#elif __IS_COMPILER_ARM_COMPILER_6__ || __IS_COMPILER_ARM_COMPILER_5__
299
300#ifndef __VECTOR_TABLE
301# define __VECTOR_TABLE __Vectors
302#endif
303#ifndef __VECTOR_TABLE_ATTRIBUTE
304# define __VECTOR_TABLE_ATTRIBUTE ROOT SECTION("RESET")
305#endif
306#ifndef __PROGRAM_START
307# define __PROGRAM_START __main
308#endif
309#ifndef __INITIAL_SP
310# define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit
311#endif
312
313#else //__IS_COMPILER_GCC__ || __IS_COMPILER_LLVM__
314
315#ifndef __PROGRAM_START
316#define __PROGRAM_START __cmsis_start
317
318#endif
320#ifndef __INITIAL_SP
321#define __INITIAL_SP __StackTop
322#endif
323
324#ifndef __STACK_LIMIT
325#define __STACK_LIMIT __StackLimit
326#endif
327
328#ifndef __VECTOR_TABLE
329#define __VECTOR_TABLE __Vectors
330#endif
331
332#ifndef __VECTOR_TABLE_ATTRIBUTE
333#define __VECTOR_TABLE_ATTRIBUTE __attribute((used, section(".vectors")))
334#endif
335#endif
337/*============================ TYPES =========================================*/
338/*============================ PROTOTYPES ====================================*/
339
340#ifdef __cplusplus
341}
342#endif
343
344#endif /* end of __USE_ARM_COMPILER_H_PART_2__ */
345
346
347
#define __volatile__
Definition __compiler.h:56
uint32_t vsf_gint_state_t
Definition arm_compiler.h:254
unsigned uint32_t
Definition stdint.h:9
Generated from commit: vsfteam/vsf@1e0abbc