CSR 位字段

RISC-V vstopei CSR 寄存器详解

地址 0x25C特权级 Hypervisor 直接访问 / VS 别名访问访问 HRW(Hypervisor 读写) / VSXLENHypervisor 与虚拟化 CSR

vstopei 是 VS 顶层外部中断 claim CSR。

字段映射

按 bit 字段理解 vstopei

1 个关键字段
VSXLEN-1:0

VSTOPEI

读取 / claim

读出格式为 bits 26:16 interrupt identity、bits 10:0 interrupt priority(与 identity 相同),其它位为 0;读 0 表示没有满足 pending、enabled 和 threshold 条件的外部中断。

这个字段控制什么

  • - 读出格式为 bits 26:16 interrupt identity、bits 10:0 interrupt priority(与 identity 相同),其它位为 0;读 0 表示没有满足 pending、enabled 和 threshold 条件的外部中断。

常见取值

0无可 claim 中断

guest interrupt file 中没有 pending 且 enabled 的外部中断,或 eithreshold 非零且没有中断 identity 小于 threshold。

bits 26:16 / 10:0interrupt identity / priority

bits 26:16 给出外部中断 minor identity;bits 10:0 给出相同数值作为 priority。写入 vstopei 会忽略写入值,并按当前可读值 claim 对应 pending 位。

打开官方手册
官方依据与检索要点

vstopei 是 AIA 的 VS top external interrupt CSR。它只在有 IMSIC guest interrupt file 且 hstatus.VGEIN 选择有效 guest file 时与该文件交互;读值给出最高优先级 pending-and-enabled 外部中断,写入用于 claim 当前读值。

vstopei 的地址、访问类和宽度按官方 CSR 表核对:0x25C,HRW(Hypervisor 读写),VSXLEN。
AIA 定义 vstopei 只在有 IMSIC 时存在;若 hstatus.VGEIN 不是有效 guest interrupt file,M/HS 访问 vstopei 或 VS 通过 stopei 访问会分别触发官方规定的异常。
读值格式为 bits 26:16 interrupt identity、bits 10:0 priority(同 identity),其它位为 0;该值不受 eidelivery、mie、sie、hie、hgeie 或 vsie 影响。
写入时写入值被忽略,当前可读值决定清除哪个 pending bit;读值为 0 时写入无效果。
mstateen0.IMSIC 和 hstateen0.IMSIC 可限制较低特权级或 VM 访问 IMSIC guest interrupt file 状态。

读这个 CSR 时先看什么

  • - vstopei 的独立 CSR 地址按 AIA 表属于 HRW,宽度 VSXLEN,并且只在有 IMSIC 时作为 top external interrupt CSR 存在。
  • - 只有当 H 扩展实现且 hstatus.VGEIN 是已实现 guest interrupt file 的编号时,vstopei 才与该 guest interrupt file 交互;否则 M/HS 访问独立 CSR 会触发 illegal-instruction exception,VS 通过 stopei 访问会触发 virtual-instruction exception。
  • - vstopei 的读值不受 eidelivery、mie、sie、hie、hgeie 或 vsie 影响;它依据 guest interrupt file 的 eip/eie 和 eithreshold 计算。

写入前的风险检查

  • - 写 vstopei 会 claim 当前可读值指定的 interrupt identity,写入数据本身被忽略;若读值为 0,写入无效果。

放回真实流程里理解

1

确认实现 AIA、IMSIC 和 H 扩展,并确认 hstatus.VGEIN 选择了已实现 guest interrupt file。

2

读取返回 0 表示没有 pending-and-enabled 的外部中断,或 eithreshold 非零且没有 identity 小于该阈值的此类中断;非零值的 bits 26:16 和 bits 10:0 分别给出 identity 和相同 priority。

3

用单条 CSR 读写指令同时读取并 claim,可避免分离读写期间更高优先级中断到来导致 claim 错误。

常见问题

vstopei 属于哪一类 AIA 状态?

vstopei 是 IMSIC guest interrupt file 的 top external interrupt CSR,用于报告并 claim VS-level 外部中断的 minor identity。

vstopei 的访问受 state-enable 控制吗?

是。vstopei 属于 IMSIC 状态;在实现 Smstateen/Ssstateen 和 AIA 时,mstateen0.IMSIC 与 hstateen0.IMSIC 可限制较低特权级或 VM 对该状态的访问。