From nobody Mon Feb 9 01:50:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+88845+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88845+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1649831084; cv=none; d=zohomail.com; s=zohoarc; b=MEZn+HfnrwAiCguY4u+OLIUX3cpup6nI3RVqKCeuceDtRB8hXf9ZsOXEWUwwrnxVDkBSb8OpPKkejtSuOZl1O9iAH4noBoA2bdPi/ftsbFJm0u6CL+z9e0qcYFgM+ImnGdqcnWm2B7M2rbSxESTjdZ5VWQdwlWvbFvfbfDU11Sg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649831084; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AdPiKTYDqatgr7//YkLaZRDTGPgsVKYgKo1tYuIpPOc=; b=cYCSr2KVNauI4Uh/VNwOtFC2UvfFOE0CFJFlGWVK77Lwf9wvlJK1V/vle4qM0txtxUENapzw2STdg3VWJGXFzOJkGefwtXZZ1ZjXw0V6TDHKBuES/Fb5GS2BWGCSwvpUPaVQosCZPeryrYFZQqjpatg62yWwD7iODisouZTNwQE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88845+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 164983108489348.88840366285092; Tue, 12 Apr 2022 23:24:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mFeTYY1788612xD6CcchlUPw; Tue, 12 Apr 2022 23:24:44 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web09.3166.1649831080670201284 for ; Tue, 12 Apr 2022 23:24:43 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10315"; a="323030842" X-IronPort-AV: E=Sophos;i="5.90,256,1643702400"; d="scan'208";a="323030842" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2022 23:24:42 -0700 X-IronPort-AV: E=Sophos;i="5.90,256,1643702400"; d="scan'208";a="573133392" X-Received: from shwdejointd178.ccr.corp.intel.com ([10.239.153.103]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2022 23:24:41 -0700 From: "yi1 li" To: devel@edk2.groups.io Cc: yi1 li , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH 1/3] CryptoPkg: Add instrinsics to support building ECC on IA32 windows Date: Wed, 13 Apr 2022 14:24:30 +0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yi1.li@intel.com X-Gm-Message-State: QCdP9G2behyLXlvMZaPC50gix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1649831084; bh=2lr2BGcCre8jXfc1a2BG6bkl5kseOJgkcifxmHPHo9M=; h=Cc:Date:From:Reply-To:Subject:To; b=UspL4emXKMXjvirJUNTG3GBiBnHbaU6NEjdsX4ah6t/CmLZ8A+gHo0wDqSk6l2t1plF GQXSrzaRJoWBP/rsfIawKYNk3ztmDbeNhYj/22qUlaMX9b7YnbJikZKWfvrtkWk5xt7+9 JFFa219F5REY7DXJYNXxyRxdbg+xOhsFVrE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1649831086277100007 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3679 This dependency is needed to build openssl lib with ECC ciphers under IA32 Windows and adds implementation for _allmul and _allshr instrinsics. It is taken from Project Mu: microsoft/mu_basecore@b55b341 Cc: Jiewen Yao Cc: Jian J Wang Signed-off-by: yi1 li Reviewed-by: Jiewen Yao --- .../Library/IntrinsicLib/Ia32/MathLlmul.asm | 98 +++++++++++++++++++ .../Library/IntrinsicLib/Ia32/MathLlshr.asm | 78 +++++++++++++++ .../Library/IntrinsicLib/IntrinsicLib.inf | 2 + 3 files changed, 178 insertions(+) create mode 100644 CryptoPkg/Library/IntrinsicLib/Ia32/MathLlmul.asm create mode 100644 CryptoPkg/Library/IntrinsicLib/Ia32/MathLlshr.asm diff --git a/CryptoPkg/Library/IntrinsicLib/Ia32/MathLlmul.asm b/CryptoPkg/= Library/IntrinsicLib/Ia32/MathLlmul.asm new file mode 100644 index 000000000000..341ea8a7bc0d --- /dev/null +++ b/CryptoPkg/Library/IntrinsicLib/Ia32/MathLlmul.asm @@ -0,0 +1,98 @@ +;*** +;llmul.asm - long multiply routine +; +; Copyright (c) Microsoft Corporation. All rights reserved. +; SPDX-License-Identifier: BSD-2-Clause-Patent +; +;Purpose: +; Defines long multiply routine +; Both signed and unsigned routines are the same, since multiply's +; work out the same in 2's complement +; creates the following routine: +; __allmul +; +;Original Implemenation: MSVC 14.12.25827 +; +;*************************************************************************= ****** + .686 + .model flat,C + .code + + +;*** +;llmul - long multiply routine +; +;Purpose: +; Does a long multiply (same for signed/unsigned) +; Parameters are not changed. +; +;Entry: +; Parameters are passed on the stack: +; 1st pushed: multiplier (QWORD) +; 2nd pushed: multiplicand (QWORD) +; +;Exit: +; EDX:EAX - product of multiplier and multiplicand +; NOTE: parameters are removed from the stack +; +;Uses: +; ECX +; +;Exceptions: +; +;*************************************************************************= ****** +_allmul PROC NEAR + +A EQU [esp + 4] ; stack address of a +B EQU [esp + 12] ; stack address of b + +HIGH_PART EQU [4] ; +LOW_PART EQU [0] + +; +; AHI, BHI : upper 32 bits of A and B +; ALO, BLO : lower 32 bits of A and B +; +; ALO * BLO +; ALO * BHI +; + BLO * AHI +; --------------------- +; + + mov eax,HIGH_PART(A) + mov ecx,HIGH_PART(B) + or ecx,eax ;test for both high dwords zero. + mov ecx,LOW_PART(B) + jnz short hard ;both are zero, just mult ALO and BLO + + mov eax,LOW_PART(A) + mul ecx + + ret 16 ; callee restores the stack + +hard: + push ebx + +; must redefine A and B since esp has been altered + +A2 EQU [esp + 8] ; stack address of a +B2 EQU [esp + 16] ; stack address of b + + mul ecx ;eax has AHI, ecx has BLO, so AHI * BLO + mov ebx,eax ;save result + + mov eax,LOW_PART(A2) + mul dword ptr HIGH_PART(B2) ;ALO * BHI + add ebx,eax ;ebx =3D ((ALO * BHI) + (AHI * BLO)) + + mov eax,LOW_PART(A2);ecx =3D BLO + mul ecx ;so edx:eax =3D ALO*BLO + add edx,ebx ;now edx has all the LO*HI stuff + + pop ebx + + ret 16 ; callee restores the stack + +_allmul ENDP + + end diff --git a/CryptoPkg/Library/IntrinsicLib/Ia32/MathLlshr.asm b/CryptoPkg/= Library/IntrinsicLib/Ia32/MathLlshr.asm new file mode 100644 index 000000000000..ab8294580f16 --- /dev/null +++ b/CryptoPkg/Library/IntrinsicLib/Ia32/MathLlshr.asm @@ -0,0 +1,78 @@ +;*** +;llshr.asm - long shift right +; +; Copyright (c) Microsoft Corporation. All rights reserved. +; SPDX-License-Identifier: BSD-2-Clause-Patent +; +;Purpose: +; define signed long shift right routine +; __allshr +; +;Original Implemenation: MSVC 14.12.25827 +; +;*************************************************************************= ****** + .686 + .model flat,C + .code + + + +;*** +;llshr - long shift right +; +;Purpose: +; Does a signed Long Shift Right +; Shifts a long right any number of bits. +; +;Entry: +; EDX:EAX - long value to be shifted +; CL - number of bits to shift by +; +;Exit: +; EDX:EAX - shifted value +; +;Uses: +; CL is destroyed. +; +;Exceptions: +; +;*************************************************************************= ****** +_allshr PROC NEAR + +; +; Handle shifts of 64 bits or more (if shifting 64 bits or more, the result +; depends only on the high order bit of edx). +; + cmp cl,64 + jae short RETSIGN + +; +; Handle shifts of between 0 and 31 bits +; + cmp cl, 32 + jae short MORE32 + shrd eax,edx,cl + sar edx,cl + ret + +; +; Handle shifts of between 32 and 63 bits +; +MORE32: + mov eax,edx + sar edx,31 + and cl,31 + sar eax,cl + ret + +; +; Return double precision 0 or -1, depending on the sign of edx +; +RETSIGN: + sar edx,31 + mov eax,edx + ret + +_allshr ENDP + + end diff --git a/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf b/CryptoPkg/Li= brary/IntrinsicLib/IntrinsicLib.inf index fcbb93316cf7..86e74b57b109 100644 --- a/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf +++ b/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf @@ -30,6 +30,8 @@ Ia32/MathLShiftS64.c | MSFT Ia32/MathRShiftU64.c | MSFT Ia32/MathFtol.c | MSFT + Ia32/MathLlmul.asm | MSFT + Ia32/MathLlshr.asm | MSFT =20 Ia32/MathLShiftS64.c | INTEL Ia32/MathRShiftU64.c | INTEL --=20 2.33.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#88845): https://edk2.groups.io/g/devel/message/88845 Mute This Topic: https://groups.io/mt/90435463/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-