简体   繁体   English

RISC-V - 软件中断

[英]RISC-V - Software Interrupts

I'm trying to implement a simple interrupt controller for my RV32I core.我正在尝试为我的 RV32I 内核实现一个简单的中断控制器。 I believe I understand how an interrupt should be handled in RISC-V, and the role of the CSR registers in the process.我相信我理解在 RISC-V 中应该如何处理中断,以及 CSR 寄存器在这个过程中的作用。

RISC-V defines three sources of interrupts: External, Software and Timer. RISC-V 定义了三种中断源:外部、软件和定时器。 I understand how a timer and an external interrupt would generate.我了解定时器和外部中断是如何产生的。 However, I do not understand how or what would generate a software interrupt.但是,我不明白如何或什么会产生软件中断。 An instruction?指令? A sequence of instructions?指令序列? Maybe implementation defined flags?也许实现定义的标志? I have no idea.我不知道。

Could anyone give an example and the explanation of a software interrupt, preferably with the associated assembly code if it is relevant?任何人都可以举一个例子和软件中断的解释,最好是相关的汇编代码吗?

Thanks in advance!提前致谢!

What you are looking for are SSIP and USIP bits from the mip csr.您正在寻找的是来自 mip csr 的 SSIP 和 USIP 位。

A supervisor-level software interrupt is triggered on the current hart by writing 1 to its supervisor software interrupt-pending (SSIP) bit in the sip register.通过将 1 写入 sip 寄存器中的主管软件中断挂起 (SSIP) 位,在当前 hart 上触发主管级软件中断。 A pending supervisor-level software interrupt can be cleared by writing 0 to the SSIP bit in sip.可以通过向 sip 中的 SSIP 位写入 0 来清除挂起的管理员级软件中断。 Supervisor-level software interrupts are disabled when the SSIE bit in the sie register is clear.当 sie 寄存器中的 SSIE 位清零时,禁止管理员级软件中断。

A user-level software interrupt is triggered on the current hart by writing 1 to its user software interrupt-pending (USIP) bit in the sip register.通过向 sip 寄存器中的用户软件中断挂起 (USIP) 位写入 1,在当前 hart 上触发用户级软件中断。 A pending user-level software interrupt can be cleared by writing 0 to the USIP bit in sip.挂起的用户级软件中断可以通过将 0 写入 sip 中的 USIP 位来清除。 User-level software interrupts are disabled when the USIE bit in the sie register is clear.当 sie 寄存器中的 USIE 位被清除时,用户级软件中断被禁用。

You can find this information in The RISC-V Instruction Set Manual Volume II: Privileged Architecture V20190608.您可以在The RISC-V Instruction Set Manual Volume II: Privileged Architecture V20190608 中找到此信息。

Software interrupts are caused by (user) program execution.软件中断是由(用户)程序执行引起的。

Software interrupts can occur from ecall — the equivalent of syscall on MIPS;软件中断可以从ecall发生——相当于 MIPS 上的syscall this is a request of a user program for operating system services and it crosses privilege boundaries in a well-controlled manner.这是用户程序对操作系统服务的请求,它以良好控制的方式跨越权限边界。

Software interrupts can also occur from memory operations that are illegal or malformed, ie lw , sw .软件中断也可能因非法或格式错误的内存操作(即lwsw

Look at the list of exceptions on Tables 3.6, 4.1 (here I'm only showing the 2nd half; note that ecall appears in the first half):查看表 3.6、4.1 中的异常列表(这里我只展示了第二部分;注意 ecall 出现在第一部分):

  • 0 Instruction address misaligned 0 指令地址未对齐
  • 1 Instruction access fault 1 指令访问错误
  • 2 Illegal instruction 2 非法指令
  • 3 Breakpoint 3 断点
  • 4 Reserved 4 保留
  • 5 Load access fault 5 负载访问故障
  • 6 AMO address misaligned 6 AMO 地址未对齐
  • 7 Store/AMO access fault 7 Store/AMO 访问故障
  • 8-11 Environment 8-11 环境

The first is caused by placing bad value (eg odd) in the program counter, which might be caused by a jump register or return whose stack was corrupted.第一个是由在程序计数器中放置错误值(例如奇数)引起的,这可能是由堆栈损坏的跳转寄存器或返回引起的。

The next by allowing the program counter to refer to an unmapped address, ie a page not marked executable.接下来允许程序计数器引用未映射的地址,即未标记为可执行的页面。

Breakpoint is used by software during debugging, usually.断点通常在调试期间由软件使用。

Load access fault refers to using load or store to an unmapped or otherwise protected address.加载访问错误是指使用加载或存储到未映射或以其他方式受保护的地址。

The atomic operations are given their own exception numbers (not sure why).原子操作有自己的异常编号(不知道为什么)。

And lastly, they can be caused by switching between privilege modes (U,S,H,M)最后,它们可能是由特权模式(U、S、H、M)之间的切换引起的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM