target/riscv: fix invalid sstc predicate in gdbstub
PATCH 1/1 target/riscv: fix invalid sstc predicate in gdbstub
sstc function incorrectly checks for avaibility of env->rdtime_fn. This causes it to fail each time it's called because rdtime_fn is setup later in the procedure (when timer devices are created). This prevents stimecmp's addition to gdb.
This change ensures only the riscv_cpu_cfg(env) check is done. rdtime_fn will always be NULL otherwise and fail.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
--- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/csr.c +1 -1
@@ -590,7 +590,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 ; }
Signature · 1 line
2.54.0
Quoted 7 lines · Abhigyan Kumar
sstc function incorrectly checks for avaibility of
env->rdtime_fn. This causes it to fail each time it's called becauserdtime_fnis setup later in the procedure (when timer devices are created). This prevents stimecmp's addition to gdb.This change ensures only the
riscv_cpu_cfg(env)check is done.rdtime_fnwill always be NULL otherwise and fail.
I am not sure we can do that - there are several boards that don't create the timer that implements rdtime_fn (e.g. spike). If we just remove the check we'll break the sstc check for them.
I suggest using the 'env->debugger' flag to skip the rdtimer check if we're running the gdbstub:
$ git diff
target/riscv/csr.c +2 -1
@@ -590,7 +590,8 @@ 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 + || (!env->debugger && !env->rdtime_fn)) {return RISCV_EXCP_ILLEGAL_INST ; }
Testing with gitlab 3496 this seems to work:
$ riscv64-unknown-elf-gdb (gdb) target extended-remote :1234 (gdb) p $stimecmp $1 = 0 (gdb)
Thanks,
Daniel
Quoted 20 lines
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
Signed-off-by Abhigyan Kumar <[email protected]>--- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/csr.c +1
-1@@ -590,7 +590,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 ; }
Quoted 19 lines · Abhigyan Kumar
sstc function incorrectly checks for avaibility of
env->rdtime_fn. This causes it to fail each time it's called becauserdtime_fnis setup later in the procedure (when timer devices are created). This prevents stimecmp's addition to gdb.This change ensures only the
riscv_cpu_cfg(env)check is done.rdtime_fnwill always be NULL otherwise and fail.Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
Signed-off-by Abhigyan Kumar <[email protected]>--- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/csr.c +0
-0
target/riscv/csr.c static RISCVException sstc(CPURISCVState *env, int csrno) · line 596
Quoted 8 lines
target/riscv/csr.c +1
-1@@ -590,7 +590,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 ; }
Greetings. It has been over two and a half months since I submitted this patch. It's my humble request to know the status of the review/acceptance for my patch. Please inform me about any required amends.
Thank you for your patience and attention.
Signature · 1 line
Abhigyan Kumar