Skip to contentSkip to conversation

target/microblaze: Add dynamic GDB XML and correct SReg reporting

PATCH Superseded Joe Komlodi 3 participants 8 messages May 11, 2020 – May 13, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover target/microblaze: Add dynamic GDB XML and correct SReg reporting

Hi all,

This series adds dynamic GDB XML support for Micraoblaze CPUs, and fixes an issue when reporting Microblaze SRegs through GDB.

The SRegs used to be printed out by iterating over the SReg array, but the SReg array isn't laid out in memory in the same order that GDB expects them.

When reporting register to GDB, note that even though 32-bit Microblaze supports having certain registers wider than 32-bits, we're repoting all of them as being 32-bits wide right now to maintain compatibility with GDB.

Thanks!
Joe

Joe Komlodi (4):
target/microblaze: gdb: Add dynamic GDB XML register support target/microblaze: gdb: Extend the number of registers presented to
GDB
target/microblaze: gdb: Fix incorrect SReg reporting target/microblaze: monitor: Increase the number of registers reported

 configure                     |   1 +
 target/microblaze/cpu.c       |   6 +-
 target/microblaze/cpu.h       |   9 ++
 target/microblaze/gdbstub.c   | 214 +++++++++++++++++++++++++++++++++++++++++-
 target/microblaze/translate.c |  16 +++-
 5 files changed, 240 insertions(+), 6 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 target/microblaze: gdb: Add dynamic GDB XML register support

Add dynamic GDB register XML for Microblaze, and modify the config file to use XML when building for Microblaze.
For the dynamic XML to be read, there still needs to be a core XML file.

---
 configure                   |   1 +
 target/microblaze/cpu.c     |   4 ++
 target/microblaze/cpu.h     |   9 ++++
 target/microblaze/gdbstub.c | 123 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 137 insertions(+)
configure +1 -0
index 0d69c36..5a099b6 100755
@@ -7832,6 +7832,7 @@ case "$target_name" in
     TARGET_ARCH=microblaze
     TARGET_SYSTBL_ABI=common
     bflt="yes"
+    gdb_xml_files="microblaze-core.xml"
     echo "TARGET_ABI32=y" >> $config_target_mak
   ;;
   mips|mipsel)
target/microblaze/cpu.c +4 -0
index aa99830..41cac1b 100644
@@ -226,6 +226,8 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp)
     env->pvr.regs[11] = (cpu->cfg.use_mmu ? PVR11_USE_MMU : 0) |
                         16 << 17;
 
+    mb_gen_dynamic_xml(cpu);
+
     mcc->parent_realize(dev, errp);
 }
 
@@ -330,6 +332,8 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
     dc->vmsd = &vmstate_mb_cpu;
     device_class_set_props(dc, mb_properties);
     cc->gdb_num_core_regs = 32 + 5;
+    cc->gdb_get_dynamic_xml = mb_gdb_get_dynamic_xml;
+    cc->gdb_core_xml_file = "microblaze-core.xml";
 
     cc->disas_set_info = mb_disas_set_info;
     cc->tcg_initialize = mb_tcg_init;
target/microblaze/cpu.h +9 -0
index a31134b..074a18e 100644
@@ -25,6 +25,8 @@
 #include "fpu/softfloat-types.h"
 
 typedef struct CPUMBState CPUMBState;
+typedef struct DynamicMBGDBXMLInfo DynamicMBGDBXMLInfo;
+
 #if !defined(CONFIG_USER_ONLY)
 #include "mmu.h"
 #endif
@@ -272,6 +274,10 @@ struct CPUMBState {
     } pvr;
 };
 
+struct DynamicMBGDBXMLInfo {
+    char *xml;
+};
+
 /**
  * MicroBlazeCPU:
  * @env: #CPUMBState
@@ -286,6 +292,7 @@ struct MicroBlazeCPU {
 
     CPUNegativeOffsetState neg;
     CPUMBState env;
+    DynamicMBGDBXMLInfo dyn_xml;
 
     /* Microblaze Configuration Settings */
     struct {
@@ -321,6 +328,8 @@ void mb_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
 hwaddr mb_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 int mb_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
 int mb_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
+void mb_gen_dynamic_xml(MicroBlazeCPU *cpu);
+const char *mb_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname);
 
 void mb_tcg_init(void);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
