]> begriffs open source - freertos/blob - portable/ARMv8M/secure/macros/secure_port_macros.h
[AUTO][RELEASE]: Bump file header version to "10.4.5"
[freertos] / portable / ARMv8M / secure / macros / secure_port_macros.h
1 /*\r
2  * FreeRTOS Kernel V10.4.5\r
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * SPDX-License-Identifier: MIT\r
6  *\r
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
8  * this software and associated documentation files (the "Software"), to deal in\r
9  * the Software without restriction, including without limitation the rights to\r
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
11  * the Software, and to permit persons to whom the Software is furnished to do so,\r
12  * subject to the following conditions:\r
13  *\r
14  * The above copyright notice and this permission notice shall be included in all\r
15  * copies or substantial portions of the Software.\r
16  *\r
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23  *\r
24  * https://www.FreeRTOS.org\r
25  * https://github.com/FreeRTOS\r
26  *\r
27  */\r
28 \r
29 #ifndef __SECURE_PORT_MACROS_H__\r
30 #define __SECURE_PORT_MACROS_H__\r
31 \r
32 /**\r
33  * @brief Byte alignment requirements.\r
34  */\r
35 #define secureportBYTE_ALIGNMENT         8\r
36 #define secureportBYTE_ALIGNMENT_MASK    ( 0x0007 )\r
37 \r
38 /**\r
39  * @brief Macro to declare a function as non-secure callable.\r
40  */\r
41 #if defined( __IAR_SYSTEMS_ICC__ )\r
42     #define secureportNON_SECURE_CALLABLE    __cmse_nonsecure_entry __root\r
43 #else\r
44     #define secureportNON_SECURE_CALLABLE    __attribute__( ( cmse_nonsecure_entry ) ) __attribute__( ( used ) )\r
45 #endif\r
46 \r
47 /**\r
48  * @brief Set the secure PRIMASK value.\r
49  */\r
50 #define secureportSET_SECURE_PRIMASK( ulPrimaskValue ) \\r
51     __asm volatile ( "msr primask, %0" : : "r" ( ulPrimaskValue ) : "memory" )\r
52 \r
53 /**\r
54  * @brief Set the non-secure PRIMASK value.\r
55  */\r
56 #define secureportSET_NON_SECURE_PRIMASK( ulPrimaskValue ) \\r
57     __asm volatile ( "msr primask_ns, %0" : : "r" ( ulPrimaskValue ) : "memory" )\r
58 \r
59 /**\r
60  * @brief Read the PSP value in the given variable.\r
61  */\r
62 #define secureportREAD_PSP( pucOutCurrentStackPointer ) \\r
63     __asm volatile ( "mrs %0, psp"  : "=r" ( pucOutCurrentStackPointer ) )\r
64 \r
65 /**\r
66  * @brief Set the PSP to the given value.\r
67  */\r
68 #define secureportSET_PSP( pucCurrentStackPointer ) \\r
69     __asm volatile ( "msr psp, %0" : : "r" ( pucCurrentStackPointer ) )\r
70 \r
71 /**\r
72  * @brief Read the PSPLIM value in the given variable.\r
73  */\r
74 #define secureportREAD_PSPLIM( pucOutStackLimit ) \\r
75     __asm volatile ( "mrs %0, psplim"  : "=r" ( pucOutStackLimit ) )\r
76 \r
77 /**\r
78  * @brief Set the PSPLIM to the given value.\r
79  */\r
80 #define secureportSET_PSPLIM( pucStackLimit ) \\r
81     __asm volatile ( "msr psplim, %0" : : "r" ( pucStackLimit ) )\r
82 \r
83 /**\r
84  * @brief Set the NonSecure MSP to the given value.\r
85  */\r
86 #define secureportSET_MSP_NS( pucMainStackPointer ) \\r
87     __asm volatile ( "msr msp_ns, %0" : : "r" ( pucMainStackPointer ) )\r
88 \r
89 /**\r
90  * @brief Set the CONTROL register to the given value.\r
91  */\r
92 #define secureportSET_CONTROL( ulControl ) \\r
93     __asm volatile ( "msr control, %0" : : "r" ( ulControl ) : "memory" )\r
94 \r
95 /**\r
96  * @brief Read the Interrupt Program Status Register (IPSR) value in the given\r
97  * variable.\r
98  */\r
99 #define secureportREAD_IPSR( ulIPSR ) \\r
100     __asm volatile ( "mrs %0, ipsr"  : "=r" ( ulIPSR ) )\r
101 \r
102 /**\r
103  * @brief PRIMASK value to enable interrupts.\r
104  */\r
105 #define secureportPRIMASK_ENABLE_INTERRUPTS_VAL     0\r
106 \r
107 /**\r
108  * @brief PRIMASK value to disable interrupts.\r
109  */\r
110 #define secureportPRIMASK_DISABLE_INTERRUPTS_VAL    1\r
111 \r
112 /**\r
113  * @brief Disable secure interrupts.\r
114  */\r
115 #define secureportDISABLE_SECURE_INTERRUPTS()        secureportSET_SECURE_PRIMASK( secureportPRIMASK_DISABLE_INTERRUPTS_VAL )\r
116 \r
117 /**\r
118  * @brief Disable non-secure interrupts.\r
119  *\r
120  * This effectively disables context switches.\r
121  */\r
122 #define secureportDISABLE_NON_SECURE_INTERRUPTS()    secureportSET_NON_SECURE_PRIMASK( secureportPRIMASK_DISABLE_INTERRUPTS_VAL )\r
123 \r
124 /**\r
125  * @brief Enable non-secure interrupts.\r
126  */\r
127 #define secureportENABLE_NON_SECURE_INTERRUPTS()     secureportSET_NON_SECURE_PRIMASK( secureportPRIMASK_ENABLE_INTERRUPTS_VAL )\r
128 \r
129 /**\r
130  * @brief Assert definition.\r
131  */\r
132 #define secureportASSERT( x )                      \\r
133     if( ( x ) == 0 )                               \\r
134     {                                              \\r
135         secureportDISABLE_SECURE_INTERRUPTS();     \\r
136         secureportDISABLE_NON_SECURE_INTERRUPTS(); \\r
137         for( ; ; ) {; }                            \\r
138     }\r
139 \r
140 #endif /* __SECURE_PORT_MACROS_H__ */\r