csrrc/csrrs with mip, sip and uip

Simon Davidmann Imperas

We posted this on https://groups.google.com/a/groups.riscv.org/g/isa-dev/
but had no response in 2 weeks - so maybe this is a better place:
Looking forward to a response.

The Privileged Architecture specification describes special behavior for mip.SEIP as follows:
When mip is read with a CSR instruction, the value of the SEIP bit returned in the rd destination register is the logical-OR of the software-writable bit and the interrupt signal from the interrupt controller. However, the value used in the read-modify-write sequence of a CSRRS or CSRRC instruction contains only the software-writable SEIP bit, ignoring the interrupt value from the external interrupt controller.
The SEIP field behavior is designed to allow a higher privilege layer to mimic external interrupts cleanly, without losing any real external interrupts. The behavior of the CSR instructions is slightly modified from regular CSR accesses as a result.
I think this description needs improvement, because the intent is not fully clear for SEIP, or other bits. In particular:
1. What about other set-pending bits that are writable by software? For example, if the N extension is implemented, how do mip.UEIP and sip.UEIP behave?
2. For which bits does any externally-asserted interrupt contribute to the result seen in rd for csrrc or csrrs? For example, would the external value of mip.SEIP contribute to rd in this case, or is just the software-writable bit value seen?
As a general case, imagine that:
1. A system using the N extension is being used;
2. All interrupts are delegated to their lowest possible privilege level using mideleg and sideleg;
3. All interrupts are disabled;
4. Interrupts MEISEIUEIMTISTI and UTI are all asserted externally (so csrr t1, mip returns 0xbb0).
5. No software pending bits are set for these interrupts.
Given the above set up, what value is observed in t1 in each of these cases:
li      t0, 0
csrrc   t1, mip, t0    // t1 = ???
csrrc   t1, sip, t0    // t1 = ???
csrrc   t1, uip, t0    // t1 = ???
(Note that no CSR state is changed by these instructions - only the result in t1 is of interest.)
And given the same set up, which (if any) software-writable bits are set by these instructions:
li      t0, 0
csrrs   t1, mip, t0
csrrs   t1, sip, t0
(In other words, what externally-asserted interrupt signal values are propagated to software-writable bits?)

Join tech-privileged@lists.riscv.org to automatically receive all group messages.