ibex icon indicating copy to clipboard operation
ibex copied to clipboard

Mhartid illegal instruction exception

Open udinator opened this issue 7 years ago • 1 comments

Hi, Just a quick question about the mhartid csr in the Ibex core. The RISC-V Privileged Spec says that mhartid should be a read-only CSR, and I noticed that Ibex will throw an illegal instruction exception if any write to mhartid is encountered. However, with the misa csr, which is hardwired to its reset value, Ibex will just ignore any writes to that address if it encounters any, instead of throwing any exceptions. As a result, I was wondering if this difference in behavior was intended, since both CSRs are intended to be read-only?

udinator avatar Aug 13 '19 16:08 udinator

Hi @udinator , thanks for opening this issue.

Yes, the difference between writing mhartid and misa is intended.

mhartid is a read-only CSR. This can be seen right from looking at bits 11 and 10 of its address (0xF14). 2'b11 means read-only and the spec defines that write accesses to read-only CSRs lead to an illegal instruction exception.

In contrast, the misa CSR is theoretically writable as bits 11 and 10 of its address (0x301) are 2'b00. However, the spec defines this register as WARL (write-any, read-legal). This means the implementation defines the subset of values defined in the spec which the CSR can actually hold. For misa, the write capability would theoretically allow to enable/disable certain ISA extensions at run time. But as Ibex is a fairly simple core, this feature is not supported. Or in other words, the only misa value supported in Ibex is the reset value. Ibex supports enabling/disabling the E and M extensions at design time which impacts the reset value of misa.

Best regards, Pirmin

vogelpi avatar Aug 13 '19 17:08 vogelpi