From nobody Wed Feb 11 03:24:32 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1770730496; cv=none; d=zohomail.com; s=zohoarc; b=Ep1htJj45XQX8T9LHJLsbk3zuVosfQ4IRL28fnBLQWAkuOTdU1X7DkXKJEjwkz6V37HZVb62tZ/Ayp0wnNMCBw3WVehYL66FPiYEQ4RG9BuRJCeBoszYcGj7pneNNV1ORQzZVoDqO+NrtAMKfItXsULMF9rGpH+yrmvG40vQYso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770730496; 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=xbXi2oXZsKBH1Y/QXhqVGsr/9BWhgHx07lNx0z3p67k=; b=fTMFbj8d1I+AMHkhNDaOsLhdc7sBlZbIqSwRsx4Ls3aGgWJL7s+l12zLa8s8GkG+36t2vehswjpOGWUkHcDiTNPPf6/3cNMVDKSpmZS8vYXz6rvOD7mEHFTc3JsygqmdmqVTuPHNcVpVzfvlFMCoBXiGeE+RhYXv3OARNi1GCG4= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770730496248178.32102806318812; Tue, 10 Feb 2026 05:34:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vpnsx-0005fr-4m; Tue, 10 Feb 2026 08:34:35 -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 1vpnsn-0005eT-Rp for qemu-devel@nongnu.org; Tue, 10 Feb 2026 08:34:27 -0500 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vpnsk-0001o6-7G for qemu-devel@nongnu.org; Tue, 10 Feb 2026 08:34:25 -0500 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61A7jMlE1419505 for ; Tue, 10 Feb 2026 13:34:21 GMT Received: from mail-dy1-f197.google.com (mail-dy1-f197.google.com [74.125.82.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4c7rpvtjf2-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 10 Feb 2026 13:34:21 +0000 (GMT) Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-2ba67282cabso6501011eec.1 for ; Tue, 10 Feb 2026 05:34:21 -0800 (PST) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ba7e149c58sm2716162eec.26.2026.02.10.05.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Feb 2026 05:34:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= xbXi2oXZsKBH1Y/QXhqVGsr/9BWhgHx07lNx0z3p67k=; b=a0KhVxby59OU9hBm tmx5Z6Knj68rUN1ZP3J0O5G1E6hdNOIhiTjhad2IPFnvQUfjlLIO1sk9Cf5hrpoD RIIZVpGU9UhL2FhhzrGTdbdFvpBhE/ZjcQ08lrntzw1dgMqm1bXkQQnWawwtEWBR copu9njJhfCP+1eOgVRr+bh6YAeGcpCUSalQsvdNmWHktBwBQhm32yJNtY5c84v0 w72QbaqS9jXVxRQgo3BvoqJ/pgCuOQ64EFwMIiReyIqAWX//BdEmHJ06f8JNMx1Z aqRxLIQ2jE11i+ClIbDx/czV66dKfT4UxYn6HSDEWNzJPqDNQh5xGUcc8lgoVA0k TSHiyw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1770730460; x=1771335260; 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=xbXi2oXZsKBH1Y/QXhqVGsr/9BWhgHx07lNx0z3p67k=; b=CEpzUX2d9aoK/fYMPbQMUYRp/++NeD8PEq4qyNCBGdK2e9cibJgy8P8aeyDRXT7tCE J+PAYdxHVZR6tYAuSxWpWghsMFVSn0pQ2itq1iwwUUiYsH+Frg82CWpn1/M16xfdhkqR 3ON9vOoh4dQ4/BTZP1oN25Ga/0tkqpUcm+ObPWZEJ93SfW92pCUXwzZ3wyiEVPGOY+uS egKHZJgNv7hkzWJaKha2sufTPluKXBiHBv1/3CcNkUaxu6V/EvIlTcflBo9EYiMjlClb w/Z4fjdpNHBiU6WhnS0f0saXP2j2wqH0wVI02ihtEjewEcYQuCDxibZhxPruhDAx9D3i HXxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770730460; x=1771335260; 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=xbXi2oXZsKBH1Y/QXhqVGsr/9BWhgHx07lNx0z3p67k=; b=gdIzUHsfB21IkZba7J4tR4UsmITIEaNimWW+IRcbcTWn/GdnaVcFIYKcPtA9Vwjgtl RoFlS9HlrhUYd81EnIl+pOPvgw9vcr9ZaZdEBen5OOtZL4gW09gilTb2BOtcBDPRLw9S Nk2jKKk3gCfWfYnaGquJL5mZHcvH7ipOlSk+gDKPjDcLcOt38PB2/WcmiTJ6VOlI2DC2 4s+Yt1PJQW3h+q0CASH2EtzO5UaSeGjbwkUaCHVfsXxoUzieLTGZ6IhqtxTPj8i0FNUc YPzN65AyWKlYL07GC9JNE5OqKQ/67+evUGpylrmPTuGzC5L1mtFfz7aDHR96OVU+MYXD hRHw== X-Gm-Message-State: AOJu0YwhOp8lsJkIftS2Atvs8z2Bs4thVBGIs/Uq7p7wZkC6SxbndyvU k2LKiDPnP5+p03WMdxc4SVh9D1LU8meAc2/JB7xu0xfJx9Ceo+XNZldvpJEHxvYrj3YqbRApOjU f5pmNjlX1TWsHylGrXitAFk2GqCEEleEkRlMFaXVEMvmKhlar26BdgQ/TA2f75xwizg== X-Gm-Gg: AZuq6aI12wbYzujx8u3VI4wQM4rsgUZV+I/8m3D0Vpb5W6/6iuqslKA4YOpCb/2IMbH jFgfxiF97Ov9jUAa4OU/SpKwrLbq0tKawFduqV751W5hGiAuGtzCb8SvMOptTPMbW6spGaS2vfg FfdM/8AzMGmQUTdBc5GmOrdpVrfR5+TLl/KFXgrIMFr3407NXv746gkSF4XbbSIIAZVKE82yDW2 0YSCUDyH2UgMOOFqPfO2zzZs1bSxCiQPsroUHg4uGwq21uJsWxeKXlpEvtdmYxGJxI7U/daqaKI +04VTR1tQSXiz0p1tF9ezF0lFnDFhW1j1R54BefhswDr27JxWl8iY3V9nUzLTidj1YatPCPeKX6 aL9P3VaHBccqDE6set7OgUqyj3V8aybuupnObAmWKoMkXlkn6NzUQeybKg0dBtnrxxuVNwQ== X-Received: by 2002:a05:7300:3720:b0:2ba:956e:d26a with SMTP id 5a478bee46e88-2ba956ed77cmr117825eec.36.1770730459772; Tue, 10 Feb 2026 05:34:19 -0800 (PST) X-Received: by 2002:a05:7300:3720:b0:2ba:956e:d26a with SMTP id 5a478bee46e88-2ba956ed77cmr117805eec.36.1770730459104; Tue, 10 Feb 2026 05:34:19 -0800 (PST) From: Brian Cain To: qemu-devel@nongnu.org Cc: brian.cain@oss.qualcomm.com, ltaylorsimpson@gmail.com, alex@alexrp.com, Laurent Vivier , Pierrick Bouvier Subject: [PATCH v3 4/4] target/hexagon: Detect register write conflicts with bitmap algorithm Date: Tue, 10 Feb 2026 05:33:54 -0800 Message-Id: <20260210133355.16093-5-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260210133355.16093-1-brian.cain@oss.qualcomm.com> References: <20260210133355.16093-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjEwMDExNCBTYWx0ZWRfXwnESCry89Ee+ 40woOtbmn7JLl5mpUtQO4GjGGaxRtA9fU9UPcalu5TXdf+UjVZyaoI2V62xw479z/JZSwPE8t9w B6Zobnd0K1uUC4ZOOvrZLV3CbT17lYg1gPuMf4nJNkzno8njCzNxjLpOMgLpyNWuQqmy5YK9nD3 sVls0Q81E06QVE4MmI25UYwbOt4H0bkv69JRpvnf6QcvBppUQ6gv7nIFQsYDpakGqZcpBzsuOxx kmYyvZh9Id7vHu9vbfkGKd5YZYfgQxWsUT7M2mu0oZrIVsA5CNmFBJmOF7gg+CsgGE57WpVFMUv /CSDYKdsVtEQl5JzztJXtdC+tlip2n9LQw/ACTG2PCTUdYwq4ZwBWspr1EUoGX1siG3sgTz+XG4 Tc6jasPxlCSA3XHrsxlxsvyczRGiYj5VGx79TTgtFCDubKuFMItAJV6z3vCnbh7Utf3e1s3iXae UaKugI+tqeCAVAMMWyg== X-Authority-Analysis: v=2.4 cv=KKZXzVFo c=1 sm=1 tr=0 ts=698b33dd cx=c_pps a=Uww141gWH0fZj/3QKPojxA==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=p0WdMEafAAAA:8 a=EUspDBNiAAAA:8 a=JaF38Zb2HHyKl8zT_ZQA:9 a=QEXdDO2ut3YA:10 a=PxkB5W3o20Ba91AHUih5:22 X-Proofpoint-ORIG-GUID: XPZItImDGrbtETHP0ERQVBQqiqswJGF2 X-Proofpoint-GUID: XPZItImDGrbtETHP0ERQVBQqiqswJGF2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-10_01,2026-02-10_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 spamscore=0 adultscore=0 malwarescore=0 priorityscore=1501 phishscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602100114 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=205.220.180.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 @qualcomm.com) X-ZM-MESSAGEID: 1770730499147154100 A conflict exists when any GPR is written by multiple instructions and at least one write is unconditional. This catches (1) two unconditional writes to the same GPR and (2) an unconditional write combined with a predicated write. Add HEX_CAUSE_REG_WRITE_CONFLICT and map it to SIGILL. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2696 Signed-off-by: Brian Cain --- target/hexagon/cpu_bits.h | 1 + target/hexagon/insn.h | 6 + linux-user/hexagon/cpu_loop.c | 1 + target/hexagon/decode.c | 43 +++++++ target/hexagon/translate.c | 21 +++- tests/tcg/hexagon/multiple-writes.c | 169 ++++++++++++++++++++++++++++ target/hexagon/gen_trans_funcs.py | 10 ++ tests/tcg/hexagon/Makefile.target | 1 + 8 files changed, 250 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/hexagon/multiple-writes.c diff --git a/target/hexagon/cpu_bits.h b/target/hexagon/cpu_bits.h index ff596e2a94..19beca81c0 100644 --- a/target/hexagon/cpu_bits.h +++ b/target/hexagon/cpu_bits.h @@ -34,6 +34,7 @@ enum hex_cause { HEX_CAUSE_FETCH_NO_UPAGE =3D 0x012, HEX_CAUSE_INVALID_PACKET =3D 0x015, HEX_CAUSE_INVALID_OPCODE =3D 0x015, + HEX_CAUSE_REG_WRITE_CONFLICT =3D 0x01d, HEX_CAUSE_PC_NOT_ALIGNED =3D 0x01e, HEX_CAUSE_PRIV_NO_UREAD =3D 0x024, HEX_CAUSE_PRIV_NO_UWRITE =3D 0x025, diff --git a/target/hexagon/insn.h b/target/hexagon/insn.h index 5d59430da9..db4dbb728a 100644 --- a/target/hexagon/insn.h +++ b/target/hexagon/insn.h @@ -41,6 +41,8 @@ struct Instruction { uint32_t new_value_producer_slot:4; int32_t new_read_idx; int32_t dest_idx; + bool dest_is_pair; + bool dest_is_gpr; bool has_pred_dest; =20 bool part1; /* @@ -72,6 +74,10 @@ struct Packet { bool pkt_has_hvx; Insn *vhist_insn; =20 + /* Bitmaps for detecting duplicate GPR destination writes */ + DECLARE_BITMAP(wreg_mult_gprs, 32); /* GPRs written by >1 insn */ + DECLARE_BITMAP(uncond_wreg_gprs, 32); /* GPRs written unconditionally = */ + Insn insn[INSTRUCTIONS_MAX]; }; =20 diff --git a/linux-user/hexagon/cpu_loop.c b/linux-user/hexagon/cpu_loop.c index c0e1098e3f..5711055aff 100644 --- a/linux-user/hexagon/cpu_loop.c +++ b/linux-user/hexagon/cpu_loop.c @@ -65,6 +65,7 @@ void cpu_loop(CPUHexagonState *env) env->gpr[HEX_REG_R31]); break; case HEX_CAUSE_INVALID_PACKET: + case HEX_CAUSE_REG_WRITE_CONFLICT: force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->gpr[HEX_REG_PC]); break; diff --git a/target/hexagon/decode.c b/target/hexagon/decode.c index 33ad60c5b4..08b0fa2c8d 100644 --- a/target/hexagon/decode.c +++ b/target/hexagon/decode.c @@ -655,6 +655,44 @@ decode_set_slot_number(Packet *pkt) return has_valid_slot_assignment(pkt); } =20 +/* + * Build bitmaps of destination GPR writes across the packet. + */ +static void decode_mark_dest_regs(Packet *pkt) +{ + DECLARE_BITMAP(all_dest_gprs, 32) =3D { 0 }; + + for (int i =3D 0; i < pkt->num_insns; i++) { + Insn *insn =3D &pkt->insn[i]; + int dest =3D insn->dest_idx; + + if (dest < 0 || !insn->dest_is_gpr) { + continue; + } + + int rnum =3D insn->regno[dest]; + bool is_uncond =3D !GET_ATTRIB(insn->opcode, A_CONDEXEC); + + if (test_bit(rnum, all_dest_gprs)) { + set_bit(rnum, pkt->wreg_mult_gprs); + } + set_bit(rnum, all_dest_gprs); + if (is_uncond) { + set_bit(rnum, pkt->uncond_wreg_gprs); + } + + if (insn->dest_is_pair) { + if (test_bit(rnum + 1, all_dest_gprs)) { + set_bit(rnum + 1, pkt->wreg_mult_gprs); + } + set_bit(rnum + 1, all_dest_gprs); + if (is_uncond) { + set_bit(rnum + 1, pkt->uncond_wreg_gprs); + } + } + } +} + /* * decode_packet * Decodes packet with given words @@ -674,6 +712,10 @@ int decode_packet(DisasContext *ctx, int max_words, co= nst uint32_t *words, =20 /* Initialize */ memset(pkt, 0, sizeof(*pkt)); + for (i =3D 0; i < INSTRUCTIONS_MAX; i++) { + pkt->insn[i].dest_idx =3D -1; + pkt->insn[i].new_read_idx =3D -1; + } /* Try to build packet */ while (!end_of_packet && (words_read < max_words)) { Insn *insn =3D &pkt->insn[num_insns]; @@ -737,6 +779,7 @@ int decode_packet(DisasContext *ctx, int max_words, con= st uint32_t *words, /* Invalid packet */ return 0; } + decode_mark_dest_regs(pkt); } decode_fill_newvalue_regno(pkt); =20 diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c index 7fe8b35351..6e399bc2f2 100644 --- a/target/hexagon/translate.c +++ b/target/hexagon/translate.c @@ -940,10 +940,21 @@ static void gen_commit_packet(DisasContext *ctx) } } =20 +/* + * Check for register write conflicts in the packet. + */ +static bool pkt_has_write_conflict(Packet *pkt) +{ + DECLARE_BITMAP(conflict, 32); + + bitmap_and(conflict, pkt->wreg_mult_gprs, pkt->uncond_wreg_gprs, 32); + return !bitmap_empty(conflict, 32); +} + static void decode_and_translate_packet(CPUHexagonState *env, DisasContext= *ctx) { uint32_t words[PACKET_WORDS_MAX]; - int nwords; + int nwords, words_read; Packet pkt; int i; =20 @@ -954,8 +965,14 @@ static void decode_and_translate_packet(CPUHexagonStat= e *env, DisasContext *ctx) } =20 ctx->pkt =3D &pkt; - if (decode_packet(ctx, nwords, words, &pkt, false) > 0) { + words_read =3D decode_packet(ctx, nwords, words, &pkt, false); + if (words_read > 0) { pkt.pc =3D ctx->base.pc_next; + if (pkt_has_write_conflict(&pkt)) { + gen_exception_decode_fail(ctx, words_read, + HEX_CAUSE_REG_WRITE_CONFLICT); + return; + } gen_start_packet(ctx); for (i =3D 0; i < pkt.num_insns; i++) { ctx->insn =3D &pkt.insn[i]; diff --git a/tests/tcg/hexagon/multiple-writes.c b/tests/tcg/hexagon/multip= le-writes.c new file mode 100644 index 0000000000..8686317fdc --- /dev/null +++ b/tests/tcg/hexagon/multiple-writes.c @@ -0,0 +1,169 @@ +/* + * Test detection of multiple writes to the same register. + * + * Ported from the system test (tests/tcg/hexagon/system/multiple_writes.c= ). + * In linux-user mode, duplicate GPR writes are detected at translate time + * and raise SIGILL when at least one conflicting write is unconditional. + * Purely predicated duplicate writes (e.g., complementary if/if-not) are + * legal and are not flagged statically. + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include + +static void *resume_pc; + +static void handle_sigill(int sig, siginfo_t *info, void *puc) +{ + ucontext_t *uc =3D (ucontext_t *)puc; + + if (sig !=3D SIGILL) { + _exit(EXIT_FAILURE); + } + + uc->uc_mcontext.r0 =3D SIGILL; + uc->uc_mcontext.pc =3D (unsigned long)resume_pc; +} + +/* + * Unconditional pair write overlapping a single write: + * { r1:0 =3D add(r3:2, r3:2); r1 =3D add(r0, r1) } + * R1 is written by both instructions. This is invalid and must raise SIG= ILL. + */ +static int test_static_pair_overlap(void) +{ + int sig; + + asm volatile( + "r0 =3D #0\n" + "r1 =3D ##1f\n" + "memw(%1) =3D r1\n" + ".word 0xd30242e0\n" /* r1:0 =3D add(r3:2, r3:2), parse=3D01 */ + ".word 0xf300c101\n" /* r1 =3D add(r0, r1), parse=3D11 (end) */ + "1:\n" + "%0 =3D r0\n" + : "=3Dr"(sig) + : "r"(&resume_pc) + : "r0", "r1", "memory"); + + return sig; +} + +/* + * Two predicated writes under complementary predicates: + * { if (p0) r0 =3D r2; if (!p0) r0 =3D r3 } + * This is architecturally valid: only one write executes at runtime. + * Must NOT raise SIGILL; the result should reflect the executed branch. + */ +static int test_legal_predicated(void) +{ + int result; + + asm volatile( + "r0 =3D #0\n" + "r1 =3D ##1f\n" + "memw(%1) =3D r1\n" + "r2 =3D #7\n" + "r3 =3D #13\n" + "p0 =3D cmp.eq(r2, r2)\n" + "{\n" + " if (p0) r0 =3D r2\n" + " if (!p0) r0 =3D r3\n" + "}\n" + "1:\n" + "%0 =3D r0\n" + : "=3Dr"(result) + : "r"(&resume_pc) + : "r0", "r1", "r2", "r3", "p0", "memory"); + + return result; +} + +/* + * Mixed: unconditional + predicated writes to the same register: + * { if (p0) r1 =3D add(r0, #0); if (!p0) r1 =3D add(r0, #0); + * r1 =3D add(r0, #0) } + * The unconditional write always conflicts with the predicated writes. + * Must raise SIGILL. + */ +static int test_mixed_writes(void) +{ + int sig; + + asm volatile( + "r0 =3D #0\n" + "r1 =3D ##1f\n" + "memw(%1) =3D r1\n" + "p0 =3D cmp.eq(r0, r0)\n" + ".word 0x7e204021\n" /* if (p0) r1 =3D add(r0, #0), parse=3D01 */ + ".word 0x7ea04021\n" /* if (!p0) r1 =3D add(r0, #0), parse=3D01 */ + ".word 0x7800c021\n" /* r1 =3D add(r0, #0), parse=3D11 (end) */ + "1:\n" + "%0 =3D r0\n" + : "=3Dr"(sig) + : "r"(&resume_pc) + : "r0", "r1", "p0", "memory"); + + return sig; +} + +/* + * Zero encoding (issue #2696): + * The encoding 0x00000000 decodes as a duplex with parse bits + * [15:14] =3D 0b00: + * slot1: SL1_loadri_io R0 =3D memw(R0+#0x0) + * slot0: SL1_loadri_io R0 =3D memw(R0+#0x0) + * + * Both sub-instructions write R0 unconditionally, which is an invalid + * packet. This tests what happens when we jump to zeroed memory. + * Must raise SIGILL. + */ +static int test_zero(void) +{ + int sig; + + asm volatile( + "r0 =3D #0\n" + "r1 =3D ##1f\n" + "memw(%1) =3D r1\n" + ".word 0x00000000\n" + "1:\n" + "%0 =3D r0\n" + : "=3Dr"(sig) + : "r"(&resume_pc) + : "r0", "r1", "memory"); + + return sig; +} + +int main() +{ + struct sigaction act; + + memset(&act, 0, sizeof(act)); + act.sa_sigaction =3D handle_sigill; + act.sa_flags =3D SA_SIGINFO; + assert(sigaction(SIGILL, &act, NULL) =3D=3D 0); + + /* Legal: complementary predicated writes must not raise SIGILL */ + assert(test_legal_predicated() =3D=3D 7); + + /* Illegal: unconditional pair + single overlap must raise SIGILL */ + assert(test_static_pair_overlap() =3D=3D SIGILL); + + /* Illegal: unconditional + predicated writes to same reg must SIGILL = */ + assert(test_mixed_writes() =3D=3D SIGILL); + + /* Illegal: zero encoding =3D duplex with duplicate dest R0 */ + assert(test_zero() =3D=3D SIGILL); + + puts("PASS"); + return EXIT_SUCCESS; +} diff --git a/target/hexagon/gen_trans_funcs.py b/target/hexagon/gen_trans_f= uncs.py index 45da1b7b5d..19c1f9fdea 100755 --- a/target/hexagon/gen_trans_funcs.py +++ b/target/hexagon/gen_trans_funcs.py @@ -91,6 +91,8 @@ def gen_trans_funcs(f): new_read_idx =3D -1 dest_idx =3D -1 dest_idx_reg_id =3D None + dest_is_pair =3D "false" + dest_is_gpr =3D "false" has_pred_dest =3D "false" for regno, (reg_type, reg_id, *_) in enumerate(regs): reg =3D hex_common.get_register(tag, reg_type, reg_id) @@ -104,6 +106,12 @@ def gen_trans_funcs(f): if dest_idx_reg_id is None or reg_id < dest_idx_reg_id: dest_idx =3D regno dest_idx_reg_id =3D reg_id + dest_is_pair =3D ("true" + if isinstance(reg, hex_common.Pair) + else "false") + dest_is_gpr =3D ("true" + if reg_type =3D=3D "R" + else "false") if reg_type =3D=3D "P" and reg.is_written() and not reg.is_rea= d(): has_pred_dest =3D "true" =20 @@ -129,6 +137,8 @@ def gen_trans_funcs(f): f.write(code_fmt(f"""\ insn->new_read_idx =3D {new_read_idx}; insn->dest_idx =3D {dest_idx}; + insn->dest_is_pair =3D {dest_is_pair}; + insn->dest_is_gpr =3D {dest_is_gpr}; insn->has_pred_dest =3D {has_pred_dest}; """)) f.write(textwrap.dedent(f"""\ diff --git a/tests/tcg/hexagon/Makefile.target b/tests/tcg/hexagon/Makefile= .target index d64aeba090..f86f02bb31 100644 --- a/tests/tcg/hexagon/Makefile.target +++ b/tests/tcg/hexagon/Makefile.target @@ -52,6 +52,7 @@ HEX_TESTS +=3D hvx_misc HEX_TESTS +=3D hvx_histogram HEX_TESTS +=3D invalid-slots HEX_TESTS +=3D invalid-encoding +HEX_TESTS +=3D multiple-writes HEX_TESTS +=3D unaligned_pc =20 HEX_TESTS +=3D test_abs --=20 2.34.1