From 2090f6ef7eccfcfdcd1545fdd86dd7b02790cc1b Mon Sep 17 00:00:00 2001 From: Mikhail Krichanov Date: Thu, 15 Feb 2024 11:43:50 +0300 Subject: [PATCH] Ring3: Merged Ring3Dxe and Ring3UefiBootServicesTableLib into DxeRing3. --- MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.c | 102 ++++++++++++++++++ .../Ring3Dxe.inf => DxeRing3/DxeRing3.inf} | 16 ++- .../Core/Dxe/DxeRing3}/Ring3.h | 0 .../Core/Dxe/DxeRing3/Ring3UefiBootServices.c | 77 +------------ .../Core/Dxe/DxeRing3}/X64/SysCall.nasm | 0 MdeModulePkg/Core/Dxe/SysCall/Ring3Dxe.c | 62 ----------- .../Ring3UefiBootServicesTableLib.inf | 41 ------- .../Ring3UefiBootServicesTableLib.uni | 12 --- 8 files changed, 116 insertions(+), 194 deletions(-) create mode 100644 MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.c rename MdeModulePkg/Core/Dxe/{SysCall/Ring3Dxe.inf => DxeRing3/DxeRing3.inf} (69%) rename {MdePkg/Library/Ring3UefiBootServicesTableLib => MdeModulePkg/Core/Dxe/DxeRing3}/Ring3.h (100%) rename MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.c => MdeModulePkg/Core/Dxe/DxeRing3/Ring3UefiBootServices.c (62%) rename {MdePkg/Library/Ring3UefiBootServicesTableLib => MdeModulePkg/Core/Dxe/DxeRing3}/X64/SysCall.nasm (100%) delete mode 100644 MdeModulePkg/Core/Dxe/SysCall/Ring3Dxe.c delete mode 100644 MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.inf delete mode 100644 MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.uni diff --git a/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.c b/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.c new file mode 100644 index 0000000000..94f8e78ef7 --- /dev/null +++ b/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.c @@ -0,0 +1,102 @@ +/** @file + + Copyright (c) 2024, Mikhail Krichanov. All rights reserved. + SPDX-License-Identifier: BSD-3-Clause + +**/ + +#include +#include + +#include "Ring3.h" + +EFI_BOOT_SERVICES mBootServices = { + { + EFI_BOOT_SERVICES_SIGNATURE, // Signature + EFI_BOOT_SERVICES_REVISION, // Revision + sizeof (EFI_BOOT_SERVICES), // HeaderSize + 0, // CRC32 + 0 // Reserved + }, + (EFI_RAISE_TPL)Ring3RaiseTpl, // RaiseTPL + (EFI_RESTORE_TPL)Ring3RestoreTpl, // RestoreTPL + (EFI_ALLOCATE_PAGES)Ring3AllocatePages, // AllocatePages + (EFI_FREE_PAGES)Ring3FreePages, // FreePages + (EFI_GET_MEMORY_MAP)Ring3GetMemoryMap, // GetMemoryMap + (EFI_ALLOCATE_POOL)Ring3AllocatePool, // AllocatePool + (EFI_FREE_POOL)Ring3FreePool, // FreePool + (EFI_CREATE_EVENT)Ring3CreateEvent, // CreateEvent + (EFI_SET_TIMER)Ring3SetTimer, // SetTimer + (EFI_WAIT_FOR_EVENT)Ring3WaitForEvent, // WaitForEvent + (EFI_SIGNAL_EVENT)Ring3SignalEvent, // SignalEvent + (EFI_CLOSE_EVENT)Ring3CloseEvent, // CloseEvent + (EFI_CHECK_EVENT)Ring3CheckEvent, // CheckEvent + (EFI_INSTALL_PROTOCOL_INTERFACE)Ring3InstallProtocolInterface, // InstallProtocolInterface + (EFI_REINSTALL_PROTOCOL_INTERFACE)Ring3ReinstallProtocolInterface, // ReinstallProtocolInterface + (EFI_UNINSTALL_PROTOCOL_INTERFACE)Ring3UninstallProtocolInterface, // UninstallProtocolInterface + (EFI_HANDLE_PROTOCOL)Ring3HandleProtocol, // HandleProtocol + (VOID *)NULL, // Reserved + (EFI_REGISTER_PROTOCOL_NOTIFY)Ring3RegisterProtocolNotify, // RegisterProtocolNotify + (EFI_LOCATE_HANDLE)Ring3LocateHandle, // LocateHandle + (EFI_LOCATE_DEVICE_PATH)Ring3LocateDevicePath, // LocateDevicePath + (EFI_INSTALL_CONFIGURATION_TABLE)Ring3InstallConfigurationTable, // InstallConfigurationTable + (EFI_IMAGE_LOAD)Ring3LoadImage, // LoadImage + (EFI_IMAGE_START)Ring3StartImage, // StartImage + (EFI_EXIT)Ring3Exit, // Exit + (EFI_IMAGE_UNLOAD)Ring3UnloadImage, // UnloadImage + (EFI_EXIT_BOOT_SERVICES)Ring3ExitBootServices, // ExitBootServices + (EFI_GET_NEXT_MONOTONIC_COUNT)Ring3GetNextMonotonicCount, // GetNextMonotonicCount + (EFI_STALL)Ring3Stall, // Stall + (EFI_SET_WATCHDOG_TIMER)Ring3SetWatchdogTimer, // SetWatchdogTimer + (EFI_CONNECT_CONTROLLER)Ring3ConnectController, // ConnectController + (EFI_DISCONNECT_CONTROLLER)Ring3DisconnectController, // DisconnectController + (EFI_OPEN_PROTOCOL)Ring3OpenProtocol, // OpenProtocol + (EFI_CLOSE_PROTOCOL)Ring3CloseProtocol, // CloseProtocol + (EFI_OPEN_PROTOCOL_INFORMATION)Ring3OpenProtocolInformation, // OpenProtocolInformation + (EFI_PROTOCOLS_PER_HANDLE)Ring3ProtocolsPerHandle, // ProtocolsPerHandle + (EFI_LOCATE_HANDLE_BUFFER)Ring3LocateHandleBuffer, // LocateHandleBuffer + (EFI_LOCATE_PROTOCOL)Ring3LocateProtocol, // LocateProtocol + (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)Ring3InstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces + (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)Ring3UninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces + (EFI_CALCULATE_CRC32)Ring3CalculateCrc32, // CalculateCrc32 + (EFI_COPY_MEM)CopyMem, // CopyMem + (EFI_SET_MEM)SetMem, // SetMem + (EFI_CREATE_EVENT_EX)Ring3CreateEventEx, // CreateEventEx +}; + +EFI_STATUS +EFIAPI +Ring3Call ( + IN VOID *Dummy, + IN VOID *EntryPoint, + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_IMAGE_ENTRY_POINT Function; + + Function = (EFI_IMAGE_ENTRY_POINT)EntryPoint; + + Function (ImageHandle, SystemTable); + + SysCall (SysCallReturnToCore); + + return EFI_UNSUPPORTED; +} + +EFI_STATUS +EFIAPI +Ring3EntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + RING3_DATA *Ring3Data; + + Ring3Data = (RING3_DATA *)SystemTable; + + Ring3Data->EntryPoint = (VOID *)Ring3Call; + Ring3Data->BootServices = &mBootServices; + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Core/Dxe/SysCall/Ring3Dxe.inf b/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.inf similarity index 69% rename from MdeModulePkg/Core/Dxe/SysCall/Ring3Dxe.inf rename to MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.inf index 42f33e2d66..9eb3b52184 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/Ring3Dxe.inf +++ b/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.inf @@ -9,7 +9,7 @@ [Defines] INF_VERSION = 0x00010005 - BASE_NAME = Ring3Dxe + BASE_NAME = DxeRing3 FILE_GUID = 88EA50C2-0DEA-4F13-B691-B506554E632B MODULE_TYPE = DXE_DRIVER VERSION_STRING = 1.0 @@ -22,15 +22,25 @@ # [Sources] - Ring3Dxe.c + Ring3.h + DxeRing3.c + Ring3UefiBootServices.c + +[Sources.X64] + X64/SysCall.nasm [Packages] MdePkg/MdePkg.dec [LibraryClasses] BaseLib - UefiBootServicesTableLib + BaseMemoryLib + DebugLib UefiDriverEntryPoint +[Protocols] + gEfiDevicePathUtilitiesProtocolGuid ## SOMETIMES_CONSUMES + gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES + [Depex] TRUE diff --git a/MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3.h b/MdeModulePkg/Core/Dxe/DxeRing3/Ring3.h similarity index 100% rename from MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3.h rename to MdeModulePkg/Core/Dxe/DxeRing3/Ring3.h diff --git a/MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.c b/MdeModulePkg/Core/Dxe/DxeRing3/Ring3UefiBootServices.c similarity index 62% rename from MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.c rename to MdeModulePkg/Core/Dxe/DxeRing3/Ring3UefiBootServices.c index c5cf04a03e..fc15ffd278 100644 --- a/MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.c +++ b/MdeModulePkg/Core/Dxe/DxeRing3/Ring3UefiBootServices.c @@ -1,5 +1,5 @@ /** @file - This library constructs Ring 3 wrappers for the EFI_BOOT_SERVICES. + This driver constructs Ring 3 wrappers for the EFI_BOOT_SERVICES. Copyright (c) 2024, Mikhail Krichanov. All rights reserved. SPDX-License-Identifier: BSD-3-Clause @@ -16,81 +16,6 @@ #include "Ring3.h" -EFI_BOOT_SERVICES mBootServices = { - { - EFI_BOOT_SERVICES_SIGNATURE, // Signature - EFI_BOOT_SERVICES_REVISION, // Revision - sizeof (EFI_BOOT_SERVICES), // HeaderSize - 0, // CRC32 - 0 // Reserved - }, - (EFI_RAISE_TPL)Ring3RaiseTpl, // RaiseTPL - (EFI_RESTORE_TPL)Ring3RestoreTpl, // RestoreTPL - (EFI_ALLOCATE_PAGES)Ring3AllocatePages, // AllocatePages - (EFI_FREE_PAGES)Ring3FreePages, // FreePages - (EFI_GET_MEMORY_MAP)Ring3GetMemoryMap, // GetMemoryMap - (EFI_ALLOCATE_POOL)Ring3AllocatePool, // AllocatePool - (EFI_FREE_POOL)Ring3FreePool, // FreePool - (EFI_CREATE_EVENT)Ring3CreateEvent, // CreateEvent - (EFI_SET_TIMER)Ring3SetTimer, // SetTimer - (EFI_WAIT_FOR_EVENT)Ring3WaitForEvent, // WaitForEvent - (EFI_SIGNAL_EVENT)Ring3SignalEvent, // SignalEvent - (EFI_CLOSE_EVENT)Ring3CloseEvent, // CloseEvent - (EFI_CHECK_EVENT)Ring3CheckEvent, // CheckEvent - (EFI_INSTALL_PROTOCOL_INTERFACE)Ring3InstallProtocolInterface, // InstallProtocolInterface - (EFI_REINSTALL_PROTOCOL_INTERFACE)Ring3ReinstallProtocolInterface, // ReinstallProtocolInterface - (EFI_UNINSTALL_PROTOCOL_INTERFACE)Ring3UninstallProtocolInterface, // UninstallProtocolInterface - (EFI_HANDLE_PROTOCOL)Ring3HandleProtocol, // HandleProtocol - (VOID *)NULL, // Reserved - (EFI_REGISTER_PROTOCOL_NOTIFY)Ring3RegisterProtocolNotify, // RegisterProtocolNotify - (EFI_LOCATE_HANDLE)Ring3LocateHandle, // LocateHandle - (EFI_LOCATE_DEVICE_PATH)Ring3LocateDevicePath, // LocateDevicePath - (EFI_INSTALL_CONFIGURATION_TABLE)Ring3InstallConfigurationTable, // InstallConfigurationTable - (EFI_IMAGE_LOAD)Ring3LoadImage, // LoadImage - (EFI_IMAGE_START)Ring3StartImage, // StartImage - (EFI_EXIT)Ring3Exit, // Exit - (EFI_IMAGE_UNLOAD)Ring3UnloadImage, // UnloadImage - (EFI_EXIT_BOOT_SERVICES)Ring3ExitBootServices, // ExitBootServices - (EFI_GET_NEXT_MONOTONIC_COUNT)Ring3GetNextMonotonicCount, // GetNextMonotonicCount - (EFI_STALL)Ring3Stall, // Stall - (EFI_SET_WATCHDOG_TIMER)Ring3SetWatchdogTimer, // SetWatchdogTimer - (EFI_CONNECT_CONTROLLER)Ring3ConnectController, // ConnectController - (EFI_DISCONNECT_CONTROLLER)Ring3DisconnectController, // DisconnectController - (EFI_OPEN_PROTOCOL)Ring3OpenProtocol, // OpenProtocol - (EFI_CLOSE_PROTOCOL)Ring3CloseProtocol, // CloseProtocol - (EFI_OPEN_PROTOCOL_INFORMATION)Ring3OpenProtocolInformation, // OpenProtocolInformation - (EFI_PROTOCOLS_PER_HANDLE)Ring3ProtocolsPerHandle, // ProtocolsPerHandle - (EFI_LOCATE_HANDLE_BUFFER)Ring3LocateHandleBuffer, // LocateHandleBuffer - (EFI_LOCATE_PROTOCOL)Ring3LocateProtocol, // LocateProtocol - (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)Ring3InstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces - (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)Ring3UninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces - (EFI_CALCULATE_CRC32)Ring3CalculateCrc32, // CalculateCrc32 - (EFI_COPY_MEM)CopyMem, // CopyMem - (EFI_SET_MEM)SetMem, // SetMem - (EFI_CREATE_EVENT_EX)Ring3CreateEventEx, // CreateEventEx -}; - -EFI_BOOT_SERVICES *gBS = &mBootServices; - -/** - The function constructs Ring 3 wrappers for the EFI_BOOT_SERVICES. - - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. - -**/ -EFI_STATUS -EFIAPI -UefiBootServicesTableLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - return EFI_SUCCESS; -} - EFI_TPL EFIAPI Ring3RaiseTpl ( diff --git a/MdePkg/Library/Ring3UefiBootServicesTableLib/X64/SysCall.nasm b/MdeModulePkg/Core/Dxe/DxeRing3/X64/SysCall.nasm similarity index 100% rename from MdePkg/Library/Ring3UefiBootServicesTableLib/X64/SysCall.nasm rename to MdeModulePkg/Core/Dxe/DxeRing3/X64/SysCall.nasm diff --git a/MdeModulePkg/Core/Dxe/SysCall/Ring3Dxe.c b/MdeModulePkg/Core/Dxe/SysCall/Ring3Dxe.c deleted file mode 100644 index 55d971eda5..0000000000 --- a/MdeModulePkg/Core/Dxe/SysCall/Ring3Dxe.c +++ /dev/null @@ -1,62 +0,0 @@ -/** @file - - Copyright (c) 2024, Mikhail Krichanov. All rights reserved. - SPDX-License-Identifier: BSD-3-Clause - -**/ - -#include -#include - -EFI_STATUS -EFIAPI -Ring3Call ( - IN VOID *Dummy, - IN VOID *EntryPoint, - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ); - -EFI_STATUS -EFIAPI -SysCall ( - IN UINT8 Type, - ... - ); - -EFI_STATUS -EFIAPI -Ring3EntryPoint ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - RING3_DATA *Ring3Data; - - Ring3Data = (RING3_DATA *)SystemTable; - - Ring3Data->EntryPoint = (VOID *)Ring3Call; - Ring3Data->BootServices = gBS; - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -Ring3Call ( - IN VOID *Dummy, - IN VOID *EntryPoint, - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_IMAGE_ENTRY_POINT Function; - - Function = (EFI_IMAGE_ENTRY_POINT)EntryPoint; - - Function (ImageHandle, SystemTable); - - SysCall (SysCallReturnToCore); - - return EFI_UNSUPPORTED; -} diff --git a/MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.inf b/MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.inf deleted file mode 100644 index c17cb16fe5..0000000000 --- a/MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.inf +++ /dev/null @@ -1,41 +0,0 @@ -## @file -# Ring 3 wrapper for UEFI Boot Services Table Library implementation. -# -# Copyright (c) 2024, Mikhail Krichanov. All rights reserved. -# SPDX-License-Identifier: BSD-3-Clause -# -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = Ring3UefiBootServicesTableLib - MODULE_UNI_FILE = Ring3UefiBootServicesTableLib.uni - FILE_GUID = b503b4b4-6dc1-412b-965f-a0f330b1d453 - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = UefiBootServicesTableLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER - - CONSTRUCTOR = UefiBootServicesTableLibConstructor - -# -# VALID_ARCHITECTURES = IA32 X64 EBC -# - -[Sources] - Ring3.h - Ring3UefiBootServicesTableLib.c - -[Sources.X64] - X64/SysCall.nasm - -[Packages] - MdePkg/MdePkg.dec - -[LibraryClasses] - BaseMemoryLib - DebugLib - -[Protocols] - gEfiDevicePathUtilitiesProtocolGuid ## SOMETIMES_CONSUMES - gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES diff --git a/MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.uni b/MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.uni deleted file mode 100644 index 1121e5078f..0000000000 --- a/MdePkg/Library/Ring3UefiBootServicesTableLib/Ring3UefiBootServicesTableLib.uni +++ /dev/null @@ -1,12 +0,0 @@ -// /** @file -// Ring 3 wrapper for UEFI Boot Services Table Library implementation. -// -// Copyright (c) 2024, Mikhail Krichanov. All rights reserved. -// SPDX-License-Identifier: BSD-3-Clause -// -// **/ - - -#string STR_MODULE_ABSTRACT #language en-US "Ring 3 wrapper for UEFI Boot Services Table Library implementation." - -#string STR_MODULE_DESCRIPTION #language en-US "Ring 3 wrapper for UEFI Boot Services Table Library implementation."