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#if __IS_COMPILER_IAR__
113# define LOW_LEVEL_INIT_RET_T int
114# define VSF_CAL_NO_INIT __no_init
115# define VSF_CAL_NO_RETURN __attribute__((noreturn))
116# define VSF_CAL_ROOT __root
117# define VSF_CAL_INLINE inline
118# define VSF_CAL_NO_INLINE __attribute__((noinline))
119# define VSF_CAL_ALWAYS_INLINE inline __attribute__((always_inline))
120# define VSF_CAL_WEAK(...) __weak
121# define VSF_CAL_RAMFUNC __ramfunc
122# define __asm__ __asm
123# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
124# define __VSF_CAL_AT_ADDR(__ADDR) @ __ADDR
125# define __VSF_CAL_SECTION(__SEC) __attribute__((section (__SEC)))
126# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
127 _Pragma(__VSF_STR(weak __ORIGIN=__ALIAS))
128# define VSF_CAL_PACKED __attribute__((packed))
129# define VSF_CAL_UNALIGNED __packed
130# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
131# define __VSF_CAL_ALIGN_OF(...) __ALIGNOF__(__VA_ARGS__)
132
133# define __IAR_STARTUP_DATA_INIT __iar_data_init3
134
135# define __VSF_CAL_ISR(__VEC) void __VEC(void)
136
137#elif __IS_COMPILER_ARM_COMPILER_5__
138# define VSF_CAL_NO_INIT __attribute__( ( section( ".bss.noinit"),zero_init) )
139# define VSF_CAL_NO_RETURN __attribute__((noreturn))
140# define VSF_CAL_ROOT __attribute__((used))
141# define VSF_CAL_INLINE __inline
142# define VSF_CAL_NO_INLINE __attribute__((noinline))
143# define VSF_CAL_ALWAYS_INLINE __inline __attribute__((always_inline))
144# define VSF_CAL_WEAK(...) __attribute__((weak))
145# define VSF_CAL_RAMFUNC __attribute__((section (".textrw")))
146# define __asm__ __asm
147# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
148# define __VSF_CAL_AT_ADDR(__ADDR) __attribute__((at(__ADDR)))
149# define __VSF_CAL_SECTION(__SEC) __attribute__((section (__SEC)))
150# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
151 __attribute__((weakref(__VSF_STR(__ALIAS))))
152
153# define VSF_CAL_PACKED __attribute__((packed))
154# define VSF_CAL_UNALIGNED __packed
155# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
156# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
157
158# define __VSF_CAL_ISR(__VEC) void __VEC(void)
159
160#elif __IS_COMPILER_ARM_COMPILER_6__
161# define VSF_CAL_NO_INIT __attribute__( ( section( ".bss.noinit")) )
162# define VSF_CAL_NO_RETURN __attribute__((noreturn))
163# define VSF_CAL_ROOT __attribute__((used))
164# define VSF_CAL_INLINE __inline
165# define VSF_CAL_NO_INLINE __attribute__((noinline))
166# define VSF_CAL_ALWAYS_INLINE __inline __attribute__((always_inline))
167# define VSF_CAL_WEAK(...) __attribute__((weak))
168# define VSF_CAL_RAMFUNC __attribute__((section (".textrw")))
169# define __asm__ __asm
170# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
171# define __VSF_CAL_AT_ADDR(__ADDR) __attribute__((section (".ARM.__at_" #__ADDR)))
172# define __VSF_CAL_SECTION(__SEC) __attribute__((section (__SEC)))
173# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
174 __attribute__((weakref(__VSF_STR(__ALIAS))))
175
176# define VSF_CAL_PACKED __attribute__((packed))
177# define VSF_CAL_UNALIGNED __unaligned
178# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
179# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
180
181# define __VSF_CAL_ISR(__VEC) void __VEC(void)
182#endif
183
184/*----------------------------------------------------------------------------*
185 * Signal & Interrupt Definition *
186 *----------------------------------------------------------------------------*/
187
189#if __IS_COMPILER_IAR__
190# define ENABLE_GLOBAL_INTERRUPT() __enable_interrupt()
191#else
192# define ENABLE_GLOBAL_INTERRUPT() __enable_irq()
193#endif
194
196#if __IS_COMPILER_IAR__
197# define DISABLE_GLOBAL_INTERRUPT() ____disable_irq()
199static VSF_CAL_ALWAYS_INLINE uint32_t ____disable_irq(void)
200{
201 uint32_t wPRIMASK = __get_interrupt_state();
202 __disable_interrupt();
203 return wPRIMASK;
204}
205
206#elif __IS_COMPILER_ARM_COMPILER_5__
207# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
208#elif __IS_COMPILER_ARM_COMPILER_6__ && !defined(__CMSIS_ARMCC_V6_H)
209# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
210#elif __IS_COMPILER_GCC_
211# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
212#else /* for other compilers, using gcc assembly syntax to implement */
213
214# define DISABLE_GLOBAL_INTERRUPT() ____disable_irq()
215
216static VSF_CAL_ALWAYS_INLINE uint32_t ____disable_irq(void)
218 uint32_t cpsr;
219
220 __asm__ __volatile__("mrs %[cpsr], primask\n"
221 "cpsid i\n"
222 : [cpsr] "=r"(cpsr));
223 return cpsr & 0x1;
224}
225#endif
226
227#if __IS_COMPILER_IAR__
228# define GET_GLOBAL_INTERRUPT_STATE() __get_interrupt_state()
229# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_interrupt_state(__STATE)
230typedef __istate_t vsf_gint_state_t;
231#elif __IS_COMPILER_ARM_COMPILER_5__ || __IS_COMPILER_ARM_COMPILER_6__
232# define GET_GLOBAL_INTERRUPT_STATE() __get_PRIMASK()
233# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_PRIMASK(__STATE)
235#elif __IS_COMPILER_GCC__
236# define GET_GLOBAL_INTERRUPT_STATE() __get_PRIMASK()
237# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_PRIMASK(__STATE)
239#else
241# define GET_GLOBAL_INTERRUPT_STATE() ____get_PRIMASK()
242
248VSF_CAL_ALWAYS_INLINE static inline uint32_t ____get_PRIMASK(void)
249{
250 unsigned int result;
251
252 __asm__ volatile ("MRS %0, primask" : "=r" (result) );
253 return(result);
254}
255
256# define SET_GLOBAL_INTERRUPT_STATE(__STATE) ____set_PRIMASK(__STATE)
257
263VSF_CAL_ALWAYS_INLINE static inline void ____set_PRIMASK(uint32_t priMask)
264{
265 __asm__ volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
266}
267#endif
268
269/*----------------------------------------------------------------------------*
270 * Startup Source Code *
271 *----------------------------------------------------------------------------*/
272#if __IS_COMPILER_IAR__
273
274#ifndef __VECTOR_TABLE
275# define __VECTOR_TABLE __vector_table
276#endif
277#ifndef __VECTOR_TABLE_ATTRIBUTE
278# define __VECTOR_TABLE_ATTRIBUTE @".intvec"
279#endif
280#ifndef __PROGRAM_START
281# define __PROGRAM_START __iar_program_start
282#endif
283#ifndef __INITIAL_SP
284# define __INITIAL_SP CSTACK$$Limit
285#endif
286
287#elif __IS_COMPILER_ARM_COMPILER_6__ || __IS_COMPILER_ARM_COMPILER_5__
288
289#ifndef __VECTOR_TABLE
290# define __VECTOR_TABLE __Vectors
291#endif
292#ifndef __VECTOR_TABLE_ATTRIBUTE
293# define __VECTOR_TABLE_ATTRIBUTE ROOT SECTION("RESET")
294#endif
295#ifndef __PROGRAM_START
296# define __PROGRAM_START __main
297#endif
298#ifndef __INITIAL_SP
299# define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit
300#endif
301
302#else //__IS_COMPILER_GCC__ || __IS_COMPILER_LLVM__
303
304#ifndef __PROGRAM_START
305#define __PROGRAM_START __cmsis_start
306
307#endif
309#ifndef __INITIAL_SP
310#define __INITIAL_SP __StackTop
311#endif
312
313#ifndef __STACK_LIMIT
314#define __STACK_LIMIT __StackLimit
315#endif
316
317#ifndef __VECTOR_TABLE
318#define __VECTOR_TABLE __Vectors
319#endif
320
321#ifndef __VECTOR_TABLE_ATTRIBUTE
322#define __VECTOR_TABLE_ATTRIBUTE __attribute((used, section(".vectors")))
323#endif
324#endif
326/*============================ TYPES =========================================*/
327/*============================ PROTOTYPES ====================================*/
328
329#ifdef __cplusplus
330}
331#endif
332
333#endif /* end of __USE_ARM_COMPILER_H_PART_2__ */
334
335
336
#define __volatile__
Definition __compiler.h:56
uint32_t vsf_gint_state_t
Definition arm_compiler.h:243
unsigned int uint32_t
Definition lvgl.h:43