From nobody Sat May 11 05:34:09 2024 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=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1682553559; cv=none; d=zohomail.com; s=zohoarc; b=WQoIRmqcRIOUq5UZ9FhEUqFGj6arUYPKK89H5Nk+pTKkgbWfhjvQGpGC4GGdWGs8QWlgqt77U2ylornK7jcZQg4N4lvI28YI67PzM5bIlXnhIFQSfjXIK0TlN/1vkARmnmJhUCHEbIxNIJ2P4LYmdq8ATn5FSEyLHFDnShw2/qc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682553559; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tk2ZwUrCwzAwZiKr29kiMxgB77ddR4C/cSaxXkI2Q1w=; b=d5AUFbEsxubXSt9mWpSOV59OUfLmgl2PPMDRpqjAgxEH9cSEto0VIVmp5oFJNyAqv/zG3Vvak/bABR+pa4Jb165MlONUvjZldozqp9ON52hIaTDZN/0tnDmmWypq4lXjPzhp01p8SB5+pJF25NugKVVgroM/u/x/Cq9M4T0VU1g= 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 1682553559122862.739320512865; Wed, 26 Apr 2023 16:59:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prp1x-000359-0X; Wed, 26 Apr 2023 19:58:37 -0400 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 1prp1r-00030T-Ep; Wed, 26 Apr 2023 19:58:31 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prp1p-0005G8-FN; Wed, 26 Apr 2023 19:58:31 -0400 Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33QNcDdv028423; Wed, 26 Apr 2023 23:58:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q7c7ntqay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Apr 2023 23:58:27 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33QNnRL1032637; Wed, 26 Apr 2023 23:58:26 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q7c7ntqaf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Apr 2023 23:58:26 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 33QMc48p013088; Wed, 26 Apr 2023 23:58:24 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3q46ug2m58-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Apr 2023 23:58:24 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 33QNwLLD23724618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Apr 2023 23:58:21 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1595520043; Wed, 26 Apr 2023 23:58:21 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 968EB20040; Wed, 26 Apr 2023 23:58:20 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.69.68]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 26 Apr 2023 23:58:20 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=tk2ZwUrCwzAwZiKr29kiMxgB77ddR4C/cSaxXkI2Q1w=; b=gZQN3/8kGu90RYYllhQ0zUbDUF0eknxC454veYaA3tmzCT/SzDb8OLvnYBmqfFgzBLTf HztK+4qbe/tmCDcMPNTRbj5/9vtKnNRQdIak6YFZMjOfPC2degEwbFtCyQQlVZu4Y14U jYft2kNGp6KYixej1/bGFMvFZJVC5jMtg/R43Arx+lNg8wSE/JUofjmjJtSaQkGLBXgb nu3D4HWbVv+noyxVwMmKzpSSjkMDkKXKudGb7adIgQExqHX2SmuKCvndoDkvIqnnXbRW ms8gyMSFGOddnvYw5pCYORSMRivneENbBLu45s9zw/qGqpjBG+pk/1J5CxgDoLIz+KTW Ig== From: Ilya Leoshkevich To: Richard Henderson , David Hildenbrand , Thomas Huth Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich , Nina Schoetterl-Glausch Subject: [PATCH 1/2] target/s390x: Fix EXECUTE of relative branches Date: Thu, 27 Apr 2023 01:58:12 +0200 Message-Id: <20230426235813.198183-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230426235813.198183-1-iii@linux.ibm.com> References: <20230426235813.198183-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: BJzN-xOIXMxD07-8ejqPL5YaIAmviCdI X-Proofpoint-GUID: Hr4ugYhPK7JMdkbicfvxIXwpyTTGsXP5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-26_10,2023-04-26_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 suspectscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304260203 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=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @ibm.com) X-ZM-MESSAGEID: 1682553559792100001 Content-Type: text/plain; charset="utf-8" Fix a problem similar to the one fixed by commit 703d03a4aaf3 ("target/s390x: Fix EXECUTE of relative long instructions"), but now for relative branches. Reported-by: Nina Schoetterl-Glausch Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- target/s390x/tcg/translate.c | 81 ++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c index 46b874e94da..2a681428af1 100644 --- a/target/s390x/tcg/translate.c +++ b/target/s390x/tcg/translate.c @@ -1534,18 +1534,51 @@ static DisasJumpType op_bal(DisasContext *s, DisasO= ps *o) } } =20 +/* + * Disassemble the target of a branch. The results are returned in a form + * suitable for passing into help_branch(): + * + * - bool IS_IMM reflects whether the target is fixed or computed. Non-EXE= CUTEd + * branches, whose DisasContext *S contains the relative immediate field= RI, + * are considered fixed. All the other branches are considered computed. + * - int IMM is the value of RI. + * - TCGv_i64 CDEST is the address of the computed target. + */ +#define disas_jdest(s, ri, is_imm, imm, cdest) do { = \ + if (have_field(s, ri)) { = \ + if (unlikely(s->ex_value)) { = \ + cdest =3D tcg_temp_new_i64(); = \ + tcg_gen_ld_i64(cdest, cpu_env, offsetof(CPUS390XState, ex_targ= et));\ + tcg_gen_addi_i64(cdest, cdest, (int64_t)get_field(s, ri) * 2);= \ + is_imm =3D false; = \ + } else { = \ + is_imm =3D true; = \ + } = \ + } else { = \ + is_imm =3D false; = \ + } = \ + imm =3D is_imm ? get_field(s, ri) : 0; = \ +} while (false) + static DisasJumpType op_basi(DisasContext *s, DisasOps *o) { + DisasCompare c; + bool is_imm; + int imm; + pc_to_link_info(o->out, s, s->pc_tmp); - return help_goto_direct(s, s->base.pc_next + (int64_t)get_field(s, i2)= * 2); + + disas_jdest(s, i2, is_imm, imm, o->in2); + disas_jcc(s, &c, 0xf); + return help_branch(s, &c, is_imm, imm, o->in2); } =20 static DisasJumpType op_bc(DisasContext *s, DisasOps *o) { int m1 =3D get_field(s, m1); - bool is_imm =3D have_field(s, i2); - int imm =3D is_imm ? get_field(s, i2) : 0; DisasCompare c; + bool is_imm; + int imm; =20 /* BCR with R2 =3D 0 causes no branching */ if (have_field(s, r2) && get_field(s, r2) =3D=3D 0) { @@ -1562,6 +1595,7 @@ static DisasJumpType op_bc(DisasContext *s, DisasOps = *o) return DISAS_NEXT; } =20 + disas_jdest(s, i2, is_imm, imm, o->in2); disas_jcc(s, &c, m1); return help_branch(s, &c, is_imm, imm, o->in2); } @@ -1569,10 +1603,10 @@ static DisasJumpType op_bc(DisasContext *s, DisasOp= s *o) static DisasJumpType op_bct32(DisasContext *s, DisasOps *o) { int r1 =3D get_field(s, r1); - bool is_imm =3D have_field(s, i2); - int imm =3D is_imm ? get_field(s, i2) : 0; DisasCompare c; + bool is_imm; TCGv_i64 t; + int imm; =20 c.cond =3D TCG_COND_NE; c.is_64 =3D false; @@ -1584,6 +1618,7 @@ static DisasJumpType op_bct32(DisasContext *s, DisasO= ps *o) c.u.s32.b =3D tcg_constant_i32(0); tcg_gen_extrl_i64_i32(c.u.s32.a, t); =20 + disas_jdest(s, i2, is_imm, imm, o->in2); return help_branch(s, &c, is_imm, imm, o->in2); } =20 @@ -1611,9 +1646,9 @@ static DisasJumpType op_bcth(DisasContext *s, DisasOp= s *o) static DisasJumpType op_bct64(DisasContext *s, DisasOps *o) { int r1 =3D get_field(s, r1); - bool is_imm =3D have_field(s, i2); - int imm =3D is_imm ? get_field(s, i2) : 0; DisasCompare c; + bool is_imm; + int imm; =20 c.cond =3D TCG_COND_NE; c.is_64 =3D true; @@ -1622,6 +1657,7 @@ static DisasJumpType op_bct64(DisasContext *s, DisasO= ps *o) c.u.s64.a =3D regs[r1]; c.u.s64.b =3D tcg_constant_i64(0); =20 + disas_jdest(s, i2, is_imm, imm, o->in2); return help_branch(s, &c, is_imm, imm, o->in2); } =20 @@ -1629,10 +1665,10 @@ static DisasJumpType op_bx32(DisasContext *s, Disas= Ops *o) { int r1 =3D get_field(s, r1); int r3 =3D get_field(s, r3); - bool is_imm =3D have_field(s, i2); - int imm =3D is_imm ? get_field(s, i2) : 0; DisasCompare c; + bool is_imm; TCGv_i64 t; + int imm; =20 c.cond =3D (s->insn->data ? TCG_COND_LE : TCG_COND_GT); c.is_64 =3D false; @@ -1645,6 +1681,7 @@ static DisasJumpType op_bx32(DisasContext *s, DisasOp= s *o) tcg_gen_extrl_i64_i32(c.u.s32.b, regs[r3 | 1]); store_reg32_i64(r1, t); =20 + disas_jdest(s, i2, is_imm, imm, o->in2); return help_branch(s, &c, is_imm, imm, o->in2); } =20 @@ -1652,9 +1689,9 @@ static DisasJumpType op_bx64(DisasContext *s, DisasOp= s *o) { int r1 =3D get_field(s, r1); int r3 =3D get_field(s, r3); - bool is_imm =3D have_field(s, i2); - int imm =3D is_imm ? get_field(s, i2) : 0; DisasCompare c; + bool is_imm; + int imm; =20 c.cond =3D (s->insn->data ? TCG_COND_LE : TCG_COND_GT); c.is_64 =3D true; @@ -1668,6 +1705,7 @@ static DisasJumpType op_bx64(DisasContext *s, DisasOp= s *o) tcg_gen_add_i64(regs[r1], regs[r1], regs[r3]); c.u.s64.a =3D regs[r1]; =20 + disas_jdest(s, i2, is_imm, imm, o->in2); return help_branch(s, &c, is_imm, imm, o->in2); } =20 @@ -1685,10 +1723,9 @@ static DisasJumpType op_cj(DisasContext *s, DisasOps= *o) c.u.s64.a =3D o->in1; c.u.s64.b =3D o->in2; =20 - is_imm =3D have_field(s, i4); - if (is_imm) { - imm =3D get_field(s, i4); - } else { + o->out =3D NULL; + disas_jdest(s, i4, is_imm, imm, o->out); + if (!is_imm && !o->out) { imm =3D 0; o->out =3D get_address(s, 0, get_field(s, b4), get_field(s, d4)); @@ -5774,15 +5811,13 @@ static void in2_a2(DisasContext *s, DisasOps *o) =20 static TCGv gen_ri2(DisasContext *s) { - int64_t delta =3D (int64_t)get_field(s, i2) * 2; - TCGv ri2; + TCGv ri2 =3D NULL; + bool is_imm; + int imm; =20 - if (unlikely(s->ex_value)) { - ri2 =3D tcg_temp_new_i64(); - tcg_gen_ld_i64(ri2, cpu_env, offsetof(CPUS390XState, ex_target)); - tcg_gen_addi_i64(ri2, ri2, delta); - } else { - ri2 =3D tcg_constant_i64(s->base.pc_next + delta); + disas_jdest(s, i2, is_imm, imm, ri2); + if (is_imm) { + ri2 =3D tcg_constant_i64(s->base.pc_next + imm * 2); } =20 return ri2; --=20 2.40.0 From nobody Sat May 11 05:34:09 2024 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=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1682553560; cv=none; d=zohomail.com; s=zohoarc; b=L9XyNj6X+Az4MZgz7LRgU747LEBXOcHAckGhOt8t1mkcXvmEbD8XmGYuW1WgbVaj+kBK8BnKqbh4AQuZMfTZ8JTWj9C6prp5yYsfKbTS0503V30C9CvYv3NWc+bGPgh+jH7XZ8sTi+T5PG2MDXoKEjymStcJ7M/aI2hfza655Jc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682553560; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hiqiRac3dxtgF39ZNOcW2loLDhOLmcN8rVWRikfrgy0=; b=JCvwxb5ROObesER13I5q1TyfMLHRYfapAMu/WpT0z7buM8QjRTsJ27p0PuMeEj0UL8JEIB3/uVzTmmgq7RwqG7aAnJ8Bx5d98qMtp0n+65tZOMzrILg7xEpvp3PCb0ARP3teWR4X64m6rD81zULl/T6kef+H331H3OXvM89S8Bw= 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 1682553560359575.2930664459441; Wed, 26 Apr 2023 16:59:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prp1v-000327-2A; Wed, 26 Apr 2023 19:58:35 -0400 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 1prp1q-0002zo-VS; Wed, 26 Apr 2023 19:58:31 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prp1p-0005GA-7K; Wed, 26 Apr 2023 19:58:30 -0400 Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33QNdfYj012717; Wed, 26 Apr 2023 23:58:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q7d0jhm89-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Apr 2023 23:58:27 +0000 Received: from m0353722.ppops.net (m0353722.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33QNwRMD032021; Wed, 26 Apr 2023 23:58:27 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q7d0jhm7u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Apr 2023 23:58:26 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 33QLPCuM019354; Wed, 26 Apr 2023 23:58:25 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3q47772myb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Apr 2023 23:58:25 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 33QNwMOM43188634 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Apr 2023 23:58:22 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C0F8720040; Wed, 26 Apr 2023 23:58:22 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5B7AC20043; Wed, 26 Apr 2023 23:58:22 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.69.68]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 26 Apr 2023 23:58:22 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=hiqiRac3dxtgF39ZNOcW2loLDhOLmcN8rVWRikfrgy0=; b=sQg+qsIAfqOmA0jnS0xTzqWDkfcvze8Gfackkf375WyA0cdlCxB7rBnRIi9KsnbVOLAA WdRyHW64pSYymM9juXPFo+hk7xOUdGtFtEHduxDTNi+9iVCJpihUxeWkjBfBAv9PDI3u hasT3BimnZerl8rBjW6mxopHSZ0eAWrVpJyu55hAYrFT9acPpbuj/Eh2Oug0W2ZCt3eO qPFbk3DAbUZ+yWZU0SL+aYr0m4GSe+P8C3vHg600qQnf17PGR3UulEiDy4kh0h3pIwSD bS/hL7CKNkewDXphjGVJbi9jZH8/YnRkPfshi0gRVwHYzB07LWGSyw1YrhR1W6fE3La0 DA== From: Ilya Leoshkevich To: Richard Henderson , David Hildenbrand , Thomas Huth Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH 2/2] tests/tcg/s390x: Test EXECUTE of relative branches Date: Thu, 27 Apr 2023 01:58:13 +0200 Message-Id: <20230426235813.198183-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230426235813.198183-1-iii@linux.ibm.com> References: <20230426235813.198183-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 9GHWKpnd_WB3AXcHBdlF2XmpInzJIrQo X-Proofpoint-GUID: DjPkcf7oCXE8zCf-Zye_ngc_aKkCKHdb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-26_10,2023-04-26_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 phishscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304260203 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=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @ibm.com) X-ZM-MESSAGEID: 1682553561991100007 Content-Type: text/plain; charset="utf-8" Add a small test to prevent regressions. Signed-off-by: Ilya Leoshkevich Acked-by: Richard Henderson --- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/ex-branch.c | 158 ++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 tests/tcg/s390x/ex-branch.c diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.tar= get index 0031868b136..23dc8b6a63f 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -34,6 +34,7 @@ TESTS+=3Dcdsg TESTS+=3Dchrl TESTS+=3Drxsbg TESTS+=3Dex-relative-long +TESTS+=3Dex-branch =20 cdsg: CFLAGS+=3D-pthread cdsg: LDFLAGS+=3D-pthread diff --git a/tests/tcg/s390x/ex-branch.c b/tests/tcg/s390x/ex-branch.c new file mode 100644 index 00000000000..c6067191528 --- /dev/null +++ b/tests/tcg/s390x/ex-branch.c @@ -0,0 +1,158 @@ +/* Check EXECUTE with relative branch instructions as targets. */ +#include +#include +#include +#include +#include + +struct test { + const char *name; + void (*func)(long *link, long *magic); + long exp_link; +}; + +/* Branch instructions and their expected effects. */ +#define LINK_64(test) ((long)test ## _exp_link) +#define LINK_NONE(test) -1L +#define FOR_EACH_INSN(F) = \ + F(bras, "%[link]", LINK_64) = \ + F(brasl, "%[link]", LINK_64) = \ + F(brc, "0x8", LINK_NONE) = \ + F(brcl, "0x8", LINK_NONE) = \ + F(brct, "%%r0", LINK_NONE) = \ + F(brctg, "%%r0", LINK_NONE) = \ + F(brxh, "%%r2,%%r0", LINK_NONE) = \ + F(brxhg, "%%r2,%%r0", LINK_NONE) = \ + F(brxle, "%%r0,%%r1", LINK_NONE) = \ + F(brxlg, "%%r0,%%r1", LINK_NONE) = \ + F(crj, "%%r0,%%r0,8", LINK_NONE) = \ + F(cgrj, "%%r0,%%r0,8", LINK_NONE) = \ + F(cij, "%%r0,0,8", LINK_NONE) = \ + F(cgij, "%%r0,0,8", LINK_NONE) = \ + F(clrj, "%%r0,%%r0,8", LINK_NONE) = \ + F(clgrj, "%%r0,%%r0,8", LINK_NONE) = \ + F(clij, "%%r0,0,8", LINK_NONE) = \ + F(clgij, "%%r0,0,8", LINK_NONE) + +#define INIT_TEST = \ + "xgr %%r0,%%r0\n" /* %r0 =3D 0; %cc =3D 0 */ = \ + "lghi %%r1,1\n" /* %r1 =3D 1 */ = \ + "lghi %%r2,2\n" /* %r2 =3D 2 */ + +#define CLOBBERS_TEST "cc", "0", "1", "2" + +#define DEFINE_TEST(insn, args, exp_link) = \ + extern char insn ## _exp_link[]; = \ + static void test_ ## insn(long *link, long *magic) = \ + { = \ + asm(INIT_TEST = \ + #insn " " args ",0f\n" = \ + ".globl " #insn "_exp_link\n" = \ + #insn "_exp_link:\n" = \ + ".org . + 90\n" = \ + "0: lgfi %[magic],0x12345678\n" = \ + : [link] "+r" (*link) = \ + , [magic] "+r" (*magic) = \ + : : CLOBBERS_TEST); = \ + } = \ + extern char ex_ ## insn ## _exp_link[]; = \ + static void test_ex_ ## insn(long *link, long *magic) = \ + { = \ + unsigned long target; = \ + = \ + asm(INIT_TEST = \ + "larl %[target],0f\n" = \ + "ex %%r0,0(%[target])\n" = \ + ".globl ex_" #insn "_exp_link\n" = \ + "ex_" #insn "_exp_link:\n" = \ + ".org . + 60\n" = \ + "0: " #insn " " args ",1f\n" = \ + ".org . + 120\n" = \ + "1: lgfi %[magic],0x12345678\n" = \ + : [target] "=3Dr" (target) = \ + , [link] "+r" (*link) = \ + , [magic] "+r" (*magic) = \ + : : CLOBBERS_TEST); = \ + } = \ + extern char exrl_ ## insn ## _exp_link[]; = \ + static void test_exrl_ ## insn(long *link, long *magic) = \ + { = \ + asm(INIT_TEST = \ + "exrl %%r0,0f\n" = \ + ".globl exrl_" #insn "_exp_link\n" = \ + "exrl_" #insn "_exp_link:\n" = \ + ".org . + 60\n" = \ + "0: " #insn " " args ",1f\n" = \ + ".org . + 120\n" = \ + "1: lgfi %[magic],0x12345678\n" = \ + : [link] "+r" (*link) = \ + , [magic] "+r" (*magic) = \ + : : CLOBBERS_TEST); = \ + } + +/* Test functions. */ +FOR_EACH_INSN(DEFINE_TEST) + +/* Test definitions. */ +#define REGISTER_TEST(insn, args, _exp_link) = \ + { = \ + .name =3D #insn, = \ + .func =3D test_ ## insn, = \ + .exp_link =3D (_exp_link(insn)), = \ + }, = \ + { = \ + .name =3D "ex " #insn, = \ + .func =3D test_ex_ ## insn, = \ + .exp_link =3D (_exp_link(ex_ ## insn)), = \ + }, = \ + { = \ + .name =3D "exrl " #insn, = \ + .func =3D test_exrl_ ## insn, = \ + .exp_link =3D (_exp_link(exrl_ ## insn)), = \ + }, + +static const struct test tests[] =3D { + FOR_EACH_INSN(REGISTER_TEST) +}; + +int main(int argc, char **argv) +{ + const struct test *test; + int ret =3D EXIT_SUCCESS; + bool verbose =3D false; + long link, magic; + size_t i; + + for (i =3D 1; i < argc; i++) { + if (strcmp(argv[i], "-v") =3D=3D 0) { + verbose =3D true; + } + } + + for (i =3D 0; i < sizeof(tests) / sizeof(tests[0]); i++) { + test =3D &tests[i]; + if (verbose) { + fprintf(stderr, "[ RUN ] %s\n", test->name); + } + link =3D -1; + magic =3D -1; + test->func(&link, &magic); +#define ASSERT_EQ(expected, actual) do { = \ + if (expected !=3D actual) { = \ + fprintf(stderr, "%s: " #expected " (0x%lx) !=3D " #actual " (0x%lx= )\n", \ + test->name, expected, actual); = \ + ret =3D EXIT_FAILURE; = \ + } = \ +} while (0) + ASSERT_EQ(test->exp_link, link); + ASSERT_EQ(0x12345678L, magic); +#undef ASSERT_EQ + } + + if (verbose) { + fprintf(stderr, ret =3D=3D EXIT_SUCCESS ? "[ PASSED ]\n" : + "[ FAILED ]\n"); + } + + return ret; +} --=20 2.40.0