Riscv 异常处理 原文地址:https://joessem.com/archives/riscv-exception-handler.html 简单描述 RISCV 处理器在发生异常时的处理过程。 异常与中断的关系。 中断和异常都为异常,分为: 同步异常:IO,illegal, page fault,miss_aligh 等来自处理器内部的发生的异常。 异步异常(中断):鼠标,键盘,Timer 等外部事件。
There are no specific enable bits to allow exceptions to occur since they are always enabled by default. However, early in the boot flow, software should set up mtvec.BASE to a defined value, which contains the base address of the default exception handler. All exceptions will trap to mtve...
异常和中断 在RISC-V里,异常(exception)和中断(interrupt)统称为陷阱(trap),这里的异常又可以称作同步中断,而中断是指异步中断。说到异常和中断,就不得不提RISC-V的特权级别(Privilege Levels)了,RISC-V架构目前一共定义了3种特权级别,由低到高分别是用户、监督者和机器级别(模式)。其中机器模式是必须要实现的,...
la x3, interrupt_vector_table add x3, x3, x1 # Get the address of the specific interrupt handler jr x3 # Jump to the interrupt handler handle_exception: # Handle exception li x2, 0x7FFFFFFF # Load mask to clear the highest bit and x1, x1, x2 # Clear the highest bit to get the...
U-mode往往是普通用户或应用使用的模式,是在不可信任运行环境下的特权模式。hart通常在U-mode下运行应用程序代码,直到遇到某些trap(如supervisor call或者timer interrupt)而迫使其切换至trap handler,交给更高特权模式处理异常与安全中断。 2.3 RISC-V 架构的异常与中断 ...
入口函数 EXCEPTION_HANDLER,根据异常号跳转至相应的异常处理程序。 初始化时设置 mtvec = EXCEPTION_HANDLER,使用正常中断模式(MODE = DIRECT);如果不支持 MODE = DIRECT(利用 mtvec 的 WARL 判断),则会使用向量中断模式(MODE = VECTORED)。 用户程序在 U-mode 中运行(mret 时 mstatus.MPP = 0),通过 ebre...
setup_trap_vector: /* Set trap vector to exception handler */ /* 设置CSR_TVEC寄存器,为异常以及中断做准备 */ la a0, handle_exception csrw CSR_TVEC, a0 /* * Set sup0 scratch register to 0, indicating to exception vector that * we are presently executing in kernel. ...
call core_exception_handler//调用中断处理函数,将前面传的a0和a1作为函数的参数 RESTORE_CSR_CONTEXT//调用宏RESTORE_CSR_CONTEXT,作用是恢复保存的寄存器内容 RESTORE_CONTEXT//调用宏RESTORE_CONTEXT,作用是恢复保存的上下文 mret//退出中断处理函数 在汇编中调用C/C++函数 ...
运行期间的、与某条指令有关的异常情况,例如指令地址未对齐instruction-address-misaligned、非法指令illegal-instruction;用中断(interrupt)来指代发生在外部的、可能导致hart转移控制权的异步事件,例如计时器中断timer-interrupt;用陷阱(trap)统称由exception或者interrupt造成的、将控制权转到陷阱处理器(trap handler)的控制...
medeleg(machine exception delegation)用于指示转发哪些异常到 S-mode;mideleg(machine interrupt delegation)用于指示转发哪些中断到 S-mode。 当将陷阱委托给 S 模式时,scause寄存器会写入陷阱原因;sepc寄存器会写入引发陷阱的指令的虚拟地址;stval寄存器会写入特定于异常的数据;mstatus的 SPP 字段会写入发生陷阱时的...