UefiCpuPkg/CpuPageTableLib: Add intrinsic lib to fix MSVC build

For the bitfield access, MSVC apparently uses a right shift of the base type of the bitfield member. In our case, is is cased by IA32_PTE_4K and
IA32_PAGE_LEAF_ENTRY_BIG_PAGESIZE and other structures which uses uint64
bitfields and 32-bit x86 doesn't have a 64-bit integer shift (except using MMX or SSE2). With -Od (NOOPT) even for constant counts it puts
the data in EDX:EAX, the shift count in cl and calls __aullshr.

Signed-off-by: Savva Mitrofanov <savvamtr@gmail.com>
This commit is contained in:
Savva Mitrofanov 2023-02-10 16:24:01 +06:00 committed by Mikhail Krichanov
parent 9252fc0e1a
commit 30afd72eaf
4 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,91 @@
/** @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) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Library/BaseLib.h>
/*
* Divides a 64-bit unsigned value by another 64-bit unsigned value and returns
* the 64-bit unsigned remainder.
*/
__declspec(naked) void __cdecl
_aullrem(void)
{
//
// Wrapper Implementation over EDKII DivU64x64Remainder() routine
// UINT64
// EFIAPI
// DivU64x64Remainder (
// IN UINT64 Dividend,
// IN UINT64 Divisor,
// OUT UINT64 *Remainder OPTIONAL
// )
//
_asm {
; Original local stack when calling _aullrem
; -----------------
; | |
; |---------------|
; | |
; |-- Divisor --|
; | |
; |---------------|
; | |
; |-- Dividend --|
; | |
; |---------------|
; | ReturnAddr** |
; ESP---->|---------------|
;
;
; Set up the local stack for Reminder pointer
;
sub esp, 8
push esp
;
; Set up the local stack for Divisor parameter
;
mov eax, [esp + 28]
push eax
mov eax, [esp + 28]
push eax
;
; Set up the local stack for Dividend parameter
;
mov eax, [esp + 28]
push eax
mov eax, [esp + 28]
push eax
;
; Call native DivU64x64Remainder of BaseLib
;
call DivU64x64Remainder
;
; Put the Reminder in EDX:EAX as return value
;
mov eax, [esp + 20]
mov edx, [esp + 24]
;
; Adjust stack
;
add esp, 28
ret 16
}
}

View File

@ -27,6 +27,7 @@
[Sources.IA32]
CopyMem.c
Ia32/MathDivU64xU64Rem.c | MSFT
Ia32/MathLShiftS64.c | MSFT
Ia32/MathRShiftU64.c | MSFT
Ia32/MathFtol.c | MSFT
@ -37,6 +38,7 @@
Ia32/MathLldiv.asm | MSFT
Ia32/MathUllrem.asm | MSFT
Ia32/MathDivU64xU64Rem.c | INTEL
Ia32/MathLShiftS64.c | INTEL
Ia32/MathRShiftU64.c | INTEL
Ia32/MathFtol.c | INTEL

View File

@ -33,3 +33,4 @@
BaseLib
BaseMemoryLib
DebugLib
IntrinsicLib

View File

@ -69,6 +69,7 @@
UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf
UnitTestPersistenceLib|UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.inf
UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.inf
IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
[LibraryClasses.common.SEC]
PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf
@ -129,6 +130,9 @@
UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf
UefiCpuPkg/MicrocodeMeasurementDxe/MicrocodeMeasurementDxe.inf
[Components.IA32]
CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
[Components.IA32, Components.X64]
UefiCpuPkg/CpuDxe/CpuDxe.inf
UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf {