On Fri, May 15, 2026 at 5:47 AM Daniel Henrique Barboza
<[email protected]> wrote:
>
> By the priv spec the value "3" is marked as 'Reserved' for mstatus.UXL.
> Handle a mstatus.UXL = 3 write by writing the current 'xl' instead.
>
> Fixes: https://gitlab.com/qemu-project/qemu/-/work_items/3367
> Signed-off-by: Daniel Henrique Barboza <[email protected]>

Acked-by: Alistair Francis <[email protected]>

Alistair

> ---
>  target/riscv/csr.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index 74f5f868f0..53bbecb617 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -2041,7 +2041,17 @@ static RISCVException write_mstatus(CPURISCVState 
> *env, int csrno,
>
>      if (xl != MXL_RV32 || env->debugger) {
>          if ((val & MSTATUS64_UXL) != 0) {
> +            uint64_t uxl = val & MSTATUS64_UXL >> 32;
>              mask |= MSTATUS64_UXL;
> +
> +            /*
> +             * uxl = 3 is reserved so write the current xl instead.
> +             * In case xl = MXL_RV128 (3) write MXL_RV64.
> +             */
> +            if (uxl == 3) {
> +                uxl = xl == MXL_RV128 ? MXL_RV64 : xl;
> +                val = deposit64(val, 32, 2, uxl);
> +            }
>          }
>      }
>
> --
> 2.43.0
>
>

Reply via email to