1 /*
2 * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 /*
20 * This file is derivative of CMSIS V5.9.0 startup_ARMCM55.c
21 * Git SHA: 2b7495b8535bdcb306dac29b9ded4cfb679d7e5c
22 */
23
24 #include "tfm_hal_device_header.h"
25
26 /*----------------------------------------------------------------------------
27 External References
28 *----------------------------------------------------------------------------*/
29 extern uint32_t __INITIAL_SP;
30 extern uint32_t __STACK_LIMIT;
31 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
32 extern uint64_t __STACK_SEAL;
33 #endif
34
35 extern __NO_RETURN void __PROGRAM_START(void);
36
37 /*----------------------------------------------------------------------------
38 Internal References
39 *----------------------------------------------------------------------------*/
40 __NO_RETURN void Reset_Handler (void);
41
42 /*----------------------------------------------------------------------------
43 Exception / Interrupt Handler
44 *----------------------------------------------------------------------------*/
45 #define DEFAULT_IRQ_HANDLER(handler_name) \
46 __NO_RETURN void __WEAK handler_name(void); \
47 void handler_name(void) { \
48 while(1); \
49 }
50
51 /* Exceptions */
52 DEFAULT_IRQ_HANDLER(NMI_Handler)
53 DEFAULT_IRQ_HANDLER(HardFault_Handler)
54 DEFAULT_IRQ_HANDLER(MemManage_Handler)
55 DEFAULT_IRQ_HANDLER(BusFault_Handler)
56 DEFAULT_IRQ_HANDLER(UsageFault_Handler)
57 DEFAULT_IRQ_HANDLER(SecureFault_Handler)
58 DEFAULT_IRQ_HANDLER(SVC_Handler)
59 DEFAULT_IRQ_HANDLER(DebugMon_Handler)
60 DEFAULT_IRQ_HANDLER(PendSV_Handler)
61 DEFAULT_IRQ_HANDLER(SysTick_Handler)
62
63 DEFAULT_IRQ_HANDLER(NONSEC_WATCHDOG_RESET_REQ_Handler)
64 DEFAULT_IRQ_HANDLER(NONSEC_WATCHDOG_Handler)
65 DEFAULT_IRQ_HANDLER(SLOWCLK_Timer_Handler)
66 DEFAULT_IRQ_HANDLER(TFM_TIMER0_IRQ_Handler)
67 DEFAULT_IRQ_HANDLER(TIMER1_Handler)
68 DEFAULT_IRQ_HANDLER(TIMER2_Handler)
69 DEFAULT_IRQ_HANDLER(MPC_Handler)
70 DEFAULT_IRQ_HANDLER(PPC_Handler)
71 DEFAULT_IRQ_HANDLER(MSC_Handler)
72 DEFAULT_IRQ_HANDLER(BRIDGE_ERROR_Handler)
73 DEFAULT_IRQ_HANDLER(PPU_Combined_Handler)
74 DEFAULT_IRQ_HANDLER(NPU0_Handler)
75 DEFAULT_IRQ_HANDLER(NPU1_Handler)
76 DEFAULT_IRQ_HANDLER(NPU2_Handler)
77 DEFAULT_IRQ_HANDLER(NPU3_Handler)
78 DEFAULT_IRQ_HANDLER(KMU_Handler)
79 DEFAULT_IRQ_HANDLER(DMA_Combined_S_Handler)
80 DEFAULT_IRQ_HANDLER(DMA_Combined_NS_Handler)
81 DEFAULT_IRQ_HANDLER(DMA_Security_Violation_Handler)
82 DEFAULT_IRQ_HANDLER(TIMER3_AON_Handler)
83 DEFAULT_IRQ_HANDLER(CPU0_CTI_0_Handler)
84 DEFAULT_IRQ_HANDLER(CPU0_CTI_1_Handler)
85
86 DEFAULT_IRQ_HANDLER(SAM_Critical_Sec_Fault_S_Handler)
87 DEFAULT_IRQ_HANDLER(SAM_Sec_Fault_S_Handler)
88 DEFAULT_IRQ_HANDLER(GPIO_Combined_S_Handler)
89 DEFAULT_IRQ_HANDLER(SDC_Handler)
90 DEFAULT_IRQ_HANDLER(FPU_Handler)
91 DEFAULT_IRQ_HANDLER(SRAM_TRAM_ECC_Err_S_Handler)
92 DEFAULT_IRQ_HANDLER(SIC_S_Handler)
93 DEFAULT_IRQ_HANDLER(ATU_S_Handler)
94 DEFAULT_IRQ_HANDLER(CMU_MHU0_Sender_Handler)
95 DEFAULT_IRQ_HANDLER(CMU_MHU0_Receiver_Handler)
96 DEFAULT_IRQ_HANDLER(CMU_MHU1_Sender_Handler)
97 DEFAULT_IRQ_HANDLER(CMU_MHU1_Receiver_Handler)
98 DEFAULT_IRQ_HANDLER(CMU_MHU2_Sender_Handler)
99 DEFAULT_IRQ_HANDLER(CMU_MHU2_Receiver_Handler)
100 DEFAULT_IRQ_HANDLER(CMU_MHU3_Sender_Handler)
101 DEFAULT_IRQ_HANDLER(CMU_MHU3_Receiver_Handler)
102 DEFAULT_IRQ_HANDLER(CMU_MHU4_Sender_Handler)
103 DEFAULT_IRQ_HANDLER(CMU_MHU4_Receiver_Handler)
104 DEFAULT_IRQ_HANDLER(CMU_MHU5_Sender_Handler)
105 DEFAULT_IRQ_HANDLER(CMU_MHU5_Receiver_Handler)
106 DEFAULT_IRQ_HANDLER(CMU_MHU6_Sender_Handler)
107 DEFAULT_IRQ_HANDLER(CMU_MHU6_Receiver_Handler)
108 DEFAULT_IRQ_HANDLER(CMU_MHU7_Sender_Handler)
109 DEFAULT_IRQ_HANDLER(CMU_MHU7_Receiver_Handler)
110 DEFAULT_IRQ_HANDLER(CMU_MHU8_Sender_Handler)
111 DEFAULT_IRQ_HANDLER(CMU_MHU8_Receiver_Handler)
112 DEFAULT_IRQ_HANDLER(Crypto_Engine_S_Handler)
113 DEFAULT_IRQ_HANDLER(SoC_System_Timer0_AON_Handler)
114 DEFAULT_IRQ_HANDLER(SoC_System_Timer1_AON_Handler)
115 DEFAULT_IRQ_HANDLER(SRAM_ECC_Partial_Write_S_Handler)
116 DEFAULT_IRQ_HANDLER(Integrity_Checker_Handler)
117
118 /*----------------------------------------------------------------------------
119 Exception / Interrupt Vector table
120 *----------------------------------------------------------------------------*/
121
122 #if defined ( __GNUC__ )
123 #pragma GCC diagnostic push
124 #pragma GCC diagnostic ignored "-Wpedantic"
125 #endif
126
127 extern const VECTOR_TABLE_Type __VECTOR_TABLE[];
128 const VECTOR_TABLE_Type __VECTOR_TABLE[] __VECTOR_TABLE_ATTRIBUTE = {
129 (VECTOR_TABLE_Type)(&__INITIAL_SP), /* Initial Stack Pointer */
130 Reset_Handler, /* Reset Handler */
131 NMI_Handler, /* -14: NMI Handler */
132 HardFault_Handler, /* -13: Hard Fault Handler */
133 MemManage_Handler, /* -12: MPU Fault Handler */
134 BusFault_Handler, /* -11: Bus Fault Handler */
135 UsageFault_Handler, /* -10: Usage Fault Handler */
136 SecureFault_Handler, /* -9: Secure Fault Handler */
137 0, /* Reserved */
138 0, /* Reserved */
139 0, /* Reserved */
140 SVC_Handler, /* -5: SVCall Handler */
141 DebugMon_Handler, /* -4: Debug Monitor Handler */
142 0, /* Reserved */
143 PendSV_Handler, /* -2: PendSV Handler */
144 SysTick_Handler, /* -1: SysTick Handler */
145
146 NONSEC_WATCHDOG_RESET_REQ_Handler, /* 0: Non-Secure Watchdog Reset Request Handler */
147 NONSEC_WATCHDOG_Handler, /* 1: Non-Secure Watchdog Handler */
148 SLOWCLK_Timer_Handler, /* 2: SLOWCLK Timer Handler */
149 TFM_TIMER0_IRQ_Handler, /* 3: TIMER 0 Handler */
150 TIMER1_Handler, /* 4: TIMER 1 Handler */
151 TIMER2_Handler, /* 5: TIMER 2 Handler */
152 0, /* 6: Reserved */
153 0, /* 7: Reserved */
154 0, /* 8: Reserved */
155 MPC_Handler, /* 9: MPC Combined (Secure) Handler */
156 PPC_Handler, /* 10: PPC Combined (Secure) Handler */
157 MSC_Handler, /* 11: MSC Combined (Secure) Handler */
158 BRIDGE_ERROR_Handler, /* 12: Bridge Error (Secure) Handler */
159 0, /* 13: Reserved */
160 PPU_Combined_Handler, /* 14: PPU Combined (Secure) Handler */
161 0, /* 15: Reserved */
162 NPU0_Handler, /* 16: NPU0 Handler */
163 NPU1_Handler, /* 17: NPU1 Handler */
164 NPU2_Handler, /* 18: NPU2 Handler */
165 NPU3_Handler, /* 19: NPU3 Handler */
166 KMU_Handler, /* 20: KMU (Secure) Handler */
167 0, /* 21: Reserved */
168 0, /* 22: Reserved */
169 0, /* 23: Reserved */
170 DMA_Combined_S_Handler, /* 24: DMA350 Combined (Secure) Handler */
171 DMA_Combined_NS_Handler, /* 25: DMA350 Combined (Non-Secure) Handler */
172 DMA_Security_Violation_Handler, /* 26: DMA350 Security Violation Handler */
173 TIMER3_AON_Handler, /* 27: TIMER 3 AON Handler */
174 CPU0_CTI_0_Handler, /* 28: CPU0 CTI IRQ 0 Handler */
175 CPU0_CTI_1_Handler, /* 29: CPU0 CTI IRQ 1 Handler */
176 0, /* 30: Reserved */
177 0, /* 31: Reserved */
178
179 /* External interrupts */
180 SAM_Critical_Sec_Fault_S_Handler, /* 32: SAM Critical Security Fault (Secure) Handler */
181 SAM_Sec_Fault_S_Handler, /* 33: SAM Security Fault (Secure) Handler */
182 GPIO_Combined_S_Handler, /* 34: GPIO Combined (Secure) Handler */
183 SDC_Handler, /* 35: Secure Debug Channel Handler */
184 FPU_Handler, /* 36: FPU Exception Handler */
185 SRAM_TRAM_ECC_Err_S_Handler, /* 37: SRAM or TRAM Corrected ECC Error (Secure) Handler */
186 SIC_S_Handler, /* 38: Secure I-Cache (Secure) Handler */
187 ATU_S_Handler, /* 39: ATU (Secure) Handler */
188 CMU_MHU0_Sender_Handler, /* 40: CMU MHU 0 Sender Handler */
189 CMU_MHU0_Receiver_Handler, /* 41: CMU MHU 0 Receiver Handler */
190 CMU_MHU1_Sender_Handler, /* 42: CMU MHU 1 Sender Handler */
191 CMU_MHU1_Receiver_Handler, /* 43: CMU MHU 1 Receiver Handler */
192 CMU_MHU2_Sender_Handler, /* 44: CMU MHU 2 Sender Handler */
193 CMU_MHU2_Receiver_Handler, /* 45: CMU MHU 2 Receiver Handler */
194 CMU_MHU3_Sender_Handler, /* 46: CMU MHU 3 Sender Handler */
195 CMU_MHU3_Receiver_Handler, /* 47: CMU MHU 3 Receiver Handler */
196 CMU_MHU4_Sender_Handler, /* 48: CMU MHU 4 Sender Handler */
197 CMU_MHU4_Receiver_Handler, /* 49: CMU MHU 4 Receiver Handler */
198 CMU_MHU5_Sender_Handler, /* 50: CMU MHU 5 Sender Handler */
199 CMU_MHU5_Receiver_Handler, /* 51: CMU MHU 5 Receiver Handler */
200 CMU_MHU6_Sender_Handler, /* 52: CMU MHU 6 Sender Handler */
201 CMU_MHU6_Receiver_Handler, /* 53: CMU MHU 6 Receiver Handler */
202 CMU_MHU7_Sender_Handler, /* 54: CMU MHU 7 Sender Handler */
203 CMU_MHU7_Receiver_Handler, /* 55: CMU MHU 7 Receiver Handler */
204 CMU_MHU8_Sender_Handler, /* 56: CMU MHU 8 Sender Handler */
205 CMU_MHU8_Receiver_Handler, /* 57: CMU MHU 8 Receiver Handler */
206 Crypto_Engine_S_Handler, /* 58: Crypto Engine (Secure) Handler */
207 SoC_System_Timer0_AON_Handler, /* 59: SoC System Timer 0 AON Handler */
208 SoC_System_Timer1_AON_Handler, /* 60: SoC System Timer 1 AON Handler */
209 SRAM_ECC_Partial_Write_S_Handler, /* 61: SRAM ECC Detected Partial Write (Secure) Handler */
210 Integrity_Checker_Handler, /* 62: Integrity Checker Handler */
211 0, /* 63: Reserved */
212 0, /* 64: Reserved */
213 0, /* 65: Reserved */
214 0, /* 66: Reserved */
215 0, /* 67: Reserved */
216 0, /* 68: Reserved */
217 0, /* 69: Reserved */
218 0, /* 70: Reserved */
219 0, /* 71: Reserved */
220 0, /* 72: Reserved */
221 0, /* 73: Reserved */
222 0, /* 74: Reserved */
223 0, /* 75: Reserved */
224 0, /* 76: Reserved */
225 0, /* 77: Reserved */
226 0, /* 78: Reserved */
227 0, /* 79: Reserved */
228 0, /* 80: Reserved */
229 0, /* 81: Reserved */
230 0, /* 82: Reserved */
231 0, /* 83: Reserved */
232 0, /* 84: Reserved */
233 0, /* 85: Reserved */
234 0, /* 86: Reserved */
235 0, /* 87: Reserved */
236 0, /* 88: Reserved */
237 0, /* 89: Reserved */
238 0, /* 90: Reserved */
239 0, /* 91: Reserved */
240 0, /* 92: Reserved */
241 0, /* 93: Reserved */
242 0, /* 94: Reserved */
243 0, /* 95: Reserved */
244 };
245
246 #if defined ( __GNUC__ )
247 #pragma GCC diagnostic pop
248 #endif
249
250 /*----------------------------------------------------------------------------
251 Reset Handler called on controller reset
252 *----------------------------------------------------------------------------*/
Reset_Handler(void)253 void Reset_Handler(void)
254 {
255 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
256 __disable_irq();
257 #endif
258 __set_PSP((uint32_t)(&__INITIAL_SP));
259
260 __set_MSPLIM((uint32_t)(&__STACK_LIMIT));
261 __set_PSPLIM((uint32_t)(&__STACK_LIMIT));
262
263 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
264 __TZ_set_STACKSEAL_S((uint32_t *)(&__STACK_SEAL));
265 #endif
266
267 SystemInit(); /* CMSIS System Initialization */
268 __PROGRAM_START(); /* Enter PreMain (C library entry point) */
269 }
270