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