Skip to contentSkip to conversation

target/arm: Added support for SME register exposure to GDB

PATCH Superseded Vacha Bhavsar 2 participants 3 messages Jul 14, 2025

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target/arm: Added support for SME register exposure to GDB

The QEMU GDB stub does not expose the ZA storage SME register to GDB via the remote serial protocol, which can be a useful functionality to debug SME code. To provide this functionality in Aarch64 target, this patch registers the SME register set with the GDB stub. To do so, this patch implements the aarch64_gdb_get_sme_reg() and aarch64_gdb_set_sme_reg() functions to specify how to get and set the SME registers, and the arm_gen_dynamic_smereg_feature() function to generate the target description in XML format to indicate the target architecture supports SME. Finally, this patch includes a dyn_smereg_feature structure to hold this GDB XML description of the SME registers for each CPU.

---
Changes since v1:
- Removed unnecessary comments in aarch64_gdb_set_sme_reg() regarding the zregs
- Used aarch64_set_svcr to correctly set the 64 bit SVCR in aarch64_gdb_set_sme_reg()
- Corrected typo in comment in aarch64_gdb_set_sme_reg() and aarch64_gdb_get_sme_reg()

 target/arm/cpu.h       |   1 +
 target/arm/gdbstub.c   |   6 +++
 target/arm/gdbstub64.c | 118 +++++++++++++++++++++++++++++++++++++++++
 target/arm/internals.h |   3 ++
 4 files changed, 128 insertions(+)
target/arm/cpu.h +1 -0
index dc9b6dce4c..8bd66d7049 100644
@@ -933,6 +933,7 @@ struct ArchCPU {
 
     DynamicGDBFeatureInfo dyn_sysreg_feature;
     DynamicGDBFeatureInfo dyn_svereg_feature;
+    DynamicGDBFeatureInfo dyn_smereg_feature;
     DynamicGDBFeatureInfo dyn_m_systemreg_feature;
     DynamicGDBFeatureInfo dyn_m_secextreg_feature;
 
target/arm/gdbstub.c +6 -0
index ce4497ad7c..9c942c77cc 100644
@@ -531,6 +531,12 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
             GDBFeature *feature = arm_gen_dynamic_svereg_feature(cs, cs->gdb_num_regs);
             gdb_register_coprocessor(cs, aarch64_gdb_get_sve_reg,
                                      aarch64_gdb_set_sve_reg, feature, 0);
+            if (isar_feature_aa64_sme(&cpu->isar)) {
+                GDBFeature *sme_feature = arm_gen_dynamic_smereg_feature(cs,
+                                             cs->gdb_num_regs);
+                gdb_register_coprocessor(cs, aarch64_gdb_get_sme_reg,
+                    aarch64_gdb_set_sme_reg, sme_feature, 0);
+            }
         } else {
             gdb_register_coprocessor(cs, aarch64_gdb_get_fpu_reg,
                                      aarch64_gdb_set_fpu_reg,
target/arm/gdbstub64.c +118 -0

130 lines not on this page · raw message

target/arm/internals.h +3 -0
index c4765e4489..760e1c6490 100644
@@ -1808,8 +1808,11 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env)
 }
 
 GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cpu, int base_reg);
+GDBFeature *arm_gen_dynamic_smereg_feature(CPUState *cpu, int base_reg);
 int aarch64_gdb_get_sve_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg);
+int aarch64_gdb_get_sme_reg(CPUState *cs, GByteArray *buf, int reg);
+int aarch64_gdb_set_sme_reg(CPUState *cs, uint8_t *buf, int reg);
 int aarch64_gdb_get_fpu_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_fpu_reg(CPUState *cs, uint8_t *buf, int reg);
 int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg);
Signature · 1 line
2.34.1
#1 lore raw

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 235

Quoted 13 lines · Vacha Bhavsar
target/arm/gdbstub64.c +5 -0
index 64ee9b3b56..c39d636caa 100644
@@ -228,6 +228,87 @@ int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)
      return 0;
  }
 
