wfi in u-mode when u+s configuration

36 views
Skip to first unread message

Muhammed Furqan

unread,
Feb 26, 2024, 4:59:10 AMFeb 26
to RISC-V HW Dev
Hi,

I am a little confused about the behavior of wfi in u+s configuration.

As spec in section 3.1.6.5 stated:
"When S-mode is implemented, then executing WFI in U-mode causes an illegal instruction exception, unless it completes within an implementation-specific, bounded time limit. A future revision of this specification might add a feature that allows S-mode to selectively permit WFI in U-mode. Such a feature would only be active when TW=0."

My understanding is that, (in u+s) wfi is illegal in u-mode when mstatus.TW=0, while if mstatus.TW=1 it will be legal if completes within an implementation-specific bounded time limit else would be illegal.

Am I interpreting it right or is there something I am missing out.
Please let me know.

I have posted an issue about this description also https://github.com/riscv/riscv-isa-manual/issues/1224 (I should have post it here!)

I got response there as well which is below:
"The description of the TW bit (right before your excerpt) says:

When TW=0, the WFI instruction may execute in lower privilege modes when not prevented for some other reason. When TW=1, then if WFI is executed in any less-privileged mode, and it does not complete within an implementation-specific, bounded time limit, the WFI instruction causes an illegal-instruction exception.

Note that the preceding general statement applies to any and all lower privilege modes that are implemented (which may or may not include S-mode).

Your excerpt then specifies an additional behavior specifically for when S-mode is implemented and only when TW=0 - which falls under the earlier "when not prevented for some other reason" clause."

I am still confused about the behavior.

When s-mode is implemented, and WFI is executed in u-mode (s-mode is there), would the bounded time limit will be independent of TW? Because looking at the above response I got, it should wait for bounded time limit even when TW=0, but my understanding is that, when TW=0 wfi is illegal (without wait) in u-mode (hence the future revision), while when TW=1 it will wait for bounded time limit in u-mode (when s-mode is implemented).

Please have a look at it and let me know if my understanding is correct or not.

Thanks
Reply all
Reply to author
Forward
0 new messages