← Home

wfi

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).

Assembly format

wfi

Encoding

313029282726252423222120191817161514131211109876543210
00010000010100000000000001110011

Execution

# 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();

Defined by

Sm

Access

SUVSVU
SometimesSometimesSometimesSometimes

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.