Skip to content

Commit

Permalink
target/riscv: FIX xATP_MODE validation
Browse files Browse the repository at this point in the history
The SATP register is an SXLEN-bit read/write WARL register. It means that CSR fields are only defined
for a subset of bit encodings, but allow any value to be written while guaranteeing to return a legal
value whenever read (See riscv-privileged-20211203, SATP CSR).

For example on rv64 we are trying to write to SATP CSR val = 0x1000000000000000 (SATP_MODE = 1 - Reserved for standard use)
and after that we are trying to read SATP_CSR. We read from the SATP CSR value = 0x1000000000000000, which is not a correct
operation (return illegal value).

Signed-off-by: Irina Ryapolova <irina.ryapolova@syntacore.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20240109145923.37893-1-irina.ryapolova@syntacore.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
  • Loading branch information
ir-sc authored and alistair23 committed Mar 8, 2024
1 parent adb4975 commit 57020a4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions target/riscv/csr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1295,8 +1295,8 @@ static RISCVException read_mstatus(CPURISCVState *env, int csrno,

static bool validate_vm(CPURISCVState *env, target_ulong vm)
{
return (vm & 0xf) <=
satp_mode_max_from_map(riscv_cpu_cfg(env)->satp_mode.map);
uint64_t mode_supported = riscv_cpu_cfg(env)->satp_mode.map;
return get_field(mode_supported, (1 << vm));
}

static target_ulong legalize_mpp(CPURISCVState *env, target_ulong old_mpp,
Expand Down

0 comments on commit 57020a4

Please sign in to comment.