[PATCH-for-10.1 7/8] target/mips: Get CPU register size using mips_cpu_is_64bit()

Philippe Mathieu-Daudé posted 8 patches 10 months, 3 weeks ago
[PATCH-for-10.1 7/8] target/mips: Get CPU register size using mips_cpu_is_64bit()
Posted by Philippe Mathieu-Daudé 10 months, 3 weeks ago
CPU registers size is static and depends on the type of CPU.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/mips/gdbstub.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/target/mips/gdbstub.c b/target/mips/gdbstub.c
index b9fc667373e..84fd3de4137 100644
--- a/target/mips/gdbstub.c
+++ b/target/mips/gdbstub.c
@@ -75,11 +75,16 @@ int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
     return 0;
 }
 
+static size_t mips_regsize(MIPSCPU *cpu)
+{
+    return mips_cpu_is_64bit(cpu) ? sizeof(uint64_t) : sizeof(uint32_t);
+}
+
 int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 {
     CPUMIPSState *env = cpu_env(cs);
     target_ulong tmp;
-    size_t regsize = sizeof(tmp);
+    size_t regsize = mips_regsize(MIPS_CPU(cs));
 
     tmp = ldn_p(mem_buf, regsize);
 
-- 
2.47.1


Re: [PATCH-for-10.1 7/8] target/mips: Get CPU register size using mips_cpu_is_64bit()
Posted by Pierrick Bouvier 10 months, 2 weeks ago
On 3/25/25 08:40, Philippe Mathieu-Daudé wrote:
> CPU registers size is static and depends on the type of CPU.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/mips/gdbstub.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/target/mips/gdbstub.c b/target/mips/gdbstub.c
> index b9fc667373e..84fd3de4137 100644
> --- a/target/mips/gdbstub.c
> +++ b/target/mips/gdbstub.c
> @@ -75,11 +75,16 @@ int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
>       return 0;
>   }
>   
> +static size_t mips_regsize(MIPSCPU *cpu)
> +{
> +    return mips_cpu_is_64bit(cpu) ? sizeof(uint64_t) : sizeof(uint32_t);
> +}
> +
>   int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
>   {
>       CPUMIPSState *env = cpu_env(cs);
>       target_ulong tmp;
> -    size_t regsize = sizeof(tmp);
> +    size_t regsize = mips_regsize(MIPS_CPU(cs));
>   
>       tmp = ldn_p(mem_buf, regsize);
>   

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>