+int aarch64_gdb_get_sme_reg(CPUState *cs, GByteArray *buf, int reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+    bool streaming_mode = ((env->svcr & 0x01) != 0);

env->svcr & R_SVCR_SM_MASK, although perhaps

Quoted 4 lines
target/arm/gdbstub64.c +4 -0
+
+    switch (reg) {
+    /* Svg register */
+    case 0:

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 249

Quoted 10 lines
target/arm/gdbstub64.c +10 -0
+    {
+        int vq;
+        if (streaming_mode) {
+            vq = sve_vqm1_for_el_sm(env, arm_current_el(env),
+                     streaming_mode) + 1;
+        } else {
+            vq = 0;
+        }
+        /* svg = vector granules (2 * vector quardwords) in streaming mode */
+        return gdb_get_reg64(buf, vq * 2);
    int vq = 0;
    if (FIELD_EX64(env->svcr, SVCR, SM)) {
        vq = ...
    }

is clearer.

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 257

Quoted 8 lines
target/arm/gdbstub64.c +8 -0
+    }
+    case 1:
+        return gdb_get_reg64(buf, env->svcr);
+    case 2:
+    {
+        int q;
+        int len = 0;
+        int vq = cpu->sve_max_vq;

sme_max_vq.

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 260

Quoted 3 lines
target/arm/gdbstub64.c +3 -0
+        int svl = vq * 16;
+        for (int i = 0; i < svl; i++) {
+            for (q = 0; q < vq; q++) {

for (int q = 0

Quoted 17 lines
target/arm/gdbstub64.c +17 -0
+                len += gdb_get_reg128(buf,
+                           env->za_state.za[i].d[q * 2 + 1],
+                           env->za_state.za[i].d[q * 2]);
+            }
+        }
+        return len;
+    }
+    default:
+        /* gdbstub asked for something out of range */
+        qemu_log_mask(LOG_UNIMP, "%s: out of range register %d", __func__, reg);
+        break;
+    }
+
+    return 0;
+}
+
+int aarch64_gdb_set_sme_reg(CPUState *cs, uint8_t *buf, int reg)

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 287

Quoted 10 lines
target/arm/gdbstub64.c +10 -0
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    switch (reg) {
+    case 0:
+    {
+        /* cannot set svg via gdbstub */
+        return 0;
+    }

I think you return 8 anyway to ignore.

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 289

Quoted 2 lines
target/arm/gdbstub64.c +2 -0
+    case 1:
+        aarch64_set_svcr(env, *(uint64_t *)buf,

ldq_le_p(buf)

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 294

Quoted 5 lines
target/arm/gdbstub64.c +5 -0
+            R_SVCR_SM_MASK | R_SVCR_ZA_MASK);
+        return 8;
+    case 2:
+        int vq, len = 0;
+        int svl = cpu->sve_max_vq * 16;

sme_max_vq.

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 297

Quoted 3 lines
target/arm/gdbstub64.c +3 -0
+        uint64_t *p = (uint64_t *) buf;
+        for (int i = 0; i < svl; i++) {
+            for (vq = 0; vq < cpu->sve_max_vq; vq++) {

Mirror the q/vq loop from above.

Quoted 18 lines
target/arm/gdbstub64.c +14 -0
+                env->za_state.za[i].d[vq * 2 + 1] = *p++;
+                env->za_state.za[i].d[vq * 2] = *p++;
+                len += 16;
+            }
+        }
+        return len;
+    default:
+        /* gdbstub asked for something out of range */
+        break;
+    }
+
+    return 0;
+}
+
  int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg)
  {
      ARMCPU *cpu = ARM_CPU(cs);

target/arm/gdbstub64.c GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg) · line 479

Quoted 7 lines
target/arm/gdbstub64.c +4 -0
@@ -392,6 +473,43 @@ GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg)
      return &cpu->dyn_svereg_feature.desc;
  }
 
+GDBFeature *arm_gen_dynamic_smereg_feature(CPUState *cs, int base_reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    int vq = cpu->sve_max_vq;

sme_max_vq.

r~

#2 lore raw

Hi Richard,

Thank you for the feedback! I have sent an updated version your way with the suggested changes!

Thanks,
Vacha

Quoted 141 lines · Richard Henderson

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t

Quoted 5 lines · Vacha Bhavsar
target/arm/gdbstub64.c +0 -0
index 64ee9b3b56..c39d636caa 100644
@@ -228,6 +228,87 @@ int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t

*buf, int reg)

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 235

Quoted 8 lines
target/arm/gdbstub64.c +5 -0
      return 0;
  }
 
