Wait for interrupt
Can causes the processor to enter a low-power state until the next interrupt occurs.
The behavior of `wfi` is affected by the `mstatus.TW` and `hstatus.VTW` bits, as summarized below.
.2+| [.rotate]#`mstatus.TW`# .2+| [.rotate]#`hstatus.VTW`# 4+^.>| `wfi` behavior h| HS-mode h| U-mode h| VS-mode h| in VU-mode
0 — 0 — Wait — Trap (I) — Wait — Trap (V) 0 — 1 — Wait — Trap (I) — Trap (V) — Trap (V) 1 — Trap (I) — Trap (I) — Trap (I) — Trap (I)
6+| Trap (I) - Trap with `Illegal Instruction` code + Trap (V) - Trap with `Virtual Instruction` code
The `wfi` instruction is also affected by `mstatus.TW`, as shown below:
.2+| [.rotate]#`mstatus.TW`# 2+^.>| `wfi` behavior h| S-mode h| U-mode
0 — Wait — Trap (I) 1 — Trap (I) — Trap (I)
3+| Trap (I) - Trap with `Illegal Instruction` code
When `wfi` is marked as causing a trap above, the implementation is allowed to wait for an unspecified period of time to see if an interrupt occurs before raising the trap. That period of time can be zero (_i.e._, `wfi` always causes a trap in the cases identified above).
wfi
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 000 | 1 | 00000 | 1 | 0 | 1 | 0000000000000 | 111 | 00 | 11 | ||||||||||||||||||||||
# first, perform all the access checks
if (mode() == PrivilegeMode::U && !WFI_U_MODE) {
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}
if ((CSR[misa].S == 1) && (CSR[mstatus].TW == 1'b1)) {
if (mode() != PrivilegeMode::M) {
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}
}
if (CSR[misa].H == 1) {
if (CSR[hstatus].VTW == 1'b0) {
if (mode() == PrivilegeMode::VU) {
raise (ExceptionCode::VirtualInstruction, mode(), $encoding);
}
} else if (CSR[hstatus].VTW == 1'b1) {
if ((mode() == PrivilegeMode::VS) || (mode() == PrivilegeMode::VU)) {
raise (ExceptionCode::VirtualInstruction, mode(), $encoding);
}
}
}
# passed, so now do the wait
wfi();
Sm
| S | U | VS | VU |
|---|---|---|---|
| Sometimes | Sometimes | Sometimes | Sometimes |
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.