We pass the Hexagon CPU version to disassemble_hexagon. This allows
decode_packet to know if the opcodes are supported.
Fix the printing of invalid packets.
Co-authored-by: Matheus Tavares Bernardino <matheus.bernardino@oss.qualcomm.com>
Co-authored-by: Brian Cain <brian.cain@oss.qualcomm.com>
Signed-off-by: Taylor Simpson <ltaylorsimpson@gmail.com>
---
target/hexagon/cpu_bits.h | 4 +++-
disas/hexagon.c | 3 ++-
target/hexagon/cpu.c | 3 +++
target/hexagon/decode.c | 20 +++++++++++++++++---
4 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/target/hexagon/cpu_bits.h b/target/hexagon/cpu_bits.h
index ff596e2a94..ba580df3c1 100644
--- a/target/hexagon/cpu_bits.h
+++ b/target/hexagon/cpu_bits.h
@@ -19,6 +19,7 @@
#define HEXAGON_CPU_BITS_H
#include "qemu/bitops.h"
+#include "cpu-qom.h"
#define PCALIGN 4
#define PCALIGN_MASK (PCALIGN - 1)
@@ -64,6 +65,7 @@ static inline bool is_packet_end(uint32_t endocing)
return ((bits == 0x3) || (bits == 0x0));
}
-int disassemble_hexagon(uint32_t *words, int nwords, bfd_vma pc, GString *buf);
+int disassemble_hexagon(uint32_t *words, int nwords, bfd_vma pc, GString *buf,
+ HexagonVersion hex_version);
#endif
diff --git a/disas/hexagon.c b/disas/hexagon.c
index c1a4ffc5f6..9a18f12854 100644
--- a/disas/hexagon.c
+++ b/disas/hexagon.c
@@ -31,6 +31,7 @@
int print_insn_hexagon(bfd_vma memaddr, struct disassemble_info *info)
{
+ HexagonVersion hex_version = (HexagonVersion)info->target_info;
uint32_t words[PACKET_WORDS_MAX];
bool found_end = false;
GString *buf;
@@ -58,7 +59,7 @@ int print_insn_hexagon(bfd_vma memaddr, struct disassemble_info *info)
}
buf = g_string_sized_new(PACKET_BUFFER_LEN);
- len = disassemble_hexagon(words, i, memaddr, buf);
+ len = disassemble_hexagon(words, i, memaddr, buf, hex_version);
(*info->fprintf_func)(info->stream, "%s", buf->str);
g_string_free(buf, true);
diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 09a0de3c2f..4b16214ace 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -314,8 +314,11 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetType type)
static void hexagon_cpu_disas_set_info(const CPUState *cs,
disassemble_info *info)
{
+ CPUState *cs_nonconst = (CPUState *)cs; /* so we can get hex_cpu */
+ HexagonCPU *hex_cpu = env_archcpu(cpu_env(cs_nonconst));
info->print_insn = print_insn_hexagon;
info->endian = BFD_ENDIAN_LITTLE;
+ info->target_info = (void *)HEXAGON_CPU_GET_CLASS(hex_cpu)->hex_version;
}
static void hexagon_cpu_realize(DeviceState *dev, Error **errp)
diff --git a/target/hexagon/decode.c b/target/hexagon/decode.c
index 0cff15e890..bfc769be62 100644
--- a/target/hexagon/decode.c
+++ b/target/hexagon/decode.c
@@ -768,19 +768,33 @@ int decode_packet(DisasContext *ctx, int max_words, const uint32_t *words,
/* Used for "-d in_asm" logging */
int disassemble_hexagon(uint32_t *words, int nwords, bfd_vma pc,
- GString *buf)
+ GString *buf, HexagonVersion hex_version)
{
DisasContext ctx;
Packet pkt;
memset(&ctx, 0, sizeof(DisasContext));
+ ctx.hex_version = hex_version;
ctx.pkt = &pkt;
if (decode_packet(&ctx, nwords, words, &pkt, true) > 0) {
snprint_a_pkt_disas(buf, &pkt, words, pc);
return pkt.encod_pkt_size_in_bytes;
} else {
- g_string_assign(buf, "<invalid>");
- return 0;
+ for (int i = 0; i < nwords; i++) {
+ g_string_append_printf(buf, "0x" TARGET_FMT_lx "\t", words[i]);
+ if (i == 0) {
+ g_string_append(buf, "{");
+ }
+ g_string_append(buf, "\t");
+ g_string_append(buf, "<invalid>");
+ if (i < nwords - 1) {
+ pc += 4;
+ g_string_append_printf(buf, "\n0x" TARGET_FMT_lx ": ",
+ (target_ulong)pc);
+ }
+ }
+ g_string_append(buf, " }");
+ return nwords * sizeof(uint32_t);
}
}
--
2.43.0