8 #ifndef HPM_INTERRUPT_H
9 #define HPM_INTERRUPT_H
254 #define intc_m_enable_irq(irq) \
255 intc_enable_irq(HPM_PLIC_TARGET_M_MODE, irq)
262 #define intc_m_disable_irq(irq) \
263 intc_disable_irq(HPM_PLIC_TARGET_M_MODE, irq)
265 #define intc_m_set_threshold(threshold) \
266 intc_set_threshold(HPM_PLIC_TARGET_M_MODE, threshold)
268 #define intc_m_get_threshold() \
269 intc_get_threshold(HPM_PLIC_TARGET_M_MODE)
276 #define intc_m_complete_irq(irq) \
277 intc_complete_irq(HPM_PLIC_TARGET_M_MODE, irq)
283 #define intc_m_claim_irq() intc_claim_irq(HPM_PLIC_TARGET_M_MODE)
291 #define intc_m_enable_irq_with_priority(irq, priority) \
293 intc_set_irq_priority(irq, priority); \
294 intc_m_enable_irq(irq); \
345 #define intc_s_enable_irq(irq) \
346 intc_enable_irq(HPM_PLIC_TARGET_S_MODE, irq)
353 #define intc_s_disable_irq(irq) \
354 intc_disable_irq(HPM_PLIC_TARGET_S_MODE, irq)
356 #define intc_set_s_threshold(threshold) \
357 intc_set_threshold(HPM_PLIC_TARGET_S_MODE, threshold)
364 #define intc_s_complete_irq(irq) \
365 intc_complete_irq(HPM_PLIC_TARGET_S_MODE, irq)
371 #define intc_s_claim_irq() intc_claim_irq(HPM_PLIC_TARGET_S_MODE)
379 #define intc_s_enable_irq_with_priority(irq, priority) \
381 intc_set_irq_priority(irq, priority); \
382 intc_s_enable_irq(irq); \
467 extern int __vector_table[];
477 ATTR_ALWAYS_INLINE
static inline void install_isr(uint32_t irq, uint32_t isr)
479 __vector_table[irq] = isr;
494 extern int __vector_s_table[];
503 ATTR_ALWAYS_INLINE
static inline void install_s_isr(uint32_t irq, uint32_t isr)
505 __vector_s_table[irq] = isr;
527 #define SAVE_CSR(r) register long __##r = read_csr(r);
534 #define RESTORE_CSR(r) write_csr(r, __##r);
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)
540 #define SAVE_MXSTATUS()
541 #define RESTORE_MXSTATUS()
545 #define SAVE_FCSR() register int __fcsr = read_fcsr();
546 #define RESTORE_FCSR() write_fcsr(__fcsr);
549 #define RESTORE_FCSR()
553 #define SAVE_UCODE() SAVE_CSR(CSR_UCODE)
554 #define RESTORE_UCODE() RESTORE_CSR(CSR_UCODE)
557 #define RESTORE_UCODE()
561 #if __riscv_flen == 32
563 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * (22 + 20)), 16)
566 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * (22 + 20 * 2)), 16)
571 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * 22), 16)
579 #if __riscv_flen == 32
581 #define SAVE_FPU_CONTEXT() { \
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");\
609 #define RESTORE_FPU_CONTEXT() { \
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");\
633 #define SAVE_FPU_CONTEXT() { \
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");\
661 #define RESTORE_FPU_CONTEXT() { \
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");\
687 #define SAVE_FPU_CONTEXT() { \
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");\
715 #define RESTORE_FPU_CONTEXT() { \
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");\
739 #define SAVE_FPU_CONTEXT() { \
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");\
767 #define RESTORE_FPU_CONTEXT() { \
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");\
793 #define SAVE_FPU_CONTEXT()
794 #define RESTORE_FPU_CONTEXT()
801 #define SAVE_CALLER_CONTEXT() { \
802 __asm volatile("addi sp, sp, %0" : : "i"(-CONTEXT_REG_NUM) :);\
826 SAVE_FPU_CONTEXT(); \
832 #define RESTORE_CALLER_CONTEXT() { \
855 c.lwsp t6, 21*4 \n");\
856 RESTORE_FPU_CONTEXT(); \
857 __asm volatile("addi sp, sp, %0" : : "i"(CONTEXT_REG_NUM) :);\
863 #define SAVE_CALLER_CONTEXT() { \
864 __asm volatile("addi sp, sp, %0" : : "i"(-CONTEXT_REG_NUM) :);\
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(); \
894 #define RESTORE_CALLER_CONTEXT() { \
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) :);\
924 #define SAVE_FPU_STATE() { \
925 __asm volatile("frcsr s1\n"); \
928 #define RESTORE_FPU_STATE() { \
929 __asm volatile("fscsr s1\n"); \
932 #define SAVE_FPU_STATE()
933 #define RESTORE_FPU_STATE()
940 #define SAVE_DSP_CONTEXT() { \
941 __asm volatile("csrrs s4, %0, x0\n" ::"i"(CSR_UCODE):); \
946 #define RESTORE_DSP_CONTEXT() {\
947 __asm volatile("csrw %0, s4\n" ::"i"(CSR_UCODE):); \
951 #define SAVE_DSP_CONTEXT()
952 #define RESTORE_DSP_CONTEXT()
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):); \
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):); \
978 #define ENTER_NESTED_IRQ_HANDLING_M() { \
981 csrr s3, mstatus \n");\
983 SAVE_DSP_CONTEXT(); \
984 SAVE_MCCTL_CONTEXT(); \
985 __asm volatile("csrsi mstatus, 8"); \
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)"); \
1006 #define EXIT_NESTED_IRQ_HANDLING_M() { \
1008 csrw mstatus, s3 \n\
1009 csrw mepc, s2 \n");\
1010 RESTORE_FPU_STATE(); \
1011 RESTORE_DSP_CONTEXT(); \
1012 RESTORE_MCCTL_CONTEXT(); \
1016 #define ENTER_NESTED_IRQ_HANDLING_S() {\
1019 csrr s3, sstatus \n");\
1021 SAVE_DSP_CONTEXT(); \
1022 __asm volatile("csrsi sstatus, 2"); \
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)"); \
1038 #define EXIT_NESTED_IRQ_HANDLING_S() { \
1040 csrw sstatus, s3 \n\
1041 csrw sepc, s2 \n");\
1042 RESTORE_FPU_STATE(); \
1043 RESTORE_DSP_CONTEXT(); \
1047 #define NESTED_IRQ_ENTER() \
1048 SAVE_CSR(CSR_MEPC) \
1049 SAVE_CSR(CSR_MSTATUS) \
1053 set_csr(CSR_MSTATUS, CSR_MSTATUS_MIE_MASK);
1056 #define NESTED_IRQ_EXIT() \
1057 RESTORE_CSR(CSR_MSTATUS) \
1058 RESTORE_CSR(CSR_MEPC) \
1059 RESTORE_MXSTATUS() \
1064 #define HPM_EXTERN_C extern "C"
1066 #define HPM_EXTERN_C
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) \
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) \
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) \
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");\
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");\
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) { \
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) { \
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) {\
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) {\
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) {\
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) {\
1206 #define CSR_MSTATUS_MPP_S_MODE (0x1)
1207 #define MODE_SWITCH_FROM_M(mstatus, mepc, label, mode) \
1210 write_csr(mepc, label); \
1212 clear_csr(mstatus, CSR_MSTATUS_MPP_MASK); \
1213 set_csr(mstatus, CSR_MSTATUS_MPP_SET(mode)); \
#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