From patchwork Mon Feb 11 23:52:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 158051 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3211411jaa; Mon, 11 Feb 2019 16:08:46 -0800 (PST) X-Google-Smtp-Source: AHgI3Ibgqt8A2W/JOuGvqUuhs409qdk/NVQtaKRq9LtrlSLzK9V6ymybUDFSvfiPZPOCpFaLB1QM X-Received: by 2002:a81:3944:: with SMTP id g65mr670015ywa.337.1549930126932; Mon, 11 Feb 2019 16:08:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549930126; cv=none; d=google.com; s=arc-20160816; b=bpV36i4Y82ECviqBl32QN84TlQxUZf7dL6kfmevjBdtCB4LNL5Djq9zGFhjR0jjzjh lIrnsnH3K5Sl4S+cwmtEoPJM0U92xX+wAPhhyN0a5lMYZarxSsF3khQLggGwHjJHa6XH ci1N+5k6lv2IVpnE83aLrpdMXb2D75VKIZC7qoNwhRjkhqTSr9Uh2Yhlbh2pzJFrdY7B FreD1/1YG7O4rUWQn9wLENQC4KDDR4xObzS/zSHjtQCIkuggO+HC4ANtFLPZrfJNFT2d qeuRG3XgzHKLUwi4KUpLLDgRTwtWeXt4z7Z5cqcP03Mm5vYp98uRDCluBs0OAOx7KEHg 85Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=GFj0m2pqBwYhUNoAsjQMSgz6zB0/Trk1Z4b3L8tgOKM=; b=LT7MT8Jti50t1hicGVk9MAtkZTLI0iw1qSLriN/+g5s93gq8xtXi6SSo1x2B4e5kxK 3oBdB9zD/K874O3F8H6/wmPF6StEDLRE3POj1OmPxki1f4NnZne+n9W41nM2YXhp4fvx 1iD7NSUyZknGCkryO7GMb29WdlGa17fGSwSJkfXxwd0UC8mlix97aFbElavzInSf/vEz f19Vf/9KnTuJJfhK+DEJWmTWQquigXAI6sNTfjPe4NH3c5EDCQYQn127fSyDdXGqnNEM kQd2aQ7hjQ3Qg+zSbJNU6kb5p011CtY2PSIlSQ+TXGtjNeDzZ3Br9lW70qMSuWNKhC5b pGIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="LZourBT/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q1si6424601ybp.151.2019.02.11.16.08.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Feb 2019 16:08:46 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="LZourBT/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:58374 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtLd0-0000Em-D3 for patch@linaro.org; Mon, 11 Feb 2019 19:08:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtLOh-0005s5-Ih for qemu-devel@nongnu.org; Mon, 11 Feb 2019 18:54:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtLOf-0004zw-0G for qemu-devel@nongnu.org; Mon, 11 Feb 2019 18:53:59 -0500 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:37775) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gtLOe-0004Rn-Ju for qemu-devel@nongnu.org; Mon, 11 Feb 2019 18:53:56 -0500 Received: by mail-pf1-x443.google.com with SMTP id y126so337556pfb.4 for ; Mon, 11 Feb 2019 15:53:18 -0800 (PST) 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=GFj0m2pqBwYhUNoAsjQMSgz6zB0/Trk1Z4b3L8tgOKM=; b=LZourBT/lW/TOntHWoLTxskhFtFMwzLnxrT7C3tVNxI2XDf/XQ7W2746S9xe8tj6QZ zEgSLsVgqUs1efrqc2NRmUhaQILHTJhj63tVMqQvAZCVs3druPI2FYnxGxpQorSUICSi 0MHObMqHoL//mFX4lzqiVvjLwcYK1jqs0i4Pk1ThI+RaYpGXURdX+uen/bKYaMWBl34f OJPfVveMX3sERHwqVDZ0TqWs5hqcQS8N5D2XI3xu6ujn18fE+OiM/JXopEm12q8DGs7X TodJjd3vsb9JuEMBGOE9nhAGqiBmMQqaPL9upsDs/mpOACm69jCaXR8Ee4CU805pi4+E atmw== 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=GFj0m2pqBwYhUNoAsjQMSgz6zB0/Trk1Z4b3L8tgOKM=; b=sZKjOQmkF3+uaYKOZN4tyeDuBkZwnA3Gg0YtTxtiH+TihkFEKso4JKPUUT/Q+fDqG/ D9XVDbAoOQmiugQ0fW0JvrUNZxJhcNV2u8DrNMMifAyeYWKofpFVLI/8AjkUG7iheuNE GHRxgAqqL81xn2717oq4d96KU7tGneSTo4TLiJn7QGQPjcSTvQ6F5j/kLDCuVFOBPwdy RsOh2/MMddY9vnP72WOfnPdKo0nZjUaisRQZDfohq4gUaul3HUvpSdqjya96SBeMrxfg A391IQDNSewXIshFl8Gl6d2zqv9GWMq0rLWIRqM/4lO4fFdbIKJBZdhjYwkjg3y14hF6 Ccdg== X-Gm-Message-State: AHQUAuZtR6ZB3QxQ77WHjK9MnG3dNQbtb/x6meDW+Ioly+bx86pE8bzs tR0+ZwDLLUKYeRm55cwBz9fjUCNavK4= X-Received: by 2002:a62:f5d7:: with SMTP id b84mr949245pfm.36.1549929195835; Mon, 11 Feb 2019 15:53:15 -0800 (PST) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id c4sm11861031pgq.85.2019.02.11.15.53.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Feb 2019 15:53:15 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 11 Feb 2019 15:52:41 -0800 Message-Id: <20190211235258.542-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190211235258.542-1-richard.henderson@linaro.org> References: <20190211235258.542-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v3 11/28] target/arm: Implement ADDG, SUBG instructions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v2: Shift offset in translate; use extract32. --- target/arm/helper-a64.h | 2 ++ target/arm/internals.h | 4 +++ target/arm/mte_helper.c | 32 +++++++++++++++++ target/arm/translate-a64.c | 71 ++++++++++++++++++++++++++------------ 4 files changed, 86 insertions(+), 23 deletions(-) -- 2.17.2 diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h index 0f6e78c77e..6ad23bf9ee 100644 --- a/target/arm/helper-a64.h +++ b/target/arm/helper-a64.h @@ -106,3 +106,5 @@ DEF_HELPER_FLAGS_2(xpacd, TCG_CALL_NO_RWG_SE, i64, env, i64) DEF_HELPER_FLAGS_2(mte_check1, TCG_CALL_NO_WG, i64, env, i64) DEF_HELPER_FLAGS_3(mte_check2, TCG_CALL_NO_WG, i64, env, i64, i32) DEF_HELPER_FLAGS_3(irg, TCG_CALL_NO_RWG, i64, env, i64, i64) +DEF_HELPER_FLAGS_4(addg, TCG_CALL_NO_RWG_SE, i64, env, i64, i32, i32) +DEF_HELPER_FLAGS_4(subg, TCG_CALL_NO_RWG_SE, i64, env, i64, i32, i32) diff --git a/target/arm/internals.h b/target/arm/internals.h index fbfa770c23..8d1a81df8c 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1008,4 +1008,8 @@ static inline bool allocation_tag_access_enabled(CPUARMState *env, int el, */ #define GMID_EL1_BS 6 +/* We associate one allocation tag per 16 bytes, the minimum. */ +#define LOG2_TAG_GRANULE 4 +#define TAG_GRANULE (1 << LOG2_TAG_GRANULE) + #endif diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index cd04e4954b..7aca5b074f 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -188,3 +188,35 @@ uint64_t HELPER(irg)(CPUARMState *env, uint64_t rn, uint64_t rm) return address_with_allocation_tag(rn, rtag); } + +uint64_t HELPER(addg)(CPUARMState *env, uint64_t ptr, + uint32_t offset, uint32_t tag_offset) +{ + int el = arm_current_el(env); + uint64_t sctlr = arm_sctlr(env, el); + int rtag = 0; + + if (allocation_tag_access_enabled(env, el, sctlr)) { + int start_tag = allocation_tag_from_addr(ptr); + uint16_t exclude = extract32(env->cp15.gcr_el1, 0, 16); + rtag = choose_nonexcluded_tag(start_tag, tag_offset, exclude); + } + + return address_with_allocation_tag(ptr + offset, rtag); +} + +uint64_t HELPER(subg)(CPUARMState *env, uint64_t ptr, + uint32_t offset, uint32_t tag_offset) +{ + int el = arm_current_el(env); + uint64_t sctlr = arm_sctlr(env, el); + int rtag = 0; + + if (allocation_tag_access_enabled(env, el, sctlr)) { + int start_tag = allocation_tag_from_addr(ptr); + uint16_t exclude = extract32(env->cp15.gcr_el1, 0, 16); + rtag = choose_nonexcluded_tag(start_tag, tag_offset, exclude); + } + + return address_with_allocation_tag(ptr - offset, rtag); +} diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 141a03a88f..8e322bd6a0 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -3679,7 +3679,9 @@ static void disas_pc_rel_adr(DisasContext *s, uint32_t insn) * sf: 0 -> 32bit, 1 -> 64bit * op: 0 -> add , 1 -> sub * S: 1 -> set flags - * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12 + * shift: 00 -> LSL imm by 0, + * 01 -> LSL imm by 12 + * 10 -> ADDG, SUBG */ static void disas_add_sub_imm(DisasContext *s, uint32_t insn) { @@ -3690,10 +3692,10 @@ static void disas_add_sub_imm(DisasContext *s, uint32_t insn) bool setflags = extract32(insn, 29, 1); bool sub_op = extract32(insn, 30, 1); bool is_64bit = extract32(insn, 31, 1); + bool is_tag = false; TCGv_i64 tcg_rn = cpu_reg_sp(s, rn); TCGv_i64 tcg_rd = setflags ? cpu_reg(s, rd) : cpu_reg_sp(s, rd); - TCGv_i64 tcg_result; switch (shift) { case 0x0: @@ -3701,35 +3703,58 @@ static void disas_add_sub_imm(DisasContext *s, uint32_t insn) case 0x1: imm <<= 12; break; + case 0x2: + /* ADDG, SUBG */ + if (!is_64bit || setflags || (imm & 0x30) || + !dc_isar_feature(aa64_mte_insn_reg, s)) { + goto do_unallocated; + } + is_tag = true; + break; default: + do_unallocated: unallocated_encoding(s); return; } - tcg_result = tcg_temp_new_i64(); - if (!setflags) { - if (sub_op) { - tcg_gen_subi_i64(tcg_result, tcg_rn, imm); - } else { - tcg_gen_addi_i64(tcg_result, tcg_rn, imm); - } - } else { - TCGv_i64 tcg_imm = tcg_const_i64(imm); - if (sub_op) { - gen_sub_CC(is_64bit, tcg_result, tcg_rn, tcg_imm); - } else { - gen_add_CC(is_64bit, tcg_result, tcg_rn, tcg_imm); - } - tcg_temp_free_i64(tcg_imm); - } + if (is_tag) { + TCGv_i32 tag_offset = tcg_const_i32(imm & 15); + TCGv_i32 offset = tcg_const_i32((imm >> 6) << LOG2_TAG_GRANULE); - if (is_64bit) { - tcg_gen_mov_i64(tcg_rd, tcg_result); + if (sub_op) { + gen_helper_subg(tcg_rd, cpu_env, tcg_rn, offset, tag_offset); + } else { + gen_helper_addg(tcg_rd, cpu_env, tcg_rn, offset, tag_offset); + } + tcg_temp_free_i32(tag_offset); + tcg_temp_free_i32(offset); } else { - tcg_gen_ext32u_i64(tcg_rd, tcg_result); - } + TCGv_i64 tcg_result; - tcg_temp_free_i64(tcg_result); + if (!setflags) { + tcg_result = tcg_rd; + if (sub_op) { + tcg_gen_subi_i64(tcg_result, tcg_rn, imm); + } else { + tcg_gen_addi_i64(tcg_result, tcg_rn, imm); + } + } else { + TCGv_i64 tcg_imm = tcg_const_i64(imm); + tcg_result = new_tmp_a64(s); + if (sub_op) { + gen_sub_CC(is_64bit, tcg_result, tcg_rn, tcg_imm); + } else { + gen_add_CC(is_64bit, tcg_result, tcg_rn, tcg_imm); + } + tcg_temp_free_i64(tcg_imm); + } + + if (is_64bit) { + tcg_gen_mov_i64(tcg_rd, tcg_result); + } else { + tcg_gen_ext32u_i64(tcg_rd, tcg_result); + } + } } /* The input should be a value in the bottom e bits (with higher