]> begriffs open source - freertos/blob - portable/GCC/ARM_CM85/secure/secure_init.c
[AUTO][RELEASE]: Bump file header version to "10.5.1"
[freertos] / portable / GCC / ARM_CM85 / secure / secure_init.c
1 /*\r
2  * FreeRTOS Kernel V10.5.1\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 /* Standard includes. */\r
30 #include <stdint.h>\r
31 \r
32 /* Secure init includes. */\r
33 #include "secure_init.h"\r
34 \r
35 /* Secure port macros. */\r
36 #include "secure_port_macros.h"\r
37 \r
38 /**\r
39  * @brief Constants required to manipulate the SCB.\r
40  */\r
41 #define secureinitSCB_AIRCR                 ( ( volatile uint32_t * ) 0xe000ed0c )  /* Application Interrupt and Reset Control Register. */\r
42 #define secureinitSCB_AIRCR_VECTKEY_POS     ( 16UL )\r
43 #define secureinitSCB_AIRCR_VECTKEY_MASK    ( 0xFFFFUL << secureinitSCB_AIRCR_VECTKEY_POS )\r
44 #define secureinitSCB_AIRCR_PRIS_POS        ( 14UL )\r
45 #define secureinitSCB_AIRCR_PRIS_MASK       ( 1UL << secureinitSCB_AIRCR_PRIS_POS )\r
46 \r
47 /**\r
48  * @brief Constants required to manipulate the FPU.\r
49  */\r
50 #define secureinitFPCCR                     ( ( volatile uint32_t * ) 0xe000ef34 )  /* Floating Point Context Control Register. */\r
51 #define secureinitFPCCR_LSPENS_POS          ( 29UL )\r
52 #define secureinitFPCCR_LSPENS_MASK         ( 1UL << secureinitFPCCR_LSPENS_POS )\r
53 #define secureinitFPCCR_TS_POS              ( 26UL )\r
54 #define secureinitFPCCR_TS_MASK             ( 1UL << secureinitFPCCR_TS_POS )\r
55 \r
56 #define secureinitNSACR                     ( ( volatile uint32_t * ) 0xe000ed8c )  /* Non-secure Access Control Register. */\r
57 #define secureinitNSACR_CP10_POS            ( 10UL )\r
58 #define secureinitNSACR_CP10_MASK           ( 1UL << secureinitNSACR_CP10_POS )\r
59 #define secureinitNSACR_CP11_POS            ( 11UL )\r
60 #define secureinitNSACR_CP11_MASK           ( 1UL << secureinitNSACR_CP11_POS )\r
61 /*-----------------------------------------------------------*/\r
62 \r
63 secureportNON_SECURE_CALLABLE void SecureInit_DePrioritizeNSExceptions( void )\r
64 {\r
65     uint32_t ulIPSR;\r
66 \r
67     /* Read the Interrupt Program Status Register (IPSR) value. */\r
68     secureportREAD_IPSR( ulIPSR );\r
69 \r
70     /* Do nothing if the processor is running in the Thread Mode. IPSR is zero\r
71      * when the processor is running in the Thread Mode. */\r
72     if( ulIPSR != 0 )\r
73     {\r
74         *( secureinitSCB_AIRCR ) = ( *( secureinitSCB_AIRCR ) & ~( secureinitSCB_AIRCR_VECTKEY_MASK | secureinitSCB_AIRCR_PRIS_MASK ) ) |\r
75                                    ( ( 0x05FAUL << secureinitSCB_AIRCR_VECTKEY_POS ) & secureinitSCB_AIRCR_VECTKEY_MASK ) |\r
76                                    ( ( 0x1UL << secureinitSCB_AIRCR_PRIS_POS ) & secureinitSCB_AIRCR_PRIS_MASK );\r
77     }\r
78 }\r
79 /*-----------------------------------------------------------*/\r
80 \r
81 secureportNON_SECURE_CALLABLE void SecureInit_EnableNSFPUAccess( void )\r
82 {\r
83     uint32_t ulIPSR;\r
84 \r
85     /* Read the Interrupt Program Status Register (IPSR) value. */\r
86     secureportREAD_IPSR( ulIPSR );\r
87 \r
88     /* Do nothing if the processor is running in the Thread Mode. IPSR is zero\r
89      * when the processor is running in the Thread Mode. */\r
90     if( ulIPSR != 0 )\r
91     {\r
92         /* CP10 = 1 ==> Non-secure access to the Floating Point Unit is\r
93          * permitted. CP11 should be programmed to the same value as CP10. */\r
94         *( secureinitNSACR ) |= ( secureinitNSACR_CP10_MASK | secureinitNSACR_CP11_MASK );\r
95 \r
96         /* LSPENS = 0 ==> LSPEN is writable fron non-secure state. This ensures\r
97          * that we can enable/disable lazy stacking in port.c file. */\r
98         *( secureinitFPCCR ) &= ~( secureinitFPCCR_LSPENS_MASK );\r
99 \r
100         /* TS = 1 ==> Treat FP registers as secure i.e. callee saved FP\r
101          * registers (S16-S31) are also pushed to stack on exception entry and\r
102          * restored on exception return. */\r
103         *( secureinitFPCCR ) |= ( secureinitFPCCR_TS_MASK );\r
104     }\r
105 }\r
106 /*-----------------------------------------------------------*/\r