]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
target/riscv/csr.c: fix mstatus.UXL reserved value
authorDaniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Thu, 14 May 2026 19:45:37 +0000 (16:45 -0300)
committerAlistair Francis <alistair.francis@wdc.com>
Mon, 15 Jun 2026 03:10:14 +0000 (13:10 +1000)
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 <daniel.barboza@oss.qualcomm.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20260514194537.2416243-3-daniel.barboza@oss.qualcomm.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
target/riscv/csr.c

index 83ca354bf002f78d34c4583594cd4e58b84454f3..d004a4bfb4986a6fd50df158cc4d2691ca1e583b 100644 (file)
@@ -2045,7 +2045,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);
+            }
         }
     }