target/riscv: do not write RVG in misa CSR [GL4811]
Subsystems (2)
v2 cover target/riscv: do not write RVG in misa CSR [GL4811]
Hi,
In this version we removed the change in the RVG description, as suggested by Alistair. Sashiko also wanted a "Fixes" trailer in the commit msg so I added one.
No other changes made.
Changes in v2:
- do not change RVG description;
- add a "Fixes" tag.
- v1 link: https://lore.kernel.org/qemu-devel/[email protected]/
Daniel Henrique Barboza (1):
target/riscv: do not write RVG in misa CSR [GL4811]
target/riscv/tcg/csr.c | 17 ++++++++++ tests/tcg/riscv64/system/meson.build | 7 ++++ tests/tcg/riscv64/test-misa-G.S | 51 ++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 tests/tcg/riscv64/test-misa-G.S
Signature · 1 line
2.43.0
PATCH v2 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. The "Fixes" commit refers to the very first usage of RVG being written in MISA.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4811
--- target/riscv/tcg/csr.c | 17 ++++++++++ tests/tcg/riscv64/system/meson.build | 7 ++++ tests/tcg/riscv64/test-misa-G.S | 51 ++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 tests/tcg/riscv64/test-misa-G.S
target/riscv/tcg/csr.c +17 -0
@@ -2215,6 +2215,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 ; }
@@ -2243,6 +2252,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
@@ -116,6 +116,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 24 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.
The "Fixes" commit refers to the very first usage of RVG being written
in MISA.
Quoted 5 lines
Fixes 4f13abcb2bcb ("target/riscv: add RVG and remove cpu-Quoted 1 line
cfg.ext_g")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4811
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 123 lines
---
target/riscv/tcg/csr.c | 17 ++++++++++ tests/tcg/riscv64/system/meson.build | 7 ++++ tests/tcg/riscv64/test-misa-G.S | 51
++++++++++++++++++++++++++++3 files changed, 75 insertions(+)create mode 100644
tests/tcg/riscv64/test-misa-G.Starget/riscv/tcg/csr.c +0
-0@@ -2215,6 +2215,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@@ -2243,6 +2252,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 forIMAFD_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 +0
-0@@ -116,6 +116,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