HPM SDK
HPMicro Software Development Kit
hpm_interrupt.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2025 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_INTERRUPT_H
9 #define HPM_INTERRUPT_H
10 #include "hpm_common.h"
11 #include "hpm_csr_drv.h"
12 #include "hpm_plic_drv.h"
13 
20 #define M_MODE 0
21 #define S_MODE 1
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Machine mode API: these APIs are supposed to be called at machine mode */
28 
34 ATTR_ALWAYS_INLINE static inline void enable_global_irq(uint32_t mask)
35 {
36  set_csr(CSR_MSTATUS, mask);
37 }
38 
45 ATTR_ALWAYS_INLINE static inline uint32_t disable_global_irq(uint32_t mask)
46 {
47  return read_clear_csr(CSR_MSTATUS, mask);
48 }
49 
55 ATTR_ALWAYS_INLINE static inline void restore_global_irq(uint32_t mask)
56 {
57  set_csr(CSR_MSTATUS, mask);
58 }
59 
64 ATTR_ALWAYS_INLINE static inline void enable_irq_from_intc(void)
65 {
67 }
68 
73 ATTR_ALWAYS_INLINE static inline void disable_irq_from_intc(void)
74 {
76 }
77 
81 ATTR_ALWAYS_INLINE static inline void enable_mchtmr_irq(void)
82 {
84 }
85 
90 ATTR_ALWAYS_INLINE static inline void disable_mchtmr_irq(void)
91 {
93 }
94 
100 ATTR_ALWAYS_INLINE static inline void delegate_irq(uint32_t mask)
101 {
102  set_csr(CSR_MIDELEG, mask);
103 }
104 
110 ATTR_ALWAYS_INLINE static inline void undelegate_irq(uint32_t mask)
111 {
112  clear_csr(CSR_MIDELEG, mask);
113 }
114 
115 
116 /* Supervisor mode API: these APIs are supposed to be called at supervisor mode */
117 
123 ATTR_ALWAYS_INLINE static inline void enable_s_global_irq(uint32_t mask)
124 {
125  set_csr(CSR_SSTATUS, mask);
126 }
127 
134 ATTR_ALWAYS_INLINE static inline uint32_t disable_s_global_irq(uint32_t mask)
135 {
136  return read_clear_csr(CSR_SSTATUS, mask);
137 }
138 
144 ATTR_ALWAYS_INLINE static inline void restore_s_global_irq(uint32_t mask)
145 {
146  set_csr(CSR_SSTATUS, mask);
147 }
148 
153 ATTR_ALWAYS_INLINE static inline void disable_s_irq_from_intc(void)
154 {
156 }
157 
162 ATTR_ALWAYS_INLINE static inline void enable_s_irq_from_intc(void)
163 {
165 }
166 
170 ATTR_ALWAYS_INLINE static inline void enable_s_mchtmr_irq(void)
171 {
173 }
174 
179 ATTR_ALWAYS_INLINE static inline void disable_s_mchtmr_irq(void)
180 {
182 }
183 
184 
185 /*
186  * CPU Machine SWI control
187  *
188  * Machine SWI (MSIP) is connected to PLICSW irq 1.
189  */
190 #define PLICSWI 1
191 
196 ATTR_ALWAYS_INLINE static inline void intc_m_init_swi(void)
197 {
198  __plic_enable_irq(HPM_PLICSW_BASE, HPM_PLIC_TARGET_M_MODE, PLICSWI);
199 }
200 
201 
206 ATTR_ALWAYS_INLINE static inline void intc_m_enable_swi(void)
207 {
209 }
210 
211 
216 ATTR_ALWAYS_INLINE static inline void intc_m_disable_swi(void)
217 {
219 }
220 
221 
226 ATTR_ALWAYS_INLINE static inline void intc_m_trigger_swi(void)
227 {
228  __plic_set_irq_pending(HPM_PLICSW_BASE, PLICSWI);
229 }
230 
235 ATTR_ALWAYS_INLINE static inline void intc_m_claim_swi(void)
236 {
237  __plic_claim_irq(HPM_PLICSW_BASE, 0);
238 }
239 
244 ATTR_ALWAYS_INLINE static inline void intc_m_complete_swi(void)
245 {
246  __plic_complete_irq(HPM_PLICSW_BASE, HPM_PLIC_TARGET_M_MODE, PLICSWI);
247 }
248 
249 /*
250  * @brief Enable IRQ for machine mode
251  *
252  * @param[in] irq Interrupt number
253  */
254 #define intc_m_enable_irq(irq) \
255  intc_enable_irq(HPM_PLIC_TARGET_M_MODE, irq)
256 
257 /*
258  * @brief Disable IRQ for machine mode
259  *
260  * @param[in] irq Interrupt number
261  */
262 #define intc_m_disable_irq(irq) \
263  intc_disable_irq(HPM_PLIC_TARGET_M_MODE, irq)
264 
265 #define intc_m_set_threshold(threshold) \
266  intc_set_threshold(HPM_PLIC_TARGET_M_MODE, threshold)
267 
268 #define intc_m_get_threshold() \
269  intc_get_threshold(HPM_PLIC_TARGET_M_MODE)
270 
271 /*
272  * @brief Complete IRQ for machine mode
273  *
274  * @param[in] irq Interrupt number
275  */
276 #define intc_m_complete_irq(irq) \
277  intc_complete_irq(HPM_PLIC_TARGET_M_MODE, irq)
278 
279 /*
280  * @brief Claim IRQ for machine mode
281  *
282  */
283 #define intc_m_claim_irq() intc_claim_irq(HPM_PLIC_TARGET_M_MODE)
284 
285 /*
286  * @brief Enable IRQ for machine mode with priority
287  *
288  * @param[in] irq Interrupt number
289  * @param[in] priority Priority of interrupt
290  */
291 #define intc_m_enable_irq_with_priority(irq, priority) \
292  do { \
293  intc_set_irq_priority(irq, priority); \
294  intc_m_enable_irq(irq); \
295  } while (0)
296 
297 
298 
299 /* Supervisor mode */
300 
305 ATTR_ALWAYS_INLINE static inline void intc_s_enable_swi(void)
306 {
308 }
309 
310 
315 ATTR_ALWAYS_INLINE static inline void intc_s_disable_swi(void)
316 {
318 }
319 
320 
325 ATTR_ALWAYS_INLINE static inline void intc_s_trigger_swi(void)
326 {
328 }
329 
330 
335 ATTR_ALWAYS_INLINE static inline void intc_s_complete_swi(void)
336 {
338 }
339 
340 /*
341  * @brief Enable IRQ for supervisor mode
342  *
343  * @param[in] irq Interrupt number
344  */
345 #define intc_s_enable_irq(irq) \
346  intc_enable_irq(HPM_PLIC_TARGET_S_MODE, irq)
347 
348 /*
349  * @brief Disable IRQ for supervisor mode
350  *
351  * @param[in] irq Interrupt number
352  */
353 #define intc_s_disable_irq(irq) \
354  intc_disable_irq(HPM_PLIC_TARGET_S_MODE, irq)
355 
356 #define intc_set_s_threshold(threshold) \
357  intc_set_threshold(HPM_PLIC_TARGET_S_MODE, threshold)
358 
359 /*
360  * @brief Complete IRQ for supervisor mode
361  *
362  * @param[in] irq Interrupt number
363  */
364 #define intc_s_complete_irq(irq) \
365  intc_complete_irq(HPM_PLIC_TARGET_S_MODE, irq)
366 
367 /*
368  * @brief Claim IRQ for supervisor mode
369  *
370  */
371 #define intc_s_claim_irq() intc_claim_irq(HPM_PLIC_TARGET_S_MODE)
372 
373 /*
374  * @brief Enable IRQ for supervisor mode with priority
375  *
376  * @param[in] irq Interrupt number
377  * @param[in] priority Priority of interrupt
378  */
379 #define intc_s_enable_irq_with_priority(irq, priority) \
380  do { \
381  intc_set_irq_priority(irq, priority); \
382  intc_s_enable_irq(irq); \
383  } while (0)
384 
385 
386 /*
387  * @brief Enable specific interrupt
388  *
389  * @param[in] target Target to handle specific interrupt
390  * @param[in] irq Interrupt number
391  */
392 ATTR_ALWAYS_INLINE static inline void intc_enable_irq(uint32_t target, uint32_t irq)
393 {
394  __plic_enable_irq(HPM_PLIC_BASE, target, irq);
395 }
396 
403 ATTR_ALWAYS_INLINE static inline void intc_set_irq_priority(uint32_t irq, uint32_t priority)
404 {
405  __plic_set_irq_priority(HPM_PLIC_BASE, irq, priority);
406 }
407 
414 ATTR_ALWAYS_INLINE static inline void intc_disable_irq(uint32_t target, uint32_t irq)
415 {
416  __plic_disable_irq(HPM_PLIC_BASE, target, irq);
417 }
418 
425 ATTR_ALWAYS_INLINE static inline void intc_set_threshold(uint32_t target, uint32_t threshold)
426 {
427  __plic_set_threshold(HPM_PLIC_BASE, target, threshold);
428 }
429 
435 ATTR_ALWAYS_INLINE static inline uint32_t intc_get_threshold(uint32_t target)
436 {
437  return __plic_get_threshold(HPM_PLIC_BASE, target);
438 }
439 
446 ATTR_ALWAYS_INLINE static inline uint32_t intc_claim_irq(uint32_t target)
447 {
448  return __plic_claim_irq(HPM_PLIC_BASE, target);
449 }
450 
458 ATTR_ALWAYS_INLINE static inline void intc_complete_irq(uint32_t target, uint32_t irq)
459 {
460  __plic_complete_irq(HPM_PLIC_BASE, target, irq);
461 }
462 
463 /*
464  * Vectored based irq install and uninstall
465  */
466 /* Machine mode */
467 extern int __vector_table[];
468 extern void default_irq_entry(void);
469 
477 ATTR_ALWAYS_INLINE static inline void install_isr(uint32_t irq, uint32_t isr)
478 {
479  __vector_table[irq] = isr;
480 }
481 
488 ATTR_ALWAYS_INLINE static inline void uninstall_isr(uint32_t irq)
489 {
490  __vector_table[irq] = (int) default_irq_entry;
491 }
492 
493 /* Supervisor mode */
494 extern int __vector_s_table[];
495 extern void default_s_irq_entry(void);
503 ATTR_ALWAYS_INLINE static inline void install_s_isr(uint32_t irq, uint32_t isr)
504 {
505  __vector_s_table[irq] = isr;
506 }
507 
514 ATTR_ALWAYS_INLINE static inline void uninstall_s_isr(uint32_t irq)
515 {
516  __vector_s_table[irq] = (int) default_s_irq_entry;
517 }
518 
519 
520 /*
521  * Inline nested irq entry/exit macros
522  */
523 /*
524  * @brief Save CSR
525  * @param[in] r Target CSR to be saved
526  */
527 #define SAVE_CSR(r) register long __##r = read_csr(r);
528 
529 /*
530  * @brief Restore macro
531  *
532  * @param[in] r Target CSR to be restored
533  */
534 #define RESTORE_CSR(r) write_csr(r, __##r);
535 
536 #if defined(SUPPORT_PFT_ARCH) && SUPPORT_PFT_ARCH
537 #define SAVE_MXSTATUS() SAVE_CSR(CSR_MXSTATUS)
538 #define RESTORE_MXSTATUS() RESTORE_CSR(CSR_MXSTATUS)
539 #else
540 #define SAVE_MXSTATUS()
541 #define RESTORE_MXSTATUS()
542 #endif
543 
544 #ifdef __riscv_flen
545 #define SAVE_FCSR() register int __fcsr = read_fcsr();
546 #define RESTORE_FCSR() write_fcsr(__fcsr);
547 #else
548 #define SAVE_FCSR()
549 #define RESTORE_FCSR()
550 #endif
551 
552 #ifdef __riscv_dsp
553 #define SAVE_UCODE() SAVE_CSR(CSR_UCODE)
554 #define RESTORE_UCODE() RESTORE_CSR(CSR_UCODE)
555 #else
556 #define SAVE_UCODE()
557 #define RESTORE_UCODE()
558 #endif
559 
560 #ifdef __riscv_flen
561 #if __riscv_flen == 32
562 /* RV32I caller registers + MCAUSE + MEPC + MSTATUS + FCSR + UCODE (DSP) + MCCTL + 20 FPU caller registers */
563 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * (22 + 20)), 16)
564 #else /* __riscv_flen = 64 */
565 /* RV32I caller registers + MCAUSE + MEPC + MSTATUS + FCSR + UCODE (DSP) + MCCTL + 20 DFPU caller */
566 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * (22 + 20 * 2)), 16)
567 #endif
568 
569 #else
570 /* RV32I caller registers + MCAUSE + MEPC + MSTATUS + FCSR + UCODE (DSP) + MCCTL */
571 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * 22), 16)
572 #endif
573 
574 #ifdef __riscv_flen
575 /*
576  * Save FPU caller registers:
577  * NOTE: To simplify the logic, the FPU caller registers are always stored at word offset 22 in the stack
578  */
579 #if __riscv_flen == 32
580 #ifdef __ICCRISCV__
581 #define SAVE_FPU_CONTEXT() { \
582  __asm volatile("\n\
583  c.fswsp ft0, 22*4\n\
584  c.fswsp ft1, 23*4 \n\
585  c.fswsp ft2, 24*4 \n\
586  c.fswsp ft3, 25*4 \n\
587  c.fswsp ft4, 26*4 \n\
588  c.fswsp ft5, 27*4 \n\
589  c.fswsp ft6, 28*4 \n\
590  c.fswsp ft7, 29*4 \n\
591  c.fswsp fa0, 30*4 \n\
592  c.fswsp fa1, 31*4 \n\
593  c.fswsp fa2, 32*4 \n\
594  c.fswsp fa3, 33*4 \n\
595  c.fswsp fa4, 34*4 \n\
596  c.fswsp fa5, 35*4 \n\
597  c.fswsp fa6, 36*4 \n\
598  c.fswsp fa7, 37*4 \n\
599  c.fswsp ft8, 38*4 \n\
600  c.fswsp ft9, 39*4 \n\
601  c.fswsp ft10, 40*4 \n\
602  c.fswsp ft11, 41*4 \n");\
603 }
604 
605 /*
606  * Restore FPU caller registers:
607  * NOTE: To simplify the logic, the FPU caller registers are always stored at word offset 22 in the stack
608  */
609 #define RESTORE_FPU_CONTEXT() { \
610  __asm volatile("\n\
611  c.flwsp ft0, 22*4\n\
612  c.flwsp ft1, 23*4 \n\
613  c.flwsp ft2, 24*4 \n\
614  c.flwsp ft3, 25*4 \n\
615  c.flwsp ft4, 26*4 \n\
616  c.flwsp ft5, 27*4 \n\
617  c.flwsp ft6, 28*4 \n\
618  c.flwsp ft7, 29*4 \n\
619  c.flwsp fa0, 30*4 \n\
620  c.flwsp fa1, 31*4 \n\
621  c.flwsp fa2, 32*4 \n\
622  c.flwsp fa3, 33*4 \n\
623  c.flwsp fa4, 34*4 \n\
624  c.flwsp fa5, 35*4 \n\
625  c.flwsp fa6, 36*4 \n\
626  c.flwsp fa7, 37*4 \n\
627  c.flwsp ft8, 38*4 \n\
628  c.flwsp ft9, 39*4 \n\
629  c.flwsp ft10, 40*4 \n\
630  c.flwsp ft11, 41*4 \n");\
631 }
632 #else /* __ICCRISCV__ not defined */
633 #define SAVE_FPU_CONTEXT() { \
634  __asm volatile("\n\
635  c.fswsp ft0, 22*4(sp)\n\
636  c.fswsp ft1, 23*4(sp) \n\
637  c.fswsp ft2, 24*4(sp) \n\
638  c.fswsp ft3, 25*4(sp) \n\
639  c.fswsp ft4, 26*4(sp) \n\
640  c.fswsp ft5, 27*4(sp) \n\
641  c.fswsp ft6, 28*4(sp) \n\
642  c.fswsp ft7, 29*4(sp) \n\
643  c.fswsp fa0, 30*4(sp) \n\
644  c.fswsp fa1, 31*4(sp) \n\
645  c.fswsp fa2, 32*4(sp) \n\
646  c.fswsp fa3, 33*4(sp) \n\
647  c.fswsp fa4, 34*4(sp) \n\
648  c.fswsp fa5, 35*4(sp) \n\
649  c.fswsp fa6, 36*4(sp) \n\
650  c.fswsp fa7, 37*4(sp) \n\
651  c.fswsp ft8, 38*4(sp) \n\
652  c.fswsp ft9, 39*4(sp) \n\
653  c.fswsp ft10, 40*4(sp) \n\
654  c.fswsp ft11, 41*4(sp) \n");\
655 }
656 
657 /*
658  * Restore FPU caller registers:
659  * NOTE: To simplify the logic, the FPU caller registers are always stored at word offset 22 in the stack
660  */
661 #define RESTORE_FPU_CONTEXT() { \
662  __asm volatile("\n\
663  c.flwsp ft0, 22*4(sp)\n\
664  c.flwsp ft1, 23*4(sp) \n\
665  c.flwsp ft2, 24*4(sp) \n\
666  c.flwsp ft3, 25*4(sp) \n\
667  c.flwsp ft4, 26*4(sp) \n\
668  c.flwsp ft5, 27*4(sp) \n\
669  c.flwsp ft6, 28*4(sp) \n\
670  c.flwsp ft7, 29*4(sp) \n\
671  c.flwsp fa0, 30*4(sp) \n\
672  c.flwsp fa1, 31*4(sp) \n\
673  c.flwsp fa2, 32*4(sp) \n\
674  c.flwsp fa3, 33*4(sp) \n\
675  c.flwsp fa4, 34*4(sp) \n\
676  c.flwsp fa5, 35*4(sp) \n\
677  c.flwsp fa6, 36*4(sp) \n\
678  c.flwsp fa7, 37*4(sp) \n\
679  c.flwsp ft8, 38*4(sp) \n\
680  c.flwsp ft9, 39*4(sp) \n\
681  c.flwsp ft10, 40*4(sp) \n\
682  c.flwsp ft11, 41*4(sp) \n");\
683 }
684 #endif
685 #else /*__riscv_flen == 64*/
686 #ifdef __ICCRISCV__
687 #define SAVE_FPU_CONTEXT() { \
688  __asm volatile("\n\
689  c.fsdsp ft0, 22*4\n\
690  c.fsdsp ft1, 24*4 \n\
691  c.fsdsp ft2, 26*4 \n\
692  c.fsdsp ft3, 28*4 \n\
693  c.fsdsp ft4, 30*4 \n\
694  c.fsdsp ft5, 32*4 \n\
695  c.fsdsp ft6, 34*4 \n\
696  c.fsdsp ft7, 36*4 \n\
697  c.fsdsp fa0, 38*4 \n\
698  c.fsdsp fa1, 40*4 \n\
699  c.fsdsp fa2, 42*4 \n\
700  c.fsdsp fa3, 44*4 \n\
701  c.fsdsp fa4, 46*4 \n\
702  c.fsdsp fa5, 48*4 \n\
703  c.fsdsp fa6, 50*4 \n\
704  c.fsdsp fa7, 52*4 \n\
705  c.fsdsp ft8, 54*4 \n\
706  c.fsdsp ft9, 56*4 \n\
707  c.fsdsp ft10, 58*4 \n\
708  c.fsdsp ft11, 60*4 \n");\
709 }
710 
711 /*
712  * Restore FPU caller registers:
713  * NOTE: To simplify the logic, the FPU caller registers are always stored at word offset 22 in the stack
714  */
715 #define RESTORE_FPU_CONTEXT() { \
716  __asm volatile("\n\
717  c.fldsp ft0, 22*4\n\
718  c.fldsp ft1, 24*4 \n\
719  c.fldsp ft2, 26*4 \n\
720  c.fldsp ft3, 28*4 \n\
721  c.fldsp ft4, 30*4 \n\
722  c.fldsp ft5, 32*4 \n\
723  c.fldsp ft6, 34*4 \n\
724  c.fldsp ft7, 36*4 \n\
725  c.fldsp fa0, 38*4 \n\
726  c.fldsp fa1, 40*4 \n\
727  c.fldsp fa2, 42*4 \n\
728  c.fldsp fa3, 44*4 \n\
729  c.fldsp fa4, 46*4 \n\
730  c.fldsp fa5, 48*4 \n\
731  c.fldsp fa6, 50*4 \n\
732  c.fldsp fa7, 52*4 \n\
733  c.fldsp ft8, 54*4 \n\
734  c.fldsp ft9, 56*4 \n\
735  c.fldsp ft10, 58*4 \n\
736  c.fldsp ft11, 60*4 \n");\
737 }
738 #else /*__riscv_flen == 64*/
739 #define SAVE_FPU_CONTEXT() { \
740  __asm volatile("\n\
741  c.fsdsp ft0, 22*4(sp)\n\
742  c.fsdsp ft1, 24*4(sp) \n\
743  c.fsdsp ft2, 26*4(sp) \n\
744  c.fsdsp ft3, 28*4(sp) \n\
745  c.fsdsp ft4, 30*4(sp) \n\
746  c.fsdsp ft5, 32*4(sp) \n\
747  c.fsdsp ft6, 34*4(sp) \n\
748  c.fsdsp ft7, 36*4(sp) \n\
749  c.fsdsp fa0, 38*4(sp) \n\
750  c.fsdsp fa1, 40*4(sp) \n\
751  c.fsdsp fa2, 42*4(sp) \n\
752  c.fsdsp fa3, 44*4(sp) \n\
753  c.fsdsp fa4, 46*4(sp) \n\
754  c.fsdsp fa5, 48*4(sp) \n\
755  c.fsdsp fa6, 50*4(sp) \n\
756  c.fsdsp fa7, 52*4(sp) \n\
757  c.fsdsp ft8, 54*4(sp) \n\
758  c.fsdsp ft9, 56*4(sp) \n\
759  c.fsdsp ft10, 58*4(sp) \n\
760  c.fsdsp ft11, 60*4(sp) \n");\
761 }
762 
763 /*
764  * Restore FPU caller registers:
765  * NOTE: To simplify the logic, the FPU caller registers are always stored at word offset 22 in the stack
766  */
767 #define RESTORE_FPU_CONTEXT() { \
768  __asm volatile("\n\
769  c.fldsp ft0, 22*4(sp)\n\
770  c.fldsp ft1, 24*4(sp) \n\
771  c.fldsp ft2, 26*4(sp) \n\
772  c.fldsp ft3, 28*4(sp) \n\
773  c.fldsp ft4, 30*4(sp) \n\
774  c.fldsp ft5, 32*4(sp) \n\
775  c.fldsp ft6, 34*4(sp) \n\
776  c.fldsp ft7, 36*4(sp) \n\
777  c.fldsp fa0, 38*4(sp) \n\
778  c.fldsp fa1, 40*4(sp) \n\
779  c.fldsp fa2, 42*4(sp) \n\
780  c.fldsp fa3, 44*4(sp) \n\
781  c.fldsp fa4, 46*4(sp) \n\
782  c.fldsp fa5, 48*4(sp) \n\
783  c.fldsp fa6, 50*4(sp) \n\
784  c.fldsp fa7, 52*4(sp) \n\
785  c.fldsp ft8, 54*4(sp) \n\
786  c.fldsp ft9, 56*4(sp) \n\
787  c.fldsp ft10, 58*4(sp) \n\
788  c.fldsp ft11, 60*4(sp) \n");\
789 }
790 #endif
791 #endif
792 #else
793 #define SAVE_FPU_CONTEXT()
794 #define RESTORE_FPU_CONTEXT()
795 #endif
796 
797 #ifdef __ICCRISCV__
801 #define SAVE_CALLER_CONTEXT() { \
802  __asm volatile("addi sp, sp, %0" : : "i"(-CONTEXT_REG_NUM) :);\
803  __asm volatile("\n\
804  c.swsp ra, 0*4 \n\
805  c.swsp t0, 1*4 \n\
806  c.swsp t1, 2*4 \n\
807  c.swsp t2, 3*4 \n\
808  c.swsp s1, 4*4 \n\
809  c.swsp a0, 5*4 \n\
810  c.swsp a1, 6*4 \n\
811  c.swsp a2, 7*4 \n\
812  c.swsp a3, 8*4 \n\
813  c.swsp a4, 9*4 \n\
814  c.swsp a5, 10*4 \n\
815  c.swsp a6, 11*4 \n\
816  c.swsp a7, 12*4 \n\
817  c.swsp s2, 13*4 \n\
818  c.swsp s3, 14*4 \n\
819  c.swsp s4, 15*4 \n\
820  c.swsp s5, 16*4 \n\
821  c.swsp s6, 17*4 \n\
822  c.swsp t3, 18*4 \n\
823  c.swsp t4, 19*4 \n\
824  c.swsp t5, 20*4 \n\
825  c.swsp t6, 21*4"); \
826  SAVE_FPU_CONTEXT(); \
827 }
828 
832 #define RESTORE_CALLER_CONTEXT() { \
833  __asm volatile("\n\
834  c.lwsp ra, 0*4 \n\
835  c.lwsp t0, 1*4 \n\
836  c.lwsp t1, 2*4 \n\
837  c.lwsp t2, 3*4 \n\
838  c.lwsp s1, 4*4 \n\
839  c.lwsp a0, 5*4 \n\
840  c.lwsp a1, 6*4 \n\
841  c.lwsp a2, 7*4 \n\
842  c.lwsp a3, 8*4 \n\
843  c.lwsp a4, 9*4 \n\
844  c.lwsp a5, 10*4 \n\
845  c.lwsp a6, 11*4 \n\
846  c.lwsp a7, 12*4 \n\
847  c.lwsp s2, 13*4 \n\
848  c.lwsp s3, 14*4 \n\
849  c.lwsp s4, 15*4 \n\
850  c.lwsp s5, 16*4 \n\
851  c.lwsp s6, 17*4 \n\
852  c.lwsp t3, 18*4 \n\
853  c.lwsp t4, 19*4 \n\
854  c.lwsp t5, 20*4 \n\
855  c.lwsp t6, 21*4 \n");\
856  RESTORE_FPU_CONTEXT(); \
857  __asm volatile("addi sp, sp, %0" : : "i"(CONTEXT_REG_NUM) :);\
858 }
859 #else
863 #define SAVE_CALLER_CONTEXT() { \
864  __asm volatile("addi sp, sp, %0" : : "i"(-CONTEXT_REG_NUM) :);\
865  __asm volatile("\n\
866  c.swsp ra, 0*4(sp) \n\
867  c.swsp t0, 1*4(sp) \n\
868  c.swsp t1, 2*4(sp) \n\
869  c.swsp t2, 3*4(sp) \n\
870  c.swsp s1, 4*4(sp) \n\
871  c.swsp a0, 5*4(sp) \n\
872  c.swsp a1, 6*4(sp) \n\
873  c.swsp a2, 7*4(sp) \n\
874  c.swsp a3, 8*4(sp) \n\
875  c.swsp a4, 9*4(sp) \n\
876  c.swsp a5, 10*4(sp) \n\
877  c.swsp a6, 11*4(sp) \n\
878  c.swsp a7, 12*4(sp) \n\
879  c.swsp s2, 13*4(sp) \n\
880  c.swsp s3, 14*4(sp) \n\
881  c.swsp s4, 15*4(sp) \n\
882  c.swsp s5, 16*4(sp) \n\
883  c.swsp s6, 17*4(sp) \n\
884  c.swsp t3, 18*4(sp) \n\
885  c.swsp t4, 19*4(sp) \n\
886  c.swsp t5, 20*4(sp) \n\
887  c.swsp t6, 21*4(sp)"); \
888  SAVE_FPU_CONTEXT(); \
889 }
890 
894 #define RESTORE_CALLER_CONTEXT() { \
895  __asm volatile("\n\
896  c.lwsp ra, 0*4(sp) \n\
897  c.lwsp t0, 1*4(sp) \n\
898  c.lwsp t1, 2*4(sp) \n\
899  c.lwsp t2, 3*4(sp) \n\
900  c.lwsp s1, 4*4(sp) \n\
901  c.lwsp a0, 5*4(sp) \n\
902  c.lwsp a1, 6*4(sp) \n\
903  c.lwsp a2, 7*4(sp) \n\
904  c.lwsp a3, 8*4(sp) \n\
905  c.lwsp a4, 9*4(sp) \n\
906  c.lwsp a5, 10*4(sp) \n\
907  c.lwsp a6, 11*4(sp) \n\
908  c.lwsp a7, 12*4(sp) \n\
909  c.lwsp s2, 13*4(sp) \n\
910  c.lwsp s3, 14*4(sp) \n\
911  c.lwsp s4, 15*4(sp) \n\
912  c.lwsp s5, 16*4(sp) \n\
913  c.lwsp s6, 17*4(sp) \n\
914  c.lwsp t3, 18*4(sp) \n\
915  c.lwsp t4, 19*4(sp) \n\
916  c.lwsp t5, 20*4(sp) \n\
917  c.lwsp t6, 21*4(sp) \n");\
918  RESTORE_FPU_CONTEXT(); \
919  __asm volatile("addi sp, sp, %0" : : "i"(CONTEXT_REG_NUM) :);\
920 }
921 #endif
922 
923 #ifdef __riscv_flen
924 #define SAVE_FPU_STATE() { \
925  __asm volatile("frcsr s1\n"); \
926 }
927 
928 #define RESTORE_FPU_STATE() { \
929  __asm volatile("fscsr s1\n"); \
930 }
931 #else
932 #define SAVE_FPU_STATE()
933 #define RESTORE_FPU_STATE()
934 #endif
935 
936 #ifdef __riscv_dsp
937 /*
938  * @brief Save DSP context
939  */
940 #define SAVE_DSP_CONTEXT() { \
941  __asm volatile("csrrs s4, %0, x0\n" ::"i"(CSR_UCODE):); \
942 }
943 /*
944  * @brief Restore DSP context
945  */
946 #define RESTORE_DSP_CONTEXT() {\
947  __asm volatile("csrw %0, s4\n" ::"i"(CSR_UCODE):); \
948 }
949 
950 #else
951 #define SAVE_DSP_CONTEXT()
952 #define RESTORE_DSP_CONTEXT()
953 #endif
954 
955 /*
956  * @brief Save MCCTL context
957  */
958 #define SAVE_MCCTL_CONTEXT() { \
959  __asm volatile("csrrs s5, %0, x0\n" ::"i"(CSR_MCCTLBEGINADDR):); \
960  __asm volatile("csrrs s6, %0, x0\n" ::"i"(CSR_MCCTLDATA):); \
961 }
962 /*
963  * @brief Restore MCCTL context
964  */
965 #define RESTORE_MCCTL_CONTEXT() {\
966  __asm volatile("csrw %0, s6\n" ::"i"(CSR_MCCTLDATA):); \
967  __asm volatile("csrw %0, s5\n" ::"i"(CSR_MCCTLBEGINADDR):); \
968 }
969 
970 /*
971  * @brief Enter Nested IRQ Handling
972  * @note To simplify the logic, Nested IRQ related registers are stored in the stack as below:
973  * MCAUSE - word offset 16 (not used in the vectored mode)
974  * EPC - word offset 17
975  * MSTATUS = word offset 18
976  * MXSTATUS = word offset 19
977  */
978 #define ENTER_NESTED_IRQ_HANDLING_M() { \
979  __asm volatile("\n\
980  csrr s2, mepc \n\
981  csrr s3, mstatus \n");\
982  SAVE_FPU_STATE(); \
983  SAVE_DSP_CONTEXT(); \
984  SAVE_MCCTL_CONTEXT(); \
985  __asm volatile("csrsi mstatus, 8"); \
986 }
987 
988 /*
989  * @brief Complete IRQ Handling
990  */
991 #define COMPLETE_IRQ_HANDLING_M(irq_num) { \
992  __asm volatile("csrci mstatus, 8"); \
993  __asm volatile("lui a4, 0xe4200"); \
994  __asm volatile("li a3, %0" : : "i" (irq_num) :); \
995  __asm volatile("sw a3, 4(a4)"); \
996 }
997 
998 /*
999  * @brief Exit Nested IRQ Handling
1000  * @note To simplify the logic, Nested IRQ related registers are stored in the stack as below:
1001  * MCAUSE - word offset 16 (not used in the vectored mode)
1002  * EPC - word offset 17
1003  * MSTATUS = word offset 18
1004  * MXSTATUS = word offset 19
1005  */
1006 #define EXIT_NESTED_IRQ_HANDLING_M() { \
1007  __asm volatile("\n\
1008  csrw mstatus, s3 \n\
1009  csrw mepc, s2 \n");\
1010  RESTORE_FPU_STATE(); \
1011  RESTORE_DSP_CONTEXT(); \
1012  RESTORE_MCCTL_CONTEXT(); \
1013 }
1014 
1015 
1016 #define ENTER_NESTED_IRQ_HANDLING_S() {\
1017  __asm volatile("\n\
1018  csrr s2, sepc \n\
1019  csrr s3, sstatus \n");\
1020  SAVE_FPU_STATE(); \
1021  SAVE_DSP_CONTEXT(); \
1022  __asm volatile("csrsi sstatus, 2"); \
1023 }
1024 #define COMPLETE_IRQ_HANDLING_S(irq_num) {\
1025  __asm volatile("csrci sstatus, 2"); \
1026  __asm volatile("lui a4, 0xe4201"); \
1027  __asm volatile("li a3, %0" : : "i" (irq_num) :); \
1028  __asm volatile("sw a3, 4(a4)"); \
1029 }
1030 
1031 /*
1032  * @brief Exit Nested IRQ Handling at supervisor mode
1033  * @note To simplify the logic, Nested IRQ related registers are stored in the stack as below:
1034  * SCAUSE - word offset 16 (not used in the vectored mode)
1035  * EPC - word offset 17
1036  * SSTATUS = word offset 18
1037  */
1038 #define EXIT_NESTED_IRQ_HANDLING_S() { \
1039  __asm volatile("\n\
1040  csrw sstatus, s3 \n\
1041  csrw sepc, s2 \n");\
1042  RESTORE_FPU_STATE(); \
1043  RESTORE_DSP_CONTEXT(); \
1044 }
1045 
1046 /* @brief Nested IRQ entry macro : Save CSRs and enable global irq. */
1047 #define NESTED_IRQ_ENTER() \
1048  SAVE_CSR(CSR_MEPC) \
1049  SAVE_CSR(CSR_MSTATUS) \
1050  SAVE_MXSTATUS() \
1051  SAVE_FCSR() \
1052  SAVE_UCODE() \
1053  set_csr(CSR_MSTATUS, CSR_MSTATUS_MIE_MASK);
1054 
1055 /* @brief Nested IRQ exit macro : Restore CSRs */
1056 #define NESTED_IRQ_EXIT() \
1057  RESTORE_CSR(CSR_MSTATUS) \
1058  RESTORE_CSR(CSR_MEPC) \
1059  RESTORE_MXSTATUS() \
1060  RESTORE_FCSR() \
1061  RESTORE_UCODE()
1062 
1063 #ifdef __cplusplus
1064 #define HPM_EXTERN_C extern "C"
1065 #else
1066 #define HPM_EXTERN_C
1067 #endif
1068 
1069 #define ISR_NAME_M(irq_num) default_isr_##irq_num
1070 #define ISR_NAME_S(irq_num) default_isr_s_##irq_num
1077 #if !defined(USE_NONVECTOR_MODE) || (USE_NONVECTOR_MODE == 0)
1078 #if defined(CONFIG_FREERTOS) && CONFIG_FREERTOS
1079 #define FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num) irq_handler_wrapper_##irq_num
1080 #define SDK_DECLARE_EXT_ISR_M(irq_num, isr) \
1081 void isr(void) __attribute__((section(".isr_vector"))); \
1082 HPM_EXTERN_C void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) __attribute__((section(".isr_vector"))); \
1083 void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) \
1084 { \
1085  isr();\
1086 }
1087 
1094 #define SDK_DECLARE_EXT_ISR_S(irq_num, isr) \
1095 void isr(void) __attribute__((section(".isr_s_vector")));\
1096 HPM_EXTERN_C void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) __attribute__((section(".isr_s_vector")));\
1097 void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) \
1098 { \
1099  isr();\
1100 }
1101 #else
1102 #define SDK_DECLARE_EXT_ISR_M(irq_num, isr) \
1103 void isr(void) __attribute__((section(".isr_vector")));\
1104 HPM_EXTERN_C HPM_ATTR_MACHINE_INTERRUPT void ISR_NAME_M(irq_num)(void);\
1105 HPM_ATTR_MACHINE_INTERRUPT void ISR_NAME_M(irq_num)(void) \
1106 { \
1107  SAVE_CALLER_CONTEXT(); \
1108  ENTER_NESTED_IRQ_HANDLING_M();\
1109  __asm volatile("la t1, %0\n\t" : : "i" (isr) : );\
1110  __asm volatile("jalr t1\n");\
1111  COMPLETE_IRQ_HANDLING_M(irq_num);\
1112  EXIT_NESTED_IRQ_HANDLING_M();\
1113  RESTORE_CALLER_CONTEXT();\
1114  __asm volatile("fence io, io");\
1115 }
1116 
1123 #define SDK_DECLARE_EXT_ISR_S(irq_num, isr) \
1124 void isr(void) __attribute__((section(".isr_s_vector")));\
1125 HPM_EXTERN_C HPM_ATTR_SUPERVISOR_INTERRUPT void ISR_NAME_S(irq_num)(void);\
1126 HPM_ATTR_SUPERVISOR_INTERRUPT void ISR_NAME_S(irq_num)(void) {\
1127  SAVE_CALLER_CONTEXT(); \
1128  ENTER_NESTED_IRQ_HANDLING_S();\
1129  __asm volatile("la t1, %0\n\t" : : "i" (isr) : );\
1130  __asm volatile("jalr t1\n");\
1131  COMPLETE_IRQ_HANDLING_S(irq_num);\
1132  EXIT_NESTED_IRQ_HANDLING_S();\
1133  RESTORE_CALLER_CONTEXT();\
1134  __asm volatile("fence io, io");\
1135 }
1136 #endif
1137 #else
1138 
1139 #define SDK_DECLARE_EXT_ISR_M(irq_num, isr) \
1140 void isr(void) __attribute__((section(".isr_vector")));\
1141 HPM_EXTERN_C void ISR_NAME_M(irq_num)(void) __attribute__((section(".isr_vector")));\
1142 void ISR_NAME_M(irq_num)(void) { \
1143  isr(); \
1144 }
1145 
1146 #define SDK_DECLARE_EXT_ISR_S(irq_num, isr) \
1147 void isr(void) __attribute__((section(".isr_vector")));\
1148 HPM_EXTERN_C void ISR_NAME_S(irq_num)(void) __attribute__((section(".isr_vector")));\
1149 void ISR_NAME_S(irq_num)(void) { \
1150  isr(); \
1151 }
1152 
1153 #endif
1154 
1155 
1161 #define SDK_DECLARE_MCHTMR_ISR(isr) \
1162 void isr(void) __attribute__((section(".isr_vector")));\
1163 HPM_EXTERN_C void mchtmr_isr(void) __attribute__((section(".isr_vector"))); \
1164 void mchtmr_isr(void) {\
1165  isr();\
1166 }
1167 
1173 #define SDK_DECLARE_SWI_ISR(isr)\
1174 void isr(void) __attribute__((section(".isr_vector")));\
1175 HPM_EXTERN_C void swi_isr(void) __attribute__((section(".isr_vector"))); \
1176 void swi_isr(void) {\
1177  isr();\
1178 }
1179 
1180 /* Supervisor mode */
1181 
1187 #define SDK_DECLARE_MCHTMR_ISR_S(isr) \
1188 void isr(void) __attribute__((section(".isr_vector")));\
1189 HPM_EXTERN_C void mchtmr_s_isr(void) __attribute__((section(".isr_vector"))); \
1190 void mchtmr_s_isr(void) {\
1191  isr();\
1192 }
1193 
1199 #define SDK_DECLARE_SWI_ISR_S(isr)\
1200 void isr(void) __attribute__((section(".isr_vector")));\
1201 HPM_EXTERN_C void swi_s_isr(void) __attribute__((section(".isr_vector"))); \
1202 void swi_s_isr(void) {\
1203  isr();\
1204 }
1205 
1206 #define CSR_MSTATUS_MPP_S_MODE (0x1)
1207 #define MODE_SWITCH_FROM_M(mstatus, mepc, label, mode) \
1208 do { \
1209  if (label) { \
1210  write_csr(mepc, label); \
1211  } \
1212  clear_csr(mstatus, CSR_MSTATUS_MPP_MASK); \
1213  set_csr(mstatus, CSR_MSTATUS_MPP_SET(mode)); \
1214 } while(0)
1215 
1216 typedef void (*s_mode_entry)(void);
1217 
1223 static inline void switch_to_s_mode(s_mode_entry entry)
1224 {
1225  write_csr(CSR_SEPC, entry);
1227  if (entry) {
1228  __asm("mret");
1229  }
1230 }
1231 #ifdef __cplusplus
1232 }
1233 #endif
1234 
1238 #endif /* HPM_INTERRUPT_H */
#define CSR_MIE_MEIE_MASK
Definition: hpm_csr_regs.h:734
#define CSR_MEPC
Definition: hpm_csr_regs.h:31
#define CSR_MSTATUS
Definition: hpm_csr_regs.h:21
#define CSR_MIE_MTIE_MASK
Definition: hpm_csr_regs.h:758
#define CSR_MIE
Definition: hpm_csr_regs.h:23
#define CSR_MIE_MSIE_MASK
Definition: hpm_csr_regs.h:782
#define HPM_PLICSW_BASE
Definition: hpm_soc.h:52
#define HPM_PLIC_BASE
Definition: hpm_soc.h:38
#define CSR_SEPC
Definition: hpm_csr_regs.h:27
#define CSR_SSTATUS
Definition: hpm_csr_regs.h:21
#define CSR_SIE_SEIE_MASK
Definition: hpm_csr_regs.h:677
#define CSR_SIE_SSIE_MASK
Definition: hpm_csr_regs.h:725
#define CSR_SIP
Definition: hpm_csr_regs.h:30
#define CSR_SIE_STIE_MASK
Definition: hpm_csr_regs.h:701
#define CSR_MIDELEG
Definition: hpm_csr_regs.h:35
#define CSR_SIP_SSIP_MASK
Definition: hpm_csr_regs.h:889
#define CSR_SIE
Definition: hpm_csr_regs.h:24
static ATTR_ALWAYS_INLINE void intc_complete_irq(uint32_t target, uint32_t irq)
Complete IRQ.
Definition: hpm_interrupt.h:458
static ATTR_ALWAYS_INLINE void enable_global_irq(uint32_t mask)
Enable global IRQ with mask.
Definition: hpm_interrupt.h:34
static ATTR_ALWAYS_INLINE void intc_m_disable_swi(void)
Disable software interrupt.
Definition: hpm_interrupt.h:216
static ATTR_ALWAYS_INLINE void intc_s_complete_swi(void)
Complete software interrupt for supervisor mode.
Definition: hpm_interrupt.h:335
static ATTR_ALWAYS_INLINE void intc_s_trigger_swi(void)
Trigger software interrupt for supervisor mode.
Definition: hpm_interrupt.h:325
static ATTR_ALWAYS_INLINE void disable_irq_from_intc(void)
Disable IRQ from interrupt controller.
Definition: hpm_interrupt.h:73
static ATTR_ALWAYS_INLINE void intc_set_irq_priority(uint32_t irq, uint32_t priority)
Set interrupt priority.
Definition: hpm_interrupt.h:403
static ATTR_ALWAYS_INLINE void intc_disable_irq(uint32_t target, uint32_t irq)
Disable specific interrupt.
Definition: hpm_interrupt.h:414
static ATTR_ALWAYS_INLINE void intc_m_trigger_swi(void)
Trigger software interrupt.
Definition: hpm_interrupt.h:226
static ATTR_ALWAYS_INLINE void install_isr(uint32_t irq, uint32_t isr)
Install ISR for certain IRQ for ram based vector table.
Definition: hpm_interrupt.h:477
static ATTR_ALWAYS_INLINE void restore_s_global_irq(uint32_t mask)
Restore global IRQ with mask for supervisor mode.
Definition: hpm_interrupt.h:144
static ATTR_ALWAYS_INLINE void enable_irq_from_intc(void)
Enable IRQ from interrupt controller.
Definition: hpm_interrupt.h:64
static ATTR_ALWAYS_INLINE void restore_global_irq(uint32_t mask)
Restore global IRQ with mask.
Definition: hpm_interrupt.h:55
static ATTR_ALWAYS_INLINE void uninstall_s_isr(uint32_t irq)
Uninstall ISR for certain IRQ for ram based vector table for supervisor mode.
Definition: hpm_interrupt.h:514
static ATTR_ALWAYS_INLINE void enable_s_global_irq(uint32_t mask)
Enable global IRQ with mask for supervisor mode.
Definition: hpm_interrupt.h:123
static ATTR_ALWAYS_INLINE void intc_enable_irq(uint32_t target, uint32_t irq)
Definition: hpm_interrupt.h:392
static ATTR_ALWAYS_INLINE void install_s_isr(uint32_t irq, uint32_t isr)
Install ISR for certain IRQ for ram based vector table for supervisor mode.
Definition: hpm_interrupt.h:503
static ATTR_ALWAYS_INLINE void enable_s_irq_from_intc(void)
Enable IRQ from interrupt controller for supervisor mode.
Definition: hpm_interrupt.h:162
static ATTR_ALWAYS_INLINE void delegate_irq(uint32_t mask)
Delegate IRQ handling.
Definition: hpm_interrupt.h:100
static ATTR_ALWAYS_INLINE void undelegate_irq(uint32_t mask)
Undelegate IRQ handling.
Definition: hpm_interrupt.h:110
static ATTR_ALWAYS_INLINE void disable_mchtmr_irq(void)
Disable machine timer IRQ.
Definition: hpm_interrupt.h:90
static ATTR_ALWAYS_INLINE void intc_m_init_swi(void)
Initialize software interrupt.
Definition: hpm_interrupt.h:196
static ATTR_ALWAYS_INLINE void intc_m_enable_swi(void)
Enable software interrupt.
Definition: hpm_interrupt.h:206
static ATTR_ALWAYS_INLINE void intc_m_complete_swi(void)
Complete software interrupt.
Definition: hpm_interrupt.h:244
static ATTR_ALWAYS_INLINE void intc_s_disable_swi(void)
Disable software interrupt for supervisor mode.
Definition: hpm_interrupt.h:315
static void switch_to_s_mode(s_mode_entry entry)
Switch mode to supervisor from machine.
Definition: hpm_interrupt.h:1223
static ATTR_ALWAYS_INLINE uint32_t intc_get_threshold(uint32_t target)
Get interrupt threshold.
Definition: hpm_interrupt.h:435
static ATTR_ALWAYS_INLINE void enable_s_mchtmr_irq(void)
Enable machine timer IRQ for supervisor mode.
Definition: hpm_interrupt.h:170
static ATTR_ALWAYS_INLINE void intc_set_threshold(uint32_t target, uint32_t threshold)
Set interrupt threshold.
Definition: hpm_interrupt.h:425
static ATTR_ALWAYS_INLINE void uninstall_isr(uint32_t irq)
Uninstall ISR for certain IRQ for ram based vector table.
Definition: hpm_interrupt.h:488
static ATTR_ALWAYS_INLINE uint32_t disable_s_global_irq(uint32_t mask)
Disable global IRQ with mask and return sstatus for supervisor mode.
Definition: hpm_interrupt.h:134
static ATTR_ALWAYS_INLINE uint32_t intc_claim_irq(uint32_t target)
Claim IRQ.
Definition: hpm_interrupt.h:446
static ATTR_ALWAYS_INLINE void intc_m_claim_swi(void)
Claim software interrupt.
Definition: hpm_interrupt.h:235
static ATTR_ALWAYS_INLINE uint32_t disable_global_irq(uint32_t mask)
Disable global IRQ with mask and return mstatus.
Definition: hpm_interrupt.h:45
static ATTR_ALWAYS_INLINE void disable_s_mchtmr_irq(void)
Disable machine timer IRQ.
Definition: hpm_interrupt.h:179
static ATTR_ALWAYS_INLINE void enable_mchtmr_irq(void)
Enable machine timer IRQ.
Definition: hpm_interrupt.h:81
static ATTR_ALWAYS_INLINE void disable_s_irq_from_intc(void)
Disable IRQ from interrupt controller for supervisor mode.
Definition: hpm_interrupt.h:153
static ATTR_ALWAYS_INLINE void intc_s_enable_swi(void)
Enable software interrupt for supervisor mode.
Definition: hpm_interrupt.h:305
#define CSR_MSTATUS_MPP_S_MODE
Definition: hpm_interrupt.h:1206
void default_s_irq_entry(void)
#define MODE_SWITCH_FROM_M(mstatus, mepc, label, mode)
Definition: hpm_interrupt.h:1207
void default_irq_entry(void)
#define PLICSWI
Definition: hpm_interrupt.h:190
void(* s_mode_entry)(void)
Definition: hpm_interrupt.h:1218
#define HPM_PLIC_TARGET_M_MODE
Definition: hpm_plic_drv.h:17
#define set_csr(csr_num, bit)
set bits in csr
Definition: riscv_core.h:58
#define write_csr(csr_num, v)
write value to csr
Definition: riscv_core.h:66
#define clear_csr(csr_num, bit)
clear bits in csr
Definition: riscv_core.h:30
#define read_clear_csr(csr_num, bit)
read and clear bits in csr
Definition: riscv_core.h:40