target/microblaze/gdbstub.c +123 -0

126 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/4 target/microblaze: gdb: Extend the number of registers presented to GDB

In reply to Joe Komlodi

Increase the number of Microblaze registers QEMU will report when talking to GDB.

---
 target/microblaze/cpu.c     |  2 +-
 target/microblaze/gdbstub.c | 52 ++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 50 insertions(+), 4 deletions(-)
target/microblaze/cpu.c +1 -1
index 41cac1b..5b6ad5b 100644
@@ -331,7 +331,7 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
 #endif
     dc->vmsd = &vmstate_mb_cpu;
     device_class_set_props(dc, mb_properties);
-    cc->gdb_num_core_regs = 32 + 5;
+    cc->gdb_num_core_regs = 32 + 27;
     cc->gdb_get_dynamic_xml = mb_gdb_get_dynamic_xml;
     cc->gdb_core_xml_file = "microblaze-core.xml";
 
target/microblaze/gdbstub.c +49 -3

68 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/4 target/microblaze: gdb: Fix incorrect SReg reporting

In reply to Joe Komlodi

SRegs used to be reported to GDB by iterating over the SRegs array, however we do not store them in an order that allows them to be reported to GDB in that way.

To fix this, a simple map is used to map the register GDB wants to its location in the SRegs array.

---
 target/microblaze/gdbstub.c | 59 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 49 insertions(+), 10 deletions(-)
