From nobody Sun Apr 12 07:25:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1771363463; cv=none; d=zohomail.com; s=zohoarc; b=mgdLG48RFu5mdH8Mz8LO1UMwGzoS27u3RyoUVQSewACkgbPOY4EgbdN7b+OCj5WIAtTJEuPXMBf8ka9CxJt51lHawkEErt4hJ/SfletK0tDOrtA7nIypAaku/ehypSWXCkitrNFLatgp2TJ2LrtE0Gnid9UcsvUjS+X+q9+FhLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771363463; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rNHs4Sobj03r02yaX9a9D3Jb/8tlBnii4di7lAr9aUU=; b=EfftKb0SqBYNO/uwPe3mxLIGf3FGinUjz+8FIQk4NFIfTFEa3pjbVRXLlJOs4afKq2iF5kJ3wAPkV4HHKFpfF4DW+3xL88+zSNzILGW881YZ5suuWyWv8CyLmZcExo8OsTWh6+wLpyWFPq5zZsRtFRjTZftQPL40roHZvfMTjeA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771363463852307.64065154664684; Tue, 17 Feb 2026 13:24:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsSX6-0002hj-DP; Tue, 17 Feb 2026 16:23:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsSX5-0002hH-F9 for qemu-devel@nongnu.org; Tue, 17 Feb 2026 16:22:59 -0500 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vsSX3-0002Ip-N0 for qemu-devel@nongnu.org; Tue, 17 Feb 2026 16:22:59 -0500 Received: by mail-oi1-x243.google.com with SMTP id 5614622812f47-46398742245so1208041b6e.1 for ; Tue, 17 Feb 2026 13:22:57 -0800 (PST) Received: from taylor-ubuntu.. (c-67-172-136-152.hsd1.co.comcast.net. [67.172.136.152]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4636ae8f86fsm12899319b6e.3.2026.02.17.13.22.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Feb 2026 13:22:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771363376; x=1771968176; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rNHs4Sobj03r02yaX9a9D3Jb/8tlBnii4di7lAr9aUU=; b=AZPB/2NhI7eyRNpYn+COF0OcbV8tFX+xIKC43T7RU6Rbj8Pkx38Tw/SrbM7eKr0D0c noTIx5pQFrlL+Kv3meVuWhiy92HAR10ptVx/seKQyO3IhIYT43dYEjSa2qEceIG3JVAX dO/SYvQloA7AslopsTTX5KeCPsPsLmSbp6Oq4Y7F0PT2uce+AzvOlE4OVfQfTvqvkf1u zgdI8sexybn6G6wLDgzN7RgWWF/5+AbvU+DZPbtqDmoDTa6wLygomISHncSiYmfA3w4J eUWZKsOalEqBTu/HQ3oliNpGQNd+OPE7U3vHP2k3OvlUe3PGHfL2KcsOjb63UrwH2Eoq A+Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771363376; x=1771968176; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rNHs4Sobj03r02yaX9a9D3Jb/8tlBnii4di7lAr9aUU=; b=AllnYYvm5+odIoZGJTBgQSJOlzwXn6e62q+1ESEH6uD/hyRygHievVW7+vK9CQkNxo PkO21QExlb98tCixOHuaUPLbVmUqTOAamp/zAKPk1qjlPOkszJsGCqo+iCrD4WHrkAiW WGFN3L7EqGVuIK/af60Ps5yTJ+zJU9DQZfM0N2i4QHndvnUOUbRdu5ixSvS2O2BGwpM8 76jK6wIqAvPDK1Utx4wDjn03P6eus8OM5Kbk8XG/NAHfCMhQiNwp5hWix1LyU7x16XvT 9KNe5kTyFMVfg84NXXNzvq9wrZPiihaZz9jxhrjR7JIQEh0t2t/0gcZ9P/ruxpQ3v/17 pX7w== X-Gm-Message-State: AOJu0YwI5CdICNizPz1u8JlTig7PywxLjJOavUHvnrjoZ+f5SZfbdAxg hN5kZmZvUt7a+wXQySUlTmzzfKNqKD3eiCCjRC8ic7Tycvw++Ez+eOWA2Vse7DGd X-Gm-Gg: AZuq6aIvGmcFJfzdIV5TXUCT8cl7PCZlmXJHHY+oyQp6Kyzs9IC6wZKaxA3BDh3ESLo O0u3bpKEG+XuYRc9xVVz/G2SfabRWwWjZS0M+taHY4Fc5gZrvx3m7BPEKjBcp1A0hO9shtSxFo2 ZuiFnQWfm5EgeKUI5Z1BqTgKPGVN0Wzqd+KrC2je4DDs+zQojsWYt7dYb14I0qfRWXb5slGFlSH R9R0oqowZH5A9uZPx1VWiRfP5t3JObk7x3eJgfbAmF2Eu5rFMbFiH5lAhncJDfl/VYG63skV+cd LDILZh1R7bRpr+D6mhFqQbyhy1RtPziYukuUe7UD82nHTOTLgaM7lmleBjheiJ3XR4iYtNAMHmJ cdk86dnRxx+qFHlV84T9X+zwr2PSHqtZ1HLug5NgPD0TZgYPdhMAK2BSJhZfJtaDahSztUvZOqP kvDoRXfVQG2tq63sBLLVvYf9xC8IhljNrva2qcp+MmlJAoo2RnrsnJSxT+ZsaYqKN46740qfxXV Eo1mxSvgL2P/lPW X-Received: by 2002:a05:6808:158e:b0:45f:210:4dbd with SMTP id 5614622812f47-4639ef3137fmr6741119b6e.16.1771363376022; Tue, 17 Feb 2026 13:22:56 -0800 (PST) From: Taylor Simpson To: qemu-devel@nongnu.org Cc: brian.cain@oss.qualcomm.com, matheus.bernardino@oss.qualcomm.com, sid.manning@oss.qualcomm.com, marco.liebel@oss.qualcomm.com, richard.henderson@linaro.org, philmd@linaro.org, ale@rev.ng, anjo@rev.ng, ltaylorsimpson@gmail.com Subject: [PATCH v3 6/8] Hexagon (target/hexagon) Disassembly of invalid packets Date: Tue, 17 Feb 2026 14:22:43 -0700 Message-ID: <20260217212245.95321-7-ltaylorsimpson@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260217212245.95321-1-ltaylorsimpson@gmail.com> References: <20260217212245.95321-1-ltaylorsimpson@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::243; envelope-from=ltaylorsimpson@gmail.com; helo=mail-oi1-x243.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1771363465942158500 We pass the Hexagon CPU definition to disassemble_hexagon. This allows decode_packet to know if the opcodes are supported. Note that we print valid instructions in a packet when one or more is invalid. Rather than this 0x0002128c: 0x1eae4fec { 0x00021290: 0x1c434c04 0x00021294: 0x1e03edf0 } We print this 0x0002128c: 0x1eae4fec { 0x00021290: 0x1c434c04 V4.w =3D vadd(V12.w,V3.w) 0x00021294: 0x1e03edf0 V16 =3D V13 } Co-authored-by: Matheus Tavares Bernardino Co-authored-by: Brian Cain Signed-off-by: Taylor Simpson Reviewed-by: Anton Johansson --- target/hexagon/cpu_bits.h | 4 +++- target/hexagon/printinsn.h | 3 ++- disas/hexagon.c | 3 ++- target/hexagon/cpu.c | 2 ++ target/hexagon/decode.c | 25 +++++++++++++++++++++---- target/hexagon/printinsn.c | 9 +++++++-- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/target/hexagon/cpu_bits.h b/target/hexagon/cpu_bits.h index 19beca81c0..aaac6b9ea6 100644 --- a/target/hexagon/cpu_bits.h +++ b/target/hexagon/cpu_bits.h @@ -19,6 +19,7 @@ #define HEXAGON_CPU_BITS_H =20 #include "qemu/bitops.h" +#include "cpu-qom.h" =20 #define PCALIGN 4 #define PCALIGN_MASK (PCALIGN - 1) @@ -65,6 +66,7 @@ static inline bool is_packet_end(uint32_t endocing) return ((bits =3D=3D 0x3) || (bits =3D=3D 0x0)); } =20 -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, + const HexagonCPUDef *hex_def); =20 #endif diff --git a/target/hexagon/printinsn.h b/target/hexagon/printinsn.h index 2ecd1731d0..6f84ef93c3 100644 --- a/target/hexagon/printinsn.h +++ b/target/hexagon/printinsn.h @@ -18,10 +18,11 @@ #ifndef HEXAGON_PRINTINSN_H #define HEXAGON_PRINTINSN_H =20 +#include "cpu-qom.h" #include "insn.h" =20 void snprint_a_pkt_disas(GString *buf, Packet *pkt, uint32_t *words, - target_ulong pc); + target_ulong pc, const HexagonCPUDef *hex_def); void snprint_a_pkt_debug(GString *buf, Packet *pkt); =20 #endif diff --git a/disas/hexagon.c b/disas/hexagon.c index c1a4ffc5f6..36b8321c26 100644 --- a/disas/hexagon.c +++ b/disas/hexagon.c @@ -31,6 +31,7 @@ =20 int print_insn_hexagon(bfd_vma memaddr, struct disassemble_info *info) { + const HexagonCPUDef *hex_def =3D (const HexagonCPUDef *)info->target_i= nfo; uint32_t words[PACKET_WORDS_MAX]; bool found_end =3D false; GString *buf; @@ -58,7 +59,7 @@ int print_insn_hexagon(bfd_vma memaddr, struct disassembl= e_info *info) } =20 buf =3D g_string_sized_new(PACKET_BUFFER_LEN); - len =3D disassemble_hexagon(words, i, memaddr, buf); + len =3D disassemble_hexagon(words, i, memaddr, buf, hex_def); (*info->fprintf_func)(info->stream, "%s", buf->str); g_string_free(buf, true); =20 diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index 949d509a15..001ea3c4ef 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -297,8 +297,10 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetT= ype type) static void hexagon_cpu_disas_set_info(const CPUState *cs, disassemble_info *info) { + const HexagonCPU *cpu =3D HEXAGON_CPU(cs); info->print_insn =3D print_insn_hexagon; info->endian =3D BFD_ENDIAN_LITTLE; + info->target_info =3D HEXAGON_CPU_GET_CLASS(cpu)->hex_def; } =20 static void hexagon_cpu_realize(DeviceState *dev, Error **errp) diff --git a/target/hexagon/decode.c b/target/hexagon/decode.c index b8a1cd5b12..c4cf430e5a 100644 --- a/target/hexagon/decode.c +++ b/target/hexagon/decode.c @@ -828,19 +828,36 @@ int decode_packet(DisasContext *ctx, int max_words, c= onst uint32_t *words, =20 /* Used for "-d in_asm" logging */ int disassemble_hexagon(uint32_t *words, int nwords, bfd_vma pc, - GString *buf) + GString *buf, const HexagonCPUDef *hex_def) { + HexagonCPUDef any_def =3D { + .hex_version =3D HEX_VER_ANY, /* Allow decode to accept anything = */ + }; DisasContext ctx; Packet pkt; =20 memset(&ctx, 0, sizeof(DisasContext)); + ctx.hex_def =3D &any_def; ctx.pkt =3D &pkt; =20 if (decode_packet(&ctx, nwords, words, &pkt, true) > 0) { - snprint_a_pkt_disas(buf, &pkt, words, pc); + snprint_a_pkt_disas(buf, &pkt, words, pc, hex_def); return pkt.encod_pkt_size_in_bytes; } else { - g_string_assign(buf, ""); - return 0; + for (int i =3D 0; i < nwords; i++) { + g_string_append_printf(buf, "0x" TARGET_FMT_lx "\t", words[i]); + if (i =3D=3D 0) { + g_string_append(buf, "{"); + } + g_string_append(buf, "\t"); + g_string_append(buf, ""); + if (i < nwords - 1) { + pc +=3D 4; + g_string_append_printf(buf, "\n0x" TARGET_FMT_lx ": ", + (target_ulong)pc); + } + } + g_string_append(buf, " }"); + return nwords * sizeof(uint32_t); } } diff --git a/target/hexagon/printinsn.c b/target/hexagon/printinsn.c index 4865cdd133..22b305f018 100644 --- a/target/hexagon/printinsn.c +++ b/target/hexagon/printinsn.c @@ -21,6 +21,7 @@ #include "insn.h" #include "reg_fields.h" #include "internal.h" +#include "decode.h" =20 static const char *sreg2str(unsigned int reg) { @@ -51,7 +52,7 @@ static void snprintinsn(GString *buf, Insn *insn) } =20 void snprint_a_pkt_disas(GString *buf, Packet *pkt, uint32_t *words, - target_ulong pc) + target_ulong pc, const HexagonCPUDef *hex_def) { bool has_endloop0 =3D false; bool has_endloop1 =3D false; @@ -83,7 +84,11 @@ void snprint_a_pkt_disas(GString *buf, Packet *pkt, uint= 32_t *words, } =20 g_string_append(buf, "\t"); - snprintinsn(buf, &(pkt->insn[i])); + if (opcode_supported(pkt->insn[i].opcode, hex_def)) { + snprintinsn(buf, &(pkt->insn[i])); + } else { + g_string_append(buf, ""); + } =20 if (i < pkt->num_insns - 1) { /* --=20 2.43.0