From nobody Mon Feb 9 23:39:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1566252029; cv=none; d=zoho.com; s=zohoarc; b=N729Yj/eVwFBpPlHY6pJQc6w8PjB6BFAs6MF9QxInb+q6NCLLtszWmwq/AmwdVqVBmnJc8jamQ9COHlDJeY+BiuLdQOwapFbxpSqkcQKCgm0jl5pXvNVEevMpEmmAWrRwbuN9bMyYkbZ+I1bnoea77Xiq2hcoKufxXSUw+eOU6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566252029; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=v9AR5e2vTyYPnkVwbheCeAc1mDx0MtVRV+9wSe0MQcA=; b=RW+9itF0sytAjBOx+fvnxYh2FRKCPhCVZOBxLogDuYBG3QZb5AAYOAl0NK3iguKQWX5qOzYzQLGrHZB22TGutK248zv9ayYzDiybWkK0vmUhU4IFzfJ4sYWK+WzuWI6MoYsNzP+ri9UhNiExax70oAEfWWmN981DdOxG44Tj8yk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566252029733119.51847072013538; Mon, 19 Aug 2019 15:00:29 -0700 (PDT) Received: from localhost ([::1]:59348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hzphT-0004wZ-Vc for importer@patchew.org; Mon, 19 Aug 2019 18:00:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59277) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hzpMO-0002Bt-0j for qemu-devel@nongnu.org; Mon, 19 Aug 2019 17:38:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hzpML-0006PX-RE for qemu-devel@nongnu.org; Mon, 19 Aug 2019 17:38:39 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:44076) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hzpML-0006P1-Jh for qemu-devel@nongnu.org; Mon, 19 Aug 2019 17:38:37 -0400 Received: by mail-pg1-x531.google.com with SMTP id i18so1918362pgl.11 for ; Mon, 19 Aug 2019 14:38:37 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id d2sm13446951pjs.21.2019.08.19.14.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 14:38:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v9AR5e2vTyYPnkVwbheCeAc1mDx0MtVRV+9wSe0MQcA=; b=wV4Onl44EKekCd9FaaKJMCo1vE4fdDbrqc2iDsjvigz6jF4KNk5jjjpbFUEgSWsfYn cMvFLsfgjGmS3gJ0PbsjrVEkGlnbqTNb5m2Hi68lWz/0CRKTr8cJ8m0/KWewBywxeW0E mf8qmGZkkt3OZa2BZbZxFXbV2r6zdWN2sBsWryDaqhIx71oraD4VrYY9JwoC5HO7yF5y HpoghHt75dQWeTAjvuDDlnDQ1CNvIjLO7naBiGBvd0yZh7E94ctGRdh+TJyylEDr44BO jV3ERhB1fugFkZmLTpUYOvhjgWIcQZSsA6H0pK3IpNVhLrL+P2nzDsD1ehSDpLfz0qvd WyMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v9AR5e2vTyYPnkVwbheCeAc1mDx0MtVRV+9wSe0MQcA=; b=jF95GAfzXXV4pVBhmolZNbjnfGS3IcaBo2sFl3/T92Q1582VW1PGOHRCqu7VkUzfGI rXsnIvVgVLHgQg4xbk3yagyIzYhN6u5y41447NurYB1FcolqL1haIz+WBJ4WyU7UKXC/ PsdqqYXq9K4VKx7F+w79UxBqMdKYfokNs/mRHaR22SqbpA8L/ghlRKounc+9EMYANlVK ClQ98I+XsTId/knZf3lb/zC2r6PH+0ZQKrIv4O1/SUNyas8pa+xffE4GvtBzO/DgtI5q 77l5E8ZE+8o1tvZfJCQmxqW5Y1lE3z2Sp3GZL/BrK+Vq+E0tylHrLCo9utMRhL3GrXRh 2T3Q== X-Gm-Message-State: APjAAAWBiP5oTflWxKtRiB+z7Rq6VVAxcw3dv5hglQXBsTamooypAE+k I33kMxm3ZY6YKWlhe7YSbmyYPTYI4/Y= X-Google-Smtp-Source: APXvYqz8EyxmQUGzacBCvd7RvkMsncsnWF7EMViwR8Kh/QIZfDefJt51KrsrUwBq87Pd7MGq4LvsvA== X-Received: by 2002:a17:90a:feb:: with SMTP id 98mr21704602pjz.55.1566250716060; Mon, 19 Aug 2019 14:38:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 19 Aug 2019 14:37:18 -0700 Message-Id: <20190819213755.26175-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190819213755.26175-1-richard.henderson@linaro.org> References: <20190819213755.26175-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::531 Subject: [Qemu-devel] [PATCH v2 31/68] target/arm: Convert B, BL, BLX (immediate) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/translate.c | 133 +++++++++++++++-------------------- target/arm/a32-uncond.decode | 8 +++ target/arm/a32.decode | 8 +++ target/arm/t32.decode | 81 ++++++++++++--------- 4 files changed, 123 insertions(+), 107 deletions(-) diff --git a/target/arm/translate.c b/target/arm/translate.c index 09636aab4e..6b7b3df685 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -7523,6 +7523,14 @@ static int t32_expandimm_imm(DisasContext *s, int x) return imm; } =20 +static int t32_branch24(DisasContext *s, int x) +{ + /* Convert J1:J2 at x[22:21] to I2:I1, which involves I=3DJ^~S. */ + x ^=3D !(x < 0) * (3 << 21); + /* Append the final zero. */ + return x << 1; +} + /* * Include the generated decoders. */ @@ -9917,13 +9925,56 @@ static bool trans_LDM_t32(DisasContext *s, arg_ldst= _block *a) return do_ldm(s, a, 2); } =20 +/* + * Branch, branch with link + */ + +static bool trans_B(DisasContext *s, arg_i *a) +{ + gen_jmp(s, read_pc(s) + a->imm); + return true; +} + +static bool trans_B_cond_thumb(DisasContext *s, arg_ci *a) +{ + /* This has cond from encoding, required to be outside IT block. */ + if (a->cond >=3D 0xe) { + return false; + } + if (s->condexec_mask) { + unallocated_encoding(s); + return true; + } + arm_skip_unless(s, a->cond); + gen_jmp(s, read_pc(s) + a->imm); + return true; +} + +static bool trans_BL(DisasContext *s, arg_i *a) +{ + tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | s->thumb); + gen_jmp(s, read_pc(s) + a->imm); + return true; +} + +static bool trans_BLX_i(DisasContext *s, arg_BLX_i *a) +{ + /* For A32, ARCH(5) is checked near the start of the uncond block. */ + if (s->thumb && (a->imm & 2)) { + return false; + } + tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | s->thumb); + gen_bx_im(s, (read_pc(s) & ~3) + a->imm + !s->thumb); + return true; +} + /* * Legacy decoder. */ =20 static void disas_arm_insn(DisasContext *s, unsigned int insn) { - unsigned int cond, val, op1, i, rn; + unsigned int cond, op1, i, rn; TCGv_i32 tmp; TCGv_i32 tmp2; TCGv_i32 addr; @@ -10091,21 +10142,6 @@ static void disas_arm_insn(DisasContext *s, unsign= ed int insn) } gen_rfe(s, tmp, tmp2); return; - } else if ((insn & 0x0e000000) =3D=3D 0x0a000000) { - /* branch link and change to thumb (blx ) */ - int32_t offset; - - tmp =3D tcg_temp_new_i32(); - tcg_gen_movi_i32(tmp, s->base.pc_next); - store_reg(s, 14, tmp); - /* Sign-extend the 24-bit offset */ - offset =3D (((int32_t)insn) << 8) >> 8; - val =3D read_pc(s); - /* offset * 4 + bit24 * 2 + (thumb bit) */ - val +=3D (offset << 2) | ((insn >> 23) & 2) | 1; - /* protected by ARCH(5); above, near the start of uncond block= */ - gen_bx_im(s, val); - return; } else if ((insn & 0x0e000f00) =3D=3D 0x0c000100) { if (arm_dc_feature(s, ARM_FEATURE_IWMMXT)) { /* iWMMXt register transfer. */ @@ -10197,23 +10233,10 @@ static void disas_arm_insn(DisasContext *s, unsig= ned int insn) case 0x7: case 0x08: case 0x09: - /* All done in decodetree. Reach here for illegal ops. */ - goto illegal_op; case 0xa: case 0xb: - { - int32_t offset; - - /* branch (and link) */ - if (insn & (1 << 24)) { - tmp =3D tcg_temp_new_i32(); - tcg_gen_movi_i32(tmp, s->base.pc_next); - store_reg(s, 14, tmp); - } - offset =3D sextract32(insn << 2, 0, 26); - gen_jmp(s, read_pc(s) + offset); - } - break; + /* All done in decodetree. Reach here for illegal ops. */ + goto illegal_op; case 0xc: case 0xd: case 0xe: @@ -10580,32 +10603,8 @@ static void disas_thumb2_insn(DisasContext *s, uin= t32_t insn) if (insn & (1 << 15)) { /* Branches, misc control. */ if (insn & 0x5000) { - /* Unconditional branch. */ - /* signextend(hw1[10:0]) -> offset[:12]. */ - offset =3D ((int32_t)insn << 5) >> 9 & ~(int32_t)0xfff; - /* hw1[10:0] -> offset[11:1]. */ - offset |=3D (insn & 0x7ff) << 1; - /* (~hw2[13, 11] ^ offset[24]) -> offset[23,22] - offset[24:22] already have the same value because of the - sign extension above. */ - offset ^=3D ((~insn) & (1 << 13)) << 10; - offset ^=3D ((~insn) & (1 << 11)) << 11; - - if (insn & (1 << 14)) { - /* Branch and link. */ - tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | 1); - } - - offset +=3D read_pc(s); - if (insn & (1 << 12)) { - /* b/bl */ - gen_jmp(s, offset); - } else { - /* blx */ - offset &=3D ~(uint32_t)2; - /* thumb2 bx, no need to check */ - gen_bx_im(s, offset); - } + /* Unconditional branch, in decodetree */ + goto illegal_op; } else if (((insn >> 23) & 7) =3D=3D 7) { /* Misc control */ if (insn & (1 << 13)) @@ -10691,24 +10690,8 @@ static void disas_thumb2_insn(DisasContext *s, uin= t32_t insn) } } } else { - /* Conditional branch. */ - op =3D (insn >> 22) & 0xf; - /* Generate a conditional jump to next instruction. */ - arm_skip_unless(s, op); - - /* offset[11:1] =3D insn[10:0] */ - offset =3D (insn & 0x7ff) << 1; - /* offset[17:12] =3D insn[21:16]. */ - offset |=3D (insn & 0x003f0000) >> 4; - /* offset[31:20] =3D insn[26]. */ - offset |=3D ((int32_t)((insn << 5) & 0x80000000)) >> 11; - /* offset[18] =3D insn[13]. */ - offset |=3D (insn & (1 << 13)) << 5; - /* offset[19] =3D insn[11]. */ - offset |=3D (insn & (1 << 11)) << 8; - - /* jump to the offset */ - gen_jmp(s, read_pc(s) + offset); + /* Conditional branch, in decodetree */ + goto illegal_op; } } else { /* diff --git a/target/arm/a32-uncond.decode b/target/arm/a32-uncond.decode index 8dee26d3b6..573ac2cf8e 100644 --- a/target/arm/a32-uncond.decode +++ b/target/arm/a32-uncond.decode @@ -21,3 +21,11 @@ # All insns that have 0xf in insn[31:28] are decoded here. # All of those that have a COND field in insn[31:28] are in a32.decode # + +&i !extern imm + +# Branch with Link and Exchange + +%imm24h 0:s24 24:1 !function=3Dtimes_2 + +BLX_i 1111 101 . ........................ &i imm=3D%im= m24h diff --git a/target/arm/a32.decode b/target/arm/a32.decode index 1267a689e2..62c6f8562e 100644 --- a/target/arm/a32.decode +++ b/target/arm/a32.decode @@ -520,3 +520,11 @@ SMMLSR .... 0111 0101 .... .... .... 1111 ..= .. @rdamn =20 STM ---- 100 b:1 i:1 u:1 w:1 0 rn:4 list:16 &ldst_block LDM_a32 ---- 100 b:1 i:1 u:1 w:1 1 rn:4 list:16 &ldst_block + +# Branch, branch with link + +%imm26 0:s24 !function=3Dtimes_4 +@branch ---- .... ........................ &i imm=3D%im= m26 + +B .... 1010 ........................ @branch +BL .... 1011 ........................ @branch diff --git a/target/arm/t32.decode b/target/arm/t32.decode index f1e2b934f8..ebc92f2c28 100644 --- a/target/arm/t32.decode +++ b/target/arm/t32.decode @@ -284,47 +284,55 @@ CLZ 1111 1010 1011 ---- 1111 .... 1000 .= ... @rdm %msr_sysm 4:1 8:4 %mrs_sysm 4:1 16:4 %imm16_16_0 16:4 0:12 +%imm21 26:s1 11:1 13:1 16:6 0:11 !function=3Dtimes_2 +&ci cond imm =20 { + # Group insn[25:23] =3D 111, which is cond=3D111x for the branch below, + # or unconditional, which would be illegal for the branch. { - YIELD 1111 0011 1010 1111 1000 0000 0000 0001 - WFE 1111 0011 1010 1111 1000 0000 0000 0010 - WFI 1111 0011 1010 1111 1000 0000 0000 0011 + # Hints + { + YIELD 1111 0011 1010 1111 1000 0000 0000 0001 + WFE 1111 0011 1010 1111 1000 0000 0000 0010 + WFI 1111 0011 1010 1111 1000 0000 0000 0011 =20 - # TODO: Implement SEV, SEVL; may help SMP performance. - # SEV 1111 0011 1010 1111 1000 0000 0000 0100 - # SEVL 1111 0011 1010 1111 1000 0000 0000 0101 + # TODO: Implement SEV, SEVL; may help SMP performance. + # SEV 1111 0011 1010 1111 1000 0000 0000 0100 + # SEVL 1111 0011 1010 1111 1000 0000 0000 0101 =20 - # The canonical nop ends in 0000 0000, but the whole rest - # of the space is "reserved hint, behaves as nop". - NOP 1111 0011 1010 1111 1000 0000 ---- ---- - } - # Note that the v7m insn overlaps both the normal and banked insn. - { - MRS_bank 1111 0011 111 r:1 .... 1000 rd:4 001. 0000 \ + # The canonical nop ends in 0000 0000, but the whole rest + # of the space is "reserved hint, behaves as nop". + NOP 1111 0011 1010 1111 1000 0000 ---- ---- + } + # Note that the v7m insn overlaps both the normal and banked insn. + { + MRS_bank 1111 0011 111 r:1 .... 1000 rd:4 001. 0000 \ &mrs_bank sysm=3D%mrs_sysm - MRS_reg 1111 0011 111 r:1 1111 1000 rd:4 0000 0000 &mrs_reg - MRS_v7m 1111 0011 111 0 1111 1000 rd:4 sysm:8 - } - { - MSR_bank 1111 0011 100 r:1 rn:4 1000 .... 001. 0000 \ + MRS_reg 1111 0011 111 r:1 1111 1000 rd:4 0000 0000 &mrs_reg + MRS_v7m 1111 0011 111 0 1111 1000 rd:4 sysm:8 + } + { + MSR_bank 1111 0011 100 r:1 rn:4 1000 .... 001. 0000 \ &msr_bank sysm=3D%msr_sysm - MSR_reg 1111 0011 100 r:1 rn:4 1000 mask:4 0000 0000 &msr_reg - MSR_v7m 1111 0011 100 0 rn:4 1000 mask:2 00 sysm:8 - } - BXJ 1111 0011 1100 rm:4 1000 1111 0000 0000 &r - { - # At v6T2, this is the T5 encoding of SUBS PC, LR, #IMM, and works as = for - # every other encoding of SUBS. With v7VE, IMM=3D0 is redefined as ER= ET. - # The distinction between the two only matters for Hyp mode. - ERET 1111 0011 1101 1110 1000 1111 0000 0000 - SUB_rri 1111 0011 1101 1110 1000 1111 imm:8 \ + MSR_reg 1111 0011 100 r:1 rn:4 1000 mask:4 0000 0000 &msr_reg + MSR_v7m 1111 0011 100 0 rn:4 1000 mask:2 00 sysm:8 + } + BXJ 1111 0011 1100 rm:4 1000 1111 0000 0000 &r + { + # At v6T2, this is the T5 encoding of SUBS PC, LR, #IMM, and works a= s for + # every other encoding of SUBS. With v7VE, IMM=3D0 is redefined as = ERET. + # The distinction between the two only matters for Hyp mode. + ERET 1111 0011 1101 1110 1000 1111 0000 0000 + SUB_rri 1111 0011 1101 1110 1000 1111 imm:8 \ &s_rri_rot rot=3D0 s=3D1 rd=3D15 rn=3D14 - } - SMC 1111 0111 1111 imm:4 1000 0000 0000 0000 &i - HVC 1111 0111 1110 .... 1000 .... .... .... \ + } + SMC 1111 0111 1111 imm:4 1000 0000 0000 0000 &i + HVC 1111 0111 1110 .... 1000 .... .... .... \ &i imm=3D%imm16_16_0 - UDF 1111 0111 1111 ---- 1010 ---- ---- ---- + UDF 1111 0111 1111 ---- 1010 ---- ---- ---- + } + B_cond_thumb 1111 0. cond:4 ...... 10.0 ............ &ci imm=3D%i= mm21 } =20 # Load/store (register, immediate, literal) @@ -573,3 +581,12 @@ STM_t32 1110 1000 10.0 .... ................ = @ldstm i=3D1 b=3D0 STM_t32 1110 1001 00.0 .... ................ @ldstm i=3D0= b=3D1 LDM_t32 1110 1000 10.1 .... ................ @ldstm i=3D1= b=3D0 LDM_t32 1110 1001 00.1 .... ................ @ldstm i=3D0= b=3D1 + +# Branches + +%imm24 26:s1 13:1 11:1 16:10 0:11 !function=3Dt32_branch24 +@branch24 ................................ &i imm=3D%im= m24 + +B 1111 0. .......... 10.1 ............ @branch24 +BL 1111 0. .......... 11.1 ............ @branch24 +BLX_i 1111 0. .......... 11.0 ............ @branch24 --=20 2.17.1