From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mx.groups.io with SMTP id smtpd.web10.143669.1671134412296544870 for ; Thu, 15 Dec 2022 12:00:12 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=UZndFq5m; spf=pass (domain: ventanamicro.com, ip: 209.85.214.170, mailfrom: tphan@ventanamicro.com) Received: by mail-pl1-f170.google.com with SMTP id l10so96503plb.8 for ; Thu, 15 Dec 2022 12:00:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nToplOkB2lh1q52UnttsDDkw7Avz7sxR948hVHwAzfA=; b=UZndFq5msDkoXUaJg/2k36wICVtuFicPxIT9ROGnb7ETLLcJqQ4a9Qq/vN5uIwLsTY 5lEje29ChOn4KDltYLiXpthCrDAPo/Ere3J8BxqwQfZ+HG17jsVLDiimvreM7QrtRdlN RgI2gosQr47ESHGZVh1SI/GLwaD+dbuU2YPc+5tMv1eRy7or0VRqDAQVoFr46B5xNiay 0D13uWI8SmIhjR7hIUz7eFTRfd2Rj0KZ9vD4aOtLT+B7GQr+kN6LPplNlmX1mNkJyVeO AP/Weud59DyOZVe1uuHVvs09YuBhSRKHTvxAUyl7b5vBFEy74iPPKxbocEK+FpXAT74h VTTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nToplOkB2lh1q52UnttsDDkw7Avz7sxR948hVHwAzfA=; b=b/ER0Kg1AHxbgIGEqAt4NWjVUb5Kqj3TWlSeYWkKh1VMbTJGFrIkTxi5q+nHVNP79a QuSRTQU9VXUCYlkde/11pyWG+TDXxF7zTqRmEzWOMxMmtdXnhOrXIK3yU22U51h+bewy b1Xa43atIwTxbMz+m8Tp2nmjv+RltInpwyB779mMyzAzZO7zqHOgEZC9VAYB15tqkhgO 6MoG36dTnEo544Fo3bKgP7yDWcvSHOSqXS9lNWJFU0ZPddJG73ctlWBOq93qxGWYf//x zJAqmrGrn63dwDd/wBbLtVsc/f3E1pandiJ5l/52j4cM0UWTK6BCVkav0vidaQf7/DtM Qthg== X-Gm-Message-State: ANoB5pmix3MYexY9LpiFPq3AohJjh++kCiR/4uqMf55zzUNHeYTXeXQC ChBVPOsGqan2AQeb3hEavMQ2em1DuBM2jLa0 X-Google-Smtp-Source: AA0mqf5iimFfausJXCYYr+4TE0bNUR7Ra/Plr3L3Jpain1hr4mTo1BEgR1gleU76CMI+b89XmY0K8w== X-Received: by 2002:a17:902:f54f:b0:189:d068:270 with SMTP id h15-20020a170902f54f00b00189d0680270mr44090017plf.30.1671134411365; Thu, 15 Dec 2022 12:00:11 -0800 (PST) Return-Path: Received: from localhost.localdomain (c-24-7-118-148.hsd1.ca.comcast.net. [24.7.118.148]) by smtp.gmail.com with ESMTPSA id t7-20020a1709027fc700b00189f69c1aa0sm5508plb.270.2022.12.15.12.00.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 12:00:10 -0800 (PST) From: tphan@ventanamicro.com To: Cc: devel@edk2.groups.io, sunilvl@ventanamicro.com, Tuan Phan Subject: [PATCH] CryptoPkg/IntrinsicLib: RiscV: Provide implementation of memcpy and __ctzdi2 Date: Thu, 15 Dec 2022 09:48:59 -0800 Message-Id: <20221215174859.11638-1-tphan@ventanamicro.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable The RiscV toolchain doesn't provide __ctzdi2 implementation when compiled with -nostdlib that needed by openssl library when EC=20 enabled. So adding the simple implementation of __ctzdi2. Forcing to use CopyMem of EDK2 as builtin memcpy disabled for RiscV with -fno-builtin-memcpy flag. Signed-off-by: Tuan Phan --- .../Library/IntrinsicLib/CompilerHelper.c | 41 +++++++++++++++++++ .../Library/IntrinsicLib/IntrinsicLib.inf | 6 ++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 CryptoPkg/Library/IntrinsicLib/CompilerHelper.c diff --git a/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c b/CryptoPkg/Li= brary/IntrinsicLib/CompilerHelper.c new file mode 100644 index 000000000000..9e700a11ed17 --- /dev/null +++ b/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c @@ -0,0 +1,41 @@ +/** @file + Implement functions that not available when compiled with -nostdlib flag. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +unsigned int +__ctzdi2 (unsigned long long x) +{ + unsigned int ret =3D 0; + + if (!x) { + return 64; + } + if (!(x & 0xffffffff)) { + x >>=3D 32; + ret |=3D 32; + } + if (!(x & 0xffff)) { + x >>=3D 16; + ret |=3D 16; + } + if (!(x & 0xff)) { + x >>=3D 8; + ret |=3D 8; + } + if (!(x & 0xf)) { + x >>=3D 4; + ret |=3D 4; + } + if (!(x & 0x3)) { + x >>=3D 2; + ret |=3D 2; + } + if (!(x & 0x1)) { + x >>=3D 1; + ret |=3D 1; + } + return ret; +} diff --git a/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf b/CryptoPkg/Li= brary/IntrinsicLib/IntrinsicLib.inf index 86e74b57b109..6796b39b07cf 100644 --- a/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf +++ b/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf @@ -18,7 +18,7 @@ #=0D # The following information is for reference only and not required by the = build tools.=0D #=0D -# VALID_ARCHITECTURES =3D IA32 X64=0D +# VALID_ARCHITECTURES =3D IA32 X64 RISCV64=0D #=0D =0D [Sources]=0D @@ -43,6 +43,10 @@ [Sources.X64]=0D CopyMem.c=0D =0D +[Sources.RISCV64]=0D + CopyMem.c=0D + CompilerHelper.c=0D +=0D [Packages]=0D MdePkg/MdePkg.dec=0D =0D --=20 2.25.1