CSR 位字段

RISC-V stopei CSR 寄存器详解

地址 0x15C特权级 Supervisor 模式访问 读写 / XLENSupervisor AIA、定时器与间接中断 CSR

stopei(0x15C)是 AIA/IMSIC 的 Supervisor top external interrupt CSR,报告并可声明 supervisor interrupt file 中最高优先级的 pending-and-enabled 外部中断。

位作用速览
bit 3 = 只有第 3 位;bits 12..11 = 第 12 到第 11 位
高位 MSB低位 LSB
字段映射

按 bit 字段理解 stopei

3 个关键字段
26:16

IID

只读/写入声明

读取时给出当前最高优先级 pending-and-enabled 外部中断 identity;写 stopei 会按当前可读值清除对应 pending 位。

这个字段控制什么

  • - 读取时给出当前最高优先级 pending-and-enabled 外部中断 identity;写 stopei 会按当前可读值清除对应 pending 位。

常见取值

这个字段更适合结合上下文字段解释,不用按固定枚举背诵。

打开官方手册
10:0

IPRIO

只读

读取值中的 interrupt priority,AIA/IMSIC 中与 identity 相同。

这个字段控制什么

  • - 读取值中的 interrupt priority,AIA/IMSIC 中与 identity 相同。

常见取值

这个字段更适合结合上下文字段解释,不用按固定枚举背诵。

打开官方手册
XLEN-1:27,15:11

ReservedZero

只读 0

其他位读为 0。

这个字段控制什么

  • - 其他位读为 0。

常见取值

stopei reserved-zero bits
0只读零

这些位按 AIA/IMSIC `stopei` 格式读为 0;软件不应写入或依赖 1 的含义。

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

stopei 是 IMSIC supervisor interrupt file 的 top-external-interrupt 视图。它的读值由 pending、enable 和 eithreshold 决定;写入声明当前读值对应的中断。

读取返回 0 表示没有 pending-and-enabled 且超过 threshold 的外部中断。
返回值 bits 26:16 是 interrupt identity,bits 10:0 是 priority。
官方 AIA 明确警告不要分离读和写声明,除非通过 eip array 精确清除 pending 位。

读这个 CSR 时先看什么

  • - 先确认当前 hart 实现 stopei 所属扩展;未实现或权限不足的 CSR 访问会触发非法指令异常。
  • - 结合地址 0x15C、最低访问特权级和官方访问类判断软件是否可以直接访问。
  • - 读取保留、WPRI、WARL 或 WLRL 字段时不要假设固定值,应按官方规范和实现返回值解释。

写入前的风险检查

  • - 通常应使用同时读写的 CSR 指令声明 stopei;先读后写可能清除两条指令之间新出现的更高优先级中断。
  • - 当 stopei 当前值为 0 时写入无效果。

放回真实流程里理解

1

在 supervisor external interrupt handler 中读取 stopei 得到 top interrupt identity。

2

用同一 CSR read/write 操作声明该中断;返回值右移 16 得到 minor identity。

3

调用对应外部中断服务例程;若需要分步声明,应通过 siselect/sireg 清除 eip pending 位。

常见问题

stopei 受 sie.SEIE 影响吗?

stopei 的可读 top 值不受 sie/hie/vsie 等 enable CSR 影响;这些寄存器影响中断投递,而 stopei 反映 interrupt file 内部 pending-and-enabled 状态。

写 stopei 的写入值有意义吗?

写入值被忽略;清除哪个 pending 位由写入时 stopei 当前可读值决定。