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