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