]> begriffs open source - cmsis/blob - CMSIS/Core/Include/m-profile/armv81m_pac.h
Fix CodeQL issues
[cmsis] / CMSIS / Core / Include / m-profile / armv81m_pac.h
1 /******************************************************************************
2  * @file     armv81m_pac.h
3  * @brief    CMSIS PAC key functions for Armv8.1-M PAC extension
4  * @version  V1.0.0
5  * @date     23. March 2022
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2022 Arm Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the License); you may
13  * not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24
25 #ifndef PAC_ARMV81_H
26 #define PAC_ARMV81_H
27
28 #if   defined ( __ICCARM__ )
29   #pragma system_include         /* treat file as system include file for MISRA check */
30 #elif defined (__clang__)
31   #pragma clang system_header    /* treat file as system include file */
32 #endif
33
34 /* ###################  PAC Key functions  ########################### */
35 /**
36   \ingroup  CMSIS_Core_FunctionInterface
37   \defgroup CMSIS_Core_PacKeyFunctions PAC Key functions
38   \brief    Functions that access the PAC keys.
39   @{
40  */
41
42 #if (defined (__ARM_FEATURE_PAUTH) && (__ARM_FEATURE_PAUTH == 1))
43
44 /**
45   \brief   read the PAC key used for privileged mode
46   \details Reads the PAC key stored in the PAC_KEY_P registers.
47   \param [out]    pPacKey  128bit PAC key
48  */
49 __STATIC_FORCEINLINE void __get_PAC_KEY_P (uint32_t* pPacKey) {
50   __ASM volatile (
51   "mrs   r1, pac_key_p_0\n"
52   "str   r1,[%0,#0]\n"
53   "mrs   r1, pac_key_p_1\n"
54   "str   r1,[%0,#4]\n"
55   "mrs   r1, pac_key_p_2\n"
56   "str   r1,[%0,#8]\n"
57   "mrs   r1, pac_key_p_3\n"
58   "str   r1,[%0,#12]\n"
59   : : "r" (pPacKey) : "memory", "r1"
60   );
61 }
62
63 /**
64   \brief   write the PAC key used for privileged mode
65   \details writes the given PAC key to the PAC_KEY_P registers.
66   \param [in]    pPacKey  128bit PAC key
67  */
68 __STATIC_FORCEINLINE void __set_PAC_KEY_P (uint32_t* pPacKey) {
69   __ASM volatile (
70   "ldr   r1,[%0,#0]\n"
71   "msr   pac_key_p_0, r1\n"
72   "ldr   r1,[%0,#4]\n"
73   "msr   pac_key_p_1, r1\n"
74   "ldr   r1,[%0,#8]\n"
75   "msr   pac_key_p_2, r1\n"
76   "ldr   r1,[%0,#12]\n"
77   "msr   pac_key_p_3, r1\n"
78   : : "r" (pPacKey) : "memory", "r1"
79   );
80 }
81
82 /**
83   \brief   read the PAC key used for unprivileged mode
84   \details Reads the PAC key stored in the PAC_KEY_U registers.
85   \param [out]    pPacKey  128bit PAC key
86  */
87 __STATIC_FORCEINLINE void __get_PAC_KEY_U (uint32_t* pPacKey) {
88   __ASM volatile (
89   "mrs   r1, pac_key_u_0\n"
90   "str   r1,[%0,#0]\n"
91   "mrs   r1, pac_key_u_1\n"
92   "str   r1,[%0,#4]\n"
93   "mrs   r1, pac_key_u_2\n"
94   "str   r1,[%0,#8]\n"
95   "mrs   r1, pac_key_u_3\n"
96   "str   r1,[%0,#12]\n"
97   : : "r" (pPacKey) : "memory", "r1"
98   );
99 }
100
101 /**
102   \brief   write the PAC key used for unprivileged mode
103   \details writes the given PAC key to the PAC_KEY_U registers.
104   \param [in]    pPacKey  128bit PAC key
105  */
106 __STATIC_FORCEINLINE void __set_PAC_KEY_U (uint32_t* pPacKey) {
107   __ASM volatile (
108   "ldr   r1,[%0,#0]\n"
109   "msr   pac_key_u_0, r1\n"
110   "ldr   r1,[%0,#4]\n"
111   "msr   pac_key_u_1, r1\n"
112   "ldr   r1,[%0,#8]\n"
113   "msr   pac_key_u_2, r1\n"
114   "ldr   r1,[%0,#12]\n"
115   "msr   pac_key_u_3, r1\n"
116   : : "r" (pPacKey) : "memory", "r1"
117   );
118 }
119
120 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
121
122 /**
123   \brief   read the PAC key used for privileged mode (non-secure)
124   \details Reads the PAC key stored in the non-secure PAC_KEY_P registers when in secure mode.
125   \param [out]    pPacKey  128bit PAC key
126  */
127 __STATIC_FORCEINLINE void __TZ_get_PAC_KEY_P_NS (uint32_t* pPacKey) {
128   __ASM volatile (
129   "mrs   r1, pac_key_p_0_ns\n"
130   "str   r1,[%0,#0]\n"
131   "mrs   r1, pac_key_p_1_ns\n"
132   "str   r1,[%0,#4]\n"
133   "mrs   r1, pac_key_p_2_ns\n"
134   "str   r1,[%0,#8]\n"
135   "mrs   r1, pac_key_p_3_ns\n"
136   "str   r1,[%0,#12]\n"
137   : : "r" (pPacKey) : "memory", "r1"
138   );
139 }
140
141 /**
142   \brief   write the PAC key used for privileged mode (non-secure)
143   \details writes the given PAC key to the non-secure PAC_KEY_P registers when in secure mode.
144   \param [in]    pPacKey  128bit PAC key
145  */
146 __STATIC_FORCEINLINE void __TZ_set_PAC_KEY_P_NS (uint32_t* pPacKey) {
147   __ASM volatile (
148   "ldr   r1,[%0,#0]\n"
149   "msr   pac_key_p_0_ns, r1\n"
150   "ldr   r1,[%0,#4]\n"
151   "msr   pac_key_p_1_ns, r1\n"
152   "ldr   r1,[%0,#8]\n"
153   "msr   pac_key_p_2_ns, r1\n"
154   "ldr   r1,[%0,#12]\n"
155   "msr   pac_key_p_3_ns, r1\n"
156   : : "r" (pPacKey) : "memory", "r1"
157   );
158 }
159
160 /**
161   \brief   read the PAC key used for unprivileged mode (non-secure)
162   \details Reads the PAC key stored in the non-secure PAC_KEY_U registers when in secure mode.
163   \param [out]    pPacKey  128bit PAC key
164  */
165 __STATIC_FORCEINLINE void __TZ_get_PAC_KEY_U_NS (uint32_t* pPacKey) {
166   __ASM volatile (
167   "mrs   r1, pac_key_u_0_ns\n"
168   "str   r1,[%0,#0]\n"
169   "mrs   r1, pac_key_u_1_ns\n"
170   "str   r1,[%0,#4]\n"
171   "mrs   r1, pac_key_u_2_ns\n"
172   "str   r1,[%0,#8]\n"
173   "mrs   r1, pac_key_u_3_ns\n"
174   "str   r1,[%0,#12]\n"
175   : : "r" (pPacKey) : "memory", "r1"
176   );
177 }
178
179 /**
180   \brief   write the PAC key used for unprivileged mode (non-secure)
181   \details writes the given PAC key to the non-secure PAC_KEY_U registers when in secure mode.
182   \param [in]    pPacKey  128bit PAC key
183  */
184 __STATIC_FORCEINLINE void __TZ_set_PAC_KEY_U_NS (uint32_t* pPacKey) {
185   __ASM volatile (
186   "ldr   r1,[%0,#0]\n"
187   "msr   pac_key_u_0_ns, r1\n"
188   "ldr   r1,[%0,#4]\n"
189   "msr   pac_key_u_1_ns, r1\n"
190   "ldr   r1,[%0,#8]\n"
191   "msr   pac_key_u_2_ns, r1\n"
192   "ldr   r1,[%0,#12]\n"
193   "msr   pac_key_u_3_ns, r1\n"
194   : : "r" (pPacKey) : "memory", "r1"
195   );
196 }
197
198 #endif /* (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) */
199
200 #endif /* (defined (__ARM_FEATURE_PAUTH) && (__ARM_FEATURE_PAUTH == 1)) */
201
202 /*@} end of CMSIS_Core_PacKeyFunctions */
203
204
205 #endif /* PAC_ARMV81_H */