]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg: Add instrinsics to support building ECC on IA32 windows
authoryi1 li <yi1.li@intel.com>
Wed, 13 Apr 2022 07:02:00 +0000 (15:02 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 14 Apr 2022 03:16:59 +0000 (03:16 +0000)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3679

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 <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: yi1 li <yi1.li@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
CryptoPkg/Library/IntrinsicLib/Ia32/MathLlmul.asm [new file with mode: 0644]
CryptoPkg/Library/IntrinsicLib/Ia32/MathLlshr.asm [new file with mode: 0644]
CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf

diff --git a/CryptoPkg/Library/IntrinsicLib/Ia32/MathLlmul.asm b/CryptoPkg/Library/IntrinsicLib/Ia32/MathLlmul.asm
new file mode 100644 (file)
index 0000000..341ea8a
--- /dev/null
@@ -0,0 +1,98 @@
+;***\r
+;llmul.asm - long multiply routine\r
+;\r
+;       Copyright (c) Microsoft Corporation. All rights reserved.\r
+;       SPDX-License-Identifier: BSD-2-Clause-Patent\r
+;\r
+;Purpose:\r
+;       Defines long multiply routine\r
+;       Both signed and unsigned routines are the same, since multiply's\r
+;       work out the same in 2's complement\r
+;       creates the following routine:\r
+;           __allmul\r
+;\r
+;Original Implemenation: MSVC 14.12.25827\r
+;\r
+;*******************************************************************************\r
+    .686\r
+    .model  flat,C\r
+    .code\r
+\r
+\r
+;***\r
+;llmul - long multiply routine\r
+;\r
+;Purpose:\r
+;       Does a long multiply (same for signed/unsigned)\r
+;       Parameters are not changed.\r
+;\r
+;Entry:\r
+;       Parameters are passed on the stack:\r
+;               1st pushed: multiplier (QWORD)\r
+;               2nd pushed: multiplicand (QWORD)\r
+;\r
+;Exit:\r
+;       EDX:EAX - product of multiplier and multiplicand\r
+;       NOTE: parameters are removed from the stack\r
+;\r
+;Uses:\r
+;       ECX\r
+;\r
+;Exceptions:\r
+;\r
+;*******************************************************************************\r
+_allmul PROC NEAR\r
+\r
+A       EQU     [esp + 4]       ; stack address of a\r
+B       EQU     [esp + 12]      ; stack address of b\r
+\r
+HIGH_PART  EQU     [4]             ;\r
+LOW_PART   EQU     [0]\r
+\r
+;\r
+;       AHI, BHI : upper 32 bits of A and B\r
+;       ALO, BLO : lower 32 bits of A and B\r
+;\r
+;             ALO * BLO\r
+;       ALO * BHI\r
+; +     BLO * AHI\r
+; ---------------------\r
+;\r
+\r
+        mov     eax,HIGH_PART(A)\r
+        mov     ecx,HIGH_PART(B)\r
+        or      ecx,eax         ;test for both high dwords zero.\r
+        mov     ecx,LOW_PART(B)\r
+        jnz     short hard      ;both are zero, just mult ALO and BLO\r
+\r
+        mov     eax,LOW_PART(A)\r
+        mul     ecx\r
+\r
+        ret     16              ; callee restores the stack\r
+\r
+hard:\r
+        push    ebx\r
+\r
+; must redefine A and B since esp has been altered\r
+\r
+A2      EQU     [esp + 8]       ; stack address of a\r
+B2      EQU     [esp + 16]      ; stack address of b\r
+\r
+        mul     ecx             ;eax has AHI, ecx has BLO, so AHI * BLO\r
+        mov     ebx,eax         ;save result\r
+\r
+        mov     eax,LOW_PART(A2)\r
+        mul     dword ptr HIGH_PART(B2) ;ALO * BHI\r
+        add     ebx,eax         ;ebx = ((ALO * BHI) + (AHI * BLO))\r
+\r
+        mov     eax,LOW_PART(A2);ecx = BLO\r
+        mul     ecx             ;so edx:eax = ALO*BLO\r
+        add     edx,ebx         ;now edx has all the LO*HI stuff\r
+\r
+        pop     ebx\r
+\r
+        ret     16              ; callee restores the stack\r
+\r
+_allmul ENDP\r
+\r
+        end\r
diff --git a/CryptoPkg/Library/IntrinsicLib/Ia32/MathLlshr.asm b/CryptoPkg/Library/IntrinsicLib/Ia32/MathLlshr.asm
new file mode 100644 (file)
index 0000000..ab82945
--- /dev/null
@@ -0,0 +1,78 @@
+;***\r
+;llshr.asm - long shift right\r
+;\r
+;       Copyright (c) Microsoft Corporation. All rights reserved.\r
+;       SPDX-License-Identifier: BSD-2-Clause-Patent\r
+;\r
+;Purpose:\r
+;       define signed long shift right routine\r
+;           __allshr\r
+;\r
+;Original Implemenation: MSVC 14.12.25827\r
+;\r
+;*******************************************************************************\r
+    .686\r
+    .model  flat,C\r
+    .code\r
+\r
+\r
+\r
+;***\r
+;llshr - long shift right\r
+;\r
+;Purpose:\r
+;       Does a signed Long Shift Right\r
+;       Shifts a long right any number of bits.\r
+;\r
+;Entry:\r
+;       EDX:EAX - long value to be shifted\r
+;       CL    - number of bits to shift by\r
+;\r
+;Exit:\r
+;       EDX:EAX - shifted value\r
+;\r
+;Uses:\r
+;       CL is destroyed.\r
+;\r
+;Exceptions:\r
+;\r
+;*******************************************************************************\r
+_allshr PROC NEAR\r
+\r
+;\r
+; Handle shifts of 64 bits or more (if shifting 64 bits or more, the result\r
+; depends only on the high order bit of edx).\r
+;\r
+        cmp     cl,64\r
+        jae     short RETSIGN\r
+\r
+;\r
+; Handle shifts of between 0 and 31 bits\r
+;\r
+        cmp     cl, 32\r
+        jae     short MORE32\r
+        shrd    eax,edx,cl\r
+        sar     edx,cl\r
+        ret\r
+\r
+;\r
+; Handle shifts of between 32 and 63 bits\r
+;\r
+MORE32:\r
+        mov     eax,edx\r
+        sar     edx,31\r
+        and     cl,31\r
+        sar     eax,cl\r
+        ret\r
+\r
+;\r
+; Return double precision 0 or -1, depending on the sign of edx\r
+;\r
+RETSIGN:\r
+        sar     edx,31\r
+        mov     eax,edx\r
+        ret\r
+\r
+_allshr ENDP\r
+\r
+        end\r
index fcbb93316cf75ae984274b15523c14267f37c224..86e74b57b109dc1ec20ae82a68225bdf1ef0c5ad 100644 (file)
@@ -30,6 +30,8 @@
   Ia32/MathLShiftS64.c      | MSFT\r
   Ia32/MathRShiftU64.c      | MSFT\r
   Ia32/MathFtol.c           | MSFT\r
+  Ia32/MathLlmul.asm        | MSFT\r
+  Ia32/MathLlshr.asm        | MSFT\r
 \r
   Ia32/MathLShiftS64.c      | INTEL\r
   Ia32/MathRShiftU64.c      | INTEL\r