mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
Merge OcSupportPkg into OpenCorePkg
This commit is contained in:
commit
1de38f70f6
17
.gitignore
vendored
17
.gitignore
vendored
@ -7,6 +7,18 @@ xcshareddata
|
||||
xcuserdata
|
||||
project.xcworkspace
|
||||
*.dSYM
|
||||
TestsUser/DiskImage/DiskImage
|
||||
TestsUser/Macho/Macho
|
||||
TestsUser/Prelinked/Prelinked
|
||||
TestsUser/Prelinked/Result.xml
|
||||
TestsUser/RsaPreprocess/RsaPreprocess
|
||||
TestsUser/Serialized/Serialized
|
||||
TestsUser/Smbios/Smbios
|
||||
Utilities/RsaTool/RsaTool
|
||||
Utilities/EfiResTool/EfiResTool
|
||||
Utilities/AppleEfiSignTool/AppleEfiSignTool
|
||||
Utilities/readlabel/readlabel
|
||||
*.o
|
||||
DICT
|
||||
fuzz-*.log
|
||||
crash-*
|
||||
@ -17,3 +29,8 @@ slow-unit-*
|
||||
*.out
|
||||
*.synctex.gz
|
||||
*.toc
|
||||
out.bin
|
||||
prelinkedkernel.unpack
|
||||
.gdb_history
|
||||
*.dmg
|
||||
*.chunklist
|
||||
|
||||
112
Application/BootKicker/BootKicker.c
Normal file
112
Application/BootKicker/BootKicker.c
Normal file
@ -0,0 +1,112 @@
|
||||
/** @file
|
||||
Run Apple Boot Picker.
|
||||
|
||||
Copyright (c) 2020, 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 <PiDxe.h>
|
||||
#include <Guid/AppleFile.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/OcBootManagementLib.h>
|
||||
#include <Library/OcConsoleLib.h>
|
||||
#include <Library/OcMiscLib.h>
|
||||
#include <Library/OcFileLib.h>
|
||||
#include <Library/UefiApplicationEntryPoint.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
#include <Protocol/GraphicsOutput.h>
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UefiMain (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Pixel;
|
||||
UINTN Index;
|
||||
|
||||
gBS->SetWatchdogTimer (0, 0, 0, NULL);
|
||||
|
||||
OcProvideConsoleGop (FALSE);
|
||||
|
||||
OcSetConsoleResolution (0, 0, 0);
|
||||
|
||||
Status = gBS->HandleProtocol (
|
||||
gST->ConsoleOutHandle,
|
||||
&gEfiGraphicsOutputProtocolGuid,
|
||||
(VOID **) &Gop
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
//
|
||||
// Note: Ensure that stall value is within UINT32 in nanoseconds.
|
||||
//
|
||||
for (Index = 0; Index < 10; ++Index) {
|
||||
gBS->Stall (SECONDS_TO_MICROSECONDS (1));
|
||||
}
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = OcRunAppleBootPicker ();
|
||||
|
||||
Pixel.Raw = 0x0;
|
||||
if (Status == EFI_NOT_FOUND) {
|
||||
//
|
||||
// Red. No BootPicker in firmware or we cannot get it.
|
||||
//
|
||||
Pixel.Pixel.Red = 0xFF;
|
||||
} else if (Status == EFI_UNSUPPORTED) {
|
||||
//
|
||||
// Yellow. BootPicker does not start.
|
||||
//
|
||||
Pixel.Pixel.Red = 0xFF;
|
||||
Pixel.Pixel.Green = 0xFF;
|
||||
} else if (EFI_ERROR (Status) /* Status == EFI_INVALID_PARAMETER */) {
|
||||
//
|
||||
// Fuchsia. BootPicker does not load.
|
||||
//
|
||||
Pixel.Pixel.Blue = 0xFF;
|
||||
Pixel.Pixel.Red = 0xFF;
|
||||
} else {
|
||||
//
|
||||
// Green. BootPicker started but returned.
|
||||
//
|
||||
Pixel.Pixel.Green = 0xFF;
|
||||
}
|
||||
|
||||
Gop->Blt (
|
||||
Gop,
|
||||
&Pixel.Pixel,
|
||||
EfiBltVideoFill,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
Gop->Mode->Info->HorizontalResolution,
|
||||
Gop->Mode->Info->VerticalResolution,
|
||||
0
|
||||
);
|
||||
|
||||
//
|
||||
// Note: Ensure that stall value is within UINT32 in nanoseconds.
|
||||
//
|
||||
for (Index = 0; Index < 10; ++Index) {
|
||||
gBS->Stall (SECONDS_TO_MICROSECONDS (1));
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
56
Application/BootKicker/BootKicker.inf
Normal file
56
Application/BootKicker/BootKicker.inf
Normal file
@ -0,0 +1,56 @@
|
||||
## @file
|
||||
# Run Apple Boot Picker.
|
||||
#
|
||||
# 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 = BootKicker
|
||||
FILE_GUID = 3099A880-582F-44BA-8DA3-F4A875F3E34D
|
||||
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]
|
||||
BootKicker.c
|
||||
|
||||
[Guids]
|
||||
gAppleBootPickerFileGuid
|
||||
|
||||
[Protocols]
|
||||
gEfiDevicePathProtocolGuid
|
||||
gEfiFirmwareVolumeProtocolGuid
|
||||
gEfiGraphicsOutputProtocolGuid
|
||||
|
||||
[Packages]
|
||||
EfiPkg/EfiPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
OcSupportPkg/OcSupportPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
OcBootManagementLib
|
||||
OcConsoleLib
|
||||
OcFileLib
|
||||
UefiApplicationEntryPoint
|
||||
UefiBootServicesTableLib
|
||||
UefiLib
|
||||
170
Application/ChipTune/ChipTune.c
Normal file
170
Application/ChipTune/ChipTune.c
Normal file
@ -0,0 +1,170 @@
|
||||
/** @file
|
||||
Play beep.
|
||||
|
||||
Copyright (c) 2020, 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/OcDebugLogLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/OcConsoleLib.h>
|
||||
#include <Library/OcMiscLib.h>
|
||||
#include <Library/UefiApplicationEntryPoint.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
#include <Protocol/AppleHda.h>
|
||||
#include <Protocol/AppleBeepGen.h>
|
||||
#include <Protocol/ShellParameters.h>
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
GetArguments (
|
||||
OUT UINTN *Argc,
|
||||
OUT CHAR16 ***Argv
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters;
|
||||
|
||||
Status = gBS->HandleProtocol (
|
||||
gImageHandle,
|
||||
&gEfiShellParametersProtocolGuid,
|
||||
(VOID**) &ShellParameters
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
*Argc = ShellParameters->Argc;
|
||||
*Argv = ShellParameters->Argv;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UefiMain (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Argc;
|
||||
CHAR16 **Argv;
|
||||
APPLE_HIGH_DEFINITION_AUDIO_PROTOCOL *HdaProtocol;
|
||||
APPLE_BEEP_GEN_PROTOCOL *BeepGenProtocol;
|
||||
UINTN Count;
|
||||
UINTN Signal;
|
||||
UINTN Silence;
|
||||
UINTN Frequency;
|
||||
|
||||
gBS->SetWatchdogTimer (0, 0, 0, NULL);
|
||||
|
||||
OcProvideConsoleGop (FALSE);
|
||||
|
||||
OcConsoleControlSetMode (EfiConsoleControlScreenText);
|
||||
|
||||
OcSetConsoleResolution (0, 0, 0);
|
||||
|
||||
Status = GetArguments (&Argc, &Argv);
|
||||
if (EFI_ERROR (Status) || Argc < 5) {
|
||||
Print (L"Usage: ChipTune <any|hda|beep> <count> <signal> <silence> [<frequency>]\n");
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
Status = StrDecimalToUintnS (Argv[2], NULL, &Count);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Print (L"Invalid count value - %r\n", Status);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
Status = StrDecimalToUintnS (Argv[3], NULL, &Signal);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Print (L"Invalid signal length value - %r\n", Status);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
Status = StrDecimalToUintnS (Argv[4], NULL, &Silence);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Print (L"Invalid silence length value - %r\n", Status);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
if (Argc >= 6) {
|
||||
Status = StrDecimalToUintnS (Argv[5], NULL, &Frequency);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Print (L"Invalid frequency value - %r\n", Status);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
Frequency = 0;
|
||||
}
|
||||
|
||||
HdaProtocol = NULL;
|
||||
BeepGenProtocol = NULL;
|
||||
|
||||
if (StrCmp (Argv[1], L"any") == 0 || StrCmp (Argv[1], L"beep") == 0) {
|
||||
Status = gBS->LocateProtocol (
|
||||
&gAppleBeepGenProtocolGuid,
|
||||
NULL,
|
||||
(VOID **) &BeepGenProtocol
|
||||
);
|
||||
if (EFI_ERROR (Status) || BeepGenProtocol->GenBeep == NULL) {
|
||||
Print (L"Beep protocol is unusable - %r\n", Status);
|
||||
BeepGenProtocol = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (BeepGenProtocol == NULL && (StrCmp (Argv[1], L"any") == 0 || StrCmp (Argv[1], L"hda") == 0)) {
|
||||
Status = gBS->LocateProtocol (
|
||||
&gAppleHighDefinitionAudioProtocolGuid,
|
||||
NULL,
|
||||
(VOID **) &HdaProtocol
|
||||
);
|
||||
if (EFI_ERROR (Status) || HdaProtocol->PlayTone == NULL) {
|
||||
Print (L"HDA protocol is unusable - %r\n", Status);
|
||||
HdaProtocol = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Print (
|
||||
L"Trying playback %u %Lu %Lu %d\n",
|
||||
(UINT32) Count,
|
||||
(UINT64) Signal,
|
||||
(UINT64) Silence,
|
||||
(UINT64) Frequency
|
||||
);
|
||||
|
||||
if (BeepGenProtocol != NULL) {
|
||||
Status = BeepGenProtocol->GenBeep (
|
||||
Count,
|
||||
Signal,
|
||||
Silence
|
||||
);
|
||||
} else if (HdaProtocol != NULL) {
|
||||
Status = HdaProtocol->PlayTone (
|
||||
HdaProtocol,
|
||||
(UINT32) Count,
|
||||
Signal,
|
||||
Silence,
|
||||
Frequency
|
||||
);
|
||||
} else {
|
||||
Status = EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
Print (L"Playback failure - %r\n", Status);
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
51
Application/ChipTune/ChipTune.inf
Normal file
51
Application/ChipTune/ChipTune.inf
Normal file
@ -0,0 +1,51 @@
|
||||
## @file
|
||||
# Run Apple Boot Picker.
|
||||
#
|
||||
# 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 = ChipTune
|
||||
FILE_GUID = CEFAA9E4-8EFC-4B0A-809D-773AF878EC80
|
||||
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]
|
||||
ChipTune.c
|
||||
|
||||
[Protocols]
|
||||
gEfiShellParametersProtocolGuid
|
||||
gAppleHighDefinitionAudioProtocolGuid
|
||||
gAppleBeepGenProtocolGuid
|
||||
|
||||
[Packages]
|
||||
EfiPkg/EfiPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
OcSupportPkg/OcSupportPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
OcConsoleLib
|
||||
UefiApplicationEntryPoint
|
||||
UefiBootServicesTableLib
|
||||
UefiLib
|
||||
38
Application/CleanNvram/CleanNvram.c
Normal file
38
Application/CleanNvram/CleanNvram.c
Normal file
@ -0,0 +1,38 @@
|
||||
/** @file
|
||||
Clean several important nvram variables to recover from issues.
|
||||
|
||||
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/OcBootManagementLib.h>
|
||||
#include <Library/OcMiscLib.h>
|
||||
#include <Library/UefiApplicationEntryPoint.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UefiMain (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
Print (L"NVRAM cleanup...\n");
|
||||
|
||||
OcDeleteVariables ();
|
||||
|
||||
Print (L"NVRAM cleanup completed, please reboot!\n");
|
||||
|
||||
gBS->Stall (SECONDS_TO_MICROSECONDS (3));
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
48
Application/CleanNvram/CleanNvram.inf
Normal file
48
Application/CleanNvram/CleanNvram.inf
Normal file
@ -0,0 +1,48 @@
|
||||
## @file
|
||||
# Clean several important nvram variables to recover from issues.
|
||||
#
|
||||
# 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 = CleanNvram
|
||||
FILE_GUID = 09BD751B-774E-4F54-A339-D9D6D8274BD1
|
||||
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]
|
||||
CleanNvram.c
|
||||
|
||||
[Packages]
|
||||
EfiPkg/EfiPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
OcSupportPkg/OcSupportPkg.dec
|
||||
UefiCpuPkg/UefiCpuPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
OcBootManagementLib
|
||||
OcConsoleControlEntryModeLib
|
||||
UefiApplicationEntryPoint
|
||||
UefiBootServicesTableLib
|
||||
BIN
Application/GopStop/Examples/Step10.png
Normal file
BIN
Application/GopStop/Examples/Step10.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
BIN
Application/GopStop/Examples/Step3.png
Normal file
BIN
Application/GopStop/Examples/Step3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
458
Application/GopStop/GopStop.c
Normal file
458
Application/GopStop/GopStop.c
Normal file
@ -0,0 +1,458 @@
|
||||
/** @file
|
||||
Test graphics output protocol.
|
||||
|
||||
Copyright (c) 2020, 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 <Guid/AppleFile.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/OcBootManagementLib.h>
|
||||
#include <Library/OcConsoleLib.h>
|
||||
#include <Library/OcMiscLib.h>
|
||||
#include <Library/OcFileLib.h>
|
||||
#include <Library/UefiApplicationEntryPoint.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
#include <Protocol/GraphicsOutput.h>
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
AnalyzeGopHandle (
|
||||
IN EFI_HANDLE Handle,
|
||||
IN UINTN GopIndex,
|
||||
IN UINTN HandleCount,
|
||||
OUT CHAR8 *Report
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;
|
||||
UINT32 Index;
|
||||
CHAR8 Tmp[256];
|
||||
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
|
||||
UINTN InfoSize;
|
||||
UINTN Width;
|
||||
UINTN Height;
|
||||
INTN NewMode;
|
||||
|
||||
Status = gBS->HandleProtocol (
|
||||
Handle,
|
||||
&gEfiGraphicsOutputProtocolGuid,
|
||||
(VOID **) &Gop
|
||||
);
|
||||
|
||||
//
|
||||
// GOP report:
|
||||
//
|
||||
AsciiSPrint (
|
||||
Tmp,
|
||||
sizeof (Tmp),
|
||||
"GOP #%u of total %u, %a - %r\n",
|
||||
(UINT32) (GopIndex + 1),
|
||||
(UINT32) HandleCount,
|
||||
gST->ConsoleOutHandle == Handle ? "console" : "auxiliary",
|
||||
Status
|
||||
);
|
||||
DEBUG ((DEBUG_WARN, "GSTT: %a", Tmp));
|
||||
AsciiStrCatS (Report, EFI_PAGE_SIZE, Tmp);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
AsciiSPrint (
|
||||
Tmp,
|
||||
sizeof (Tmp),
|
||||
"Current mode %u, max mode %u, FB: %p, FBS: %LX\n",
|
||||
Gop->Mode->Mode,
|
||||
Gop->Mode->MaxMode,
|
||||
(UINT64) Gop->Mode->FrameBufferBase,
|
||||
(UINT32) Gop->Mode->FrameBufferSize
|
||||
);
|
||||
DEBUG ((DEBUG_WARN, "GSTT: %a", Tmp));
|
||||
AsciiStrCatS (Report, EFI_PAGE_SIZE, Tmp);
|
||||
|
||||
Info = Gop->Mode->Info;
|
||||
AsciiSPrint (
|
||||
Tmp,
|
||||
sizeof (Tmp),
|
||||
"Current: %u x %u, pixel %d (%X %X %X %X), scan: %u\n",
|
||||
Info->HorizontalResolution,
|
||||
Info->VerticalResolution,
|
||||
Info->PixelFormat,
|
||||
Info->PixelInformation.RedMask,
|
||||
Info->PixelInformation.GreenMask,
|
||||
Info->PixelInformation.BlueMask,
|
||||
Info->PixelInformation.ReservedMask,
|
||||
Info->PixelsPerScanLine
|
||||
);
|
||||
DEBUG ((DEBUG_WARN, "GSTT: %a", Tmp));
|
||||
AsciiStrCatS (Report, EFI_PAGE_SIZE, Tmp);
|
||||
|
||||
Width = 0;
|
||||
Height = 0;
|
||||
NewMode = -1;
|
||||
|
||||
for (Index = 0; Index < Gop->Mode->MaxMode; ++Index) {
|
||||
Status = Gop->QueryMode (
|
||||
Gop,
|
||||
Index,
|
||||
&InfoSize,
|
||||
&Info
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
AsciiSPrint (
|
||||
Tmp,
|
||||
sizeof (Tmp),
|
||||
"%u: %r\n",
|
||||
Index,
|
||||
Status
|
||||
);
|
||||
DEBUG ((DEBUG_WARN, "GSTT: %a", Tmp));
|
||||
AsciiStrCatS (Report, EFI_PAGE_SIZE, Tmp);
|
||||
continue;
|
||||
}
|
||||
|
||||
AsciiSPrint (
|
||||
Tmp,
|
||||
sizeof (Tmp),
|
||||
"%u: %u x %u, pixel %d (%X %X %X %X), scan: %u\n",
|
||||
Index,
|
||||
Info->HorizontalResolution,
|
||||
Info->VerticalResolution,
|
||||
Info->PixelFormat,
|
||||
Info->PixelInformation.RedMask,
|
||||
Info->PixelInformation.GreenMask,
|
||||
Info->PixelInformation.BlueMask,
|
||||
Info->PixelInformation.ReservedMask,
|
||||
Info->PixelsPerScanLine
|
||||
);
|
||||
DEBUG ((DEBUG_WARN, "GSTT: %a", Tmp));
|
||||
AsciiStrCatS (Report, EFI_PAGE_SIZE, Tmp);
|
||||
|
||||
if (Info->HorizontalResolution > Width
|
||||
|| (Info->HorizontalResolution == Width && Info->VerticalResolution > Height)) {
|
||||
Width = Info->HorizontalResolution;
|
||||
Height = Info->VerticalResolution;
|
||||
NewMode = (INTN) Index;
|
||||
}
|
||||
|
||||
FreePool (Info);
|
||||
}
|
||||
|
||||
if (NewMode >= 0) {
|
||||
Status = Gop->SetMode (
|
||||
Gop,
|
||||
(UINTN) NewMode
|
||||
);
|
||||
|
||||
Info = Gop->Mode->Info;
|
||||
AsciiSPrint (
|
||||
Tmp,
|
||||
sizeof (Tmp),
|
||||
"New %u <-> %u: max mode %u, FB: %p, FBS: %LX - %r\n",
|
||||
(UINT32) NewMode,
|
||||
Gop->Mode->Mode,
|
||||
Gop->Mode->MaxMode,
|
||||
(UINT64) Gop->Mode->FrameBufferBase,
|
||||
(UINT32) Gop->Mode->FrameBufferSize,
|
||||
Status
|
||||
);
|
||||
DEBUG ((DEBUG_WARN, "GSTT: %a", Tmp));
|
||||
AsciiStrCatS (Report, EFI_PAGE_SIZE, Tmp);
|
||||
AsciiSPrint (
|
||||
Tmp,
|
||||
sizeof (Tmp),
|
||||
"New %u <-> %u: %u x %u, pixel %d (%X %X %X %X), scan: %u\n",
|
||||
(UINT32) NewMode,
|
||||
Gop->Mode->Mode,
|
||||
Info->HorizontalResolution,
|
||||
Info->VerticalResolution,
|
||||
Info->PixelFormat,
|
||||
Info->PixelInformation.RedMask,
|
||||
Info->PixelInformation.GreenMask,
|
||||
Info->PixelInformation.BlueMask,
|
||||
Info->PixelInformation.ReservedMask,
|
||||
Info->PixelsPerScanLine
|
||||
);
|
||||
DEBUG ((DEBUG_WARN, "GSTT: %a", Tmp));
|
||||
AsciiStrCatS (Report, EFI_PAGE_SIZE, Tmp);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
RunGopTest (
|
||||
IN EFI_HANDLE Handle
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;
|
||||
UINTN Index;
|
||||
UINT32 ChunkX;
|
||||
UINT32 ChunkY;
|
||||
UINT32 ChunkW;
|
||||
UINT32 ChunkH;
|
||||
UINT32 ColorIndex;
|
||||
|
||||
|
||||
Status = gBS->HandleProtocol (
|
||||
Handle,
|
||||
&gEfiGraphicsOutputProtocolGuid,
|
||||
(VOID **) &Gop
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)
|
||||
|| Gop->Mode->Info->HorizontalResolution == 0
|
||||
|| Gop->Mode->Info->VerticalResolution == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL mGraphicsEfiColors[16] = {
|
||||
//
|
||||
// B G R reserved
|
||||
//
|
||||
{0x00, 0x00, 0x00, 0x00}, // 0 - BLACK
|
||||
{0x98, 0x00, 0x00, 0x00}, // 1 - LIGHTBLUE
|
||||
{0x00, 0x98, 0x00, 0x00}, // 2 - LIGHGREEN
|
||||
{0x98, 0x98, 0x00, 0x00}, // 3 - LIGHCYAN
|
||||
{0x00, 0x00, 0x98, 0x00}, // 4 - LIGHRED
|
||||
{0x98, 0x00, 0x98, 0x00}, // 5 - MAGENTA
|
||||
{0x00, 0x98, 0x98, 0x00}, // 6 - BROWN
|
||||
{0x98, 0x98, 0x98, 0x00}, // 7 - LIGHTGRAY
|
||||
{0x30, 0x30, 0x30, 0x00}, // 8 - DARKGRAY - BRIGHT BLACK
|
||||
{0xff, 0x00, 0x00, 0x00}, // 9 - BLUE
|
||||
{0x00, 0xff, 0x00, 0x00}, // 10 - LIME
|
||||
{0xff, 0xff, 0x00, 0x00}, // 11 - CYAN
|
||||
{0x00, 0x00, 0xff, 0x00}, // 12 - RED
|
||||
{0xff, 0x00, 0xff, 0x00}, // 13 - FUCHSIA
|
||||
{0x00, 0xff, 0xff, 0x00}, // 14 - YELLOW
|
||||
{0xff, 0xff, 0xff, 0x00} // 15 - WHITE
|
||||
};
|
||||
|
||||
STATIC UINT32 mColorsTest[9] = {12, 10, 9, 15, 7, 0, 11, 5, 14};
|
||||
|
||||
//
|
||||
// 1. Fill screen with Red (#FF0000) in direct mode.
|
||||
//
|
||||
SetMem32 (
|
||||
(VOID *)(UINTN) Gop->Mode->FrameBufferBase,
|
||||
Gop->Mode->Info->VerticalResolution * Gop->Mode->Info->PixelsPerScanLine * sizeof (UINT32),
|
||||
*(UINT32 *) &mGraphicsEfiColors[mColorsTest[0]]
|
||||
);
|
||||
|
||||
//
|
||||
// 2. Wait 5 seconds.
|
||||
// Note: Ensure that stall value is within UINT32 in nanoseconds.
|
||||
//
|
||||
for (Index = 0; Index < 5; ++Index) {
|
||||
gBS->Stall (SECONDS_TO_MICROSECONDS (1));
|
||||
}
|
||||
|
||||
//
|
||||
// 3. Fill screen with 4 Red (#FF0000) / Green (#00FF00) / Blue (#0000FF) / White (#FFFFFF) rectangles.
|
||||
// The user should visually ensure that the colours match and that rectangles equally split the screen in 4 parts.
|
||||
//
|
||||
ChunkW = Gop->Mode->Info->HorizontalResolution / 2;
|
||||
ChunkH = Gop->Mode->Info->VerticalResolution / 2;
|
||||
ColorIndex = 0;
|
||||
for (ChunkY = 0; ChunkY + ChunkH <= Gop->Mode->Info->VerticalResolution; ChunkY += ChunkH) {
|
||||
for (ChunkX = 0; ChunkX + ChunkW <= Gop->Mode->Info->HorizontalResolution; ChunkX += ChunkW) {
|
||||
Gop->Blt (
|
||||
Gop,
|
||||
&mGraphicsEfiColors[mColorsTest[ColorIndex]],
|
||||
EfiBltVideoFill,
|
||||
0,
|
||||
0,
|
||||
ChunkX,
|
||||
ChunkY,
|
||||
ChunkW,
|
||||
ChunkH,
|
||||
0
|
||||
);
|
||||
++ColorIndex;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 4. Wait 5 seconds.
|
||||
// Note: Ensure that stall value is within UINT32 in nanoseconds.
|
||||
//
|
||||
for (Index = 0; Index < 5; ++Index) {
|
||||
gBS->Stall (SECONDS_TO_MICROSECONDS (1));
|
||||
}
|
||||
|
||||
//
|
||||
// TODO:
|
||||
// 5. Fill screen with white text on black screen in normal mode.
|
||||
// The screen should effectively be filled with 9 equal rectangles.
|
||||
// From left to right top to bottom they should contain the following symbols: A B C D # F G H I.
|
||||
// Instead of # there should be current GOP number. The user should visually ensure text and
|
||||
// background colour, rectangle sizes, rectangle data.
|
||||
// 6. Wait 5 seconds.
|
||||
// 7. Fill screen with white text on black screen in HiDPI mode. This should repeat the previous test
|
||||
// but the text should be twice bigger. The user should ensure all previous requirements and the
|
||||
// fact that the text got bigger.
|
||||
// 8. Wait 5 seconds.
|
||||
// 9. Print all GOP reports one by one (on separate screens) with white text in black screen in
|
||||
// normal mode. Wait 5 seconds after each. The user should screenshot these and later compare
|
||||
// to the file if available.
|
||||
//
|
||||
|
||||
//
|
||||
// 10. Fill screen with 9 rectangles of different colours. From left to right top to bottom they
|
||||
// should contain the following colours: Red (#FF0000), Green (#00FF00), Blue (#0000FF), White (#FFFFFF),
|
||||
// Light Grey (#989898), Black (#000000), Cyan (#00FFFF), Magenta (#FF00FF), Yellow (#FFFF00). The user should
|
||||
// visually ensure that the colours match and that rectangles equally split the screen in 9 parts.
|
||||
//
|
||||
ChunkW = Gop->Mode->Info->HorizontalResolution / 3;
|
||||
ChunkH = Gop->Mode->Info->VerticalResolution / 3;
|
||||
ColorIndex = 0;
|
||||
for (ChunkY = 0; ChunkY + ChunkH <= Gop->Mode->Info->VerticalResolution; ChunkY += ChunkH) {
|
||||
for (ChunkX = 0; ChunkX + ChunkW <= Gop->Mode->Info->HorizontalResolution; ChunkX += ChunkW) {
|
||||
Gop->Blt (
|
||||
Gop,
|
||||
&mGraphicsEfiColors[mColorsTest[ColorIndex]],
|
||||
EfiBltVideoFill,
|
||||
0,
|
||||
0,
|
||||
ChunkX,
|
||||
ChunkY,
|
||||
ChunkW,
|
||||
ChunkH,
|
||||
0
|
||||
);
|
||||
++ColorIndex;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 11. Wait 5 seconds.
|
||||
// Note: Ensure that stall value is within UINT32 in nanoseconds.
|
||||
//
|
||||
for (Index = 0; Index < 5; ++Index) {
|
||||
gBS->Stall (SECONDS_TO_MICROSECONDS (1));
|
||||
}
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UefiMain (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN HandleCount;
|
||||
EFI_HANDLE *HandleBuffer;
|
||||
UINTN Index;
|
||||
CHAR8 (*Reports)[EFI_PAGE_SIZE];
|
||||
CHAR8 *FinalReport;
|
||||
CHAR16 Filename[64];
|
||||
EFI_TIME Date;
|
||||
|
||||
//
|
||||
// 1. Disable watchdog timer.
|
||||
//
|
||||
gBS->SetWatchdogTimer (0, 0, 0, NULL);
|
||||
|
||||
//
|
||||
// 2. Gather all N available GOP protocols.
|
||||
//
|
||||
HandleCount = 0;
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiGraphicsOutputProtocolGuid,
|
||||
NULL,
|
||||
&HandleCount,
|
||||
&HandleBuffer
|
||||
);
|
||||
|
||||
DEBUG ((
|
||||
DEBUG_WARN,
|
||||
"GTT: Found %u handles with GOP protocol - %r\n",
|
||||
(UINT32) HandleCount,
|
||||
Status
|
||||
));
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// 3. Allocate N buffer for GOP reports (PAGE_SIZE).
|
||||
//
|
||||
Reports = AllocateZeroPool (EFI_PAGE_SIZE * HandleCount);
|
||||
if (Reports == NULL) {
|
||||
DEBUG ((DEBUG_WARN, "GTT: Cannot allocate memory for GOP reports\n"));
|
||||
FreePool (HandleBuffer);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// 4. Get GOP reports for every GOP and set maximum resolution.
|
||||
//
|
||||
for (Index = 0; Index < HandleCount; ++Index) {
|
||||
AnalyzeGopHandle (HandleBuffer[Index], Index, HandleCount, Reports[Index]);
|
||||
}
|
||||
|
||||
//
|
||||
// 5. Save GOP reports to file to any writable fs (gop-date.txt).
|
||||
//
|
||||
FinalReport = AllocateZeroPool (EFI_PAGE_SIZE * HandleCount);
|
||||
if (FinalReport != NULL) {
|
||||
for (Index = 0; Index < HandleCount; ++Index) {
|
||||
AsciiStrCatS (FinalReport, EFI_PAGE_SIZE * HandleCount, Reports[Index]);
|
||||
AsciiStrCatS (FinalReport, EFI_PAGE_SIZE * HandleCount, "\n\n");
|
||||
}
|
||||
|
||||
Status = gRT->GetTime (&Date, NULL);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ZeroMem (&Date, sizeof (Date));
|
||||
}
|
||||
|
||||
UnicodeSPrint (
|
||||
Filename,
|
||||
sizeof (Filename),
|
||||
L"gop-%04u-%02u-%02u-%02u%02u%02u.txt",
|
||||
(UINT32) Date.Year,
|
||||
(UINT32) Date.Month,
|
||||
(UINT32) Date.Day,
|
||||
(UINT32) Date.Hour,
|
||||
(UINT32) Date.Minute,
|
||||
(UINT32) Date.Second
|
||||
);
|
||||
|
||||
SetFileData (NULL, Filename, FinalReport, AsciiStrLen (FinalReport));
|
||||
|
||||
FreePool (FinalReport);
|
||||
} else {
|
||||
DEBUG ((DEBUG_WARN, "GTT: Cannot allocate memory for final report\n"));
|
||||
}
|
||||
|
||||
//
|
||||
// 6. Run tests in every GOP with non-zero resolution.
|
||||
//
|
||||
for (Index = 0; Index < HandleCount; ++Index) {
|
||||
RunGopTest (HandleBuffer[Index]);
|
||||
}
|
||||
|
||||
FreePool (Reports);
|
||||
FreePool (HandleBuffer);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
54
Application/GopStop/GopStop.inf
Normal file
54
Application/GopStop/GopStop.inf
Normal file
@ -0,0 +1,54 @@
|
||||
## @file
|
||||
# Test graphics output protocol.
|
||||
#
|
||||
# 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 = GopStop
|
||||
FILE_GUID = 76EFA38A-84A0-4B8F-ADA0-E2BE88CFA8D0
|
||||
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]
|
||||
GopStop.c
|
||||
|
||||
[Protocols]
|
||||
gEfiGraphicsOutputProtocolGuid
|
||||
|
||||
[Packages]
|
||||
EfiPkg/EfiPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
OcSupportPkg/OcSupportPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
MemoryAllocationLib
|
||||
OcFileLib
|
||||
PrintLib
|
||||
UefiApplicationEntryPoint
|
||||
UefiBootServicesTableLib
|
||||
UefiRuntimeServicesTableLib
|
||||
UefiLib
|
||||
42
Application/GopStop/README.md
Normal file
42
Application/GopStop/README.md
Normal file
@ -0,0 +1,42 @@
|
||||
GOP Testing Tool
|
||||
================
|
||||
|
||||
1. Disable watchdog timer.
|
||||
2. Gather all N available GOP protocols.
|
||||
3. Allocate N buffer for GOP reports (`EFI_PAGE_SIZE`).
|
||||
4. Get GOP reports for every GOP and set maximum resolution.
|
||||
5. Save GOP reports to file to any writable fs (`gop-{date}.txt`)
|
||||
6. Run tests in every GOP with non-zero resolution.
|
||||
|
||||
### GOP Report
|
||||
|
||||
```
|
||||
GOP #(%u+1) of total %u, console/auxiliary
|
||||
Current mode %u, max mode %u, FB: %p, FBS: %X
|
||||
Current: W x H, pixel %u (%X %X %X %X), scan: %u
|
||||
0: W x H, pixel %u (%X %X %X %X), scan: %u
|
||||
1: Invalid parameter
|
||||
New mode %u, max mode %u, FB: %p, FBS: %X
|
||||
New: W x H, pixel %u (%X %X %X %X), scan: %u
|
||||
```
|
||||
|
||||
### GOP Test
|
||||
|
||||
1. Fill screen with Red (#FF0000) in direct mode.
|
||||
1. Wait 5 seconds.
|
||||
1. Fill screen with 4 rectangles. From left to right top to bottom they should contain the following colours: Red (#FF0000) / Green (#00FF00) / Blue (#0000FF) / White (#FFFFFF). The user should visually ensure that the colours match and that rectangles equally split the screen in 4 parts.
|
||||
1. Wait 5 seconds.
|
||||
1. **UNIMPLEMENTED** Fill screen with white text on black screen in normal mode. The screen should effectively be filled with 9 equal rectangles. From left to right top to bottom they should contain the following symbols: A B C D # F G H I. Instead of # there should be current GOP number. The user should visually ensure text and background colour, rectangle sizes, rectangle data.
|
||||
1. **UNIMPLEMENTED** Wait 5 seconds.
|
||||
1. **UNIMPLEMENTED** Fill screen with white text on black screen in HiDPI mode. This should repeat the previous test but the text should be twice bigger. The user should ensure all previous requirements and the fact that the text got bigger.
|
||||
1. **UNIMPLEMENTED** Wait 5 seconds.
|
||||
1. **UNIMPLEMENTED** Print all GOP reports one by one (on separate screens) with white text in black screen in normal mode. Wait 5 seconds after each. The user should screenshot these and later compare to the file if available.
|
||||
1. Fill screen with 9 rectangles of different colours. From left to right top to bottom they should contain the following colours: Red (#FF0000), Green (#00FF00), Blue (#0000FF), White (#FFFFFF), Light Grey (#989898), Black (#000000), Cyan (#00FFFF), Magenta (#FF00FF), Yellow (#FFFF00). visually ensure that the colours match and that rectangles equally split the screen in 9 parts.
|
||||
1. Wait 5 seconds.
|
||||
|
||||
### Hints
|
||||
|
||||
- Due to not all resolutions being divisible by 2 and 3, right and bottom pixel rows may be unused in corresponding tests.
|
||||
- Depending on rendering performance and amount of GOPs the test may take up to several minutes.
|
||||
- Reference images for some tests are availale in `Examples` directory.
|
||||
|
||||
575
Application/HdaCodecDump/HdaCodecDump.c
Executable file
575
Application/HdaCodecDump/HdaCodecDump.c
Executable file
@ -0,0 +1,575 @@
|
||||
/*
|
||||
* File: HdaCodecDump.c
|
||||
*
|
||||
* Copyright (c) 2018 John Davis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "HdaCodecDump.h"
|
||||
|
||||
STATIC CONST CHAR16 *mWidgetNames[HDA_WIDGET_TYPE_VENDOR + 1] = {
|
||||
L"Audio Output",
|
||||
L"Audio Input",
|
||||
L"Audio Mixer",
|
||||
L"Audio Selector",
|
||||
L"Pin Complex",
|
||||
L"Power Widget",
|
||||
L"Volume Knob Widget",
|
||||
L"Beep Generator Widget",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"Vendor Defined Widget"
|
||||
};
|
||||
|
||||
STATIC CONST CHAR16 *mPortConnectivities[4] = {
|
||||
L"Jack",
|
||||
L"None",
|
||||
L"Fixed",
|
||||
L"Int Jack"
|
||||
};
|
||||
|
||||
STATIC CONST CHAR16 *mDefaultDevices[HDA_CONFIG_DEFAULT_DEVICE_OTHER + 1] = {
|
||||
L"Line Out",
|
||||
L"Speaker",
|
||||
L"HP Out",
|
||||
L"CD",
|
||||
L"SPDIF Out",
|
||||
L"Digital Out",
|
||||
L"Modem Line",
|
||||
L"Modem Handset",
|
||||
L"Line In",
|
||||
L"Aux",
|
||||
L"Mic",
|
||||
L"Telephone",
|
||||
L"SPDIF In",
|
||||
L"Digital In",
|
||||
L"Reserved",
|
||||
L"Other"
|
||||
};
|
||||
|
||||
STATIC CONST CHAR16 *mSurfaces[4] = {
|
||||
L"Ext",
|
||||
L"Int",
|
||||
L"Ext",
|
||||
L"Other"
|
||||
};
|
||||
|
||||
STATIC CONST CHAR16 *mLocations[16] = {
|
||||
L"N/A",
|
||||
L"Rear",
|
||||
L"Front",
|
||||
L"Left",
|
||||
L"Right",
|
||||
L"Top",
|
||||
L"Bottom",
|
||||
L"Special",
|
||||
L"Special",
|
||||
L"Special",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"Reserved"
|
||||
};
|
||||
|
||||
STATIC CONST CHAR16 *mConnTypes[HDA_CONFIG_DEFAULT_CONN_OTHER + 1] = {
|
||||
L"Unknown",
|
||||
L"1/8",
|
||||
L"1/4",
|
||||
L"ATAPI",
|
||||
L"RCA",
|
||||
L"Optical",
|
||||
L"Digital",
|
||||
L"Analog",
|
||||
L"Multi",
|
||||
L"XLR",
|
||||
L"RJ11",
|
||||
L"Combo",
|
||||
L"Other",
|
||||
L"Other",
|
||||
L"Other",
|
||||
L"Other"
|
||||
};
|
||||
|
||||
STATIC CONST CHAR16 *mColors[HDA_CONFIG_DEFAULT_COLOR_OTHER + 1] = {
|
||||
L"Unknown",
|
||||
L"Black",
|
||||
L"Grey",
|
||||
L"Blue",
|
||||
L"Green",
|
||||
L"Red",
|
||||
L"Orange",
|
||||
L"Yellow",
|
||||
L"Purple",
|
||||
L"Pink",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"Reserved",
|
||||
L"White",
|
||||
L"Other"
|
||||
};
|
||||
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
HdaCodecDumpPrintRatesFormats (
|
||||
IN UINT32 Rates,
|
||||
IN UINT32 Formats
|
||||
)
|
||||
{
|
||||
//
|
||||
// Print sample rates.
|
||||
//
|
||||
Print (L" rates [0x%X]:", (UINT16) Rates);
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_8KHZ) != 0) {
|
||||
Print (L" 8000");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_11KHZ) != 0) {
|
||||
Print (L" 11025");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_16KHZ) != 0) {
|
||||
Print (L" 16000");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_22KHZ) != 0) {
|
||||
Print (L" 22050");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_32KHZ) != 0) {
|
||||
Print (L" 32000");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_44KHZ) != 0) {
|
||||
Print (L" 44100");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_48KHZ) != 0) {
|
||||
Print (L" 48000");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_88KHZ) != 0) {
|
||||
Print (L" 88200");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_96KHZ) != 0) {
|
||||
Print (L" 96000");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_176KHZ) != 0) {
|
||||
Print (L" 176400");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_192KHZ) != 0) {
|
||||
Print (L" 192000");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_384KHZ) != 0) {
|
||||
Print (L" 384000");
|
||||
}
|
||||
Print (L"\n");
|
||||
|
||||
//
|
||||
// Print bits.
|
||||
//
|
||||
Print (L" bits [0x%X]:", (UINT16) (Rates >> 16U));
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_8BIT) != 0) {
|
||||
Print (L" 8");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_16BIT) != 0) {
|
||||
Print (L" 16");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_20BIT) != 0) {
|
||||
Print (L" 20");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_24BIT) != 0) {
|
||||
Print (L" 24");
|
||||
}
|
||||
if ((Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_32BIT) != 0) {
|
||||
Print (L" 32");
|
||||
}
|
||||
Print (L"\n");
|
||||
|
||||
//
|
||||
// Print formats.
|
||||
//
|
||||
Print (L" formats [0x%X]:", Formats);
|
||||
if ((Formats & HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_PCM) != 0) {
|
||||
Print (L" PCM");
|
||||
}
|
||||
if ((Formats & HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_FLOAT32) != 0) {
|
||||
Print (L" FLOAT32");
|
||||
}
|
||||
if ((Formats & HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_AC3) != 0) {
|
||||
Print (L" AC3");
|
||||
}
|
||||
Print (L"\n");
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
HdaCodecDumpPrintAmpCaps (
|
||||
IN UINT32 AmpCaps
|
||||
)
|
||||
{
|
||||
if (AmpCaps) {
|
||||
Print (
|
||||
L"ofs=0x%2X, nsteps=0x%2X, stepsize=0x%2X, mute=%u\n",
|
||||
HDA_PARAMETER_AMP_CAPS_OFFSET (AmpCaps),
|
||||
HDA_PARAMETER_AMP_CAPS_NUM_STEPS (AmpCaps),
|
||||
HDA_PARAMETER_AMP_CAPS_STEP_SIZE (AmpCaps),
|
||||
(AmpCaps & HDA_PARAMETER_AMP_CAPS_MUTE) != 0
|
||||
);
|
||||
} else {
|
||||
Print (L"N/A\n");
|
||||
}
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
HdaCodecDumpPrintWidgets (
|
||||
IN HDA_WIDGET *Widgets,
|
||||
IN UINTN WidgetCount
|
||||
)
|
||||
{
|
||||
UINTN Index;
|
||||
UINTN Index2;
|
||||
|
||||
for (Index = 0; Index < WidgetCount; ++Index) {
|
||||
//
|
||||
// Print each widget.
|
||||
//
|
||||
|
||||
//
|
||||
// Print header and capabilities.
|
||||
//
|
||||
Print (
|
||||
L"Node %2u [%s] wcaps 0x%X:",
|
||||
Widgets[Index].NodeId,
|
||||
mWidgetNames[HDA_PARAMETER_WIDGET_CAPS_TYPE (Widgets[Index].Capabilities)],
|
||||
Widgets[Index].Capabilities
|
||||
);
|
||||
if ((Widgets[Index].Capabilities & HDA_PARAMETER_WIDGET_CAPS_STEREO) != 0) {
|
||||
Print (L" Stereo");
|
||||
} else {
|
||||
Print (L" Mono");
|
||||
}
|
||||
|
||||
if ((Widgets[Index].Capabilities & HDA_PARAMETER_WIDGET_CAPS_DIGITAL) != 0) {
|
||||
Print (L" Digital");
|
||||
}
|
||||
if ((Widgets[Index].Capabilities & HDA_PARAMETER_WIDGET_CAPS_IN_AMP) != 0) {
|
||||
Print (L" Amp-In");
|
||||
}
|
||||
if ((Widgets[Index].Capabilities & HDA_PARAMETER_WIDGET_CAPS_OUT_AMP) != 0) {
|
||||
Print (L" Amp-Out");
|
||||
}
|
||||
if ((Widgets[Index].Capabilities & HDA_PARAMETER_WIDGET_CAPS_L_R_SWAP) != 0) {
|
||||
Print (L" R/L");
|
||||
}
|
||||
Print (L"\n");
|
||||
|
||||
//
|
||||
// Print input amp info.
|
||||
//
|
||||
if ((Widgets[Index].Capabilities & HDA_PARAMETER_WIDGET_CAPS_IN_AMP) != 0) {
|
||||
//
|
||||
// Print caps.
|
||||
//
|
||||
Print (L" Amp-in caps: ");
|
||||
HdaCodecDumpPrintAmpCaps (Widgets[Index].AmpInCapabilities);
|
||||
|
||||
//
|
||||
// Print default values.
|
||||
//
|
||||
Print (L" Amp-In vals:");
|
||||
for (Index2 = 0; Index2 < HDA_PARAMETER_CONN_LIST_LENGTH_LEN (Widgets[Index].ConnectionListLength); ++Index2) {
|
||||
if ((Widgets[Index].Capabilities & HDA_PARAMETER_WIDGET_CAPS_STEREO) != 0) {
|
||||
Print (
|
||||
L" [0x%2X 0x%2X]",
|
||||
Widgets[Index].AmpInLeftDefaultGainMute[Index2],
|
||||
Widgets[Index].AmpInRightDefaultGainMute[Index2]
|
||||
);
|
||||
} else {
|
||||
Print (L" [0x%2X]", Widgets[Index].AmpInLeftDefaultGainMute[Index2]);
|
||||
}
|
||||
}
|
||||
Print (L"\n");
|
||||
}
|
||||
|
||||
//
|
||||
// Print output amp info.
|
||||
//
|
||||
if ((Widgets[Index].Capabilities & HDA_PARAMETER_WIDGET_CAPS_OUT_AMP) != 0) {
|
||||
//
|
||||
// Print caps.
|
||||
//
|
||||
Print (L" Amp-Out caps: ");
|
||||
HdaCodecDumpPrintAmpCaps (Widgets[Index].AmpOutCapabilities);
|
||||
|
||||
//
|
||||
// Print default values.
|
||||
//
|
||||
Print (L" Amp-Out vals:");
|
||||
if ((Widgets[Index].Capabilities & HDA_PARAMETER_WIDGET_CAPS_STEREO) != 0) {
|
||||
Print (L" [0x%2X 0x%2X]\n", Widgets[Index].AmpOutLeftDefaultGainMute, Widgets[Index].AmpOutRightDefaultGainMute);
|
||||
} else {
|
||||
Print (L" [0x%2X]\n", Widgets[Index].AmpOutLeftDefaultGainMute);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Print pin complexe info.
|
||||
//
|
||||
if (HDA_PARAMETER_WIDGET_CAPS_TYPE (Widgets[Index].Capabilities) == HDA_WIDGET_TYPE_PIN_COMPLEX) {
|
||||
//
|
||||
// Print pin capabilities.
|
||||
//
|
||||
Print (L" Pincap 0x%8X:", Widgets[Index].PinCapabilities);
|
||||
if ((Widgets[Index].PinCapabilities & HDA_PARAMETER_PIN_CAPS_INPUT) != 0) {
|
||||
Print (L" IN");
|
||||
}
|
||||
if ((Widgets[Index].PinCapabilities & HDA_PARAMETER_PIN_CAPS_OUTPUT) != 0) {
|
||||
Print (L" OUT");
|
||||
}
|
||||
if ((Widgets[Index].PinCapabilities & HDA_PARAMETER_PIN_CAPS_HEADPHONE) != 0) {
|
||||
Print (L" HP");
|
||||
}
|
||||
if ((Widgets[Index].PinCapabilities & HDA_PARAMETER_PIN_CAPS_EAPD) != 0) {
|
||||
Print (L" EAPD");
|
||||
}
|
||||
if ((Widgets[Index].PinCapabilities & HDA_PARAMETER_PIN_CAPS_TRIGGER) != 0) {
|
||||
Print (L" Trigger");
|
||||
}
|
||||
if ((Widgets[Index].PinCapabilities & HDA_PARAMETER_PIN_CAPS_PRESENCE) != 0) {
|
||||
Print (L" Detect");
|
||||
}
|
||||
if ((Widgets[Index].PinCapabilities & HDA_PARAMETER_PIN_CAPS_HBR) != 0) {
|
||||
Print (L" HBR");
|
||||
}
|
||||
if ((Widgets[Index].PinCapabilities & HDA_PARAMETER_PIN_CAPS_HDMI) != 0) {
|
||||
Print (L" HDMI");
|
||||
}
|
||||
if ((Widgets[Index].PinCapabilities & HDA_PARAMETER_PIN_CAPS_DISPLAYPORT) != 0) {
|
||||
Print (L" DP");
|
||||
}
|
||||
Print (L"\n");
|
||||
|
||||
//
|
||||
// Print EAPD info.
|
||||
//
|
||||
if ((Widgets[Index].PinCapabilities & HDA_PARAMETER_PIN_CAPS_EAPD) != 0) {
|
||||
Print (L" EAPD 0x%X:", Widgets[Index].DefaultEapd);
|
||||
if ((Widgets[Index].DefaultEapd & HDA_EAPD_BTL_ENABLE_BTL) != 0) {
|
||||
Print (L" BTL");
|
||||
}
|
||||
if ((Widgets[Index].DefaultEapd & HDA_EAPD_BTL_ENABLE_EAPD) != 0) {
|
||||
Print (L" EAPD");
|
||||
}
|
||||
if ((Widgets[Index].DefaultEapd & HDA_EAPD_BTL_ENABLE_L_R_SWAP) != 0) {
|
||||
Print (L" R/L");
|
||||
}
|
||||
Print (L"\n");
|
||||
}
|
||||
|
||||
//
|
||||
// Create pin default names.
|
||||
//
|
||||
|
||||
//
|
||||
// Print pin default header.
|
||||
//
|
||||
Print (
|
||||
L" Pin Default 0x%8X: [%s] %s at %s %s\n",
|
||||
Widgets[Index].DefaultConfiguration,
|
||||
mPortConnectivities[HDA_VERB_GET_CONFIGURATION_DEFAULT_PORT_CONN (Widgets[Index].DefaultConfiguration)],
|
||||
mDefaultDevices[HDA_VERB_GET_CONFIGURATION_DEFAULT_DEVICE (Widgets[Index].DefaultConfiguration)],
|
||||
mSurfaces[HDA_VERB_GET_CONFIGURATION_DEFAULT_SURF (Widgets[Index].DefaultConfiguration)],
|
||||
mLocations[HDA_VERB_GET_CONFIGURATION_DEFAULT_LOC (Widgets[Index].DefaultConfiguration)]);
|
||||
|
||||
//
|
||||
// Print connection type and color.
|
||||
//
|
||||
Print (
|
||||
L" Conn = %s, Color = %s\n",
|
||||
mConnTypes[HDA_VERB_GET_CONFIGURATION_DEFAULT_CONN_TYPE (Widgets[Index].DefaultConfiguration)],
|
||||
mColors[HDA_VERB_GET_CONFIGURATION_DEFAULT_COLOR (Widgets[Index].DefaultConfiguration)]
|
||||
);
|
||||
|
||||
//
|
||||
// Print default association and sequence.
|
||||
//
|
||||
Print (
|
||||
L" DefAssociation = 0x%X, Sequence = 0x%X\n",
|
||||
HDA_VERB_GET_CONFIGURATION_DEFAULT_ASSOCIATION (Widgets[Index].DefaultConfiguration),
|
||||
HDA_VERB_GET_CONFIGURATION_DEFAULT_SEQUENCE (Widgets[Index].DefaultConfiguration)
|
||||
);
|
||||
|
||||
//
|
||||
// Print default pin control.
|
||||
//
|
||||
Print (L"Pin-ctls: 0x%2X:", Widgets[Index].DefaultPinControl);
|
||||
if ((Widgets[Index].DefaultPinControl & HDA_PIN_WIDGET_CONTROL_VREF_EN) != 0) {
|
||||
Print (L" VREF");
|
||||
}
|
||||
if ((Widgets[Index].DefaultPinControl & HDA_PIN_WIDGET_CONTROL_IN_EN) != 0) {
|
||||
Print (L" IN");
|
||||
}
|
||||
if ((Widgets[Index].DefaultPinControl & HDA_PIN_WIDGET_CONTROL_OUT_EN) != 0) {
|
||||
Print (L" OUT");
|
||||
}
|
||||
if ((Widgets[Index].DefaultPinControl & HDA_PIN_WIDGET_CONTROL_HP_EN) != 0) {
|
||||
Print (L" HP");
|
||||
}
|
||||
Print (L"\n");
|
||||
}
|
||||
|
||||
//
|
||||
// Print connections.
|
||||
//
|
||||
if ((Widgets[Index].Capabilities & HDA_PARAMETER_WIDGET_CAPS_CONN_LIST) != 0) {
|
||||
Print (
|
||||
L" Connection: %u\n ",
|
||||
HDA_PARAMETER_CONN_LIST_LENGTH_LEN (Widgets[Index].ConnectionListLength)
|
||||
);
|
||||
for (Index2 = 0; Index2 < HDA_PARAMETER_CONN_LIST_LENGTH_LEN (Widgets[Index].ConnectionListLength); ++Index2) {
|
||||
Print (L" %2u", Widgets[Index].Connections[Index2]);
|
||||
}
|
||||
Print (L"\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
HdaCodecDumpMain (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE *HdaCodecHandles;
|
||||
UINTN HdaCodecHandleCount;
|
||||
EFI_HDA_CODEC_INFO_PROTOCOL *HdaCodecInfo;
|
||||
UINTN Index;
|
||||
CONST CHAR16 *Name;
|
||||
UINT32 VendorId;
|
||||
UINT32 RevisionId;
|
||||
UINT32 Rates;
|
||||
UINT32 Formats;
|
||||
UINT32 AmpInCaps;
|
||||
UINT32 AmpOutCaps;
|
||||
HDA_WIDGET *Widgets;
|
||||
UINTN WidgetCount;
|
||||
UINT8 AudioFuncId;
|
||||
BOOLEAN Unsol;
|
||||
|
||||
Print (L"HdaCodecDump start\n");
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiHdaCodecInfoProtocolGuid,
|
||||
NULL,
|
||||
&HdaCodecHandleCount,
|
||||
&HdaCodecHandles
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Print (L"No audio devices were found (%r). Ensure AudioDxe is loaded.\n", Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Print each codec found.
|
||||
//
|
||||
for (Index = 0; Index < HdaCodecHandleCount; ++Index) {
|
||||
Status = gBS->HandleProtocol (
|
||||
HdaCodecHandles[Index],
|
||||
&gEfiHdaCodecInfoProtocolGuid,
|
||||
(VOID**) &HdaCodecInfo
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Print (
|
||||
L"Cannot open audio protocol for %p handle - %r.\n",
|
||||
HdaCodecHandles[Index],
|
||||
Status
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Get name.
|
||||
//
|
||||
Status = HdaCodecInfo->GetName (HdaCodecInfo, &Name);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Print (L"Codec: %s\n", Name);
|
||||
}
|
||||
|
||||
//
|
||||
// Get AFG ID.
|
||||
//
|
||||
Status = HdaCodecInfo->GetAudioFuncId (HdaCodecInfo, &AudioFuncId, &Unsol);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Print (L"AFG Function Id: 0x%X (unsol %d)\n", AudioFuncId, Unsol);
|
||||
}
|
||||
|
||||
//
|
||||
// Get vendor.
|
||||
//
|
||||
Status = HdaCodecInfo->GetVendorId (HdaCodecInfo, &VendorId);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Print (L"Vendor ID: 0x%X\n", VendorId);
|
||||
}
|
||||
|
||||
//
|
||||
// Get revision.
|
||||
//
|
||||
Status = HdaCodecInfo->GetRevisionId (HdaCodecInfo, &RevisionId);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Print (L"Revision ID: 0x%X\n", RevisionId);
|
||||
}
|
||||
|
||||
//
|
||||
// Get supported rates/formats.
|
||||
//
|
||||
Status = HdaCodecInfo->GetDefaultRatesFormats (HdaCodecInfo, &Rates, &Formats);
|
||||
if (!EFI_ERROR (Status) && (Rates != 0 || Formats != 0)) {
|
||||
Print (L"Default PCM:\n");
|
||||
HdaCodecDumpPrintRatesFormats(Rates, Formats);
|
||||
} else {
|
||||
Print (L"Default PCM: N/A\n");
|
||||
}
|
||||
|
||||
//
|
||||
// Get default amp caps.
|
||||
//
|
||||
Status = HdaCodecInfo->GetDefaultAmpCaps(HdaCodecInfo, &AmpInCaps, &AmpOutCaps);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Print (L"Default Amp-In caps: ");
|
||||
HdaCodecDumpPrintAmpCaps (AmpInCaps);
|
||||
Print (L"Default Amp-Out caps: ");
|
||||
HdaCodecDumpPrintAmpCaps (AmpOutCaps);
|
||||
}
|
||||
|
||||
//
|
||||
// Get widgets.
|
||||
//
|
||||
Status = HdaCodecInfo->GetWidgets(HdaCodecInfo, &Widgets, &WidgetCount);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
HdaCodecDumpPrintWidgets (Widgets, WidgetCount);
|
||||
HdaCodecInfo->FreeWidgetsBuffer(Widgets, WidgetCount);
|
||||
}
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
38
Application/HdaCodecDump/HdaCodecDump.h
Normal file
38
Application/HdaCodecDump/HdaCodecDump.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* File: HdaCodecDump.h
|
||||
*
|
||||
* Copyright (c) 2018 John Davis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EFI_HDA_CODEC_DUMP_H
|
||||
#define EFI_HDA_CODEC_DUMP_H
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <IndustryStandard/HdaVerbs.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Protocol/HdaCodecInfo.h>
|
||||
|
||||
#endif // EFI_HDA_CODEC_DUMP_H
|
||||
42
Application/HdaCodecDump/HdaCodecDump.inf
Normal file
42
Application/HdaCodecDump/HdaCodecDump.inf
Normal file
@ -0,0 +1,42 @@
|
||||
## @file
|
||||
# Test graphics output protocol.
|
||||
#
|
||||
# Copyright (c) 2018, John Davis. 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 = HdaCodecDump
|
||||
ENTRY_POINT = HdaCodecDumpMain
|
||||
FILE_GUID = 73271011-9220-40C5-8A77-537BB247B616
|
||||
MODULE_TYPE = UEFI_APPLICATION
|
||||
VERSION_STRING = 1.0
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
OcSupportPkg/OcSupportPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
MemoryAllocationLib
|
||||
OcConsoleControlEntryModeLib
|
||||
PcdLib
|
||||
UefiApplicationEntryPoint
|
||||
UefiBootServicesTableLib
|
||||
UefiLib
|
||||
|
||||
[Protocols]
|
||||
gEfiHdaCodecInfoProtocolGuid # CONSUMES
|
||||
|
||||
[Sources]
|
||||
HdaCodecDump.h
|
||||
HdaCodecDump.c
|
||||
628
Application/PavpProvision/PavpProvision.c
Normal file
628
Application/PavpProvision/PavpProvision.c
Normal file
@ -0,0 +1,628 @@
|
||||
/** @file
|
||||
Provision EPID key.
|
||||
|
||||
Copyright (c) 2019, 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 <PiDxe.h>
|
||||
#include <Protocol/FirmwareVolume.h>
|
||||
#include <Protocol/PciRootBridgeIo.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PciLib.h>
|
||||
#include <Library/HobLib.h>
|
||||
#include <Library/IoLib.h>
|
||||
#include <Guid/GlobalVariable.h>
|
||||
|
||||
#include <Library/OcDebugLogLib.h>
|
||||
#include <Library/OcHeciLib.h>
|
||||
#include <Library/OcMiscLib.h>
|
||||
|
||||
#include <Protocol/Heci.h>
|
||||
#include <Protocol/Heci2.h>
|
||||
#include <IndustryStandard/AppleProvisioning.h>
|
||||
#include <IndustryStandard/HeciMsg.h>
|
||||
#include <IndustryStandard/HeciClientMsg.h>
|
||||
|
||||
#define FORCE_PROVISIONING 1
|
||||
#define SA_MC_BUS 0x00
|
||||
#define R_SA_PAVPC (0x58)
|
||||
|
||||
#define MmPciAddress(Segment, Bus, Device, Function, Register) \
|
||||
((UINTN) (PciRead32 (PCI_LIB_ADDRESS (0,0,0,0x60)) & 0xFC000000) + \
|
||||
(UINTN) (Bus << 20) + (UINTN) (Device << 15) + (UINTN) \
|
||||
(Function << 12) + (UINTN) (Register))
|
||||
|
||||
#define MmPci32(Segment, Bus, Device, Function, Register) \
|
||||
*((volatile UINT32 *) MmPciAddress (Segment, Bus, Device, Function, Register))
|
||||
|
||||
STATIC UINT8 mMeClientMap[HBM_ME_CLIENT_MAX];
|
||||
STATIC UINT8 mMeClientActiveCount;
|
||||
|
||||
extern UINT8 gDefaultAppleEpidCertificate[];
|
||||
extern UINTN gDefaultAppleEpidCertificateSize;
|
||||
|
||||
extern UINT8 gDefaultAppleGroupPublicKeys[];
|
||||
extern UINTN gDefaultAppleGroupPublicKeysSize;
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ReadProvisioningDataFile (
|
||||
IN EFI_GUID *FvNameGuid,
|
||||
OUT VOID **Buffer,
|
||||
OUT UINTN *BufferSize
|
||||
)
|
||||
{
|
||||
UINTN Index;
|
||||
EFI_STATUS Status;
|
||||
UINT32 AuthenticationStatus;
|
||||
EFI_FIRMWARE_VOLUME_PROTOCOL *FirmwareVolumeInterface;
|
||||
UINTN NumOfHandles;
|
||||
EFI_HANDLE *HandleBuffer;
|
||||
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiFirmwareVolumeProtocolGuid,
|
||||
NULL,
|
||||
&NumOfHandles,
|
||||
&HandleBuffer
|
||||
);
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
for (Index = 0; Index < NumOfHandles; ++Index) {
|
||||
Status = gBS->HandleProtocol (
|
||||
HandleBuffer[Index],
|
||||
&gEfiFirmwareVolumeProtocolGuid,
|
||||
(VOID **) &FirmwareVolumeInterface
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePool (HandleBuffer);
|
||||
return Status;
|
||||
}
|
||||
|
||||
*Buffer = NULL;
|
||||
*BufferSize = 0;
|
||||
|
||||
Status = FirmwareVolumeInterface->ReadSection (
|
||||
FirmwareVolumeInterface,
|
||||
FvNameGuid,
|
||||
EFI_SECTION_RAW,
|
||||
0,
|
||||
Buffer,
|
||||
BufferSize,
|
||||
&AuthenticationStatus
|
||||
);
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
gBS->FreePool (HandleBuffer);
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
||||
gBS->FreePool (HandleBuffer);
|
||||
Status = EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
//
|
||||
// Implement fallback for our firmwares.
|
||||
//
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_INFO, "OCME: No %g in firmware, using default - %r\n", FvNameGuid, Status));
|
||||
|
||||
if (CompareGuid (&gAppleEpidCertificateFileGuid, FvNameGuid)) {
|
||||
*Buffer = AllocateCopyPool (gDefaultAppleEpidCertificateSize, gDefaultAppleEpidCertificate);
|
||||
*BufferSize = gDefaultAppleEpidCertificateSize;
|
||||
} else if (CompareGuid (&gAppleEpidGroupPublicKeysFileGuid, FvNameGuid)) {
|
||||
*Buffer = AllocateCopyPool (gDefaultAppleGroupPublicKeysSize, gDefaultAppleGroupPublicKeys);
|
||||
*BufferSize = gDefaultAppleGroupPublicKeysSize;
|
||||
} else {
|
||||
*Buffer = NULL;
|
||||
}
|
||||
|
||||
if (*Buffer != NULL) {
|
||||
Status = EFI_SUCCESS;
|
||||
} else {
|
||||
Status = EFI_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ReadProvisioningData (
|
||||
OUT EPID_CERTIFICATE **EpidCertificate,
|
||||
OUT EPID_GROUP_PUBLIC_KEY **EpidGroupPublicKeys,
|
||||
OUT UINT32 *EpidGroupPublicKeysCount
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN EpidCertificateSize;
|
||||
UINTN EpidGroupPublicKeysSize;
|
||||
|
||||
Status = ReadProvisioningDataFile (
|
||||
&gAppleEpidCertificateFileGuid,
|
||||
(VOID **) EpidCertificate,
|
||||
&EpidCertificateSize
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = ReadProvisioningDataFile (
|
||||
&gAppleEpidGroupPublicKeysFileGuid,
|
||||
(VOID **) EpidGroupPublicKeys,
|
||||
&EpidGroupPublicKeysSize
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePool (*EpidGroupPublicKeys);
|
||||
return Status;
|
||||
}
|
||||
|
||||
if (EpidCertificateSize == EPID_CERTIFICATE_SIZE
|
||||
&& EpidGroupPublicKeysSize % EPID_GROUP_PUBLIC_KEY_SIZE == 0) {
|
||||
*EpidGroupPublicKeysCount = EpidGroupPublicKeysSize / EPID_GROUP_PUBLIC_KEY_SIZE;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
gBS->FreePool (*EpidCertificate);
|
||||
gBS->FreePool (*EpidGroupPublicKeys);
|
||||
return EFI_VOLUME_CORRUPTED;
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
SetProvisioningVariable (
|
||||
IN CHAR16 *Variable,
|
||||
IN UINT32 Value
|
||||
)
|
||||
{
|
||||
#ifdef FORCE_PROVISIONING
|
||||
(VOID) Variable;
|
||||
(VOID) Value;
|
||||
#else
|
||||
gRT->SetVariable (
|
||||
Variable,
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||
sizeof (Value),
|
||||
&Value
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
GetGroupPublicKey (
|
||||
IN EPID_GROUP_PUBLIC_KEY *PublicKeys,
|
||||
IN UINTN PublicKeyCount,
|
||||
IN UINT32 Key,
|
||||
OUT EPID_GROUP_PUBLIC_KEY **ChosenPublicKey
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 Index;
|
||||
|
||||
Status = EFI_NOT_FOUND;
|
||||
|
||||
for (Index = 0; Index < PublicKeyCount; ++Index) {
|
||||
if (SwapBytes32 (PublicKeys[Index].GroupId) == Key) {
|
||||
*ChosenPublicKey = &PublicKeys[Index];
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
STATIC
|
||||
BOOLEAN
|
||||
IsBuiltinGpuAvailable (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 Value;
|
||||
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *Interface;
|
||||
|
||||
Status = gBS->LocateProtocol (
|
||||
&gEfiPciRootBridgeIoProtocolGuid,
|
||||
NULL,
|
||||
(VOID **) &Interface
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_INFO, "OC: Failed to find PCI root protocol - %r\n", Status));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// IGPU_DEVICE_ID = 0x2
|
||||
// PCI_VENDOR_ID_OFFSET = 0x0
|
||||
// (IGPU_DEVICE_ID << 16U | PCI_VENDOR_ID_OFFSET)
|
||||
// See EFI_PCI_ADDRESS
|
||||
//
|
||||
Status = Interface->Pci.Read (
|
||||
Interface,
|
||||
EfiPciWidthUint32,
|
||||
0x20000,
|
||||
1,
|
||||
&Value
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_INFO, "OC: Failed to read from IGPU device - %r\n", Status));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: IGPU is %X\n", Value));
|
||||
|
||||
return Value != 0xFFFFFFFFU;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
NeedsEpidProvisioning (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 Data;
|
||||
UINTN DataSize;
|
||||
|
||||
if (IsBuiltinGpuAvailable()) {
|
||||
DataSize = sizeof (Data);
|
||||
|
||||
Status = gRT->GetVariable (
|
||||
APPLE_EPID_PROVISIONED_VARIABLE_NAME,
|
||||
&gEfiGlobalVariableGuid,
|
||||
NULL,
|
||||
&DataSize,
|
||||
&Data
|
||||
);
|
||||
|
||||
#ifdef FORCE_PROVISIONING
|
||||
Data = 0;
|
||||
#endif
|
||||
|
||||
if (EFI_ERROR (Status) || Data != 1) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
NeedsFpfProvisioning (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 Data;
|
||||
UINTN DataSize;
|
||||
APPLE_FPF_CONFIGURATION_HOB *Hob;
|
||||
|
||||
#if 0
|
||||
Hob = GetFirstGuidHob (&gAppleFpfConfigurationHobGuid);
|
||||
#else
|
||||
Hob = NULL;
|
||||
#endif
|
||||
|
||||
DEBUG ((DEBUG_INFO, "OC: HOB for FPF is %p\n", Hob));
|
||||
|
||||
if (Hob == NULL || Hob->ShouldProvision) {
|
||||
DataSize = sizeof (Data);
|
||||
Status = gRT->GetVariable (
|
||||
APPLE_FPF_PROVISIONED_VARIABLE_NAME,
|
||||
&gEfiGlobalVariableGuid,
|
||||
NULL,
|
||||
&DataSize,
|
||||
&Data
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status) || Data != 1) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
OcPerformEpidProvisioning (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
HECI_CLIENT_PROPERTIES Properties;
|
||||
EPID_GROUP_PUBLIC_KEY *EpidGroupPublicKeys;
|
||||
EPID_CERTIFICATE *EpidCertificate;
|
||||
UINT32 EpidGroupPublicKeysCount;
|
||||
UINT32 EpidStatus;
|
||||
UINT32 EpidGroupId;
|
||||
EPID_GROUP_PUBLIC_KEY *EpidCurrentGroupPublicKey;
|
||||
BOOLEAN SetVar;
|
||||
|
||||
Status = NeedsEpidProvisioning ();
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Needs provisioning EPID - %r\n", Status));
|
||||
if (EFI_ERROR (Status)) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
Status = HeciLocateProtocol ();
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: HECI protocol lookup - %r\n", Status));
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = ReadProvisioningData (
|
||||
&EpidCertificate,
|
||||
&EpidGroupPublicKeys,
|
||||
&EpidGroupPublicKeysCount
|
||||
);
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Provisioning data - %r\n", Status));
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Management Engine proccesses namespace.
|
||||
// Each App like PAVP or FPF have unique identifier represented as GUID.
|
||||
//
|
||||
Status = HeciGetClientMap (mMeClientMap, &mMeClientActiveCount);
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Got %d clients - %r\n", mMeClientActiveCount, Status));
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = EFI_NOT_FOUND;
|
||||
|
||||
for (Index = 0; Index < mMeClientActiveCount; ++Index) {
|
||||
Status = HeciGetClientProperties (
|
||||
mMeClientMap[Index],
|
||||
&Properties
|
||||
);
|
||||
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"OCPAVP: Client %u has %g protocol - %r\n",
|
||||
(UINT32) Index,
|
||||
Properties.ProtocolName,
|
||||
Status
|
||||
));
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (CompareGuid (&Properties.ProtocolName, &gMePavpProtocolGuid)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!EFI_ERROR (Status) && Index != mMeClientActiveCount) {
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Found application at %u\n", (UINT32) Index));
|
||||
|
||||
Status = HeciConnectToClient (mMeClientMap[Index]);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
|
||||
EpidStatus = EpidGroupId = 0;
|
||||
Status = HeciPavpRequestProvisioning (&EpidStatus, &EpidGroupId);
|
||||
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Got EPID status %X and group id %x - %r\n", EpidStatus, EpidGroupId, Status));
|
||||
}
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
|
||||
if (EpidStatus == EPID_STATUS_PROVISIONED) {
|
||||
SetProvisioningVariable (APPLE_EPID_PROVISIONED_VARIABLE_NAME, 1);
|
||||
} else if (EpidStatus == EPID_STATUS_CAN_PROVISION) {
|
||||
Status = GetGroupPublicKey (
|
||||
EpidGroupPublicKeys,
|
||||
EpidGroupPublicKeysCount,
|
||||
EpidGroupId,
|
||||
&EpidCurrentGroupPublicKey
|
||||
);
|
||||
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Got EPID group public key - %r\n", Status));
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Status = HeciPavpPerformProvisioning (EpidCertificate, EpidCurrentGroupPublicKey, &SetVar);
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Sent EPID certificate - %r / %d\n", Status, SetVar));
|
||||
if (!EFI_ERROR (Status) || SetVar) {
|
||||
SetProvisioningVariable (APPLE_EPID_PROVISIONED_VARIABLE_NAME, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HeciDisconnectFromClients ();
|
||||
} else {
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: No EPID application found\n"));
|
||||
|
||||
if (Index == mMeClientActiveCount) {
|
||||
//
|
||||
// Do not retry provisioning on incompatible firmware.
|
||||
// TODO: Do we really need this?
|
||||
//
|
||||
SetProvisioningVariable (APPLE_EPID_PROVISIONED_VARIABLE_NAME, 1);
|
||||
Status = EFI_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
gBS->FreePool (EpidCertificate);
|
||||
gBS->FreePool (EpidGroupPublicKeys);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
OcPerformFpfProvisioning (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
HECI_CLIENT_PROPERTIES Properties;
|
||||
UINT32 FpfStatus;
|
||||
|
||||
Status = NeedsFpfProvisioning ();
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Needs provisioning FPF - %r\n", Status));
|
||||
if (EFI_ERROR (Status)) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
Status = HeciLocateProtocol ();
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: HECI protocol lookup - %r\n", Status));
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Management Engine proccesses namespace.
|
||||
// Each App like PAVP or FPF have unique identifier represented as GUID.
|
||||
//
|
||||
Status = HeciGetClientMap (mMeClientMap, &mMeClientActiveCount);
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Got %d clients - %r\n", mMeClientActiveCount, Status));
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = EFI_NOT_FOUND;
|
||||
|
||||
for (Index = 0; Index < mMeClientActiveCount; ++Index) {
|
||||
Status = HeciGetClientProperties (
|
||||
mMeClientMap[Index],
|
||||
&Properties
|
||||
);
|
||||
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"OCPAVP: Client %u has %g protocol - %r\n",
|
||||
(UINT32) Index,
|
||||
Properties.ProtocolName,
|
||||
Status
|
||||
));
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (CompareGuid (&Properties.ProtocolName, &gMeFpfProtocolGuid)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!EFI_ERROR (Status) && Index != mMeClientActiveCount) {
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Found application at %u\n", (UINT32) Index));
|
||||
|
||||
Status = HeciConnectToClient (mMeClientMap[Index]);
|
||||
|
||||
//
|
||||
// I *think* FPF provisioning locks fuses from further update.
|
||||
// For this reason we do not want it.
|
||||
//
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Status = HeciFpfGetStatus (&FpfStatus);
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Got FPF status %u - %r\n", FpfStatus, Status));
|
||||
if (!EFI_ERROR (Status)) {
|
||||
if (FpfStatus == 250) {
|
||||
Status = HeciFpfProvision (&FpfStatus);
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Got FPF provisioning %u - %r\n", FpfStatus, Status));
|
||||
if (!EFI_ERROR (Status) && FpfStatus == 0) {
|
||||
SetProvisioningVariable (APPLE_FPF_PROVISIONED_VARIABLE_NAME, 1);
|
||||
} else {
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
} else {
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
HeciDisconnectFromClients ();
|
||||
}
|
||||
} else {
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: No FPF application found\n"));
|
||||
|
||||
if (Index == mMeClientActiveCount) {
|
||||
//
|
||||
// Do not retry provisioning on incompatible firmware.
|
||||
// TODO: Do we really need this?
|
||||
//
|
||||
SetProvisioningVariable (APPLE_FPF_PROVISIONED_VARIABLE_NAME, 1);
|
||||
Status = EFI_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
OcPerformProvisioning (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Checking PAVPC register...\n"));
|
||||
|
||||
UINT32 PAVPC = MmPci32 (0, SA_MC_BUS, 0, 0, R_SA_PAVPC);
|
||||
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Current PAVPC is %X\n", PAVPC));
|
||||
|
||||
if ((PAVPC & BIT2) == 0) {
|
||||
MmPci32 (0, SA_MC_BUS, 0, 0, R_SA_PAVPC) = (PAVPC & (~BIT2)) | BIT4;
|
||||
PAVPC = MmPci32 (0, SA_MC_BUS, 0, 0, R_SA_PAVPC);
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: New PAVPC is %X\n", PAVPC));
|
||||
}
|
||||
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Starting EPID provisioning\n"));
|
||||
|
||||
Status = OcPerformEpidProvisioning ();
|
||||
|
||||
DEBUG ((DEBUG_INFO, "OCPAVP: Done EPID provisioning - %r\n", Status));
|
||||
|
||||
#if 0
|
||||
DEBUG ((DEBUG_INFO, "OC: Starting FPF provisioning\n"));
|
||||
|
||||
Status = OcPerformFpfProvisioning ();
|
||||
|
||||
DEBUG ((DEBUG_INFO, "OC: Done FPF provisioning - %r\n", Status));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UefiMain (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
OcPerformProvisioning ();
|
||||
|
||||
gBS->Stall (SECONDS_TO_MICROSECONDS (3));
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
61
Application/PavpProvision/PavpProvision.inf
Normal file
61
Application/PavpProvision/PavpProvision.inf
Normal file
@ -0,0 +1,61 @@
|
||||
## @file
|
||||
# Provision EPID key.
|
||||
#
|
||||
# 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 = PavpProvision
|
||||
FILE_GUID = 8D4366DB-B5FC-40B7-924E-DEA24EBF7E1F
|
||||
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]
|
||||
PavpProvision.c
|
||||
PavpProvisionData.c
|
||||
|
||||
[Guids]
|
||||
gAppleEpidCertificateFileGuid
|
||||
gAppleEpidGroupPublicKeysFileGuid
|
||||
gMePavpProtocolGuid
|
||||
gMeFpfProtocolGuid
|
||||
|
||||
[Packages]
|
||||
EfiPkg/EfiPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
OcSupportPkg/OcSupportPkg.dec
|
||||
UefiCpuPkg/UefiCpuPkg.dec
|
||||
|
||||
[Protocols]
|
||||
gEfiPciRootBridgeIoProtocolGuid
|
||||
gEfiFirmwareVolumeProtocolGuid
|
||||
|
||||
[LibraryClasses]
|
||||
OcConsoleControlEntryModeLib
|
||||
OcHeciLib
|
||||
UefiApplicationEntryPoint
|
||||
UefiLib
|
||||
PcdLib
|
||||
IoLib
|
||||
29
Application/PavpProvision/PavpProvisionData.c
Normal file
29
Application/PavpProvision/PavpProvisionData.c
Normal file
@ -0,0 +1,29 @@
|
||||
/** @file
|
||||
Provision EPID data.
|
||||
|
||||
Copyright (c) 2019, 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.
|
||||
|
||||
**/
|
||||
|
||||
//
|
||||
// This needs to be dumped from some firmware.
|
||||
//
|
||||
|
||||
UINT8 gDefaultAppleEpidCertificate[] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
UINTN gDefaultAppleEpidCertificateSize = sizeof (gDefaultAppleEpidCertificate);
|
||||
|
||||
UINT8 gDefaultAppleGroupPublicKeys[] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
UINTN gDefaultAppleGroupPublicKeysSize = sizeof (gDefaultAppleGroupPublicKeys);
|
||||
101
Application/VerifyMsrE2/VerifyMsrE2.c
Normal file
101
Application/VerifyMsrE2/VerifyMsrE2.c
Normal file
@ -0,0 +1,101 @@
|
||||
/** @file
|
||||
Verify MSR 0xE2 status on all the processors.
|
||||
|
||||
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 <PiDxe.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/OcMiscLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/UefiApplicationEntryPoint.h>
|
||||
#include <Register/Msr.h>
|
||||
#include <Protocol/MpService.h>
|
||||
|
||||
STATIC EFI_MP_SERVICES_PROTOCOL *mMpServices;
|
||||
STATIC UINTN mHasLockedCores;
|
||||
STATIC UINTN mHasUnlockedCores;
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ReadMsrE2 (
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
UINTN ProcNum = 0;
|
||||
MSR_BROADWELL_PKG_CST_CONFIG_CONTROL_REGISTER Value;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = mMpServices->WhoAmI (mMpServices, &ProcNum);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
Print (L"Failed to detect CPU Number\n");
|
||||
}
|
||||
|
||||
Value.Uint64 = AsmReadMsr64 (MSR_BROADWELL_PKG_CST_CONFIG_CONTROL);
|
||||
|
||||
Print (L"CPU%02d has MSR 0xE2: 0x%016LX\n", ProcNum, Value.Uint64);
|
||||
|
||||
if (Value.Bits.CFGLock) {
|
||||
mHasLockedCores = 1;
|
||||
} else {
|
||||
mHasUnlockedCores = 1;
|
||||
}
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UefiMain (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
Print (L"Looking up EFI_MP_SERVICES_PROTOCOL...\n");
|
||||
|
||||
Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&mMpServices);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Print (L"Failed to find EFI_MP_SERVICES_PROTOCOL - %r\n", Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
Print (L"Checking MSR 0xE2 on all CPUs. Values must be SAME!!!\n");
|
||||
|
||||
ReadMsrE2 (NULL);
|
||||
|
||||
Print (L"Starting All APs to verify 0xE2 register...\n", Status);
|
||||
|
||||
Status = mMpServices->StartupAllAPs (mMpServices, ReadMsrE2, TRUE, NULL, 5000000, NULL, NULL);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Print (L"Failed to StartupAllAPs - %r\n", Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
Print (L"Done checking MSR 0xE2 register, compare the values printed!\n");
|
||||
|
||||
if (mHasLockedCores && mHasUnlockedCores) {
|
||||
Print (L"This firmware has BORKED MSR 0xE2 register!\n");
|
||||
Print (L"Some cores are locked, some are not!!!\n");
|
||||
} else if (mHasUnlockedCores) {
|
||||
Print (L"This firmware has UNLOCKED MSR 0xE2 register!\n");
|
||||
} else {
|
||||
Print (L"This firmware has LOCKED MSR 0xE2 register!\n");
|
||||
}
|
||||
|
||||
gBS->Stall (SECONDS_TO_MICROSECONDS (3));
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
51
Application/VerifyMsrE2/VerifyMsrE2.inf
Normal file
51
Application/VerifyMsrE2/VerifyMsrE2.inf
Normal file
@ -0,0 +1,51 @@
|
||||
## @file
|
||||
# Viery MSR 0xE2 status on all the processors.
|
||||
#
|
||||
# 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 = VerifyMsrE2
|
||||
FILE_GUID = 9031CCA3-EF7A-4D36-ADCA-F75802085D32
|
||||
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]
|
||||
VerifyMsrE2.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
OcSupportPkg/OcSupportPkg.dec
|
||||
UefiCpuPkg/UefiCpuPkg.dec
|
||||
|
||||
[Protocols]
|
||||
gEfiMpServiceProtocolGuid ## CONSUMES
|
||||
|
||||
[LibraryClasses]
|
||||
OcConsoleControlEntryModeLib
|
||||
UefiApplicationEntryPoint
|
||||
UefiLib
|
||||
PcdLib
|
||||
IoLib
|
||||
BIN
Debug/GdbSyms/Bin/X64_XCODE5/GdbSyms.dll
Normal file
BIN
Debug/GdbSyms/Bin/X64_XCODE5/GdbSyms.dll
Normal file
Binary file not shown.
79
Debug/GdbSyms/GdbSyms.c
Normal file
79
Debug/GdbSyms/GdbSyms.c
Normal file
@ -0,0 +1,79 @@
|
||||
/** @file
|
||||
|
||||
Bare-minimum GDB symbols needed for reloading symbols.
|
||||
|
||||
This is not a "driver" and should not be placed in a FD.
|
||||
|
||||
Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>
|
||||
|
||||
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 "PiDxe.h"
|
||||
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/UefiDriverEntryPoint.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/UefiRuntimeLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/DevicePathLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Guid/DebugImageInfoTable.h>
|
||||
|
||||
/**
|
||||
Main entry point.
|
||||
|
||||
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
||||
@param[in] SystemTable A pointer to the EFI System Table.
|
||||
|
||||
@retval EFI_SUCCESS Successfully initialized.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Initialize (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_SYSTEM_TABLE_POINTER ESTP;
|
||||
EFI_DEBUG_IMAGE_INFO_TABLE_HEADER EDIITH;
|
||||
EFI_IMAGE_DOS_HEADER EIDH;
|
||||
EFI_IMAGE_OPTIONAL_HEADER_UNION EIOHU;
|
||||
EFI_IMAGE_SECTION_HEADER EISH;
|
||||
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY EIDDE;
|
||||
EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY EIDCNE;
|
||||
EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY EIDCRE;
|
||||
EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY EIDCME;
|
||||
UINTN Dummy =
|
||||
(UINTN) &ESTP |
|
||||
(UINTN) &EDIITH |
|
||||
(UINTN) &EIDH |
|
||||
(UINTN) &EIOHU |
|
||||
(UINTN) &EISH |
|
||||
(UINTN) &EIDDE |
|
||||
(UINTN) &EIDCNE |
|
||||
(UINTN) &EIDCRE |
|
||||
(UINTN) &EIDCME |
|
||||
1
|
||||
;
|
||||
DEBUG ((DEBUG_VERBOSE, "%a: %llx\n", __FUNCTION__, &ESTP));
|
||||
DEBUG ((DEBUG_VERBOSE, "%a: %llx\n", __FUNCTION__, &EDIITH));
|
||||
DEBUG ((DEBUG_VERBOSE, "%a: %llx\n", __FUNCTION__, &EIDH));
|
||||
DEBUG ((DEBUG_VERBOSE, "%a: %llx\n", __FUNCTION__, &EIOHU));
|
||||
DEBUG ((DEBUG_VERBOSE, "%a: %llx\n", __FUNCTION__, &EISH));
|
||||
DEBUG ((DEBUG_VERBOSE, "%a: %llx\n", __FUNCTION__, &EIDDE));
|
||||
DEBUG ((DEBUG_VERBOSE, "%a: %llx\n", __FUNCTION__, &EIDCNE));
|
||||
DEBUG ((DEBUG_VERBOSE, "%a: %llx\n", __FUNCTION__, &EIDCRE));
|
||||
DEBUG ((DEBUG_VERBOSE, "%a: %llx\n", __FUNCTION__, &EIDCME));
|
||||
return !!Dummy & EFI_SUCCESS;
|
||||
}
|
||||
59
Debug/GdbSyms/GdbSyms.inf
Normal file
59
Debug/GdbSyms/GdbSyms.inf
Normal file
@ -0,0 +1,59 @@
|
||||
## @file
|
||||
#
|
||||
# Bare-minimum GDB symbols needed for reloading symbols.
|
||||
#
|
||||
# This is not a "driver" and should not be placed in a FD.
|
||||
#
|
||||
# Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>
|
||||
#
|
||||
# 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 = GdbSyms
|
||||
FILE_GUID = 22abcb60-fb40-42ac-b01f-3ab1fad9aad8
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
ENTRY_POINT = Initialize
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC ARM
|
||||
#
|
||||
|
||||
[Sources]
|
||||
GdbSyms.c
|
||||
|
||||
[Packages]
|
||||
OcSupportPkg/OcSupportPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
DxeServicesTableLib
|
||||
HobLib
|
||||
MemoryAllocationLib
|
||||
PcdLib
|
||||
UefiBootServicesTableLib
|
||||
UefiDriverEntryPoint
|
||||
UefiLib
|
||||
OcGuardLib
|
||||
OcTimerLib
|
||||
|
||||
[Guids]
|
||||
|
||||
[Protocols]
|
||||
|
||||
[Depex]
|
||||
TRUE
|
||||
88
Debug/README.md
Normal file
88
Debug/README.md
Normal file
@ -0,0 +1,88 @@
|
||||
UEFI Debugging with GDB
|
||||
=======================
|
||||
|
||||
These scripts provide support for easier UEFI code debugging on virtual machines like VMware Fusion
|
||||
or QEMU. The code is based on [Andrei Warkentin](https://github.com/andreiw)'s
|
||||
[DebugPkg](https://github.com/andreiw/andreiw-wip/tree/master/uefi/DebugPkg) with improvements
|
||||
in macOS support, pretty printing, and bug fixing.
|
||||
|
||||
The general approach is as follows:
|
||||
|
||||
1. Build GdbSyms binary with EDK II type info in DWARF
|
||||
1. Locate `EFI_SYSTEM_TABLE` in memory by its magic
|
||||
1. Locate `EFI_DEBUG_IMAGE_INFO_TABLE` by its GUID
|
||||
1. Map relocated images within GDB
|
||||
1. Provide handy functions and pretty printers
|
||||
|
||||
#### Preparing Source Code
|
||||
|
||||
By default EDK II optimises produced binaries, so to build a "real" debug binary one should target
|
||||
`NOOPT`. Do be aware that it strongly affects resulting binary size.
|
||||
|
||||
`GdbSyms.dll` is built as a part of OcSupportPkg, yet prebuilt binaries are also available:
|
||||
|
||||
- `GdbSyms/Bin/X64_XCODE5/GdbSyms.dll` is built with UDK2018 and XCODE5
|
||||
|
||||
To wait for debugger connection on startup `WaitForKeyPress` functions from `OcMiscLib.h` can be
|
||||
utilised. Do be aware that this function additionally calls `DebugBreak` function, which may
|
||||
be broken at during GDB init.
|
||||
|
||||
#### VMware Configuration
|
||||
|
||||
VMware Fusion contains a dedicated debugStub, which can be enabled by adding the following
|
||||
lines to .vmx file. Afterwards vmware-vmx will listen on TCP ports 8832 and 8864 (on the host)
|
||||
for 32-bit and 64-bit gdb connections respectively, similarly to QEMU:
|
||||
```
|
||||
debugStub.listen.guest32 = "TRUE"
|
||||
debugStub.listen.guest64 = "TRUE"
|
||||
```
|
||||
|
||||
In case the debugging session is remote the following lines should be appended:
|
||||
```
|
||||
debugStub.listen.guest32.remote = "TRUE"
|
||||
debugStub.listen.guest64.remote = "TRUE"
|
||||
```
|
||||
|
||||
To halt the virtual machine upon executing the first instruction the following line code be added.
|
||||
Note, that it does not seem to work on VMware Fusion 11 and results in freezes:
|
||||
```
|
||||
monitor.debugOnStartGuest32 = "TRUE"
|
||||
```
|
||||
|
||||
To force hardware breakpoints (instead of software INT 3 breakpoints) add the following line:
|
||||
```
|
||||
debugStub.hideBreakpoints = "TRUE"
|
||||
```
|
||||
|
||||
To stall during POST for 3 seconds add the following line. Pressing any key will boot into firmware
|
||||
settings:
|
||||
```
|
||||
bios.bootDelay = "3000"
|
||||
```
|
||||
|
||||
#### GDB Configuration
|
||||
|
||||
It is a good idea to use GDB Multiarch in case different debugging architectures are planned to be
|
||||
used. This can be done in several ways:
|
||||
|
||||
- https://www.gnu.org/software/gdb/ — from source
|
||||
- https://macports.org/ — via MacPorts (`sudo port install gdb +multiarch`)
|
||||
- Your preferred method here
|
||||
|
||||
Once GDB is installed the process is as simple as running the following set of commands:
|
||||
|
||||
```
|
||||
$ ggdb /opt/UDK/Build/OcSupportPkg/NOOPT_XCODE5/X64/OcSupportPkg/Debug/GdbSyms/GdbSyms/DEBUG/GdbSyms.dll.dSYM/Contents/Resources/DWARF/GdbSyms.dll
|
||||
|
||||
target remote localhost:8864
|
||||
source /opt/UDK/OcSupportPkg/Debug/Scripts/gdb_uefi.py
|
||||
set pagination off
|
||||
reload-uefi
|
||||
b DebugBreak
|
||||
```
|
||||
|
||||
#### References
|
||||
|
||||
1. https://communities.vmware.com/thread/390128
|
||||
1. https://wiki.osdev.org/VMware
|
||||
1. https://github.com/andreiw/andreiw-wip/tree/master/uefi/DebugPkg
|
||||
671
Debug/Scripts/gdb_uefi.py
Normal file
671
Debug/Scripts/gdb_uefi.py
Normal file
@ -0,0 +1,671 @@
|
||||
"""
|
||||
Allows loading TianoCore symbols into a GDB session attached to EFI
|
||||
Firmware.
|
||||
|
||||
This is how it works: build GdbSyms - it's a dummy binary that
|
||||
contains the relevant symbols needed to find and load image symbols.
|
||||
|
||||
$ gdb /path/to/GdbSyms.dll
|
||||
(gdb) target remote ....
|
||||
(gdb) source Scripts/gdb_uefi.py
|
||||
(gdb) reload-uefi -o /path/to/GdbSyms.dll
|
||||
|
||||
N.B: it was noticed that GDB for certain targets behaves strangely
|
||||
when run without any binary - like assuming a certain physical
|
||||
address space size and endianness. To avoid this madness and
|
||||
seing strange bugs, make sure to pass /path/to/GdbSyms.dll
|
||||
when starting gdb.
|
||||
|
||||
The -o option should be used if you've debugging EFI, where the PE
|
||||
images were converted from MACH-O or ELF binaries.
|
||||
|
||||
"""
|
||||
|
||||
import array
|
||||
import getopt
|
||||
import binascii
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
__license__ = "BSD"
|
||||
__version = "1.0.0"
|
||||
__maintainer__ = "Andrei Warkentin"
|
||||
__email__ = "andrey.warkentin@gmail.com"
|
||||
__status__ = "Works"
|
||||
|
||||
if sys.version_info > (3,):
|
||||
long = int
|
||||
|
||||
class UefiMisc():
|
||||
#
|
||||
# Returns string corresponding to type value in specified charset.
|
||||
#
|
||||
@classmethod
|
||||
def parse_string (cls, value, type, charset):
|
||||
index = 0
|
||||
data = array.array (type)
|
||||
while value[index] != 0:
|
||||
# TODO: add more ASCII symbols?
|
||||
v = value[index]
|
||||
if v == 0x0A: # \n
|
||||
data.append(0x5C)
|
||||
data.append(0x6E)
|
||||
elif v == 0x0D: # \r
|
||||
data.append(0x5C)
|
||||
data.append(0x72)
|
||||
elif v == 0x09: # \t
|
||||
data.append(0x5C)
|
||||
data.append(0x74)
|
||||
elif v == 0x22: # "
|
||||
data.append(0x5C)
|
||||
data.append(0x22)
|
||||
elif v == 0x5C: # \
|
||||
data.append(0x5C)
|
||||
data.append(0x5C)
|
||||
else:
|
||||
data.append (v)
|
||||
index = index + 1
|
||||
return data.tostring ().decode (charset)
|
||||
|
||||
#
|
||||
# Returns a UTF16 string corresponding to a (CHAR16 *) value in EFI.
|
||||
#
|
||||
@classmethod
|
||||
def parse_utf16 (cls, value):
|
||||
return UefiMisc.parse_string (value, 'H', 'utf-16')
|
||||
|
||||
#
|
||||
# Returns a UTF8 string corresponding to a (CHAR8 *) value in EFI.
|
||||
#
|
||||
@classmethod
|
||||
def parse_utf8 (cls, value):
|
||||
return UefiMisc.parse_string (value, 'B', 'utf-8')
|
||||
|
||||
#
|
||||
# Returns a printable EFI or RETURN status.
|
||||
#
|
||||
@classmethod
|
||||
def parse_status (cls, value, efi):
|
||||
suffix = ''
|
||||
err = 0
|
||||
val = long(value)
|
||||
if val & 0x80000000:
|
||||
err = val & ~0x80000000
|
||||
elif val & 0x8000000000000000:
|
||||
err = val & ~0x8000000000000000
|
||||
|
||||
if err != 0:
|
||||
# TODO: make this a collection...
|
||||
if err == 1:
|
||||
suffix = 'LOAD_ERROR'
|
||||
elif err == 2:
|
||||
suffix = 'INVALID_PARAMETER'
|
||||
elif err == 3:
|
||||
suffix = 'UNSUPPORTED'
|
||||
elif err == 4:
|
||||
suffix = 'BAD_BUFFER_SIZE'
|
||||
elif err == 5:
|
||||
suffix = 'BUFFER_TOO_SMALL'
|
||||
elif err == 6:
|
||||
suffix = 'NOT_READY'
|
||||
elif err == 7:
|
||||
suffix = 'DEVICE_ERROR'
|
||||
elif err == 8:
|
||||
suffix = 'WRITE_PROTECTED'
|
||||
elif err == 9:
|
||||
suffix = 'OUT_OF_RESOURCES'
|
||||
elif err == 10:
|
||||
suffix = 'VOLUME_CORRUPTED'
|
||||
elif err == 11:
|
||||
suffix = 'VOLUME_FULL'
|
||||
elif err == 12:
|
||||
suffix = 'NO_MEDIA'
|
||||
elif err == 13:
|
||||
suffix = 'MEDIA_CHANGED'
|
||||
elif err == 14:
|
||||
suffix = 'NOT_FOUND'
|
||||
elif err == 15:
|
||||
suffix = 'ACCESS_DENIED'
|
||||
elif err == 16:
|
||||
suffix = 'NO_RESPONSE'
|
||||
elif err == 17:
|
||||
suffix = 'NO_MAPPING'
|
||||
elif err == 18:
|
||||
suffix = 'TIMEOUT'
|
||||
elif err == 19:
|
||||
suffix = 'NOT_STARTED'
|
||||
elif err == 20:
|
||||
suffix = 'ALREADY_STARTED'
|
||||
elif err == 21:
|
||||
suffix = 'ABORTED'
|
||||
elif err == 22:
|
||||
suffix = 'ICMP_ERROR'
|
||||
elif err == 23:
|
||||
suffix = 'TFTP_ERROR'
|
||||
elif err == 24:
|
||||
suffix = 'PROTOCOL_ERROR'
|
||||
elif err == 25:
|
||||
suffix = 'INCOMPATIBLE_VERSION'
|
||||
elif err == 26:
|
||||
suffix = 'SECURITY_VIOLATION'
|
||||
elif err == 27:
|
||||
suffix = 'CRC_ERROR'
|
||||
elif err == 28:
|
||||
suffix = 'END_OF_MEDIA'
|
||||
elif err == 31:
|
||||
suffix = 'END_OF_FILE'
|
||||
elif err == 32:
|
||||
suffix = 'INVALID_LANGUAGE'
|
||||
elif err == 33:
|
||||
suffix = 'COMPROMISED_DATA'
|
||||
elif err == 35:
|
||||
suffix = 'HTTP_ERROR'
|
||||
elif efi and err == 100:
|
||||
suffix = 'NETWORK_UNREACHABLE'
|
||||
elif efi and err == 101:
|
||||
suffix = 'HOST_UNREACHABLE'
|
||||
elif efi and err == 102:
|
||||
suffix = 'PROTOCOL_UNREACHABLE'
|
||||
elif efi and err == 103:
|
||||
suffix = 'PORT_UNREACHABLE'
|
||||
elif efi and err == 104:
|
||||
suffix = 'CONNECTION_FIN'
|
||||
elif efi and err == 105:
|
||||
suffix = 'CONNECTION_RESET'
|
||||
elif efi and err == 106:
|
||||
suffix = 'CONNECTION_REFUSED'
|
||||
else:
|
||||
if val == 0:
|
||||
suffix = 'SUCCESS'
|
||||
elif val == 1:
|
||||
suffix = 'WARN_UNKNOWN_GLYPH'
|
||||
elif val == 2:
|
||||
suffix = 'WARN_DELETE_FAILURE'
|
||||
elif val == 3:
|
||||
suffix = 'WARN_WRITE_FAILURE'
|
||||
elif val == 4:
|
||||
suffix = 'WARN_BUFFER_TOO_SMALL'
|
||||
elif val == 5:
|
||||
suffix = 'WARN_STALE_DATA'
|
||||
elif val == 6:
|
||||
suffix = 'WARN_FILE_SYSTEM'
|
||||
if suffix != '':
|
||||
return ('EFI_' if efi else 'RETURN_') + suffix
|
||||
return hex(val)
|
||||
|
||||
#
|
||||
# Returns a UTF16 string corresponding to a (CHAR16 *) value in EFI.
|
||||
#
|
||||
@classmethod
|
||||
def parse_guid (cls, value):
|
||||
guid = "<%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X>" % (
|
||||
value['Data1'],
|
||||
value['Data2'],
|
||||
value['Data3'],
|
||||
value['Data4'][0],
|
||||
value['Data4'][1],
|
||||
value['Data4'][2],
|
||||
value['Data4'][3],
|
||||
value['Data4'][4],
|
||||
value['Data4'][5],
|
||||
value['Data4'][6],
|
||||
value['Data4'][7])
|
||||
return guid
|
||||
|
||||
class ReloadUefi (gdb.Command):
|
||||
"""Reload UEFI symbols"""
|
||||
|
||||
#
|
||||
# Various constants.
|
||||
#
|
||||
|
||||
EINVAL = 0xffffffff
|
||||
CV_NB10 = 0x3031424E
|
||||
CV_RSDS = 0x53445352
|
||||
CV_MTOC = 0x434F544D
|
||||
DOS_MAGIC = 0x5A4D
|
||||
PE32PLUS_MAGIC = 0x20b
|
||||
EST_SIGNATURE = 0x5453595320494249L
|
||||
DEBUG_GUID = [0x49152E77, 0x1ADA, 0x4764,
|
||||
[0xB7,0xA2,0x7A,0xFE,
|
||||
0xFE,0xD9,0x5E, 0x8B]]
|
||||
DEBUG_IS_UPDATING = 0x1
|
||||
|
||||
#
|
||||
# If the images were built as ELF/MACH-O and then converted to PE,
|
||||
# then the base address needs to be offset by PE headers.
|
||||
#
|
||||
|
||||
offset_by_headers = False
|
||||
|
||||
def __init__ (self):
|
||||
super (ReloadUefi, self).__init__ ("reload-uefi", gdb.COMMAND_OBSCURE)
|
||||
|
||||
#
|
||||
# Returns gdb.Type for a type.
|
||||
#
|
||||
|
||||
def type (self, typename):
|
||||
return gdb.lookup_type (typename)
|
||||
|
||||
#
|
||||
# Returns gdb.Type for a pointer to a type.
|
||||
#
|
||||
|
||||
def ptype (self, typename):
|
||||
return gdb.lookup_type (typename).pointer ()
|
||||
|
||||
#
|
||||
# Computes CRC32 on an array of data.
|
||||
#
|
||||
|
||||
def crc32 (self, data):
|
||||
return binascii.crc32 (data) & 0xFFFFFFFF
|
||||
|
||||
#
|
||||
# Sets a field in a struct to a value, i.e.
|
||||
# value->field_name = data.
|
||||
#
|
||||
# Newer Py bindings to Gdb provide access to the inferior
|
||||
# memory, but not all, so have to do it this awkward way.
|
||||
#
|
||||
|
||||
def set_field (self, value, field_name, data):
|
||||
gdb.execute ("set *(%s *) 0x%x = 0x%x" % \
|
||||
(str (value[field_name].type), \
|
||||
long (value[field_name].address), data))
|
||||
|
||||
#
|
||||
# Returns data backing a gdb.Value as an array.
|
||||
# Same comment as above regarding newer Py bindings...
|
||||
#
|
||||
|
||||
def value_data (self, value, bytes=0):
|
||||
value_address = gdb.Value (value.address)
|
||||
array_t = self.ptype ('UINT8')
|
||||
value_array = value_address.cast (array_t)
|
||||
if bytes == 0:
|
||||
bytes = value.type.sizeof
|
||||
data = array.array ('B')
|
||||
for i in range (0, bytes):
|
||||
data.append (value_array[i])
|
||||
return data
|
||||
|
||||
#
|
||||
# Locates the EFI_SYSTEM_TABLE as per UEFI spec 17.4.
|
||||
# Returns base address or -1.
|
||||
#
|
||||
|
||||
def search_est (self):
|
||||
address = 0
|
||||
estp_t = self.ptype ('EFI_SYSTEM_TABLE_POINTER')
|
||||
while True:
|
||||
try:
|
||||
estp = gdb.Value(address).cast(estp_t)
|
||||
if estp['Signature'] == self.EST_SIGNATURE:
|
||||
oldcrc = long(estp['Crc32'])
|
||||
self.set_field (estp, 'Crc32', 0)
|
||||
newcrc = self.crc32 (self.value_data (estp.dereference (), 0))
|
||||
self.set_field (estp, 'Crc32', long(oldcrc))
|
||||
if newcrc == oldcrc:
|
||||
return estp['EfiSystemTableBase']
|
||||
except gdb.MemoryError:
|
||||
pass
|
||||
|
||||
address = address + 4*1024*1024
|
||||
if long(address) == 0:
|
||||
return gdb.Value(self.EINVAL)
|
||||
|
||||
#
|
||||
# Searches for a vendor-specific configuration table (in EST),
|
||||
# given a vendor-specific table GUID. GUID is a list like -
|
||||
# [32-bit, 16-bit, 16-bit, [8 bytes]]
|
||||
#
|
||||
|
||||
def search_config (self, cfg_table, count, guid):
|
||||
index = 0
|
||||
while index != count:
|
||||
cfg_entry = cfg_table[index]['VendorGuid']
|
||||
if cfg_entry['Data1'] == guid[0] and \
|
||||
cfg_entry['Data2'] == guid[1] and \
|
||||
cfg_entry['Data3'] == guid[2] and \
|
||||
self.value_data (cfg_entry['Data4']).tolist () == guid[3]:
|
||||
return cfg_table[index]['VendorTable']
|
||||
index = index + 1
|
||||
return gdb.Value(self.EINVAL)
|
||||
|
||||
#
|
||||
# Returns offset of a field within structure. Useful
|
||||
# for getting container of a structure.
|
||||
#
|
||||
|
||||
def offsetof (self, typename, field):
|
||||
t = gdb.Value (0).cast (self.ptype (typename))
|
||||
return long(t[field].address)
|
||||
|
||||
#
|
||||
# Returns sizeof of a type.
|
||||
#
|
||||
|
||||
def sizeof (self, typename):
|
||||
return self.type (typename).sizeof
|
||||
|
||||
#
|
||||
# Returns the EFI_IMAGE_NT_HEADERS32 pointer, given
|
||||
# an ImageBase address as a gdb.Value.
|
||||
#
|
||||
|
||||
def pe_headers (self, imagebase):
|
||||
dosh_t = self.ptype ('EFI_IMAGE_DOS_HEADER')
|
||||
head_t = self.ptype ('EFI_IMAGE_OPTIONAL_HEADER_UNION')
|
||||
dosh = imagebase.cast (dosh_t)
|
||||
h_addr = imagebase
|
||||
if dosh['e_magic'] == self.DOS_MAGIC:
|
||||
h_addr = h_addr + dosh['e_lfanew']
|
||||
return gdb.Value(h_addr).cast (head_t)
|
||||
|
||||
def pe_sections (self, opt, file, imagebase):
|
||||
sect_t = self.ptype ('EFI_IMAGE_SECTION_HEADER')
|
||||
sections = (opt.address + 1).cast (sect_t)
|
||||
sects = {}
|
||||
for i in xrange (file['NumberOfSections']):
|
||||
name = UefiMisc.parse_utf8 (sections[i]['Name'])
|
||||
addr = long(sections[i]['VirtualAddress'])
|
||||
if name != '':
|
||||
sects[name] = addr
|
||||
return sects
|
||||
|
||||
# TODO: implement pe sections
|
||||
|
||||
#
|
||||
# Returns True if pe_headers refer to a PE32+ image.
|
||||
#
|
||||
|
||||
def pe_is_64 (self, pe_headers):
|
||||
if pe_headers['Pe32']['OptionalHeader']['Magic'] == self.PE32PLUS_MAGIC:
|
||||
return True
|
||||
return False
|
||||
|
||||
#
|
||||
# Returns the PE fileheader.
|
||||
#
|
||||
|
||||
def pe_file (self, pe):
|
||||
if self.pe_is_64 (pe):
|
||||
return pe['Pe32Plus']['FileHeader']
|
||||
else:
|
||||
return pe['Pe32']['FileHeader']
|
||||
|
||||
#
|
||||
# Returns the PE (not so) optional header.
|
||||
#
|
||||
|
||||
def pe_optional (self, pe):
|
||||
if self.pe_is_64 (pe):
|
||||
return pe['Pe32Plus']['OptionalHeader']
|
||||
else:
|
||||
return pe['Pe32']['OptionalHeader']
|
||||
|
||||
#
|
||||
# Returns the symbol file name for a PE image.
|
||||
#
|
||||
|
||||
def pe_parse_debug (self, pe):
|
||||
opt = self.pe_optional (pe)
|
||||
debug_dir_entry = opt['DataDirectory'][6]
|
||||
dep = debug_dir_entry['VirtualAddress'] + opt['ImageBase']
|
||||
dep = dep.cast (self.ptype ('EFI_IMAGE_DEBUG_DIRECTORY_ENTRY'))
|
||||
cvp = dep.dereference ()['RVA'] + opt['ImageBase']
|
||||
cvv = cvp.cast(self.ptype ('UINT32')).dereference ()
|
||||
if cvv == self.CV_NB10:
|
||||
return cvp + self.sizeof('EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY')
|
||||
elif cvv == self.CV_RSDS:
|
||||
return cvp + self.sizeof('EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY')
|
||||
elif cvv == self.CV_MTOC:
|
||||
return cvp + self.sizeof('EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY')
|
||||
return gdb.Value(self.EINVAL)
|
||||
|
||||
#
|
||||
# Prepares gdb symbol load command with proper section information.
|
||||
# Currently supports Mach-O and single-section files.
|
||||
#
|
||||
# TODO: Proper ELF support.
|
||||
#
|
||||
def get_sym_cmd (self, file, orgbase, sections, macho, fallack_base):
|
||||
cmd = 'add-symbol-file %s' % file
|
||||
|
||||
# Fallback case, no sections, just load .text.
|
||||
if not sections.get('.text') or not sections.get('.data'):
|
||||
cmd += ' 0x%x' % (fallack_base)
|
||||
return cmd
|
||||
|
||||
cmd += ' 0x%x' % (long(orgbase) + sections['.text'])
|
||||
|
||||
if not macho or not os.path.exists(file):
|
||||
# Another fallback, try to load data at least.
|
||||
cmd += ' -s .data 0x%x' % (long(orgbase) + sections['.data'])
|
||||
return cmd
|
||||
|
||||
# 1. Parse Mach-O.
|
||||
# FIXME: We should not rely on otool really.
|
||||
commands = subprocess.check_output(['otool', '-l', file])
|
||||
in_sect = False
|
||||
machsections = {}
|
||||
for line in commands.split('\n'):
|
||||
line = line.strip()
|
||||
if line.startswith('Section'):
|
||||
in_sect = True
|
||||
sectname = None
|
||||
segname = None
|
||||
elif in_sect:
|
||||
if line.startswith('sectname'):
|
||||
sectname = line.split()[1]
|
||||
elif line.startswith('segname'):
|
||||
segname = line.split()[1]
|
||||
elif line.startswith('addr'):
|
||||
machsections[segname + '.' + sectname] = long(line.split()[1], base=16)
|
||||
in_sect = False
|
||||
|
||||
# 2. Convert section names to gdb sections.
|
||||
mapping = {
|
||||
'__TEXT.__cstring': '.cstring',
|
||||
'__TEXT.__const': '.const',
|
||||
'__TEXT.__ustring': '__TEXT.__ustring',
|
||||
'__DATA.__const': '.const_data',
|
||||
'__DATA.__data': '.data',
|
||||
'__DATA.__bss': '.bss',
|
||||
'__DATA.__common': '__DATA.__common',
|
||||
# FIXME: These should not be loadable, but gdb still loads them :/
|
||||
# '__DWARF.__apple_names': '__DWARF.__apple_names',
|
||||
# '__DWARF.__apple_namespac': '__DWARF.__apple_namespac',
|
||||
# '__DWARF.__apple_types': '__DWARF.__apple_types',
|
||||
# '__DWARF.__apple_objc': '__DWARF.__apple_objc',
|
||||
}
|
||||
|
||||
# 3. Rebase.
|
||||
for entry in mapping:
|
||||
if machsections.get(entry):
|
||||
cmd += ' -s %s 0x%x' % (mapping[entry], long(orgbase) + machsections[entry])
|
||||
|
||||
return cmd
|
||||
|
||||
#
|
||||
# Parses an EFI_LOADED_IMAGE_PROTOCOL, figuring out the symbol file name.
|
||||
# This file name is then appended to list of loaded symbols.
|
||||
#
|
||||
# TODO: Support TE images.
|
||||
#
|
||||
|
||||
def parse_image (self, image, syms):
|
||||
orgbase = base = image['ImageBase']
|
||||
pe = self.pe_headers (base)
|
||||
opt = self.pe_optional (pe)
|
||||
file = self.pe_file (pe)
|
||||
sym_name = self.pe_parse_debug (pe)
|
||||
sections = self.pe_sections (opt, file, base)
|
||||
|
||||
# For ELF and Mach-O-derived images...
|
||||
if self.offset_by_headers:
|
||||
base = base + opt['SizeOfHeaders']
|
||||
if sym_name != self.EINVAL:
|
||||
sym_name = sym_name.cast (self.ptype('CHAR8')).string ()
|
||||
sym_name_dbg = re.sub(r"\.dll$", ".debug", sym_name)
|
||||
macho = False
|
||||
if os.path.isdir(sym_name + '.dSYM'):
|
||||
sym_name += '.dSYM/Contents/Resources/DWARF/' + os.path.basename(sym_name)
|
||||
macho = True
|
||||
elif sym_name_dbg != sym_name and os.path.exists(sym_name_dbg):
|
||||
# TODO: implement .elf handling.
|
||||
sym_name = sym_name_dbg
|
||||
syms.append (self.get_sym_cmd (sym_name, long(orgbase), sections, macho, long(base)))
|
||||
|
||||
#
|
||||
# Parses table EFI_DEBUG_IMAGE_INFO structures, builds
|
||||
# a list of add-symbol-file commands, and reloads debugger
|
||||
# symbols.
|
||||
#
|
||||
|
||||
def parse_edii (self, edii, count):
|
||||
index = 0
|
||||
syms = []
|
||||
while index != count:
|
||||
entry = edii[index]
|
||||
if entry['ImageInfoType'].dereference () == 1:
|
||||
entry = entry['NormalImage']
|
||||
self.parse_image(entry['LoadedImageProtocolInstance'], syms)
|
||||
else:
|
||||
print ("Skipping unknown EFI_DEBUG_IMAGE_INFO (Type 0x%x)" % \
|
||||
entry['ImageInfoType'].dereference ())
|
||||
index = index + 1
|
||||
gdb.execute ("symbol-file")
|
||||
print ("Loading new symbols...")
|
||||
for sym in syms:
|
||||
try:
|
||||
gdb.execute (sym)
|
||||
except (gdb.error) as err:
|
||||
print ('Failed: %s' % err)
|
||||
|
||||
#
|
||||
# Parses EFI_DEBUG_IMAGE_INFO_TABLE_HEADER, in order to load
|
||||
# image symbols.
|
||||
#
|
||||
|
||||
def parse_dh (self, dh):
|
||||
dh_t = self.ptype ('EFI_DEBUG_IMAGE_INFO_TABLE_HEADER')
|
||||
dh = dh.cast (dh_t)
|
||||
print ("DebugImageInfoTable @ 0x%x, 0x%x entries" % \
|
||||
(long (dh['EfiDebugImageInfoTable']), dh['TableSize']))
|
||||
if dh['UpdateStatus'] & self.DEBUG_IS_UPDATING:
|
||||
print ("EfiDebugImageInfoTable update in progress, retry later")
|
||||
return
|
||||
self.parse_edii (dh['EfiDebugImageInfoTable'], dh['TableSize'])
|
||||
|
||||
#
|
||||
# Parses EFI_SYSTEM_TABLE, in order to load image symbols.
|
||||
#
|
||||
|
||||
def parse_est (self, est):
|
||||
est_t = self.ptype ('EFI_SYSTEM_TABLE')
|
||||
est = est.cast (est_t)
|
||||
print ("Connected to %s (Rev. 0x%x)" % \
|
||||
(UefiMisc.parse_utf16 (est['FirmwareVendor']), \
|
||||
long (est['FirmwareRevision'])))
|
||||
print ("ConfigurationTable @ 0x%x, 0x%x entries" % \
|
||||
(long (est['ConfigurationTable']), est['NumberOfTableEntries']))
|
||||
|
||||
dh = self.search_config(est['ConfigurationTable'],
|
||||
est['NumberOfTableEntries'], self.DEBUG_GUID)
|
||||
if dh == self.EINVAL:
|
||||
print ("No EFI_DEBUG_IMAGE_INFO_TABLE_HEADER")
|
||||
return
|
||||
self.parse_dh (dh)
|
||||
|
||||
#
|
||||
# Usage information.
|
||||
#
|
||||
|
||||
def usage (self):
|
||||
print ("Usage: reload-uefi [-o] [/path/to/GdbSyms.dll]")
|
||||
|
||||
#
|
||||
# Handler for reload-uefi.
|
||||
#
|
||||
|
||||
def invoke (self, arg, from_tty):
|
||||
args = arg.split(' ')
|
||||
try:
|
||||
opts, args = getopt.getopt(args, "o", ["offset-by-headers"])
|
||||
except (getopt.GetoptError) as err:
|
||||
self.usage ()
|
||||
return
|
||||
for opt, arg in opts:
|
||||
if opt == "-o":
|
||||
self.offset_by_headers = True
|
||||
|
||||
if len(args) >= 1 and args[0] != '':
|
||||
gdb.execute ("symbol-file")
|
||||
gdb.execute ("symbol-file %s" % args[0])
|
||||
else:
|
||||
# FIXME: gdb.objfiles () loses files after symbol-file execution,
|
||||
# so we have to extract GdbSymbs.dll manually.
|
||||
lines = gdb.execute ("info files", to_string=True).split('\n')
|
||||
for line in lines:
|
||||
m = re.search("`([^']+)'", line)
|
||||
if m:
|
||||
gdb.execute ("symbol-file")
|
||||
gdb.execute ("symbol-file %s" % m.group(1))
|
||||
break
|
||||
|
||||
est = self.search_est ()
|
||||
if est == self.EINVAL:
|
||||
print ("No EFI_SYSTEM_TABLE...")
|
||||
return
|
||||
|
||||
print ("EFI_SYSTEM_TABLE @ 0x%x" % est)
|
||||
self.parse_est (est)
|
||||
|
||||
class UefiStringPrinter:
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
def to_string (self):
|
||||
if not self.val:
|
||||
return "NULL"
|
||||
return 'L"' + UefiMisc.parse_utf16(self.val) + '"'
|
||||
|
||||
class UefiEfiStatusPrinter:
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
def to_string (self):
|
||||
return UefiMisc.parse_status(self.val, True)
|
||||
|
||||
class UefiReturnStatusPrinter:
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
def to_string (self):
|
||||
return UefiMisc.parse_status(self.val, False)
|
||||
|
||||
class UefiGuidPrinter:
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
def to_string (self):
|
||||
return UefiMisc.parse_guid(self.val)
|
||||
|
||||
def lookup_uefi_type (val):
|
||||
if str(val.type) == 'const CHAR16 *' or str(val.type) == 'CHAR16 *':
|
||||
return UefiStringPrinter(val)
|
||||
elif str(val.type) == 'EFI_STATUS':
|
||||
return UefiEfiStatusPrinter(val)
|
||||
elif str(val.type) == 'RETURN_STATUS':
|
||||
return UefiReturnStatusPrinter(val)
|
||||
elif str(val.type) == 'GUID' or str(val.type) == 'EFI_GUID':
|
||||
return UefiGuidPrinter(val)
|
||||
return None
|
||||
|
||||
ReloadUefi ()
|
||||
gdb.pretty_printers.append (lookup_uefi_type)
|
||||
28
Debug/macgdb.tool
Executable file
28
Debug/macgdb.tool
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
RUNDIR=$(dirname "$0")
|
||||
pushd "$RUNDIR" >/dev/null
|
||||
RUNDIR=$(pwd)
|
||||
popd >/dev/null
|
||||
|
||||
cd "$RUNDIR"
|
||||
|
||||
if [ "$GDB" = "" ]; then
|
||||
GDB=$(which ggdb)
|
||||
fi
|
||||
|
||||
if [ "$GDB" = "" ]; then
|
||||
GDB=$(which gdb)
|
||||
fi
|
||||
|
||||
if [ "$GDB" = "" ]; then
|
||||
echo "Failed to find GDB"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
"$GDB" -ex "target remote localhost:8864" \
|
||||
-ex "source Scripts/gdb_uefi.py" \
|
||||
-ex "set pagination off" \
|
||||
-ex "reload-uefi" \
|
||||
-ex "b DebugBreak" \
|
||||
GdbSyms/Bin/X64_XCODE5/GdbSyms.dll
|
||||
55
Include/Guid/MicrosoftVariable.h
Normal file
55
Include/Guid/MicrosoftVariable.h
Normal file
@ -0,0 +1,55 @@
|
||||
/** @file
|
||||
Declare the GUID that is expected:
|
||||
|
||||
- as EFI_SIGNATURE_DATA.SignatureOwner GUID in association with X509 and
|
||||
RSA2048 Secure Boot certificates issued by/for Microsoft,
|
||||
|
||||
- as UEFI variable vendor GUID in association with (unspecified)
|
||||
Microsoft-owned variables.
|
||||
|
||||
Copyright (C) 2014-2019, Red Hat, Inc.
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
@par Specification Reference:
|
||||
- MSDN: System.Fundamentals.Firmware at
|
||||
<https://msdn.microsoft.com/en-us/ie/dn932805(v=vs.94)>.
|
||||
**/
|
||||
|
||||
#ifndef MICROSOFT_VARIABLE_H
|
||||
#define MICROSOFT_VARIABLE_H
|
||||
|
||||
#include <Uefi/UefiBaseType.h>
|
||||
|
||||
//
|
||||
// The following test cases of the Secure Boot Logo Test in the Microsoft
|
||||
// Hardware Certification Kit:
|
||||
//
|
||||
// - Microsoft.UefiSecureBootLogo.Tests.OutOfBoxVerifyMicrosoftKEKpresent
|
||||
// - Microsoft.UefiSecureBootLogo.Tests.OutOfBoxConfirmMicrosoftSignatureInDB
|
||||
//
|
||||
// expect the EFI_SIGNATURE_DATA.SignatureOwner GUID to be
|
||||
// 77FA9ABD-0359-4D32-BD60-28F4E78F784B, when the
|
||||
// EFI_SIGNATURE_DATA.SignatureData field carries any of the following X509
|
||||
// certificates:
|
||||
//
|
||||
// - "Microsoft Corporation KEK CA 2011" (in KEK)
|
||||
// - "Microsoft Windows Production PCA 2011" (in db)
|
||||
// - "Microsoft Corporation UEFI CA 2011" (in db)
|
||||
//
|
||||
// This is despite the fact that the UEFI specification requires
|
||||
// EFI_SIGNATURE_DATA.SignatureOwner to reflect the agent (i.e., OS,
|
||||
// application or driver) that enrolled and therefore owns
|
||||
// EFI_SIGNATURE_DATA.SignatureData, and not the organization that issued
|
||||
// EFI_SIGNATURE_DATA.SignatureData.
|
||||
//
|
||||
#define MICROSOFT_VENDOR_GUID \
|
||||
{ 0x77fa9abd, \
|
||||
0x0359, \
|
||||
0x4d32, \
|
||||
{ 0xbd, 0x60, 0x28, 0xf4, 0xe7, 0x8f, 0x78, 0x4b }, \
|
||||
}
|
||||
|
||||
extern EFI_GUID gMicrosoftVariableGuid;
|
||||
|
||||
#endif /* MICROSOFT_VARIABLE_H */
|
||||
112
Include/Guid/OcVariables.h
Normal file
112
Include/Guid/OcVariables.h
Normal file
@ -0,0 +1,112 @@
|
||||
/** @file
|
||||
Lilu & OpenCore specific GUIDs for UEFI Variable Storage, version 1.0.
|
||||
|
||||
Copyright (c) 2019, 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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_VARIABLES_H
|
||||
#define OC_VARIABLES_H
|
||||
|
||||
//
|
||||
// Variable used for OpenCore log storage (if enabled).
|
||||
//
|
||||
#define OC_LOG_VARIABLE_NAME L"boot-log"
|
||||
|
||||
//
|
||||
// Variable used for OpenCore boot path (if enabled).
|
||||
//
|
||||
#define OC_LOG_VARIABLE_PATH L"boot-path"
|
||||
|
||||
//
|
||||
// Variable used for OpenCore request to redirect NVRAM Boot variable write.
|
||||
// Boot Services only.
|
||||
// See: https://github.com/acidanthera/bugtracker/issues/308.
|
||||
//
|
||||
#define OC_BOOT_REDIRECT_VARIABLE_NAME L"boot-redirect"
|
||||
|
||||
//
|
||||
// Variable used for OpenCore request to fallback NVRAM Boot variable write.
|
||||
// Serves for resolving issues with borked ASUS APTIO V BIOSes.
|
||||
// Boot Services only.
|
||||
//
|
||||
#define OC_BOOT_FALLBACK_VARIABLE_NAME L"boot-fallback"
|
||||
|
||||
//
|
||||
// Variable used for exposing OpenCore Security -> LoadPolicy.
|
||||
// Boot Services only.
|
||||
//
|
||||
#define OC_LOAD_POLICY_VARIABLE_NAME L"load-policy"
|
||||
|
||||
//
|
||||
// Variable used for exposing OpenCore Security -> ScanPolicy.
|
||||
// Boot Services only.
|
||||
//
|
||||
#define OC_SCAN_POLICY_VARIABLE_NAME L"scan-policy"
|
||||
|
||||
//
|
||||
// Variable used to report OpenCore version in the following format:
|
||||
// REL-001-2019-01-01. This follows versioning style of Lilu and plugins.
|
||||
//
|
||||
#define OC_VERSION_VARIABLE_NAME L"opencore-version"
|
||||
|
||||
//
|
||||
// Variable used to report OEM product from SMBIOS Type1 ProductName.
|
||||
//
|
||||
#define OC_OEM_PRODUCT_VARIABLE_NAME L"oem-product"
|
||||
|
||||
//
|
||||
// Variable used to report OEM board vendor from SMBIOS Type2 Manufacturer.
|
||||
//
|
||||
#define OC_OEM_VENDOR_VARIABLE_NAME L"oem-vendor"
|
||||
|
||||
//
|
||||
// Variable used to report OEM board vendor from SMBIOS Type2 ProductName.
|
||||
//
|
||||
#define OC_OEM_BOARD_VARIABLE_NAME L"oem-board"
|
||||
|
||||
//
|
||||
// Variable used to share CPU frequency calculated from ACPI between the drivers.
|
||||
//
|
||||
#define OC_ACPI_CPU_FREQUENCY_VARIABLE_NAME L"acpi-cpu-frequency"
|
||||
|
||||
//
|
||||
// 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102
|
||||
// This GUID is specifically used for normal variable access by Lilu kernel extension and its plugins.
|
||||
//
|
||||
#define OC_VENDOR_VARIABLE_GUID \
|
||||
{ 0x4D1FDA02, 0x38C7, 0x4A6A, { 0x9C, 0xC6, 0x4B, 0xCC, 0xA8, 0xB3, 0x01, 0x02 } }
|
||||
|
||||
//
|
||||
// E09B9297-7928-4440-9AAB-D1F8536FBF0A
|
||||
// This GUID is specifically used for reading variables by Lilu kernel extension and its plugins.
|
||||
// Any writes to this GUID should be prohibited via EFI_RUNTIME_SERVICES after EXIT_BOOT_SERVICES.
|
||||
// The expected return code on variable write is EFI_SECURITY_VIOLATION.
|
||||
//
|
||||
#define OC_READ_ONLY_VARIABLE_GUID \
|
||||
{ 0xE09B9297, 0x7928, 0x4440, { 0x9A, 0xAB, 0xD1, 0xF8, 0x53, 0x6F, 0xBF, 0x0A } }
|
||||
|
||||
//
|
||||
// F0B9AF8F-2222-4840-8A37-ECF7CC8C12E1
|
||||
// This GUID is specifically used for reading variables by Lilu and plugins.
|
||||
// Any reads from this GUID should be prohibited via EFI_RUNTIME_SERVICES after EXIT_BOOT_SERVICES.
|
||||
// The expected return code on variable read is EFI_SECURITY_VIOLATION.
|
||||
//
|
||||
#define OC_WRITE_ONLY_VARIABLE_GUID \
|
||||
{ 0xF0B9AF8F, 0x2222, 0x4840, { 0x8A, 0x37, 0xEC, 0xF7, 0xCC, 0x8C, 0x12, 0xE1 } }
|
||||
|
||||
//
|
||||
// External global variables with GUID values.
|
||||
//
|
||||
extern EFI_GUID gOcVendorVariableGuid;
|
||||
extern EFI_GUID gOcReadOnlyVariableGuid;
|
||||
extern EFI_GUID gOcWriteOnlyVariableGuid;
|
||||
|
||||
#endif // OC_VARIABLES_H
|
||||
218
Include/IndustryStandard/CpuId.h
Executable file
218
Include/IndustryStandard/CpuId.h
Executable file
@ -0,0 +1,218 @@
|
||||
/** @file
|
||||
Copyright (C) 2016, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef CPUID_H
|
||||
#define CPUID_H
|
||||
|
||||
#include <Register/Cpuid.h>
|
||||
|
||||
#define CPUID_L2_CACHE_FEATURE 0x80000006
|
||||
|
||||
// Feature Flag Values Reported in the EDX Register
|
||||
|
||||
#define CPUID_FEATURE_FPU BIT0 ///< Floating point unit on-chip
|
||||
#define CPUID_FEATURE_VME BIT1 ///< Virtual Mode Extension
|
||||
#define CPUID_FEATURE_DE BIT2 ///< Debugging Extension
|
||||
#define CPUID_FEATURE_PSE BIT3 ///< Page Size Extension
|
||||
#define CPUID_FEATURE_TSC BIT4 ///< Time Stamp Counter
|
||||
#define CPUID_FEATURE_MSR BIT5 ///< Model Specific Registers
|
||||
#define CPUID_FEATURE_PAE BIT6 ///< Physical Address Extension
|
||||
#define CPUID_FEATURE_MCE BIT7 ///< Machine Check Exception
|
||||
#define CPUID_FEATURE_CX8 BIT8 ///< CMPXCHG8B
|
||||
#define CPUID_FEATURE_APIC BIT9 ///< On-chip APIC
|
||||
#define CPUID_FEATURE_SEP BIT11 ///< Fast System Call
|
||||
#define CPUID_FEATURE_MTRR BIT12 ///< Memory Type Range Register
|
||||
#define CPUID_FEATURE_PGE BIT13 ///< Page Global Enable
|
||||
#define CPUID_FEATURE_MCA BIT14 ///< Machine Check Architecture
|
||||
#define CPUID_FEATURE_CMOV BIT15 ///< Conditional Move Instruction
|
||||
#define CPUID_FEATURE_PAT BIT16 ///< Page Attribute Table
|
||||
#define CPUID_FEATURE_PSE36 BIT17 ///< 36-bit Page Size Extension
|
||||
#define CPUID_FEATURE_PSN BIT18 ///< Processor Serial Number
|
||||
#define CPUID_FEATURE_CLFSH BIT19 ///< CLFLUSH Instruction Supported
|
||||
#define CPUID_FEATURE_RESV20 BIT20 ///< Reserved
|
||||
#define CPUID_FEATURE_DS BIT21 ///< Debug Store
|
||||
#define CPUID_FEATURE_ACPI BIT22 ///< Thermal Monitor and Clock Control
|
||||
#define CPUID_FEATURE_MMX BIT23 ///< MMX Supported
|
||||
#define CPUID_FEATURE_FXSR BIT24 ///< Fast Floating Point Save/Restore
|
||||
#define CPUID_FEATURE_SSE BIT25 ///< Streaming SIMD Extensions
|
||||
#define CPUID_FEATURE_SSE2 BIT26 ///< Streaming SIMD Extensions 2
|
||||
#define CPUID_FEATURE_SS BIT27 ///< Self-Snoop
|
||||
#define CPUID_FEATURE_HTT BIT28 ///< Hyper-Threading Technology
|
||||
#define CPUID_FEATURE_TM BIT29 ///< Thermal Monitor (TM1)
|
||||
#define CPUID_FEATURE_IA64 BIT30 ///< Itanium Family Emulating IA-32
|
||||
#define CPUID_FEATURE_PBE BIT31 ///< Pending Break Enable
|
||||
|
||||
// Feature Flag Values Reported in the ECX Register
|
||||
|
||||
#define CPUID_FEATURE_SSE3 BIT32 ///< Streaming SIMD extensions 3
|
||||
#define CPUID_FEATURE_PCLMULQDQ BIT33 ///< PCLMULQDQ Instruction
|
||||
#define CPUID_FEATURE_DTES64 BIT34 ///< 64-Bit Debug Store
|
||||
#define CPUID_FEATURE_MONITOR BIT35 ///< MONITOR/MWAIT
|
||||
#define CPUID_FEATURE_DSCPL BIT36 ///< CPL Qualified Debug Store
|
||||
#define CPUID_FEATURE_VMX BIT37 ///< Virtual Machine Extensions (VMX)
|
||||
#define CPUID_FEATURE_SMX BIT38 ///< Safer Mode Extensions (SMX)
|
||||
#define CPUID_FEATURE_EST BIT39 ///< Enhanced Intel SpeedStep (GV3)
|
||||
#define CPUID_FEATURE_TM2 BIT40 ///< Thermal Monitor 2
|
||||
#define CPUID_FEATURE_SSSE3 BIT41 ///< Supplemental SSE3 Instructions
|
||||
#define CPUID_FEATURE_CID BIT42 ///< L1 Context ID
|
||||
#define CPUID_FEATURE_SEGLIM64 BIT43 ///< 64-bit segment limit checking
|
||||
#define CPUID_FEATURE_RESVH12 BIT44 ///< Reserved
|
||||
#define CPUID_FEATURE_CX16 BIT45 ///< CMPXCHG16B Instruction
|
||||
#define CPUID_FEATURE_xTPR BIT46 ///< Task Priority Update Control
|
||||
#define CPUID_FEATURE_PDCM BIT47 ///< Perfmon/Debug Capability MSR
|
||||
#define CPUID_FEATURE_RESVH16 BIT48 ///< Reserved
|
||||
#define CPUID_FEATURE_PCID BIT49 ///< ASID-PCID support
|
||||
#define CPUID_FEATURE_DCA BIT50 ///< Direct Cache Access
|
||||
#define CPUID_FEATURE_SSE4_1 BIT51 ///< Streaming SIMD Extensions 4.1
|
||||
#define CPUID_FEATURE_SSE4_2 BIT52 ///< Streaming SIMD Extensions 4.1
|
||||
#define CPUID_FEATURE_xAPIC BIT53 ///< Extended xAPIC Support
|
||||
#define CPUID_FEATURE_MOVBE BIT54 ///< MOVBE Instruction
|
||||
#define CPUID_FEATURE_POPCNT BIT55 ///< POPCNT Instruction
|
||||
#define CPUID_FEATURE_TSCTMR BIT56 ///< TSC deadline timer
|
||||
#define CPUID_FEATURE_AES BIT57 ///< AES instructions
|
||||
#define CPUID_FEATURE_XSAVE BIT58 ///< XSAVE/XSTOR States
|
||||
#define CPUID_FEATURE_OSXSAVE BIT59 ///< OS Has Enabled XSETBV/XGETBV
|
||||
#define CPUID_FEATURE_AVX1_0 BIT60 ///< AVX 1.0 instructions
|
||||
#define CPUID_FEATURE_RDRAND BIT61 ///< RDRAND instruction
|
||||
#define CPUID_FEATURE_F16C BIT62 ///< Float16 convert instructions
|
||||
#define CPUID_FEATURE_VMM BIT63 ///< VMM (Hypervisor) present
|
||||
|
||||
// The CPUID_EXTFEATURE_XXX values define 64-bit values
|
||||
// returned in %ecx:%edx to a CPUID request with %eax of 0x80000001:
|
||||
|
||||
#define CPUID_EXTFEATURE_SYSCALL BIT11 ///< SYSCALL/sysret
|
||||
|
||||
#define CPUID_EXTFEATURE_XD BIT20 ///< eXecute Disable
|
||||
#define CPUID_EXTFEATURE_1GBPAGE BIT21 ///< 1GB pages
|
||||
|
||||
#define CPUID_EXTFEATURE_RDTSCP BIT27 ///< RDTSCP
|
||||
|
||||
#define CPUID_EXTFEATURE_EM64T BIT29 ///< Extended Mem 64 Technology
|
||||
|
||||
#define CPUID_EXTFEATURE_LAHF BIT32 ///< LAFH/SAHF instructions
|
||||
|
||||
|
||||
// The CPUID_EXTFEATURE_XXX values define 64-bit values
|
||||
// returned in %ecx:%edx to a CPUID request with %eax of 0x80000007:
|
||||
|
||||
#define CPUID_EXTFEATURE_TSCI BIT8 ///< TSC Invariant
|
||||
|
||||
// When the EAX register contains a value of 2, the CPUID instruction loads
|
||||
// the EAX, EBX, ECX, and EDX registers with descriptors that indicate the
|
||||
// processor's cache and TLB characteristics.
|
||||
|
||||
// CPUID_CACHE_SIZE
|
||||
/// Number of 8-bit descriptor values
|
||||
#define CPUID_CACHE_SIZE 16
|
||||
|
||||
enum {
|
||||
CpuIdCacheNull = 0x00, ///< NULL
|
||||
CpuIdCacheItlb4K_32_4 = 0x01, ///< Inst TLB: 4K pages, 32 ents, 4-way
|
||||
CpuIdCacheItlb4M_2 = 0x02, ///< Inst TLB: 4M pages, 2 ents
|
||||
CpuIdCacheDtlb4K_64_4 = 0x03, ///< Data TLB: 4K pages, 64 ents, 4-way
|
||||
CpuIdCacheDtlb4M_8_4 = 0x04, ///< Data TLB: 4M pages, 8 ents, 4-way
|
||||
CpuIdCacheDtlb4M_32_4 = 0x05, ///< Data TLB: 4M pages, 32 ents, 4-way
|
||||
CpuIdCacheL1I_8K = 0x06, ///< Icache: 8K
|
||||
CpuIdCacheL1I_16K = 0x08, ///< Icache: 16K
|
||||
CpuIdCacheL1I_32K = 0x09, ///< Icache: 32K, 4-way, 64 bytes
|
||||
CpuIdCacheL1D_8K = 0x0A, ///< Dcache: 8K
|
||||
CpuIdCacheL1D_16K = 0x0C, ///< Dcache: 16K
|
||||
CpuIdCacheL1D_16K_4_32 = 0x0D, ///< Dcache: 16K, 4-way, 64 byte, ECC
|
||||
CpuIdCacheL2_256K_8_64 = 0x21, ///< L2: 256K, 8-way, 64 bytes
|
||||
CpuIdCacheL3_512K = 0x22, ///< L3: 512K
|
||||
CpuIdCacheL3_1M = 0x23, ///< L3: 1M
|
||||
CpuIdCacheL3_2M = 0x25, ///< L3: 2M
|
||||
CpuIdCacheL3_4M = 0x29, ///< L3: 4M
|
||||
CpuIdCacheL1D_32K_8 = 0x2C, ///< Dcache: 32K, 8-way, 64 byte
|
||||
CpuIdCacheL1I_32K_8 = 0x30, ///< Icache: 32K, 8-way
|
||||
CpuIdCacheL2_128K_S4 = 0x39, ///< L2: 128K, 4-way, sectored, 64B
|
||||
CpuIdCacheL2_192K_S6 = 0x3A, ///< L2: 192K, 6-way, sectored, 64B
|
||||
CpuIdCacheL2_128K_S2 = 0x3B, ///< L2: 128K, 2-way, sectored, 64B
|
||||
CpuIdCacheL2_256K_S4 = 0x3C, ///< L2: 256K, 4-way, sectored, 64B
|
||||
CpuIdCacheL2_384K_S6 = 0x3D, ///< L2: 384K, 6-way, sectored, 64B
|
||||
CpuIdCacheL2_512K_S4 = 0x3E, ///< L2: 512K, 4-way, sectored, 64B
|
||||
CpuIdCacheNoCache = 0x40, ///< No 2nd level or 3rd-level cache
|
||||
CpuIdCacheL2_128K = 0x41, ///< L2: 128K
|
||||
CpuIdCacheL2_256K = 0x42, ///< L2: 256K
|
||||
CpuIdCacheL2_512K = 0x43, ///< L2: 512K
|
||||
CpuIdCacheL2_1M_4 = 0x44, ///< L2: 1M, 4-way
|
||||
CpuIdCacheL2_2M_4 = 0x45, ///< L2: 2M, 4-way
|
||||
CpuIdCacheL3_4M_4_64 = 0x46, ///< L3: 4M, 4-way, 64 bytes
|
||||
CpuIdCacheL3_8M_8_64 = 0x47, ///< L3: 8M, 8-way, 64 bytes*/
|
||||
CpuIdCacheL2_3M_12_64 = 0x48, ///< L3: 3M, 8-way, 64 bytes*/
|
||||
CpuIdCacheL2_4M_16_64 = 0x49, ///< L2: 4M, 16-way, 64 bytes
|
||||
CpuIdCacheL2_6M_12_64 = 0x4A, ///< L2: 6M, 12-way, 64 bytes
|
||||
CpuIdCacheL2_8M_16_64 = 0x4B, ///< L2: 8M, 16-way, 64 bytes
|
||||
CpuIdCacheL2_12M_12_64 = 0x4C, ///< L2: 12M, 12-way, 64 bytes
|
||||
CpuIdCacheL2_16M_16_64 = 0x4D, ///< L2: 16M, 16-way, 64 bytes
|
||||
CpuIdCacheL2_6M_24_64 = 0x4E, ///< L2: 6M, 24-way, 64 bytes
|
||||
CpuIdCacheItlb64 = 0x50, ///< Inst TLB: 64 entries
|
||||
CpuIdCacheItlb128 = 0x51, ///< Inst TLB: 128 entries
|
||||
CpuIdCacheItlb256 = 0x52, ///< Inst TLB: 256 entries
|
||||
CpuIdCacheItlb4M2M_7 = 0x55, ///< Inst TLB: 4M/2M, 7 entries
|
||||
CpuIdCacheDtlb4M_16_4 = 0x56, ///< Data TLB: 4M, 16 entries, 4-way
|
||||
CpuIdCacheDtlb4K_16_4 = 0x57, ///< Data TLB: 4K, 16 entries, 4-way
|
||||
CpuIdCacheDtlb4M2M_32_4 = 0x5A, ///< Data TLB: 4M/2M, 32 entries
|
||||
CpuIdCacheDtlb64 = 0x5B, ///< Data TLB: 64 entries
|
||||
CpuIdCacheDtlb128 = 0x5C, ///< Data TLB: 128 entries
|
||||
CpuIdCacheDtlb256 = 0x5D, ///< Data TLB: 256 entries
|
||||
CpuIdCacheL1D_16K_8_64 = 0x60, ///< Data cache: 16K, 8-way, 64 bytes
|
||||
CpuIdCacheL1D_8K_4_64 = 0x66, ///< Data cache: 8K, 4-way, 64 bytes
|
||||
CpuIdCacheL1D_16K_4_64 = 0x67, ///< Data cache: 16K, 4-way, 64 bytes
|
||||
CpuIdCacheL1D_32K_4_64 = 0x68, ///< Data cache: 32K, 4-way, 64 bytes
|
||||
CpuIdCacheTRACE_12K_8 = 0x70, ///< Trace cache 12K-uop, 8-way
|
||||
CpuIdCacheTRACE_16K_8 = 0x71, ///< Trace cache 16K-uop, 8-way
|
||||
CpuIdCacheTRACE_32K_8 = 0x72, ///< Trace cache 32K-uop, 8-way
|
||||
CpuIdCacheTRACE_64K_8 = 0x73, ///< Trace cache 64K-uop, 8-way
|
||||
CpuIdCacheL2_1M_4_64 = 0x78, ///< L2: 1M, 4-way, 64 bytes
|
||||
CpuIdCacheL2_128K_8_64_2 = 0x79, ///< L2: 128K, 8-way, 64b, 2 lines/sec
|
||||
CpuIdCacheL2_256K_8_64_2 = 0x7A, ///< L2: 256K, 8-way, 64b, 2 lines/sec
|
||||
CpuIdCacheL2_512K_8_64_2 = 0x7B, ///< L2: 512K, 8-way, 64b, 2 lines/sec
|
||||
CpuIdCacheL2_1M_8_64_2 = 0x7C, ///< L2: 1M, 8-way, 64b, 2 lines/sec
|
||||
CpuIdCacheL2_2M_8_64 = 0x7D, ///< L2: 2M, 8-way, 64 bytes
|
||||
CpuIdCacheL2_512K_2_64 = 0x7F, ///< L2: 512K, 2-way, 64 bytes
|
||||
CpuIdCacheL2_256K_8_32 = 0x82, ///< L2: 256K, 8-way, 32 bytes
|
||||
CpuIdCacheL2_512K_8_32 = 0x83, ///< L2: 512K, 8-way, 32 bytes
|
||||
CpuIdCacheL2_1M_8_32 = 0x84, ///< L2: 1M, 8-way, 32 bytes
|
||||
CpuIdCacheL2_2M_8_32 = 0x85, ///< L2: 2M, 8-way, 32 bytes
|
||||
CpuIdCacheL2_512K_4_64 = 0x86, ///< L2: 512K, 4-way, 64 bytes
|
||||
CpuIdCacheL2_1M_8_64 = 0x87, ///< L2: 1M, 8-way, 64 bytes
|
||||
CpuIdCacheItlb4K_128_4 = 0xB0, ///< ITLB: 4KB, 128 entries, 4-way
|
||||
CpuIdCacheItlb4M_4_4 = 0xB1, ///< ITLB: 4MB, 4 entries, 4-way, or
|
||||
CpuIdCacheItlb2M_8_4 = 0xB1, ///< ITLB: 2MB, 8 entries, 4-way, or
|
||||
CpuIdCacheItlb4M_8 = 0xB1, ///< ITLB: 4MB, 8 entries
|
||||
CpuIdCacheItlb4K_64_4 = 0xB2, ///< ITLB: 4KB, 64 entries, 4-way
|
||||
CpuIdCacheDtlb4K_128_4 = 0xB3, ///< DTLB: 4KB, 128 entries, 4-way
|
||||
CpuIdCacheDtlb4K_256_4 = 0xB4, ///< DTLB: 4KB, 256 entries, 4-way
|
||||
CpuIdCache2TLB_4K_512_4 = 0xCA, ///< 2nd-level TLB: 4KB, 512, 4-way
|
||||
CpuIdCacheL3_512K_4_64 = 0xD0, ///< L3: 512KB, 4-way, 64 bytes
|
||||
CpuIdCacheL3_1M_4_64 = 0xD1, ///< L3: 1M, 4-way, 64 bytes
|
||||
CpuIdCacheL3_2M_4_64 = 0xD2, ///< L3: 2M, 4-way, 64 bytes
|
||||
CpuIdCacheL3_1M_8_64 = 0xD6, ///< L3: 1M, 8-way, 64 bytes
|
||||
CpuIdCacheL3_2M_8_64 = 0xD7, ///< L3: 2M, 8-way, 64 bytes
|
||||
CpuIdCacheL3_4M_8_64 = 0xD8, ///< L3: 4M, 8-way, 64 bytes
|
||||
CpuIdCacheL3_1M5_12_64 = 0xDC, ///< L3: 1.5M, 12-way, 64 bytes
|
||||
CpuIdCacheL3_3M_12_64 = 0xDD, ///< L3: 3M, 12-way, 64 bytes
|
||||
CpuIdCacheL3_6M_12_64 = 0xDE, ///< L3: 6M, 12-way, 64 bytes
|
||||
CpuIdCacheL3_2M_16_64 = 0xE2, ///< L3: 2M, 16-way, 64 bytes
|
||||
CpuIdCacheL3_4M_16_64 = 0xE3, ///< L3: 4M, 16-way, 64 bytes
|
||||
CpuIdCacheL3_8M_16_64 = 0xE4, ///< L3: 8M, 16-way, 64 bytes
|
||||
CpuIdCachePrefetch64 = 0xF0, ///< 64-Byte Prefetching
|
||||
CpuIdCachePrefetch128 = 0xF1, ///< 128-Byte Prefetching
|
||||
};
|
||||
|
||||
#define CPUID_VENDOR_INTEL 0x756E6547
|
||||
#define CPUID_VENDOR_AMD 0x68747541
|
||||
|
||||
#endif // CPUID_H
|
||||
84
Include/IndustryStandard/GenericIch.h
Executable file
84
Include/IndustryStandard/GenericIch.h
Executable file
@ -0,0 +1,84 @@
|
||||
/** @file
|
||||
Copyright (C) 2016, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef GENERIC_ICH_H
|
||||
#define GENERIC_ICH_H
|
||||
|
||||
// GenericIchDefs Generic ICH Definitions.
|
||||
//
|
||||
// Definitions beginning with "R_" are registers.
|
||||
// Definitions beginning with "B_" are bits within registers.
|
||||
// Definitions beginning with "V_" are meaningful values of bits within the registers.
|
||||
|
||||
// IchPciAddressing PCI Bus Address for ICH.
|
||||
|
||||
#define PCI_BUS_NUMBER_ICH 0x00 ///< ICH is on PCI Bus 0.
|
||||
#define PCI_DEVICE_NUMBER_ICH 31 ///< ICH is Device 31.
|
||||
#define PCI_FUNCTION_NUMBER_ICH_LPC 0 ///< LPC is Function 0.
|
||||
#define PCI_FUNCTION_NUMBER_ICH_PMC 2 ///< PMC is Function 2.
|
||||
|
||||
#define V_ICH_PCI_VENDOR_ID 0x8086 ///< Intel vendor-id
|
||||
|
||||
// IchAcpiCntr Control for the ICH's ACPI Counter.
|
||||
|
||||
#define R_ICH_ACPI_BASE 0x40
|
||||
#define B_ICH_ACPI_BASE_BAR 0x0000FF80
|
||||
#define R_ICH_ACPI_CNTL 0x44 ///< See ACPI_CNTL
|
||||
#define B_ICH_ACPI_CNTL_ACPI_EN 0x80
|
||||
|
||||
#define R_ICH_BAR2_BASE 0x20
|
||||
#define B_ICH_BAR2_BASE_BAR 0x0000FFC0
|
||||
#define B_ICH_BAR2_BASE_BAR_EN 0x1
|
||||
|
||||
// Pre Intel Sunrisepoint
|
||||
|
||||
#define R_ICH_LPC_ACPI_BASE R_ICH_ACPI_BASE
|
||||
#define B_ICH_LPC_ACPI_BASE_BAR B_ICH_ACPI_BASE_BAR
|
||||
#define R_ICH_LPC_ACPI_CNTL R_ICH_ACPI_CNTL
|
||||
#define B_ICH_LPC_ACPI_CNTL_ACPI_EN B_ICH_ACPI_CNTL_ACPI_EN
|
||||
|
||||
// Intel Sunrisepoint
|
||||
|
||||
#define R_ICH_PMC_ACPI_BASE R_ICH_ACPI_BASE
|
||||
#define B_ICH_PMC_ACPI_BASE_BAR B_ICH_ACPI_BASE_BAR
|
||||
#define R_ICH_PMC_ACPI_CNTL R_ICH_ACPI_CNTL
|
||||
#define B_ICH_PMC_ACPI_CNTL_ACPI_EN B_ICH_ACPI_CNTL_ACPI_EN
|
||||
|
||||
// Intel Coffee Lake
|
||||
|
||||
#define R_ICH_PMC_BAR2_BASE R_ICH_BAR2_BASE
|
||||
#define B_ICH_PMC_BAR2_BASE_BAR B_ICH_BAR2_BASE_BAR
|
||||
#define B_ICH_PMC_BAR2_BASE_BAR_EN B_ICH_BAR2_BASE_BAR_EN
|
||||
|
||||
// AMD Bolton (AMD Bolton Register Reference Guide 3.03)
|
||||
|
||||
#define R_AMD_ACPI_MMIO_BASE 0xFED80000 ///< AcpiMMioAddr (3-268)
|
||||
#define R_AMD_ACPI_MMIO_PMIO_BASE 0x300 ///< PMIO (3-268)
|
||||
#define R_AMD_ACPI_PM_TMR_BLOCK 0x64 ///< AcpiPmTmrBlk (3-289)
|
||||
|
||||
// IchAcpiTimer The ICH's ACPI Timer.
|
||||
|
||||
#define R_ACPI_PM1_TMR 0x08
|
||||
#define V_ACPI_TMR_FREQUENCY 3579545
|
||||
#define V_ACPI_PM1_TMR_MAX_VAL 0x01000000 ///< The timer is 24 bit overflow.
|
||||
|
||||
/// Macro to generate the PCI address of any given ICH LPC Register.
|
||||
#define PCI_ICH_LPC_ADDRESS(Register) \
|
||||
((UINTN)(PCI_LIB_ADDRESS (PCI_BUS_NUMBER_ICH, PCI_DEVICE_NUMBER_ICH, PCI_FUNCTION_NUMBER_ICH_LPC, (Register))))
|
||||
|
||||
/// Macro to generate the PCI address of any given ICH PMC Register.
|
||||
#define PCI_ICH_PMC_ADDRESS(Register) \
|
||||
((UINTN)(PCI_LIB_ADDRESS (PCI_BUS_NUMBER_ICH, PCI_DEVICE_NUMBER_ICH, PCI_FUNCTION_NUMBER_ICH_PMC, (Register))))
|
||||
|
||||
#endif // GENERIC_ICH_H
|
||||
257
Include/IndustryStandard/HdaRegisters.h
Normal file
257
Include/IndustryStandard/HdaRegisters.h
Normal file
@ -0,0 +1,257 @@
|
||||
/*
|
||||
* File: HdaRegisters.h
|
||||
*
|
||||
* Copyright (c) 2018 John Davis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EFI_HDA_REGS_H
|
||||
#define EFI_HDA_REGS_H
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
//
|
||||
// Global Capabilities, Status, and Control.
|
||||
//
|
||||
|
||||
// Global Capabilities; 2 bytes.
|
||||
#define HDA_REG_GCAP 0x00
|
||||
#define HDA_REG_GCAP_64OK BIT0
|
||||
#define HDA_REG_GCAP_NSDO(a) ((UINT8)((a >> 1) & 0x3))
|
||||
#define HDA_REG_GCAP_BSS(a) ((UINT8)((a >> 3) & 0x1F))
|
||||
#define HDA_REG_GCAP_ISS(a) ((UINT8)((a >> 8) & 0xF))
|
||||
#define HDA_REG_GCAP_OSS(a) ((UINT8)((a >> 12) & 0xF))
|
||||
|
||||
// Minor Version; 1 byte.
|
||||
#define HDA_REG_VMIN 0x02
|
||||
|
||||
// Major Version; 1 byte.
|
||||
#define HDA_REG_VMAJ 0x03
|
||||
|
||||
// Output Payload Capability; 2 bytes.
|
||||
#define HDA_REG_OUTPAY 0x04
|
||||
|
||||
// Input Payload Capability; 2 bytes.
|
||||
#define HDA_REG_INPAY 0x06
|
||||
|
||||
// Global Control; 4 bytes.
|
||||
#define HDA_REG_GCTL 0x08
|
||||
#define HDA_REG_GCTL_CRST BIT0
|
||||
#define HDA_REG_GCTL_FCNTRL BIT1
|
||||
#define HDA_REG_GCTL_UNSOL BIT8
|
||||
|
||||
// Wake Enable; 2 bytes.
|
||||
#define HDA_REG_WAKEEN 0x0C
|
||||
|
||||
// State Change Status; 2 bytes.
|
||||
#define HDA_REG_STATESTS 0x0E
|
||||
#define HDA_REG_STATESTS_INDEX(i) ((UINT16)(1 << (i)))
|
||||
#define HDA_REG_STATESTS_CLEAR 0xEFFF
|
||||
|
||||
// Global Status; 2 bytes
|
||||
#define HDA_REG_GSTS 0x10
|
||||
#define HDA_REG_GSTS_FSTS BIT1
|
||||
|
||||
// Output Stream Payload Capability; 2 bytes.
|
||||
#define HDA_REG_OUTSTRMPAY 0x18
|
||||
|
||||
// Input Stream Payload Capability; 2 bytes.
|
||||
#define HDA_REG_INSTRMPAY 0x1A
|
||||
|
||||
//
|
||||
// Interrupt Status and Control.
|
||||
//
|
||||
|
||||
// Interrupt Control; 4 bytes.
|
||||
#define HDA_REG_INTCTL 0x20
|
||||
|
||||
// Interrupt Status; 4 bytes.
|
||||
#define HDA_REG_INTSTS 0x24
|
||||
|
||||
// Wall Clock Counter; 4 bytes.
|
||||
#define HDA_REG_WALLCLOCK 0x30
|
||||
|
||||
// Stream Synchronization; 4 bytes.
|
||||
#define HDA_REG_SSYNC 0x38
|
||||
|
||||
// CORB Lower Base Address; 4 bytes.
|
||||
#define HDA_REG_CORBLBASE 0x40
|
||||
|
||||
// CORB Upper Base Address; 4 bytes.
|
||||
#define HDA_REG_CORBUBASE 0x44
|
||||
|
||||
// CORB Write Pointer; 2 bytes.
|
||||
#define HDA_REG_CORBWP 0x48
|
||||
|
||||
// CORB Read Pointer; 2 bytes.
|
||||
#define HDA_REG_CORBRP 0x4A
|
||||
#define HDA_REG_CORBRP_RP(a) ((UINT8)a)
|
||||
#define HDA_REG_CORBRP_RST BIT15
|
||||
|
||||
// CORB Control; 1 byte.
|
||||
#define HDA_REG_CORBCTL 0x4C
|
||||
#define HDA_REG_CORBCTL_CMEIE BIT0
|
||||
#define HDA_REG_CORBCTL_CORBRUN BIT1
|
||||
|
||||
// CORB Status; 1 byte.
|
||||
#define HDA_REG_CORBSTS 0x4D
|
||||
#define HDA_REG_CORBSTS_CMEI BIT0
|
||||
|
||||
// CORB Size; 1 byte.
|
||||
#define HDA_REG_CORBSIZE 0x4E
|
||||
#define HDA_REG_CORBSIZE_MASK (BIT0 | BIT1)
|
||||
#define HDA_REG_CORBSIZE_ENT2 0 // 8 B = 2 entries.
|
||||
#define HDA_REG_CORBSIZE_ENT16 BIT0 // 64 B = 16 entries.
|
||||
#define HDA_REG_CORBSIZE_ENT256 BIT1 // 1 KB = 256 entries.
|
||||
#define HDA_REG_CORBSIZE_CORBSZCAP_2 BIT4 // 8 B = 2 entries.
|
||||
#define HDA_REG_CORBSIZE_CORBSZCAP_16 BIT5 // 64 B = 16 entries.
|
||||
#define HDA_REG_CORBSIZE_CORBSZCAP_256 BIT6 // 1 KB = 256 entries.
|
||||
|
||||
// RIRB Lower Base Address; 4 bytes.
|
||||
#define HDA_REG_RIRBLBASE 0x50
|
||||
|
||||
// RIRB Upper Base Address; 4 bytes.
|
||||
#define HDA_REG_RIRBUBASE 0x54
|
||||
|
||||
// RIRB Write Pointer; 2 bytes.
|
||||
#define HDA_REG_RIRBWP 0x58
|
||||
#define HDA_REG_RIRBWP_WP(a) ((UINT8)a)
|
||||
#define HDA_REG_RIRBWP_RST BIT15
|
||||
|
||||
// Response Interrupt Count; 2 bytes.
|
||||
#define HDA_REG_RINTCNT 0x5A
|
||||
|
||||
// RIRB Control; 1 byte.
|
||||
#define HDA_REG_RIRBCTL 0x5C
|
||||
#define HDA_REG_RIRBCTL_RINTCTL BIT0
|
||||
#define HDA_REG_RIRBCTL_RIRBDMAEN BIT1
|
||||
#define HDA_REG_RIRBCTL_RIRBOIC BIT2
|
||||
|
||||
// RIRB Status; 1 byte.
|
||||
#define HDA_REG_RIRBSTS 0x5D
|
||||
#define HDA_REG_RIRBSTS_RINTFL BIT0
|
||||
#define HDA_REG_RIRBSTS_RIRBOIS BIT2
|
||||
|
||||
// RIRB Size; 1 byte.
|
||||
#define HDA_REG_RIRBSIZE 0x5E
|
||||
#define HDA_REG_RIRBSIZE_MASK (BIT0 | BIT1)
|
||||
#define HDA_REG_RIRBSIZE_ENT2 0 // 16 B = 2 entries.
|
||||
#define HDA_REG_RIRBSIZE_ENT16 BIT0 // 128 B = 16 entries.
|
||||
#define HDA_REG_RIRBSIZE_ENT256 BIT1 // 2 KB = 256 entries.
|
||||
#define HDA_REG_RIRBSIZE_RIRBSZCAP_2 BIT4 // 16 B = 2 entries.
|
||||
#define HDA_REG_RIRBSIZE_RIRBSZCAP_16 BIT5 // 128 B = 16 entries.
|
||||
#define HDA_REG_RIRBSIZE_RIRBSZCAP_256 BIT6 // 2 KB = 256 entries.
|
||||
|
||||
// DMA Position Lower Base Address; 4 bytes.
|
||||
#define HDA_REG_DPLBASE 0x70
|
||||
#define HDA_REG_DPLBASE_EN BIT0
|
||||
|
||||
// DMA Position Upper Base Address; 4 bytes.
|
||||
#define HDA_REG_DPUBASE 0x74
|
||||
|
||||
//
|
||||
// Immediate Command Input and Output Registers.
|
||||
//
|
||||
|
||||
// Immediate Command Output Interface; 4 bytes.
|
||||
#define HDA_REG_ICOI 0x60
|
||||
|
||||
// Immediate Command Input Interface; 4 bytes.
|
||||
#define HDA_REG_ICII 0x64
|
||||
|
||||
// Immediate Command Status; 2 bytes.
|
||||
#define HDA_REG_ICIS 0x68
|
||||
#define HDA_REG_ICIS_ICB BIT0
|
||||
#define HDA_REG_ICIS_IRV BIT1
|
||||
#define HDA_REG_ICIS_ICV BIT2
|
||||
#define HDA_REG_ICIS_IRRUNSOL BIT3
|
||||
#define HDA_REG_ICIS_IRRADD(a) ((UINT8)((a >> 4) & 0xF))
|
||||
|
||||
//
|
||||
// Stream Descriptors.
|
||||
//
|
||||
|
||||
// Input/Output/Bidirectional Stream Descriptor n Control; 3 bytes.
|
||||
// Byte 1.
|
||||
#define HDA_REG_SDNCTL1(n) (0x80 + (0x20 * (n)))
|
||||
#define HDA_REG_SDNCTL1_SRST BIT0
|
||||
#define HDA_REG_SDNCTL1_RUN BIT1
|
||||
#define HDA_REG_SDNCTL1_IOCE BIT2
|
||||
#define HDA_REG_SDNCTL1_FEIE BIT3
|
||||
#define HDA_REG_SDNCTL1_DEIE BIT4
|
||||
|
||||
// Byte 2.
|
||||
#define HDA_REG_SDNCTL2(n) (0x81 + (0x20 * (n)))
|
||||
|
||||
// Byte 3.
|
||||
#define HDA_REG_SDNCTL3(n) (0x82 + (0x20 * (n)))
|
||||
#define HDA_REG_SDNCTL3_TP BIT2
|
||||
#define HDA_REG_SDNCTL3_DIR BIT3
|
||||
#define HDA_REG_SDNCTL3_STRM_GET(a) ((UINT8)((a >> 4) & 0xF))
|
||||
#define HDA_REG_SDNCTL3_STRM_SET(a, s) ((UINT8)(((a) & 0x0F) | (((s) & 0xF)) << 4))
|
||||
|
||||
// Input/Output/Bidirectional Stream Descriptor n Status; 1 byte.
|
||||
#define HDA_REG_SDNSTS(n) (0x83 + (0x20 * (n)))
|
||||
#define HDA_REG_SDNSTS_BCIS BIT2
|
||||
#define HDA_REG_SDNSTS_FIFOE BIT3
|
||||
#define HDA_REG_SDNSTS_DESE BIT4
|
||||
#define HDA_REG_SDNSTS_FIFORDY BIT5
|
||||
|
||||
// Input/Output/Bidirectional Stream Descriptor n Link Position in Buffer; 4 bytes.
|
||||
#define HDA_REG_SDNLPIB(n) (0x84 + (0x20 * (n)))
|
||||
|
||||
// Input/Output/Bidirectional Stream Descriptor n Cyclic Buffer Length; 4 bytes.
|
||||
#define HDA_REG_SDNCBL(n) (0x88 + (0x20 * (n)))
|
||||
|
||||
// Input/Output/Bidirectional Stream Descriptor n Last Valid Index; 2 bytes.
|
||||
#define HDA_REG_SDNLVI(n) (0x8C + (0x20 * (n)))
|
||||
|
||||
// Input/Output/Bidirectional Stream Descriptor n FIFO Size; 2 bytes.
|
||||
#define HDA_REG_SDNFIFOS(n) (0x90 + (0x20 * (n)))
|
||||
|
||||
// Input/Output/Bidirectional Stream Descriptor n Format; 2 bytes.
|
||||
#define HDA_REG_SDNFMT(n) (0x92 + (0x20 * (n)))
|
||||
#define HDA_REG_SDNFMT_CHAN(a) ((UINT8)((a) & 0xF))
|
||||
#define HDA_REG_SDNFMT_BITS(a) ((UINT8)(((a) >> 4) & 0x3))
|
||||
#define HDA_REG_SDNFMT_BITS_8 0x0
|
||||
#define HDA_REG_SDNFMT_BITS_16 0x1
|
||||
#define HDA_REG_SDNFMT_BITS_20 0x2
|
||||
#define HDA_REG_SDNFMT_BITS_24 0x3
|
||||
#define HDA_REG_SDNFMT_BITS_32 0x4
|
||||
#define HDA_REG_SDNFMT_DIV(a) ((UINT8)(((a) >> 8) & 0x3))
|
||||
#define HDA_REG_SDNFMT_MULT(a) ((UINT8)(((a) >> 11) & 0x3))
|
||||
#define HDA_REG_SDNFMT_BASE_44KHZ BIT14
|
||||
#define HDA_REG_SDNFMT_SET(chan, bits, div, mult, base) \
|
||||
((UINT16)(((chan) & 0xF) | (((bits) & 0x3) << 4) | (((div) & 0x3) << 8) | \
|
||||
(((mult) & 0x3) << 11) | ((base) ? HDA_REG_SDNFMT_BASE_44KHZ : 0)))
|
||||
|
||||
// Input/Output/Bidirectional Stream Descriptor n BDL Pointer Lower Base Address; 4 bytes.
|
||||
#define HDA_REG_SDNBDPL(n) (0x98 + (0x20 * (n)))
|
||||
|
||||
// Input/Output/Bidirectional Stream Descriptor n BDL Pointer Upper Base Address; 4 bytes.
|
||||
#define HDA_REG_SDNBDPU(n) (0x9C + (0x20 * (n)))
|
||||
|
||||
// Wall Clock Counter Alias; 4 bytes.
|
||||
#define HDA_REG_WALCLKA 0x2030
|
||||
|
||||
// Input/Output/Bidirectional Stream Descriptor n Link Position in Buffer Alias; 4 bytes.
|
||||
#define HDA_REG_SDNLPIBA(n) (0x2084 + (0x20 * (n)))
|
||||
|
||||
#endif // EFI_HDA_REGS_H
|
||||
504
Include/IndustryStandard/HdaVerbs.h
Normal file
504
Include/IndustryStandard/HdaVerbs.h
Normal file
@ -0,0 +1,504 @@
|
||||
/*
|
||||
* File: HdaVerbs.h
|
||||
*
|
||||
* Copyright (c) 2018 John Davis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EFI_HDA_VERBS_H
|
||||
#define EFI_HDA_VERBS_H
|
||||
|
||||
// Root node ID.
|
||||
#define HDA_NID_ROOT 0
|
||||
|
||||
// Macro for building verbs. 4-bit verbs will be zero when masked against 0xFF0.
|
||||
#define HDA_CODEC_VERB(Verb, Payload) ((UINT32)((((Verb) & 0xFFF) & 0xFF0) ? \
|
||||
((((Verb) & 0xFFF) << 8) | ((Payload) & 0xFF)) : /* 12-bit verbs */ \
|
||||
((((Verb) & 0xF) << 16) | ((Payload) & 0xFFFF)))) /* 4-bit verbs */
|
||||
|
||||
// Get/Set Converter Format.
|
||||
#define HDA_VERB_GET_CONVERTER_FORMAT 0xA
|
||||
#define HDA_VERB_SET_CONVERTER_FORMAT 0x2
|
||||
#define HDA_CONVERTER_FORMAT_CHAN(a) ((UINT8)((a) & 0xF))
|
||||
#define HDA_CONVERTER_FORMAT_BITS(a) ((UINT8)(((a) >> 4) & 0x3))
|
||||
#define HDA_CONVERTER_FORMAT_BITS_8 0x0
|
||||
#define HDA_CONVERTER_FORMAT_BITS_16 0x1
|
||||
#define HDA_CONVERTER_FORMAT_BITS_20 0x2
|
||||
#define HDA_CONVERTER_FORMAT_BITS_24 0x3
|
||||
#define HDA_CONVERTER_FORMAT_BITS_32 0x4
|
||||
#define HDA_CONVERTER_FORMAT_DIV(a) ((UINT8)(((a) >> 8) & 0x3))
|
||||
#define HDA_CONVERTER_FORMAT_MULT(a) ((UINT8)(((a) >> 11) & 0x3))
|
||||
#define HDA_CONVERTER_FORMAT_BASE_44KHZ BIT14
|
||||
#define HDA_CONVERTER_FORMAT_SET(chan, bits, div, mult, base) \
|
||||
((UINT16)(((chan) & 0xF) | (((bits) & 0x3) << 4) | (((div) & 0x3) << 8) | \
|
||||
(((mult) & 0x3) << 11) | ((base) ? HDA_CONVERTER_FORMAT_BASE_44KHZ : 0)))
|
||||
|
||||
// Get Amplifier Gain/Mute.
|
||||
#define HDA_VERB_GET_AMP_GAIN_MUTE 0xB
|
||||
#define HDA_VERB_GET_AMP_GAIN_MUTE_PAYLOAD(index, left, out) ((UINT16)(index | (left ? BIT13 : 0) | (out ? BIT15 : 0)))
|
||||
#define HDA_VERB_GET_AMP_GAIN_MUTE_GAIN(a) ((UINT8)(a & 0x7F))
|
||||
#define HDA_VERB_GET_AMP_GAIN_MUTE_MUTE BIT7
|
||||
|
||||
// Set Amplifier Gain/Mute.
|
||||
#define HDA_VERB_SET_AMP_GAIN_MUTE 0x3
|
||||
#define HDA_VERB_SET_AMP_GAIN_MUTE_PAYLOAD(index, gain, mute, right, left, in, out) \
|
||||
((UINT16)((gain & 0x7F) | (mute ? BIT7 : 0) | (index & 0xFF) << 8) \
|
||||
| (right ? BIT12 : 0) | (left ? BIT13 : 0) | (in ? BIT14 : 0) | (out ? BIT15 : 0))
|
||||
|
||||
// Get/Set Processing Coefficient.
|
||||
#define HDA_VERB_GET_PROCESSING_COEFFICIENT 0xC
|
||||
#define HDA_VERB_SET_PROCESSING_COEFFICIENT 0x4
|
||||
|
||||
// Get/Set Coefficient Index.
|
||||
#define HDA_VERB_GET_COEFFICIENT_INDEX 0xD
|
||||
#define HDA_VERB_SET_COEFFICIENT_INDEX 0x5
|
||||
|
||||
// Get/Set Connection Select Control.
|
||||
#define HDA_VERB_GET_CONN_SELECT_CONTROL 0xF01
|
||||
#define HDA_VERB_SET_CONN_SELECT_CONTROL 0x701
|
||||
|
||||
// Get Connection List Entry.
|
||||
#define HDA_VERB_GET_CONN_LIST_ENTRY 0xF02
|
||||
#define HDA_VERB_GET_CONN_LIST_ENTRY_SHORT(a, i) ((UINT8)(a >> (8 * (i))))
|
||||
#define HDA_VERB_GET_CONN_LIST_ENTRY_LONG(a, i) ((UINT16)(a >> (16 * (i))))
|
||||
|
||||
// Get/Set Processing State.
|
||||
#define HDA_VERB_GET_PROCESSING_STATE 0xF03
|
||||
#define HDA_VERB_SET_PROCESSING_STATE 0x703
|
||||
#define HDA_PROCESSING_STATE_OFF 0x00
|
||||
#define HDA_PROCESSING_STATE_ON 0x01
|
||||
#define HDA_PROCESSING_STATE_BENIGN 0x02
|
||||
|
||||
// Get/Set Input Converter SDI Select.
|
||||
#define HDA_VERB_GET_INPUT_CONV_SDI_SELECT 0xF04
|
||||
#define HDA_VERB_SET_INPUT_CONV_SDI_SELECT 0x704
|
||||
|
||||
// Get/Set Power State.
|
||||
#define HDA_VERB_GET_POWER_STATE 0xF05
|
||||
#define HDA_VERB_SET_POWER_STATE 0x705
|
||||
|
||||
// Get/Set Converter Stream, Channel.
|
||||
#define HDA_VERB_GET_CONVERTER_STREAM_CHANNEL 0xF06
|
||||
#define HDA_VERB_SET_CONVERTER_STREAM_CHANNEL 0x706
|
||||
#define HDA_VERB_GET_CONVERTER_STREAM_CHAN(a) ((UINT8)(a & 0xF))
|
||||
#define HDA_VERB_GET_CONVERTER_STREAM_STR(a) ((UINT8)((a >> 4) & 0xF))
|
||||
#define HDA_VERB_SET_CONVERTER_STREAM_PAYLOAD(c, s) ((UINT8)(((c) & 0xF) | (((s) & 0xF) << 4)))
|
||||
|
||||
// Get/Set Pin Widget Control.
|
||||
#define HDA_VERB_GET_PIN_WIDGET_CONTROL 0xF07
|
||||
#define HDA_VERB_SET_PIN_WIDGET_CONTROL 0x707
|
||||
#define HDA_PIN_WIDGET_CONTROL_VREF(a) ((UINT8)(a & 0x3))
|
||||
#define HDA_PIN_WIDGET_CONTROL_VREF_EN BIT2
|
||||
#define HDA_PIN_WIDGET_CONTROL_IN_EN BIT5
|
||||
#define HDA_PIN_WIDGET_CONTROL_OUT_EN BIT6
|
||||
#define HDA_PIN_WIDGET_CONTROL_HP_EN BIT7
|
||||
#define HDA_VERB_SET_PIN_WIDGET_CONTROL_PAYLOAD(vref, vrefEn, in, out, hp) \
|
||||
((UINT8)(HDA_PIN_WIDGET_CONTROL_VREF(vref) | (vrefEn ? HDA_PIN_WIDGET_CONTROL_VREF_EN : 0) \
|
||||
| (in ? HDA_PIN_WIDGET_CONTROL_IN_EN : 0) | (out ? HDA_PIN_WIDGET_CONTROL_OUT_EN : 0) \
|
||||
| (hp ? HDA_PIN_WIDGET_CONTROL_HP_EN : 0)))
|
||||
|
||||
// Get/Set Unsolicited Response.
|
||||
#define HDA_VERB_GET_UNSOL_RESPONSE 0xF08
|
||||
#define HDA_VERB_SET_UNSOL_RESPONSE 0x708
|
||||
#define HDA_UNSOL_RESPONSE_EN BIT7
|
||||
|
||||
|
||||
// Get/Set Digital Converter Control.
|
||||
#define HDA_VERB_GET_DIGITAL_CONV_CONTROL 0xF0D
|
||||
#define HDA_VERB_SET_DIGITAL_CONV_CONTROL1 0x70D
|
||||
#define HDA_VERB_SET_DIGITAL_CONV_CONTROL2 0x70E
|
||||
#define HDA_VERB_SET_DIGITAL_CONV_CONTROL3 0x73E
|
||||
#define HDA_VERB_SET_DIGITAL_CONV_CONTROL4 0x73F
|
||||
#define HDA_DIGITAL_CONV_CONTROL_DIGEN BIT0
|
||||
#define HDA_DIGITAL_CONV_CONTROL_V BIT1
|
||||
#define HDA_DIGITAL_CONV_CONTROL_VCFG BIT2
|
||||
#define HDA_DIGITAL_CONV_CONTROL_PRE BIT3
|
||||
#define HDA_DIGITAL_CONV_CONTROL_NO_CP BIT4
|
||||
#define HDA_DIGITAL_CONV_CONTROL_NO_AUDIO BIT5
|
||||
#define HDA_DIGITAL_CONV_CONTROL_PRO BIT6
|
||||
#define HDA_DIGITAL_CONV_CONTROL_L BIT7
|
||||
#define HDA_DIGITAL_CONV_CONTROL_CC(a) ((UINT8)((a >> 8) & 0x7F))
|
||||
#define HDA_DIGITAL_CONV_CONTROL_ICT ((UINT8)((a >> 16) & 0xF))
|
||||
#define HDA_DIGITAL_CONV_CONTROL_KAE BIT23
|
||||
|
||||
// Get/Execute Pin Sense.
|
||||
#define HDA_VERB_GET_PIN_SENSE 0xF09
|
||||
#define HDA_VERB_EXE_PIN_SENSE 0x709
|
||||
#define HDA_PIN_SENSE_PD BIT31
|
||||
|
||||
// Get/Set Beep Generation.
|
||||
#define HDA_VERB_GET_BEEP_GENERATION 0xF0A
|
||||
#define HDA_VERB_SET_BEEP_GENERATION 0x70A
|
||||
|
||||
// Get/Set EAPD/BTL Enable.
|
||||
#define HDA_VERB_GET_EAPD_BTL_ENABLE 0xF0C
|
||||
#define HDA_VERB_SET_EAPD_BTL_ENABLE 0x70C
|
||||
#define HDA_EAPD_BTL_ENABLE_BTL BIT0
|
||||
#define HDA_EAPD_BTL_ENABLE_EAPD BIT1
|
||||
#define HDA_EAPD_BTL_ENABLE_L_R_SWAP BIT2
|
||||
|
||||
// Get/Set Volume Knob.
|
||||
#define HDA_VERB_GET_VOLUME_KNOB 0xF0F
|
||||
#define HDA_VERB_SET_VOLUME_KNOB 0x70F
|
||||
#define HDA_VOLUME_KNOB_DIRECT BIT7
|
||||
|
||||
// Get/Set GPI Data.
|
||||
#define HDA_VERB_GET_GPI_DATA 0xF10
|
||||
#define HDA_VERB_SET_GPI_DATA 0x710
|
||||
|
||||
// Get/Set GPI Wake Enable Mask.
|
||||
#define HDA_VERB_GET_GPI_WAKE_ENABLE_MASK 0xF11
|
||||
#define HDA_VERB_SET_GPI_WAKE_ENABLE_MASK 0x711
|
||||
|
||||
// Get/Set GPI Unsolicited Enable Mask.
|
||||
#define HDA_VERB_GET_GPI_UNSOL_ENABLE_MASK 0xF12
|
||||
#define HDA_VERB_SET_GPI_UNSOL_ENABLE_MASK 0x712
|
||||
|
||||
// Get/Set GPI Sticky Mask.
|
||||
#define HDA_VERB_GET_GPI_STICK_MASK 0xF13
|
||||
#define HDA_VERB_SET_GPI_STICK_MASK 0x713
|
||||
|
||||
// Get/Set GPO Data.
|
||||
#define HDA_VERB_GET_GPO_DATA 0xF14
|
||||
#define HDA_VERB_SET_GPO_DATA 0x714
|
||||
|
||||
// Get/Set GPIO Data.
|
||||
#define HDA_VERB_GET_GPIO_DATA 0xF15
|
||||
#define HDA_VERB_SET_GPIO_DATA 0x715
|
||||
|
||||
// Get/Set GPIO Enable Mask.
|
||||
#define HDA_VERB_GET_GPIO_ENABLE_MASK 0xF16
|
||||
#define HDA_VERB_SET_GPIO_ENABLE_MASK 0x716
|
||||
|
||||
// Get/Set GPIO Direction.
|
||||
#define HDA_VERB_GET_GPIO_DIRECTION 0xF17
|
||||
#define HDA_VERB_SET_GPIO_DIRECTION 0x717
|
||||
|
||||
// Get/Set GPIO Wake Enable Mask.
|
||||
#define HDA_VERB_GET_GPIO_WAKE_ENABLE_MASK 0xF18
|
||||
#define HDA_VERB_SET_GPIO_WAKE_ENABLE_MASK 0x718
|
||||
|
||||
// Get/Set GPIO Unsolicited Enable Mask.
|
||||
#define HDA_VERB_GET_GPIO_UNSOL_ENABLE_MASK 0xF19
|
||||
#define HDA_VERB_SET_GPIO_UNSOL_ENABLE_MASK 0x719
|
||||
|
||||
// Get/Set GPIO Sticky Mask.
|
||||
#define HDA_VERB_GET_GPIO_STICKY_MASK 0xF1A
|
||||
#define HDA_VERB_SET_GPIO_STICKY_MASK 0x71A
|
||||
|
||||
// Get/Set Implementation Identification.
|
||||
#define HDA_VERB_GET_IMPLEMENTATION_ID 0xF20
|
||||
#define HDA_VERB_SET_IMPLEMENTATION_ID1 0x720
|
||||
#define HDA_VERB_SET_IMPLEMENTATION_ID2 0x721
|
||||
#define HDA_VERB_SET_IMPLEMENTATION_ID3 0x722
|
||||
#define HDA_VERB_SET_IMPLEMENTATION_ID4 0x723
|
||||
|
||||
//
|
||||
// Get/Set Configuration Default.
|
||||
//
|
||||
#define HDA_VERB_GET_CONFIGURATION_DEFAULT 0xF1C
|
||||
#define HDA_VERB_SET_CONFIGURATION_DEFAULT0 0x71C
|
||||
#define HDA_VERB_SET_CONFIGURATION_DEFAULT1 0x71D
|
||||
#define HDA_VERB_SET_CONFIGURATION_DEFAULT2 0x71E
|
||||
#define HDA_VERB_SET_CONFIGURATION_DEFAULT3 0x71F
|
||||
|
||||
// Configuration Default sequence.
|
||||
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_SEQUENCE(a) \
|
||||
((UINT8)(a & 0xF))
|
||||
|
||||
// Configuration Default default associaton.
|
||||
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_ASSOCIATION(a) \
|
||||
((UINT8)((a >> 4) & 0xF))
|
||||
|
||||
// Configuration Default misc.
|
||||
#define HDA_CONFIG_DEFAULT_MISC_JACK_DETECT_OVERRIDE BIT8
|
||||
|
||||
// Configuration Default color.
|
||||
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_COLOR(a) \
|
||||
((UINT8)((a >> 12) & 0xF))
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_UNKNOWN 0x0
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_BLACK 0x1
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_GREY 0x2
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_BLUE 0x3
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_GREEN 0x4
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_RED 0x5
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_ORANGE 0x6
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_YELLOW 0x7
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_PURPLE 0x8
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_PINK 0x9
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_WHITE 0xE
|
||||
#define HDA_CONFIG_DEFAULT_COLOR_OTHER 0xF
|
||||
|
||||
// Configuration Default connection type.
|
||||
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_CONN_TYPE(a) \
|
||||
((UINT8)((a >> 16) & 0xF))
|
||||
#define HDA_CONFIG_DEFAULT_CONN_UNKNOWN 0x0
|
||||
#define HDA_CONFIG_DEFAULT_CONN_1_8_STEREO 0x1
|
||||
#define HDA_CONFIG_DEFAULT_CONN_1_4_STEREO 0x2
|
||||
#define HDA_CONFIG_DEFAULT_CONN_ATAPI 0x3
|
||||
#define HDA_CONFIG_DEFAULT_CONN_RCA 0x4
|
||||
#define HDA_CONFIG_DEFAULT_CONN_OPTICAL 0x5
|
||||
#define HDA_CONFIG_DEFAULT_CONN_DIGITAL_OTHER 0x6
|
||||
#define HDA_CONFIG_DEFAULT_CONN_ANALOG_OTHER 0x7
|
||||
#define HDA_CONFIG_DEFAULT_CONN_MULTI_ANALOG 0x8
|
||||
#define HDA_CONFIG_DEFAULT_CONN_XLR 0x9
|
||||
#define HDA_CONFIG_DEFAULT_CONN_RJ11 0xA
|
||||
#define HDA_CONFIG_DEFAULT_CONN_COMBO 0xB
|
||||
#define HDA_CONFIG_DEFAULT_CONN_OTHER 0xF
|
||||
|
||||
// Configuration Default default device.
|
||||
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_DEVICE(a) \
|
||||
((UINT8)((a >> 20) & 0xF))
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_LINE_OUT 0x0
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_SPEAKER 0x1
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_HEADPHONE_OUT 0x2
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_CD 0x3
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_SPDIF_OUT 0x4
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_OTHER_DIGITAL_OUT 0x5
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_MODEM_LINE 0x6
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_MODEM_HANDSET 0x7
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_LINE_IN 0x8
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_AUX 0x9
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_MIC_IN 0xA
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_TELEPHONY 0xB
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_SPDIF_IN 0xC
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_OTHER_DIGITAL_IN 0xD
|
||||
#define HDA_CONFIG_DEFAULT_DEVICE_OTHER 0xF
|
||||
|
||||
// Configuration Default location.
|
||||
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_LOC(a) \
|
||||
((UINT8)((a >> 24) & 0xF))
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SPEC_NA 0x0
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SPEC_REAR 0x1
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SPEC_FRONT 0x2
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SPEC_LEFT 0x3
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SPEC_RIGHT 0x4
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SPEC_TOP 0x5
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SPEC_BOTTOM 0x6
|
||||
|
||||
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_SURF(a) \
|
||||
((UINT8)((a >> 28) & 0x3))
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SURF_EXTERNAL 0x0
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SURF_INTERNAL 0x1
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SURF_SEPARATE 0x2
|
||||
#define HDA_CONFIG_DEFAULT_LOC_SURF_OTHER 0x3
|
||||
|
||||
// Configuration Default port connectivity.
|
||||
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_PORT_CONN(a) \
|
||||
((UINT8)((a >> 30) & 0x3))
|
||||
#define HDA_CONFIG_DEFAULT_PORT_CONN_JACK 0x0
|
||||
#define HDA_CONFIG_DEFAULT_PORT_CONN_NONE 0x1
|
||||
#define HDA_CONFIG_DEFAULT_PORT_CONN_FIXED_DEVICE 0x2
|
||||
#define HDA_CONFIG_DEFAULT_PORT_CONN_INT_JACK 0x3
|
||||
|
||||
// Configuration Default payload set.
|
||||
#define HDA_VERB_SET_CONFIGURATION_DEFAULT_PAYLOAD(seq, assoc, jacko, color, connType, device, loc, surf, portConn) \
|
||||
((UINT32)(((seq) & 0xF) | (((assoc) & 0xF) << 4) | (jacko ? HDA_CONFIG_DEFAULT_MISC_JACK_DETECT_OVERRIDE : 0) \
|
||||
| (((color) & 0xF) << 12) | (((connType) & 0xF) << 16) | (((device) & 0xF) << 20) | (((loc) & 0x3) << 24) \
|
||||
| (((surf) & 0x3) << 28) | (((portConn) & 0x3) << 30)))
|
||||
|
||||
// Get/Set Stripe Control.
|
||||
#define HDA_VERB_GET_STRIPE_CONTROL 0xF24
|
||||
#define HDA_VERB_SET_STRIPE_CONTROL 0x724
|
||||
|
||||
// Get/Set Converter Channel Count.
|
||||
#define HDA_VERB_GET_CONVERTER_CHANNEL_COUNT 0xF2D
|
||||
#define HDA_VERB_SET_CONVERTER_CHANNEL_COUNT 0x72D
|
||||
|
||||
// Get Data Island Packet - Size Info.
|
||||
#define HDA_VERB_GET_DATA_ISLAND_PACKET_SIZE 0xF2E
|
||||
|
||||
// Get EDID-Like Data (ELD).
|
||||
#define HDA_VERB_GET_EDID_LIKE_DATA 0xF2F
|
||||
|
||||
// Get/Set Data Island Packet - Index.
|
||||
#define HDA_VERB_GET_DATA_ISLAND_PACKET_INDEX 0xF30
|
||||
#define HDA_VERB_SET_DATA_ISLAND_PACKET_INDEX 0x730
|
||||
|
||||
// Get/Set Data Island Packet – Data.
|
||||
#define HDA_VERB_GET_DATA_ISLAND_PACKET_DATA 0xF31
|
||||
#define HDA_VERB_SET_DATA_ISLAND_PACKET_DATA 0x731
|
||||
|
||||
// Get/Set Data Island Packet – Transmit Control.
|
||||
#define HDA_VERB_GET_DATA_ISLAND_PACKET_XMIT 0xF32
|
||||
#define HDA_VERB_SET_DATA_ISLAND_PACKET_XMIT 0x732
|
||||
|
||||
// Get/Set Content Protection Control (CP_CONTROL).
|
||||
#define HDA_VERB_GET_CP_CONTROL 0xF33
|
||||
#define HDA_VERB_SET_CP_CONTROL 0x733
|
||||
|
||||
// Get/Set ASP Channel Mapping.
|
||||
#define HDA_VERB_GET_ASP_MAPPING 0xF34
|
||||
#define HDA_VERB_SET_ASP_MAPPING 0x734
|
||||
|
||||
// Execute Function Reset.
|
||||
#define HDA_VERB_EXE_FUNC_RESET 0x7FF
|
||||
|
||||
// Get Parameter.
|
||||
#define HDA_VERB_GET_PARAMETER 0xF00
|
||||
|
||||
//
|
||||
// Parameters.
|
||||
//
|
||||
|
||||
// Vendor ID.
|
||||
#define HDA_PARAMETER_VENDOR_ID 0x00
|
||||
#define HDA_PARAMETER_VENDOR_ID_DEV(a) ((UINT16)a)
|
||||
#define HDA_PARAMETER_VENDOR_ID_VEN(a) ((UINT16)(a >> 16))
|
||||
|
||||
// Revision ID.
|
||||
#define HDA_PARAMETER_REVISION_ID 0x02
|
||||
#define HDA_PARAMETER_REVISION_ID_STEPPING(a) ((UINT8)a)
|
||||
#define HDA_PARAMETER_REVISION_ID_REV_ID(a) ((UINT8)(a >> 8))
|
||||
#define HDA_PARAMETER_REVISION_ID_MINOR_REV(a) ((UINT8)((a >> 16) & 0xF))
|
||||
#define HDA_PARAMETER_REVISION_ID_MAJOR_REV(a) ((UINT8)((a >> 20) & 0xF))
|
||||
|
||||
// Subordinate Node Count.
|
||||
#define HDA_PARAMETER_SUBNODE_COUNT 0x04
|
||||
#define HDA_PARAMETER_SUBNODE_COUNT_TOTAL(a) ((UINT8)a);
|
||||
#define HDA_PARAMETER_SUBNODE_COUNT_START(a) ((UINT8)(a >> 16));
|
||||
|
||||
// Function Group Type.
|
||||
#define HDA_PARAMETER_FUNC_GROUP_TYPE 0x05
|
||||
#define HDA_PARAMETER_FUNC_GROUP_TYPE_NODETYPE(a) ((UINT8)a)
|
||||
#define HDA_PARAMETER_FUNC_GROUP_TYPE_UNSOL BIT8
|
||||
#define HDA_FUNC_GROUP_TYPE_AUDIO 0x01
|
||||
#define HDA_FUNC_GROUP_TYPE_MODEM 0x02
|
||||
|
||||
// Audio Function Group Capabilities.
|
||||
#define HDA_PARAMETER_FUNC_GROUP_CAPS 0x08
|
||||
#define HDA_PARAMETER_FUNC_GROUP_CAPS_OUT_DELAY(a) ((UINT8)(a & 0xF))
|
||||
#define HDA_PARAMETER_FUNC_GROUP_CAPS_IN_DELAY(a) ((UINT8)((a >> 8) & 0xF))
|
||||
#define HDA_PARAMETER_FUNC_GROUP_CAPS_BEEP_GEN BIT16
|
||||
|
||||
// Audio Widget Capabilities.
|
||||
#define HDA_PARAMETER_WIDGET_CAPS 0x09
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_STEREO BIT0
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_IN_AMP BIT1
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_OUT_AMP BIT2
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_AMP_OVERRIDE BIT3
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_FORMAT_OVERRIDE BIT4
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_STRIPE BIT5
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_PROC_WIDGET BIT6
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_UNSOL_CAPABLE BIT7
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_CONN_LIST BIT8
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_DIGITAL BIT9
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_POWER_CNTRL BIT10
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_L_R_SWAP BIT11
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_CP_CAPS BIT12
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_CHAN_COUNT(a) ((UINT8)(((a >> 12) & 0xE) | (a & 0x1)))
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_DELAY(a) ((UINT8)((a >> 16) & 0xF))
|
||||
#define HDA_PARAMETER_WIDGET_CAPS_TYPE(a) ((UINT8)((a >> 20) & 0xF))
|
||||
|
||||
// Widget types.
|
||||
#define HDA_WIDGET_TYPE_OUTPUT 0x0
|
||||
#define HDA_WIDGET_TYPE_INPUT 0x1
|
||||
#define HDA_WIDGET_TYPE_MIXER 0x2
|
||||
#define HDA_WIDGET_TYPE_SELECTOR 0x3
|
||||
#define HDA_WIDGET_TYPE_PIN_COMPLEX 0x4
|
||||
#define HDA_WIDGET_TYPE_POWER 0x5
|
||||
#define HDA_WIDGET_TYPE_VOLUME_KNOB 0x6
|
||||
#define HDA_WIDGET_TYPE_BEEP_GEN 0x7
|
||||
#define HDA_WIDGET_TYPE_VENDOR 0xF
|
||||
|
||||
// Supported PCM Size, Rates.
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES 0x0A
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_8KHZ BIT0
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_11KHZ BIT1
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_16KHZ BIT2
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_22KHZ BIT3
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_32KHZ BIT4
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_44KHZ BIT5
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_48KHZ BIT6
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_88KHZ BIT7
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_96KHZ BIT8
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_176KHZ BIT9
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_192KHZ BIT10
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_384KHZ BIT11
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_8BIT BIT16
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_16BIT BIT17
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_20BIT BIT18
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_24BIT BIT19
|
||||
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_32BIT BIT20
|
||||
|
||||
// Supported Stream Formats.
|
||||
#define HDA_PARAMETER_SUPPORTED_STREAM_FORMATS 0x0B
|
||||
#define HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_PCM BIT0
|
||||
#define HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_FLOAT32 BIT1
|
||||
#define HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_AC3 BIT2
|
||||
|
||||
// Pin Capabilities.
|
||||
#define HDA_PARAMETER_PIN_CAPS 0x0C
|
||||
#define HDA_PARAMETER_PIN_CAPS_IMPEDANCE BIT0
|
||||
#define HDA_PARAMETER_PIN_CAPS_TRIGGER BIT1
|
||||
#define HDA_PARAMETER_PIN_CAPS_PRESENCE BIT2
|
||||
#define HDA_PARAMETER_PIN_CAPS_HEADPHONE BIT3
|
||||
#define HDA_PARAMETER_PIN_CAPS_OUTPUT BIT4
|
||||
#define HDA_PARAMETER_PIN_CAPS_INPUT BIT5
|
||||
#define HDA_PARAMETER_PIN_CAPS_BALANCED BIT6
|
||||
#define HDA_PARAMETER_PIN_CAPS_HDMI BIT7
|
||||
#define HDA_PARAMETER_PIN_CAPS_VREF(a) ((UINT8)(a >> 8))
|
||||
#define HDA_PARAMETER_PIN_CAPS_EAPD BIT16
|
||||
#define HDA_PARAMETER_PIN_CAPS_DISPLAYPORT BIT24
|
||||
#define HDA_PARAMETER_PIN_CAPS_HBR BIT27
|
||||
|
||||
// Amplifier Capabilities (input and output).
|
||||
#define HDA_PARAMETER_AMP_CAPS_INPUT 0x0D
|
||||
#define HDA_PARAMETER_AMP_CAPS_OUTPUT 0x12
|
||||
#define HDA_PARAMETER_AMP_CAPS_OFFSET(a) ((UINT8)(a & 0x7F))
|
||||
#define HDA_PARAMETER_AMP_CAPS_NUM_STEPS(a) ((UINT8)((a >> 8) & 0x7F))
|
||||
#define HDA_PARAMETER_AMP_CAPS_STEP_SIZE(a) ((UINT8)((a >> 16) & 0x7F))
|
||||
#define HDA_PARAMETER_AMP_CAPS_MUTE BIT31
|
||||
|
||||
// Connection List Length.
|
||||
#define HDA_PARAMETER_CONN_LIST_LENGTH 0x0E
|
||||
#define HDA_PARAMETER_CONN_LIST_LENGTH_LEN(a) ((UINT8)(a & 0x7F))
|
||||
#define HDA_PARAMETER_CONN_LIST_LENGTH_LONG BIT7
|
||||
|
||||
// Supported Power States.
|
||||
#define HDA_PARAMETER_SUPPORTED_POWER_STATES 0x0F
|
||||
#define HDA_PARAMETER_SUPPORTED_POWER_STATES_D0 BIT0
|
||||
#define HDA_PARAMETER_SUPPORTED_POWER_STATES_D1 BIT1
|
||||
#define HDA_PARAMETER_SUPPORTED_POWER_STATES_D2 BIT2
|
||||
#define HDA_PARAMETER_SUPPORTED_POWER_STATES_D3 BIT3
|
||||
#define HDA_PARAMETER_SUPPORTED_POWER_STATES_D3_COLD BIT4
|
||||
#define HDA_PARAMETER_SUPPORTED_POWER_STATES_S3_D3_COLD BIT29
|
||||
#define HDA_PARAMETER_SUPPORTED_POWER_STATES_CLKSTOP BIT30
|
||||
#define HDA_PARAMETER_SUPPORTED_POWER_STATES_EPSS BIT31
|
||||
|
||||
// Processing Capabilities.
|
||||
#define HDA_PARAMETER_PROCESSING_CAPS 0x10
|
||||
#define HDA_PARAMETER_PROCESSING_CAPS_BENIGN BIT0
|
||||
#define HDA_PARAMETER_PROCESSING_CAPS_NUM_COEFF(a) ((UINT8)(a >> 8))
|
||||
|
||||
// GPIO Count.
|
||||
#define HDA_PARAMETER_GPIO_COUNT 0x11
|
||||
#define HDA_PARAMETER_GPIO_COUNT_NUM_GPIOS(a) ((UINT8)a)
|
||||
#define HDA_PARAMETER_GPIO_COUNT_NUM_GPOS(a) ((UINT8)(a >> 8))
|
||||
#define HDA_PARAMETER_GPIO_COUNT_NUM_GPIS(a) ((UINT8)(a >> 16))
|
||||
#define HDA_PARAMETER_GPIO_COUNT_GPI_UNSOL BIT30
|
||||
#define HDA_PARAMETER_GPIO_COUNT_GPI_WAKE BIT31
|
||||
|
||||
// Volume Knob Capabilities.
|
||||
#define HDA_PARAMETER_VOLUME_KNOB_CAPS 0x13
|
||||
#define HDA_PARAMETER_VOLUME_KNOB_CAPS_NUM_STEPS(a) ((UINT8)(a & 0x7F))
|
||||
#define HDA_PARAMETER_VOLUME_KNOB_CAPS_DELTA BIT7
|
||||
|
||||
#endif // EFI_HDA_VERBS_H
|
||||
105
Include/IndustryStandard/Riff.h
Normal file
105
Include/IndustryStandard/Riff.h
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* File: Riff.h
|
||||
*
|
||||
* Description: Resource Interchange File Format format definition.
|
||||
*
|
||||
* Copyright (c) 2018 John Davis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EFI_RIFF_H
|
||||
#define EFI_RIFF_H
|
||||
|
||||
/**
|
||||
See http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html.
|
||||
**/
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
//
|
||||
// RIFF chunk IDs.
|
||||
//
|
||||
#define RIFF_CHUNK_ID_SIZE 4
|
||||
#define RIFF_CHUNK_ID "RIFF"
|
||||
#define LIST_CHUNK_ID "LIST"
|
||||
#define PAL_CHUNK_ID "PAL "
|
||||
#define RDIB_CHUNK_ID "RDIB"
|
||||
#define RMID_CHUNK_ID "RMID"
|
||||
#define RMMP_CHUNK_ID "RMMP"
|
||||
|
||||
//
|
||||
// WAVE chunk IDs.
|
||||
//
|
||||
#define WAVE_CHUNK_ID "WAVE"
|
||||
#define WAVE_CUE_CHUNK_ID "cue "
|
||||
#define WAVE_DATA_CHUNK_ID "data"
|
||||
#define WAVE_FACT_CHUNK_ID "fact"
|
||||
#define WAVE_FILE_CHUNK_ID "file"
|
||||
#define WAVE_FORMAT_CHUNK_ID "fmt "
|
||||
#define WAVE_LABEL_CHUNK_ID "labl"
|
||||
#define WAVE_NOTE_CHUNK_ID "note"
|
||||
#define WAVE_PLAYLIST_CHUNK_ID "plst"
|
||||
#define WAVE_SILENCE_CHUNK_ID "slnt"
|
||||
#define WAVE_TEXT_DATA_CHUNK_ID "ltxt"
|
||||
#define WAVE_WAVE_LIST_CHUNK_ID "wavl"
|
||||
|
||||
//
|
||||
// WAVE format types.
|
||||
//
|
||||
#define WAVE_FORMAT_PCM 0x0001
|
||||
#define WAVE_FORMAT_EXTENSIBLE 0xFFFE
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
/**
|
||||
RIFF chunk.
|
||||
**/
|
||||
typedef struct {
|
||||
CHAR8 Id[RIFF_CHUNK_ID_SIZE];
|
||||
UINT32 Size;
|
||||
UINT8 Data[];
|
||||
} RIFF_CHUNK;
|
||||
|
||||
/**
|
||||
WAVE format data.
|
||||
**/
|
||||
typedef struct {
|
||||
UINT16 FormatTag;
|
||||
UINT16 Channels;
|
||||
UINT32 SamplesPerSec;
|
||||
UINT32 AvgBytesPerSec;
|
||||
UINT16 BlockAlign;
|
||||
UINT16 BitsPerSample;
|
||||
} WAVE_FORMAT_DATA;
|
||||
|
||||
/**
|
||||
WAVE format data extended.
|
||||
**/
|
||||
typedef struct {
|
||||
WAVE_FORMAT_DATA Header;
|
||||
UINT16 ExtensionSize;
|
||||
UINT16 ValidBitsPerSample;
|
||||
UINT32 ChannelMask;
|
||||
GUID SubFormat;
|
||||
} WAVE_FORMAT_DATA_EX;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#endif // EFI_RIFF_H
|
||||
153
Include/IndustryStandard/VirtualMemory.h
Executable file
153
Include/IndustryStandard/VirtualMemory.h
Executable file
@ -0,0 +1,153 @@
|
||||
/** @file
|
||||
x64 Long Mode Virtual Memory Management Definitions
|
||||
|
||||
References:
|
||||
1) IA-32 Intel(R) Architecture Software Developer's Manual Volume 1:Basic Architecture, Intel
|
||||
2) IA-32 Intel(R) Architecture Software Developer's Manual Volume 2:Instruction Set Reference, Intel
|
||||
3) IA-32 Intel(R) Architecture Software Developer's Manual Volume 3:System Programmer's Guide, Intel
|
||||
4) AMD64 Architecture Programmer's Manual Volume 2: System Programming
|
||||
|
||||
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
|
||||
Copyright (c) 2011, dmazar. All rights reserved.<BR>
|
||||
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#ifndef VIRTUAL_MEMORY_H
|
||||
#define VIRTUAL_MEMORY_H
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
//
|
||||
// Page-Map Level-4 Offset (PML4) and
|
||||
// Page-Directory-Pointer Offset (PDPE) entries 4K & 2MB
|
||||
//
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
|
||||
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
|
||||
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
|
||||
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
|
||||
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
|
||||
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
|
||||
UINT64 Reserved:1; // Reserved
|
||||
UINT64 MustBeZero:2; // Must Be Zero
|
||||
UINT64 Available:3; // Available for use by system software
|
||||
UINT64 PageTableBaseAddress:40; // Page Table Base Address
|
||||
UINT64 AvabilableHigh:11; // Available for use by system software
|
||||
UINT64 Nx:1; // No Execute bit
|
||||
} Bits;
|
||||
UINT64 Uint64;
|
||||
} PAGE_MAP_AND_DIRECTORY_POINTER;
|
||||
|
||||
//
|
||||
// Page Table Entry 4KB
|
||||
//
|
||||
typedef union {
|
||||
struct {
|
||||
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
|
||||
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
|
||||
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
|
||||
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
|
||||
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
|
||||
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
|
||||
UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
|
||||
UINT64 PAT:1; //
|
||||
UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
|
||||
UINT64 Available:3; // Available for use by system software
|
||||
UINT64 PageTableBaseAddress:40; // Page Table Base Address
|
||||
UINT64 AvabilableHigh:11; // Available for use by system software
|
||||
UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
|
||||
} Bits;
|
||||
UINT64 Uint64;
|
||||
} PAGE_TABLE_4K_ENTRY;
|
||||
|
||||
//
|
||||
// Page Table Entry 2MB
|
||||
//
|
||||
typedef union {
|
||||
struct {
|
||||
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
|
||||
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
|
||||
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
|
||||
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
|
||||
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
|
||||
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
|
||||
UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
|
||||
UINT64 MustBe1:1; // Must be 1
|
||||
UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
|
||||
UINT64 Available:3; // Available for use by system software
|
||||
UINT64 PAT:1; //
|
||||
UINT64 MustBeZero:8; // Must be zero;
|
||||
UINT64 PageTableBaseAddress:31; // Page Table Base Address
|
||||
UINT64 AvabilableHigh:11; // Available for use by system software
|
||||
UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
|
||||
} Bits;
|
||||
UINT64 Uint64;
|
||||
} PAGE_TABLE_2M_ENTRY;
|
||||
|
||||
//
|
||||
// Page Table Entry 1GB
|
||||
//
|
||||
typedef union {
|
||||
struct {
|
||||
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
|
||||
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
|
||||
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
|
||||
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
|
||||
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
|
||||
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
|
||||
UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
|
||||
UINT64 MustBe1:1; // Must be 1
|
||||
UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
|
||||
UINT64 Available:3; // Available for use by system software
|
||||
UINT64 PAT:1; //
|
||||
UINT64 MustBeZero:17; // Must be zero;
|
||||
UINT64 PageTableBaseAddress:22; // Page Table Base Address
|
||||
UINT64 AvabilableHigh:11; // Available for use by system software
|
||||
UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
|
||||
} Bits;
|
||||
UINT64 Uint64;
|
||||
} PAGE_TABLE_1G_ENTRY;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
UINT64 PhysPgOffset:12; // 0 = Physical Page Offset
|
||||
UINT64 PTOffset:9; // 0 = Page Table Offset
|
||||
UINT64 PDOffset:9; // 0 = Page Directory Offset
|
||||
UINT64 PDPOffset:9; // 0 = Page Directory Pointer Offset
|
||||
UINT64 PML4Offset:9; // 0 = Page Map Level 4 Offset
|
||||
UINT64 SignExtend:16; // 0 = Sign Extend
|
||||
} Pg4K;
|
||||
struct {
|
||||
UINT64 PhysPgOffset:21; // 0 = Physical Page Offset
|
||||
UINT64 PDOffset:9; // 0 = Page Directory Offset
|
||||
UINT64 PDPOffset:9; // 0 = Page Directory Pointer Offset
|
||||
UINT64 PML4Offset:9; // 0 = Page Map Level 4 Offset
|
||||
UINT64 SignExtend:16; // 0 = Sign Extend
|
||||
} Pg2M;
|
||||
struct {
|
||||
UINT64 PhysPgOffset:30; // 0 = Physical Page Offset
|
||||
UINT64 PDPOffset:9; // 0 = Page Directory Pointer Offset
|
||||
UINT64 PML4Offset:9; // 0 = Page Map Level 4 Offset
|
||||
UINT64 SignExtend:16; // 0 = Sign Extend
|
||||
} Pg1G;
|
||||
UINT64 Uint64;
|
||||
} VIRTUAL_ADDR;
|
||||
|
||||
#define VA_FIX_SIGN_EXTEND(VA) ((VA).Pg4K.SignExtend = ((VA).Pg4K.PML4Offset & 0x100U) ? 0xFFFFU : 0U);
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#define CR3_ADDR_MASK 0x000FFFFFFFFFF000ull
|
||||
#define CR3_FLAG_PWT 0x0000000000000008ull
|
||||
#define CR3_FLAG_PCD 0x0000000000000010ull
|
||||
|
||||
#define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull
|
||||
#define PAGING_2M_ADDRESS_MASK_64 0x000FFFFFFFE00000ull
|
||||
#define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull
|
||||
|
||||
#endif // VIRTUAL_MEMORY_H
|
||||
296
Include/Library/OcAcpiLib.h
Executable file
296
Include/Library/OcAcpiLib.h
Executable file
@ -0,0 +1,296 @@
|
||||
/** @file
|
||||
Copyright (C) 2016, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_ACPI_LIB_H
|
||||
#define OC_ACPI_LIB_H
|
||||
|
||||
#include <IndustryStandard/Acpi62.h>
|
||||
|
||||
#define OC_ACPI_NAME_SIZE 4
|
||||
|
||||
//
|
||||
// RSDP and XSDT table definitions not provided by EDK2 due to no
|
||||
// flexible array support.
|
||||
//
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct {
|
||||
EFI_ACPI_DESCRIPTION_HEADER Header;
|
||||
UINT32 Tables[];
|
||||
} OC_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_TABLE;
|
||||
|
||||
typedef struct {
|
||||
EFI_ACPI_DESCRIPTION_HEADER Header;
|
||||
UINT64 Tables[];
|
||||
} OC_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
//
|
||||
// Operation region structure.
|
||||
//
|
||||
typedef struct {
|
||||
//
|
||||
// Region address.
|
||||
//
|
||||
UINT32 Address;
|
||||
//
|
||||
// Region name, not guaranteed to be null-terminated.
|
||||
//
|
||||
CHAR8 Name[OC_ACPI_NAME_SIZE+1];
|
||||
} OC_ACPI_REGION;
|
||||
|
||||
//
|
||||
// Main ACPI context describing current tableset worked on.
|
||||
//
|
||||
typedef struct {
|
||||
//
|
||||
// Pointer to original RSDP table.
|
||||
//
|
||||
EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;
|
||||
//
|
||||
// Pointer to active RSDT table.
|
||||
//
|
||||
OC_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_TABLE *Rsdt;
|
||||
//
|
||||
// Pointer to active XSDT table.
|
||||
//
|
||||
OC_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE *Xsdt;
|
||||
//
|
||||
// Pointer to active FADT table.
|
||||
//
|
||||
EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;
|
||||
//
|
||||
// Pointer to active DSDT table.
|
||||
//
|
||||
EFI_ACPI_DESCRIPTION_HEADER *Dsdt;
|
||||
//
|
||||
// Current list of tables allocated from heap.
|
||||
//
|
||||
EFI_ACPI_COMMON_HEADER **Tables;
|
||||
//
|
||||
// Number of tables.
|
||||
//
|
||||
UINT32 NumberOfTables;
|
||||
//
|
||||
// Number of allocated table slots.
|
||||
//
|
||||
UINT32 AllocatedTables;
|
||||
//
|
||||
// Detected operation regions if any.
|
||||
//
|
||||
OC_ACPI_REGION *Regions;
|
||||
//
|
||||
// Number of regions.
|
||||
//
|
||||
UINT32 NumberOfRegions;
|
||||
//
|
||||
// Number of allocated region slots.
|
||||
//
|
||||
UINT32 AllocatedRegions;
|
||||
} OC_ACPI_CONTEXT;
|
||||
|
||||
//
|
||||
// ACPI patch structure.
|
||||
//
|
||||
typedef struct {
|
||||
//
|
||||
// Find bytes.
|
||||
//
|
||||
CONST UINT8 *Find;
|
||||
//
|
||||
// Replace bytes.
|
||||
//
|
||||
CONST UINT8 *Replace;
|
||||
//
|
||||
// Find mask or NULL.
|
||||
//
|
||||
CONST UINT8 *Mask;
|
||||
//
|
||||
// Replace mask or NULL.
|
||||
//
|
||||
CONST UINT8 *ReplaceMask;
|
||||
//
|
||||
// Patch size.
|
||||
//
|
||||
UINT32 Size;
|
||||
//
|
||||
// Replace count or 0 for all.
|
||||
//
|
||||
UINT32 Count;
|
||||
//
|
||||
// Skip count or 0 to start from 1 match.
|
||||
//
|
||||
UINT32 Skip;
|
||||
//
|
||||
// Limit replacement size to this value or 0, which assumes table size.
|
||||
//
|
||||
UINT32 Limit;
|
||||
//
|
||||
// ACPI Table signature or 0.
|
||||
//
|
||||
UINT32 TableSignature;
|
||||
//
|
||||
// ACPI Table length or 0.
|
||||
//
|
||||
UINT32 TableLength;
|
||||
//
|
||||
// ACPI Table Id or 0.
|
||||
//
|
||||
UINT64 OemTableId;
|
||||
} OC_ACPI_PATCH;
|
||||
|
||||
/**
|
||||
Find ACPI System Tables for later table configuration.
|
||||
|
||||
@param Context ACPI library context.
|
||||
|
||||
@return EFI_SUCCESS when Rsdp and Xsdt or Rsdt are found.
|
||||
**/
|
||||
EFI_STATUS
|
||||
AcpiInitContext (
|
||||
IN OUT OC_ACPI_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Free ACPI context dynamic resources.
|
||||
|
||||
@param Context ACPI library context.
|
||||
**/
|
||||
VOID
|
||||
AcpiFreeContext (
|
||||
IN OUT OC_ACPI_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Apply ACPI context to this system.
|
||||
|
||||
@param Context ACPI library context.
|
||||
**/
|
||||
EFI_STATUS
|
||||
AcpiApplyContext (
|
||||
IN OUT OC_ACPI_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Drop one ACPI table.
|
||||
|
||||
@param Context ACPI library context.
|
||||
@param Signature Table signature or 0.
|
||||
@param Length Table length or 0.
|
||||
@param OemTableId Table Id or 0.
|
||||
@param All Drop all tables or first matched.
|
||||
**/
|
||||
EFI_STATUS
|
||||
AcpiDropTable (
|
||||
IN OUT OC_ACPI_CONTEXT *Context,
|
||||
IN UINT32 Signature,
|
||||
IN UINT32 Length,
|
||||
IN UINT64 OemTableId,
|
||||
IN BOOLEAN All
|
||||
);
|
||||
|
||||
/**
|
||||
Install one ACPI table. For DSDT this performs table replacement.
|
||||
|
||||
@param Context ACPI library context.
|
||||
@param Data Table data.
|
||||
@param Length Table length.
|
||||
**/
|
||||
EFI_STATUS
|
||||
AcpiInsertTable (
|
||||
IN OUT OC_ACPI_CONTEXT *Context,
|
||||
IN CONST UINT8 *Data,
|
||||
IN UINT32 Length
|
||||
);
|
||||
|
||||
/**
|
||||
Normalise ACPI headers to contain 7-bit ASCII.
|
||||
|
||||
@param Context ACPI library context.
|
||||
**/
|
||||
VOID
|
||||
AcpiNormalizeHeaders (
|
||||
IN OUT OC_ACPI_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Patch ACPI tables.
|
||||
|
||||
@param Context ACPI library context.
|
||||
@param Patch ACPI patch.
|
||||
**/
|
||||
EFI_STATUS
|
||||
AcpiApplyPatch (
|
||||
IN OUT OC_ACPI_CONTEXT *Context,
|
||||
IN OC_ACPI_PATCH *Patch
|
||||
);
|
||||
|
||||
/**
|
||||
Try to load ACPI regions.
|
||||
|
||||
@param Context ACPI library context.
|
||||
**/
|
||||
EFI_STATUS
|
||||
AcpiLoadRegions (
|
||||
IN OUT OC_ACPI_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Attempt to relocate ACPI regions based on loaded ones.
|
||||
|
||||
@param Context ACPI library context.
|
||||
**/
|
||||
VOID
|
||||
AcpiRelocateRegions (
|
||||
IN OUT OC_ACPI_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Upgrade FADT to support reset register needed on very
|
||||
old legacy hardware.
|
||||
|
||||
@param Context ACPI library context.
|
||||
|
||||
@return EFI_SUCCESS if successful or not needed.
|
||||
**/
|
||||
EFI_STATUS
|
||||
AcpiFadtEnableReset (
|
||||
IN OUT OC_ACPI_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Reset BGRT Displayed status.
|
||||
|
||||
@param Context ACPI library context.
|
||||
**/
|
||||
VOID
|
||||
AcpiResetLogoStatus (
|
||||
IN OUT OC_ACPI_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Log and reset FACS hardware signature.
|
||||
|
||||
@param Context ACPI library context.
|
||||
@param Reset Perform reset.
|
||||
**/
|
||||
VOID
|
||||
AcpiHandleHardwareSignature (
|
||||
IN OUT OC_ACPI_CONTEXT *Context,
|
||||
IN BOOLEAN Reset
|
||||
);
|
||||
|
||||
#endif // OC_ACPI_LIB_H
|
||||
120
Include/Library/OcAppleBootCompatLib.h
Normal file
120
Include/Library/OcAppleBootCompatLib.h
Normal file
@ -0,0 +1,120 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_BOOT_COMPAT_LIB_H
|
||||
#define OC_APPLE_BOOT_COMPAT_LIB_H
|
||||
|
||||
/**
|
||||
Apple Boot Compatibility layer configuration.
|
||||
**/
|
||||
typedef struct OC_ABC_SETTINGS_ {
|
||||
///
|
||||
/// Protect from boot.efi from defragmenting runtime memory. This fixes UEFI runtime services
|
||||
/// (date and time, NVRAM, power control, etc.) support on many firmwares.
|
||||
/// Needed basically by everyone that uses SMM implementation of variable services.
|
||||
///
|
||||
BOOLEAN AvoidRuntimeDefrag;
|
||||
///
|
||||
/// Setup virtual memory mapping after SetVirtualAddresses call. This fixes crashes in many
|
||||
/// firmwares at early boot as they accidentally access virtual addresses after ExitBootServices.
|
||||
///
|
||||
BOOLEAN SetupVirtualMap;
|
||||
///
|
||||
/// Provide custom Apple KASLR slide calculation for firmwares with polluted low memory ranges.
|
||||
/// This also ensures that slide= argument is never passed to the operating system.
|
||||
///
|
||||
BOOLEAN ProvideCustomSlide;
|
||||
///
|
||||
/// Remove runtime flag from MMIO areas and prevent virtual address assignment for known
|
||||
/// MMIO regions. This may improve the amount of slides available, but may not work on
|
||||
/// unknown configurations.
|
||||
///
|
||||
BOOLEAN DevirtualiseMmio;
|
||||
///
|
||||
/// Disable passing -s to operating system through key presses, to simulate T2 Mac behaviour.
|
||||
/// Ref: https://support.apple.com/HT201573
|
||||
///
|
||||
BOOLEAN DisableSingleUser;
|
||||
///
|
||||
/// Discard UEFI memory map after waking from hibernation and preserve the original mapping.
|
||||
///
|
||||
BOOLEAN DiscardHibernateMap;
|
||||
///
|
||||
/// Try to patch Apple bootloader to have KASLR enabled even in SafeMode.
|
||||
///
|
||||
BOOLEAN EnableSafeModeSlide;
|
||||
///
|
||||
/// Attempt to protect certain CSM memory regions from being used by the kernel.
|
||||
/// On older firmwares this caused wake issues.
|
||||
///
|
||||
BOOLEAN ProtectCsmRegion;
|
||||
///
|
||||
/// Attempt to reduce memory map entries through grouping to fit into Apple kernel.
|
||||
///
|
||||
BOOLEAN ShrinkMemoryMap;
|
||||
///
|
||||
/// Ensure that ExitBootServices call succeeds even with outdated MemoryMap key.
|
||||
///
|
||||
BOOLEAN ForceExitBootServices;
|
||||
///
|
||||
/// Disable NVRAM variable write support to protect from malware or to prevent
|
||||
/// buggy NVRAM implementations cause system issues.
|
||||
///
|
||||
BOOLEAN DisableVariableWrite;
|
||||
///
|
||||
/// Protect secure boot variables.
|
||||
///
|
||||
BOOLEAN ProtectSecureBoot;
|
||||
///
|
||||
/// Permit writing to executable memory in UEFI runtime services. Fixes crashes
|
||||
/// on many APTIO V firmwares.
|
||||
///
|
||||
BOOLEAN EnableWriteUnprotector;
|
||||
///
|
||||
/// Signal OSInfo protocol that every loaded non-macOS OS is macOS.
|
||||
/// Works around disabled IGPU in Windows and Linux on Apple laptops.
|
||||
///
|
||||
BOOLEAN SignalAppleOS;
|
||||
///
|
||||
/// List of physical addresses to not be devirtualised by DevirtualiseMmio.
|
||||
///
|
||||
EFI_PHYSICAL_ADDRESS *MmioWhitelist;
|
||||
///
|
||||
/// Size of list of physical addresses to not be devirtualised by DevirtualiseMmio.
|
||||
///
|
||||
UINTN MmioWhitelistSize;
|
||||
///
|
||||
/// List of NULL-terminated handlers for TPL_APPLICATION execution within ExitBootServices.
|
||||
///
|
||||
EFI_EVENT_NOTIFY *ExitBootServicesHandlers;
|
||||
///
|
||||
/// List of handler contexts for ExitBootServicesHandlers.
|
||||
///
|
||||
VOID **ExitBootServicesHandlerContexts;
|
||||
} OC_ABC_SETTINGS;
|
||||
|
||||
/**
|
||||
Initialize Apple Boot Compatibility layer. This layer is needed on partially
|
||||
incompatible firmwares to prevent boot failure and UEFI services breakage.
|
||||
|
||||
@param[in] Settings Compatibility layer configuration.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcAbcInitialize (
|
||||
IN OC_ABC_SETTINGS *Settings
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_BOOT_COMPAT_LIB_H
|
||||
42
Include/Library/OcAppleBootPolicyLib.h
Executable file
42
Include/Library/OcAppleBootPolicyLib.h
Executable file
@ -0,0 +1,42 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_BOOT_POLICY_LIB_H
|
||||
#define OC_APPLE_BOOT_POLICY_LIB_H
|
||||
|
||||
#include <Protocol/AppleBootPolicy.h>
|
||||
|
||||
/**
|
||||
Install and initialise Apple Boot policy protocol.
|
||||
|
||||
@param[in] Overwrite Overwrite installed protocol.
|
||||
|
||||
@retval installed or located protocol or NULL.
|
||||
**/
|
||||
APPLE_BOOT_POLICY_PROTOCOL *
|
||||
OcAppleBootPolicyInstallProtocol (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
OcGetBooterFromPredefinedNameList (
|
||||
IN EFI_HANDLE Device,
|
||||
IN EFI_FILE_PROTOCOL *Root,
|
||||
IN CONST CHAR16 **BootPathNames,
|
||||
IN UINTN NumBootPathNames,
|
||||
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath OPTIONAL,
|
||||
IN CHAR16 *Prefix OPTIONAL
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_BOOT_POLICY_LIB_H
|
||||
77
Include/Library/OcAppleChunklistLib.h
Normal file
77
Include/Library/OcAppleChunklistLib.h
Normal file
@ -0,0 +1,77 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, Goldfish64. All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef APPLE_CHUNKLIST_LIB_H
|
||||
#define APPLE_CHUNKLIST_LIB_H
|
||||
|
||||
#include <IndustryStandard/AppleChunklist.h>
|
||||
|
||||
#include <Library/OcAppleRamDiskLib.h>
|
||||
#include <Library/OcCryptoLib.h>
|
||||
|
||||
//
|
||||
// Chunklist context.
|
||||
//
|
||||
typedef struct OC_APPLE_CHUNKLIST_CONTEXT_ {
|
||||
UINTN ChunkCount;
|
||||
CONST APPLE_CHUNKLIST_CHUNK *Chunks;
|
||||
APPLE_CHUNKLIST_SIG *Signature;
|
||||
UINT8 Hash[SHA256_DIGEST_SIZE];
|
||||
} OC_APPLE_CHUNKLIST_CONTEXT;
|
||||
|
||||
//
|
||||
// Chunklist functions.
|
||||
//
|
||||
|
||||
/**
|
||||
Initializes a chunklist context.
|
||||
|
||||
@param[out] Context The Context to initialize.
|
||||
@param[in] Buffer A pointer to a buffer containing the chunklist data.
|
||||
@param[in] BufferSize The size of the buffer specified in Buffer.
|
||||
|
||||
@retval EFI_SUCCESS The Context was intialized successfully.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
@retval EFI_UNSUPPORTED The chunklist is unsupported.
|
||||
**/
|
||||
BOOLEAN
|
||||
OcAppleChunklistInitializeContext (
|
||||
OUT OC_APPLE_CHUNKLIST_CONTEXT *Context,
|
||||
IN VOID *Buffer,
|
||||
IN UINT32 BufferSize
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcAppleChunklistVerifySignature (
|
||||
IN OUT OC_APPLE_CHUNKLIST_CONTEXT *Context,
|
||||
IN CONST OC_RSA_PUBLIC_KEY *PublicKey
|
||||
);
|
||||
|
||||
/**
|
||||
Verifies the specified data against a chunklist context.
|
||||
|
||||
@param[in] Context The Context to verify against.
|
||||
@param[in] ExtentTable A pointer to the RAM disk extent table to be
|
||||
verified.
|
||||
|
||||
@retval EFI_SUCCESS The data was verified successfully.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
@retval EFI_END_OF_FILE The end of Buffer was reached.
|
||||
@retval EFI_COMPROMISED_DATA The data failed verification.
|
||||
**/
|
||||
BOOLEAN
|
||||
OcAppleChunklistVerifyData (
|
||||
IN OUT OC_APPLE_CHUNKLIST_CONTEXT *Context,
|
||||
IN CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable
|
||||
);
|
||||
|
||||
#endif // APPLE_CHUNKLIST_LIB_H
|
||||
85
Include/Library/OcAppleDiskImageLib.h
Normal file
85
Include/Library/OcAppleDiskImageLib.h
Normal file
@ -0,0 +1,85 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, Goldfish64. All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef APPLE_DISK_IMAGE_LIB_H_
|
||||
#define APPLE_DISK_IMAGE_LIB_H_
|
||||
|
||||
#include <IndustryStandard/AppleDiskImage.h>
|
||||
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
|
||||
#include <Library/OcAppleChunklistLib.h>
|
||||
#include <Library/OcAppleRamDiskLib.h>
|
||||
|
||||
//
|
||||
// Disk image context.
|
||||
//
|
||||
typedef struct {
|
||||
CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable;
|
||||
|
||||
UINTN SectorCount;
|
||||
|
||||
UINT32 BlockCount;
|
||||
APPLE_DISK_IMAGE_BLOCK_DATA **Blocks;
|
||||
} OC_APPLE_DISK_IMAGE_CONTEXT;
|
||||
|
||||
BOOLEAN
|
||||
OcAppleDiskImageInitializeContext (
|
||||
OUT OC_APPLE_DISK_IMAGE_CONTEXT *Context,
|
||||
IN CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable,
|
||||
IN UINTN FileSize
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcAppleDiskImageInitializeFromFile (
|
||||
OUT OC_APPLE_DISK_IMAGE_CONTEXT *Context,
|
||||
IN EFI_FILE_PROTOCOL *File
|
||||
);
|
||||
|
||||
VOID
|
||||
OcAppleDiskImageFreeContext (
|
||||
IN OC_APPLE_DISK_IMAGE_CONTEXT *Context
|
||||
);
|
||||
VOID
|
||||
OcAppleDiskImageFreeFile (
|
||||
IN OC_APPLE_DISK_IMAGE_CONTEXT *Context
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcAppleDiskImageVerifyData (
|
||||
IN OUT OC_APPLE_DISK_IMAGE_CONTEXT *Context,
|
||||
IN OUT OC_APPLE_CHUNKLIST_CONTEXT *ChunklistContext
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcAppleDiskImageRead (
|
||||
IN OC_APPLE_DISK_IMAGE_CONTEXT *Context,
|
||||
IN UINTN Lba,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_HANDLE
|
||||
OcAppleDiskImageInstallBlockIo (
|
||||
IN OC_APPLE_DISK_IMAGE_CONTEXT *Context,
|
||||
IN UINTN FileSize,
|
||||
OUT CONST EFI_DEVICE_PATH_PROTOCOL **DevicePath OPTIONAL,
|
||||
OUT UINTN *DevicePathSize OPTIONAL
|
||||
);
|
||||
|
||||
VOID
|
||||
OcAppleDiskImageUninstallBlockIo (
|
||||
IN OC_APPLE_DISK_IMAGE_CONTEXT *Context,
|
||||
IN VOID *BlockIoHandle
|
||||
);
|
||||
|
||||
#endif
|
||||
33
Include/Library/OcAppleEventLib.h
Normal file
33
Include/Library/OcAppleEventLib.h
Normal file
@ -0,0 +1,33 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, Download-Fritz. All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_EVENT_LIB_H
|
||||
#define OC_APPLE_EVENT_LIB_H
|
||||
|
||||
#include <IndustryStandard/AppleHid.h>
|
||||
|
||||
#include <Protocol/AppleEvent.h>
|
||||
|
||||
/**
|
||||
Install and initialise Apple Event protocol.
|
||||
|
||||
@param[in] Reinstall Overwrite installed protocol.
|
||||
|
||||
@retval installed or located protocol or NULL.
|
||||
**/
|
||||
APPLE_EVENT_PROTOCOL *
|
||||
OcAppleEventInstallProtocol (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_EVENT_LIB_H
|
||||
34
Include/Library/OcAppleImageConversionLib.h
Normal file
34
Include/Library/OcAppleImageConversionLib.h
Normal file
@ -0,0 +1,34 @@
|
||||
/** @file
|
||||
Copyright (C) 2018 savvas. All rights reserved.<BR>
|
||||
Portions copyright (C) 2016 slice. All rights reserved.<BR>
|
||||
Portions 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.
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_IMAGE_CONVERSION_LIB_H
|
||||
#define OC_APPLE_IMAGE_CONVERSION_LIB_H
|
||||
|
||||
#include <Protocol/UgaDraw.h>
|
||||
#include <Protocol/AppleImageConversion.h>
|
||||
|
||||
/**
|
||||
Install and initialise the Apple Image Conversion protocol.
|
||||
|
||||
@param[in] Reinstall Replace any installed protocol.
|
||||
|
||||
@returns Installed or located protocol.
|
||||
@retval NULL There was an error locating or installing the protocol.
|
||||
**/
|
||||
APPLE_IMAGE_CONVERSION_PROTOCOL *
|
||||
OcAppleImageConversionInstallProtocol (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_IMAGE_CONVERSION_LIB_H
|
||||
91
Include/Library/OcAppleImageVerificationLib.h
Normal file
91
Include/Library/OcAppleImageVerificationLib.h
Normal file
@ -0,0 +1,91 @@
|
||||
/** @file
|
||||
|
||||
OcAppleImageVerificationLib
|
||||
|
||||
Copyright (c) 2018, savvas
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef APPLE_DXE_IMAGE_VERIFICATION_H
|
||||
#define APPLE_DXE_IMAGE_VERIFICATION_H
|
||||
|
||||
#include <IndustryStandard/PeImage.h>
|
||||
|
||||
#define APPLE_SIGNATURE_SECENTRY_SIZE 8
|
||||
|
||||
typedef struct APPLE_PE_COFF_LOADER_IMAGE_CONTEXT_ {
|
||||
UINT64 ImageAddress;
|
||||
UINT64 ImageSize;
|
||||
UINT64 EntryPoint;
|
||||
UINT64 SizeOfHeaders;
|
||||
UINT16 ImageType;
|
||||
UINT16 NumberOfSections;
|
||||
UINT32 *OptHdrChecksum;
|
||||
UINT32 SizeOfOptionalHeader;
|
||||
UINT64 SumOfSectionBytes;
|
||||
EFI_IMAGE_SECTION_HEADER *FirstSection;
|
||||
EFI_IMAGE_DATA_DIRECTORY *RelocDir;
|
||||
EFI_IMAGE_DATA_DIRECTORY *SecDir;
|
||||
UINT64 NumberOfRvaAndSizes;
|
||||
UINT16 PeHdrMagic;
|
||||
EFI_IMAGE_OPTIONAL_HEADER_UNION *PeHdr;
|
||||
UINT8 PeImageHash[32];
|
||||
} APPLE_PE_COFF_LOADER_IMAGE_CONTEXT;
|
||||
|
||||
//
|
||||
// Signature context
|
||||
//
|
||||
typedef struct APPLE_SIGNATURE_CONTEXT_ {
|
||||
UINT8 PublicKey[256];
|
||||
UINT8 PublicKeyHash[32];
|
||||
UINT8 Signature[256];
|
||||
} APPLE_SIGNATURE_CONTEXT;
|
||||
|
||||
//
|
||||
// Function prototypes
|
||||
//
|
||||
EFI_STATUS
|
||||
BuildPeContext (
|
||||
VOID *Image,
|
||||
UINTN ImageSize,
|
||||
APPLE_PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
||||
);
|
||||
|
||||
VOID
|
||||
SanitizeApplePeImage (
|
||||
VOID *Image,
|
||||
UINTN *RealImageSize,
|
||||
APPLE_PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
GetApplePeImageSignature (
|
||||
VOID *Image,
|
||||
UINTN ImageSize,
|
||||
APPLE_PE_COFF_LOADER_IMAGE_CONTEXT *Context,
|
||||
APPLE_SIGNATURE_CONTEXT *SignatureContext
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
GetApplePeImageSha256 (
|
||||
VOID *Image,
|
||||
APPLE_PE_COFF_LOADER_IMAGE_CONTEXT *Context
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
VerifyApplePeImageSignature (
|
||||
IN OUT VOID *PeImage,
|
||||
IN OUT UINTN *ImageSize
|
||||
);
|
||||
|
||||
#endif //APPLE_DXE_IMAGE_VERIFICATION_H
|
||||
50
Include/Library/OcAppleImg4Lib.h
Normal file
50
Include/Library/OcAppleImg4Lib.h
Normal file
@ -0,0 +1,50 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, Download-Fritz. All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_IMG4_LIB_H
|
||||
#define OC_APPLE_IMG4_LIB_H
|
||||
|
||||
/**
|
||||
Verify the signature of ImageBuffer against Type of its IMG4 Manifest.
|
||||
|
||||
@param[in] This The pointer to the current protocol instance.
|
||||
@param[in] ObjType The IMG4 object type to validate against.
|
||||
@param[in] ImageBuffer The buffer to validate.
|
||||
@param[in] ImageSize The size, in bytes, of ImageBuffer.
|
||||
@param[in] SbMode The requested IMG4 Secure Boot mode.
|
||||
@param[in] ManifestBuffer The buffer of the IMG4 Manifest.
|
||||
@param[in] ManifestSize The size, in bytes, of ManifestBuffer.
|
||||
@param[out] HashDigest On output, a pointer to ImageBuffer's digest.
|
||||
@param[out] DigestSize On output, the size, in bytes, of *HashDigest.
|
||||
|
||||
@retval EFI_SUCCESS ImageBuffer is correctly signed.
|
||||
@retval EFI_INVALID_PARAMETER One or more required parameters are NULL.
|
||||
@retval EFI_OUT_OF_RESOURCES Not enough resources are available.
|
||||
@retval EFI_SECURITY_VIOLATION ImageBuffer's signature is invalid.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AppleImg4Verify (
|
||||
IN APPLE_IMG4_VERIFICATION_PROTOCOL *This,
|
||||
IN UINT32 ObjType,
|
||||
IN CONST VOID *ImageBuffer,
|
||||
IN UINTN ImageSize,
|
||||
IN UINT8 SbMode,
|
||||
IN CONST VOID *ManifestBuffer,
|
||||
IN UINTN ManifestSize,
|
||||
OUT UINT8 **HashDigest OPTIONAL,
|
||||
OUT UINTN *DigestSize OPTIONAL
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_IMG4_LIB_H
|
||||
589
Include/Library/OcAppleKernelLib.h
Normal file
589
Include/Library/OcAppleKernelLib.h
Normal file
@ -0,0 +1,589 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_KERNEL_LIB_H
|
||||
#define OC_APPLE_KERNEL_LIB_H
|
||||
|
||||
#include <Library/OcCpuLib.h>
|
||||
#include <Library/OcMachoLib.h>
|
||||
#include <Library/OcXmlLib.h>
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
|
||||
#define PRELINK_KERNEL_IDENTIFIER "__kernel__"
|
||||
#define PRELINK_KPI_IDENTIFIER_PREFIX "com.apple.kpi."
|
||||
|
||||
#define PRELINK_INFO_SEGMENT "__PRELINK_INFO"
|
||||
#define PRELINK_INFO_SECTION "__info"
|
||||
#define PRELINK_TEXT_SEGMENT "__PRELINK_TEXT"
|
||||
#define PRELINK_TEXT_SECTION "__text"
|
||||
|
||||
#define PRELINK_INFO_DICTIONARY_KEY "_PrelinkInfoDictionary"
|
||||
#define PRELINK_INFO_KMOD_INFO_KEY "_PrelinkKmodInfo"
|
||||
#define PRELINK_INFO_BUNDLE_PATH_KEY "_PrelinkBundlePath"
|
||||
#define PRELINK_INFO_EXECUTABLE_RELATIVE_PATH_KEY "_PrelinkExecutableRelativePath"
|
||||
#define PRELINK_INFO_EXECUTABLE_LOAD_ADDR_KEY "_PrelinkExecutableLoadAddr"
|
||||
#define PRELINK_INFO_EXECUTABLE_SOURCE_ADDR_KEY "_PrelinkExecutableSourceAddr"
|
||||
#define PRELINK_INFO_EXECUTABLE_SIZE_KEY "_PrelinkExecutableSize"
|
||||
|
||||
#define INFO_BUNDLE_IDENTIFIER_KEY "CFBundleIdentifier"
|
||||
#define INFO_BUNDLE_EXECUTABLE_KEY "CFBundleExecutable"
|
||||
#define INFO_BUNDLE_LIBRARIES_KEY "OSBundleLibraries"
|
||||
#define INFO_BUNDLE_LIBRARIES_64_KEY "OSBundleLibraries_x86_64"
|
||||
#define INFO_BUNDLE_VERSION_KEY "CFBundleVersion"
|
||||
#define INFO_BUNDLE_COMPATIBLE_VERSION_KEY "OSBundleCompatibleVersion"
|
||||
|
||||
|
||||
#define PRELINK_INFO_INTEGER_ATTRIBUTES "size=\"64\""
|
||||
|
||||
//
|
||||
// Failsafe default for plist reserve allocation.
|
||||
//
|
||||
#define PRELINK_INFO_RESERVE_SIZE (5U * 1024U * 1024U)
|
||||
|
||||
//
|
||||
// Prelinked context used for kernel modification.
|
||||
//
|
||||
typedef struct {
|
||||
//
|
||||
// Current version of prelinkedkernel. It takes a reference of user-allocated
|
||||
// memory block from pool, and grows if needed.
|
||||
//
|
||||
UINT8 *Prelinked;
|
||||
//
|
||||
// Exportable prelinkedkernel size, i.e. the payload size. Also references user field.
|
||||
//
|
||||
UINT32 PrelinkedSize;
|
||||
//
|
||||
// Currently allocated prelinkedkernel size, used for reduced rellocations.
|
||||
//
|
||||
UINT32 PrelinkedAllocSize;
|
||||
//
|
||||
// Current last virtual address (kext source files and plist are put here).
|
||||
//
|
||||
UINT64 PrelinkedLastAddress;
|
||||
//
|
||||
// Current last virtual load address (kexts are loaded here after kernel startup).
|
||||
//
|
||||
UINT64 PrelinkedLastLoadAddress;
|
||||
//
|
||||
// Mach-O context for prelinkedkernel.
|
||||
//
|
||||
OC_MACHO_CONTEXT PrelinkedMachContext;
|
||||
//
|
||||
// Pointer to PRELINK_INFO_SEGMENT.
|
||||
//
|
||||
MACH_SEGMENT_COMMAND_64 *PrelinkedInfoSegment;
|
||||
//
|
||||
// Pointer to PRELINK_INFO_SECTION.
|
||||
//
|
||||
MACH_SECTION_64 *PrelinkedInfoSection;
|
||||
//
|
||||
// Pointer to PRELINK_TEXT_SEGMENT.
|
||||
//
|
||||
MACH_SEGMENT_COMMAND_64 *PrelinkedTextSegment;
|
||||
//
|
||||
// Pointer to PRELINK_TEXT_SECTION.
|
||||
//
|
||||
MACH_SECTION_64 *PrelinkedTextSection;
|
||||
//
|
||||
// Copy of prelinkedkernel PRELINK_INFO_SECTION used for XML_DOCUMENT.
|
||||
// Freed upon context destruction.
|
||||
//
|
||||
CHAR8 *PrelinkedInfo;
|
||||
//
|
||||
// Parsed instance of PlistInfo. New entries are added here.
|
||||
//
|
||||
XML_DOCUMENT *PrelinkedInfoDocument;
|
||||
//
|
||||
// Reference for PRELINK_INFO_DICTIONARY_KEY in PlistDocument.
|
||||
// This reference is used for quick path during kext injection.
|
||||
//
|
||||
XML_NODE *KextList;
|
||||
//
|
||||
// Buffers allocated from pool for internal needs.
|
||||
//
|
||||
VOID **PooledBuffers;
|
||||
//
|
||||
// Currently used pooled buffers.
|
||||
//
|
||||
UINT32 PooledBuffersCount;
|
||||
//
|
||||
// Currently allocated pooled buffers. PooledBuffersAllocCount >= PooledBuffersCount.
|
||||
//
|
||||
UINT32 PooledBuffersAllocCount;
|
||||
VOID *LinkBuffer;
|
||||
UINT32 LinkBufferSize;
|
||||
//
|
||||
// Used for caching prelinked kexts.
|
||||
//
|
||||
LIST_ENTRY PrelinkedKexts;
|
||||
} PRELINKED_CONTEXT;
|
||||
|
||||
//
|
||||
// Kernel and kext patching context.
|
||||
//
|
||||
typedef struct {
|
||||
//
|
||||
// Mach-O context for patched binary.
|
||||
//
|
||||
OC_MACHO_CONTEXT MachContext;
|
||||
//
|
||||
// Virtual base to subtract to obtain file offset.
|
||||
//
|
||||
UINT64 VirtualBase;
|
||||
//
|
||||
// Virtual kmod_info_t address.
|
||||
//
|
||||
UINT64 VirtualKmod;
|
||||
} PATCHER_CONTEXT;
|
||||
|
||||
//
|
||||
// Kernel and kext patch description.
|
||||
//
|
||||
typedef struct {
|
||||
//
|
||||
// Comment or NULL (0 base is used then).
|
||||
//
|
||||
CONST CHAR8 *Comment;
|
||||
//
|
||||
// Symbol base or NULL (0 base is used then).
|
||||
//
|
||||
CONST CHAR8 *Base;
|
||||
//
|
||||
// Find bytes or NULL (data is written to base then).
|
||||
//
|
||||
CONST UINT8 *Find;
|
||||
//
|
||||
// Replace bytes.
|
||||
//
|
||||
CONST UINT8 *Replace;
|
||||
//
|
||||
// Find mask or NULL.
|
||||
//
|
||||
CONST UINT8 *Mask;
|
||||
//
|
||||
// Replace mask or NULL.
|
||||
//
|
||||
CONST UINT8 *ReplaceMask;
|
||||
//
|
||||
// Patch size.
|
||||
//
|
||||
UINT32 Size;
|
||||
//
|
||||
// Replace count or 0 for all.
|
||||
//
|
||||
UINT32 Count;
|
||||
//
|
||||
// Skip count or 0 to start from 1 match.
|
||||
//
|
||||
UINT32 Skip;
|
||||
//
|
||||
// Limit replacement size to this value or 0, which assumes table size.
|
||||
//
|
||||
UINT32 Limit;
|
||||
} PATCHER_GENERIC_PATCH;
|
||||
|
||||
/**
|
||||
Read Apple kernel for target architecture (possibly decompressing)
|
||||
into pool allocated buffer.
|
||||
|
||||
@param[in] File File handle instance.
|
||||
@param[in, out] Kernel Resulting non-fat kernel buffer from pool.
|
||||
@param[out] KernelSize Actual kernel size.
|
||||
@param[out] AllocatedSize Allocated kernel size (AllocatedSize >= KernelSize).
|
||||
@param[in] ReservedSize Allocated extra size for added kernel extensions.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
ReadAppleKernel (
|
||||
IN EFI_FILE_PROTOCOL *File,
|
||||
IN OUT UINT8 **Kernel,
|
||||
OUT UINT32 *KernelSize,
|
||||
OUT UINT32 *AllocatedSize,
|
||||
IN UINT32 ReservedSize
|
||||
);
|
||||
|
||||
/**
|
||||
Construct prelinked context for later modification.
|
||||
Must be freed with PrelinkedContextFree on success.
|
||||
Note, that PrelinkedAllocSize never changes, and is to be estimated.
|
||||
|
||||
@param[in,out] Context Prelinked context.
|
||||
@param[in,out] Prelinked Unpacked prelinked buffer (Mach-O image).
|
||||
@param[in] PrelinkedSize Unpacked prelinked buffer size.
|
||||
@param[in] PrelinkedAllocSize Unpacked prelinked buffer allocated size.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PrelinkedContextInit (
|
||||
IN OUT PRELINKED_CONTEXT *Context,
|
||||
IN OUT UINT8 *Prelinked,
|
||||
IN UINT32 PrelinkedSize,
|
||||
IN UINT32 PrelinkedAllocSize
|
||||
);
|
||||
|
||||
/**
|
||||
Free resources consumed by prelinked context.
|
||||
|
||||
@param[in,out] Context Prelinked context.
|
||||
**/
|
||||
VOID
|
||||
PrelinkedContextFree (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Insert pool-allocated buffer dependency with the same lifetime as
|
||||
prelinked context, so it gets freed with PrelinkedContextFree.
|
||||
|
||||
@param[in,out] Context Prelinked context.
|
||||
@param[in] Buffer Pool allocated buffer.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PrelinkedDependencyInsert (
|
||||
IN OUT PRELINKED_CONTEXT *Context,
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Drop current plist entry, required for kext injection.
|
||||
Ensure that prelinked text can grow with new kexts.
|
||||
|
||||
@param[in,out] Context Prelinked context.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PrelinkedInjectPrepare (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Insert current plist entry after kext injection.
|
||||
|
||||
@param[in,out] Context Prelinked context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PrelinkedInjectComplete (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Updated required reserve size to inject this kext.
|
||||
|
||||
@param[in,out] ReservedSize Current reserved size, updated.
|
||||
@param[in] InfoPlistSize Kext Info.plist size.
|
||||
@param[in] Executable Kext executable, optional.
|
||||
@param[in] ExecutableSize Kext executable size, optional.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PrelinkedReserveKextSize (
|
||||
IN OUT UINT32 *ReservedSize,
|
||||
IN UINT32 InfoPlistSize,
|
||||
IN UINT8 *Executable OPTIONAL,
|
||||
IN UINT32 ExecutableSize OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Perform kext injection.
|
||||
|
||||
@param[in,out] Context Prelinked context.
|
||||
@param[in] BundlePath Kext bundle path (e.g. /L/E/mykext.kext).
|
||||
@param[in,out] InfoPlist Kext Info.plist.
|
||||
@param[in] InfoPlistSize Kext Info.plist size.
|
||||
@param[in,out] ExecutablePath Kext executable path (e.g. Contents/MacOS/mykext), optional.
|
||||
@param[in,out] Executable Kext executable, optional.
|
||||
@param[in] ExecutableSize Kext executable size, optional.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PrelinkedInjectKext (
|
||||
IN OUT PRELINKED_CONTEXT *Context,
|
||||
IN CONST CHAR8 *BundlePath,
|
||||
IN CONST CHAR8 *InfoPlist,
|
||||
IN UINT32 InfoPlistSize,
|
||||
IN CONST CHAR8 *ExecutablePath OPTIONAL,
|
||||
IN OUT CONST UINT8 *Executable OPTIONAL,
|
||||
IN UINT32 ExecutableSize OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Initialize patcher from prelinked context for kext patching.
|
||||
|
||||
@param[in,out] Context Patcher context.
|
||||
@param[in,out] Prelinked Prelinked context.
|
||||
@param[in] Name Kext bundle identifier.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatcherInitContextFromPrelinked (
|
||||
IN OUT PATCHER_CONTEXT *Context,
|
||||
IN OUT PRELINKED_CONTEXT *Prelinked,
|
||||
IN CONST CHAR8 *Name
|
||||
);
|
||||
|
||||
/**
|
||||
Initialize patcher from buffer for e.g. kernel patching.
|
||||
|
||||
@param[in,out] Context Patcher context.
|
||||
@param[in,out] Buffer Kernel buffer (could be prelinked).
|
||||
@param[in] BufferSize Kernel buffer size.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatcherInitContextFromBuffer (
|
||||
IN OUT PATCHER_CONTEXT *Context,
|
||||
IN OUT UINT8 *Buffer,
|
||||
IN UINT32 BufferSize
|
||||
);
|
||||
|
||||
/**
|
||||
Get local symbol address.
|
||||
|
||||
@param[in,out] Context Patcher context.
|
||||
@param[in] Name Symbol name.
|
||||
@param[in,out] Address Returned symbol address in file.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatcherGetSymbolAddress (
|
||||
IN OUT PATCHER_CONTEXT *Context,
|
||||
IN CONST CHAR8 *Name,
|
||||
IN OUT UINT8 **Address
|
||||
);
|
||||
|
||||
/**
|
||||
Apply generic patch.
|
||||
|
||||
@param[in,out] Context Patcher context.
|
||||
@param[in] Patch Patch description.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatcherApplyGenericPatch (
|
||||
IN OUT PATCHER_CONTEXT *Context,
|
||||
IN PATCHER_GENERIC_PATCH *Patch
|
||||
);
|
||||
|
||||
/**
|
||||
Block kext from loading.
|
||||
|
||||
@param[in,out] Context Patcher context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatcherBlockKext (
|
||||
IN OUT PATCHER_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Apply MSR E2 patches to AppleIntelCPUPowerManagement kext.
|
||||
|
||||
@param Context Prelinked kernel context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchAppleCpuPmCfgLock (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Apply MSR E2 patches to XNU kernel (XCPM).
|
||||
|
||||
@param Patcher Patcher context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchAppleXcpmCfgLock (
|
||||
IN OUT PATCHER_CONTEXT *Patcher
|
||||
);
|
||||
|
||||
/**
|
||||
Apply extra MSR patches to XNU kernel (XCPM).
|
||||
|
||||
@param Patcher Patcher context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchAppleXcpmExtraMsrs (
|
||||
IN OUT PATCHER_CONTEXT *Patcher
|
||||
);
|
||||
|
||||
/**
|
||||
Apply max MSR_IA32_PERF_CONTROL patches to XNU kernel (XCPM).
|
||||
|
||||
@param Patcher Patcher context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchAppleXcpmForceBoost (
|
||||
IN OUT PATCHER_CONTEXT *Patcher
|
||||
);
|
||||
|
||||
/**
|
||||
Apply port limit patches to AppleUSBXHCI and AppleUSBXHCIPCI kexts.
|
||||
|
||||
@param Context Prelinked kernel context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchUsbXhciPortLimit (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Apply vendor patches to IOAHCIFamily kext to enable native features for third-party drives,
|
||||
such as TRIM on SSDs or hibernation support on 10.15.
|
||||
|
||||
@param Context Prelinked kernel context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchThirdPartyDriveSupport (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Apply icon type patches to IOAHCIPort kext to force internal disk icons.
|
||||
|
||||
@param Context Prelinked kernel context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchForceInternalDiskIcons (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Apply VT-d disabling patches to IOPCIFamily kext to disable IOMapper in macOS.
|
||||
|
||||
@param Context Prelinked kernel context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchAppleIoMapperSupport (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Apply dummy power management patches to AppleIntelCpuPowerManagement in macOS.
|
||||
|
||||
@param Context Prelinked kernel context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchDummyPowerManagement (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Apply PCI bar size patches to IOPCIFamily kext for compatibility with select configuration.
|
||||
|
||||
@param Context Prelinked kernel context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchIncreasePciBarSize (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Apply modification to CPUID 1.
|
||||
|
||||
@param Patcher Patcher context.
|
||||
@param CpuInfo CPU information.
|
||||
@param Data 4 32-bit integers with CPUID data.
|
||||
@param DataMask 4 32-bit integers with CPUID enabled overrides data.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchKernelCpuId (
|
||||
IN OUT PATCHER_CONTEXT *Patcher,
|
||||
IN OC_CPU_INFO *CpuInfo,
|
||||
IN UINT32 *Data,
|
||||
IN UINT32 *DataMask
|
||||
);
|
||||
|
||||
/**
|
||||
Apply custom AppleSMBIOS kext GUID patch for Custom UpdateSMBIOSMode.
|
||||
|
||||
@param Context Prelinked kernel context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchCustomSmbiosGuid (
|
||||
IN OUT PRELINKED_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Apply kernel patches to remove kext dumping in the panic log.
|
||||
|
||||
@param Patcher Patcher context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchPanicKextDump (
|
||||
IN OUT PATCHER_CONTEXT *Patcher
|
||||
);
|
||||
|
||||
/**
|
||||
Disable LAPIC interrupt kernel panic on AP cores.
|
||||
|
||||
@param Patcher Patcher context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchLapicKernelPanic (
|
||||
IN OUT PATCHER_CONTEXT *Patcher
|
||||
);
|
||||
|
||||
/**
|
||||
Disable power state change timeout kernel panic (10.15+).
|
||||
|
||||
@param Patcher Patcher context.
|
||||
|
||||
@return RETURN_SUCCESS on success.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PatchPowerStateTimeout (
|
||||
IN OUT PATCHER_CONTEXT *Patcher
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_KERNEL_LIB_H
|
||||
99
Include/Library/OcAppleKeyMapLib.h
Normal file
99
Include/Library/OcAppleKeyMapLib.h
Normal file
@ -0,0 +1,99 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, Download-Fritz. All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_KEY_MAP_LIB_H
|
||||
#define OC_APPLE_KEY_MAP_LIB_H
|
||||
|
||||
#include <Protocol/AppleKeyMapDatabase.h>
|
||||
#include <Protocol/AppleKeyMapAggregator.h>
|
||||
|
||||
/**
|
||||
Default buffer size for key map.
|
||||
**/
|
||||
#define OC_KEY_MAP_DEFAULT_SIZE 8
|
||||
|
||||
/**
|
||||
Returns the previously install Apple Key Map Database protocol.
|
||||
|
||||
@retval installed or located protocol or NULL
|
||||
**/
|
||||
APPLE_KEY_MAP_DATABASE_PROTOCOL *
|
||||
OcAppleKeyMapGetDatabase (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Install and initialise Apple Key Map protocols.
|
||||
|
||||
@param[in] Reinstall Overwrite installed protocols.
|
||||
|
||||
@retval installed or located protocol or NULL
|
||||
**/
|
||||
APPLE_KEY_MAP_AGGREGATOR_PROTOCOL *
|
||||
OcAppleKeyMapInstallProtocols (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
/**
|
||||
Checks whether or not a list of keys is contained within another.
|
||||
|
||||
@param[in] Keys The reference keys.
|
||||
@param[in] NumKeys The number of keys in Keys.
|
||||
@param[in] CheckKeys The keys to locate in Keys.
|
||||
@param[in] NumCheckKeys The number of keys in CheckKeys.
|
||||
@param[in] ExactMatch Specifies whether matches must be exact.
|
||||
|
||||
@returns Whether the reference keys contain the checked keys.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
OcKeyMapHasKeys (
|
||||
IN CONST APPLE_KEY_CODE *Keys,
|
||||
IN UINTN NumKeys,
|
||||
IN CONST APPLE_KEY_CODE *CheckKeys,
|
||||
IN UINTN NumCheckKeys,
|
||||
IN BOOLEAN ExactMatch
|
||||
);
|
||||
|
||||
/**
|
||||
Checks whether or not a KeyCode is contained within Keys.
|
||||
|
||||
@param[in] Keys The reference keys.
|
||||
@param[in] NumKeys The number of keys in Keys.
|
||||
@param[in] KeyCode The key to locate in Keys.
|
||||
|
||||
@returns Whether the reference keys contain the checked key.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
OcKeyMapHasKey (
|
||||
IN CONST APPLE_KEY_CODE *Keys,
|
||||
IN UINTN NumKeys,
|
||||
IN CONST APPLE_KEY_CODE KeyCode
|
||||
);
|
||||
|
||||
/**
|
||||
Performs keyboard input flush.
|
||||
|
||||
@param[in] KeyMap Apple Key Map Aggregator protocol.
|
||||
@param[in] Key Key to wait for removal or 0.
|
||||
@param[in] FlushConsole Also flush console input.
|
||||
**/
|
||||
VOID
|
||||
OcKeyMapFlush (
|
||||
IN APPLE_KEY_MAP_AGGREGATOR_PROTOCOL *KeyMap,
|
||||
IN APPLE_KEY_CODE Key,
|
||||
IN BOOLEAN FlushConsole
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_KEY_MAP_LIB_H
|
||||
33
Include/Library/OcAppleKeysLib.h
Normal file
33
Include/Library/OcAppleKeysLib.h
Normal file
@ -0,0 +1,33 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_KEYS_LIB_H
|
||||
#define OC_APPLE_KEYS_LIB_H
|
||||
|
||||
#include <Library/OcGuardLib.h>
|
||||
#include <Library/OcCryptoLib.h>
|
||||
|
||||
#define NUM_OF_PK 2
|
||||
|
||||
typedef struct APPLE_PK_ENTRY_ {
|
||||
UINT8 Hash[SHA256_DIGEST_SIZE];
|
||||
CONST OC_RSA_PUBLIC_KEY *PublicKey;
|
||||
} APPLE_PK_ENTRY;
|
||||
|
||||
extern CONST APPLE_PK_ENTRY PkDataBase[NUM_OF_PK];
|
||||
|
||||
extern CONST UINT8 gAppleX86SecureBootRootCaCert[];
|
||||
extern CONST UINTN gAppleX86SecureBootRootCaCertSize;
|
||||
|
||||
#endif // OC_APPLE_KEYS_LIB_H
|
||||
97
Include/Library/OcAppleRamDiskLib.h
Normal file
97
Include/Library/OcAppleRamDiskLib.h
Normal file
@ -0,0 +1,97 @@
|
||||
/** @file
|
||||
Apple RAM Disk library.
|
||||
|
||||
Copyright (C) 2019, Download-Fritz. 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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_RAM_DISK_LIB_H
|
||||
#define OC_APPLE_RAM_DISK_LIB_H
|
||||
|
||||
#include <Protocol/AppleRamDisk.h>
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
|
||||
/**
|
||||
Request allocation of Size bytes in extents table.
|
||||
|
||||
@param[in] Size Requested memory size.
|
||||
@param[in] MemoryType Requested memory type.
|
||||
|
||||
@retval Allocated extent table.
|
||||
**/
|
||||
CONST APPLE_RAM_DISK_EXTENT_TABLE *
|
||||
OcAppleRamDiskAllocate (
|
||||
IN UINTN Size,
|
||||
IN EFI_MEMORY_TYPE MemoryType
|
||||
);
|
||||
|
||||
/**
|
||||
Read RAM disk data.
|
||||
|
||||
@param[in] ExtentTable Allocated extent table.
|
||||
@param[in] Offset Offset in RAM disk.
|
||||
@param[in] Size Amount of data to read.
|
||||
@param[out] Buffer Resulting data.
|
||||
|
||||
@retval TRUE on success.
|
||||
**/
|
||||
BOOLEAN
|
||||
OcAppleRamDiskRead (
|
||||
IN CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable,
|
||||
IN UINTN Offset,
|
||||
IN UINTN Size,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Write RAM disk data.
|
||||
|
||||
@param[in] ExtentTable Allocated extent table.
|
||||
@param[in] Offset Offset in RAM disk.
|
||||
@param[in] Size Amount of data to write.
|
||||
@param[in] Buffer Source data.
|
||||
|
||||
@retval TRUE on success.
|
||||
**/
|
||||
BOOLEAN
|
||||
OcAppleRamDiskWrite (
|
||||
IN CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable,
|
||||
IN UINTN Offset,
|
||||
IN UINTN Size,
|
||||
IN CONST VOID *Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Load file into RAM disk as it is.
|
||||
|
||||
@param[in] ExtentTable Allocated extent table.
|
||||
@param[in] File File protocol open for reading.
|
||||
@param[in] FileSize Amount of data to write.
|
||||
|
||||
@retval TRUE on success.
|
||||
**/
|
||||
BOOLEAN
|
||||
OcAppleRamDiskLoadFile (
|
||||
IN OUT CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable,
|
||||
IN EFI_FILE_PROTOCOL *File,
|
||||
IN UINTN FileSize
|
||||
);
|
||||
|
||||
/**
|
||||
Free RAM disk.
|
||||
|
||||
@param[in] ExtentTable Allocated extent table.
|
||||
**/
|
||||
VOID
|
||||
OcAppleRamDiskFree (
|
||||
IN CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_RAM_DISK_LIB_H
|
||||
38
Include/Library/OcAppleSecureBootLib.h
Normal file
38
Include/Library/OcAppleSecureBootLib.h
Normal file
@ -0,0 +1,38 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, Download-Fritz. All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_SECURE_BOOT_LIB_H
|
||||
#define OC_APPLE_SECURE_BOOT_LIB_H
|
||||
|
||||
#include <Protocol/AppleSecureBoot.h>
|
||||
|
||||
/**
|
||||
Install and initialise the Apple Secure Boot protocol.
|
||||
|
||||
@param[in] Reinstall Replace any installed protocol.
|
||||
@param[in] SbPolicy Apple Secure Boot Policy to install.
|
||||
@param[in] SbWinPolicy Apple Secure Boot Windows Policy to install.
|
||||
@param[in] SbWinPolicyValid Whether SbWinPolicy should be installed.
|
||||
|
||||
@returns Installed or located protocol.
|
||||
@retval NULL There was an error locating or installing the protocol.
|
||||
|
||||
**/
|
||||
APPLE_SECURE_BOOT_PROTOCOL *
|
||||
OcAppleSecureBootInstallProtocol (
|
||||
IN BOOLEAN Reinstall,
|
||||
IN UINT8 SbPolicy,
|
||||
IN UINT8 SbWinPolicy OPTIONAL,
|
||||
IN BOOLEAN SbWinPolicyValid
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_SECURE_BOOT_LIB_H
|
||||
32
Include/Library/OcAppleUserInterfaceThemeLib.h
Normal file
32
Include/Library/OcAppleUserInterfaceThemeLib.h
Normal file
@ -0,0 +1,32 @@
|
||||
/** @file
|
||||
Copyright (c) 2016-2018, vit9696. All rights reserved.<BR>
|
||||
Portions copyright (c) 2018, savvas. 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.
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_USER_INTERFACE_THEME_LIB_H
|
||||
#define OC_APPLE_USER_INTERFACE_THEME_LIB_H
|
||||
|
||||
#include <Protocol/UserInterfaceTheme.h>
|
||||
|
||||
/**
|
||||
Install and initialise the Apple User Interface Theme protocol.
|
||||
|
||||
@param[in] Reinstall Replace any installed protocol.
|
||||
|
||||
@returns Installed or located protocol.
|
||||
@retval NULL There was an error locating or installing the protocol.
|
||||
**/
|
||||
EFI_USER_INTERFACE_THEME_PROTOCOL *
|
||||
OcAppleUserInterfaceThemeInstallProtocol (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_USER_INTERFACE_THEME_LIB_H
|
||||
68
Include/Library/OcAudioLib.h
Normal file
68
Include/Library/OcAudioLib.h
Normal file
@ -0,0 +1,68 @@
|
||||
/** @file
|
||||
This library implements audio interaction.
|
||||
|
||||
Copyright (c) 2020, vit9696. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause
|
||||
**/
|
||||
|
||||
#ifndef OC_AUDIO_LIB_H
|
||||
#define OC_AUDIO_LIB_H
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <Protocol/OcAudio.h>
|
||||
|
||||
#define OC_AUDIO_DEFAULT_VOLUME_LEVEL 70
|
||||
|
||||
/**
|
||||
Install audio support protocols.
|
||||
|
||||
@param[in] Reinstall Overwrite installed protocols.
|
||||
|
||||
@retval installed protocol.
|
||||
@retval NULL when conflicting audio implementation is present.
|
||||
@retval NULL when installation failed.
|
||||
**/
|
||||
OC_AUDIO_PROTOCOL *
|
||||
OcAudioInstallProtocols (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
/**
|
||||
Convert language code to ASCII string.
|
||||
|
||||
@param[in] LanguageCode Code.
|
||||
|
||||
@retval ASCII string.
|
||||
**/
|
||||
CONST CHAR8 *
|
||||
OcLanguageCodeToString (
|
||||
IN APPLE_VOICE_OVER_LANGUAGE_CODE LanguageCode
|
||||
);
|
||||
|
||||
/**
|
||||
Get system volume level in 0~100 range.
|
||||
|
||||
@param[in] Amplifier Amplification coefficient 1~999.
|
||||
@param[out] Muted Whether volume is off.
|
||||
|
||||
@retval ASCII string.
|
||||
**/
|
||||
UINT8
|
||||
OcGetVolumeLevel (
|
||||
IN UINT32 Amplifier,
|
||||
OUT BOOLEAN *Muted
|
||||
);
|
||||
|
||||
/**
|
||||
Set VoiceOver language from string.
|
||||
|
||||
@param[in] Language Language string, optional for system.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcSetVoiceOverLanguage (
|
||||
CONST CHAR8 *Language OPTIONAL
|
||||
);
|
||||
|
||||
#endif // OC_AUDIO_LIB_H
|
||||
1008
Include/Library/OcBootManagementLib.h
Executable file
1008
Include/Library/OcBootManagementLib.h
Executable file
File diff suppressed because it is too large
Load Diff
120
Include/Library/OcCompressionLib.h
Normal file
120
Include/Library/OcCompressionLib.h
Normal file
@ -0,0 +1,120 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_COMPRESSION_LIB_H
|
||||
#define OC_COMPRESSION_LIB_H
|
||||
|
||||
/**
|
||||
Maximumum compression and decompression buffer size may vary from
|
||||
0 to OC_COMPRESSION_MAX_LENGTH inclusive.
|
||||
**/
|
||||
#define OC_COMPRESSION_MAX_LENGTH BASE_1GB
|
||||
|
||||
/**
|
||||
Allow the use of extra adler32 validation.
|
||||
Not very useful as dmg has own checks.
|
||||
**/
|
||||
// #define OC_INFLATE_VERIFY_DATA
|
||||
|
||||
/**
|
||||
Compress buffer with LZSS algorithm.
|
||||
|
||||
@param[out] Dst Destination buffer.
|
||||
@param[in] DstLen Destination buffer size.
|
||||
@param[in] Src Source buffer.
|
||||
@param[in] SrcLen Source buffer size.
|
||||
|
||||
@return Dst + CompressedLen on success otherwise NULL.
|
||||
**/
|
||||
UINT8 *
|
||||
CompressLZSS (
|
||||
OUT UINT8 *Dst,
|
||||
IN UINT32 DstLen,
|
||||
IN UINT8 *Src,
|
||||
IN UINT32 SrcLen
|
||||
);
|
||||
|
||||
/**
|
||||
Decompress buffer with LZSS algorithm.
|
||||
|
||||
@param[out] Dst Destination buffer.
|
||||
@param[in] DstLen Destination buffer size.
|
||||
@param[in] Src Source buffer.
|
||||
@param[in] SrcLen Source buffer size.
|
||||
|
||||
@return DecompressedLen on success otherwise 0.
|
||||
**/
|
||||
UINT32
|
||||
DecompressLZSS (
|
||||
OUT UINT8 *Dst,
|
||||
IN UINT32 DstLen,
|
||||
IN UINT8 *Src,
|
||||
IN UINT32 SrcLen
|
||||
);
|
||||
|
||||
/**
|
||||
Decompress buffer with LZVN algorithm.
|
||||
|
||||
@param[out] Dst Destination buffer.
|
||||
@param[in] DstLen Destination buffer size.
|
||||
@param[in] Src Source buffer.
|
||||
@param[in] SrcLen Source buffer size.
|
||||
|
||||
@return DecompressedLen on success otherwise 0.
|
||||
**/
|
||||
UINTN
|
||||
DecompressLZVN (
|
||||
OUT UINT8 *Dst,
|
||||
IN UINTN DstLen,
|
||||
IN CONST UINT8 *Src,
|
||||
IN UINTN SrcLen
|
||||
);
|
||||
|
||||
/**
|
||||
Compress buffer with ZLIB algorithm.
|
||||
|
||||
@param[out] Dst Destination buffer.
|
||||
@param[in] DstLen Destination buffer size.
|
||||
@param[in] Src Source buffer.
|
||||
@param[in] SrcLen Source buffer size.
|
||||
|
||||
@return Dst + CompressedLen on success otherwise NULL.
|
||||
**/
|
||||
UINT8 *
|
||||
CompressZLIB (
|
||||
OUT UINT8 *Dst,
|
||||
IN UINT32 DstLen,
|
||||
IN CONST UINT8 *Src,
|
||||
IN UINT32 SrcLen
|
||||
);
|
||||
|
||||
/**
|
||||
Decompress buffer with ZLIB algorithm.
|
||||
|
||||
@param[out] Dst Destination buffer.
|
||||
@param[in] DstLen Destination buffer size.
|
||||
@param[in] Src Source buffer.
|
||||
@param[in] SrcLen Source buffer size.
|
||||
|
||||
@return DecompressedLen on success otherwise 0.
|
||||
**/
|
||||
UINTN
|
||||
DecompressZLIB (
|
||||
OUT UINT8 *Dst,
|
||||
IN UINTN DstLen,
|
||||
IN CONST UINT8 *Src,
|
||||
IN UINTN SrcLen
|
||||
);
|
||||
|
||||
#endif // OC_COMPRESSION_LIB_H
|
||||
595
Include/Library/OcConfigurationLib.h
Normal file
595
Include/Library/OcConfigurationLib.h
Normal file
@ -0,0 +1,595 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_CONFIGURATION_LIB_H
|
||||
#define OC_CONFIGURATION_LIB_H
|
||||
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/OcSerializeLib.h>
|
||||
#include <Library/OcBootManagementLib.h>
|
||||
|
||||
/**
|
||||
ACPI section
|
||||
**/
|
||||
|
||||
///
|
||||
/// ACPI added tables.
|
||||
///
|
||||
#define OC_ACPI_ADD_ENTRY_FIELDS(_, __) \
|
||||
_(BOOLEAN , Enabled , , FALSE , () ) \
|
||||
_(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , Path , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) )
|
||||
OC_DECLARE (OC_ACPI_ADD_ENTRY)
|
||||
|
||||
#define OC_ACPI_ADD_ARRAY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_ACPI_ADD_ENTRY, _, __)
|
||||
OC_DECLARE (OC_ACPI_ADD_ARRAY)
|
||||
|
||||
///
|
||||
/// ACPI table blocks.
|
||||
///
|
||||
#define OC_ACPI_BLOCK_ENTRY_FIELDS(_, __) \
|
||||
_(BOOLEAN , All , , FALSE , () ) \
|
||||
_(BOOLEAN , Enabled , , FALSE , () ) \
|
||||
_(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(UINT8 , OemTableId , [8] , {0} , () ) \
|
||||
_(UINT32 , TableLength , , 0 , () ) \
|
||||
_(UINT8 , TableSignature , [4] , {0} , () )
|
||||
OC_DECLARE (OC_ACPI_BLOCK_ENTRY)
|
||||
|
||||
#define OC_ACPI_BLOCK_ARRAY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_ACPI_BLOCK_ENTRY, _, __)
|
||||
OC_DECLARE (OC_ACPI_BLOCK_ARRAY)
|
||||
|
||||
///
|
||||
/// ACPI patches.
|
||||
///
|
||||
#define OC_ACPI_PATCH_ENTRY_FIELDS(_, __) \
|
||||
_(UINT32 , Count , , 0 , () ) \
|
||||
_(BOOLEAN , Enabled , , FALSE , () ) \
|
||||
_(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_DATA , Find , , OC_EDATA_CONSTR (_, __) , OC_DESTR (OC_DATA) ) \
|
||||
_(UINT32 , Limit , , 0 , () ) \
|
||||
_(OC_DATA , Mask , , OC_EDATA_CONSTR (_, __) , OC_DESTR (OC_DATA) ) \
|
||||
_(OC_DATA , Replace , , OC_EDATA_CONSTR (_, __) , OC_DESTR (OC_DATA) ) \
|
||||
_(OC_DATA , ReplaceMask , , OC_EDATA_CONSTR (_, __) , OC_DESTR (OC_DATA) ) \
|
||||
_(UINT8 , OemTableId , [8] , {0} , () ) \
|
||||
_(UINT32 , TableLength , , 0 , () ) \
|
||||
_(UINT8 , TableSignature , [4] , {0} , () ) \
|
||||
_(UINT32 , Skip , , 0 , () )
|
||||
OC_DECLARE (OC_ACPI_PATCH_ENTRY)
|
||||
|
||||
#define OC_ACPI_PATCH_ARRAY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_ACPI_PATCH_ENTRY, _, __)
|
||||
OC_DECLARE (OC_ACPI_PATCH_ARRAY)
|
||||
|
||||
///
|
||||
/// ACPI quirks.
|
||||
///
|
||||
#define OC_ACPI_QUIRKS_FIELDS(_, __) \
|
||||
_(BOOLEAN , FadtEnableReset , , FALSE , ()) \
|
||||
_(BOOLEAN , NormalizeHeaders , , FALSE , ()) \
|
||||
_(BOOLEAN , RebaseRegions , , FALSE , ()) \
|
||||
_(BOOLEAN , ResetHwSig , , FALSE , ()) \
|
||||
_(BOOLEAN , ResetLogoStatus , , FALSE , ())
|
||||
OC_DECLARE (OC_ACPI_QUIRKS)
|
||||
|
||||
#define OC_ACPI_CONFIG_FIELDS(_, __) \
|
||||
_(OC_ACPI_ADD_ARRAY , Add , , OC_CONSTR2 (OC_ACPI_ADD_ARRAY, _, __) , OC_DESTR (OC_ACPI_ADD_ARRAY)) \
|
||||
_(OC_ACPI_BLOCK_ARRAY , Block , , OC_CONSTR2 (OC_ACPI_BLOCK_ARRAY, _, __) , OC_DESTR (OC_ACPI_BLOCK_ARRAY)) \
|
||||
_(OC_ACPI_PATCH_ARRAY , Patch , , OC_CONSTR2 (OC_ACPI_PATCH_ARRAY, _, __) , OC_DESTR (OC_ACPI_PATCH_ARRAY)) \
|
||||
_(OC_ACPI_QUIRKS , Quirks , , OC_CONSTR2 (OC_ACPI_QUIRKS, _, __) , OC_DESTR (OC_ACPI_QUIRKS))
|
||||
OC_DECLARE (OC_ACPI_CONFIG)
|
||||
|
||||
/**
|
||||
Apple bootloader section
|
||||
**/
|
||||
|
||||
///
|
||||
/// Apple bootloader quirks.
|
||||
///
|
||||
|
||||
|
||||
#define OC_BOOTER_WL_ENTRY_FIELDS(_, __) \
|
||||
_(UINT64 , Address , , 0 , () ) \
|
||||
_(BOOLEAN , Enabled , , FALSE , () ) \
|
||||
_(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) )
|
||||
OC_DECLARE (OC_BOOTER_WL_ENTRY)
|
||||
|
||||
#define OC_BOOTER_WL_ARRAY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_BOOTER_WL_ENTRY, _, __)
|
||||
OC_DECLARE (OC_BOOTER_WL_ARRAY)
|
||||
|
||||
#define OC_BOOTER_QUIRKS_FIELDS(_, __) \
|
||||
_(BOOLEAN , AvoidRuntimeDefrag , , FALSE , ()) \
|
||||
_(BOOLEAN , DevirtualiseMmio , , FALSE , ()) \
|
||||
_(BOOLEAN , DisableSingleUser , , FALSE , ()) \
|
||||
_(BOOLEAN , DisableVariableWrite , , FALSE , ()) \
|
||||
_(BOOLEAN , ProtectSecureBoot , , FALSE , ()) \
|
||||
_(BOOLEAN , DiscardHibernateMap , , FALSE , ()) \
|
||||
_(BOOLEAN , EnableSafeModeSlide , , FALSE , ()) \
|
||||
_(BOOLEAN , EnableWriteUnprotector , , FALSE , ()) \
|
||||
_(BOOLEAN , ForceExitBootServices , , FALSE , ()) \
|
||||
_(BOOLEAN , ProtectCsmRegion , , FALSE , ()) \
|
||||
_(BOOLEAN , ProvideCustomSlide , , FALSE , ()) \
|
||||
_(BOOLEAN , SetupVirtualMap , , FALSE , ()) \
|
||||
_(BOOLEAN , ShrinkMemoryMap , , FALSE , ()) \
|
||||
_(BOOLEAN , SignalAppleOS , , FALSE , ())
|
||||
OC_DECLARE (OC_BOOTER_QUIRKS)
|
||||
|
||||
///
|
||||
/// Apple bootloader section.
|
||||
///
|
||||
#define OC_BOOTER_CONFIG_FIELDS(_, __) \
|
||||
_(OC_BOOTER_WL_ARRAY , MmioWhitelist , , OC_CONSTR2 (OC_BOOTER_WL_ARRAY, _, __) , OC_DESTR (OC_BOOTER_WL_ARRAY)) \
|
||||
_(OC_BOOTER_QUIRKS , Quirks , , OC_CONSTR2 (OC_BOOTER_QUIRKS, _, __) , OC_DESTR (OC_BOOTER_QUIRKS))
|
||||
OC_DECLARE (OC_BOOTER_CONFIG)
|
||||
|
||||
/**
|
||||
DeviceProperties section
|
||||
**/
|
||||
|
||||
///
|
||||
/// Device properties is an associative map of devices with their property key value maps.
|
||||
///
|
||||
#define OC_DEV_PROP_ADD_MAP_FIELDS(_, __) \
|
||||
OC_MAP (OC_STRING, OC_ASSOC, _, __)
|
||||
OC_DECLARE (OC_DEV_PROP_ADD_MAP)
|
||||
|
||||
#define OC_DEV_PROP_BLOCK_ENTRY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_STRING, _, __)
|
||||
OC_DECLARE (OC_DEV_PROP_BLOCK_ENTRY)
|
||||
|
||||
#define OC_DEV_PROP_BLOCK_MAP_FIELDS(_, __) \
|
||||
OC_MAP (OC_STRING, OC_DEV_PROP_BLOCK_ENTRY, _, __)
|
||||
OC_DECLARE (OC_DEV_PROP_BLOCK_MAP)
|
||||
|
||||
#define OC_DEV_PROP_CONFIG_FIELDS(_, __) \
|
||||
_(OC_DEV_PROP_ADD_MAP , Add , , OC_CONSTR2 (OC_DEV_PROP_ADD_MAP, _, __) , OC_DESTR (OC_DEV_PROP_ADD_MAP)) \
|
||||
_(OC_DEV_PROP_BLOCK_MAP , Block , , OC_CONSTR2 (OC_DEV_PROP_BLOCK_MAP, _, __) , OC_DESTR (OC_DEV_PROP_BLOCK_MAP))
|
||||
OC_DECLARE (OC_DEV_PROP_CONFIG)
|
||||
|
||||
/**
|
||||
KernelSpace section
|
||||
**/
|
||||
|
||||
///
|
||||
/// KernelSpace kext adds.
|
||||
///
|
||||
#define OC_KERNEL_ADD_ENTRY_FIELDS(_, __) \
|
||||
_(BOOLEAN , Enabled , , FALSE , () ) \
|
||||
_(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , MaxKernel , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , MinKernel , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , BundlePath , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , ExecutablePath , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , PlistPath , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(UINT8 * , ImageData , , NULL , OcFreePointer ) \
|
||||
_(UINT32 , ImageDataSize , , 0 , () ) \
|
||||
_(CHAR8 * , PlistData , , NULL , OcFreePointer ) \
|
||||
_(UINT32 , PlistDataSize , , 0 , () )
|
||||
OC_DECLARE (OC_KERNEL_ADD_ENTRY)
|
||||
|
||||
#define OC_KERNEL_ADD_ARRAY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_KERNEL_ADD_ENTRY, _, __)
|
||||
OC_DECLARE (OC_KERNEL_ADD_ARRAY)
|
||||
|
||||
///
|
||||
/// KernelSpace kext blocks.
|
||||
///
|
||||
#define OC_KERNEL_BLOCK_ENTRY_FIELDS(_, __) \
|
||||
_(BOOLEAN , Enabled , , FALSE , () ) \
|
||||
_(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , Identifier , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , MaxKernel , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , MinKernel , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) )
|
||||
OC_DECLARE (OC_KERNEL_BLOCK_ENTRY)
|
||||
|
||||
#define OC_KERNEL_BLOCK_ARRAY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_KERNEL_BLOCK_ENTRY, _, __)
|
||||
OC_DECLARE (OC_KERNEL_BLOCK_ARRAY)
|
||||
|
||||
///
|
||||
/// Kernel emulation preferences.
|
||||
///
|
||||
#define OC_KERNEL_EMULATE_FIELDS(_,__) \
|
||||
_(UINT32 , Cpuid1Data , [4] , {0} , () ) \
|
||||
_(UINT32 , Cpuid1Mask , [4] , {0} , () )
|
||||
OC_DECLARE (OC_KERNEL_EMULATE)
|
||||
|
||||
///
|
||||
/// KernelSpace patches.
|
||||
///
|
||||
#define OC_KERNEL_PATCH_ENTRY_FIELDS(_, __) \
|
||||
_(OC_STRING , Base , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(UINT32 , Count , , 0 , () ) \
|
||||
_(BOOLEAN , Enabled , , FALSE , () ) \
|
||||
_(OC_DATA , Find , , OC_EDATA_CONSTR (_, __) , OC_DESTR (OC_DATA) ) \
|
||||
_(OC_STRING , Identifier , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_DATA , Mask , , OC_EDATA_CONSTR (_, __) , OC_DESTR (OC_DATA) ) \
|
||||
_(OC_STRING , MaxKernel , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , MinKernel , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_DATA , Replace , , OC_EDATA_CONSTR (_, __) , OC_DESTR (OC_DATA) ) \
|
||||
_(OC_DATA , ReplaceMask , , OC_EDATA_CONSTR (_, __) , OC_DESTR (OC_DATA) ) \
|
||||
_(UINT32 , Limit , , 0 , () ) \
|
||||
_(UINT32 , Skip , , 0 , () )
|
||||
OC_DECLARE (OC_KERNEL_PATCH_ENTRY)
|
||||
|
||||
#define OC_KERNEL_PATCH_ARRAY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_KERNEL_PATCH_ENTRY, _, __)
|
||||
OC_DECLARE (OC_KERNEL_PATCH_ARRAY)
|
||||
|
||||
///
|
||||
/// KernelSpace quirks.
|
||||
///
|
||||
#define OC_KERNEL_QUIRKS_FIELDS(_, __) \
|
||||
_(BOOLEAN , AppleCpuPmCfgLock , , FALSE , ()) \
|
||||
_(BOOLEAN , AppleXcpmCfgLock , , FALSE , ()) \
|
||||
_(BOOLEAN , AppleXcpmExtraMsrs , , FALSE , ()) \
|
||||
_(BOOLEAN , AppleXcpmForceBoost , , FALSE , ()) \
|
||||
_(BOOLEAN , CustomSmbiosGuid , , FALSE , ()) \
|
||||
_(BOOLEAN , DisableIoMapper , , FALSE , ()) \
|
||||
_(BOOLEAN , DummyPowerManagement , , FALSE , ()) \
|
||||
_(BOOLEAN , ExternalDiskIcons , , FALSE , ()) \
|
||||
_(BOOLEAN , IncreasePciBarSize , , FALSE , ()) \
|
||||
_(BOOLEAN , LapicKernelPanic , , FALSE , ()) \
|
||||
_(BOOLEAN , PanicNoKextDump , , FALSE , ()) \
|
||||
_(BOOLEAN , PowerTimeoutKernelPanic , , FALSE , ()) \
|
||||
_(BOOLEAN , ThirdPartyDrives , , FALSE , ()) \
|
||||
_(BOOLEAN , XhciPortLimit , , FALSE , ())
|
||||
OC_DECLARE (OC_KERNEL_QUIRKS)
|
||||
|
||||
#define OC_KERNEL_CONFIG_FIELDS(_, __) \
|
||||
_(OC_KERNEL_ADD_ARRAY , Add , , OC_CONSTR2 (OC_KERNEL_ADD_ARRAY, _, __) , OC_DESTR (OC_KERNEL_ADD_ARRAY)) \
|
||||
_(OC_KERNEL_BLOCK_ARRAY , Block , , OC_CONSTR2 (OC_KERNEL_BLOCK_ARRAY, _, __) , OC_DESTR (OC_KERNEL_BLOCK_ARRAY)) \
|
||||
_(OC_KERNEL_EMULATE , Emulate , , OC_CONSTR2 (OC_KERNEL_EMULATE, _, __) , OC_DESTR (OC_KERNEL_EMULATE)) \
|
||||
_(OC_KERNEL_PATCH_ARRAY , Patch , , OC_CONSTR2 (OC_KERNEL_PATCH_ARRAY, _, __) , OC_DESTR (OC_KERNEL_PATCH_ARRAY)) \
|
||||
_(OC_KERNEL_QUIRKS , Quirks , , OC_CONSTR2 (OC_KERNEL_QUIRKS, _, __) , OC_DESTR (OC_KERNEL_QUIRKS))
|
||||
OC_DECLARE (OC_KERNEL_CONFIG)
|
||||
|
||||
/**
|
||||
Misc section
|
||||
**/
|
||||
|
||||
#define OC_MISC_BLESS_ARRAY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_STRING, _, __)
|
||||
OC_DECLARE (OC_MISC_BLESS_ARRAY)
|
||||
|
||||
#define OC_MISC_BOOT_FIELDS(_, __) \
|
||||
_(OC_STRING , PickerMode , , OC_STRING_CONSTR ("Builtin", _, __) , OC_DESTR (OC_STRING)) \
|
||||
_(OC_STRING , HibernateMode , , OC_STRING_CONSTR ("None", _, __) , OC_DESTR (OC_STRING)) \
|
||||
_(UINT32 , PickerAttributes , , 0 , ()) \
|
||||
_(UINT32 , TakeoffDelay , , 0 , ()) \
|
||||
_(UINT32 , Timeout , , 0 , ()) \
|
||||
_(BOOLEAN , PickerAudioAssist , , FALSE , ()) \
|
||||
_(BOOLEAN , HideAuxiliary , , FALSE , ()) \
|
||||
_(BOOLEAN , HideSelf , , FALSE , ()) \
|
||||
_(BOOLEAN , PollAppleHotKeys , , FALSE , ()) \
|
||||
_(BOOLEAN , ShowPicker , , FALSE , ())
|
||||
OC_DECLARE (OC_MISC_BOOT)
|
||||
|
||||
#define OC_MISC_DEBUG_FIELDS(_, __) \
|
||||
_(BOOLEAN , DisableWatchDog , , FALSE , ()) \
|
||||
_(UINT32 , DisplayDelay , , 0 , ()) \
|
||||
_(UINT64 , DisplayLevel , , 0 , ()) \
|
||||
_(UINT32 , Target , , 0 , ())
|
||||
OC_DECLARE (OC_MISC_DEBUG)
|
||||
|
||||
#define OCS_EXPOSE_BOOT_PATH 1U
|
||||
#define OCS_EXPOSE_VERSION_VAR 2U
|
||||
#define OCS_EXPOSE_VERSION_UI 4U
|
||||
#define OCS_EXPOSE_OEM_INFO 8U
|
||||
#define OCS_EXPOSE_VERSION (OCS_EXPOSE_VERSION_VAR | OCS_EXPOSE_VERSION_UI)
|
||||
|
||||
typedef enum {
|
||||
OcsVaultOptional = 0,
|
||||
OcsVaultBasic = 1,
|
||||
OcsVaultSecure = 2,
|
||||
} OCS_VAULT_MODE;
|
||||
|
||||
#define OC_MISC_SECURITY_FIELDS(_, __) \
|
||||
_(OC_STRING , Vault , , OC_STRING_CONSTR ("Secure", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(UINT32 , ScanPolicy , , OC_SCAN_DEFAULT_POLICY , ()) \
|
||||
_(BOOLEAN , AllowNvramReset , , FALSE , ()) \
|
||||
_(BOOLEAN , AllowSetDefault , , FALSE , ()) \
|
||||
_(BOOLEAN , ExposeSensitiveData , , OCS_EXPOSE_VERSION , ()) \
|
||||
_(BOOLEAN , AuthRestart , , FALSE , ()) \
|
||||
_(BOOLEAN , EnablePassword , , FALSE , ()) \
|
||||
_(UINT8 , PasswordHash , [64] , {0} , ()) \
|
||||
_(OC_DATA , PasswordSalt , , OC_EDATA_CONSTR (_, __) , OC_DESTR (OC_DATA)) \
|
||||
_(UINT64 , HaltLevel , , 0x80000000 , ())
|
||||
OC_DECLARE (OC_MISC_SECURITY)
|
||||
|
||||
#define OC_MISC_TOOLS_ENTRY_FIELDS(_, __) \
|
||||
_(OC_STRING , Arguments , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(BOOLEAN , Auxiliary , , FALSE , () ) \
|
||||
_(BOOLEAN , Enabled , , FALSE , () ) \
|
||||
_(OC_STRING , Name , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , Path , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) )
|
||||
OC_DECLARE (OC_MISC_TOOLS_ENTRY)
|
||||
|
||||
#define OC_MISC_TOOLS_ARRAY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_MISC_TOOLS_ENTRY, _, __)
|
||||
OC_DECLARE (OC_MISC_TOOLS_ARRAY)
|
||||
|
||||
#define OC_MISC_CONFIG_FIELDS(_, __) \
|
||||
_(OC_MISC_BLESS_ARRAY , BlessOverride , , OC_CONSTR2 (OC_MISC_BLESS_ARRAY, _, __) , OC_DESTR (OC_MISC_BLESS_ARRAY)) \
|
||||
_(OC_MISC_BOOT , Boot , , OC_CONSTR2 (OC_MISC_BOOT, _, __) , OC_DESTR (OC_MISC_BOOT)) \
|
||||
_(OC_MISC_DEBUG , Debug , , OC_CONSTR2 (OC_MISC_DEBUG, _, __) , OC_DESTR (OC_MISC_DEBUG)) \
|
||||
_(OC_MISC_SECURITY , Security , , OC_CONSTR2 (OC_MISC_SECURITY, _, __) , OC_DESTR (OC_MISC_SECURITY)) \
|
||||
_(OC_MISC_TOOLS_ARRAY , Entries , , OC_CONSTR2 (OC_MISC_TOOLS_ARRAY, _, __) , OC_DESTR (OC_MISC_TOOLS_ARRAY)) \
|
||||
_(OC_MISC_TOOLS_ARRAY , Tools , , OC_CONSTR2 (OC_MISC_TOOLS_ARRAY, _, __) , OC_DESTR (OC_MISC_TOOLS_ARRAY))
|
||||
OC_DECLARE (OC_MISC_CONFIG)
|
||||
|
||||
/**
|
||||
NVRAM section
|
||||
**/
|
||||
|
||||
///
|
||||
/// NVRAM values is an associative map of GUIDS with their property key value maps.
|
||||
///
|
||||
#define OC_NVRAM_ADD_MAP_FIELDS(_, __) \
|
||||
OC_MAP (OC_STRING, OC_ASSOC, _, __)
|
||||
OC_DECLARE (OC_NVRAM_ADD_MAP)
|
||||
|
||||
#define OC_NVRAM_BLOCK_ENTRY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_STRING, _, __)
|
||||
OC_DECLARE (OC_NVRAM_BLOCK_ENTRY)
|
||||
|
||||
#define OC_NVRAM_BLOCK_MAP_FIELDS(_, __) \
|
||||
OC_MAP (OC_STRING, OC_NVRAM_BLOCK_ENTRY, _, __)
|
||||
OC_DECLARE (OC_NVRAM_BLOCK_MAP)
|
||||
|
||||
#define OC_NVRAM_LEGACY_ENTRY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_STRING, _, __)
|
||||
OC_DECLARE (OC_NVRAM_LEGACY_ENTRY)
|
||||
|
||||
#define OC_NVRAM_LEGACY_MAP_FIELDS(_, __) \
|
||||
OC_MAP (OC_STRING, OC_NVRAM_LEGACY_ENTRY, _, __)
|
||||
OC_DECLARE (OC_NVRAM_LEGACY_MAP)
|
||||
|
||||
#define OC_NVRAM_CONFIG_FIELDS(_, __) \
|
||||
_(OC_NVRAM_ADD_MAP , Add , , OC_CONSTR2 (OC_NVRAM_ADD_MAP, _, __) , OC_DESTR (OC_NVRAM_ADD_MAP)) \
|
||||
_(OC_NVRAM_BLOCK_MAP , Block , , OC_CONSTR2 (OC_NVRAM_BLOCK_MAP, _, __) , OC_DESTR (OC_NVRAM_BLOCK_MAP)) \
|
||||
_(OC_NVRAM_LEGACY_MAP , Legacy , , OC_CONSTR2 (OC_NVRAM_LEGACY_MAP, _, __) , OC_DESTR (OC_NVRAM_LEGACY_MAP)) \
|
||||
_(BOOLEAN , LegacyEnable , , FALSE , () ) \
|
||||
_(BOOLEAN , LegacyOverwrite , , FALSE , () ) \
|
||||
_(BOOLEAN , WriteFlash , , FALSE , () )
|
||||
OC_DECLARE (OC_NVRAM_CONFIG)
|
||||
|
||||
/**
|
||||
Platform information configuration
|
||||
**/
|
||||
|
||||
#define OC_PLATFORM_GENERIC_CONFIG_FIELDS(_, __) \
|
||||
_(OC_STRING , SystemProductName , , OC_STRING_CONSTR ("MacPro6,1", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemSerialNumber , , OC_STRING_CONSTR ("OPENCORE_SN1", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemUuid , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , Mlb , , OC_STRING_CONSTR ("OPENCORE_MLB_SN11", _, __), OC_DESTR (OC_STRING) ) \
|
||||
_(UINT8 , Rom , [6] , {0} , () ) \
|
||||
_(BOOLEAN , SpoofVendor , , FALSE , () ) \
|
||||
_(BOOLEAN , AdviseWindows , , FALSE , () )
|
||||
OC_DECLARE (OC_PLATFORM_GENERIC_CONFIG)
|
||||
|
||||
#define OC_PLATFORM_DATA_HUB_CONFIG_FIELDS(_, __) \
|
||||
_(OC_STRING , PlatformName , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemProductName , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemSerialNumber , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemUuid , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , BoardProduct , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(UINT8 , BoardRevision , [1] , {0} , () ) \
|
||||
_(UINT64 , StartupPowerEvents , , 0 , () ) \
|
||||
_(UINT64 , InitialTSC , , 0 , () ) \
|
||||
_(UINT64 , FSBFrequency , , 0 , () ) \
|
||||
_(UINT64 , ARTFrequency , , 0 , () ) \
|
||||
_(UINT32 , DevicePathsSupported, , 0 , () ) \
|
||||
_(UINT8 , SmcRevision , [6] , {0} , () ) \
|
||||
_(UINT8 , SmcBranch , [8] , {0} , () ) \
|
||||
_(UINT8 , SmcPlatform , [8] , {0} , () )
|
||||
OC_DECLARE (OC_PLATFORM_DATA_HUB_CONFIG)
|
||||
|
||||
#define OC_PLATFORM_NVRAM_CONFIG_FIELDS(_, __) \
|
||||
_(OC_STRING , Bid , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , Mlb , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(UINT8 , Rom , [6] , {0} , () ) \
|
||||
_(UINT64 , FirmwareFeatures , , 0 , () ) \
|
||||
_(UINT64 , FirmwareFeaturesMask , , 0 , () )
|
||||
OC_DECLARE (OC_PLATFORM_NVRAM_CONFIG)
|
||||
|
||||
#define OC_PLATFORM_SMBIOS_CONFIG_FIELDS(_, __) \
|
||||
_(OC_STRING , BIOSVendor , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , BIOSVersion , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , BIOSReleaseDate , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemManufacturer , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemProductName , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemVersion , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemSerialNumber , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemUuid , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemSKUNumber , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , SystemFamily , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , BoardManufacturer , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , BoardProduct , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , BoardVersion , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , BoardSerialNumber , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , BoardAssetTag , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(UINT8 , BoardType , , 0 , () ) \
|
||||
_(OC_STRING , BoardLocationInChassis, , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_STRING , ChassisManufacturer , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(UINT8 , ChassisType , , 0 , () ) \
|
||||
_(OC_STRING , ChassisVersion , , OC_STRING_CONSTR ("", _, __) , () ) \
|
||||
_(OC_STRING , ChassisSerialNumber , , OC_STRING_CONSTR ("", _, __) , () ) \
|
||||
_(OC_STRING , ChassisAssetTag , , OC_STRING_CONSTR ("", _, __) , () ) \
|
||||
_(UINT32 , PlatformFeature , , 0xFFFFFFFFU , () ) \
|
||||
_(UINT64 , FirmwareFeatures , , 0 , () ) \
|
||||
_(UINT64 , FirmwareFeaturesMask , , 0 , () ) \
|
||||
_(UINT8 , SmcVersion , [16] , {0} , () ) \
|
||||
_(UINT16 , ProcessorType , , 0 , () ) \
|
||||
_(UINT8 , MemoryFormFactor , , 0 , () )
|
||||
OC_DECLARE (OC_PLATFORM_SMBIOS_CONFIG)
|
||||
|
||||
#define OC_PLATFORM_CONFIG_FIELDS(_, __) \
|
||||
_(BOOLEAN , Automatic , , FALSE , ()) \
|
||||
_(BOOLEAN , UpdateDataHub , , FALSE , ()) \
|
||||
_(BOOLEAN , UpdateNvram , , FALSE , ()) \
|
||||
_(BOOLEAN , UpdateSmbios , , FALSE , ()) \
|
||||
_(OC_STRING , UpdateSmbiosMode , , OC_STRING_CONSTR ("Create", _, __) , OC_DESTR (OC_STRING) ) \
|
||||
_(OC_PLATFORM_GENERIC_CONFIG , Generic , , OC_CONSTR2 (OC_PLATFORM_GENERIC_CONFIG, _, __) , OC_DESTR (OC_PLATFORM_GENERIC_CONFIG)) \
|
||||
_(OC_PLATFORM_DATA_HUB_CONFIG , DataHub , , OC_CONSTR2 (OC_PLATFORM_DATA_HUB_CONFIG, _, __) , OC_DESTR (OC_PLATFORM_DATA_HUB_CONFIG)) \
|
||||
_(OC_PLATFORM_NVRAM_CONFIG , Nvram , , OC_CONSTR2 (OC_PLATFORM_NVRAM_CONFIG, _, __) , OC_DESTR (OC_PLATFORM_NVRAM_CONFIG)) \
|
||||
_(OC_PLATFORM_SMBIOS_CONFIG , Smbios , , OC_CONSTR2 (OC_PLATFORM_SMBIOS_CONFIG, _, __) , OC_DESTR (OC_PLATFORM_SMBIOS_CONFIG))
|
||||
OC_DECLARE (OC_PLATFORM_CONFIG)
|
||||
|
||||
|
||||
/**
|
||||
Uefi section
|
||||
**/
|
||||
|
||||
///
|
||||
/// Drivers is a sorted array of strings containing driver paths.
|
||||
///
|
||||
#define OC_UEFI_DRIVER_ARRAY_FIELDS(_, __) \
|
||||
OC_ARRAY (OC_STRING, _, __)
|
||||
OC_DECLARE (OC_UEFI_DRIVER_ARRAY)
|
||||
|
||||
///
|
||||
/// Audio is a set of options for sound configuration.
|
||||
///
|
||||
#define OC_UEFI_AUDIO_FIELDS(_, __) \
|
||||
_(OC_STRING , AudioDevice , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING)) \
|
||||
_(UINT16 , VolumeAmplifier , , 0 , ()) \
|
||||
_(BOOLEAN , AudioSupport , , FALSE , ()) \
|
||||
_(BOOLEAN , PlayChime , , FALSE , ()) \
|
||||
_(UINT8 , AudioCodec , , 0 , ()) \
|
||||
_(UINT8 , AudioOut , , 0 , ()) \
|
||||
_(UINT8 , MinimumVolume , , 0 , ())
|
||||
OC_DECLARE (OC_UEFI_AUDIO)
|
||||
|
||||
///
|
||||
/// Input is a set of options to support advanced input.
|
||||
///
|
||||
#define OC_UEFI_INPUT_FIELDS(_, __) \
|
||||
_(UINT8 , KeyForgetThreshold , , 0 , ()) \
|
||||
_(UINT8 , KeyMergeThreshold , , 0 , ()) \
|
||||
_(BOOLEAN , KeySupport , , FALSE , ()) \
|
||||
_(OC_STRING , KeySupportMode , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING)) \
|
||||
_(BOOLEAN , KeySwap , , FALSE , ()) \
|
||||
_(BOOLEAN , PointerSupport , , FALSE , ()) \
|
||||
_(OC_STRING , PointerSupportMode , , OC_STRING_CONSTR ("", _, __) , OC_DESTR (OC_STRING)) \
|
||||
_(UINT32 , TimerResolution , , 0 , ())
|
||||
OC_DECLARE (OC_UEFI_INPUT)
|
||||
|
||||
///
|
||||
/// Output is a set of options to support advanced output.
|
||||
///
|
||||
#define OC_UEFI_OUTPUT_FIELDS(_, __) \
|
||||
_(OC_STRING , ConsoleMode , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING)) \
|
||||
_(OC_STRING , Resolution , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING)) \
|
||||
_(OC_STRING , TextRenderer , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING)) \
|
||||
_(BOOLEAN , IgnoreTextInGraphics , , FALSE , ()) \
|
||||
_(BOOLEAN , ClearScreenOnModeSwitch , , FALSE , ()) \
|
||||
_(BOOLEAN , ProvideConsoleGop , , FALSE , ()) \
|
||||
_(BOOLEAN , ReplaceTabWithSpace , , FALSE , ()) \
|
||||
_(BOOLEAN , ReconnectOnResChange , , FALSE , ()) \
|
||||
_(BOOLEAN , SanitiseClearScreen , , FALSE , ()) \
|
||||
_(BOOLEAN , DirectGopRendering , , FALSE , ())
|
||||
OC_DECLARE (OC_UEFI_OUTPUT)
|
||||
|
||||
///
|
||||
/// Prefer own protocol implementation for these protocols.
|
||||
///
|
||||
#define OC_UEFI_PROTOCOLS_FIELDS(_, __) \
|
||||
_(BOOLEAN , AppleAudio , , FALSE , ()) \
|
||||
_(BOOLEAN , AppleBootPolicy , , FALSE , ()) \
|
||||
_(BOOLEAN , AppleEvent , , FALSE , ()) \
|
||||
_(BOOLEAN , AppleImageConversion , , FALSE , ()) \
|
||||
_(BOOLEAN , AppleKeyMap , , FALSE , ()) \
|
||||
_(BOOLEAN , AppleSmcIo , , FALSE , ()) \
|
||||
_(BOOLEAN , AppleUserInterfaceTheme , , FALSE , ()) \
|
||||
_(BOOLEAN , DataHub , , FALSE , ()) \
|
||||
_(BOOLEAN , DeviceProperties , , FALSE , ()) \
|
||||
_(BOOLEAN , FirmwareVolume , , FALSE , ()) \
|
||||
_(BOOLEAN , HashServices , , FALSE , ()) \
|
||||
_(BOOLEAN , OSInfo , , FALSE , ()) \
|
||||
_(BOOLEAN , UnicodeCollation , , FALSE , ())
|
||||
OC_DECLARE (OC_UEFI_PROTOCOLS)
|
||||
|
||||
///
|
||||
/// Quirks is a set of hacks for different firmwares.
|
||||
///
|
||||
#define OC_UEFI_QUIRKS_FIELDS(_, __) \
|
||||
_(UINT32 , ExitBootServicesDelay , , 0 , ()) \
|
||||
_(BOOLEAN , IgnoreInvalidFlexRatio , , FALSE , ()) \
|
||||
_(BOOLEAN , ReleaseUsbOwnership , , FALSE , ()) \
|
||||
_(BOOLEAN , RequestBootVarFallback , , FALSE , ()) \
|
||||
_(BOOLEAN , RequestBootVarRouting , , FALSE , ()) \
|
||||
_(BOOLEAN , UnblockFsConnect , , FALSE , ())
|
||||
OC_DECLARE (OC_UEFI_QUIRKS)
|
||||
|
||||
///
|
||||
/// Uefi contains firmware tweaks and extra drivers.
|
||||
///
|
||||
#define OC_UEFI_CONFIG_FIELDS(_, __) \
|
||||
_(BOOLEAN , ConnectDrivers , , FALSE , ()) \
|
||||
_(OC_UEFI_AUDIO , Audio , , OC_CONSTR2 (OC_UEFI_AUDIO, _, __) , OC_DESTR (OC_UEFI_AUDIO)) \
|
||||
_(OC_UEFI_DRIVER_ARRAY , Drivers , , OC_CONSTR2 (OC_UEFI_DRIVER_ARRAY, _, __) , OC_DESTR (OC_UEFI_DRIVER_ARRAY)) \
|
||||
_(OC_UEFI_INPUT , Input , , OC_CONSTR2 (OC_UEFI_INPUT, _, __) , OC_DESTR (OC_UEFI_INPUT)) \
|
||||
_(OC_UEFI_OUTPUT , Output , , OC_CONSTR2 (OC_UEFI_OUTPUT, _, __) , OC_DESTR (OC_UEFI_OUTPUT)) \
|
||||
_(OC_UEFI_PROTOCOLS , Protocols , , OC_CONSTR2 (OC_UEFI_PROTOCOLS, _, __) , OC_DESTR (OC_UEFI_PROTOCOLS)) \
|
||||
_(OC_UEFI_QUIRKS , Quirks , , OC_CONSTR2 (OC_UEFI_QUIRKS, _, __) , OC_DESTR (OC_UEFI_QUIRKS))
|
||||
OC_DECLARE (OC_UEFI_CONFIG)
|
||||
|
||||
/**
|
||||
Root configuration
|
||||
**/
|
||||
|
||||
#define OC_GLOBAL_CONFIG_FIELDS(_, __) \
|
||||
_(OC_ACPI_CONFIG , Acpi , , OC_CONSTR1 (OC_ACPI_CONFIG, _, __) , OC_DESTR (OC_ACPI_CONFIG)) \
|
||||
_(OC_BOOTER_CONFIG , Booter , , OC_CONSTR1 (OC_BOOTER_CONFIG, _, __) , OC_DESTR (OC_BOOTER_CONFIG)) \
|
||||
_(OC_DEV_PROP_CONFIG , DeviceProperties , , OC_CONSTR1 (OC_DEV_PROP_CONFIG, _, __) , OC_DESTR (OC_DEV_PROP_CONFIG)) \
|
||||
_(OC_KERNEL_CONFIG , Kernel , , OC_CONSTR1 (OC_KERNEL_CONFIG, _, __) , OC_DESTR (OC_KERNEL_CONFIG)) \
|
||||
_(OC_MISC_CONFIG , Misc , , OC_CONSTR1 (OC_MISC_CONFIG, _, __) , OC_DESTR (OC_MISC_CONFIG)) \
|
||||
_(OC_NVRAM_CONFIG , Nvram , , OC_CONSTR1 (OC_NVRAM_CONFIG, _, __) , OC_DESTR (OC_NVRAM_CONFIG)) \
|
||||
_(OC_PLATFORM_CONFIG , PlatformInfo , , OC_CONSTR1 (OC_PLATFORM_CONFIG, _, __) , OC_DESTR (OC_PLATFORM_CONFIG)) \
|
||||
_(OC_UEFI_CONFIG , Uefi , , OC_CONSTR1 (OC_UEFI_CONFIG, _, __) , OC_DESTR (OC_UEFI_CONFIG))
|
||||
OC_DECLARE (OC_GLOBAL_CONFIG)
|
||||
|
||||
/**
|
||||
Initialize configuration with plist data.
|
||||
|
||||
@param[out] Config Configuration structure.
|
||||
@param[in] Buffer Configuration buffer in plist format.
|
||||
@param[in] Size Configuration buffer size.
|
||||
|
||||
@retval EFI_SUCCESS on success
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcConfigurationInit (
|
||||
OUT OC_GLOBAL_CONFIG *Config,
|
||||
IN VOID *Buffer,
|
||||
IN UINT32 Size
|
||||
);
|
||||
|
||||
/**
|
||||
Free configuration structure.
|
||||
|
||||
@param[in,out] Config Configuration structure.
|
||||
**/
|
||||
VOID
|
||||
OcConfigurationFree (
|
||||
IN OUT OC_GLOBAL_CONFIG *Config
|
||||
);
|
||||
|
||||
#endif // OC_CONFIGURATION_LIB_H
|
||||
165
Include/Library/OcConsoleLib.h
Normal file
165
Include/Library/OcConsoleLib.h
Normal file
@ -0,0 +1,165 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_CONSOLE_LIB_H
|
||||
#define OC_CONSOLE_LIB_H
|
||||
|
||||
#include <Protocol/ConsoleControl.h>
|
||||
|
||||
/**
|
||||
Console renderer to use.
|
||||
**/
|
||||
typedef enum {
|
||||
OcConsoleRendererBuiltinGraphics,
|
||||
OcConsoleRendererSystemGraphics,
|
||||
OcConsoleRendererSystemText,
|
||||
OcConsoleRendererSystemGeneric
|
||||
} OC_CONSOLE_RENDERER;
|
||||
|
||||
/**
|
||||
Special commands sent to Builtin text renderer through TestString.
|
||||
**/
|
||||
#define OC_CONSOLE_CLEAR_AND_CLIP L"ClearAndClip"
|
||||
|
||||
/**
|
||||
Configure console control protocol with given options.
|
||||
|
||||
@param[in] Renderer Renderer to use.
|
||||
@param[in] IgnoreTextOutput Skip console output in text mode.
|
||||
@param[in] SanitiseClearScreen Workaround ClearScreen breaking resolution.
|
||||
@param[in] ClearScreenOnModeSwitch Clear graphic screen when switching to text mode.
|
||||
@param[in] ReplaceTabWithSpace Replace invisible tab characters with spaces in OutputString.
|
||||
**/
|
||||
VOID
|
||||
OcSetupConsole (
|
||||
IN OC_CONSOLE_RENDERER Renderer,
|
||||
IN BOOLEAN IgnoreTextOutput,
|
||||
IN BOOLEAN SanitiseClearScreen,
|
||||
IN BOOLEAN ClearScreenOnModeSwitch,
|
||||
IN BOOLEAN ReplaceTabWithSpace
|
||||
);
|
||||
|
||||
/**
|
||||
Update console control screen mode.
|
||||
|
||||
@param[in] Mode Desired mode.
|
||||
|
||||
@retval previous console control mode.
|
||||
**/
|
||||
EFI_CONSOLE_CONTROL_SCREEN_MODE
|
||||
OcConsoleControlSetMode (
|
||||
IN EFI_CONSOLE_CONTROL_SCREEN_MODE Mode
|
||||
);
|
||||
|
||||
/**
|
||||
Parse screen resolution from string.
|
||||
|
||||
@param[in] String Resolution in WxH@B or WxH format.
|
||||
@param[out] Width Parsed resolution width or 0.
|
||||
@param[out] Height Parsed resolution height or 0.
|
||||
@param[out] Bpp Parsed resolution bpp or 0.
|
||||
@param[out] Max Set to TRUE when String equals to Max.
|
||||
**/
|
||||
VOID
|
||||
OcParseScreenResolution (
|
||||
IN CONST CHAR8 *String,
|
||||
OUT UINT32 *Width,
|
||||
OUT UINT32 *Height,
|
||||
OUT UINT32 *Bpp,
|
||||
OUT BOOLEAN *Max
|
||||
);
|
||||
|
||||
/**
|
||||
Parse console mode from string.
|
||||
|
||||
@param[in] String Resolution in WxH format.
|
||||
@param[out] Width Parsed mode width or 0.
|
||||
@param[out] Height Parsed mode height or 0.
|
||||
@param[out] Max Set to TRUE when String equals to Max.
|
||||
**/
|
||||
VOID
|
||||
OcParseConsoleMode (
|
||||
IN CONST CHAR8 *String,
|
||||
OUT UINT32 *Width,
|
||||
OUT UINT32 *Height,
|
||||
OUT BOOLEAN *Max
|
||||
);
|
||||
|
||||
/**
|
||||
Set screen resolution on console handle.
|
||||
|
||||
@param[in] Width Resolution width or 0 for Max.
|
||||
@param[in] Height Resolution height or 0 for Max.
|
||||
@param[in] Bpp Resolution bpp or 0 for automatic.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcSetConsoleResolution (
|
||||
IN UINT32 Width,
|
||||
IN UINT32 Height,
|
||||
IN UINT32 Bpp OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Set console mode.
|
||||
|
||||
@param[in] Width Resolution width or 0 for Max.
|
||||
@param[in] Height Resolution height or 0 for Max.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcSetConsoleMode (
|
||||
IN UINT32 Width,
|
||||
IN UINT32 Height
|
||||
);
|
||||
|
||||
/**
|
||||
Ensure installed GOP protocol on ConOut handle.
|
||||
**/
|
||||
VOID
|
||||
OcProvideConsoleGop (
|
||||
IN BOOLEAN Route
|
||||
);
|
||||
|
||||
/**
|
||||
Perform console reconnection.
|
||||
**/
|
||||
VOID
|
||||
OcReconnectConsole (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Use direct GOP renderer for console.
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcUseDirectGop (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Allocate new System Table with disabled text output.
|
||||
|
||||
@param[in] SystemTable Base System Table.
|
||||
|
||||
@retval non NULL The System Table table was allocated successfully.
|
||||
**/
|
||||
EFI_SYSTEM_TABLE *
|
||||
AllocateNullTextOutSystemTable (
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
#endif // OC_CONSOLE_LIB_H
|
||||
197
Include/Library/OcCpuLib.h
Executable file
197
Include/Library/OcCpuLib.h
Executable file
@ -0,0 +1,197 @@
|
||||
/** @file
|
||||
Copyright (C) 2016 - 2017, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_CPU_LIB_H
|
||||
#define OC_CPU_LIB_H
|
||||
|
||||
#include <IndustryStandard/CpuId.h>
|
||||
#include <IndustryStandard/AppleIntelCpuInfo.h>
|
||||
|
||||
/**
|
||||
Assumed CPU frequency when it cannot be detected.
|
||||
**/
|
||||
#define OC_FALLBACK_CPU_FREQUENCY 1000000000
|
||||
|
||||
typedef struct {
|
||||
//
|
||||
// Note, Vendor and BrandString are reordered for proper alignment.
|
||||
//
|
||||
UINT32 Vendor[4];
|
||||
CHAR8 BrandString[48];
|
||||
|
||||
CPUID_VERSION_INFO_EAX CpuidVerEax;
|
||||
CPUID_VERSION_INFO_EBX CpuidVerEbx;
|
||||
CPUID_VERSION_INFO_ECX CpuidVerEcx;
|
||||
CPUID_VERSION_INFO_EDX CpuidVerEdx;
|
||||
|
||||
UINT32 MicrocodeRevision;
|
||||
BOOLEAN Hypervisor; //< indicate whether we are under virtualization
|
||||
|
||||
UINT8 Type;
|
||||
UINT8 Family;
|
||||
UINT8 Model;
|
||||
UINT8 ExtModel;
|
||||
UINT8 ExtFamily;
|
||||
UINT8 Stepping;
|
||||
UINT64 Features;
|
||||
UINT64 ExtFeatures;
|
||||
UINT32 Signature;
|
||||
UINT8 Brand;
|
||||
UINT16 AppleProcessorType;
|
||||
BOOLEAN CstConfigLock;
|
||||
|
||||
UINT32 MaxId;
|
||||
UINT32 MaxExtId;
|
||||
|
||||
UINT8 MaxDiv;
|
||||
UINT8 CurBusRatio; ///< Current Multiplier
|
||||
UINT8 MinBusRatio; ///< Min Bus Ratio
|
||||
UINT8 MaxBusRatio; ///< Max Bus Ratio
|
||||
|
||||
UINT8 TurboBusRatio1;
|
||||
UINT8 TurboBusRatio2;
|
||||
UINT8 TurboBusRatio3;
|
||||
UINT8 TurboBusRatio4;
|
||||
|
||||
UINT16 PackageCount;
|
||||
UINT16 CoreCount;
|
||||
UINT16 ThreadCount;
|
||||
|
||||
//
|
||||
// External clock for SMBIOS Type4 table.
|
||||
//
|
||||
UINT16 ExternalClock;
|
||||
|
||||
//
|
||||
// Platform-dependent frequency for the Always Running Timer (ART), normally
|
||||
// 24Mhz. Firmwares may choose to override this. Some CPUs like Xeon Scalable
|
||||
// use a different frequency. CPUs report the frequency through CPUID.15H.ECX.
|
||||
// If unreported, the frequency is looked up based on the model and family.
|
||||
//
|
||||
// Nominal Core Crystal Clock Frequency for known processor families:
|
||||
// Intel Xeon Scalable with CPUID signature 0x0655: 25 Mhz (server segment)
|
||||
// 6th and 7th generation Intel Core & Xeon W: 24 Mhz (client segment)
|
||||
// Nex Generation Intel Atom with CPUID 0x065C: 19.2 Mhz (atom segment)
|
||||
//
|
||||
UINT64 ARTFrequency;
|
||||
|
||||
//
|
||||
// The CPU frequency derived from either CPUFrequencyFromTSC (legacy) or
|
||||
// CPUFrequencyFromART (preferred for Skylake and presumably newer processors
|
||||
// that have an Always Running Timer).
|
||||
//
|
||||
// CPUFrequencyFromTSC should approximate equal CPUFrequencyFromART. If not,
|
||||
// there is likely a bug or miscalculation.
|
||||
//
|
||||
UINT64 CPUFrequency;
|
||||
|
||||
//
|
||||
// The CPU frequency as reported by the Time Stamp Counter (TSC).
|
||||
//
|
||||
UINT64 CPUFrequencyFromTSC;
|
||||
|
||||
//
|
||||
// The CPU frequency derived from the Always Running Timer (ART) frequency:
|
||||
// TSC Freq = (ART Freq * CPUID.15H:EBX[31:0]) / CPUID.15H:EAX[31:0]
|
||||
//
|
||||
// 0 if ART is not present.
|
||||
//
|
||||
UINT64 CPUFrequencyFromART;
|
||||
|
||||
|
||||
//
|
||||
// The CPU frequency derived from the CPUID VMWare Timing leaf.
|
||||
// 0 if VMWare Timing leaf is not present.
|
||||
//
|
||||
UINT64 CPUFrequencyFromVMT;
|
||||
|
||||
//
|
||||
// The Front Side Bus (FSB) frequency calculated from dividing the CPU
|
||||
// frequency by the Max Ratio.
|
||||
//
|
||||
UINT64 FSBFrequency;
|
||||
} OC_CPU_INFO;
|
||||
|
||||
typedef enum {
|
||||
OcCpuGenerationUnknown,
|
||||
OcCpuGenerationPenryn,
|
||||
OcCpuGenerationNehalem,
|
||||
OcCpuGenerationWestmere,
|
||||
OcCpuGenerationSandyBridge,
|
||||
OcCpuGenerationIvyBridge,
|
||||
OcCpuGenerationHaswell,
|
||||
OcCpuGenerationBroadwell,
|
||||
OcCpuGenerationSkylake,
|
||||
OcCpuGenerationKabyLake,
|
||||
OcCpuGenerationCoffeeLake,
|
||||
OcCpuGenerationCannonLake,
|
||||
OcCpuGenerationMaxGeneration
|
||||
} OC_CPU_GENERATION;
|
||||
|
||||
/**
|
||||
Scan the processor and fill the cpu info structure with results.
|
||||
|
||||
@param[in] Cpu A pointer to the cpu info structure to fill with results.
|
||||
**/
|
||||
VOID
|
||||
OcCpuScanProcessor (
|
||||
IN OUT OC_CPU_INFO *Cpu
|
||||
);
|
||||
|
||||
/**
|
||||
Disable flex ratio if it has invalid value.
|
||||
Commonly fixes early reboot on APTIO IV (Ivy/Haswell).
|
||||
|
||||
@param[in] Cpu A pointer to the cpu info.
|
||||
**/
|
||||
VOID
|
||||
OcCpuCorrectFlexRatio (
|
||||
IN OC_CPU_INFO *Cpu
|
||||
);
|
||||
|
||||
/**
|
||||
Converts CPUID Family and Model extracted from EAX
|
||||
CPUID (1) call to AppleFamily value. This implements
|
||||
cpuid_set_cpufamily functionality as it is in XNU.
|
||||
|
||||
@param[in] VersionEax CPUID (1) EAX value.
|
||||
|
||||
@retval Apple Family (e.g. CPUFAMILY_UNKNOWN)
|
||||
**/
|
||||
UINT32
|
||||
OcCpuModelToAppleFamily (
|
||||
IN CPUID_VERSION_INFO_EAX VersionEax
|
||||
);
|
||||
|
||||
/**
|
||||
Obtain CPU's generation.
|
||||
|
||||
@retval CPU's generation (e.g. OcCpuGenerationUnknown).
|
||||
*/
|
||||
OC_CPU_GENERATION
|
||||
OcCpuGetGeneration (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Obtain CPU's invariant TSC frequency.
|
||||
|
||||
@retval CPU's TSC frequency or OC_FALLBACK_CPU_FREQUENCY.
|
||||
**/
|
||||
UINT64
|
||||
OcGetTSCFrequency (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif // OC_CPU_LIB_H_
|
||||
541
Include/Library/OcCryptoLib.h
Normal file
541
Include/Library/OcCryptoLib.h
Normal file
@ -0,0 +1,541 @@
|
||||
/** @file
|
||||
|
||||
OcCryptoLib
|
||||
|
||||
Copyright (c) 2018, savvas
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_CRYPTO_LIB_H
|
||||
#define OC_CRYPTO_LIB_H
|
||||
|
||||
#include <Library/OcGuardLib.h>
|
||||
|
||||
//
|
||||
// Default to 128-bit key length for AES.
|
||||
//
|
||||
#ifndef CONFIG_AES_KEY_SIZE
|
||||
#define CONFIG_AES_KEY_SIZE 16
|
||||
#endif
|
||||
|
||||
//
|
||||
// Digest sizes.
|
||||
//
|
||||
#define MD5_DIGEST_SIZE 16
|
||||
#define SHA1_DIGEST_SIZE 20
|
||||
#define SHA256_DIGEST_SIZE 32
|
||||
#define SHA384_DIGEST_SIZE 48
|
||||
#define SHA512_DIGEST_SIZE 64
|
||||
|
||||
#define OC_MAX_SHA_DIGEST_SIZE SHA512_DIGEST_SIZE
|
||||
|
||||
//
|
||||
// Block sizes.
|
||||
//
|
||||
#define SHA256_BLOCK_SIZE 64
|
||||
#define SHA512_BLOCK_SIZE 128
|
||||
#define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE
|
||||
|
||||
//
|
||||
// Derived parameters.
|
||||
//
|
||||
#define AES_BLOCK_SIZE 16
|
||||
|
||||
//
|
||||
// Support all AES key sizes.
|
||||
//
|
||||
#if CONFIG_AES_KEY_SIZE == 32
|
||||
#define AES_KEY_EXP_SIZE 240
|
||||
#elif CONFIG_AES_KEY_SIZE == 24
|
||||
#define AES_KEY_EXP_SIZE 208
|
||||
#elif CONFIG_AES_KEY_SIZE == 16
|
||||
#define AES_KEY_EXP_SIZE 176
|
||||
#else
|
||||
#error "Only AES-128, AES-192, and AES-256 are supported!"
|
||||
#endif
|
||||
|
||||
//
|
||||
// ChaCha key size.
|
||||
//
|
||||
#define CHACHA_KEY_SIZE 32
|
||||
|
||||
//
|
||||
// ChaCha IV size.
|
||||
//
|
||||
#define CHACHA_IV_SIZE 12
|
||||
|
||||
//
|
||||
// Possible RSA algorithm types supported by OcCryptoLib
|
||||
// for RSA digital signature verification
|
||||
// PcdOcCryptoAllowedSigHashTypes MUST be kept in sync with changes!
|
||||
//
|
||||
typedef enum OC_SIG_HASH_TYPE_ {
|
||||
OcSigHashTypeSha256,
|
||||
OcSigHashTypeSha384,
|
||||
OcSigHashTypeSha512,
|
||||
OcSigHashTypeMax
|
||||
} OC_SIG_HASH_TYPE;
|
||||
|
||||
typedef struct AES_CONTEXT_ {
|
||||
UINT8 RoundKey[AES_KEY_EXP_SIZE];
|
||||
UINT8 Iv[AES_BLOCK_SIZE];
|
||||
} AES_CONTEXT;
|
||||
|
||||
typedef struct CHACHA_CONTEXT_ {
|
||||
UINT32 Input[16];
|
||||
} CHACHA_CONTEXT;
|
||||
|
||||
typedef struct MD5_CONTEXT_ {
|
||||
UINT8 Data[64];
|
||||
UINT32 DataLen;
|
||||
UINT64 BitLen;
|
||||
UINT32 State[4];
|
||||
} MD5_CONTEXT;
|
||||
|
||||
typedef struct SHA1_CONTEXT_ {
|
||||
UINT8 Data[64];
|
||||
UINT32 DataLen;
|
||||
UINT64 BitLen;
|
||||
UINT32 State[5];
|
||||
UINT32 K[4];
|
||||
} SHA1_CONTEXT;
|
||||
|
||||
typedef struct SHA256_CONTEXT_ {
|
||||
UINT8 Data[64];
|
||||
UINT32 DataLen;
|
||||
UINT64 BitLen;
|
||||
UINT32 State[8];
|
||||
} SHA256_CONTEXT;
|
||||
|
||||
typedef struct SHA512_CONTEXT_ {
|
||||
UINT64 TotalLength;
|
||||
UINTN Length;
|
||||
UINT8 Block[2 * SHA512_BLOCK_SIZE];
|
||||
UINT64 State[8];
|
||||
} SHA512_CONTEXT;
|
||||
|
||||
typedef SHA512_CONTEXT SHA384_CONTEXT;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
///
|
||||
/// The structure describing the RSA Public Key format.
|
||||
/// The exponent is always 65537.
|
||||
///
|
||||
typedef PACKED struct {
|
||||
///
|
||||
/// The number of 64-bit values of N and RSqrMod each.
|
||||
///
|
||||
UINT16 NumQwords;
|
||||
///
|
||||
/// Padding for 64-bit alignment. Must be 0 to allow future extensions.
|
||||
///
|
||||
UINT8 Reserved[6];
|
||||
///
|
||||
/// The Montgomery Inverse in 64-bit space: -1 / N[0] mod 2^64.
|
||||
///
|
||||
UINT64 N0Inv;
|
||||
} OC_RSA_PUBLIC_KEY_HDR;
|
||||
|
||||
typedef PACKED struct {
|
||||
///
|
||||
/// The RSA Public Key header structure.
|
||||
///
|
||||
OC_RSA_PUBLIC_KEY_HDR Hdr;
|
||||
///
|
||||
/// The Modulus and Montgomery's R^2 mod N in little endian byte order.
|
||||
///
|
||||
UINT64 Data[];
|
||||
} OC_RSA_PUBLIC_KEY;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
//
|
||||
// Functions prototypes
|
||||
//
|
||||
|
||||
VOID
|
||||
AesInitCtxIv (
|
||||
OUT AES_CONTEXT *Context,
|
||||
IN CONST UINT8 *Key,
|
||||
IN CONST UINT8 *Iv
|
||||
);
|
||||
|
||||
VOID
|
||||
AesSetCtxIv (
|
||||
OUT AES_CONTEXT *Context,
|
||||
IN CONST UINT8 *Iv
|
||||
);
|
||||
|
||||
//
|
||||
// Data size MUST be mutiple of AES_BLOCK_SIZE;
|
||||
// Suggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for Padding scheme
|
||||
// NOTES: you need to set Iv in Context via AesInitCtxIv() or AesSetCtxIv()
|
||||
// no Iv should ever be reused with the same key
|
||||
//
|
||||
VOID
|
||||
AesCbcEncryptBuffer (
|
||||
IN OUT AES_CONTEXT *Context,
|
||||
IN OUT UINT8 *Data,
|
||||
IN UINT32 Len
|
||||
);
|
||||
|
||||
VOID
|
||||
AesCbcDecryptBuffer (
|
||||
IN OUT AES_CONTEXT *Context,
|
||||
IN OUT UINT8 *Data,
|
||||
IN UINT32 Len
|
||||
);
|
||||
|
||||
//
|
||||
// Same function for encrypting as for decrypting.
|
||||
// Iv is incremented for every block, and used after encryption as XOR-compliment for output
|
||||
// Suggesting https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for Padding scheme
|
||||
// NOTES: you need to set Iv in Context via AesInitCtxIv() or AesSetCtxIv()
|
||||
// no Iv should ever be reused with the same key
|
||||
//
|
||||
VOID
|
||||
AesCtrXcryptBuffer (
|
||||
IN OUT AES_CONTEXT *Context,
|
||||
IN OUT UINT8 *Data,
|
||||
IN UINT32 Len
|
||||
);
|
||||
|
||||
/**
|
||||
Setup ChaCha context (IETF variant).
|
||||
|
||||
@param[out] Context ChaCha context.
|
||||
@param[in] Key ChaCha 256-bit key.
|
||||
@param[in] Iv ChaCha 96-bit initialisation vector.
|
||||
@param[in] Counter ChaCha 32-bit counter.
|
||||
**/
|
||||
VOID
|
||||
ChaChaInitCtx (
|
||||
OUT CHACHA_CONTEXT *Context,
|
||||
IN CONST UINT8 *Key,
|
||||
IN CONST UINT8 *Iv,
|
||||
IN UINT32 Counter
|
||||
);
|
||||
|
||||
/**
|
||||
Perform ChaCha encryption/decryption.
|
||||
Source may match Destination.
|
||||
|
||||
@param[in,out] Context ChaCha context.
|
||||
@param[in] Source Data for transformation.
|
||||
@param[out] Destination Resulting data.
|
||||
@param[in] Length Data and ciphertext lengths.
|
||||
**/
|
||||
VOID
|
||||
ChaChaCryptBuffer (
|
||||
IN OUT CHACHA_CONTEXT *Context,
|
||||
IN CONST UINT8 *Source,
|
||||
OUT UINT8 *Destination,
|
||||
IN UINT32 Length
|
||||
);
|
||||
|
||||
VOID
|
||||
Md5Init (
|
||||
MD5_CONTEXT *Context
|
||||
);
|
||||
|
||||
VOID
|
||||
Md5Update (
|
||||
MD5_CONTEXT *Context,
|
||||
CONST UINT8 *Data,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
VOID
|
||||
Md5Final (
|
||||
MD5_CONTEXT *Context,
|
||||
UINT8 *Hash
|
||||
);
|
||||
|
||||
VOID
|
||||
Md5 (
|
||||
UINT8 *Hash,
|
||||
UINT8 *Data,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha1Init (
|
||||
SHA1_CONTEXT *Context
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha1Update (
|
||||
SHA1_CONTEXT *Context,
|
||||
CONST UINT8 *Data,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha1Final (
|
||||
SHA1_CONTEXT *Context,
|
||||
UINT8 *Hash
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha1 (
|
||||
UINT8 *Hash,
|
||||
UINT8 *Data,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha256Init (
|
||||
SHA256_CONTEXT *Context
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha256Update (
|
||||
SHA256_CONTEXT *Context,
|
||||
CONST UINT8 *Data,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha256Final (
|
||||
SHA256_CONTEXT *Context,
|
||||
UINT8 *HashDigest
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha256 (
|
||||
UINT8 *Hash,
|
||||
CONST UINT8 *Data,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha512Init (
|
||||
SHA512_CONTEXT *Context
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha512Update (
|
||||
SHA512_CONTEXT *Context,
|
||||
CONST UINT8 *Data,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha512Final (
|
||||
SHA512_CONTEXT *Context,
|
||||
UINT8 *HashDigest
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha512 (
|
||||
UINT8 *Hash,
|
||||
CONST UINT8 *Data,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha384Init (
|
||||
SHA384_CONTEXT *Context
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha384Update (
|
||||
SHA384_CONTEXT *Context,
|
||||
CONST UINT8 *Data,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha384Final (
|
||||
SHA384_CONTEXT *Context,
|
||||
UINT8 *HashDigest
|
||||
);
|
||||
|
||||
VOID
|
||||
Sha384 (
|
||||
UINT8 *Hash,
|
||||
CONST UINT8 *Data,
|
||||
UINTN Len
|
||||
);
|
||||
|
||||
/**
|
||||
Verifies Data against Hash with the appropiate SHA2 algorithm for HashSize.
|
||||
|
||||
@param[in] Data The data to verify the hash of.
|
||||
@param[in] DataSize The, in bytes, of Data.
|
||||
@param[in] Hash The reference hash to verify against.
|
||||
@param[in] HashSize The size, in bytes, of Hash.
|
||||
|
||||
@return 0 All HashSize bytes of the two buffers are identical.
|
||||
@retval Non-zero If HashSize is not a valid SHA2 digest size, -1. Otherwise,
|
||||
the first mismatched byte in Data's hash subtracted from
|
||||
the first mismatched byte in Hash.
|
||||
|
||||
**/
|
||||
INTN
|
||||
SigVerifyShaHashBySize (
|
||||
IN CONST VOID *Data,
|
||||
IN UINTN DataSize,
|
||||
IN CONST UINT8 *Hash,
|
||||
IN UINTN HashSize
|
||||
);
|
||||
|
||||
/**
|
||||
Verify a RSA PKCS1.5 signature against an expected hash.
|
||||
The exponent is always 65537 as per the format specification.
|
||||
|
||||
@param[in] Key The RSA Public Key.
|
||||
@param[in] Signature The RSA signature to be verified.
|
||||
@param[in] SignatureSize Size, in bytes, of Signature.
|
||||
@param[in] Hash The Hash digest of the signed data.
|
||||
@param[in] HashSize Size, in bytes, of Hash.
|
||||
@param[in] Algorithm The RSA algorithm used.
|
||||
|
||||
@returns Whether the signature has been successfully verified as valid.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
RsaVerifySigHashFromKey (
|
||||
IN CONST OC_RSA_PUBLIC_KEY *Key,
|
||||
IN CONST UINT8 *Signature,
|
||||
IN UINTN SignatureSize,
|
||||
IN CONST UINT8 *Hash,
|
||||
IN UINTN HashSize,
|
||||
IN OC_SIG_HASH_TYPE Algorithm
|
||||
);
|
||||
|
||||
/**
|
||||
Verify RSA PKCS1.5 signed data against its signature.
|
||||
The modulus' size must be a multiple of the configured BIGNUM word size.
|
||||
This will be true for any conventional RSA, which use two's potencies.
|
||||
|
||||
@param[in] Modulus The RSA modulus byte array.
|
||||
@param[in] ModulusSize The size, in bytes, of Modulus.
|
||||
@param[in] Exponent The RSA exponent.
|
||||
@param[in] Signature The RSA signature to be verified.
|
||||
@param[in] SignatureSize Size, in bytes, of Signature.
|
||||
@param[in] Data The signed data to verify.
|
||||
@param[in] DataSize Size, in bytes, of Data.
|
||||
@param[in] Algorithm The RSA algorithm used.
|
||||
|
||||
@returns Whether the signature has been successfully verified as valid.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
RsaVerifySigDataFromData (
|
||||
IN CONST UINT8 *Modulus,
|
||||
IN UINTN ModulusSize,
|
||||
IN UINT32 Exponent,
|
||||
IN CONST UINT8 *Signature,
|
||||
IN UINTN SignatureSize,
|
||||
IN CONST UINT8 *Data,
|
||||
IN UINTN DataSize,
|
||||
IN OC_SIG_HASH_TYPE Algorithm
|
||||
);
|
||||
|
||||
/**
|
||||
Verify RSA PKCS1.5 signed data against its signature.
|
||||
The modulus' size must be a multiple of the configured BIGNUM word size.
|
||||
This will be true for any conventional RSA, which use two's potencies.
|
||||
The exponent is always 65537 as per the format specification.
|
||||
|
||||
@param[in] Key The RSA Public Key.
|
||||
@param[in] Signature The RSA signature to be verified.
|
||||
@param[in] SignatureSize Size, in bytes, of Signature.
|
||||
@param[in] Data The signed data to verify.
|
||||
@param[in] DataSize Size, in bytes, of Data.
|
||||
@param[in] Algorithm The RSA algorithm used.
|
||||
|
||||
@returns Whether the signature has been successfully verified as valid.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
RsaVerifySigDataFromKey (
|
||||
IN CONST OC_RSA_PUBLIC_KEY *Key,
|
||||
IN CONST UINT8 *Signature,
|
||||
IN UINTN SignatureSize,
|
||||
IN CONST UINT8 *Data,
|
||||
IN UINTN DataSize,
|
||||
IN OC_SIG_HASH_TYPE Algorithm
|
||||
);
|
||||
|
||||
/**
|
||||
Performs a cryptographically secure comparison of the contents of two
|
||||
buffers.
|
||||
|
||||
This function compares Length bytes of SourceBuffer to Length bytes of
|
||||
DestinationBuffer in a cryptographically secure fashion. This especially
|
||||
implies that different lengths of the longest shared prefix do not change
|
||||
execution time in a way relevant to security.
|
||||
|
||||
If Length > 0 and DestinationBuffer is NULL, then ASSERT().
|
||||
If Length > 0 and SourceBuffer is NULL, then ASSERT().
|
||||
If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().
|
||||
If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
|
||||
|
||||
@param DestinationBuffer The pointer to the destination buffer to compare.
|
||||
@param SourceBuffer The pointer to the source buffer to compare.
|
||||
@param Length The number of bytes to compare.
|
||||
|
||||
@return 0 All Length bytes of the two buffers are identical.
|
||||
@retval -1 The two buffers are not identical within Length
|
||||
bytes.
|
||||
**/
|
||||
INTN
|
||||
SecureCompareMem (
|
||||
IN CONST VOID *DestinationBuffer,
|
||||
IN CONST VOID *SourceBuffer,
|
||||
IN UINTN Length
|
||||
);
|
||||
|
||||
/**
|
||||
Performs a cryptographically secure memory zeroing.
|
||||
|
||||
If Length > 0 and Buffer is NULL, then ASSERT().
|
||||
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
||||
|
||||
@param[out] Buffer The pointer to the destination buffer to zero.
|
||||
@param[in] Length The number of bytes to zero.
|
||||
|
||||
@return Buffer.
|
||||
**/
|
||||
VOID *
|
||||
SecureZeroMem (
|
||||
OUT VOID *Buffer,
|
||||
IN UINTN Length
|
||||
);
|
||||
|
||||
/**
|
||||
Verify Password and Salt against RefHash. The used hash function is SHA-512,
|
||||
thus the caller must ensure RefHash is at least 64 bytes in size.
|
||||
|
||||
@param[in] Password The entered password to verify.
|
||||
@param[in] PasswordSize The size, in bytes, of Password.
|
||||
@param[in] Salt The cryptographic salt appended to Password on hash.
|
||||
@param[in] SaltSize The size, in bytes, of Salt.
|
||||
@param[in] RefHash The SHA-512 hash of the reference password and Salt.
|
||||
|
||||
@returns Whether Password and Salt cryptographically match RefHash.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
OcVerifyPasswordSha512 (
|
||||
IN CONST UINT8 *Password,
|
||||
IN UINT32 PasswordSize,
|
||||
IN CONST UINT8 *Salt,
|
||||
IN UINT32 SaltSize,
|
||||
IN CONST UINT8 *RefHash
|
||||
);
|
||||
|
||||
#endif // OC_CRYPTO_LIB_H
|
||||
108
Include/Library/OcDataHubLib.h
Normal file
108
Include/Library/OcDataHubLib.h
Normal file
@ -0,0 +1,108 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_DATA_HUB_LIB_H
|
||||
#define OC_DATA_HUB_LIB_H
|
||||
|
||||
#include <Guid/AppleDataHub.h>
|
||||
#include <Library/OcCpuLib.h>
|
||||
#include <Protocol/DataHub.h>
|
||||
|
||||
#define OC_PLATFORM_NAME L"name"
|
||||
#define OC_SYSTEM_PRODUCT_NAME L"Model"
|
||||
#define OC_SYSTEM_SERIAL_NUMBER L"SystemSerialNumber"
|
||||
#define OC_SYSTEM_UUID L"system-id"
|
||||
#define OC_BOARD_PRODUCT L"board-id"
|
||||
#define OC_BOARD_REVISION L"board-rev"
|
||||
#define OC_STARTUP_POWER_EVENTS L"StartupPowerEvents"
|
||||
#define OC_INITIAL_TSC L"InitialTSC"
|
||||
#define OC_FSB_FREQUENCY L"FSBFrequency"
|
||||
#define OC_ART_FREQUENCY L"ARTFrequency"
|
||||
#define OC_DEVICE_PATHS_SUPPORTED L"DevicePathsSupported"
|
||||
|
||||
//
|
||||
// These are custom and match VirtualSMC, FakeSMC, and Clover.
|
||||
//
|
||||
#define OC_SMC_REVISION L"REV"
|
||||
#define OC_SMC_BRANCH L"RBr"
|
||||
#define OC_SMC_PLATFORM L"RPlt"
|
||||
|
||||
#define OC_SMC_REVISION_SIZE 6U
|
||||
#define OC_SMC_BRANCH_SIZE 8U
|
||||
#define OC_SMC_PLATFORM_SIZE 8U
|
||||
|
||||
typedef struct {
|
||||
CONST CHAR8 *PlatformName;
|
||||
CONST CHAR8 *SystemProductName;
|
||||
CONST CHAR8 *SystemSerialNumber;
|
||||
CONST GUID *SystemUUID;
|
||||
CONST CHAR8 *BoardProduct;
|
||||
CONST UINT8 *BoardRevision;
|
||||
CONST UINT64 *StartupPowerEvents;
|
||||
CONST UINT64 *InitialTSC;
|
||||
CONST UINT64 *FSBFrequency;
|
||||
CONST UINT64 *ARTFrequency;
|
||||
CONST UINT32 *DevicePathsSupported;
|
||||
CONST UINT8 *SmcRevision;
|
||||
CONST UINT8 *SmcBranch;
|
||||
CONST UINT8 *SmcPlatform;
|
||||
} OC_DATA_HUB_DATA;
|
||||
|
||||
/**
|
||||
Locate Data Hub protocol.
|
||||
|
||||
@param[in] Reinstall Force local Data Hub instance.
|
||||
|
||||
@retval Data Hub protocol instance or NULL.
|
||||
**/
|
||||
EFI_DATA_HUB_PROTOCOL *
|
||||
OcDataHubInstallProtocol (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
/**
|
||||
Set Data Hub entry.
|
||||
|
||||
@param[in] DataHub Data Hub protocol instance.
|
||||
@param[in] DataRecordGuid The guid of the record to use.
|
||||
@param[in] Key A pointer to the unicode key string.
|
||||
@param[in] Data A pointer to the data to store.
|
||||
@param[in] DataSize The length of the data to store.
|
||||
|
||||
@retval EFI_SUCCESS The datahub was updated successfully.
|
||||
**/
|
||||
EFI_STATUS
|
||||
SetDataHubEntry (
|
||||
IN EFI_DATA_HUB_PROTOCOL *DataHub,
|
||||
IN EFI_GUID *DataRecordGuid,
|
||||
IN CONST CHAR16 *Key,
|
||||
IN CONST VOID *Data,
|
||||
IN UINT32 DataSize
|
||||
);
|
||||
|
||||
/**
|
||||
Update DataHub entries.
|
||||
|
||||
@param[in] Data Data to be used for updating.
|
||||
|
||||
@retval EFI_SUCCESS The datahub was updated successfully.
|
||||
**/
|
||||
EFI_STATUS
|
||||
UpdateDataHub (
|
||||
IN EFI_DATA_HUB_PROTOCOL *DataHub,
|
||||
IN OC_DATA_HUB_DATA *Data,
|
||||
IN OC_CPU_INFO *CpuInfo
|
||||
);
|
||||
|
||||
#endif // OC_DATA_HUB_LIB_H
|
||||
131
Include/Library/OcDebugLogLib.h
Normal file
131
Include/Library/OcDebugLogLib.h
Normal file
@ -0,0 +1,131 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_DEBUG_LOG_LIB_H
|
||||
#define OC_DEBUG_LOG_LIB_H
|
||||
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Protocol/OcLog.h>
|
||||
|
||||
#define OC_HEX_LOWER(x) "0123456789ABCDEF"[((UINT32) (x) & 0x0FU)]
|
||||
#define OC_HEX_UPPER(x) "0123456789ABCDEF"[((UINT32) (x) & 0xF0U) >> 4U]
|
||||
|
||||
/**
|
||||
Debug information that is not logged when NVRAM logging is on.
|
||||
**/
|
||||
#ifndef DEBUG_BULK_INFO
|
||||
#define DEBUG_BULK_INFO (DEBUG_VERBOSE|DEBUG_INFO)
|
||||
#endif
|
||||
|
||||
/**
|
||||
This is a place print debug messages when they happen after ExitBootServices.
|
||||
**/
|
||||
#define RUNTIME_DEBUG(x) do { } while (0)
|
||||
|
||||
/**
|
||||
Pointer debug kit.
|
||||
**/
|
||||
#if defined(OC_TARGET_DEBUG) || defined(OC_TARGET_NOOPT)
|
||||
#define DEBUG_POINTER(x) x
|
||||
#elif defined(OC_TARGET_RELEASE)
|
||||
#define DEBUG_POINTER(x) NULL
|
||||
#else
|
||||
#error "Define target macro: OC_TARGET_<TARGET>!"
|
||||
#endif
|
||||
|
||||
/**
|
||||
Install or update the OcLog protocol with specified options.
|
||||
|
||||
@param[in] Options Logging options.
|
||||
@param[in] Delay Delay in microseconds after each log entry.
|
||||
@param[in] DisplayLevel Console visible error level.
|
||||
@param[in] HaltLevel Error level causing CPU halt.
|
||||
@param[in] LogPrefixPath Log path (without timestamp).
|
||||
@param[in] LogFileSystem Log filesystem, optional.
|
||||
|
||||
@retval EFI_SUCCESS The entry point is executed successfully.
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcConfigureLogProtocol (
|
||||
IN OC_LOG_OPTIONS Options,
|
||||
IN UINT32 DisplayDelay,
|
||||
IN UINTN DisplayLevel,
|
||||
IN UINTN HaltLevel,
|
||||
IN CONST CHAR16 *LogPrefixPath OPTIONAL,
|
||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *LogFileSystem OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Prints via gST->ConOut without any pool allocations.
|
||||
Otherwise equivalent to Print.
|
||||
Note: EFIAPI must be present for VA_ARGS forwarding (causes bugs with gcc).
|
||||
|
||||
@param[in] Format Formatted string.
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
OcPrintScreen (
|
||||
IN CONST CHAR16 *Format,
|
||||
...
|
||||
);
|
||||
|
||||
/**
|
||||
Dummy function that debuggers may break on.
|
||||
**/
|
||||
VOID
|
||||
DebugBreak (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Wait for user input after printing message.
|
||||
|
||||
@param[in] Message Message to print.
|
||||
**/
|
||||
VOID
|
||||
WaitForKeyPress (
|
||||
CONST CHAR16 *Message
|
||||
);
|
||||
|
||||
/**
|
||||
Print Device Path to log.
|
||||
|
||||
@param[in] ErrorLevel Debug error level.
|
||||
@param[in] Message Prefixed message.
|
||||
@param[in] DevicePath Device path to print.
|
||||
**/
|
||||
VOID
|
||||
DebugPrintDevicePath (
|
||||
IN UINTN ErrorLevel,
|
||||
IN CONST CHAR8 *Message,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Print hex dump to log.
|
||||
|
||||
@param[in] ErrorLevel Debug error level.
|
||||
@param[in] Message Prefixed message.
|
||||
@param[in] Bytes Byte sequence.
|
||||
@param[in] Size Byte sequence size.
|
||||
**/
|
||||
VOID
|
||||
DebugPrintHexDump (
|
||||
IN UINTN ErrorLevel,
|
||||
IN CONST CHAR8 *Message,
|
||||
IN UINT8 *Bytes,
|
||||
IN UINTN Size
|
||||
);
|
||||
|
||||
#endif // OC_DEBUG_LOG_LIB_H
|
||||
243
Include/Library/OcDevicePathLib.h
Executable file
243
Include/Library/OcDevicePathLib.h
Executable file
@ -0,0 +1,243 @@
|
||||
/** @file
|
||||
Copyright (C) 2016, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_DEVICE_PATH_LIB_H
|
||||
#define OC_DEVICE_PATH_LIB_H
|
||||
|
||||
/**
|
||||
Append file name to device path.
|
||||
|
||||
@param[in] DevicePath The device path which to append the file path.
|
||||
@param[in] FileName The file name to append to the device path.
|
||||
|
||||
@retval EFI_SUCCESS The defaults were initialized successfully.
|
||||
@retval EFI_INVALID_PARAMETER The parameters passed were invalid.
|
||||
@retval EFI_OUT_OF_RESOURCES The system ran out of memory.
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
AppendFileNameDevicePath (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
IN CHAR16 *FileName
|
||||
);
|
||||
|
||||
/**
|
||||
Locate the node inside the device path specified by Type an SubType values.
|
||||
|
||||
@param[in] DevicePath The device path used in the search.
|
||||
@param[in] Type The Type field of the device path node specified by Node.
|
||||
@param[in] SubType The SubType field of the device path node specified by Node.
|
||||
|
||||
@return Returned is the first Device Path Node with the given type.
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
FindDevicePathNodeWithType (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
IN UINT8 Type,
|
||||
IN UINT8 SubType OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Check whether device paths are equal.
|
||||
|
||||
@param[in] DevicePath1 The first device path protocol to compare.
|
||||
@param[in] DevicePath2 The second device path protocol to compare.
|
||||
|
||||
@retval TRUE The device paths matched
|
||||
@retval FALSE The device paths were different
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsDevicePathEqual (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2
|
||||
);
|
||||
|
||||
/**
|
||||
Check whether File Device Paths are equal.
|
||||
|
||||
@param[in] FilePath1 The first device path protocol to compare.
|
||||
@param[in] FilePath2 The second device path protocol to compare.
|
||||
|
||||
@retval TRUE The device paths matched
|
||||
@retval FALSE The device paths were different
|
||||
**/
|
||||
BOOLEAN
|
||||
FileDevicePathsEqual (
|
||||
IN FILEPATH_DEVICE_PATH *FilePath1,
|
||||
IN FILEPATH_DEVICE_PATH *FilePath2
|
||||
);
|
||||
|
||||
/**
|
||||
Check whether one device path exists in the other.
|
||||
|
||||
@param[in] ParentPath The parent device path protocol to check against.
|
||||
@param[in] ChildPath The device path protocol of the child device to compare.
|
||||
|
||||
@retval TRUE The child device path contains the parent device path.
|
||||
@retval FALSE The device paths were different
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsDevicePathChild (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *ParentPath,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *ChildPath
|
||||
);
|
||||
|
||||
/**
|
||||
Get absolute device path.
|
||||
|
||||
@param[in] Handle Device handle.
|
||||
@param[in] RelativePath Relative device path to handle, optional.
|
||||
|
||||
@retval New device path or NULL.
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
AbsoluteDevicePath (
|
||||
IN EFI_HANDLE Handle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RelativePath OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Get trailed (slash-appended) device path for booter paths.
|
||||
This way \\smth.efi gets NULL and \\smth gives \\smth\\.
|
||||
|
||||
@param[in] DevicePath Device path.
|
||||
|
||||
@retval New device path or NULL.
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
TrailedBooterDevicePath (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Returns the size of PathName.
|
||||
|
||||
@param[in] FilePath The file Device Path node to inspect.
|
||||
|
||||
@retval Name size in bytes.
|
||||
**/
|
||||
UINTN
|
||||
OcFileDevicePathNameSize (
|
||||
IN CONST FILEPATH_DEVICE_PATH *FilePath
|
||||
);
|
||||
|
||||
/**
|
||||
Returns the length of PathName.
|
||||
|
||||
@param[in] FilePath The file Device Path node to inspect.
|
||||
|
||||
@retval Name length in characters (without trailing zero).
|
||||
**/
|
||||
UINTN
|
||||
OcFileDevicePathNameLen (
|
||||
IN CONST FILEPATH_DEVICE_PATH *FilePath
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieve the size of the full file path described by DevicePath.
|
||||
|
||||
@param[in] DevicePath The Device Path to inspect.
|
||||
|
||||
@returns The size of the full file path.
|
||||
@retval 0 DevicePath does not start with a File Path node or contains
|
||||
non-terminating nodes that are not File Path nodes.
|
||||
|
||||
**/
|
||||
UINTN
|
||||
OcFileDevicePathFullNameSize (
|
||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieve the full file path described by FilePath.
|
||||
The caller is expected to call OcFileDevicePathFullNameSize() or ensure its
|
||||
guarantees are met.
|
||||
|
||||
@param[out] PathName On output, the full file path of FilePath.
|
||||
@param[in] FilePath The File Device Path to inspect.
|
||||
@param[in] PathNameSize The size, in bytes, of PathnName. Must equal the
|
||||
actual fill file path size.
|
||||
|
||||
**/
|
||||
VOID
|
||||
OcFileDevicePathFullName (
|
||||
OUT CHAR16 *PathName,
|
||||
IN CONST FILEPATH_DEVICE_PATH *FilePath,
|
||||
IN UINTN PathNameSize
|
||||
);
|
||||
|
||||
/**
|
||||
Duplicate device path with DevicePathInstance appended if it is not present.
|
||||
|
||||
@param[in] DevicePath Device Path to append new instance to, optional.
|
||||
@param[in] DevicePathInstance Device Path instance to append.
|
||||
|
||||
@retval New Device Path or NULL.
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
OcAppendDevicePathInstanceDedupe (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
|
||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
|
||||
);
|
||||
|
||||
/**
|
||||
Calculate number of device path instances.
|
||||
|
||||
@param[in] DevicePath Device Path to calculate instances in.
|
||||
|
||||
@retval Number of instances in device path.
|
||||
**/
|
||||
UINTN
|
||||
OcGetNumDevicePathInstances (
|
||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Fix Apple Boot Device Path to be compatible with conventional UEFI
|
||||
implementations.
|
||||
|
||||
@param[in,out] DevicePath On input, a pointer to the device path to fix.
|
||||
On output, the device path pointer is modified to
|
||||
point to the remaining part of the device path.
|
||||
|
||||
@retval -1 DevicePath could not be fixed.
|
||||
@retval other The number of fixed nodes in DevicePath.
|
||||
|
||||
**/
|
||||
INTN
|
||||
OcFixAppleBootDevicePath (
|
||||
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Get the next possible full path pointing to the load option.
|
||||
The routine doesn't guarantee the returned full path points to an existing
|
||||
file, and it also doesn't guarantee the existing file is a valid load option.
|
||||
|
||||
@param FilePath The device path pointing to a load option.
|
||||
It could be a short-form device path.
|
||||
@param FullPath The full path returned by the routine in last call.
|
||||
Set to NULL in first call.
|
||||
|
||||
@return The next possible full path pointing to the load option.
|
||||
Caller is responsible to free the memory.
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
OcGetNextLoadOptionDevicePath (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *FullPath
|
||||
);
|
||||
|
||||
#endif // OC_DEVICE_PATH_LIB_H
|
||||
32
Include/Library/OcDevicePropertyLib.h
Executable file
32
Include/Library/OcDevicePropertyLib.h
Executable file
@ -0,0 +1,32 @@
|
||||
/** @file
|
||||
Copyright (C) 2016, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_DEVICE_PROPERTY_LIB_H
|
||||
#define OC_DEVICE_PROPERTY_LIB_H
|
||||
|
||||
#include <Protocol/DevicePathPropertyDatabase.h>
|
||||
|
||||
/**
|
||||
Install and initialise EFI DevicePath property protocol.
|
||||
|
||||
@param[in] Overwrite Overwrite installed protocol.
|
||||
|
||||
@retval installed or located protocol or NULL.
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROPERTY_DATABASE_PROTOCOL *
|
||||
OcDevicePathPropertyInstallProtocol (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
#endif // OC_DEVICE_PROPERTY_LIB_H
|
||||
282
Include/Library/OcDeviceTreeLib.h
Normal file
282
Include/Library/OcDeviceTreeLib.h
Normal file
@ -0,0 +1,282 @@
|
||||
/** @file
|
||||
Copyright (C) 2016, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_DEVICE_TREE_LIB_H
|
||||
#define OC_DEVICE_TREE_LIB_H
|
||||
|
||||
//
|
||||
// Struct at the beginning of every loaded kext.
|
||||
// Pointers to every loaded kext (to this struct) are
|
||||
// properties Driver-<hex addr of DriverInfo> in DevTree /chosen/memory-map.
|
||||
//
|
||||
typedef struct DTBooterKextFileInfo_ {
|
||||
UINT32 InfoDictPhysAddr;
|
||||
UINT32 InfoDictLength;
|
||||
UINT32 ExecutablePhysAddr;
|
||||
UINT32 ExecutableLength;
|
||||
UINT32 BundlePathPhysAddr;
|
||||
UINT32 BundlePathLength;
|
||||
} DTBooterKextFileInfo;
|
||||
|
||||
//
|
||||
// DeviceTree MemoryMap entry structure.
|
||||
//
|
||||
typedef struct DTMemMapEntry_ {
|
||||
UINT32 Address;
|
||||
UINT32 Length;
|
||||
} DTMemMapEntry;
|
||||
|
||||
//
|
||||
// Foundation Types.
|
||||
//
|
||||
|
||||
#define DT_PATH_NAME_SEPERATOR '/' //< 0x2F
|
||||
|
||||
#define DT_MAX_PROPERTY_NAME_LENGTH 31 //< Max length of Property Name (terminator not included)
|
||||
#define DT_MAX_ENTRY_NAME_LENGTH 31 //< Max length of a C-String Entry Name (terminator not included)
|
||||
#define DT_PROPERTY_NAME_LENGTH 32
|
||||
|
||||
typedef CHAR8 DTEntryNameBuf[DT_PROPERTY_NAME_LENGTH]; //< Length of DTEntryNameBuf = DT_MAX_ENTRY_NAME_LENGTH + 1
|
||||
|
||||
typedef struct OpaqueDTEntry_ DeviceTreeNode;
|
||||
typedef DeviceTreeNode *DTEntry; //< Entry
|
||||
|
||||
typedef struct OpaqueDTProperty_ DTProperty;
|
||||
|
||||
typedef struct DTSavedScope_ DTSavedScope;
|
||||
typedef DTSavedScope *DTSavedScopePtr;
|
||||
|
||||
typedef struct OpaqueDTEntryIterator_ OpaqueDTEntryIterator;
|
||||
typedef OpaqueDTEntryIterator *DTEntryIterator;
|
||||
|
||||
typedef struct OpaqueDTPropertyIterator_ OpaqueDTPropertyIterator;
|
||||
typedef OpaqueDTPropertyIterator *DTPropertyIterator;
|
||||
|
||||
//
|
||||
// Structures for a Flattened Device Tree.
|
||||
//
|
||||
|
||||
struct OpaqueDTProperty_ {
|
||||
CHAR8 Name[DT_PROPERTY_NAME_LENGTH]; //< NUL terminated property name
|
||||
UINT32 Length; //< Length (bytes) of folloing prop value
|
||||
};
|
||||
|
||||
struct OpaqueDTEntry_ {
|
||||
UINT32 NumProperties; // Number of props[] elements (0 => end)
|
||||
UINT32 NumChildren; // Number of children[] elements
|
||||
};
|
||||
|
||||
//
|
||||
// Entry.
|
||||
//
|
||||
|
||||
struct DTSavedScope_ {
|
||||
DTSavedScopePtr NextScope;
|
||||
DTEntry Scope;
|
||||
DTEntry Entry;
|
||||
UINT32 Index;
|
||||
};
|
||||
|
||||
//
|
||||
// Entry Iterator.
|
||||
//
|
||||
struct OpaqueDTEntryIterator_ {
|
||||
DTEntry OuterScope;
|
||||
DTEntry CurrentScope;
|
||||
DTEntry CurrentEntry;
|
||||
DTSavedScopePtr SavedScope;
|
||||
UINT32 CurrentIndex;
|
||||
};
|
||||
|
||||
//
|
||||
// Property Iterator.
|
||||
//
|
||||
struct OpaqueDTPropertyIterator_ {
|
||||
DTEntry Entry;
|
||||
DTProperty *CurrentProperty;
|
||||
UINT32 CurrentIndex;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Lookup Entry
|
||||
Locates an entry given a specified subroot (searchPoint) and path name. If the
|
||||
searchPoint pointer is NULL, the path name is assumed to be an absolute path
|
||||
name rooted to the root of the device tree.
|
||||
**/
|
||||
EFI_STATUS
|
||||
DTLookupEntry (
|
||||
IN CONST DTEntry SearchPoint,
|
||||
IN CONST CHAR8 *PathName,
|
||||
IN DTEntry *FoundEntry
|
||||
);
|
||||
|
||||
/**
|
||||
An Entry Iterator maintains three variables that are of interest to clients.
|
||||
First is an "OutermostScope" which defines the outer boundry of the iteration.
|
||||
This is defined by the starting entry and includes that entry plus all of it's
|
||||
embedded entries. Second is a "currentScope" which is the entry the iterator is
|
||||
currently in. And third is a "currentPosition" which is the last entry returned
|
||||
during an iteration.
|
||||
|
||||
Create Entry Iterator
|
||||
Create the iterator structure. The outermostScope and currentScope of the iterator
|
||||
are set to "startEntry". If "startEntry" = NULL, the outermostScope and
|
||||
currentScope are set to the root entry. The currentPosition for the iterator is
|
||||
set to "nil".
|
||||
**/
|
||||
EFI_STATUS
|
||||
DTCreateEntryIterator (
|
||||
IN CONST DTEntry StartEntry,
|
||||
IN DTEntryIterator *Iterator
|
||||
);
|
||||
|
||||
/**
|
||||
Dispose Entry Iterator
|
||||
**/
|
||||
EFI_STATUS
|
||||
DTDisposeEntryIterator (
|
||||
IN DTEntryIterator Iterator
|
||||
);
|
||||
|
||||
/**
|
||||
Enter Child Entry
|
||||
Move an Entry Iterator into the scope of a specified child entry. The
|
||||
currentScope of the iterator is set to the entry specified in "childEntry". If
|
||||
"childEntry" is nil, the currentScope is set to the entry specified by the
|
||||
currentPosition of the iterator.
|
||||
**/
|
||||
EFI_STATUS
|
||||
DTEnterEntry (
|
||||
IN DTEntryIterator Iterator,
|
||||
IN DTEntry ChildEntry
|
||||
);
|
||||
|
||||
/**
|
||||
Exit to Parent Entry
|
||||
Move an Entry Iterator out of the current entry back into the scope of it's parent
|
||||
entry. The currentPosition of the iterator is reset to the current entry (the
|
||||
previous currentScope), so the next iteration call will continue where it left off.
|
||||
This position is returned in parameter "currentPosition".
|
||||
**/
|
||||
EFI_STATUS
|
||||
DTExitEntry (
|
||||
IN DTEntryIterator Iterator,
|
||||
IN DTEntry *CurrentPosition
|
||||
);
|
||||
|
||||
/**
|
||||
Iterate Entries
|
||||
Iterate and return entries contained within the entry defined by the current
|
||||
scope of the iterator. Entries are returned one at a time. When
|
||||
int == kIterationDone, all entries have been exhausted, and the
|
||||
value of nextEntry will be Nil.
|
||||
**/
|
||||
EFI_STATUS
|
||||
DTIterateEntries (
|
||||
IN DTEntryIterator Iterator,
|
||||
IN DTEntry *NextEntry
|
||||
);
|
||||
|
||||
/**
|
||||
Restart Entry Iteration
|
||||
Restart an iteration within the current scope. The iterator is reset such that
|
||||
iteration of the contents of the currentScope entry can be restarted. The
|
||||
outermostScope and currentScope of the iterator are unchanged. The currentPosition
|
||||
for the iterator is set to "nil".
|
||||
**/
|
||||
EFI_STATUS
|
||||
DTRestartEntryIteration (
|
||||
IN DTEntryIterator Iterator
|
||||
);
|
||||
|
||||
/**
|
||||
Get the value of the specified property for the specified entry.
|
||||
**/
|
||||
EFI_STATUS
|
||||
DTGetProperty (
|
||||
IN CONST DTEntry Entry,
|
||||
IN CHAR8 *PropertyName,
|
||||
IN VOID **PropertyValue,
|
||||
IN UINT32 *PropertySize
|
||||
);
|
||||
|
||||
/**
|
||||
Create Property Iterator
|
||||
Create the property iterator structure. The target entry is defined by entry.
|
||||
**/
|
||||
EFI_STATUS
|
||||
DTCreatePropertyIterator (
|
||||
IN CONST DTEntry Entry,
|
||||
IN DTPropertyIterator Iterator
|
||||
);
|
||||
|
||||
/**
|
||||
Iterate Properites
|
||||
Iterate and return properties for given entry.
|
||||
EFI_END_OF_MEDIA, all properties have been exhausted.
|
||||
**/
|
||||
|
||||
EFI_STATUS
|
||||
DTIterateProperties (
|
||||
IN DTPropertyIterator Iterator,
|
||||
IN CHAR8 **FoundProperty
|
||||
);
|
||||
|
||||
/**
|
||||
Restart Property Iteration
|
||||
Used to re-iterate over a list of properties. The Property Iterator is
|
||||
reset to the beginning of the list of properties for an entry.
|
||||
**/
|
||||
EFI_STATUS
|
||||
DTRestartPropertyIteration (
|
||||
IN DTPropertyIterator Iterator
|
||||
);
|
||||
|
||||
//
|
||||
// Exported Functions
|
||||
//
|
||||
|
||||
/**
|
||||
Used to initalize the device tree functions.
|
||||
Base is the base address of the flatened device tree.
|
||||
**/
|
||||
VOID
|
||||
DTInit (
|
||||
IN VOID *Base,
|
||||
IN UINT32 *Length
|
||||
);
|
||||
|
||||
VOID
|
||||
DumpDeviceTree (
|
||||
VOID
|
||||
);
|
||||
|
||||
UINT32
|
||||
DTDeleteProperty (
|
||||
IN CHAR8 *NodeName,
|
||||
IN CHAR8 *DeletePropertyName
|
||||
);
|
||||
|
||||
VOID
|
||||
DTInsertProperty (
|
||||
IN CHAR8 *NodeName,
|
||||
IN CHAR8 *InsertPropertyName,
|
||||
IN CHAR8 *AddPropertyName,
|
||||
IN VOID *AddPropertyValue,
|
||||
IN UINT32 ValueLength,
|
||||
IN BOOLEAN InsertAfter OPTIONAL
|
||||
);
|
||||
|
||||
#endif // OC_DEVICE_TREE_LIB_H
|
||||
40
Include/Library/OcDriverConnectionLib.h
Normal file
40
Include/Library/OcDriverConnectionLib.h
Normal file
@ -0,0 +1,40 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_DRIVER_CONNECTION_LIB_H
|
||||
#define OC_DRIVER_CONNECTION_LIB_H
|
||||
|
||||
/**
|
||||
Registers given PriorityDrivers to highest priority during connecting controllers.
|
||||
Does this by installing custom EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
|
||||
or by overriding existing EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.GetDriver.
|
||||
|
||||
@param[in] PriorityDrivers NULL-terminated list of drivers to prioritise.
|
||||
|
||||
@retval EFI_SUCCESS on successful override or installation.
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcRegisterDriversToHighestPriority (
|
||||
IN EFI_HANDLE *PriorityDrivers
|
||||
);
|
||||
|
||||
/**
|
||||
Connect effectively all drivers to effectively all handles.
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcConnectDrivers (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif // OC_DRIVER_CONNECTION_LIB_H
|
||||
330
Include/Library/OcFileLib.h
Executable file
330
Include/Library/OcFileLib.h
Executable file
@ -0,0 +1,330 @@
|
||||
/** @file
|
||||
Copyright (C) 2016 - 2017, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_FILE_LIB_H
|
||||
#define OC_FILE_LIB_H
|
||||
|
||||
// Include the abstracted protocol for its definitions
|
||||
|
||||
#include <Guid/FileInfo.h>
|
||||
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
|
||||
/**
|
||||
Maximum safe volume label size.
|
||||
**/
|
||||
#define OC_MAX_VOLUME_LABEL_SIZE 64
|
||||
|
||||
/**
|
||||
Locate file system from Device handle or path.
|
||||
|
||||
@param[in] DeviceHandle Device handle.
|
||||
@param[in] FilePath Device path.
|
||||
|
||||
@retval simple file system protocol or NULL.
|
||||
**/
|
||||
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *
|
||||
LocateFileSystem (
|
||||
IN EFI_HANDLE DeviceHandle OPTIONAL,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *FilePath OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Locate root volume from Device handle or path.
|
||||
|
||||
@param[in] DeviceHandle Device handle.
|
||||
@param[in] FilePath Device path.
|
||||
|
||||
@retval opened file protocol or NULL.
|
||||
**/
|
||||
EFI_FILE_PROTOCOL *
|
||||
LocateRootVolume (
|
||||
IN EFI_HANDLE DeviceHandle OPTIONAL,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *FilePath OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Locate file system from GUID.
|
||||
|
||||
@param[in] Guid GUID of the volume to locate.
|
||||
|
||||
@retval simple file system protocol or NULL.
|
||||
**/
|
||||
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *
|
||||
LocateFileSystemByGuid (
|
||||
IN CONST GUID *Guid
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves volume label.
|
||||
|
||||
@param[in] FileSystem A pointer to the file system protocol of the volume.
|
||||
|
||||
@retval A pointer to the NULL terminated unicode volume label.
|
||||
**/
|
||||
CHAR16 *
|
||||
GetVolumeLabel (
|
||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem
|
||||
);
|
||||
|
||||
/**
|
||||
Opens a new file relative to the source file's location.
|
||||
This function is equivalent to EFI_FILE_OPEN but has additional restrictions
|
||||
to provide board compatibility. Currently the only restriction is
|
||||
no trailing slash in the filename due to issues in FAT drivers.
|
||||
|
||||
- Multiple boards, namely ASUS P8H61-M and P8H61-M LX2 will not
|
||||
open directories with trailing slash. It is irrelevant whether
|
||||
front slash is present for them.
|
||||
For example, it means that L"EFI\\OC\\" or L"\\EFI\\OC\\" will both
|
||||
fail to open, while L"EFI\\OC" and L"\\EFI\\OC" will open fine.
|
||||
- Most newer boards on APTIO IV do handle directories with trailing
|
||||
slash, however, their driver will modify passed string by removing
|
||||
the slash by \0.
|
||||
|
||||
@param Protocol File protocol instance.
|
||||
@param NewHandle Pointer for returned handle.
|
||||
@param FileName Null-terminated file name.
|
||||
@param OpenMode File open mode.
|
||||
@param Attributes Attributes for the newly created file.
|
||||
|
||||
@retval EFI_SUCCESS for successfully opened file.
|
||||
*/
|
||||
EFI_STATUS
|
||||
SafeFileOpen (
|
||||
IN EFI_FILE_PROTOCOL *Protocol,
|
||||
OUT EFI_FILE_PROTOCOL **NewHandle,
|
||||
IN CONST CHAR16 *FileName,
|
||||
IN UINT64 OpenMode,
|
||||
IN UINT64 Attributes
|
||||
);
|
||||
|
||||
/**
|
||||
Read file from device path with implicit double (2 byte) null termination.
|
||||
Null termination does not affect the returned file size.
|
||||
Depending on the implementation 0 byte files may return null.
|
||||
|
||||
@param[in] FileSystem A pointer to the file system protocol of the volume.
|
||||
@param[in] FilePath The full path to the file on the device.
|
||||
@param[out] FileSize The size of the file read (optional).
|
||||
@param[in] MaxFileSize Upper file size bound (optional).
|
||||
|
||||
@retval A pointer to a buffer containing file read or NULL.
|
||||
**/
|
||||
VOID *
|
||||
ReadFile (
|
||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
|
||||
IN CONST CHAR16 *FilePath,
|
||||
OUT UINT32 *FileSize OPTIONAL,
|
||||
IN UINT32 MaxFileSize OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Determine file size if it is less than 4 GB.
|
||||
|
||||
@param[in] File A pointer to the file protocol.
|
||||
@param[out] Size 32-bit file size.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
ReadFileSize (
|
||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
|
||||
IN CONST CHAR16 *FilePath,
|
||||
OUT UINT32 *Size
|
||||
);
|
||||
|
||||
/**
|
||||
Read exact amount of bytes from EFI_FILE_PROTOCOL at specified position.
|
||||
|
||||
@param[in] File A pointer to the file protocol.
|
||||
@param[in] Position Position to read data from.
|
||||
@param[in] Size The size of the data read.
|
||||
@param[out] Buffer A pointer to previously allocated buffer to read data to.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
GetFileData (
|
||||
IN EFI_FILE_PROTOCOL *File,
|
||||
IN UINT32 Position,
|
||||
IN UINT32 Size,
|
||||
OUT UINT8 *Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Write exact amount of bytes to a newly created file in EFI_FILE_PROTOCOL.
|
||||
Please note, that several filesystems (or drivers) may limit file name length.
|
||||
|
||||
@param[in] WritableFs A pointer to the file protocol, any will be tried if NULL.
|
||||
@param[in] FileName File name (possibly with path) to write.
|
||||
@param[in] Buffer A pointer with the data to be written.
|
||||
@param[in] Size Amount of data to be written.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
SetFileData (
|
||||
IN EFI_FILE_PROTOCOL *WritableFs OPTIONAL,
|
||||
IN CONST CHAR16 *FileName,
|
||||
IN CONST VOID *Buffer,
|
||||
IN UINT32 Size
|
||||
);
|
||||
|
||||
/**
|
||||
Get file information of specified type.
|
||||
|
||||
@param[in] FileHandle A pointer to file handle.
|
||||
@param[in] InformationType A pointer to file info GUID.
|
||||
@param[in] MinFileInfoSize Minimal size of the info provided.
|
||||
@param[out] RealFileInfoSize Actual info size read (optional).
|
||||
|
||||
@retval read file info or NULL.
|
||||
**/
|
||||
VOID *
|
||||
GetFileInfo (
|
||||
IN EFI_FILE_PROTOCOL *File,
|
||||
IN EFI_GUID *InformationType,
|
||||
IN UINTN MinFileInfoSize,
|
||||
OUT UINTN *RealFileInfoSize OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Determine file size if it is less than 4 GB.
|
||||
|
||||
@param[in] File A pointer to the file protocol.
|
||||
@param[out] Size 32-bit file size.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
GetFileSize (
|
||||
IN EFI_FILE_PROTOCOL *File,
|
||||
OUT UINT32 *Size
|
||||
);
|
||||
|
||||
/**
|
||||
Determine file modification time.
|
||||
|
||||
@param[in] File A pointer to the file protocol.
|
||||
@param[out] Time Modification time.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
GetFileModifcationTime (
|
||||
IN EFI_FILE_PROTOCOL *File,
|
||||
OUT EFI_TIME *Time
|
||||
);
|
||||
|
||||
/**
|
||||
Determine writeable filesystem.
|
||||
|
||||
@param[in,out] WritableFs First found writeable file system.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
FindWritableFileSystem (
|
||||
IN OUT EFI_FILE_PROTOCOL **WritableFs
|
||||
);
|
||||
|
||||
/**
|
||||
Open a file or directory by device path. This is a modified
|
||||
version of EfiOpenFileByDevicePath function, which handles paths
|
||||
with trailing slashes, that cause Open failure on old firmwares.
|
||||
EfiOpenFileByDevicePath is additionally not available in UDK.
|
||||
|
||||
See more details at:
|
||||
https://github.com/tianocore/edk2/commit/768b611136d0f2b99a99e446c089d1a30c3fa5d5
|
||||
|
||||
@param[in,out] FilePath Device path protocol.
|
||||
@param[out] File Resulting file protocol.
|
||||
@param[in] OpenMode File open mode.
|
||||
@param[in] Attributes File attributes.
|
||||
|
||||
@retval EFI_SUCCESS on succesful open.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
OcOpenFileByDevicePath (
|
||||
IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
|
||||
OUT EFI_FILE_PROTOCOL **File,
|
||||
IN UINT64 OpenMode,
|
||||
IN UINT64 Attributes
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieve the disk's device handle from a partition's Device Path.
|
||||
|
||||
@param[in] HdDevicePath The Device Path of the partition.
|
||||
|
||||
@retval device handle or NULL
|
||||
**/
|
||||
EFI_HANDLE
|
||||
OcPartitionGetDiskHandle (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *HdDevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Locate the disk's EFI System Partition.
|
||||
|
||||
@param[in] DiskDevicePath The Device Path of the disk to scan.
|
||||
@param[out] EspDevicePathSize The size of the returned Device Path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
OcDiskFindSystemPartitionPath (
|
||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DiskDevicePath,
|
||||
OUT UINTN *EspDevicePathSize
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieve the partition's GPT information, if applicable.
|
||||
Calls to this function undergo internal lazy caching.
|
||||
|
||||
@param[in] FsHandle The device handle of the partition to retrieve info of.
|
||||
|
||||
@retval partition entry or NULL
|
||||
**/
|
||||
CONST EFI_PARTITION_ENTRY *
|
||||
OcGetGptPartitionEntry (
|
||||
IN EFI_HANDLE FsHandle
|
||||
);
|
||||
|
||||
/**
|
||||
Unblocks all partition handles without a File System protocol attached from
|
||||
driver connection, if applicable.
|
||||
**/
|
||||
VOID
|
||||
OcUnblockUnmountedPartitions (
|
||||
VOID
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
Creates a device path for a firmware file.
|
||||
|
||||
@param[in] FileGuid Firmware file GUID.
|
||||
|
||||
@retval device path allocated from pool on success.
|
||||
@retval NULL on failure (e.g. when a file is not present).
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
CreateFvFileDevicePath (
|
||||
IN EFI_GUID *FileGuid
|
||||
);
|
||||
|
||||
#endif // OC_FILE_LIB_H
|
||||
32
Include/Library/OcFirmwarePasswordLib.h
Executable file
32
Include/Library/OcFirmwarePasswordLib.h
Executable file
@ -0,0 +1,32 @@
|
||||
/** @file
|
||||
Copyright (C) 2016, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_FIRMWARE_PASSWORD_LIB_H
|
||||
#define OC_FIRMWARE_PASSWORD_LIB_H
|
||||
|
||||
// OcFirmwarePasswordInstallProtocol
|
||||
/// Install the Apple Firmware Password protocol
|
||||
///
|
||||
/// @param[in] ImageHandle The firmware allocated handle for the EFI image.
|
||||
/// @param[in] SystemTable A pointer to the EFI System Table.
|
||||
///
|
||||
/// @retval EFI_SUCCESS The entry point is executed successfully.
|
||||
|
||||
EFI_STATUS
|
||||
OcFirmwarePasswordInstallProtocol (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
#endif // OC_FIRMWARE_PASSWORD_LIB_H
|
||||
36
Include/Library/OcFirmwareVolumeLib.h
Executable file
36
Include/Library/OcFirmwareVolumeLib.h
Executable file
@ -0,0 +1,36 @@
|
||||
/** @file
|
||||
Copyright (C) 2016 Sergey Slice. All rights reserved.<BR>
|
||||
Portions copyright (C) 2018 savvas.<BR>
|
||||
Portions copyright (C) 2006-2014 Intel Corporation. All rights reserved.<BR>
|
||||
Portions copyright (C) 2016-2018 Alex James. 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.
|
||||
**/
|
||||
|
||||
#ifndef OC_FIRMWARE_VOLUME_LIB_H
|
||||
#define OC_FIRMWARE_VOLUME_LIB_H
|
||||
|
||||
#include <Pi/PiFirmwareFile.h>
|
||||
#include <Pi/PiFirmwareVolume.h>
|
||||
#include <Protocol/FirmwareVolume.h>
|
||||
|
||||
/**
|
||||
Install and initialise EFI Firmware Volume protocol.
|
||||
|
||||
@param[in] Reinstall Replace any installed protocol.
|
||||
|
||||
@returns Installed protocol.
|
||||
@retval NULL There was an error installing the protocol.
|
||||
**/
|
||||
EFI_FIRMWARE_VOLUME_PROTOCOL *
|
||||
OcFirmwareVolumeInstallProtocol (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
#endif // OC_FIRMWARE_VOLUME_LIB_H
|
||||
630
Include/Library/OcGuardLib.h
Normal file
630
Include/Library/OcGuardLib.h
Normal file
@ -0,0 +1,630 @@
|
||||
/** @file
|
||||
|
||||
OcGuardLib
|
||||
|
||||
Copyright (c) 2018, vit9696
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_GUARD_LIB_H
|
||||
#define OC_GUARD_LIB_H
|
||||
|
||||
//
|
||||
// The macros below provide pointer alignment checking interfaces.
|
||||
// TypedPtr - pointer of a dedicated type, which alignment is to be checked.
|
||||
// Align - valid alignment for the target platform (power of two so far).
|
||||
// Type - valid complete typename.
|
||||
// Ptr - raw pointer value, must fit into UINTN, meant to be uintptr_t equivalent.
|
||||
//
|
||||
|
||||
#define OC_ALIGNOF(Type) (_Alignof (Type))
|
||||
#define OC_POT_ALIGNED(Align, Ptr) (0ULL == (((UINTN) (Ptr)) & (Align-1U)))
|
||||
#define OC_TYPE_ALIGNED(Type, Ptr) (OC_POT_ALIGNED (OC_ALIGNOF (Type), Ptr))
|
||||
|
||||
//
|
||||
// The interfaces below provide base safe arithmetics, reporting
|
||||
// signed integer overflow and unsigned integer wraparound similarly to
|
||||
// os/overflow.h in macOS SDK.
|
||||
//
|
||||
// Each interface may be implemented not only as an actual function, but
|
||||
// a macro as well. Macro implementations are allowed to evaluate the
|
||||
// expressions no more than once, and are supposed to provide faster
|
||||
// compiler builtins if available.
|
||||
//
|
||||
// Each interface returns FALSE when the the stored result is equal to
|
||||
// the infinite precision result, otherwise TRUE. The operands should
|
||||
// be read left to right with the last argument representing a non-NULL
|
||||
// pointer to the resulting value of the same type.
|
||||
//
|
||||
// More information could be found in Clang Extensions documentation:
|
||||
// http://releases.llvm.org/7.0.0/tools/clang/docs/LanguageExtensions.html#checked-arithmetic-builtins
|
||||
//
|
||||
|
||||
//
|
||||
// 32-bit integer addition, subtraction, multiplication, triple addition (A+B+C),
|
||||
// triple multiplication (A*B*C), addition with multiplication ((A+B)*C),
|
||||
// and multiplication with addition (A*B+C) support.
|
||||
//
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddU32 (
|
||||
UINT32 A,
|
||||
UINT32 B,
|
||||
UINT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowSubU32 (
|
||||
UINT32 A,
|
||||
UINT32 B,
|
||||
UINT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulU32 (
|
||||
UINT32 A,
|
||||
UINT32 B,
|
||||
UINT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriAddU32 (
|
||||
UINT32 A,
|
||||
UINT32 B,
|
||||
UINT32 C,
|
||||
UINT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriMulU32 (
|
||||
UINT32 A,
|
||||
UINT32 B,
|
||||
UINT32 C,
|
||||
UINT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddMulU32 (
|
||||
UINT32 A,
|
||||
UINT32 B,
|
||||
UINT32 C,
|
||||
UINT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulAddU32 (
|
||||
UINT32 A,
|
||||
UINT32 B,
|
||||
UINT32 C,
|
||||
UINT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddS32 (
|
||||
INT32 A,
|
||||
INT32 B,
|
||||
INT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowSubS32 (
|
||||
INT32 A,
|
||||
INT32 B,
|
||||
INT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulS32 (
|
||||
INT32 A,
|
||||
INT32 B,
|
||||
INT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriAddS32 (
|
||||
INT32 A,
|
||||
INT32 B,
|
||||
INT32 C,
|
||||
INT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriMulS32 (
|
||||
INT32 A,
|
||||
INT32 B,
|
||||
INT32 C,
|
||||
INT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddMulS32 (
|
||||
INT32 A,
|
||||
INT32 B,
|
||||
INT32 C,
|
||||
INT32 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulAddS32 (
|
||||
INT32 A,
|
||||
INT32 B,
|
||||
INT32 C,
|
||||
INT32 *Result
|
||||
);
|
||||
|
||||
//
|
||||
// 64-bit integer addition, subtraction, multiplication, triple addition (A+B+C),
|
||||
// triple multiplication (A*B*C), addition with multiplication ((A+B)*C),
|
||||
// and multiplication with addition (A*B+C) support.
|
||||
//
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddU64 (
|
||||
UINT64 A,
|
||||
UINT64 B,
|
||||
UINT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowSubU64 (
|
||||
UINT64 A,
|
||||
UINT64 B,
|
||||
UINT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulU64 (
|
||||
UINT64 A,
|
||||
UINT64 B,
|
||||
UINT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriAddU64 (
|
||||
UINT64 A,
|
||||
UINT64 B,
|
||||
UINT64 C,
|
||||
UINT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriMulU64 (
|
||||
UINT64 A,
|
||||
UINT64 B,
|
||||
UINT64 C,
|
||||
UINT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddMulU64 (
|
||||
UINT64 A,
|
||||
UINT64 B,
|
||||
UINT64 C,
|
||||
UINT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulAddU64 (
|
||||
UINT64 A,
|
||||
UINT64 B,
|
||||
UINT64 C,
|
||||
UINT64 *Result
|
||||
);
|
||||
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddS64 (
|
||||
INT64 A,
|
||||
INT64 B,
|
||||
INT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowSubS64 (
|
||||
INT64 A,
|
||||
INT64 B,
|
||||
INT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulS64 (
|
||||
INT64 A,
|
||||
INT64 B,
|
||||
INT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriAddS64 (
|
||||
INT64 A,
|
||||
INT64 B,
|
||||
INT64 C,
|
||||
INT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriMulS64 (
|
||||
INT64 A,
|
||||
INT64 B,
|
||||
INT64 C,
|
||||
INT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddMulS64 (
|
||||
INT64 A,
|
||||
INT64 B,
|
||||
INT64 C,
|
||||
INT64 *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulAddS64 (
|
||||
INT64 A,
|
||||
INT64 B,
|
||||
INT64 C,
|
||||
INT64 *Result
|
||||
);
|
||||
|
||||
//
|
||||
// Native integer addition, subtraction, multiplication, triple addition (A+B+C),
|
||||
// triple multiplication (A*B*C), addition with multiplication ((A+B)*C),
|
||||
// and multiplication with addition (A*B+C) support.
|
||||
//
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddUN (
|
||||
UINTN A,
|
||||
UINTN B,
|
||||
UINTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowSubUN (
|
||||
UINTN A,
|
||||
UINTN B,
|
||||
UINTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulUN (
|
||||
UINTN A,
|
||||
UINTN B,
|
||||
UINTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriAddUN (
|
||||
UINTN A,
|
||||
UINTN B,
|
||||
UINTN C,
|
||||
UINTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriMulUN (
|
||||
UINTN A,
|
||||
UINTN B,
|
||||
UINTN C,
|
||||
UINTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddMulUN (
|
||||
UINTN A,
|
||||
UINTN B,
|
||||
UINTN C,
|
||||
UINTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulAddUN (
|
||||
UINTN A,
|
||||
UINTN B,
|
||||
UINTN C,
|
||||
UINTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddSN (
|
||||
INTN A,
|
||||
INTN B,
|
||||
INTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowSubSN (
|
||||
INTN A,
|
||||
INTN B,
|
||||
INTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulSN (
|
||||
INTN A,
|
||||
INTN B,
|
||||
INTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriAddSN (
|
||||
INTN A,
|
||||
INTN B,
|
||||
INTN C,
|
||||
INTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowTriMulSN (
|
||||
INTN A,
|
||||
INTN B,
|
||||
INTN C,
|
||||
INTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowAddMulSN (
|
||||
INTN A,
|
||||
INTN B,
|
||||
INTN C,
|
||||
INTN *Result
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
OcOverflowMulAddSN (
|
||||
INTN A,
|
||||
INTN B,
|
||||
INTN C,
|
||||
INTN *Result
|
||||
);
|
||||
|
||||
//
|
||||
// Macro implemenations of the above declarations
|
||||
//
|
||||
|
||||
#ifdef __has_builtin
|
||||
|
||||
//
|
||||
// Type-generic checkers are available
|
||||
//
|
||||
#if __has_builtin(__builtin_add_overflow) && __has_builtin(__builtin_sub_overflow) && __has_builtin(__builtin_mul_overflow)
|
||||
|
||||
#define OcOverflowAddU32(A, B, Res) __builtin_add_overflow((UINT32)(A), (UINT32)(B), (UINT32 *)(Res))
|
||||
#define OcOverflowSubU32(A, B, Res) __builtin_sub_overflow((UINT32)(A), (UINT32)(B), (UINT32 *)(Res))
|
||||
#define OcOverflowMulU32(A, B, Res) __builtin_mul_overflow((UINT32)(A), (UINT32)(B), (UINT32 *)(Res))
|
||||
#define OcOverflowAddS32(A, B, Res) __builtin_add_overflow((INT32)(A), (INT32)(B), (INT32 *)(Res))
|
||||
#define OcOverflowSubS32(A, B, Res) __builtin_sub_overflow((INT32)(A), (INT32)(B), (INT32 *)(Res))
|
||||
#define OcOverflowMulS32(A, B, Res) __builtin_mul_overflow((INT32)(A), (INT32)(B), (INT32 *)(Res))
|
||||
|
||||
#define OcOverflowAddU64(A, B, Res) __builtin_add_overflow((UINT64)(A), (UINT64)(B), (UINT64 *)(Res))
|
||||
#define OcOverflowSubU64(A, B, Res) __builtin_sub_overflow((UINT64)(A), (UINT64)(B), (UINT64 *)(Res))
|
||||
#define OcOverflowMulU64(A, B, Res) __builtin_mul_overflow((UINT64)(A), (UINT64)(B), (UINT64 *)(Res))
|
||||
#define OcOverflowAddS64(A, B, Res) __builtin_add_overflow((INT64)(A), (INT64)(B), (INT64 *)(Res))
|
||||
#define OcOverflowSubS64(A, B, Res) __builtin_sub_overflow((INT64)(A), (INT64)(B), (INT64 *)(Res))
|
||||
#define OcOverflowMulS64(A, B, Res) __builtin_mul_overflow((INT64)(A), (INT64)(B), (INT64 *)(Res))
|
||||
|
||||
#define OcOverflowAddUN(A, B, Res) __builtin_add_overflow((UINTN)(A), (UINTN)(B), (UINTN *)(Res))
|
||||
#define OcOverflowSubUN(A, B, Res) __builtin_sub_overflow((UINTN)(A), (UINTN)(B), (UINTN *)(Res))
|
||||
#define OcOverflowMulUN(A, B, Res) __builtin_mul_overflow((UINTN)(A), (UINTN)(B), (UINTN *)(Res))
|
||||
#define OcOverflowAddSN(A, B, Res) __builtin_add_overflow((INTN)(A), (INTN)(B), (INTN *)(Res))
|
||||
#define OcOverflowSubSN(A, B, Res) __builtin_sub_overflow((INTN)(A), (INTN)(B), (INTN *)(Res))
|
||||
#define OcOverflowMulSN(A, B, Res) __builtin_mul_overflow((INTN)(A), (INTN)(B), (INTN *)(Res))
|
||||
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
|
||||
//
|
||||
// Builtin type checkers are available, but we have to match their sizes.
|
||||
// For this reason we force the list of supported architectures here based on ProcessorBind.h,
|
||||
// and with the assumption that CHAR_BIT is 8.
|
||||
//
|
||||
|
||||
//
|
||||
// Implement 32-bit intrinsics with int and unsigned int on architectures that support it.
|
||||
//
|
||||
#if defined(MDE_CPU_AARCH64) || defined(MDE_CPU_ARM) || defined(MDE_CPU_X64) || defined(MDE_CPU_IA32)
|
||||
|
||||
STATIC_ASSERT (sizeof (int) == 4, "int is expected to be 4 bytes");
|
||||
STATIC_ASSERT (sizeof (unsigned) == 4, "unsigned is expected to be 4 bytes");
|
||||
|
||||
#define OcOverflowAddU32(A, B, Res) __builtin_uadd_overflow((UINT32)(A), (UINT32)(B), (UINT32 *)(Res))
|
||||
#define OcOverflowSubU32(A, B, Res) __builtin_usub_overflow((UINT32)(A), (UINT32)(B), (UINT32 *)(Res))
|
||||
#define OcOverflowMulU32(A, B, Res) __builtin_umul_overflow((UINT32)(A), (UINT32)(B), (UINT32 *)(Res))
|
||||
#define OcOverflowAddS32(A, B, Res) __builtin_sadd_overflow((INT32)(A), (INT32)(B), (INT32 *)(Res))
|
||||
#define OcOverflowSubS32(A, B, Res) __builtin_ssub_overflow((INT32)(A), (INT32)(B), (INT32 *)(Res))
|
||||
#define OcOverflowMulS32(A, B, Res) __builtin_smul_overflow((INT32)(A), (INT32)(B), (INT32 *)(Res))
|
||||
|
||||
#endif // 32-bit integer support
|
||||
|
||||
//
|
||||
// Implement 64-bit intrinsics with long long and unsigned long long on architectures that support it.
|
||||
// Note: ProcessorBind.h may use long on X64, but it is as large as long long.
|
||||
//
|
||||
#if defined(MDE_CPU_AARCH64) || defined(MDE_CPU_ARM) || defined(MDE_CPU_X64) || defined(MDE_CPU_IA32)
|
||||
|
||||
STATIC_ASSERT (sizeof (long long) == 8, "long long is expected to be 8 bytes");
|
||||
STATIC_ASSERT (sizeof (unsigned long long) == 8, "unsigned long long is expected to be 8 bytes");
|
||||
|
||||
#define OcOverflowAddU64(A, B, Res) __builtin_uaddll_overflow((UINT64)(A), (UINT64)(B), (UINT64 *)(Res))
|
||||
#define OcOverflowSubU64(A, B, Res) __builtin_usubll_overflow((UINT64)(A), (UINT64)(B), (UINT64 *)(Res))
|
||||
#define OcOverflowMulU64(A, B, Res) __builtin_umulll_overflow((UINT64)(A), (UINT64)(B), (UINT64 *)(Res))
|
||||
#define OcOverflowAddS64(A, B, Res) __builtin_saddll_overflow((INT64)(A), (INT64)(B), (INT64 *)(Res))
|
||||
#define OcOverflowSubS64(A, B, Res) __builtin_ssubll_overflow((INT64)(A), (INT64)(B), (INT64 *)(Res))
|
||||
#define OcOverflowMulS64(A, B, Res) __builtin_smulll_overflow((INT64)(A), (INT64)(B), (INT64 *)(Res))
|
||||
|
||||
#endif // 64-bit integer support
|
||||
|
||||
//
|
||||
// Implement native intrinsics with 32-bit or 64-bit intrinsics depending on the support.
|
||||
//
|
||||
#if defined(MDE_CPU_AARCH64) || defined(MDE_CPU_X64)
|
||||
|
||||
STATIC_ASSERT (sizeof (INTN) == 8, "UINTN is expected to be 8 bytes");
|
||||
STATIC_ASSERT (sizeof (UINTN) == 8, "UINTN is expected to be 8 bytes");
|
||||
|
||||
#define OcOverflowAddUN(A, B, Res) OcOverflowAddU64((A), (B), (Res))
|
||||
#define OcOverflowSubUN(A, B, Res) OcOverflowSubU64((A), (B), (Res))
|
||||
#define OcOverflowMulUN(A, B, Res) OcOverflowMulU64((A), (B), (Res))
|
||||
#define OcOverflowAddSN(A, B, Res) OcOverflowAddS64((A), (B), (Res))
|
||||
#define OcOverflowSubSN(A, B, Res) OcOverflowSubS64((A), (B), (Res))
|
||||
#define OcOverflowMulSN(A, B, Res) OcOverflowMulS64((A), (B), (Res))
|
||||
|
||||
#elif defined(MDE_CPU_ARM) || defined(MDE_CPU_IA32)
|
||||
|
||||
STATIC_ASSERT (sizeof (INTN) == 4, "UINTN is expected to be 4 bytes");
|
||||
STATIC_ASSERT (sizeof (UINTN) == 4, "UINTN is expected to be 4 bytes");
|
||||
|
||||
#define OcOverflowAddUN(A, B, Res) OcOverflowAddU32((A), (B), (Res))
|
||||
#define OcOverflowSubUN(A, B, Res) OcOverflowSubU32((A), (B), (Res))
|
||||
#define OcOverflowMulUN(A, B, Res) OcOverflowMulU32((A), (B), (Res))
|
||||
#define OcOverflowAddSN(A, B, Res) OcOverflowAddS32((A), (B), (Res))
|
||||
#define OcOverflowSubSN(A, B, Res) OcOverflowSubS32((A), (B), (Res))
|
||||
#define OcOverflowMulSN(A, B, Res) OcOverflowMulS32((A), (B), (Res))
|
||||
|
||||
#endif // native integer support
|
||||
|
||||
#endif // type integer support
|
||||
|
||||
#endif // __has_builtin
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
|
||||
//
|
||||
// Macro implementations for compilers supporting Statement Expressions:
|
||||
// https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
|
||||
//
|
||||
|
||||
#define OcOverflowTriAddU32(A, B, C, Res) ({ \
|
||||
UINT32 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddU32((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddU32(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowTriMulU32(A, B, C, Res) ({ \
|
||||
UINT32 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulU32((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulU32(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowAddMulU32(A, B, C, Res) ({ \
|
||||
UINT32 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddU32((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulU32(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowMulAddU32(A, B, C, Res) ({ \
|
||||
UINT32 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulU32((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddU32(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowTriAddS32(A, B, C, Res) ({ \
|
||||
INT32 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddS32((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddS32(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowTriMulS32(A, B, C, Res) ({ \
|
||||
INT32 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulS32((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulS32(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowAddMulS32(A, B, C, Res) ({ \
|
||||
INT32 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddS32((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulS32(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowMulAddS32(A, B, C, Res) ({ \
|
||||
INT32 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulS32((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddS32(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
|
||||
#define OcOverflowTriAddU64(A, B, C, Res) ({ \
|
||||
UINT64 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddU64((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddU64(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowTriMulU64(A, B, C, Res) ({ \
|
||||
UINT64 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulU64((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulU64(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowAddMulU64(A, B, C, Res) ({ \
|
||||
UINT64 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddU64((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulU64(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowMulAddU64(A, B, C, Res) ({ \
|
||||
UINT64 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulU64((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddU64(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowTriAddS64(A, B, C, Res) ({ \
|
||||
INT64 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddS64((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddS64(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowTriMulS64(A, B, C, Res) ({ \
|
||||
INT64 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulS64((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulS64(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowAddMulS64(A, B, C, Res) ({ \
|
||||
INT64 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddS64((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulS64(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowMulAddS64(A, B, C, Res) ({ \
|
||||
INT64 OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulS64((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddS64(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
|
||||
#define OcOverflowTriAddUN(A, B, C, Res) ({ \
|
||||
UINTN OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddUN((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddUN(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowTriMulUN(A, B, C, Res) ({ \
|
||||
UINTN OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulUN((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulUN(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowAddMulUN(A, B, C, Res) ({ \
|
||||
UINTN OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddUN((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulUN(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowMulAddUN(A, B, C, Res) ({ \
|
||||
UINTN OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulUN((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddUN(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowTriAddSN(A, B, C, Res) ({ \
|
||||
INTN OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddSN((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddSN(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowTriMulSN(A, B, C, Res) ({ \
|
||||
INTN OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulSN((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulSN(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowAddMulSN(A, B, C, Res) ({ \
|
||||
INTN OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowAddSN((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowMulSN(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
#define OcOverflowMulAddSN(A, B, C, Res) ({ \
|
||||
INTN OcTmp__; BOOLEAN OcFirst__, OcSecond__; \
|
||||
OcFirst__ = OcOverflowMulSN((A), (B), &OcTmp__); \
|
||||
OcSecond__ = OcOverflowAddSN(OcTmp__, (C), (Res)); \
|
||||
OcFirst__ | OcSecond__; })
|
||||
|
||||
#endif // __GNUC__ or __clang__
|
||||
|
||||
#endif // OC_GUARD_LIB_H
|
||||
31
Include/Library/OcHashServicesLib.h
Normal file
31
Include/Library/OcHashServicesLib.h
Normal file
@ -0,0 +1,31 @@
|
||||
/** @file
|
||||
Author: Joel Höner <athre0z@zyantific.com>
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_HASH_SERVICES_LIB_H
|
||||
#define OC_HASH_SERVICES_LIB_H
|
||||
|
||||
#include <Protocol/ServiceBinding.h>
|
||||
|
||||
/**
|
||||
Install and initialise EFI Service Binding protocol.
|
||||
|
||||
@param[in] Reinstall Replace any installed protocol.
|
||||
|
||||
@returns Installed protocol.
|
||||
@retval NULL There was an error installing the protocol.
|
||||
**/
|
||||
EFI_SERVICE_BINDING_PROTOCOL *
|
||||
OcHashServicesInstallProtocol (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
#endif // OC_HASH_SERVICES_LIB_H
|
||||
86
Include/Library/OcHdaDevicesLib.h
Normal file
86
Include/Library/OcHdaDevicesLib.h
Normal file
@ -0,0 +1,86 @@
|
||||
/** @file
|
||||
This library implements HDA device information.
|
||||
|
||||
Copyright (c) 2018 John Davis. All rights reserved.<BR>
|
||||
Copyright (c) 2020, vit9696. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause
|
||||
**/
|
||||
|
||||
#ifndef OC_HDA_DEVICES_LIB_H
|
||||
#define OC_HDA_DEVICES_LIB_H
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
/**
|
||||
Based on FreeBSD audio driver later borrowed by VoodooHDA.
|
||||
**/
|
||||
|
||||
/**
|
||||
Generic names.
|
||||
**/
|
||||
#define HDA_CONTROLLER_MODEL_GENERIC "HD Audio Controller"
|
||||
#define HDA_CODEC_MODEL_GENERIC "Unknown Codec"
|
||||
|
||||
/**
|
||||
Vendor IDs.
|
||||
**/
|
||||
#define VEN_AMD_ID 0x1002
|
||||
#define VEN_ANALOGDEVICES_ID 0x11D4
|
||||
#define VEN_AGERE_ID 0x11C1
|
||||
#define VEN_CIRRUSLOGIC_ID 0x1013
|
||||
#define VEN_CHRONTEL_ID 0x17E8
|
||||
#define VEN_CONEXANT_ID 0x14F1
|
||||
#define VEN_CREATIVE_ID 0x1102
|
||||
#define VEN_IDT_ID 0x111D
|
||||
#define VEN_INTEL_ID 0x8086
|
||||
#define VEN_LG_ID 0x1854
|
||||
#define VEN_NVIDIA_ID 0x10DE
|
||||
#define VEN_QEMU_ID 0x1AF4
|
||||
#define VEN_REALTEK_ID 0x10EC
|
||||
#define VEN_SIGMATEL_ID 0x8384
|
||||
#define VEN_VIA_ID 0x1106
|
||||
#define VEN_CMEDIA_ID 0x13F6
|
||||
#define VEN_CMEDIA2_ID 0x434D
|
||||
#define VEN_RDC_ID 0x17F3
|
||||
#define VEN_SIS_ID 0x1039
|
||||
#define VEN_ULI_ID 0x10B9
|
||||
#define VEN_MOTO_ID 0x1057
|
||||
#define VEN_SII_ID 0x1095
|
||||
#define VEN_WOLFSON_ID 0x14EC
|
||||
|
||||
#define VEN_INVALID_ID 0xFFFF
|
||||
|
||||
#define GET_PCI_VENDOR_ID(a) (a & 0xFFFFU)
|
||||
#define GET_PCI_DEVICE_ID(a) ((a >> 16U) & 0xFFFFU)
|
||||
#define GET_PCI_GENERIC_ID(a) ((0xFFFFU << 16U) | a)
|
||||
#define GET_CODEC_VENDOR_ID(a) ((a >> 16U) & 0xFFFFU)
|
||||
#define GET_CODEC_DEVICE_ID(a) (a & 0xFFFFU)
|
||||
#define GET_CODEC_GENERIC_ID(a) (a | 0xFFFFU)
|
||||
|
||||
/**
|
||||
Get controller name.
|
||||
|
||||
@param[in] ControllerId Controller identifier.
|
||||
|
||||
@retval Controller name or NULL.
|
||||
**/
|
||||
CONST CHAR8 *
|
||||
OcHdaControllerGetName (
|
||||
IN UINT32 ControllerId
|
||||
);
|
||||
|
||||
/**
|
||||
Get codec name.
|
||||
|
||||
@param[in] CodecId Codec identifier.
|
||||
@param[in] RevisionId Codec revision.
|
||||
|
||||
@retval Controller name or NULL.
|
||||
**/
|
||||
CONST CHAR8 *
|
||||
OcHdaCodecGetName (
|
||||
IN UINT32 CodecId,
|
||||
IN UINT16 RevisionId
|
||||
);
|
||||
|
||||
#endif // OC_HDA_DEVICES_LIB_H
|
||||
104
Include/Library/OcHeciLib.h
Normal file
104
Include/Library/OcHeciLib.h
Normal file
@ -0,0 +1,104 @@
|
||||
/** @file
|
||||
This library implements interaction with HECI.
|
||||
|
||||
Copyright (c) 2019, vit9696. All rights reserved.<BR>
|
||||
Portions copyright (c) 2019, savvas. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause
|
||||
**/
|
||||
|
||||
#ifndef OC_HECI_LIB_H
|
||||
#define OC_HECI_LIB_H
|
||||
|
||||
#include <IndustryStandard/HeciMsg.h>
|
||||
#include <IndustryStandard/HeciClientMsg.h>
|
||||
|
||||
EFI_STATUS
|
||||
HeciReadMessage (
|
||||
IN UINT32 Blocking,
|
||||
IN UINT32 *MessageBody,
|
||||
IN OUT UINT32 *Length
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciSendMessage (
|
||||
IN UINT32 *Message,
|
||||
IN UINT32 Length,
|
||||
IN UINT8 HostAddress,
|
||||
IN UINT8 MEAddress
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciLocateProtocol (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
HeciUpdateReceiveMsgStatus (
|
||||
VOID
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciGetResponse (
|
||||
OUT VOID *MessageData,
|
||||
IN UINT32 ResponseSize
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciSendMessageWithResponse (
|
||||
IN OUT VOID *MessageData,
|
||||
IN UINT32 RequestSize,
|
||||
IN UINT32 ResponseSize
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciGetClientMap (
|
||||
OUT UINT8 *ClientMap,
|
||||
OUT UINT8 *ClientActiveCount
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciGetClientProperties (
|
||||
IN UINT8 Address,
|
||||
OUT HECI_CLIENT_PROPERTIES *Properties
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciConnectToClient (
|
||||
IN UINT8 Address
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciSendMessagePerClient (
|
||||
IN VOID *Message,
|
||||
IN UINT32 Size
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciDisconnectFromClients (
|
||||
VOID
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciPavpRequestProvisioning (
|
||||
OUT UINT32 *EpidStatus,
|
||||
OUT UINT32 *EpidGroupId
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciPavpPerformProvisioning (
|
||||
IN EPID_CERTIFICATE *EpidCertificate,
|
||||
IN EPID_GROUP_PUBLIC_KEY *EpidGroupPublicKey,
|
||||
OUT BOOLEAN *SetVar OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciFpfGetStatus (
|
||||
OUT UINT32 *FpfStatus
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HeciFpfProvision (
|
||||
OUT UINT32 *FpfStatus
|
||||
);
|
||||
|
||||
#endif // OC_HECI_LIB_H
|
||||
64
Include/Library/OcInputLib.h
Normal file
64
Include/Library/OcInputLib.h
Normal file
@ -0,0 +1,64 @@
|
||||
/** @file
|
||||
OC Apple generic input library.
|
||||
|
||||
Copyright (c) 2019, 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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_GENERIC_INPUT_LIB_H
|
||||
#define OC_APPLE_GENERIC_INPUT_LIB_H
|
||||
|
||||
typedef enum {
|
||||
OcInputPointerModeAsus,
|
||||
OcInputPointerModeMax
|
||||
} OC_INPUT_POINTER_MODE;
|
||||
|
||||
typedef enum {
|
||||
OcInputKeyModeAuto,
|
||||
OcInputKeyModeV1,
|
||||
OcInputKeyModeV2,
|
||||
OcInputKeyModeAmi,
|
||||
OcInputKeyModeMax
|
||||
} OC_INPUT_KEY_MODE;
|
||||
|
||||
EFI_STATUS
|
||||
OcAppleGenericInputTimerQuirkInit (
|
||||
IN UINT32 TimerResolution
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
OcAppleGenericInputTimerQuirkExit (
|
||||
VOID
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
OcAppleGenericInputPointerInit (
|
||||
IN OC_INPUT_POINTER_MODE Mode
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
OcAppleGenericInputPointerExit (
|
||||
VOID
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
OcAppleGenericInputKeycodeInit (
|
||||
IN OC_INPUT_KEY_MODE Mode,
|
||||
IN UINT8 KeyForgotThreshold,
|
||||
IN UINT8 KeyMergeThreshold,
|
||||
IN BOOLEAN KeySwap
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
OcAppleGenericInputKeycodeExit (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif // OC_APPLE_GENERIC_INPUT_LIB_H
|
||||
761
Include/Library/OcMachoLib.h
Normal file
761
Include/Library/OcMachoLib.h
Normal file
@ -0,0 +1,761 @@
|
||||
/** @file
|
||||
Provides Mach-O parsing helper functions.
|
||||
|
||||
Copyright (c) 2016 - 2018, Download-Fritz. 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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_MACHO_LIB_H
|
||||
#define OC_MACHO_LIB_H
|
||||
|
||||
#include <IndustryStandard/AppleMachoImage.h>
|
||||
|
||||
///
|
||||
/// Default assumed page size.
|
||||
///
|
||||
#define MACHO_PAGE_SIZE 4096U
|
||||
|
||||
///
|
||||
/// Macro to align by default assumed page size.
|
||||
///
|
||||
#define MACHO_ALIGN(x) ALIGN_VALUE((x), MACHO_PAGE_SIZE)
|
||||
|
||||
///
|
||||
/// Context used to refer to a Mach-O. This struct is exposed for reference
|
||||
/// only. Members are not guaranteed to be sane.
|
||||
///
|
||||
typedef struct {
|
||||
MACH_HEADER_64 *MachHeader;
|
||||
UINT32 FileSize;
|
||||
MACH_SYMTAB_COMMAND *Symtab;
|
||||
MACH_NLIST_64 *SymbolTable;
|
||||
CHAR8 *StringTable;
|
||||
MACH_DYSYMTAB_COMMAND *DySymtab;
|
||||
MACH_NLIST_64 *IndirectSymbolTable;
|
||||
MACH_RELOCATION_INFO *LocalRelocations;
|
||||
MACH_RELOCATION_INFO *ExternRelocations;
|
||||
} OC_MACHO_CONTEXT;
|
||||
|
||||
/**
|
||||
Initializes a Mach-O Context.
|
||||
|
||||
@param[out] Context Mach-O Context to initialize.
|
||||
@param[in] FileData Pointer to the file's data.
|
||||
@param[in] FileSize File size of FileData.
|
||||
|
||||
@return Whether Context has been initialized successfully.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoInitializeContext (
|
||||
OUT OC_MACHO_CONTEXT *Context,
|
||||
IN VOID *FileData,
|
||||
IN UINT32 FileSize
|
||||
);
|
||||
|
||||
/**
|
||||
Returns the Mach-O Header structure.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
|
||||
**/
|
||||
MACH_HEADER_64 *
|
||||
MachoGetMachHeader64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Returns the Mach-O's file size.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
|
||||
**/
|
||||
UINT32
|
||||
MachoGetFileSize (
|
||||
IN OUT OC_MACHO_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Returns the Mach-O's virtual address space size.
|
||||
|
||||
@param[out] Context Context of the Mach-O.
|
||||
|
||||
**/
|
||||
UINT32
|
||||
MachoGetVmSize64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Returns the last virtual address of a Mach-O.
|
||||
|
||||
@param[in] Context Context of the Mach-O.
|
||||
|
||||
@retval 0 The binary is malformed.
|
||||
|
||||
**/
|
||||
UINT64
|
||||
MachoGetLastAddress64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the first UUID Load Command.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
MACH_UUID_COMMAND *
|
||||
MachoGetUuid64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the first segment by the name of SegmentName.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] SegmentName Segment name to search for.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
MACH_SEGMENT_COMMAND_64 *
|
||||
MachoGetSegmentByName64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST CHAR8 *SegmentName
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the first section by the name of SectionName.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Segment Segment to search in.
|
||||
@param[in] SectionName Section name to search for.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
MACH_SECTION_64 *
|
||||
MachoGetSectionByName64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN MACH_SEGMENT_COMMAND_64 *Segment,
|
||||
IN CONST CHAR8 *SectionName
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves a section within a segment by the name of SegmentName.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] SegmentName The name of the segment to search in.
|
||||
@param[in] SectionName The name of the section to search for.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
MACH_SECTION_64 *
|
||||
MachoGetSegmentSectionByName64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST CHAR8 *SegmentName,
|
||||
IN CONST CHAR8 *SectionName
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the next segment.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Segment Segment to retrieve the successor of.
|
||||
if NULL, the first segment is returned.
|
||||
|
||||
@retal NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
MACH_SEGMENT_COMMAND_64 *
|
||||
MachoGetNextSegment64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST MACH_SEGMENT_COMMAND_64 *Segment OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the next section of a segment.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Segment The segment to get the section of.
|
||||
@param[in] Section The section to get the successor of.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
MACH_SECTION_64 *
|
||||
MachoGetNextSection64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN MACH_SEGMENT_COMMAND_64 *Segment,
|
||||
IN MACH_SECTION_64 *Section OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves a section by its index.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Index Index of the section to retrieve.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
MACH_SECTION_64 *
|
||||
MachoGetSectionByIndex64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN UINT32 Index
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves a section by its address.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Address Address of the section to retrieve.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
MACH_SECTION_64 *
|
||||
MachoGetSectionByAddress64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN UINT64 Address
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether Symbol describes a section.
|
||||
|
||||
@param[in] Symbol Symbol to evaluate.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoSymbolIsSection (
|
||||
IN CONST MACH_NLIST_64 *Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether Symbol is defined.
|
||||
|
||||
@param[in] Symbol Symbol to evaluate.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoSymbolIsDefined (
|
||||
IN CONST MACH_NLIST_64 *Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether Symbol is defined locally.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Symbol Symbol to evaluate.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoSymbolIsLocalDefined (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST MACH_NLIST_64 *Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves a locally defined symbol by its name.
|
||||
|
||||
@param[in] Context Context of the Mach-O.
|
||||
@param[in] Name Name of the symbol to locate.
|
||||
|
||||
**/
|
||||
MACH_NLIST_64 *
|
||||
MachoGetLocalDefinedSymbolByName (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST CHAR8 *Name
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves a symbol by its index.
|
||||
|
||||
@param[in] Context Context of the Mach-O.
|
||||
@param[in] Index Index of the symbol to locate.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
MACH_NLIST_64 *
|
||||
MachoGetSymbolByIndex64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN UINT32 Index
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves Symbol's name.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Symbol Symbol to retrieve the name of.
|
||||
|
||||
@retval symbol name.
|
||||
|
||||
**/
|
||||
CONST CHAR8 *
|
||||
MachoGetSymbolName64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST MACH_NLIST_64 *Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves Symbol's name.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Symbol Indirect symbol to retrieve the name of.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
CONST CHAR8 *
|
||||
MachoGetIndirectSymbolName64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST MACH_NLIST_64 *Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether the symbol's value is a valid address within the Mach-O
|
||||
referenced to by Context.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Symbol Symbol to verify the value of.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoIsSymbolValueInRange64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST MACH_NLIST_64 *Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the symbol referenced by the Relocation targeting Address.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Address Address to search for.
|
||||
@param[out] Symbol Buffer to output the symbol referenced by the
|
||||
Relocation into. The output is undefined when FALSE
|
||||
is returned. May be NULL.
|
||||
|
||||
@returns Whether the Relocation exists.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoGetSymbolByRelocationOffset64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN UINT64 Address,
|
||||
OUT MACH_NLIST_64 **Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the symbol referenced by the extern Relocation targeting Address.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Address Address to search for.
|
||||
@param[out] Symbol Buffer to output the symbol referenced by the
|
||||
Relocation into. The output is undefined when FALSE
|
||||
is returned. May be NULL.
|
||||
|
||||
@returns Whether the Relocation exists.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoGetSymbolByExternRelocationOffset64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN UINT64 Address,
|
||||
OUT MACH_NLIST_64 **Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Relocate Symbol to be against LinkAddress.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] LinkAddress The address to be linked against.
|
||||
@param[in,out] Symbol The symbol to be relocated.
|
||||
|
||||
@returns Whether the operation has been completed successfully.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoRelocateSymbol64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN UINT64 LinkAddress,
|
||||
IN OUT MACH_NLIST_64 *Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the Mach-O file offset of the address pointed to by Symbol.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Symbol Symbol to retrieve the offset of.
|
||||
@param[out] FileOffset Pointer the file offset is returned into.
|
||||
If FALSE is returned, the output is undefined.
|
||||
@param[out] MaxSize Maximum data safely available from FileOffset.
|
||||
|
||||
@retval 0 0 is returned on failure.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoSymbolGetFileOffset64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST MACH_NLIST_64 *Symbol,
|
||||
OUT UINT32 *FileOffset,
|
||||
OUT UINT32 *MaxSize OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether Name is pure virtual.
|
||||
|
||||
@param[in] Name The name to evaluate.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoSymbolNameIsPureVirtual (
|
||||
IN CONST CHAR8 *Name
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether Name is a Padslot.
|
||||
|
||||
@param[in] Name The name to evaluate.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoSymbolNameIsPadslot (
|
||||
IN CONST CHAR8 *Name
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether SymbolName defines a Super Metaclass Pointer.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] SymbolName The symbol name to check.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoSymbolNameIsSmcp64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST CHAR8 *SymbolName
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether SymbolName defines a Super Metaclass Pointer.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] SymbolName The symbol name to check.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoSymbolNameIsMetaclassPointer64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST CHAR8 *SymbolName
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the class name of a Super Meta Class Pointer.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] SmcpName SMCP Symbol name to get the class name of.
|
||||
@param[in] ClassNameSize The size of ClassName.
|
||||
@param[out] ClassName The output buffer for the class name.
|
||||
|
||||
@returns Whether the name has been retrieved successfully.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoGetClassNameFromSuperMetaClassPointer (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST CHAR8 *SmcpName,
|
||||
IN UINTN ClassNameSize,
|
||||
OUT CHAR8 *ClassName
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the class name of a VTable.
|
||||
|
||||
@param[out] VtableName The VTable's name.
|
||||
|
||||
**/
|
||||
CONST CHAR8 *
|
||||
MachoGetClassNameFromVtableName (
|
||||
IN CONST CHAR8 *VtableName
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the function prefix of a class name.
|
||||
|
||||
@param[in] ClassName The class name to evaluate.
|
||||
@param[in] FunctionPrefixSize The size of FunctionPrefix.
|
||||
@param[out] FunctionPrefix The output buffer for the function prefix.
|
||||
|
||||
@returns Whether the name has been retrieved successfully.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoGetFunctionPrefixFromClassName (
|
||||
IN CONST CHAR8 *ClassName,
|
||||
IN UINTN FunctionPrefixSize,
|
||||
OUT CHAR8 *FunctionPrefix
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the class name of a Meta Class Pointer.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] MetaClassName MCP Symbol name to get the class name of.
|
||||
@param[in] ClassNameSize The size of ClassName.
|
||||
@param[out] ClassName The output buffer for the class name.
|
||||
|
||||
@returns Whether the name has been retrieved successfully.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoGetClassNameFromMetaClassPointer (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST CHAR8 *MetaClassName,
|
||||
IN UINTN ClassNameSize,
|
||||
OUT CHAR8 *ClassName
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the VTable name of a class name.
|
||||
|
||||
@param[in] ClassName Class name to get the VTable name of.
|
||||
@param[in] VtableNameSize The size of VtableName.
|
||||
@param[out] VtableName The output buffer for the VTable name.
|
||||
|
||||
@returns Whether the name has been retrieved successfully.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoGetVtableNameFromClassName (
|
||||
IN CONST CHAR8 *ClassName,
|
||||
IN UINTN VtableNameSize,
|
||||
OUT CHAR8 *VtableName
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the Meta VTable name of a class name.
|
||||
|
||||
@param[in] ClassName Class name to get the Meta VTable name of.
|
||||
@param[in] VtableNameSize The size of VtableName.
|
||||
@param[out] VtableName The output buffer for the VTable name.
|
||||
|
||||
@returns Whether the name has been retrieved successfully.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoGetMetaVtableNameFromClassName (
|
||||
IN CONST CHAR8 *ClassName,
|
||||
IN UINTN VtableNameSize,
|
||||
OUT CHAR8 *VtableName
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the final symbol name of a class name.
|
||||
|
||||
@param[in] ClassName Class name to get the final symbol name of.
|
||||
@param[in] FinalSymbolNameSize The size of FinalSymbolName.
|
||||
@param[out] FinalSymbolName The output buffer for the final symbol name.
|
||||
|
||||
@returns Whether the name has been retrieved successfully.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoGetFinalSymbolNameFromClassName (
|
||||
IN CONST CHAR8 *ClassName,
|
||||
IN UINTN FinalSymbolNameSize,
|
||||
OUT CHAR8 *FinalSymbolName
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether SymbolName defines a VTable.
|
||||
|
||||
@param[in] SymbolName The symbol name to check.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoSymbolNameIsVtable64 (
|
||||
IN CONST CHAR8 *SymbolName
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether the symbol name describes a C++ symbol.
|
||||
|
||||
@param[in] Name The name to evaluate.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoSymbolNameIsCxx (
|
||||
IN CONST CHAR8 *Name
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves Metaclass symbol of a SMCP.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Smcp The SMCP to evaluate.
|
||||
|
||||
@retval NULL NULL is returned on failure.
|
||||
|
||||
**/
|
||||
MACH_NLIST_64 *
|
||||
MachoGetMetaclassSymbolFromSmcpSymbol64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST MACH_NLIST_64 *Smcp
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves VTable and Meta VTable of a SMCP.
|
||||
Logically matches XNU's get_vtable_syms_from_smcp.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] SmcpName SMCP Symbol mame to retrieve the VTables from.
|
||||
@param[out] Vtable Output buffer for the VTable symbol pointer.
|
||||
@param[out] MetaVtable Output buffer for the Meta VTable symbol pointer.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoGetVtableSymbolsFromSmcp64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN CONST CHAR8 *SmcpName,
|
||||
OUT CONST MACH_NLIST_64 **Vtable,
|
||||
OUT CONST MACH_NLIST_64 **MetaVtable
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether the Relocation's type indicates a Pair for the Intel 64
|
||||
platform.
|
||||
|
||||
@param[in] Type The Relocation's type to verify.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoRelocationIsPairIntel64 (
|
||||
IN UINT8 Type
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether the Relocation's type matches a Pair's for the Intel 64
|
||||
platform.
|
||||
|
||||
@param[in] Type The Relocation's type to verify.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoIsRelocationPairTypeIntel64 (
|
||||
IN UINT8 Type
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether the Relocation shall be preserved for the Intel 64 platform.
|
||||
|
||||
@param[in] Type The Relocation's type to verify.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
MachoPreserveRelocationIntel64 (
|
||||
IN UINT8 Type
|
||||
);
|
||||
|
||||
/**
|
||||
Obtain symbol tables.
|
||||
|
||||
@param[in] Context Context of the Mach-O.
|
||||
@param[out] SymbolTable Symbol table.
|
||||
@param[out] StringTable String table for that symbol table.
|
||||
@param[out] LocalSymbols Local symbol table.
|
||||
@param[out] NumLocalSymbols Number of symbols in local symbol table.
|
||||
@param[out] ExternalSymbols External symbol table.
|
||||
@param[out] NumExternalSymbols Number of symbols in external symbol table.
|
||||
@param[out] UndefinedSymbols Undefined symbol table.
|
||||
@param[out] NumUndefinedSymbols Number of symbols in undefined symbol table.
|
||||
|
||||
@return number of symbols in symbol table or 0.
|
||||
**/
|
||||
UINT32
|
||||
MachoGetSymbolTable (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
OUT CONST MACH_NLIST_64 **SymbolTable,
|
||||
OUT CONST CHAR8 **StringTable OPTIONAL,
|
||||
OUT CONST MACH_NLIST_64 **LocalSymbols OPTIONAL,
|
||||
OUT UINT32 *NumLocalSymbols OPTIONAL,
|
||||
OUT CONST MACH_NLIST_64 **ExternalSymbols OPTIONAL,
|
||||
OUT UINT32 *NumExternalSymbols OPTIONAL,
|
||||
OUT CONST MACH_NLIST_64 **UndefinedSymbols OPTIONAL,
|
||||
OUT UINT32 *NumUndefinedSymbols OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Obtain indirect symbol table.
|
||||
|
||||
@param[in] Context Context of the Mach-O.
|
||||
@param[in,out] SymbolTable Indirect symbol table.
|
||||
|
||||
@return number of symbols in indirect symbol table or 0.
|
||||
**/
|
||||
UINT32
|
||||
MachoGetIndirectSymbolTable (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
OUT CONST MACH_NLIST_64 **SymbolTable
|
||||
);
|
||||
|
||||
/**
|
||||
Returns a pointer to the Mach-O file at the specified virtual address.
|
||||
|
||||
@param[in,out] Context Context of the Mach-O.
|
||||
@param[in] Address Virtual address to look up.
|
||||
@param[out] MaxSize Maximum data safely available from FileOffset.
|
||||
If NULL is returned, the output is undefined.
|
||||
|
||||
**/
|
||||
VOID *
|
||||
MachoGetFilePointerByAddress64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN UINT64 Address,
|
||||
OUT UINT32 *MaxSize OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Expand Mach-O image to Destination (make segment file sizes equal to vm sizes).
|
||||
|
||||
@param[in] Context Context of the Mach-O.
|
||||
@param[out] Destination Output buffer.
|
||||
@param[in] DestinationSize Output buffer maximum size.
|
||||
@param[in] Strip Output with stripped prelink commands.
|
||||
|
||||
@returns New image size or 0 on failure.
|
||||
|
||||
**/
|
||||
UINT32
|
||||
MachoExpandImage64 (
|
||||
IN OC_MACHO_CONTEXT *Context,
|
||||
OUT UINT8 *Destination,
|
||||
IN UINT32 DestinationSize,
|
||||
IN BOOLEAN Strip
|
||||
);
|
||||
|
||||
/**
|
||||
Find Mach-O entry point from LC_UNIXTHREAD loader command.
|
||||
This command does not verify Mach-O and assumes it is valid.
|
||||
|
||||
@param[in] Image Loaded Mach-O image.
|
||||
|
||||
@returns Entry point or 0.
|
||||
**/
|
||||
UINT64
|
||||
MachoRuntimeGetEntryAddress (
|
||||
IN VOID *Image
|
||||
);
|
||||
|
||||
#endif // OC_MACHO_LIB_H
|
||||
382
Include/Library/OcMemoryLib.h
Normal file
382
Include/Library/OcMemoryLib.h
Normal file
@ -0,0 +1,382 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_MEMORY_LIB_H
|
||||
#define OC_MEMORY_LIB_H
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <IndustryStandard/VirtualMemory.h>
|
||||
|
||||
/**
|
||||
Reverse equivalent of NEXT_MEMORY_DESCRIPTOR.
|
||||
**/
|
||||
#define PREV_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \
|
||||
((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size)))
|
||||
|
||||
|
||||
/**
|
||||
Get last descriptor address.
|
||||
It is assumed that the descriptor contains pages.
|
||||
**/
|
||||
#define LAST_DESCRIPTOR_ADDR(Desc) \
|
||||
((Desc)->PhysicalStart + (EFI_PAGES_TO_SIZE ((UINTN) (Desc)->NumberOfPages) - 1))
|
||||
|
||||
/**
|
||||
Check if area is within the specified descriptor.
|
||||
It is assumed that the descriptor contains pages and AreaSize is not 0.
|
||||
**/
|
||||
#define AREA_WITHIN_DESCRIPTOR(Desc, Area, AreaSize) \
|
||||
((Area) >= (Desc)->PhysicalStart && ((Area) + ((AreaSize) - 1)) <= LAST_DESCRIPTOR_ADDR (Desc))
|
||||
|
||||
/**
|
||||
Reasonable default virtual memory page pool size (2 MB).
|
||||
**/
|
||||
#define OC_DEFAULT_VMEM_PAGE_COUNT 0x200
|
||||
|
||||
/**
|
||||
Lock the legacy region specified to enable modification.
|
||||
|
||||
@param[in] LegacyAddress The address of the region to lock.
|
||||
@param[in] LegacyLength The size of the region to lock.
|
||||
|
||||
@retval EFI_SUCCESS The region was locked successfully.
|
||||
**/
|
||||
EFI_STATUS
|
||||
LegacyRegionLock (
|
||||
IN UINT32 LegacyAddress,
|
||||
IN UINT32 LegacyLength
|
||||
);
|
||||
|
||||
/**
|
||||
Unlock the legacy region specified to enable modification.
|
||||
|
||||
@param[in] LegacyAddress The address of the region to unlock.
|
||||
@param[in] LegacyLength The size of the region to unlock.
|
||||
|
||||
@retval EFI_SUCCESS The region was unlocked successfully.
|
||||
**/
|
||||
EFI_STATUS
|
||||
LegacyRegionUnlock (
|
||||
IN UINT32 LegacyAddress,
|
||||
IN UINT32 LegacyLength
|
||||
);
|
||||
|
||||
/**
|
||||
Get current memory map allocated on pool.
|
||||
|
||||
@param[out] MemoryMapSize Resulting memory map size in bytes.
|
||||
@param[out] DescriptorSize Resulting memory map descriptor size in bytes.
|
||||
@param[out] MapKey Memory map key, optional.
|
||||
@param[out] DescriptorVersion Memory map descriptor version, optional.
|
||||
|
||||
@retval current memory map or NULL.
|
||||
**/
|
||||
EFI_MEMORY_DESCRIPTOR *
|
||||
GetCurrentMemoryMap (
|
||||
OUT UINTN *MemoryMapSize,
|
||||
OUT UINTN *DescriptorSize,
|
||||
OUT UINTN *MapKey OPTIONAL,
|
||||
OUT UINT32 *DescriptorVersion OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Get current memory map of custom allocation.
|
||||
|
||||
@param[out] MemoryMapSize Resulting memory map size in bytes.
|
||||
@param[out] MemoryMap Resulting memory map.
|
||||
@param[out] MapKey Memory map key.
|
||||
@param[out] DescriptorSize Resulting memory map descriptor size in bytes.
|
||||
@param[out] DescriptorVersion Memory map descriptor version.
|
||||
@param[in] GetMemoryMap Custom GetMemoryMap implementation to use, optional.
|
||||
@param[in,out] TopMemory Base top address for AllocatePagesFromTop allocation, number of pages after return.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
GetCurrentMemoryMapAlloc (
|
||||
OUT UINTN *MemoryMapSize,
|
||||
OUT EFI_MEMORY_DESCRIPTOR **MemoryMap,
|
||||
OUT UINTN *MapKey,
|
||||
OUT UINTN *DescriptorSize,
|
||||
OUT UINT32 *DescriptorVersion,
|
||||
IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL,
|
||||
IN OUT EFI_PHYSICAL_ADDRESS *TopMemory OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Shrink memory map by joining non-runtime records.
|
||||
|
||||
@param[in,out] MemoryMapSize Memory map size in bytes, updated on shrink.
|
||||
@param[in,out] MemoryMap Memory map to shrink.
|
||||
@param[in] DescriptorSize Memory map descriptor size in bytes.
|
||||
**/
|
||||
VOID
|
||||
ShrinkMemoryMap (
|
||||
IN OUT UINTN *MemoryMapSize,
|
||||
IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,
|
||||
IN UINTN DescriptorSize
|
||||
);
|
||||
|
||||
/**
|
||||
Check range allocation compatibility callback.
|
||||
|
||||
@param[in] Address Starting address.
|
||||
@param[in] Size Size of memory range.
|
||||
|
||||
@retval TRUE when suitable for allocation.
|
||||
**/
|
||||
typedef
|
||||
BOOLEAN
|
||||
(*CHECK_ALLOCATION_RANGE) (
|
||||
IN EFI_PHYSICAL_ADDRESS Address,
|
||||
IN UINTN Size
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
Filter memory map entries.
|
||||
|
||||
@param[in] Context Parameterised filter data.
|
||||
@param[in,out] MemoryMapSize Memory map size in bytes.
|
||||
@param[in,out] MemoryMap Memory map to filter.
|
||||
@param[in] DescriptorSize Memory map descriptor size in bytes.
|
||||
**/
|
||||
typedef
|
||||
VOID
|
||||
(*OC_MEMORY_FILTER) (
|
||||
IN VOID *Context OPTIONAL,
|
||||
IN UINTN MemoryMapSize,
|
||||
IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,
|
||||
IN UINTN DescriptorSize
|
||||
);
|
||||
|
||||
/**
|
||||
Allocate pages from the top of physical memory up to address specified in Memory.
|
||||
Unlike AllocateMaxAddress, this method guarantees to choose top most address.
|
||||
|
||||
@param[in] MemoryType Allocated memory type.
|
||||
@param[in] Pages Amount of pages to allocate.
|
||||
@param[in,out] Memory Top address for input, allocated address for output.
|
||||
@param[in] GetMemoryMap Custom GetMemoryMap implementation to use, optional.
|
||||
@param[in] CheckRange Handler allowing to not allocate select ranges, optional.
|
||||
|
||||
@retval EFI_SUCCESS on successful allocation.
|
||||
**/
|
||||
EFI_STATUS
|
||||
AllocatePagesFromTop (
|
||||
IN EFI_MEMORY_TYPE MemoryType,
|
||||
IN UINTN Pages,
|
||||
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
|
||||
IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL,
|
||||
IN CHECK_ALLOCATION_RANGE CheckRange OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Calculate number of runtime pages in the memory map.
|
||||
|
||||
@param[in] MemoryMapSize Memory map size in bytes.
|
||||
@param[in] MemoryMap Memory map to inspect.
|
||||
@param[in] DescriptorSize Memory map descriptor size in bytes.
|
||||
@param[out] DescriptorCount Number of relevant descriptors, optional.
|
||||
|
||||
@retval Number of runtime pages.
|
||||
**/
|
||||
UINT64
|
||||
CountRuntimePages (
|
||||
IN UINTN MemoryMapSize,
|
||||
IN EFI_MEMORY_DESCRIPTOR *MemoryMap,
|
||||
IN UINTN DescriptorSize,
|
||||
OUT UINTN *DescriptorCount OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Calculate number of free pages in the memory map.
|
||||
|
||||
@param[out] LowerMemory Number of free pages below 4 GB, optional.
|
||||
|
||||
@retval Number of free pages.
|
||||
**/
|
||||
UINTN
|
||||
CountFreePages (
|
||||
OUT UINTN *LowerMemory OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Return pointer to PML4 table in PageTable and PWT and PCD flags in Flags.
|
||||
|
||||
@param[out] Flags Current page table PWT and PCT flags.
|
||||
|
||||
@retval Current page table address.
|
||||
**/
|
||||
PAGE_MAP_AND_DIRECTORY_POINTER *
|
||||
GetCurrentPageTable (
|
||||
OUT UINTN *Flags OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Return physical addrress for given virtual addrress.
|
||||
|
||||
@param[in] PageTable Page table to use for solving.
|
||||
@param[in] VirtualAddr Virtual address to look up.
|
||||
@param[out] PhysicalAddr Physical address to return.
|
||||
|
||||
@retval EFI_SUCCESS on successful lookup.
|
||||
**/
|
||||
EFI_STATUS
|
||||
GetPhysicalAddress (
|
||||
IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL,
|
||||
IN EFI_VIRTUAL_ADDRESS VirtualAddr,
|
||||
OUT EFI_PHYSICAL_ADDRESS *PhysicalAddr
|
||||
);
|
||||
|
||||
/**
|
||||
Virtual memory context
|
||||
**/
|
||||
typedef struct OC_VMEM_CONTEXT_ {
|
||||
///
|
||||
/// Memory pool containing memory to be spread across allocations.
|
||||
///
|
||||
UINT8 *MemoryPool;
|
||||
///
|
||||
/// Free pages in the memory pool.
|
||||
///
|
||||
UINTN FreePages;
|
||||
} OC_VMEM_CONTEXT;
|
||||
|
||||
/**
|
||||
Allocate EfiBootServicesData virtual memory pool from boot services
|
||||
in the end of BASE_4GB of RAM. Should be called while boot services are
|
||||
still usable.
|
||||
|
||||
@param[out] Context Virtual memory pool context.
|
||||
@param[in] NumPages Number of pages to be allocated in the pool.
|
||||
|
||||
@retval EFI_SUCCESS on successful allocation.
|
||||
**/
|
||||
EFI_STATUS
|
||||
VmAllocateMemoryPool (
|
||||
OUT OC_VMEM_CONTEXT *Context,
|
||||
IN UINTN NumPages
|
||||
);
|
||||
|
||||
/**
|
||||
Allocate pages for e.g. vm page maps.
|
||||
|
||||
@param[in,out] Context Virtual memory pool context.
|
||||
@param[in] NumPages Number of pages to allocate.
|
||||
|
||||
@retval allocated pages or NULL.
|
||||
**/
|
||||
VOID *
|
||||
VmAllocatePages (
|
||||
IN OUT OC_VMEM_CONTEXT *Context,
|
||||
IN UINTN NumPages
|
||||
);
|
||||
|
||||
/**
|
||||
Map (remap) given page at physical address to given virtual address in
|
||||
the specified page table.
|
||||
|
||||
@param[in,out] Context Virtual memory pool context.
|
||||
@param[in] PageTable Page table to update.
|
||||
@param[in] VirtualAddr Virtual memory address to map at.
|
||||
@param[in] PhysicalAddr Physical memory address to map from.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
VmMapVirtualPage (
|
||||
IN OUT OC_VMEM_CONTEXT *Context,
|
||||
IN OUT PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL,
|
||||
IN EFI_VIRTUAL_ADDRESS VirtualAddr,
|
||||
IN EFI_PHYSICAL_ADDRESS PhysicalAddr
|
||||
);
|
||||
|
||||
/**
|
||||
Map (remap) a range of 4K pages at physical address to given virtual address
|
||||
in the specified page table.
|
||||
|
||||
@param[in,out] Context Virtual memory pool context.
|
||||
@param[in] PageTable Page table to update.
|
||||
@param[in] VirtualAddr Virtual memory address to map at.
|
||||
@param[in] NumPages Number of 4K pages to map.
|
||||
@param[in] PhysicalAddr Physical memory address to map from.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
VmMapVirtualPages (
|
||||
IN OUT OC_VMEM_CONTEXT *Context,
|
||||
IN OUT PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL,
|
||||
IN EFI_VIRTUAL_ADDRESS VirtualAddr,
|
||||
IN UINT64 NumPages,
|
||||
IN EFI_PHYSICAL_ADDRESS PhysicalAddr
|
||||
);
|
||||
|
||||
/**
|
||||
Flushes TLB caches.
|
||||
**/
|
||||
VOID
|
||||
VmFlushCaches (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Check whether built-in allocator is initialized.
|
||||
|
||||
@retval TRUE on success.
|
||||
**/
|
||||
BOOLEAN
|
||||
UmmInitialized (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Initialize built-in allocator.
|
||||
|
||||
@param[in] Heap Memory pool used for allocations.
|
||||
@param[in] Size Memory pool size.
|
||||
**/
|
||||
VOID
|
||||
UmmSetHeap (
|
||||
IN VOID *Heap,
|
||||
IN UINT32 Size
|
||||
);
|
||||
|
||||
/**
|
||||
Perform allocation from built-in allocator.
|
||||
|
||||
@param[in] Size Allocation size.
|
||||
|
||||
@retval allocated memory on success.
|
||||
**/
|
||||
VOID *
|
||||
UmmMalloc (
|
||||
IN UINT32 Size
|
||||
);
|
||||
|
||||
/**
|
||||
Perform free of allocated memory. Accepts NULL pointer
|
||||
and checks whether memory belongs to itself.
|
||||
|
||||
@param[in] Ptr Memory to free.
|
||||
|
||||
@retval TRUE on success
|
||||
**/
|
||||
BOOLEAN
|
||||
UmmFree (
|
||||
IN VOID *Ptr
|
||||
);
|
||||
|
||||
#endif // OC_MEMORY_LIB_H
|
||||
101
Include/Library/OcMiscLib.h
Executable file
101
Include/Library/OcMiscLib.h
Executable file
@ -0,0 +1,101 @@
|
||||
/** @file
|
||||
Copyright (C) 2016 - 2018, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_MISC_LIB_H
|
||||
#define OC_MISC_LIB_H
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <Library/OcStringLib.h>
|
||||
|
||||
/**
|
||||
The size, in Bits, of one Byte.
|
||||
**/
|
||||
#define OC_CHAR_BIT 8
|
||||
|
||||
/**
|
||||
Convert seconds to microseconds for use in e.g. gBS->Stall.
|
||||
**/
|
||||
#define SECONDS_TO_MICROSECONDS(x) ((x)*1000000)
|
||||
|
||||
INT32
|
||||
FindPattern (
|
||||
IN CONST UINT8 *Pattern,
|
||||
IN CONST UINT8 *PatternMask OPTIONAL,
|
||||
IN CONST UINT32 PatternSize,
|
||||
IN CONST UINT8 *Data,
|
||||
IN UINT32 DataSize,
|
||||
IN INT32 DataOff
|
||||
);
|
||||
|
||||
UINT32
|
||||
ApplyPatch (
|
||||
IN CONST UINT8 *Pattern,
|
||||
IN CONST UINT8 *PatternMask OPTIONAL,
|
||||
IN CONST UINT32 PatternSize,
|
||||
IN CONST UINT8 *Replace,
|
||||
IN CONST UINT8 *ReplaceMask OPTIONAL,
|
||||
IN UINT8 *Data,
|
||||
IN UINT32 DataSize,
|
||||
IN UINT32 Count,
|
||||
IN UINT32 Skip
|
||||
);
|
||||
|
||||
/**
|
||||
@param[in] Protocol The published unique identifier of the protocol. It is the caller’s responsibility to pass in
|
||||
a valid GUID.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
UninstallAllProtocolInstances (
|
||||
EFI_GUID *Protocol
|
||||
);
|
||||
|
||||
/**
|
||||
Release UEFI ownership from USB controllers at booting.
|
||||
**/
|
||||
EFI_STATUS
|
||||
ReleaseUsbOwnership (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Perform cold reboot directly bypassing UEFI services. Does not return.
|
||||
Supposed to work in any modern physical or virtual environment.
|
||||
**/
|
||||
VOID
|
||||
DirectRestCold (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Return the result of (Multiplicand * Multiplier / Divisor).
|
||||
|
||||
@param Multiplicand A 64-bit unsigned value.
|
||||
@param Multiplier A 64-bit unsigned value.
|
||||
@param Divisor A 32-bit unsigned value.
|
||||
@param Remainder A pointer to a 32-bit unsigned value. This parameter is
|
||||
optional and may be NULL.
|
||||
|
||||
@return Multiplicand * Multiplier / Divisor.
|
||||
**/
|
||||
UINT64
|
||||
MultThenDivU64x64x32 (
|
||||
IN UINT64 Multiplicand,
|
||||
IN UINT64 Multiplier,
|
||||
IN UINT32 Divisor,
|
||||
OUT UINT32 *Remainder OPTIONAL
|
||||
);
|
||||
|
||||
#endif // OC_MISC_LIB_H
|
||||
32
Include/Library/OcOSInfoLib.h
Normal file
32
Include/Library/OcOSInfoLib.h
Normal file
@ -0,0 +1,32 @@
|
||||
/** @file
|
||||
Copyright (C) 2020, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_OS_INFO_LIB_H
|
||||
#define OC_OS_INFO_LIB_H
|
||||
|
||||
#include <Protocol/OSInfo.h>
|
||||
|
||||
/**
|
||||
Install and initialise OS Info protocol.
|
||||
|
||||
@param[in] Reinstall Overwrite installed protocol.
|
||||
|
||||
@retval installed or located protocol or NULL.
|
||||
**/
|
||||
EFI_OS_INFO_PROTOCOL *
|
||||
OcOSInfoInstallProtocol (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
#endif // OC_OS_INFO_LIB_H
|
||||
88
Include/Library/OcPngLib.h
Normal file
88
Include/Library/OcPngLib.h
Normal file
@ -0,0 +1,88 @@
|
||||
/** @file
|
||||
|
||||
OcPngLib - library with PNG decoder functions
|
||||
|
||||
Copyright (c) 2018, savvas
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_PNG_LIB_H
|
||||
#define OC_PNG_LIB_H
|
||||
|
||||
/**
|
||||
Retrieves PNG image dimensions
|
||||
|
||||
@param Buffer Buffer with desired png image
|
||||
@param Size Size of input image
|
||||
@param Width Image width at output
|
||||
@param Height Image height at output
|
||||
|
||||
@return EFI_SUCCESS The function completed successfully.
|
||||
@return EFI_OUT_OF_RESOURCES There are not enough resources to init state.
|
||||
@return EFI_INVALID_PARAMETER Passed wrong parameter
|
||||
**/
|
||||
EFI_STATUS
|
||||
GetPngDims (
|
||||
IN VOID *Buffer,
|
||||
IN UINTN Size,
|
||||
OUT UINT32 *Width,
|
||||
OUT UINT32 *Height
|
||||
);
|
||||
|
||||
/**
|
||||
Decodes PNG image into raw pixel buffer
|
||||
|
||||
@param Buffer Buffer with desired png image
|
||||
@param Size Size of input image
|
||||
@param RawData Output buffer with raw data
|
||||
@param Width Image width at output
|
||||
@param Height Image height at output
|
||||
@param HasAlphaType Returns 1 if alpha layer present, optional param
|
||||
Set NULL, if not used
|
||||
|
||||
@return EFI_SUCCESS The function completed successfully.
|
||||
@return EFI_OUT_OF_RESOURCES There are not enough resources to init state.
|
||||
@return EFI_INVALID_PARAMETER Passed wrong parameter
|
||||
**/
|
||||
EFI_STATUS
|
||||
DecodePng (
|
||||
IN VOID *Buffer,
|
||||
IN UINTN Size,
|
||||
OUT VOID **RawData,
|
||||
OUT UINT32 *Width,
|
||||
OUT UINT32 *Height,
|
||||
OUT BOOLEAN *HasAlphaType OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Encodes raw pixel buffer into PNG image data
|
||||
|
||||
@param RawData RawData from png image
|
||||
@param Width Image width
|
||||
@param Height Image height
|
||||
@param Buffer Output buffer
|
||||
@param BufferSize Output size
|
||||
|
||||
@return EFI_SUCCESS The function completed successfully.
|
||||
@return EFI_INVALID_PARAMETER Passed wrong parameter
|
||||
**/
|
||||
EFI_STATUS
|
||||
EncodePng (
|
||||
IN VOID *RawData,
|
||||
IN UINT32 Width,
|
||||
IN UINT32 Height,
|
||||
OUT VOID **Buffer,
|
||||
OUT UINTN *BufferSize
|
||||
);
|
||||
|
||||
#endif
|
||||
59
Include/Library/OcRngLib.h
Normal file
59
Include/Library/OcRngLib.h
Normal file
@ -0,0 +1,59 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_RNG_LIB_H
|
||||
#define OC_RNG_LIB_H
|
||||
|
||||
#include <Library/RngLib.h>
|
||||
|
||||
/**
|
||||
Generates a 16-bit pseudo random number.
|
||||
This generator is still guaranteed to be cryptographically secure
|
||||
by the use of CPRNG with entropy.
|
||||
|
||||
@retval 16-bit pseudo random number.
|
||||
**/
|
||||
UINT16
|
||||
EFIAPI
|
||||
GetPseudoRandomNumber16 (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Generates a 32-bit pseudo random number.
|
||||
This generator is still guaranteed to be cryptographically secure
|
||||
by the use of CPRNG with entropy.
|
||||
|
||||
@retval 32-bit pseudo random number.
|
||||
**/
|
||||
UINT32
|
||||
EFIAPI
|
||||
GetPseudoRandomNumber32 (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Generates a 64-bit pseudo random number.
|
||||
This generator is still guaranteed to be cryptographically secure
|
||||
by the use of CPRNG with entropy.
|
||||
|
||||
@retval 64-bit pseudo random number.
|
||||
**/
|
||||
UINT64
|
||||
EFIAPI
|
||||
GetPseudoRandomNumber64 (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif // OC_RNG_LIB_H
|
||||
52
Include/Library/OcRtcLib.h
Normal file
52
Include/Library/OcRtcLib.h
Normal file
@ -0,0 +1,52 @@
|
||||
/** @file
|
||||
|
||||
OcRtcLib - library with RTC I/O functions
|
||||
|
||||
Copyright (c) 2017-2018, vit9696
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_RTC_LIB_H
|
||||
#define OC_RTC_LIB_H
|
||||
|
||||
//
|
||||
// Standard interface, available on most Intel chipsets
|
||||
//
|
||||
|
||||
UINT8
|
||||
OcRtcRead (
|
||||
IN UINT8 Offset
|
||||
);
|
||||
|
||||
VOID
|
||||
OcRtcWrite (
|
||||
IN UINT8 Offset,
|
||||
IN UINT8 Value
|
||||
);
|
||||
|
||||
//
|
||||
// Modern faster interface, available on IvyBridge or newer
|
||||
//
|
||||
|
||||
UINT8
|
||||
OcRtcReadIvy (
|
||||
IN UINT8 Offset
|
||||
);
|
||||
|
||||
VOID
|
||||
OcRtcWriteIvy (
|
||||
IN UINT8 Offset,
|
||||
IN UINT8 Value
|
||||
);
|
||||
|
||||
#endif // OC_RTC_LIB_H
|
||||
331
Include/Library/OcSerializeLib.h
Normal file
331
Include/Library/OcSerializeLib.h
Normal file
@ -0,0 +1,331 @@
|
||||
/** @file
|
||||
|
||||
OcSerializeLib
|
||||
|
||||
Copyright (c) 2018, vit9696
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_SERIALIZE_LIB_H
|
||||
#define OC_SERIALIZE_LIB_H
|
||||
|
||||
#include <Library/OcXmlLib.h>
|
||||
#include <Library/OcTemplateLib.h>
|
||||
|
||||
typedef struct OC_SCHEMA_ OC_SCHEMA;
|
||||
typedef union OC_SCHEMA_INFO_ OC_SCHEMA_INFO;
|
||||
|
||||
//
|
||||
// Generic applier interface that knows how to provide Info with data from Node.
|
||||
//
|
||||
typedef
|
||||
VOID
|
||||
(*OC_APPLY) (
|
||||
VOID *Serialized,
|
||||
XML_NODE *Node,
|
||||
OC_SCHEMA_INFO *Info
|
||||
);
|
||||
|
||||
//
|
||||
// OC_SCHEMA_INFO for nested dictionaries
|
||||
//
|
||||
typedef struct {
|
||||
//
|
||||
// Nested schema list.
|
||||
//
|
||||
OC_SCHEMA *Schema;
|
||||
//
|
||||
// Nested schema list size.
|
||||
//
|
||||
UINT32 SchemaSize;
|
||||
} OC_SCHEMA_DICT;
|
||||
|
||||
//
|
||||
// OC_SCHEMA_INFO for static values
|
||||
//
|
||||
|
||||
typedef enum OC_SCHEMA_VALUE_TYPE_ {
|
||||
OC_SCHEMA_VALUE_BOOLEAN,
|
||||
OC_SCHEMA_VALUE_INTEGER,
|
||||
OC_SCHEMA_VALUE_DATA,
|
||||
OC_SCHEMA_VALUE_STRING,
|
||||
OC_SCHEMA_VALUE_MDATA
|
||||
} OC_SCHEMA_VALUE_TYPE;
|
||||
|
||||
typedef struct {
|
||||
//
|
||||
// Value pointer.
|
||||
//
|
||||
UINTN Field;
|
||||
//
|
||||
// Value size.
|
||||
//
|
||||
UINT32 FieldSize;
|
||||
//
|
||||
// Source type.
|
||||
//
|
||||
OC_SCHEMA_VALUE_TYPE Type;
|
||||
} OC_SCHEMA_VALUE;
|
||||
|
||||
//
|
||||
// OC_SCHEMA_INFO for blob values
|
||||
//
|
||||
|
||||
typedef enum OC_SCHEMA_BLOB_TYPE_ {
|
||||
OC_SCHEMA_BLOB_DATA,
|
||||
OC_SCHEMA_BLOB_STRING,
|
||||
OC_SCHEMA_BLOB_MDATA
|
||||
} OC_SCHEMA_BLOB_TYPE;
|
||||
|
||||
typedef struct {
|
||||
//
|
||||
// Blob pointer.
|
||||
//
|
||||
UINTN Field;
|
||||
//
|
||||
// Source type.
|
||||
//
|
||||
OC_SCHEMA_BLOB_TYPE Type;
|
||||
} OC_SCHEMA_BLOB;
|
||||
|
||||
//
|
||||
// OC_SCHEMA_INFO for array/map lists
|
||||
//
|
||||
typedef struct {
|
||||
//
|
||||
// List pointer.
|
||||
//
|
||||
UINTN Field;
|
||||
//
|
||||
// List entry schema.
|
||||
//
|
||||
OC_SCHEMA *Schema;
|
||||
} OC_SCHEMA_LIST;
|
||||
|
||||
//
|
||||
// All standard variants of schema info
|
||||
//
|
||||
union OC_SCHEMA_INFO_ {
|
||||
OC_SCHEMA_DICT Dict;
|
||||
OC_SCHEMA_VALUE Value;
|
||||
OC_SCHEMA_BLOB Blob;
|
||||
OC_SCHEMA_LIST List;
|
||||
};
|
||||
|
||||
//
|
||||
// Schema context, allowing node recursion.
|
||||
//
|
||||
struct OC_SCHEMA_ {
|
||||
//
|
||||
// Key name to match against in the dictionary.
|
||||
//
|
||||
CONST CHAR8 *Name;
|
||||
//
|
||||
// Node type required to match to be able to call Apply.
|
||||
// PLIST_NODE_TYPE_ANY could be specified if Apply does the validation.
|
||||
//
|
||||
PLIST_NODE_TYPE Type;
|
||||
//
|
||||
// Apply handler that will merge Node data into object.
|
||||
//
|
||||
OC_APPLY Apply;
|
||||
//
|
||||
// Information about Node to object bridge.
|
||||
//
|
||||
OC_SCHEMA_INFO Info;
|
||||
};
|
||||
|
||||
//
|
||||
// Find schema in a sorted list
|
||||
//
|
||||
OC_SCHEMA *
|
||||
LookupConfigSchema (
|
||||
OC_SCHEMA *SortedList,
|
||||
UINT32 Size,
|
||||
CONST CHAR8 *Name
|
||||
);
|
||||
|
||||
//
|
||||
// Apply interface to parse serialized dictionaries
|
||||
//
|
||||
VOID
|
||||
ParseSerializedDict (
|
||||
VOID *Serialized,
|
||||
XML_NODE *Node,
|
||||
OC_SCHEMA_INFO *Info
|
||||
);
|
||||
|
||||
//
|
||||
// Apply interface to parse serialized OC_SCHEMA_VALUE_TYPE.
|
||||
//
|
||||
VOID
|
||||
ParseSerializedValue (
|
||||
VOID *Serialized,
|
||||
XML_NODE *Node,
|
||||
OC_SCHEMA_INFO *Info
|
||||
);
|
||||
|
||||
//
|
||||
// Apply interface to parse serialized OC_SCHEMA_BLOB_TYPE.
|
||||
//
|
||||
VOID
|
||||
ParseSerializedBlob (
|
||||
VOID *Serialized,
|
||||
XML_NODE *Node,
|
||||
OC_SCHEMA_INFO *Info
|
||||
);
|
||||
|
||||
//
|
||||
// Apply interface to parse serialized array
|
||||
//
|
||||
VOID
|
||||
ParseSerializedArray (
|
||||
VOID *Serialized,
|
||||
XML_NODE *Node,
|
||||
OC_SCHEMA_INFO *Info
|
||||
);
|
||||
|
||||
//
|
||||
// Apply interface to parse serialized map with arbitrary values,
|
||||
// and OC_STRING strings.
|
||||
//
|
||||
VOID
|
||||
ParseSerializedMap (
|
||||
VOID *Serialized,
|
||||
XML_NODE *Node,
|
||||
OC_SCHEMA_INFO *Info
|
||||
);
|
||||
|
||||
//
|
||||
// Main interface for parsing serialized data.
|
||||
// PlistBuffer will be modified during the execution.
|
||||
//
|
||||
BOOLEAN
|
||||
ParseSerialized (
|
||||
VOID *Serialized,
|
||||
OC_SCHEMA_INFO *RootSchema,
|
||||
VOID *PlistBuffer,
|
||||
UINT32 PlistSize
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve typed field pointer from offset
|
||||
//
|
||||
#define OC_SCHEMA_FIELD(Base, Type, Offset) \
|
||||
((Type *)(((UINT8 *) (Base)) + (Offset)))
|
||||
|
||||
//
|
||||
// Smart declaration base macros, see usage below.
|
||||
//
|
||||
#define OC_SCHEMA_VALUE(Name, Offset, Type, SourceType) \
|
||||
{(Name), PLIST_NODE_TYPE_ANY, ParseSerializedValue, \
|
||||
{.Value = {Offset, sizeof (Type), SourceType}}}
|
||||
|
||||
#define OC_SCHEMA_BLOB(Name, Offset, SourceType) \
|
||||
{(Name), PLIST_NODE_TYPE_ANY, ParseSerializedBlob, \
|
||||
{.Blob = {Offset, SourceType}}}
|
||||
|
||||
//
|
||||
// Smart declaration macros for builtin appliers,
|
||||
// which point straight to types.
|
||||
//
|
||||
// Name represents dictionary name if any (otherwise NULL).
|
||||
// Type represents value or value type for size calculation.
|
||||
// Schema represents element schema.
|
||||
//
|
||||
// M prefix stands for Meta, which means meta data type casting is used.
|
||||
// F suffix stands for Fixed, which means fixed file size is assumed.
|
||||
//
|
||||
#define OC_SCHEMA_DICT(Name, Schema) \
|
||||
{(Name), PLIST_NODE_TYPE_DICT, ParseSerializedDict, \
|
||||
{.Dict = {(Schema), ARRAY_SIZE (Schema)}}}
|
||||
|
||||
#define OC_SCHEMA_BOOLEAN(Name) \
|
||||
OC_SCHEMA_VALUE (Name, 0, BOOLEAN, OC_SCHEMA_VALUE_BOOLEAN)
|
||||
|
||||
#define OC_SCHEMA_INTEGER(Name, Type) \
|
||||
OC_SCHEMA_VALUE (Name, 0, Type, OC_SCHEMA_VALUE_INTEGER)
|
||||
|
||||
#define OC_SCHEMA_STRING(Name) \
|
||||
OC_SCHEMA_BLOB (Name, 0, OC_SCHEMA_BLOB_STRING)
|
||||
|
||||
#define OC_SCHEMA_STRINGF(Name, Type) \
|
||||
OC_SCHEMA_VALUE (Name, 0, Type, OC_SCHEMA_VALUE_STRING)
|
||||
|
||||
#define OC_SCHEMA_DATA(Name) \
|
||||
OC_SCHEMA_BLOB (Name, 0, OC_SCHEMA_BLOB_DATA)
|
||||
|
||||
#define OC_SCHEMA_DATAF(Name, Type) \
|
||||
OC_SCHEMA_VALUE (Name, 0, Type, OC_SCHEMA_VALUE_DATA)
|
||||
|
||||
#define OC_SCHEMA_MDATA(Name) \
|
||||
OC_SCHEMA_BLOB (Name, 0, OC_SCHEMA_BLOB_MDATA)
|
||||
|
||||
#define OC_SCHEMA_MDATAF(Name, Type) \
|
||||
OC_SCHEMA_VALUE (Name, 0, Type, OC_SCHEMA_VALUE_MDATA)
|
||||
|
||||
#define OC_SCHEMA_ARRAY(Name, ChildSchema) \
|
||||
{(Name), PLIST_NODE_TYPE_ARRAY, ParseSerializedArray, \
|
||||
{.List = {0, ChildSchema}}}
|
||||
|
||||
#define OC_SCHEMA_MAP(Name, ChildSchema) \
|
||||
{(Name), PLIST_NODE_TYPE_DICT, ParseSerializedMap, \
|
||||
{.List = {0, ChildSchema}}}
|
||||
|
||||
//
|
||||
// Smart declaration macros for builtin appliers,
|
||||
// which point to structures, containing these types.
|
||||
//
|
||||
// Name represents dictionary name if any (otherwise NULL).
|
||||
// Type represents container structure type for this value.
|
||||
// Field represents item in the container type.
|
||||
// Schema represents element schema.
|
||||
//
|
||||
#define OC_SCHEMA_BOOLEAN_IN(Name, Type, Field) \
|
||||
OC_SCHEMA_VALUE (Name, OFFSET_OF (Type, Field), (((Type *)0)->Field), \
|
||||
OC_SCHEMA_VALUE_BOOLEAN)
|
||||
|
||||
#define OC_SCHEMA_INTEGER_IN(Name, Type, Field) \
|
||||
OC_SCHEMA_VALUE (Name, OFFSET_OF (Type, Field), (((Type *)0)->Field), \
|
||||
OC_SCHEMA_VALUE_INTEGER)
|
||||
|
||||
#define OC_SCHEMA_STRING_IN(Name, Type, Field) \
|
||||
OC_SCHEMA_BLOB (Name, OFFSET_OF (Type, Field), OC_SCHEMA_BLOB_STRING)
|
||||
|
||||
#define OC_SCHEMA_STRINGF_IN(Name, Type, Field) \
|
||||
OC_SCHEMA_VALUE (Name, OFFSET_OF (Type, Field), (((Type *)0)->Field), \
|
||||
OC_SCHEMA_VALUE_STRING)
|
||||
|
||||
#define OC_SCHEMA_DATA_IN(Name, Type, Field) \
|
||||
OC_SCHEMA_BLOB (Name, OFFSET_OF (Type, Field), OC_SCHEMA_BLOB_DATA)
|
||||
|
||||
#define OC_SCHEMA_DATAF_IN(Name, Type, Field) \
|
||||
OC_SCHEMA_VALUE (Name, OFFSET_OF (Type, Field), (((Type *)0)->Field), \
|
||||
OC_SCHEMA_VALUE_DATA)
|
||||
|
||||
#define OC_SCHEMA_MDATA_IN(Name, Type, Field) \
|
||||
OC_SCHEMA_BLOB (Name, OFFSET_OF (Type, Field), OC_SCHEMA_BLOB_MDATA)
|
||||
|
||||
#define OC_SCHEMA_MDATAF_IN(Name, Type, Field) \
|
||||
OC_SCHEMA_VALUE (Name, OFFSET_OF (Type, Field), (((Type *)0)->Field), \
|
||||
OC_SCHEMA_VALUE_MDATA)
|
||||
|
||||
#define OC_SCHEMA_ARRAY_IN(Name, Type, Field, ChildSchema) \
|
||||
{(Name), PLIST_NODE_TYPE_ARRAY, ParseSerializedArray, \
|
||||
{.List = {OFFSET_OF (Type, Field), ChildSchema}}}
|
||||
|
||||
#define OC_SCHEMA_MAP_IN(Name, Type, Field, ChildSchema) \
|
||||
{(Name), PLIST_NODE_TYPE_DICT, ParseSerializedMap, \
|
||||
{.List = {OFFSET_OF (Type, Field), ChildSchema}}}
|
||||
|
||||
#endif // OC_SERIALIZE_LIB_H
|
||||
217
Include/Library/OcSmbiosLib.h
Normal file
217
Include/Library/OcSmbiosLib.h
Normal file
@ -0,0 +1,217 @@
|
||||
/** @file
|
||||
|
||||
OcSmbiosLib
|
||||
|
||||
Copyright (c) 2019, vit9696
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_SMBIOS_LIB_H
|
||||
#define OC_SMBIOS_LIB_H
|
||||
|
||||
#include <Library/OcCpuLib.h>
|
||||
#include <IndustryStandard/AppleSmBios.h>
|
||||
|
||||
//
|
||||
// This GUID is used for storing SMBIOS data when the firmware overwrites SMBIOS data at original
|
||||
// GUID at ExitBootServices, like it happens on some Dell computers.
|
||||
// Found by David Passmore. Guid matches syscl's implementation in Clover.
|
||||
// See: https://sourceforge.net/p/cloverefiboot/tickets/203/#c070
|
||||
//
|
||||
#define OC_CUSTOM_SMBIOS_TABLE_GUID \
|
||||
{ \
|
||||
0xeb9d2d35, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
|
||||
}
|
||||
|
||||
extern EFI_GUID gOcCustomSmbiosTableGuid;
|
||||
|
||||
//
|
||||
// We use this vendor name to spoof SMBIOS data on request.
|
||||
// Note, never use Apple or similar on non apple instances (e.g. VMs).
|
||||
// This breaks many internal and external os mechanisms.
|
||||
//
|
||||
#define OC_SMBIOS_VENDOR_NAME "Acidanthera"
|
||||
|
||||
typedef struct OC_SMBIOS_DATA_ {
|
||||
//
|
||||
// Type 0
|
||||
//
|
||||
CONST CHAR8 *BIOSVendor;
|
||||
CONST CHAR8 *BIOSVersion;
|
||||
CONST CHAR8 *BIOSReleaseDate;
|
||||
//
|
||||
// Type 1
|
||||
//
|
||||
CONST CHAR8 *SystemManufacturer;
|
||||
CONST CHAR8 *SystemProductName;
|
||||
CONST CHAR8 *SystemVersion;
|
||||
CONST CHAR8 *SystemSerialNumber;
|
||||
CONST GUID *SystemUUID;
|
||||
CONST CHAR8 *SystemSKUNumber;
|
||||
CONST CHAR8 *SystemFamily;
|
||||
//
|
||||
// Type 2
|
||||
//
|
||||
CONST CHAR8 *BoardManufacturer;
|
||||
CONST CHAR8 *BoardProduct;
|
||||
CONST CHAR8 *BoardVersion;
|
||||
CONST CHAR8 *BoardSerialNumber;
|
||||
CONST CHAR8 *BoardAssetTag;
|
||||
CONST CHAR8 *BoardLocationInChassis;
|
||||
CONST UINT8 *BoardType;
|
||||
//
|
||||
// Type 3
|
||||
//
|
||||
CONST UINT8 *ChassisType;
|
||||
CONST CHAR8 *ChassisManufacturer;
|
||||
CONST CHAR8 *ChassisVersion;
|
||||
CONST CHAR8 *ChassisSerialNumber;
|
||||
CONST CHAR8 *ChassisAssetTag;
|
||||
//
|
||||
// Type 17
|
||||
//
|
||||
CONST UINT8 *MemoryFormFactor;
|
||||
//
|
||||
// Type 128
|
||||
// FirmwareFeatures and FirmwareFeaturesMask are split into two UINT32
|
||||
// values, the lower referring to the traditional FirmwareFeatures and the
|
||||
// upper representing the additions introduced by ExtendedFirmwareFeatures.
|
||||
//
|
||||
UINT64 FirmwareFeatures;
|
||||
UINT64 FirmwareFeaturesMask;
|
||||
//
|
||||
// Type 131
|
||||
//
|
||||
CONST UINT16 *ProcessorType;
|
||||
//
|
||||
// Type 133
|
||||
//
|
||||
CONST UINT32 *PlatformFeature;
|
||||
//
|
||||
// Type 134
|
||||
//
|
||||
CONST UINT8 *SmcVersion;
|
||||
} OC_SMBIOS_DATA;
|
||||
|
||||
typedef enum OC_SMBIOS_UPDATE_MODE_ {
|
||||
//
|
||||
// OcSmbiosUpdateOverwrite if new size is <= than the page-aligned original and
|
||||
// there are no issues with legacy region unlock. OcSmbiosUpdateCreate otherwise.
|
||||
//
|
||||
OcSmbiosUpdateTryOverwrite = 0,
|
||||
//
|
||||
// Replace the tables with newly allocated. Normally it is in EfiRuntimeData (EDK 2), but
|
||||
// boot.efi relocates EfiRuntimeData unless AptioMemoryFix is used, so it is incorrect.
|
||||
// * MacEFI allocates in EfiReservedMemoryType at BASE_4GB-1:
|
||||
// - gEfiSmbiosTableGuid entry: AllocateMaxAddress or AllocateAnyPages
|
||||
// - gEfiSmbiosTableGuid pages: AllocateMaxAddress
|
||||
// - gEfiSmbiosTable3Guid entry and pages: AllocateAnyPages
|
||||
// * Clover similarly allocates at EfiACPIMemoryNVS or EfiACPIReclaimMemory, if allocating
|
||||
// from EfiACPIMemoryNVS fails. EfiACPIReclaimMemory is actually unsafe, as ACPI driver may
|
||||
// theoretically nuke it after loading as per 7.2 Memory Allocation Services, Table 29 of
|
||||
// UEFI 2.7A specification (page 166).
|
||||
// * We allocate EfiReservedMemoryType at AllocateMaxAddress without any fallbacks.
|
||||
//
|
||||
OcSmbiosUpdateCreate = 1,
|
||||
//
|
||||
// Overwrite existing gEfiSmbiosTableGuid and gEfiSmbiosTable3Guid data if it fits new size.
|
||||
// Abort with unspecified state otherwise.
|
||||
//
|
||||
OcSmbiosUpdateOverwrite = 2,
|
||||
//
|
||||
// Writes first SMBIOS table (gEfiSmbiosTableGuid) to gOcCustomSmbiosTableGuid to workaround
|
||||
// firmwares overwriting SMBIOS contents at ExitBootServices. Otherwise equivalent to
|
||||
// OcSmbiosUpdateCreate. Requires patching AppleSmbios.kext and AppleACPIPlatform.kext to read
|
||||
// from another GUID: "EB9D2D31" -> "EB9D2D35" (in ASCII).
|
||||
//
|
||||
OcSmbiosUpdateCustom = 3,
|
||||
} OC_SMBIOS_UPDATE_MODE;
|
||||
|
||||
//
|
||||
// Growing SMBIOS table data.
|
||||
//
|
||||
typedef struct OC_SMBIOS_TABLE_ {
|
||||
//
|
||||
// SMBIOS table.
|
||||
//
|
||||
UINT8 *Table;
|
||||
//
|
||||
// Current table position.
|
||||
//
|
||||
APPLE_SMBIOS_STRUCTURE_POINTER CurrentPtr;
|
||||
//
|
||||
// Current string position.
|
||||
//
|
||||
CHAR8 *CurrentStrPtr;
|
||||
//
|
||||
// Allocated table size, multiple of EFI_PAGE_SIZE.
|
||||
//
|
||||
UINT32 AllocatedTableSize;
|
||||
//
|
||||
// Incrementable handle.
|
||||
//
|
||||
SMBIOS_HANDLE Handle;
|
||||
//
|
||||
// Largest structure size within the table.
|
||||
//
|
||||
UINT16 MaxStructureSize;
|
||||
//
|
||||
// Number of structures within the table.
|
||||
//
|
||||
UINT16 NumberOfStructures;
|
||||
} OC_SMBIOS_TABLE;
|
||||
|
||||
/**
|
||||
Prepare new SMBIOS table based on host data.
|
||||
|
||||
@param SmbiosTable
|
||||
|
||||
@retval EFI_SUCCESS if buffer is ready to be filled.
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcSmbiosTablePrepare (
|
||||
IN OUT OC_SMBIOS_TABLE *SmbiosTable
|
||||
);
|
||||
|
||||
/**
|
||||
Free SMBIOS table
|
||||
|
||||
@param[in, out] Table Current table buffer.
|
||||
|
||||
@retval EFI_SUCCESS on success
|
||||
**/
|
||||
VOID
|
||||
OcSmbiosTableFree (
|
||||
IN OUT OC_SMBIOS_TABLE *Table
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
OcSmbiosCreate (
|
||||
IN OUT OC_SMBIOS_TABLE *SmbiosTable,
|
||||
IN OC_SMBIOS_DATA *Data,
|
||||
IN OC_SMBIOS_UPDATE_MODE Mode,
|
||||
IN OC_CPU_INFO *CpuInfo
|
||||
);
|
||||
|
||||
VOID
|
||||
OcSmbiosExposeOemInfo (
|
||||
IN OC_SMBIOS_TABLE *SmbiosTable
|
||||
);
|
||||
|
||||
VOID
|
||||
OcSmbiosGetSmcVersion (
|
||||
IN CONST UINT8 *SmcRevision,
|
||||
OUT UINT8 *SmcVersion
|
||||
);
|
||||
|
||||
#endif // OC_SMBIOS_LIB_H
|
||||
34
Include/Library/OcSmcLib.h
Normal file
34
Include/Library/OcSmcLib.h
Normal file
@ -0,0 +1,34 @@
|
||||
/** @file
|
||||
Copyright (C) 2020, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_SMC_LIB_H
|
||||
#define OC_SMC_LIB_H
|
||||
|
||||
#include <Protocol/AppleSmcIo.h>
|
||||
|
||||
/**
|
||||
Install and initialise SMC I/O protocol.
|
||||
|
||||
@param[in] Reinstall Overwrite installed protocol.
|
||||
@param[in] AuthRestart Support AuthRestart protocol via VSMC.
|
||||
|
||||
@retval installed or located protocol or NULL.
|
||||
**/
|
||||
APPLE_SMC_IO_PROTOCOL *
|
||||
OcSmcIoInstallProtocol (
|
||||
IN BOOLEAN Reinstall,
|
||||
IN BOOLEAN AuthRestart
|
||||
);
|
||||
|
||||
#endif // OC_SMC_LIB_H
|
||||
150
Include/Library/OcStorageLib.h
Normal file
150
Include/Library/OcStorageLib.h
Normal file
@ -0,0 +1,150 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_STORAGE_LIB_H
|
||||
#define OC_STORAGE_LIB_H
|
||||
|
||||
#include <Library/OcCryptoLib.h>
|
||||
#include <Library/OcGuardLib.h>
|
||||
#include <Library/OcFileLib.h>
|
||||
#include <Library/OcSerializeLib.h>
|
||||
|
||||
/**
|
||||
Storage vault file containing a dictionary with SHA-256 hashes for all files.
|
||||
**/
|
||||
#define OC_STORAGE_VAULT_PATH L"vault.plist"
|
||||
|
||||
/**
|
||||
RSA-2048 signature of SHA-256 hash of vault.plist.
|
||||
**/
|
||||
#define OC_STORAGE_VAULT_SIGNATURE_PATH L"vault.sig"
|
||||
|
||||
/**
|
||||
Storage vault version declaring vault compatibility.
|
||||
**/
|
||||
#define OC_STORAGE_VAULT_VERSION 1
|
||||
|
||||
/**
|
||||
Structure declaration for valult file.
|
||||
**/
|
||||
#define OC_STORAGE_VAULT_HASH_FIELDS(_, __) \
|
||||
_(UINT8 , Hash , [SHA256_DIGEST_SIZE] , {0} , () )
|
||||
OC_DECLARE (OC_STORAGE_VAULT_HASH)
|
||||
|
||||
#define OC_STORAGE_VAULT_FILES_FIELDS(_, __) \
|
||||
OC_MAP (OC_STRING, OC_STORAGE_VAULT_HASH, _, __)
|
||||
OC_DECLARE (OC_STORAGE_VAULT_FILES)
|
||||
|
||||
#define OC_STORAGE_VAULT_FIELDS(_, __) \
|
||||
_(UINT32 , Version , , 0 , () ) \
|
||||
_(OC_STORAGE_VAULT_FILES , Files , , OC_CONSTR (OC_STORAGE_VAULT_FILES, _, __) , OC_DESTR (OC_STORAGE_VAULT_FILES))
|
||||
OC_DECLARE (OC_STORAGE_VAULT)
|
||||
|
||||
/**
|
||||
Storage abstraction context
|
||||
**/
|
||||
typedef struct {
|
||||
///
|
||||
/// Storage file system if any.
|
||||
///
|
||||
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;
|
||||
///
|
||||
/// Storage root owned by context.
|
||||
///
|
||||
EFI_FILE_PROTOCOL *StorageRoot;
|
||||
///
|
||||
/// Device handle with storage (dummy) device path for loading.
|
||||
///
|
||||
EFI_HANDLE StorageHandle;
|
||||
///
|
||||
/// Dummy file path for file storage.
|
||||
///
|
||||
EFI_DEVICE_PATH_PROTOCOL *DummyDevicePath;
|
||||
///
|
||||
/// Dummy file path relative to storage.
|
||||
///
|
||||
EFI_DEVICE_PATH_PROTOCOL *DummyFilePath;
|
||||
///
|
||||
/// Vault context.
|
||||
///
|
||||
OC_STORAGE_VAULT Vault;
|
||||
///
|
||||
/// Vault status.
|
||||
///
|
||||
BOOLEAN HasVault;
|
||||
} OC_STORAGE_CONTEXT;
|
||||
|
||||
/**
|
||||
Create storage context from UEFI file system at specified path.
|
||||
|
||||
@param[out] Context Resulting storage context.
|
||||
@param[in] FileSystem Storage file system.
|
||||
@param[in] Path Storage file system path (e.g. L"\\").
|
||||
@param[in] Key Storage signature verification key, optional.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
OcStorageInitFromFs (
|
||||
OUT OC_STORAGE_CONTEXT *Context,
|
||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
|
||||
IN CONST CHAR16 *Path,
|
||||
IN OC_RSA_PUBLIC_KEY *StorageKey OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Free storage context resources.
|
||||
|
||||
@param[in,out] Context Storage context.
|
||||
**/
|
||||
VOID
|
||||
OcStorageFree (
|
||||
IN OUT OC_STORAGE_CONTEXT *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Check whether file exists.
|
||||
|
||||
@param[in] Context Storage context.
|
||||
@param[in] FilePath The full path to the file on the device.
|
||||
|
||||
@retval TRUE if file is present in vault or ondisk.
|
||||
**/
|
||||
BOOLEAN
|
||||
OcStorageExistsFileUnicode (
|
||||
IN OC_STORAGE_CONTEXT *Context,
|
||||
IN CONST CHAR16 *FilePath
|
||||
);
|
||||
|
||||
/**
|
||||
Read file from storage with implicit double (2 byte) null termination.
|
||||
Null termination does not affect the returned file size.
|
||||
Depending on the implementation 0 byte files may return null.
|
||||
If storage context was created with valid storage key, then signature
|
||||
checking will be performed
|
||||
|
||||
@param[in] Context Storage context.
|
||||
@param[in] FilePath The full path to the file on the device.
|
||||
@param[out] FileSize The size of the file read (optional).
|
||||
|
||||
@retval A pointer to a buffer containing file read or NULL.
|
||||
**/
|
||||
VOID *
|
||||
OcStorageReadFileUnicode (
|
||||
IN OC_STORAGE_CONTEXT *Context,
|
||||
IN CONST CHAR16 *FilePath,
|
||||
OUT UINT32 *FileSize OPTIONAL
|
||||
);
|
||||
|
||||
#endif // OC_STORAGE_LIB_H
|
||||
229
Include/Library/OcStringLib.h
Executable file
229
Include/Library/OcStringLib.h
Executable file
@ -0,0 +1,229 @@
|
||||
/** @file
|
||||
Copyright (C) 2016 - 2018, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_STRING_LIB_H_
|
||||
#define OC_STRING_LIB_H_
|
||||
|
||||
/**
|
||||
Returns the length of a Null-terminated string literal.
|
||||
|
||||
@param[in] String The Null-terminated string literal.
|
||||
|
||||
**/
|
||||
#define L_STR_LEN(String) (ARRAY_SIZE (String) - 1)
|
||||
|
||||
/**
|
||||
Returns the size of a Null-terminated string literal in bytes, including the
|
||||
Null terminator.
|
||||
|
||||
@param[in] String The Null-terminated string literal.
|
||||
|
||||
**/
|
||||
#define L_STR_SIZE(String) (sizeof (String))
|
||||
|
||||
/**
|
||||
Returns the size of a Null-terminated string literal in bytes, excluding the
|
||||
Null terminator.
|
||||
|
||||
@param[in] String The Null-terminated string literal.
|
||||
|
||||
**/
|
||||
#define L_STR_SIZE_NT(String) (sizeof (String) - sizeof (*(String)))
|
||||
|
||||
/** Check if character is printable
|
||||
|
||||
@param[in] Char The ascii character to check if is printable.
|
||||
|
||||
@retval TRUE, if character is printable.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsAsciiPrint (
|
||||
IN CHAR8 Char
|
||||
);
|
||||
|
||||
/** Check if character is a white space character
|
||||
|
||||
@param[in] Char The ascii character to check if is white space.
|
||||
|
||||
@retval TRUE, if character is a white space character
|
||||
**/
|
||||
INTN
|
||||
IsAsciiSpace (
|
||||
IN CHAR8 Char
|
||||
);
|
||||
|
||||
/** Convert null terminated ascii string to unicode.
|
||||
|
||||
@param[in] String1 A pointer to the ascii string to convert to unicode.
|
||||
@param[in] Length Length or 0 to calculate the length of the ascii string to convert.
|
||||
|
||||
@retval A pointer to the converted unicode string allocated from pool.
|
||||
**/
|
||||
CHAR16 *
|
||||
AsciiStrCopyToUnicode (
|
||||
IN CONST CHAR8 *String,
|
||||
IN UINTN Length
|
||||
);
|
||||
|
||||
/**
|
||||
Convert 64-bit unsigned integer to a nul-termianted hex string.
|
||||
|
||||
@param[out] Buffer Destination buffer.
|
||||
@param[in] BufferSize Destination buffer size in bytes.
|
||||
@param[in] Value Value to convert.
|
||||
**/
|
||||
BOOLEAN
|
||||
AsciiUint64ToLowerHex (
|
||||
OUT CHAR8 *Buffer,
|
||||
IN UINT32 BufferSize,
|
||||
IN UINT64 Value
|
||||
);
|
||||
|
||||
/**
|
||||
Performs a case insensitive comparison of two Null-terminated Unicode strings,
|
||||
and returns the difference between the first mismatched Unicode characters.
|
||||
|
||||
This function performs a case insensitive comparison of the Null-terminated
|
||||
Unicode string FirstString to the Null-terminated Unicode string
|
||||
SecondString. If FirstString is identical to SecondString, then 0 is
|
||||
returned. Otherwise, the value returned is the first mismatched upper case
|
||||
Unicode character in SecondString subtracted from the first mismatched upper
|
||||
case Unicode character in FirstString.
|
||||
|
||||
If FirstString is NULL, then ASSERT().
|
||||
If SecondString is NULL, then ASSERT().
|
||||
If PcdMaximumUnicodeStringLength is not zero and FirstString contains more
|
||||
than PcdMaximumUnicodeStringLength Unicode characters, not including the
|
||||
Null-terminator, then ASSERT().
|
||||
If PcdMaximumUnicodeStringLength is not zero and SecondString contains more
|
||||
than PcdMaximumUnicodeStringLength Unicode characters, not including the
|
||||
Null-terminator, then ASSERT().
|
||||
|
||||
@param FirstString A pointer to a Null-terminated Unicode string.
|
||||
@param SecondString A pointer to a Null-terminated Unicode string.
|
||||
|
||||
@retval ==0 FirstString is identical to SecondString using case
|
||||
insensitiv comparisons.
|
||||
@retval !=0 FirstString is not identical to SecondString using case
|
||||
insensitive comparisons.
|
||||
|
||||
**/
|
||||
INTN
|
||||
EFIAPI
|
||||
StriCmp (
|
||||
IN CHAR16 *FirstString,
|
||||
IN CHAR16 *SecondString
|
||||
);
|
||||
|
||||
/**
|
||||
Compares up to a specified length the contents of two Null-terminated Unicode
|
||||
strings using case insensitive comparisons, and returns the difference
|
||||
between the first mismatched Unicode characters.
|
||||
|
||||
This function compares the Null-terminated Unicode string FirstString to the
|
||||
Null-terminated Unicode string SecondString using case insensitive
|
||||
comparisons. At most, Length Unicode characters will be compared. If Length
|
||||
is 0, then 0 is returned. If FirstString is identical to SecondString, then 0
|
||||
is returned. Otherwise, the value returned is the first mismatched upper case
|
||||
Unicode character in SecondString subtracted from the first mismatched upper
|
||||
case Unicode character in FirstString.
|
||||
|
||||
If Length > 0 and FirstString is NULL, then ASSERT().
|
||||
If Length > 0 and FirstString is not aligned on a 16-bit boundary, then
|
||||
ASSERT().
|
||||
If Length > 0 and SecondString is NULL, then ASSERT().
|
||||
If Length > 0 and SecondString is not aligned on a 16-bit boundary, then
|
||||
ASSERT().
|
||||
If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
|
||||
PcdMaximumUnicodeStringLength, then ASSERT().
|
||||
If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
|
||||
than PcdMaximumUnicodeStringLength Unicode characters, not including the
|
||||
Null-terminator, then ASSERT().
|
||||
If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
|
||||
than PcdMaximumUnicodeStringLength Unicode characters, not including the
|
||||
Null-terminator, then ASSERT().
|
||||
|
||||
@param FirstString A pointer to a Null-terminated Unicode string.
|
||||
@param SecondString A pointer to a Null-terminated Unicode string.
|
||||
@param Length The maximum number of Unicode characters to compare.
|
||||
|
||||
@retval ==0 FirstString is identical to SecondString using case
|
||||
insensitive comparisons.
|
||||
@retval others FirstString is not identical to SecondString using case
|
||||
insensitive comparisons.
|
||||
|
||||
**/
|
||||
INTN
|
||||
EFIAPI
|
||||
StrniCmp (
|
||||
IN CONST CHAR16 *FirstString,
|
||||
IN CONST CHAR16 *SecondString,
|
||||
IN UINTN Length
|
||||
);
|
||||
|
||||
/**
|
||||
Returns the first occurrence of a Null-terminated Unicode sub-string
|
||||
in a Null-terminated Unicode string through a case insensitive comparison.
|
||||
|
||||
This function scans the contents of the Null-terminated Unicode string
|
||||
specified by String and returns the first occurrence of SearchString.
|
||||
If SearchString is not found in String, then NULL is returned. If
|
||||
the length of SearchString is zero, then String is returned.
|
||||
|
||||
If String is NULL, then ASSERT().
|
||||
If String is not aligned on a 16-bit boundary, then ASSERT().
|
||||
If SearchString is NULL, then ASSERT().
|
||||
If SearchString is not aligned on a 16-bit boundary, then ASSERT().
|
||||
|
||||
If PcdMaximumUnicodeStringLength is not zero, and SearchString
|
||||
or String contains more than PcdMaximumUnicodeStringLength Unicode
|
||||
characters, not including the Null-terminator, then ASSERT().
|
||||
|
||||
@param String The pointer to a Null-terminated Unicode string.
|
||||
@param SearchString The pointer to a Null-terminated Unicode string to search for.
|
||||
|
||||
@retval NULL If the SearchString does not appear in String.
|
||||
@return others If there is a match.
|
||||
|
||||
**/
|
||||
CHAR16 *
|
||||
EFIAPI
|
||||
StriStr (
|
||||
IN CONST CHAR16 *String,
|
||||
IN CONST CHAR16 *SearchString
|
||||
);
|
||||
|
||||
/**
|
||||
Convert path with mixed slashes to UEFI slashes (\\).
|
||||
|
||||
@param[in,out] String Path.
|
||||
**/
|
||||
VOID
|
||||
UnicodeUefiSlashes (
|
||||
IN OUT CHAR16 *String
|
||||
);
|
||||
|
||||
/**
|
||||
Filter string from unprintable characters.
|
||||
|
||||
@param[in,out] String String to filter.
|
||||
@param[in] SingleLine Enforce only one line.
|
||||
**/
|
||||
VOID
|
||||
UnicodeFilterString (
|
||||
IN OUT CHAR16 *String,
|
||||
IN BOOLEAN SingleLine
|
||||
);
|
||||
|
||||
#endif // OC_STRING_LIB_H_
|
||||
290
Include/Library/OcTemplateLib.h
Normal file
290
Include/Library/OcTemplateLib.h
Normal file
@ -0,0 +1,290 @@
|
||||
/** @file
|
||||
|
||||
OcTemplateLib
|
||||
|
||||
Copyright (c) 2018, vit9696
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef OC_TEMPLATE_LIB_H
|
||||
#define OC_TEMPLATE_LIB_H
|
||||
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
|
||||
//
|
||||
// Common structor prototype.
|
||||
//
|
||||
typedef
|
||||
VOID
|
||||
(*OC_STRUCTOR) (
|
||||
VOID *Ptr,
|
||||
UINT32 Size
|
||||
);
|
||||
|
||||
//
|
||||
// Private primitives for type generations
|
||||
//
|
||||
|
||||
#define PRIV_OC_STRUCTOR_IGNORE(...)
|
||||
#define PRIV_OC_STRUCTOR_EXPAND(...) __VA_ARGS__
|
||||
|
||||
#define PRIV_OC_SELECT_NEXT_INNER(Dummy, Next, ...) Next
|
||||
//
|
||||
// Without this layer of indirection, MSVC evaluates __VA_ARGS__ early and
|
||||
// PRIV_OC_SELECT_NEXT_INNER receives only two arguments, the second always
|
||||
// being Unused as per PRIV_OC_SELECT_NEXT.
|
||||
//
|
||||
#define PRIV_OC_SELECT_NEXT_INNER_INDIR(...) PRIV_OC_SELECT_NEXT_INNER __VA_ARGS__
|
||||
#define PRIV_OC_SELECT_NEXT(...) PRIV_OC_SELECT_NEXT_INNER_INDIR((__VA_ARGS__, Unused))
|
||||
#define PRIV_OC_REMOVE_NEXT(...) , do { } while (0),
|
||||
|
||||
#define PRIV_OC_DECLARE_STRUCT_MEMBER(Type, Name, Suffix, Constructor, Destructor) \
|
||||
Type Name Suffix;
|
||||
|
||||
#define PRIV_OC_CONSTRUCT_STRUCT_MEMBER(Type, Name, Suffix, Constructor, Destructor) \
|
||||
.Name = Constructor,
|
||||
|
||||
#define PRIV_OC_DESTRUCT_STRUCT_MEMBER(Type, Name, Suffix, Constructor, Destructor) \
|
||||
PRIV_OC_SELECT_NEXT(PRIV_OC_REMOVE_NEXT Destructor, Destructor(&Obj->Name, sizeof (Type Suffix)));
|
||||
|
||||
#define PRIV_OC_INVOKE_DESTRUCTOR(Destructor, Obj, Size) \
|
||||
PRIV_OC_SELECT_NEXT(PRIV_OC_REMOVE_NEXT Destructor, Destructor(Obj, Size))
|
||||
|
||||
#define PRIV_NO_KEY_TYPE UINT8
|
||||
|
||||
//
|
||||
// Declare structure type NAME. Construction and destruction interfaces will also be
|
||||
// available with corresponding prototypes:
|
||||
// VOID NAME_CONSTRUCT(Void *Ptr, UINTN Size);
|
||||
// VOID NAME_DESTRUCT(Void *Ptr, UINTN Size);
|
||||
//
|
||||
// Field information will be retrieved from NAME_FIELDS X-Macro, written as follows:
|
||||
#if 0
|
||||
#define NAME_FIELDS(_, __) \
|
||||
_(Type, Name, Type Suffix, __(Constant Initializer), Destructor Function) \
|
||||
_(Type, Name, Type Suffix, OC_CONSTR(Type, _, __), OC_DESTR(Type))
|
||||
#endif
|
||||
//
|
||||
|
||||
#define OC_DECLARE(Name) \
|
||||
typedef struct Name ## _ { \
|
||||
Name ## _FIELDS (PRIV_OC_DECLARE_STRUCT_MEMBER, PRIV_OC_STRUCTOR_IGNORE) \
|
||||
} Name; \
|
||||
VOID Name ## _CONSTRUCT(VOID *Ptr, UINT32 Size); \
|
||||
VOID Name ## _DESTRUCT(VOID *Ptr, UINT32 Size);
|
||||
|
||||
//
|
||||
// Generate constructors and destructors for structure type NAME.
|
||||
// Second argument permits to do extra actions prior to field destruction.
|
||||
// Pass () to the second argument to ignore this option.
|
||||
//
|
||||
#define OC_STRUCTORS(Name, Destructor) \
|
||||
VOID Name ## _CONSTRUCT(VOID *Ptr, UINT32 Size) { \
|
||||
STATIC Name Obj = { \
|
||||
Name ## _FIELDS(PRIV_OC_CONSTRUCT_STRUCT_MEMBER, PRIV_OC_STRUCTOR_EXPAND) \
|
||||
}; \
|
||||
CopyMem (Ptr, &Obj, sizeof (Name)); \
|
||||
} \
|
||||
VOID Name ## _DESTRUCT(VOID *Ptr, UINT32 Size) { \
|
||||
Name *Obj = (Name *) Ptr; (VOID) Obj; \
|
||||
PRIV_OC_INVOKE_DESTRUCTOR(Destructor, Obj, sizeof (Name)); \
|
||||
Name ## _FIELDS(PRIV_OC_DESTRUCT_STRUCT_MEMBER, PRIV_OC_STRUCTOR_EXPAND) \
|
||||
}
|
||||
|
||||
//
|
||||
// Use previously defined structure constructor or destructor
|
||||
// FIXME: We need to use these recursively, and normally one would implement
|
||||
// it with deferred execution, like this:
|
||||
// #define OC_CONSTR_REAL(A, _, __) ({A ## _FIELDS(_, __)})
|
||||
// #define OC_CONSTR_REAL_ID() OC_CONSTR_REAL
|
||||
// #define OC_CONSTR DEFER(OC_CONSTR_REAL_ID)()
|
||||
// However, this will not work in this exact case, as _, which itself is a macro,
|
||||
// changes the expansion order. The right fix here is to entirely remove the mess
|
||||
// and use external tool for template generation.
|
||||
//
|
||||
#define OC_CONSTR(A, _, __) {A ## _FIELDS(_, __)}
|
||||
#define OC_CONSTR1(A, _, __) {A ## _FIELDS(_, __)}
|
||||
#define OC_CONSTR2(A, _, __) {A ## _FIELDS(_, __)}
|
||||
#define OC_CONSTR3(A, _, __) {A ## _FIELDS(_, __)}
|
||||
#define OC_CONSTR5(A, _, __) {A ## _FIELDS(_, __)}
|
||||
#define OC_DESTR(A) A ## _DESTRUCT
|
||||
|
||||
//
|
||||
// Generate array-like blob (string, data, metadata) of type Type,
|
||||
// Count static size, MaxSize is real size, and default value Default.
|
||||
//
|
||||
#define OC_BLOB(Type, Count, Default, _, __) \
|
||||
_(UINT32 , Size , , 0 , OcZeroField ) \
|
||||
_(UINT32 , MaxSize , , sizeof (Type Count) , OcZeroField ) \
|
||||
_(Type * , DynValue , , NULL , OcFreePointer ) \
|
||||
_(Type , Value , Count , __(Default) , () )
|
||||
|
||||
#define OC_BLOB_STRUCTORS(Name) \
|
||||
OC_STRUCTORS(Name, ())
|
||||
|
||||
#define OC_BLOB_CONSTR(Type, Constructor, SizeConstructor, _, __) \
|
||||
__({.Size = SizeConstructor, .MaxSize = sizeof (((Type *)0)->Value), .DynValue = NULL, .Value = Constructor})
|
||||
|
||||
//
|
||||
// Generate map-like container with key elements of type KeyType, OC_BLOB derivative,
|
||||
// value types of Type constructed by Constructor and destructed by Destructor:
|
||||
#if 0
|
||||
#define CONT_FIELDS(_, __) \
|
||||
OC_MAP (KEY, ELEM, _, __)
|
||||
OC_DECLARE (CONT)
|
||||
#endif
|
||||
//
|
||||
|
||||
#define OC_MAP(KeyType, Type, _, __) \
|
||||
_(UINT32 , Count , , 0 , () ) \
|
||||
_(UINT32 , AllocCount , , 0 , () ) \
|
||||
_(OC_STRUCTOR , Construct , , Type ## _CONSTRUCT , () ) \
|
||||
_(OC_STRUCTOR , Destruct , , Type ## _DESTRUCT , () ) \
|
||||
_(Type ** , Values , , NULL , () ) \
|
||||
_(UINT32 , ValueSize , , sizeof (Type) , () ) \
|
||||
_(UINT32 , KeySize , , sizeof (KeyType) , () ) \
|
||||
_(OC_STRUCTOR , KeyConstruct , , KeyType ## _CONSTRUCT , () ) \
|
||||
_(OC_STRUCTOR , KeyDestruct , , KeyType ## _DESTRUCT , () ) \
|
||||
_(KeyType ** , Keys , , NULL , () )
|
||||
|
||||
#define OC_MAP_STRUCTORS(Name) \
|
||||
OC_STRUCTORS(Name, OcFreeMap)
|
||||
|
||||
//
|
||||
// Generate array-like container with elements of type Type, constructed
|
||||
// by Constructor and destructed by Destructor.
|
||||
#if 0
|
||||
#define CONT_FIELDS(_, __) \
|
||||
OC_ARRAY (ELEM, _, __)
|
||||
OC_DECLARE (CONT)
|
||||
#endif
|
||||
//
|
||||
|
||||
#define OC_ARRAY(Type, _, __) \
|
||||
_(UINT32 , Count , , 0 , () ) \
|
||||
_(UINT32 , AllocCount , , 0 , () ) \
|
||||
_(OC_STRUCTOR , Construct , , Type ## _CONSTRUCT , () ) \
|
||||
_(OC_STRUCTOR , Destruct , , Type ## _DESTRUCT , () ) \
|
||||
_(Type ** , Values , , NULL , () ) \
|
||||
_(UINT32 , ValueSize , , sizeof (Type) , () )
|
||||
|
||||
#define OC_ARRAY_STRUCTORS(Name) \
|
||||
OC_STRUCTORS(Name, OcFreeArray)
|
||||
|
||||
//
|
||||
// Free dynamically allocated memory if non NULL.
|
||||
// Note, that the first argument is actually VOID **.
|
||||
//
|
||||
VOID
|
||||
OcFreePointer (
|
||||
VOID *Pointer,
|
||||
UINT32 Size
|
||||
);
|
||||
|
||||
//
|
||||
// Zero field memory.
|
||||
//
|
||||
VOID
|
||||
OcZeroField (
|
||||
VOID *Pointer,
|
||||
UINT32 Size
|
||||
);
|
||||
|
||||
//
|
||||
// Do not invoke any actions at destruction.
|
||||
//
|
||||
VOID
|
||||
OcDestructEmpty (
|
||||
VOID *Pointer,
|
||||
UINT32 Size
|
||||
);
|
||||
|
||||
//
|
||||
// OC_MAP-like destructor.
|
||||
//
|
||||
VOID
|
||||
OcFreeMap (
|
||||
VOID *Pointer,
|
||||
UINT32 Size
|
||||
);
|
||||
|
||||
//
|
||||
// OC_ARRAY-like destructor.
|
||||
//
|
||||
VOID
|
||||
OcFreeArray (
|
||||
VOID *Pointer,
|
||||
UINT32 Size
|
||||
);
|
||||
|
||||
//
|
||||
// Prepare memory for blob at Pointer to contain Size bytes.
|
||||
// Assignable size may be returned via OutSize.
|
||||
// This method guarantees not to overwrite "Default" value,
|
||||
// but may destroy the previous value.
|
||||
// NULL is returned on allocation failure.
|
||||
//
|
||||
VOID *
|
||||
OcBlobAllocate (
|
||||
VOID *Pointer,
|
||||
UINT32 Size,
|
||||
UINT32 **OutSize OPTIONAL
|
||||
);
|
||||
|
||||
//
|
||||
// Obtain blob value
|
||||
//
|
||||
#define OC_BLOB_GET(Blob) (((Blob)->DynValue) != NULL ? ((Blob)->DynValue) : ((Blob)->Value))
|
||||
|
||||
//
|
||||
// Insert new empty element into the OC_MAP or OC_ARRAY, depending
|
||||
// on Key value.
|
||||
//
|
||||
BOOLEAN
|
||||
OcListEntryAllocate (
|
||||
VOID *Pointer,
|
||||
VOID **Value,
|
||||
VOID **Key
|
||||
);
|
||||
|
||||
//
|
||||
// Some useful generic types
|
||||
// OC_STRING - implements support for resizable ASCII strings.
|
||||
// OC_DATA - implements support for resizable data blobs.
|
||||
// OC_ASSOC - implements support for maps with ASCII keys and data values.
|
||||
//
|
||||
#define OC_STRING_FIELDS(_, __) \
|
||||
OC_BLOB (CHAR8, [64], {0}, _, __)
|
||||
OC_DECLARE (OC_STRING)
|
||||
|
||||
#define OC_STRING_CONSTR(Constructor, _, __) \
|
||||
OC_BLOB_CONSTR (OC_STRING, __(Constructor), sizeof (Constructor), _, __)
|
||||
|
||||
#define OC_ESTRING_CONSTR(_, __) \
|
||||
OC_BLOB_CONSTR (OC_STRING, __(""), 0, _, __)
|
||||
|
||||
#define OC_DATA_FIELDS(_, __) \
|
||||
OC_BLOB (UINT8, [64], {0}, _, __)
|
||||
OC_DECLARE (OC_DATA)
|
||||
|
||||
#define OC_EDATA_CONSTR(_, __) \
|
||||
OC_BLOB_CONSTR (OC_DATA, __({0}), 0, _, __)
|
||||
|
||||
#define OC_DATA_CONSTR(Constructor, _, __) \
|
||||
OC_BLOB_CONSTR (OC_DATA, __(Constructor), sizeof ((UINT8[]) Constructor), _, __)
|
||||
|
||||
#define OC_ASSOC_FIELDS(_, __) \
|
||||
OC_MAP (OC_STRING, OC_DATA, _, __)
|
||||
OC_DECLARE (OC_ASSOC)
|
||||
|
||||
#endif // OC_TEMPLATE_LIB_H
|
||||
30
Include/Library/OcTimerLib.h
Executable file
30
Include/Library/OcTimerLib.h
Executable file
@ -0,0 +1,30 @@
|
||||
/** @file
|
||||
Copyright (C) 2016, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_TIMER_LIB_H
|
||||
#define OC_TIMER_LIB_H
|
||||
|
||||
#include <Library/TimerLib.h>
|
||||
|
||||
/**
|
||||
Calculate the TSC frequency
|
||||
|
||||
@retval The calculated TSC frequency.
|
||||
**/
|
||||
UINT64
|
||||
RecalculateTSC (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif // OC_TIMER_LIB_H
|
||||
34
Include/Library/OcUnicodeCollationEngLib.h
Normal file
34
Include/Library/OcUnicodeCollationEngLib.h
Normal file
@ -0,0 +1,34 @@
|
||||
/** @file
|
||||
Copyright (c) 2006 - 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.
|
||||
**/
|
||||
|
||||
#ifndef OC_UNICODE_COLLATION_ENG_LIB_H
|
||||
#define OC_UNICODE_COLLATION_ENG_LIB_H
|
||||
|
||||
#include <Protocol/UnicodeCollation.h>
|
||||
|
||||
/**
|
||||
The user Entry Point for English module.
|
||||
|
||||
This function initializes unicode character mapping and then installs Unicode
|
||||
Collation & Unicode Collation 2 Protocols based on the feature flags.
|
||||
|
||||
@param[in] Reinstall Replace any installed protocol.
|
||||
|
||||
@returns Installed protocol.
|
||||
@retval NULL There was an error installing the protocol.
|
||||
**/
|
||||
EFI_UNICODE_COLLATION_PROTOCOL *
|
||||
OcUnicodeCollationEngInstallProtocol (
|
||||
IN BOOLEAN Reinstall
|
||||
);
|
||||
|
||||
#endif // OC_UNICODE_COLLATION_ENG_LIB_H
|
||||
113
Include/Library/OcVirtualFsLib.h
Normal file
113
Include/Library/OcVirtualFsLib.h
Normal file
@ -0,0 +1,113 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_VIRTUAL_FS_LIB_H
|
||||
#define OC_VIRTUAL_FS_LIB_H
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
|
||||
/**
|
||||
Creates read-only EFI_FILE_PROTOCOL instance over a buffer allocated
|
||||
from pool. On success FileName and FileData ownership is transferred
|
||||
to the resulting EFI_FILE_PROTOCOL, which frees them with FreePool
|
||||
upon closing EFI_FILE_PROTOCOL.
|
||||
|
||||
Resulting EFI_FILE_PROTOCOL has 2nd revision, but may be downgraded
|
||||
to 1st by updating the corresponding field.
|
||||
|
||||
@param[in] FileName Pointer to the file's name.
|
||||
@param[in] FileBuffer Pointer to the file's data.
|
||||
@param[in] FileSize File size of FileData.
|
||||
@param[in] ModificationTime File modification date, optional.
|
||||
@param[in, out] File Resulting file protocol.
|
||||
|
||||
@return EFI_SUCCESS if instance was successfully created.
|
||||
**/
|
||||
EFI_STATUS
|
||||
CreateVirtualFile (
|
||||
IN CHAR16 *FileName,
|
||||
IN VOID *FileBuffer,
|
||||
IN UINT64 FileSize,
|
||||
IN EFI_TIME *ModificationTime OPTIONAL,
|
||||
IN OUT EFI_FILE_PROTOCOL **File
|
||||
);
|
||||
|
||||
/**
|
||||
Creates virtual file system instance around any file.
|
||||
CreateRealFile or CreateVirtualFile must be called from
|
||||
any registered OpenCallback.
|
||||
|
||||
@param[in] OriginalFile Pointer to the original file.
|
||||
@param[in] OpenCallback File open callback.
|
||||
@param[in] CloseOnFailure Close the original file on failure.
|
||||
@param[in, out] File Resulting file protocol.
|
||||
|
||||
@return EFI_SUCCESS if instance was successfully created.
|
||||
@return EFI_SIMPLE_FILE_SYSTEM Open-compatible error return code.
|
||||
**/
|
||||
EFI_STATUS
|
||||
CreateRealFile (
|
||||
IN EFI_FILE_PROTOCOL *OriginalFile OPTIONAL,
|
||||
IN EFI_FILE_OPEN OpenCallback OPTIONAL,
|
||||
IN BOOLEAN CloseOnFailure,
|
||||
IN OUT EFI_FILE_PROTOCOL **File
|
||||
);
|
||||
|
||||
/**
|
||||
Create virtual file system by wrapping OriginalFileSystem
|
||||
into NewFileSystem with specified callback. Cacheable.
|
||||
|
||||
@param[in] OriginalFileSystem Source file system.
|
||||
@param[in] OpenCallback File open callback.
|
||||
@param[in, out] NewFileSystem Wrapped file system.
|
||||
|
||||
@return EFI_SUCCESS on successful wrapping.
|
||||
**/
|
||||
EFI_STATUS
|
||||
CreateVirtualFs (
|
||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *OriginalFileSystem,
|
||||
IN EFI_FILE_OPEN OpenCallback,
|
||||
IN OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **NewFileSystem
|
||||
);
|
||||
|
||||
/**
|
||||
Enables virtual file system access for given BootServices
|
||||
with callback on file open.
|
||||
|
||||
@param[in, out] BootServices Hooked EFI_BOOT_SERVICES.
|
||||
@param[in] OpenCallback File open callback.
|
||||
|
||||
@return EFI_SUCCESS on successful hooking.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EnableVirtualFs (
|
||||
IN OUT EFI_BOOT_SERVICES *BootServices,
|
||||
IN EFI_FILE_OPEN OpenCallback
|
||||
);
|
||||
|
||||
/**
|
||||
Enables virtual file system access for given BootServices.
|
||||
|
||||
@param[in, out] BootServices Hooked EFI_BOOT_SERVICES.
|
||||
|
||||
@return EFI_SUCCESS on successful unhooking.
|
||||
**/
|
||||
EFI_STATUS
|
||||
DisableVirtualFs (
|
||||
IN OUT EFI_BOOT_SERVICES *BootServices
|
||||
);
|
||||
|
||||
#endif // OC_VIRTUAL_FS_LIB_H
|
||||
388
Include/Library/OcXmlLib.h
Executable file
388
Include/Library/OcXmlLib.h
Executable file
@ -0,0 +1,388 @@
|
||||
/** @file
|
||||
|
||||
OcXmlLib
|
||||
|
||||
Copyright (c) 2018, vit9696
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
**/
|
||||
|
||||
//
|
||||
// Copyright (c) 2012 ooxi/xml.c
|
||||
// https://github.com/ooxi/xml.c
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the
|
||||
// use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software in a
|
||||
// product, an acknowledgment in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#ifndef OC_XML_LIB_H
|
||||
#define OC_XML_LIB_H
|
||||
|
||||
#include <Library/OcGuardLib.h>
|
||||
|
||||
//
|
||||
// Maximum nest level.
|
||||
// XML_PARSER_NEST_LEVEL is required to fit into INT32.
|
||||
//
|
||||
#ifndef XML_PARSER_NEST_LEVEL
|
||||
#define XML_PARSER_NEST_LEVEL 32ULL
|
||||
#endif
|
||||
|
||||
//
|
||||
// Maximum child node count
|
||||
// XML_PARSER_NODE_COUNT*2 is required to fit into INT32.
|
||||
//
|
||||
#ifndef XML_PARSER_NODE_COUNT
|
||||
#define XML_PARSER_NODE_COUNT 32768ULL
|
||||
#endif
|
||||
|
||||
//
|
||||
// Maximum reference count.
|
||||
// XML_PARSER_MAX_REFERENCE_COUNT*2 is required to fit into INT32.
|
||||
//
|
||||
#ifndef XML_PARSER_MAX_REFERENCE_COUNT
|
||||
#define XML_PARSER_MAX_REFERENCE_COUNT (32ULL*1024)
|
||||
#endif
|
||||
|
||||
//
|
||||
// Maximum input data size, currently 32 MB.
|
||||
// XML_PARSER_MAX_SIZE is required to fit into INT32.
|
||||
//
|
||||
#ifndef XML_PARSER_MAX_SIZE
|
||||
#define XML_PARSER_MAX_SIZE (32ULL*1024*1024)
|
||||
#endif
|
||||
|
||||
//
|
||||
// Debug controls
|
||||
//
|
||||
//#define XML_PARSER_VERBOSE
|
||||
//#define XML_PRINT_ERRORS
|
||||
|
||||
//
|
||||
// Plist node types.
|
||||
//
|
||||
typedef enum PLIST_NODE_TYPE_ {
|
||||
PLIST_NODE_TYPE_ANY,
|
||||
PLIST_NODE_TYPE_ARRAY,
|
||||
PLIST_NODE_TYPE_DICT,
|
||||
PLIST_NODE_TYPE_KEY,
|
||||
PLIST_NODE_TYPE_STRING,
|
||||
PLIST_NODE_TYPE_DATA,
|
||||
PLIST_NODE_TYPE_DATE,
|
||||
PLIST_NODE_TYPE_TRUE,
|
||||
PLIST_NODE_TYPE_FALSE,
|
||||
PLIST_NODE_TYPE_REAL,
|
||||
PLIST_NODE_TYPE_INTEGER,
|
||||
PLIST_NODE_TYPE_MAX
|
||||
} PLIST_NODE_TYPE;
|
||||
|
||||
//
|
||||
// Opaque structure holding the parsed xml document.
|
||||
//
|
||||
struct XML_DOCUMENT_;
|
||||
struct XML_NODE_;
|
||||
typedef struct XML_DOCUMENT_ XML_DOCUMENT;
|
||||
typedef struct XML_NODE_ XML_NODE;
|
||||
|
||||
|
||||
//
|
||||
// Tries to parse the XML fragment in buffer
|
||||
// References in the document to allow deduplicated node reading:
|
||||
// <integer ID="0" size="64">0x0</integer>
|
||||
// <integer IDREF="0" size="64"/>
|
||||
//
|
||||
// @param Buffer Chunk to parse
|
||||
// @param Length Size of the buffer
|
||||
// @param WithRef Enable reference lookup support
|
||||
//
|
||||
// @warning `Buffer` will be referenced by the document, you may not free it
|
||||
// until you free the XML_DOCUMENT
|
||||
// @warning You have to call XmlDocumentFree after you finished using the
|
||||
// document
|
||||
// @warning `Buffer` contents are permanently modified during parsing
|
||||
//
|
||||
// @return The parsed xml fragment iff parsing was successful, 0 otherwise
|
||||
//
|
||||
XML_DOCUMENT *
|
||||
XmlDocumentParse (
|
||||
CHAR8 *Buffer,
|
||||
UINT32 Length,
|
||||
BOOLEAN WithRefs
|
||||
);
|
||||
|
||||
//
|
||||
// Exports parsed document into the buffer.
|
||||
//
|
||||
// @param Document XML_DOCUMENT to export
|
||||
// @param Length Resulting length of the buffer without trailing \0 (optional)
|
||||
// @param Skip N root levels before exporting, normally 0.
|
||||
//
|
||||
// @return Exported buffer allocated from pool or NULL.
|
||||
//
|
||||
CHAR8 *
|
||||
XmlDocumentExport (
|
||||
XML_DOCUMENT *Document,
|
||||
UINT32 *Length,
|
||||
UINT32 Skip
|
||||
);
|
||||
|
||||
//
|
||||
// Frees all resources associated with the document. All XML_NODE
|
||||
// references obtained through the document will be invalidated.
|
||||
//
|
||||
// @param Document XML_DOCUMENT to free
|
||||
//
|
||||
VOID
|
||||
XmlDocumentFree (
|
||||
XML_DOCUMENT *Document
|
||||
);
|
||||
|
||||
//
|
||||
// @return XML_NODE representing the document root.
|
||||
//
|
||||
XML_NODE *
|
||||
XmlDocumentRoot (
|
||||
XML_DOCUMENT *Document
|
||||
);
|
||||
|
||||
//
|
||||
// @return The XML_NODE's tag name.
|
||||
//
|
||||
CONST CHAR8 *
|
||||
XmlNodeName (
|
||||
XML_NODE *Node
|
||||
);
|
||||
|
||||
//
|
||||
// @return The XML_NODE's string content (if available, otherwise NULL).
|
||||
//
|
||||
CONST CHAR8 *
|
||||
XmlNodeContent (
|
||||
XML_NODE *Node
|
||||
);
|
||||
|
||||
//
|
||||
// @return Number of child nodes.
|
||||
//
|
||||
UINT32
|
||||
XmlNodeChildren (
|
||||
XML_NODE *Node
|
||||
);
|
||||
|
||||
//
|
||||
// @return The n-th child, behaviour is undefined if out of range.
|
||||
//
|
||||
XML_NODE *
|
||||
XmlNodeChild (
|
||||
XML_NODE *Node,
|
||||
UINT32 Child
|
||||
);
|
||||
|
||||
//
|
||||
// @return The node described by the path or NULL if child cannot be found.
|
||||
// @warning Each element on the way must be unique.
|
||||
// @warning Last argument must be NULL.
|
||||
//
|
||||
XML_NODE *
|
||||
EFIAPI
|
||||
XmlEasyChild (
|
||||
XML_NODE *Node,
|
||||
CONST CHAR8 *Child,
|
||||
...
|
||||
);
|
||||
|
||||
//
|
||||
// Append new node to current node.
|
||||
//
|
||||
// @param Node Current node.
|
||||
// @param Name Name of the new node.
|
||||
// @param Attributes Attributes of the new node (optional).
|
||||
// @param Content New node content (optional).
|
||||
//
|
||||
// @return Newly created node or NULL.
|
||||
//
|
||||
// @warning Name, Attributes, and Content must stay valid till XmlDocumentFree.
|
||||
//
|
||||
XML_NODE *
|
||||
XmlNodeAppend (
|
||||
XML_NODE *Node,
|
||||
CONST CHAR8 *Name,
|
||||
CONST CHAR8 *Attributes,
|
||||
CONST CHAR8 *Content
|
||||
);
|
||||
|
||||
//
|
||||
// Prepend new node to current node.
|
||||
// Otherwise equivalent to XmlNodeAppend.
|
||||
//
|
||||
XML_NODE *
|
||||
XmlNodePrepend (
|
||||
XML_NODE *Node,
|
||||
CONST CHAR8 *Name,
|
||||
CONST CHAR8 *Attributes,
|
||||
CONST CHAR8 *Content
|
||||
);
|
||||
|
||||
//
|
||||
// @return XML_NODE representing plist root or NULL.
|
||||
// @warning Only a subset of plist is supported.
|
||||
// @warning No validation of plist format is performed.
|
||||
//
|
||||
XML_NODE *
|
||||
PlistDocumentRoot (
|
||||
XML_DOCUMENT *Document
|
||||
);
|
||||
|
||||
//
|
||||
// Performs basic type casting (up to PLIST_NODE_TYPE_MAX).
|
||||
// Guarantees that node represents passed type.
|
||||
// Guarantees that arrays and dicts have valid amount of children, while others have 0.
|
||||
// Guarantees that keys have names and integers have values.
|
||||
//
|
||||
// @return Node if it is not NULL and represents passed Type or NULL.
|
||||
// @warning It is not guaranteed that Node has valid data for data or integer types.
|
||||
//
|
||||
XML_NODE *
|
||||
PlistNodeCast (
|
||||
XML_NODE *Node,
|
||||
PLIST_NODE_TYPE Type
|
||||
);
|
||||
|
||||
//
|
||||
// @return Number of plist dictionary entries.
|
||||
//
|
||||
UINT32
|
||||
PlistDictChildren (
|
||||
XML_NODE *Node
|
||||
);
|
||||
|
||||
//
|
||||
// @return The n-th dictionary key, behaviour is undefined if out of range.
|
||||
//
|
||||
XML_NODE *
|
||||
PlistDictChild (
|
||||
XML_NODE *Node,
|
||||
UINT32 Child,
|
||||
XML_NODE **Value OPTIONAL
|
||||
);
|
||||
|
||||
//
|
||||
// @return key value for valid type or NULL.
|
||||
//
|
||||
CONST CHAR8 *
|
||||
PlistKeyValue (
|
||||
XML_NODE *Node
|
||||
);
|
||||
|
||||
//
|
||||
// @return string value for valid type or empty string ("").
|
||||
//
|
||||
BOOLEAN
|
||||
PlistStringValue (
|
||||
XML_NODE *Node,
|
||||
CHAR8 *Value,
|
||||
UINT32 *Size
|
||||
);
|
||||
|
||||
//
|
||||
// Decodes data content for valid type or sets *Size to 0.
|
||||
//
|
||||
// @param Buffer output buffer.
|
||||
// @param Size size of buffer.
|
||||
//
|
||||
BOOLEAN
|
||||
PlistDataValue (
|
||||
XML_NODE *Node,
|
||||
UINT8 *Buffer,
|
||||
UINT32 *Size
|
||||
);
|
||||
|
||||
//
|
||||
// @return boolean value for valid type or FALSE.
|
||||
//
|
||||
BOOLEAN
|
||||
PlistBooleanValue (
|
||||
XML_NODE *Node,
|
||||
BOOLEAN *Value
|
||||
);
|
||||
|
||||
//
|
||||
// @return integral value for valid type or 0.
|
||||
//
|
||||
BOOLEAN
|
||||
PlistIntegerValue (
|
||||
XML_NODE *Node,
|
||||
VOID *Value,
|
||||
UINT32 Size,
|
||||
BOOLEAN Hex
|
||||
);
|
||||
|
||||
//
|
||||
// Decodes data content for valid type or sets *Size to 0.
|
||||
// Valid type for MetaData is DATA itself, STRING, INTEGER,
|
||||
// or BOOLEAN (as 1 byte with 1 or 0 value).
|
||||
//
|
||||
// @param Buffer output buffer.
|
||||
// @param Size size of buffer.
|
||||
// @warn Integer must fit 32-bit UNSIGNED.
|
||||
// @warn Buffer must be at least 1 byte long.
|
||||
//
|
||||
BOOLEAN
|
||||
PlistMetaDataValue (
|
||||
XML_NODE *Node,
|
||||
VOID *Buffer,
|
||||
UINT32 *Size
|
||||
);
|
||||
|
||||
//
|
||||
// Estimates string content size.
|
||||
//
|
||||
BOOLEAN
|
||||
PlistStringSize (
|
||||
XML_NODE *Node,
|
||||
UINT32 *Size
|
||||
);
|
||||
|
||||
//
|
||||
// Estimates data content size.
|
||||
//
|
||||
BOOLEAN
|
||||
PlistDataSize (
|
||||
XML_NODE *Node,
|
||||
UINT32 *Size
|
||||
);
|
||||
|
||||
//
|
||||
// Estimates meta data content size.
|
||||
//
|
||||
BOOLEAN
|
||||
PlistMetaDataSize (
|
||||
XML_NODE *Node,
|
||||
UINT32 *Size
|
||||
);
|
||||
|
||||
#endif // OC_XML_LIB_H
|
||||
221
Include/ProcessorInfo.h
Executable file
221
Include/ProcessorInfo.h
Executable file
@ -0,0 +1,221 @@
|
||||
/** @file
|
||||
Copyright (C) 2016 - 2018, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_PROCESSOR_INFO_H
|
||||
#define OC_PROCESSOR_INFO_H
|
||||
|
||||
// SandyBridge/IvyBridge bus clock is fixed at 100MHz
|
||||
|
||||
#define BRIDGE_BCLK 100
|
||||
|
||||
#define BASE_NHM_CLOCK_SOURCE 133333333ULL
|
||||
|
||||
//
|
||||
// Skylake bus clock is fixed at 100MHz
|
||||
// This constant is also known as BASE_ART_CLOCK_SOURCE in XNU
|
||||
//
|
||||
#define CLIENT_ART_CLOCK_SOURCE 24000000ULL
|
||||
#define SERVER_ART_CLOCK_SOURCE 25000000ULL
|
||||
#define ATOM_ART_CLOCK_SOURCE 19200000ULL
|
||||
|
||||
#define DEFAULT_ART_CLOCK_SOURCE CLIENT_ART_CLOCK_SOURCE
|
||||
|
||||
#define MSR_PIC_MSG_CONTROL 0x2E
|
||||
#define MSR_CORE_THREAD_COUNT 0x35
|
||||
|
||||
#define EFI_PLATFORM_INFORMATION 0x000000CE
|
||||
#define N_EFI_PLATFORM_INFO_MIN_RATIO 40
|
||||
#define B_EFI_PLATFORM_INFO_RATIO_MASK 0xFF
|
||||
#define N_EFI_PLATFORM_INFO_MAX_RATIO 8
|
||||
#define B_EFI_PLATFORM_INFO_TDC_TDP_LIMIT (1 << 29)
|
||||
#define N_EFI_PLATFORM_INFO_RATIO_LIMIT 28
|
||||
#define B_EFI_PLATFORM_INFO_RATIO_LIMIT (1 << 28)
|
||||
#define B_EFI_PLATFORM_INFO_SMM_SAVE_CONTROL (1 << 16)
|
||||
#define N_EFI_PLATFORM_INFO_PROG_TCC_ACTIVATION_OFFSET 30
|
||||
#define B_EFI_PLATFORM_INFO_PROG_TCC_ACTIVATION_OFFSET (1 << 30)
|
||||
|
||||
//#define PLATFORM_INFO_SET_TDP
|
||||
|
||||
#define MSR_PMG_IO_CAPTURE_BASE 0xE4
|
||||
#define MSR_IA32_EXT_CONFIG 0xEE
|
||||
#define MSR_FEATURE_CONFIG 0x13C
|
||||
#define MSR_FLEX_RATIO 0x194
|
||||
#define FLEX_RATIO_LOCK (1U << 20U)
|
||||
#define FLEX_RATIO_EN (1U << 16U)
|
||||
#define MSR_IA32_PERF_CONTROL 0x199
|
||||
#define MSR_THERM2_CTL 0x19D
|
||||
|
||||
#define MSR_IA32_MISC_ENABLES 0x1A0
|
||||
#define TURBO_DISABLE_MASK ((UINT64)1 << 38)
|
||||
#define TURBO_MODE_DISABLE_BIT 38
|
||||
|
||||
#define MSR_TEMPERATURE_TARGET 0x1A2
|
||||
#define MSR_MISC_PWR_MGMT 0x1AA
|
||||
#define MISC_PWR_MGMT_EIST_HW_DIS (1 << 0)
|
||||
#define MISC_PWR_MGMT_LOCK (1 << 13)
|
||||
#define MAX_RATIO_LIMIT_8C_OFFSET 56
|
||||
#define MAX_RATIO_LIMIT_7C_OFFSET 48
|
||||
#define MAX_RATIO_LIMIT_6C_OFFSET 40
|
||||
#define MAX_RATIO_LIMIT_5C_OFFSET 32
|
||||
#define MAX_RATIO_LIMIT_4C_OFFSET 24
|
||||
#define MAX_RATIO_LIMIT_3C_OFFSET 16
|
||||
#define MAX_RATIO_LIMIT_2C_OFFSET 8
|
||||
#define MAX_RATIO_LIMIT_1C_OFFSET 0
|
||||
#define MAX_RATIO_LIMIT_MASK 0xff
|
||||
#define MSR_IA32_ENERGY_PERFORMANCE_BIAS 0x1B0
|
||||
#define ENERGY_POLICY_PERFORMANCE 0
|
||||
#define ENERGY_POLICY_NORMAL 6
|
||||
#define ENERGY_POLICY_POWERSAVE 15
|
||||
#define MSR_POWER_CTL 0x1FC
|
||||
#define MSR_LT_LOCK_MEMORY 0x2E7
|
||||
#define MSR_IA32_CR_PAT 0x277
|
||||
|
||||
// Sandy Bridge & JakeTown specific 'Running Average Power Limit' MSR's.
|
||||
#define MSR_PP0_CURRENT_CONFIG 0x601
|
||||
#define PP0_CURRENT_LIMIT (112 << 3) ///< 112 A
|
||||
#define MSR_PP1_CURRENT_CONFIG 0x602
|
||||
#define PP1_CURRENT_LIMIT (35 << 3) ///< 35 A
|
||||
#define MSR_PKG_POWER_SKU_UNIT 0x606
|
||||
|
||||
#define MSR_PKGC3_IRTL 0x60A
|
||||
#define MSR_PKGC6_IRTL 0x60B
|
||||
#define MSR_PKGC7_IRTL 0x60C
|
||||
#define IRTL_VALID (1 << 15)
|
||||
#define IRTL_1_NS (0 << 10)
|
||||
#define IRTL_32_NS (1 << 10)
|
||||
#define IRTL_1024_NS (2 << 10)
|
||||
#define IRTL_32768_NS (3 << 10)
|
||||
#define IRTL_1048576_NS (4 << 10)
|
||||
#define IRTL_33554432_NS (5 << 10)
|
||||
#define IRTL_RESPONSE_MASK (0x3ff)
|
||||
|
||||
// long duration in low dword, short duration in high dword
|
||||
#define MSR_PKG_POWER_LIMIT 0x610
|
||||
#define PKG_POWER_LIMIT_MASK 0x7fff
|
||||
#define PKG_POWER_LIMIT_EN (1 << 15)
|
||||
#define PKG_POWER_LIMIT_CLAMP (1 << 16)
|
||||
#define PKG_POWER_LIMIT_TIME_SHIFT 17
|
||||
#define PKG_POWER_LIMIT_TIME_MASK 0x7f
|
||||
|
||||
#define MSR_PKG_ENERGY_STATUS 0x611
|
||||
#define MSR_PKG_PERF_STATUS 0x613
|
||||
#define MSR_PKG_POWER_SKU 0x614
|
||||
|
||||
// Sandy Bridge IA (Core) domain MSR's.
|
||||
#define MSR_PP0_POWER_LIMIT 0x638
|
||||
#define MSR_PP0_ENERGY_STATUS 0x639
|
||||
#define MSR_PP0_POLICY 0x63A
|
||||
#define MSR_PP0_PERF_STATUS 0x63B
|
||||
|
||||
// Sandy Bridge Uncore (IGPU) domain MSR's (Not on JakeTown).
|
||||
#define MSR_PP1_POWER_LIMIT 0x640
|
||||
#define MSR_PP1_ENERGY_STATUS 0x641
|
||||
#define MSR_PP1_POLICY 0x642
|
||||
|
||||
// JakeTown only Memory MSR's.
|
||||
#define MSR_DRAM_POWER_LIMIT 0x618
|
||||
#define MSR_DRAM_ENERGY_STATUS 0x619
|
||||
#define MSR_DRAM_PERF_STATUS 0x61B
|
||||
#define MSR_DRAM_POWER_INFO 0x61C
|
||||
|
||||
/// x86 Page Address Translation
|
||||
enum {
|
||||
PageAddressTranslationUncached = 0,
|
||||
PageAddressTranslationWriteCombining = 1,
|
||||
PageAddressTranslationWriteThrough = 4,
|
||||
PageAddressTranslationWriteProtected = 5,
|
||||
PageAddressTranslationWriteBack = 6,
|
||||
/// Uncached, but can be overriden by MTRR
|
||||
PageAddressTranslationOverridableUncached = 7,
|
||||
};
|
||||
|
||||
#define K8_FIDVID_STATUS 0xC0010042
|
||||
#define K10_COFVID_STATUS 0xC0010071
|
||||
#define K10_PSTATE_STATUS 0xC0010064
|
||||
|
||||
#define CPU_MODEL_DOTHAN 0x0D ///< Dothan
|
||||
#define CPU_MODEL_YONAH 0x0E ///< Sossaman, Yonah
|
||||
#define CPU_MODEL_MEROM 0x0F ///< Allendale, Conroe, Kentsfield, Woodcrest, Clovertown, Tigerton, Merom
|
||||
#define CPU_MODEL_PENRYN 0x17 ///< Wolfdale, Yorkfield, Harpertown, Penryn
|
||||
#define CPU_MODEL_NEHALEM 0x1A ///< Bloomfield. Nehalem-EP, Nehalem-WS, Gainestown
|
||||
#define CPU_MODEL_ATOM 0x1C ///< Atom
|
||||
#define CPU_MODEL_FIELDS 0x1E ///< Lynnfield, Clarksfield, Jasper Forest
|
||||
#define CPU_MODEL_DALES 0x1F ///< Havendale, Auburndale
|
||||
#define CPU_MODEL_NEHALEM_EX 0x2E ///< Beckton
|
||||
#define CPU_MODEL_DALES_32NM 0x25 ///< Clarkdale, Arrandale
|
||||
#define CPU_MODEL_WESTMERE 0x2C ///< Gulftown, Westmere-EP, Westmere-WS
|
||||
#define CPU_MODEL_WESTMERE_EX 0x2F
|
||||
#define CPU_MODEL_SANDYBRIDGE 0x2A ///< Sandy Bridge
|
||||
#define CPU_MODEL_JAKETOWN 0x2D ///< Sandy Bridge Xeon E5, Core i7 Extreme
|
||||
#define CPU_MODEL_IVYBRIDGE 0x3A ///< Ivy Bridge
|
||||
#define CPU_MODEL_IVYBRIDGE_EP 0x3E
|
||||
#define CPU_MODEL_CRYSTALWELL 0x46
|
||||
#define CPU_MODEL_HASWELL 0x3C
|
||||
#define CPU_MODEL_HASWELL_EP 0x3F ///< Haswell MB
|
||||
#define CPU_MODEL_HASWELL_ULT 0x45 ///< Haswell ULT
|
||||
#define CPU_MODEL_BROADWELL 0x3D ///< Broadwell
|
||||
#define CPU_MODEL_BROADWELL_EP 0x4F ///< Broadwell_EP
|
||||
#define CPU_MODEL_BROADWELL_ULX 0x3D
|
||||
#define CPU_MODEL_BROADWELL_ULT 0x3D
|
||||
#define CPU_MODEL_BRYSTALWELL 0x47
|
||||
#define CPU_MODEL_AIRMONT 0x4C ///< CherryTrail / Braswell
|
||||
#define CPU_MODEL_AVOTON 0x4D ///< Avaton/Rangely
|
||||
#define CPU_MODEL_SKYLAKE 0x4E ///< Skylake-S
|
||||
#define CPU_MODEL_SKYLAKE_ULT 0x4E
|
||||
#define CPU_MODEL_SKYLAKE_ULX 0x4E
|
||||
#define CPU_MODEL_SKYLAKE_DT 0x5E
|
||||
#define CPU_MODEL_SKYLAKE_W 0x55
|
||||
#define CPU_MODEL_GOLDMONT 0x5C ///< Apollo Lake
|
||||
#define CPU_MODEL_DENVERTON 0x5F ///< Goldmont Microserver
|
||||
#define CPU_MODEL_CANNONLAKE 0x66
|
||||
#define CPU_MODEL_XEON_MILL 0x85 ///< Knights Mill
|
||||
#define CPU_MODEL_KABYLAKE 0x8E ///< Kabylake Dektop
|
||||
#define CPU_MODEL_KABYLAKE_ULT 0x8E
|
||||
#define CPU_MODEL_KABYLAKE_ULX 0x8E
|
||||
#define CPU_MODEL_KABYLAKE_DT 0x9E
|
||||
#define CPU_MODEL_COFFEELAKE 0x9E
|
||||
#define CPU_MODEL_COFFEELAKE_ULT 0x9E
|
||||
#define CPU_MODEL_COFFEELAKE_ULX 0x9E
|
||||
#define CPU_MODEL_COFFEELAKE_DT 0x9E
|
||||
|
||||
#define CPU_SOCKET_UNKNOWN 0x02
|
||||
#define CPU_SOCKET_PGA478 0x0F
|
||||
#define CPU_SOCKET_LGA771 0x14
|
||||
#define CPU_SOCKET_LGA775 0x15
|
||||
#define CPU_SOCKET_LGA1156 0x1D
|
||||
#define CPU_SOCKET_LGA1366 0x19
|
||||
|
||||
#define AMD_CPU_FAMILY 0xF
|
||||
#define AMD_CPU_EXT_FAMILY_15H 0x6
|
||||
#define AMD_CPU_EXT_FAMILY_16H 0x7
|
||||
#define AMD_CPU_EXT_FAMILY_17H 0x8
|
||||
|
||||
// CPU_P_STATE_COORDINATION
|
||||
/// P-State Coordination
|
||||
typedef enum {
|
||||
/// The OS Power Manager is responsible for coordinating the P-state among logical
|
||||
/// processors with dependencies and must initiate the transition on all of those Logical Processors.
|
||||
CpuPStateCoordinationSoftwareAll = 0xFC,
|
||||
|
||||
/// The OS Power Manager is responsible for coordinating the P-state among logical
|
||||
/// processors with dependencies and may initiate the transition on any of those Logical Processors.
|
||||
CpuPStateCoordinationSoftwareAny = 0xFD,
|
||||
|
||||
/// The processor hardware is responsible for coordinating the P-state among logical
|
||||
/// processors dependencies. The OS is responsible for keeping the P-state request up to date on all
|
||||
/// logical processors.
|
||||
CpuPStateCoordinationHardwareAll = 0xFE
|
||||
} CPU_P_STATE_COORDINATION;
|
||||
|
||||
#endif // OC_PROCESSOR_INFO_H
|
||||
59
Include/Protocol/AmiKeycode.h
Normal file
59
Include/Protocol/AmiKeycode.h
Normal file
@ -0,0 +1,59 @@
|
||||
/** @file
|
||||
Header file for AMI EfiKeycode protocol definitions.
|
||||
|
||||
Copyright (c) 2016, 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.
|
||||
|
||||
**/
|
||||
#ifndef AMI_KEYCODE_H
|
||||
#define AMI_KEYCODE_H
|
||||
|
||||
// 0ADFB62D-FF74-484C-8944-F85C4BEA87A8
|
||||
#define AMI_EFIKEYCODE_PROTOCOL_GUID \
|
||||
{ 0x0ADFB62D, 0xFF74, 0x484C, { 0x89, 0x44, 0xF8, 0x5C, 0x4B, 0xEA, 0x87, 0xA8 } }
|
||||
|
||||
extern EFI_GUID gAmiEfiKeycodeProtocolGuid;
|
||||
|
||||
typedef struct _AMI_EFIKEYCODE_PROTOCOL AMI_EFIKEYCODE_PROTOCOL;
|
||||
|
||||
#ifndef KEY_STATE_EXPOSED
|
||||
#define KEY_STATE_EXPOSED 0x40
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
EFI_INPUT_KEY Key;
|
||||
EFI_KEY_STATE KeyState;
|
||||
EFI_KEY EfiKey;
|
||||
UINT8 EfiKeyIsValid;
|
||||
UINT8 PS2ScanCode;
|
||||
UINT8 PS2ScanCodeIsValid;
|
||||
} AMI_EFI_KEY_DATA;
|
||||
|
||||
typedef EFI_STATUS (EFIAPI *AMI_READ_EFI_KEY) (
|
||||
IN AMI_EFIKEYCODE_PROTOCOL *This,
|
||||
OUT AMI_EFI_KEY_DATA *KeyData
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *AMI_RESET_EX) (
|
||||
IN AMI_EFIKEYCODE_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
);
|
||||
|
||||
struct _AMI_EFIKEYCODE_PROTOCOL {
|
||||
AMI_RESET_EX Reset;
|
||||
AMI_READ_EFI_KEY ReadEfikey;
|
||||
EFI_EVENT WaitForKeyEx;
|
||||
EFI_SET_STATE SetState;
|
||||
EFI_REGISTER_KEYSTROKE_NOTIFY RegisterKeyNotify;
|
||||
EFI_UNREGISTER_KEYSTROKE_NOTIFY UnregisterKeyNotify;
|
||||
};
|
||||
|
||||
#endif // AMI_KEYCODE_H
|
||||
82
Include/Protocol/AmiPointer.h
Normal file
82
Include/Protocol/AmiPointer.h
Normal file
@ -0,0 +1,82 @@
|
||||
/** @file
|
||||
Header file for AMI EfiPointer protocol definitions.
|
||||
|
||||
Copyright (c) 2016, 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.
|
||||
|
||||
**/
|
||||
#ifndef AMI_POINTER_H
|
||||
#define AMI_POINTER_H
|
||||
|
||||
#include <Library/OcGuardLib.h>
|
||||
|
||||
// 15A10CE7-EAB5-43BF-9042-74432E696377
|
||||
#define AMI_EFIPOINTER_PROTOCOL_GUID \
|
||||
{ 0x15A10CE7, 0xEAB5, 0x43BF, { 0x90, 0x42, 0x74, 0x43, 0x2E, 0x69, 0x63, 0x77 } }
|
||||
|
||||
extern EFI_GUID gAmiEfiPointerProtocolGuid;
|
||||
|
||||
typedef struct _AMI_EFIPOINTER_PROTOCOL AMI_EFIPOINTER_PROTOCOL;
|
||||
|
||||
// Unless Changed == 1, no data is provided
|
||||
typedef struct {
|
||||
UINT8 Absolute;
|
||||
UINT8 One;
|
||||
UINT8 Changed;
|
||||
UINT8 Reserved;
|
||||
INT32 PositionX;
|
||||
INT32 PositionY;
|
||||
INT32 PositionZ;
|
||||
} AMI_POINTER_POSITION_STATE_DATA;
|
||||
|
||||
STATIC_ASSERT (
|
||||
sizeof (AMI_POINTER_POSITION_STATE_DATA) == 16,
|
||||
"AMI_POINTER_POSITION_STATE_DATA is expected to be 16 bytes"
|
||||
);
|
||||
|
||||
// Unless Changed == 1, no data is provided
|
||||
typedef struct {
|
||||
UINT8 Changed;
|
||||
UINT8 LeftButton;
|
||||
UINT8 MiddleButton;
|
||||
UINT8 RightButton;
|
||||
} AMI_POINTER_BUTTON_STATE_DATA;
|
||||
|
||||
STATIC_ASSERT (
|
||||
sizeof (AMI_POINTER_BUTTON_STATE_DATA) == 4,
|
||||
"AMI_POINTER_BUTTON_STATE_DATA is expected to be 4 bytes"
|
||||
);
|
||||
|
||||
typedef
|
||||
VOID
|
||||
(EFIAPI *AMI_EFIPOINTER_RESET) (
|
||||
IN AMI_EFIPOINTER_PROTOCOL *This
|
||||
);
|
||||
|
||||
typedef
|
||||
VOID
|
||||
(EFIAPI *AMI_EFIPOINTER_GET_BUTTON_STATE) (
|
||||
IN AMI_EFIPOINTER_PROTOCOL *This,
|
||||
OUT AMI_POINTER_BUTTON_STATE_DATA *State
|
||||
);
|
||||
|
||||
typedef
|
||||
VOID
|
||||
(EFIAPI *AMI_EFIPOINTER_GET_POSITION_STATE) (
|
||||
IN AMI_EFIPOINTER_PROTOCOL *This,
|
||||
OUT AMI_POINTER_POSITION_STATE_DATA *State
|
||||
);
|
||||
|
||||
struct _AMI_EFIPOINTER_PROTOCOL {
|
||||
AMI_EFIPOINTER_RESET Reset;
|
||||
AMI_EFIPOINTER_GET_POSITION_STATE GetPositionState;
|
||||
AMI_EFIPOINTER_GET_BUTTON_STATE GetButtonState;
|
||||
};
|
||||
|
||||
#endif // AMI_POINTER_H
|
||||
257
Include/Protocol/AudioIo.h
Normal file
257
Include/Protocol/AudioIo.h
Normal file
@ -0,0 +1,257 @@
|
||||
/*
|
||||
* File: AudioIo.h
|
||||
*
|
||||
* Copyright (c) 2018 John Davis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EFI_AUDIO_IO_H
|
||||
#define EFI_AUDIO_IO_H
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
/**
|
||||
Audio I/O protocol GUID.
|
||||
**/
|
||||
#define EFI_AUDIO_IO_PROTOCOL_GUID \
|
||||
{ 0xF05B559C, 0x1971, 0x4AF5, \
|
||||
{ 0xB2, 0xAE, 0xD6, 0x08, 0x08, 0xF7, 0x4F, 0x70 } }
|
||||
|
||||
typedef struct EFI_AUDIO_IO_PROTOCOL_ EFI_AUDIO_IO_PROTOCOL;
|
||||
|
||||
/**
|
||||
Port type.
|
||||
**/
|
||||
typedef enum {
|
||||
EfiAudioIoTypeOutput,
|
||||
EfiAudioIoTypeInput,
|
||||
EfiAudioIoTypeMaximum
|
||||
} EFI_AUDIO_IO_PROTOCOL_TYPE;
|
||||
|
||||
/**
|
||||
Device type.
|
||||
**/
|
||||
typedef enum {
|
||||
EfiAudioIoDeviceLine,
|
||||
EfiAudioIoDeviceSpeaker,
|
||||
EfiAudioIoDeviceHeadphones,
|
||||
EfiAudioIoDeviceSpdif,
|
||||
EfiAudioIoDeviceMic,
|
||||
EfiAudioIoDeviceHdmi,
|
||||
EfiAudioIoDeviceOther,
|
||||
EfiAudioIoDeviceMaximum
|
||||
} EFI_AUDIO_IO_PROTOCOL_DEVICE;
|
||||
|
||||
/**
|
||||
Port location.
|
||||
**/
|
||||
typedef enum {
|
||||
EfiAudioIoLocationNone,
|
||||
EfiAudioIoLocationRear,
|
||||
EfiAudioIoLocationFront,
|
||||
EfiAudioIoLocationLeft,
|
||||
EfiAudioIoLocationRight,
|
||||
EfiAudioIoLocationTop,
|
||||
EfiAudioIoLocationBottom,
|
||||
EfiAudioIoLocationOther,
|
||||
EfiAudioIoLocationMaximum
|
||||
} EFI_AUDIO_IO_PROTOCOL_LOCATION;
|
||||
|
||||
/**
|
||||
Port surface.
|
||||
**/
|
||||
typedef enum {
|
||||
EfiAudioIoSurfaceExternal,
|
||||
EfiAudioIoSurfaceInternal,
|
||||
EfiAudioIoSurfaceOther,
|
||||
EfiAudioIoSurfaceMaximum
|
||||
} EFI_AUDIO_IO_PROTOCOL_SURFACE;
|
||||
|
||||
/**
|
||||
Size in bits of each sample.
|
||||
**/
|
||||
typedef enum {
|
||||
EfiAudioIoBits8 = BIT0,
|
||||
EfiAudioIoBits16 = BIT1,
|
||||
EfiAudioIoBits20 = BIT2,
|
||||
EfiAudioIoBits24 = BIT3,
|
||||
EfiAudioIoBits32 = BIT4
|
||||
} EFI_AUDIO_IO_PROTOCOL_BITS;
|
||||
|
||||
/**
|
||||
Frequency of each sample.
|
||||
**/
|
||||
typedef enum {
|
||||
EfiAudioIoFreq8kHz = BIT0,
|
||||
EfiAudioIoFreq11kHz = BIT1,
|
||||
EfiAudioIoFreq16kHz = BIT2,
|
||||
EfiAudioIoFreq22kHz = BIT3,
|
||||
EfiAudioIoFreq32kHz = BIT4,
|
||||
EfiAudioIoFreq44kHz = BIT5,
|
||||
EfiAudioIoFreq48kHz = BIT6,
|
||||
EfiAudioIoFreq88kHz = BIT7,
|
||||
EfiAudioIoFreq96kHz = BIT8,
|
||||
EfiAudioIoFreq192kHz = BIT9
|
||||
} EFI_AUDIO_IO_PROTOCOL_FREQ;
|
||||
|
||||
/**
|
||||
Audio input/output structure.
|
||||
**/
|
||||
typedef struct {
|
||||
EFI_AUDIO_IO_PROTOCOL_TYPE Type;
|
||||
EFI_AUDIO_IO_PROTOCOL_BITS SupportedBits;
|
||||
EFI_AUDIO_IO_PROTOCOL_FREQ SupportedFreqs;
|
||||
EFI_AUDIO_IO_PROTOCOL_DEVICE Device;
|
||||
EFI_AUDIO_IO_PROTOCOL_LOCATION Location;
|
||||
EFI_AUDIO_IO_PROTOCOL_SURFACE Surface;
|
||||
} EFI_AUDIO_IO_PROTOCOL_PORT;
|
||||
|
||||
/**
|
||||
Maximum number of channels.
|
||||
**/
|
||||
#define EFI_AUDIO_IO_PROTOCOL_MAX_CHANNELS 16
|
||||
#define EFI_AUDIO_IO_PROTOCOL_MAX_VOLUME 100
|
||||
|
||||
/**
|
||||
Callback function.
|
||||
**/
|
||||
typedef
|
||||
VOID
|
||||
(EFIAPI* EFI_AUDIO_IO_CALLBACK) (
|
||||
IN EFI_AUDIO_IO_PROTOCOL *AudioIo,
|
||||
IN VOID *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Gets the collection of output ports.
|
||||
|
||||
@param[in] This A pointer to the EFI_AUDIO_IO_PROTOCOL instance.
|
||||
@param[out] OutputPorts A pointer to a buffer where the output ports will be placed.
|
||||
@param[out] OutputPortsCount The number of ports in OutputPorts.
|
||||
|
||||
@retval EFI_SUCCESS The audio data was played successfully.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_AUDIO_IO_GET_OUTPUTS) (
|
||||
IN EFI_AUDIO_IO_PROTOCOL *This,
|
||||
OUT EFI_AUDIO_IO_PROTOCOL_PORT **OutputPorts,
|
||||
OUT UINTN *OutputPortsCount
|
||||
);
|
||||
|
||||
/**
|
||||
Sets up the device to play audio data.
|
||||
|
||||
@param[in] This A pointer to the EFI_AUDIO_IO_PROTOCOL instance.
|
||||
@param[in] OutputIndex The zero-based index of the desired output.
|
||||
@param[in] Volume The volume (0-100) to use.
|
||||
@param[in] Bits The width in bits of the source data.
|
||||
@param[in] Freq The frequency of the source data.
|
||||
@param[in] Channels The number of channels the source data contains.
|
||||
|
||||
@retval EFI_SUCCESS The audio data was played successfully.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_AUDIO_IO_SETUP_PLAYBACK) (
|
||||
IN EFI_AUDIO_IO_PROTOCOL *This,
|
||||
IN UINT8 OutputIndex,
|
||||
IN UINT8 Volume,
|
||||
IN EFI_AUDIO_IO_PROTOCOL_FREQ Freq,
|
||||
IN EFI_AUDIO_IO_PROTOCOL_BITS Bits,
|
||||
IN UINT8 Channels
|
||||
);
|
||||
|
||||
/**
|
||||
Begins playback on the device and waits for playback to complete.
|
||||
|
||||
@param[in] This A pointer to the EFI_AUDIO_IO_PROTOCOL instance.
|
||||
@param[in] Data A pointer to the buffer containing the audio data to play.
|
||||
@param[in] DataLength The size, in bytes, of the data buffer specified by Data.
|
||||
@param[in] Position The position in the buffer to start at.
|
||||
|
||||
@retval EFI_SUCCESS The audio data was played successfully.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_AUDIO_IO_START_PLAYBACK) (
|
||||
IN EFI_AUDIO_IO_PROTOCOL *This,
|
||||
IN VOID *Data,
|
||||
IN UINTN DataLength,
|
||||
IN UINTN Position OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Begins playback on the device asynchronously.
|
||||
The callback if specified will be executed with TPL_NOTIFY.
|
||||
|
||||
@param[in] This A pointer to the EFI_AUDIO_IO_PROTOCOL instance.
|
||||
@param[in] Data A pointer to the buffer containing the audio data to play.
|
||||
@param[in] DataLength The size, in bytes, of the data buffer specified by Data.
|
||||
@param[in] Position The position in the buffer to start at.
|
||||
@param[in] Callback A pointer to an optional callback to be invoked when playback is complete.
|
||||
@param[in] Context A pointer to data to be passed to the callback function.
|
||||
|
||||
@retval EFI_SUCCESS The audio data was played successfully.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_AUDIO_IO_START_PLAYBACK_ASYNC) (
|
||||
IN EFI_AUDIO_IO_PROTOCOL *This,
|
||||
IN VOID *Data,
|
||||
IN UINTN DataLength,
|
||||
IN UINTN Position OPTIONAL,
|
||||
IN EFI_AUDIO_IO_CALLBACK Callback OPTIONAL,
|
||||
IN VOID *Context OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Stops playback on the device.
|
||||
Note, this will not call registered callbacks for stop audio.
|
||||
|
||||
@param[in] This A pointer to the EFI_AUDIO_IO_PROTOCOL instance.
|
||||
|
||||
@retval EFI_SUCCESS The audio data was played successfully.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_AUDIO_IO_STOP_PLAYBACK) (
|
||||
IN EFI_AUDIO_IO_PROTOCOL *This
|
||||
);
|
||||
|
||||
/**
|
||||
Protocol struct.
|
||||
**/
|
||||
struct EFI_AUDIO_IO_PROTOCOL_ {
|
||||
EFI_AUDIO_IO_GET_OUTPUTS GetOutputs;
|
||||
EFI_AUDIO_IO_SETUP_PLAYBACK SetupPlayback;
|
||||
EFI_AUDIO_IO_START_PLAYBACK StartPlayback;
|
||||
EFI_AUDIO_IO_START_PLAYBACK_ASYNC StartPlaybackAsync;
|
||||
EFI_AUDIO_IO_STOP_PLAYBACK StopPlayback;
|
||||
};
|
||||
|
||||
extern EFI_GUID gEfiAudioIoProtocolGuid;
|
||||
|
||||
#endif // EFI_AUDIO_IO_H
|
||||
243
Include/Protocol/HdaCodecInfo.h
Normal file
243
Include/Protocol/HdaCodecInfo.h
Normal file
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* File: HdaCodecInfo.h
|
||||
*
|
||||
* Copyright (c) 2018 John Davis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EFI_HDA_CODEC_INFO_H
|
||||
#define EFI_HDA_CODEC_INFO_H
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
/**
|
||||
HDA Codec Info protocol GUID.
|
||||
**/
|
||||
#define EFI_HDA_CODEC_INFO_PROTOCOL_GUID \
|
||||
{ 0x6C9CDDE1, 0xE8A5, 0x43E5, \
|
||||
{ 0xBE, 0x88, 0xDA, 0x15, 0xBC, 0x1C, 0x02, 0x50 } }
|
||||
|
||||
typedef struct EFI_HDA_CODEC_INFO_PROTOCOL_ EFI_HDA_CODEC_INFO_PROTOCOL;
|
||||
|
||||
/**
|
||||
Widget structure.
|
||||
**/
|
||||
|
||||
typedef struct {
|
||||
UINT8 NodeId;
|
||||
///
|
||||
/// General widgets.
|
||||
///
|
||||
UINT32 Capabilities;
|
||||
UINT8 DefaultUnSol;
|
||||
UINT8 DefaultEapd;
|
||||
///
|
||||
/// Connections.
|
||||
///
|
||||
UINT32 ConnectionListLength;
|
||||
UINT16 *Connections;
|
||||
///
|
||||
/// Power.
|
||||
///
|
||||
UINT32 SupportedPowerStates;
|
||||
UINT32 DefaultPowerState;
|
||||
///
|
||||
/// Amps.
|
||||
///
|
||||
UINT32 AmpInCapabilities;
|
||||
UINT32 AmpOutCapabilities;
|
||||
UINT8 *AmpInLeftDefaultGainMute;
|
||||
UINT8 *AmpInRightDefaultGainMute;
|
||||
UINT8 AmpOutLeftDefaultGainMute;
|
||||
UINT8 AmpOutRightDefaultGainMute;
|
||||
///
|
||||
/// Input/Output.
|
||||
///
|
||||
UINT32 SupportedPcmRates;
|
||||
UINT32 SupportedFormats;
|
||||
UINT16 DefaultConvFormat;
|
||||
UINT8 DefaultConvStreamChannel;
|
||||
UINT8 DefaultConvChannelCount;
|
||||
///
|
||||
/// Pin Complex.
|
||||
///
|
||||
UINT32 PinCapabilities;
|
||||
UINT8 DefaultPinControl;
|
||||
UINT32 DefaultConfiguration;
|
||||
///
|
||||
/// Volume Knob.
|
||||
///
|
||||
UINT32 VolumeCapabilities;
|
||||
UINT8 DefaultVolume;
|
||||
} HDA_WIDGET;
|
||||
|
||||
/**
|
||||
Gets the codec's name.
|
||||
|
||||
@param[in] This A pointer to the EFI_HDA_CODEC_INFO_PROTOCOL instance.
|
||||
@param[out] CodecName A pointer to the buffer to return the codec name.
|
||||
|
||||
@retval EFI_SUCCESS The codec name was retrieved.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_CODEC_INFO_GET_NAME) (
|
||||
IN EFI_HDA_CODEC_INFO_PROTOCOL *This,
|
||||
OUT CONST CHAR16 **CodecName
|
||||
);
|
||||
|
||||
/**
|
||||
Gets the codec's vendor and device ID.
|
||||
|
||||
@param[in] This A pointer to the EFI_HDA_CODEC_INFO_PROTOCOL instance.
|
||||
@param[out] VendorId The vendor and device ID of the codec.
|
||||
|
||||
@retval EFI_SUCCESS The vendor and device ID was retrieved.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_CODEC_INFO_GET_VENDOR_ID) (
|
||||
IN EFI_HDA_CODEC_INFO_PROTOCOL *This,
|
||||
OUT UINT32 *VendorId
|
||||
);
|
||||
|
||||
/**
|
||||
Gets the codec's revision ID.
|
||||
|
||||
@param[in] This A pointer to the EFI_HDA_CODEC_INFO_PROTOCOL instance.
|
||||
@param[out] RevisionId The revision ID of the codec.
|
||||
|
||||
@retval EFI_SUCCESS The revision ID was retrieved.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_CODEC_INFO_GET_REVISION_ID) (
|
||||
IN EFI_HDA_CODEC_INFO_PROTOCOL *This,
|
||||
OUT UINT32 *RevisionId
|
||||
);
|
||||
|
||||
/**
|
||||
Gets the node ID of the codec's audio function.
|
||||
|
||||
@param[in] This A pointer to the EFI_HDA_CODEC_INFO_PROTOCOL instance.
|
||||
@param[out] AudioFuncId The node ID of the codec's audio function.
|
||||
@param[out] UnsolCapable Whether or not the function supports unsolicitation.
|
||||
|
||||
@retval EFI_SUCCESS The node ID was retrieved.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_CODEC_INFO_GET_AUDIO_FUNC_ID) (
|
||||
IN EFI_HDA_CODEC_INFO_PROTOCOL *This,
|
||||
OUT UINT8 *AudioFuncId,
|
||||
OUT BOOLEAN *UnsolCapable
|
||||
);
|
||||
|
||||
/**
|
||||
Gets the codec's default supported stream rates and formats.
|
||||
|
||||
@param[in] This A pointer to the EFI_HDA_CODEC_INFO_PROTOCOL instance.
|
||||
@param[out] Rates The default supported rates.
|
||||
@param[out] Formats The default supported formats.
|
||||
|
||||
@retval EFI_SUCCESS The stream rates and formats were retrieved.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_CODEC_INFO_GET_DEFAULT_RATES_FORMATS) (
|
||||
IN EFI_HDA_CODEC_INFO_PROTOCOL *This,
|
||||
OUT UINT32 *Rates,
|
||||
OUT UINT32 *Formats
|
||||
);
|
||||
|
||||
/**
|
||||
Gets the codec's default amp capabilities.
|
||||
|
||||
@param[in] This A pointer to the EFI_HDA_CODEC_INFO_PROTOCOL instance.
|
||||
@param[out] AmpInCaps The default input amp capabilities.
|
||||
@param[out] AmpOutCaps The default output amp capabilities.
|
||||
|
||||
@retval EFI_SUCCESS The default amp capabilities were retrieved.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_CODEC_INFO_GET_DEFAULT_AMP_CAPS) (
|
||||
IN EFI_HDA_CODEC_INFO_PROTOCOL *This,
|
||||
OUT UINT32 *AmpInCaps,
|
||||
OUT UINT32 *AmpOutCaps
|
||||
);
|
||||
|
||||
/**
|
||||
Gets the codec's widgets.
|
||||
|
||||
@param[in] This A pointer to the EFI_HDA_CODEC_INFO_PROTOCOL instance.
|
||||
@param[out] Widgets A pointer to the buffer to return the requested array of widgets.
|
||||
@param[out] WidgetCount The number of widgets returned in Widgets.
|
||||
|
||||
@retval EFI_SUCCESS The widgets were retrieved.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_CODEC_INFO_GET_WIDGETS) (
|
||||
IN EFI_HDA_CODEC_INFO_PROTOCOL *This,
|
||||
OUT HDA_WIDGET **Widgets,
|
||||
OUT UINTN *WidgetCount
|
||||
);
|
||||
|
||||
/**
|
||||
Frees an array of HDA_WIDGET.
|
||||
|
||||
@param[in] Widgets A pointer to the buffer array of widgets that is to be freed.
|
||||
@param[in] WidgetCount The number of widgets in Widgets.
|
||||
|
||||
@retval EFI_SUCCESS The buffer was freed.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_CODEC_INFO_FREE_WIDGETS_BUFFER) (
|
||||
IN HDA_WIDGET *Widgets,
|
||||
IN UINTN WidgetCount
|
||||
);
|
||||
|
||||
/**
|
||||
Protocol struct.
|
||||
**/
|
||||
struct EFI_HDA_CODEC_INFO_PROTOCOL_ {
|
||||
EFI_HDA_CODEC_INFO_GET_NAME GetName;
|
||||
EFI_HDA_CODEC_INFO_GET_VENDOR_ID GetVendorId;
|
||||
EFI_HDA_CODEC_INFO_GET_REVISION_ID GetRevisionId;
|
||||
EFI_HDA_CODEC_INFO_GET_AUDIO_FUNC_ID GetAudioFuncId;
|
||||
EFI_HDA_CODEC_INFO_GET_DEFAULT_RATES_FORMATS GetDefaultRatesFormats;
|
||||
EFI_HDA_CODEC_INFO_GET_DEFAULT_AMP_CAPS GetDefaultAmpCaps;
|
||||
EFI_HDA_CODEC_INFO_GET_WIDGETS GetWidgets;
|
||||
EFI_HDA_CODEC_INFO_FREE_WIDGETS_BUFFER FreeWidgetsBuffer;
|
||||
};
|
||||
|
||||
extern EFI_GUID gEfiHdaCodecInfoProtocolGuid;
|
||||
|
||||
#endif // EFI_HDA_CODEC_INFO_H
|
||||
81
Include/Protocol/HdaControllerInfo.h
Normal file
81
Include/Protocol/HdaControllerInfo.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* File: HdaControllerInfo.h
|
||||
*
|
||||
* Copyright (c) 2018 John Davis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EFI_HDA_CONTROLLER_INFO_H
|
||||
#define EFI_HDA_CONTROLLER_INFO_H
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
/**
|
||||
HDA Controller Info protocol GUID.
|
||||
**/
|
||||
#define EFI_HDA_CONTROLLER_INFO_PROTOCOL_GUID \
|
||||
{ 0xE5FC2CAF, 0x0291, 0x46F2, \
|
||||
{ 0x87, 0xF8, 0x10, 0xC7, 0x58, 0x72, 0x58, 0x04 } }
|
||||
|
||||
typedef struct EFI_HDA_CONTROLLER_INFO_PROTOCOL_ EFI_HDA_CONTROLLER_INFO_PROTOCOL;
|
||||
|
||||
/**
|
||||
Gets the controller's name.
|
||||
|
||||
@param[in] This A pointer to the EFI_HDA_CONTROLLER_INFO_PROTOCOL instance.
|
||||
@param[out] CodecName A pointer to the buffer to return the codec name.
|
||||
|
||||
@retval EFI_SUCCESS The controller name was retrieved.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_CONTROLLER_INFO_GET_NAME) (
|
||||
IN EFI_HDA_CONTROLLER_INFO_PROTOCOL *This,
|
||||
OUT CONST CHAR16 **ControllerName
|
||||
);
|
||||
|
||||
/**
|
||||
Gets the controller's vendor and device ID.
|
||||
|
||||
@param[in] This A pointer to the EFI_HDA_CONTROLLER_INFO_PROTOCOL instance.
|
||||
@param[out] VendorId The vendor and device ID of the controller.
|
||||
|
||||
@retval EFI_SUCCESS The vendor and device ID was retrieved.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_CONTROLLER_INFO_GET_VENDOR_ID) (
|
||||
IN EFI_HDA_CONTROLLER_INFO_PROTOCOL *This,
|
||||
OUT UINT32 *VendorId
|
||||
);
|
||||
|
||||
/**
|
||||
Protocol struct.
|
||||
**/
|
||||
struct EFI_HDA_CONTROLLER_INFO_PROTOCOL_ {
|
||||
EFI_HDA_CONTROLLER_INFO_GET_NAME GetName;
|
||||
EFI_HDA_CONTROLLER_INFO_GET_VENDOR_ID GetVendorId;
|
||||
};
|
||||
|
||||
extern EFI_GUID gEfiHdaControllerInfoProtocolGuid;
|
||||
|
||||
#endif // EFI_HDA_CONTROLLER_INFO_H
|
||||
234
Include/Protocol/HdaIo.h
Normal file
234
Include/Protocol/HdaIo.h
Normal file
@ -0,0 +1,234 @@
|
||||
/*
|
||||
* File: HdaIo.h
|
||||
*
|
||||
* Copyright (c) 2018 John Davis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EFI_HDA_IO_H
|
||||
#define EFI_HDA_IO_H
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
|
||||
//
|
||||
// HDA I/O protocol.
|
||||
//
|
||||
|
||||
//
|
||||
// HDA I/O protocol GUID.
|
||||
//
|
||||
#define EFI_HDA_IO_PROTOCOL_GUID \
|
||||
{ 0xA090D7F9, 0xB50A, 0x4EA1, \
|
||||
{ 0xBD, 0xE9, 0x1A, 0xA5, 0xE9, 0x81, 0x2F, 0x45 } }
|
||||
|
||||
typedef struct EFI_HDA_IO_PROTOCOL_ EFI_HDA_IO_PROTOCOL;
|
||||
|
||||
/**
|
||||
Stream type.
|
||||
**/
|
||||
typedef enum {
|
||||
EfiHdaIoTypeInput,
|
||||
EfiHdaIoTypeOutput,
|
||||
EfiHdaIoTypeMaximum
|
||||
} EFI_HDA_IO_PROTOCOL_TYPE;
|
||||
|
||||
/**
|
||||
Verb list structure.
|
||||
**/
|
||||
typedef struct {
|
||||
UINT32 Count;
|
||||
UINT32 *Verbs ;
|
||||
UINT32 *Responses;
|
||||
} EFI_HDA_IO_VERB_LIST;
|
||||
|
||||
/**
|
||||
Callback function.
|
||||
**/
|
||||
typedef
|
||||
VOID
|
||||
(EFIAPI* EFI_HDA_IO_STREAM_CALLBACK) (
|
||||
IN EFI_HDA_IO_PROTOCOL_TYPE Type,
|
||||
IN VOID *Context1,
|
||||
IN VOID *Context2,
|
||||
IN VOID *Context3
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves this codec's address.
|
||||
|
||||
@param[in] This A pointer to the HDA_IO_PROTOCOL instance.
|
||||
@param[out] CodecAddress The codec's address.
|
||||
|
||||
@retval EFI_SUCCESS The codec's address was returned.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_IO_GET_ADDRESS) (
|
||||
IN EFI_HDA_IO_PROTOCOL *This,
|
||||
OUT UINT8 *CodecAddress
|
||||
);
|
||||
|
||||
/**
|
||||
Sends a single command to the codec.
|
||||
|
||||
@param[in] This A pointer to the HDA_IO_PROTOCOL instance.
|
||||
@param[in] Node The destination node.
|
||||
@param[in] Verb The verb to send.
|
||||
@param[out] Response The response received.
|
||||
|
||||
@retval EFI_SUCCESS The verb was sent successfully and a response received.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_IO_SEND_COMMAND) (
|
||||
IN EFI_HDA_IO_PROTOCOL *This,
|
||||
IN UINT8 Node,
|
||||
IN UINT32 Verb,
|
||||
OUT UINT32 *Response
|
||||
);
|
||||
|
||||
/**
|
||||
Sends a set of commands to the codec.
|
||||
|
||||
@param[in] This A pointer to the HDA_IO_PROTOCOL instance.
|
||||
@param[in] Node The destination node.
|
||||
@param[in] Verbs The verbs to send. Responses will be delievered in the same list.
|
||||
|
||||
@retval EFI_SUCCESS The verbs were sent successfully and all responses received.
|
||||
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_IO_SEND_COMMANDS) (
|
||||
IN EFI_HDA_IO_PROTOCOL *This,
|
||||
IN UINT8 Node,
|
||||
IN OUT EFI_HDA_IO_VERB_LIST *Verbs
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_IO_SETUP_STREAM) (
|
||||
IN EFI_HDA_IO_PROTOCOL *This,
|
||||
IN EFI_HDA_IO_PROTOCOL_TYPE Type,
|
||||
IN UINT16 Format,
|
||||
OUT UINT8 *StreamId
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_IO_CLOSE_STREAM) (
|
||||
IN EFI_HDA_IO_PROTOCOL *This,
|
||||
IN EFI_HDA_IO_PROTOCOL_TYPE Type
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_IO_GET_STREAM) (
|
||||
IN EFI_HDA_IO_PROTOCOL *This,
|
||||
IN EFI_HDA_IO_PROTOCOL_TYPE Type,
|
||||
OUT BOOLEAN *State
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_IO_START_STREAM) (
|
||||
IN EFI_HDA_IO_PROTOCOL *This,
|
||||
IN EFI_HDA_IO_PROTOCOL_TYPE Type,
|
||||
IN VOID *Buffer,
|
||||
IN UINTN BufferLength,
|
||||
IN UINTN BufferPosition OPTIONAL,
|
||||
IN EFI_HDA_IO_STREAM_CALLBACK Callback OPTIONAL,
|
||||
IN VOID *Context1 OPTIONAL,
|
||||
IN VOID *Context2 OPTIONAL,
|
||||
IN VOID *Context3 OPTIONAL
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_HDA_IO_STOP_STREAM) (
|
||||
IN EFI_HDA_IO_PROTOCOL *This,
|
||||
IN EFI_HDA_IO_PROTOCOL_TYPE Type
|
||||
);
|
||||
|
||||
/**
|
||||
HDA I/O protocol structure.
|
||||
**/
|
||||
struct EFI_HDA_IO_PROTOCOL_ {
|
||||
EFI_HDA_IO_GET_ADDRESS GetAddress;
|
||||
EFI_HDA_IO_SEND_COMMAND SendCommand;
|
||||
EFI_HDA_IO_SEND_COMMANDS SendCommands;
|
||||
EFI_HDA_IO_SETUP_STREAM SetupStream;
|
||||
EFI_HDA_IO_CLOSE_STREAM CloseStream;
|
||||
EFI_HDA_IO_GET_STREAM GetStream;
|
||||
EFI_HDA_IO_START_STREAM StartStream;
|
||||
EFI_HDA_IO_STOP_STREAM StopStream;
|
||||
};
|
||||
|
||||
extern EFI_GUID gEfiHdaIoProtocolGuid;
|
||||
|
||||
//
|
||||
// HDA I/O Device Path protocol.
|
||||
//
|
||||
|
||||
/**
|
||||
HDA I/O Device Path GUID.
|
||||
**/
|
||||
#define EFI_HDA_IO_DEVICE_PATH_GUID \
|
||||
{ 0xA9003FEB, 0xD806, 0x41DB, \
|
||||
{ 0xA4, 0x91, 0x54, 0x05, 0xFE, 0xEF, 0x46, 0xC3 } }
|
||||
|
||||
/**
|
||||
HDA I/O Device Path structure.
|
||||
**/
|
||||
typedef struct {
|
||||
///
|
||||
/// Vendor-specific device path fields.
|
||||
///
|
||||
EFI_DEVICE_PATH_PROTOCOL Header;
|
||||
EFI_GUID Guid;
|
||||
///
|
||||
/// Codec address.
|
||||
///
|
||||
UINT8 Address;
|
||||
} EFI_HDA_IO_DEVICE_PATH;
|
||||
|
||||
extern EFI_GUID gEfiHdaIoDevicePathGuid;
|
||||
|
||||
/**
|
||||
Template for HDA I/O Device Path protocol.
|
||||
**/
|
||||
#define EFI_HDA_IO_DEVICE_PATH_TEMPLATE \
|
||||
{ \
|
||||
{ \
|
||||
MESSAGING_DEVICE_PATH, \
|
||||
MSG_VENDOR_DP, \
|
||||
{ \
|
||||
(UINT8) (sizeof (EFI_HDA_IO_DEVICE_PATH) & 0xFFU), \
|
||||
(UINT8) ((sizeof (EFI_HDA_IO_DEVICE_PATH) >> 8U) & 0xFFU) \
|
||||
} \
|
||||
}, \
|
||||
gEfiHdaIoDevicePathGuid, \
|
||||
0 \
|
||||
}
|
||||
|
||||
#endif // EFI_HDA_IO_H
|
||||
37
Include/Protocol/OcAppleBootCompat.h
Normal file
37
Include/Protocol/OcAppleBootCompat.h
Normal file
@ -0,0 +1,37 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_APPLE_BOOT_COMPAT_PROTOCOL_H
|
||||
#define OC_APPLE_BOOT_COMPAT_PROTOCOL_H
|
||||
|
||||
#define OC_APPLE_BOOT_COMPAT_PROTOCOL_REVISION 0x010000
|
||||
|
||||
//
|
||||
// OC_APPLE_BOOT_COMPAT_PROTOCOL_GUID
|
||||
// C7CBA84E-CC77-461D-9E3C-6BE0CB79A7C1
|
||||
//
|
||||
#define OC_APPLE_BOOT_COMPAT_PROTOCOL_GUID \
|
||||
{ 0xC7CBA84E, 0xCC77, 0x461D, \
|
||||
{ 0x9E, 0x3C, 0x6B, 0xE0, 0xCB, 0x79, 0xA7, 0xC1 } }
|
||||
|
||||
//
|
||||
// Includes a revision for debugging reasons
|
||||
//
|
||||
typedef struct {
|
||||
UINTN Revision;
|
||||
} OC_APPLE_BOOT_COMPAT_PROTOCOL;
|
||||
|
||||
extern EFI_GUID gOcAppleBootCompatProtocolGuid;
|
||||
|
||||
#endif // OC_APPLE_BOOT_COMPAT_PROTOCOL_H
|
||||
231
Include/Protocol/OcAudio.h
Normal file
231
Include/Protocol/OcAudio.h
Normal file
@ -0,0 +1,231 @@
|
||||
/** @file
|
||||
Copyright (C) 2020, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_AUDIO_PROTOCOL_H
|
||||
#define OC_AUDIO_PROTOCOL_H
|
||||
|
||||
#include <Protocol/AppleVoiceOver.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
|
||||
#define OC_AUDIO_PROTOCOL_REVISION 0x010000
|
||||
|
||||
//
|
||||
// OC_AUDIO_PROTOCOL_GUID
|
||||
// 4B228577-6274-4A48-82AE-0713A1171987
|
||||
//
|
||||
#define OC_AUDIO_PROTOCOL_GUID \
|
||||
{ 0x4B228577, 0x6274, 0x4A48, \
|
||||
{ 0x82, 0xAE, 0x07, 0x13, 0xA1, 0x17, 0x19, 0x87 } }
|
||||
|
||||
typedef struct OC_AUDIO_PROTOCOL_ OC_AUDIO_PROTOCOL;
|
||||
|
||||
/**
|
||||
Custom OpenCore audio files.
|
||||
**/
|
||||
typedef enum {
|
||||
OcVoiceOverAudioFileBase = 0x1000,
|
||||
|
||||
OcVoiceOverAudioFileIndexBase = 0x1000,
|
||||
OcVoiceOverAudioFile1 = 0x1001,
|
||||
OcVoiceOverAudioFile2 = 0x1002,
|
||||
OcVoiceOverAudioFile3 = 0x1003,
|
||||
OcVoiceOverAudioFile4 = 0x1004,
|
||||
OcVoiceOverAudioFile5 = 0x1005,
|
||||
OcVoiceOverAudioFile6 = 0x1006,
|
||||
OcVoiceOverAudioFile7 = 0x1007,
|
||||
OcVoiceOverAudioFile8 = 0x1008,
|
||||
OcVoiceOverAudioFile9 = 0x1009,
|
||||
OcVoiceOverAudioFileIndexAlphabetical = 0x100A,
|
||||
OcVoiceOverAudioFileLetterA = 0x100A,
|
||||
OcVoiceOverAudioFileLetterB = 0x100B,
|
||||
OcVoiceOverAudioFileLetterC = 0x100C,
|
||||
OcVoiceOverAudioFileLetterD = 0x100D,
|
||||
OcVoiceOverAudioFileLetterE = 0x100E,
|
||||
OcVoiceOverAudioFileLetterF = 0x100F,
|
||||
OcVoiceOverAudioFileLetterG = 0x1010,
|
||||
OcVoiceOverAudioFileLetterH = 0x1011,
|
||||
OcVoiceOverAudioFileLetterI = 0x1012,
|
||||
OcVoiceOverAudioFileLetterJ = 0x1013,
|
||||
OcVoiceOverAudioFileLetterK = 0x1014,
|
||||
OcVoiceOverAudioFileLetterL = 0x1015,
|
||||
OcVoiceOverAudioFileLetterM = 0x1016,
|
||||
OcVoiceOverAudioFileLetterN = 0x1017,
|
||||
OcVoiceOverAudioFileLetterO = 0x1018,
|
||||
OcVoiceOverAudioFileLetterP = 0x1019,
|
||||
OcVoiceOverAudioFileLetterQ = 0x101A,
|
||||
OcVoiceOverAudioFileLetterR = 0x101B,
|
||||
OcVoiceOverAudioFileLetterS = 0x101C,
|
||||
OcVoiceOverAudioFileLetterT = 0x101D,
|
||||
OcVoiceOverAudioFileLetterU = 0x101E,
|
||||
OcVoiceOverAudioFileLetterV = 0x101F,
|
||||
OcVoiceOverAudioFileLetterW = 0x1020,
|
||||
OcVoiceOverAudioFileLetterX = 0x1021,
|
||||
OcVoiceOverAudioFileLetterY = 0x1022,
|
||||
OcVoiceOverAudioFileLetterZ = 0x1023,
|
||||
OcVoiceOverAudioFileIndexMax = 0x1023,
|
||||
|
||||
OcVoiceOverAudioFileAbortTimeout = 0x1030,
|
||||
OcVoiceOverAudioFileChooseOS = 0x1031,
|
||||
OcVoiceOverAudioFileDefault = 0x1032,
|
||||
OcVoiceOverAudioFileDiskImage = 0x1033,
|
||||
OcVoiceOverAudioFileEnterPassword = 0x1034,
|
||||
OcVoiceOverAudioFileExecutionFailure = 0x1035,
|
||||
OcVoiceOverAudioFileExecutionSuccessful = 0x1036,
|
||||
OcVoiceOverAudioFileExternal = 0x1037,
|
||||
OcVoiceOverAudioFileExternalOption = 0x1038,
|
||||
OcVoiceOverAudioFileLoading = 0x1039,
|
||||
OcVoiceOverAudioFilemacOS = 0x103A,
|
||||
OcVoiceOverAudioFilemacOS_Recovery = 0x103B,
|
||||
OcVoiceOverAudioFileOtherOS = 0x103C,
|
||||
OcVoiceOverAudioFilePasswordAccepted = 0x103D,
|
||||
OcVoiceOverAudioFilePasswordIncorrect = 0x103E,
|
||||
OcVoiceOverAudioFilePasswordRetryLimit = 0x103F,
|
||||
OcVoiceOverAudioFileReloading = 0x1040,
|
||||
OcVoiceOverAudioFileResetNVRAM = 0x1041,
|
||||
OcVoiceOverAudioFileSelected = 0x1042,
|
||||
OcVoiceOverAudioFileShowAuxiliary = 0x1043,
|
||||
OcVoiceOverAudioFileTimeout = 0x1044,
|
||||
OcVoiceOverAudioFileUEFI_Shell = 0x1045,
|
||||
OcVoiceOverAudioFileWelcome = 0x1046,
|
||||
OcVoiceOverAudioFileWindows = 0x1047,
|
||||
|
||||
OcVoiceOverAudioFileMax = 0x1048,
|
||||
} OC_VOICE_OVER_AUDIO_FILE;
|
||||
|
||||
STATIC_ASSERT (OcVoiceOverAudioFileIndexMax - OcVoiceOverAudioFileIndexBase == 9 + 26, "Invalid index count");
|
||||
|
||||
/**
|
||||
Connect to Audio I/O.
|
||||
|
||||
@param[in,out] This Audio protocol instance.
|
||||
@param[in] DevicePath Controller device path, optional.
|
||||
@param[in] CodecAddress Codec address, optional.
|
||||
@param[in] OutputIndex Output index, optional.
|
||||
@param[in] Volume Raw volume level from 0 to 100.
|
||||
|
||||
@retval EFI_SUCESS on success.
|
||||
@retval EFI_NOT_FOUND when missing.
|
||||
@retval EFI_UNSUPPORTED on failure.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI* OC_AUDIO_CONNECT) (
|
||||
IN OUT OC_AUDIO_PROTOCOL *This,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
|
||||
IN UINT8 CodecAddress OPTIONAL,
|
||||
IN UINT8 OutputIndex OPTIONAL,
|
||||
IN UINT8 Volume
|
||||
);
|
||||
|
||||
/**
|
||||
Retrive file contents callback.
|
||||
|
||||
@param[in,out] Context Externally specified context.
|
||||
@param[in] File File identifier, see APPLE_VOICE_OVER_AUDIO_FILE.
|
||||
@paran[in] LanguageCode Language code for the file.
|
||||
@param[out] Buffer Pointer to buffer.
|
||||
@param[out] BufferSize Pointer to buffer size.
|
||||
|
||||
@retval EFI_SUCCESS on successful file lookup.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI* OC_AUDIO_PROVIDER_ACQUIRE) (
|
||||
IN VOID *Context,
|
||||
IN UINT32 File,
|
||||
IN APPLE_VOICE_OVER_LANGUAGE_CODE LanguageCode,
|
||||
OUT UINT8 **Buffer,
|
||||
OUT UINT32 *BufferSize
|
||||
);
|
||||
|
||||
/**
|
||||
Release file contents given by acquire callback.
|
||||
|
||||
@param[in,out] Context Externally specified context.
|
||||
@param[out] Buffer Pointer to buffer.
|
||||
|
||||
@retval EFI_SUCCESS on successful release.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI* OC_AUDIO_PROVIDER_RELEASE) (
|
||||
IN VOID *Context,
|
||||
IN UINT8 *Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Set resource provider.
|
||||
|
||||
@param[in,out] This Audio protocol instance.
|
||||
@param[in] Acquire Resource acquire handler.
|
||||
@param[in] Release Resource release handler, optional.
|
||||
@param[in] Context Resource handler context.
|
||||
|
||||
@retval EFI_SUCCESS on successful provider update.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI* OC_AUDIO_SET_PROVIDER) (
|
||||
IN OUT OC_AUDIO_PROTOCOL *This,
|
||||
IN OC_AUDIO_PROVIDER_ACQUIRE Acquire,
|
||||
IN OC_AUDIO_PROVIDER_RELEASE Release OPTIONAL,
|
||||
IN VOID *Context
|
||||
);
|
||||
|
||||
/**
|
||||
Play file.
|
||||
|
||||
@param[in,out] This Audio protocol instance.
|
||||
@param[in] File File to play.
|
||||
@param[in] Wait Wait for completion of the previous track.
|
||||
|
||||
@retval EFI_SUCCESS on successful playback startup.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI* OC_AUDIO_PLAY_FILE) (
|
||||
IN OUT OC_AUDIO_PROTOCOL *This,
|
||||
IN UINT32 File,
|
||||
IN BOOLEAN Wait
|
||||
);
|
||||
|
||||
/**
|
||||
Stop playback.
|
||||
|
||||
@param[in,out] This Audio protocol instance.
|
||||
@param[in] Wait Wait for audio completion.
|
||||
|
||||
@retval EFI_SUCCESS on successful playback stop.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI* OC_AUDIO_STOP_PLAYBACK) (
|
||||
IN OUT OC_AUDIO_PROTOCOL *This,
|
||||
IN BOOLEAN Wait
|
||||
);
|
||||
|
||||
//
|
||||
// Includes a revision for debugging reasons.
|
||||
//
|
||||
struct OC_AUDIO_PROTOCOL_ {
|
||||
UINTN Revision;
|
||||
OC_AUDIO_CONNECT Connect;
|
||||
OC_AUDIO_SET_PROVIDER SetProvider;
|
||||
OC_AUDIO_PLAY_FILE PlayFile;
|
||||
OC_AUDIO_STOP_PLAYBACK StopPlayback;
|
||||
};
|
||||
|
||||
extern EFI_GUID gOcAudioProtocolGuid;
|
||||
|
||||
#endif // OC_AUDIO_PROTOCOL_H
|
||||
70
Include/Protocol/OcBootstrap.h
Normal file
70
Include/Protocol/OcBootstrap.h
Normal file
@ -0,0 +1,70 @@
|
||||
/** @file
|
||||
Copyright (C) 2018, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_BOOTSTRAP_PROTOCOL_H
|
||||
#define OC_BOOTSTRAP_PROTOCOL_H
|
||||
|
||||
#include <Library/OcCryptoLib.h>
|
||||
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
|
||||
///
|
||||
/// BA1EB455-B182-4F14-8521-E422C325DEF6
|
||||
///
|
||||
#define OC_BOOTSTRAP_PROTOCOL_GUID \
|
||||
{ \
|
||||
0xBA1EB455, 0xB182, 0x4F14, { 0x85, 0x21, 0xE4, 0x22, 0xC3, 0x25, 0xDE, 0xF6 } \
|
||||
}
|
||||
|
||||
///
|
||||
/// OC_BOOTSTRAP_PROTOCOL revision
|
||||
///
|
||||
#define OC_BOOTSTRAP_PROTOCOL_REVISION 5
|
||||
|
||||
///
|
||||
/// Forward declaration of OC_BOOTSTRAP_PROTOCOL structure.
|
||||
///
|
||||
typedef struct OC_BOOTSTRAP_PROTOCOL_ OC_BOOTSTRAP_PROTOCOL;
|
||||
|
||||
/**
|
||||
Restart OpenCore at specified file system.
|
||||
|
||||
@param[in] This This protocol.
|
||||
@param[in] FileSystem File system to bootstrap in.
|
||||
@param[in] LoadPath EFI device path to loaded image.
|
||||
|
||||
@retval EFI_ALREADY_STARTED if already started.
|
||||
@retval Does not return on success.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *OC_BOOTSTRAP_RERUN) (
|
||||
IN OC_BOOTSTRAP_PROTOCOL *This,
|
||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *LoadPath OPTIONAL
|
||||
);
|
||||
|
||||
///
|
||||
/// The structure exposed by the OC_BOOTSTRAP_PROTOCOL.
|
||||
///
|
||||
struct OC_BOOTSTRAP_PROTOCOL_ {
|
||||
UINTN Revision;
|
||||
UINTN NestedCount;
|
||||
OC_RSA_PUBLIC_KEY *VaultKey;
|
||||
OC_BOOTSTRAP_RERUN ReRun;
|
||||
};
|
||||
|
||||
extern EFI_GUID gOcBootstrapProtocolGuid;
|
||||
|
||||
#endif // OC_BOOTSTRAP_PROTOCOL_H
|
||||
137
Include/Protocol/OcFirmwareRuntime.h
Normal file
137
Include/Protocol/OcFirmwareRuntime.h
Normal file
@ -0,0 +1,137 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_FIRMWARE_RUNTIME_PROTOCOL_H
|
||||
#define OC_FIRMWARE_RUNTIME_PROTOCOL_H
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
#define OC_FIRMWARE_RUNTIME_REVISION 4
|
||||
|
||||
/**
|
||||
OC_FIRMWARE_RUNTIME_PROTOCOL_GUID
|
||||
570332E4-FC50-4B21-ABE8-AE72F05B4FF7
|
||||
**/
|
||||
#define OC_FIRMWARE_RUNTIME_PROTOCOL_GUID \
|
||||
{ 0x570332E4, 0xFC50, 0x4B21, \
|
||||
{ 0xAB, 0xE8, 0xAE, 0x72, 0xF0, 0x5B, 0x4F, 0xF7 } }
|
||||
/**
|
||||
Configuration request to change firmware runtime behaviour.
|
||||
**/
|
||||
typedef struct OC_FWRT_CONFIG_ {
|
||||
///
|
||||
/// Enforce restricted access to OpenCore read-only and write-only GUIDs.
|
||||
///
|
||||
BOOLEAN RestrictedVariables;
|
||||
///
|
||||
/// Enforce BootXXXX variable redirection to OpenCore vendor GUID.
|
||||
///
|
||||
BOOLEAN BootVariableRedirect;
|
||||
///
|
||||
/// Route boot variables back to EfiGlobalVariable when they are compatible.
|
||||
/// In general we do not want this, as this basically escapes OpenCore security
|
||||
/// jail, and permits booting operating systems bypassing OpenCore.
|
||||
/// However, some firmwares, namely ASUS APTIO V, will freeze/fail to boot
|
||||
/// by manually adding boot entries for Windows after Windows itself did not
|
||||
/// create them.
|
||||
///
|
||||
BOOLEAN BootVariableFallback;
|
||||
///
|
||||
/// Make SetVariable do nothing and always return EFI_SECURITY_VIOLATION.
|
||||
/// When we do not want variables to be stored in NVRAM or NVRAM implementation
|
||||
/// is buggy we can disable variable writing.
|
||||
///
|
||||
BOOLEAN WriteProtection;
|
||||
///
|
||||
/// Make UEFI runtime services drop CR0 WP bit on calls to allow writing
|
||||
/// to read only memory. This workarounds a bug in many APTIO firmwares
|
||||
/// that do not survive W^X.
|
||||
/// Latest Windows brings Virtualization-based security and monitors
|
||||
/// CR0 by launching itself under a hypevisor. Since we need WP disable
|
||||
/// on macOS to let NVRAM work, and for the time being no other OS
|
||||
/// requires it, here we decide to use it for macOS exclusively.
|
||||
///
|
||||
BOOLEAN WriteUnprotector;
|
||||
///
|
||||
/// Secure boot variable protection.
|
||||
///
|
||||
BOOLEAN ProtectSecureBoot;
|
||||
} OC_FWRT_CONFIG;
|
||||
|
||||
/**
|
||||
Get current used configuration data.
|
||||
|
||||
@param[out] Config Current configuration to store.
|
||||
**/
|
||||
typedef
|
||||
VOID
|
||||
(EFIAPI *OC_FWRT_GET_CURRENT_CONFIG) (
|
||||
OUT OC_FWRT_CONFIG *Config
|
||||
);
|
||||
|
||||
/**
|
||||
Set main configuration.
|
||||
|
||||
@param[in] Config Runtime services configuration to apply.
|
||||
**/
|
||||
typedef
|
||||
VOID
|
||||
(EFIAPI *OC_FWRT_SET_MAIN_CONFIG) (
|
||||
IN CONST OC_FWRT_CONFIG *Config
|
||||
);
|
||||
|
||||
/**
|
||||
Perform configuration override, NULL Config implies disable override.
|
||||
|
||||
@param[in] Config Runtime services configuration to apply, optional.
|
||||
**/
|
||||
typedef
|
||||
VOID
|
||||
(EFIAPI *OC_FWRT_SET_OVERRIDE_CONFIG) (
|
||||
IN CONST OC_FWRT_CONFIG *Config OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Set GetVariable override for customising values.
|
||||
|
||||
@param[in] GetVariable GetVariable to call on each call.
|
||||
@param[out] OrgGetVariable Original GetVariable to call from GetVariable.
|
||||
|
||||
@retval EFI_SUCCESS on successful override.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *OC_FWRT_ON_GET_VARIABLE) (
|
||||
IN EFI_GET_VARIABLE GetVariable,
|
||||
OUT EFI_GET_VARIABLE *OrgGetVariable OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Firmware runtime protocol instance.
|
||||
Check for revision to ensure binary compatibility.
|
||||
**/
|
||||
typedef struct {
|
||||
UINTN Revision;
|
||||
OC_FWRT_GET_CURRENT_CONFIG GetCurrent;
|
||||
OC_FWRT_SET_MAIN_CONFIG SetMain;
|
||||
OC_FWRT_SET_OVERRIDE_CONFIG SetOverride;
|
||||
OC_FWRT_ON_GET_VARIABLE OnGetVariable;
|
||||
} OC_FIRMWARE_RUNTIME_PROTOCOL;
|
||||
|
||||
/**
|
||||
Firmware runtime protocol GUID.
|
||||
**/
|
||||
extern EFI_GUID gOcFirmwareRuntimeProtocolGuid;
|
||||
|
||||
#endif // OC_FIRMWARE_RUNTIME_PROTOCOL_H
|
||||
71
Include/Protocol/OcInterface.h
Normal file
71
Include/Protocol/OcInterface.h
Normal file
@ -0,0 +1,71 @@
|
||||
/** @file
|
||||
Copyright (C) 2019, vit9696. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_INTERFACE_PROTOCOL_H
|
||||
#define OC_INTERFACE_PROTOCOL_H
|
||||
|
||||
#include <Library/OcBootManagementLib.h>
|
||||
#include <Library/OcStorageLib.h>
|
||||
|
||||
/**
|
||||
Current supported interface protocol revision.
|
||||
It is changed every time the contract changes.
|
||||
|
||||
WARNING: This protocol currently undergoes design process.
|
||||
**/
|
||||
#define OC_INTERFACE_REVISION 2
|
||||
|
||||
/**
|
||||
The GUID of the OC_INTERFACE_PROTOCOL.
|
||||
**/
|
||||
#define OC_INTERFACE_PROTOCOL_GUID \
|
||||
{ 0x53027CDF, 0x3A89, 0x4255, \
|
||||
{ 0xAE, 0x29, 0xD6, 0x66, 0x6E, 0xFE, 0x99, 0xEF } }
|
||||
|
||||
/**
|
||||
The forward declaration for the protocol for the OC_INTERFACE_PROTOCOL_H.
|
||||
**/
|
||||
typedef struct OC_INTERFACE_PROTOCOL_ OC_INTERFACE_PROTOCOL;
|
||||
|
||||
/**
|
||||
Add an entry to the log buffer
|
||||
|
||||
@param[in] This This protocol.
|
||||
@param[in] Storage File system access storage.
|
||||
@param[in] Picker User interface configuration.
|
||||
|
||||
@retval does not return unless a fatal error happened.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *OC_INTERFACE_RUN) (
|
||||
IN OC_INTERFACE_PROTOCOL *This,
|
||||
IN OC_STORAGE_CONTEXT *Storage,
|
||||
IN OC_PICKER_CONTEXT *Picker
|
||||
);
|
||||
|
||||
/**
|
||||
The structure exposed by the OC_INTERFACE_PROTOCOL.
|
||||
**/
|
||||
struct OC_INTERFACE_PROTOCOL_ {
|
||||
UINT32 Revision; ///< The revision of the installed protocol.
|
||||
OC_INTERFACE_RUN ShowInteface; ///< A pointer to the ShowInterface function.
|
||||
};
|
||||
|
||||
/**
|
||||
A global variable storing the GUID of the OC_INTERFACE_PROTOCOL.
|
||||
**/
|
||||
extern EFI_GUID gOcInterfaceProtocolGuid;
|
||||
|
||||
#endif // OC_INTERFACE_PROTOCOL_H
|
||||
136
Include/Protocol/OcLog.h
Executable file
136
Include/Protocol/OcLog.h
Executable file
@ -0,0 +1,136 @@
|
||||
/** @file
|
||||
Copyright (C) 2016, The HermitCrabs Lab. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef OC_LOG_PROTOCOL_H
|
||||
#define OC_LOG_PROTOCOL_H
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
|
||||
///
|
||||
/// Current supported log protocol revision.
|
||||
///
|
||||
#define OC_LOG_REVISION 0x01000A
|
||||
|
||||
///
|
||||
/// The defines for the log flags.
|
||||
///
|
||||
#define OC_LOG_ENABLE BIT0
|
||||
#define OC_LOG_CONSOLE BIT1
|
||||
#define OC_LOG_DATA_HUB BIT2
|
||||
#define OC_LOG_SERIAL BIT3
|
||||
#define OC_LOG_VARIABLE BIT4
|
||||
#define OC_LOG_NONVOLATILE BIT5
|
||||
#define OC_LOG_FILE BIT6
|
||||
|
||||
typedef UINT32 OC_LOG_OPTIONS;
|
||||
|
||||
/**
|
||||
The GUID of the OC_LOG_PROTOCOL.
|
||||
**/
|
||||
#define OC_LOG_PROTOCOL_GUID \
|
||||
{ 0xDBB6008F, 0x89E4, 0x4272, \
|
||||
{ 0x98, 0x81, 0xCE, 0x3A, 0xFD, 0x97, 0x24, 0xD0 } }
|
||||
|
||||
/**
|
||||
The forward declaration for the protocol for the OC_LOG_PROTOCOL.
|
||||
**/
|
||||
typedef struct OC_LOG_PROTOCOL_ OC_LOG_PROTOCOL;
|
||||
|
||||
/**
|
||||
Add an entry to the log buffer
|
||||
|
||||
@param[in] This This protocol.
|
||||
@param[in] ErrorLevel Debug level.
|
||||
@param[in] FormatString String containing the output format.
|
||||
@param[in] Marker Address of the VA_ARGS marker.
|
||||
|
||||
@retval EFI_SUCCESS The entry was successfully added.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *OC_LOG_ADD_ENTRY) (
|
||||
IN OC_LOG_PROTOCOL *This,
|
||||
IN UINTN ErrorLevel,
|
||||
IN CONST CHAR8 *FormatString,
|
||||
IN VA_LIST Marker
|
||||
);
|
||||
|
||||
/**
|
||||
Reset the internal timers
|
||||
|
||||
@param[in] This This protocol.
|
||||
|
||||
@retval EFI_SUCCESS The timers were reset successfully.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *OC_LOG_RESET_TIMERS) (
|
||||
IN OC_LOG_PROTOCOL *This
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieve pointer to the log buffer
|
||||
|
||||
@param[in] This This protocol.
|
||||
@param[in] OcLogBuffer Address to store the buffer pointer.
|
||||
|
||||
@retval EFI_SUCCESS The timers were reset successfully.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *OC_LOG_GET_LOG) (
|
||||
IN OC_LOG_PROTOCOL *This,
|
||||
OUT CHAR8 **OcLogBuffer
|
||||
);
|
||||
|
||||
/**
|
||||
Save the current log
|
||||
|
||||
@param[in] This This protocol.
|
||||
@param[in] NonVolatile Variable.
|
||||
@param[in] FilePath Filepath to save the log. OPTIONAL
|
||||
|
||||
@retval EFI_SUCCESS The log was saved successfully.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *OC_LOG_SAVE_LOG) (
|
||||
IN OC_LOG_PROTOCOL *This,
|
||||
IN UINT32 NonVolatile OPTIONAL,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *FilePath OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
The structure exposed by the OC_LOG_PROTOCOL.
|
||||
**/
|
||||
struct OC_LOG_PROTOCOL_ {
|
||||
UINT32 Revision; ///< The revision of the installed protocol.
|
||||
UINTN Reserved; ///< Reserved for future extension.
|
||||
OC_LOG_ADD_ENTRY AddEntry; ///< A pointer to the AddEntry function.
|
||||
OC_LOG_GET_LOG GetLog; ///< A pointer to the GetLog function.
|
||||
OC_LOG_SAVE_LOG SaveLog; ///< A pointer to the SaveLog function.
|
||||
OC_LOG_RESET_TIMERS ResetTimers; ///< A pointer to the ResetTimers function.
|
||||
OC_LOG_OPTIONS Options; ///< The current options of the installed protocol.
|
||||
UINT32 DisplayDelay; ///< The delay after visible onscreen message in microseconds.
|
||||
UINTN DisplayLevel; ///< The error level visible onscreen.
|
||||
UINTN HaltLevel; ///< The error level causing CPU dead loop.
|
||||
EFI_FILE_PROTOCOL *FileSystem; ///< Log file system root, not owned.
|
||||
CHAR16 *FilePath; ///< Log file path.
|
||||
};
|
||||
|
||||
/// A global variable storing the GUID of the OC_LOG_PROTOCOL.
|
||||
extern EFI_GUID gOcLogProtocolGuid;
|
||||
|
||||
#endif // OC_LOG_PROTOCOL_H
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user