public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Tuan Phan" <tphan@ventanamicro.com>
Cc: devel@edk2.groups.io, sunilvl@ventanamicro.com,
	michael.d.kinney@intel.com, jiewen.yao@intel.com,
	jian.j.wang@intel.com, xiaoyu1.lu@intel.com,
	guomin.jiang@intel.com, Tuan Phan <tphan@ventanamicro.com>
Subject: [PATCH v2] CryptoPkg/IntrinsicLib: RiscV: Provide implementation of memcpy and __ctzdi2
Date: Fri, 16 Dec 2022 10:47:54 -0800	[thread overview]
Message-ID: <20221216184754.4381-1-tphan@ventanamicro.com> (raw)

The RiscV toolchain doesn't provide __ctzdi2 implementation when
compiled with -nostdlib that needed by openssl library.
So adding the implementation of __ctzdi2.

Forcing to use CopyMem of EDK2 as memcpy buildin disabled for RiscV
with -fno-builtin-memcpy flag.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4103
Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
Acked-by: Sunil V L <sunilvl@ventanamicro.com>
---
V2:
- Add license header.
- Add REF to the bugzilla.

 .../Library/IntrinsicLib/CompilerHelper.c     | 42 +++++++++++++++++++
 .../Library/IntrinsicLib/IntrinsicLib.inf     |  6 ++-
 2 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 CryptoPkg/Library/IntrinsicLib/CompilerHelper.c

diff --git a/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c b/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c
new file mode 100644
index 000000000000..3844fd14ae66
--- /dev/null
+++ b/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c
@@ -0,0 +1,42 @@
+/** @file
+  Implement functions that not available when compiled with -nostdlib.
+
+  Copyright (c) 2022, Ventana Micro Systems Inc. All Rights Reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+unsigned int
+__ctzdi2 (unsigned long long x)
+{
+  unsigned int ret = 0;
+
+  if (!x) {
+    return 64;
+  }
+  if (!(x & 0xffffffff)) {
+    x >>= 32;
+    ret |= 32;
+  }
+  if (!(x & 0xffff)) {
+    x >>= 16;
+    ret |= 16;
+  }
+  if (!(x & 0xff)) {
+    x >>= 8;
+    ret |= 8;
+  }
+  if (!(x & 0xf)) {
+    x >>= 4;
+    ret |= 4;
+  }
+  if (!(x & 0x3)) {
+    x >>= 2;
+    ret |= 2;
+  }
+  if (!(x & 0x1)) {
+    x >>= 1;
+    ret |= 1;
+  }
+  return ret;
+}
diff --git a/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf b/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
index 86e74b57b109..6796b39b07cf 100644
--- a/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
+++ b/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
@@ -18,7 +18,7 @@
 #
 # The following information is for reference only and not required by the build tools.
 #
-#  VALID_ARCHITECTURES           = IA32 X64
+#  VALID_ARCHITECTURES           = IA32 X64 RISCV64
 #
 
 [Sources]
@@ -43,6 +43,10 @@
 [Sources.X64]
   CopyMem.c
 
+[Sources.RISCV64]
+  CopyMem.c
+  CompilerHelper.c
+
 [Packages]
   MdePkg/MdePkg.dec
 
-- 
2.25.1


             reply	other threads:[~2022-12-16 18:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 18:47 Tuan Phan [this message]
2022-12-17  0:06 ` [PATCH v2] CryptoPkg/IntrinsicLib: RiscV: Provide implementation of memcpy and __ctzdi2 Michael D Kinney
2022-12-17  1:59   ` [edk2-devel] " Pedro Falcato
2022-12-17  2:15     ` Tuan Phan
2022-12-21  2:56       ` Pedro Falcato
2022-12-19 18:26   ` Tuan Phan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221216184754.4381-1-tphan@ventanamicro.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox