target/riscv: Do not hide Sstc CSRs from gdbstub
PATCH 1/1 target/riscv: Do not hide Sstc CSRs from gdbstub
The Sstc predicate currently checks both ext_sstc and rdtime_fn. This causes the gdbstub CSR XML generation to skip Sstc CSRs when rdtime_fn has not been initialized yet, even if the CPU supports Sstc.
As a result, GDB reports $stimecmp as void with a CPU that exposes the sstc extension.
Only use ext_sstc for the early existence check, and keep the rdtime_fn check for non-debugger accesses.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
---
Testing:
Start QEMU with:
qemu-system-riscv64 -M virt,aclint=on -cpu max,sstc=true -s -S -nographic
Before:
(gdb) p $stimecmp
$1 = void
After:
(gdb) p $stimecmp
$1 = 0
target/riscv/csr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
target/riscv/csr.c +5 -1
@@ -586,7 +586,7 @@ static RISCVException sstc(CPURISCVState *env, int csrno) {bool hmode_check = false; -if (!riscv_cpu_cfg (env)->ext_sstc || !env->rdtime_fn) { +if (!riscv_cpu_cfg (env)->ext_sstc) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -603,6 +603,10 @@ static RISCVException sstc(CPURISCVState *env, int csrno)return RISCV_EXCP_NONE ; } +if (!env->rdtime_fn) { +return RISCV_EXCP_ILLEGAL_INST ; + } +if (env->priv ==PRV_M ) {return RISCV_EXCP_NONE ; }
Signature · 1 line
2.43.0
Quoted 4 lines · Zephyr Li
The Sstc predicate currently checks both
ext_sstcandrdtime_fn. This causes the gdbstub CSR XML generation to skip Sstc CSRs whenrdtime_fnhas not been initialized yet, even if the CPU supports Sstc.
Quoted 8 lines
As a result, GDB reports $stimecmp as void with a CPU that exposes the sstc extension.
Only use
ext_sstcfor the early existence check, and keep therdtime_fncheck for non-debugger accesses.Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
Signed-off-by Zephyr Li <[email protected]>
Quoted 44 lines
---
Testing:
Start QEMU with:
qemu-system-riscv64 -M virt,aclint=on -cpu max,sstc=true -s -S -nographicBefore:
(gdb) p $stimecmp
$1 = voidAfter:
(gdb) p $stimecmp
$1 = 0target/riscv/csr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)target/riscv/csr.c +5
-1@@ -586,7 +586,7 @@ static RISCVException sstc(CPURISCVState *env, int csrno) {bool hmode_check = false; -if (!riscv_cpu_cfg (env)->ext_sstc || !env->rdtime_fn) { +if (!riscv_cpu_cfg (env)->ext_sstc) {return RISCV_EXCP_ILLEGAL_INST ; }@@ -603,6 +603,10 @@ static RISCVException sstc(CPURISCVState *env, int csrno)return RISCV_EXCP_NONE ; } +if (!env->rdtime_fn) { +return RISCV_EXCP_ILLEGAL_INST ; + } +if (env->priv ==PRV_M ) {return RISCV_EXCP_NONE ; }Signature · 1 line
2.43.0
Quoted 9 lines · Zephyr Li
The Sstc predicate currently checks both
ext_sstcandrdtime_fn. This causes the gdbstub CSR XML generation to skip Sstc CSRs whenrdtime_fn
has not been initialized yet, even if the CPU supports Sstc.As a result, GDB reports $stimecmp as void with a CPU that exposes the
sstc extension.
Quoted 6 lines
Only use
ext_sstcfor the early existence check, and keep therdtime_fn
check for non-debugger accesses.Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
Signed-off-by Zephyr Li <[email protected]>
Alistair
Quoted 44 lines
---
Testing:
Start QEMU with:
qemu-system-riscv64 -M virt,aclint=on -cpu max,sstc=true -s - S -nographicBefore:
(gdb) p $stimecmp
$1 = voidAfter:
(gdb) p $stimecmp
$1 = 0target/riscv/csr.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)target/riscv/csr.c +0
-0@@ -586,7 +586,7 @@ static RISCVException sstc(CPURISCVState *env, int csrno) { bool hmode_check = false;
- if (!riscv_cpu_cfg(env)->ext_sstc || !env->rdtime_fn) { + if (!riscv_cpu_cfg(env)->ext_sstc) {
returnRISCV_EXCP_ILLEGAL_INST;
}target/riscv/csr.c +0
-0@@ -603,6 +603,10 @@ static RISCVException sstc(CPURISCVState *env, int csrno) return RISCV_EXCP_NONE; }
+ if (!env->rdtime_fn) {
+ returnRISCV_EXCP_ILLEGAL_INST;
+ }
+
if (env->priv==PRV_M) {
returnRISCV_EXCP_NONE;
}
Alistair Francis
AppliedQuoted 9 lines · Zephyr Li
The Sstc predicate currently checks both
ext_sstcandrdtime_fn. This causes the gdbstub CSR XML generation to skip Sstc CSRs whenrdtime_fn
has not been initialized yet, even if the CPU supports Sstc.As a result, GDB reports $stimecmp as void with a CPU that exposes the
sstc extension.
Quoted 6 lines
Only use
ext_sstcfor the early existence check, and keep therdtime_fn
check for non-debugger accesses.Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
Signed-off-by Zephyr Li <[email protected]>
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 44 lines
---
Testing:
Start QEMU with:
qemu-system-riscv64 -M virt,aclint=on -cpu max,sstc=true -s - S -nographicBefore:
(gdb) p $stimecmp
$1 = voidAfter:
(gdb) p $stimecmp
$1 = 0target/riscv/csr.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)target/riscv/csr.c +0
-0@@ -586,7 +586,7 @@ static RISCVException sstc(CPURISCVState *env, int csrno) { bool hmode_check = false;
- if (!riscv_cpu_cfg(env)->ext_sstc || !env->rdtime_fn) { + if (!riscv_cpu_cfg(env)->ext_sstc) {
returnRISCV_EXCP_ILLEGAL_INST;
}target/riscv/csr.c +0
-0@@ -603,6 +603,10 @@ static RISCVException sstc(CPURISCVState *env, int csrno) return RISCV_EXCP_NONE; }
+ if (!env->rdtime_fn) {
+ returnRISCV_EXCP_ILLEGAL_INST;
+ }
+
if (env->priv==PRV_M) {
returnRISCV_EXCP_NONE;
}