Skip to contentSkip to conversation

hexagon: sys+guest regs in gdbstub

PATCH Superseded Brian Cain 3 participants 8 messages Sep 30 – Oct 5

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

cover hexagon: sys+guest regs in gdbstub

Add support for reading/writing system/guest registers in the gdbstub.

Brian Cain (2):
gdbstub/gdb-xml: Add hexagon sys regs
target/hexagon: gdbstub - Add sys reg support

 configs/targets/hexagon-softmmu.mak |   2 +-
 target/hexagon/cpu.h                |   1 +
 target/hexagon/internal.h           |   4 +
 target/hexagon/cpu.c                |  14 +++
 target/hexagon/gdbstub.c            |  68 ++++++++++++
 gdbstub/gdb-xml/hexagon-sys.xml     | 157 ++++++++++++++++++++++++++++
 6 files changed, 245 insertions(+), 1 deletion(-)
 create mode 100644 gdbstub/gdb-xml/hexagon-sys.xml
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 gdbstub/gdb-xml: Add hexagon sys regs

Add the hexagon-sys.xml gdb feature describing the system and guest registers.

---
 configs/targets/hexagon-softmmu.mak |   2 +-
 gdbstub/gdb-xml/hexagon-sys.xml     | 157 ++++++++++++++++++++++++++++
 2 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 gdbstub/gdb-xml/hexagon-sys.xml
configs/targets/hexagon-softmmu.mak +1 -1
index 6cbdc64be56..1ba6420d205 100644
@@ -1,7 +1,7 @@
 # Default configuration for hexagon-softmmu
 
 TARGET_ARCH=hexagon
-TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml
+TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml hexagon-sys.xml
 TARGET_LONG_BITS=32
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
 TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
gdbstub/gdb-xml/hexagon-sys.xml new file +157 -0

157 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] gdbstub/gdb-xml: Add hexagon sys regs

Quoted 31 lines · Brian Cain

Add the hexagon-sys.xml gdb feature describing the system and guest registers.

---
 configs/targets/hexagon-softmmu.mak |   2 +-
 gdbstub/gdb-xml/hexagon-sys.xml     | 157 ++++++++++++++++++++++++++++
 2 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 gdbstub/gdb-xml/hexagon-sys.xml
configs/targets/hexagon-softmmu.mak +1 -1
index 6cbdc64be56..1ba6420d205 100644
@@ -1,7 +1,7 @@
 # Default configuration for hexagon-softmmu
 
 TARGET_ARCH=hexagon
-TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml
+TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml hexagon-sys.xml
 TARGET_LONG_BITS=32
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
 TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
gdbstub/gdb-xml/hexagon-sys.xml new file +2 -0
new file mode 100644
index 00000000000..434f11c0747
@@ -0,0 +1,157 @@
+<?xml version="1.0"?>
+<!--

gdbstub/gdb-xml/hexagon-sys.xml line 12

Quoted 10 lines
gdbstub/gdb-xml/hexagon-sys.xml new file +10 -0
+  Copyright(c) 2023-2025 Qualcomm Innovation Center, Inc. All Rights Reserved.
+
+  SPDX-License-Identifier: GPL-2.0-or-later
+
+  Note: this file is intended to be use with LLDB, so it contains fields
+  that may be unknown to GDB. For more information on such fields, please
+  see:
+  https://github.com/llvm/llvm-project/blob/287aa6c4536408413b860e61fca0318a27214cf3/lldb/docs/lldb-gdb-remote.txt#L738-L860
+  https://github.com/llvm/llvm-project/blob/287aa6c4536408413b860e61fca0318a27214cf3/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp#L4275-L4335
+-->

small nit - could we reference a specific llvm version (tag) instead of a commit?

For the rest,

Regards,
Pierrick

author
#3 lore raw

Re: [PATCH 1/2] gdbstub/gdb-xml: Add hexagon sys regs

Quoted 36 lines · Pierrick Bouvier
Quoted 35 lines · Brian Cain

Add the hexagon-sys.xml gdb feature describing the system and guest registers.

---
  configs/targets/hexagon-softmmu.mak |   2 +-
  gdbstub/gdb-xml/hexagon-sys.xml     | 157 ++++++++++++++++++++++++++++
  2 files changed, 158 insertions(+), 1 deletion(-)

create mode 100644 gdbstub/gdb-xml/hexagon-sys.xml

configs/targets/hexagon-softmmu.mak +1 -1
index 6cbdc64be56..1ba6420d205 100644
@@ -1,7 +1,7 @@
  # Default configuration for hexagon-softmmu
 
  TARGET_ARCH=hexagon
-TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml
+TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml hexagon-sys.xml
  TARGET_LONG_BITS=32
  TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
  TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
