Csr访问

在测试counter的时候,对0x320进行读取访问会报 Instruction access fault,当前mstatus为0x8000000a00007800

具体的操作方法?

可能是我的mode有问题,具体是在opensbi init后用csr_read去读取0x320

You must be in machine mode per The RISC-V Instruction Set Manual, Volume II: Privileged Architecture | Five EmbedDev Mstatus >= 0x1800 should work. Perhaps a sret or mret changed it behind your back?

(Sorry. Only English. Google Translate is amazing.)

根据 The RISC-V Instruction Set Manual, Volume II: Privileged Architecture | Five EmbedDev Mstatus >= 0x1800,您必须处于机器模式。 也许是一个 sret 或 mret 在你背后改变了它?

I try read in ecall handler, but it’s fail

csr_read(CSR_MCOUNTINHIBIT);
system_opcode_insn: Failed to access CSR 0x320 from M-mode

current mode is M-mode,and I try enable the mcounteren and mcounteren,it not work

标准里写的是

If the mcountinhibit register is not implemented, the implementation behaves as though the register were set to zero.

好像 mcountinhibit 就是没有实现

Maybe you are right,I try all others csr is work

Supplementary instruction:U74 priv version is privileged specification v1.10, so in opensbi code they skip the CSR Reg.So this topic can be closed