// kern/trap/trap.c/* trap_dispatch - dispatch based on what type of trap occurred */staticinlinevoidtrap_dispatch(struct trapframe *tf) {//scause的最高位是1,说明trap是由中断引起的if ((intptr_t)tf->cause <0) {// interruptsinterrupt_handler(tf); } else {// exceptionsexception_handler(tf); }}/* * * trap - handles or dispatches an exception/interrupt. if and when trap() * returns, * the code in kern/trap/trapentry.S restores the old CPU state saved in the * trapframe and then uses the iret instruction to return from the exception. * */voidtrap(struct trapframe *tf) { trap_dispatch(tf); }
interrupt_handler()和exception_handler()的实现还比较简单,只是简单地根据scause的数值更仔细地分了下类,做了一些输出就直接返回了。switch里的各种case, 如IRQ_U_SOFT,CAUSE_USER_ECALL,是riscv ISA 标准里规定的。我们在riscv.h里定义了这些常量。我们接下来主要关注时钟中断的处理。