target/riscv: Expose "virt" register for GDB for reads
PATCH 1/2 target/riscv: Expose "virt" register for GDB for reads
This patch enables a debugger to read current virtualization mode via virtual "virt" register. After it, we could get full current privilege mode via both "priv" and "virt" register.
Extend previous commit ab9056ff9bdb3f95db6e7a666d10522d289f14ec to support H-extension.
--- gdb-xml/riscv-32bit-virtual.xml | 1 + gdb-xml/riscv-64bit-virtual.xml | 1 + target/riscv/gdbstub.c | 12 ++++++++---- 3 files changed, 10 insertions(+), 4 deletions(-)
gdb-xml/riscv-32bit-virtual.xml +1 -0
@@ -8,4 +8,5 @@ <!DOCTYPE feature SYSTEM "gdb-target.dtd"> <feature name="org.gnu.gdb.riscv.virtual"> <reg name="priv" bitsize="32"/> + <reg name="virt" bitsize="32"/> </feature>
gdb-xml/riscv-64bit-virtual.xml +1 -0
@@ -8,4 +8,5 @@ <!DOCTYPE feature SYSTEM "gdb-target.dtd"> <feature name="org.gnu.gdb.riscv.virtual"> <reg name="priv" bitsize="64"/> + <reg name="virt" bitsize="64"/> </feature>
target/riscv/gdbstub.c +8 -4
@@ -187,13 +187,17 @@ static int riscv_gdb_set_csr(CPURISCVState *env, uint8_t *mem_buf, int n)static int riscv_gdb_get_virtual (CPURISCVState *cs,GByteArray *buf,int n) { -if (n ==0 ) {#ifdef CONFIG_USER_ONLY +if (n >=0 && n <=1 ) {return gdb_get_regl (buf,0 ); + }#else +if (n ==0 ) {return gdb_get_regl (buf, cs->priv); -#endif + }else if (n ==1 ) { +return gdb_get_regl (buf,riscv_cpu_virt_enabled (cs)); } +#endif return 0 ; }
@@ -328,13 +332,13 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)case MXL_RV32 :gdb_register_coprocessor (cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, -1 ,"riscv-32bit-virtual.xml" ,0 ); +2 ,"riscv-32bit-virtual.xml" ,0 );break ;case MXL_RV64 :case MXL_RV128 :gdb_register_coprocessor (cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, -1 ,"riscv-64bit-virtual.xml" ,0 ); +2 ,"riscv-64bit-virtual.xml" ,0 );break ;default :g_assert_not_reached ();
Signature · 1 line
2.17.1
PATCH 2/2 target/riscv: Make the "virt" register writable by GDB
This patch also enables debugger to set current privilege mode to VU/VS-mode.
Extend previous commit 81d2929c41d32af138f3562f5a7b309f6eac7ca7 to support H-extension.
--- target/riscv/gdbstub.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
target/riscv/gdbstub.c +16 -2
@@ -203,15 +203,29 @@ static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n)static int riscv_gdb_set_virtual (CPURISCVState *cs,uint8_t *mem_buf,int n) { +#ifdef CONFIG_USER_ONLY +if (n >=0 && n <=1 ) { +return sizeof (target_ulong); + } +#else +bool virt; +if (n ==0 ) { -#ifndef CONFIG_USER_ONLY cs->priv =ldtul_p (mem_buf) &0x3 ;if (cs->priv ==PRV_H ) { cs->priv =PRV_S ; } -#endif +return sizeof (target_ulong); + }else if (n ==1 ) { + virt =ldtul_p (mem_buf) &0x1 ; +if ((cs->priv ==PRV_M ) && (virt == true)) { +/* M-mode only supports V=0. */ + virt = false; + } +riscv_cpu_set_virt_enabled (cs, virt);return sizeof (target_ulong); } +#endif return 0 ; }
Signature · 1 line
2.17.1
Re: [PATCH 2/2] target/riscv: Make the "virt" register writable by GDB
Quoted 25 lines · Jim Shu
This patch also enables debugger to set current privilege mode to VU/VS-mode.
Extend previous commit
81d2929c41d32af138f3562f5a7b309f6eac7ca7to support H-extension.Signed-off-by Jim Shu <[email protected]>Reviewed-by Frank Chang <[email protected]>--- target/riscv/gdbstub.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)target/riscv/gdbstub.c +5
-0@@ -203,15 +203,29 @@ static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n)static int riscv_gdb_set_virtual (CPURISCVState *cs,uint8_t *mem_buf,int n) { +#ifdef CONFIG_USER_ONLY +if (n >=0 && n <=1 ) { +return sizeof (target_ulong); + } +#else
target/riscv/gdbstub.c static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n) · line 218
Quoted 10 lines
target/riscv/gdbstub.c +3
-2+bool virt; +if (n ==0 ) { -#ifndef CONFIG_USER_ONLY cs->priv =ldtul_p (mem_buf) &0x3 ;if (cs->priv ==PRV_H ) { cs->priv =PRV_S ; } -#endif +return sizeof (target_ulong);
We should return according to the misa_mxl_max. And this is a bug before your commit.
target/riscv/gdbstub.c static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n) · line 226
Quoted 8 lines
target/riscv/gdbstub.c +7
-0+ }else if (n ==1 ) { + virt =ldtul_p (mem_buf) &0x1 ; +if ((cs->priv ==PRV_M ) && (virt == true)) { +/* M-mode only supports V=0. */ + virt = false; + } +riscv_cpu_set_virt_enabled (cs, virt);return sizeof (target_ulong);
Same error here. Otherwise,
Zhiwei
Quoted 5 lines
target/riscv/gdbstub.c +1
-0} +#endif return 0 ; }
Re: [PATCH 2/2] target/riscv: Make the "virt" register writable by GDB
Thanks for reviewing.
I'll fix this issue.
Quoted 59 lines · LIU Zhiwei
Quoted 25 lines · Jim Shu
This patch also enables debugger to set current privilege mode to VU/VS-mode.
Extend previous commit
81d2929c41d32af138f3562f5a7b309f6eac7ca7to support H-extension.Signed-off-by Jim Shu <[email protected]>Reviewed-by Frank Chang <[email protected]>--- target/riscv/gdbstub.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)target/riscv/gdbstub.c +5
-0@@ -203,15 +203,29 @@ static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n)static int riscv_gdb_set_virtual (CPURISCVState *cs,uint8_t *mem_buf,int n) { +#ifdef CONFIG_USER_ONLY +if (n >=0 && n <=1 ) { +return sizeof (target_ulong); + } +#else target/riscv/gdbstub.c static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n) · line 218
Quoted 10 lines
target/riscv/gdbstub.c +3
-2+bool virt; +if (n ==0 ) { -#ifndef CONFIG_USER_ONLY cs->priv =ldtul_p (mem_buf) &0x3 ;if (cs->priv ==PRV_H ) { cs->priv =PRV_S ; } -#endif +return sizeof (target_ulong);We should return according to the
misa_mxl_max. And this is a bug before your commit.target/riscv/gdbstub.c static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n) · line 226
Quoted 8 lines
target/riscv/gdbstub.c +7
-0+ }else if (n ==1 ) { + virt =ldtul_p (mem_buf) &0x1 ; +if ((cs->priv ==PRV_M ) && (virt == true)) { +/* M-mode only supports V=0. */ + virt = false; + } +riscv_cpu_set_virt_enabled (cs, virt);return sizeof (target_ulong);Same error here. Otherwise,
Reviewed-by LIU Zhiwei <[email protected]>Zhiwei
Quoted 5 lines
target/riscv/gdbstub.c +1
-0} +#endif return 0 ; }
Re: [PATCH 2/2] target/riscv: Make the "virt" register writable by GDB
In reply to LIU ZhiweiQuoted 32 lines · LIU Zhiwei
Quoted 29 lines · Jim Shu
This patch also enables debugger to set current privilege mode to VU/VS-mode.
Extend previous commit
81d2929c41d32af138f3562f5a7b309f6eac7ca7to support H-extension.Signed-off-by Jim Shu <[email protected]>Reviewed-by Frank Chang <[email protected]>--- target/riscv/gdbstub.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)target/riscv/gdbstub.c +7
-1@@ -203,15 +203,29 @@ static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n)static int riscv_gdb_set_virtual (CPURISCVState *cs,uint8_t *mem_buf,int n) { +#ifdef CONFIG_USER_ONLY +if (n >=0 && n <=1 ) { +return sizeof (target_ulong); + } +#else +bool virt; +if (n ==0 ) { -#ifndef CONFIG_USER_ONLY
Quoted 8 lines
target/riscv/gdbstub.c static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n) · line 218
Quoted 6 lines
target/riscv/gdbstub.c +1
-1cs->priv =ldtul_p (mem_buf) &0x3 ;if (cs->priv ==PRV_H ) { cs->priv =PRV_S ; } -#endif +return sizeof (target_ulong);We should return according to the
misa_mxl_max. And this is a bug before your commit.
Hi Zhiwei,
After reading other gdbstub.c code, I think it is OK to use 'sizeof(target_ulong)' as virtual register length.
Its length is 32-bit in RV32 and is 64-bit in RV64/RV128. We don't need to handle RV128 specially.
Virtual register length is same as CSR length and 'riscv_gdb_set_csr()' also use 'sizeof(target_ulong)'.
Jim Shu
Quoted 19 lines
target/riscv/gdbstub.c static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n) · line 226
Quoted 8 lines
target/riscv/gdbstub.c +7
-0+ }else if (n ==1 ) { + virt =ldtul_p (mem_buf) &0x1 ; +if ((cs->priv ==PRV_M ) && (virt == true)) { +/* M-mode only supports V=0. */ + virt = false; + } +riscv_cpu_set_virt_enabled (cs, virt);return sizeof (target_ulong);Same error here. Otherwise,
Reviewed-by LIU Zhiwei <[email protected]>Zhiwei
Quoted 5 lines
target/riscv/gdbstub.c +1
-0} +#endif return 0 ; }
Re: [PATCH 2/2] target/riscv: Make the "virt" register writable by GDB
Quoted 40 lines · Jim Shu
Quoted 31 lines · LIU Zhiwei
Quoted 29 lines · Jim Shu
This patch also enables debugger to set current privilege mode to VU/VS-mode.
Extend previous commit
81d2929c41d32af138f3562f5a7b309f6eac7ca7to support H-extension.Signed-off-by Jim Shu <[email protected]>Reviewed-by Frank Chang <[email protected]>--- target/riscv/gdbstub.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)target/riscv/gdbstub.c +7
-1@@ -203,15 +203,29 @@ static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n)static int riscv_gdb_set_virtual (CPURISCVState *cs,uint8_t *mem_buf,int n) { +#ifdef CONFIG_USER_ONLY +if (n >=0 && n <=1 ) { +return sizeof (target_ulong); + } +#else +bool virt; +if (n ==0 ) { -#ifndef CONFIG_USER_ONLY Quoted 8 lines
target/riscv/gdbstub.c static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n) · line 218
Quoted 6 lines
target/riscv/gdbstub.c +1
-1cs->priv =ldtul_p (mem_buf) &0x3 ;if (cs->priv ==PRV_H ) { cs->priv =PRV_S ; } -#endif +return sizeof (target_ulong);We should return according to the
misa_mxl_max. And this is a bug before your commit.
Quoted 4 lines
Hi Zhiwei,
After reading other
gdbstub.ccode, I think it is OK to use 'sizeof(target_ulong)' as virtual register length.
No, you should refer to the riscv_cpu_gdb_read(write)_register.
Quoted 1 line
Its length is 32-bit in RV32 and is 64-bit in RV64/RV128.
Although we don't support MXLEN 32bit currently on qemu-system-riscv64, we should not introduce more code to make dynamic xlen support complex.
Zhiwei
Quoted 26 lines
We don't
need to handle RV128 specially.
Virtual register length is same as CSR length and 'riscv_gdb_set_csr()' also use 'sizeof(target_ulong)'.Jim Shu
Quoted 19 lines
target/riscv/gdbstub.c static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n) · line 226
Quoted 8 lines
target/riscv/gdbstub.c +7
-0+ }else if (n ==1 ) { + virt =ldtul_p (mem_buf) &0x1 ; +if ((cs->priv ==PRV_M ) && (virt == true)) { +/* M-mode only supports V=0. */ + virt = false; + } +riscv_cpu_set_virt_enabled (cs, virt);return sizeof (target_ulong);Same error here. Otherwise,
Reviewed-by LIU Zhiwei <[email protected]>Zhiwei
Quoted 5 lines
target/riscv/gdbstub.c +1
-0} +#endif return 0 ; }
Re: [PATCH 2/2] target/riscv: Make the "virt" register writable by GDB
In reply to Jim ShuQuoted 6 lines · Jim Shu
This patch also enables debugger to set current privilege mode to VU/VS-mode.
Extend previous commit
81d2929c41d32af138f3562f5a7b309f6eac7ca7to support H-extension.
I'm not sure we want this. What is the use case for this?
Changing the virt mode on the fly like this is likely to break lots of software. Should we really allow users to do this?
Alistair
Quoted 47 lines
Signed-off-by Jim Shu <[email protected]>Reviewed-by Frank Chang <[email protected]>--- target/riscv/gdbstub.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)target/riscv/gdbstub.c +16
-3@@ -203,15 +203,29 @@ static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n)static int riscv_gdb_set_virtual (CPURISCVState *cs,uint8_t *mem_buf,int n) { +#ifdef CONFIG_USER_ONLY +if (n >=0 && n <=1 ) { +return sizeof (target_ulong); + } +#else +bool virt; +if (n ==0 ) { -#ifndef CONFIG_USER_ONLY cs->priv =ldtul_p (mem_buf) &0x3 ;if (cs->priv ==PRV_H ) { cs->priv =PRV_S ; } -#endif +return sizeof (target_ulong); + }else if (n ==1 ) { + virt =ldtul_p (mem_buf) &0x1 ; +if ((cs->priv ==PRV_M ) && (virt == true)) { +/* M-mode only supports V=0. */ + virt = false; + } +riscv_cpu_set_virt_enabled (cs, virt);return sizeof (target_ulong); } +#endif return 0 ; } --2.17.1
Quoted 62 lines · Jim Shu
This patch enables a debugger to read current virtualization mode via virtual "virt" register. After it, we could get full current privilege mode via both "priv" and "virt" register.
Extend previous commit
ab9056ff9bdb3f95db6e7a666d10522d289f14ecto support H-extension.Signed-off-by Jim Shu <[email protected]>Reviewed-by Frank Chang <[email protected]>--- gdb-xml/riscv-32bit-virtual.xml | 1 + gdb-xml/riscv-64bit-virtual.xml | 1 + target/riscv/gdbstub.c | 12 ++++++++---- 3 files changed, 10 insertions(+), 4 deletions(-)gdb-xml/riscv-32bit-virtual.xml +1
-0@@ -8,4 +8,5 @@ <!DOCTYPE feature SYSTEM "gdb-target.dtd"> <feature name="org.gnu.gdb.riscv.virtual"> <reg name="priv" bitsize="32"/> + <reg name="virt" bitsize="32"/> </feature>gdb-xml/riscv-64bit-virtual.xml +1
-0@@ -8,4 +8,5 @@ <!DOCTYPE feature SYSTEM "gdb-target.dtd"> <feature name="org.gnu.gdb.riscv.virtual"> <reg name="priv" bitsize="64"/> + <reg name="virt" bitsize="64"/> </feature>target/riscv/gdbstub.c +6
-2@@ -187,13 +187,17 @@ static int riscv_gdb_set_csr(CPURISCVState *env, uint8_t *mem_buf, int n)static int riscv_gdb_get_virtual (CPURISCVState *cs,GByteArray *buf,int n) { -if (n ==0 ) {#ifdef CONFIG_USER_ONLY +if (n >=0 && n <=1 ) {return gdb_get_regl (buf,0 ); + }#else +if (n ==0 ) {return gdb_get_regl (buf, cs->priv); -#endif + }else if (n ==1 ) { +return gdb_get_regl (buf,riscv_cpu_virt_enabled (cs)); } +#endif return 0 ; }@@ -328,13 +332,13 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)case MXL_RV32 : gdb_register_coprocessor(cs, riscv_gdb_get_virtual,
target/riscv/gdbstub.c void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) · line 341
Quoted 10 lines
target/riscv/gdbstub.c +2
-2riscv_gdb_set_virtual, - 1, "riscv-32bit-virtual.xml", 0); + 2, "riscv-32bit-virtual.xml", 0);break ;case MXL_RV64 :case MXL_RV128 :gdb_register_coprocessor (cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, -1 ,"riscv-64bit-virtual.xml" ,0 ); +2 ,"riscv-64bit-virtual.xml" ,0 );
Zhiwei
Quoted 3 lines
target/riscv/gdbstub.c +0
-0break ;default :g_assert_not_reached ();
Quoted 10 lines · Jim Shu
This patch enables a debugger to read current virtualization mode via virtual "virt" register. After it, we could get full current privilege mode via both "priv" and "virt" register.
Extend previous commit
ab9056ff9bdb3f95db6e7a666d10522d289f14ecto support H-extension.Signed-off-by Jim Shu <[email protected]>Reviewed-by Frank Chang <[email protected]>
Alistair
Quoted 70 lines
--- gdb-xml/riscv-32bit-virtual.xml | 1 + gdb-xml/riscv-64bit-virtual.xml | 1 + target/riscv/gdbstub.c | 12 ++++++++---- 3 files changed, 10 insertions(+), 4 deletions(-)gdb-xml/riscv-32bit-virtual.xml +1
-0@@ -8,4 +8,5 @@ <!DOCTYPE feature SYSTEM "gdb-target.dtd"> <feature name="org.gnu.gdb.riscv.virtual"> <reg name="priv" bitsize="32"/> + <reg name="virt" bitsize="32"/> </feature>gdb-xml/riscv-64bit-virtual.xml +1
-0@@ -8,4 +8,5 @@ <!DOCTYPE feature SYSTEM "gdb-target.dtd"> <feature name="org.gnu.gdb.riscv.virtual"> <reg name="priv" bitsize="64"/> + <reg name="virt" bitsize="64"/> </feature>target/riscv/gdbstub.c +8
-5@@ -187,13 +187,17 @@ static int riscv_gdb_set_csr(CPURISCVState *env, uint8_t *mem_buf, int n)static int riscv_gdb_get_virtual (CPURISCVState *cs,GByteArray *buf,int n) { -if (n ==0 ) {#ifdef CONFIG_USER_ONLY +if (n >=0 && n <=1 ) {return gdb_get_regl (buf,0 ); + }#else +if (n ==0 ) {return gdb_get_regl (buf, cs->priv); -#endif + }else if (n ==1 ) { +return gdb_get_regl (buf,riscv_cpu_virt_enabled (cs)); } +#endif return 0 ; }@@ -328,13 +332,13 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)case MXL_RV32 :gdb_register_coprocessor (cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, -1 ,"riscv-32bit-virtual.xml" ,0 ); +2 ,"riscv-32bit-virtual.xml" ,0 );break ;case MXL_RV64 :case MXL_RV128 :gdb_register_coprocessor (cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, -1 ,"riscv-64bit-virtual.xml" ,0 ); +2 ,"riscv-64bit-virtual.xml" ,0 );break ;default :g_assert_not_reached (); --2.17.1