1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| .section .text.irq .align 2 .global irq_entry .weak irq_entry irq_entry: // -------------> This label will be set to MTVT2 register // Allocate the stack space //保存现场 SAVE_CONTEXT// Save 16 regs
//------This special CSR read operation, which is actually use mcause as operand to directly store it to memory csrrwi x0, CSR_PUSHMCAUSE, 17 //------This special CSR read operation, which is actually use mepc as operand to directly store it to memory csrrwi x0, CSR_PUSHMEPC, 18 //------This special CSR read operation, which is actually use Msubm as operand to directly store it to memory csrrwi x0, CSR_PUSHMSUBM, 19
service_loop: //------This special CSR read/write operation, which is actually Claim the CLIC to find its pending highest // ID, if the ID is not 0, then automatically enable the mstatus.MIE, and jump to its vector-entry-label, and // update the link register
csrrw ra, CSR_JALMNXTI, ra //RESTORE_CONTEXT_EXCPT_X5
//恢复现场 #---- Critical section with interrupts disabled ----------------------- DISABLE_MIE # Disable interrupts
LOAD x5, 19*REGBYTES(sp) csrw CSR_MSUBM, x5 LOAD x5, 18*REGBYTES(sp) csrw CSR_MEPC, x5 LOAD x5, 17*REGBYTES(sp) csrw CSR_MCAUSE, x5
RESTORE_CONTEXT // Return to regular code mret
.global TIMER6_IRQHandler //定时器六中断,作为线程切换中断 TIMER6_IRQHandler: //保存x18~x27寄存器,s1 addi sp, sp, -11*REGBYTES STORE x27, 0*REGBYTES(sp) STORE x26, 1*REGBYTES(sp) STORE x25, 2*REGBYTES(sp) STORE x24, 3*REGBYTES(sp) STORE x23, 4*REGBYTES(sp) STORE x22, 5*REGBYTES(sp) STORE x21, 6*REGBYTES(sp) STORE x20, 7*REGBYTES(sp) STORE x19, 8*REGBYTES(sp) STORE x18, 9*REGBYTES(sp) STORE x9, 10*REGBYTES(sp)
mv a0,sp //sp mv a1,s0 //fp
addi sp,sp,-4 sw ra,0(sp) call switch_thread lw ra,0(sp) addi sp,sp,4
mv sp,x30 //切换sp mv s0,x31 //切换fp
//还原x18~x27寄存器,s1 LOAD x27, 0*REGBYTES(sp) LOAD x26, 1*REGBYTES(sp) LOAD x25, 2*REGBYTES(sp) LOAD x24, 3*REGBYTES(sp) LOAD x23, 4*REGBYTES(sp) LOAD x22, 5*REGBYTES(sp) LOAD x21, 6*REGBYTES(sp) LOAD x20, 7*REGBYTES(sp) LOAD x19, 8*REGBYTES(sp) LOAD x18, 9*REGBYTES(sp) LOAD x9, 10*REGBYTES(sp) addi sp, sp, 11*REGBYTES
//清空计数器 lui a0,0x40001 addi a1,a0,1060 sw zero,0(a1)
//清除中断标志位 addi a1,a0,1040 li a2,-2 sw a2,0(a1) ret
|