提问人:Lance E.T. Compte 提问时间:11/11/2023 更新时间:11/15/2023 访问量:52
在RISCV异常/中断处理程序中,如何返回到正确的权限模式?
In RISCV Exception/Interrupt Handlers, how to return to the correct privilege mode?
问:
假设我已将所有异常和中断配置为在机器模式下处理...
我的机器模式处理程序如何知道在执行之前将 or 等放入,以便可以在捕获陷阱的特权模式下继续执行?PRV_U
PRV_M
mstatus.MPP
mret
提出相同问题的另一种方法是,当从用户/主管/虚拟机管理程序/机器模式到达时,CSR 在到达我的机器模式处理程序时看起来有何不同......?
例如。。。
uintptr_t
exception_handler(uint64_t cause)
{
const uint64_t hartid = read_csr(mhartid);
switch (cause) {
// Do stuff to "claim", "handle", and "clear" each exception "cause"...
// Maybe it's an ecall? Maybe a page-fault? Doesn't matter...
}
clear_csr(mstatus, MSTATUS_MPP);
set_csr(mstatus, (trek_uint64_t)(???? << 11)); // <-- what goes here!?!!
return read_csr(mepc) + 4; // There is an `mret` just after this return.
}
答: 暂无答案
评论
mepc
mepc