1 /*
2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 
7 /*******************************************************************************************************************//**
8  * @addtogroup BSP_MCU
9  * @{
10  **********************************************************************************************************************/
11 
12 #ifndef BSP_COMPILER_SUPPORT_H
13  #define BSP_COMPILER_SUPPORT_H
14 
15  #if (defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
16   #include "arm_cmse.h"
17  #endif
18 
19  #ifdef __cplusplus
20 extern "C" {
21  #endif
22 
23 /***********************************************************************************************************************
24  * Macro definitions
25  **********************************************************************************************************************/
26  #if defined(__ARMCC_VERSION)          /* AC6 compiler */
27 
28 /* The AC6 linker requires uninitialized code to be placed in a section that starts with ".bss." Without this, load
29  * memory (ROM) is reserved unnecessarily. */
30   #define BSP_UNINIT_SECTION_PREFIX         ".bss"
31   #ifndef BSP_SECTION_HEAP
32    #define BSP_SECTION_HEAP                 BSP_UNINIT_SECTION_PREFIX ".heap"
33   #endif
34   #define BSP_DONT_REMOVE                   __attribute__((used))
35   #define BSP_ATTRIBUTE_STACKLESS           __attribute__((naked))
36   #define BSP_FORCE_INLINE                  __attribute__((always_inline))
37  #elif   defined(__GNUC__)             /* GCC compiler */
38   #define BSP_UNINIT_SECTION_PREFIX
39   #ifndef BSP_SECTION_HEAP
40    #define BSP_SECTION_HEAP                 ".heap"
41   #endif
42   #define BSP_DONT_REMOVE
43   #define BSP_ATTRIBUTE_STACKLESS           __attribute__((naked))
44   #define BSP_FORCE_INLINE                  __attribute__((always_inline))
45  #elif defined(__ICCARM__)             /* IAR compiler */
46   #define BSP_UNINIT_SECTION_PREFIX
47   #ifndef BSP_SECTION_HEAP
48    #define BSP_SECTION_HEAP                 "HEAP"
49   #endif
50   #define BSP_DONT_REMOVE                   __root
51   #define BSP_ATTRIBUTE_STACKLESS           __stackless
52   #define BSP_FORCE_INLINE                  _Pragma("inline=forced")
53  #endif
54 
55  #ifndef BSP_SECTION_STACK
56   #define BSP_SECTION_STACK                 BSP_UNINIT_SECTION_PREFIX ".stack"
57  #endif
58  #ifndef BSP_SECTION_FLASH_GAP
59   #define BSP_SECTION_FLASH_GAP
60  #endif
61  #define BSP_SECTION_NOINIT                 BSP_UNINIT_SECTION_PREFIX ".noinit"
62  #define BSP_SECTION_FIXED_VECTORS          ".fixed_vectors"
63  #define BSP_SECTION_APPLICATION_VECTORS    ".application_vectors"
64  #define BSP_SECTION_ROM_REGISTERS          ".rom_registers"
65  #define BSP_SECTION_ID_CODE                ".id_code"
66 
67 /* Compiler neutral macros. */
68  #define BSP_PLACE_IN_SECTION(x)    __attribute__((section(x))) __attribute__((__used__))
69 
70  #define BSP_ALIGN_VARIABLE(x)      __attribute__((aligned(x)))
71 
72  #define BSP_PACKED                    __attribute__((aligned(1))) // DEPRECATED
73 
74  #define BSP_WEAK_REFERENCE            __attribute__((weak))
75 
76 /** Stacks (and heap) must be sized and aligned to an integer multiple of this number. */
77  #define BSP_STACK_ALIGNMENT           (8)
78 
79 /***********************************************************************************************************************
80  * TrustZone definitions
81  **********************************************************************************************************************/
82  #if (defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)) && !defined(__clang_analyzer__)
83   #if defined(__ICCARM__)              /* IAR compiler */
84    #define BSP_CMSE_NONSECURE_CALL     __cmse_nonsecure_call
85    #define BSP_CMSE_NONSECURE_ENTRY    __cmse_nonsecure_entry
86   #else
87    #define BSP_CMSE_NONSECURE_CALL     __attribute__((cmse_nonsecure_call))
88    #define BSP_CMSE_NONSECURE_ENTRY    __attribute__((cmse_nonsecure_entry))
89   #endif
90  #else
91   #define BSP_CMSE_NONSECURE_CALL
92   #define BSP_CMSE_NONSECURE_ENTRY
93  #endif
94 
95 /***********************************************************************************************************************
96  * Exported global variables
97  **********************************************************************************************************************/
98 
99 /***********************************************************************************************************************
100  * Exported global functions (to be accessed by other files)
101  **********************************************************************************************************************/
102 
103 /** @} (end of addtogroup BSP_MCU) */
104 
105  #ifdef __cplusplus
106 }
107  #endif
108 
109 #endif
110