2 * Copyright (c) 2009-2024 Arm Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #ifndef __CMSIS_GCC_A_H
20 #define __CMSIS_GCC_A_H
23 #error "This file must not be included directly"
26 /* ignore some GCC warnings */
27 #pragma GCC diagnostic push
28 #pragma GCC diagnostic ignored "-Wsign-conversion"
29 #pragma GCC diagnostic ignored "-Wconversion"
30 #pragma GCC diagnostic ignored "-Wunused-parameter"
33 /** \defgroup CMSIS_Core_intrinsics CMSIS Core Intrinsics
34 Access to dedicated SIMD instructions
38 /** \brief Get CPSR Register
39 \return CPSR Register value
41 __STATIC_FORCEINLINE uint32_t __get_CPSR(void)
44 __ASM volatile("MRS %0, cpsr" : "=r" (result) );
48 /** \brief Set CPSR Register
49 \param [in] cpsr CPSR value to set
51 __STATIC_FORCEINLINE void __set_CPSR(uint32_t cpsr)
53 __ASM volatile ("MSR cpsr, %0" : : "r" (cpsr) : "cc", "memory");
57 \return Processor Mode
59 __STATIC_FORCEINLINE uint32_t __get_mode(void)
61 return (__get_CPSR() & 0x1FU);
65 \param [in] mode Mode value to set
67 __STATIC_FORCEINLINE void __set_mode(uint32_t mode)
69 __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory");
72 /** \brief Get Stack Pointer
73 \return Stack Pointer value
75 __STATIC_FORCEINLINE uint32_t __get_SP(void)
78 __ASM volatile("MOV %0, sp" : "=r" (result) : : "memory");
82 /** \brief Set Stack Pointer
83 \param [in] stack Stack Pointer value to set
85 __STATIC_FORCEINLINE void __set_SP(uint32_t stack)
87 __ASM volatile("MOV sp, %0" : : "r" (stack) : "memory");
90 /** \brief Get USR/SYS Stack Pointer
91 \return USR/SYS Stack Pointer value
93 __STATIC_FORCEINLINE uint32_t __get_SP_usr(void)
95 uint32_t cpsr = __get_CPSR();
99 "MOV %0, sp " : "=r"(result) : : "memory"
106 /** \brief Set USR/SYS Stack Pointer
107 \param [in] topOfProcStack USR/SYS Stack Pointer value to set
109 __STATIC_FORCEINLINE void __set_SP_usr(uint32_t topOfProcStack)
111 uint32_t cpsr = __get_CPSR();
114 "MOV sp, %0 " : : "r" (topOfProcStack) : "memory"
121 \return Floating Point Exception Control register value
123 __STATIC_FORCEINLINE uint32_t __get_FPEXC(void)
125 #if (__FPU_PRESENT == 1)
127 __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory");
135 \param [in] fpexc Floating Point Exception Control value to set
137 __STATIC_FORCEINLINE void __set_FPEXC(uint32_t fpexc)
139 #if (__FPU_PRESENT == 1)
140 __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory");
145 * Include common core functions to access Coprocessor 15 registers
148 #define __get_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" )
149 #define __set_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" )
150 #define __get_CP64(cp, op1, Rt, CRm) __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
151 #define __set_CP64(cp, op1, Rt, CRm) __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
153 #include "cmsis_cp15.h"
155 /** \brief Enable Floating Point Unit
157 Critical section, called from undef handler, so systick is disabled
159 __STATIC_INLINE void __FPU_Enable(void)
161 // Permit access to VFP/NEON, registers by modifying CPACR
162 const uint32_t cpacr = __get_CPACR();
163 __set_CPACR(cpacr | 0x00F00000ul);
167 const uint32_t fpexc = __get_FPEXC();
168 __set_FPEXC(fpexc | 0x40000000ul);
171 // Initialise VFP/NEON registers to 0
174 // Initialise D16 registers to 0
192 #if (defined(__ARM_NEON) && (__ARM_NEON == 1))
193 // Initialise D32 registers to 0
214 // Initialise FPSCR to a known state
215 const uint32_t fpscr = __get_FPSCR();
216 __set_FPSCR(fpscr & 0x00086060ul);
219 /*@} end of group CMSIS_Core_intrinsics */
221 #pragma GCC diagnostic pop
223 #endif /* __CMSIS_GCC_A_H */