wfi
Wait for interrupt
This instruction is defined by:
-
Sm, version >= 0
This instruction is included in the following profiles:
Synopsis
Can causes the processor to enter a low-power state until the next interrupt occurs.
<%- if ext?(:H) -%> The behavior of wfi is affected by the mstatus.TW and hstatus.VTW bits, as summarized below.
wfi behavior |
|||||
HS-mode |
U-mode |
VS-mode |
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) |
Trap (I) - Trap with |
<%- else -%> The wfi instruction is also affected by mstatus.TW, as shown below:
wfi behavior |
||
S-mode |
U-mode |
|
---|---|---|
0 |
Wait |
Trap (I) |
1 |
Trap (I) |
Trap (I) |
Trap (I) - Trap with |
<%- end -%>
Access
M | HS | U | VS | VU |
---|---|---|---|---|
Always |
Sometimes |
Sometimes |
Sometimes |
Sometimes |
<%- if ext?(:H) -%> The behavior of wfi is affected by the mstatus.TW and hstatus.VTW bits, as summarized below.
wfi behavior |
|||||
HS-mode |
U-mode |
VS-mode |
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) |
Trap (I) - Trap with |
<%- else -%> The wfi instruction is also affected by mstatus.TW, as shown below:
wfi behavior |
||
S-mode |
U-mode |
|
---|---|---|
0 |
Wait |
Trap (I) |
1 |
Trap (I) |
Trap (I) |
Trap (I) - Trap with |
<%- end -%>
Execution
-
IDL
-
Sail
if (mode() == PrivilegeMode::U) {
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);
}
}
}
wfi();
match cur_privilege {
Machine => { platform_wfi(); RETIRE_SUCCESS },
Supervisor => if mstatus.TW() == 0b1
then { handle_illegal(); RETIRE_FAIL }
else { platform_wfi(); RETIRE_SUCCESS },
User => { handle_illegal(); RETIRE_FAIL }
}