volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo;\r
UINTN Size;\r
IA32_SEGMENT_DESCRIPTOR *Selector;\r
+ IA32_CR4 Cr4;\r
\r
ExchangeInfo = CpuMpData->MpCpuExchangeInfo;\r
ExchangeInfo->Lock = 0;\r
\r
ExchangeInfo->InitializeFloatingPointUnitsAddress = (UINTN)InitializeFloatingPointUnits;\r
\r
+ //\r
+ // We can check either CPUID(7).ECX[bit16] or check CR4.LA57[bit12]\r
+ // to determin whether 5-Level Paging is enabled.\r
+ // CPUID(7).ECX[bit16] shows CPU's capability, CR4.LA57[bit12] shows\r
+ // current system setting.\r
+ // Using latter way is simpler because it also eliminates the needs to\r
+ // check whether platform wants to enable it.\r
+ //\r
+ Cr4.UintN = AsmReadCr4 ();\r
+ ExchangeInfo->Enable5LevelPaging = (BOOLEAN) (Cr4.Bits.LA57 == 1);\r
+ DEBUG ((DEBUG_INFO, "%a: 5-Level Paging = %d\n", gEfiCallerBaseName, ExchangeInfo->Enable5LevelPaging));\r
+\r
//\r
// Get the BSP's data of GDT and IDT\r
//\r
UINT16 ModeTransitionSegment;\r
UINT32 ModeHighMemory;\r
UINT16 ModeHighSegment;\r
+ //\r
+ // Enable5LevelPaging indicates whether 5-level paging is enabled in long mode.\r
+ //\r
+ BOOLEAN Enable5LevelPaging;\r
} MP_CPU_EXCHANGE_INFO;\r
\r
#pragma pack()\r
;------------------------------------------------------------------------------ ;\r
-; Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r
; SPDX-License-Identifier: BSD-2-Clause-Patent\r
;\r
; Module Name:\r
ModeTransitionSegmentLocation equ LockLocation + 98h\r
ModeHighMemoryLocation equ LockLocation + 9Ah\r
ModeHighSegmentLocation equ LockLocation + 9Eh\r
+Enable5LevelPagingLocation equ LockLocation + 0A0h\r
;------------------------------------------------------------------------------ ;\r
-; Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r
; SPDX-License-Identifier: BSD-2-Clause-Patent\r
;\r
; Module Name:\r
;\r
mov eax, cr4\r
bts eax, 5\r
+\r
+ mov esi, Enable5LevelPagingLocation\r
+ cmp byte [ebx + esi], 0\r
+ jz SkipEnable5LevelPaging\r
+\r
+ ;\r
+ ; Enable 5 Level Paging\r
+ ;\r
+ bts eax, 12 ; Set LA57=1.\r
+\r
+SkipEnable5LevelPaging:\r
+\r
mov cr4, eax\r
\r
;\r