diff options
Diffstat (limited to 'src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib')
9 files changed, 379 insertions, 0 deletions
diff --git a/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/BaseIntrinsicLib.uni b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/BaseIntrinsicLib.uni new file mode 100644 index 00000000..47f19d40 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/BaseIntrinsicLib.uni @@ -0,0 +1,16 @@ +// /** @file
+// Intrinsic Routines Wrapper Library Instance.
+//
+// This module is intrinsic routines wrapper library instance.
+//
+// Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Intrinsic Routines Wrapper Library Instance"
+
+#string STR_MODULE_DESCRIPTION #language en-US "This module is intrinsic routines wrapper library instance."
+
diff --git a/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/CopyMem.c b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/CopyMem.c new file mode 100644 index 00000000..d196296a --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/CopyMem.c @@ -0,0 +1,30 @@ +/** @file + Intrinsic Memory Routines Wrapper Implementation for OpenSSL-based + Cryptographic Library. + +Copyright (c) 2010, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Base.h> +#include <Library/BaseMemoryLib.h> + +#if defined(__clang__) && !defined(__APPLE__) + +/* Copies bytes between buffers */ +static __attribute__((__used__)) +void * __memcpy (void *dest, const void *src, unsigned int count) +{ + return CopyMem (dest, src, (UINTN)count); +} +__attribute__((__alias__("__memcpy"))) +void * memcpy (void *dest, const void *src, unsigned int count); + +#else +/* Copies bytes between buffers */ +void * memcpy (void *dest, const void *src, unsigned int count) +{ + return CopyMem (dest, src, (UINTN)count); +} +#endif diff --git a/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathFtol.c b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathFtol.c new file mode 100644 index 00000000..02df0e8d --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathFtol.c @@ -0,0 +1,22 @@ +/** @file + 64-bit Math Worker Function. + The 32-bit versions of C compiler generate calls to library routines + to handle 64-bit math. These functions use non-standard calling conventions. + +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +/* + * Floating point to integer conversion. + */ +__declspec(naked) void _ftol2 (void) +{ + _asm { + fistp qword ptr [esp-8] + mov edx, [esp-4] + mov eax, [esp-8] + ret + } +} diff --git a/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathLShiftS64.c b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathLShiftS64.c new file mode 100644 index 00000000..3b1255db --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathLShiftS64.c @@ -0,0 +1,48 @@ +/** @file + 64-bit Math Worker Function. + The 32-bit versions of C compiler generate calls to library routines + to handle 64-bit math. These functions use non-standard calling conventions. + +Copyright (c) 2014, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + + +/* + * Shifts a 64-bit signed value left by a particular number of bits. + */ +__declspec(naked) void __cdecl _allshl (void) +{ + _asm { + ; + ; Handle shifting of 64 or more bits (return 0) + ; + cmp cl, 64 + jae short ReturnZero + + ; + ; Handle shifting of between 0 and 31 bits + ; + cmp cl, 32 + jae short More32 + shld edx, eax, cl + shl eax, cl + ret + + ; + ; Handle shifting of between 32 and 63 bits + ; +More32: + mov edx, eax + xor eax, eax + and cl, 31 + shl edx, cl + ret + +ReturnZero: + xor eax,eax + xor edx,edx + ret + } +} diff --git a/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathLShiftS64.nasm b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathLShiftS64.nasm new file mode 100644 index 00000000..110ffec4 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathLShiftS64.nasm @@ -0,0 +1,42 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR> +; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; MathLShiftS64.nasm +; +; Abstract: +; +; 64-bit Math Worker Function. +; Shifts a 64-bit signed value left by a certain number of bits. +; +;------------------------------------------------------------------------------ + + SECTION .text + +global ASM_PFX(__ashldi3) +;------------------------------------------------------------------------------ +; +; void __cdecl __ashldi3 (void) +; +;------------------------------------------------------------------------------ +ASM_PFX(__ashldi3): + cmp cl,0x40 + jnc ReturnZero + cmp cl,0x20 + jnc More32 + shld edx,eax,cl + shl eax,cl + ret +More32: + mov edx,eax + xor eax,eax + and cl,0x1f + shl edx,cl + ret +ReturnZero: + xor eax,eax + xor edx,edx + ret diff --git a/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathRShiftU64.c b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathRShiftU64.c new file mode 100644 index 00000000..29497692 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathRShiftU64.c @@ -0,0 +1,51 @@ +/** @file + 64-bit Math Worker Function. + The 32-bit versions of C compiler generate calls to library routines + to handle 64-bit math. These functions use non-standard calling conventions. + +Copyright (c) 2014, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + + +/* + * Shifts a 64-bit unsigned value right by a certain number of bits. + */ +__declspec(naked) void __cdecl _aullshr (void) +{ + _asm { + ; + ; Checking: Only handle 64bit shifting or more + ; + cmp cl, 64 + jae _Exit + + ; + ; Handle shifting between 0 and 31 bits + ; + cmp cl, 32 + jae More32 + shrd eax, edx, cl + shr edx, cl + ret + + ; + ; Handle shifting of 32-63 bits + ; +More32: + mov eax, edx + xor edx, edx + and cl, 31 + shr eax, cl + ret + + ; + ; Invalid number (less then 32bits), return 0 + ; +_Exit: + xor eax, eax + xor edx, edx + ret + } +} diff --git a/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathRShiftU64.nasm b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathRShiftU64.nasm new file mode 100644 index 00000000..2939aad4 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/Ia32/MathRShiftU64.nasm @@ -0,0 +1,43 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR> +; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; MathRShiftU64.nasm +; +; Abstract: +; +; 64-bit Math Worker Function. +; Shifts a 64-bit unsigned value right by a certain number of bits. +; +;------------------------------------------------------------------------------ + + SECTION .text + +;------------------------------------------------------------------------------ +; +; void __cdecl __ashrdi3 (void) +; +;------------------------------------------------------------------------------ +global ASM_PFX(__ashrdi3) +ASM_PFX(__ashrdi3): + cmp cl,0x40 + jnc _Exit + cmp cl,0x20 + jnc More32 + shrd eax,edx,cl + shr edx,cl + ret +More32: + mov eax,edx + xor edx,edx + and cl,0x1f + shr eax,cl + ret +_Exit: + xor eax,eax + xor edx,edx + ret + diff --git a/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf new file mode 100644 index 00000000..aa7aa1e5 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf @@ -0,0 +1,67 @@ +## @file +# Intrinsic Routines Wrapper Library Instance. +# +# Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR> +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BaseIntrinsicLib + MODULE_UNI_FILE = BaseIntrinsicLib.uni + FILE_GUID = 63850097-3E97-4c4f-A52D-C811A0106105 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = IntrinsicLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + MemoryIntrinsics.c + +[Sources.IA32] + CopyMem.c + + Ia32/MathLShiftS64.c | MSFT + Ia32/MathRShiftU64.c | MSFT + Ia32/MathFtol.c | MSFT + + Ia32/MathLShiftS64.c | INTEL + Ia32/MathRShiftU64.c | INTEL + Ia32/MathFtol.c | INTEL + + Ia32/MathLShiftS64.nasm | GCC + Ia32/MathRShiftU64.nasm | GCC + +[Sources.X64] + CopyMem.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + +[BuildOptions] + # + # Override MSFT build option to remove /Oi and /GL + # + MSFT:DEBUG_VS2003_IA32_CC_FLAGS == /nologo /c /WX /W4 /Gs32768 /Gy /D UNICODE /O1b2 /FIAutoGen.h /EHs-c- /GR- /GF /GX- /Zi /Gm + MSFT:RELEASE_VS2003_IA32_CC_FLAGS == /nologo /c /WX /W4 /Gs32768 /Gy /D UNICODE /O1b2 /FIAutoGen.h /EHs-c- /GR- /GF /GX- + MSFT:DEBUG_VS2003xASL_IA32_CC_FLAGS == /nologo /c /WX /W4 /Gs32768 /Gy /D UNICODE /O1b2 /FIAutoGen.h /EHs-c- /GR- /GF /GX- /Zi /Gm + MSFT:RELEASE_VS2003xASL_IA32_CC_FLAGS == /nologo /c /WX /W4 /Gs32768 /Gy /D UNICODE /O1b2 /FIAutoGen.h /EHs-c- /GR- /GF /GX- + MSFT:DEBUG_DDK3790_IA32_CC_FLAGS == /nologo /c /WX /Gy /Gs32768 /D UNICODE /O1b2 /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm + MSFT:RELEASE_DDK3790_IA32_CC_FLAGS == /nologo /c /WX /Gy /Gs32768 /D UNICODE /O1b2 /FIAutoGen.h /EHs-c- /GR- /GF + MSFT:DEBUG_DDK3790xASL_IA32_CC_FLAGS == /nologo /c /WX /Gy /Gs32768 /D UNICODE /O1b2 /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm + MSFT:RELEASE_DDK3790xASL_IA32_CC_FLAGS == /nologo /c /WX /Gy /Gs32768 /D UNICODE /O1b2 /FIAutoGen.h /EHs-c- /GR- /GF + MSFT:DEBUG_*_IA32_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm + MSFT:RELEASE_*_IA32_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /FIAutoGen.h /EHs-c- /GR- /GF + MSFT:DEBUG_*_X64_CC_FLAGS == /nologo /c /WX /GS- /X /W4 /Gs32768 /D UNICODE /O1b2s /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm + MSFT:RELEASE_*_X64_CC_FLAGS == /nologo /c /WX /GS- /X /W4 /Gs32768 /D UNICODE /O1b2s /Gy /FIAutoGen.h /EHs-c- /GR- /GF + INTEL:*_*_*_CC_FLAGS = /Oi- diff --git a/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/MemoryIntrinsics.c b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/MemoryIntrinsics.c new file mode 100644 index 00000000..25c3cc35 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/CryptoPkg/Library/IntrinsicLib/MemoryIntrinsics.c @@ -0,0 +1,60 @@ +/** @file + Intrinsic Memory Routines Wrapper Implementation for OpenSSL-based + Cryptographic Library. + +Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR> +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Base.h> +#include <Library/BaseMemoryLib.h> +#include <Library/BaseLib.h> + +typedef UINTN size_t; + +#if defined(__GNUC__) || defined(__clang__) + #define GLOBAL_USED __attribute__((used)) +#else + #define GLOBAL_USED +#endif + +/* OpenSSL will use floating point support, and C compiler produces the _fltused + symbol by default. Simply define this symbol here to satisfy the linker. */ +int GLOBAL_USED _fltused = 1; + +/* Sets buffers to a specified character */ +void * memset (void *dest, int ch, size_t count) +{ + // + // NOTE: Here we use one base implementation for memset, instead of the direct + // optimized SetMem() wrapper. Because the IntrinsicLib has to be built + // without whole program optimization option, and there will be some + // potential register usage errors when calling other optimized codes. + // + + // + // Declare the local variables that actually move the data elements as + // volatile to prevent the optimizer from replacing this function with + // the intrinsic memset() + // + volatile UINT8 *Pointer; + + Pointer = (UINT8 *)dest; + while (count-- != 0) { + *(Pointer++) = (UINT8)ch; + } + + return dest; +} + +/* Compare bytes in two buffers. */ +int memcmp (const void *buf1, const void *buf2, size_t count) +{ + return (int)CompareMem(buf1, buf2, count); +} + +int strcmp (const char *s1, const char *s2) +{ + return (int)AsciiStrCmp(s1, s2); +} |