target/riscv: do not write RVG in misa CSR [GL4811]
Subsystems (2)
PATCH 1/1 target/riscv: do not write RVG in misa CSR [GL4811]
It seems like we can't write RVG into misa. The bit has been marked as "Reserved" for priv specs 1.11+, i.e. it does not represent the extension pack "IMAFD_Zicsr_Zifencei". The official explanation, at least from what I could find, is that setting RVG is redundant with reading riscv,isa and/or other extension discovery mechanisms.
To make matters more interesting, 'g' is still supposed to be present in riscv,isa. Toolchains will keep using 'g' in their 'march' normally too. So aside from sparing one bit in the MISA every other use of RVG is still valid.
We have a good chunk of code that uses RVG as a synonym for that extension pack and, for now, I don't see a reason to refactor it. We will cross that bridge when/if RVG acquires another official use.
For now, if we're running priv spec 1.11+, filter the bit out of misa. Update the bit description in misa_ext_info_arr too for clarity.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4811
--- target/riscv/cpu.c | 7 +++- target/riscv/tcg/csr.c | 17 ++++++++++ tests/tcg/riscv64/system/meson.build | 7 ++++ tests/tcg/riscv64/test-misa-G.S | 51 ++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/riscv64/test-misa-G.S
target/riscv/cpu.c +6 -1
@@ -1620,7 +1620,12 @@ static const MISAExtInfo misa_ext_info_arr[] = {MISA_EXT_INFO (RVU ,"u" ,"User-level instructions" ),MISA_EXT_INFO (RVH ,"h" ,"Hypervisor" ),MISA_EXT_INFO (RVV ,"v" ,"Vector operations" ), -MISA_EXT_INFO (RVG ,"g" ,"General purpose (IMAFD_Zicsr_Zifencei)" ), +/* +* As of priv versions 1.11+ the spec marks RVG as Reserved. +* Internally we'll keep using it as a shortcut for +* IMAFD_Zicsr_Zifencei. +*/ +MISA_EXT_INFO (RVG ,"g" ,"Reserved" ), MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)") };
target/riscv/tcg/csr.c +17 -0
@@ -2200,6 +2200,15 @@ static RISCVException read_misa(CPURISCVState *env, int csrno, } *val = misa | env->misa_ext; + +/* +* RVG is reserved for priv > 1.10 but we're setting the +* bit internally as a shortcut for IMAFD_Zicsr_Zifencei. +*/ +if (env->priv_ver >PRIV_VERSION_1_10_0 ) { + *val &= ~RVG ; + } +return RISCV_EXCP_NONE ; }
@@ -2228,6 +2237,14 @@ static RISCVException write_misa(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } +/* +* RVG is reserved for priv > 1.10 but we're setting the +* bit internally as a shortcut for IMAFD_Zicsr_Zifencei. +*/ +if (env->priv_ver >PRIV_VERSION_1_10_0 ) { + val &= ~RVG ; + } +/* Mask extensions that are not supported by this hart */ val &= env->misa_ext_mask;
tests/tcg/riscv64/system/meson.build +7 -0
@@ -89,6 +89,13 @@ tests += { } } +tests += { + 'test-misa-G.S': { + 'cflags': cflags, + 'qemu_args': ['-cpu', 'max', qemu_args], + } +} + if 'qemu-system-riscv64' in emulators tcg_tests += { 'riscv64-softmmu': {
tests/tcg/riscv64/test-misa-G.S new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 41 lines · Daniel Henrique Barboza
It seems like we can't write RVG into misa. The bit has been marked as
"Reserved" for priv specs 1.11+, i.e. it does not represent the extension pack "IMAFD_Zicsr_Zifencei". The official explanation, at least from what I could find, is that setting RVG is redundant with reading riscv,isa and/or other extension discovery mechanisms.To make matters more interesting, 'g' is still supposed to be present in
riscv,isa. Toolchains will keep using 'g' in their 'march' normally too. So aside from sparing one bit in the MISA every other use of RVG
is still valid.We have a good chunk of code that uses RVG as a synonym for that extension pack and, for now, I don't see a reason to refactor it. We will cross that bridge when/if RVG acquires another official use.
For now, if we're running priv spec 1.11+, filter the bit out of misa.
Update the bit description inmisa_ext_info_arrtoo for clarity.Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4811
Signed-off-by: Daniel Henrique Barboza <[email protected]>
---
target/riscv/cpu.c | 7 +++- target/riscv/tcg/csr.c | 17 ++++++++++ tests/tcg/riscv64/system/meson.build | 7 ++++ tests/tcg/riscv64/test-misa-G.S | 51
++++++++++++++++++++++++++++4 files changed, 81 insertions(+), 1 deletion(-)create mode 100644
tests/tcg/riscv64/test-misa-G.Starget/riscv/cpu.c +0
-0@@ -1620,7 +1620,12 @@ static const MISAExtInfo misa_ext_info_arr[] = { MISA_EXT_INFO(RVU, "u", "User-level instructions"),
target/riscv/cpu.c static const MISAExtInfo misa_ext_info_arr[] = · line 1630
Quoted 10 lines
target/riscv/cpu.c +6
-1MISA_EXT_INFO(RVH, "h", "Hypervisor"), MISA_EXT_INFO(RVV, "v", "Vector operations"), - MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"), + /* + * As of priv versions 1.11+ the spec marks RVG as Reserved. + * Internally we'll keep using it as a shortcut for + * IMAFD_Zicsr_Zifencei. + */ + MISA_EXT_INFO(RVG, "g", "Reserved"),
I don't think this is correct. G is still "IMAFD_Zicsr_Zifencei", check "Table 67. Standard ISA extension names." for example.
It just isn't set via MISA, which I guess makes sense, as what does turning G on/off mean...
Quoted 29 lines
target/riscv/cpu.c +0
-0MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)")};
target/riscv/tcg/csr.c +0
-0@@ -2200,6 +2200,15 @@ static RISCVException read_misa(CPURISCVState *env, int csrno, }
*val = misa |env->misa_ext;target/riscv/tcg/csr.c +9
-0+ + /* + * RVG is reserved for priv > 1.10 but we're setting the + * bit internally as a shortcut for IMAFD_Zicsr_Zifencei. + */ + if (env->priv_ver > PRIV_VERSION_1_10_0) { + *val &= ~RVG; + } +return
RISCV_EXCP_NONE;
}target/riscv/tcg/csr.c +0
-0@@ -2228,6 +2237,14 @@ static RISCVException write_misa(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; }
Quoted 8 lines
+ /*
+ * RVG is reserved for priv > 1.10 but we're setting the + * bit internally as a shortcut forIMAFD_Zicsr_Zifencei. + */
+ if (env->priv_ver>PRIV_VERSION_1_10_0) {
+ val &= ~RVG;
+ }
+
These looks good, we just shouldn't change the MISA_EXT_INFO name
Alistair
Quoted 81 lines
/* Mask extensions that are not supported by this hart */ val &=
env->misa_ext_mask;tests/tcg/riscv64/system/meson.build +0
-0@@ -89,6 +89,13 @@ tests += { } }tests/tcg/riscv64/system/meson.build +7
-0+tests += { + 'test-misa-G.S': { + 'cflags': cflags, + 'qemu_args': ['-cpu', 'max', qemu_args], + } +} +if 'qemu-system-riscv64' in emulators
tcg_tests+= {
'riscv64-softmmu': {tests/tcg/riscv64/test-misa-G.S new file +4
-0@@ -0,0 +1,51 @@ +/* + * Test if RVG is being set in misa. See Gitlab 4811 for more info. + * + * Copyright (c) Qualcomm Technologies, Inc. and/or itssubsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */tests/tcg/riscv64/test-misa-G.S new file +45
-0+ +.option norvc + .text + .global _start + +_start: + lla t0, trap + csrw mtvec, t0 + + csrr t0, misa + li t1, 1 + slli t1, t1, 6 + and t1, t1, t0 + bnez t1, _fail + + li a0, 0 + j _exit + +_fail: + li a0, 1 + j _exit + +trap: + # Any trap is a fail code 1 + li a0, 1 + +# Exit code in a0 +_exit: + lla a1, semiargs + li t0, 0x20026 # ADP_Stopped_ApplicationExit + sd t0, 0(a1) + sd a0, 8(a1) + li a0, 0x20 # TARGET_SYS_EXIT_EXTENDED + + # Semihosting call sequence +.balign 16 + slli zero, zero, 0x1f + ebreak + srai zero, zero, 0x7 + j . + + .data + .balign 16 +semiargs: + .space 16