8 #ifndef HPM_INTERRUPT_H
9 #define HPM_INTERRUPT_H
12 #include "hpm_plic_drv.h"
13 #include "hpm_soc_feature.h"
102 ATTR_ALWAYS_INLINE
static inline void delegate_irq(uint32_t mask)
112 ATTR_ALWAYS_INLINE
static inline void undelegate_irq(uint32_t mask)
119 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
127 ATTR_ALWAYS_INLINE
static inline void enable_s_global_irq(uint32_t mask)
138 ATTR_ALWAYS_INLINE
static inline uint32_t disable_s_global_irq(uint32_t mask)
148 ATTR_ALWAYS_INLINE
static inline void restore_s_global_irq(uint32_t mask)
157 ATTR_ALWAYS_INLINE
static inline void disable_s_irq_from_intc(
void)
166 ATTR_ALWAYS_INLINE
static inline void enable_s_irq_from_intc(
void)
174 ATTR_ALWAYS_INLINE
static inline void enable_s_mchtmr_irq(
void)
183 ATTR_ALWAYS_INLINE
static inline void disable_s_mchtmr_irq(
void)
259 #define intc_m_enable_irq(irq) \
260 intc_enable_irq(HPM_PLIC_TARGET_M_MODE, irq)
267 #define intc_m_disable_irq(irq) \
268 intc_disable_irq(HPM_PLIC_TARGET_M_MODE, irq)
270 #define intc_m_set_threshold(threshold) \
271 intc_set_threshold(HPM_PLIC_TARGET_M_MODE, threshold)
273 #define intc_m_get_threshold() \
274 intc_get_threshold(HPM_PLIC_TARGET_M_MODE)
281 #define intc_m_complete_irq(irq) \
282 intc_complete_irq(HPM_PLIC_TARGET_M_MODE, irq)
288 #define intc_m_claim_irq() intc_claim_irq(HPM_PLIC_TARGET_M_MODE)
296 #define intc_m_enable_irq_with_priority(irq, priority) \
298 intc_set_irq_priority(irq, priority); \
299 intc_m_enable_irq(irq); \
304 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
311 ATTR_ALWAYS_INLINE
static inline void intc_s_enable_swi(
void)
321 ATTR_ALWAYS_INLINE
static inline void intc_s_disable_swi(
void)
331 ATTR_ALWAYS_INLINE
static inline void intc_s_trigger_swi(
void)
341 ATTR_ALWAYS_INLINE
static inline void intc_s_complete_swi(
void)
351 #define intc_s_enable_irq(irq) \
352 intc_enable_irq(HPM_PLIC_TARGET_S_MODE, irq)
359 #define intc_s_disable_irq(irq) \
360 intc_disable_irq(HPM_PLIC_TARGET_S_MODE, irq)
362 #define intc_set_s_threshold(threshold) \
363 intc_set_threshold(HPM_PLIC_TARGET_S_MODE, threshold)
370 #define intc_s_complete_irq(irq) \
371 intc_complete_irq(HPM_PLIC_TARGET_S_MODE, irq)
377 #define intc_s_claim_irq() intc_claim_irq(HPM_PLIC_TARGET_S_MODE)
385 #define intc_s_enable_irq_with_priority(irq, priority) \
387 intc_set_irq_priority(irq, priority); \
388 intc_s_enable_irq(irq); \
474 extern int __vector_table[];
484 ATTR_ALWAYS_INLINE
static inline void install_isr(uint32_t irq, uint32_t isr)
486 __vector_table[irq] = isr;
500 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
502 extern int __vector_s_table[];
503 extern void default_s_irq_entry(
void);
511 ATTR_ALWAYS_INLINE
static inline void install_s_isr(uint32_t irq, uint32_t isr)
513 __vector_s_table[irq] = isr;
522 ATTR_ALWAYS_INLINE
static inline void uninstall_s_isr(uint32_t irq)
524 __vector_s_table[irq] = (int) default_s_irq_entry;
536 #define SAVE_CSR(r) register long __##r = read_csr(r);
543 #define RESTORE_CSR(r) write_csr(r, __##r);
545 #if defined(SUPPORT_PFT_ARCH) && SUPPORT_PFT_ARCH
546 #define SAVE_MXSTATUS() SAVE_CSR(CSR_MXSTATUS)
547 #define RESTORE_MXSTATUS() RESTORE_CSR(CSR_MXSTATUS)
549 #define SAVE_MXSTATUS()
550 #define RESTORE_MXSTATUS()
554 #define SAVE_FCSR() register int __fcsr = read_fcsr();
555 #define RESTORE_FCSR() write_fcsr(__fcsr);
558 #define RESTORE_FCSR()
562 #define SAVE_UCODE() SAVE_CSR(CSR_UCODE)
563 #define RESTORE_UCODE() RESTORE_CSR(CSR_UCODE)
566 #define RESTORE_UCODE()
570 #if __riscv_flen == 32
572 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * (22 + 20)), 16)
575 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * (22 + 20 * 2)), 16)
580 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * 22), 16)
588 #if __riscv_flen == 32
590 #define SAVE_FPU_CONTEXT() { \
593 c.fswsp ft1, 23*4 \n\
594 c.fswsp ft2, 24*4 \n\
595 c.fswsp ft3, 25*4 \n\
596 c.fswsp ft4, 26*4 \n\
597 c.fswsp ft5, 27*4 \n\
598 c.fswsp ft6, 28*4 \n\
599 c.fswsp ft7, 29*4 \n\
600 c.fswsp fa0, 30*4 \n\
601 c.fswsp fa1, 31*4 \n\
602 c.fswsp fa2, 32*4 \n\
603 c.fswsp fa3, 33*4 \n\
604 c.fswsp fa4, 34*4 \n\
605 c.fswsp fa5, 35*4 \n\
606 c.fswsp fa6, 36*4 \n\
607 c.fswsp fa7, 37*4 \n\
608 c.fswsp ft8, 38*4 \n\
609 c.fswsp ft9, 39*4 \n\
610 c.fswsp ft10, 40*4 \n\
611 c.fswsp ft11, 41*4 \n");\
618 #define RESTORE_FPU_CONTEXT() { \
621 c.flwsp ft1, 23*4 \n\
622 c.flwsp ft2, 24*4 \n\
623 c.flwsp ft3, 25*4 \n\
624 c.flwsp ft4, 26*4 \n\
625 c.flwsp ft5, 27*4 \n\
626 c.flwsp ft6, 28*4 \n\
627 c.flwsp ft7, 29*4 \n\
628 c.flwsp fa0, 30*4 \n\
629 c.flwsp fa1, 31*4 \n\
630 c.flwsp fa2, 32*4 \n\
631 c.flwsp fa3, 33*4 \n\
632 c.flwsp fa4, 34*4 \n\
633 c.flwsp fa5, 35*4 \n\
634 c.flwsp fa6, 36*4 \n\
635 c.flwsp fa7, 37*4 \n\
636 c.flwsp ft8, 38*4 \n\
637 c.flwsp ft9, 39*4 \n\
638 c.flwsp ft10, 40*4 \n\
639 c.flwsp ft11, 41*4 \n");\
642 #define SAVE_FPU_CONTEXT() { \
644 c.fswsp ft0, 22*4(sp)\n\
645 c.fswsp ft1, 23*4(sp) \n\
646 c.fswsp ft2, 24*4(sp) \n\
647 c.fswsp ft3, 25*4(sp) \n\
648 c.fswsp ft4, 26*4(sp) \n\
649 c.fswsp ft5, 27*4(sp) \n\
650 c.fswsp ft6, 28*4(sp) \n\
651 c.fswsp ft7, 29*4(sp) \n\
652 c.fswsp fa0, 30*4(sp) \n\
653 c.fswsp fa1, 31*4(sp) \n\
654 c.fswsp fa2, 32*4(sp) \n\
655 c.fswsp fa3, 33*4(sp) \n\
656 c.fswsp fa4, 34*4(sp) \n\
657 c.fswsp fa5, 35*4(sp) \n\
658 c.fswsp fa6, 36*4(sp) \n\
659 c.fswsp fa7, 37*4(sp) \n\
660 c.fswsp ft8, 38*4(sp) \n\
661 c.fswsp ft9, 39*4(sp) \n\
662 c.fswsp ft10, 40*4(sp) \n\
663 c.fswsp ft11, 41*4(sp) \n");\
670 #define RESTORE_FPU_CONTEXT() { \
672 c.flwsp ft0, 22*4(sp)\n\
673 c.flwsp ft1, 23*4(sp) \n\
674 c.flwsp ft2, 24*4(sp) \n\
675 c.flwsp ft3, 25*4(sp) \n\
676 c.flwsp ft4, 26*4(sp) \n\
677 c.flwsp ft5, 27*4(sp) \n\
678 c.flwsp ft6, 28*4(sp) \n\
679 c.flwsp ft7, 29*4(sp) \n\
680 c.flwsp fa0, 30*4(sp) \n\
681 c.flwsp fa1, 31*4(sp) \n\
682 c.flwsp fa2, 32*4(sp) \n\
683 c.flwsp fa3, 33*4(sp) \n\
684 c.flwsp fa4, 34*4(sp) \n\
685 c.flwsp fa5, 35*4(sp) \n\
686 c.flwsp fa6, 36*4(sp) \n\
687 c.flwsp fa7, 37*4(sp) \n\
688 c.flwsp ft8, 38*4(sp) \n\
689 c.flwsp ft9, 39*4(sp) \n\
690 c.flwsp ft10, 40*4(sp) \n\
691 c.flwsp ft11, 41*4(sp) \n");\
696 #define SAVE_FPU_CONTEXT() { \
699 c.fsdsp ft1, 24*4 \n\
700 c.fsdsp ft2, 26*4 \n\
701 c.fsdsp ft3, 28*4 \n\
702 c.fsdsp ft4, 30*4 \n\
703 c.fsdsp ft5, 32*4 \n\
704 c.fsdsp ft6, 34*4 \n\
705 c.fsdsp ft7, 36*4 \n\
706 c.fsdsp fa0, 38*4 \n\
707 c.fsdsp fa1, 40*4 \n\
708 c.fsdsp fa2, 42*4 \n\
709 c.fsdsp fa3, 44*4 \n\
710 c.fsdsp fa4, 46*4 \n\
711 c.fsdsp fa5, 48*4 \n\
712 c.fsdsp fa6, 50*4 \n\
713 c.fsdsp fa7, 52*4 \n\
714 c.fsdsp ft8, 54*4 \n\
715 c.fsdsp ft9, 56*4 \n\
716 c.fsdsp ft10, 58*4 \n\
717 c.fsdsp ft11, 60*4 \n");\
724 #define RESTORE_FPU_CONTEXT() { \
727 c.fldsp ft1, 24*4 \n\
728 c.fldsp ft2, 26*4 \n\
729 c.fldsp ft3, 28*4 \n\
730 c.fldsp ft4, 30*4 \n\
731 c.fldsp ft5, 32*4 \n\
732 c.fldsp ft6, 34*4 \n\
733 c.fldsp ft7, 36*4 \n\
734 c.fldsp fa0, 38*4 \n\
735 c.fldsp fa1, 40*4 \n\
736 c.fldsp fa2, 42*4 \n\
737 c.fldsp fa3, 44*4 \n\
738 c.fldsp fa4, 46*4 \n\
739 c.fldsp fa5, 48*4 \n\
740 c.fldsp fa6, 50*4 \n\
741 c.fldsp fa7, 52*4 \n\
742 c.fldsp ft8, 54*4 \n\
743 c.fldsp ft9, 56*4 \n\
744 c.fldsp ft10, 58*4 \n\
745 c.fldsp ft11, 60*4 \n");\
748 #define SAVE_FPU_CONTEXT() { \
750 c.fsdsp ft0, 22*4(sp)\n\
751 c.fsdsp ft1, 24*4(sp) \n\
752 c.fsdsp ft2, 26*4(sp) \n\
753 c.fsdsp ft3, 28*4(sp) \n\
754 c.fsdsp ft4, 30*4(sp) \n\
755 c.fsdsp ft5, 32*4(sp) \n\
756 c.fsdsp ft6, 34*4(sp) \n\
757 c.fsdsp ft7, 36*4(sp) \n\
758 c.fsdsp fa0, 38*4(sp) \n\
759 c.fsdsp fa1, 40*4(sp) \n\
760 c.fsdsp fa2, 42*4(sp) \n\
761 c.fsdsp fa3, 44*4(sp) \n\
762 c.fsdsp fa4, 46*4(sp) \n\
763 c.fsdsp fa5, 48*4(sp) \n\
764 c.fsdsp fa6, 50*4(sp) \n\
765 c.fsdsp fa7, 52*4(sp) \n\
766 c.fsdsp ft8, 54*4(sp) \n\
767 c.fsdsp ft9, 56*4(sp) \n\
768 c.fsdsp ft10, 58*4(sp) \n\
769 c.fsdsp ft11, 60*4(sp) \n");\
776 #define RESTORE_FPU_CONTEXT() { \
778 c.fldsp ft0, 22*4(sp)\n\
779 c.fldsp ft1, 24*4(sp) \n\
780 c.fldsp ft2, 26*4(sp) \n\
781 c.fldsp ft3, 28*4(sp) \n\
782 c.fldsp ft4, 30*4(sp) \n\
783 c.fldsp ft5, 32*4(sp) \n\
784 c.fldsp ft6, 34*4(sp) \n\
785 c.fldsp ft7, 36*4(sp) \n\
786 c.fldsp fa0, 38*4(sp) \n\
787 c.fldsp fa1, 40*4(sp) \n\
788 c.fldsp fa2, 42*4(sp) \n\
789 c.fldsp fa3, 44*4(sp) \n\
790 c.fldsp fa4, 46*4(sp) \n\
791 c.fldsp fa5, 48*4(sp) \n\
792 c.fldsp fa6, 50*4(sp) \n\
793 c.fldsp fa7, 52*4(sp) \n\
794 c.fldsp ft8, 54*4(sp) \n\
795 c.fldsp ft9, 56*4(sp) \n\
796 c.fldsp ft10, 58*4(sp) \n\
797 c.fldsp ft11, 60*4(sp) \n");\
802 #define SAVE_FPU_CONTEXT()
803 #define RESTORE_FPU_CONTEXT()
810 #define SAVE_CALLER_CONTEXT() { \
811 __asm volatile("addi sp, sp, %0" : : "i"(-CONTEXT_REG_NUM) :);\
835 SAVE_FPU_CONTEXT(); \
841 #define RESTORE_CALLER_CONTEXT() { \
864 c.lwsp t6, 21*4 \n");\
865 RESTORE_FPU_CONTEXT(); \
866 __asm volatile("addi sp, sp, %0" : : "i"(CONTEXT_REG_NUM) :);\
872 #define SAVE_CALLER_CONTEXT() { \
873 __asm volatile("addi sp, sp, %0" : : "i"(-CONTEXT_REG_NUM) :);\
875 c.swsp ra, 0*4(sp) \n\
876 c.swsp t0, 1*4(sp) \n\
877 c.swsp t1, 2*4(sp) \n\
878 c.swsp t2, 3*4(sp) \n\
879 c.swsp s1, 4*4(sp) \n\
880 c.swsp a0, 5*4(sp) \n\
881 c.swsp a1, 6*4(sp) \n\
882 c.swsp a2, 7*4(sp) \n\
883 c.swsp a3, 8*4(sp) \n\
884 c.swsp a4, 9*4(sp) \n\
885 c.swsp a5, 10*4(sp) \n\
886 c.swsp a6, 11*4(sp) \n\
887 c.swsp a7, 12*4(sp) \n\
888 c.swsp s2, 13*4(sp) \n\
889 c.swsp s3, 14*4(sp) \n\
890 c.swsp s4, 15*4(sp) \n\
891 c.swsp s5, 16*4(sp) \n\
892 c.swsp s6, 17*4(sp) \n\
893 c.swsp t3, 18*4(sp) \n\
894 c.swsp t4, 19*4(sp) \n\
895 c.swsp t5, 20*4(sp) \n\
896 c.swsp t6, 21*4(sp)"); \
897 SAVE_FPU_CONTEXT(); \
903 #define RESTORE_CALLER_CONTEXT() { \
905 c.lwsp ra, 0*4(sp) \n\
906 c.lwsp t0, 1*4(sp) \n\
907 c.lwsp t1, 2*4(sp) \n\
908 c.lwsp t2, 3*4(sp) \n\
909 c.lwsp s1, 4*4(sp) \n\
910 c.lwsp a0, 5*4(sp) \n\
911 c.lwsp a1, 6*4(sp) \n\
912 c.lwsp a2, 7*4(sp) \n\
913 c.lwsp a3, 8*4(sp) \n\
914 c.lwsp a4, 9*4(sp) \n\
915 c.lwsp a5, 10*4(sp) \n\
916 c.lwsp a6, 11*4(sp) \n\
917 c.lwsp a7, 12*4(sp) \n\
918 c.lwsp s2, 13*4(sp) \n\
919 c.lwsp s3, 14*4(sp) \n\
920 c.lwsp s4, 15*4(sp) \n\
921 c.lwsp s5, 16*4(sp) \n\
922 c.lwsp s6, 17*4(sp) \n\
923 c.lwsp t3, 18*4(sp) \n\
924 c.lwsp t4, 19*4(sp) \n\
925 c.lwsp t5, 20*4(sp) \n\
926 c.lwsp t6, 21*4(sp) \n");\
927 RESTORE_FPU_CONTEXT(); \
928 __asm volatile("addi sp, sp, %0" : : "i"(CONTEXT_REG_NUM) :);\
933 #define SAVE_FPU_STATE() { \
934 __asm volatile("frcsr s1\n"); \
937 #define RESTORE_FPU_STATE() { \
938 __asm volatile("fscsr s1\n"); \
941 #define SAVE_FPU_STATE()
942 #define RESTORE_FPU_STATE()
949 #define SAVE_DSP_CONTEXT() { \
950 __asm volatile("csrrs s4, %0, x0\n" ::"i"(CSR_UCODE):); \
955 #define RESTORE_DSP_CONTEXT() {\
956 __asm volatile("csrw %0, s4\n" ::"i"(CSR_UCODE):); \
960 #define SAVE_DSP_CONTEXT()
961 #define RESTORE_DSP_CONTEXT()
964 #if !defined(DISABLE_IRQ_PREEMPTIVE) || (DISABLE_IRQ_PREEMPTIVE == 0)
968 #define SAVE_MCCTL_CONTEXT() { \
969 __asm volatile("csrrs s5, %0, x0\n" ::"i"(CSR_MCCTLBEGINADDR):); \
970 __asm volatile("csrrs s6, %0, x0\n" ::"i"(CSR_MCCTLDATA):); \
975 #define RESTORE_MCCTL_CONTEXT() {\
976 __asm volatile("csrw %0, s6\n" ::"i"(CSR_MCCTLDATA):); \
977 __asm volatile("csrw %0, s5\n" ::"i"(CSR_MCCTLBEGINADDR):); \
988 #define ENTER_NESTED_IRQ_HANDLING_M() { \
991 csrr s3, mstatus \n");\
993 SAVE_DSP_CONTEXT(); \
994 SAVE_MCCTL_CONTEXT(); \
995 __asm volatile("csrsi mstatus, 8"); \
1001 #define COMPLETE_IRQ_HANDLING_M(irq_num) { \
1002 __asm volatile("csrci mstatus, 8"); \
1003 __asm volatile("lui a4, 0xe4200"); \
1004 __asm volatile("li a3, %0" : : "i" (irq_num) :); \
1005 __asm volatile("sw a3, 4(a4)"); \
1011 #define SAVE_MCCTL_CONTEXT()
1015 #define RESTORE_MCCTL_CONTEXT()
1025 #define ENTER_NESTED_IRQ_HANDLING_M() { \
1028 csrr s3, mstatus \n");\
1030 SAVE_DSP_CONTEXT(); \
1031 SAVE_MCCTL_CONTEXT(); \
1037 #define COMPLETE_IRQ_HANDLING_M(irq_num) { \
1038 __asm volatile("lui a4, 0xe4200"); \
1039 __asm volatile("li a3, %0" : : "i" (irq_num) :); \
1040 __asm volatile("sw a3, 4(a4)"); \
1053 #define EXIT_NESTED_IRQ_HANDLING_M() { \
1055 csrw mstatus, s3 \n\
1056 csrw mepc, s2 \n");\
1057 RESTORE_FPU_STATE(); \
1058 RESTORE_DSP_CONTEXT(); \
1059 RESTORE_MCCTL_CONTEXT(); \
1062 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1063 #if !defined(DISABLE_IRQ_PREEMPTIVE) || (DISABLE_IRQ_PREEMPTIVE == 0)
1064 #define ENTER_NESTED_IRQ_HANDLING_S() {\
1067 csrr s3, sstatus \n");\
1069 SAVE_DSP_CONTEXT(); \
1070 __asm volatile("csrsi sstatus, 2"); \
1072 #define COMPLETE_IRQ_HANDLING_S(irq_num) {\
1073 __asm volatile("csrci sstatus, 2"); \
1074 __asm volatile("lui a4, 0xe4201"); \
1075 __asm volatile("li a3, %0" : : "i" (irq_num) :); \
1076 __asm volatile("sw a3, 4(a4)"); \
1079 #define ENTER_NESTED_IRQ_HANDLING_S() {\
1082 csrr s3, sstatus \n");\
1084 SAVE_DSP_CONTEXT(); \
1086 #define COMPLETE_IRQ_HANDLING_S(irq_num) {\
1087 __asm volatile("lui a4, 0xe4201"); \
1088 __asm volatile("li a3, %0" : : "i" (irq_num) :); \
1089 __asm volatile("sw a3, 4(a4)"); \
1102 #define EXIT_NESTED_IRQ_HANDLING_S() { \
1104 csrw sstatus, s3 \n\
1105 csrw sepc, s2 \n");\
1106 RESTORE_FPU_STATE(); \
1107 RESTORE_DSP_CONTEXT(); \
1111 #define NESTED_IRQ_ENTER() \
1112 SAVE_CSR(CSR_MEPC) \
1113 SAVE_CSR(CSR_MSTATUS) \
1117 set_csr(CSR_MSTATUS, CSR_MSTATUS_MIE_MASK);
1120 #define NESTED_IRQ_EXIT() \
1121 RESTORE_CSR(CSR_MSTATUS) \
1122 RESTORE_CSR(CSR_MEPC) \
1123 RESTORE_MXSTATUS() \
1128 #define HPM_EXTERN_C extern "C"
1130 #define HPM_EXTERN_C
1133 #define ISR_NAME_M(irq_num) default_isr_##irq_num
1135 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1136 #define ISR_NAME_S(irq_num) default_isr_s_##irq_num
1145 #if !defined(USE_NONVECTOR_MODE) || (USE_NONVECTOR_MODE == 0)
1146 #if defined(CONFIG_FREERTOS) && CONFIG_FREERTOS
1147 #define FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num) irq_handler_wrapper_##irq_num
1148 #define SDK_DECLARE_EXT_ISR_M(irq_num, isr) \
1149 void isr(void) __attribute__((section(".isr_vector"))); \
1150 HPM_EXTERN_C void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) __attribute__((section(".isr_vector"))); \
1151 void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) \
1156 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1163 #define SDK_DECLARE_EXT_ISR_S(irq_num, isr) \
1164 void isr(void) __attribute__((section(".isr_s_vector")));\
1165 HPM_EXTERN_C void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) __attribute__((section(".isr_s_vector")));\
1166 void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) \
1173 #define SDK_DECLARE_EXT_ISR_M(irq_num, isr) \
1174 void isr(void) __attribute__((section(".isr_vector")));\
1175 HPM_EXTERN_C HPM_ATTR_MACHINE_INTERRUPT void ISR_NAME_M(irq_num)(void);\
1176 HPM_ATTR_MACHINE_INTERRUPT void ISR_NAME_M(irq_num)(void) \
1178 SAVE_CALLER_CONTEXT(); \
1179 ENTER_NESTED_IRQ_HANDLING_M();\
1180 __asm volatile("la t1, %0\n\t" : : "i" (isr) : );\
1181 __asm volatile("jalr t1\n");\
1182 COMPLETE_IRQ_HANDLING_M(irq_num);\
1183 EXIT_NESTED_IRQ_HANDLING_M();\
1184 RESTORE_CALLER_CONTEXT();\
1185 __asm volatile("fence io, io");\
1188 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1195 #define SDK_DECLARE_EXT_ISR_S(irq_num, isr) \
1196 void isr(void) __attribute__((section(".isr_s_vector")));\
1197 HPM_EXTERN_C HPM_ATTR_SUPERVISOR_INTERRUPT void ISR_NAME_S(irq_num)(void);\
1198 HPM_ATTR_SUPERVISOR_INTERRUPT void ISR_NAME_S(irq_num)(void) {\
1199 SAVE_CALLER_CONTEXT(); \
1200 ENTER_NESTED_IRQ_HANDLING_S();\
1201 __asm volatile("la t1, %0\n\t" : : "i" (isr) : );\
1202 __asm volatile("jalr t1\n");\
1203 COMPLETE_IRQ_HANDLING_S(irq_num);\
1204 EXIT_NESTED_IRQ_HANDLING_S();\
1205 RESTORE_CALLER_CONTEXT();\
1206 __asm volatile("fence io, io");\
1213 #define SDK_DECLARE_EXT_ISR_M(irq_num, isr) \
1214 void isr(void) __attribute__((section(".isr_vector")));\
1215 HPM_EXTERN_C void ISR_NAME_M(irq_num)(void) __attribute__((section(".isr_vector")));\
1216 void ISR_NAME_M(irq_num)(void) { \
1220 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1221 #define SDK_DECLARE_EXT_ISR_S(irq_num, isr) \
1222 void isr(void) __attribute__((section(".isr_vector")));\
1223 HPM_EXTERN_C void ISR_NAME_S(irq_num)(void) __attribute__((section(".isr_vector")));\
1224 void ISR_NAME_S(irq_num)(void) { \
1237 #define SDK_DECLARE_MCHTMR_ISR(isr) \
1238 void isr(void) __attribute__((section(".isr_vector")));\
1239 HPM_EXTERN_C void mchtmr_isr(void) __attribute__((section(".isr_vector"))); \
1240 void mchtmr_isr(void) {\
1249 #define SDK_DECLARE_SWI_ISR(isr)\
1250 void isr(void) __attribute__((section(".isr_vector")));\
1251 HPM_EXTERN_C void swi_isr(void) __attribute__((section(".isr_vector"))); \
1252 void swi_isr(void) {\
1256 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1264 #define SDK_DECLARE_MCHTMR_ISR_S(isr) \
1265 void isr(void) __attribute__((section(".isr_vector")));\
1266 HPM_EXTERN_C void mchtmr_s_isr(void) __attribute__((section(".isr_vector"))); \
1267 void mchtmr_s_isr(void) {\
1276 #define SDK_DECLARE_SWI_ISR_S(isr)\
1277 void isr(void) __attribute__((section(".isr_vector")));\
1278 HPM_EXTERN_C void swi_s_isr(void) __attribute__((section(".isr_vector"))); \
1279 void swi_s_isr(void) {\
1283 #define CSR_MSTATUS_MPP_S_MODE (0x1)
1284 #define MODE_SWITCH_FROM_M(mstatus, mepc, label, mode) \
1286 set_csr(CSR_SSTATUS, CSR_SSTATUS_SUM_MASK); \
1287 write_csr(mepc, label); \
1288 clear_csr(mstatus, CSR_MSTATUS_MPP_MASK); \
1289 set_csr(mstatus, CSR_MSTATUS_MPP_SET(mode)); \
1290 __asm volatile("mret"); \
1293 typedef void (*s_mode_entry)(void);
1300 static inline void switch_to_s_mode(s_mode_entry entry)
#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_ip.h:51
#define HPM_PLIC_BASE
Definition: hpm_soc_ip.h:37
#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:465
static ATTR_ALWAYS_INLINE void enable_global_irq(uint32_t mask)
Enable global IRQ with mask.
Definition: hpm_interrupt.h:35
static ATTR_ALWAYS_INLINE void intc_m_disable_swi(void)
Disable software interrupt.
Definition: hpm_interrupt.h:221
static ATTR_ALWAYS_INLINE void disable_irq_from_intc(void)
Disable IRQ from interrupt controller.
Definition: hpm_interrupt.h:74
static ATTR_ALWAYS_INLINE void intc_set_irq_priority(uint32_t irq, uint32_t priority)
Set interrupt priority.
Definition: hpm_interrupt.h:410
static ATTR_ALWAYS_INLINE void intc_disable_irq(uint32_t target, uint32_t irq)
Disable specific interrupt.
Definition: hpm_interrupt.h:421
static ATTR_ALWAYS_INLINE void intc_m_trigger_swi(void)
Trigger software interrupt.
Definition: hpm_interrupt.h:231
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:484
void default_irq_entry(void)
static ATTR_ALWAYS_INLINE void enable_irq_from_intc(void)
Enable IRQ from interrupt controller.
Definition: hpm_interrupt.h:65
static ATTR_ALWAYS_INLINE void restore_global_irq(uint32_t mask)
Restore global IRQ with mask.
Definition: hpm_interrupt.h:56
static ATTR_ALWAYS_INLINE void intc_enable_irq(uint32_t target, uint32_t irq)
Definition: hpm_interrupt.h:399
#define PLICSWI
Definition: hpm_interrupt.h:195
static ATTR_ALWAYS_INLINE void disable_mchtmr_irq(void)
Disable machine timer IRQ.
Definition: hpm_interrupt.h:91
static ATTR_ALWAYS_INLINE void intc_m_init_swi(void)
Initialize software interrupt.
Definition: hpm_interrupt.h:201
static ATTR_ALWAYS_INLINE void intc_m_enable_swi(void)
Enable software interrupt.
Definition: hpm_interrupt.h:211
static ATTR_ALWAYS_INLINE void intc_m_complete_swi(void)
Complete software interrupt.
Definition: hpm_interrupt.h:249
static ATTR_ALWAYS_INLINE uint32_t intc_get_threshold(uint32_t target)
Get interrupt threshold.
Definition: hpm_interrupt.h:442
static ATTR_ALWAYS_INLINE void intc_set_threshold(uint32_t target, uint32_t threshold)
Set interrupt threshold.
Definition: hpm_interrupt.h:432
static ATTR_ALWAYS_INLINE void uninstall_isr(uint32_t irq)
Uninstall ISR for certain IRQ for ram based vector table.
Definition: hpm_interrupt.h:495
static ATTR_ALWAYS_INLINE uint32_t intc_claim_irq(uint32_t target)
Claim IRQ.
Definition: hpm_interrupt.h:453
static ATTR_ALWAYS_INLINE void intc_m_claim_swi(void)
Claim software interrupt.
Definition: hpm_interrupt.h:240
static ATTR_ALWAYS_INLINE uint32_t disable_global_irq(uint32_t mask)
Disable global IRQ with mask and return mstatus.
Definition: hpm_interrupt.h:46
static ATTR_ALWAYS_INLINE void enable_mchtmr_irq(void)
Enable machine timer IRQ.
Definition: hpm_interrupt.h:82
#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 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