From dda6df5ce5cea9245a8e39fc8ba603f29bbfbd52 Mon Sep 17 00:00:00 2001 From: Marco Liebel Date: Thu, 29 Oct 2026 10:44:11 -0700 Subject: [PATCH] target/hexagon: expose HLX registers through the gdbstub Add GDB register access for the active HLX context and register the feature for V85 CPUs with HLX support. Signed-off-by: Marco Liebel Reviewed-by: Brian Cain Signed-off-by: Brian Cain --- configs/targets/hexagon-linux-user.mak | 2 +- configs/targets/hexagon-softmmu.mak | 2 +- gdbstub/gdb-xml/hexagon-hlx.xml | 51 ++++++++++++++++++++++++++ target/hexagon/cpu.c | 18 +++++++++ target/hexagon/gdbstub.c | 46 +++++++++++++++++++++++ target/hexagon/internal.h | 2 + 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 gdbstub/gdb-xml/hexagon-hlx.xml diff --git a/configs/targets/hexagon-linux-user.mak b/configs/targets/hexagon-linux-user.mak index 51fde5d60e..10ae1943a5 100644 --- a/configs/targets/hexagon-linux-user.mak +++ b/configs/targets/hexagon-linux-user.mak @@ -1,5 +1,5 @@ TARGET_ARCH=hexagon -TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml +TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml hexagon-hlx.xml TARGET_SYSTBL=syscall.tbl TARGET_SYSTBL_ABI=common,32,hexagon,time32,stat64,rlimit,renameat TARGET_LONG_BITS=32 diff --git a/configs/targets/hexagon-softmmu.mak b/configs/targets/hexagon-softmmu.mak index 1ba6420d20..8c3a9cd4b1 100644 --- a/configs/targets/hexagon-softmmu.mak +++ b/configs/targets/hexagon-softmmu.mak @@ -1,7 +1,7 @@ # Default configuration for hexagon-softmmu TARGET_ARCH=hexagon -TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml hexagon-sys.xml +TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml hexagon-sys.xml hexagon-hlx.xml TARGET_LONG_BITS=32 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y diff --git a/gdbstub/gdb-xml/hexagon-hlx.xml b/gdbstub/gdb-xml/hexagon-hlx.xml new file mode 100644 index 0000000000..91040762ea --- /dev/null +++ b/gdbstub/gdb-xml/hexagon-hlx.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index c87e6c1a73..fec57e6fd4 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -540,6 +540,18 @@ static void hexagon_cpu_disas_set_info(const CPUState *cs, info->target_info = &cpu->cfg; } +static bool hexagon_cpu_has_hlx(HexagonCPU *cpu) +{ + if (cpu->cfg.hex_def->hex_version < HEX_VER_V85) { + return false; + } +#ifdef CONFIG_USER_ONLY + return true; +#else + return cpu->hlx && cpu->hlx->num_contexts > 0; +#endif +} + static void hexagon_cpu_realize(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); @@ -559,6 +571,12 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp) hexagon_hvx_gdb_write_register, gdb_find_static_feature("hexagon-hvx.xml")); + if (hexagon_cpu_has_hlx(cpu)) { + gdb_register_coprocessor(cs, hexagon_hlx_gdb_read_register, + hexagon_hlx_gdb_write_register, + gdb_find_static_feature("hexagon-hlx.xml")); + } + #ifndef CONFIG_USER_ONLY gdb_register_coprocessor(cs, hexagon_sys_gdb_read_register, hexagon_sys_gdb_write_register, diff --git a/target/hexagon/gdbstub.c b/target/hexagon/gdbstub.c index 5b79e42c4d..1065f3a826 100644 --- a/target/hexagon/gdbstub.c +++ b/target/hexagon/gdbstub.c @@ -217,3 +217,49 @@ int hexagon_hvx_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) g_assert_not_reached(); } + +int hexagon_hlx_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +{ + CPUHexagonState *env = cpu_env(cs); + int total = 0; + + BQL_LOCK_GUARD(); + + if (n < 0 || n >= NUM_LREGS) { + g_assert_not_reached(); + } + + /* Return zeroes when no HLX context is active. */ + if (env->hlx_ctx == NULL) { + for (int i = 0; i < HLX_VEC_SIZE_BYTES; i++) { + g_byte_array_append(mem_buf, (const guint8 *)"\0", 1); + } + return HLX_VEC_SIZE_BYTES; + } + + for (int i = 0; i < (int)ARRAY_SIZE(env->hlx_ctx->LRegs[n].uw); i++) { + total += gdb_get_reg32(mem_buf, env->hlx_ctx->LRegs[n].uw[i]); + } + return total; +} + +int hexagon_hlx_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +{ + CPUHexagonState *env = cpu_env(cs); + BQL_LOCK_GUARD(); + + if (n < 0 || n >= NUM_LREGS) { + g_assert_not_reached(); + } + + /* Ignore writes without an active context. */ + if (env->hlx_ctx == NULL) { + return HLX_VEC_SIZE_BYTES; + } + + for (int i = 0; i < (int)ARRAY_SIZE(env->hlx_ctx->LRegs[n].uw); i++) { + env->hlx_ctx->LRegs[n].uw[i] = ldl_le_p(mem_buf); + mem_buf += 4; + } + return HLX_VEC_SIZE_BYTES; +} diff --git a/target/hexagon/internal.h b/target/hexagon/internal.h index 073de10284..6def331a83 100644 --- a/target/hexagon/internal.h +++ b/target/hexagon/internal.h @@ -24,6 +24,8 @@ 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); +int hexagon_hlx_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n); +int hexagon_hlx_gdb_write_register(CPUState *cs, 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);