1 /*******************************************************************************
2 * Copyright 2019-2021 Microchip FPGA Embedded Systems Solutions.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * MPFS HAL Embedded Software
7 *
8 */
9
10 /***************************************************************************
11 *
12 * @file mss_mtrap.c
13 * @author Microchip-FPGA Embedded Systems Solutions
14 * @brief trap functions
15 *
16 */
17 #include "mpfs_hal/mss_hal.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23
24
25 void handle_local_interrupt(uint8_t interrupt_no);
26 void handle_m_soft_interrupt(void);
27 void handle_m_timer_interrupt(void);
28 void illegal_insn_trap(uintptr_t * regs, uintptr_t mcause, uintptr_t mepc);
29 void misaligned_store_trap(uintptr_t * regs, uintptr_t mcause, uintptr_t mepc);
30 void misaligned_load_trap(uintptr_t * regs, uintptr_t mcause, uintptr_t mepc);
31 void pmp_trap(uintptr_t * regs, uintptr_t mcause, uintptr_t mepc);
32 void trap_from_machine_mode(uintptr_t * regs, uintptr_t dummy, uintptr_t mepc);
33 void bad_trap(uintptr_t* regs, uintptr_t dummy, uintptr_t mepc);
34
35
bad_trap(uintptr_t * regs,uintptr_t dummy,uintptr_t mepc)36 void bad_trap(uintptr_t* regs, uintptr_t dummy, uintptr_t mepc)
37 {
38 (void)regs;
39 (void)dummy;
40 (void)mepc;
41 while(1)
42 {
43 }
44 }
45
misaligned_store_trap(uintptr_t * regs,uintptr_t mcause,uintptr_t mepc)46 void misaligned_store_trap(uintptr_t * regs, uintptr_t mcause, uintptr_t mepc)
47 {
48 (void)regs;
49 (void)mcause;
50 (void)mepc;
51 while(1)
52 {
53 }
54 }
55
misaligned_load_trap(uintptr_t * regs,uintptr_t mcause,uintptr_t mepc)56 void misaligned_load_trap(uintptr_t * regs, uintptr_t mcause, uintptr_t mepc)
57 {
58 (void)regs;
59 (void)mcause;
60 (void)mepc;
61 while(1)
62 {
63 }
64 }
65
illegal_insn_trap(uintptr_t * regs,uintptr_t mcause,uintptr_t mepc)66 void illegal_insn_trap(uintptr_t * regs, uintptr_t mcause, uintptr_t mepc)
67 {
68 (void)regs;
69 (void)mcause;
70 (void)mepc;
71 while(1)
72 {
73 }
74 }
75
pmp_trap(uintptr_t * regs,uintptr_t mcause,uintptr_t mepc)76 void pmp_trap(uintptr_t * regs, uintptr_t mcause, uintptr_t mepc)
77 {
78 (void)regs;
79 (void)mcause;
80 (void)mepc;
81 while(1)
82 {
83 }
84 }
85
86 /*------------------------------------------------------------------------------
87 * RISC-V interrupt handler for external interrupts.
88 */
89 #ifndef SIFIVE_HIFIVE_UNLEASHED
90 uint8_t (*ext_irq_handler_table[PLIC_NUM_SOURCES])(void) =
91 {
92 Invalid_IRQHandler,
93 l2_metadata_corr_IRQHandler,
94 l2_metadata_uncorr_IRQHandler,
95 l2_data_corr_IRQHandler,
96 l2_data_uncorr_IRQHandler,
97 dma_ch0_DONE_IRQHandler,
98 dma_ch0_ERR_IRQHandler,
99 dma_ch1_DONE_IRQHandler,
100 dma_ch1_ERR_IRQHandler,
101 dma_ch2_DONE_IRQHandler,
102 dma_ch2_ERR_IRQHandler,
103 dma_ch3_DONE_IRQHandler,
104 dma_ch3_ERR_IRQHandler,
105 gpio0_bit0_or_gpio2_bit13_plic_0_IRQHandler,
106 gpio0_bit1_or_gpio2_bit13_plic_1_IRQHandler,
107 gpio0_bit2_or_gpio2_bit13_plic_2_IRQHandler,
108 gpio0_bit3_or_gpio2_bit13_plic_3_IRQHandler,
109 gpio0_bit4_or_gpio2_bit13_plic_4_IRQHandler,
110 gpio0_bit5_or_gpio2_bit13_plic_5_IRQHandler,
111 gpio0_bit6_or_gpio2_bit13_plic_6_IRQHandler,
112 gpio0_bit7_or_gpio2_bit13_plic_7_IRQHandler,
113 gpio0_bit8_or_gpio2_bit13_plic_8_IRQHandler,
114 gpio0_bit9_or_gpio2_bit13_plic_9_IRQHandler,
115 gpio0_bit10_or_gpio2_bit13_plic_10_IRQHandler,
116 gpio0_bit11_or_gpio2_bit13_plic_11_IRQHandler,
117 gpio0_bit12_or_gpio2_bit13_plic_12_IRQHandler,
118
119 gpio0_bit13_or_gpio2_bit13_plic_13_IRQHandler,
120 gpio1_bit0_or_gpio2_bit14_plic_14_IRQHandler,
121 gpio1_bit1_or_gpio2_bit15_plic_15_IRQHandler,
122 gpio1_bit2_or_gpio2_bit16_plic_16_IRQHandler,
123 gpio1_bit3_or_gpio2_bit17_plic_17_IRQHandler,
124 gpio1_bit4_or_gpio2_bit18_plic_18_IRQHandler,
125 gpio1_bit5_or_gpio2_bit19_plic_19_IRQHandler,
126 gpio1_bit6_or_gpio2_bit20_plic_20_IRQHandler,
127 gpio1_bit7_or_gpio2_bit21_plic_21_IRQHandler,
128 gpio1_bit8_or_gpio2_bit22_plic_22_IRQHandler,
129 gpio1_bit9_or_gpio2_bit23_plic_23_IRQHandler,
130 gpio1_bit10_or_gpio2_bit24_plic_24_IRQHandler,
131 gpio1_bit11_or_gpio2_bit25_plic_25_IRQHandler,
132 gpio1_bit12_or_gpio2_bit26_plic_26_IRQHandler,
133 gpio1_bit13_or_gpio2_bit27_plic_27_IRQHandler,
134
135 gpio1_bit14_or_gpio2_bit28_plic_28_IRQHandler,
136 gpio1_bit15_or_gpio2_bit29_plic_29_IRQHandler,
137 gpio1_bit16_or_gpio2_bit30_plic_30_IRQHandler,
138 gpio1_bit17_or_gpio2_bit31_plic_31_IRQHandler,
139
140 gpio1_bit18_plic_32_IRQHandler,
141 gpio1_bit19_plic_33_IRQHandler,
142 gpio1_bit20_plic_34_IRQHandler,
143 gpio1_bit21_plic_35_IRQHandler,
144 gpio1_bit22_plic_36_IRQHandler,
145 gpio1_bit23_plic_37_IRQHandler,
146
147 gpio0_non_direct_plic_IRQHandler,
148 gpio1_non_direct_plic_IRQHandler,
149 gpio2_non_direct_plic_IRQHandler,
150
151 spi0_plic_IRQHandler,
152 spi1_plic_IRQHandler,
153 external_can0_plic_IRQHandler,
154 can1_IRQHandler,
155 External_i2c0_main_plic_IRQHandler,
156 External_i2c0_alert_plic_IRQHandler,
157 i2c0_sus_plic_IRQHandler,
158 i2c1_main_plic_IRQHandler,
159 i2c1_alert_plic_IRQHandler,
160 i2c1_sus_plic_IRQHandler,
161 mac0_int_plic_IRQHandler,
162 mac0_queue1_plic_IRQHandler,
163 mac0_queue2_plic_IRQHandler,
164 mac0_queue3_plic_IRQHandler,
165 mac0_emac_plic_IRQHandler,
166 mac0_mmsl_plic_IRQHandler,
167 mac1_int_plic_IRQHandler,
168 mac1_queue1_plic_IRQHandler,
169 mac1_queue2_plic_IRQHandler,
170 mac1_queue3_plic_IRQHandler,
171 mac1_emac_plic_IRQHandler,
172 mac1_mmsl_plic_IRQHandler,
173 ddrc_train_plic_IRQHandler,
174 scb_interrupt_plic_IRQHandler,
175 ecc_error_plic_IRQHandler,
176 ecc_correct_plic_IRQHandler,
177 rtc_wakeup_plic_IRQHandler,
178 rtc_match_plic_IRQHandler,
179 timer1_plic_IRQHandler,
180 timer2_plic_IRQHandler,
181 envm_plic_IRQHandler,
182 qspi_plic_IRQHandler,
183 usb_dma_plic_IRQHandler,
184 usb_mc_plic_IRQHandler,
185 mmc_main_plic_IRQHandler,
186 mmc_wakeup_plic_IRQHandler,
187 mmuart0_plic_77_IRQHandler,
188 mmuart1_plic_IRQHandler,
189 mmuart2_plic_IRQHandler,
190 mmuart3_plic_IRQHandler,
191 mmuart4_plic_IRQHandler,
192
193 g5c_devrst_plic_IRQHandler,
194 g5c_message_plic_IRQHandler,
195 usoc_vc_interrupt_plic_IRQHandler,
196 usoc_smb_interrupt_plic_IRQHandler,
197 e51_0_Maintence_plic_IRQHandler,
198
199 wdog0_mvrp_plic_IRQHandler,
200 wdog1_mvrp_plic_IRQHandler, /*100 contains multiple interrupts- */
201 wdog2_mvrp_plic_IRQHandler,
202 wdog3_mvrp_plic_IRQHandler,
203 wdog4_mvrp_plic_IRQHandler,
204 wdog0_tout_plic_IRQHandler,
205 wdog1_tout_plic_IRQHandler,
206 wdog2_tout_plic_IRQHandler,
207 wdog3_tout_plic_IRQHandler,
208 wdog4_tout_plic_IRQHandler,
209
210 g5c_mss_spi_plic_IRQHandler,
211 volt_temp_alarm_plic_IRQHandler,
212 athena_complete_plic_IRQHandler,
213 athena_alarm_plic_IRQHandler,
214 athena_bus_error_plic_IRQHandler,
215 usoc_axic_us_plic_IRQHandler,
216 usoc_axic_ds_plic_IRQHandler,
217
218 reserved_104_plic_IRQHandler,
219
220 fabric_f2h_0_plic_IRQHandler,
221 fabric_f2h_1_plic_IRQHandler,
222 fabric_f2h_2_plic_IRQHandler,
223 fabric_f2h_3_plic_IRQHandler,
224 fabric_f2h_4_plic_IRQHandler,
225 fabric_f2h_5_plic_IRQHandler,
226 fabric_f2h_6_plic_IRQHandler,
227 fabric_f2h_7_plic_IRQHandler,
228 fabric_f2h_8_plic_IRQHandler,
229 fabric_f2h_9_plic_IRQHandler,
230
231 fabric_f2h_10_plic_IRQHandler,
232 fabric_f2h_11_plic_IRQHandler,
233 fabric_f2h_12_plic_IRQHandler,
234 fabric_f2h_13_plic_IRQHandler,
235 fabric_f2h_14_plic_IRQHandler,
236 fabric_f2h_15_plic_IRQHandler,
237 fabric_f2h_16_plic_IRQHandler,
238 fabric_f2h_17_plic_IRQHandler,
239 fabric_f2h_18_plic_IRQHandler,
240 fabric_f2h_19_plic_IRQHandler,
241
242 fabric_f2h_20_plic_IRQHandler,
243 fabric_f2h_21_plic_IRQHandler,
244 fabric_f2h_22_plic_IRQHandler,
245 fabric_f2h_23_plic_IRQHandler,
246 fabric_f2h_24_plic_IRQHandler,
247 fabric_f2h_25_plic_IRQHandler,
248 fabric_f2h_26_plic_IRQHandler,
249 fabric_f2h_27_plic_IRQHandler,
250 fabric_f2h_28_plic_IRQHandler,
251 fabric_f2h_29_plic_IRQHandler,
252
253 fabric_f2h_30_plic_IRQHandler,
254 fabric_f2h_31_plic_IRQHandler,
255
256 fabric_f2h_32_plic_IRQHandler,
257 fabric_f2h_33_plic_IRQHandler,
258 fabric_f2h_34_plic_IRQHandler,
259 fabric_f2h_35_plic_IRQHandler,
260 fabric_f2h_36_plic_IRQHandler,
261 fabric_f2h_37_plic_IRQHandler,
262 fabric_f2h_38_plic_IRQHandler,
263 fabric_f2h_39_plic_IRQHandler,
264 fabric_f2h_40_plic_IRQHandler,
265 fabric_f2h_41_plic_IRQHandler,
266
267 fabric_f2h_42_plic_IRQHandler,
268 fabric_f2h_43_plic_IRQHandler,
269 fabric_f2h_44_plic_IRQHandler,
270 fabric_f2h_45_plic_IRQHandler,
271 fabric_f2h_46_plic_IRQHandler,
272 fabric_f2h_47_plic_IRQHandler,
273 fabric_f2h_48_plic_IRQHandler,
274 fabric_f2h_49_plic_IRQHandler,
275 fabric_f2h_50_plic_IRQHandler,
276 fabric_f2h_51_plic_IRQHandler,
277
278 fabric_f2h_52_plic_IRQHandler,
279 fabric_f2h_53_plic_IRQHandler,
280 fabric_f2h_54_plic_IRQHandler,
281 fabric_f2h_55_plic_IRQHandler,
282 fabric_f2h_56_plic_IRQHandler,
283 fabric_f2h_57_plic_IRQHandler,
284 fabric_f2h_58_plic_IRQHandler,
285 fabric_f2h_59_plic_IRQHandler,
286 fabric_f2h_60_plic_IRQHandler,
287 fabric_f2h_61_plic_IRQHandler,
288
289 fabric_f2h_62_plic_IRQHandler,
290 fabric_f2h_63_plic_IRQHandler,
291
292 bus_error_unit_hart_0_plic_IRQHandler,
293 bus_error_unit_hart_1_plic_IRQHandler,
294 bus_error_unit_hart_2_plic_IRQHandler,
295 bus_error_unit_hart_3_plic_IRQHandler,
296 bus_error_unit_hart_4_plic_IRQHandler
297 };
298
299 #define E51_LOCAL_NUM_SOURCES 48U
300
301
302 void (*local_irq_handler_e51_table[E51_LOCAL_NUM_SOURCES])(void) =
303 {
304 maintenance_e51_local_IRQHandler_0, /* reference multiple interrupts */
305 usoc_smb_interrupt_e51_local_IRQHandler_1,
306 usoc_vc_interrupt_e51_local_IRQHandler_2,
307 g5c_message_e51_local_IRQHandler_3,
308 g5c_devrst_e51_local_IRQHandler_4,
309 wdog4_tout_e51_local_IRQHandler_5,
310 wdog3_tout_e51_local_IRQHandler_6,
311 wdog2_tout_e51_local_IRQHandler_7,
312 wdog1_tout_e51_local_IRQHandler_8,
313 wdog0_tout_e51_local_IRQHandler_9,
314 wdog0_mvrp_e51_local_IRQHandler_10,
315 mmuart0_e51_local_IRQHandler_11,
316 envm_e51_local_IRQHandler_12,
317 ecc_correct_e51_local_IRQHandler_13,
318 ecc_error_e51_local_IRQHandler_14,
319 scb_interrupt_e51_local_IRQHandler_15,
320 fabric_f2h_32_e51_local_IRQHandler_16,
321 fabric_f2h_33_e51_local_IRQHandler_17,
322 fabric_f2h_34_e51_local_IRQHandler_18,
323 fabric_f2h_35_e51_local_IRQHandler_19,
324 fabric_f2h_36_e51_local_IRQHandler_20,
325 fabric_f2h_37_e51_local_IRQHandler_21,
326 fabric_f2h_38_e51_local_IRQHandler_22,
327 fabric_f2h_39_e51_local_IRQHandler_23,
328 fabric_f2h_40_e51_local_IRQHandler_24,
329 fabric_f2h_41_e51_local_IRQHandler_25,
330
331 fabric_f2h_42_e51_local_IRQHandler_26,
332 fabric_f2h_43_e51_local_IRQHandler_27,
333 fabric_f2h_44_e51_local_IRQHandler_28,
334 fabric_f2h_45_e51_local_IRQHandler_29,
335 fabric_f2h_46_e51_local_IRQHandler_30,
336 fabric_f2h_47_e51_local_IRQHandler_31,
337 fabric_f2h_48_e51_local_IRQHandler_32,
338 fabric_f2h_49_e51_local_IRQHandler_33,
339 fabric_f2h_50_e51_local_IRQHandler_34,
340 fabric_f2h_51_e51_local_IRQHandler_35,
341
342 fabric_f2h_52_e51_local_IRQHandler_36,
343 fabric_f2h_53_e51_local_IRQHandler_37,
344 fabric_f2h_54_e51_local_IRQHandler_38,
345 fabric_f2h_55_e51_local_IRQHandler_39,
346 fabric_f2h_56_e51_local_IRQHandler_40,
347 fabric_f2h_57_e51_local_IRQHandler_41,
348 fabric_f2h_58_e51_local_IRQHandler_42,
349 fabric_f2h_59_e51_local_IRQHandler_43,
350 fabric_f2h_60_e51_local_IRQHandler_44,
351 fabric_f2h_61_e51_local_IRQHandler_45,
352
353 fabric_f2h_62_e51_local_IRQHandler_46,
354 fabric_f2h_63_e51_local_IRQHandler_47
355 };
356
357
358 typedef void (*local_int_p_t)(void);
359
360 /* U54 1 */
361 local_int_p_t local_irq_handler_u54_1_table[E51_LOCAL_NUM_SOURCES] =
362 {
363 /*reference multiple interrupts*/
364 spare_u54_local_IRQHandler_0,
365 spare_u54_local_IRQHandler_1,
366 spare_u54_local_IRQHandler_2,
367
368 /*parse hart ID to discover which mac is the source*/
369 mac_mmsl_u54_1_local_IRQHandler_3,
370 mac_emac_u54_1_local_IRQHandler_4,
371 mac_queue3_u54_1_local_IRQHandler_5,
372 mac_queue2_u54_1_local_IRQHandler_6,
373 mac_queue1_u54_1_local_IRQHandler_7,
374 mac_int_u54_1_local_IRQHandler_8,
375
376 /*parse hart ID to discover which wdog is the source*/
377 wdog_tout_u54_h1_local_IRQHandler_9,
378 mvrp_u54_local_IRQHandler_10,
379 mmuart_u54_h1_local_IRQHandler_11,
380
381 spare_u54_local_IRQHandler_12,
382 spare_u54_local_IRQHandler_13,
383 spare_u54_local_IRQHandler_14,
384 spare_u54_local_IRQHandler_15,
385
386 fabric_f2h_0_u54_local_IRQHandler_16,
387 fabric_f2h_1_u54_local_IRQHandler_17,
388 fabric_f2h_2_u54_local_IRQHandler_18,
389 fabric_f2h_3_u54_local_IRQHandler_19,
390 fabric_f2h_4_u54_local_IRQHandler_20,
391 fabric_f2h_5_u54_local_IRQHandler_21,
392 fabric_f2h_6_u54_local_IRQHandler_22,
393 fabric_f2h_7_u54_local_IRQHandler_23,
394 fabric_f2h_8_u54_local_IRQHandler_24,
395 fabric_f2h_9_u54_local_IRQHandler_25,
396
397 fabric_f2h_10_u54_local_IRQHandler_26,
398 fabric_f2h_11_u54_local_IRQHandler_27,
399 fabric_f2h_12_u54_local_IRQHandler_28,
400 fabric_f2h_13_u54_local_IRQHandler_29,
401 fabric_f2h_14_u54_local_IRQHandler_30,
402 fabric_f2h_15_u54_local_IRQHandler_31,
403 fabric_f2h_16_u54_local_IRQHandler_32,
404 fabric_f2h_17_u54_local_IRQHandler_33,
405 fabric_f2h_18_u54_local_IRQHandler_34,
406 fabric_f2h_19_u54_local_IRQHandler_35,
407
408 fabric_f2h_20_u54_local_IRQHandler_36,
409 fabric_f2h_21_u54_local_IRQHandler_37,
410 fabric_f2h_22_u54_local_IRQHandler_38,
411 fabric_f2h_23_u54_local_IRQHandler_39,
412 fabric_f2h_24_u54_local_IRQHandler_40,
413 fabric_f2h_25_u54_local_IRQHandler_41,
414 fabric_f2h_26_u54_local_IRQHandler_42,
415 fabric_f2h_27_u54_local_IRQHandler_43,
416 fabric_f2h_28_u54_local_IRQHandler_44,
417 fabric_f2h_29_u54_local_IRQHandler_45,
418
419 fabric_f2h_30_u54_local_IRQHandler_46,
420 fabric_f2h_31_u54_local_IRQHandler_47
421 };
422
423 /* U54 2 */
424 local_int_p_t local_irq_handler_u54_2_table[E51_LOCAL_NUM_SOURCES] =
425 {
426 /*reference multiple interrupts*/
427 spare_u54_local_IRQHandler_0,
428 spare_u54_local_IRQHandler_1,
429 spare_u54_local_IRQHandler_2,
430
431 /*parse hart ID to discover which mac is the source*/
432 mac_mmsl_u54_2_local_IRQHandler_3,
433 mac_emac_u54_2_local_IRQHandler_4,
434 mac_queue3_u54_2_local_IRQHandler_5,
435 mac_queue2_u54_2_local_IRQHandler_6,
436 mac_queue1_u54_2_local_IRQHandler_7,
437 mac_int_u54_2_local_IRQHandler_8,
438
439 /*parse hart ID to discover which wdog is the source*/
440 wdog_tout_u54_h2_local_IRQHandler_9,
441 mvrp_u54_local_IRQHandler_10,
442 mmuart_u54_h2_local_IRQHandler_11,
443
444 spare_u54_local_IRQHandler_12,
445 spare_u54_local_IRQHandler_13,
446 spare_u54_local_IRQHandler_14,
447 spare_u54_local_IRQHandler_15,
448
449 fabric_f2h_0_u54_local_IRQHandler_16,
450 fabric_f2h_1_u54_local_IRQHandler_17,
451 fabric_f2h_2_u54_local_IRQHandler_18,
452 fabric_f2h_3_u54_local_IRQHandler_19,
453 fabric_f2h_4_u54_local_IRQHandler_20,
454 fabric_f2h_5_u54_local_IRQHandler_21,
455 fabric_f2h_6_u54_local_IRQHandler_22,
456 fabric_f2h_7_u54_local_IRQHandler_23,
457 fabric_f2h_8_u54_local_IRQHandler_24,
458 fabric_f2h_9_u54_local_IRQHandler_25,
459
460 fabric_f2h_10_u54_local_IRQHandler_26,
461 fabric_f2h_11_u54_local_IRQHandler_27,
462 fabric_f2h_12_u54_local_IRQHandler_28,
463 fabric_f2h_13_u54_local_IRQHandler_29,
464 fabric_f2h_14_u54_local_IRQHandler_30,
465 fabric_f2h_15_u54_local_IRQHandler_31,
466 fabric_f2h_16_u54_local_IRQHandler_32,
467 fabric_f2h_17_u54_local_IRQHandler_33,
468 fabric_f2h_18_u54_local_IRQHandler_34,
469 fabric_f2h_19_u54_local_IRQHandler_35,
470
471 fabric_f2h_20_u54_local_IRQHandler_36,
472 fabric_f2h_21_u54_local_IRQHandler_37,
473 fabric_f2h_22_u54_local_IRQHandler_38,
474 fabric_f2h_23_u54_local_IRQHandler_39,
475 fabric_f2h_24_u54_local_IRQHandler_40,
476 fabric_f2h_25_u54_local_IRQHandler_41,
477 fabric_f2h_26_u54_local_IRQHandler_42,
478 fabric_f2h_27_u54_local_IRQHandler_43,
479 fabric_f2h_28_u54_local_IRQHandler_44,
480 fabric_f2h_29_u54_local_IRQHandler_45,
481
482 fabric_f2h_30_u54_local_IRQHandler_46,
483 fabric_f2h_31_u54_local_IRQHandler_47
484 };
485
486 /* U54 3 */
487 local_int_p_t local_irq_handler_u54_3_table[E51_LOCAL_NUM_SOURCES] =
488 {
489 /*reference multiple interrupts*/
490 spare_u54_local_IRQHandler_0,
491 spare_u54_local_IRQHandler_1,
492 spare_u54_local_IRQHandler_2,
493
494 /*parse hart ID to discover which mac is the source*/
495 mac_mmsl_u54_3_local_IRQHandler_3,
496 mac_emac_u54_3_local_IRQHandler_4,
497 mac_queue3_u54_3_local_IRQHandler_5,
498 mac_queue2_u54_3_local_IRQHandler_6,
499 mac_queue1_u54_3_local_IRQHandler_7,
500 mac_int_u54_3_local_IRQHandler_8,
501
502 /*parse hart ID to discover which wdog is the source*/
503 wdog_tout_u54_h3_local_IRQHandler_9,
504 mvrp_u54_local_IRQHandler_10,
505 mmuart_u54_h3_local_IRQHandler_11,
506
507 spare_u54_local_IRQHandler_12,
508 spare_u54_local_IRQHandler_13,
509 spare_u54_local_IRQHandler_14,
510 spare_u54_local_IRQHandler_15,
511
512 fabric_f2h_0_u54_local_IRQHandler_16,
513 fabric_f2h_1_u54_local_IRQHandler_17,
514 fabric_f2h_2_u54_local_IRQHandler_18,
515 fabric_f2h_3_u54_local_IRQHandler_19,
516 fabric_f2h_4_u54_local_IRQHandler_20,
517 fabric_f2h_5_u54_local_IRQHandler_21,
518 fabric_f2h_6_u54_local_IRQHandler_22,
519 fabric_f2h_7_u54_local_IRQHandler_23,
520 fabric_f2h_8_u54_local_IRQHandler_24,
521 fabric_f2h_9_u54_local_IRQHandler_25,
522
523 fabric_f2h_10_u54_local_IRQHandler_26,
524 fabric_f2h_11_u54_local_IRQHandler_27,
525 fabric_f2h_12_u54_local_IRQHandler_28,
526 fabric_f2h_13_u54_local_IRQHandler_29,
527 fabric_f2h_14_u54_local_IRQHandler_30,
528 fabric_f2h_15_u54_local_IRQHandler_31,
529 fabric_f2h_16_u54_local_IRQHandler_32,
530 fabric_f2h_17_u54_local_IRQHandler_33,
531 fabric_f2h_18_u54_local_IRQHandler_34,
532 fabric_f2h_19_u54_local_IRQHandler_35,
533
534 fabric_f2h_20_u54_local_IRQHandler_36,
535 fabric_f2h_21_u54_local_IRQHandler_37,
536 fabric_f2h_22_u54_local_IRQHandler_38,
537 fabric_f2h_23_u54_local_IRQHandler_39,
538 fabric_f2h_24_u54_local_IRQHandler_40,
539 fabric_f2h_25_u54_local_IRQHandler_41,
540 fabric_f2h_26_u54_local_IRQHandler_42,
541 fabric_f2h_27_u54_local_IRQHandler_43,
542 fabric_f2h_28_u54_local_IRQHandler_44,
543 fabric_f2h_29_u54_local_IRQHandler_45,
544
545 fabric_f2h_30_u54_local_IRQHandler_46,
546 fabric_f2h_31_u54_local_IRQHandler_47
547 };
548
549 /* U54 4 */
550 local_int_p_t local_irq_handler_u54_4_table[E51_LOCAL_NUM_SOURCES] =
551 {
552 /*reference multiple interrupts*/
553 spare_u54_local_IRQHandler_0,
554 spare_u54_local_IRQHandler_1,
555 spare_u54_local_IRQHandler_2,
556
557 /*parse hart ID to discover which mac is the source*/
558 mac_mmsl_u54_4_local_IRQHandler_3,
559 mac_emac_u54_4_local_IRQHandler_4,
560 mac_queue3_u54_4_local_IRQHandler_5,
561 mac_queue2_u54_4_local_IRQHandler_6,
562 mac_queue1_u54_4_local_IRQHandler_7,
563 mac_int_u54_4_local_IRQHandler_8,
564
565 /*parse hart ID to discover which wdog is the source*/
566 wdog_tout_u54_h4_local_IRQHandler_9,
567 mvrp_u54_local_IRQHandler_10,
568 mmuart_u54_h4_local_IRQHandler_11,
569
570 spare_u54_local_IRQHandler_12,
571 spare_u54_local_IRQHandler_13,
572 spare_u54_local_IRQHandler_14,
573 spare_u54_local_IRQHandler_15,
574
575 fabric_f2h_0_u54_local_IRQHandler_16,
576 fabric_f2h_1_u54_local_IRQHandler_17,
577 fabric_f2h_2_u54_local_IRQHandler_18,
578 fabric_f2h_3_u54_local_IRQHandler_19,
579 fabric_f2h_4_u54_local_IRQHandler_20,
580 fabric_f2h_5_u54_local_IRQHandler_21,
581 fabric_f2h_6_u54_local_IRQHandler_22,
582 fabric_f2h_7_u54_local_IRQHandler_23,
583 fabric_f2h_8_u54_local_IRQHandler_24,
584 fabric_f2h_9_u54_local_IRQHandler_25,
585
586 fabric_f2h_10_u54_local_IRQHandler_26,
587 fabric_f2h_11_u54_local_IRQHandler_27,
588 fabric_f2h_12_u54_local_IRQHandler_28,
589 fabric_f2h_13_u54_local_IRQHandler_29,
590 fabric_f2h_14_u54_local_IRQHandler_30,
591 fabric_f2h_15_u54_local_IRQHandler_31,
592 fabric_f2h_16_u54_local_IRQHandler_32,
593 fabric_f2h_17_u54_local_IRQHandler_33,
594 fabric_f2h_18_u54_local_IRQHandler_34,
595 fabric_f2h_19_u54_local_IRQHandler_35,
596
597 fabric_f2h_20_u54_local_IRQHandler_36,
598 fabric_f2h_21_u54_local_IRQHandler_37,
599 fabric_f2h_22_u54_local_IRQHandler_38,
600 fabric_f2h_23_u54_local_IRQHandler_39,
601 fabric_f2h_24_u54_local_IRQHandler_40,
602 fabric_f2h_25_u54_local_IRQHandler_41,
603 fabric_f2h_26_u54_local_IRQHandler_42,
604 fabric_f2h_27_u54_local_IRQHandler_43,
605 fabric_f2h_28_u54_local_IRQHandler_44,
606 fabric_f2h_29_u54_local_IRQHandler_45,
607
608 fabric_f2h_30_u54_local_IRQHandler_46,
609 fabric_f2h_31_u54_local_IRQHandler_47
610 };
611
612 local_int_p_t *local_int_mux[5] =
613 {
614 local_irq_handler_e51_table,
615 local_irq_handler_u54_1_table,
616 local_irq_handler_u54_2_table,
617 local_irq_handler_u54_3_table,
618 local_irq_handler_u54_4_table
619 };
620
621 #else
622 uint8_t (*ext_irq_handler_table[PLIC_NUM_SOURCES])(void) =
623 {
624 Invalid_IRQHandler,
625 External_1_IRQHandler,
626 External_2_IRQHandler,
627 External_3_IRQHandler,
628 USART0_plic_4_IRQHandler,
629 External_5_IRQHandler,
630 External_6_IRQHandler,
631 External_7_IRQHandler,
632 External_8_IRQHandler,
633 External_9_IRQHandler,
634 External_10_IRQHandler,
635 External_11_IRQHandler,
636 External_12_IRQHandler,
637 External_13_IRQHandler,
638 External_14_IRQHandler,
639 External_15_IRQHandler,
640 External_16_IRQHandler,
641 External_17_IRQHandler,
642 External_18_IRQHandler,
643 External_19_IRQHandler,
644 External_20_IRQHandler,
645 External_21_IRQHandler,
646 External_22_IRQHandler,
647 dma_ch0_DONE_IRQHandler,
648 dma_ch0_ERR_IRQHandler,
649 dma_ch1_DONE_IRQHandler,
650 dma_ch1_ERR_IRQHandler,
651 dma_ch2_DONE_IRQHandler,
652 dma_ch2_ERR_IRQHandler,
653 dma_ch3_DONE_IRQHandler,
654 dma_ch3_ERR_IRQHandler,
655 External_31_IRQHandler,
656 External_32_IRQHandler,
657 External_33_IRQHandler,
658 External_34_IRQHandler,
659 External_35_IRQHandler,
660 External_36_IRQHandler,
661 External_37_IRQHandler,
662 External_38_IRQHandler,
663 External_39_IRQHandler,
664 External_40_IRQHandler,
665 External_41_IRQHandler,
666 External_42_IRQHandler,
667 External_43_IRQHandler,
668 External_44_IRQHandler,
669 External_45_IRQHandler,
670 External_46_IRQHandler,
671 External_47_IRQHandler,
672 External_48_IRQHandler,
673 External_49_IRQHandler,
674 External_50_IRQHandler,
675 External_51_IRQHandler,
676 External_52_IRQHandler,
677 MAC0_plic_53_IRQHandler
678
679 };
680 #endif
681 /*------------------------------------------------------------------------------
682 *
683 */
handle_m_ext_interrupt(void)684 void handle_m_ext_interrupt(void)
685 {
686
687 volatile uint32_t int_num = PLIC_ClaimIRQ();
688
689 if (INVALID_IRQn == int_num)
690 {
691 return;
692 }
693
694 uint8_t disable = EXT_IRQ_KEEP_ENABLED;
695 #ifndef SIFIVE_HIFIVE_UNLEASHED
696 disable = ext_irq_handler_table[int_num /* + OFFSET_TO_MSS_GLOBAL_INTS Think this was required in early bitfile */]();
697 #else
698 disable = ext_irq_handler_table[int_num]();
699 #endif
700
701 PLIC_CompleteIRQ(int_num);
702
703 if(EXT_IRQ_DISABLE == disable)
704 {
705 PLIC_DisableIRQ((PLIC_IRQn_Type)int_num);
706 }
707
708 }
709
710
711 /*------------------------------------------------------------------------------
712 *
713 */
handle_local_interrupt(uint8_t interrupt_no)714 void handle_local_interrupt(uint8_t interrupt_no)
715 {
716 #ifndef SIFIVE_HIFIVE_UNLEASHED /* no local interrupts on unleashed */
717 uint64_t mhart_id = read_csr(mhartid);
718 uint8_t local_interrupt_no = (uint8_t)(interrupt_no - 16U);
719 local_int_p_t *local_int_table = local_int_mux[mhart_id];
720
721 (*local_int_table[local_interrupt_no])();
722
723 #endif
724 }
725
726 /*------------------------------------------------------------------------------
727 *
728 */
trap_from_machine_mode(uintptr_t * regs,uintptr_t dummy,uintptr_t mepc)729 void trap_from_machine_mode(uintptr_t * regs, uintptr_t dummy, uintptr_t mepc)
730 {
731 volatile uintptr_t mcause = read_csr(mcause);
732
733 if (((mcause & MCAUSE_INT) == MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) > 15U)&& ((mcause & MCAUSE_CAUSE) < 64U))
734 {
735 handle_local_interrupt((uint8_t)(mcause & MCAUSE_CAUSE));
736 }
737 else if (((mcause & MCAUSE_INT) == MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_EXT))
738 {
739 handle_m_ext_interrupt();
740 }
741 else if (((mcause & MCAUSE_INT) == MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_SOFT))
742 {
743 handle_m_soft_interrupt();
744 }
745 else if (((mcause & MCAUSE_INT) == MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_TIMER))
746 {
747 handle_m_timer_interrupt();
748 }
749 else
750 {
751 uint32_t i = 0U;
752 while(1)
753 {
754 /* wait for watchdog */
755 i++; /* added some code as SC debugger hangs if in loop doing nothing */
756 if(i == 0x1000U)
757 {
758 i = mcause; /* so mcause is not optimised out */
759 }
760 }
761 switch(mcause)
762 {
763
764 case CAUSE_LOAD_PAGE_FAULT:
765 break;
766 case CAUSE_STORE_PAGE_FAULT:
767 break;
768 case CAUSE_FETCH_ACCESS:
769 break;
770 case CAUSE_LOAD_ACCESS:
771 break;
772 case CAUSE_STORE_ACCESS:
773 break;
774 default:
775 bad_trap(regs, dummy, mepc);
776 break;
777 }
778 }
779 }
780
781 #ifdef __cplusplus
782 }
783 #endif
784