[Qemu-devel] [PATCH v2 2/3] target/ppc: Add GDB callbacks for SPRs

Fabiano Rosas posted 3 patches 6 years, 9 months ago
Maintainers: David Gibson <david@gibson.dropbear.id.au>
There is a newer version of this series
[Qemu-devel] [PATCH v2 2/3] target/ppc: Add GDB callbacks for SPRs
Posted by Fabiano Rosas 6 years, 9 months ago
These will be used to let GDB know about PPC's Special Purpose
Registers (SPR).

They take an index based on the order the registers appear in the XML
file sent by QEMU to GDB. This index does not match the actual
location of the registers in the env->spr array so the
gdb_find_spr_idx function does that conversion.

Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
---
 target/ppc/translate_init.inc.c | 49 +++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c
index ade06cc773..bbb468f38d 100644
--- a/target/ppc/translate_init.inc.c
+++ b/target/ppc/translate_init.inc.c
@@ -9483,6 +9483,55 @@ static bool avr_need_swap(CPUPPCState *env)
 #endif
 }
 
+#if !defined(CONFIG_USER_ONLY)
+static int gdb_find_spr_idx(CPUPPCState *env, int n)
+{
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(env->spr_cb); i++) {
+        ppc_spr_t *spr = &env->spr_cb[i];
+
+        if (spr->name && spr->gdb_id == n) {
+            return i;
+        }
+    }
+    return -1;
+}
+
+static int gdb_get_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
+{
+    int reg;
+    int len;
+
+    reg = gdb_find_spr_idx(env, n);
+    if (reg < 0) {
+        return 0;
+    }
+
+    len = TARGET_LONG_SIZE;
+    stn_p(mem_buf, len, env->spr[reg]);
+    ppc_maybe_bswap_register(env, mem_buf, len);
+    return len;
+}
+
+static int gdb_set_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
+{
+    int reg;
+    int len;
+
+    reg = gdb_find_spr_idx(env, n);
+    if (reg < 0) {
+        return 0;
+    }
+
+    len = TARGET_LONG_SIZE;
+    ppc_maybe_bswap_register(env, mem_buf, len);
+    env->spr[reg] = ldn_p(mem_buf, len);
+
+    return len;
+}
+#endif
+
 static int gdb_get_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
 {
     if (n < 32) {
-- 
2.17.1


Re: [Qemu-devel] [PATCH v2 2/3] target/ppc: Add GDB callbacks for SPRs
Posted by Fabiano Rosas 6 years, 9 months ago
Fabiano Rosas <farosas@linux.ibm.com> writes:

> These will be used to let GDB know about PPC's Special Purpose
> Registers (SPR).
>
> They take an index based on the order the registers appear in the XML
> file sent by QEMU to GDB. This index does not match the actual
> location of the registers in the env->spr array so the
> gdb_find_spr_idx function does that conversion.
>
> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
> ---
>  target/ppc/translate_init.inc.c | 49 +++++++++++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)
>
> diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c
> index ade06cc773..bbb468f38d 100644
> --- a/target/ppc/translate_init.inc.c
> +++ b/target/ppc/translate_init.inc.c
> @@ -9483,6 +9483,55 @@ static bool avr_need_swap(CPUPPCState *env)
>  #endif
>  }
>  
> +#if !defined(CONFIG_USER_ONLY)
> +static int gdb_find_spr_idx(CPUPPCState *env, int n)
> +{
> +    int i;
> +
> +    for (i = 0; i < ARRAY_SIZE(env->spr_cb); i++) {
> +        ppc_spr_t *spr = &env->spr_cb[i];
> +
> +        if (spr->name && spr->gdb_id == n) {
> +            return i;
> +        }
> +    }
> +    return -1;
> +}
> +
> +static int gdb_get_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
> +{
> +    int reg;
> +    int len;
> +
> +    reg = gdb_find_spr_idx(env, n);
> +    if (reg < 0) {
> +        return 0;
> +    }
> +
> +    len = TARGET_LONG_SIZE;
> +    stn_p(mem_buf, len, env->spr[reg]);
> +    ppc_maybe_bswap_register(env, mem_buf, len);
> +    return len;
> +}
> +
> +static int gdb_set_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
> +{
> +    int reg;
> +    int len;
> +
> +    reg = gdb_find_spr_idx(env, n);
> +    if (reg < 0) {
> +        return 0;
> +    }
> +
> +    len = TARGET_LONG_SIZE;
> +    ppc_maybe_bswap_register(env, mem_buf, len);
> +    env->spr[reg] = ldn_p(mem_buf, len);
> +
> +    return len;
> +}
> +#endif
> +
>  static int gdb_get_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
>  {
>      if (n < 32) {

I just noticed this patch doesn't build atomically because the callbacks
are not being used. I'll send another version fixing this.


Re: [Qemu-devel] [PATCH v2 2/3] target/ppc: Add GDB callbacks for SPRs
Posted by Alexey Kardashevskiy 6 years, 9 months ago

On 16/01/2019 06:10, Fabiano Rosas wrote:
> Fabiano Rosas <farosas@linux.ibm.com> writes:
> 
>> These will be used to let GDB know about PPC's Special Purpose
>> Registers (SPR).
>>
>> They take an index based on the order the registers appear in the XML
>> file sent by QEMU to GDB. This index does not match the actual
>> location of the registers in the env->spr array so the
>> gdb_find_spr_idx function does that conversion.
>>
>> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
>> ---
>>  target/ppc/translate_init.inc.c | 49 +++++++++++++++++++++++++++++++++
>>  1 file changed, 49 insertions(+)
>>
>> diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c
>> index ade06cc773..bbb468f38d 100644
>> --- a/target/ppc/translate_init.inc.c
>> +++ b/target/ppc/translate_init.inc.c
>> @@ -9483,6 +9483,55 @@ static bool avr_need_swap(CPUPPCState *env)
>>  #endif
>>  }
>>  
>> +#if !defined(CONFIG_USER_ONLY)
>> +static int gdb_find_spr_idx(CPUPPCState *env, int n)
>> +{
>> +    int i;
>> +
>> +    for (i = 0; i < ARRAY_SIZE(env->spr_cb); i++) {
>> +        ppc_spr_t *spr = &env->spr_cb[i];
>> +
>> +        if (spr->name && spr->gdb_id == n) {
>> +            return i;
>> +        }
>> +    }
>> +    return -1;
>> +}
>> +
>> +static int gdb_get_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
>> +{
>> +    int reg;
>> +    int len;
>> +
>> +    reg = gdb_find_spr_idx(env, n);
>> +    if (reg < 0) {
>> +        return 0;
>> +    }
>> +
>> +    len = TARGET_LONG_SIZE;
>> +    stn_p(mem_buf, len, env->spr[reg]);
>> +    ppc_maybe_bswap_register(env, mem_buf, len);
>> +    return len;
>> +}
>> +
>> +static int gdb_set_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
>> +{
>> +    int reg;
>> +    int len;
>> +
>> +    reg = gdb_find_spr_idx(env, n);
>> +    if (reg < 0) {
>> +        return 0;
>> +    }
>> +
>> +    len = TARGET_LONG_SIZE;
>> +    ppc_maybe_bswap_register(env, mem_buf, len);
>> +    env->spr[reg] = ldn_p(mem_buf, len);
>> +
>> +    return len;
>> +}
>> +#endif
>> +
>>  static int gdb_get_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
>>  {
>>      if (n < 32) {
> 
> I just noticed this patch doesn't build atomically because the callbacks
> are not being used. I'll send another version fixing this.

Just merge it into 3/3.



-- 
Alexey