2 * FreeRTOS Kernel V202110.00
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * https://www.FreeRTOS.org
23 * https://github.com/FreeRTOS
28 /* Standard includes. */
31 /* Secure init includes. */
32 #include "secure_init.h"
34 /* Secure port macros. */
35 #include "secure_port_macros.h"
38 * @brief Constants required to manipulate the SCB.
40 #define secureinitSCB_AIRCR ( ( volatile uint32_t * ) 0xe000ed0c ) /* Application Interrupt and Reset Control Register. */
41 #define secureinitSCB_AIRCR_VECTKEY_POS ( 16UL )
42 #define secureinitSCB_AIRCR_VECTKEY_MASK ( 0xFFFFUL << secureinitSCB_AIRCR_VECTKEY_POS )
43 #define secureinitSCB_AIRCR_PRIS_POS ( 14UL )
44 #define secureinitSCB_AIRCR_PRIS_MASK ( 1UL << secureinitSCB_AIRCR_PRIS_POS )
47 * @brief Constants required to manipulate the FPU.
49 #define secureinitFPCCR ( ( volatile uint32_t * ) 0xe000ef34 ) /* Floating Point Context Control Register. */
50 #define secureinitFPCCR_LSPENS_POS ( 29UL )
51 #define secureinitFPCCR_LSPENS_MASK ( 1UL << secureinitFPCCR_LSPENS_POS )
52 #define secureinitFPCCR_TS_POS ( 26UL )
53 #define secureinitFPCCR_TS_MASK ( 1UL << secureinitFPCCR_TS_POS )
55 #define secureinitNSACR ( ( volatile uint32_t * ) 0xe000ed8c ) /* Non-secure Access Control Register. */
56 #define secureinitNSACR_CP10_POS ( 10UL )
57 #define secureinitNSACR_CP10_MASK ( 1UL << secureinitNSACR_CP10_POS )
58 #define secureinitNSACR_CP11_POS ( 11UL )
59 #define secureinitNSACR_CP11_MASK ( 1UL << secureinitNSACR_CP11_POS )
60 /*-----------------------------------------------------------*/
62 secureportNON_SECURE_CALLABLE void SecureInit_DePrioritizeNSExceptions( void )
66 /* Read the Interrupt Program Status Register (IPSR) value. */
67 secureportREAD_IPSR( ulIPSR );
69 /* Do nothing if the processor is running in the Thread Mode. IPSR is zero
70 * when the processor is running in the Thread Mode. */
73 *( secureinitSCB_AIRCR ) = ( *( secureinitSCB_AIRCR ) & ~( secureinitSCB_AIRCR_VECTKEY_MASK | secureinitSCB_AIRCR_PRIS_MASK ) ) |
74 ( ( 0x05FAUL << secureinitSCB_AIRCR_VECTKEY_POS ) & secureinitSCB_AIRCR_VECTKEY_MASK ) |
75 ( ( 0x1UL << secureinitSCB_AIRCR_PRIS_POS ) & secureinitSCB_AIRCR_PRIS_MASK );
78 /*-----------------------------------------------------------*/
80 secureportNON_SECURE_CALLABLE void SecureInit_EnableNSFPUAccess( void )
84 /* Read the Interrupt Program Status Register (IPSR) value. */
85 secureportREAD_IPSR( ulIPSR );
87 /* Do nothing if the processor is running in the Thread Mode. IPSR is zero
88 * when the processor is running in the Thread Mode. */
91 /* CP10 = 1 ==> Non-secure access to the Floating Point Unit is
92 * permitted. CP11 should be programmed to the same value as CP10. */
93 *( secureinitNSACR ) |= ( secureinitNSACR_CP10_MASK | secureinitNSACR_CP11_MASK );
95 /* LSPENS = 0 ==> LSPEN is writable fron non-secure state. This ensures
96 * that we can enable/disable lazy stacking in port.c file. */
97 *( secureinitFPCCR ) &= ~( secureinitFPCCR_LSPENS_MASK );
99 /* TS = 1 ==> Treat FP registers as secure i.e. callee saved FP
100 * registers (S16-S31) are also pushed to stack on exception entry and
101 * restored on exception return. */
102 *( secureinitFPCCR ) |= ( secureinitFPCCR_TS_MASK );
105 /*-----------------------------------------------------------*/