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_TRANSPARENT_UNION __attribute__((transparent_union))
139# define __VSF_CAL_ALIGN_OF(...) __ALIGNOF__(__VA_ARGS__)
140
141# define __IAR_STARTUP_DATA_INIT __iar_data_init3
142
143# define __VSF_CAL_ISR(__VEC) void __VEC(void)
144
145#elif __IS_COMPILER_ARM_COMPILER_5__
146# define VSF_CAL_NO_INIT __attribute__( ( section( ".bss.noinit"),zero_init) )
147# define VSF_CAL_NO_RETURN __attribute__((noreturn))
148# define VSF_CAL_ROOT __attribute__((used))
149# define VSF_CAL_INLINE __inline
150# define VSF_CAL_NO_INLINE __attribute__((noinline))
151# define VSF_CAL_ALWAYS_INLINE __inline __attribute__((always_inline))
152# define VSF_CAL_WEAK(...) __attribute__((weak))
153# define VSF_CAL_RAMFUNC __attribute__((section (".textrw")))
154# define __asm__ __asm
155# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
156# define __VSF_CAL_AT_ADDR(__ADDR) __attribute__((at(__ADDR)))
157# define __VSF_CAL_SECTION(__SEC_STR) __attribute__((section (__SEC_STR)))
158# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
159 __attribute__((weakref(__VSF_STR(__ALIAS))))
160
161# define VSF_CAL_PACKED __attribute__((packed))
162# define VSF_CAL_UNALIGNED __packed
163# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
164# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
165
166# define __VSF_CAL_ISR(__VEC) void __VEC(void)
167
168#elif __IS_COMPILER_ARM_COMPILER_6__
169# define VSF_CAL_NO_INIT __attribute__( ( section( ".bss.noinit")) )
170# define VSF_CAL_NO_RETURN __attribute__((noreturn))
171# define VSF_CAL_ROOT __attribute__((used))
172# define VSF_CAL_INLINE __inline
173# define VSF_CAL_NO_INLINE __attribute__((noinline))
174# define VSF_CAL_ALWAYS_INLINE __inline __attribute__((always_inline))
175# define VSF_CAL_WEAK(...) __attribute__((weak))
176# define VSF_CAL_RAMFUNC __attribute__((section (".textrw")))
177# define __asm__ __asm
178# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
179# define __VSF_CAL_AT_ADDR(__ADDR) __attribute__((section (".ARM.__at_" #__ADDR)))
180# define __VSF_CAL_SECTION(__SEC_STR) __attribute__((section (__SEC_STR)))
181# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
182 __attribute__((weakref(__VSF_STR(__ALIAS))))
183
184# define VSF_CAL_PACKED __attribute__((packed))
185# define VSF_CAL_UNALIGNED __unaligned
186# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
187# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
188
189# define __VSF_CAL_ISR(__VEC) void __VEC(void)
190#endif
191
192/*----------------------------------------------------------------------------*
193 * Signal & Interrupt Definition *
194 *----------------------------------------------------------------------------*/
195
197#if __IS_COMPILER_IAR__
198# define ENABLE_GLOBAL_INTERRUPT() __enable_interrupt()
199#else
200# define ENABLE_GLOBAL_INTERRUPT() __enable_irq()
201#endif
202
204#if __IS_COMPILER_IAR__
205# define DISABLE_GLOBAL_INTERRUPT() ____disable_irq()
207static VSF_CAL_ALWAYS_INLINE uint32_t ____disable_irq(void)
208{
209 uint32_t wPRIMASK = __get_interrupt_state();
210 __disable_interrupt();
211 return wPRIMASK;
212}
213
214#elif __IS_COMPILER_ARM_COMPILER_5__
215# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
216#elif __IS_COMPILER_ARM_COMPILER_6__ && !defined(__CMSIS_ARMCC_V6_H)
217# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
218#elif __IS_COMPILER_GCC_
219# define DISABLE_GLOBAL_INTERRUPT() __disable_irq()
220#else /* for other compilers, using gcc assembly syntax to implement */
221
222# define DISABLE_GLOBAL_INTERRUPT() ____disable_irq()
223
224static VSF_CAL_ALWAYS_INLINE uint32_t ____disable_irq(void)
226 uint32_t cpsr;
227
228 __asm__ __volatile__("mrs %[cpsr], primask\n"
229 "cpsid i\n"
230 : [cpsr] "=r"(cpsr));
231 return cpsr & 0x1;
232}
233#endif
234
235#if __IS_COMPILER_IAR__
236# define GET_GLOBAL_INTERRUPT_STATE() __get_interrupt_state()
237# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_interrupt_state(__STATE)
238typedef __istate_t vsf_gint_state_t;
239#elif __IS_COMPILER_ARM_COMPILER_5__ || __IS_COMPILER_ARM_COMPILER_6__
240# define GET_GLOBAL_INTERRUPT_STATE() __get_PRIMASK()
241# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_PRIMASK(__STATE)
243#elif __IS_COMPILER_GCC__
244# define GET_GLOBAL_INTERRUPT_STATE() __get_PRIMASK()
245# define SET_GLOBAL_INTERRUPT_STATE(__STATE) __set_PRIMASK(__STATE)
247#else
249# define GET_GLOBAL_INTERRUPT_STATE() ____get_PRIMASK()
250
256VSF_CAL_ALWAYS_INLINE static inline uint32_t ____get_PRIMASK(void)
257{
258 unsigned int result;
259
260 __asm__ volatile ("MRS %0, primask" : "=r" (result) );
261 return(result);
262}
263
264# define SET_GLOBAL_INTERRUPT_STATE(__STATE) ____set_PRIMASK(__STATE)
265
271VSF_CAL_ALWAYS_INLINE static inline void ____set_PRIMASK(uint32_t priMask)
272{
273 __asm__ volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
274}
275#endif
276
277/*----------------------------------------------------------------------------*
278 * Startup Source Code *
279 *----------------------------------------------------------------------------*/
280#if __IS_COMPILER_IAR__
281
282#ifndef __VECTOR_TABLE
283# define __VECTOR_TABLE __vector_table
284#endif
285#ifndef __VECTOR_TABLE_ATTRIBUTE
286# define __VECTOR_TABLE_ATTRIBUTE @".intvec"
287#endif
288#ifndef __PROGRAM_START
289# define __PROGRAM_START __iar_program_start
290#endif
291#ifndef __INITIAL_SP
292# define __INITIAL_SP CSTACK$$Limit
293#endif
294
295#elif __IS_COMPILER_ARM_COMPILER_6__ || __IS_COMPILER_ARM_COMPILER_5__
296
297#ifndef __VECTOR_TABLE
298# define __VECTOR_TABLE __Vectors
299#endif
300#ifndef __VECTOR_TABLE_ATTRIBUTE
301# define __VECTOR_TABLE_ATTRIBUTE ROOT SECTION("RESET")
302#endif
303#ifndef __PROGRAM_START
304# define __PROGRAM_START __main
305#endif
306#ifndef __INITIAL_SP
307# define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit
308#endif
309
310#else //__IS_COMPILER_GCC__ || __IS_COMPILER_LLVM__
311
312#ifndef __PROGRAM_START
313#define __PROGRAM_START __cmsis_start
314
315#endif
317#ifndef __INITIAL_SP
318#define __INITIAL_SP __StackTop
319#endif
320
321#ifndef __STACK_LIMIT
322#define __STACK_LIMIT __StackLimit
323#endif
324
325#ifndef __VECTOR_TABLE
326#define __VECTOR_TABLE __Vectors
327#endif
328
329#ifndef __VECTOR_TABLE_ATTRIBUTE
330#define __VECTOR_TABLE_ATTRIBUTE __attribute((used, section(".vectors")))
331#endif
332#endif
334/*============================ TYPES =========================================*/
335/*============================ PROTOTYPES ====================================*/
336
337#ifdef __cplusplus
338}
339#endif
340
341#endif /* end of __USE_ARM_COMPILER_H_PART_2__ */
342
343
344
#define __volatile__
Definition __compiler.h:56
uint32_t vsf_gint_state_t
Definition arm_compiler.h:251
unsigned uint32_t
Definition stdint.h:9
Generated from commit: vsfteam/vsf@89cfb73