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#elif __IS_COMPILER_GCC__
77/* anonymous unions are enabled by default */
78#elif __IS_COMPILER_LLVM__
79/* anonymous unions are enabled by default */
80#elif defined(__TMS470__)
81/* anonymous unions are enabled by default */
82#elif defined(__TASKING__)
83 #pragma warning 586
84#else
85 #warning Not supported compiler type
86#endif
87
88/*----------------------------------------------------------------------------*
89 * Warning Mitigation *
90 *----------------------------------------------------------------------------*/
91
92#if __IS_COMPILER_ARM_COMPILER_6__
93# pragma clang diagnostic ignored "-Wdollar-in-identifier-extension"
94#endif
95
96
97
98/*============================ MACROS ========================================*/
99
101#ifndef NOP
102 #define NOP() __asm__ __volatile__ ("nop");
103#endif
104
105
107#if __IS_COMPILER_IAR__
108# define LOW_LEVEL_INIT_RET_T int
109# define VSF_CAL_NO_INIT __no_init
110# define VSF_CAL_NO_RETURN __attribute__((noreturn))
111# define VSF_CAL_ROOT __root
112# define VSF_CAL_INLINE inline
113# define VSF_CAL_NO_INLINE __attribute__((noinline))
114# define VSF_CAL_ALWAYS_INLINE inline __attribute__((always_inline))
115# define VSF_CAL_WEAK(...) __weak
116# define VSF_CAL_RAMFUNC __ramfunc
117# define __asm__ __asm
118# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
119# define __VSF_CAL_AT_ADDR(__ADDR) @ __ADDR
120# define __VSF_CAL_SECTION(__SEC) __attribute__((section (__SEC)))
121# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
122 _Pragma(__VSF_STR(weak __ORIGIN=__ALIAS))
123# define VSF_CAL_PACKED __attribute__((packed))
124# define VSF_CAL_UNALIGNED __packed
125# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
126# define __VSF_CAL_ALIGN_OF(...) __ALIGNOF__(__VA_ARGS__)
127
128# define __IAR_STARTUP_DATA_INIT __iar_data_init3
129
130# define __VSF_CAL_ISR(__VEC) void __VEC(void)
131
132#elif __IS_COMPILER_ARM_COMPILER_5__
133# define VSF_CAL_NO_INIT __attribute__( ( section( ".bss.noinit"),zero_init) )
134# define VSF_CAL_NO_RETURN __attribute__((noreturn))
135# define VSF_CAL_ROOT __attribute__((used))
136# define VSF_CAL_INLINE __inline
137# define VSF_CAL_NO_INLINE __attribute__((noinline))
138# define VSF_CAL_ALWAYS_INLINE __inline __attribute__((always_inline))
139# define VSF_CAL_WEAK(...) __attribute__((weak))
140# define VSF_CAL_RAMFUNC __attribute__((section (".textrw")))
141# define __asm__ __asm
142# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
143# define __VSF_CAL_AT_ADDR(__ADDR) __attribute__((at(__ADDR)))
144# define __VSF_CAL_SECTION(__SEC) __attribute__((section (__SEC)))
145# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
146 __attribute__((weakref(__VSF_STR(__ALIAS))))
147
148# define VSF_CAL_PACKED __attribute__((packed))
149# define VSF_CAL_UNALIGNED __packed
150# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
151# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
152
153# define __VSF_CAL_ISR(__VEC) void __VEC(void)
154
155#elif __IS_COMPILER_ARM_COMPILER_6__
156# define VSF_CAL_NO_INIT __attribute__( ( section( ".bss.noinit")) )
157# define VSF_CAL_NO_RETURN __attribute__((noreturn))
158# define VSF_CAL_ROOT __attribute__((used))
159# define VSF_CAL_INLINE __inline
160# define VSF_CAL_NO_INLINE __attribute__((noinline))
161# define VSF_CAL_ALWAYS_INLINE __inline __attribute__((always_inline))
162# define VSF_CAL_WEAK(...) __attribute__((weak))
163# define VSF_CAL_RAMFUNC __attribute__((section (".textrw")))
164# define __asm__ __asm
165# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
166# define __VSF_CAL_AT_ADDR(__ADDR) __attribute__((section (".ARM.__at_" #__ADDR)))
167# define __VSF_CAL_SECTION(__SEC) __attribute__((section (__SEC)))
168# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
169 __attribute__((weakref(__VSF_STR(__ALIAS))))
170
171# define VSF_CAL_PACKED __attribute__((packed))
172# define VSF_CAL_UNALIGNED __unaligned
173# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
174# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
175
176# define __VSF_CAL_ISR(__VEC) void __VEC(void)
177#endif
178
179/*----------------------------------------------------------------------------*
180 * Signal & Interrupt Definition *
181 *----------------------------------------------------------------------------*/
182
184#if __IS_COMPILER_IAR__
185# define ENABLE_GLOBAL_INTERRUPT() __enable_interrupt()
186#else
187# define ENABLE_GLOBAL_INTERRUPT() __enable_irq()
188#endif
189
191#if __IS_COMPILER_IAR__
192# define DISABLE_GLOBAL_INTERRUPT() ____disable_irq()
194static VSF_CAL_ALWAYS_INLINE uint32_t ____disable_irq(void)
195{
196 uint32_t wPRIMASK = __get_interrupt_state();
197 __disable_interrupt();
198 return wPRIMASK;
199}
200
201#elif __IS_COMPILER_ARM_COMPILER_5__
202# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
203#elif __IS_COMPILER_ARM_COMPILER_6__ && !defined(__CMSIS_ARMCC_V6_H)
204# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
205#elif __IS_COMPILER_GCC_
206# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
207#else /* for other compilers, using gcc assembly syntax to implement */
208
209# define DISABLE_GLOBAL_INTERRUPT() ____disable_irq()
210
211static VSF_CAL_ALWAYS_INLINE uint32_t ____disable_irq(void)
213 uint32_t cpsr;
214
215 __asm__ __volatile__("mrs %[cpsr], primask\n"
216 "cpsid i\n"
217 : [cpsr] "=r"(cpsr));
218 return cpsr & 0x1;
219}
220#endif
221
222#if __IS_COMPILER_IAR__
223# define GET_GLOBAL_INTERRUPT_STATE() __get_interrupt_state()
224# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_interrupt_state(__STATE)
225typedef __istate_t vsf_gint_state_t;
226#elif __IS_COMPILER_ARM_COMPILER_5__ || __IS_COMPILER_ARM_COMPILER_6__
227# define GET_GLOBAL_INTERRUPT_STATE() __get_PRIMASK()
228# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_PRIMASK(__STATE)
230#elif __IS_COMPILER_GCC__
231# define GET_GLOBAL_INTERRUPT_STATE() __get_PRIMASK()
232# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_PRIMASK(__STATE)
234#else
236# define GET_GLOBAL_INTERRUPT_STATE() ____get_PRIMASK()
237
243VSF_CAL_ALWAYS_INLINE static inline uint32_t ____get_PRIMASK(void)
244{
245 unsigned int result;
246
247 __asm__ volatile ("MRS %0, primask" : "=r" (result) );
248 return(result);
249}
250
251# define SET_GLOBAL_INTERRUPT_STATE(__STATE) ____set_PRIMASK(__STATE)
252
258VSF_CAL_ALWAYS_INLINE static inline void ____set_PRIMASK(uint32_t priMask)
259{
260 __asm__ volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
261}
262#endif
263
264/*----------------------------------------------------------------------------*
265 * Startup Source Code *
266 *----------------------------------------------------------------------------*/
267#if __IS_COMPILER_IAR__
268
269#ifndef __VECTOR_TABLE
270# define __VECTOR_TABLE __vector_table
271#endif
272#ifndef __VECTOR_TABLE_ATTRIBUTE
273# define __VECTOR_TABLE_ATTRIBUTE @".intvec"
274#endif
275#ifndef __PROGRAM_START
276# define __PROGRAM_START __iar_program_start
277#endif
278#ifndef __INITIAL_SP
279# define __INITIAL_SP CSTACK$$Limit
280#endif
281
282#elif __IS_COMPILER_ARM_COMPILER_6__ || __IS_COMPILER_ARM_COMPILER_5__
283
284#ifndef __VECTOR_TABLE
285# define __VECTOR_TABLE __Vectors
286#endif
287#ifndef __VECTOR_TABLE_ATTRIBUTE
288# define __VECTOR_TABLE_ATTRIBUTE ROOT SECTION("RESET")
289#endif
290#ifndef __PROGRAM_START
291# define __PROGRAM_START __main
292#endif
293#ifndef __INITIAL_SP
294# define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit
295#endif
296
297#else //__IS_COMPILER_GCC__ || __IS_COMPILER_LLVM__
298
299#ifndef __PROGRAM_START
300#define __PROGRAM_START __cmsis_start
301
302#endif
304#ifndef __INITIAL_SP
305#define __INITIAL_SP __StackTop
306#endif
307
308#ifndef __STACK_LIMIT
309#define __STACK_LIMIT __StackLimit
310#endif
311
312#ifndef __VECTOR_TABLE
313#define __VECTOR_TABLE __Vectors
314#endif
315
316#ifndef __VECTOR_TABLE_ATTRIBUTE
317#define __VECTOR_TABLE_ATTRIBUTE __attribute((used, section(".vectors")))
318#endif
319#endif
321/*============================ TYPES =========================================*/
322/*============================ PROTOTYPES ====================================*/
323
324#ifdef __cplusplus
325}
326#endif
327
328#endif /* end of __USE_ARM_COMPILER_H_PART_2__ */
329
330
331
#define __volatile__
Definition __compiler.h:56
uint32_t vsf_gint_state_t
Definition arm_compiler.h:238
unsigned uint32_t
Definition stdint.h:9