forked from acidanthera/OpenCorePkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build: Switch to BaseMemoryLibRepStr for optimised memory routines
We cannot use BaseMemoryLibOptDxe since it uses SSE instructions, and some firmwares fail to properly maintain MMX register contexts across the timers. This results in exceptions when trying to execute primitives like CopyMem in timers (e.g. AIKDataWriteEntry). Reproduced on ASUS M5A97 with AMD FX8320 CPU. closes acidanthera/bugtracker#754
- Loading branch information
Showing
6 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** @file | ||
Check memory routine compatibility. | ||
Copyright (c) 2018, vit9696. 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 <Uefi.h> | ||
#include <Library/BaseMemoryLib.h> | ||
#include <Library/BaseLib.h> | ||
#include <Library/DebugLib.h> | ||
#include <Library/OcMiscLib.h> | ||
#include <Library/UefiLib.h> | ||
#include <Library/UefiBootServicesTableLib.h> | ||
|
||
STATIC UINT8 mSource[64]; | ||
STATIC UINT8 mDestination[64]; | ||
|
||
EFI_STATUS | ||
EFIAPI | ||
UefiMain ( | ||
IN EFI_HANDLE ImageHandle, | ||
IN EFI_SYSTEM_TABLE *SystemTable | ||
) | ||
{ | ||
UINT8 *Src; | ||
UINT8 *Dst; | ||
UINT32 Size; | ||
IA32_CR0 Cr0; | ||
IA32_CR4 Cr4; | ||
IA32_EFLAGS32 Flags; | ||
|
||
Src = ALIGN_POINTER (mSource, 16); | ||
Dst = ALIGN_POINTER (mDestination, 16); | ||
Size = 32; | ||
|
||
gST->ConOut->OutputString (gST->ConOut, L"VerifyMemOpt\r\n"); | ||
gBS->Stall (SECONDS_TO_MICROSECONDS (1)); | ||
|
||
Cr0.UintN = AsmReadCr0 (); | ||
Cr4.UintN = AsmReadCr4 (); | ||
Flags.UintN = AsmReadEflags(); | ||
|
||
// | ||
// CR0.MP bit (BIT1) must be set. | ||
// CR0.EM bit (BIT2) must be cleared. | ||
// CR4.OSFXSR bit (BIT9) must be set. | ||
// CR4.OSXMMEXCPT bit (BIT10) must be set. | ||
// | ||
DEBUG ((DEBUG_WARN, "VMOPT: CR0 %08X CR4 %08X EFLAGS %08X\n", Cr0, Cr4, Flags)); | ||
|
||
if (Cr0.Bits.MP == 0) { | ||
DEBUG ((DEBUG_WARN, "VMOPT: WARN CR0 MP is NOT set\n")); | ||
} | ||
|
||
if (Cr0.Bits.EM != 0) { | ||
DEBUG ((DEBUG_WARN, "VMOPT: WARN CR0 EM is set\n")); | ||
} | ||
|
||
if (Cr4.Bits.OSFXSR == 0) { | ||
DEBUG ((DEBUG_WARN, "VMOPT: WARN CR4 OSFXSR is NOT set\n")); | ||
} | ||
|
||
if (Cr4.Bits.OSXMMEXCPT == 0) { | ||
DEBUG ((DEBUG_WARN, "VMOPT: WARN CR4 OSXMMEXCPT is NOT set\n")); | ||
} | ||
|
||
if (Flags.Bits.DF != 0) { | ||
DEBUG ((DEBUG_WARN, "VMOPT: WARN EFLAGS DF is set\n")); | ||
} | ||
|
||
DEBUG ((DEBUG_WARN, "VMOPT: CopyMem aligned src %p/aligned dst %p/size %u\n", Src, Dst, Size)); | ||
gBS->Stall (SECONDS_TO_MICROSECONDS (1)); | ||
CopyMem (Dst, Src, Size); | ||
|
||
Src += 6; | ||
DEBUG ((DEBUG_WARN, "VMOPT: CopyMem unaligned src %p/aligned dst %p/size %u\n", Src, Dst, Size)); | ||
gBS->Stall (SECONDS_TO_MICROSECONDS (1)); | ||
CopyMem (Dst, Src, Size); | ||
|
||
Size -= 12; | ||
DEBUG ((DEBUG_WARN, "VMOPT: CopyMem unaligned src %p/aligned dst %p/size %u\n", Src, Dst, Size)); | ||
gBS->Stall (SECONDS_TO_MICROSECONDS (1)); | ||
CopyMem (Dst, Src, Size); | ||
|
||
Dst += 6; | ||
DEBUG ((DEBUG_WARN, "VMOPT: CopyMem unaligned src %p/unaligned dst %p/size %u\n", Src, Dst, Size)); | ||
gBS->Stall (SECONDS_TO_MICROSECONDS (1)); | ||
CopyMem (Dst, Src, Size); | ||
|
||
DEBUG ((DEBUG_WARN, "VMOPT: Done testing\n")); | ||
gBS->Stall (SECONDS_TO_MICROSECONDS (1)); | ||
|
||
return EFI_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## @file | ||
# Check memory routine compatibility. | ||
# | ||
# Copyright (c) 2018, vit9696. 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. | ||
# | ||
## | ||
|
||
[Defines] | ||
INF_VERSION = 0x00010005 | ||
BASE_NAME = VerifyMemOpt | ||
FILE_GUID = 00697824-B09E-43D6-8A2A-1CD9E5C7BFBC | ||
MODULE_TYPE = UEFI_APPLICATION | ||
VERSION_STRING = 1.0 | ||
ENTRY_POINT = UefiMain | ||
|
||
# | ||
# This flag specifies whether HII resource section is generated into PE image. | ||
# | ||
UEFI_HII_RESOURCE_SECTION = TRUE | ||
|
||
# | ||
# The following information is for reference only and not required by the build tools. | ||
# | ||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC | ||
# | ||
|
||
[Sources] | ||
VerifyMemOpt.c | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
MdeModulePkg/MdeModulePkg.dec | ||
OpenCorePkg/OpenCorePkg.dec | ||
UefiCpuPkg/UefiCpuPkg.dec | ||
|
||
[LibraryClasses] | ||
OcConsoleControlEntryModeGenericLib | ||
UefiApplicationEntryPoint | ||
UefiLib | ||
PcdLib | ||
IoLib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters