Machine Interrupt Delegation
Controls exception delegation from M-mode to HS/S-mode
By default, all traps at any privilege level are handled in machine mode, though a machine-mode handler can redirect traps back to the appropriate level with the `MRET` instruction. To increase performance, implementations can provide individual read/write bits within `mideleg` to indicate that certain exceptions and interrupts should be processed directly by a lower privilege level.
In harts with S-mode, the `mideleg` register must exist, and setting a bit `mideleg` will delegate the corresponding trap, when occurring in S-mode or U-mode, to the S-mode trap handler
(which could further be delegated to VS-mode through hideleg)
.
In harts without S-mode, the `mideleg` register should not exist.
Note: In versions 1.9.1 and earlier , this register existed but was hardwired to zero in M-mode only, or M/U without N harts. There is no reason to require they return zero in those cases, as the `misa` register indicates whether they exist.
In harts without S-mode, the `mideleg` register is read-only zero.
An implementation can choose to subset the delegatable traps, with the supported delegatable bits found by writing one to every bit location, then reading back the value in `mideleg` to see which bit positions hold a one.
Note: Version 1.11 and earlier prohibited having any bits of `mideleg` be read-only one. Platform standards may always add such restrictions.
Traps never transition from a more-privileged mode to a less-privileged mode. For example, if M-mode has delegated illegal-instruction exceptions to S-mode, and M-mode software later executes an illegal instruction, the trap is taken in M-mode, rather than being delegated to S-mode. By contrast, traps may be taken horizontally. Using the same example, if M-mode has delegated illegal-instruction exceptions to S-mode, and S-mode software later executes an illegal instruction, the trap is taken in S-mode.
Delegated interrupts result in the interrupt being masked at the delegator privilege level. For example, if the supervisor timer interrupt (STI) is delegated to S-mode by setting `mideleg`[5], STIs will not be taken when executing in M-mode. By contrast, if `mideleg`[5] is clear, STIs can be taken in any mode and regardless of current mode will transfer control to M-mode.
`mideleg` holds trap delegation bits for individual interrupts, with the layout of bits matching those in the `mip` register (i.e., STIP interrupt delegation control is located in bit 5).
For exceptions that cannot occur in less privileged modes, the corresponding `medeleg` bits should be read-only zero. In particular, `medeleg`[11] is read-only zero.
The `medeleg`[16] is read-only zero as double trap is not delegatable.
| 31:24 | 23:16 | 15:8 | 7:0 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| — | LCOFI | SGEI | MEI | VSEI | SEI | — | MTI | VSTI | STI | — | MSI | VSSI | SSI | — | |||||||||||||||||
| 63:56 | 55:48 | 47:40 | 39:32 | 31:24 | 23:16 | 15:8 | 7:0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| — | LCOFI | SGEI | MEI | VSEI | SEI | — | MTI | VSTI | STI | — | MSI | VSSI | SSI | — | |||||||||||||||||||||||||||||||||||||||||||||||||
| Bits | Field | Alias | Description | Type | Reset |
|---|---|---|---|---|---|
| [1] | SSI | *Supervisor Software Interrupt delegation* When 1, Supervisor Software interrupts are delegated to HS/S-mode. | return MIDELEG_DELEGATABLE[1] ? CsrFieldType::RW : CsrFieldType::RO; | 0 | |
| [2] | VSSI | *Virtual Supervisor Software Interrupt delegation* When 1, Virtual Supervisor Software interrupts are delegated to HS-mode. Virtual Supervisor Software Interrupts are always delegated to HS-mode, so this field is read-only one. | RO | 1 | |
| [3] | MSI | *Machine Software interrupt delegation* When 1, Machine Software interrupts are delegated to HS/S-mode. This is unusual but permitted. See https://github.com/riscv/riscv-isa-manual/issues/3162. | return MIDELEG_DELEGATABLE[3] ? CsrFieldType::RW : CsrFieldType::RO; | 0 | |
| [5] | STI | *Supervisor Timer interrupt delegation* When 1, Supervisor Timer interrupts are delegated to HS/S-mode. | return MIDELEG_DELEGATABLE[5] ? CsrFieldType::RW : CsrFieldType::RO; | 0 | |
| [6] | VSTI | *Virtual Supervisor Timer interrupt delegation* When 1, Virtual Supervisor Timer interrupts are delegated to HS-mode. Virtual Supervisor Time Interrupts are always delegated to HS-mode, so this field is read-only one. | RO | 1 | |
| [7] | MTI | *Machine Timer interrupt delegation* When 1, Machine Timer interrupts are delegated to HS/S-mode. This is unusual but permitted. See https://github.com/riscv/riscv-isa-manual/issues/3162. | return MIDELEG_DELEGATABLE[7] ? CsrFieldType::RW : CsrFieldType::RO; | 0 | |
| [9] | SEI | *Supervisor External interrupt delegation* When 1, Supervisor External interrupts are delegated to HS/S-mode. | return MIDELEG_DELEGATABLE[9] ? CsrFieldType::RW : CsrFieldType::RO; | 0 | |
| [10] | VSEI | *Virtual Supervisor External interrupt delegation* Virtual Supervisor External Interrupts are always delegated to HS-mode, so this field is read-only one. | RO | 1 | |
| [11] | MEI | *Machine External interrupt delegation* When 1, Machine External interrupts are delegated to HS/S-mode. This is unusual but permitted. See https://github.com/riscv/riscv-isa-manual/issues/3162. | return MIDELEG_DELEGATABLE[11] ? CsrFieldType::RW : CsrFieldType::RO; | 0 | |
| [12] | SGEI | *Supervisor Guest External Interrupt delegation* Supervisor Guest External interrupts are always delegated to HS-mode when any guest external interrupts are implemented (`NUM_EXTERNAL_GUEST_INTERRUPTS` is nonzero), so this field is read-only one; otherwise it is read-only zero. | RO | return MIDELEG_DELEGATABLE[12] ? 1 : 0; | |
| [13] | LCOFI | *Local Counter Overflow Interrupt delegation* When 1, local counter overflow interrupts are delegated to (H)S-mode. | return MIDELEG_DELEGATABLE[13] ? CsrFieldType::RW : CsrFieldType::RO; | 0 |
Version af3eaf9+cheriot.f635218
Data from the RISC-V Unified Database, copyright RISC-V International and contributors.
CHERIoT extensions from the CHERIoT specification and Sail model, copyright Microsoft and the CHERIoT Platform contributors.
This site is provided as a community resource and is NOT affiliated with nor endorsed by RISC-V International.