Skip to content

Commit

Permalink
MdePkg: Use VsIntrinsicLib for VS2022 Build Tools
Browse files Browse the repository at this point in the history
Update MdePkg.dsc to use VsIntrinsicLib when building IA32 components
with VS2022 Build Tools.

Signed-off-by: Bret Barkelew <[email protected]>
  • Loading branch information
Bret Barkelew authored and Javagedes committed Jul 2, 2024
1 parent f8e120c commit 4df5202
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 1 deletion.
98 changes: 98 additions & 0 deletions MdePkg/Library/VsIntrinsicLib/IA32/llmul.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
;***
;llmul.asm - long multiply routine
;
; Copyright (c) Microsoft Corporation.
; 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 = ((ALO * BHI) + (AHI * BLO))

mov eax,LOW_PART(A2);ecx = BLO
mul ecx ;so edx:eax = ALO*BLO
add edx,ebx ;now edx has all the LO*HI stuff

pop ebx

ret 16 ; callee restores the stack

_allmul ENDP

end
35 changes: 35 additions & 0 deletions MdePkg/Library/VsIntrinsicLib/VsIntrinsicLib.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## @file
# Since the C compiler does very aggressive full program optimizations there are cases
# where some small number of compiler inserted functions can not be avoided.
# To handle that case this NULL library can be injected into all 32bit modules
# so that the link time dependency is met and the modules compile.
#
# The routines are based on src delivered with the visual studio product. it is
# critical that calling convention, stack usage, register usage, etc is in line
# with what the compiler expects as there is no way to influence the behaviors
# for compiler inserted functions.
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = VsIntrinsicLib
MODULE_UNI_FILE = VsIntrinsicLib.uni
FILE_GUID = ed449fc0-3265-40ed-91b8-435b8df0aa5f
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = NULL

#
# VALID_ARCHITECTURES = IA32
#

[Sources]

[Sources.Ia32]
IA32/llmul.asm

[Packages]
MdePkg/MdePkg.dec
13 changes: 13 additions & 0 deletions MdePkg/Library/VsIntrinsicLib/VsIntrinsicLib.uni
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// /** @file
// VsIntrinsic Library implementation.
//
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/


#string STR_MODULE_ABSTRACT #language en-US "VsIntrinsic Library implementation"

#string STR_MODULE_DESCRIPTION #language en-US "VsIntrinsic Library implementation"

4 changes: 3 additions & 1 deletion MdePkg/MdePkg.ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@

## options defined ci/Plugin/DscCompleteCheck
"DscCompleteCheck": {
"IgnoreInf": [""],
"IgnoreInf": [
"MdePkg/Library/VsIntrinsicLib/VsIntrinsicLib.inf", # MU_CHANGE - Ignore intrinsics for toolchains that don't support it.
],
"DscPath": "MdePkg.dsc"
},

Expand Down
7 changes: 7 additions & 0 deletions MdePkg/MdePkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@
MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.inf

# MU_CHANGE [BEGIN]
!if $(TOOLCHAIN) == VS2017 or $(TOOLCHAIN) == VS2019 or $(TOOLCHAIN) == VS2022
[Components.IA32]
MdePkg/Library/VsIntrinsicLib/VsIntrinsicLib.inf
!endif
# MU_CHANGE [END]

[Components.EBC]
MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
Expand Down

0 comments on commit 4df5202

Please sign in to comment.