gdbstub/gdb-xml/hexagon-sys.xml new file +6 -0
new file mode 100644
index 00000000000..434f11c0747
@@ -0,0 +1,157 @@
+<?xml version="1.0"?>
+<!--
+  Copyright(c) 2023-2025 Qualcomm Innovation Center, Inc. All Rights Reserved.
+
+  SPDX-License-Identifier: GPL-2.0-or-later
+
Quoted 8 lines

gdbstub/gdb-xml/hexagon-sys.xml line 12

Quoted 6 lines
gdbstub/gdb-xml/hexagon-sys.xml new file +6 -0
+  Note: this file is intended to be use with LLDB, so it contains fields
+  that may be unknown to GDB. For more information on such fields, please
+  see:
+  https://github.com/llvm/llvm-project/blob/287aa6c4536408413b860e61fca0318a27214cf3/lldb/docs/lldb-gdb-remote.txt#L738-L860
+  https://github.com/llvm/llvm-project/blob/287aa6c4536408413b860e61fca0318a27214cf3/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp#L4275-L4335
+-->

small nit - could we reference a specific llvm version (tag) instead of a commit?

Ok - can do.  New URLs below are what I'll use instead:

https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0/lldb/docs/lldb-gdb-remote.txt#L738-L860

https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp#L4056-L4116

Quoted 6 lines

For the rest,

Regards,
Pierrick

author
#4 lore raw

PATCH 2/2 target/hexagon: gdbstub - Add sys reg support

In reply to Brian Cain

Add support for the system and guest registers to the gdbstub.

---
 target/hexagon/cpu.h      |  1 +
 target/hexagon/internal.h |  4 +++
 target/hexagon/cpu.c      | 14 ++++++++
 target/hexagon/gdbstub.c  | 68 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+)
target/hexagon/cpu.h +1 -0
index df4c0182247..ea54af621d2 100644
@@ -241,6 +241,7 @@ G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,
  */
 bool hexagon_thread_is_enabled(const CPUHexagonState *thread_env);
 uint32_t hexagon_greg_read(CPUHexagonState *env, uint32_t reg);
+void hexagon_greg_write(CPUHexagonState *env, uint32_t reg, uint32_t val);
 void hexagon_cpu_soft_reset(CPUHexagonState *env);
 #endif
 
target/hexagon/internal.h +4 -0
index 05d1129916e..3ed83904eb7 100644
@@ -24,6 +24,10 @@ int hexagon_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
 int hexagon_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
 int hexagon_hvx_gdb_read_register(CPUState *env, GByteArray *mem_buf, int n);
 int hexagon_hvx_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n);
+#ifndef CONFIG_USER_ONLY
+int hexagon_sys_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n);
+int hexagon_sys_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n);
+#endif
 
 void hexagon_debug_vreg(CPUHexagonState *env, int regnum);
 void hexagon_debug_qreg(CPUHexagonState *env, int regnum);
target/hexagon/cpu.c +14 -0
index 1f7d8a8df70..45eb9a5fb99 100644
@@ -494,6 +494,10 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp)
                              gdb_find_static_feature("hexagon-hvx.xml"));
 
 #ifndef CONFIG_USER_ONLY
+    gdb_register_coprocessor(cs, hexagon_sys_gdb_read_register,
+                             hexagon_sys_gdb_write_register,
+                             gdb_find_static_feature("hexagon-sys.xml"));
+
     if (!HEXAGON_CPU(dev)->tlb) {
         error_setg(errp, "hexagon cpu requires 'tlb' link property to be set");
         return;
@@ -863,6 +867,16 @@ uint32_t hexagon_greg_read(CPUHexagonState *env, uint32_t reg)
         return 0;
     }
 }
+
+void hexagon_greg_write(CPUHexagonState *env, uint32_t reg, uint32_t val)
+{
+    if (reg <= HEX_GREG_G3) {
+        env->greg[reg] = val;
+        return;
+    }
+    qemu_log_mask(LOG_UNIMP, "writing greg %" PRIu32
+            " not yet supported.\n", reg);
+}
 #endif
 
 static void hexagon_cpu_class_base_init(ObjectClass *c, const void *data)
target/hexagon/gdbstub.c +68 -0

83 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] target/hexagon: gdbstub - Add sys reg support

Quoted 10 lines · Brian Cain

Add support for the system and guest registers to the gdbstub.

---
 target/hexagon/cpu.h      |  1 +
 target/hexagon/internal.h |  4 +++
 target/hexagon/cpu.c      | 14 ++++++++
 target/hexagon/gdbstub.c  | 68 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+)
#6 lore raw

Re: [PATCH 2/2] target/hexagon: gdbstub - Add sys reg support

In reply to Brian Cain
Quoted 11 lines · Brian Cain

Add support for the system and guest registers to the gdbstub.

---
  target/hexagon/cpu.h      |  1 +
  target/hexagon/internal.h |  4 +++
  target/hexagon/cpu.c      | 14 ++++++++
  target/hexagon/gdbstub.c  | 68 +++++++++++++++++++++++++++++++++++++++
  4 files changed, 87 insertions(+)

target/hexagon/cpu.c uint32_t hexagon_greg_read(CPUHexagonState *env, uint32_t reg) · line 878

Quoted 8 lines
target/hexagon/cpu.c +8 -0
+void hexagon_greg_write(CPUHexagonState *env, uint32_t reg, uint32_t val)
+{
+    if (reg <= HEX_GREG_G3) {
+        env->greg[reg] = val;
+        return;
+    }
+    qemu_log_mask(LOG_UNIMP, "writing greg %" PRIu32
+            " not yet supported.\n", reg);

Not sure void/LOG_UNIMP is safe, LOG_UNIMP is only enabled with '-d unimp' and goes on stderr, ...

(nit misaligned style)

Quoted 17 lines
target/hexagon/gdbstub.c +15 -0
+}
 
 
+int hexagon_sys_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
+{
+    CPUHexagonState *env = cpu_env(cs);
+    HexagonCPU *cpu = env_archcpu(env);
+    BQL_LOCK_GUARD();
+
+    if (n < NUM_SREGS) {
+        uint32_t val = ldl_le_p(mem_buf);
+        if (n == HEX_SREG_SSR) {
+            uint32_t old = env->t_sreg[HEX_SREG_SSR];
+            env->t_sreg[HEX_SREG_SSR] = val;
+            hexagon_modify_ssr(env, val, old);
+        } else if (n < HEX_SREG_GLB_START) {
+            env->t_sreg[n] = val;

target/hexagon/gdbstub.c int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) · line 139

Quoted 10 lines
target/hexagon/gdbstub.c +10 -0
+        } else if (cpu->globalregs) {
+            hexagon_globalreg_write(cpu->globalregs, n, val, env->threadId);
+        }
+        return sizeof(uint32_t);
+    }
+    n -= NUM_SREGS;
+
+    if (n < NUM_GREGS) {
+        hexagon_greg_write(env, n, ldl_le_p(mem_buf));
+        return sizeof(uint32_t);

... and here we tell the user the register was correctly written.

Quoted 5 lines
target/hexagon/gdbstub.c +5 -0
+    }
+    n -= NUM_GREGS;
+
+    g_assert_not_reached();
+}
author
#7 lore raw

Re: [PATCH 2/2] target/hexagon: gdbstub - Add sys reg support

Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Brian Cain

Add support for the system and guest registers to the gdbstub.

---
  target/hexagon/cpu.h      |  1 +
  target/hexagon/internal.h |  4 +++
  target/hexagon/cpu.c      | 14 ++++++++ target/hexagon/gdbstub.c  | 68 +++++++++++++++++++++++++++++++++++++++

  4 files changed, 87 insertions(+)
Quoted 9 lines

+void hexagon_greg_write(CPUHexagonState *env, uint32_t reg, uint32_t val)
+{
+    if (reg <= HEX_GREG_G3) {
+        env->greg[reg] = val;
+        return;
+    }
+    qemu_log_mask(LOG_UNIMP, "writing greg %" PRIu32
+            " not yet supported.\n", reg);

Not sure void/LOG_UNIMP is safe, LOG_UNIMP is only enabled with '-d unimp' and goes on stderr, ...

Quoted 4 lines

(nit misaligned style)

Quoted 1 line

+}

Sorry I unintentionally omitted you from the v2, Phil.  The changes here should solve the UNIMP/returncode issues by taking another approach - just delivering the reg read/writes without the G3 guard.

https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 35 lines
Quoted 19 lines

+int hexagon_sys_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)

target/hexagon/gdbstub.c +15 -0
+{
+    CPUHexagonState *env = cpu_env(cs);
+    HexagonCPU *cpu = env_archcpu(env);
+    BQL_LOCK_GUARD();
+
+    if (n < NUM_SREGS) {
+        uint32_t val = ldl_le_p(mem_buf);
+        if (n == HEX_SREG_SSR) {
+            uint32_t old = env->t_sreg[HEX_SREG_SSR];
+            env->t_sreg[HEX_SREG_SSR] = val;
+            hexagon_modify_ssr(env, val, old);
+        } else if (n < HEX_SREG_GLB_START) {
+            env->t_sreg[n] = val;
+        } else if (cpu->globalregs) {
+            hexagon_globalreg_write(cpu->globalregs, n, val, 

env->threadId);

Quoted 8 lines

+        }
+        return sizeof(uint32_t);
+    }
+    n -= NUM_SREGS;
+
+    if (n < NUM_GREGS) {
+        hexagon_greg_write(env, n, ldl_le_p(mem_buf)); +        return sizeof(uint32_t);

... and here we tell the user the register was correctly written.

Quoted 5 lines

+    }
+    n -= NUM_GREGS;

target/hexagon/gdbstub.c +3 -0
+
+    g_assert_not_reached();
+}