From patchwork Fri Jan 19 14:17:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 125163 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp313001ljf; Fri, 19 Jan 2018 06:20:39 -0800 (PST) X-Google-Smtp-Source: ACJfBouELaoagkW8hHVd+6rkgQpE0UWI6g3pBH9d+6pAD4FTyw5JQ3Q+YYZvUm2AK+lt+biUt9ur X-Received: by 10.129.77.9 with SMTP id a9mr9321993ywb.439.1516371639038; Fri, 19 Jan 2018 06:20:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516371639; cv=none; d=google.com; s=arc-20160816; b=A5CeKT5SXwBkQaLmYHeHLyFBkNpayJT26zBSCPSkBbzm12NRJCRS+HywZA9FLTfoFL Nss91HBadTmDKZDXkK8ok/FGER/YGF25skxjf/GFcpPJ+gZul78o9A1cDMncmbLCRbtN Y7m34OdZj1vFNYbIamUEe5WeerPisL8sN3XBrxt9Bkaq3v0SLDhJsh32zHs8q69TyDJy 4tYl/hZfjaxudWWgSixlEhGYFz3yrBMM/zomjOaFb95h2yL5KGwsTtqj+n/AH60K79TR PyXYWVhWW34TW9GuGqFMrJBlu7hQ7wNNi5E6AQDSQGMbZeAIyD4eD1rwM6dELZPQS7kI qzoA== 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:arc-authentication-results; bh=qBZt09cinziBTShs18kNmYFdShTC00QvYSjBfY2rS7w=; b=ZS/a9IL1/SrbwSEIrAJDqePkR8uT8FND6K/ex65JDFIB+X4bNQ8PnjMXN+sTaNPUSG kNe2nqcsHoC2NgbI2T4p4R+SU7WvlAPiCMQRqE31C6M6FzElWcvq64l6NEAnEh+2MiRy ywK4PoXyl79x4C/xu4ZA8J/OBM+Q4N9pC0Djx2lDZ71zCmjUk3ja/GgnSlQSFgkNwRSC on2Ar3t/Zt/zkHHpcwFmM4owTEbkQmRq8VbwItKLRmo2SEDWl1DkPVXmPhLZ6EXQnFzW Zqj7wLiWHYXUZOdJG19NG7e1M5R95Z6w5kvThlz30AcXj/IBhG//XJvHiKHOYv1zTHEY C62g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hh+F0RRx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e68si2266467ywa.793.2018.01.19.06.20.38 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Jan 2018 06:20:39 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hh+F0RRx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:51666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecXX4-0006eL-82 for patch@linaro.org; Fri, 19 Jan 2018 09:20:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecXTu-00058l-Eq for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecXTr-00041x-Vf for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:21 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:40191) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ecXTr-00041G-Mh for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:19 -0500 Received: by mail-wr0-x241.google.com with SMTP id 100so1708218wrb.7 for ; Fri, 19 Jan 2018 06:17:19 -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=qBZt09cinziBTShs18kNmYFdShTC00QvYSjBfY2rS7w=; b=hh+F0RRxCD4vthtm02xysED58O5bjs5zohlTm7ozdRh3JYqkfHASw/cPyBcmKObC/j CCKO2OZiRddBMuUvNBlRu3FDKMjl5UTQUvTzLb8j5806rccHYN7oCe1dZKnDPdnzv71d wLMeCzf6G0YEk4jZ/4Av5UML0Mb+Awsb0XJfw= 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=qBZt09cinziBTShs18kNmYFdShTC00QvYSjBfY2rS7w=; b=FGXglIIhq+IUZ40UgFsJZpN14NgLv7vgrQA2pNCMhtgBx3pbtKknCsrfdimBECM3/F cVheXMqM88AC5A/YHEa8UozKc0Rm/nsDLancAs7Q/Bwno3C5lXAubIg929boX5DfNYgp tpmzfFODhTp4QMactiU1ry6AmalaDWszP1xLBOj86/Z83bAju6KyO/42aKHVj/RaJ9n7 RwRMOifeR8AtHcjtqXEXBrLw7dDp/ZE+JX2LDjAwCUM5m56D/1QkERutxNqP1jNnNjP+ Ce6ywDGRqVYC/dBQI+zmx5IfUtvJPit2nzGQFlTjzCEk6Dc2FYg9il83z0MlzMqqpBTI C5cg== X-Gm-Message-State: AKwxytehQE7zprAKZ8XU5nrCnKvOjLw7x85FA+w7xJkYCd96zRndpm69 qbDeCU6XSu6K8/sBnj7KoYOnxrL6YFA= X-Received: by 10.223.173.131 with SMTP id w3mr9983364wrc.214.1516371438332; Fri, 19 Jan 2018 06:17:18 -0800 (PST) Received: from localhost.localdomain ([160.170.62.40]) by smtp.gmail.com with ESMTPSA id m45sm6877266wrf.75.2018.01.19.06.17.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 06:17:17 -0800 (PST) From: Ard Biesheuvel To: qemu-devel@nongnu.org Date: Fri, 19 Jan 2018 14:17:04 +0000 Message-Id: <20180119141707.11733-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180119141707.11733-1-ard.biesheuvel@linaro.org> References: <20180119141707.11733-1-ard.biesheuvel@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH v3 1/4] target/arm: implement SHA-512 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, Ard Biesheuvel Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This implements emulation of the new SHA-512 instructions that have been added as an optional extensions to the ARMv8 Crypto Extensions in ARM v8.2. Signed-off-by: Ard Biesheuvel --- target/arm/cpu.h | 1 + target/arm/crypto_helper.c | 99 +++++++++++++++++++- target/arm/helper.h | 5 + target/arm/translate-a64.c | 99 ++++++++++++++++++++ 4 files changed, 203 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 96316700dd6f..295529366c0a 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1340,6 +1340,7 @@ enum arm_features { ARM_FEATURE_VBAR, /* has cp15 VBAR */ ARM_FEATURE_M_SECURITY, /* M profile Security Extension */ ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ + ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ }; static inline int arm_feature(CPUARMState *env, int feature) diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c index 3b6df3f41a42..15c22c82ca5e 100644 --- a/target/arm/crypto_helper.c +++ b/target/arm/crypto_helper.c @@ -1,7 +1,7 @@ /* * crypto_helper.c - emulate v8 Crypto Extensions instructions * - * Copyright (C) 2013 - 2014 Linaro Ltd + * Copyright (C) 2013 - 2018 Linaro Ltd * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -463,3 +463,100 @@ void HELPER(crypto_sha256su1)(CPUARMState *env, uint32_t rd, uint32_t rn, env->vfp.regs[rd] = make_float64(d.l[0]); env->vfp.regs[rd + 1] = make_float64(d.l[1]); } + +/* + * The SHA-512 logical functions (same as above but using 64-bit operands) + */ + +static uint64_t cho512(uint64_t x, uint64_t y, uint64_t z) +{ + return (x & (y ^ z)) ^ z; +} + +static uint64_t maj512(uint64_t x, uint64_t y, uint64_t z) +{ + return (x & y) | ((x | y) & z); +} + +static uint64_t S0_512(uint64_t x) +{ + return ror64(x, 28) ^ ror64(x, 34) ^ ror64(x, 39); +} + +static uint64_t S1_512(uint64_t x) +{ + return ror64(x, 14) ^ ror64(x, 18) ^ ror64(x, 41); +} + +static uint64_t s0_512(uint64_t x) +{ + return ror64(x, 1) ^ ror64(x, 8) ^ (x >> 7); +} + +static uint64_t s1_512(uint64_t x) +{ + return ror64(x, 19) ^ ror64(x, 61) ^ (x >> 6); +} + +void HELPER(crypto_sha512h)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t rm) +{ + uint64_t d0 = float64_val(env->vfp.regs[rd]); + uint64_t d1 = float64_val(env->vfp.regs[rd + 1]); + uint64_t n0 = float64_val(env->vfp.regs[rn]); + uint64_t n1 = float64_val(env->vfp.regs[rn + 1]); + uint64_t m0 = float64_val(env->vfp.regs[rm]); + uint64_t m1 = float64_val(env->vfp.regs[rm + 1]); + + d1 += S1_512(m1) + cho512(m1, n0, n1); + d0 += S1_512(d1 + m0) + cho512(d1 + m0, m1, n0); + + env->vfp.regs[rd] = make_float64(d0); + env->vfp.regs[rd + 1] = make_float64(d1); +} + +void HELPER(crypto_sha512h2)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t rm) +{ + uint64_t d0 = float64_val(env->vfp.regs[rd]); + uint64_t d1 = float64_val(env->vfp.regs[rd + 1]); + uint64_t n0 = float64_val(env->vfp.regs[rn]); + uint64_t m0 = float64_val(env->vfp.regs[rm]); + uint64_t m1 = float64_val(env->vfp.regs[rm + 1]); + + d1 += S0_512(m0) + maj512(n0, m1, m0); + d0 += S0_512(d1) + maj512(d1, m0, m1); + + env->vfp.regs[rd] = make_float64(d0); + env->vfp.regs[rd + 1] = make_float64(d1); +} + +void HELPER(crypto_sha512su0)(CPUARMState *env, uint32_t rd, uint32_t rn) +{ + uint64_t d0 = float64_val(env->vfp.regs[rd]); + uint64_t d1 = float64_val(env->vfp.regs[rd + 1]); + uint64_t n0 = float64_val(env->vfp.regs[rn]); + + d0 += s0_512(d1); + d1 += s0_512(n0); + + env->vfp.regs[rd] = make_float64(d0); + env->vfp.regs[rd + 1] = make_float64(d1); +} + +void HELPER(crypto_sha512su1)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t rm) +{ + uint64_t d0 = float64_val(env->vfp.regs[rd]); + uint64_t d1 = float64_val(env->vfp.regs[rd + 1]); + uint64_t n0 = float64_val(env->vfp.regs[rn]); + uint64_t n1 = float64_val(env->vfp.regs[rn + 1]); + uint64_t m0 = float64_val(env->vfp.regs[rm]); + uint64_t m1 = float64_val(env->vfp.regs[rm + 1]); + + d0 += s1_512(n0) + m0; + d1 += s1_512(n1) + m1; + + env->vfp.regs[rd] = make_float64(d0); + env->vfp.regs[rd + 1] = make_float64(d1); +} diff --git a/target/arm/helper.h b/target/arm/helper.h index 066729e8ad8e..efa75440ce81 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -534,6 +534,11 @@ DEF_HELPER_4(crypto_sha256h2, void, env, i32, i32, i32) DEF_HELPER_3(crypto_sha256su0, void, env, i32, i32) DEF_HELPER_4(crypto_sha256su1, void, env, i32, i32, i32) +DEF_HELPER_4(crypto_sha512h, void, env, i32, i32, i32) +DEF_HELPER_4(crypto_sha512h2, void, env, i32, i32, i32) +DEF_HELPER_3(crypto_sha512su0, void, env, i32, i32) +DEF_HELPER_4(crypto_sha512su1, void, env, i32, i32, i32) + DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) DEF_HELPER_2(dc_zva, void, env, i64) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index ba94f7d0456a..ec17391f4ff4 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -11111,6 +11111,103 @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn) tcg_temp_free_i32(tcg_rn_regno); } +/* Crypto three-reg SHA512 + * 31 21 20 16 15 14 13 12 11 10 9 5 4 0 + * +-----------------------+------+---+---+-----+--------+------+------+ + * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd | + * +-----------------------+------+---+---+-----+--------+------+------+ + */ +static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) +{ + int opcode = extract32(insn, 10, 2); + int o = extract32(insn, 14, 1); + int rm = extract32(insn, 16, 5); + int rn = extract32(insn, 5, 5); + int rd = extract32(insn, 0, 5); + TCGv_i32 tcg_rd_regno, tcg_rn_regno, tcg_rm_regno; + CryptoThreeOpEnvFn *genfn; + + if (o != 0) { + unallocated_encoding(s); + return; + } + + switch (opcode) { + case 0: /* SHA512H */ + genfn = gen_helper_crypto_sha512h; + break; + case 1: /* SHA512H2 */ + genfn = gen_helper_crypto_sha512h2; + break; + case 2: /* SHA512SU1 */ + genfn = gen_helper_crypto_sha512su1; + break; + default: + unallocated_encoding(s); + return; + } + + if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA512)) { + unallocated_encoding(s); + return; + } + + if (!fp_access_check(s)) { + return; + } + + tcg_rd_regno = tcg_const_i32(rd << 1); + tcg_rn_regno = tcg_const_i32(rn << 1); + tcg_rm_regno = tcg_const_i32(rm << 1); + + genfn(cpu_env, tcg_rd_regno, tcg_rn_regno, tcg_rm_regno); + + tcg_temp_free_i32(tcg_rd_regno); + tcg_temp_free_i32(tcg_rn_regno); + tcg_temp_free_i32(tcg_rm_regno); +} + +/* Crypto two-reg SHA512 + * 31 12 11 10 9 5 4 0 + * +-----------------------------------------+--------+------+------+ + * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd | + * +-----------------------------------------+--------+------+------+ + */ +static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) +{ + int opcode = extract32(insn, 10, 2); + int rn = extract32(insn, 5, 5); + int rd = extract32(insn, 0, 5); + TCGv_i32 tcg_rd_regno, tcg_rn_regno; + CryptoTwoOpEnvFn *genfn; + + switch (opcode) { + case 0: /* SHA512SU0 */ + genfn = gen_helper_crypto_sha512su0; + break; + default: + unallocated_encoding(s); + return; + } + + if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA512)) { + unallocated_encoding(s); + return; + } + + if (!fp_access_check(s)) { + return; + } + + tcg_rd_regno = tcg_const_i32(rd << 1); + tcg_rn_regno = tcg_const_i32(rn << 1); + + genfn(cpu_env, tcg_rd_regno, tcg_rn_regno); + + tcg_temp_free_i32(tcg_rd_regno); + tcg_temp_free_i32(tcg_rn_regno); +} + /* C3.6 Data processing - SIMD, inc Crypto * * As the decode gets a little complex we are using a table based @@ -11140,6 +11237,8 @@ static const AArch64DecodeTable data_proc_simd[] = { { 0x4e280800, 0xff3e0c00, disas_crypto_aes }, { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha }, { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha }, + { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 }, + { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, { 0x00000000, 0x00000000, NULL } }; From patchwork Fri Jan 19 14:17:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 125166 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp313540ljf; Fri, 19 Jan 2018 06:22:03 -0800 (PST) X-Google-Smtp-Source: ACJfBotLGThE+3EHjsvz9Fe0r9FUSKDk3K7TniBFLF2t/Bx5LR3KSzwxOlv6psPpkL3A02HDCsMc X-Received: by 10.129.60.9 with SMTP id j9mr9466462ywa.315.1516371723105; Fri, 19 Jan 2018 06:22:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516371723; cv=none; d=google.com; s=arc-20160816; b=QOpsLL4dDjJglHZeC0lNXWLLkJzg5satD9qluuGRdojtiMeUETaZgkc+G5TYYufq4c zB2BWiIEY9beOi9t6GoLN0qYa8nYHTjB2kURcqjTYd84R7yx36YQfkUVnmsna5NJqWKy ULGu8G3U9ptlq/oOs7JEfp5+mKdOF7yGDFaNXyynzk8APE3fy0+zfSUVga1UHBokz2/C 3DBzurHeUwSoaJZ5T5URUy9VrIo1LiHHrUX6CPwhCGYOywyQAnDJP1Pi9etE+sobffDF fc61e5AyorEscdLGp+DH0fnwB6wmmTSBzefFux6r/RWr28zhE0+onF5lAdYTP1lPluMM +7ag== 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:arc-authentication-results; bh=lSyq7DB1K8Z4KtCRzayzaZF2p0I3QteJCk8Io6RQ4e0=; b=V0iLC7uzJZox800kTBQLTOwIzzzyIIm1DlTye6U/oAoQc0n3G26TdCoMhiz9mXDPON lcSjQ7oS+hhzGXCDs4T4k40QP/+TxTTZwUi4+D0bKDycvQtmZkFgdVLcypiP0X/+5lJT 0aXK7/kTdT068Bfnd7UwA4/4xolvcqXt+sSL/P5mPG58IN6TlXCmByI7PNhboLp9SZdS 3AJKzUfeYdvmiSuSKIKJyL+NpIG/4Nn9ISNOjka7Y2gRs8zWrWv/Ome8+EGCJXQ+s6Y/ u06vXhEW8r2g6aflyEHFVBTGIxDsfaHYgaQAE1u+7PD3P94BsLB9nEFio57z6V+9HzAf INTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eHcap9sd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q124si2224845ywb.237.2018.01.19.06.22.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Jan 2018 06:22:03 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eHcap9sd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:51674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecXYQ-0007xb-Bv for patch@linaro.org; Fri, 19 Jan 2018 09:22:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecXTv-00059y-VO for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecXTu-000442-Au for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:23 -0500 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:34357) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ecXTu-00043D-1q for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:22 -0500 Received: by mail-wr0-x242.google.com with SMTP id 36so1724573wrh.1 for ; Fri, 19 Jan 2018 06:17:21 -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=lSyq7DB1K8Z4KtCRzayzaZF2p0I3QteJCk8Io6RQ4e0=; b=eHcap9sdSnKy+RbYWmS2Bdc9y/ejSY9ItcVyvDzVQN5R029/aEKmcPuca5cqvXtvil emrV34GNOzx6oeA0ye8ZkT1uH0s8WGaFkldIOAlTZpYXeQfpjGYTSITMTe52O6knwE7G FYEiDOEpOQ48+1bMosvItoHt8nkNUdsotWupc= 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=lSyq7DB1K8Z4KtCRzayzaZF2p0I3QteJCk8Io6RQ4e0=; b=e12/vVT3l8lxw/GxFu1sQZ/kWIKZAXQKE/YFZtyjiV6L9MeeleQXOP8u+JP0OMJgL2 yYy1IwlJ1crC+EAC1KROXNhLJTeqa1mDhD2fhb+ftn3OisHpM5+wzCbQpq+N/op5XGfQ 1ikaTyYbR/5eKSsYYxEgQkroVdDIjmJ++dKC7RSB3mGdgjNseNFYxzlNZGCKrXVlHC6D TnwboqMF5PghGm0dvTzTYcAxPTJQuYLTtMlf70AQhig1kJHJX1r6zYcGGGLEAHI73E1Q FzN4dcXLzGWHHeIvLkFzFrO3VkfYlhMYGmdrICmPmkZkL6tn3qRpbOxIwUSVO1jgOdYm 6Qgg== X-Gm-Message-State: AKwxytcYA2nd8X8wUg0AywJg9DIJMLbK+6DFc6rFzw6R7TUrL+KP04q2 PmzdWVM52rSqBJlVJ5irgtcqNpN3DiY= X-Received: by 10.223.157.146 with SMTP id p18mr9054756wre.71.1516371440701; Fri, 19 Jan 2018 06:17:20 -0800 (PST) Received: from localhost.localdomain ([160.170.62.40]) by smtp.gmail.com with ESMTPSA id m45sm6877266wrf.75.2018.01.19.06.17.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 06:17:19 -0800 (PST) From: Ard Biesheuvel To: qemu-devel@nongnu.org Date: Fri, 19 Jan 2018 14:17:05 +0000 Message-Id: <20180119141707.11733-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180119141707.11733-1-ard.biesheuvel@linaro.org> References: <20180119141707.11733-1-ard.biesheuvel@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PATCH v3 2/4] target/arm: implement SHA-3 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, Ard Biesheuvel Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This implements emulation of the new SHA-3 instructions that have been added as an optional extensions to the ARMv8 Crypto Extensions in ARM v8.2. Signed-off-by: Ard Biesheuvel --- target/arm/cpu.h | 1 + target/arm/crypto_helper.c | 69 +++++++++++++ target/arm/helper.h | 5 + target/arm/translate-a64.c | 108 +++++++++++++++++++- 4 files changed, 179 insertions(+), 4 deletions(-) -- 2.11.0 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 295529366c0a..8e355398e3e0 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1341,6 +1341,7 @@ enum arm_features { ARM_FEATURE_M_SECURITY, /* M profile Security Extension */ ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ + ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ }; static inline int arm_feature(CPUARMState *env, int feature) diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c index 15c22c82ca5e..b51fb0bd2897 100644 --- a/target/arm/crypto_helper.c +++ b/target/arm/crypto_helper.c @@ -560,3 +560,72 @@ void HELPER(crypto_sha512su1)(CPUARMState *env, uint32_t rd, uint32_t rn, env->vfp.regs[rd] = make_float64(d0); env->vfp.regs[rd + 1] = make_float64(d1); } + +void HELPER(crypto_rax1)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t rm) +{ + uint64_t d0 = float64_val(env->vfp.regs[rd]); + uint64_t d1 = float64_val(env->vfp.regs[rd + 1]); + uint64_t n0 = float64_val(env->vfp.regs[rn]); + uint64_t n1 = float64_val(env->vfp.regs[rn + 1]); + uint64_t m0 = float64_val(env->vfp.regs[rm]); + uint64_t m1 = float64_val(env->vfp.regs[rm + 1]); + + d0 = n0 ^ rol64(m0, 1); + d1 = n1 ^ rol64(m1, 1); + + env->vfp.regs[rd] = make_float64(d0); + env->vfp.regs[rd + 1] = make_float64(d1); +} + +void HELPER(crypto_eor3)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t ra, uint32_t rm) +{ + uint64_t d0, d1; + uint64_t n0 = float64_val(env->vfp.regs[rn]); + uint64_t n1 = float64_val(env->vfp.regs[rn + 1]); + uint64_t a0 = float64_val(env->vfp.regs[ra]); + uint64_t a1 = float64_val(env->vfp.regs[ra + 1]); + uint64_t m0 = float64_val(env->vfp.regs[rm]); + uint64_t m1 = float64_val(env->vfp.regs[rm + 1]); + + d0 = n0 ^ a0 ^ m0; + d1 = n1 ^ a1 ^ m1; + + env->vfp.regs[rd] = make_float64(d0); + env->vfp.regs[rd + 1] = make_float64(d1); +} + +void HELPER(crypto_bcax)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t ra, uint32_t rm) +{ + uint64_t d0, d1; + uint64_t n0 = float64_val(env->vfp.regs[rn]); + uint64_t n1 = float64_val(env->vfp.regs[rn + 1]); + uint64_t a0 = float64_val(env->vfp.regs[ra]); + uint64_t a1 = float64_val(env->vfp.regs[ra + 1]); + uint64_t m0 = float64_val(env->vfp.regs[rm]); + uint64_t m1 = float64_val(env->vfp.regs[rm + 1]); + + d0 = n0 ^ (~a0 & m0); + d1 = n1 ^ (~a1 & m1); + + env->vfp.regs[rd] = make_float64(d0); + env->vfp.regs[rd + 1] = make_float64(d1); +} + +void HELPER(crypto_xar)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t imm6, uint32_t rm) +{ + uint64_t d0, d1; + uint64_t n0 = float64_val(env->vfp.regs[rn]); + uint64_t n1 = float64_val(env->vfp.regs[rn + 1]); + uint64_t m0 = float64_val(env->vfp.regs[rm]); + uint64_t m1 = float64_val(env->vfp.regs[rm + 1]); + + d0 = ror64(n0 ^ m0, imm6); + d1 = ror64(n1 ^ m1, imm6); + + env->vfp.regs[rd] = make_float64(d0); + env->vfp.regs[rd + 1] = make_float64(d1); +} diff --git a/target/arm/helper.h b/target/arm/helper.h index efa75440ce81..2053ea10b2a5 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -539,6 +539,11 @@ DEF_HELPER_4(crypto_sha512h2, void, env, i32, i32, i32) DEF_HELPER_3(crypto_sha512su0, void, env, i32, i32) DEF_HELPER_4(crypto_sha512su1, void, env, i32, i32, i32) +DEF_HELPER_4(crypto_rax1, void, env, i32, i32, i32) +DEF_HELPER_5(crypto_eor3, void, env, i32, i32, i32, i32) +DEF_HELPER_5(crypto_bcax, void, env, i32, i32, i32, i32) +DEF_HELPER_5(crypto_xar, void, env, i32, i32, i32, i32) + DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) DEF_HELPER_2(dc_zva, void, env, i64) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index ec17391f4ff4..c632f584aad6 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -82,6 +82,8 @@ typedef void NeonGenTwoDoubleOPFn(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_ptr); typedef void NeonGenOneOpFn(TCGv_i64, TCGv_i64); typedef void CryptoTwoOpEnvFn(TCGv_ptr, TCGv_i32, TCGv_i32); typedef void CryptoThreeOpEnvFn(TCGv_ptr, TCGv_i32, TCGv_i32, TCGv_i32); +typedef void CryptoFourOpEnvFn(TCGv_ptr, TCGv_i32, TCGv_i32, TCGv_i32, + TCGv_i32); /* initialize TCG globals. */ void a64_translate_init(void) @@ -11125,6 +11127,7 @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) int rn = extract32(insn, 5, 5); int rd = extract32(insn, 0, 5); TCGv_i32 tcg_rd_regno, tcg_rn_regno, tcg_rm_regno; + int feature; CryptoThreeOpEnvFn *genfn; if (o != 0) { @@ -11134,20 +11137,24 @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) switch (opcode) { case 0: /* SHA512H */ + feature = ARM_FEATURE_V8_SHA512; genfn = gen_helper_crypto_sha512h; break; case 1: /* SHA512H2 */ + feature = ARM_FEATURE_V8_SHA512; genfn = gen_helper_crypto_sha512h2; break; case 2: /* SHA512SU1 */ + feature = ARM_FEATURE_V8_SHA512; genfn = gen_helper_crypto_sha512su1; break; - default: - unallocated_encoding(s); - return; + case 3: /* RAX1 */ + feature = ARM_FEATURE_V8_SHA3; + genfn = gen_helper_crypto_rax1; + break; } - if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA512)) { + if (!arm_dc_feature(s, feature)) { unallocated_encoding(s); return; } @@ -11208,6 +11215,97 @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) tcg_temp_free_i32(tcg_rn_regno); } +/* Crypto four-register + * 31 23 22 21 20 16 15 14 10 9 5 4 0 + * +-------------------+-----+------+---+------+------+------+ + * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd | + * +-------------------+-----+------+---+------+------+------+ + */ +static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) +{ + int op0 = extract32(insn, 21, 2); + int rm = extract32(insn, 16, 5); + int ra = extract32(insn, 10, 5); + int rn = extract32(insn, 5, 5); + int rd = extract32(insn, 0, 5); + TCGv_i32 tcg_rd_regno, tcg_rn_regno, tcg_ra_regno, tcg_rm_regno; + int feature; + CryptoFourOpEnvFn *genfn; + + switch (op0) { + case 0: /* EOR3 */ + feature = ARM_FEATURE_V8_SHA3; + genfn = gen_helper_crypto_eor3; + break; + case 1: /* BCAX */ + feature = ARM_FEATURE_V8_SHA3; + genfn = gen_helper_crypto_bcax; + break; + default: + unallocated_encoding(s); + return; + } + + if (!arm_dc_feature(s, feature)) { + unallocated_encoding(s); + return; + } + + if (!fp_access_check(s)) { + return; + } + + tcg_rd_regno = tcg_const_i32(rd << 1); + tcg_rn_regno = tcg_const_i32(rn << 1); + tcg_ra_regno = tcg_const_i32(ra << 1); + tcg_rm_regno = tcg_const_i32(rm << 1); + + genfn(cpu_env, tcg_rd_regno, tcg_rn_regno, tcg_ra_regno, tcg_rm_regno); + + tcg_temp_free_i32(tcg_rd_regno); + tcg_temp_free_i32(tcg_rn_regno); + tcg_temp_free_i32(tcg_ra_regno); + tcg_temp_free_i32(tcg_rm_regno); +} + +/* Crypto XAR + * 31 21 20 16 15 10 9 5 4 0 + * +-----------------------+------+--------+------+------+ + * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd | + * +-----------------------+------+--------+------+------+ + */ +static void disas_crypto_xar(DisasContext *s, uint32_t insn) +{ + int rm = extract32(insn, 16, 5); + int imm6 = extract32(insn, 10, 6); + int rn = extract32(insn, 5, 5); + int rd = extract32(insn, 0, 5); + TCGv_i32 tcg_rd_regno, tcg_rn_regno, tcg_imm6, tcg_rm_regno; + + if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA3)) { + unallocated_encoding(s); + return; + } + + if (!fp_access_check(s)) { + return; + } + + tcg_rd_regno = tcg_const_i32(rd << 1); + tcg_rn_regno = tcg_const_i32(rn << 1); + tcg_imm6 = tcg_const_i32(imm6); + tcg_rm_regno = tcg_const_i32(rm << 1); + + gen_helper_crypto_xar(cpu_env, tcg_rd_regno, tcg_rn_regno, tcg_imm6, + tcg_rm_regno); + + tcg_temp_free_i32(tcg_rd_regno); + tcg_temp_free_i32(tcg_rn_regno); + tcg_temp_free_i32(tcg_imm6); + tcg_temp_free_i32(tcg_rm_regno); + +} + /* C3.6 Data processing - SIMD, inc Crypto * * As the decode gets a little complex we are using a table based @@ -11239,6 +11337,8 @@ static const AArch64DecodeTable data_proc_simd[] = { { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha }, { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 }, { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, + { 0xce000000, 0xff808000, disas_crypto_four_reg }, + { 0xce800000, 0xffe00000, disas_crypto_xar }, { 0x00000000, 0x00000000, NULL } }; From patchwork Fri Jan 19 14:17:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 125167 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp314062ljf; Fri, 19 Jan 2018 06:23:26 -0800 (PST) X-Google-Smtp-Source: ACJfBouHaxTcBWUTnlljGNW/r7H5LZ6GtkvCo6JnwyIwe88Z6+kaR6lkc9GqWDx5TWdnC6AM4zwe X-Received: by 10.37.232.1 with SMTP id k1mr29957460ybd.87.1516371806539; Fri, 19 Jan 2018 06:23:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516371806; cv=none; d=google.com; s=arc-20160816; b=D+O4O+nswgTjiT99IvMPnuaoiaYSpfLxvE3rogriEgef8DygxMONPeuCctOEecrXdO PmZAu1zht8Er0oIhNnkqwqoFhF3Ni3yfQDT5WxMpAdC4ui8eOCpWBcG83b3jm7neF1iO +gXHwFN6i0LIBm6ntHZ4E+rN2UYdZNorUtXwFQTXoVKF3ZLE0E4iyMGMAMRwAbdxFVx3 50SFP2MYV0B/cBq3rfFc3QCnUzqyh5M6yX7emkQDP2OncBDD8Z1R5PmJkykw0tE+iMT6 3UpBvSLaffon+TYG7vI88i6KxrdJmN767ey2p7FzdGZwWljlHsYX8ThAmq7jwk5SE+pB nAnQ== 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:arc-authentication-results; bh=BNIuaMMFznbmeDwNBH6iGCtDWDMhIgdXjWrBCP6AjHo=; b=dqFgYdXKmyVn+JgSBvfaddDTuxQG7/zSQ36I61SsKmKTcdm9PoPSwwe5r6na589LmA EtYvrnC60HgMoCf9untH6WApfLjgfon4xJv1kDrT8fNgqFPzUq4ulMPy3CPA1c+cKtzz R28YZF+Bj82g82uxiF/dwb3FWRmJqxkQHU6voIBD0CD60c2q0eih5FamcgPOCx6f8egI 5hBNxMWN2PO+IooMzEBRKkzIfUP191ZwxyNRq4cZ5fKwu+tpWJHyVrymo1r9u0tR0OYb CY4nY+1OzUt5muwp9+Km3+EsxhE39GFWb2/GlWMA23IIH9lvyEUW8+ABViucHA5pPFyQ enEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ArYkNWtA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h4si1154199ywa.389.2018.01.19.06.23.26 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Jan 2018 06:23:26 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ArYkNWtA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:51753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecXZl-0000tj-QE for patch@linaro.org; Fri, 19 Jan 2018 09:23:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecXTx-0005C1-WF for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecXTw-00046N-9q for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:26 -0500 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:41332) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ecXTw-000453-0i for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:24 -0500 Received: by mail-wr0-x243.google.com with SMTP id o7so1706507wro.8 for ; Fri, 19 Jan 2018 06:17:23 -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=BNIuaMMFznbmeDwNBH6iGCtDWDMhIgdXjWrBCP6AjHo=; b=ArYkNWtAqdvpXs27x51ANI6tg0RtupBPUe8ESKa0GlrAUnnk/QJbdRwNB//ooYvMCC hi1B8txK2R2RLs/JEHVzU7sHHlRZnRsYw6+ygIT3/DM1l3a2N/ABvjn/QFzLW4tzkrlt 73xk9TcVL4utO2D+T6PTcljaj7goJ/49JmHMM= 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=BNIuaMMFznbmeDwNBH6iGCtDWDMhIgdXjWrBCP6AjHo=; b=Lm5P4rHCCdONAaCawQJdw9SoJnJmWA3d8U2YhTd/z66JwVe+lWn8/g482plkvfjKkY aIDeqQUIHnhycZuQiSyqi+u/lJKWK+OhR6BSfSCYd5AJUptjjDHzTl8EB6tsb7m7FXxS iJAC29D4DzPX+MEPcGVEvlfBsh/0JgCu1UxpvBFqT++cqX6OFQSrRjEJPv4NxnpbDygh xN+cvjH3ssjTyWvdxsmOAheskV37Ok/ecPVgcjJGk9t8/wthqstA1X9ly6UaerOeK4uj q8pHx81IqZiWHMu1kTiqooWjqfOd2ZrFdEni2fJE9G27/QGV+nDGx+ukcu1yvYRDojwd LnUA== X-Gm-Message-State: AKwxytf4k+bKIXTMFqT4EdEeW1/jN7jRA4hf+uqE3pkurD4RQrwxwzQD EKBLdkkf2wvcJzNbF7rpU+WQ3abwjhU= X-Received: by 10.223.144.100 with SMTP id h91mr10140788wrh.147.1516371442665; Fri, 19 Jan 2018 06:17:22 -0800 (PST) Received: from localhost.localdomain ([160.170.62.40]) by smtp.gmail.com with ESMTPSA id m45sm6877266wrf.75.2018.01.19.06.17.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 06:17:21 -0800 (PST) From: Ard Biesheuvel To: qemu-devel@nongnu.org Date: Fri, 19 Jan 2018 14:17:06 +0000 Message-Id: <20180119141707.11733-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180119141707.11733-1-ard.biesheuvel@linaro.org> References: <20180119141707.11733-1-ard.biesheuvel@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH v3 3/4] target/arm: implement SM3 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, Ard Biesheuvel Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This implements emulation of the new SM3 instructions that have been added as an optional extension to the ARMv8 Crypto Extensions in ARM v8.2. Signed-off-by: Ard Biesheuvel --- target/arm/cpu.h | 1 + target/arm/crypto_helper.c | 143 ++++++++++++++++++++ target/arm/helper.h | 5 + target/arm/translate-a64.c | 100 +++++++++++--- 4 files changed, 227 insertions(+), 22 deletions(-) -- 2.11.0 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 8e355398e3e0..917d15fa346c 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1342,6 +1342,7 @@ enum arm_features { ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ + ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ }; static inline int arm_feature(CPUARMState *env, int feature) diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c index b51fb0bd2897..6c601351b177 100644 --- a/target/arm/crypto_helper.c +++ b/target/arm/crypto_helper.c @@ -629,3 +629,146 @@ void HELPER(crypto_xar)(CPUARMState *env, uint32_t rd, uint32_t rn, env->vfp.regs[rd] = make_float64(d0); env->vfp.regs[rd + 1] = make_float64(d1); } + +void HELPER(crypto_sm3partw1)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t rm) +{ + union CRYPTO_STATE d = { .l = { + float64_val(env->vfp.regs[rd]), + float64_val(env->vfp.regs[rd + 1]) + } }; + union CRYPTO_STATE n = { .l = { + float64_val(env->vfp.regs[rn]), + float64_val(env->vfp.regs[rn + 1]) + } }; + union CRYPTO_STATE m = { .l = { + float64_val(env->vfp.regs[rm]), + float64_val(env->vfp.regs[rm + 1]) + } }; + uint32_t t; + + t = CR_ST_WORD(d, 0) ^ CR_ST_WORD(n, 0) ^ ror32(CR_ST_WORD(m, 1), 17); + CR_ST_WORD(d, 0) = t ^ ror32(t, 17) ^ ror32(t, 9); + + t = CR_ST_WORD(d, 1) ^ CR_ST_WORD(n, 1) ^ ror32(CR_ST_WORD(m, 2), 17); + CR_ST_WORD(d, 1) = t ^ ror32(t, 17) ^ ror32(t, 9); + + t = CR_ST_WORD(d, 2) ^ CR_ST_WORD(n, 2) ^ ror32(CR_ST_WORD(m, 3), 17); + CR_ST_WORD(d, 2) = t ^ ror32(t, 17) ^ ror32(t, 9); + + t = CR_ST_WORD(d, 3) ^ CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(d, 0), 17); + CR_ST_WORD(d, 3) = t ^ ror32(t, 17) ^ ror32(t, 9); + + env->vfp.regs[rd] = make_float64(d.l[0]); + env->vfp.regs[rd + 1] = make_float64(d.l[1]); +} + +void HELPER(crypto_sm3partw2)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t rm) +{ + union CRYPTO_STATE d = { .l = { + float64_val(env->vfp.regs[rd]), + float64_val(env->vfp.regs[rd + 1]) + } }; + union CRYPTO_STATE n = { .l = { + float64_val(env->vfp.regs[rn]), + float64_val(env->vfp.regs[rn + 1]) + } }; + union CRYPTO_STATE m = { .l = { + float64_val(env->vfp.regs[rm]), + float64_val(env->vfp.regs[rm + 1]) + } }; + uint32_t t = CR_ST_WORD(n, 0) ^ ror32(CR_ST_WORD(m, 0), 25); + + CR_ST_WORD(d, 0) ^= t; + CR_ST_WORD(d, 1) ^= CR_ST_WORD(n, 1) ^ ror32(CR_ST_WORD(m, 1), 25); + CR_ST_WORD(d, 2) ^= CR_ST_WORD(n, 2) ^ ror32(CR_ST_WORD(m, 2), 25); + CR_ST_WORD(d, 3) ^= CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(m, 3), 25) ^ + ror32(t, 17) ^ ror32(t, 2) ^ ror32(t, 26); + + env->vfp.regs[rd] = make_float64(d.l[0]); + env->vfp.regs[rd + 1] = make_float64(d.l[1]); +} + +void HELPER(crypto_sm3ss1)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t ra, uint32_t rm) +{ + union CRYPTO_STATE d; + union CRYPTO_STATE a = { .l = { + float64_val(env->vfp.regs[ra]), + float64_val(env->vfp.regs[ra + 1]) + } }; + union CRYPTO_STATE n = { .l = { + float64_val(env->vfp.regs[rn]), + float64_val(env->vfp.regs[rn + 1]) + } }; + union CRYPTO_STATE m = { .l = { + float64_val(env->vfp.regs[rm]), + float64_val(env->vfp.regs[rm + 1]) + } }; + + CR_ST_WORD(d, 0) = 0; + CR_ST_WORD(d, 1) = 0; + CR_ST_WORD(d, 2) = 0; + CR_ST_WORD(d, 3) = ror32(ror32(CR_ST_WORD(n, 3), 20) + CR_ST_WORD(m, 3) + + CR_ST_WORD(a, 3), 25); + + env->vfp.regs[rd] = make_float64(d.l[0]); + env->vfp.regs[rd + 1] = make_float64(d.l[1]); +} + +void HELPER(crypto_sm3tt)(CPUARMState *env, uint32_t rd, uint32_t rn, + uint32_t rm, uint32_t imm2, uint32_t opcode) +{ + union CRYPTO_STATE d = { .l = { + float64_val(env->vfp.regs[rd]), + float64_val(env->vfp.regs[rd + 1]) + } }; + union CRYPTO_STATE n = { .l = { + float64_val(env->vfp.regs[rn]), + float64_val(env->vfp.regs[rn + 1]) + } }; + union CRYPTO_STATE m = { .l = { + float64_val(env->vfp.regs[rm]), + float64_val(env->vfp.regs[rm + 1]) + } }; + uint32_t t; + + assert(imm2 < 4); + + if (opcode == 0 || opcode == 2) { + /* SM3TT1A, SM3TT2A */ + t = par(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); + } else if (opcode == 1) { + /* SM3TT1B */ + t = maj(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); + } else if (opcode == 3) { + /* SM3TT2B */ + t = cho(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); + } else { + g_assert_not_reached(); + } + + t += CR_ST_WORD(d, 0) + CR_ST_WORD(m, imm2); + + CR_ST_WORD(d, 0) = CR_ST_WORD(d, 1); + + if (opcode < 2) { + /* SM3TT1A, SM3TT1B */ + t += CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(d, 3), 20); + + CR_ST_WORD(d, 1) = ror32(CR_ST_WORD(d, 2), 23); + } else { + /* SM3TT2A, SM3TT2B */ + t += CR_ST_WORD(n, 3); + t ^= rol32(t, 9) ^ rol32(t, 17); + + CR_ST_WORD(d, 1) = ror32(CR_ST_WORD(d, 2), 13); + } + + CR_ST_WORD(d, 2) = CR_ST_WORD(d, 3); + CR_ST_WORD(d, 3) = t; + + env->vfp.regs[rd] = make_float64(d.l[0]); + env->vfp.regs[rd + 1] = make_float64(d.l[1]); +} diff --git a/target/arm/helper.h b/target/arm/helper.h index 2053ea10b2a5..913c551bf14b 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -544,6 +544,11 @@ DEF_HELPER_5(crypto_eor3, void, env, i32, i32, i32, i32) DEF_HELPER_5(crypto_bcax, void, env, i32, i32, i32, i32) DEF_HELPER_5(crypto_xar, void, env, i32, i32, i32, i32) +DEF_HELPER_5(crypto_sm3ss1, void, env, i32, i32, i32, i32) +DEF_HELPER_6(crypto_sm3tt, void, env, i32, i32, i32, i32, i32) +DEF_HELPER_4(crypto_sm3partw1, void, env, i32, i32, i32) +DEF_HELPER_4(crypto_sm3partw2, void, env, i32, i32, i32) + DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) DEF_HELPER_2(dc_zva, void, env, i64) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index c632f584aad6..9d805d4a7d26 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -11130,28 +11130,39 @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) int feature; CryptoThreeOpEnvFn *genfn; - if (o != 0) { - unallocated_encoding(s); - return; - } - - switch (opcode) { - case 0: /* SHA512H */ - feature = ARM_FEATURE_V8_SHA512; - genfn = gen_helper_crypto_sha512h; - break; - case 1: /* SHA512H2 */ - feature = ARM_FEATURE_V8_SHA512; - genfn = gen_helper_crypto_sha512h2; - break; - case 2: /* SHA512SU1 */ - feature = ARM_FEATURE_V8_SHA512; - genfn = gen_helper_crypto_sha512su1; - break; - case 3: /* RAX1 */ - feature = ARM_FEATURE_V8_SHA3; - genfn = gen_helper_crypto_rax1; - break; + if (o == 0) { + switch (opcode) { + case 0: /* SHA512H */ + feature = ARM_FEATURE_V8_SHA512; + genfn = gen_helper_crypto_sha512h; + break; + case 1: /* SHA512H2 */ + feature = ARM_FEATURE_V8_SHA512; + genfn = gen_helper_crypto_sha512h2; + break; + case 2: /* SHA512SU1 */ + feature = ARM_FEATURE_V8_SHA512; + genfn = gen_helper_crypto_sha512su1; + break; + case 3: /* RAX1 */ + feature = ARM_FEATURE_V8_SHA3; + genfn = gen_helper_crypto_rax1; + break; + } + } else { + switch (opcode) { + case 0: /* SM3PARTW1 */ + feature = ARM_FEATURE_V8_SM3; + genfn = gen_helper_crypto_sm3partw1; + break; + case 1: /* SM3PARTW2 */ + feature = ARM_FEATURE_V8_SM3; + genfn = gen_helper_crypto_sm3partw2; + break; + default: + unallocated_encoding(s); + return; + } } if (!arm_dc_feature(s, feature)) { @@ -11241,6 +11252,10 @@ static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) feature = ARM_FEATURE_V8_SHA3; genfn = gen_helper_crypto_bcax; break; + case 2: /* SM3SS1 */ + feature = ARM_FEATURE_V8_SM3; + genfn = gen_helper_crypto_sm3ss1; + break; default: unallocated_encoding(s); return; @@ -11306,6 +11321,46 @@ static void disas_crypto_xar(DisasContext *s, uint32_t insn) } +/* Crypto three-reg imm2 + * 31 21 20 16 15 14 13 12 11 10 9 5 4 0 + * +-----------------------+------+-----+------+--------+------+------+ + * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd | + * +-----------------------+------+-----+------+--------+------+------+ + */ +static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn) +{ + int opcode = extract32(insn, 10, 2); + int imm2 = extract32(insn, 12, 2); + int rm = extract32(insn, 16, 5); + int rn = extract32(insn, 5, 5); + int rd = extract32(insn, 0, 5); + TCGv_i32 tcg_rd_regno, tcg_rn_regno, tcg_rm_regno, tcg_imm2, tcg_opcode; + + if (!arm_dc_feature(s, ARM_FEATURE_V8_SM3)) { + unallocated_encoding(s); + return; + } + + if (!fp_access_check(s)) { + return; + } + + tcg_rd_regno = tcg_const_i32(rd << 1); + tcg_rn_regno = tcg_const_i32(rn << 1); + tcg_rm_regno = tcg_const_i32(rm << 1); + tcg_imm2 = tcg_const_i32(imm2); + tcg_opcode = tcg_const_i32(opcode); + + gen_helper_crypto_sm3tt(cpu_env, tcg_rd_regno, tcg_rn_regno, tcg_rm_regno, + tcg_imm2, tcg_opcode); + + tcg_temp_free_i32(tcg_rd_regno); + tcg_temp_free_i32(tcg_rn_regno); + tcg_temp_free_i32(tcg_rm_regno); + tcg_temp_free_i32(tcg_imm2); + tcg_temp_free_i32(tcg_opcode); +} + /* C3.6 Data processing - SIMD, inc Crypto * * As the decode gets a little complex we are using a table based @@ -11339,6 +11394,7 @@ static const AArch64DecodeTable data_proc_simd[] = { { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, { 0xce000000, 0xff808000, disas_crypto_four_reg }, { 0xce800000, 0xffe00000, disas_crypto_xar }, + { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2 }, { 0x00000000, 0x00000000, NULL } }; From patchwork Fri Jan 19 14:17:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 125169 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp315615ljf; Fri, 19 Jan 2018 06:27:22 -0800 (PST) X-Google-Smtp-Source: ACJfBou0MYOXPGUYHWP/4/M70+SuoA6Z1kTgDwZGt0WkOCYiHKgVczqd73YnWQTM+QWWM1GHNqwu X-Received: by 10.37.211.76 with SMTP id e73mr17948718ybf.123.1516372042690; Fri, 19 Jan 2018 06:27:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516372042; cv=none; d=google.com; s=arc-20160816; b=Ob1aFPj66w7/TPfexln2eB4v/Er3T+LYTFlAXZneLTugN6kZphMjvtJ4KJ/r4AMVKI UrsgaKqwvPRD88ZI91l+td8LK/x8NhNwqfImqY3Qj27JxgLouUlF1DYfsXUrzerHMk8U hQjQ2R5askwXB1IBA/4kJ7zo0Hkhzy/T5K9q67UvVRYTA5DML+puYwKYPOXp6OooN3/O PyOAsORGqeLHOz7wROubBWVJZ80Qr3eEOB0VxQf7F9+lmg0gugBWsTl0GmFByMZO+7Ng PCL4sZX160D6MRkCESW5MjLEkRKOyrVhKxqKC4wEbJ5dApGwDQ71ppBZL2PkKfZtAfsQ q40A== 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:arc-authentication-results; bh=iQ1FLKmYb4BjFce8j24OXUKRD4+hEekWhEWExhcW0Ys=; b=VDkyFoOthq2TAJhuvi2WkcSIa+FzhFYKqRp35TOYjKRyJVUQco2SA53oKCXb4fYnK3 3/d8Sppm5Lk8skKotuTcfAwkgfhmO9ju8ks9C4Eqg5wTjLfYWfEyRc4PXmEdbfU80tYV zWfW4cON6F95B8ov8ueMQroXeCrFeG79nFzCaYG7fs4F8hxCHzr2qn0kiVt7dihIPIpi M59yBcAxgNnn9ztyKcUPh53oTDuV+qJ05HNY7725j/99M1ioZZpF9zvUHJDvAUEsSI2a LUFnuUeF2WajdEz6frUCUMcQ+ebLvDCQy3jcEaN+3YD2FjPKtrRhvtqvmSwkP+MslQFj fMjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DefZIc8r; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c184si644601yba.483.2018.01.19.06.27.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Jan 2018 06:27:22 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DefZIc8r; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:52147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecXda-0004ts-39 for patch@linaro.org; Fri, 19 Jan 2018 09:27:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecXTz-0005Dx-6M for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecXTy-0004Aq-Cg for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:27 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:45641) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ecXTy-000498-6S for qemu-devel@nongnu.org; Fri, 19 Jan 2018 09:17:26 -0500 Received: by mail-wr0-x241.google.com with SMTP id 16so1700345wry.12 for ; Fri, 19 Jan 2018 06:17:26 -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=iQ1FLKmYb4BjFce8j24OXUKRD4+hEekWhEWExhcW0Ys=; b=DefZIc8ruBKX1rFOb3FoknEgzvbsJrZ93TpDZIBiyVPQpMVIKpMwGFhbcbcqWDHJSf dWndMYn6CRGw2E67jzWMggBVZ16qms8XZhW92hnZUMOLubzWG23GAVPjxvE3fz6rnbj4 QxZnfhYhHPk5Ky0X+Q7g8gnWQsE31raCrQON4= 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=iQ1FLKmYb4BjFce8j24OXUKRD4+hEekWhEWExhcW0Ys=; b=AT7bstWM/R7VU7V64j0GaHS93ld4nPCUyDJzjVMHU1Nu7QTRnF8aP33fUpPIAr3+kR i5P2sB9hr7nKazDI4tum8jS9BbLUN9gpSmu+EAfFDFLHX6hgahzJIbInD3bXsrEYqrgV Me3fP7li/aXWLENmekvYkQeGFjZdTf1agXxZGtT44eAJVc+gDoEl779ZOHEEN4rTxOR3 xFvXB9KLmyfxzWNrQONPx6WjFJZUT+3t6xz5J5MDgZlV+pXQs3dzZNQiS1HyP1KyZ6iA IevQyOHw/Ll52nP5rWupsopmBpCc9Wldg301TaRqFyNH21pAy2qyGcv0dFkKkkxTAdhF v1fQ== X-Gm-Message-State: AKwxyteDvQCvWT0D2b3Z1nUcK0U5LF16l9eNV/BF1LQWYVaVTBNJnqp2 OeC76j46WYbSpneRiGvub31oWqqEALY= X-Received: by 10.223.166.248 with SMTP id t111mr10371671wrc.248.1516371444996; Fri, 19 Jan 2018 06:17:24 -0800 (PST) Received: from localhost.localdomain ([160.170.62.40]) by smtp.gmail.com with ESMTPSA id m45sm6877266wrf.75.2018.01.19.06.17.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 06:17:24 -0800 (PST) From: Ard Biesheuvel To: qemu-devel@nongnu.org Date: Fri, 19 Jan 2018 14:17:07 +0000 Message-Id: <20180119141707.11733-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180119141707.11733-1-ard.biesheuvel@linaro.org> References: <20180119141707.11733-1-ard.biesheuvel@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH v3 4/4] target/arm: enable user-mode SHA-3, SM3 and SHA-512 instruction support 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, Ard Biesheuvel Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Add support for the new ARMv8.2 SHA-3, SM3 and SHA-512 instructions to AArch64 user mode emulation. Signed-off-by: Ard Biesheuvel --- linux-user/elfload.c | 18 ++++++++++++++++++ target/arm/cpu64.c | 3 +++ 2 files changed, 21 insertions(+) -- 2.11.0 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 20f3d8c2c373..5d5aa26d2710 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -512,6 +512,21 @@ enum { ARM_HWCAP_A64_SHA1 = 1 << 5, ARM_HWCAP_A64_SHA2 = 1 << 6, ARM_HWCAP_A64_CRC32 = 1 << 7, + ARM_HWCAP_A64_ATOMICS = 1 << 8, + ARM_HWCAP_A64_FPHP = 1 << 9, + ARM_HWCAP_A64_ASIMDHP = 1 << 10, + ARM_HWCAP_A64_CPUID = 1 << 11, + ARM_HWCAP_A64_ASIMDRDM = 1 << 12, + ARM_HWCAP_A64_JSCVT = 1 << 13, + ARM_HWCAP_A64_FCMA = 1 << 14, + ARM_HWCAP_A64_LRCPC = 1 << 15, + ARM_HWCAP_A64_DCPOP = 1 << 16, + ARM_HWCAP_A64_SHA3 = 1 << 17, + ARM_HWCAP_A64_SM3 = 1 << 18, + ARM_HWCAP_A64_SM4 = 1 << 19, + ARM_HWCAP_A64_ASIMDDP = 1 << 20, + ARM_HWCAP_A64_SHA512 = 1 << 21, + ARM_HWCAP_A64_SVE = 1 << 22, }; #define ELF_HWCAP get_elf_hwcap() @@ -532,6 +547,9 @@ static uint32_t get_elf_hwcap(void) GET_FEATURE(ARM_FEATURE_V8_SHA1, ARM_HWCAP_A64_SHA1); GET_FEATURE(ARM_FEATURE_V8_SHA256, ARM_HWCAP_A64_SHA2); GET_FEATURE(ARM_FEATURE_CRC, ARM_HWCAP_A64_CRC32); + GET_FEATURE(ARM_FEATURE_V8_SHA3, ARM_HWCAP_A64_SHA3); + GET_FEATURE(ARM_FEATURE_V8_SM3, ARM_HWCAP_A64_SM3); + GET_FEATURE(ARM_FEATURE_V8_SHA512, ARM_HWCAP_A64_SHA512); #undef GET_FEATURE return hwcaps; diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 670c07ab6ed4..56d50ba57194 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -224,6 +224,9 @@ static void aarch64_any_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V8_AES); set_feature(&cpu->env, ARM_FEATURE_V8_SHA1); set_feature(&cpu->env, ARM_FEATURE_V8_SHA256); + set_feature(&cpu->env, ARM_FEATURE_V8_SHA3); + set_feature(&cpu->env, ARM_FEATURE_V8_SM3); + set_feature(&cpu->env, ARM_FEATURE_V8_SHA512); set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); set_feature(&cpu->env, ARM_FEATURE_CRC); cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */