@samitouri / QOSamiQemu / commits / dcd0285177

target/riscv: Apply UXL WARL handling to vsstatus

write_mstatus() already handles the reserved UXL value by writing a legal value instead. Apply the same handling when writing vsstatus so that reserved UXL values follow the same WARL behavior. Factor the common logic into a local helper riscv_write_uxl() and use it for both mstatus and vsstatus. Suggested-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com> Fixes: f310df58bd2 ("target/riscv: Enable uxl field write") Signed-off-by: SeungJu Cheon <suunj1331@gmail.com> Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com> Message-ID: <20260625081521.595683-1-suunj1331@gmail.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

SeungJu Cheon committed Jun 25, 2026 at 17:15 UTC dcd028517749835a618bb1fe8dca32d82318e1c1
1 file changed +17 -10
target/riscv/csr.c
+17 -10
@@ -2021,6 +2021,20 @@ static target_ulong legalize_mpp(CPURISCVState *env, target_ulong old_mpp,
2021 return val;
2022 }
2023
2024 +static uint64_t riscv_write_uxl(CPURISCVState *env, uint64_t val,
2025 + uint64_t field)
2026 +{
2027 + RISCVMXL xl = riscv_cpu_mxl(env);
2028 + uint64_t uxl = get_field(val, field);
2029 +
2030 + if (uxl == MXL_RV128) {
2031 + uxl = xl == MXL_RV128 ? MXL_RV64 : xl;
2032 + val = set_field(val, field, uxl);
2033 + }
2034 +
2035 + return val;
2036 +}
2037 +
2038 static RISCVException write_mstatus(CPURISCVState *env, int csrno,
2039 target_ulong val, uintptr_t ra)
2040 {
@@ -2067,17 +2081,8 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
2081
2082 if (xl != MXL_RV32 || env->debugger) {
2083 if ((val & MSTATUS64_UXL) != 0) {
2070 - uint64_t uxl = val & MSTATUS64_UXL >> 32;
2084 mask |= MSTATUS64_UXL;
2072 -
2073 - /*
2074 - * uxl = 3 is reserved so write the current xl instead.
2075 - * In case xl = MXL_RV128 (3) write MXL_RV64.
2076 - */
2077 - if (uxl == 3) {
2078 - uxl = xl == MXL_RV128 ? MXL_RV64 : xl;
2079 - val = deposit64(val, 32, 2, uxl);
2080 - }
2085 + val = riscv_write_uxl(env, val, MSTATUS64_UXL);
2086 }
2087 }
2088
@@ -5239,6 +5244,8 @@ static RISCVException write_vsstatus(CPURISCVState *env, int csrno,
5244 uint64_t mask = (target_ulong)-1;
5245 if ((val & VSSTATUS64_UXL) == 0) {
5246 mask &= ~VSSTATUS64_UXL;
5247 + } else {
5248 + val = riscv_write_uxl(env, val, VSSTATUS64_UXL);
5249 }
5250 if ((env->henvcfg & HENVCFG_DTE)) {
5251 if ((val & SSTATUS_SDT) != 0) {