+int aarch64_gdb_get_sme_reg(CPUState *cs, GByteArray *buf, int reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+    bool streaming_mode = ((env->svcr & 0x01) != 0);

env->svcr & R_SVCR_SM_MASK, although perhaps

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)

Quoted 13 lines
target/arm/gdbstub64.c +13 -0
+
+    switch (reg) {
+    /* Svg register */
+    case 0:
+    {
+        int vq;
+        if (streaming_mode) {
+            vq = sve_vqm1_for_el_sm(env, arm_current_el(env),
+                     streaming_mode) + 1;
+        } else {
+            vq = 0;
+        }
+        /* svg = vector granules (2 * vector quardwords) in streaming

mode */

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 249

Quoted 1 line
target/arm/gdbstub64.c +1 -0
+        return gdb_get_reg64(buf, vq * 2);
     int vq = 0;
     if (FIELD_EX64(env->svcr, SVCR, SM)) {
         vq = ...
     }

is clearer.

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 257

Quoted 8 lines
target/arm/gdbstub64.c +8 -0
+    }
+    case 1:
+        return gdb_get_reg64(buf, env->svcr);
+    case 2:
+    {
+        int q;
+        int len = 0;
+        int vq = cpu->sve_max_vq;

sme_max_vq.

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 260

Quoted 3 lines
target/arm/gdbstub64.c +3 -0
+        int svl = vq * 16;
+        for (int i = 0; i < svl; i++) {
+            for (q = 0; q < vq; q++) {

for (int q = 0

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg)

Quoted 10 lines
target/arm/gdbstub64.c +10 -0
+                len += gdb_get_reg128(buf,
+                           env->za_state.za[i].d[q * 2 + 1],
+                           env->za_state.za[i].d[q * 2]);
+            }
+        }
+        return len;
+    }
+    default:
+        /* gdbstub asked for something out of range */
+        qemu_log_mask(LOG_UNIMP, "%s: out of range register %d",

__func__, reg);

Quoted 7 lines
target/arm/gdbstub64.c +7 -0
+        break;
+    }
+
+    return 0;
+}
+
+int aarch64_gdb_set_sme_reg(CPUState *cs, uint8_t *buf, int reg)

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 287

Quoted 10 lines
target/arm/gdbstub64.c +10 -0
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    switch (reg) {
+    case 0:
+    {
+        /* cannot set svg via gdbstub */
+        return 0;
+    }

I think you return 8 anyway to ignore.

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t · line 289

Quoted 2 lines
target/arm/gdbstub64.c +2 -0
+    case 1:
+        aarch64_set_svcr(env, *(uint64_t *)buf,

ldq_le_p(buf)

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 294

Quoted 5 lines
target/arm/gdbstub64.c +5 -0
+            R_SVCR_SM_MASK | R_SVCR_ZA_MASK);
+        return 8;
+    case 2:
+        int vq, len = 0;
+        int svl = cpu->sve_max_vq * 16;

sme_max_vq.

target/arm/gdbstub64.c int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) · line 297

Quoted 3 lines
target/arm/gdbstub64.c +3 -0
+        uint64_t *p = (uint64_t *) buf;
+        for (int i = 0; i < svl; i++) {
+            for (vq = 0; vq < cpu->sve_max_vq; vq++) {

Mirror the q/vq loop from above.

target/arm/gdbstub64.c GDBFeature *arm_gen_dynamic_svereg_feature(CPUState

Quoted 18 lines
target/arm/gdbstub64.c +14 -0
+                env->za_state.za[i].d[vq * 2 + 1] = *p++;
+                env->za_state.za[i].d[vq * 2] = *p++;
+                len += 16;
+            }
+        }
+        return len;
+    default:
+        /* gdbstub asked for something out of range */
+        break;
+    }
+
+    return 0;
+}
+
  int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg)
  {
      ARMCPU *cpu = ARM_CPU(cs);
@@ -392,6 +473,43 @@ GDBFeature *arm_gen_dynamic_svereg_feature(CPUState

*cs, int base_reg)

target/arm/gdbstub64.c GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cs, int base_reg) · line 479

Quoted 7 lines
target/arm/gdbstub64.c +4 -0
      return &cpu->dyn_svereg_feature.desc;
  }
 
+GDBFeature *arm_gen_dynamic_smereg_feature(CPUState *cs, int base_reg)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    int vq = cpu->sve_max_vq;

sme_max_vq.

r~