RVG is enabled when IMAFD_Zicsr_Zifencei is also enabled. Change write_misa() to enable IMAFD if G is being written in the CSR.
Likewise, RVG should be disabled if any of IMAFD got disabled during the process. Clear RVG in this case. Signed-off-by: Daniel Henrique Barboza <dbarb...@ventanamicro.com> --- target/riscv/csr.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 839862f1a8..1c0f438dfb 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1381,6 +1381,14 @@ static RISCVException write_misa(CPURISCVState *env, int csrno, val &= RVE; } + if (val & RVG && !(env->misa_ext & RVG)) { + /* + * If the write wants to enable RVG, enable all its + * dependencies as well. + */ + val |= RVI | RVM | RVA | RVF | RVD; + } + /* * This flow is similar to what riscv_cpu_realize() does, * with the difference that we will update env->misa_ext @@ -1396,6 +1404,12 @@ static RISCVException write_misa(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } + if (!(val & RVI && val & RVM && val & RVA && + val & RVF && val & RVD)) { + /* Disable RVG if any of its dependencies were disabled */ + val &= ~RVG; + } + riscv_cpu_commit_cpu_cfg(cpu, val); if (!(val & RVF)) { -- 2.39.2