MdePkg/BaseLib: Add support for the XGETBV instruction

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198

Under SEV-ES, a CPUID instruction requires the current value of the XCR0
register. In order to retrieve that value, the XGETBV instruction needs
to be executed.

Provide the necessary support to execute the XGETBV instruction.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Tom Lendacky 2020-08-12 15:21:35 -05:00 committed by mergify[bot]
parent b098f5e9e9
commit 9b3ca509ab
4 changed files with 84 additions and 0 deletions

View File

@ -7831,6 +7831,23 @@ AsmLfence (
VOID
);
/**
Executes a XGETBV instruction
Executes a XGETBV instruction. This function is only available on IA-32 and
x64.
@param[in] Index Extended control register index
@return The current value of the extended control register
**/
UINT64
EFIAPI
AsmXGetBv (
IN UINT32 Index
);
/**
Patch the immediate operand of an IA32 or X64 instruction such that the byte,
word, dword or qword operand is encoded at the end of the instruction's

View File

@ -183,6 +183,7 @@
Ia32/EnableCache.nasm| GCC
Ia32/DisableCache.nasm| GCC
Ia32/RdRand.nasm
Ia32/XGetBv.nasm
Ia32/DivS64x64Remainder.c
Ia32/InternalSwitchStack.c | MSFT
@ -315,6 +316,7 @@
X64/EnableDisableInterrupts.nasm
X64/DisablePaging64.nasm
X64/RdRand.nasm
X64/XGetBv.nasm
ChkStkGcc.c | GCC
[Sources.EBC]

View File

@ -0,0 +1,31 @@
;------------------------------------------------------------------------------
;
; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
; Module Name:
;
; XGetBv.Asm
;
; Abstract:
;
; AsmXgetBv function
;
; Notes:
;
;------------------------------------------------------------------------------
SECTION .text
;------------------------------------------------------------------------------
; UINT64
; EFIAPI
; AsmXGetBv (
; IN UINT32 Index
; );
;------------------------------------------------------------------------------
global ASM_PFX(AsmXGetBv)
ASM_PFX(AsmXGetBv):
mov ecx, [esp + 4]
xgetbv
ret

View File

@ -0,0 +1,34 @@
;------------------------------------------------------------------------------
;
; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
; Module Name:
;
; XGetBv.Asm
;
; Abstract:
;
; AsmXgetBv function
;
; Notes:
;
;------------------------------------------------------------------------------
DEFAULT REL
SECTION .text
;------------------------------------------------------------------------------
; UINT64
; EFIAPI
; AsmXGetBv (
; IN UINT32 Index
; );
;------------------------------------------------------------------------------
global ASM_PFX(AsmXGetBv)
ASM_PFX(AsmXGetBv):
xgetbv
shl rdx, 32
or rax, rdx
ret