target/microblaze/gdbstub.c +49 -10
index af29f00..485b717 100644
@@ -25,6 +25,21 @@ int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
 {
     MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
     CPUMBState *env = &cpu->env;
+    /*
+     * GDB expects SREGs in the following order:
+     * PC, MSR, EAR, ESR, FSR, BTR, EDR, PID, ZPR, TLBX, TLBSX, TLBLO, TLBHI.
+     * They aren't stored in this order, so make a map.
+     * PID, ZPR, TLBx, TLBsx, TLBLO, and TLBHI aren't modeled, so we don't
+     * map them to anything and return a value of 0 instead.
+     */
+    static const uint8_t sreg_map[6] = {
+        SR_PC,
+        SR_MSR,
+        SR_EAR,
+        SR_ESR,
+        SR_FSR,
+        SR_BTR
+    };
 
     /*
      * GDB expects registers to be reported in this order:
@@ -40,15 +55,16 @@ int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
         n -= 32;
         switch (n) {
         case 0 ... 5:
-            return gdb_get_reg32(mem_buf, env->sregs[n]);
+            return gdb_get_reg32(mem_buf, env->sregs[sreg_map[n]]);
         /* PVR12 is intentionally skipped */
         case 6 ... 17:
             n -= 6;
             return gdb_get_reg32(mem_buf, env->pvr.regs[n]);
-        case 18 ... 24:
-            /* Add an offset of 6 to resume where we left off with SRegs */
-            n = n - 18 + 6;
-            return gdb_get_reg32(mem_buf, env->sregs[n]);
+        case 18:
+            return gdb_get_reg32(mem_buf, env->sregs[SR_EDR]);
+        /* Other SRegs aren't modeled, so report a value of 0 */
+        case 19 ... 24:
+            return gdb_get_reg32(mem_buf, 0);
         case 25:
             return gdb_get_reg32(mem_buf, env->slr);
         case 26:
@@ -66,29 +82,52 @@ int mb_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     CPUMBState *env = &cpu->env;
     uint32_t tmp;
 
+    /*
+     * GDB expects SREGs in the following order:
+     * PC, MSR, EAR, ESR, FSR, BTR, EDR, PID, ZPR, TLBX, TLBSX, TLBLO, TLBHI.
+     * They aren't stored in this order, so make a map.
+     * PID, ZPR, TLBx, TLBsx, TLBLO, and TLBHI aren't modeled, so we don't
+     * map them to anything.
+     */
+    static const uint8_t sreg_map[6] = {
+        SR_PC,
+        SR_MSR,
+        SR_EAR,
+        SR_ESR,
+        SR_FSR,
+        SR_BTR
+    };
+
     if (n > cc->gdb_num_core_regs) {
         return 0;
     }
 
     tmp = ldl_p(mem_buf);
 
+    /*
+     * GDB expects registers to be reported in this order:
+     * R0-R31
+     * PC-BTR
+     * PVR0-PVR11
+     * EDR-TLBHI
+     * SLR-SHR
+     */
     if (n < 32) {
         env->regs[n] = tmp;
     } else {
         n -= 32;
         switch (n) {
         case 0 ... 5:
-            env->sregs[n] = tmp;
+            env->sregs[sreg_map[n]] = tmp;
             break;
         /* PVR12 is intentionally skipped */
         case 6 ... 17:
             n -= 6;
             env->pvr.regs[n] = tmp;
             break;
-        case 18 ... 24:
-            /* Add an offset of 6 to resume where we left off with SRegs */
-            n = n - 18 + 6;
-            env->sregs[n] = tmp;
+        /* Only EDR is modeled in these indeces, so ignore the rest */
+        case 18:
+            env->sregs[SR_EDR] = tmp;
             break;
         case 25:
             env->slr = tmp;
Signature · 1 line
2.7.4
#4 lore raw

PATCH 4/4 target/microblaze: monitor: Increase the number of registers reported

In reply to Joe Komlodi

Increase the number of registers reported to match GDB.

Registers that aren't modeled are reported as 0.

---
 target/microblaze/translate.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
target/microblaze/translate.c +14 -2
index 20b7427..4e7f903a 100644
@@ -1788,9 +1788,11 @@ void mb_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     qemu_fprintf(f, "IN: PC=%" PRIx64 " %s\n",
                  env->sregs[SR_PC], lookup_symbol(env->sregs[SR_PC]));
     qemu_fprintf(f, "rmsr=%" PRIx64 " resr=%" PRIx64 " rear=%" PRIx64 " "
-                 "debug=%x imm=%x iflags=%x fsr=%" PRIx64 "\n",
+                 "debug=%x imm=%x iflags=%x fsr=%" PRIx64 " "
+                 "rbtr=%" PRIx64 "\n",
                  env->sregs[SR_MSR], env->sregs[SR_ESR], env->sregs[SR_EAR],
-                 env->debug, env->imm, env->iflags, env->sregs[SR_FSR]);
+                 env->debug, env->imm, env->iflags, env->sregs[SR_FSR],
+                 env->sregs[SR_BTR]);
     qemu_fprintf(f, "btaken=%d btarget=%" PRIx64 " mode=%s(saved=%s) "
                  "eip=%d ie=%d\n",
                  env->btaken, env->btarget,
@@ -1798,7 +1800,17 @@ void mb_cpu_dump_state(CPUState *cs, FILE *f, int flags)
                  (env->sregs[SR_MSR] & MSR_UMS) ? "user" : "kernel",
                  (bool)(env->sregs[SR_MSR] & MSR_EIP),
                  (bool)(env->sregs[SR_MSR] & MSR_IE));
+    for (i = 0; i < 12; i++) {
+        qemu_fprintf(f, "rpvr%2.2d=%8.8x ", i, env->pvr.regs[i]);
+        if ((i + 1) % 4 == 0) {
+            qemu_fprintf(f, "\n");
+        }
+    }
 
+    /* Registers that aren't modeled are reported as 0 */
+    qemu_fprintf(f, "redr=%" PRIx64 " rpid=0 rzpr=0 rtlbx=0 rtlbsx=0 "
+                    "rtlblo=0 rtlbhi=0\n", env->sregs[SR_EDR]);
+    qemu_fprintf(f, "slr=%x shr=%x\n", env->slr, env->shr);
     for (i = 0; i < 32; i++) {
         qemu_fprintf(f, "r%2.2d=%8.8x ", i, env->regs[i]);
         if ((i + 1) % 4 == 0)
Signature · 1 line
2.7.4
Reviewed-by on the v1 series
#5 lore raw
In reply to Joe Komlodi
Quoted 8 lines · Joe Komlodi

Hi all,

This series adds dynamic GDB XML support for Micraoblaze CPUs, and fixes an issue when reporting Microblaze SRegs through GDB.

The SRegs used to be printed out by iterating over the SReg array, but the SReg array isn't laid out in memory in the same order that GDB expects them.

Quoted 6 lines

When reporting register to GDB, note that even though 32-bit Microblaze supports having certain registers wider than 32-bits, we're repoting all of them as being 32-bits wide right now to maintain compatibility with GDB.

Thanks!
Joe

Thanks Joe!

Quoted 18 lines

Joe Komlodi (4):
target/microblaze: gdb: Add dynamic GDB XML register support target/microblaze: gdb: Extend the number of registers presented to
GDB
target/microblaze: gdb: Fix incorrect SReg reporting target/microblaze: monitor: Increase the number of registers reported

 configure                     |   1 +
 target/microblaze/cpu.c       |   6 +-
 target/microblaze/cpu.h       |   9 ++
 target/microblaze/gdbstub.c   | 214 +++++++++++++++++++++++++++++++++++++++++-
 target/microblaze/translate.c |  16 +++-
 5 files changed, 240 insertions(+), 6 deletions(-)
Signature · 1 line
2.7.4
#6 lore raw
In reply to Joe Komlodi
Quoted 8 lines · Joe Komlodi

Hi all,

This series adds dynamic GDB XML support for Micraoblaze CPUs, and fixes an issue when reporting Microblaze SRegs through GDB.

The SRegs used to be printed out by iterating over the SReg array, but the SReg array isn't laid out in memory in the same order that GDB expects them.

Quoted 6 lines

When reporting register to GDB, note that even though 32-bit Microblaze supports having certain registers wider than 32-bits, we're repoting all of them as being 32-bits wide right now to maintain compatibility with GDB.

Thanks!
Joe

Hi Joe,

Looks like you forgot the patch that adds the xml file?

Thanks,
Edgar

Quoted 18 lines

Joe Komlodi (4):
target/microblaze: gdb: Add dynamic GDB XML register support target/microblaze: gdb: Extend the number of registers presented to
GDB
target/microblaze: gdb: Fix incorrect SReg reporting target/microblaze: monitor: Increase the number of registers reported

 configure                     |   1 +
 target/microblaze/cpu.c       |   6 +-
 target/microblaze/cpu.h       |   9 ++
 target/microblaze/gdbstub.c   | 214 +++++++++++++++++++++++++++++++++++++++++-
 target/microblaze/translate.c |  16 +++-
 5 files changed, 240 insertions(+), 6 deletions(-)
Signature · 1 line
2.7.4
#7 lore raw

Hi Edgar,

Ah, I did. It was in my directory but didn't get added to git. It should have been part of the first patch.

I'll add it to the first patch and send up a v2.

Thanks!
Joe

-----Original Message-----
From: Edgar E. Iglesias <[email protected]>
Sent: Wednesday, May 13, 2020 10:29 AM
To: Joe Komlodi <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v1 0/4] target/microblaze: Add dynamic GDB XML and correct SReg reporting

Quoted 8 lines · Joe Komlodi

Hi all,

This series adds dynamic GDB XML support for Micraoblaze CPUs, and fixes an issue when reporting Microblaze SRegs through GDB.

The SRegs used to be printed out by iterating over the SReg array, but the SReg array isn't laid out in memory in the same order that GDB expects them.

Quoted 6 lines

When reporting register to GDB, note that even though 32-bit
Microblaze supports having certain registers wider than 32-bits, we're repoting all of them as being 32-bits wide right now to maintain compatibility with GDB.

Thanks!
Joe

Hi Joe,

Looks like you forgot the patch that adds the xml file?

Thanks,
Edgar

Quoted 19 lines

Joe Komlodi (4):
target/microblaze: gdb: Add dynamic GDB XML register support target/microblaze: gdb: Extend the number of registers presented to
GDB
target/microblaze: gdb: Fix incorrect SReg reporting target/microblaze: monitor: Increase the number of registers
reported

 configure                     |   1 +
 target/microblaze/cpu.c       |   6 +-
 target/microblaze/cpu.h       |   9 ++
 target/microblaze/gdbstub.c   | 214 +++++++++++++++++++++++++++++++++++++++++-
 target/microblaze/translate.c |  16 +++-
 5 files changed, 240 insertions(+), 6 deletions(-)

--
2.7.4