ppc/gdbstub: Expose SPRs to GDB
cover ppc/gdbstub: Expose SPRs to GDB
This series implements the reading and writing of Special Purpose Registers in PPC's gdbstub.
* How it works generally [1]:
GDB asks for the target.xml file which contains the target description along with the list of available feature XMLs. GDB then asks for each of the XML files in sequence.
The XML files contain a list of registers descriptions:
<reg name="msr" bitsize="64" type="uint64"/>
When the user tries to access a register, GDB looks for the register name in the XML file and sends QEMU the index of the register. This index is sequential across all feature files.
The index provided by GDB must be converted by QEMU to match QEMU's internal representation.
A set of callbacks are implemented to read/write the register.
* In this series:
The first patch implements the dynamic generation of the power-spr.xml file. Making it dynamically facilitates converting the GDB index to an index useful for addressing the env->spr array.
The second patch implements the gdb_{get,set}_spr_reg callbacks along with the convertion from GDB index to QEMU index.
The third patch enables the functionality.
1- https://sourceware.org/gdb/current/onlinedocs/gdb/Target-Descriptions.html
Fabiano Rosas (3):
target/ppc: Add SPRs XML generation code for gdbstub target/ppc: Add GDB callbacks for SPRs target/ppc: Enable reporting of SPRs to GDB
target/ppc/cpu.h | 7 ++++ target/ppc/gdbstub.c | 45 +++++++++++++++++++++++++ target/ppc/translate_init.inc.c | 59 +++++++++++++++++++++++++++++++-- 3 files changed, 109 insertions(+), 2 deletions(-)
--
2.17.1
PATCH 1/3 target/ppc: Add SPRs XML generation code for gdbstub
A following patch will add support for handling the Special Purpose Registers (SPR) in GDB via gdbstub. For that purpose, GDB needs to be provided with an XML description of the registers (see gdb-xml directory).
This patch adds the code that generates the XML dynamically based on the SPRs already defined in the machine. This eliminates the need for several XML files to match each possible ppc machine.
A "group" is defined so that the GDB command info registers spr can be used.
--- target/ppc/cpu.h | 7 +++++++ target/ppc/gdbstub.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+)
target/ppc/cpu.h +7 -0
@@ -1052,6 +1052,9 @@ struct CPUPPCState {/* Special purpose registers */ target_ulong spr[1024 ];ppc_spr_t spr_cb[1024 ]; +#if !defined(CONFIG_USER_ONLY ) +const char *gdb_spr_xml; +#endif /* Altivec registers */ ppc_avr_t avr[32 ];uint32_t vscr;
@@ -1264,6 +1267,10 @@ int ppc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);int ppc_cpu_gdb_read_register_apple (CPUState *cpu,uint8_t *buf,int reg);int ppc_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);int ppc_cpu_gdb_write_register_apple (CPUState *cpu,uint8_t *buf,int reg); +#ifndef CONFIG_USER_ONLY +int ppc_gdb_gen_spr_xml (CPUState *cpu); +const char *ppc_gdb_get_dynamic_xml (CPUState *cs,const char *xml_name); +#endif int ppc64_cpu_write_elf64_note (WriteCoreDumpFunction f,CPUState *cs,int cpuid,void *opaque); int ppc32_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
target/ppc/gdbstub.c +45 -0
48 lines not on this page · raw message
--
2.17.1
PATCH 2/3 target/ppc: Add GDB callbacks for SPRs
In reply to Fabiano RosasThese 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.
--- target/ppc/translate_init.inc.c | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
target/ppc/translate_init.inc.c +50 -0
@@ -9483,6 +9483,56 @@ static bool avr_need_swap(CPUPPCState *env)#endif } +#if !defined(CONFIG_USER_ONLY ) +static int gdb_find_spr_idx (CPUPPCState *env,int n) +{ +int idx =-1 ; +int i; + +for (i =0 ; i <ARRAY_SIZE (env->spr_cb); i++) { +ppc_spr_t *spr = &env->spr_cb[i]; + +if (spr->name && ++idx == n) { +break ; + } + } +return i; +} + +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) { +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) { +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 ) {
Signature · 1 line
2.17.1
PATCH 3/3 target/ppc: Enable reporting of SPRs to GDB
In reply to Fabiano RosasThis allows reading and writing of SPRs via GDB:
(gdb) p/x $srr1
$1 = 0x8000000002803033
(gdb) p/x $pvr
$2 = 0x4b0201
(gdb) set $pvr=0x4b0000
(gdb) p/x $pvr
$3 = 0x4b0000
They can also be shown as a group:
(gdb) info reg spr
--- target/ppc/translate_init.inc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
target/ppc/translate_init.inc.c +7 -2
@@ -9760,7 +9760,10 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp)gdb_register_coprocessor (cs, gdb_get_vsx_reg, gdb_set_vsx_reg,32 ,"power-vsx.xml" ,0 ); } - +#ifndef CONFIG_USER_ONLY +gdb_register_coprocessor (cs, gdb_get_spr_reg, gdb_set_spr_reg, +ppc_gdb_gen_spr_xml (cs),"power-spr.xml" ,0 ); +#endif qemu_init_vcpu (cs); pcc->parent_realize (dev, errp);
@@ -10523,7 +10526,9 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)#endif cc->gdb_num_core_regs =71 ; - +#ifndef CONFIG_USER_ONLY + cc->gdb_get_dynamic_xml = ppc_gdb_get_dynamic_xml; +#endif #ifdef USE_APPLE_GDB cc->gdb_read_register = ppc_cpu_gdb_read_register_apple; cc->gdb_write_register = ppc_cpu_gdb_write_register_apple;
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 2/3] target/ppc: Add GDB callbacks for SPRs
In reply to Fabiano RosasQuoted 26 lines · Fabiano Rosas
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->sprarray so thegdb_find_spr_idxfunction does that conversion.Signed-off-by Fabiano Rosas <[email protected]>--- target/ppc/translate_init.inc.c | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)target/ppc/translate_init.inc.c +5
-0@@ -9483,6 +9483,56 @@ static bool avr_need_swap(CPUPPCState *env)#endif } +#if !defined(CONFIG_USER_ONLY ) +static int gdb_find_spr_idx (CPUPPCState *env,int n) +{ +int idx =-1 ; +int i;
target/ppc/translate_init.inc.c static bool avr_need_swap(CPUPPCState *env) · line 9500
Quoted 10 lines
target/ppc/translate_init.inc.c +10
-0+ +for (i =0 ; i <ARRAY_SIZE (env->spr_cb); i++) { +ppc_spr_t *spr = &env->spr_cb[i]; + +if (spr->name && ++idx == n) { +break ; + } + } +return i; +}
This is very subtle - it relies on the fact that you also generate the XML in sequence, which makes for a very non-obvious dependency between different parts of the code. At the very least this needs a big fat comment explaining how the gdb ids are allocated.
I think better would be to explicitly put a gdb_id into the spr_cb structure - that would be filled in at the same time you generate the XML, then referenced here.
Quoted 37 lines
target/ppc/translate_init.inc.c +34
-0+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) { +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) { +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 ) {
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson